libcamera/src/py
Tomi Valkeinen b3cefd4c0e py: cam: Fix demosaic overflow issue
The demosaic code first expands the buffer datatype to uint16, and then
shifts the data left so that the 8, 10 and 12 bitspp formats all become
16 bitspp.

It then, eventually, uses np.einsum to calculate averages, but this
averaging sums multiple uint16 values together, and stores them in
uint16 storage. As in the first step we shifted the values left,
possibly getting values close to the maximum of uint16 range, we, of
course, overflow when summing them together. This leads to rather bad
looking images.

Fix this by dropping the original shift. It serves no purpose, and is
probably a remnant of some early testing code. This way the largest
numbers we are summing together are 12 bit values, and as we use a 3x3
window from which we fetch values, for a single rgb plane, the max
number of 12 bit values is 5 (for green). Sum of 5 12 bit values is well
below the 16 bit maximum.

Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
2023-03-21 23:33:43 +00:00
..
cam py: cam: Fix demosaic overflow issue 2023-03-21 23:33:43 +00:00
examples py: Switch to non-blocking eventfd 2022-08-19 15:44:28 +03:00
libcamera Expose the Request Sequence Number in Python Bindings 2022-12-19 15:07:30 +00:00
meson.build libcamera: Add missing SPDX headers for miscellaneous CC0-1.0 contents 2022-09-30 21:51:23 +03:00