pedrocr / rawloader

rust library to extract the raw data and some metadata from digital camera images
GNU Lesser General Public License v2.1
304 stars 53 forks source link

SRW: Keep scale for lossy compressed v3 images #38

Open cytrinox opened 2 years ago

cytrinox commented 2 years ago

While integrating srw support into dnglab, I stumbled across this little bug. The Samsung NX500 (see raw samples at raw.pixls.us) produces 12 and 14 bit images with lossy or lossless compression. For lossy, the srw3 scale parameter is used to rescale the pixels. The scale is recalculated every 64 pixels. Resetting the scale to zero in other cases leads to invalid images.

Output of an image decoded with invalid scale values:

grafik

Feel free to modify this PR for your needs.

Just FYI: I've played around the srw3 decoder and I'm not sure if it is properly implemented. The diff and out values are all clamped to u16. If the calculation is done entirely with i32 and after full decompression everything is clamped to u16, the checksum for the output is different. And again different when only one row (in the for-height loop) is keept as i32 and then clamped and copied into the out buffer. So three methods, three different outputs. I don't see any visible difference, I just wonder what's the correct method is. I can't find a source at opensource.samsung.com.