Skip to content

Commit

Permalink
v2.3.1: around 5% speedup in png without alpha channel (tested on 2 c…
Browse files Browse the repository at this point in the history
…ores and sata ssd laptop)
  • Loading branch information
SzBenedek2006 committed Aug 30, 2024
1 parent affcda6 commit 16fd140
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 14 deletions.
36 changes: 23 additions & 13 deletions PNG_generator.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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);

Expand All @@ -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);

Expand Down
2 changes: 1 addition & 1 deletion version.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#ifndef VERSION_H
#define VERSION_H

#define RIG_VERSION "2.3"
#define RIG_VERSION "2.3.1"


#endif

0 comments on commit 16fd140

Please sign in to comment.