当前位置: 首页>>代码示例>>C++>>正文


C++ png_set_compression_level函数代码示例

本文整理汇总了C++中png_set_compression_level函数的典型用法代码示例。如果您正苦于以下问题:C++ png_set_compression_level函数的具体用法?C++ png_set_compression_level怎么用?C++ png_set_compression_level使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了png_set_compression_level函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: _mapcache_imageio_png_encode

/**
 * \brief encode an image to RGB(A) PNG format
 * \private \memberof mapcache_image_format_png
 * \sa mapcache_image_format::write()
 */
mapcache_buffer* _mapcache_imageio_png_encode(mapcache_context *ctx, mapcache_image *img, mapcache_image_format *format) {
   png_infop info_ptr;
   int color_type;
   size_t row;
   mapcache_buffer *buffer = NULL;
   int compression = ((mapcache_image_format_png*)format)->compression_level;
   png_structp png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL,NULL,NULL);
   if (!png_ptr) {
      ctx->set_error(ctx, 500, "failed to allocate png_struct structure");
      return NULL;
   }

   info_ptr = png_create_info_struct(png_ptr);
   if (!info_ptr)
   {
      png_destroy_write_struct(&png_ptr,
            (png_infopp)NULL);
      ctx->set_error(ctx, 500, "failed to allocate png_info structure");
      return NULL;
   }

   if (setjmp(png_jmpbuf(png_ptr)))
   {
      ctx->set_error(ctx, 500, "failed to setjmp(png_jmpbuf(png_ptr))");
      png_destroy_write_struct(&png_ptr, &info_ptr);
      return NULL;
   }

   buffer = mapcache_buffer_create(5000,ctx->pool);

   png_set_write_fn(png_ptr, buffer, _mapcache_imageio_png_write_func, _mapcache_imageio_png_flush_func);

   if(mapcache_image_has_alpha(img))
      color_type = PNG_COLOR_TYPE_RGB_ALPHA;
   else
      color_type = PNG_COLOR_TYPE_RGB;
      
   png_set_IHDR(png_ptr, info_ptr, img->w, img->h,
         8, color_type, PNG_INTERLACE_NONE,
         PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT);
   if(compression == MAPCACHE_COMPRESSION_BEST)
      png_set_compression_level (png_ptr, Z_BEST_COMPRESSION);
   else if(compression == MAPCACHE_COMPRESSION_FAST)
      png_set_compression_level (png_ptr, Z_BEST_SPEED);

   png_write_info(png_ptr, info_ptr);
   if(color_type == PNG_COLOR_TYPE_RGB)
       png_set_filler(png_ptr, 255, PNG_FILLER_AFTER);

   png_bytep rowptr = img->data;
   for(row=0;row<img->h;row++) {
      png_write_row(png_ptr,rowptr);
      rowptr += img->stride;
   }
   png_write_end(png_ptr, info_ptr);
   png_destroy_write_struct(&png_ptr, &info_ptr);
   return buffer;
}
开发者ID:msilex,项目名称:mapserver,代码行数:63,代码来源:imageio_png.c

示例2: s_PngWriteInit

