|
@@ -306,6 +306,8 @@ 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. */
|
|
/* Calculates the number of bytes required to store a row of pixels for a given mode and width. */
|
|
uint32_t
|
|
uint32_t
|
|
libmegapixels_mode_width_to_bytes(int index, uint32_t width)
|
|
libmegapixels_mode_width_to_bytes(int index, uint32_t width)
|
|
@@ -313,13 +315,10 @@ libmegapixels_mode_width_to_bytes(int index, uint32_t width)
|
|
uint32_t bits_per_pixel = mode_lut[index].bpp;
|
|
uint32_t bits_per_pixel = mode_lut[index].bpp;
|
|
uint64_t bits_per_width = width * (uint64_t) bits_per_pixel;
|
|
uint64_t bits_per_width = width * (uint64_t) bits_per_pixel;
|
|
uint64_t remainder = bits_per_width % 8;
|
|
uint64_t remainder = bits_per_width % 8;
|
|
- uint32_t result = 0;
|
|
|
|
if (remainder == 0)
|
|
if (remainder == 0)
|
|
- result = bits_per_width / 8;
|
|
|
|
- else
|
|
|
|
- result = (bits_per_width + 8 - remainder) / 8;
|
|
|
|
|
|
+ return bits_per_width / 8;
|
|
|
|
|
|
- return result;
|
|
|
|
|
|
+ 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. */
|
|
/* Calculates the padding (in bytes) required at the end of each row for a given mode and width. */
|
|
@@ -327,7 +326,7 @@ uint32_t
|
|
libmegapixels_mode_width_to_padding(int index, uint32_t width)
|
|
libmegapixels_mode_width_to_padding(int index, uint32_t width)
|
|
{
|
|
{
|
|
int remainder = mode_lut[index].bpp % 8;
|
|
int remainder = mode_lut[index].bpp % 8;
|
|
- if (remainder == 0)
|
|
|
|
|
|
+ if (remainder == 0 || libmegapixels_mode_is_packed(index))
|
|
return 0;
|
|
return 0;
|
|
|
|
|
|
uint32_t padding = ((uint64_t) (8 - remainder) * width) / 8;
|
|
uint32_t padding = ((uint64_t) (8 - remainder) * width) / 8;
|
|
@@ -399,6 +398,20 @@ libmegapixels_mode_equals(libmegapixels_mode *a, libmegapixels_mode *b)
|
|
return 1;
|
|
return 1;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+int
|
|
|
|
+libmegapixels_mode_is_packed(int index)
|
|
|
|
+{
|
|
|
|
+ switch (mode_lut[index].v4l_pixel_format) {
|
|
|
|
+ case V4L2_PIX_FMT_SBGGR10P:
|
|
|
|
+ case V4L2_PIX_FMT_SGBRG10P:
|
|
|
|
+ case V4L2_PIX_FMT_SGRBG10P:
|
|
|
|
+ case V4L2_PIX_FMT_SRGGB10P:
|
|
|
|
+ return 1;
|
|
|
|
+ default:
|
|
|
|
+ return 0;
|
|
|
|
+ }
|
|
|
|
+}
|
|
|
|
+
|
|
int
|
|
int
|
|
mode_snprintf(char *buf, size_t maxlen, libmegapixels_mode *mode)
|
|
mode_snprintf(char *buf, size_t maxlen, libmegapixels_mode *mode)
|
|
{
|
|
{
|