~cosme/ubuntu/precise/freeimage/freeimage-3.15.1

« back to all changes in this revision

Viewing changes to Source/LibPNG/pngwrite.c

  • Committer: Bazaar Package Importer
  • Author(s): Cosme Domínguez Díaz
  • Date: 2010-07-20 13:42:15 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20100720134215-xt1454zaedv3b604
Tags: 3.13.1-0ubuntu1
* New upstream release. Closes: (LP: #607800)
 - Updated debian/freeimage-get-orig-source script.
 - Removing no longer necessary debian/patches/* and
   the patch system in debian/rules.
 - Updated debian/rules to work with the new Makefiles.
 - Drop from -O3 to -O2 and use lzma compression saves
   ~10 MB of free space. 
* lintian stuff
 - fixed debhelper-but-no-misc-depends
 - fixed ldconfig-symlink-missing-for-shlib

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
 
2
2
/* pngwrite.c - general routines to write a PNG file
3
3
 *
4
 
 * Last changed in libpng 1.2.15 January 5, 2007
5
 
 * For conditions of distribution and use, see copyright notice in png.h
6
 
 * Copyright (c) 1998-2007 Glenn Randers-Pehrson
 
4
 * Last changed in libpng 1.2.41 [December 3, 2009]
 
5
 * Copyright (c) 1998-2009 Glenn Randers-Pehrson
7
6
 * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
8
7
 * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
 
8
 *
 
9
 * This code is released under the libpng license.
 
10
 * For conditions of distribution and use, see the disclaimer
 
11
 * and license in png.h
9
12
 */
10
13
 
11
 
/* get internal access to png.h */
 
14
/* Get internal access to png.h */
12
15
#define PNG_INTERNAL
 
16
#define PNG_NO_PEDANTIC_WARNINGS
13
17
#include "png.h"
14
18
#ifdef PNG_WRITE_SUPPORTED
15
19
 
25
29
void PNGAPI
26
30
png_write_info_before_PLTE(png_structp png_ptr, png_infop info_ptr)
27
31
{
28
 
   png_debug(1, "in png_write_info_before_PLTE\n");
 
32
   png_debug(1, "in png_write_info_before_PLTE");
 
33
 
29
34
   if (png_ptr == NULL || info_ptr == NULL)
30
35
      return;
31
36
   if (!(png_ptr->mode & PNG_WROTE_INFO_BEFORE_PLTE))
32
37
   {
33
 
   png_write_sig(png_ptr); /* write PNG signature */
34
 
#if defined(PNG_MNG_FEATURES_SUPPORTED)
35
 
   if((png_ptr->mode&PNG_HAVE_PNG_SIGNATURE)&&(png_ptr->mng_features_permitted))
 
38
   /* Write PNG signature */
 
39
   png_write_sig(png_ptr);
 
40
#ifdef PNG_MNG_FEATURES_SUPPORTED
 
41
   if ((png_ptr->mode&PNG_HAVE_PNG_SIGNATURE)&&(png_ptr->mng_features_permitted))
36
42
   {
37
 
      png_warning(png_ptr,"MNG features are not allowed in a PNG datastream");
38
 
      png_ptr->mng_features_permitted=0;
 
43
      png_warning(png_ptr, "MNG features are not allowed in a PNG datastream");
 
44
      png_ptr->mng_features_permitted = 0;
39
45
   }
40
46
#endif
41
 
   /* write IHDR information. */
 
47
   /* Write IHDR information. */
42
48
   png_write_IHDR(png_ptr, info_ptr->width, info_ptr->height,
43
49
      info_ptr->bit_depth, info_ptr->color_type, info_ptr->compression_type,
44
50
      info_ptr->filter_type,
45
 
#if defined(PNG_WRITE_INTERLACING_SUPPORTED)
 
51
#ifdef PNG_WRITE_INTERLACING_SUPPORTED
46
52
      info_ptr->interlace_type);
47
53
#else
48
54
      0);
49
55
#endif
50
 
   /* the rest of these check to see if the valid field has the appropriate
51
 
      flag set, and if it does, writes the chunk. */
52
 
#if defined(PNG_WRITE_gAMA_SUPPORTED)
 
56
   /* The rest of these check to see if the valid field has the appropriate
 
57
    * flag set, and if it does, writes the chunk.
 
58
    */
 
59
#ifdef PNG_WRITE_gAMA_SUPPORTED
53
60
   if (info_ptr->valid & PNG_INFO_gAMA)
54
61
   {
55
62
#  ifdef PNG_FLOATING_POINT_SUPPORTED
61
68
#endif
62
69
   }
63
70
#endif
64
 
#if defined(PNG_WRITE_sRGB_SUPPORTED)
 
71
#ifdef PNG_WRITE_sRGB_SUPPORTED
65
72
   if (info_ptr->valid & PNG_INFO_sRGB)
66
73
      png_write_sRGB(png_ptr, (int)info_ptr->srgb_intent);
67
74
#endif
68
 
#if defined(PNG_WRITE_iCCP_SUPPORTED)
 
75
#ifdef PNG_WRITE_iCCP_SUPPORTED
69
76
   if (info_ptr->valid & PNG_INFO_iCCP)
70
77
      png_write_iCCP(png_ptr, info_ptr->iccp_name, PNG_COMPRESSION_TYPE_BASE,
71
78
                     info_ptr->iccp_profile, (int)info_ptr->iccp_proflen);
72
79
#endif
73
 
#if defined(PNG_WRITE_sBIT_SUPPORTED)
 
80
#ifdef PNG_WRITE_sBIT_SUPPORTED
74
81
   if (info_ptr->valid & PNG_INFO_sBIT)
75
82
      png_write_sBIT(png_ptr, &(info_ptr->sig_bit), info_ptr->color_type);
76
83
#endif
77
 
#if defined(PNG_WRITE_cHRM_SUPPORTED)
 
84
#ifdef PNG_WRITE_cHRM_SUPPORTED
78
85
   if (info_ptr->valid & PNG_INFO_cHRM)
79
86
   {
80
87
#ifdef PNG_FLOATING_POINT_SUPPORTED
94
101
#endif
95
102
   }
96
103
#endif
97
 
#if defined(PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED)
 
104
#ifdef PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED
98
105
   if (info_ptr->unknown_chunks_num)
99
106
   {
100
 
       png_unknown_chunk *up;
101
 
 
102
 
       png_debug(5, "writing extra chunks\n");
103
 
 
104
 
       for (up = info_ptr->unknown_chunks;
105
 
            up < info_ptr->unknown_chunks + info_ptr->unknown_chunks_num;
106
 
            up++)
107
 
       {
108
 
         int keep=png_handle_as_unknown(png_ptr, up->name);
 
107
      png_unknown_chunk *up;
 
108
 
 
109
      png_debug(5, "writing extra chunks");
 
110
 
 
111
      for (up = info_ptr->unknown_chunks;
 
112
           up < info_ptr->unknown_chunks + info_ptr->unknown_chunks_num;
 
113
           up++)
 
114
      {
 
115
         int keep = png_handle_as_unknown(png_ptr, up->name);
109
116
         if (keep != PNG_HANDLE_CHUNK_NEVER &&
110
117
            up->location && !(up->location & PNG_HAVE_PLTE) &&
111
118
            !(up->location & PNG_HAVE_IDAT) &&
112
119
            ((up->name[3] & 0x20) || keep == PNG_HANDLE_CHUNK_ALWAYS ||
113
120
            (png_ptr->flags & PNG_FLAG_KEEP_UNSAFE_CHUNKS)))
114
121
         {
 
122
            if (up->size == 0)
 
123
               png_warning(png_ptr, "Writing zero-length unknown chunk");
115
124
            png_write_chunk(png_ptr, up->name, up->data, up->size);
116
125
         }
117
 
       }
 
126
      }
118
127
   }
119
128
#endif
120
129
      png_ptr->mode |= PNG_WROTE_INFO_BEFORE_PLTE;
128
137
   int i;
129
138
#endif
130
139
 
131
 
   png_debug(1, "in png_write_info\n");
 
140
   png_debug(1, "in png_write_info");
132
141
 
133
142
   if (png_ptr == NULL || info_ptr == NULL)
134
143
      return;
141
150
   else if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
142
151
      png_error(png_ptr, "Valid palette required for paletted images");
143
152
 
144
 
#if defined(PNG_WRITE_tRNS_SUPPORTED)
 
153
#ifdef PNG_WRITE_tRNS_SUPPORTED
145
154
   if (info_ptr->valid & PNG_INFO_tRNS)
 
155
   {
 
156
#ifdef PNG_WRITE_INVERT_ALPHA_SUPPORTED
 
157
      /* Invert the alpha channel (in tRNS) */
 
158
      if ((png_ptr->transformations & PNG_INVERT_ALPHA) &&
 
159
         info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
146
160
      {
147
 
#if defined(PNG_WRITE_INVERT_ALPHA_SUPPORTED)
148
 
         /* invert the alpha channel (in tRNS) */
149
 
         if ((png_ptr->transformations & PNG_INVERT_ALPHA) &&
150
 
            info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
151
 
         {
152
 
            int j;
153
 
            for (j=0; j<(int)info_ptr->num_trans; j++)
154
 
               info_ptr->trans[j] = (png_byte)(255 - info_ptr->trans[j]);
155
 
         }
 
161
         int j;
 
162
         for (j = 0; j<(int)info_ptr->num_trans; j++)
 
163
            info_ptr->trans[j] = (png_byte)(255 - info_ptr->trans[j]);
 
164
      }
156
165
#endif
157
166
      png_write_tRNS(png_ptr, info_ptr->trans, &(info_ptr->trans_values),
158
167
         info_ptr->num_trans, info_ptr->color_type);
159
 
      }
 
168
   }
160
169
#endif
161
 
#if defined(PNG_WRITE_bKGD_SUPPORTED)
 
170
#ifdef PNG_WRITE_bKGD_SUPPORTED
162
171
   if (info_ptr->valid & PNG_INFO_bKGD)
163
172
      png_write_bKGD(png_ptr, &(info_ptr->background), info_ptr->color_type);
164
173
#endif
165
 
#if defined(PNG_WRITE_hIST_SUPPORTED)
 
174
#ifdef PNG_WRITE_hIST_SUPPORTED
166
175
   if (info_ptr->valid & PNG_INFO_hIST)
167
176
      png_write_hIST(png_ptr, info_ptr->hist, info_ptr->num_palette);
168
177
#endif
169
 
#if defined(PNG_WRITE_oFFs_SUPPORTED)
 
178
#ifdef PNG_WRITE_oFFs_SUPPORTED
170
179
   if (info_ptr->valid & PNG_INFO_oFFs)
171
180
      png_write_oFFs(png_ptr, info_ptr->x_offset, info_ptr->y_offset,
172
181
         info_ptr->offset_unit_type);
173
182
#endif
174
 
#if defined(PNG_WRITE_pCAL_SUPPORTED)
 
183
#ifdef PNG_WRITE_pCAL_SUPPORTED
175
184
   if (info_ptr->valid & PNG_INFO_pCAL)
176
185
      png_write_pCAL(png_ptr, info_ptr->pcal_purpose, info_ptr->pcal_X0,
177
186
         info_ptr->pcal_X1, info_ptr->pcal_type, info_ptr->pcal_nparams,
178
187
         info_ptr->pcal_units, info_ptr->pcal_params);
179
188
#endif
180
 
#if defined(PNG_WRITE_sCAL_SUPPORTED)
 
189
 
 
190
#ifdef PNG_sCAL_SUPPORTED
181
191
   if (info_ptr->valid & PNG_INFO_sCAL)
182
 
#if defined(PNG_FLOATING_POINT_SUPPORTED) && !defined(PNG_NO_STDIO)
 
192
#ifdef PNG_WRITE_sCAL_SUPPORTED
 
193
#if defined(PNG_FLOATING_POINT_SUPPORTED) && defined(PNG_STDIO_SUPPORTED)
183
194
      png_write_sCAL(png_ptr, (int)info_ptr->scal_unit,
184
195
          info_ptr->scal_pixel_width, info_ptr->scal_pixel_height);
185
 
#else
 
196
#else /* !FLOATING_POINT */
186
197
#ifdef PNG_FIXED_POINT_SUPPORTED
187
198
      png_write_sCAL_s(png_ptr, (int)info_ptr->scal_unit,
188
199
          info_ptr->scal_s_width, info_ptr->scal_s_height);
189
 
#else
 
200
#endif /* FIXED_POINT */
 
201
#endif /* FLOATING_POINT */
 
202
#else  /* !WRITE_sCAL */
190
203
      png_warning(png_ptr,
191
204
          "png_write_sCAL not supported; sCAL chunk not written.");
192
 
#endif
193
 
#endif
194
 
#endif
195
 
#if defined(PNG_WRITE_pHYs_SUPPORTED)
 
205
#endif /* WRITE_sCAL */
 
206
#endif /* sCAL */
 
207
 
 
208
#ifdef PNG_WRITE_pHYs_SUPPORTED
196
209
   if (info_ptr->valid & PNG_INFO_pHYs)
197
210
      png_write_pHYs(png_ptr, info_ptr->x_pixels_per_unit,
198
211
         info_ptr->y_pixels_per_unit, info_ptr->phys_unit_type);
199
 
#endif
200
 
#if defined(PNG_WRITE_tIME_SUPPORTED)
 
212
#endif /* pHYs */
 
213
 
 
214
#ifdef PNG_WRITE_tIME_SUPPORTED
201
215
   if (info_ptr->valid & PNG_INFO_tIME)
202
216
   {
203
217
      png_write_tIME(png_ptr, &(info_ptr->mod_time));
204
218
      png_ptr->mode |= PNG_WROTE_tIME;
205
219
   }
206
 
#endif
207
 
#if defined(PNG_WRITE_sPLT_SUPPORTED)
 
220
#endif /* tIME */
 
221
 
 
222
#ifdef PNG_WRITE_sPLT_SUPPORTED
208
223
   if (info_ptr->valid & PNG_INFO_sPLT)
209
224
     for (i = 0; i < (int)info_ptr->splt_palettes_num; i++)
210
225
       png_write_sPLT(png_ptr, info_ptr->splt_palettes + i);
211
 
#endif
212
 
#if defined(PNG_WRITE_TEXT_SUPPORTED)
 
226
#endif /* sPLT */
 
227
 
 
228
#ifdef PNG_WRITE_TEXT_SUPPORTED
213
229
   /* Check to see if we need to write text chunks */
214
230
   for (i = 0; i < info_ptr->num_text; i++)
215
231
   {
216
 
      png_debug2(2, "Writing header text chunk %d, type %d\n", i,
 
232
      png_debug2(2, "Writing header text chunk %d, type %d", i,
217
233
         info_ptr->text[i].compression);
218
 
      /* an internationalized chunk? */
 
234
      /* An internationalized chunk? */
219
235
      if (info_ptr->text[i].compression > 0)
220
236
      {
221
 
#if defined(PNG_WRITE_iTXt_SUPPORTED)
222
 
          /* write international chunk */
 
237
#ifdef PNG_WRITE_iTXt_SUPPORTED
 
238
          /* Write international chunk */
223
239
          png_write_iTXt(png_ptr,
224
240
                         info_ptr->text[i].compression,
225
241
                         info_ptr->text[i].key,
235
251
      /* If we want a compressed text chunk */
236
252
      else if (info_ptr->text[i].compression == PNG_TEXT_COMPRESSION_zTXt)
237
253
      {
238
 
#if defined(PNG_WRITE_zTXt_SUPPORTED)
239
 
         /* write compressed chunk */
 
254
#ifdef PNG_WRITE_zTXt_SUPPORTED
 
255
         /* Write compressed chunk */
240
256
         png_write_zTXt(png_ptr, info_ptr->text[i].key,
241
257
            info_ptr->text[i].text, 0,
242
258
            info_ptr->text[i].compression);
248
264
      }
249
265
      else if (info_ptr->text[i].compression == PNG_TEXT_COMPRESSION_NONE)
250
266
      {
251
 
#if defined(PNG_WRITE_tEXt_SUPPORTED)
252
 
         /* write uncompressed chunk */
 
267
#ifdef PNG_WRITE_tEXt_SUPPORTED
 
268
         /* Write uncompressed chunk */
253
269
         png_write_tEXt(png_ptr, info_ptr->text[i].key,
254
270
                         info_ptr->text[i].text,
255
271
                         0);
 
272
         /* Mark this chunk as written */
 
273
         info_ptr->text[i].compression = PNG_TEXT_COMPRESSION_NONE_WR;
256
274
#else
 
275
         /* Can't get here */
257
276
         png_warning(png_ptr, "Unable to write uncompressed text");
258
277
#endif
259
 
         /* Mark this chunk as written */
260
 
         info_ptr->text[i].compression = PNG_TEXT_COMPRESSION_NONE_WR;
261
278
      }
262
279
   }
263
 
#endif
264
 
#if defined(PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED)
 
280
#endif /* tEXt */
 
281
 
 
282
#ifdef PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED
265
283
   if (info_ptr->unknown_chunks_num)
266
284
   {
267
 
       png_unknown_chunk *up;
268
 
 
269
 
       png_debug(5, "writing extra chunks\n");
270
 
 
271
 
       for (up = info_ptr->unknown_chunks;
272
 
            up < info_ptr->unknown_chunks + info_ptr->unknown_chunks_num;
273
 
            up++)
274
 
       {
275
 
         int keep=png_handle_as_unknown(png_ptr, up->name);
 
285
      png_unknown_chunk *up;
 
286
 
 
287
      png_debug(5, "writing extra chunks");
 
288
 
 
289
      for (up = info_ptr->unknown_chunks;
 
290
           up < info_ptr->unknown_chunks + info_ptr->unknown_chunks_num;
 
291
           up++)
 
292
      {
 
293
         int keep = png_handle_as_unknown(png_ptr, up->name);
276
294
         if (keep != PNG_HANDLE_CHUNK_NEVER &&
277
295
            up->location && (up->location & PNG_HAVE_PLTE) &&
278
296
            !(up->location & PNG_HAVE_IDAT) &&
281
299
         {
282
300
            png_write_chunk(png_ptr, up->name, up->data, up->size);
283
301
         }
284
 
       }
 
302
      }
285
303
   }
286
304
#endif
287
305
}
294
312
void PNGAPI
295
313
png_write_end(png_structp png_ptr, png_infop info_ptr)
296
314
{
297
 
   png_debug(1, "in png_write_end\n");
 
315
   png_debug(1, "in png_write_end");
 
316
 
298
317
   if (png_ptr == NULL)
299
318
      return;
300
319
   if (!(png_ptr->mode & PNG_HAVE_IDAT))
301
320
      png_error(png_ptr, "No IDATs written into file");
302
321
 
303
 
   /* see if user wants us to write information chunks */
 
322
   /* See if user wants us to write information chunks */
304
323
   if (info_ptr != NULL)
305
324
   {
306
 
#if defined(PNG_WRITE_TEXT_SUPPORTED)
 
325
#ifdef PNG_WRITE_TEXT_SUPPORTED
307
326
      int i; /* local index variable */
308
327
#endif
309
 
#if defined(PNG_WRITE_tIME_SUPPORTED)
310
 
      /* check to see if user has supplied a time chunk */
 
328
#ifdef PNG_WRITE_tIME_SUPPORTED
 
329
      /* Check to see if user has supplied a time chunk */
311
330
      if ((info_ptr->valid & PNG_INFO_tIME) &&
312
331
         !(png_ptr->mode & PNG_WROTE_tIME))
313
332
         png_write_tIME(png_ptr, &(info_ptr->mod_time));
314
333
#endif
315
 
#if defined(PNG_WRITE_TEXT_SUPPORTED)
316
 
      /* loop through comment chunks */
 
334
#ifdef PNG_WRITE_TEXT_SUPPORTED
 
335
      /* Loop through comment chunks */
317
336
      for (i = 0; i < info_ptr->num_text; i++)
318
337
      {
319
 
         png_debug2(2, "Writing trailer text chunk %d, type %d\n", i,
 
338
         png_debug2(2, "Writing trailer text chunk %d, type %d", i,
320
339
            info_ptr->text[i].compression);
321
 
         /* an internationalized chunk? */
 
340
         /* An internationalized chunk? */
322
341
         if (info_ptr->text[i].compression > 0)
323
342
         {
324
 
#if defined(PNG_WRITE_iTXt_SUPPORTED)
325
 
             /* write international chunk */
326
 
             png_write_iTXt(png_ptr,
327
 
                         info_ptr->text[i].compression,
328
 
                         info_ptr->text[i].key,
329
 
                         info_ptr->text[i].lang,
330
 
                         info_ptr->text[i].lang_key,
331
 
                         info_ptr->text[i].text);
 
343
#ifdef PNG_WRITE_iTXt_SUPPORTED
 
344
            /* Write international chunk */
 
345
            png_write_iTXt(png_ptr,
 
346
                        info_ptr->text[i].compression,
 
347
                        info_ptr->text[i].key,
 
348
                        info_ptr->text[i].lang,
 
349
                        info_ptr->text[i].lang_key,
 
350
                        info_ptr->text[i].text);
332
351
#else
333
 
             png_warning(png_ptr, "Unable to write international text");
 
352
            png_warning(png_ptr, "Unable to write international text");
334
353
#endif
335
 
             /* Mark this chunk as written */
336
 
             info_ptr->text[i].compression = PNG_TEXT_COMPRESSION_NONE_WR;
 
354
            /* Mark this chunk as written */
 
355
            info_ptr->text[i].compression = PNG_TEXT_COMPRESSION_NONE_WR;
337
356
         }
338
357
         else if (info_ptr->text[i].compression >= PNG_TEXT_COMPRESSION_zTXt)
339
358
         {
340
 
#if defined(PNG_WRITE_zTXt_SUPPORTED)
341
 
            /* write compressed chunk */
 
359
#ifdef PNG_WRITE_zTXt_SUPPORTED
 
360
            /* Write compressed chunk */
342
361
            png_write_zTXt(png_ptr, info_ptr->text[i].key,
343
362
               info_ptr->text[i].text, 0,
344
363
               info_ptr->text[i].compression);
350
369
         }
351
370
         else if (info_ptr->text[i].compression == PNG_TEXT_COMPRESSION_NONE)
352
371
         {
353
 
#if defined(PNG_WRITE_tEXt_SUPPORTED)
354
 
            /* write uncompressed chunk */
 
372
#ifdef PNG_WRITE_tEXt_SUPPORTED
 
373
            /* Write uncompressed chunk */
355
374
            png_write_tEXt(png_ptr, info_ptr->text[i].key,
356
375
               info_ptr->text[i].text, 0);
357
376
#else
363
382
         }
364
383
      }
365
384
#endif
366
 
#if defined(PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED)
 
385
#ifdef PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED
367
386
   if (info_ptr->unknown_chunks_num)
368
387
   {
369
 
       png_unknown_chunk *up;
370
 
 
371
 
       png_debug(5, "writing extra chunks\n");
372
 
 
373
 
       for (up = info_ptr->unknown_chunks;
374
 
            up < info_ptr->unknown_chunks + info_ptr->unknown_chunks_num;
375
 
            up++)
376
 
       {
377
 
         int keep=png_handle_as_unknown(png_ptr, up->name);
 
388
      png_unknown_chunk *up;
 
389
 
 
390
      png_debug(5, "writing extra chunks");
 
391
 
 
392
      for (up = info_ptr->unknown_chunks;
 
393
           up < info_ptr->unknown_chunks + info_ptr->unknown_chunks_num;
 
394
           up++)
 
395
      {
 
396
         int keep = png_handle_as_unknown(png_ptr, up->name);
378
397
         if (keep != PNG_HANDLE_CHUNK_NEVER &&
379
398
            up->location && (up->location & PNG_AFTER_IDAT) &&
380
399
            ((up->name[3] & 0x20) || keep == PNG_HANDLE_CHUNK_ALWAYS ||
382
401
         {
383
402
            png_write_chunk(png_ptr, up->name, up->data, up->size);
384
403
         }
385
 
       }
 
404
      }
386
405
   }
387
406
#endif
388
407
   }
389
408
 
390
409
   png_ptr->mode |= PNG_AFTER_IDAT;
391
410
 
392
 
   /* write end of PNG file */
 
411
   /* Write end of PNG file */
393
412
   png_write_IEND(png_ptr);
 
413
   /* This flush, added in libpng-1.0.8, removed from libpng-1.0.9beta03,
 
414
    * and restored again in libpng-1.2.30, may cause some applications that
 
415
    * do not set png_ptr->output_flush_fn to crash.  If your application
 
416
    * experiences a problem, please try building libpng with
 
417
    * PNG_WRITE_FLUSH_AFTER_IEND_SUPPORTED defined, and report the event to
 
418
    * png-mng-implement at lists.sf.net .  This kludge will be removed
 
419
    * from libpng-1.4.0.
 
420
    */
 
421
#if defined(PNG_WRITE_FLUSH_SUPPORTED) && \
 
422
    defined(PNG_WRITE_FLUSH_AFTER_IEND_SUPPORTED)
 
423
   png_flush(png_ptr);
 
424
#endif
394
425
}
395
426
 
396
 
#if defined(PNG_WRITE_tIME_SUPPORTED)
397
 
#if !defined(_WIN32_WCE)
398
 
/* "time.h" functions are not supported on WindowsCE */
 
427
#ifdef PNG_CONVERT_tIME_SUPPORTED
 
428
/* "tm" structure is not supported on WindowsCE */
399
429
void PNGAPI
400
430
png_convert_from_struct_tm(png_timep ptime, struct tm FAR * ttime)
401
431
{
402
 
   png_debug(1, "in png_convert_from_struct_tm\n");
 
432
   png_debug(1, "in png_convert_from_struct_tm");
 
433
 
403
434
   ptime->year = (png_uint_16)(1900 + ttime->tm_year);
404
435
   ptime->month = (png_byte)(ttime->tm_mon + 1);
405
436
   ptime->day = (png_byte)ttime->tm_mday;
413
444
{
414
445
   struct tm *tbuf;
415
446
 
416
 
   png_debug(1, "in png_convert_from_time_t\n");
 
447
   png_debug(1, "in png_convert_from_time_t");
 
448
 
417
449
   tbuf = gmtime(&ttime);
418
450
   png_convert_from_struct_tm(ptime, tbuf);
419
451
}
420
452
#endif
421
 
#endif
422
453
 
423
454
/* Initialize png_ptr structure, and allocate any memory needed */
424
455
png_structp PNGAPI
437
468
   png_malloc_ptr malloc_fn, png_free_ptr free_fn)
438
469
{
439
470
#endif /* PNG_USER_MEM_SUPPORTED */
 
471
#ifdef PNG_SETJMP_SUPPORTED
 
472
   volatile
 
473
#endif
440
474
   png_structp png_ptr;
441
475
#ifdef PNG_SETJMP_SUPPORTED
442
476
#ifdef USE_FAR_KEYWORD
444
478
#endif
445
479
#endif
446
480
   int i;
447
 
   png_debug(1, "in png_create_write_struct\n");
 
481
 
 
482
   png_debug(1, "in png_create_write_struct");
 
483
 
448
484
#ifdef PNG_USER_MEM_SUPPORTED
449
485
   png_ptr = (png_structp)png_create_struct_2(PNG_STRUCT_PNG,
450
486
      (png_malloc_ptr)malloc_fn, (png_voidp)mem_ptr);
454
490
   if (png_ptr == NULL)
455
491
      return (NULL);
456
492
 
457
 
   /* added at libpng-1.2.6 */
 
493
   /* Added at libpng-1.2.6 */
458
494
#ifdef PNG_SET_USER_LIMITS_SUPPORTED
459
 
   png_ptr->user_width_max=PNG_USER_WIDTH_MAX;
460
 
   png_ptr->user_height_max=PNG_USER_HEIGHT_MAX;
 
495
   png_ptr->user_width_max = PNG_USER_WIDTH_MAX;
 
496
   png_ptr->user_height_max = PNG_USER_HEIGHT_MAX;
461
497
#endif
462
498
 
463
499
#ifdef PNG_SETJMP_SUPPORTED
468
504
#endif
469
505
   {
470
506
      png_free(png_ptr, png_ptr->zbuf);
471
 
      png_ptr->zbuf=NULL;
472
 
      png_destroy_struct(png_ptr);
 
507
      png_ptr->zbuf = NULL;
 
508
#ifdef PNG_USER_MEM_SUPPORTED
 
509
      png_destroy_struct_2((png_voidp)png_ptr,
 
510
         (png_free_ptr)free_fn, (png_voidp)mem_ptr);
 
511
#else
 
512
      png_destroy_struct((png_voidp)png_ptr);
 
513
#endif
473
514
      return (NULL);
474
515
   }
475
516
#ifdef USE_FAR_KEYWORD
476
 
   png_memcpy(png_ptr->jmpbuf,jmpbuf,png_sizeof(jmp_buf));
 
517
   png_memcpy(png_ptr->jmpbuf, jmpbuf, png_sizeof(jmp_buf));
477
518
#endif
478
519
#endif
479
520
 
482
523
#endif /* PNG_USER_MEM_SUPPORTED */
483
524
   png_set_error_fn(png_ptr, error_ptr, error_fn, warn_fn);
484
525
 
485
 
   i=0;
486
 
   do
 
526
   if (user_png_ver)
487
527
   {
488
 
     if(user_png_ver[i] != png_libpng_ver[i])
489
 
        png_ptr->flags |= PNG_FLAG_LIBRARY_MISMATCH;
490
 
   } while (png_libpng_ver[i++]);
 
528
      i = 0;
 
529
      do
 
530
      {
 
531
         if (user_png_ver[i] != png_libpng_ver[i])
 
532
            png_ptr->flags |= PNG_FLAG_LIBRARY_MISMATCH;
 
533
      } while (png_libpng_ver[i++]);
 
534
   }
491
535
 
492
536
   if (png_ptr->flags & PNG_FLAG_LIBRARY_MISMATCH)
493
537
   {
500
544
         (user_png_ver[0] == '1' && user_png_ver[2] != png_libpng_ver[2]) ||
501
545
         (user_png_ver[0] == '0' && user_png_ver[2] < '9'))
502
546
     {
503
 
#if !defined(PNG_NO_STDIO) && !defined(_WIN32_WCE)
 
547
#if defined(PNG_STDIO_SUPPORTED) && !defined(_WIN32_WCE)
504
548
        char msg[80];
505
549
        if (user_png_ver)
506
550
        {
507
 
          png_snprintf(msg, 80,
508
 
             "Application was compiled with png.h from libpng-%.20s",
509
 
             user_png_ver);
510
 
          png_warning(png_ptr, msg);
 
551
           png_snprintf(msg, 80,
 
552
              "Application was compiled with png.h from libpng-%.20s",
 
553
              user_png_ver);
 
554
           png_warning(png_ptr, msg);
511
555
        }
512
556
        png_snprintf(msg, 80,
513
557
           "Application  is  running with png.c from libpng-%.20s",
515
559
        png_warning(png_ptr, msg);
516
560
#endif
517
561
#ifdef PNG_ERROR_NUMBERS_SUPPORTED
518
 
        png_ptr->flags=0;
 
562
        png_ptr->flags = 0;
519
563
#endif
520
564
        png_error(png_ptr,
521
565
           "Incompatible libpng version in application and library");
522
566
     }
523
567
   }
524
568
 
525
 
   /* initialize zbuf - compression buffer */
 
569
   /* Initialize zbuf - compression buffer */
526
570
   png_ptr->zbuf_size = PNG_ZBUF_SIZE;
527
571
   png_ptr->zbuf = (png_bytep)png_malloc(png_ptr,
528
 
      (png_uint_32)png_ptr->zbuf_size);
 
572
     (png_uint_32)png_ptr->zbuf_size);
529
573
 
530
574
   png_set_write_fn(png_ptr, png_voidp_NULL, png_rw_ptr_NULL,
531
575
      png_flush_ptr_NULL);
532
576
 
533
 
#if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
 
577
#ifdef PNG_WRITE_WEIGHTED_FILTER_SUPPORTED
534
578
   png_set_filter_heuristics(png_ptr, PNG_FILTER_HEURISTIC_DEFAULT,
535
579
      1, png_doublep_NULL, png_doublep_NULL);
536
580
#endif
537
581
 
538
582
#ifdef PNG_SETJMP_SUPPORTED
539
 
/* Applications that neglect to set up their own setjmp() and then encounter
540
 
   a png_error() will longjmp here.  Since the jmpbuf is then meaningless we
541
 
   abort instead of returning. */
 
583
   /* Applications that neglect to set up their own setjmp() and then
 
584
    * encounter a png_error() will longjmp here.  Since the jmpbuf is
 
585
    * then meaningless we abort instead of returning.
 
586
    */
542
587
#ifdef USE_FAR_KEYWORD
543
588
   if (setjmp(jmpbuf))
544
589
      PNG_ABORT();
545
 
   png_memcpy(png_ptr->jmpbuf,jmpbuf,png_sizeof(jmp_buf));
 
590
   png_memcpy(png_ptr->jmpbuf, jmpbuf, png_sizeof(jmp_buf));
546
591
#else
547
592
   if (setjmp(png_ptr->jmpbuf))
548
593
      PNG_ABORT();
567
612
   png_size_t png_struct_size, png_size_t png_info_size)
568
613
{
569
614
   /* We only come here via pre-1.0.12-compiled applications */
570
 
   if(png_ptr == NULL) return;
571
 
#if !defined(PNG_NO_STDIO) && !defined(_WIN32_WCE)
572
 
   if(png_sizeof(png_struct) > png_struct_size ||
 
615
   if (png_ptr == NULL) return;
 
616
#if defined(PNG_STDIO_SUPPORTED) && !defined(_WIN32_WCE)
 
617
   if (png_sizeof(png_struct) > png_struct_size ||
573
618
      png_sizeof(png_info) > png_info_size)
574
619
   {
575
620
      char msg[80];
576
 
      png_ptr->warning_fn=NULL;
 
621
      png_ptr->warning_fn = NULL;
577
622
      if (user_png_ver)
578
623
      {
579
 
        png_snprintf(msg, 80,
580
 
           "Application was compiled with png.h from libpng-%.20s",
581
 
           user_png_ver);
582
 
        png_warning(png_ptr, msg);
 
624
         png_snprintf(msg, 80,
 
625
            "Application was compiled with png.h from libpng-%.20s",
 
626
            user_png_ver);
 
627
         png_warning(png_ptr, msg);
583
628
      }
584
629
      png_snprintf(msg, 80,
585
630
         "Application  is  running with png.c from libpng-%.20s",
587
632
      png_warning(png_ptr, msg);
588
633
   }
589
634
#endif
590
 
   if(png_sizeof(png_struct) > png_struct_size)
591
 
     {
592
 
       png_ptr->error_fn=NULL;
593
 
#ifdef PNG_ERROR_NUMBERS_SUPPORTED
594
 
       png_ptr->flags=0;
595
 
#endif
596
 
       png_error(png_ptr,
597
 
       "The png struct allocated by the application for writing is too small.");
598
 
     }
599
 
   if(png_sizeof(png_info) > png_info_size)
600
 
     {
601
 
       png_ptr->error_fn=NULL;
602
 
#ifdef PNG_ERROR_NUMBERS_SUPPORTED
603
 
       png_ptr->flags=0;
604
 
#endif
605
 
       png_error(png_ptr,
606
 
       "The info struct allocated by the application for writing is too small.");
607
 
     }
 
635
   if (png_sizeof(png_struct) > png_struct_size)
 
636
   {
 
637
      png_ptr->error_fn = NULL;
 
638
#ifdef PNG_ERROR_NUMBERS_SUPPORTED
 
639
      png_ptr->flags = 0;
 
640
#endif
 
641
      png_error(png_ptr,
 
642
      "The png struct allocated by the application for writing is too small.");
 
643
   }
 
644
   if (png_sizeof(png_info) > png_info_size)
 
645
   {
 
646
      png_ptr->error_fn = NULL;
 
647
#ifdef PNG_ERROR_NUMBERS_SUPPORTED
 
648
      png_ptr->flags = 0;
 
649
#endif
 
650
      png_error(png_ptr,
 
651
      "The info struct allocated by the application for writing is too small.");
 
652
   }
608
653
   png_write_init_3(&png_ptr, user_png_ver, png_struct_size);
609
654
}
610
655
#endif /* PNG_1_0_X || PNG_1_2_X */
614
659
png_write_init_3(png_structpp ptr_ptr, png_const_charp user_png_ver,
615
660
   png_size_t png_struct_size)
616
661
{
617
 
   png_structp png_ptr=*ptr_ptr;
 
662
   png_structp png_ptr = *ptr_ptr;
618
663
#ifdef PNG_SETJMP_SUPPORTED
619
664
   jmp_buf tmp_jmp; /* to save current jump buffer */
620
665
#endif
626
671
 
627
672
   do
628
673
   {
629
 
     if (user_png_ver[i] != png_libpng_ver[i])
630
 
     {
 
674
      if (user_png_ver[i] != png_libpng_ver[i])
 
675
      {
631
676
#ifdef PNG_LEGACY_SUPPORTED
632
 
       png_ptr->flags |= PNG_FLAG_LIBRARY_MISMATCH;
 
677
         png_ptr->flags |= PNG_FLAG_LIBRARY_MISMATCH;
633
678
#else
634
 
       png_ptr->warning_fn=NULL;
635
 
       png_warning(png_ptr,
636
 
     "Application uses deprecated png_write_init() and should be recompiled.");
637
 
       break;
 
679
         png_ptr->warning_fn = NULL;
 
680
         png_warning(png_ptr,
 
681
 "Application uses deprecated png_write_init() and should be recompiled.");
638
682
#endif
639
 
     }
 
683
      }
640
684
   } while (png_libpng_ver[i++]);
641
685
 
642
 
   png_debug(1, "in png_write_init_3\n");
 
686
   png_debug(1, "in png_write_init_3");
643
687
 
644
688
#ifdef PNG_SETJMP_SUPPORTED
645
 
   /* save jump buffer and error functions */
646
 
   png_memcpy(tmp_jmp, png_ptr->jmpbuf, png_sizeof (jmp_buf));
 
689
   /* Save jump buffer and error functions */
 
690
   png_memcpy(tmp_jmp, png_ptr->jmpbuf, png_sizeof(jmp_buf));
647
691
#endif
648
692
 
649
693
   if (png_sizeof(png_struct) > png_struct_size)
650
 
     {
651
 
       png_destroy_struct(png_ptr);
652
 
       png_ptr = (png_structp)png_create_struct(PNG_STRUCT_PNG);
653
 
       *ptr_ptr = png_ptr;
654
 
     }
655
 
 
656
 
   /* reset all variables to 0 */
657
 
   png_memset(png_ptr, 0, png_sizeof (png_struct));
658
 
 
659
 
   /* added at libpng-1.2.6 */
 
694
   {
 
695
      png_destroy_struct(png_ptr);
 
696
      png_ptr = (png_structp)png_create_struct(PNG_STRUCT_PNG);
 
697
      *ptr_ptr = png_ptr;
 
698
   }
 
699
 
 
700
   /* Reset all variables to 0 */
 
701
   png_memset(png_ptr, 0, png_sizeof(png_struct));
 
702
 
 
703
   /* Added at libpng-1.2.6 */
660
704
#ifdef PNG_SET_USER_LIMITS_SUPPORTED
661
 
   png_ptr->user_width_max=PNG_USER_WIDTH_MAX;
662
 
   png_ptr->user_height_max=PNG_USER_HEIGHT_MAX;
 
705
   png_ptr->user_width_max = PNG_USER_WIDTH_MAX;
 
706
   png_ptr->user_height_max = PNG_USER_HEIGHT_MAX;
663
707
#endif
664
708
 
665
709
#ifdef PNG_SETJMP_SUPPORTED
666
 
   /* restore jump buffer */
667
 
   png_memcpy(png_ptr->jmpbuf, tmp_jmp, png_sizeof (jmp_buf));
 
710
   /* Restore jump buffer */
 
711
   png_memcpy(png_ptr->jmpbuf, tmp_jmp, png_sizeof(jmp_buf));
668
712
#endif
669
713
 
670
714
   png_set_write_fn(png_ptr, png_voidp_NULL, png_rw_ptr_NULL,
671
715
      png_flush_ptr_NULL);
672
716
 
673
 
   /* initialize zbuf - compression buffer */
 
717
   /* Initialize zbuf - compression buffer */
674
718
   png_ptr->zbuf_size = PNG_ZBUF_SIZE;
675
719
   png_ptr->zbuf = (png_bytep)png_malloc(png_ptr,
676
 
      (png_uint_32)png_ptr->zbuf_size);
677
 
 
678
 
#if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
 
720
     (png_uint_32)png_ptr->zbuf_size);
 
721
#ifdef PNG_WRITE_WEIGHTED_FILTER_SUPPORTED
679
722
   png_set_filter_heuristics(png_ptr, PNG_FILTER_HEURISTIC_DEFAULT,
680
723
      1, png_doublep_NULL, png_doublep_NULL);
681
724
#endif
693
736
   png_uint_32 i; /* row counter */
694
737
   png_bytepp rp; /* row pointer */
695
738
 
696
 
   png_debug(1, "in png_write_rows\n");
 
739
   png_debug(1, "in png_write_rows");
697
740
 
698
741
   if (png_ptr == NULL)
699
742
      return;
700
743
 
701
 
   /* loop through the rows */
 
744
   /* Loop through the rows */
702
745
   for (i = 0, rp = row; i < num_rows; i++, rp++)
703
746
   {
704
747
      png_write_row(png_ptr, *rp);
718
761
   if (png_ptr == NULL)
719
762
      return;
720
763
 
721
 
   png_debug(1, "in png_write_image\n");
722
 
#if defined(PNG_WRITE_INTERLACING_SUPPORTED)
723
 
   /* intialize interlace handling.  If image is not interlaced,
724
 
      this will set pass to 1 */
 
764
   png_debug(1, "in png_write_image");
 
765
 
 
766
#ifdef PNG_WRITE_INTERLACING_SUPPORTED
 
767
   /* Initialize interlace handling.  If image is not interlaced,
 
768
    * this will set pass to 1
 
769
    */
725
770
   num_pass = png_set_interlace_handling(png_ptr);
726
771
#else
727
772
   num_pass = 1;
728
773
#endif
729
 
   /* loop through passes */
 
774
   /* Loop through passes */
730
775
   for (pass = 0; pass < num_pass; pass++)
731
776
   {
732
 
      /* loop through image */
 
777
      /* Loop through image */
733
778
      for (i = 0, rp = image; i < png_ptr->height; i++, rp++)
734
779
      {
735
780
         png_write_row(png_ptr, *rp);
737
782
   }
738
783
}
739
784
 
740
 
/* called by user to write a row of image data */
 
785
/* Called by user to write a row of image data */
741
786
void PNGAPI
742
787
png_write_row(png_structp png_ptr, png_bytep row)
743
788
{
744
789
   if (png_ptr == NULL)
745
790
      return;
746
 
   png_debug2(1, "in png_write_row (row %ld, pass %d)\n",
 
791
 
 
792
   png_debug2(1, "in png_write_row (row %ld, pass %d)",
747
793
      png_ptr->row_number, png_ptr->pass);
748
794
 
749
 
   /* initialize transformations and other stuff if first time */
 
795
   /* Initialize transformations and other stuff if first time */
750
796
   if (png_ptr->row_number == 0 && png_ptr->pass == 0)
751
797
   {
752
 
   /* make sure we wrote the header info */
753
 
   if (!(png_ptr->mode & PNG_WROTE_INFO_BEFORE_PLTE))
754
 
      png_error(png_ptr,
755
 
         "png_write_info was never called before png_write_row.");
 
798
      /* Make sure we wrote the header info */
 
799
      if (!(png_ptr->mode & PNG_WROTE_INFO_BEFORE_PLTE))
 
800
         png_error(png_ptr,
 
801
            "png_write_info was never called before png_write_row.");
756
802
 
757
 
   /* check for transforms that have been set but were defined out */
 
803
      /* Check for transforms that have been set but were defined out */
758
804
#if !defined(PNG_WRITE_INVERT_SUPPORTED) && defined(PNG_READ_INVERT_SUPPORTED)
759
 
   if (png_ptr->transformations & PNG_INVERT_MONO)
760
 
      png_warning(png_ptr, "PNG_WRITE_INVERT_SUPPORTED is not defined.");
 
805
      if (png_ptr->transformations & PNG_INVERT_MONO)
 
806
         png_warning(png_ptr, "PNG_WRITE_INVERT_SUPPORTED is not defined.");
761
807
#endif
762
808
#if !defined(PNG_WRITE_FILLER_SUPPORTED) && defined(PNG_READ_FILLER_SUPPORTED)
763
 
   if (png_ptr->transformations & PNG_FILLER)
764
 
      png_warning(png_ptr, "PNG_WRITE_FILLER_SUPPORTED is not defined.");
 
809
      if (png_ptr->transformations & PNG_FILLER)
 
810
         png_warning(png_ptr, "PNG_WRITE_FILLER_SUPPORTED is not defined.");
765
811
#endif
766
812
#if !defined(PNG_WRITE_PACKSWAP_SUPPORTED) && defined(PNG_READ_PACKSWAP_SUPPORTED)
767
 
   if (png_ptr->transformations & PNG_PACKSWAP)
768
 
      png_warning(png_ptr, "PNG_WRITE_PACKSWAP_SUPPORTED is not defined.");
 
813
      if (png_ptr->transformations & PNG_PACKSWAP)
 
814
         png_warning(png_ptr, "PNG_WRITE_PACKSWAP_SUPPORTED is not defined.");
769
815
#endif
770
816
#if !defined(PNG_WRITE_PACK_SUPPORTED) && defined(PNG_READ_PACK_SUPPORTED)
771
 
   if (png_ptr->transformations & PNG_PACK)
772
 
      png_warning(png_ptr, "PNG_WRITE_PACK_SUPPORTED is not defined.");
 
817
      if (png_ptr->transformations & PNG_PACK)
 
818
         png_warning(png_ptr, "PNG_WRITE_PACK_SUPPORTED is not defined.");
773
819
#endif
774
820
#if !defined(PNG_WRITE_SHIFT_SUPPORTED) && defined(PNG_READ_SHIFT_SUPPORTED)
775
 
   if (png_ptr->transformations & PNG_SHIFT)
776
 
      png_warning(png_ptr, "PNG_WRITE_SHIFT_SUPPORTED is not defined.");
 
821
      if (png_ptr->transformations & PNG_SHIFT)
 
822
         png_warning(png_ptr, "PNG_WRITE_SHIFT_SUPPORTED is not defined.");
777
823
#endif
778
824
#if !defined(PNG_WRITE_BGR_SUPPORTED) && defined(PNG_READ_BGR_SUPPORTED)
779
 
   if (png_ptr->transformations & PNG_BGR)
780
 
      png_warning(png_ptr, "PNG_WRITE_BGR_SUPPORTED is not defined.");
 
825
      if (png_ptr->transformations & PNG_BGR)
 
826
         png_warning(png_ptr, "PNG_WRITE_BGR_SUPPORTED is not defined.");
781
827
#endif
782
828
#if !defined(PNG_WRITE_SWAP_SUPPORTED) && defined(PNG_READ_SWAP_SUPPORTED)
783
 
   if (png_ptr->transformations & PNG_SWAP_BYTES)
784
 
      png_warning(png_ptr, "PNG_WRITE_SWAP_SUPPORTED is not defined.");
 
829
      if (png_ptr->transformations & PNG_SWAP_BYTES)
 
830
         png_warning(png_ptr, "PNG_WRITE_SWAP_SUPPORTED is not defined.");
785
831
#endif
786
832
 
787
833
      png_write_start_row(png_ptr);
788
834
   }
789
835
 
790
 
#if defined(PNG_WRITE_INTERLACING_SUPPORTED)
791
 
   /* if interlaced and not interested in row, return */
 
836
#ifdef PNG_WRITE_INTERLACING_SUPPORTED
 
837
   /* If interlaced and not interested in row, return */
792
838
   if (png_ptr->interlaced && (png_ptr->transformations & PNG_INTERLACE))
793
839
   {
794
840
      switch (png_ptr->pass)
846
892
   }
847
893
#endif
848
894
 
849
 
   /* set up row info for transformations */
 
895
   /* Set up row info for transformations */
850
896
   png_ptr->row_info.color_type = png_ptr->color_type;
851
897
   png_ptr->row_info.width = png_ptr->usr_width;
852
898
   png_ptr->row_info.channels = png_ptr->usr_channels;
857
903
   png_ptr->row_info.rowbytes = PNG_ROWBYTES(png_ptr->row_info.pixel_depth,
858
904
      png_ptr->row_info.width);
859
905
 
860
 
   png_debug1(3, "row_info->color_type = %d\n", png_ptr->row_info.color_type);
861
 
   png_debug1(3, "row_info->width = %lu\n", png_ptr->row_info.width);
862
 
   png_debug1(3, "row_info->channels = %d\n", png_ptr->row_info.channels);
863
 
   png_debug1(3, "row_info->bit_depth = %d\n", png_ptr->row_info.bit_depth);
864
 
   png_debug1(3, "row_info->pixel_depth = %d\n", png_ptr->row_info.pixel_depth);
865
 
   png_debug1(3, "row_info->rowbytes = %lu\n", png_ptr->row_info.rowbytes);
 
906
   png_debug1(3, "row_info->color_type = %d", png_ptr->row_info.color_type);
 
907
   png_debug1(3, "row_info->width = %lu", png_ptr->row_info.width);
 
908
   png_debug1(3, "row_info->channels = %d", png_ptr->row_info.channels);
 
909
   png_debug1(3, "row_info->bit_depth = %d", png_ptr->row_info.bit_depth);
 
910
   png_debug1(3, "row_info->pixel_depth = %d", png_ptr->row_info.pixel_depth);
 
911
   png_debug1(3, "row_info->rowbytes = %lu", png_ptr->row_info.rowbytes);
866
912
 
867
913
   /* Copy user's row into buffer, leaving room for filter byte. */
868
914
   png_memcpy_check(png_ptr, png_ptr->row_buf + 1, row,
869
915
      png_ptr->row_info.rowbytes);
870
916
 
871
 
#if defined(PNG_WRITE_INTERLACING_SUPPORTED)
872
 
   /* handle interlacing */
 
917
#ifdef PNG_WRITE_INTERLACING_SUPPORTED
 
918
   /* Handle interlacing */
873
919
   if (png_ptr->interlaced && png_ptr->pass < 6 &&
874
920
      (png_ptr->transformations & PNG_INTERLACE))
875
921
   {
876
922
      png_do_write_interlace(&(png_ptr->row_info),
877
923
         png_ptr->row_buf + 1, png_ptr->pass);
878
 
      /* this should always get caught above, but still ... */
 
924
      /* This should always get caught above, but still ... */
879
925
      if (!(png_ptr->row_info.width))
880
926
      {
881
927
         png_write_finish_row(png_ptr);
884
930
   }
885
931
#endif
886
932
 
887
 
   /* handle other transformations */
 
933
   /* Handle other transformations */
888
934
   if (png_ptr->transformations)
889
935
      png_do_write_transformations(png_ptr);
890
936
 
891
 
#if defined(PNG_MNG_FEATURES_SUPPORTED)
 
937
#ifdef PNG_MNG_FEATURES_SUPPORTED
892
938
   /* Write filter_method 64 (intrapixel differencing) only if
893
939
    * 1. Libpng was compiled with PNG_MNG_FEATURES_SUPPORTED and
894
940
    * 2. Libpng did not write a PNG signature (this filter_method is only
898
944
    * 4. The filter_method is 64 and
899
945
    * 5. The color_type is RGB or RGBA
900
946
    */
901
 
   if((png_ptr->mng_features_permitted & PNG_FLAG_MNG_FILTER_64) &&
 
947
   if ((png_ptr->mng_features_permitted & PNG_FLAG_MNG_FILTER_64) &&
902
948
      (png_ptr->filter_type == PNG_INTRAPIXEL_DIFFERENCING))
903
949
   {
904
950
      /* Intrapixel differencing */
913
959
      (*(png_ptr->write_row_fn))(png_ptr, png_ptr->row_number, png_ptr->pass);
914
960
}
915
961
 
916
 
#if defined(PNG_WRITE_FLUSH_SUPPORTED)
 
962
#ifdef PNG_WRITE_FLUSH_SUPPORTED
917
963
/* Set the automatic flush interval or 0 to turn flushing off */
918
964
void PNGAPI
919
965
png_set_flush(png_structp png_ptr, int nrows)
920
966
{
921
 
   png_debug(1, "in png_set_flush\n");
 
967
   png_debug(1, "in png_set_flush");
 
968
 
922
969
   if (png_ptr == NULL)
923
970
      return;
924
971
   png_ptr->flush_dist = (nrows < 0 ? 0 : nrows);
925
972
}
926
973
 
927
 
/* flush the current output buffers now */
 
974
/* Flush the current output buffers now */
928
975
void PNGAPI
929
976
png_write_flush(png_structp png_ptr)
930
977
{
931
978
   int wrote_IDAT;
932
979
 
933
 
   png_debug(1, "in png_write_flush\n");
 
980
   png_debug(1, "in png_write_flush");
 
981
 
934
982
   if (png_ptr == NULL)
935
983
      return;
936
984
   /* We have already written out all of the data */
937
985
   if (png_ptr->row_number >= png_ptr->num_rows)
938
 
     return;
 
986
      return;
939
987
 
940
988
   do
941
989
   {
942
990
      int ret;
943
991
 
944
 
      /* compress the data */
 
992
      /* Compress the data */
945
993
      ret = deflate(&png_ptr->zstream, Z_SYNC_FLUSH);
946
994
      wrote_IDAT = 0;
947
995
 
948
 
      /* check for compression errors */
 
996
      /* Check for compression errors */
949
997
      if (ret != Z_OK)
950
998
      {
951
999
         if (png_ptr->zstream.msg != NULL)
956
1004
 
957
1005
      if (!(png_ptr->zstream.avail_out))
958
1006
      {
959
 
         /* write the IDAT and reset the zlib output buffer */
 
1007
         /* Write the IDAT and reset the zlib output buffer */
960
1008
         png_write_IDAT(png_ptr, png_ptr->zbuf,
961
1009
                        png_ptr->zbuf_size);
962
1010
         png_ptr->zstream.next_out = png_ptr->zbuf;
968
1016
   /* If there is any data left to be output, write it into a new IDAT */
969
1017
   if (png_ptr->zbuf_size != png_ptr->zstream.avail_out)
970
1018
   {
971
 
      /* write the IDAT and reset the zlib output buffer */
 
1019
      /* Write the IDAT and reset the zlib output buffer */
972
1020
      png_write_IDAT(png_ptr, png_ptr->zbuf,
973
1021
                     png_ptr->zbuf_size - png_ptr->zstream.avail_out);
974
1022
      png_ptr->zstream.next_out = png_ptr->zbuf;
979
1027
}
980
1028
#endif /* PNG_WRITE_FLUSH_SUPPORTED */
981
1029
 
982
 
/* free all memory used by the write */
 
1030
/* Free all memory used by the write */
983
1031
void PNGAPI
984
1032
png_destroy_write_struct(png_structpp png_ptr_ptr, png_infopp info_ptr_ptr)
985
1033
{
990
1038
   png_voidp mem_ptr = NULL;
991
1039
#endif
992
1040
 
993
 
   png_debug(1, "in png_destroy_write_struct\n");
 
1041
   png_debug(1, "in png_destroy_write_struct");
 
1042
 
994
1043
   if (png_ptr_ptr != NULL)
995
1044
   {
996
1045
      png_ptr = *png_ptr_ptr;
1000
1049
#endif
1001
1050
   }
1002
1051
 
 
1052
#ifdef PNG_USER_MEM_SUPPORTED
 
1053
   if (png_ptr != NULL)
 
1054
   {
 
1055
      free_fn = png_ptr->free_fn;
 
1056
      mem_ptr = png_ptr->mem_ptr;
 
1057
   }
 
1058
#endif
 
1059
 
1003
1060
   if (info_ptr_ptr != NULL)
1004
1061
      info_ptr = *info_ptr_ptr;
1005
1062
 
1006
1063
   if (info_ptr != NULL)
1007
1064
   {
1008
 
      png_free_data(png_ptr, info_ptr, PNG_FREE_ALL, -1);
1009
 
 
1010
 
#if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
1011
 
      if (png_ptr->num_chunk_list)
 
1065
      if (png_ptr != NULL)
1012
1066
      {
1013
 
         png_free(png_ptr, png_ptr->chunk_list);
1014
 
         png_ptr->chunk_list=NULL;
1015
 
         png_ptr->num_chunk_list=0;
 
1067
        png_free_data(png_ptr, info_ptr, PNG_FREE_ALL, -1);
 
1068
 
 
1069
#ifdef PNG_UNKNOWN_CHUNKS_SUPPORTED
 
1070
        if (png_ptr->num_chunk_list)
 
1071
        {
 
1072
           png_free(png_ptr, png_ptr->chunk_list);
 
1073
           png_ptr->chunk_list = NULL;
 
1074
           png_ptr->num_chunk_list = 0;
 
1075
        }
 
1076
#endif
1016
1077
      }
1017
 
#endif
1018
1078
 
1019
1079
#ifdef PNG_USER_MEM_SUPPORTED
1020
1080
      png_destroy_struct_2((png_voidp)info_ptr, (png_free_ptr)free_fn,
1044
1104
png_write_destroy(png_structp png_ptr)
1045
1105
{
1046
1106
#ifdef PNG_SETJMP_SUPPORTED
1047
 
   jmp_buf tmp_jmp; /* save jump buffer */
 
1107
   jmp_buf tmp_jmp; /* Save jump buffer */
1048
1108
#endif
1049
1109
   png_error_ptr error_fn;
1050
1110
   png_error_ptr warning_fn;
1053
1113
   png_free_ptr free_fn;
1054
1114
#endif
1055
1115
 
1056
 
   png_debug(1, "in png_write_destroy\n");
1057
 
   /* free any memory zlib uses */
 
1116
   png_debug(1, "in png_write_destroy");
 
1117
 
 
1118
   /* Free any memory zlib uses */
1058
1119
   deflateEnd(&png_ptr->zstream);
1059
1120
 
1060
 
   /* free our memory.  png_free checks NULL for us. */
 
1121
   /* Free our memory.  png_free checks NULL for us. */
1061
1122
   png_free(png_ptr, png_ptr->zbuf);
1062
1123
   png_free(png_ptr, png_ptr->row_buf);
 
1124
#ifdef PNG_WRITE_FILTER_SUPPORTED
1063
1125
   png_free(png_ptr, png_ptr->prev_row);
1064
1126
   png_free(png_ptr, png_ptr->sub_row);
1065
1127
   png_free(png_ptr, png_ptr->up_row);
1066
1128
   png_free(png_ptr, png_ptr->avg_row);
1067
1129
   png_free(png_ptr, png_ptr->paeth_row);
 
1130
#endif
1068
1131
 
1069
 
#if defined(PNG_TIME_RFC1123_SUPPORTED)
 
1132
#ifdef PNG_TIME_RFC1123_SUPPORTED
1070
1133
   png_free(png_ptr, png_ptr->time_buffer);
1071
1134
#endif
1072
1135
 
1073
 
#if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
 
1136
#ifdef PNG_WRITE_WEIGHTED_FILTER_SUPPORTED
1074
1137
   png_free(png_ptr, png_ptr->prev_filters);
1075
1138
   png_free(png_ptr, png_ptr->filter_weights);
1076
1139
   png_free(png_ptr, png_ptr->inv_filter_weights);
1079
1142
#endif
1080
1143
 
1081
1144
#ifdef PNG_SETJMP_SUPPORTED
1082
 
   /* reset structure */
1083
 
   png_memcpy(tmp_jmp, png_ptr->jmpbuf, png_sizeof (jmp_buf));
 
1145
   /* Reset structure */
 
1146
   png_memcpy(tmp_jmp, png_ptr->jmpbuf, png_sizeof(jmp_buf));
1084
1147
#endif
1085
1148
 
1086
1149
   error_fn = png_ptr->error_fn;
1090
1153
   free_fn = png_ptr->free_fn;
1091
1154
#endif
1092
1155
 
1093
 
   png_memset(png_ptr, 0, png_sizeof (png_struct));
 
1156
   png_memset(png_ptr, 0, png_sizeof(png_struct));
1094
1157
 
1095
1158
   png_ptr->error_fn = error_fn;
1096
1159
   png_ptr->warning_fn = warning_fn;
1100
1163
#endif
1101
1164
 
1102
1165
#ifdef PNG_SETJMP_SUPPORTED
1103
 
   png_memcpy(png_ptr->jmpbuf, tmp_jmp, png_sizeof (jmp_buf));
 
1166
   png_memcpy(png_ptr->jmpbuf, tmp_jmp, png_sizeof(jmp_buf));
1104
1167
#endif
1105
1168
}
1106
1169
 
1108
1171
void PNGAPI
1109
1172
png_set_filter(png_structp png_ptr, int method, int filters)
1110
1173
{
1111
 
   png_debug(1, "in png_set_filter\n");
 
1174
   png_debug(1, "in png_set_filter");
 
1175
 
1112
1176
   if (png_ptr == NULL)
1113
1177
      return;
1114
 
#if defined(PNG_MNG_FEATURES_SUPPORTED)
1115
 
   if((png_ptr->mng_features_permitted & PNG_FLAG_MNG_FILTER_64) &&
 
1178
#ifdef PNG_MNG_FEATURES_SUPPORTED
 
1179
   if ((png_ptr->mng_features_permitted & PNG_FLAG_MNG_FILTER_64) &&
1116
1180
      (method == PNG_INTRAPIXEL_DIFFERENCING))
1117
1181
         method = PNG_FILTER_TYPE_BASE;
1118
1182
#endif
1120
1184
   {
1121
1185
      switch (filters & (PNG_ALL_FILTERS | 0x07))
1122
1186
      {
1123
 
#ifndef PNG_NO_WRITE_FILTER
 
1187
#ifdef PNG_WRITE_FILTER_SUPPORTED
1124
1188
         case 5:
1125
1189
         case 6:
1126
1190
         case 7: png_warning(png_ptr, "Unknown row filter for method 0");
1127
 
#endif /* PNG_NO_WRITE_FILTER */
 
1191
#endif /* PNG_WRITE_FILTER_SUPPORTED */
1128
1192
         case PNG_FILTER_VALUE_NONE:
1129
 
              png_ptr->do_filter=PNG_FILTER_NONE; break;
1130
 
#ifndef PNG_NO_WRITE_FILTER
 
1193
              png_ptr->do_filter = PNG_FILTER_NONE; break;
 
1194
#ifdef PNG_WRITE_FILTER_SUPPORTED
1131
1195
         case PNG_FILTER_VALUE_SUB:
1132
 
              png_ptr->do_filter=PNG_FILTER_SUB; break;
 
1196
              png_ptr->do_filter = PNG_FILTER_SUB; break;
1133
1197
         case PNG_FILTER_VALUE_UP:
1134
 
              png_ptr->do_filter=PNG_FILTER_UP; break;
 
1198
              png_ptr->do_filter = PNG_FILTER_UP; break;
1135
1199
         case PNG_FILTER_VALUE_AVG:
1136
 
              png_ptr->do_filter=PNG_FILTER_AVG; break;
 
1200
              png_ptr->do_filter = PNG_FILTER_AVG; break;
1137
1201
         case PNG_FILTER_VALUE_PAETH:
1138
 
              png_ptr->do_filter=PNG_FILTER_PAETH; break;
 
1202
              png_ptr->do_filter = PNG_FILTER_PAETH; break;
1139
1203
         default: png_ptr->do_filter = (png_byte)filters; break;
1140
1204
#else
1141
1205
         default: png_warning(png_ptr, "Unknown row filter for method 0");
1142
 
#endif /* PNG_NO_WRITE_FILTER */
 
1206
#endif /* PNG_WRITE_FILTER_SUPPORTED */
1143
1207
      }
1144
1208
 
1145
1209
      /* If we have allocated the row_buf, this means we have already started
1153
1217
       */
1154
1218
      if (png_ptr->row_buf != NULL)
1155
1219
      {
1156
 
#ifndef PNG_NO_WRITE_FILTER
 
1220
#ifdef PNG_WRITE_FILTER_SUPPORTED
1157
1221
         if ((png_ptr->do_filter & PNG_FILTER_SUB) && png_ptr->sub_row == NULL)
1158
1222
         {
1159
1223
            png_ptr->sub_row = (png_bytep)png_malloc(png_ptr,
1208
1272
         }
1209
1273
 
1210
1274
         if (png_ptr->do_filter == PNG_NO_FILTERS)
1211
 
#endif /* PNG_NO_WRITE_FILTER */
 
1275
#endif /* PNG_WRITE_FILTER_SUPPORTED */
1212
1276
            png_ptr->do_filter = PNG_FILTER_NONE;
1213
1277
      }
1214
1278
   }
1223
1287
 * filtered data going to zlib more consistent, hopefully resulting in
1224
1288
 * better compression.
1225
1289
 */
1226
 
#if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)      /* GRR 970116 */
 
1290
#ifdef PNG_WRITE_WEIGHTED_FILTER_SUPPORTED      /* GRR 970116 */
1227
1291
void PNGAPI
1228
1292
png_set_filter_heuristics(png_structp png_ptr, int heuristic_method,
1229
1293
   int num_weights, png_doublep filter_weights,
1231
1295
{
1232
1296
   int i;
1233
1297
 
1234
 
   png_debug(1, "in png_set_filter_heuristics\n");
 
1298
   png_debug(1, "in png_set_filter_heuristics");
 
1299
 
1235
1300
   if (png_ptr == NULL)
1236
1301
      return;
1237
1302
   if (heuristic_method >= PNG_FILTER_HEURISTIC_LAST)
1345
1410
void PNGAPI
1346
1411
png_set_compression_level(png_structp png_ptr, int level)
1347
1412
{
1348
 
   png_debug(1, "in png_set_compression_level\n");
 
1413
   png_debug(1, "in png_set_compression_level");
 
1414
 
1349
1415
   if (png_ptr == NULL)
1350
1416
      return;
1351
1417
   png_ptr->flags |= PNG_FLAG_ZLIB_CUSTOM_LEVEL;
1355
1421
void PNGAPI
1356
1422
png_set_compression_mem_level(png_structp png_ptr, int mem_level)
1357
1423
{
1358
 
   png_debug(1, "in png_set_compression_mem_level\n");
 
1424
   png_debug(1, "in png_set_compression_mem_level");
 
1425
 
1359
1426
   if (png_ptr == NULL)
1360
1427
      return;
1361
1428
   png_ptr->flags |= PNG_FLAG_ZLIB_CUSTOM_MEM_LEVEL;
1365
1432
void PNGAPI
1366
1433
png_set_compression_strategy(png_structp png_ptr, int strategy)
1367
1434
{
1368
 
   png_debug(1, "in png_set_compression_strategy\n");
 
1435
   png_debug(1, "in png_set_compression_strategy");
 
1436
 
1369
1437
   if (png_ptr == NULL)
1370
1438
      return;
1371
1439
   png_ptr->flags |= PNG_FLAG_ZLIB_CUSTOM_STRATEGY;
1382
1450
   else if (window_bits < 8)
1383
1451
      png_warning(png_ptr, "Only compression windows >= 256 supported by PNG");
1384
1452
#ifndef WBITS_8_OK
1385
 
   /* avoid libpng bug with 256-byte windows */
 
1453
   /* Avoid libpng bug with 256-byte windows */
1386
1454
   if (window_bits == 8)
1387
1455
     {
1388
1456
       png_warning(png_ptr, "Compression window is being reset to 512");
1389
 
       window_bits=9;
 
1457
       window_bits = 9;
1390
1458
     }
1391
1459
#endif
1392
1460
   png_ptr->flags |= PNG_FLAG_ZLIB_CUSTOM_WINDOW_BITS;
1396
1464
void PNGAPI
1397
1465
png_set_compression_method(png_structp png_ptr, int method)
1398
1466
{
1399
 
   png_debug(1, "in png_set_compression_method\n");
 
1467
   png_debug(1, "in png_set_compression_method");
 
1468
 
1400
1469
   if (png_ptr == NULL)
1401
1470
      return;
1402
1471
   if (method != 8)
1413
1482
   png_ptr->write_row_fn = write_row_fn;
1414
1483
}
1415
1484
 
1416
 
#if defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED)
 
1485
#ifdef PNG_WRITE_USER_TRANSFORM_SUPPORTED
1417
1486
void PNGAPI
1418
1487
png_set_write_user_transform_fn(png_structp png_ptr, png_user_transform_ptr
1419
1488
   write_user_transform_fn)
1420
1489
{
1421
 
   png_debug(1, "in png_set_write_user_transform_fn\n");
 
1490
   png_debug(1, "in png_set_write_user_transform_fn");
 
1491
 
1422
1492
   if (png_ptr == NULL)
1423
1493
      return;
1424
1494
   png_ptr->transformations |= PNG_USER_TRANSFORM;
1427
1497
#endif
1428
1498
 
1429
1499
 
1430
 
#if defined(PNG_INFO_IMAGE_SUPPORTED)
 
1500
#ifdef PNG_INFO_IMAGE_SUPPORTED
1431
1501
void PNGAPI
1432
1502
png_write_png(png_structp png_ptr, png_infop info_ptr,
1433
1503
              int transforms, voidp params)
1434
1504
{
1435
1505
   if (png_ptr == NULL || info_ptr == NULL)
1436
1506
      return;
1437
 
#if defined(PNG_WRITE_INVERT_ALPHA_SUPPORTED)
1438
 
   /* invert the alpha channel from opacity to transparency */
1439
 
   if (transforms & PNG_TRANSFORM_INVERT_ALPHA)
1440
 
       png_set_invert_alpha(png_ptr);
1441
 
#endif
1442
1507
 
1443
1508
   /* Write the file header information. */
1444
1509
   png_write_info(png_ptr, info_ptr);
1445
1510
 
1446
1511
   /* ------ these transformations don't touch the info structure ------- */
1447
1512
 
1448
 
#if defined(PNG_WRITE_INVERT_SUPPORTED)
1449
 
   /* invert monochrome pixels */
 
1513
#ifdef PNG_WRITE_INVERT_SUPPORTED
 
1514
   /* Invert monochrome pixels */
1450
1515
   if (transforms & PNG_TRANSFORM_INVERT_MONO)
1451
 
       png_set_invert_mono(png_ptr);
 
1516
      png_set_invert_mono(png_ptr);
1452
1517
#endif
1453
1518
 
1454
 
#if defined(PNG_WRITE_SHIFT_SUPPORTED)
 
1519
#ifdef PNG_WRITE_SHIFT_SUPPORTED
1455
1520
   /* Shift the pixels up to a legal bit depth and fill in
1456
1521
    * as appropriate to correctly scale the image.
1457
1522
    */
1458
1523
   if ((transforms & PNG_TRANSFORM_SHIFT)
1459
1524
               && (info_ptr->valid & PNG_INFO_sBIT))
1460
 
       png_set_shift(png_ptr, &info_ptr->sig_bit);
 
1525
      png_set_shift(png_ptr, &info_ptr->sig_bit);
1461
1526
#endif
1462
1527
 
1463
 
#if defined(PNG_WRITE_PACK_SUPPORTED)
1464
 
   /* pack pixels into bytes */
 
1528
#ifdef PNG_WRITE_PACK_SUPPORTED
 
1529
   /* Pack pixels into bytes */
1465
1530
   if (transforms & PNG_TRANSFORM_PACKING)
1466
1531
       png_set_packing(png_ptr);
1467
1532
#endif
1468
1533
 
1469
 
#if defined(PNG_WRITE_SWAP_ALPHA_SUPPORTED)
1470
 
   /* swap location of alpha bytes from ARGB to RGBA */
 
1534
#ifdef PNG_WRITE_SWAP_ALPHA_SUPPORTED
 
1535
   /* Swap location of alpha bytes from ARGB to RGBA */
1471
1536
   if (transforms & PNG_TRANSFORM_SWAP_ALPHA)
1472
 
       png_set_swap_alpha(png_ptr);
1473
 
#endif
1474
 
 
1475
 
#if defined(PNG_WRITE_FILLER_SUPPORTED)
1476
 
   /* Get rid of filler (OR ALPHA) bytes, pack XRGB/RGBX/ARGB/RGBA into
1477
 
    * RGB (4 channels -> 3 channels). The second parameter is not used.
1478
 
    */
1479
 
   if (transforms & PNG_TRANSFORM_STRIP_FILLER)
1480
 
       png_set_filler(png_ptr, 0, PNG_FILLER_BEFORE);
1481
 
#endif
1482
 
 
1483
 
#if defined(PNG_WRITE_BGR_SUPPORTED)
1484
 
   /* flip BGR pixels to RGB */
 
1537
      png_set_swap_alpha(png_ptr);
 
1538
#endif
 
1539
 
 
1540
#ifdef PNG_WRITE_FILLER_SUPPORTED
 
1541
   /* Pack XRGB/RGBX/ARGB/RGBA into * RGB (4 channels -> 3 channels) */
 
1542
   if (transforms & PNG_TRANSFORM_STRIP_FILLER_AFTER)
 
1543
      png_set_filler(png_ptr, 0, PNG_FILLER_AFTER);
 
1544
   else if (transforms & PNG_TRANSFORM_STRIP_FILLER_BEFORE)
 
1545
      png_set_filler(png_ptr, 0, PNG_FILLER_BEFORE);
 
1546
#endif
 
1547
 
 
1548
#ifdef PNG_WRITE_BGR_SUPPORTED
 
1549
   /* Flip BGR pixels to RGB */
1485
1550
   if (transforms & PNG_TRANSFORM_BGR)
1486
 
       png_set_bgr(png_ptr);
 
1551
      png_set_bgr(png_ptr);
1487
1552
#endif
1488
1553
 
1489
 
#if defined(PNG_WRITE_SWAP_SUPPORTED)
1490
 
   /* swap bytes of 16-bit files to most significant byte first */
 
1554
#ifdef PNG_WRITE_SWAP_SUPPORTED
 
1555
   /* Swap bytes of 16-bit files to most significant byte first */
1491
1556
   if (transforms & PNG_TRANSFORM_SWAP_ENDIAN)
1492
 
       png_set_swap(png_ptr);
 
1557
      png_set_swap(png_ptr);
1493
1558
#endif
1494
1559
 
1495
 
#if defined(PNG_WRITE_PACKSWAP_SUPPORTED)
1496
 
   /* swap bits of 1, 2, 4 bit packed pixel formats */
 
1560
#ifdef PNG_WRITE_PACKSWAP_SUPPORTED
 
1561
   /* Swap bits of 1, 2, 4 bit packed pixel formats */
1497
1562
   if (transforms & PNG_TRANSFORM_PACKSWAP)
1498
 
       png_set_packswap(png_ptr);
 
1563
      png_set_packswap(png_ptr);
 
1564
#endif
 
1565
 
 
1566
#ifdef PNG_WRITE_INVERT_ALPHA_SUPPORTED
 
1567
   /* Invert the alpha channel from opacity to transparency */
 
1568
   if (transforms & PNG_TRANSFORM_INVERT_ALPHA)
 
1569
      png_set_invert_alpha(png_ptr);
1499
1570
#endif
1500
1571
 
1501
1572
   /* ----------------------- end of transformations ------------------- */
1502
1573
 
1503
 
   /* write the bits */
 
1574
   /* Write the bits */
1504
1575
   if (info_ptr->valid & PNG_INFO_IDAT)
1505
1576
       png_write_image(png_ptr, info_ptr->row_pointers);
1506
1577
 
1507
1578
   /* It is REQUIRED to call this to finish writing the rest of the file */
1508
1579
   png_write_end(png_ptr, info_ptr);
1509
1580
 
1510
 
   transforms = transforms; /* quiet compiler warnings */
 
1581
   transforms = transforms; /* Quiet compiler warnings */
1511
1582
   params = params;
1512
1583
}
1513
1584
#endif