//
// initialize PNG writing
//
static void s_PngWriteInit(png_structp& png_ptr,
                           png_infop&   info_ptr,
                           size_t width, size_t height, size_t depth,
                           CImageIO::ECompress compress)
{
    png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL,
                                      s_PngWriteErrorHandler,
                                      s_PngWarningHandler);
    if ( !png_ptr ) {
        NCBI_THROW(CImageException, eWriteError,
                   "CImageIOPng::WriteImage(): png_create_read_struct() failed");
    }

    info_ptr = png_create_info_struct(png_ptr);
    if ( !info_ptr ) {
        NCBI_THROW(CImageException, eWriteError,
                   "CImageIOPng::WriteImage(): png_create_info_struct() failed");
    }

    png_byte color_type = PNG_COLOR_TYPE_RGB;
    if (depth == 4) {
        color_type = PNG_COLOR_TYPE_RGBA;
    }
    png_set_IHDR(png_ptr, info_ptr,
                 width, height, 8, color_type,
                 PNG_INTERLACE_NONE,
                 PNG_COMPRESSION_TYPE_BASE,
                 PNG_FILTER_TYPE_BASE);

    // set our compression quality
    switch (compress) {
    case CImageIO::eCompress_None:
        png_set_filter(png_ptr, 0, PNG_FILTER_NONE);
        png_set_compression_level(png_ptr, Z_NO_COMPRESSION);
        break;
    case CImageIO::eCompress_Low:
        png_set_filter(png_ptr, 0, PNG_FILTER_NONE);
        png_set_compression_level(png_ptr, Z_BEST_SPEED);
        break;
    case CImageIO::eCompress_Medium:
        png_set_compression_level(png_ptr, Z_DEFAULT_COMPRESSION);
        break;
    case CImageIO::eCompress_High:
        png_set_compression_level(png_ptr, Z_BEST_COMPRESSION);
        break;
    default:
        LOG_POST_X(26, Error << "unknown compression type: " << (int)compress);
        break;
    }

}
开发者ID:svn2github,项目名称:ncbi_tk,代码行数:54,代码来源:image_io_png.cpp

示例3: error

bool
PNGOutput::open (const std::string &name, const ImageSpec &userspec,
                 OpenMode mode)
{
    if (mode != Create) {
        error ("%s does not support subimages or MIP levels", format_name());
        return false;
    }

    close ();  // Close any already-opened file
    m_spec = userspec;  // Stash the spec

    m_file = Filesystem::fopen (name, "wb");
    if (! m_file) {
        error ("Could not open file \"%s\"", name.c_str());
        return false;
    }

    std::string s = PNG_pvt::create_write_struct (m_png, m_info,
                                                  m_color_type, m_spec);
    if (s.length ()) {
        close ();
        error ("%s", s.c_str ());
        return false;
    }

    png_init_io (m_png, m_file);
    png_set_compression_level (m_png, 6 /* medium speed vs size tradeoff */);

    PNG_pvt::write_info (m_png, m_info, m_color_type, m_spec, m_pngtext);

    return true;
}
开发者ID:DingTo,项目名称:oiio,代码行数:33,代码来源:pngoutput.cpp

示例4: rgb2png

static size_t rgb2png(ss_t **png, const ss_t *rgb, const struct RGB_Info *ri)
{
	RETURN_IF(!valid_rgbi(ri) ||!rgb, 0);
	size_t out_size = 0;
	png_structp s = png_create_write_struct(PNG_LIBPNG_VER_STRING, 0, 0, 0);
	png_infop pi = png_create_info_struct(s);
	if (png)
		ss_set_size(*png, 0);
	png_set_write_fn(s, (png_voidp)png, aux_png_write, NULL);
	int ctype = (ri->chn > 1 ? PNG_COLOR_MASK_COLOR : 0) |
		    (ri->chn == 2 || ri->chn == 4 ? PNG_COLOR_MASK_ALPHA : 0);
	png_set_IHDR(s, pi, (png_uint_32)ri->width, (png_uint_32)ri->height,
		     ri->bpc, ctype, PNG_INTERLACE_NONE, PNG_COMPRESSION_TYPE_BASE,
		     PNG_FILTER_TYPE_BASE);
	png_set_filter(s, PNG_FILTER_TYPE_BASE, PNG_ALL_FILTERS);
	png_set_compression_level(s, Z_BEST_COMPRESSION);
	png_write_info(s, pi);
	png_bytep *rows = (png_bytep *)alloca(sizeof(png_bytep) * pi->height);
	if (aux_png_set_rows(rows, pi, ss_get_buffer_r(rgb))) {
		png_write_image(s, rows);
		png_write_end(s, pi);
		out_size = ss_size(*png);
	}
	png_destroy_info_struct(s, &pi);
	png_destroy_write_struct(&s, &pi);
	return out_size;
}
开发者ID:lamproae,项目名称:libsrt,代码行数:27,代码来源:imgc.c

