Back to index

tetex-bin  3.0
Defines | Functions | Variables
pngtrans.c File Reference
#include "png.h"

Go to the source code of this file.

Defines

#define PNG_INTERNAL

Functions

void PNGAPI png_set_bgr (png_structp png_ptr)
void PNGAPI png_set_swap (png_structp png_ptr)
void PNGAPI png_set_packing (png_structp png_ptr)
void PNGAPI png_set_packswap (png_structp png_ptr)
void PNGAPI png_set_shift (png_structp png_ptr, png_color_8p true_bits)
int PNGAPI png_set_interlace_handling (png_structp png_ptr)
void PNGAPI png_set_filler (png_structp png_ptr, png_uint_32 filler, int filler_loc)
void PNGAPI png_set_add_alpha (png_structp png_ptr, png_uint_32 filler, int filler_loc)
void PNGAPI png_set_swap_alpha (png_structp png_ptr)
void PNGAPI png_set_invert_alpha (png_structp png_ptr)
void PNGAPI png_set_invert_mono (png_structp png_ptr)
void png_do_invert (png_row_infop row_info, png_bytep row)
void png_do_swap (png_row_infop row_info, png_bytep row)
void png_do_packswap (png_row_infop row_info, png_bytep row)
void png_do_strip_filler (png_row_infop row_info, png_bytep row, png_uint_32 flags)
void png_do_bgr (png_row_infop row_info, png_bytep row)
void PNGAPI png_set_user_transform_info (png_structp png_ptr, png_voidp user_transform_ptr, int user_transform_depth, int user_transform_channels)
png_voidp PNGAPI png_get_user_transform_ptr (png_structp png_ptr)

Variables

static png_byte onebppswaptable [256]
static png_byte twobppswaptable [256]
static png_byte fourbppswaptable [256]

Define Documentation

#define PNG_INTERNAL

Definition at line 11 of file pngtrans.c.


Function Documentation

void png_do_bgr ( png_row_infop  row_info,
png_bytep  row 
)

Definition at line 541 of file pngtrans.c.

{
   png_debug(1, "in png_do_bgr\n");
   if (
#if defined(PNG_USELESS_TESTS_SUPPORTED)
       row != NULL && row_info != NULL &&
#endif
       (row_info->color_type & PNG_COLOR_MASK_COLOR))
   {
      png_uint_32 row_width = row_info->width;
      if (row_info->bit_depth == 8)
      {
         if (row_info->color_type == PNG_COLOR_TYPE_RGB)
         {
            png_bytep rp;
            png_uint_32 i;

            for (i = 0, rp = row; i < row_width; i++, rp += 3)
            {
               png_byte save = *rp;
               *rp = *(rp + 2);
               *(rp + 2) = save;
            }
         }
         else if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
         {
            png_bytep rp;
            png_uint_32 i;

            for (i = 0, rp = row; i < row_width; i++, rp += 4)
            {
               png_byte save = *rp;
               *rp = *(rp + 2);
               *(rp + 2) = save;
            }
         }
      }
      else if (row_info->bit_depth == 16)
      {
         if (row_info->color_type == PNG_COLOR_TYPE_RGB)
         {
            png_bytep rp;
            png_uint_32 i;

            for (i = 0, rp = row; i < row_width; i++, rp += 6)
            {
               png_byte save = *rp;
               *rp = *(rp + 4);
               *(rp + 4) = save;
               save = *(rp + 1);
               *(rp + 1) = *(rp + 5);
               *(rp + 5) = save;
            }
         }
         else if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
         {
            png_bytep rp;
            png_uint_32 i;

            for (i = 0, rp = row; i < row_width; i++, rp += 8)
            {
               png_byte save = *rp;
               *rp = *(rp + 4);
               *(rp + 4) = save;
               save = *(rp + 1);
               *(rp + 1) = *(rp + 5);
               *(rp + 5) = save;
            }
         }
      }
   }
}

Here is the caller graph for this function:

void png_do_invert ( png_row_infop  row_info,
png_bytep  row 
)

Definition at line 165 of file pngtrans.c.

