|
@@ -307,12 +307,14 @@ libmegapixels_format_cfa_pattern(int format)
|
|
|
}
|
|
|
|
|
|
// Useful for the calculation: https://www.1stvision.com/cameras/IDS/IDS-manuals/en/basics-raw-bayer-pixel-formats.html
|
|
|
-
|
|
|
-/* Calculates the number of bytes required to store a row of pixels for a given mode and width. */
|
|
|
+// Note that BayerGB12 is packed according to that document, but this is likely a mistake
|
|
|
uint32_t
|
|
|
libmegapixels_mode_width_to_bytes(int index, uint32_t width)
|
|
|
{
|
|
|
uint32_t bits_per_pixel = mode_lut[index].bpp;
|
|
|
+ // For bpp like 10/12/14, for formats that are not packed, we want to set bpp to something like 16
|
|
|
+ if (bits_per_pixel % 8 != 0 && !libmegapixels_mode_is_packed(index))
|
|
|
+ bits_per_pixel = bits_per_pixel + 8 - (bits_per_pixel % 8);
|
|
|
uint64_t bits_per_width = width * (uint64_t) bits_per_pixel;
|
|
|
uint64_t remainder = bits_per_width % 8;
|
|
|
if (remainder == 0)
|
|
@@ -321,17 +323,18 @@ libmegapixels_mode_width_to_bytes(int index, uint32_t width)
|
|
|
return (bits_per_width + 8 - remainder) / 8;
|
|
|
}
|
|
|
|
|
|
-/* Calculates the padding (in bytes) required at the end of each row for a given mode and width. */
|
|
|
uint32_t
|
|
|
libmegapixels_mode_width_to_padding(int index, uint32_t width)
|
|
|
{
|
|
|
- int remainder = mode_lut[index].bpp % 8;
|
|
|
- if (remainder == 0 || libmegapixels_mode_is_packed(index))
|
|
|
+ if (mode_lut[index].bpp == 8) {
|
|
|
return 0;
|
|
|
+ }
|
|
|
+ uint64_t bytes_per_width = libmegapixels_mode_width_to_bytes(index, width);
|
|
|
+ uint64_t remainder = bytes_per_width % 8;
|
|
|
+ if (remainder == 0)
|
|
|
+ return remainder;
|
|
|
|
|
|
- uint32_t padding = ((uint64_t) (8 - remainder) * width) / 8;
|
|
|
-
|
|
|
- return padding;
|
|
|
+ return 8 - remainder;
|
|
|
}
|
|
|
|
|
|
uint32_t
|