本文整理汇总了C++中png_create_write_struct函数的典型用法代码示例。如果您正苦于以下问题:C++ png_create_write_struct函数的具体用法?C++ png_create_write_struct怎么用?C++ png_create_write_struct使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了png_create_write_struct函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: ico_write_png
static gboolean
ico_write_png (FILE *fp,
gint32 layer,
gint32 depth)
{
png_structp png_ptr;
png_infop info_ptr;
png_byte **row_pointers;
gint i, rowstride;
gint width, height;
gint num_colors_used;
guchar *palette;
guchar *buf;
row_pointers = NULL;
palette = NULL;
buf = NULL;
width = gimp_drawable_width (layer);
height = gimp_drawable_height (layer);
png_ptr = png_create_write_struct (PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
if ( !png_ptr )
return FALSE;
info_ptr = png_create_info_struct (png_ptr);
if ( !info_ptr )
{
png_destroy_write_struct (&png_ptr, NULL);
return FALSE;
}
if (setjmp (png_jmpbuf (png_ptr)))
{
png_destroy_write_struct (&png_ptr, &info_ptr);
if ( row_pointers )
g_free (row_pointers);
if (palette)
g_free (palette);
if (buf)
g_free (buf);
return FALSE;
}
ico_image_get_reduced_buf (layer, depth, &num_colors_used,
&palette, &buf);
png_init_io (png_ptr, fp);
png_set_IHDR (png_ptr, info_ptr, width, height,
8,
PNG_COLOR_TYPE_RGBA,
PNG_INTERLACE_NONE,
PNG_COMPRESSION_TYPE_DEFAULT,
PNG_FILTER_TYPE_DEFAULT);
png_write_info (png_ptr, info_ptr);
rowstride = ico_rowstride (width, 32);
row_pointers = g_new (png_byte*, height);
for (i = 0; i < height; i++)
{
row_pointers[i] = buf + rowstride * i;
}
png_write_image (png_ptr, row_pointers);
row_pointers = NULL;
png_write_end (png_ptr, info_ptr);
png_destroy_write_struct (&png_ptr, &info_ptr);
g_free (row_pointers);
g_free (palette);
g_free (buf);
return TRUE;
}
开发者ID:Distrotech,项目名称:gimp,代码行数:74,代码来源:ico-save.c
示例2: save_png_fast_progressive
PyObject *
save_png_fast_progressive (char *filename,
int w, int h,
bool has_alpha,
PyObject *data_generator,
bool write_legacy_png)
{
png_structp png_ptr = NULL;
png_infop info_ptr = NULL;
PyObject * result = NULL;
int bpc;
FILE * fp = NULL;
PyObject *iterator = NULL;
/* TODO: try if this silliness helps
#if defined(PNG_LIBPNG_VER) && (PNG_LIBPNG_VER >= 10200)
png_uint_32 mask, flags;
flags = png_get_asm_flags(png_ptr);
mask = png_get_asm_flagmask(PNG_SELECT_READ | PNG_SELECT_WRITE);
png_set_asm_flags(png_ptr, flags | mask);
#endif
*/
bpc = 8;
fp = fopen(filename, "wb");
if (!fp) {
PyErr_SetFromErrno(PyExc_IOError);
//PyErr_Format(PyExc_IOError, "Could not open PNG file for writing: %s", filename);
goto cleanup;
}
png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, (png_voidp)NULL, png_write_error_callback, NULL);
if (!png_ptr) {
PyErr_SetString(PyExc_MemoryError, "png_create_write_struct() failed");
goto cleanup;
}
info_ptr = png_create_info_struct(png_ptr);
if (!info_ptr) {
PyErr_SetString(PyExc_MemoryError, "png_create_info_struct() failed");
goto cleanup;
}
if (setjmp(png_jmpbuf(png_ptr))) {
goto cleanup;
}
png_init_io(png_ptr, fp);
png_set_IHDR (png_ptr, info_ptr,
w, h, bpc,
has_alpha ? PNG_COLOR_TYPE_RGB_ALPHA : PNG_COLOR_TYPE_RGB,
PNG_INTERLACE_NONE,
PNG_COMPRESSION_TYPE_BASE,
PNG_FILTER_TYPE_BASE);
if (! write_legacy_png) {
// Internal data is sRGB by the time it gets here.
// Explicitly save with the recommended chunks to advertise that fact.
png_set_sRGB_gAMA_and_cHRM (png_ptr, info_ptr, PNG_sRGB_INTENT_PERCEPTUAL);
}
// default (all filters enabled): 1350ms, 3.4MB
//png_set_filter(png_ptr, 0, PNG_FILTER_NONE); // 790ms, 3.8MB
//png_set_filter(png_ptr, 0, PNG_FILTER_PAETH); // 980ms, 3.5MB
png_set_filter(png_ptr, 0, PNG_FILTER_SUB); // 760ms, 3.4MB
//png_set_compression_level(png_ptr, 0); // 0.49s, 32MB
//png_set_compression_level(png_ptr, 1); // 0.98s, 9.6MB
png_set_compression_level(png_ptr, 2); // 1.08s, 9.4MB
//png_set_compression_level(png_ptr, 9); // 18.6s, 9.3MB
png_write_info(png_ptr, info_ptr);
if (!has_alpha) {
// input array format format is rgbu
png_set_filler(png_ptr, 0, PNG_FILLER_AFTER);
}
{
iterator = PyObject_GetIter(data_generator);
if (!iterator) goto cleanup;
int y = 0;
while (y < h) {
int rows;
PyObject * arr = PyIter_Next(iterator);
if (PyErr_Occurred()) goto cleanup;
assert(arr); // iterator should have data
assert(PyArray_ISALIGNED(arr));
assert(PyArray_NDIM(arr) == 3);
assert(PyArray_DIM(arr, 1) == w);
assert(PyArray_DIM(arr, 2) == 4); // rgbu
assert(PyArray_TYPE(arr) == NPY_UINT8);
assert(PyArray_STRIDE(arr, 1) == 4);
assert(PyArray_STRIDE(arr, 2) == 1);
rows = PyArray_DIM(arr, 0);
//.........这里部分代码省略.........
开发者ID:dvberkel,项目名称:mypaint,代码行数:101,代码来源:fastpng.hpp
示例3: FWARNING
bool PNGImageFileType::write(const Image *OSG_PNG_ARG(pImage ),
std::ostream &OSG_PNG_ARG(os ),
const std::string &OSG_PNG_ARG(mimetype))
{
#ifdef OSG_WITH_PNG
png_structp png_ptr;
png_infop info_ptr;
if(pImage->getDimension() < 1 || pImage->getDimension() > 2)
{
FWARNING(("PNGImageFileType::write: invalid dimension %d!\n",
pImage->getDimension()));
return false;
}
/* Create and initialize the png_struct with the desired error handler
* functions. If you want to use the default stderr and longjump method,
* you can supply NULL for the last three parameters. We also check that
* the library version is compatible with the one used at compile time,
* in case we are using dynamically linked libraries. REQUIRED.
*/
png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING,
0, &errorOutput, &warningOutput);
if(png_ptr == NULL)
return false;
/* Allocate/initialize the image information data. REQUIRED */
info_ptr = png_create_info_struct(png_ptr);
if(info_ptr == NULL)
{
png_destroy_write_struct(&png_ptr, NULL);
return false;
}
/* set up the output handlers */
png_set_write_fn(png_ptr, &os, &osWriteFunc, &osFlushFunc);
/* This is the hard way */
/* Set the image information here. Width and height are up to 2^31,
* bit_depth is one of 1, 2, 4, 8, or 16, but valid values also depend on
* the color_type selected. color_type is one of PNG_COLOR_TYPE_GRAY,
* PNG_COLOR_TYPE_GRAY_ALPHA, PNG_COLOR_TYPE_PALETTE, PNG_COLOR_TYPE_RGB,
* or PNG_COLOR_TYPE_RGB_ALPHA. interlace is either PNG_INTERLACE_NONE or
* PNG_INTERLACE_ADAM7, and the compression_type and filter_type MUST
* currently be PNG_COMPRESSION_TYPE_BASE and PNG_FILTER_TYPE_BASE. REQUIRED
*/
Int32 ctype;
switch(pImage->getPixelFormat())
{
case Image::OSG_L_PF:
ctype = PNG_COLOR_TYPE_GRAY;
break;
case Image::OSG_LA_PF:
ctype = PNG_COLOR_TYPE_GRAY_ALPHA;
break;
#if defined(GL_BGR) || defined(GL_BGR_EXT)
case Image::OSG_BGR_PF:
#endif
case Image::OSG_RGB_PF:
ctype = PNG_COLOR_TYPE_RGB;
break;
#if defined(GL_BGRA) || defined(GL_BGRA_EXT)
case Image::OSG_BGRA_PF:
#endif
case Image::OSG_RGBA_PF:
ctype = PNG_COLOR_TYPE_RGB_ALPHA;
break;
default:
FWARNING(("PNGImageFileType::write: unknown pixel format %d!\n",
pImage->getPixelFormat()));
png_destroy_write_struct(&png_ptr, NULL);
return false;
}
Int32 bit_depth;
switch(pImage->getDataType())
{
case Image::OSG_UINT8_IMAGEDATA:
bit_depth = 8;
break;
case Image::OSG_UINT16_IMAGEDATA:
bit_depth = 16;
break;
default:
FWARNING (("Invalid pixeldepth, cannot store data\n"));
return false;
};
png_set_IHDR(png_ptr, info_ptr, pImage->getWidth(), pImage->getHeight(),
//.........这里部分代码省略.........
开发者ID:Himbeertoni,项目名称:OpenSGDevMaster,代码行数:101,代码来源:OSGPNGImageFileType.cpp
示例4: encodeImageToPNG
template<typename T> void
encodeImageToPNG (typename std::vector<T>& image_arg,
size_t width_arg,
size_t height_arg,
int image_format_arg,
typename std::vector<uint8_t>& pngData_arg,
int png_level_arg)
{
png_structp png_ptr;
png_infop info_ptr;
volatile int channels;
if (image_arg.size () ==0)
return;
// Get amount of channels
switch (image_format_arg)
{
case PNG_COLOR_TYPE_GRAY:
channels = 1;
break;
case PNG_COLOR_TYPE_GRAY_ALPHA:
channels = 2;
break;
case PNG_COLOR_TYPE_RGB:
channels = 3;
break;
case PNG_COLOR_TYPE_RGB_ALPHA:
channels = 4;
break;
default:
channels = 0;
break;
}
// Ensure valid input array
assert (image_arg.size () == width_arg*height_arg*channels);
// Initialize write structure
png_ptr = png_create_write_struct (PNG_LIBPNG_VER_STRING, 0, 0, 0);
assert (png_ptr && "creating png_create_write_structpng_create_write_struct failed");
// Initialize info structure
info_ptr = png_create_info_struct (png_ptr);
assert (info_ptr && "Could not allocate info struct");
// Setup Exception handling
setjmp(png_jmpbuf(png_ptr));
// reserve memory for output data (300kB)
pngData_arg.clear ();
pngData_arg.reserve (300 * 1024);
// Define I/O methods
png_set_write_fn (png_ptr, reinterpret_cast<void*> (&pngData_arg),
user_write_data, user_flush_data);
// Define zlib compression level
if (png_level_arg >= 0)
{
png_set_compression_level (png_ptr, png_level_arg);
}
else
{
png_set_compression_level (png_ptr, Z_DEFAULT_COMPRESSION);
}
// Write header
png_set_IHDR (png_ptr, info_ptr, width_arg, height_arg, sizeof(T) * 8,
image_format_arg, PNG_INTERLACE_NONE, PNG_COMPRESSION_TYPE_DEFAULT,
PNG_FILTER_TYPE_DEFAULT);
png_write_info (png_ptr, info_ptr);
// Write image data
size_t y;
for (y = 0; y < height_arg; y++)
{
png_write_row (png_ptr, reinterpret_cast<png_bytep> (&image_arg[y * width_arg * channels]));
}
// End write
png_write_end (png_ptr, 0);
if (info_ptr)
png_free_data (png_ptr, info_ptr, PNG_FREE_ALL, -1);
if (png_ptr)
png_destroy_write_struct (&png_ptr, 0);
}
开发者ID:Bardo91,项目名称:pcl,代码行数:89,代码来源:libpng_wrapper.cpp
示例5: CAPTURE_AddImage
void CAPTURE_AddImage(Bitu width, Bitu height, Bitu bpp, Bitu pitch, Bitu flags, float fps, Bit8u * data, Bit8u * pal) {
#if (C_SSHOT)
Bitu i;
Bit8u doubleRow[SCALER_MAXWIDTH*4];
Bitu countWidth = width;
if (flags & CAPTURE_FLAG_DBLH)
height *= 2;
if (flags & CAPTURE_FLAG_DBLW)
width *= 2;
if (height > SCALER_MAXHEIGHT)
return;
if (width > SCALER_MAXWIDTH)
return;
if (CaptureState & CAPTURE_IMAGE) {
png_structp png_ptr;
png_infop info_ptr;
png_color palette[256];
CaptureState &= ~CAPTURE_IMAGE;
/* Open the actual file */
FILE * fp=OpenCaptureFile("Screenshot",".png");
if (!fp) goto skip_shot;
/* First try to allocate the png structures */
png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL,NULL, NULL);
if (!png_ptr) goto skip_shot;
info_ptr = png_create_info_struct(png_ptr);
if (!info_ptr) {
png_destroy_write_struct(&png_ptr,(png_infopp)NULL);
goto skip_shot;
}
/* Finalize the initing of png library */
png_init_io(png_ptr, fp);
png_set_compression_level(png_ptr,Z_BEST_COMPRESSION);
/* set other zlib parameters */
png_set_compression_mem_level(png_ptr, 8);
png_set_compression_strategy(png_ptr,Z_DEFAULT_STRATEGY);
png_set_compression_window_bits(png_ptr, 15);
png_set_compression_method(png_ptr, 8);
png_set_compression_buffer_size(png_ptr, 8192);
if (bpp==8) {
png_set_IHDR(png_ptr, info_ptr, width, height,
8, PNG_COLOR_TYPE_PALETTE, PNG_INTERLACE_NONE,
PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT);
for (i=0;i<256;i++) {
palette[i].red=pal[i*4+0];
palette[i].green=pal[i*4+1];
palette[i].blue=pal[i*4+2];
}
png_set_PLTE(png_ptr, info_ptr, palette,256);
} else {
png_set_bgr( png_ptr );
png_set_IHDR(png_ptr, info_ptr, width, height,
8, PNG_COLOR_TYPE_RGB, PNG_INTERLACE_NONE,
PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT);
}
#ifdef PNG_TEXT_SUPPORTED
int fields = 1;
png_text text[1];
const char* text_s = "DOSBox " VERSION;
size_t strl = strlen(text_s);
char* ptext_s = new char[strl + 1];
strcpy(ptext_s, text_s);
char software[9] = { 'S','o','f','t','w','a','r','e',0};
text[0].compression = PNG_TEXT_COMPRESSION_NONE;
text[0].key = software;
text[0].text = ptext_s;
png_set_text(png_ptr, info_ptr, text, fields);
#endif
png_write_info(png_ptr, info_ptr);
#ifdef PNG_TEXT_SUPPORTED
delete [] ptext_s;
#endif
for (i=0;i<height;i++) {
void *rowPointer;
void *srcLine;
if (flags & CAPTURE_FLAG_DBLH)
srcLine=(data+(i >> 1)*pitch);
else
srcLine=(data+(i >> 0)*pitch);
rowPointer=srcLine;
switch (bpp) {
case 8:
if (flags & CAPTURE_FLAG_DBLW) {
for (Bitu x=0;x<countWidth;x++)
doubleRow[x*2+0] =
doubleRow[x*2+1] = ((Bit8u *)srcLine)[x];
rowPointer = doubleRow;
}
break;
case 15:
if (flags & CAPTURE_FLAG_DBLW) {
for (Bitu x=0;x<countWidth;x++) {
Bitu pixel = ((Bit16u *)srcLine)[x];
doubleRow[x*6+0] = doubleRow[x*6+3] = ((pixel& 0x001f) * 0x21) >> 2;
//.........这里部分代码省略.........
开发者ID:Ailick,项目名称:dosbox,代码行数:101,代码来源:hardware.cpp
示例6: _lossless_pack_png
static DVector<uint8_t> _lossless_pack_png(const Image& p_image) {
Image img = p_image;
if (img.get_format() > Image::FORMAT_INDEXED_ALPHA)
img.decompress();
ERR_FAIL_COND_V(img.get_format() > Image::FORMAT_INDEXED_ALPHA, DVector<uint8_t>());
png_structp png_ptr;
png_infop info_ptr;
png_bytep * row_pointers;
/* initialize stuff */
png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
ERR_FAIL_COND_V(!png_ptr,DVector<uint8_t>());
info_ptr = png_create_info_struct(png_ptr);
ERR_FAIL_COND_V(!info_ptr,DVector<uint8_t>());
if (setjmp(png_jmpbuf(png_ptr))) {
ERR_FAIL_V(DVector<uint8_t>());
}
DVector<uint8_t> ret;
ret.push_back('P');
ret.push_back('N');
ret.push_back('G');
ret.push_back(' ');
png_set_write_fn(png_ptr,&ret,_write_png_data,NULL);
/* write header */
if (setjmp(png_jmpbuf(png_ptr))) {
ERR_FAIL_V(DVector<uint8_t>());
}
int pngf=0;
int pngb=8;
int cs=0;
switch(img.get_format()) {
case Image::FORMAT_GRAYSCALE: {
pngf=PNG_COLOR_TYPE_GRAY;
cs=1;
} break;
case Image::FORMAT_GRAYSCALE_ALPHA: {
pngf=PNG_COLOR_TYPE_GRAY_ALPHA;
cs=2;
} break;
case Image::FORMAT_RGB: {
pngf=PNG_COLOR_TYPE_RGB;
cs=3;
} break;
case Image::FORMAT_RGBA: {
pngf=PNG_COLOR_TYPE_RGB_ALPHA;
cs=4;
} break;
default: {
if (img.detect_alpha()) {
img.convert(Image::FORMAT_RGBA);
pngf=PNG_COLOR_TYPE_RGB_ALPHA;
cs=4;
} else {
img.convert(Image::FORMAT_RGB);
pngf=PNG_COLOR_TYPE_RGB;
cs=3;
}
}
}
int w = img.get_width();
int h = img.get_height();
png_set_IHDR(png_ptr, info_ptr, w,h,
8, pngf, PNG_INTERLACE_NONE,
PNG_COMPRESSION_TYPE_BASE, PNG_FILTER_TYPE_BASE);
png_write_info(png_ptr, info_ptr);
/* write bytes */
if (setjmp(png_jmpbuf(png_ptr))) {
ERR_FAIL_V(DVector<uint8_t>());
}
DVector<uint8_t>::Read r = img.get_data().read();
//.........这里部分代码省略.........
开发者ID:AMG194,项目名称:godot,代码行数:101,代码来源:image_loader_png.cpp
示例7: save_png
static int save_png(SDL_Surface* surface, char *path)
{
int w = surface->w;
int h = surface->h;
unsigned char * pix = (unsigned char *)surface->pixels;
unsigned char writeBuffer[1024 * 3];
FILE *f = fopen(path,"wb");
if(!f) return 0;
png_structp png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING,
NULL,
NULL,
NULL);
if(!png_ptr) {
fclose(f);
return 0;
}
png_infop info_ptr = png_create_info_struct(png_ptr);
if(!info_ptr) {
png_destroy_write_struct(&png_ptr,NULL);
fclose(f);
return 0;
}
png_init_io(png_ptr,f);
png_set_IHDR(png_ptr,
info_ptr,
w,
h,
8,
PNG_COLOR_TYPE_RGB,
PNG_INTERLACE_NONE,
PNG_COMPRESSION_TYPE_DEFAULT,
PNG_FILTER_TYPE_DEFAULT);
png_write_info(png_ptr,info_ptr);
unsigned char *b = writeBuffer;
int sizeX = w;
int sizeY = h;
int y;
int x;
unsigned short *p = (unsigned short *)pix;
for(y = 0; y < sizeY; y++)
{
for(x = 0; x < sizeX; x++)
{
unsigned short v = p[x];
*b++ = ((v & systemRedMask ) >> systemRedShift ) << 3; // R
*b++ = ((v & systemGreenMask) >> systemGreenShift) << 2; // G
*b++ = ((v & systemBlueMask ) >> systemBlueShift ) << 3; // B
}
p += surface->pitch / 2;
png_write_row(png_ptr,writeBuffer);
b = writeBuffer;
}
png_write_end(png_ptr, info_ptr);
png_destroy_write_struct(&png_ptr, &info_ptr);
fclose(f);
return 1;
}
开发者ID:nitrologic,项目名称:uae,代码行数:69,代码来源:rasp_gfx.cpp
示例8: convertToPNG
int convertToPNG(AbstractFile* imageWrapper, const unsigned int* key, const unsigned int* iv, const char* png) {
AbstractFile* imageFile;
FILE *fp = fopen(png, "wb");
if(!fp)
return -1;
if(key != NULL) {
imageFile = openAbstractFile2(imageWrapper, key, iv);
} else {
imageFile = openAbstractFile(imageWrapper);
}
InfoIBootIM* info = (InfoIBootIM*) (imageFile->data);
png_structp png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, pngError, pngWarn);
if (!png_ptr) {
return -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);
return -1;
}
png_init_io(png_ptr, fp);
int color_type;
int bytes_per_pixel;
if(info->header.format == IBOOTIM_ARGB) {
XLOG(3, "ARGB");
color_type = PNG_COLOR_TYPE_RGB_ALPHA;
bytes_per_pixel = 4;
} else if(info->header.format == IBOOTIM_GREY) {
XLOG(3, "Grayscale");
color_type = PNG_COLOR_TYPE_GRAY_ALPHA;
bytes_per_pixel = 2;
} else {
XLOG(3, "Unknown color type!");
}
png_set_IHDR(png_ptr, info_ptr, info->header.width, info->header.height,
8, color_type, PNG_INTERLACE_NONE,
PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT);
png_set_bgr(png_ptr);
png_set_invert_alpha(png_ptr);
png_write_info(png_ptr, info_ptr);
void* imageBuffer = malloc(imageFile->getLength(imageFile));
imageFile->read(imageFile, imageBuffer, imageFile->getLength(imageFile));
png_bytepp row_pointers = (png_bytepp) malloc(sizeof(png_bytep) * info->header.height);
int i;
for(i = 0; i < png_get_image_height(png_ptr, info_ptr); i++) {
row_pointers[i] = imageBuffer + (info->header.width * bytes_per_pixel * i);
}
png_write_image(png_ptr, row_pointers);
png_write_end(png_ptr, NULL);
free(imageBuffer);
return 0;
}
开发者ID:jevinskie,项目名称:xpwn,代码行数:70,代码来源:ibootim.c
示例9: SavePNG
void SavePNG(const char *name, const byte * pic, int width, int height, int numBytes, qboolean flip)
{
png_structp png;
png_infop info;
int i;
int row_stride;
byte *buffer;
byte *row;
png_bytep *row_pointers;
png = png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
if(!png)
return;
// Allocate/initialize the image information data
info = png_create_info_struct(png);
if(!info)
{
png_destroy_write_struct(&png, (png_infopp) NULL);
return;
}
png_compressed_size = 0;
buffer = ri.Hunk_AllocateTempMemory(width * height * numBytes);
// set error handling
if(setjmp(png_jmpbuf(png)))
{
ri.Hunk_FreeTempMemory(buffer);
png_destroy_write_struct(&png, &info);
return;
}
png_set_write_fn(png, buffer, png_write_data, png_flush_data);
switch ( numBytes )
{
default:
png_set_IHDR(png, info, width, height, 8, PNG_COLOR_TYPE_RGBA, PNG_INTERLACE_NONE, PNG_COMPRESSION_TYPE_DEFAULT,
PNG_FILTER_TYPE_DEFAULT);
break;
case 3:
png_set_IHDR(png, info, width, height, 8, PNG_COLOR_TYPE_RGB, PNG_INTERLACE_NONE, PNG_COMPRESSION_TYPE_DEFAULT,
PNG_FILTER_TYPE_DEFAULT);
break;
case 2:
png_set_IHDR( png, info, width, height, 8, PNG_COLOR_TYPE_GA, PNG_INTERLACE_NONE, PNG_COMPRESSION_TYPE_DEFAULT,
PNG_FILTER_TYPE_DEFAULT );
break;
case 1:
png_set_IHDR( png, info, width, height, 8, PNG_COLOR_TYPE_GRAY, PNG_INTERLACE_NONE, PNG_COMPRESSION_TYPE_DEFAULT,
PNG_FILTER_TYPE_DEFAULT );
break;
}
// write the file header information
png_write_info(png, info);
row_pointers = ri.Hunk_AllocateTempMemory(height * sizeof(png_bytep));
if(setjmp(png_jmpbuf(png)))
{
ri.Hunk_FreeTempMemory(row_pointers);
ri.Hunk_FreeTempMemory(buffer);
png_destroy_write_struct(&png, &info);
return;
}
row_stride = width * numBytes;
row = (byte *)pic + (height - 1) * row_stride;
if(flip)
{
for(i = height - 1; i >= 0; i--)
{
row_pointers[i] = row;
row -= row_stride;
}
}
else
{
for(i = 0; i < height; i++)
{
row_pointers[i] = row;
row -= row_stride;
}
}
png_write_image(png, row_pointers);
png_write_end(png, info);
// clean up after the write, and free any memory allocated
png_destroy_write_struct(&png, &info);
ri.Hunk_FreeTempMemory(row_pointers);
ri.FS_WriteFile(name, buffer, png_compressed_size);
ri.Hunk_FreeTempMemory(buffer);
//.........这里部分代码省略.........
开发者ID:otty,项目名称:cake3,代码行数:101,代码来源:tr_image_png.c
示例10: savePngInternal
/**************************************************************************
Save given buffer type to file.
**************************************************************************/
bool savePngInternal(const char *filename, unsigned char *pixels, int w, int h, int bitdepth, int color_type)
{
png_structp pngp;
png_infop infop;
int y;
FILE *fp;
png_bytep *row_pointers;
int const bytes = bitdepth / 8;
if (filename == NULL || *filename == '\0' || pixels == NULL)
{
return false;
}
if (!(fp = fopen(filename, "wb")))
{
debug(LOG_ERROR, "%s won't open for writing!", filename);
return false;
}
pngp = png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
if (!pngp)
{
debug(LOG_ERROR, "fgl_save_pixmap: Failed to create PNG write struct");
fclose(fp);
return false;
}
infop = png_create_info_struct(pngp);
if (!infop)
{
debug(LOG_ERROR, "fgl_save_pixmap: Failed to create PNG info struct");
fclose(fp);
png_destroy_write_struct(&pngp, NULL);
return false;
}
if (setjmp(png_jmpbuf(pngp)))
{
debug(LOG_ERROR, "fgl_save_pixmap: Failed to initialize IO during PNG save");
fclose(fp);
png_destroy_write_struct(&pngp, NULL);
return false;
}
png_init_io(pngp, fp);
/* write header */
if (setjmp(png_jmpbuf(pngp)))
{
debug(LOG_ERROR, "fgl_save_pixmap: Failed to write PNG header");
fclose(fp);
png_destroy_write_struct(&pngp, NULL);
return false;
}
png_set_IHDR(pngp, infop, w, h, bitdepth, color_type,
PNG_INTERLACE_NONE, PNG_COMPRESSION_TYPE_BASE,
PNG_FILTER_TYPE_BASE);
png_write_info(pngp, infop);
/* Create pointers to each row of the data, as libpng wants it */
row_pointers = malloc(sizeof(png_bytep) * h);
for (y = 0; y < h; y++)
{
row_pointers[y] = pixels + (y * w * bytes);
}
if (setjmp(png_jmpbuf(pngp)))
{
debug(LOG_ERROR, "fgl_save_pixmap: Failed to write PNG body");
fclose(fp);
png_destroy_write_struct(&pngp, NULL);
return false;
}
png_write_image(pngp, row_pointers);
if (setjmp(png_jmpbuf(pngp)))
{
debug(LOG_ERROR, "fgl_save_pixmap: Failed to finalize PNG");
fclose(fp);
png_destroy_write_struct(&pngp, NULL);
return false;
}
png_write_end(pngp, NULL);
free(row_pointers);
fclose(fp);
png_destroy_write_struct(&pngp, NULL);
return true;
}
开发者ID:ArtemusRus,项目名称:warzone2100,代码行数:91,代码来源:pngsave.c
示例11: write_PNG
int write_PNG(char *filename, int interlace, char borfb)
{
//hardcore theft from fbgrab.c
/*
* fbgrab - takes screenshots using the framebuffer.
*
* (C) Gunnar Monell <[email protected]> 2002
*
* This program is free Software, see the COPYING file
* and is based on Stephan Beyer's <[email protected]> FBShot
* (C) 2000.
*
* For features and differences, read the manual page.
*
* This program has been checked with "splint +posixlib" without
* warnings. Splint is available from http://www.splint.org/ .
* Patches and enhancements of fbgrab have to fulfill this too.
*/
png_uint_32 i;
int bit_depth=0, color_type;
png_uint_32 uheight, uwidth;
uheight = (png_uint_32)height;
uwidth = (png_uint_32)width;
png_bytep row_pointers[uheight];
png_structp png_ptr;
png_infop info_ptr;
FILE *outfile = fopen(filename, "wb");
interlace = PNG_INTERLACE_NONE;
//printf ("%d, %d\n", uheight, uwidth);
//well, either from the buffer or the framebuffer...
//yih, gotta clean this one up, reallyyyyy
//
if (borfb == 0)
for (i=0; i<uheight; i++)
row_pointers[i] = (unsigned char *)(fbp + (BPP*Ox) + (Oy + i) * 1 * (finfo.line_length/*uwidth+10*/));
if (borfb == 1)
for (i=0; i<uheight; i++)
row_pointers[i] = (unsigned char *)(tmp_buf + (BPP*Ox) + (Oy + i) * 1 * (finfo.line_length/*uwidth+10*/));
if (!outfile){
fprintf (stderr, "Error: Couldn't fopen %s.\n", filename);
return -1;
}
png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING,
(png_voidp) NULL, (png_error_ptr) NULL, (png_error_ptr) NULL);
if (!png_ptr){
fprintf(stderr,"Error: Couldn't create PNG write struct.");
return -1;
}
info_ptr = png_create_info_struct(png_ptr);
if (!info_ptr){
png_destroy_write_struct(&png_ptr, (png_infopp) NULL);
fprintf(stderr, "Error: Couldn't create PNG info struct.");
return -1;
}
if (setjmp(png_jmpbuf(png_ptr))){
fclose(outfile);
png_destroy_write_struct(&png_ptr, &info_ptr);
return -2;
}
png_init_io(png_ptr, outfile);
//png_set_compression_level(png_ptr, Z_BEST_COMPRESSION);
bit_depth = 8;
color_type = PNG_COLOR_TYPE_RGB_ALPHA;
png_set_IHDR(png_ptr, info_ptr, uwidth, uheight,
bit_depth, PNG_COLOR_TYPE_RGBA, PNG_INTERLACE_NONE,
PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT);
//png_set_packing(png_ptr);
png_set_invert_alpha(png_ptr);
//
//png_set function must be after set_IHDR
//according to libpng-manual
png_set_filter(png_ptr, 0, PNG_FILTER_NONE);
png_set_filler(png_ptr, 0 , PNG_FILLER_BEFORE);
png_set_bgr(png_ptr);
png_write_info(png_ptr, info_ptr);
//printf ("Now writing PNG file\n");
png_write_image(png_ptr, row_pointers);
//png_write_rows(png_ptr, row_pointers, uheight);
png_write_end(png_ptr, info_ptr);
//puh, done, now freeing memory...
png_destroy_write_struct(&png_ptr, &info_ptr);
//.........这里部分代码省略.........
开发者ID:noisegate,项目名称:fbpy,代码行数:101,代码来源:fbutils.c
示例12: png_create_write_struct
bool Q_INTERNAL_WIN_NO_THROW QPNGImageWriter::writeImage(const QImage& image, volatile int quality_in, const QString &description,
int off_x_in, int off_y_in)
{
QPoint offset = image.offset();
int off_x = off_x_in + offset.x();
int off_y = off_y_in + offset.y();
png_structp png_ptr;
png_infop info_ptr;
png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING,0,0,0);
if (!png_ptr) {
return false;
}
png_set_error_fn(png_ptr, 0, 0, qt_png_warning);
info_ptr = png_create_info_struct(png_ptr);
if (!info_ptr) {
png_destroy_write_struct(&png_ptr, 0);
return false;
}
if (setjmp(png_jmpbuf(png_ptr))) {
png_destroy_write_struct(&png_ptr, &info_ptr);
return false;
}
int quality = quality_in;
if (quality >= 0) {
if (quality > 9) {
qWarning("PNG: Quality %d out of range", quality);
quality = 9;
}
png_set_compression_level(png_ptr, quality);
}
png_set_write_fn(png_ptr, (void*)this, qpiw_write_fn, qpiw_flush_fn);
int color_type = 0;
if (image.colorCount()) {
if (image.isGrayscale())
color_type = PNG_COLOR_TYPE_GRAY;
else
color_type = PNG_COLOR_TYPE_PALETTE;
}
else if (image.format() == QImage::Format_Grayscale8)
color_type = PNG_COLOR_TYPE_GRAY;
else if (image.hasAlphaChannel())
color_type = PNG_COLOR_TYPE_RGB_ALPHA;
else
color_type = PNG_COLOR_TYPE_RGB;
png_set_IHDR(png_ptr, info_ptr, image.width(), image.height(),
image.depth() == 1 ? 1 : 8, // per channel
color_type, 0, 0, 0); // sets #channels
if (gamma != 0.0) {
png_set_gAMA(png_ptr, info_ptr, 1.0/gamma);
}
if (image.format() == QImage::Format_MonoLSB)
png_set_packswap(png_ptr);
if (color_type == PNG_COLOR_TYPE_PALETTE) {
// Paletted
int num_palette = qMin(256, image.colorCount());
png_color palette[256];
png_byte trans[256];
int num_trans = 0;
for (int i=0; i<num_palette; i++) {
QRgb rgba=image.color(i);
palette[i].red = qRed(rgba);
palette[i].green = qGreen(rgba);
palette[i].blue = qBlue(rgba);
trans[i] = qAlpha(rgba);
if (trans[i] < 255) {
num_trans = i+1;
}
}
png_set_PLTE(png_ptr, info_ptr, palette, num_palette);
if (num_trans) {
png_set_tRNS(png_ptr, info_ptr, trans, num_trans, 0);
}
}
// Swap ARGB to RGBA (normal PNG format) before saving on
// BigEndian machines
if (QSysInfo::ByteOrder == QSysInfo::BigEndian) {
png_set_swap_alpha(png_ptr);
}
// Qt==ARGB==Big(ARGB)==Little(BGRA). But RGB888 is RGB regardless
if (QSysInfo::ByteOrder == QSysInfo::LittleEndian
&& image.format() != QImage::Format_RGB888) {
png_set_bgr(png_ptr);
}
//.........这里部分代码省略.........
开发者ID:2gis,项目名称:2gisqt5android,代码行数:101,代码来源:qpnghandler.cpp
示例13: save_png_to_file
/* Write "bitmap" to a PNG file specified by "path"; returns 0 on
success, non-zero on error. */
int save_png_to_file(const char *path) {
FILE *fp;
png_structp png_ptr = NULL;
png_infop info_ptr = NULL;
size_t x, y;
/* "status" contains the return value of this function. At first
it is set to a value which means 'failure'. When the routine
has finished its work, it is set to a value which means
'success'. */
int status = -1;
/* The following number is set by trial and error only. I cannot
see where it it is documented in the libpng manual.
*/
int pixel_size = 3;
int depth = 8;
/****************************************************************************/
/****************************************************************************/
/****************************************************************************/
/* para el manejo de errores */
fp = fopen(path, "wb");
if (!fp) {
return status;
}
png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
if (png_ptr == NULL) {
fclose(fp);
return status;
}
info_ptr = png_create_info_struct(png_ptr);
if (info_ptr == NULL) {
png_destroy_write_struct(&png_ptr, &info_ptr);
fclose(fp);
return status;
}
/* Set up error handling. */
if (setjmp(png_jmpbuf(png_ptr))) {
png_destroy_write_struct(&png_ptr, &info_ptr);
fclose(fp);
return status;
}
/****************************************************************************/
/****************************************************************************/
/****************************************************************************/
/* Set image attributes. */
png_set_IHDR(png_ptr,
info_ptr,
H_RES, //bitmap->width,
V_RES, // bitmap->height,
depth,
PNG_COLOR_TYPE_RGB,
PNG_INTERLACE_NONE,
PNG_COMPRESSION_TYPE_DEFAULT,
PNG_FILTER_TYPE_DEFAULT);
/* Initialize rows of PNG. */
png_byte **row_pointers = NULL;
row_pointers = png_malloc(png_ptr, V_RES * sizeof (png_byte *));
//recorro todo el eje vertical(y) para ir obteniendo las filas
for (y = 0; y < V_RES; y++) {
//obtener el inverso de la fila
int y_temp = (V_RES - y) - 1;
png_byte *row = png_malloc(png_ptr, sizeof (uint8_t) * H_RES * pixel_size);
row_pointers[y_temp] = row;
//recorro todos los puntos
for (x = 0; x < H_RES; x++) {
//pixel_t * pixel = pixel_at(bitmap, x, y);
*row++ = (int) (frameBuffer[x][y].r * 255);
*row++ = (int) (frameBuffer[x][y].g * 255);
*row++ = (int) (frameBuffer[x][y].b * 255);
}
}
/* Write the image data to "fp". */
png_init_io(png_ptr, fp);
png_set_rows(png_ptr, info_ptr, row_pointers);
png_write_png(png_ptr, info_ptr, PNG_TRANSFORM_IDENTITY, NULL);
/* The routine has successfully written the file, so we set
"status" to a value which indicates success. */
//.........这里部分代码省略.........
开发者ID:josemoO,项目名称:RayTracing,代码行数:101,代码来源:RayTracing_Main.c
示例14: writepng_init
int writepng_init(mainprog_info *mainprog_ptr)
{
AMJU_CALL_STACK;
png_structp png_ptr; /* note: temporary variables! */
png_infop info_ptr;
int color_type, interlace_type;
/* could also replace libpng warning-handler (final NULL), but no need: */
png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, mainprog_ptr,
writepng_error_handler, NULL);
if (!png_ptr)
return 4; /* out of memory */
info_ptr = png_create_info_struct(png_ptr);
if (!info_ptr) {
png_destroy_write_struct(&png_ptr, NULL);
return 4; /* out of memory */
}
/* setjmp() must be called in every function that calls a PNG-writing
* libpng function, unless an alternate error handler was installed--
* but compatible error handlers must either use longjmp() themselves
* (as in this program) or exit immediately, so here we go: */
if (setjmp(mainprog_ptr->jmpbuf)) {
png_destroy_write_struct(&png_ptr, &info_ptr);
return 2;
}
/* make sure outfile is (re)opened in BINARY mode */
png_init_io(png_ptr, mainprog_ptr->outfile);
/* set the compression levels--in general, always want to leave filtering
* turned on (except for palette images) and allow all of the filters,
* which is the default; want 32K zlib window, unless entire image buffer
* is 16K or smaller (unknown here)--also the default; usually want max
* compression (NOT the default); and remaining compression flags should
* be left alone */
png_set_compression_level(png_ptr, Z_BEST_COMPRESSION);
/*
>> this is default for no filtering; Z_FILTERED is default otherwise:
png_set_compression_strategy(png_ptr, Z_DEFAULT_STRATEGY);
>> these are all defaults:
png_set_compression_mem_level(png_ptr, 8);
png_set_compression_window_bits(png_ptr, 15);
png_set_compression_method(png_ptr, 8);
*/
/* set the image parameters appropriately */
if (mainprog_ptr->pnmtype == 5)
color_type = PNG_COLOR_TYPE_GRAY;
else if (mainprog_ptr->pnmtype == 6)
color_type = PNG_COLOR_TYPE_RGB;
else if (mainprog_ptr->pnmtype == 8)
color_type = PNG_COLOR_TYPE_RGB_ALPHA;
else {
png_destroy_write_struct(&png_ptr, &info_ptr);
return 11;
}
interlace_type = mainprog_ptr->interlaced? PNG_INTERLACE_ADAM7 :
PNG_INTERLACE_NONE;
png_set_IHDR(png_ptr, info_ptr, mainprog_ptr->width, mainprog_ptr->height,
mainprog_ptr->sample_depth, color_type, interlace_type,
PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT);
if (mainprog_ptr->gamma > 0.0)
png_set_gAMA(png_ptr, info_ptr, mainprog_ptr->gamma);
if (mainprog_ptr->have_bg) { /* we know it's RGBA, not gray+alpha */
png_color_16 background;
background.red = mainprog_ptr->bg_red;
background.green = mainprog_ptr->bg_green;
background.blue = mainprog_ptr->bg_blue;
png_set_bKGD(png_ptr, info_ptr, &background);
}
if (mainprog_ptr->have_time) {
png_time modtime;
png_convert_from_time_t(&modtime, mainprog_ptr->modtime);
png_set_tIME(png_ptr, info_ptr, &modtime);
}
if (mainprog_ptr->have_text) {
png_text text[6];
int num_text = 0;
if (mainprog_ptr->have_text & TEXT_TITLE) {
text[num_text].compression = PNG_TEXT_COMPRESSION_NONE;
text[num_text].key = (char*)"Title";
//.........这里部分代码省略.........
开发者ID:jason-amju,项目名称:amjulib,代码行数:101,代码来源:SavePng.cpp
示例15: rayOrigin
void Mesh::generateHeightmap(const char* filename)
{
// Shoot rays down from a point just above the max Y position of the mesh.
// Compute ray-triangle intersection tests against the ray and this mesh to
// generate heightmap data.
Vector3 rayOrigin(0, bounds.max.y + 10, 0);
Vector3 rayDirection(0, -1, 0);
Vector3 intersectionPoint;
int minX = (int)ceil(bounds.min.x);
int maxX = (int)floor(bounds.max.x);
int minZ = (int)ceil(bounds.min.z);
int maxZ = (int)floor(bounds.max.z);
int width = maxX - minX + 1;
int height = maxZ - minZ + 1;
float* heights = new float[width * height];
int index = 0;
float minHeight = FLT_MAX;
float maxHeight = FLT_MIN;
for (int z = minZ; z <= maxZ; z++)
{
rayOrigin.z = (float)z;
for (int x = minX; x <= maxX; x++)
{
float h;
rayOrigin.x = (float)x;
if (intersect(rayOrigin, rayDirection, vertices, parts, &intersectionPoint))
{
h = intersectionPoint.y;
}
else
{
h = 0;
fprintf(stderr, "Warning: Heightmap triangle intersection failed for (%d, %d).\n", x, z);
}
if (h < minHeight)
minHeight = h;
if (h > maxHeight)
maxHeight = h;
heights[index++] = h;
}
}
// Normalize the max height value
maxHeight = maxHeight - minHeight;
png_structp png_ptr = NULL;
png_infop info_ptr = NULL;
png_bytep row = NULL;
FILE* fp = fopen(filename, "wb");
if (fp == NULL)
{
fprintf(stderr, "Error: Failed to open file for writing: %s\n", filename);
goto error;
}
png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
if (png_ptr == NULL)
{
fprintf(stderr, "Error: Write struct creation failed: %s\n", filename);
goto error;
}
info_ptr = png_create_info_struct(png_ptr);
if (info_ptr == NULL)
{
fprintf(stderr, "Error: Info struct creation failed: %s\n", filename);
goto error;
}
png_init_io(png_ptr, fp);
png_set_IHDR(png_ptr, info_ptr, width, height, 8, PNG_COLOR_TYPE_RGB, PNG_INTERLACE_NONE, PNG_COMPRESSION_TYPE_BASE, PNG_FILTER_TYPE_BASE);
png_write_info(png_ptr, info_ptr);
// Allocate memory for a single row of image data
row = (png_bytep)malloc(3 * width * sizeof(png_byte));
for (int y = 0; y < height; y++)
{
for (int x = 0; x < width; x++)
{
// Write height value normalized between 0-255 (between min and max height)
float h = heights[y*width + x];
float nh = (h - minHeight) / maxHeight;
png_byte b = (png_byte)(nh * 255.0f);
int pos = x*3;
row[pos] = row[pos+1] = row[pos+2] = b;
}
png_write_row(png_ptr, row);
}
png_write_end(png_ptr, NULL);
DEBUGPRINT_VARG("> Saved heightmap: %s\n", filename);
error:
if (heights)
delete[] heights;
//.........这里部分代码省略.........
开发者ID:aaweb,项目名称:GamePlay,代码行数:101,代码来源:Mesh.cpp
示例16: enc_png
int enc_png(char *data,g2int width,g2int height,g2int nbits,char *pngbuf)
{
int color_type;
g2int j,bytes,pnglen,bit_depth;
png_structp png_ptr;
png_infop info_ptr;
// png_bytep *row_pointers[height];
png_bytep **row_pointers;
png_stream write_io_ptr;
/* create and initialize png_structs */
png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING,
|
请发表评论