{
   png_debug(1, "in png_do_invert\n");
  /* This test removed from libpng version 1.0.13 and 1.2.0:
   *   if (row_info->bit_depth == 1 &&
   */
#if defined(PNG_USELESS_TESTS_SUPPORTED)
   if (row == NULL || row_info == NULL)
     return;
#endif
   if (row_info->color_type == PNG_COLOR_TYPE_GRAY)
   {
      png_bytep rp = row;
      png_uint_32 i;
      png_uint_32 istop = row_info->rowbytes;

      for (i = 0; i < istop; i++)
      {
         *rp = (png_byte)(~(*rp));
         rp++;
      }
   }
   else if (row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA &&
      row_info->bit_depth == 8)
   {
      png_bytep rp = row;
      png_uint_32 i;
      png_uint_32 istop = row_info->rowbytes;

      for (i = 0; i < istop; i+=2)
      {
         *rp = (png_byte)(~(*rp));
         rp+=2;
      }
   }
   else if (row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA &&
      row_info->bit_depth == 16)
   {
      png_bytep rp = row;
      png_uint_32 i;
      png_uint_32 istop = row_info->rowbytes;

      for (i = 0; i < istop; i+=4)
      {
         *rp = (png_byte)(~(*rp));
         *(rp+1) = (png_byte)(~(*(rp+1)));
         rp+=4;
      }
   }
}

Here is the caller graph for this function:

void png_do_packswap ( png_row_infop  row_info,
png_bytep  row 
)

Definition at line 351 of file pngtrans.c.

{
   png_debug(1, "in png_do_packswap\n");
   if (
#if defined(PNG_USELESS_TESTS_SUPPORTED)
       row != NULL && row_info != NULL &&
#endif
       row_info->bit_depth < 8)
   {
      png_bytep rp, end, table;

      end = row + row_info->rowbytes;

      if (row_info->bit_depth == 1)
         table = onebppswaptable;
      else if (row_info->bit_depth == 2)
         table = twobppswaptable;
      else if (row_info->bit_depth == 4)
         table = fourbppswaptable;
      else
         return;

      for (rp = row; rp < end; rp++)
         *rp = table[*rp];
   }
}

Here is the caller graph for this function:

void png_do_strip_filler ( png_row_infop  row_info,
png_bytep  row,
png_uint_32  flags 
)

Definition at line 383 of file pngtrans.c.

