gh2 file sizes

Started Dec 20, 2011 | Discussions thread
Franksson Forum Member • Posts: 93
Re: Raw: why?
5

I would like to point out that the Panasonic RW2 RAW encoding is certainly not lossless. The best that could be said is that it is partially lossy.

I will attempt to explain the RW2 encoding mechanism, as I understand it, and hopefully all will become clear.

Blocks of 14 raw pixel values (28 bytes) get encoded into a block of 16 bytes in the RW2 file. So the image is reduced to 57% of its original size.

The first 2 pixels in the group of 14 are encoded unchanged as 12 bit values. There then follows a series of 8 bit differences that are applied in sequence to the previous pixel of the same colour. In the encoder the pixel 3 is compared with the pixel 1 (same colour) and a difference is calculated. Similarly pixels 4 and 2 are compared then pixels 5 and 3. This gives three 8 bit difference values. But!!! 8 bits is not enough to cover the +or- 4097 12 bit range for all possible differences. So the highest (absolute) difference from the 3 is used to generate a 2 bit Shift value which indicates a 0, 1, 2 or 4 bit left shift to be applied to the difference value before it is used in the decoder. This Shift value is put into the raw image data immediately after pixel 2 and is followed by the 3 * 8 bit difference values. Pixels 6, 7, 8 get a new 2 bit Shift value and so on to the end of the 14 pixel block.

The effect of shifting the 8 bit difference is to lose the 1, 2 or 4 least significant bits from the difference. These bits are lost for ever. In the case where a new larger value is being generated, this loss may not be too significant. However because there are three differences all sharing the same Shift value, there could be significant errors introduced to small pixel values where there is only a small difference to be applied.

I assume that the Panasonic encoder computes the pixel value that a decoder will generate, and use that as the reference to calculate the next difference value (rather than the actual value, which will be lost for ever). That would ensure that the errors are not compounded and magnified towards the end of the 14 pixels. It would be the sensible thing to do. But then implementing a lossless mechanism might have been sensible also (or costly if there is IPR elsewhere).

I obtained the RW2 encoding information above by referencing the source code for DCRaw.

It's not all bad! - 2 out of 14 pixels are always correct. 12 out of 14 pixels might be correct and will usually be mostly correct. If it worries anyone, just try to avoid shooting high contrast pictures

 Franksson's gear list:Franksson's gear list
Panasonic Lumix DMC-GH2 Panasonic G85 Panasonic Lumix G Vario 7-14mm F4 ASPH Panasonic Lumix G Vario HD 14-140mm F4-5.8 OIS Panasonic Lumix G Vario 100-300mm F4-5.6 OIS +1 more
Post (hide subjects) Posted by
Keyboard shortcuts:
FForum PPrevious NNext WNext unread UUpvote SSubscribe RReply QQuote BBookmark MMy threads
Color scheme? Blue / Yellow