示例5: PngWriter

    /** \brief Constructor.
     *
     * @param fd File handle to adapt.
     * @param skip How many bytes of file have already been read
     */
    PngWriter(FILE *fd) :
      m_fd(fd),
      m_png(NULL),
      m_info(NULL)
    {
      m_png = png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
      if(!m_png)
      {
        std::stringstream sstr;
        sstr << "could not create a PNG read struct";
        BOOST_THROW_EXCEPTION(std::runtime_error(sstr.str()));
      }
      m_info = png_create_info_struct(m_png);
      if(!m_info)
      {
        std::stringstream sstr;
        sstr << "could not create a PNG info struct";
        BOOST_THROW_EXCEPTION(std::runtime_error(sstr.str()));
      }

      png_init_io(m_png, m_fd); // read header
      png_set_compression_buffer_size(m_png, 8192);
      png_set_compression_level(m_png, Z_BEST_COMPRESSION);
      png_set_compression_mem_level(m_png, Z_BEST_COMPRESSION);
      png_set_compression_window_bits(m_png, 15);
    }
开发者ID:eriser,项目名称:faemiyah-demoscene_2014-03_16k-intro_lavos,代码行数:31,代码来源:image_png.cpp

示例6: rwpng_write_image_init

pngquant_error rwpng_write_image_init(png_image *mainprog_ptr, png_structpp png_ptr_p, png_infopp info_ptr_p, FILE *outfile)
{
    /* could also replace libpng warning-handler (final NULL), but no need: */

    *png_ptr_p = png_create_write_struct(PNG_LIBPNG_VER_STRING, mainprog_ptr, rwpng_error_handler, NULL);

    if (!(*png_ptr_p)) {
        return LIBPNG_INIT_ERROR;   /* out of memory */
    }

    *info_ptr_p = png_create_info_struct(*png_ptr_p);
    if (!(*info_ptr_p)) {
        png_destroy_write_struct(png_ptr_p, NULL);
        return LIBPNG_INIT_ERROR;   /* 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_p, info_ptr_p);
        return LIBPNG_INIT_ERROR;   /* libpng error (via longjmp()) */
    }

    png_init_io(*png_ptr_p, outfile);

    png_set_compression_level(*png_ptr_p, Z_BEST_COMPRESSION);

    return SUCCESS;
}
开发者ID:andreydobrikov,项目名称:improved-pngquant,代码行数:33,代码来源:rwpng.c

示例7: RageSurface_Save_PNG

/* Since libpng forces us to use longjmp, this function shouldn't create any C++
 * objects, and needs to watch out for memleaks. */
