libpng/pngrcb.c

238 lines
5.4 KiB
C
Raw Normal View History

1995-07-20 03:43:20 -04:00
/* pngrcb.c - callbacks while reading a png file
1995-12-19 04:22:19 -05:00
libpng 1.0 beta 2 - version 0.85
1995-07-20 03:43:20 -04:00
For conditions of distribution and use, see copyright notice in png.h
Copyright (c) 1995 Guy Eric Schalnat, Group 42, Inc.
1995-12-19 04:22:19 -05:00
December 19, 1995
1995-07-20 03:43:20 -04:00
*/
#define PNG_INTERNAL
#include "png.h"
void
1995-12-19 04:22:19 -05:00
png_read_IHDR(png_structp png_ptr, png_infop info,
1995-07-20 03:43:20 -04:00
png_uint_32 width, png_uint_32 height, int bit_depth,
int color_type, int compression_type, int filter_type,
int interlace_type)
{
if (!png_ptr || !info)
return;
info->width = width;
info->height = height;
info->bit_depth = bit_depth;
info->color_type = color_type;
info->compression_type = compression_type;
info->filter_type = filter_type;
1995-12-19 04:22:19 -05:00
info->interlace_type = interlace_type;
1995-07-20 03:43:20 -04:00
if (info->color_type == PNG_COLOR_TYPE_PALETTE)
info->channels = 1;
else if (info->color_type & PNG_COLOR_MASK_COLOR)
info->channels = 3;
else
info->channels = 1;
if (info->color_type & PNG_COLOR_MASK_ALPHA)
info->channels++;
info->pixel_depth = info->channels * info->bit_depth;
info->rowbytes = ((info->width * info->pixel_depth + 7) >> 3);
}
void
1995-12-19 04:22:19 -05:00
png_read_PLTE(png_structp png_ptr, png_infop info,
png_colorp palette, int num)
1995-07-20 03:43:20 -04:00
{
if (!png_ptr || !info)
return;
info->palette = palette;
info->num_palette = num;
info->valid |= PNG_INFO_PLTE;
}
1995-09-26 06:22:39 -04:00
#if defined(PNG_READ_gAMA_SUPPORTED)
1995-07-20 03:43:20 -04:00
void
1995-12-19 04:22:19 -05:00
png_read_gAMA(png_structp png_ptr, png_infop info, double gamma)
1995-07-20 03:43:20 -04:00
{
if (!png_ptr || !info)
return;
info->gamma = gamma;
info->valid |= PNG_INFO_gAMA;
}
1995-09-26 06:22:39 -04:00
#endif
1995-07-20 03:43:20 -04:00
1995-09-26 06:22:39 -04:00
#if defined(PNG_READ_sBIT_SUPPORTED)
1995-07-20 03:43:20 -04:00
void
1995-12-19 04:22:19 -05:00
png_read_sBIT(png_structp png_ptr, png_infop info,
png_color_8p sig_bit)
1995-07-20 03:43:20 -04:00
{
if (!png_ptr || !info)
return;
1995-12-19 04:22:19 -05:00
png_memcpy(&(info->sig_bit), sig_bit, sizeof (png_color_8));
1995-07-20 03:43:20 -04:00
info->valid |= PNG_INFO_sBIT;
}
1995-09-26 06:22:39 -04:00
#endif
1995-07-20 03:43:20 -04:00
1995-09-26 06:22:39 -04:00
#if defined(PNG_READ_cHRM_SUPPORTED)
1995-07-20 03:43:20 -04:00
void
1995-12-19 04:22:19 -05:00
png_read_cHRM(png_structp png_ptr, png_infop info,
double white_x, double white_y, double red_x, double red_y,
double green_x, double green_y, double blue_x, double blue_y)
1995-07-20 03:43:20 -04:00
{
if (!png_ptr || !info)
return;
info->x_white = white_x;
info->y_white = white_y;
info->x_red = red_x;
info->y_red = red_y;
info->x_green = green_x;
info->y_green = green_y;
info->x_blue = blue_x;
info->y_blue = blue_y;
info->valid |= PNG_INFO_cHRM;
}
1995-09-26 06:22:39 -04:00
#endif
1995-07-20 03:43:20 -04:00
1995-09-26 06:22:39 -04:00
#if defined(PNG_READ_tRNS_SUPPORTED)
1995-07-20 03:43:20 -04:00
void
1995-12-19 04:22:19 -05:00
png_read_tRNS(png_structp png_ptr, png_infop info,
png_bytep trans, int num_trans, png_color_16p trans_values)
1995-07-20 03:43:20 -04:00
{
if (!png_ptr || !info)
return;
if (trans)
{
info->trans = trans;
}
else
{
1995-12-19 04:22:19 -05:00
png_memcpy(&(info->trans_values), trans_values,
1995-07-20 03:43:20 -04:00
sizeof(png_color_16));
}
info->num_trans = num_trans;
info->valid |= PNG_INFO_tRNS;
}
1995-09-26 06:22:39 -04:00
#endif
1995-07-20 03:43:20 -04:00
1995-09-26 06:22:39 -04:00
#if defined(PNG_READ_bKGD_SUPPORTED)
1995-07-20 03:43:20 -04:00
void
1995-12-19 04:22:19 -05:00
png_read_bKGD(png_structp png_ptr, png_infop info,
png_color_16p background)
1995-07-20 03:43:20 -04:00
{
if (!png_ptr || !info)
return;
1995-12-19 04:22:19 -05:00
png_memcpy(&(info->background), background, sizeof(png_color_16));
1995-07-20 03:43:20 -04:00
info->valid |= PNG_INFO_bKGD;
}
1995-09-26 06:22:39 -04:00
#endif
1995-07-20 03:43:20 -04:00
1995-09-26 06:22:39 -04:00
#if defined(PNG_READ_hIST_SUPPORTED)
1995-07-20 03:43:20 -04:00
void
1995-12-19 04:22:19 -05:00
png_read_hIST(png_structp png_ptr, png_infop info, png_uint_16p hist)
1995-07-20 03:43:20 -04:00
{
if (!png_ptr || !info)
return;
info->hist = hist;
info->valid |= PNG_INFO_hIST;
}
1995-09-26 06:22:39 -04:00
#endif
1995-07-20 03:43:20 -04:00
1995-09-26 06:22:39 -04:00
#if defined(PNG_READ_pHYs_SUPPORTED)
1995-07-20 03:43:20 -04:00
void
1995-12-19 04:22:19 -05:00
png_read_pHYs(png_structp png_ptr, png_infop info,
1995-07-20 03:43:20 -04:00
png_uint_32 res_x, png_uint_32 res_y, int unit_type)
{
if (!png_ptr || !info)
return;
info->x_pixels_per_unit = res_x;
info->y_pixels_per_unit = res_y;
info->phys_unit_type = unit_type;
info->valid |= PNG_INFO_pHYs;
}
1995-09-26 06:22:39 -04:00
#endif
1995-07-20 03:43:20 -04:00
1995-09-26 06:22:39 -04:00
#if defined(PNG_READ_oFFs_SUPPORTED)
1995-07-20 03:43:20 -04:00
void
1995-12-19 04:22:19 -05:00
png_read_oFFs(png_structp png_ptr, png_infop info,
1995-07-20 03:43:20 -04:00
png_uint_32 offset_x, png_uint_32 offset_y, int unit_type)
{
if (!png_ptr || !info)
return;
info->x_offset = offset_x;
info->y_offset = offset_y;
info->offset_unit_type = unit_type;
info->valid |= PNG_INFO_oFFs;
}
1995-09-26 06:22:39 -04:00
#endif
1995-07-20 03:43:20 -04:00
1995-09-26 06:22:39 -04:00
#if defined(PNG_READ_tIME_SUPPORTED)
1995-07-20 03:43:20 -04:00
void
1995-12-19 04:22:19 -05:00
png_read_tIME(png_structp png_ptr, png_infop info,
png_timep mod_time)
1995-07-20 03:43:20 -04:00
{
if (!png_ptr || !info)
return;
1995-12-19 04:22:19 -05:00
png_memcpy(&(info->mod_time), mod_time, sizeof (png_time));
1995-07-20 03:43:20 -04:00
info->valid |= PNG_INFO_tIME;
}
1995-09-26 06:22:39 -04:00
#endif
1995-07-20 03:43:20 -04:00
1995-09-26 06:22:39 -04:00
#if defined(PNG_READ_zTXt_SUPPORTED)
1995-07-20 03:43:20 -04:00
void
1995-12-19 04:22:19 -05:00
png_read_zTXt(png_structp png_ptr, png_infop info,
png_charp key, png_charp text, png_uint_32 text_len, int compression)
1995-07-20 03:43:20 -04:00
{
if (!png_ptr || !info)
return;
1995-12-19 04:22:19 -05:00
if (info->max_text <= info->num_text)
1995-07-20 03:43:20 -04:00
{
if (info->text)
{
1995-09-26 06:22:39 -04:00
png_uint_32 old_max;
old_max = info->max_text;
1995-07-20 03:43:20 -04:00
info->max_text = info->num_text + 16;
1995-12-19 04:22:19 -05:00
info->text = (png_textp)png_realloc(png_ptr,
1995-07-20 03:43:20 -04:00
info->text,
1995-09-26 06:22:39 -04:00
info->max_text * sizeof (png_text),
1995-12-19 04:22:19 -05:00
old_max * sizeof (png_text));
1995-07-20 03:43:20 -04:00
}
else
{
info->max_text = info->num_text + 16;
1995-12-19 04:22:19 -05:00
info->text = (png_textp)png_malloc(png_ptr,
1995-07-20 03:43:20 -04:00
info->max_text * sizeof (png_text));
info->num_text = 0;
}
}
info->text[info->num_text].key = key;
info->text[info->num_text].text = text;
info->text[info->num_text].text_length = text_len;
info->text[info->num_text].compression = compression;
info->num_text++;
}
1995-09-26 06:22:39 -04:00
#endif
1995-07-20 03:43:20 -04:00
1995-09-26 06:22:39 -04:00
#if defined(PNG_READ_tEXt_SUPPORTED)
1995-07-20 03:43:20 -04:00
void
1995-12-19 04:22:19 -05:00
png_read_tEXt(png_structp png_ptr, png_infop info,
png_charp key, png_charp text, png_uint_32 text_len)
1995-07-20 03:43:20 -04:00
{
if (!png_ptr || !info)
return;
1995-12-19 04:22:19 -05:00
png_read_zTXt(png_ptr, info, key, text, text_len, -1);
1995-07-20 03:43:20 -04:00
}
1995-09-26 06:22:39 -04:00
#endif
1995-07-20 03:43:20 -04:00