schoolpost / PiDNG

Create Adobe DNG RAW files using Python. Works with any Bayer RAW Data including native support for Raspberry Pi cameras.
MIT License
196 stars 37 forks source link

Correct raw image sizes for Raspberry Pi v1 and v2 sensors #57

Closed davidplowman closed 2 years ago

davidplowman commented 2 years ago

@schoolpost Hi! The one thing I'm a bit nervous about here is whether this breaks legacy stack (raspistill) support, as the raw images possibly do have vertical padding there?

One idea might be to get the caller to pass in the image dimensions and stride as Picamera2 does know them, and that might make this work for non-official cameras too.

schoolpost commented 2 years ago

I wrote this new general solution, might need some error checking; I've tested with HQ camera, would need testing with others. https://github.com/schoolpost/PiDNG/blob/48c4aee885f0b707d9d442e8c15275bac677e070/src/pidng/core.py#L166-L185

davidplowman commented 2 years ago

Thanks, this is working well with all the three official cameras. Are the sizes and stride coming from libcamera now, so that it would work with non-official cameras too?

I've noticed just one problem with it, which is that Picamera2 users can ask for packed or unpacked data. To get unpacked raw data you would use

capture_config = picam2.still_configuration(raw={'format': 'SBGGR12'})
picam2.switch_mode_and_capture_file(capture_config, "test.dng", name='raw')

and I'm finding that the image contents are garbled. I assume it's unpacking the data when it doesn't need too. You can always tell a packed format because the format string will have '_CSI2P' on the end. Is that something that can be fixed?

Thanks!

schoolpost commented 2 years ago

Thanks, this is working well with all the three official cameras. Are the sizes and stride coming from libcamera now, so that it would work with non-official cameras too?

I've noticed just one problem with it, which is that Picamera2 users can ask for packed or unpacked data. To get unpacked raw data you would use

capture_config = picam2.still_configuration(raw={'format': 'SBGGR12'})
picam2.switch_mode_and_capture_file(capture_config, "test.dng", name='raw')

and I'm finding that the image contents are garbled. I assume it's unpacking the data when it doesn't need too. You can always tell a packed format because the format string will have '_CSI2P' on the end. Is that something that can be fixed?

Thanks!

Yes this should work with non-official cameras; of course could still use some testing.

This should fix that; again pending tests on camera's other than the HQ Camera. https://github.com/schoolpost/PiDNG/blob/37b301e35ab0275303d08a80058c431d9f19c395/src/pidng/core.py#L170-L192

davidplowman commented 2 years ago

Thanks for the update. I was still having some trouble with the unpacked raw format conversion so I've updated this pull request to fix the problem that seemed to be remaining. Does this look OK to you now? Thanks!

davidplowman commented 2 years ago

And just to let you know that I've merged the Picamera2 changes to enable DNGs as that seems to be working fine. I'm very excited to see DNG support integrated nicely into Picamera2!!