static bool RageSurface_Save_PNG( RageFile &f, char szErrorbuf[1024], RageSurface *pImgIn )
{
	bool bAlpha = pImgIn->format->Amask != 0;
	RageSurface *pImg;
	bool bDeleteImg = RageSurfaceUtils::ConvertSurface( pImgIn, pImg, pImgIn->w, pImgIn->h, 32,
			Swap32BE( 0xFF000000 ),
			Swap32BE( 0x00FF0000 ),
			Swap32BE( 0x0000FF00 ),
			Swap32BE( 0x000000FF ) );
	if( !bDeleteImg )
		pImg = pImgIn;

	error_info error;
	error.szErr = szErrorbuf;

	png_struct *pPng = png_create_write_struct( PNG_LIBPNG_VER_STRING, &error, PNG_Error, PNG_Warning );
	if( pPng == NULL )
	{
		sprintf( szErrorbuf, "creating png_create_write_struct failed");
		return false;
	}

	png_info *pInfo = png_create_info_struct(pPng);
	if( pInfo == NULL )
	{
		png_destroy_read_struct( &pPng, NULL, NULL );
		if( bDeleteImg )
			delete pImg;
		sprintf( szErrorbuf, "creating png_create_info_struct failed");
		return false;
	}

	if( setjmp(png_jmpbuf(pPng)) )
	{
		png_destroy_read_struct( &pPng, &pInfo, NULL );
		return false;
	}

	png_set_write_fn( pPng, &f, RageFile_png_write, RageFile_png_flush );
	png_set_compression_level( pPng, 1 );

	png_set_IHDR( pPng, pInfo, pImg->w, pImg->h, 8, bAlpha? PNG_COLOR_TYPE_RGBA:PNG_COLOR_TYPE_RGB,
		PNG_INTERLACE_NONE, PNG_COMPRESSION_TYPE_BASE, PNG_FILTER_TYPE_BASE );

	png_write_info( pPng, pInfo );
	png_set_filler( pPng, 0, PNG_FILLER_AFTER );

	png_byte *pixels = (png_byte *) pImg->pixels;
	for( int y = 0; y < pImg->h; y++ )
		png_write_row( pPng, pixels + pImg->pitch*y );

	png_write_end( pPng, pInfo );
	png_destroy_write_struct( &pPng, &pInfo );

	/* Free the converted image. */
	if( bDeleteImg )
		delete pImg;

	return true;
}
开发者ID:Ancaro,项目名称:stepmania,代码行数:62,代码来源:RageSurface_Save_PNG.cpp

示例8: write_png_image

void write_png_image(char * dest, image_t * image)
{
        FILE *outfile;
        if ((outfile = fopen(dest, "wb")) == NULL) {
                fprintf(stderr, "can't open %s", dest);
                return;
        }
        png_structp  png_ptr;
        png_infop  info_ptr;

        png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING,
                        NULL, NULL, NULL);
        info_ptr = png_create_info_struct(png_ptr);
        png_init_io(png_ptr, outfile);
        png_set_compression_level(png_ptr, Z_BEST_COMPRESSION);

        png_set_IHDR(png_ptr, info_ptr, image->size[0],
                        image->size[1], 8,
                        PNG_COLOR_TYPE_RGB, PNG_INTERLACE_NONE,
                        PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT);
        png_write_info(png_ptr, info_ptr);

        for(int i = 0; i < image->size[1]; i++) {
                png_write_row(png_ptr
                                , &(*image->pixels)[i * image->size[0] * RGB_CHANNEL]);
        }
        png_write_end(png_ptr, NULL);
        fclose(outfile);
}
开发者ID:bonnefoa,项目名称:imagecmp,代码行数:29,代码来源:image_util.c

示例9: WritePNG

static int WritePNG(FILE* file, uint8_t* buffer, int width, int height)
{
    size_t pitch = width * 4;
    png_structp png_ptr;
    png_infop info_ptr;

    if (!(png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL))) goto png_error;
    if (!(info_ptr = png_create_info_struct(png_ptr))) goto info_error;

    if (setjmp(png_jmpbuf(png_ptr)))
    {
        png_destroy_write_struct(&png_ptr, &info_ptr);
        goto png_error;
    }

    png_init_io(png_ptr, file);
    png_set_compression_level(png_ptr, Z_BEST_COMPRESSION);
    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);

    for (int r = height * pitch - pitch; r >= 0; r -= pitch)
        png_write_row(png_ptr, buffer + r);

    png_write_end(png_ptr, info_ptr);
    png_destroy_write_struct(&png_ptr, &info_ptr);

    return 1;
info_error:
    png_destroy_write_struct(&png_ptr, NULL);
png_error:
    return 0;
}
开发者ID:rossy,项目名称:clearshot,代码行数:32,代码来源:clearshot.c

