App for viewing Code

Started by Milk and Coffee, March 02, 2021, 04:06:25 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Milk and Coffee

This is a total newb question, but I just need some help to get started on the right foot:

What app can I use to view the "code" that makes up a .CR2 or .DNG file?

Context: http://lclevy.free.fr/cr2/
That is a link that provides an explanation of the code inside a .CR2 file. BUT I cannot figure out how to open my own .CR2 files to view the "code."

What apps allow me to do this on macOSX?

Thanks so much!
Canon 5D Mark II, Mac/OSX

names_are_hard

You want a hex editor, there are many options.  010 Editor is very good, and has a free trial.

Milk and Coffee

Quote from: names_are_hard on March 02, 2021, 05:01:04 AM
You want a hex editor, there are many options.  010 Editor is very good, and has a free trial.

This is SO helpful! Thank you!
Canon 5D Mark II, Mac/OSX

Milk and Coffee

So I downloaded "Hex Fiend" for mac. From this link http://lclevy.free.fr/cr2 I'm seeing code examples like this:

(5D Mark II RAW) 
JPEG_SOF3: length=20
bits=14, wide=1448, high=3804, nb comp=4
  index=1, h=1, v=1, qt=0
  index=2, h=1, v=1, qt=0
  index=3, h=1, v=1, qt=0
  index=4, h=1, v=1, qt=0


I'm not seeing any code like that in the Hex Editor. I see the Hexidecimals of course, but the plain text view is nothing like the above. I tried Hexed.it as well. Is there a "view" setting I need to change? Is a Hex editor the correct program to view code in the format above / is there another app out there that shows me code similar to the above?

Let me know if you need clarification
Canon 5D Mark II, Mac/OSX

names_are_hard

It's data, not code :)  That text format example you give has been generated from the data, via parsing it.  The data is what a CR2 image really is, not the text.  When you use a hex editor to inspect the data, you are looking at the "code" of the file.  So, the closest answer I could imagine for your original question of "What app can I use to view the "code" that makes up a .CR2 or .DNG file?", is a hex editor.

Further in the page on the link you gave, you can find this, which may explain what I mean more easily:
https://raw.githubusercontent.com/lclevy/libcraw2/master/docs/cr2_poster.pdf

It might help if you tell us want you want to *achieve*, rather than what you think you need to do.

Milk and Coffee

I want to open my own CR2 images and compare the data to that of the same CR2 converted to DNG. I also would like to compare the Bayer data of a CR2 and a frame from an MLV. And if I'm feeling crazy, I'd also like to look at Canon's SRAW since it looks like it doesn't contain any Bayer data.

Thank you for your patience! - So to see the text format example, the file needs to be parsed. To parse the file, I should use DCraw (I see that's what the original article is using.)?
Canon 5D Mark II, Mac/OSX

names_are_hard

Thanks, those questions are well phrased now I think - people more knowledgeable about RAW formats should be able to answer them.

I can tell you that I don't think there is Bayer *data* in the files, simply because there isn't a need.  It contains the raw data for all RGB elements, and the layout of those pixels.  If they're laid out in a Bayer pattern, you can then apply a Bayer filter whenever you want (the processing tools will likely do this for you).

DCRaw is defunct, you might want to look at https://github.com/LibRaw/LibRaw as an alternative.  Either should be able to parse a CR2.  Whether that's the best way for what you want, I don't know.

Walter Schulz

RAWdigger comes to mind. You can use it for limited time after installation without fee.

Milk and Coffee

Quote from: names_are_hard on March 08, 2021, 08:15:20 PM
I can tell you that I don't think there is Bayer *data* in the files, simply because there isn't a need.

Thank you! Could you be more specific about what you mean by "Bayer Data"? I thought bayer data was present in all RAW sensor data? If there is no Bayer Data, does that mean it's not RAW?

And thanks Walter! I'll give that one a go!
Canon 5D Mark II, Mac/OSX

names_are_hard

I don't believe there is such a thing as "Bayer data".  You introduced the term, I tried to guess what you meant by it and explain why I thought it doesn't exist.

a1ex

By "Bayer data", OP means Bayer image data, that is, image data which wasn't demosaiced. Look at e.g.:

Imatest docs -> "undemosaiced (Bayer) data"
Processing-RAW-Images-in-MATLAB-Sumner.pdf -> "Bayer CFA data"
Picamera Raw Bayer data captures -> "raw Bayer data recorded by the camera's sensor"
"bayer data" site:magiclantern.fm ... ;)

