apple_png 0.1.2 → 0.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/ext/apple_png/apple_png.c +82 -4
- metadata +1 -1
data/ext/apple_png/apple_png.c
CHANGED
@@ -123,6 +123,12 @@ static int png_deflate(unsigned char *data, uint32_t length, unsigned char **out
|
|
123
123
|
return APPLE_PNG_OK;
|
124
124
|
}
|
125
125
|
|
126
|
+
static void flip_colors(unsigned char *pixelData, size_t index) {
|
127
|
+
char tmp = pixelData[index];
|
128
|
+
pixelData[index] = pixelData[index + 2];
|
129
|
+
pixelData[index + 2] = tmp;
|
130
|
+
}
|
131
|
+
|
126
132
|
/* flip first and third color in uncompressed png pixel data */
|
127
133
|
static void flip_color_bytes(unsigned char *pixelData, uint32_t width, uint32_t height) {
|
128
134
|
uint32_t x, y;
|
@@ -131,9 +137,75 @@ static void flip_color_bytes(unsigned char *pixelData, uint32_t width, uint32_t
|
|
131
137
|
for (y = 0; y < height; y++) {
|
132
138
|
i += 1;
|
133
139
|
for (x = 0; x < width; x++) {
|
134
|
-
|
135
|
-
|
136
|
-
|
140
|
+
flip_colors(pixelData, i);
|
141
|
+
i += 4;
|
142
|
+
}
|
143
|
+
}
|
144
|
+
}
|
145
|
+
|
146
|
+
static void interlaced_flip_color_bytes(unsigned char *pixelData, uint32_t width, uint32_t height) {
|
147
|
+
uint32_t x, y;
|
148
|
+
size_t i = 0;
|
149
|
+
|
150
|
+
// pass 1
|
151
|
+
for (y = 0; y < height; y += 8) {
|
152
|
+
i += 1;
|
153
|
+
for (x = 0; x < width; x += 8) {
|
154
|
+
flip_colors(pixelData, i);
|
155
|
+
i += 4;
|
156
|
+
}
|
157
|
+
}
|
158
|
+
|
159
|
+
// pass 2
|
160
|
+
for (y = 0; y < height; y += 8) {
|
161
|
+
i += 1;
|
162
|
+
for (x = 5; x < width; x += 8) {
|
163
|
+
flip_colors(pixelData, i);
|
164
|
+
i += 4;
|
165
|
+
}
|
166
|
+
}
|
167
|
+
|
168
|
+
// pass 3
|
169
|
+
for (y = 4; y < height; y += 8) {
|
170
|
+
i += 1;
|
171
|
+
for (x = 0; x < width; x += 4) {
|
172
|
+
flip_colors(pixelData, i);
|
173
|
+
i += 4;
|
174
|
+
}
|
175
|
+
}
|
176
|
+
|
177
|
+
// pass 4
|
178
|
+
for (y = 0; y < height; y += 4) {
|
179
|
+
i += 1;
|
180
|
+
for (x = 2; x < width; x += 4) {
|
181
|
+
flip_colors(pixelData, i);
|
182
|
+
i += 4;
|
183
|
+
}
|
184
|
+
}
|
185
|
+
|
186
|
+
// pass 5
|
187
|
+
for (y = 2; y < height; y += 4) {
|
188
|
+
i += 1;
|
189
|
+
for (x = 0; x < width; x += 2) {
|
190
|
+
flip_colors(pixelData, i);
|
191
|
+
i += 4;
|
192
|
+
}
|
193
|
+
}
|
194
|
+
|
195
|
+
// pass 6
|
196
|
+
for (y = 0; y < height; y += 2) {
|
197
|
+
i += 1;
|
198
|
+
for (x = 1; x < width; x += 2) {
|
199
|
+
flip_colors(pixelData, i);
|
200
|
+
i += 4;
|
201
|
+
}
|
202
|
+
}
|
203
|
+
|
204
|
+
// pass 7
|
205
|
+
for (y = 1; y < height; y += 2) {
|
206
|
+
i += 1;
|
207
|
+
for (x = 0; x < width; x++) {
|
208
|
+
flip_colors(pixelData, i);
|
137
209
|
i += 4;
|
138
210
|
}
|
139
211
|
}
|
@@ -194,7 +266,13 @@ static int readPngChunks(VALUE self, const char *oldPNG, size_t oldPngLength, dy
|
|
194
266
|
dyn_arr_free(applePngCompressedPixelData);
|
195
267
|
return error;
|
196
268
|
}
|
197
|
-
|
269
|
+
|
270
|
+
if (interlaced) {
|
271
|
+
interlaced_flip_color_bytes(decompressedPixelData, width, height);
|
272
|
+
} else {
|
273
|
+
flip_color_bytes(decompressedPixelData, width, height);
|
274
|
+
}
|
275
|
+
|
198
276
|
error = png_deflate(decompressedPixelData, uncompressed_size, &standardPngCompressedPixelData, &compressed_size);
|
199
277
|
if (error != APPLE_PNG_OK) {
|
200
278
|
dyn_arr_free(applePngCompressedPixelData);
|