示例10: begin_png

 void begin_png()
 {
     png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING,0,0,0);
     info_ptr = png_create_info_struct(png_ptr);
     png_set_compression_level(png_ptr,9);
     png_set_write_fn(png_ptr, (void*)this, write, 0);
 }
开发者ID:natros,项目名称:qt-mac-free-3.3.8,代码行数:7,代码来源:qanimationwriter.cpp

示例11: write_png

static void write_png(const png_bytep rgba, png_uint_32 width, png_uint_32 height, SkWStream& out) {
    png_structp png = png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
    SkASSERT(png != nullptr);
    png_infop info_ptr = png_create_info_struct(png);
    SkASSERT(info_ptr != nullptr);
    if (setjmp(png_jmpbuf(png))) {
        SkFAIL("png encode error");
    }
    png_set_IHDR(png, info_ptr, width, height, 8, PNG_COLOR_TYPE_RGB, PNG_INTERLACE_NONE,
                 PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT);
    png_set_compression_level(png, 1);
    png_bytepp rows = (png_bytepp) sk_malloc_throw(height * sizeof(png_byte*));
    png_bytep pixels = (png_bytep) sk_malloc_throw(width * height * 3);
    for (png_size_t y = 0; y < height; ++y) {
        const png_bytep src = rgba + y * width * 4;
        rows[y] = pixels + y * width * 3;
        // convert from RGBA to RGB
        for (png_size_t x = 0; x < width; ++x) {
            rows[y][x * 3] = src[x * 4];
            rows[y][x * 3 + 1] = src[x * 4 + 1];
            rows[y][x * 3 + 2] = src[x * 4 + 2];
        }
    }
    png_set_filter(png, 0, PNG_NO_FILTERS);
    png_set_rows(png, info_ptr, &rows[0]);
    png_set_write_fn(png, &out, write_png_callback, NULL);
    png_write_png(png, info_ptr, PNG_TRANSFORM_IDENTITY, NULL);
    png_destroy_write_struct(&png, NULL);
    sk_free(rows);
}
开发者ID:nagyist,项目名称:google-skia,代码行数:30,代码来源:Request.cpp

示例12: png_create_write_struct

std::unique_ptr<PNGImageEncoderState> PNGImageEncoderState::create(const IntSize& imageSize, Vector<unsigned char>* output)
{
    if (imageSize.width() <= 0 || imageSize.height() <= 0)
        return nullptr;

    png_struct* png = png_create_write_struct(PNG_LIBPNG_VER_STRING, 0, 0, 0);
    png_info* info = png_create_info_struct(png);
    if (!png || !info || setjmp(png_jmpbuf(png))) {
        png_destroy_write_struct(png ? &png : 0, info ? &info : 0);
        return nullptr;
    }

    // Optimize compression for speed.
    // The parameters are the same as what libpng uses by default for RGB and RGBA images, except:
    // The zlib compression level is set to 3 instead of 6, to avoid the lazy Ziv-Lempel match searching.
    png_set_compression_level(png, 3);

    // The zlib memory level is set to 8.  This actually matches the default, we are just future-proofing.
    png_set_compression_mem_level(png, 8);

    // The zlib strategy is set to Z_FILTERED, which does not match the default.
    // Avoid the zlib strategies Z_HUFFMAN_ONLY or Z_RLE.
    // Although they are the fastest for poorly-compressible images (e.g. photographs),
    // they are very slow for highly-compressible images (e.g. text, drawings or business graphics)
    png_set_compression_strategy(png, Z_FILTERED);

    // The delta filter is PNG_FILTER_SUB instead of PNG_ALL_FILTERS, to reduce the filter computations.
    png_set_filter(png, PNG_FILTER_TYPE_BASE, PNG_FILTER_SUB);

    png_set_write_fn(png, output, writeOutput, 0);
    png_set_IHDR(png, info, imageSize.width(), imageSize.height(), 8, PNG_COLOR_TYPE_RGB_ALPHA, 0, 0, 0);
    png_write_info(png, info);

    return wrapUnique(new PNGImageEncoderState(png, info));
}
开发者ID:endlessm,项目名称:chromium-browser,代码行数:35,代码来源:PNGImageEncoder.cpp