This kind of image data is what you get with "dcraw -4 -E". For a CR2, the pixel values output by that dcraw command are actually the exact values encoded in the CR2 file, after lossless decompression. For an uncompressed DNG (such as one saved by ML's silent picture module), the pixel values obtained by using that command are the exact values saved in the DNG. Same for a lossless DNG - pixels output by that dcraw command are the actual pixel values that were encoded when creating the DNG - without any image processing applied.

The only thing "dcraw -4 -E" does is to extract the image data (by parsing and unpacking/decompressing the input file), without applying any kind of image processing. That command will output the actual image data encoded in the CR2 file, into a 16-bit PPM PGM (which you can further process in Octave, for example). Or a 16-bit TIFF if you also use -T.

Quote from: man dcraw
[...] Use dcraw -E -4 to get the raw pixel values. [...]

-d     Show  the  raw  data as a grayscale image with no interpolation.
        Good for photographing black-and-white documents.

-D     Same as -d, but with the original unscaled pixel values.

-E     Same as -D, but masked pixels are not cropped.

With LibRaw, the above options were removed from dcraw_emu - apparently the unprocessed_raw command does what OP wants, but I didn't try it.

Now, the data that can be encoded into a CR2 or DNG might be either unprocessed / minimally processed by the camera (which is what Imatest calls "Camera RAW"), or it might be further processed - for example, our Dual ISO conversion tool (cr2hdr) outputs non-demosaiced (Bayer) image data as DNG. In the latter case, the image data is obviously not RAW.

So, if you know a better name for the nonexistent thing that we used to call "Bayer data", please enlighten us ;)




To summarize:
- to extract the unprocessed image data from a CR2 or DNG: "dcraw -4 -E" or "unprocessed_raw"
- to view the CR2/DNG metadata: exiftool (as answered previously) or exiv2
- to interpret the low-level CR2/DNG file contents yourself: hex editor, or... highly recommended: "exiftool -htmlDump".

Levas

Quote from: a1ex on March 09, 2021, 07:52:33 AM
That command will output the actual image data encoded in the CR2 file, into a 16-bit PPM

ppm you say, interesting, easy to modify.
Is there anyway to convert such a ppm file back to DNG or CR2 ?

Still a big fan of this script:
https://www.magiclantern.fm/forum/index.php?topic=20999.msg193367#msg193367
Curious if it works for ppm files with raw data.
I know, there are other programs out there which can average out multiple raw files, but this script works really well and is easy to modify to do a Median output instead of mean.


a1ex

Correction: for Bayer files, dcraw will output a PGM file (the grayscale version of PPM). But yes, they are reasonably easy to work with, for example with Octave scripts. There are a few examples on the forum - look up "pgm2dng" and maybe also "read_raw".

This file format is simple enough to be read/written with a few lines of C, without any dependencies - one of the reasons ML saves PPM screenshots. It doesn't handle metadata, though, but if you want to compare the image data from CR2/DNG files (for example, to make sure lossless is actually lossless), converting both files to PGM via "dcraw -4 -E" and comparing the contents works reasonably well. Caveat: these files might have embedded comments.

PGM file format: http://netpbm.sourceforge.net/doc/pgm.html

names_are_hard

QuoteSo, if you know a better name for the nonexistent thing that we used to call "Bayer data", please enlighten us

Ah, I was misinterpreting it :)  The earlier question read to me like "where is the Bayer data inside the raw data?", and not "where is the Bayer data which is the raw data?"

I think your dcraw + exiftool examples should get OP what they want, thanks!

Milk and Coffee

Thank you all for the responses! I'm slowly catching up! Appreciate your patience 🙏
Canon 5D Mark II, Mac/OSX