SRW: Keep scale for lossy compressed v3 images #38
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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:
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.