< prev index next >

src/java.desktop/share/native/libsplashscreen/libpng/pngtrans.c

Print this page




  12  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  13  * version 2 for more details (a copy is included in the LICENSE file that
  14  * accompanied this code).
  15  *
  16  * You should have received a copy of the GNU General Public License version
  17  * 2 along with this work; if not, write to the Free Software Foundation,
  18  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  19  *
  20  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  21  * or visit www.oracle.com if you need additional information or have any
  22  * questions.
  23  */
  24 
  25 /* pngtrans.c - transforms the data in a row (used by both readers and writers)
  26  *
  27  * This file is available under and governed by the GNU General Public
  28  * License version 2 only, as published by the Free Software Foundation.
  29  * However, the following notice accompanied the original version of this
  30  * file and, per its terms, should not be removed:
  31  *
  32  * Last changed in libpng 1.6.18 [July 23, 2015]
  33  * Copyright (c) 1998-2002,2004,2006-2015 Glenn Randers-Pehrson
  34  * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
  35  * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
  36  *
  37  * This code is released under the libpng license.
  38  * For conditions of distribution and use, see the disclaimer
  39  * and license in png.h
  40  */
  41 
  42 #include "pngpriv.h"
  43 
  44 #if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
  45 
  46 #if defined(PNG_READ_BGR_SUPPORTED) || defined(PNG_WRITE_BGR_SUPPORTED)
  47 /* Turn on BGR-to-RGB mapping */
  48 void PNGAPI
  49 png_set_bgr(png_structrp png_ptr)
  50 {
  51    png_debug(1, "in png_set_bgr");
  52 
  53    if (png_ptr == NULL)


 183          switch (png_ptr->color_type)
 184          {
 185             case PNG_COLOR_TYPE_RGB:
 186                png_ptr->usr_channels = 4;
 187                break;
 188 
 189             case PNG_COLOR_TYPE_GRAY:
 190                if (png_ptr->bit_depth >= 8)
 191                {
 192                   png_ptr->usr_channels = 2;
 193                   break;
 194                }
 195 
 196                else
 197                {
 198                   /* There simply isn't any code in libpng to strip out bits
 199                    * from bytes when the components are less than a byte in
 200                    * size!
 201                    */
 202                   png_app_error(png_ptr,
 203                      "png_set_filler is invalid for low bit depth gray output");

 204                   return;
 205                }
 206 
 207             default:
 208                png_app_error(png_ptr,
 209                   "png_set_filler: inappropriate color type");
 210                return;
 211          }
 212 #     else
 213          png_app_error(png_ptr, "png_set_filler not supported on write");
 214          return;
 215 #     endif
 216    }
 217 
 218    /* Here on success - libpng supports the operation, set the transformation
 219     * and the flag to say where the filler channel is.
 220     */
 221    png_ptr->transformations |= PNG_FILLER;
 222 
 223    if (filler_loc == PNG_FILLER_AFTER)


 605             *dp++ = *sp++, *dp++ = *sp, sp += 3;
 606          }
 607 
 608          row_info->pixel_depth = 48;
 609       }
 610 
 611       else
 612          return; /* bad bit depth */
 613 
 614       row_info->channels = 3;
 615 
 616       /* Finally fix the color type if it records an alpha channel */
 617       if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
 618          row_info->color_type = PNG_COLOR_TYPE_RGB;
 619    }
 620 
 621    else
 622       return; /* The filler channel has gone already */
 623 
 624    /* Fix the rowbytes value. */
 625    row_info->rowbytes = dp-row;
 626 }
 627 #endif
 628 
 629 #if defined(PNG_READ_BGR_SUPPORTED) || defined(PNG_WRITE_BGR_SUPPORTED)
 630 /* Swaps red and blue bytes within a pixel */
 631 void /* PRIVATE */
 632 png_do_bgr(png_row_infop row_info, png_bytep row)
 633 {
 634    png_debug(1, "in png_do_bgr");
 635 
 636    if ((row_info->color_type & PNG_COLOR_MASK_COLOR) != 0)
 637    {
 638       png_uint_32 row_width = row_info->width;
 639       if (row_info->bit_depth == 8)
 640       {
 641          if (row_info->color_type == PNG_COLOR_TYPE_RGB)
 642          {
 643             png_bytep rp;
 644             png_uint_32 i;
 645 


 703 #endif
 704    }
 705 }
 706 #endif /* READ_BGR || WRITE_BGR */
 707 
 708 #if defined(PNG_READ_CHECK_FOR_INVALID_INDEX_SUPPORTED) || \
 709     defined(PNG_WRITE_CHECK_FOR_INVALID_INDEX_SUPPORTED)
 710 /* Added at libpng-1.5.10 */
 711 void /* PRIVATE */
 712 png_do_check_palette_indexes(png_structrp png_ptr, png_row_infop row_info)
 713 {
 714    if (png_ptr->num_palette < (1 << row_info->bit_depth) &&
 715       png_ptr->num_palette > 0) /* num_palette can be 0 in MNG files */
 716    {
 717       /* Calculations moved outside switch in an attempt to stop different
 718        * compiler warnings.  'padding' is in *bits* within the last byte, it is
 719        * an 'int' because pixel_depth becomes an 'int' in the expression below,
 720        * and this calculation is used because it avoids warnings that other
 721        * forms produced on either GCC or MSVC.
 722        */
 723       int padding = (-row_info->pixel_depth * row_info->width) & 7;
 724       png_bytep rp = png_ptr->row_buf + row_info->rowbytes;
 725 
 726       switch (row_info->bit_depth)
 727       {
 728          case 1:
 729          {
 730             /* in this case, all bytes must be 0 so we don't need
 731              * to unpack the pixels except for the rightmost one.
 732              */
 733             for (; rp > png_ptr->row_buf; rp--)
 734             {
 735               if ((*rp >> padding) != 0)
 736                  png_ptr->num_palette_max = 1;
 737               padding = 0;
 738             }
 739 
 740             break;
 741          }
 742 
 743          case 2:




  12  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  13  * version 2 for more details (a copy is included in the LICENSE file that
  14  * accompanied this code).
  15  *
  16  * You should have received a copy of the GNU General Public License version
  17  * 2 along with this work; if not, write to the Free Software Foundation,
  18  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  19  *
  20  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  21  * or visit www.oracle.com if you need additional information or have any
  22  * questions.
  23  */
  24 
  25 /* pngtrans.c - transforms the data in a row (used by both readers and writers)
  26  *
  27  * This file is available under and governed by the GNU General Public
  28  * License version 2 only, as published by the Free Software Foundation.
  29  * However, the following notice accompanied the original version of this
  30  * file and, per its terms, should not be removed:
  31  *
  32  * Last changed in libpng 1.6.26 [October 20, 2016]
  33  * Copyright (c) 1998-2002,2004,2006-2016 Glenn Randers-Pehrson
  34  * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
  35  * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
  36  *
  37  * This code is released under the libpng license.
  38  * For conditions of distribution and use, see the disclaimer
  39  * and license in png.h
  40  */
  41 
  42 #include "pngpriv.h"
  43 
  44 #if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
  45 
  46 #if defined(PNG_READ_BGR_SUPPORTED) || defined(PNG_WRITE_BGR_SUPPORTED)
  47 /* Turn on BGR-to-RGB mapping */
  48 void PNGAPI
  49 png_set_bgr(png_structrp png_ptr)
  50 {
  51    png_debug(1, "in png_set_bgr");
  52 
  53    if (png_ptr == NULL)


 183          switch (png_ptr->color_type)
 184          {
 185             case PNG_COLOR_TYPE_RGB:
 186                png_ptr->usr_channels = 4;
 187                break;
 188 
 189             case PNG_COLOR_TYPE_GRAY:
 190                if (png_ptr->bit_depth >= 8)
 191                {
 192                   png_ptr->usr_channels = 2;
 193                   break;
 194                }
 195 
 196                else
 197                {
 198                   /* There simply isn't any code in libpng to strip out bits
 199                    * from bytes when the components are less than a byte in
 200                    * size!
 201                    */
 202                   png_app_error(png_ptr,
 203                       "png_set_filler is invalid for"
 204                       " low bit depth gray output");
 205                   return;
 206                }
 207 
 208             default:
 209                png_app_error(png_ptr,
 210                    "png_set_filler: inappropriate color type");
 211                return;
 212          }
 213 #     else
 214          png_app_error(png_ptr, "png_set_filler not supported on write");
 215          return;
 216 #     endif
 217    }
 218 
 219    /* Here on success - libpng supports the operation, set the transformation
 220     * and the flag to say where the filler channel is.
 221     */
 222    png_ptr->transformations |= PNG_FILLER;
 223 
 224    if (filler_loc == PNG_FILLER_AFTER)


 606             *dp++ = *sp++, *dp++ = *sp, sp += 3;
 607          }
 608 
 609          row_info->pixel_depth = 48;
 610       }
 611 
 612       else
 613          return; /* bad bit depth */
 614 
 615       row_info->channels = 3;
 616 
 617       /* Finally fix the color type if it records an alpha channel */
 618       if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
 619          row_info->color_type = PNG_COLOR_TYPE_RGB;
 620    }
 621 
 622    else
 623       return; /* The filler channel has gone already */
 624 
 625    /* Fix the rowbytes value. */
 626    row_info->rowbytes = (unsigned int)(dp-row);
 627 }
 628 #endif
 629 
 630 #if defined(PNG_READ_BGR_SUPPORTED) || defined(PNG_WRITE_BGR_SUPPORTED)
 631 /* Swaps red and blue bytes within a pixel */
 632 void /* PRIVATE */
 633 png_do_bgr(png_row_infop row_info, png_bytep row)
 634 {
 635    png_debug(1, "in png_do_bgr");
 636 
 637    if ((row_info->color_type & PNG_COLOR_MASK_COLOR) != 0)
 638    {
 639       png_uint_32 row_width = row_info->width;
 640       if (row_info->bit_depth == 8)
 641       {
 642          if (row_info->color_type == PNG_COLOR_TYPE_RGB)
 643          {
 644             png_bytep rp;
 645             png_uint_32 i;
 646 


 704 #endif
 705    }
 706 }
 707 #endif /* READ_BGR || WRITE_BGR */
 708 
 709 #if defined(PNG_READ_CHECK_FOR_INVALID_INDEX_SUPPORTED) || \
 710     defined(PNG_WRITE_CHECK_FOR_INVALID_INDEX_SUPPORTED)
 711 /* Added at libpng-1.5.10 */
 712 void /* PRIVATE */
 713 png_do_check_palette_indexes(png_structrp png_ptr, png_row_infop row_info)
 714 {
 715    if (png_ptr->num_palette < (1 << row_info->bit_depth) &&
 716       png_ptr->num_palette > 0) /* num_palette can be 0 in MNG files */
 717    {
 718       /* Calculations moved outside switch in an attempt to stop different
 719        * compiler warnings.  'padding' is in *bits* within the last byte, it is
 720        * an 'int' because pixel_depth becomes an 'int' in the expression below,
 721        * and this calculation is used because it avoids warnings that other
 722        * forms produced on either GCC or MSVC.
 723        */
 724       int padding = PNG_PADBITS(row_info->pixel_depth, row_info->width);
 725       png_bytep rp = png_ptr->row_buf + row_info->rowbytes;
 726 
 727       switch (row_info->bit_depth)
 728       {
 729          case 1:
 730          {
 731             /* in this case, all bytes must be 0 so we don't need
 732              * to unpack the pixels except for the rightmost one.
 733              */
 734             for (; rp > png_ptr->row_buf; rp--)
 735             {
 736               if ((*rp >> padding) != 0)
 737                  png_ptr->num_palette_max = 1;
 738               padding = 0;
 739             }
 740 
 741             break;
 742          }
 743 
 744          case 2:


< prev index next >