Skip to content

Commit 38d6fd3

Browse files
committed
[FIX] - BmpToPng
Additionally added a line to properly convert from BMP colour variant to the PNG colour variant, previously the image turned blue. This version now Fixes it for any filtered image. (Left in the commented out Functionality for them for testing purposes). - See how to add the library in the wiki!
1 parent 96dba8a commit 38d6fd3

File tree

3 files changed

+14
-4
lines changed

3 files changed

+14
-4
lines changed

src/assets/images/testpng.png

161 KB
Loading

src/converters/bmp_to_png.c

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -96,10 +96,18 @@ int bmp_to_png(const char *input_filename, const char *output_filename)
9696
// write PNG header info
9797
png_write_info(png_ptr, info_ptr);
9898
// write PNG image data
99-
for (int y = 0; y < height; y++)
100-
{
101-
png_bytep row_pointer = &bmp_data[(height - y - 1) * (width * 3 + padding)];
102-
png_write_row(png_ptr, row_pointer);
99+
for (int y = 0; y < height; y++) {
100+
png_bytep row_pointer = &bmp_data[(height - y - 1) * (width * 3 + padding)];
101+
102+
// Convert BGR to RGB
103+
for (int x = 0; x < width; x++) {
104+
png_bytep pixel = &row_pointer[x * 3];
105+
png_byte temp = pixel[0];
106+
pixel[0] = pixel[2];
107+
pixel[2] = temp;
108+
}
109+
110+
png_write_row(png_ptr, row_pointer);
103111
}
104112
// finish writing PNG file
105113
png_write_end(png_ptr, NULL);

src/main.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
#include "gtk_gui.c"
22
//#include "converters/bmp_to_jpeg.c" // Include this line to test the bmp_to_jpeg function
3+
//#include "converters/bmp_to_png.c"
34

45
int main(int argc, char **argv)
56
{
67
//Include the following line to test the bmp_to_jpeg function
78
//bmp_to_jpeg("assets/images/test_image.bmp", "assets/images/testjpg.jpg");
9+
//bmp_to_png("assets/images/test_image_negative.bmp", "assets/images/testpng.png");
810

911
GtkApplication *app;
1012
int status;

0 commit comments

Comments
 (0)