本文整理汇总了C++中png_read_end函数的典型用法代码示例。如果您正苦于以下问题:C++ png_read_end函数的具体用法?C++ png_read_end怎么用?C++ png_read_end使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了png_read_end函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: LoadPNG
//.........这里部分代码省略.........
png_structp pp; // PNG read pointer
png_infop info; // PNG info pointers
png_bytep *rows; // PNG row pointers
// Open the PNG file...
if ((fp = fopen(png, "rb")) == NULL) return;
// Setup the PNG data structures...
pp = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
info = png_create_info_struct(pp);
if (setjmp(pp->jmpbuf))
{
int debug = 1;
return;
}
// Initialize the PNG read "engine"...
png_init_io(pp, fp);
// Get the image dimensions and convert to grayscale or RGB...
png_read_info(pp, info);
if (info->color_type == PNG_COLOR_TYPE_PALETTE)
png_set_expand(pp);
if (info->color_type & PNG_COLOR_MASK_COLOR)
channels = 3;
else
channels = 1;
if ((info->color_type & PNG_COLOR_MASK_ALPHA) || info->num_trans)
channels ++;
int w = (int)(info->width);
int h = (int)(info->height);
int d = channels;
pictureWidth = w;
pictureHeight = h;
if (info->bit_depth < 8)
{
png_set_packing(pp);
png_set_expand(pp);
}
else if (info->bit_depth == 16)
png_set_strip_16(pp);
# if defined(HAVE_PNG_GET_VALID) && defined(HAVE_PNG_SET_TRNS_TO_ALPHA)
// Handle transparency...
if (png_get_valid(pp, info, PNG_INFO_tRNS))
png_set_tRNS_to_alpha(pp);
# endif // HAVE_PNG_GET_VALID && HAVE_PNG_SET_TRNS_TO_ALPHA
unsigned char *array = (unsigned char *)pictureS;
// Allocate pointers...
rows = new png_bytep[h];
for (i = 0; i < h; i ++)
rows[i] = (png_bytep)(array + i * w * d); // we flip it
// Read the image, handling interlacing as needed...
for (i = png_set_interlace_handling(pp); i > 0; i --)
png_read_rows(pp, rows, NULL, h);
#ifdef WIN32
// Some Windows graphics drivers don't honor transparency when RGB == white
if (channels == 4)
{
// Convert RGB to 0 when alpha == 0...
unsigned char *ptr = (unsigned char *)array;
for (i = w * h; i > 0; i --, ptr += 4)
if (!ptr[3]) ptr[0] = ptr[1] = ptr[2] = 0;
}
#endif // WIN32
if (channels == 3)
{
unsigned char *array2 = new unsigned char[pictureWidth * pictureHeight * 4];
for (int i = w * h - 1; i >= 0; --i)
{
array2[i*4+0] = array[i*3+0];
array2[i*4+1] = array[i*3+1];
array2[i*4+2] = array[i*3+2];
array2[i*4+3] = 255;
}
memcpy(array, array2, w * h * 4);
delete[] array2;
}
// Free memory and return...
delete[] rows;
png_read_end(pp, info);
png_destroy_read_struct(&pp, &info, NULL);
fclose(fp);
}
示例2: replaceBootImage
//.........这里部分代码省略.........
if (setjmp(png_jmpbuf(png_ptr)))
{
XLOG(0, "error reading png\n");
png_destroy_read_struct(&png_ptr, &info_ptr, &end_info);
free(buffer);
return NULL;
}
png_set_read_fn(png_ptr, png, pngRead);
png_read_info(png_ptr, info_ptr);
if(info_ptr->bit_depth > 8) {
XLOG(0, "warning: bit depth per channel is greater than 8 (%d). Attempting to strip, but image quality will be degraded.\n", info_ptr->bit_depth);
}
if(info_ptr->color_type == PNG_COLOR_TYPE_GRAY || info_ptr->color_type == PNG_COLOR_TYPE_RGB) {
XLOG(0, "notice: attempting to add dummy transparency channel\n");
}
if(info_ptr->color_type == PNG_COLOR_TYPE_PALETTE) {
XLOG(0, "notice: attempting to expand palette into full rgb\n");
}
png_set_expand(png_ptr);
png_set_strip_16(png_ptr);
png_set_bgr(png_ptr);
png_set_add_alpha(png_ptr, 0x0, PNG_FILLER_AFTER);
png_set_invert_alpha(png_ptr);
png_read_update_info(png_ptr, info_ptr);
if(info_ptr->width > 320 || info_ptr->height > 480) {
XLOG(0, "error: dimensions out of range, must be within 320x480, not %lux%lu\n", info_ptr->width, info_ptr->height);
png_destroy_read_struct(&png_ptr, &info_ptr, &end_info);
return NULL;
}
if(info_ptr->bit_depth != 8) {
XLOG(0, "error: bit depth per channel must be 8 not %d!\n", info_ptr->bit_depth);
png_destroy_read_struct(&png_ptr, &info_ptr, &end_info);
return NULL;
}
if(info_ptr->color_type != PNG_COLOR_TYPE_GRAY_ALPHA && info_ptr->color_type != PNG_COLOR_TYPE_RGB_ALPHA) {
XLOG(0, "error: incorrect color type, must be greyscale with alpha, or rgb with alpha\n");
if(info_ptr->color_type == PNG_COLOR_TYPE_GRAY || info_ptr->color_type == PNG_COLOR_TYPE_RGB) {
XLOG(0, "It appears you're missing an alpha channel. Add transparency to your image\n");
}
if(info_ptr->color_type == PNG_COLOR_TYPE_PALETTE) {
XLOG(0, "This PNG is saved with the palette color type rather than ARGB.\n");
}
png_destroy_read_struct(&png_ptr, &info_ptr, &end_info);
return NULL;
}
row_pointers = (png_bytepp) malloc(sizeof(png_bytep) * info_ptr->height);
imageBuffer = malloc(info_ptr->height * info_ptr->rowbytes);
for(i = 0; i < info_ptr->height; i++) {
row_pointers[i] = imageBuffer + (info_ptr->rowbytes * i);
}
png_read_image(png_ptr, row_pointers);
png_read_end(png_ptr, end_info);
buffer = malloc(1);
*fileSize = 0;
if(key != NULL) {
imageFile = duplicateAbstractFile2(imageWrapper, createAbstractFileFromMemoryFile((void**)&buffer, fileSize), key, iv, NULL);
} else {
imageFile = duplicateAbstractFile(imageWrapper, createAbstractFileFromMemoryFile((void**)&buffer, fileSize));
}
info = (InfoIBootIM*) (imageFile->data);
info->header.width = (uint16_t) info_ptr->width;
info->header.height = (uint16_t) info_ptr->height;
if(info_ptr->color_type == PNG_COLOR_TYPE_GRAY_ALPHA) {
info->header.format = IBOOTIM_GREY;
} else {
info->header.format = IBOOTIM_ARGB;
}
imageFile->write(imageFile, imageBuffer, info_ptr->height * info_ptr->rowbytes);
imageFile->close(imageFile);
png_destroy_read_struct(&png_ptr, &info_ptr, &end_info);
png->close(png);
free(row_pointers);
free(imageBuffer);
return buffer;
}
示例3: Read
//.........这里部分代码省略.........
}
info_ptr = png_create_info_struct (png_ptr);
if ( setjmp (png_jmpbuf (png_ptr)) )
{
return 0;
}
// We've read the signature
offset += SIGNATURE_LEN;
// Setup reading information, and read header
png_set_read_fn (png_ptr, (png_voidp)this, &user_read_data);
#ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED
// This generic "ignore all, except required chunks" requires 1.6.0 or newer"
png_set_keep_unknown_chunks (png_ptr, PNG_HANDLE_CHUNK_NEVER, NULL, -1);
#endif
png_set_sig_bytes (png_ptr, SIGNATURE_LEN);
png_read_info (png_ptr, info_ptr);
png_uint_32 width_;
png_uint_32 height_;
int depth;
int colortype;
png_get_IHDR (png_ptr, info_ptr, &width_, &height_, &depth, &colortype, NULL, NULL, NULL);
// While modern OpenGL can handle non-PoT textures, it's faster to handle only PoT
// so that the graphics driver doesn't have to fiddle about with the texture when uploading.
if ( !IsPowerOfTwo (width_) || !IsPowerOfTwo (height_) )
{
ri->Printf (PRINT_ERROR, "Width or height is not a power-of-two.\n");
return 0;
}
// This function is equivalent to using what used to be LoadPNG32. LoadPNG8 also existed,
// but this only seemed to be used by the RMG system which does not work in JKA. If this
// does need to be re-implemented, then colortype should be PNG_COLOR_TYPE_PALETTE or
// PNG_COLOR_TYPE_GRAY.
if ( colortype != PNG_COLOR_TYPE_RGB && colortype != PNG_COLOR_TYPE_RGBA )
{
ri->Printf (PRINT_ERROR, "Image is not 24-bit or 32-bit.");
return 0;
}
// Read the png data
if ( colortype == PNG_COLOR_TYPE_RGB )
{
// Expand RGB -> RGBA
png_set_add_alpha (png_ptr, 0xff, PNG_FILLER_AFTER);
}
png_read_update_info (png_ptr, info_ptr);
// We always assume there are 4 channels. RGB channels are expanded to RGBA when read.
byte *tempData = (byte *)ri->Z_Malloc (width_ * height_ * 4, TAG_TEMP_PNG, qfalse, 4);
if ( !tempData )
{
ri->Printf (PRINT_ERROR, "Could not allocate enough memory to load the image.");
return 0;
}
// Dynamic array of row pointers, with 'height' elements, initialized to NULL.
byte **row_pointers = (byte **)ri->Hunk_AllocateTempMemory (sizeof (byte *) * height_);
if ( !row_pointers )
{
ri->Printf (PRINT_ERROR, "Could not allocate enough memory to load the image.");
ri->Z_Free (tempData);
return 0;
}
// Re-set the jmp so that these new memory allocations can be reclaimed
if ( setjmp (png_jmpbuf (png_ptr)) )
{
ri->Hunk_FreeTempMemory (row_pointers);
ri->Z_Free (tempData);
return 0;
}
for ( unsigned int i = 0, j = 0; i < height_; i++, j += 4 )
{
row_pointers[i] = tempData + j * width_;
}
png_read_image (png_ptr, row_pointers);
// Finish reading
png_read_end (png_ptr, NULL);
ri->Hunk_FreeTempMemory (row_pointers);
// Finally assign all the parameters
*data = tempData;
*width = width_;
*height = height_;
return 1;
}
示例4: png_create_read_struct
//.........这里部分代码省略.........
break;
if(i == num_trans) {
/* exactly one transparent index */
ckey = t;
} else {
/* more than one transparent index, or translucency */
png_set_expand(png_ptr);
}
} else
ckey = 0; /* actual value will be set later */
}
if ( color_type == PNG_COLOR_TYPE_GRAY_ALPHA )
png_set_gray_to_rgb(png_ptr);
png_read_update_info(png_ptr, info_ptr);
png_get_IHDR(png_ptr, info_ptr, &width, &height, &bit_depth,
&color_type, &interlace_type, NULL, NULL);
/* Allocate the SDL surface to hold the image */
Rmask = Gmask = Bmask = Amask = 0 ;
if ( color_type != PNG_COLOR_TYPE_PALETTE ) {
if ( SDL_BYTEORDER == SDL_LIL_ENDIAN ) {
Rmask = 0x000000FF;
Gmask = 0x0000FF00;
Bmask = 0x00FF0000;
Amask = (info_ptr->channels == 4) ? 0xFF000000 : 0;
} else {
int s = (info_ptr->channels == 4) ? 0 : 8;
Rmask = 0xFF000000 >> s;
Gmask = 0x00FF0000 >> s;
Bmask = 0x0000FF00 >> s;
Amask = 0x000000FF >> s;
}
}
surface = SDL_AllocSurface(SDL_SWSURFACE, width, height,
bit_depth*info_ptr->channels, Rmask,Gmask,Bmask,Amask);
if ( surface == NULL ) {
IMG_SetError("Out of memory");
goto done;
}
if(ckey != -1) {
if(color_type != PNG_COLOR_TYPE_PALETTE)
/* FIXME: Should these be truncated or shifted down? */
ckey = SDL_MapRGB(surface->format,
(Uint8)transv->red,
(Uint8)transv->green,
(Uint8)transv->blue);
SDL_SetColorKey(surface, SDL_SRCCOLORKEY, ckey);
}
/* Create the array of pointers to image data */
row_pointers = (png_bytep*) malloc(sizeof(png_bytep)*height);
if ( (row_pointers == NULL) ) {
IMG_SetError("Out of memory");
SDL_FreeSurface(surface);
surface = NULL;
goto done;
}
for (row = 0; row < (int)height; row++) {
row_pointers[row] = (png_bytep)
(Uint8 *)surface->pixels + row*surface->pitch;
}
/* Read the entire image in one go */
png_read_image(png_ptr, row_pointers);
/* read rest of file, get additional chunks in info_ptr - REQUIRED */
png_read_end(png_ptr, info_ptr);
/* Load the palette, if any */
palette = surface->format->palette;
if ( palette ) {
if(color_type == PNG_COLOR_TYPE_GRAY) {
palette->ncolors = 256;
for(i = 0; i < 256; i++) {
palette->colors[i].r = i;
palette->colors[i].g = i;
palette->colors[i].b = i;
}
} else if (info_ptr->num_palette > 0 ) {
palette->ncolors = info_ptr->num_palette;
for( i=0; i<info_ptr->num_palette; ++i ) {
palette->colors[i].b = info_ptr->palette[i].blue;
palette->colors[i].g = info_ptr->palette[i].green;
palette->colors[i].r = info_ptr->palette[i].red;
}
}
}
done: /* Clean up and return */
png_destroy_read_struct(&png_ptr, info_ptr ? &info_ptr : (png_infopp)0,
(png_infopp)0);
if ( row_pointers ) {
free(row_pointers);
}
return(surface);
}
示例5: gegl_buffer_import_png
//.........这里部分代码省略.........
if (color_type == PNG_COLOR_TYPE_GRAY && bit_depth < 8)
{
png_set_expand (load_png_ptr);
bit_depth = 8;
}
if (png_get_valid (load_png_ptr, load_info_ptr, PNG_INFO_tRNS))
{
png_set_tRNS_to_alpha (load_png_ptr);
color_type |= PNG_COLOR_MASK_ALPHA;
}
switch (color_type)
{
case PNG_COLOR_TYPE_GRAY:
bpp = 1;
break;
case PNG_COLOR_TYPE_GRAY_ALPHA:
bpp = 2;
break;
case PNG_COLOR_TYPE_RGB:
bpp = 3;
break;
case PNG_COLOR_TYPE_RGB_ALPHA:
bpp = 4;
break;
case (PNG_COLOR_TYPE_PALETTE | PNG_COLOR_MASK_ALPHA):
bpp = 4;
break;
case PNG_COLOR_TYPE_PALETTE:
bpp = 3;
break;
default:
g_warning ("color type mismatch");
png_destroy_read_struct (&load_png_ptr, &load_info_ptr, NULL);
return -1;
}
if (color_type == PNG_COLOR_TYPE_PALETTE)
png_set_palette_to_rgb (load_png_ptr);
if (bit_depth == 16)
bpp = bpp << 1;
if (!format)
format = get_babl_format(bit_depth, color_type);
#if BYTE_ORDER == LITTLE_ENDIAN
if (bit_depth == 16)
png_set_swap (load_png_ptr);
#endif
if (interlace_type == PNG_INTERLACE_ADAM7)
number_of_passes = png_set_interlace_handling (load_png_ptr);
if (png_get_valid (load_png_ptr, load_info_ptr, PNG_INFO_gAMA))
{
gdouble gamma;
png_get_gAMA (load_png_ptr, load_info_ptr, &gamma);
png_set_gamma (load_png_ptr, 2.2, gamma);
}
else
{
png_set_gamma (load_png_ptr, 2.2, 0.45455);
}
png_read_update_info (load_png_ptr, load_info_ptr);
}
pixels = g_malloc0 (width*bpp);
{
gint pass;
GeglRectangle rect;
for (pass=0; pass<number_of_passes; pass++)
{
for(i=0; i<h; i++)
{
gegl_rectangle_set (&rect, 0, i, width, 1);
if (pass != 0)
gegl_buffer_get (gegl_buffer, &rect, 1.0, format, pixels, GEGL_AUTO_ROWSTRIDE, GEGL_ABYSS_NONE);
png_read_rows (load_png_ptr, &pixels, NULL, 1);
gegl_buffer_set (gegl_buffer, &rect, 0, format, pixels,
GEGL_AUTO_ROWSTRIDE);
}
}
}
png_read_end (load_png_ptr, NULL);
png_destroy_read_struct (&load_png_ptr, &load_info_ptr, NULL);
g_free (pixels);
return 0;
}
示例6: initSludge
//.........这里部分代码省略.........
png_read_info(png_ptr, info_ptr);
png_uint_32 width, height;
int bit_depth, color_type, interlace_type, compression_type, filter_method;
png_get_IHDR(png_ptr, info_ptr, &width, &height, &bit_depth, &color_type, &interlace_type, &compression_type, &filter_method);
iconW = width;
iconH = height;
if (bit_depth < 8) png_set_packing(png_ptr);
png_set_expand(png_ptr);
if (color_type == PNG_COLOR_TYPE_GRAY || color_type == PNG_COLOR_TYPE_GRAY_ALPHA) png_set_gray_to_rgb(png_ptr);
if (bit_depth == 16) png_set_strip_16(png_ptr);
png_set_add_alpha(png_ptr, 0xff, PNG_FILLER_AFTER);
png_read_update_info(png_ptr, info_ptr);
png_get_IHDR(png_ptr, info_ptr, &width, &height, &bit_depth, &color_type, &interlace_type, &compression_type, &filter_method);
}
gameIcon = new unsigned char [iconW*iconH*4];
if (! gameIcon) return fatal ("Can't reserve memory for game icon.");
int32_t transCol = 63519;
Uint8 *p = (Uint8 *) gameIcon;
if (fileIsPNG) {
unsigned char * row_pointers[iconH];
for (int i = 0; i<iconH; i++)
row_pointers[i] = p + 4*i*iconW;
png_read_image(png_ptr, (png_byte **) row_pointers);
png_read_end(png_ptr, NULL);
png_destroy_read_struct(&png_ptr, &info_ptr, &end_info);
} else {
for (int t2 = 0; t2 < iconH; t2 ++) {
int t1 = 0;
while (t1 < iconW) {
unsigned short c = (unsigned short) get2bytes (fp);
if (c & 32) {
n = fgetc (fp) + 1;
c -= 32;
} else {
n = 1;
}
while (n --) {
*p++ = (Uint8) redValue(c);
*p++ = (Uint8) greenValue(c);
*p++ = (Uint8) blueValue(c);
*p++ = (Uint8) (c == transCol) ? 0 : 255;
t1++;
}
}
}
}
}
if (customIconLogo & 2) {
// There is an logo - read it!
int n;
long file_pointer = ftell (fp);
示例7: glmReadPNG
//.........这里部分代码省略.........
/* The call to png_read_info() gives us all of the information from the
* PNG file before the first IDAT (image data chunk). REQUIRED
*/
png_read_info(png_ptr, info_ptr);
png_get_IHDR(png_ptr, info_ptr, &width, &height, &bit_depth, &color_type,
&interlace_type, NULL, NULL);
/**** Set up the data transformations you want. Note that these are all
**** optional. Only call them if you want/need them. Many of the
**** transformations only work on specific types of images, and many
**** are mutually exclusive.
****/
/* tell libpng to strip 16 bit/color files down to 8 bits/color */
png_set_strip_16(png_ptr);
/* strip alpha bytes from the input data without combining with th
* background (not recommended) */
/* png_set_strip_alpha(png_ptr); */
/* extract multiple pixels with bit depths of 1, 2, and 4 from a single
* byte into separate bytes (useful for paletted and grayscale images).
*/
/* png_set_packing(png_ptr); */
/* change the order of packed pixels to least significant bit first
* (not useful if you are using png_set_packing). */
/* png_set_packswap(png_ptr); */
/* expand paletted colors into true RGB triplets */
if (color_type == PNG_COLOR_TYPE_PALETTE)
png_set_expand(png_ptr);
/* expand grayscale images to the full 8 bits from 1, 2, or 4 bits/pixel */
if (color_type == PNG_COLOR_TYPE_GRAY && bit_depth < 8)
png_set_expand(png_ptr);
/* expand paletted or RGB images with transparency to full alpha channels
* so the data will be available as RGBA quartets */
if (png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS))
png_set_expand(png_ptr);
/* Add filler (or alpha) byte (before/after each RGB triplet) */
/* png_set_filler(png_ptr, 0xff, PNG_FILLER_AFTER); */
png_read_update_info(png_ptr, info_ptr);
channels = png_get_channels(png_ptr, info_ptr);
/* allocate the memory to hold the image using the fields of info_ptr. */
bytes_per_row = png_get_rowbytes(png_ptr, info_ptr);
buffer = (unsigned char*) malloc(bytes_per_row*height);
format = channels;
row_pointers = (png_bytepp) malloc(height*sizeof(png_bytep));
for (y = 0; y < height; y++) {
row_pointers[height-y-1] = buffer + y*bytes_per_row;
}
png_read_image(png_ptr, row_pointers);
png_read_end(png_ptr, info_ptr);
free(row_pointers);
/* clean up after the read, and free any memory allocated - REQUIRED */
png_destroy_read_struct(&png_ptr, &info_ptr, (png_infopp)NULL);
/* close the file */
fclose(fp);
/* that's it */
if (buffer) {
*width_ret = width;
*height_ret = height;
switch(format) {
case 1:
*type_ret = GL_LUMINANCE;
break;
case 2:
*type_ret = GL_LUMINANCE_ALPHA;
break;
case 3:
*type_ret = GL_RGB;
break;
case 4:
*type_ret = GL_RGBA;
break;
}
pngerror = ERR_NO_ERROR;
}
else {
pngerror = ERR_MEM;
}
return buffer;
}
示例8: autoClean
//.........这里部分代码省略.........
SkAutoLockPixels alp(*decodedBitmap);
/* Add filler (or alpha) byte (before/after each RGB triplet) */
if (color_type == PNG_COLOR_TYPE_RGB || color_type == PNG_COLOR_TYPE_GRAY) {
png_set_filler(png_ptr, 0xff, PNG_FILLER_AFTER);
}
/* Turn on interlace handling. REQUIRED if you are not using
* png_read_image(). To see how to handle interlacing passes,
* see the png_read_row() method below:
*/
const int number_passes = interlace_type != PNG_INTERLACE_NONE ?
png_set_interlace_handling(png_ptr) : 1;
/* Optional call to gamma correct and add the background to the palette
* and update info structure. REQUIRED if you are expecting libpng to
* update the palette for you (ie you selected such a transform above).
*/
png_read_update_info(png_ptr, info_ptr);
if (SkBitmap::kIndex8_Config == config && 1 == sampleSize) {
for (int i = 0; i < number_passes; i++) {
for (png_uint_32 y = 0; y < origHeight; y++) {
uint8_t* bmRow = decodedBitmap->getAddr8(0, y);
png_read_rows(png_ptr, &bmRow, png_bytepp_NULL, 1);
}
}
} else {
SkScaledBitmapSampler::SrcConfig sc;
int srcBytesPerPixel = 4;
if (colorTable != NULL) {
sc = SkScaledBitmapSampler::kIndex;
srcBytesPerPixel = 1;
} else if (hasAlpha) {
sc = SkScaledBitmapSampler::kRGBA;
} else {
sc = SkScaledBitmapSampler::kRGBX;
}
/* We have to pass the colortable explicitly, since we may have one
even if our decodedBitmap doesn't, due to the request that we
upscale png's palette to a direct model
*/
SkAutoLockColors ctLock(colorTable);
if (!sampler.begin(decodedBitmap, sc, doDither, ctLock.colors())) {
return false;
}
const int height = decodedBitmap->height();
if (number_passes > 1) {
SkAutoMalloc storage(origWidth * origHeight * srcBytesPerPixel);
uint8_t* base = (uint8_t*)storage.get();
size_t rb = origWidth * srcBytesPerPixel;
for (int i = 0; i < number_passes; i++) {
uint8_t* row = base;
for (png_uint_32 y = 0; y < origHeight; y++) {
uint8_t* bmRow = row;
png_read_rows(png_ptr, &bmRow, png_bytepp_NULL, 1);
row += rb;
}
}
// now sample it
base += sampler.srcY0() * rb;
for (int y = 0; y < height; y++) {
reallyHasAlpha |= sampler.next(base);
base += sampler.srcDY() * rb;
}
} else {
SkAutoMalloc storage(origWidth * srcBytesPerPixel);
uint8_t* srcRow = (uint8_t*)storage.get();
skip_src_rows(png_ptr, srcRow, sampler.srcY0());
for (int y = 0; y < height; y++) {
uint8_t* tmp = srcRow;
png_read_rows(png_ptr, &tmp, png_bytepp_NULL, 1);
reallyHasAlpha |= sampler.next(srcRow);
if (y < height - 1) {
skip_src_rows(png_ptr, srcRow, sampler.srcDY() - 1);
}
}
// skip the rest of the rows (if any)
png_uint_32 read = (height - 1) * sampler.srcDY() +
sampler.srcY0() + 1;
SkASSERT(read <= origHeight);
skip_src_rows(png_ptr, srcRow, origHeight - read);
}
}
/* read rest of file, and get additional chunks in info_ptr - REQUIRED */
png_read_end(png_ptr, info_ptr);
if (0 != theTranspColor) {
reallyHasAlpha |= substituteTranspColor(decodedBitmap, theTranspColor);
}
decodedBitmap->setIsOpaque(!reallyHasAlpha);
return true;
}
示例9: main
//.........这里部分代码省略.........
found = FALSE;
if ( num_not_found < MAX_NOT_FOUND ) {
for (k = 0; k < num_not_found; k++) {
if ( red == rednotfound[k] &&
green == greennotfound[k] &&
blue == bluenotfound[k] ) {
found = TRUE;
break;
}
}
if ( !found ) {
rednotfound[num_not_found] = red;
greennotfound[num_not_found] = green;
bluenotfound[num_not_found] = blue;
num_not_found++;
}
}
}
}
}
if ( num_not_found > 0 ) {
return_code = num_not_found;
fprintf(stderr, "%d Colors in image not found in color table\n", num_not_found);
for (k = 0; k < num_not_found; k++) {
fprintf(stderr, "%3d %3d %3d\n", rednotfound[k], greennotfound[k], bluenotfound[k]);
}
}
// Done with the read, clean up
free(row_pointers);
row_pointers = NULL;
png_read_end(in_png_ptr, NULL);
free(image_data);
image_data = NULL;
fclose(fp);
// Start the write
if (strcmp(filename2, "stdout") == 0)
fd = stdout;
else if ( (fd = fopen(filename2, "wb")) == NULL ) {
fprintf(stderr, "Cannot open file %s.\n", filename2);
exit(-1);
}
// Initialize write structure
png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
if (png_ptr == NULL) {
fprintf(stderr, "Could not allocate PNG write struct\n");
exit(-1);
}
// Initialize info structure
info_ptr = png_create_info_struct(png_ptr);
if (info_ptr == NULL) {
fprintf(stderr, "Could not allocate PNG info struct\n");
exit(-1);
}
if (setjmp(png_jmpbuf(png_ptr))) {
fprintf(stderr, "Error during PNG init_io\n");
exit(-1);
示例10: fh_png_load
int fh_png_load(const char *name, unsigned char *buffer, int x, int y)
{
static const png_color_16 my_background = {0, 0, 0, 0, 0};
png_structp png_ptr;
png_infop info_ptr;
png_uint_32 width, height;
unsigned int i;
int bit_depth, color_type, interlace_type;
int number_passes, pass;
png_byte * fbptr;
FILE * fh;
if (!(fh = fopen(name, "rb")))
return(FH_ERROR_FILE);
png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
if (png_ptr == NULL)
return(FH_ERROR_FORMAT);
info_ptr = png_create_info_struct(png_ptr);
if (info_ptr == NULL)
{
png_destroy_read_struct(&png_ptr, (png_infopp)NULL, (png_infopp)NULL);
fclose(fh);
return(FH_ERROR_FORMAT);
}
if (setjmp(png_ptr->jmpbuf))
{
png_destroy_read_struct(&png_ptr, &info_ptr, (png_infopp)NULL);
fclose(fh);
return(FH_ERROR_FORMAT);
}
png_init_io(png_ptr, fh);
png_read_info(png_ptr, info_ptr);
png_get_IHDR(png_ptr, info_ptr, &width, &height, &bit_depth, &color_type, &interlace_type, NULL, NULL);
if (color_type == PNG_COLOR_TYPE_PALETTE)
{
png_set_palette_to_rgb(png_ptr);
png_set_background(png_ptr, (png_color_16 *)&my_background, PNG_BACKGROUND_GAMMA_SCREEN, 0, 1.0);
/* other possibility for png_set_background: use png_get_bKGD */
}
if (color_type == PNG_COLOR_TYPE_GRAY ||
color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
{
png_set_gray_to_rgb(png_ptr);
png_set_background(png_ptr, (png_color_16 *)&my_background, PNG_BACKGROUND_GAMMA_SCREEN, 0, 1.0);
}
if (color_type & PNG_COLOR_MASK_ALPHA)
png_set_strip_alpha(png_ptr);
if (bit_depth < 8)
png_set_packing(png_ptr);
if (bit_depth == 16)
png_set_strip_16(png_ptr);
/* on Intel PC ?:
if (bit_depth == 16)
png_set_swap(png_ptr);
*/
number_passes = png_set_interlace_handling(png_ptr);
png_read_update_info(png_ptr, info_ptr);
if (width * 3 != png_get_rowbytes(png_ptr, info_ptr))
{
printf("[png.cpp]: Error processing %s - please report (including image).\n", name);
return(FH_ERROR_FORMAT);
}
for(pass = 0; pass < number_passes; pass++)
{
fbptr = (png_byte *)buffer;
for (i = 0; i < height; i++, fbptr += width * 3)
{
png_read_row(png_ptr, fbptr, NULL);
}
}
png_read_end(png_ptr, info_ptr);
png_destroy_read_struct(&png_ptr, &info_ptr, (png_infopp)NULL);
fclose(fh);
return(FH_ERROR_OK);
}
示例11: fopen
void t_RenderClass::loadTexture(int target, const char *filename)
{
FILE *theFile = fopen(filename,"rb");
if (!theFile)
{
LOGI("Fopen failed");
exit(1);
}
char header[8];
fread(header,1,8,theFile);
if (ferror(theFile))
{
LOGI("Fread failed");
exit(1);
}
if (png_sig_cmp((png_byte *) header,0,8))
{
LOGI("The file is not a png\n");
exit(1);
}
png_structp png_ptr = png_create_read_struct(
PNG_LIBPNG_VER_STRING,
NULL,NULL,NULL
);
if (!png_ptr)
{
printf("Failed initialization of png_ptr\n");
exit(1);
}
png_infop info_ptr = png_create_info_struct(png_ptr);
if (!info_ptr)
{
png_destroy_read_struct(&png_ptr,
(png_infopp)NULL, (png_infopp)NULL);
printf("Info ptr creation failed\n");
exit(1);
}
png_infop end_info = png_create_info_struct(png_ptr);
if (!end_info)
{
png_destroy_read_struct(&png_ptr, &info_ptr,
(png_infopp)NULL);
printf("Info ptr creation failed\n");
exit(1);
}
png_init_io(png_ptr,theFile);
png_set_sig_bytes(png_ptr,8);
png_read_info(png_ptr,info_ptr);
int width = png_get_image_width(png_ptr,info_ptr);
int height = png_get_image_width(png_ptr,info_ptr);
int depth = png_get_bit_depth(png_ptr,info_ptr);
int rowbytes = png_get_rowbytes(png_ptr, info_ptr);
png_byte* image_data = new png_byte[rowbytes * height];
png_bytep *row_pointers = new png_bytep [height];
for (int i = 0; i < height; ++i)
{
row_pointers[i] = image_data + i * rowbytes;
}
LOGI("I have read the image with width %d, height %d, depth %d, rowbytes %d\n",width,height,depth,rowbytes);
png_read_image(png_ptr,row_pointers);
png_read_end(png_ptr,NULL);
png_destroy_read_struct(&png_ptr, &info_ptr, &end_info);
glTexImage2D(GL_TEXTURE_2D,0,GL_RGBA,width,height,0,GL_RGBA,GL_UNSIGNED_BYTE,image_data);
checkGlError("glClear");
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
checkGlError("glClear");
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
checkGlError("glClear");
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
checkGlError("glClear");
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
checkGlError("glClear");
}
示例12: png_create_info_struct
uint8_t* ImageDecoder::decodePNGImpl(png_structp pngPtr, uint32_t* width, uint32_t* height)
{
png_bytep* rowPtrs = NULL;
uint8_t* outData = NULL;
png_infop infoPtr = png_create_info_struct(pngPtr);
if (!infoPtr)
{
LOG(LOG_ERROR,"Couldn't initialize png info struct");
png_destroy_read_struct(&pngPtr, (png_infopp)0, (png_infopp)0);
return NULL;
}
if (setjmp(png_jmpbuf(pngPtr)))
{
png_destroy_read_struct(&pngPtr, &infoPtr,(png_infopp)0);
if (rowPtrs != NULL) delete [] rowPtrs;
if (outData != NULL) delete [] outData;
LOG(LOG_ERROR,"error during reading of the png file");
return NULL;
}
png_read_info(pngPtr, infoPtr);
*width = png_get_image_width(pngPtr, infoPtr);
*height = png_get_image_height(pngPtr, infoPtr);
//bits per CHANNEL! note: not per pixel!
png_uint_32 bitdepth = png_get_bit_depth(pngPtr, infoPtr);
//Number of channels
png_uint_32 channels = png_get_channels(pngPtr, infoPtr);
//Color type. (RGB, RGBA, Luminance, luminance alpha... palette... etc)
png_uint_32 color_type = png_get_color_type(pngPtr, infoPtr);
// Transform everything into 24 bit RGB
switch (color_type)
{
case PNG_COLOR_TYPE_PALETTE:
png_set_palette_to_rgb(pngPtr);
// png_set_palette_to_rgb wil convert into 32
// bit, but we don't want the alpha
png_set_strip_alpha(pngPtr);
break;
case PNG_COLOR_TYPE_GRAY:
if (bitdepth < 8)
png_set_gray_to_rgb(pngPtr);
break;
}
if (bitdepth == 16)
{
png_set_strip_16(pngPtr);
}
if (channels > 3)
{
LOG(LOG_NOT_IMPLEMENTED, "Alpha channel not supported in PNG");
png_set_strip_alpha(pngPtr);
}
// Update the infoPtr to reflect the transformations set
// above. Read new values by calling png_get_* again.
png_read_update_info(pngPtr, infoPtr);
//bitdepth = png_get_bit_depth(pngPtr, infoPtr);
//color_type = png_get_color_type(pngPtr, infoPtr);
channels = png_get_channels(pngPtr, infoPtr);
if (channels != 3)
{
// Should never get here because of the
// transformations
LOG(LOG_NOT_IMPLEMENTED, "Unexpected number of channels in PNG!");
png_destroy_read_struct(&pngPtr, &infoPtr,(png_infopp)0);
return NULL;
}
const unsigned int stride = png_get_rowbytes(pngPtr, infoPtr);
outData = new uint8_t[(*height) * stride];
rowPtrs = new png_bytep[(*height)];
for (size_t i = 0; i < (*height); i++)
{
rowPtrs[i] = (png_bytep)outData + i* stride;
}
png_read_image(pngPtr, rowPtrs);
png_read_end(pngPtr, NULL);
png_destroy_read_struct(&pngPtr, &infoPtr,(png_infopp)0);
delete[] (png_bytep)rowPtrs;
return outData;
}
示例13: fopen
unsigned char *read_png_file(const char* file_name, int *width, int *height,
int *stride) {
png_byte color_type;
png_byte bit_depth;
png_structp png_ptr;
png_infop info_ptr;
int number_of_passes;
png_bytep* row_pointers;
int y;
unsigned char header[8]; // 8 is the maximum size that can be checked
unsigned char *buf;
FILE *fp;
/* open file and test for it being a png */
fp = fopen(file_name, "rb");
if (!fp) return NULL;
fread(header, 1, 8, fp);
if (png_sig_cmp(header, 0, 8)) {
roadmap_log (ROADMAP_ERROR,
"[read_png_file] File %s is not recognized as a PNG file",
file_name);
fclose(fp);
return NULL;
}
/* initialize stuff */
png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
if (!png_ptr) {
roadmap_log (ROADMAP_ERROR,
"[read_png_file] png_create_read_struct failed");
fclose(fp);
return NULL;
}
info_ptr = png_create_info_struct(png_ptr);
if (!info_ptr) {
roadmap_log (ROADMAP_ERROR,
"[read_png_file] png_create_info_struct failed");
fclose(fp);
return NULL;
}
if (setjmp(png_jmpbuf(png_ptr))) {
roadmap_log (ROADMAP_ERROR, "[read_png_file] Error during init_io");
fclose(fp);
return NULL;
}
png_init_io(png_ptr, fp);
png_set_sig_bytes(png_ptr, 8);
png_read_info(png_ptr, info_ptr);
*width = info_ptr->width;
*height = info_ptr->height;
*stride = info_ptr->rowbytes;
color_type = info_ptr->color_type;
bit_depth = info_ptr->bit_depth;
number_of_passes = png_set_interlace_handling(png_ptr);
png_read_update_info(png_ptr, info_ptr);
/* read file */
if (setjmp(png_jmpbuf(png_ptr))) {
roadmap_log (ROADMAP_ERROR, "[read_png_file] Error during read_image");
fclose(fp);
return NULL;
}
row_pointers = (png_bytep*) malloc(sizeof(png_bytep) * *height);
buf = malloc (*height * info_ptr->rowbytes);
for (y=0; y<*height; y++) {
row_pointers[y] = (png_byte*) (buf + y * info_ptr->rowbytes);
}
png_read_image(png_ptr, row_pointers);
png_read_end(png_ptr, NULL);
png_destroy_read_struct (&png_ptr, &info_ptr, NULL);
free (row_pointers);
fclose(fp);
return buf;
}
示例14: png_destroy_read_struct
unsigned char *readpng_get_image( png_store* pngdata)
{
double gamma;
png_uint_32 i, rowbytes;
png_bytepp row_pointers = NULL;
png_structp png_ptr = pngdata->png_ptr;
png_infop info_ptr = pngdata->info_ptr;
int color_type = pngdata->colortype;
int bit_depth = pngdata->bitdepth;
int height = pngdata->height;
double display_exponent = DISPLAY_EXPONENT;
int *pChannels = &(pngdata->channels);
unsigned long *pRowbytes = &(pngdata->rowbytes);
unsigned char * image_data;
/* setjmp() must be called in every function that calls a PNG-reading
* libpng function */
if (setjmp(png_jmpbuf(png_ptr))) {
png_destroy_read_struct(&png_ptr, &info_ptr, NULL);
return NULL;
}
/* expand palette images to RGB, low-bit-depth grayscale images to 8 bits,
* transparency chunks to full alpha channel; strip 16-bit-per-sample
* images to 8 bits per sample; and convert grayscale to RGB[A] */
if (color_type == PNG_COLOR_TYPE_PALETTE)
png_set_expand(png_ptr);
if (color_type == PNG_COLOR_TYPE_GRAY && bit_depth < 8)
png_set_expand(png_ptr);
if (png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS))
png_set_expand(png_ptr);
if (bit_depth == 16)
png_set_strip_16(png_ptr);
if (color_type == PNG_COLOR_TYPE_GRAY ||
color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
png_set_gray_to_rgb(png_ptr);
/* unlike the example in the libpng documentation, we have *no* idea where
* this file may have come from--so if it doesn't have a file gamma, don't
* do any correction ("do no harm") */
if (png_get_gAMA(png_ptr, info_ptr, &gamma))
png_set_gamma(png_ptr, display_exponent, gamma);
/* all transformations have been registered; now update info_ptr data,
* get rowbytes and channels, and allocate image memory */
png_read_update_info(png_ptr, info_ptr);
*pRowbytes = rowbytes = png_get_rowbytes(png_ptr, info_ptr);
*pChannels = (int)png_get_channels(png_ptr, info_ptr);
if ((image_data = (unsigned char *)malloc(rowbytes*height)) == NULL) {
png_destroy_read_struct(&png_ptr, &info_ptr, NULL);
return NULL;
}
if ((row_pointers = (png_bytepp)malloc(height*sizeof(png_bytep))) == NULL) {
png_destroy_read_struct(&png_ptr, &info_ptr, NULL);
free(image_data);
image_data = NULL;
return NULL;
}
/* set the individual row_pointers to point at the correct offsets */
for (i = 0; i < height; ++i)
row_pointers[i] = image_data + i*rowbytes;
/* now we can go ahead and just read the whole image */
png_read_image(png_ptr, row_pointers);
/* and we're done! (png_read_end() can be omitted if no processing of
* post-IDAT text/time/etc. is desired) */
// free(row_pointers);
// row_pointers = NULL;
png_read_end(png_ptr, NULL);
pngdata->image_data = image_data;
pngdata->row_pointers = row_pointers;
return image_data;
}
示例15: png_include_image
//.........这里部分代码省略.........
} else {
colorspace = create_cspace_CalGray(png_ptr, png_info_ptr);
}
if (!colorspace)
colorspace = pdf_new_name("DeviceGray");
switch (trans_type) {
case PDF_TRANS_TYPE_BINARY:
mask = create_ckey_mask(png_ptr, png_info_ptr);
break;
case PDF_TRANS_TYPE_ALPHA:
mask = strip_soft_mask(png_ptr, png_info_ptr,
stream_data_ptr, &rowbytes, width, height);
break;
default:
mask = NULL;
}
info.num_components = 1;
break;
default:
WARN("%s: Unknown PNG colortype %d.", PNG_DEBUG_STR, color_type);
}
pdf_add_dict(stream_dict, pdf_new_name("ColorSpace"), colorspace);
pdf_add_stream(stream, stream_data_ptr, rowbytes*height);
RELEASE(stream_data_ptr);
if (mask) {
if (trans_type == PDF_TRANS_TYPE_BINARY)
pdf_add_dict(stream_dict, pdf_new_name("Mask"), mask);
else if (trans_type == PDF_TRANS_TYPE_ALPHA) {
pdf_add_dict(stream_dict, pdf_new_name("SMask"), pdf_ref_obj(mask));
pdf_release_obj(mask);
} else {
WARN("%s: Unknown transparency type...???", PNG_DEBUG_STR);
pdf_release_obj(mask);
}
}
/* Finally read XMP Metadata
* See, XMP Specification Part 3, Storage in Files
* http://www.adobe.com/jp/devnet/xmp.html
*
* We require libpng version >= 1.6.14 since prior versions
* of libpng had a bug that incorrectly treat the compression
* flag of iTxt chunks.
*/
#if PNG_LIBPNG_VER >= 10614
if (pdf_get_version() >= 4) {
png_textp text_ptr;
pdf_obj *XMP_stream, *XMP_stream_dict;
int i, num_text;
int have_XMP = 0;
num_text = png_get_text(png_ptr, png_info_ptr, &text_ptr, NULL);
for (i = 0; i < num_text; i++) {
if (!memcmp(text_ptr[i].key, "XML:com.adobe.xmp", 17)) {
/* XMP found */
if (text_ptr[i].compression != PNG_ITXT_COMPRESSION_NONE ||
text_ptr[i].itxt_length == 0)
WARN("%s: Invalid value(s) in iTXt chunk for XMP Metadata.", PNG_DEBUG_STR);
else if (have_XMP)
WARN("%s: Multiple XMP Metadata. Don't know how to treat it.", PNG_DEBUG_STR);
else {
/* We compress XMP metadata for included images here.
* It is not recommended to compress XMP metadata for PDF documents but
* we compress XMP metadata for included images here to avoid confusing
* application programs that only want PDF document global XMP metadata
* and scan for that.
*/
XMP_stream = pdf_new_stream(STREAM_COMPRESS);
XMP_stream_dict = pdf_stream_dict(XMP_stream);
pdf_add_dict(XMP_stream_dict,
pdf_new_name("Type"), pdf_new_name("Metadata"));
pdf_add_dict(XMP_stream_dict,
pdf_new_name("Subtype"), pdf_new_name("XML"));
pdf_add_stream(XMP_stream, text_ptr[i].text, text_ptr[i].itxt_length);
pdf_add_dict(stream_dict,
pdf_new_name("Metadata"), pdf_ref_obj(XMP_stream));
pdf_release_obj(XMP_stream);
have_XMP = 1;
}
}
}
}
#endif /* PNG_LIBPNG_VER */
png_read_end(png_ptr, NULL);
/* Cleanup */
if (png_info_ptr)
png_destroy_info_struct(png_ptr, &png_info_ptr);
if (png_ptr)
png_destroy_read_struct(&png_ptr, NULL, NULL);
pdf_ximage_set_image(ximage, &info, stream);
return 0;
}