|
@@ -35,7 +35,22 @@ struct Bng
|
|
|
uint32_t width;
|
|
|
uint32_t height;
|
|
|
struct Bng_Pixel_Format pixel_format;
|
|
|
- uint8_t data[];
|
|
|
+ uint32_t pixels[];
|
|
|
} PACKED;
|
|
|
|
|
|
+#define GET_BYTE(bytes, index) ((bytes & (0xFF << ((4 - index - 1) * 8))) >> ((4 - index - 1) * 8))
|
|
|
+#define SET_BYTE(bytes, index, byte) bytes = (bytes | (byte << ((4 - index - 1) * 8)))
|
|
|
+
|
|
|
+uint32_t convert_pixel(uint32_t pixel,
|
|
|
+ struct Bng_Pixel_Format source,
|
|
|
+ struct Bng_Pixel_Format desired)
|
|
|
+{
|
|
|
+ uint32_t result = 0;
|
|
|
+ SET_BYTE(result, desired.red_byte, GET_BYTE(pixel, source.red_byte));
|
|
|
+ SET_BYTE(result, desired.green_byte, GET_BYTE(pixel, source.green_byte));
|
|
|
+ SET_BYTE(result, desired.blue_byte, GET_BYTE(pixel, source.blue_byte));
|
|
|
+ SET_BYTE(result, desired.alpha_byte, GET_BYTE(pixel, source.alpha_byte));
|
|
|
+ return result;
|
|
|
+}
|
|
|
+
|
|
|
#endif // BNG_H_
|