示例13: pngdrv_open_memmap

static int pngdrv_open_memmap(const char *filename, int x_size, int y_size, BYTE *palette)
{
    pngdrv_memmap_png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, (void *)NULL, NULL, NULL);

    if (pngdrv_memmap_png_ptr == NULL) {
        return -1;
    }

    pngdrv_memmap_info_ptr = png_create_info_struct(pngdrv_memmap_png_ptr);

    if (pngdrv_memmap_info_ptr == NULL) {
        png_destroy_write_struct(&(pngdrv_memmap_png_ptr), (png_infopp)NULL);
        return -1;
    }
/* pngdrv.c:232: warning: ‘jmpbuf‘ is deprecated (declared at /usr/include/libpng14/png.h:1096) */
/*    if (setjmp(pngdrv_memmap_png_ptr->jmpbuf)) { */
    if (setjmp(png_jmpbuf(pngdrv_memmap_png_ptr))) {
        png_destroy_write_struct(&(pngdrv_memmap_png_ptr), &(pngdrv_memmap_info_ptr));
        return -1;
    }

    pngdrv_memmap_ext_filename = util_add_extension_const(filename, png_drv.default_extension);

    pngdrv_memmap_fd = fopen(pngdrv_memmap_ext_filename, MODE_WRITE);

    if (pngdrv_memmap_fd == NULL) {
        lib_free(pngdrv_memmap_ext_filename);
        return -1;
    }

    pngdrv_memmap_png_data = lib_malloc(x_size * 4);

    png_init_io(pngdrv_memmap_png_ptr, pngdrv_memmap_fd);
    png_set_compression_level(pngdrv_memmap_png_ptr, Z_BEST_COMPRESSION);

/*
pngdrv.c:251: warning: ‘width‘ is deprecated (declared at /usr/include/libpng14/png.h:639)
pngdrv.c:252: warning: ‘height‘ is deprecated (declared at /usr/include/libpng14/png.h:640)
pngdrv.c:253: warning: ‘bit_depth‘ is deprecated (declared at /usr/include/libpng14/png.h:651)
pngdrv.c:254: warning: ‘color_type‘ is deprecated (declared at /usr/include/libpng14/png.h:653)
*/
/*
    pngdrv_memmap_info_ptr->width = x_size;
    pngdrv_memmap_info_ptr->height= y_size;
    pngdrv_memmap_info_ptr->bit_depth = 8;
    pngdrv_memmap_info_ptr->color_type = PNG_COLOR_TYPE_RGB_ALPHA;
*/
    png_set_IHDR(pngdrv_memmap_png_ptr, pngdrv_memmap_info_ptr, x_size, y_size,
                 8, PNG_COLOR_TYPE_RGB_ALPHA, PNG_INTERLACE_NONE,
                 PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT);

    png_write_info(pngdrv_memmap_png_ptr, pngdrv_memmap_info_ptr);

#ifdef PNG_READ_INVERT_ALPHA_SUPPORTED
    png_set_invert_alpha(pngdrv_memmap_png_ptr);
#endif

    return 0;
}
开发者ID:twinaphex,项目名称:vice-next,代码行数:59,代码来源:pngdrv.c

示例14: WritePNG

