|
@@ -306,31 +306,33 @@ libmegapixels_format_cfa_pattern(int format)
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-// mp_pixel_format_width_to_bytes
|
|
|
+/* Calculates the number of bytes required to store a row of pixels for a given mode and width. */
|
|
|
uint32_t
|
|
|
libmegapixels_mode_width_to_bytes(int index, uint32_t width)
|
|
|
{
|
|
|
uint32_t bits_per_pixel = mode_lut[index].bpp;
|
|
|
uint64_t bits_per_width = width * (uint64_t) bits_per_pixel;
|
|
|
uint64_t remainder = bits_per_width % 8;
|
|
|
+ uint32_t result = 0;
|
|
|
if (remainder == 0)
|
|
|
- return bits_per_width / 8;
|
|
|
+ result = bits_per_width / 8;
|
|
|
+ else
|
|
|
+ result = (bits_per_width + 8 - remainder) / 8;
|
|
|
|
|
|
- return (bits_per_width + 8 - remainder) / 8;
|
|
|
+ return result;
|
|
|
}
|
|
|
|
|
|
+/* 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)
|
|
|
{
|
|
|
- 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;
|
|
|
+ int remainder = mode_lut[index].bpp % 8;
|
|
|
if (remainder == 0)
|
|
|
- return remainder;
|
|
|
+ return 0;
|
|
|
+
|
|
|
+ uint32_t padding = ((uint64_t) (8 - remainder) * width) / 8;
|
|
|
|
|
|
- return 8 - remainder;
|
|
|
+ return padding;
|
|
|
}
|
|
|
|
|
|
uint32_t
|