PiDNG
PiDNG copied to clipboard
pack14 crashes (fix included)
When trying to save 14b raw data as a dng (see #75 for why I have to do that) PiDNG crashes:
out[:, ::7] = data[:, ::6] >> 6
~~~^^^^^^^^
ValueError: could not broadcast input array from shape (3000,502) into shape (3000,752)
This is due to the packing algorithm being just plain wrong. I'd propose the following fix, which works just fine for me:
def pack14(data : np.ndarray) -> np.ndarray:
out = np.zeros((data.shape[0], int(data.shape[1]*(1.75))), dtype=np.uint8)
out[:, ::7] = data[:, ::4] >> 6
out[:, 1::7] = ((data[:, ::4] & 0b0000000000111111) << 2)
out[:, 1::7] += data[:, 1::4] >> 12
out[:, 2::7] = ((data[:, 1::4] & 0b0000111111110000) >> 4)
out[:, 3::7] = ((data[:, 1::4] & 0b0000000000001111) << 4)
out[:, 3::7] += data[:, 2::4] >> 10
out[:, 4::7] = ((data[:, 2::4] & 0b0000001111111100) >> 2)
out[:, 5::7] = ((data[:, 2::4] & 0b0000000000000011) << 6)
out[:, 5::7] += data[:, 3::4] >> 8
out[:, 6::7] = data[:, 3::4] & 0b0000000011111111
return out
If wanted I could create a pull request for it, in which case I'd probably propose a couple other changes here to make these functions more robust.
OParczyk, you're my hero. Thank you for this contribution!!