{
   png_debug(1, "in png_do_strip_filler\n");
#if defined(PNG_USELESS_TESTS_SUPPORTED)
   if (row != NULL && row_info != NULL)
#endif
   {
      png_bytep sp=row;
      png_bytep dp=row;
      png_uint_32 row_width=row_info->width;
      png_uint_32 i;

      if ((row_info->color_type == PNG_COLOR_TYPE_RGB ||
         (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA &&
         (flags & PNG_FLAG_STRIP_ALPHA))) &&
         row_info->channels == 4)
      {
         if (row_info->bit_depth == 8)
         {
            /* This converts from RGBX or RGBA to RGB */
            if (flags & PNG_FLAG_FILLER_AFTER)
            {
               dp+=3; sp+=4;
               for (i = 1; i < row_width; i++)
               {
                  *dp++ = *sp++;
                  *dp++ = *sp++;
                  *dp++ = *sp++;
                  sp++;
               }
            }
            /* This converts from XRGB or ARGB to RGB */
            else
            {
               for (i = 0; i < row_width; i++)
               {
                  sp++;
                  *dp++ = *sp++;
                  *dp++ = *sp++;
                  *dp++ = *sp++;
               }
            }
            row_info->pixel_depth = 24;
            row_info->rowbytes = row_width * 3;
         }
         else /* if (row_info->bit_depth == 16) */
         {
            if (flags & PNG_FLAG_FILLER_AFTER)
            {
               /* This converts from RRGGBBXX or RRGGBBAA to RRGGBB */
               sp += 8; dp += 6;
               for (i = 1; i < row_width; i++)
               {
                  /* This could be (although png_memcpy is probably slower):
                  png_memcpy(dp, sp, 6);
                  sp += 8;
                  dp += 6;
                  */

                  *dp++ = *sp++;
                  *dp++ = *sp++;
                  *dp++ = *sp++;
                  *dp++ = *sp++;
                  *dp++ = *sp++;
                  *dp++ = *sp++;
                  sp += 2;
               }
            }
            else
            {
               /* This converts from XXRRGGBB or AARRGGBB to RRGGBB */
               for (i = 0; i < row_width; i++)
               {
                  /* This could be (although png_memcpy is probably slower):
                  png_memcpy(dp, sp, 6);
                  sp += 8;
                  dp += 6;
                  */

                  sp+=2;
                  *dp++ = *sp++;
                  *dp++ = *sp++;
                  *dp++ = *sp++;
                  *dp++ = *sp++;
                  *dp++ = *sp++;
                  *dp++ = *sp++;
               }
            }
            row_info->pixel_depth = 48;
            row_info->rowbytes = row_width * 6;
         }
         row_info->channels = 3;
      }
      else if ((row_info->color_type == PNG_COLOR_TYPE_GRAY ||
         (row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA &&
         (flags & PNG_FLAG_STRIP_ALPHA))) &&
          row_info->channels == 2)
      {
         if (row_info->bit_depth == 8)
         {
            /* This converts from GX or GA to G */
            if (flags & PNG_FLAG_FILLER_AFTER)
            {
               for (i = 0; i < row_width; i++)
               {
                  *dp++ = *sp++;
                  sp++;
               }
            }
            /* This converts from XG or AG to G */
            else
            {
               for (i = 0; i < row_width; i++)
               {
                  sp++;
                  *dp++ = *sp++;
               }
            }
            row_info->pixel_depth = 8;
            row_info->rowbytes = row_width;
         }
         else /* if (row_info->bit_depth == 16) */
         {
            if (flags & PNG_FLAG_FILLER_AFTER)
            {
               /* This converts from GGXX or GGAA to GG */
               sp += 4; dp += 2;
               for (i = 1; i < row_width; i++)
               {
                  *dp++ = *sp++;
                  *dp++ = *sp++;
                  sp += 2;
               }
            }
            else
            {
               /* This converts from XXGG or AAGG to GG */
               for (i = 0; i < row_width; i++)
               {
                  sp += 2;
                  *dp++ = *sp++;
                  *dp++ = *sp++;
               }
            }
            row_info->pixel_depth = 16;
            row_info->rowbytes = row_width * 2;
         }
         row_info->channels = 1;
      }
      if (flags & PNG_FLAG_STRIP_ALPHA)
        row_info->color_type &= ~PNG_COLOR_MASK_ALPHA;
   }
}

Here is the caller graph for this function:

void png_do_swap ( png_row_infop  row_info,
png_bytep  row 
)

Definition at line 220 of file pngtrans.c.

{
   png_debug(1, "in png_do_swap\n");
   if (
#if defined(PNG_USELESS_TESTS_SUPPORTED)
       row != NULL && row_info != NULL &&
#endif
       row_info->bit_depth == 16)
   {
      png_bytep rp = row;
      png_uint_32 i;
      png_uint_32 istop= row_info->width * row_info->channels;

      for (i = 0; i < istop; i++, rp += 2)
      {
         png_byte t = *rp;
         *rp = *(rp + 1);
         *(rp + 1) = t;
      }
   }
}

Here is the caller graph for this function:

Definition at line 641 of file pngtrans.c.

{
#if defined(PNG_USER_TRANSFORM_PTR_SUPPORTED)
   return ((png_voidp)png_ptr->user_transform_ptr);
#else
   if(png_ptr)
     return (NULL);
   return (NULL);
#endif
}
void PNGAPI png_set_add_alpha ( png_structp  png_ptr,
png_uint_32  filler,
int  filler_loc 
)

Definition at line 125 of file pngtrans.c.

{
   png_debug(1, "in png_set_add_alpha\n");
   png_set_filler(png_ptr, filler, filler_loc);
   png_ptr->transformations |= PNG_ADD_ALPHA;
}

Here is the call graph for this function:

Definition at line 17 of file pngtrans.c.

{
   png_debug(1, "in png_set_bgr\n");
   png_ptr->transformations |= PNG_BGR;
}

Here is the caller graph for this function:

void PNGAPI png_set_filler ( png_structp  png_ptr,
png_uint_32  filler,
int  filler_loc 
)

Definition at line 93 of file pngtrans.c.

