Skip to content

Commit ac95fc6

Browse files
committed
image: RGBA images for JPEG/PNG export
1 parent 2f61735 commit ac95fc6

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

virtual-programs/images.folk

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,16 @@ namespace eval ::image {
7575
image[i][j * 3 + 2] = data[i*bytesPerRow + j*3 + 2];
7676
}
7777
}
78+
} else if (components == 4) {
79+
image = calloc(height, sizeof (JSAMPROW));
80+
for (size_t i = 0; i < height; i++) {
81+
image[i] = calloc(width * 3, sizeof (JSAMPLE));
82+
for (size_t j = 0; j < width; j++) {
83+
image[i][j * 3 + 0] = data[i*bytesPerRow + j*4];
84+
image[i][j * 3 + 1] = data[i*bytesPerRow + j*4 + 1];
85+
image[i][j * 3 + 2] = data[i*bytesPerRow + j*4 + 2];
86+
}
87+
}
7888
} else { exit(1); }
7989

8090
struct jpeg_compress_struct compress;
@@ -108,6 +118,10 @@ namespace eval ::image {
108118
png_set_IHDR(png_w, info_w, width, height, 8, PNG_COLOR_TYPE_RGB,
109119
PNG_INTERLACE_NONE, PNG_COMPRESSION_TYPE_DEFAULT,
110120
PNG_FILTER_TYPE_DEFAULT);
121+
else if (components == 4)
122+
png_set_IHDR(png_w, info_w, width, height, 8, PNG_COLOR_TYPE_RGBA,
123+
PNG_INTERLACE_NONE, PNG_COMPRESSION_TYPE_DEFAULT,
124+
PNG_FILTER_TYPE_DEFAULT);
111125
else if (components == 1)
112126
png_set_IHDR(png_w, info_w, width, height, 8, PNG_COLOR_TYPE_GRAY,
113127
PNG_INTERLACE_NONE, PNG_COMPRESSION_TYPE_DEFAULT,

0 commit comments

Comments
 (0)