13 #ifdef PNG_WRITE_SUPPORTED
21 png_debug(1,
"in png_do_write_transformations\n");
26 #if defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED)
27 if (png_ptr->transformations & PNG_USER_TRANSFORM)
28 if (png_ptr->write_user_transform_fn != NULL)
29 (*(png_ptr->write_user_transform_fn))
38 png_ptr->row_buf + 1);
40 #if defined(PNG_WRITE_FILLER_SUPPORTED)
41 if (png_ptr->transformations & PNG_FILLER)
45 #if defined(PNG_WRITE_PACKSWAP_SUPPORTED)
46 if (png_ptr->transformations & PNG_PACKSWAP)
49 #if defined(PNG_WRITE_PACK_SUPPORTED)
50 if (png_ptr->transformations & PNG_PACK)
51 png_do_pack(&(png_ptr->row_info), png_ptr->row_buf + 1,
54 #if defined(PNG_WRITE_SWAP_SUPPORTED)
55 if (png_ptr->transformations & PNG_SWAP_BYTES)
56 png_do_swap(&(png_ptr->row_info), png_ptr->row_buf + 1);
58 #if defined(PNG_WRITE_SHIFT_SUPPORTED)
59 if (png_ptr->transformations & PNG_SHIFT)
63 #if defined(PNG_WRITE_SWAP_ALPHA_SUPPORTED)
64 if (png_ptr->transformations & PNG_SWAP_ALPHA)
67 #if defined(PNG_WRITE_INVERT_ALPHA_SUPPORTED)
68 if (png_ptr->transformations & PNG_INVERT_ALPHA)
71 #if defined(PNG_WRITE_BGR_SUPPORTED)
72 if (png_ptr->transformations & PNG_BGR)
73 png_do_bgr(&(png_ptr->row_info), png_ptr->row_buf + 1);
75 #if defined(PNG_WRITE_INVERT_SUPPORTED)
76 if (png_ptr->transformations & PNG_INVERT_MONO)
81 #if defined(PNG_WRITE_PACK_SUPPORTED)
90 if (row_info->bit_depth == 8 &&
91 #
if defined(PNG_USELESS_TESTS_SUPPORTED)
92 row != NULL && row_info != NULL &&
94 row_info->channels == 1)
110 for (
i = 0;
i < row_width;
i++)
140 for (
i = 0;
i < row_width;
i++)
145 v |= (
value << shift);
172 for (
i = 0;
i < row_width;
i++)
177 v |= (
value << shift);
198 row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth,
204 #if defined(PNG_WRITE_SHIFT_SUPPORTED)
216 #if defined(PNG_USELESS_TESTS_SUPPORTED)
217 if (
row != NULL && row_info != NULL &&
223 int shift_start[4], shift_dec[4];
226 if (row_info->color_type & PNG_COLOR_MASK_COLOR)
228 shift_start[channels] = row_info->bit_depth - bit_depth->red;
229 shift_dec[channels] = bit_depth->red;
231 shift_start[channels] = row_info->bit_depth - bit_depth->green;
232 shift_dec[channels] = bit_depth->green;
234 shift_start[channels] = row_info->bit_depth - bit_depth->blue;
235 shift_dec[channels] = bit_depth->blue;
240 shift_start[channels] = row_info->bit_depth - bit_depth->gray;
241 shift_dec[channels] = bit_depth->gray;
246 shift_start[channels] = row_info->bit_depth - bit_depth->alpha;
247 shift_dec[channels] = bit_depth->alpha;
252 if (row_info->bit_depth < 8)
257 png_uint_32 row_bytes = row_info->rowbytes;
259 if (bit_depth->gray == 1 && row_info->bit_depth == 2)
261 else if (row_info->bit_depth == 4 && bit_depth->gray == 3)
266 for (i = 0; i < row_bytes; i++, bp++)
273 for (j = shift_start[0]; j > -shift_dec[0]; j -= shift_dec[0])
276 *bp |= (png_byte)((v << j) & 0xff);
278 *bp |= (png_byte)((v >> (-j)) & mask);
282 else if (row_info->bit_depth == 8)
286 png_uint_32 istop = channels * row_info->width;
288 for (i = 0; i < istop; i++, bp++)
293 int c = (int)(i%channels);
297 for (j = shift_start[c]; j > -shift_dec[c]; j -= shift_dec[c])
300 *bp |= (png_byte)((v << j) & 0xff);
302 *bp |= (png_byte)((v >> (-j)) & 0xff);
312 for (bp =
row,
i = 0;
i < istop;
i++)
314 int c = (
int)(
i%channels);
320 for (j = shift_start[
c]; j > -shift_dec[
c]; j -= shift_dec[
c])
335 #if defined(PNG_WRITE_SWAP_ALPHA_SUPPORTED)
339 png_debug(1,
"in png_do_write_swap_alpha\n");
340 #if defined(PNG_USELESS_TESTS_SUPPORTED)
341 if (
row != NULL && row_info != NULL)
347 if (row_info->bit_depth == 8)
352 for (
i = 0, sp = dp =
row;
i < row_width;
i++)
368 for (
i = 0, sp = dp =
row;
i < row_width;
i++)
387 if (row_info->bit_depth == 8)
393 for (
i = 0, sp = dp =
row;
i < row_width;
i++)
407 for (
i = 0, sp = dp =
row;
i < row_width;
i++)
423 #if defined(PNG_WRITE_INVERT_ALPHA_SUPPORTED)
427 png_debug(1,
"in png_do_write_invert_alpha\n");
428 #if defined(PNG_USELESS_TESTS_SUPPORTED)
429 if (
row != NULL && row_info != NULL)
435 if (row_info->bit_depth == 8)
440 for (
i = 0, sp = dp =
row;
i < row_width;
i++)
448 *(dp++) = (
png_byte)(255 - *(sp++));
458 for (
i = 0, sp = dp =
row;
i < row_width;
i++)
469 *(dp++) = (
png_byte)(255 - *(sp++));
470 *(dp++) = (
png_byte)(255 - *(sp++));
477 if (row_info->bit_depth == 8)
483 for (
i = 0, sp = dp =
row;
i < row_width;
i++)
486 *(dp++) = (
png_byte)(255 - *(sp++));
496 for (
i = 0, sp = dp =
row;
i < row_width;
i++)
503 *(dp++) = (
png_byte)(255 - *(sp++));
504 *(dp++) = (
png_byte)(255 - *(sp++));
512 #if defined(PNG_MNG_FEATURES_SUPPORTED)
517 png_debug(1,
"in png_do_write_intrapixel\n");
519 #
if defined(PNG_USELESS_TESTS_SUPPORTED)
520 row != NULL && row_info != NULL &&
526 if (row_info->bit_depth == 8)
538 for (
i = 0, rp =
row;
i < row_width;
i++, rp += bytes_per_pixel)
540 *(rp) = (
png_byte)((*rp - *(rp+1))&0xff);
541 *(rp+2) = (
png_byte)((*(rp+2) - *(rp+1))&0xff);
544 else if (row_info->bit_depth == 16)
556 for (
i = 0, rp =
row;
i < row_width;
i++, rp += bytes_per_pixel)
565 *(rp+4) = (
png_byte)((blue >> 8) & 0xff);