diff --git a/PNG_generator.c b/PNG_generator.c index 8964e52..b040672 100644 --- a/PNG_generator.c +++ b/PNG_generator.c @@ -44,14 +44,7 @@ int generatePNG(const char *filename, unsigned int width, unsigned int height, b // int width = 10; // width of the image // int height = 10; // height of the image - int color_type = PNG_COLOR_TYPE_RGBA; - int bit_depth = 8; - png_set_IHDR(png_ptr, info_ptr, width, height, bit_depth, color_type, - PNG_INTERLACE_NONE, PNG_COMPRESSION_TYPE_BASE, - PNG_FILTER_TYPE_BASE); - - printDebug("IHDR set"); // Test alpha if (alpha == true) { // If alpha true run @@ -70,6 +63,15 @@ int generatePNG(const char *filename, unsigned int width, unsigned int height, b } } + int color_type = PNG_COLOR_TYPE_RGBA; + int bit_depth = 8; + + png_set_IHDR(png_ptr, info_ptr, width, height, bit_depth, color_type, + PNG_INTERLACE_NONE, PNG_COMPRESSION_TYPE_BASE, + PNG_FILTER_TYPE_BASE); + + printDebug("IHDR set"); + png_set_rows(png_ptr, info_ptr, row_pointers); png_write_png(png_ptr, info_ptr, PNG_TRANSFORM_IDENTITY, NULL); @@ -78,23 +80,31 @@ int generatePNG(const char *filename, unsigned int width, unsigned int height, b } free(row_pointers); - } else { // If alpha false run + } else { // If alpha false, run // Write the image data png_bytep *row_pointers = (png_bytep *)malloc(sizeof(png_bytep) * height); for (int y = 0; y < height; y++) { row_pointers[y] = - (png_byte *)malloc(4 * width); // 4 bytes per pixel (RGBA) + (png_byte *)malloc(3 * width); // 4 bytes per pixel (RGBA) // Fill row_pointers[y] with your image data for this row. for (int x = 0; x < width; x++) { - row_pointers[y][4 * x] = rand() % (255 + 1); // Red channel - row_pointers[y][4 * x + 1] = rand() % (255 + 1); // Green channel - row_pointers[y][4 * x + 2] = rand() % (255 + 1); // Blue channel - row_pointers[y][4 * x + 3] = 255; + row_pointers[y][3 * x] = rand() % (255 + 1); // Red channel + row_pointers[y][3 * x + 1] = rand() % (255 + 1); // Green channel + row_pointers[y][3 * x + 2] = rand() % (255 + 1); // Blue channel } } + int color_type = PNG_COLOR_TYPE_RGB; + int bit_depth = 8; + + png_set_IHDR(png_ptr, info_ptr, width, height, bit_depth, color_type, + PNG_INTERLACE_NONE, PNG_COMPRESSION_TYPE_BASE, + PNG_FILTER_TYPE_BASE); + + printDebug("IHDR set"); + png_set_rows(png_ptr, info_ptr, row_pointers); png_write_png(png_ptr, info_ptr, PNG_TRANSFORM_IDENTITY, NULL); diff --git a/version.h b/version.h index 52deaa5..df8f433 100644 --- a/version.h +++ b/version.h @@ -1,7 +1,7 @@ #ifndef VERSION_H #define VERSION_H -#define RIG_VERSION "2.3" +#define RIG_VERSION "2.3.1" #endif