~ubuntu-branches/ubuntu/maverick/libpng/maverick-security

« back to all changes in this revision

Viewing changes to pngwutil.c

  • Committer: Bazaar Package Importer
  • Author(s): Anibal Monsalve Salazar
  • Date: 2009-12-04 11:23:50 UTC
  • mfrom: (1.1.10 upstream) (15.2.3 squeeze)
  • Revision ID: james.westby@ubuntu.com-20091204112350-ln22xyakgn9bh39k
Tags: 1.2.41-1
* New upstream release
* Debian source format is 3.0 (quilt)
* Update debian/watch
* Add 02-export-png_set_strip_error_numbers.patch
  Define PNG_ERROR_NUMBERS_SUPPORTED
  Upstream doesn't define PNG_ERROR_NUMBERS_SUPPORTED since 1.2.41. As
  a consecuence, the symbol png_set_strip_error_numbe@@PNG12_0 wasn't
  exported.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
 
2
2
/* pngwutil.c - utilities to write a PNG file
3
3
 *
4
 
 * Last changed in libpng 1.2.40 [September 10, 2009]
 
4
 * Last changed in libpng 1.2.41 [December 3, 2009]
5
5
 * Copyright (c) 1998-2009 Glenn Randers-Pehrson
6
6
 * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
7
7
 * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
12
12
 */
13
13
 
14
14
#define PNG_INTERNAL
 
15
#define PNG_NO_PEDANTIC_WARNINGS
15
16
#include "png.h"
16
17
#ifdef PNG_WRITE_SUPPORTED
17
18
 
58
59
 * we should call png_set_sig_bytes() to tell libpng how many of the
59
60
 * bytes have already been written.
60
61
 */
61
 
void /* PRIVATE */
 
