Author Topic: Is anything known about the other images contained in the CR2?  (Read 2638 times)

ItsMeLenny

  • Hero Member
  • *****
  • Posts: 927
  • 550D
Is anything known about the other images contained in the CR2?
« on: December 28, 2016, 12:44:25 PM »
Is there anything known about the two other images contained in the CR2/TIFF files? (Obviously not about their existence).
In the sense that, there is the 160x120 jpeg followed by the bigger RGB image that has no white balance applied, all this before the actual RAW image.
Is anything known about how they are made? Is one able to just get a stream of either of these images either with or without moving the shutter?

Walter Schulz

  • Contributor
  • Hero Member
  • *****
  • Posts: 7611
Re: Is anything known about the other images contained in the CR2?
« Reply #1 on: December 28, 2016, 12:55:36 PM »
I thought the bigger one has colour correction applied (picture style + colour temperature) when viewed? Is this done by the viewer software and the data stored is in fact more "raw"?

ItsMeLenny

  • Hero Member
  • *****
  • Posts: 927
  • 550D
Re: Is anything known about the other images contained in the CR2?
« Reply #2 on: December 28, 2016, 03:34:21 PM »
According to http://lclevy.free.fr/cr2/#wb
 The second IFD is containing a small RGB version (160x120 pixels) of the picture compressed in Jpeg.
 The third IFD is containing a small RGB version of the picture NOT compressed (even with compression==6) and one which no white balance correction has been applied.
 The fourth IFD is containing the RAW data compressed in lossless Jpeg. The RAW offset field in the CR2 header is pointing to the beginning of this IFD.

Edit:
There is also the first one which is
 The first IFD is containing a small RGB version of the picture (one fourth the size) compressed in Jpeg, the EXIF part and the Makernote part.

a1ex

  • Administrator
  • Hero Member
  • *****
  • Posts: 12464
Re: Is anything known about the other images contained in the CR2?
« Reply #3 on: December 28, 2016, 05:07:49 PM »
Is anything known about how they are made? Is one able to just get a stream of either of these images either with or without moving the shutter?

I believe most of them are created from the full-size raw buffer (what ends up in a full-res silent picture). Writing to this buffer at the right moment (after CCDWriteEDmacCompleteCBR, or just before scsFinalReadoutDone) will alter the JPEG preview, and probably the RGB image as well.

For some low-level details, look here.

For example, on 5D3, the 160x120 jpeg is created with:
Code: [Select]
[TTJ][167,79319,0] JPEG(160,120,8,0)
ShootSsDev:000afe98:00:00: *** SetEDmac(0x1c, 0x41565200, 0x0, 0x20000000), from ff3c6b38
ShootSsDev:000afe98:00:00: *** SetEDmac(0x20, 0x43270070, 0x16669c, 0x1), from ff576404
...

From the figure linked above, channel 0x1c = 28 uses an input buffer of 400x540 bytes.

The LCD image is created from a 2880x960 input buffer (channel 25, likely YUV422) and the output is 1440x480 (channel 18, YUV422 => 720x480 pixels), so that processing path probably uses some sort of 2x2 pixel binning.

Some of the intermediate buffers seem to be created directly from the image processor; they happen at the same time as CCDWrite (5D3: channel 0), and they are probably all waiting for sensor data to be read out.

You can get such logs from dm-spy-experiments branch, and the raw data for EDMAC activity charts from the "edmac" branch. DIGIC 4 cameras are easier to analyze, because all the transfers are initiated from the main CPU. On DIGIC 5, some of them are started from Eeko.

If you can make those graphs more readable, that would be very helpful.

ItsMeLenny

  • Hero Member
  • *****
  • Posts: 927
  • 550D
Re: Is anything known about the other images contained in the CR2?
« Reply #4 on: December 29, 2016, 12:49:01 AM »
Thanks for the info and links.

I believe most of them are created from the full-size raw buffer (what ends up in a full-res silent picture). Writing to this buffer at the right moment (after CCDWriteEDmacCompleteCBR, or just before scsFinalReadoutDone) will alter the JPEG preview, and probably the RGB image as well.

Just one question as I actually haven't used silent pics before, are silent pics just jpeg or can they be raw as well. If they can be shot in raw do they store those two preview images as well (and correctly)?

dmilligan

  • Developer
  • Hero Member
  • *****
  • Posts: 3218
  • 60Da / 1100D / EOSM
Re: Is anything known about the other images contained in the CR2?
« Reply #5 on: December 29, 2016, 04:42:34 AM »
They are raw only from either a LV frame (single frame captured basically the same as raw video) or FRSP, a full resolution capture of the sensor without any mechanical shutter actuation. Using the DNG format (chdk-dng) will save a single preview IFD. It is generated manually, not using Canon routines and is probably slightly different than either of the CR2 ones. The new DNG library I wrote (ml_dng branch, still not merged) does not generate a preview IFD. You can also capture silent pics in MLV format, in which case there is no preview. AFAIK, we don't know how to get Canon firmware to generate a CR2 for us from some arbitrary raw buffer that we control (I could be wrong or it might be pretty easy to figure out).

ItsMeLenny

  • Hero Member
  • *****
  • Posts: 927
  • 550D
Re: Is anything known about the other images contained in the CR2?
« Reply #6 on: December 29, 2016, 08:09:04 AM »
They are raw only from either a LV frame (single frame captured basically the same as raw video) or FRSP, a full resolution capture of the sensor without any mechanical shutter actuation. Using the DNG format (chdk-dng) will save a single preview IFD. It is generated manually, not using Canon routines and is probably slightly different than either of the CR2 ones. The new DNG library I wrote (ml_dng branch, still not merged) does not generate a preview IFD. You can also capture silent pics in MLV format, in which case there is no preview. AFAIK, we don't know how to get Canon firmware to generate a CR2 for us from some arbitrary raw buffer that we control (I could be wrong or it might be pretty easy to figure out).

Ah! Thanks for the extra info.

And I guess for that last sentence; generating a CR2 from arbitrary raw data, and the CR2s being compressed in a lossless jpeg, would be a nice finding.

a1ex

  • Administrator
  • Hero Member
  • *****
  • Posts: 12464
Re: Is anything known about the other images contained in the CR2?
« Reply #7 on: December 29, 2016, 08:30:13 AM »
For research purposes, you can already do this. Simply overwrite the raw buffer with your own data.

Damiano

  • New to the forum
  • *
  • Posts: 10
Re: Is anything known about the other images contained in the CR2?
« Reply #8 on: July 20, 2020, 12:26:51 PM »
Hi to all,
I'm trying to generating a CR2 with my own data. A1ex said that I simply have to overwrite the raw buffer with my own data.
But how can I do that? Is it possible to do that with a self-made module?
Thank you,
Damiano