{
   png_debug(1, "in png_set_filler\n");
   png_ptr->transformations |= PNG_FILLER;
   png_ptr->filler = (png_byte)filler;
   if (filler_loc == PNG_FILLER_AFTER)
      png_ptr->flags |= PNG_FLAG_FILLER_AFTER;
   else
      png_ptr->flags &= ~PNG_FLAG_FILLER_AFTER;

   /* This should probably go in the "do_read_filler" routine.
    * I attempted to do that in libpng-1.0.1a but that caused problems
    * so I restored it in libpng-1.0.2a
   */

   if (png_ptr->color_type == PNG_COLOR_TYPE_RGB)
   {
      png_ptr->usr_channels = 4;
   }

   /* Also I added this in libpng-1.0.2a (what happens when we expand
    * a less-than-8-bit grayscale to GA? */

   if (png_ptr->color_type == PNG_COLOR_TYPE_GRAY && png_ptr->bit_depth >= 8)
   {
      png_ptr->usr_channels = 2;
   }
}

Here is the caller graph for this function:

Definition at line 73 of file pngtrans.c.

{
   png_debug(1, "in png_set_interlace handling\n");
   if (png_ptr->interlaced)
   {
      png_ptr->transformations |= PNG_INTERLACE;
      return (7);
   }

   return (1);
}

Here is the caller graph for this function:

Definition at line 148 of file pngtrans.c.

{
   png_debug(1, "in png_set_invert_alpha\n");
   png_ptr->transformations |= PNG_INVERT_ALPHA;
}

Here is the caller graph for this function:

Definition at line 157 of file pngtrans.c.

{
   png_debug(1, "in png_set_invert_mono\n");
   png_ptr->transformations |= PNG_INVERT_MONO;
}

Here is the caller graph for this function:

Definition at line 38 of file pngtrans.c.

{
   png_debug(1, "in png_set_packing\n");
   if (png_ptr->bit_depth < 8)
   {
      png_ptr->transformations |= PNG_PACK;
      png_ptr->usr_bit_depth = 8;
   }
}

Here is the caller graph for this function:

Definition at line 52 of file pngtrans.c.

{
   png_debug(1, "in png_set_packswap\n");
   if (png_ptr->bit_depth < 8)
      png_ptr->transformations |= PNG_PACKSWAP;
}

Here is the caller graph for this function:

void PNGAPI png_set_shift ( png_structp  png_ptr,
png_color_8p  true_bits 
)

Definition at line 62 of file pngtrans.c.

{
   png_debug(1, "in png_set_shift\n");
   png_ptr->transformations |= PNG_SHIFT;
   png_ptr->shift = *true_bits;
}

Here is the caller graph for this function:

Definition at line 27 of file pngtrans.c.

{
   png_debug(1, "in png_set_swap\n");
   if (png_ptr->bit_depth == 16)
      png_ptr->transformations |= PNG_SWAP_BYTES;
}

Here is the caller graph for this function:

Definition at line 138 of file pngtrans.c.

{
   png_debug(1, "in png_set_swap_alpha\n");
   png_ptr->transformations |= PNG_SWAP_ALPHA;
}

Here is the caller graph for this function:

void PNGAPI png_set_user_transform_info ( png_structp  png_ptr,
png_voidp  user_transform_ptr,
int  user_transform_depth,
int  user_transform_channels 
)

Definition at line 619 of file pngtrans.c.

{
   png_debug(1, "in png_set_user_transform_info\n");
#if defined(PNG_USER_TRANSFORM_PTR_SUPPORTED)
   png_ptr->user_transform_ptr = user_transform_ptr;
   png_ptr->user_transform_depth = (png_byte)user_transform_depth;
   png_ptr->user_transform_channels = (png_byte)user_transform_channels;
#else
   if(user_transform_ptr || user_transform_depth || user_transform_channels)
      png_warning(png_ptr,
        "This version of libpng does not support user transform info");
#endif
}

Here is the call graph for this function:


Variable Documentation

png_byte fourbppswaptable[256] [static]

Definition at line 314 of file pngtrans.c.

png_byte onebppswaptable[256] [static]

Definition at line 244 of file pngtrans.c.

png_byte twobppswaptable[256] [static]

Definition at line 279 of file pngtrans.c.