62
void PNGAPI
62
63
png_write_sig(png_structp png_ptr)
63
64
{
64
65
   png_byte png_signature[8] = {137, 80, 78, 71, 13, 10, 26, 10};
106
107
   if (png_ptr == NULL)
107
108
      return;
108
109
 
 
110
 
109
111
   /* Write the length and the chunk name */
110
112
   png_save_uint_32(buf, length);
111
113
   png_memcpy(buf + 4, chunk_name, 4);
192
194
 
193
195
   if (compression >= PNG_TEXT_COMPRESSION_LAST)
194
196
   {
195
 
#if !defined(PNG_NO_STDIO) && !defined(_WIN32_WCE)
 
197
#if defined(PNG_STDIO_SUPPORTED) && !defined(_WIN32_WCE)
196
198
      char msg[50];
197
199
      png_snprintf(msg, 50, "Unknown compression type %d", compression);
198
200
      png_warning(png_ptr, msg);
459
461
    * 5. The color_type is RGB or RGBA
460
462
    */
461
463
   if (
462
 
#if defined(PNG_MNG_FEATURES_SUPPORTED)
 
464
#ifdef PNG_MNG_FEATURES_SUPPORTED
463
465
      !((png_ptr->mng_features_permitted & PNG_FLAG_MNG_FILTER_64) &&
464
466
      ((png_ptr->mode&PNG_HAVE_PNG_SIGNATURE) == 0) &&
465
467
      (color_type == PNG_COLOR_TYPE_RGB ||
487
489
   png_ptr->bit_depth = (png_byte)bit_depth;
488
490
   png_ptr->color_type = (png_byte)color_type;
489
491
   png_ptr->interlaced = (png_byte)interlace_type;
490
 
#if defined(PNG_MNG_FEATURES_SUPPORTED)
 
492
#ifdef PNG_MNG_FEATURES_SUPPORTED
491
493
   png_ptr->filter_type = (png_byte)filter_type;
492
494
#endif
493
495
   png_ptr->compression_type = (png_byte)compression_type;
579
581
   png_debug(1, "in png_write_PLTE");
580
582
 
581
583
   if ((
582
 
#if defined(PNG_MNG_FEATURES_SUPPORTED)
 
584
#ifdef PNG_MNG_FEATURES_SUPPORTED
583
585
        !(png_ptr->mng_features_permitted & PNG_FLAG_MNG_EMPTY_PLTE) &&
584
586
#endif
585
587
        num_pal == 0) || num_pal > 256)
607
609
 
608
610
   png_write_chunk_start(png_ptr, (png_bytep)png_PLTE,
609
611
     (png_uint_32)(num_pal * 3));
610
 
#ifndef PNG_NO_POINTER_INDEXING
 
612
#ifdef PNG_POINTER_INDEXING_SUPPORTED
611
613
   for (i = 0, pal_ptr = palette; i < num_pal; i++, pal_ptr++)
612
614
   {
613
615
      buf[0] = pal_ptr->red;
700
702
   png_ptr->mode |= PNG_HAVE_IEND;
701
703
}
702
704
 
703
 
#if defined(PNG_WRITE_gAMA_SUPPORTED)
 
705
#ifdef PNG_WRITE_gAMA_SUPPORTED
704
706
/* Write a gAMA chunk */
705
707
#ifdef PNG_FLOATING_POINT_SUPPORTED
706
708
void /* PRIVATE */
738
740
#endif
739
741
#endif
740
742
 
741
 
#if defined(PNG_WRITE_sRGB_SUPPORTED)
 
743
#ifdef PNG_WRITE_sRGB_SUPPORTED
742
744
/* Write a sRGB chunk */
743
745
void /* PRIVATE */
744
746
png_write_sRGB(png_structp png_ptr, int srgb_intent)
758
760
}
759
761
#endif
760
762
 
761
 
#if defined(PNG_WRITE_iCCP_SUPPORTED)
 
763
#ifdef PNG_WRITE_iCCP_SUPPORTED
762
764
/* Write an iCCP chunk */
763
765
void /* PRIVATE */
764
766
png_write_iCCP(png_structp png_ptr, png_charp name, int compression_type,
839
841
}
840
842
#endif
841
843
 
842
 
#if defined(PNG_WRITE_sPLT_SUPPORTED)
 
844
#ifdef PNG_WRITE_sPLT_SUPPORTED
843
845
/* Write a sPLT chunk */
844
846
void /* PRIVATE */
845
847
png_write_sPLT(png_structp png_ptr, png_sPLT_tp spalette)
853
855
   int entry_size = (spalette->depth == 8 ? 6 : 10);
854
856
   int palette_size = entry_size * spalette->nentries;
855
857
   png_sPLT_entryp ep;
856
 
#ifdef PNG_NO_POINTER_INDEXING
 
858
#ifndef PNG_POINTER_INDEXING_SUPPORTED
857
859
   int i;
858
860
#endif
859
861
 
870
872
   png_write_chunk_data(png_ptr, (png_bytep)&spalette->depth, (png_size_t)1);
871
873
 
872
874
   /* Loop through each palette entry, writing appropriately */
873
 
#ifndef PNG_NO_POINTER_INDEXING
 
875
#ifdef PNG_POINTER_INDEXING_SUPPORTED
874
876
   for (ep = spalette->entries; ep<spalette->entries + spalette->nentries; ep++)
875
877
   {
876
878
      if (spalette->depth == 8)
920
922
}
921
923
#endif
922
924
 
923
 
#if defined(PNG_WRITE_sBIT_SUPPORTED)
 
925
#ifdef PNG_WRITE_sBIT_SUPPORTED
924
926
/* Write the sBIT chunk */
925
927
void /* PRIVATE */
926
928
png_write_sBIT(png_structp png_ptr, png_color_8p sbit, int color_type)
977
979
}
978
980
#endif
979
981
 
980
 
#if defined(PNG_WRITE_cHRM_SUPPORTED)
 
982
#ifdef PNG_WRITE_cHRM_SUPPORTED
981
983
/* Write the cHRM chunk */
982
984
#ifdef PNG_FLOATING_POINT_SUPPORTED
983
985
void /* PRIVATE */
1004
1006
   int_blue_x  = (png_uint_32)(blue_x  * 100000.0 + 0.5);
1005
1007
   int_blue_y  = (png_uint_32)(blue_y  * 100000.0 + 0.5);
1006
1008
 
1007
 
#if !defined(PNG_NO_CHECK_cHRM)
 
1009
#ifdef PNG_CHECK_cHRM_SUPPORTED
1008
1010
   if (png_check_cHRM_fixed(png_ptr, int_white_x, int_white_y,
1009
1011
      int_red_x, int_red_y, int_green_x, int_green_y, int_blue_x, int_blue_y))
1010
1012
#endif
1042
1044
   png_debug(1, "in png_write_cHRM");
1043
1045
 
1044
1046
   /* Each value is saved in 1/100,000ths */
1045
 
#if !defined(PNG_NO_CHECK_cHRM)
 
1047
#ifdef PNG_CHECK_cHRM_SUPPORTED
1046
1048
   if (png_check_cHRM_fixed(png_ptr, white_x, white_y, red_x, red_y,
1047
1049
      green_x, green_y, blue_x, blue_y))
1048
1050
#endif
1065
1067
#endif
1066
1068
#endif
1067
1069
 
1068
 
#if defined(PNG_WRITE_tRNS_SUPPORTED)
 
1070
#ifdef PNG_WRITE_tRNS_SUPPORTED
1069
1071
/* Write the tRNS chunk */
1070
1072
void /* PRIVATE */
1071
1073
png_write_tRNS(png_structp png_ptr, png_bytep trans, png_color_16p tran,
1122
1124
}
1123
1125
#endif
1124
1126
 
1125
 
#if defined(PNG_WRITE_bKGD_SUPPORTED)
 
1127
#ifdef PNG_WRITE_bKGD_SUPPORTED
1126
1128
/* Write the background chunk */
1127
1129
void /* PRIVATE */
1128
1130
png_write_bKGD(png_structp png_ptr, png_color_16p back, int color_type)
1137
1139
   if (color_type == PNG_COLOR_TYPE_PALETTE)
1138
1140
   {
1139
1141
      if (
1140
 
#if defined(PNG_MNG_FEATURES_SUPPORTED)
 
1142
#ifdef PNG_MNG_FEATURES_SUPPORTED
1141
1143
          (png_ptr->num_palette ||
1142
1144
          (!(png_ptr->mng_features_permitted & PNG_FLAG_MNG_EMPTY_PLTE))) &&
1143
1145
#endif
1176
1178
}
1177
1179
#endif
1178
1180
 
1179
 
#if defined(PNG_WRITE_hIST_SUPPORTED)
 
1181
#ifdef PNG_WRITE_hIST_SUPPORTED
1180
1182
/* Write the histogram */
1181
1183
void /* PRIVATE */
1182
1184
png_write_hIST(png_structp png_ptr, png_uint_16p hist, int num_hist)
1253
1255
      if ((png_byte)*kp < 0x20 ||
1254
1256
         ((png_byte)*kp > 0x7E && (png_byte)*kp < 0xA1))
1255
1257
      {
1256
 
#if !defined(PNG_NO_STDIO) && !defined(_WIN32_WCE)
 
1258
#if defined(PNG_STDIO_SUPPORTED) && !defined(_WIN32_WCE)
1257
1259
         char msg[40];
1258
1260
 
1259
1261
         png_snprintf(msg, 40,
1340
1342
}
1341
1343
#endif
1342
1344
 
1343
 
#if defined(PNG_WRITE_tEXt_SUPPORTED)
 
1345
#ifdef PNG_WRITE_tEXt_SUPPORTED
1344
1346
/* Write a tEXt chunk */
1345
1347
void /* PRIVATE */
1346
1348
png_write_tEXt(png_structp png_ptr, png_charp key, png_charp text,
1381
1383
}
1382
1384
#endif
1383
1385
 
1384
 
#if defined(PNG_WRITE_zTXt_SUPPORTED)
 
1386
#ifdef PNG_WRITE_zTXt_SUPPORTED
1385
1387
/* Write a compressed text chunk */
1386
1388
void /* PRIVATE */
1387
1389
png_write_zTXt(png_structp png_ptr, png_charp key, png_charp text,
1441
1443
}
1442
1444
#endif
1443
1445
 
1444
 
#if defined(PNG_WRITE_iTXt_SUPPORTED)
 
1446
#ifdef PNG_WRITE_iTXt_SUPPORTED
1445
1447
/* Write an iTXt chunk */
1446
1448
void /* PRIVATE */
1447
1449
png_write_iTXt(png_structp png_ptr, int compression, png_charp key,
1530
1532
}
1531
1533
#endif
1532
1534
 
1533
 
#if defined(PNG_WRITE_oFFs_SUPPORTED)
 
1535
#ifdef PNG_WRITE_oFFs_SUPPORTED
1534
1536
/* Write the oFFs chunk */
1535
1537
void /* PRIVATE */
1536
1538
png_write_oFFs(png_structp png_ptr, png_int_32 x_offset, png_int_32 y_offset,
1553
1555
   png_write_chunk(png_ptr, (png_bytep)png_oFFs, buf, (png_size_t)9);
1554
1556
}
1555
1557
#endif
1556
 
#if defined(PNG_WRITE_pCAL_SUPPORTED)
 
1558
#ifdef PNG_WRITE_pCAL_SUPPORTED
1557
1559
/* Write the pCAL chunk (described in the PNG extensions document) */
1558
1560
void /* PRIVATE */
1559
1561
png_write_pCAL(png_structp png_ptr, png_charp purpose, png_int_32 X0,
1616
1618
}
1617
1619
#endif
1618
1620
 
1619
 
#if defined(PNG_WRITE_sCAL_SUPPORTED)
 
1621
#ifdef PNG_WRITE_sCAL_SUPPORTED
1620
1622
/* Write the sCAL chunk */
1621
 
#if defined(PNG_FLOATING_POINT_SUPPORTED) && !defined(PNG_NO_STDIO)
 
1623
#if defined(PNG_FLOATING_POINT_SUPPORTED) && defined(PNG_STDIO_SUPPORTED)
1622
1624
void /* PRIVATE */
1623
1625
png_write_sCAL(png_structp png_ptr, int unit, double width, double height)
1624
1626
{
1631
1633
   png_debug(1, "in png_write_sCAL");
1632
1634
 
1633
1635
   buf[0] = (char)unit;
1634
 
#if defined(_WIN32_WCE)
 
1636
#ifdef _WIN32_WCE
1635
1637
/* sprintf() function is not supported on WindowsCE */
1636
1638
   {
1637
1639
      wchar_t wc_buf[32];
1690
1692
#endif
1691
1693
#endif
1692
1694
 
1693
 
#if defined(PNG_WRITE_pHYs_SUPPORTED)
 
1695
#ifdef PNG_WRITE_pHYs_SUPPORTED
1694
1696
/* Write the pHYs chunk */
1695
1697
void /* PRIVATE */
1696
1698
png_write_pHYs(png_structp png_ptr, png_uint_32 x_pixels_per_unit,
1715
1717
}
1716
1718
#endif
1717
1719
 
1718
 
#if defined(PNG_WRITE_tIME_SUPPORTED)
 
1720
#ifdef PNG_WRITE_tIME_SUPPORTED
1719
1721
/* Write the tIME chunk.  Use either png_convert_from_struct_tm()
1720
1722
 * or png_convert_from_time_t(), or fill in the structure yourself.
1721
1723
 */
1753
1755
png_write_start_row(png_structp png_ptr)
1754
1756
{
1755
1757
#ifdef PNG_WRITE_INTERLACING_SUPPORTED
1756
 
#ifdef PNG_USE_LOCAL_ARRAYS
1757
1758
   /* Arrays to facilitate easy interlacing - use pass (0 - 6) as index */
1758
1759
 
1759
1760
   /* Start of interlace block */
1768
1769
   /* Offset to next interlace block in the y direction */
1769
1770
   int png_pass_yinc[7] = {8, 8, 8, 4, 4, 2, 2};
1770
1771
#endif
1771
 
#endif
1772
1772
 
1773
1773
   png_size_t buf_size;
1774
1774
 
1782
1782
     (png_uint_32)buf_size);
1783
1783
   png_ptr->row_buf[0] = PNG_FILTER_VALUE_NONE;
1784
1784
 
1785
 
#ifndef PNG_NO_WRITE_FILTER
 
1785
#ifdef PNG_WRITE_FILTER_SUPPORTED
1786
1786
   /* Set up filtering buffer, if using this filter */
1787
1787
   if (png_ptr->do_filter & PNG_FILTER_SUB)
1788
1788
   {
1794
1794
   /* We only need to keep the previous row if we are using one of these. */
1795
1795
   if (png_ptr->do_filter & (PNG_FILTER_AVG | PNG_FILTER_UP | PNG_FILTER_PAETH))
1796
1796
   {
1797
 
     /* Set up previous row buffer */
1798
 
     png_ptr->prev_row = (png_bytep)png_malloc(png_ptr,
1799
 
        (png_uint_32)buf_size);
1800
 
     png_memset(png_ptr->prev_row, 0, buf_size);
 
1797
      /* Set up previous row buffer */
 
1798
      png_ptr->prev_row = (png_bytep)png_calloc(png_ptr,
 
1799
         (png_uint_32)buf_size);
1801
1800
 
1802
1801
      if (png_ptr->do_filter & PNG_FILTER_UP)
1803
1802
      {
1804
1803
         png_ptr->up_row = (png_bytep)png_malloc(png_ptr,
1805
 
           (png_uint_32)(png_ptr->rowbytes + 1));
 
1804
            (png_uint_32)(png_ptr->rowbytes + 1));
1806
1805
         png_ptr->up_row[0] = PNG_FILTER_VALUE_UP;
1807
1806
      }
1808
1807
 
1809
1808
      if (png_ptr->do_filter & PNG_FILTER_AVG)
1810
1809
      {
1811
1810
         png_ptr->avg_row = (png_bytep)png_malloc(png_ptr,
1812
 
           (png_uint_32)(png_ptr->rowbytes + 1));
 
1811
            (png_uint_32)(png_ptr->rowbytes + 1));
1813
1812
         png_ptr->avg_row[0] = PNG_FILTER_VALUE_AVG;
1814
1813
      }
1815
1814
 
1816
1815
      if (png_ptr->do_filter & PNG_FILTER_PAETH)
1817
1816
      {
1818
1817
         png_ptr->paeth_row = (png_bytep)png_malloc(png_ptr,
1819
 
           (png_uint_32)(png_ptr->rowbytes + 1));
 
1818
            (png_uint_32)(png_ptr->rowbytes + 1));
1820
1819
         png_ptr->paeth_row[0] = PNG_FILTER_VALUE_PAETH;
1821
1820
      }
1822
1821
   }
1823
 
#endif /* PNG_NO_WRITE_FILTER */
 
1822
#endif /* PNG_WRITE_FILTER_SUPPORTED */
1824
1823
 
1825
1824
#ifdef PNG_WRITE_INTERLACING_SUPPORTED
1826
1825
   /* If interlaced, we need to set up width and height of pass */
1854
1853
png_write_finish_row(png_structp png_ptr)
1855
1854
{
1856
1855
#ifdef PNG_WRITE_INTERLACING_SUPPORTED
1857
 
#ifdef PNG_USE_LOCAL_ARRAYS
1858
1856
   /* Arrays to facilitate easy interlacing - use pass (0 - 6) as index */
1859
1857
 
1860
1858
   /* Start of interlace block */
1869
1867
   /* Offset to next interlace block in the y direction */
1870
1868
   int png_pass_yinc[7] = {8, 8, 8, 4, 4, 2, 2};
1871
1869
#endif
1872
 
#endif
1873
1870
 
1874
1871
   int ret;
1875
1872
 
1962
1959
   png_ptr->zstream.data_type = Z_BINARY;
1963
1960
}
1964
1961
 
1965
 
#if defined(PNG_WRITE_INTERLACING_SUPPORTED)
 
1962
#ifdef PNG_WRITE_INTERLACING_SUPPORTED
1966
1963
/* Pick out the correct pixels for the interlace pass.
1967
1964
 * The basic idea here is to go through the row with a source
1968
1965
 * pointer and a destination pointer (sp and dp), and copy the
1973
1970
void /* PRIVATE */
1974
1971
png_do_write_interlace(png_row_infop row_info, png_bytep row, int pass)
1975
1972
{
1976
 
#ifdef PNG_USE_LOCAL_ARRAYS
1977
1973
   /* Arrays to facilitate easy interlacing - use pass (0 - 6) as index */
1978
1974
 
1979
1975
   /* Start of interlace block */
1981
1977
 
1982
1978
   /* Offset to next interlace block */
1983
1979
   int png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1};
1984
 
#endif
1985
1980
 
1986
1981
   png_debug(1, "in png_do_write_interlace");
1987
1982
 
1988
1983
   /* We don't have to do anything on the last pass (6) */
1989
 
#if defined(PNG_USELESS_TESTS_SUPPORTED)
 
1984
#ifdef PNG_USELESS_TESTS_SUPPORTED
1990
1985
   if (row != NULL && row_info != NULL && pass < 6)
1991
1986
#else
1992
1987
   if (pass < 6)
2146
2141
png_write_find_filter(png_structp png_ptr, png_row_infop row_info)
2147
2142
{
2148
2143
   png_bytep best_row;
2149
 
#ifndef PNG_NO_WRITE_FILTER
 
2144
#ifdef PNG_WRITE_FILTER_SUPPORTED
2150
2145
   png_bytep prev_row, row_buf;
2151
2146
   png_uint_32 mins, bpp;
2152
2147
   png_byte filter_to_do = png_ptr->do_filter;
2157
2152
 
2158
2153
   png_debug(1, "in png_write_find_filter");
2159
2154
 
 
2155
#ifndef PNG_WRITE_WEIGHTED_FILTER_SUPPORTED
 
2156
  if (png_ptr->row_number == 0 && filter_to_do == PNG_ALL_FILTERS)
 
2157
  {
 
2158
      /* These will never be selected so we need not test them. */
 
2159
      filter_to_do &= ~(PNG_FILTER_UP | PNG_FILTER_PAETH);
 
2160
  }
 
2161
#endif 
 
2162
 
2160
2163
   /* Find out how many bytes offset each pixel is */
2161
2164
   bpp = (row_info->pixel_depth + 7) >> 3;
2162
2165
 
2163
2166
   prev_row = png_ptr->prev_row;
2164
2167
#endif
2165
2168
   best_row = png_ptr->row_buf;
2166
 
#ifndef PNG_NO_WRITE_FILTER
 
2169
#ifdef PNG_WRITE_FILTER_SUPPORTED
2167
2170
   row_buf = best_row;
2168
2171
   mins = PNG_MAXSUM;
2169
2172
 
2206
2209
         sum += (v < 128) ? v : 256 - v;
2207
2210
      }
2208
2211
 
2209
 
#if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
 
2212
#ifdef PNG_WRITE_WEIGHTED_FILTER_SUPPORTED
2210
2213
      if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED)
2211
2214
      {
2212
2215
         png_uint_32 sumhi, sumlo;
2270
2273
      png_uint_32 i;
2271
2274
      int v;
2272
2275
 
2273
 
#if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
 
2276
#ifdef PNG_WRITE_WEIGHTED_FILTER_SUPPORTED
2274
2277
      /* We temporarily increase the "minimum sum" by the factor we
2275
2278
       * would reduce the sum of this filter, so that we can do the
2276
2279
       * early exit comparison without scaling the sum each time.
2323
2326
            break;
2324
2327
      }
2325
2328
 
2326
 
#if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
 
2329
#ifdef PNG_WRITE_WEIGHTED_FILTER_SUPPORTED
2327
2330
      if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED)
2328
2331
      {
2329
2332
         int j;
2384
2387
      int v;
2385
2388
 
2386
2389
 
2387
 
#if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
 
2390
#ifdef PNG_WRITE_WEIGHTED_FILTER_SUPPORTED
2388
2391
      if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED)
2389
2392
      {
2390
2393
         int j;
2426
2429
            break;
2427
2430
      }
2428
2431
 
2429
 
#if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
 
2432
#ifdef PNG_WRITE_WEIGHTED_FILTER_SUPPORTED
2430
2433
      if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED)
2431
2434
      {
2432
2435
         int j;
2489
2492
      png_uint_32 i;
2490
2493
      int v;
2491
2494
 
2492
 
#if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
 
2495
#ifdef PNG_WRITE_WEIGHTED_FILTER_SUPPORTED
2493
2496
      if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED)
2494
2497
      {
2495
2498
         int j;
2538
2541
            break;
2539
2542
      }
2540
2543
 
2541
 
#if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
 
2544
#ifdef PNG_WRITE_WEIGHTED_FILTER_SUPPORTED
2542
2545
      if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED)
2543
2546
      {
2544
2547
         int j;
2622
2625
      png_uint_32 i;
2623
2626
      int v;
2624
2627
 
2625
 
#if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
 
2628
#ifdef PNG_WRITE_WEIGHTED_FILTER_SUPPORTED
2626
2629
      if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED)
2627
2630
      {
2628
2631
         int j;
2703
2706
            break;
2704
2707
      }
2705
2708
 
2706
 
#if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
 
2709
#ifdef PNG_WRITE_WEIGHTED_FILTER_SUPPORTED
2707
2710
      if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED)
2708
2711
      {
2709
2712
         int j;
2739
2742
         best_row = png_ptr->paeth_row;
2740
2743
      }
2741
2744
   }
2742
 
#endif /* PNG_NO_WRITE_FILTER */
 
2745
#endif /* PNG_WRITE_FILTER_SUPPORTED */
2743
2746
   /* Do the actual writing of the filtered row data from the chosen filter. */
2744
2747
 
2745
2748
   png_write_filtered_row(png_ptr, best_row);
2746
2749
 
2747
 
#ifndef PNG_NO_WRITE_FILTER
2748
 
#if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
 
2750
#ifdef PNG_WRITE_FILTER_SUPPORTED
 
2751
#ifdef PNG_WRITE_WEIGHTED_FILTER_SUPPORTED
2749
2752
   /* Save the type of filter we picked this time for future calculations */
2750
2753
   if (png_ptr->num_prev_filters > 0)
2751
2754
   {
2757
2760
      png_ptr->prev_filters[j] = best_row[0];
2758
2761
   }
2759
2762
#endif
2760
 
#endif /* PNG_NO_WRITE_FILTER */
 
2763
#endif /* PNG_WRITE_FILTER_SUPPORTED */
2761
2764
}
2762
2765
 
2763
2766
 
2812
2815
   /* Finish row - updates counters and flushes zlib if last row */
2813
2816
   png_write_finish_row(png_ptr);
2814
2817
 
2815
 
#if defined(PNG_WRITE_FLUSH_SUPPORTED)
 
2818
#ifdef PNG_WRITE_FLUSH_SUPPORTED
2816
2819
   png_ptr->flush_rows++;
2817
2820
 
2818
2821
   if (png_ptr->flush_dist > 0 &&