errort	WritePNG( FILE * fp , unsigned char * data, unsigned int sizeX, unsigned int sizeY, int img_depth, int img_alpha)
{
  png_structp png_ptr = png_create_write_struct
    (PNG_LIBPNG_VER_STRING, (png_voidp)NULL,NULL,NULL);
  if (!png_ptr)
    return BadFormat;
  
  png_infop info_ptr = png_create_info_struct(png_ptr);
  if (!info_ptr) {
    png_destroy_write_struct(&png_ptr, (png_infopp)NULL);
    return BadFormat;
  }
  if (setjmp(png_ptr->jmpbuf)) {
    png_destroy_write_struct(&png_ptr, &info_ptr);
    return BadFormat;
  }

  png_init_io(png_ptr, fp);

  png_set_filter(png_ptr, 0, PNG_FILTER_NONE);
  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_IHDR(png_ptr, 
	       info_ptr, 
	       sizeX,
	       sizeY,
	       img_depth, 
	       img_alpha?PNG_COLOR_TYPE_RGB_ALPHA:PNG_COLOR_TYPE_RGB, 
	       PNG_INTERLACE_NONE,
	       PNG_COMPRESSION_TYPE_DEFAULT, 
	       PNG_FILTER_TYPE_DEFAULT);
  
  png_write_info(png_ptr, info_ptr);
# if __BYTE_ORDER != __BIG_ENDIAN  
  if (img_depth==16) {
    png_set_swap(png_ptr);
  }
#endif
  int stride = (img_depth/8)*(img_alpha?4:3);
  png_byte **row_pointers = new png_byte*[sizeY];
  for (unsigned int i=0;i<sizeY;i++) {
    row_pointers[i]= (png_byte *)&data[stride*i*sizeX];
  }
  png_write_image (png_ptr,row_pointers);
  png_write_end(png_ptr, info_ptr);
  png_write_flush(png_ptr);
  png_destroy_write_struct(&png_ptr, &info_ptr);

  //free (data);
  delete [] row_pointers;
  return Ok;
}
开发者ID:bsmr-games,项目名称:Privateer-Gemini-Gold,代码行数:58,代码来源:shrinker.cpp

示例15: sprintf

void Bonsai::_cacheColorImage( const char *suffix, GLubyte *data, int sz )
{
	char filename[256];
	sprintf( filename, "./%s/%s_%s.png", CACHE_DIR, m_name, suffix );

	FILE *fp = fopen( filename, "wb" );
	if (!fp)
	{
		DBG::warn( "Error writing cache file %s\n", filename );
		return;
	}

	png_structp png_ptr = png_create_write_struct( PNG_LIBPNG_VER_STRING,
					NULL, NULL, NULL );

	if (!png_ptr)
	{
		DBG::warn( "error creating png write struct\n" );
	}

	png_infop info_ptr = png_create_info_struct( png_ptr );
	if (!info_ptr)
	{
		png_destroy_write_struct( &png_ptr, (png_infopp)NULL );
		DBG::warn( "error creating png info struct\n" );
	}

	// init IO and compression
	png_init_io( png_ptr, fp );
	png_set_compression_level( png_ptr, Z_BEST_COMPRESSION );	

	// set content header
	png_set_IHDR( png_ptr, info_ptr, sz, sz,
					8, PNG_COLOR_TYPE_RGB,
					PNG_INTERLACE_NONE,
					PNG_COMPRESSION_TYPE_DEFAULT,
					PNG_FILTER_TYPE_DEFAULT );

	// write header info
	png_write_info(png_ptr, info_ptr);	
	
	// write the thing
	// FIXME -- should use sz
	png_byte *row_pointers[1024];
	for (int i=0; i < sz; i++)
	{
		// flip 
		row_pointers[i] = &(data[(1023-i) * sz * 3]);
	}
	png_write_image( png_ptr, row_pointers );

	png_write_end( png_ptr, info_ptr );
	png_destroy_write_struct( &png_ptr, &info_ptr );

	fclose( fp );

	DBG::info( "Wrote cache image %s\n", filename );
}
开发者ID:bradparks,项目名称:ld48jovoc_food_fight_3d_luxe,代码行数:58,代码来源:bonsai.cpp


注:本文中的png_set_compression_level函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。