本文整理汇总了C++中png_write_row函数的典型用法代码示例。如果您正苦于以下问题:C++ png_write_row函数的具体用法?C++ png_write_row怎么用?C++ png_write_row使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了png_write_row函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: write_gray_alpha_to_gray_alpha
static void write_gray_alpha_to_gray_alpha (png_struct *png, png_byte *data, SLindex_Type num_cols, png_byte *tmpbuf)
{
if (Is_Little_Endian == 0)
{
png_write_row (png, data);
return;
}
byte_swap16 ((unsigned char *) data, (unsigned char *) tmpbuf, num_cols);
png_write_row (png, tmpbuf);
}
示例2: dump_png24_impl
static void dump_png24_impl(
png_struct * ppng, png_info * pinfo,
const uint8_t * data, const size_t width, const size_t height, const size_t rowsize,
const bool bgr, IsOk is_ok
) {
assert(align4(rowsize) == rowsize);
png_set_IHDR(ppng, pinfo, width, height, 8,
PNG_COLOR_TYPE_RGB,
PNG_INTERLACE_NONE,
PNG_COMPRESSION_TYPE_BASE,
PNG_FILTER_TYPE_BASE);
png_write_info(ppng, pinfo);
// send image buffer to file, one pixel row at once
const uint8_t * row = data;
if (bgr) {
uint8_t bgrtmp[8192*4];
for (size_t k = 0 ; k < height && is_ok(); ++k) {
const uint8_t * s = row;
uint8_t * t = bgrtmp;
uint8_t * e = t + (width / 4) * 12;
for (; t < e; s += 12, t += 12){
t[0] = s[2];
t[1] = s[1];
t[2] = s[0];
t[3] = s[5];
t[4] = s[4];
t[5] = s[3];
t[6] = s[8];
t[7] = s[7];
t[8] = s[6];
t[9] = s[11];
t[10] = s[10];
t[11] = s[9];
}
png_write_row(ppng, const_cast<unsigned char*>(bgrtmp));
row += rowsize;
}
}
else {
for (size_t k = 0 ; k < height && is_ok(); ++k) {
png_write_row(ppng, const_cast<unsigned char*>(row));
row += rowsize;
}
}
}
示例3: each_interlace_none
static VALUE each_interlace_none(struct each_args *args)
{
struct readerdata *reader;
unsigned char *inwidthbuf, *outwidthbuf, *yinbuf;
struct xscaler *xs;
struct yscaler *ys;
uint32_t i, scaley;
int cmp;
reader = args->reader;
xs = &args->xs;
inwidthbuf = xscaler_psl_pos0(xs);
outwidthbuf = args->outwidthbuf;
ys = &args->ys;
scaley = reader->scale_height;
cmp = png_get_channels(reader->png, reader->info);
png_write_info(args->wpng, args->winfo);
for(i=0; i<scaley; i++) {
while ((yinbuf = yscaler_next(ys))) {
png_read_row(reader->png, inwidthbuf, NULL);
xscaler_scale(xs, yinbuf);
}
yscaler_scale(ys, outwidthbuf, i, cmp, 0);
png_write_row(args->wpng, outwidthbuf);
}
png_write_end(args->wpng, args->winfo);
return Qnil;
}
示例4: each_interlace
static VALUE each_interlace(struct each_args *args)
{
struct readerdata *reader;
unsigned char *inwidthbuf, *outwidthbuf;
uint32_t i, width, height, scaley;
int cmp;
struct xscaler *xs;
reader = args->reader;
xs = &args->xs;
inwidthbuf = xscaler_psl_pos0(xs);
outwidthbuf = args->outwidthbuf;
scaley = reader->scale_height;
cmp = png_get_channels(reader->png, reader->info);
width = png_get_image_width(reader->png, reader->info);
height = png_get_image_height(reader->png, reader->info);
png_write_info(args->wpng, args->winfo);
png_read_image(args->reader->png, (png_bytepp)args->scanlines);
for (i=0; i<scaley; i++) {
yscaler_prealloc_scale(height, scaley,
(uint8_t **)args->scanlines, (uint8_t *)inwidthbuf,
i, width, cmp, 0);
xscaler_scale(xs, outwidthbuf);
png_write_row(args->wpng, outwidthbuf);
}
png_write_end(args->wpng, args->winfo);
return Qnil;
}
示例5: save_rgba
/* save_rgba:
* Core save routine for 32 bpp images.
*/
static int save_rgba(png_structp png_ptr, BITMAP *bmp)
{
unsigned char *rowdata;
int x, y;
ASSERT(bitmap_color_depth(bmp) == 32);
rowdata = (unsigned char *)malloc(bmp->w * 4);
if (!rowdata)
return 0;
for (y=0; y<bmp->h; y++) {
unsigned char *p = rowdata;
for (x=0; x<bmp->w; x++) {
int c = getpixel(bmp, x, y);
*p++ = getr32(c);
*p++ = getg32(c);
*p++ = getb32(c);
*p++ = geta32(c);
}
png_write_row(png_ptr, rowdata);
}
free(rowdata);
return 1;
}
示例6: PNGWritePixels
bool PNGWritePixels(png_structp png, unsigned width, unsigned height, unsigned stride, const void* pixels) {
png_bytep row = malloc(sizeof(png_bytep) * width * 3);
if (!row) {
return false;
}
const png_byte* pixelData = pixels;
if (setjmp(png_jmpbuf(png))) {
free(row);
return false;
}
unsigned i;
for (i = 0; i < height; ++i) {
unsigned x;
for (x = 0; x < width; ++x) {
#if defined(__POWERPC__) || defined(__PPC__)
row[x * 3] = pixelData[stride * i * 4 + x * 4 + 3];
row[x * 3 + 1] = pixelData[stride * i * 4 + x * 4 + 2];
row[x * 3 + 2] = pixelData[stride * i * 4 + x * 4 + 1];
#else
row[x * 3] = pixelData[stride * i * 4 + x * 4];
row[x * 3 + 1] = pixelData[stride * i * 4 + x * 4 + 1];
row[x * 3 + 2] = pixelData[stride * i * 4 + x * 4 + 2];
#endif
}
png_write_row(png, row);
}
free(row);
return true;
}
示例7: writepng_encode_row
int writepng_encode_row(mainprog_info *mainprog_ptr) /* NON-interlaced only! */
{
AMJU_CALL_STACK;
png_structp png_ptr = (png_structp)mainprog_ptr->png_ptr;
png_infop info_ptr = (png_infop)mainprog_ptr->info_ptr;
/* as always, setjmp() must be called in every function that calls a
* PNG-writing libpng function */
if (setjmp(mainprog_ptr->jmpbuf)) {
png_destroy_write_struct(&png_ptr, &info_ptr);
mainprog_ptr->png_ptr = NULL;
mainprog_ptr->info_ptr = NULL;
return 2;
}
/* image_data points at our one row of image data */
png_write_row(png_ptr, mainprog_ptr->image_data);
return 0;
}
示例8: write_image_data
void write_image_data(const char* filename, png_bytep data, size_t w, size_t h) {
unsigned int i;
png_structp png_ptr;
png_infop info_ptr;
/* Open output file */
FILE *png_output;
if((png_output = fopen(filename, "wb")) == NULL) {
perror("Create output image file");
exit(1);
}
/* Write image data */
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, png_output);
png_set_IHDR(png_ptr, info_ptr, w, h, 16,
PNG_COLOR_TYPE_GRAY, PNG_INTERLACE_NONE,
PNG_COMPRESSION_TYPE_BASE, PNG_FILTER_TYPE_BASE);
png_write_info(png_ptr, info_ptr);
for(i=0; i<h; i++) {
png_write_row(png_ptr, data + i*png_get_rowbytes(png_ptr, info_ptr));
}
/* Close file */
png_write_end(png_ptr, NULL);
png_destroy_write_struct(&png_ptr, &info_ptr);
fclose(png_output);
}
示例9: save_pixmap_png
int save_pixmap_png(struct pixmap *p, FILE *fp)
{
int result = 0,
y;
png_structp png_ptr;
png_infop info_ptr;
if (p) {
if ((png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL)) != NULL) {
if ((info_ptr = png_create_info_struct(png_ptr)) != NULL) {
if (setjmp(png_ptr->jmpbuf) == 0) {
png_init_io(png_ptr, fp);
png_set_IHDR(png_ptr, info_ptr, p->width, p->height, 8, (p->components == 1) ? PNG_COLOR_TYPE_GRAY : PNG_COLOR_TYPE_RGB, PNG_INTERLACE_NONE, PNG_COMPRESSION_TYPE_BASE, PNG_FILTER_TYPE_BASE);
png_write_info(png_ptr, info_ptr);
for (y = 0; y < p->height; y++) {
png_write_row(png_ptr, (png_bytep)&GET_COMP(p, 0, y, 0));
}
png_write_end(png_ptr, info_ptr);
png_destroy_write_struct(&png_ptr, (png_infopp)NULL);
} else
result = -1;
} else
result = -1;
png_destroy_write_struct(&png_ptr, (png_infopp)NULL);
} else
result = -1;
}
return result;
}
示例10: 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);
}
示例11: save_truecolour
/* save_truecolour:
* Core save routine for 32 bpp images.
*/
static int save_truecolour(png_structp png_ptr, BITMAP *bmp)
{
unsigned char *row, *p;
int i, j, c;
// [OMAR]
row = malloc(bmp->w * 3);
//row = malloc(bmp->w * 4);
if (!row)
return 0;
for (i=0; i<bmp->h; i++) {
p = row;
for (j = 0; j < bmp->w; j++) {
c = getpixel(bmp, j, i);
*p++ = getr32(c);
*p++ = getg32(c);
*p++ = getb32(c);
// [OMAR]
//*p++ = geta32(c);
}
png_write_row(png_ptr, row);
}
free(row);
return 1;
}
示例12: 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;
}
示例13: rwpng_write_image_row
int rwpng_write_image_row(mainprog_info *mainprog_ptr)
{
png_structp png_ptr = (png_structp)mainprog_ptr->png_ptr;
png_infop info_ptr = (png_infop)mainprog_ptr->info_ptr;
/* as always, setjmp() must be called in every function that calls a
* PNG-writing libpng function */
if (setjmp(mainprog_ptr->jmpbuf)) {
png_destroy_write_struct(&png_ptr, &info_ptr);
mainprog_ptr->png_ptr = NULL;
mainprog_ptr->info_ptr = NULL;
mainprog_ptr->retval = 55; /* libpng error (via longjmp()) */
return mainprog_ptr->retval;
}
/* indexed_data points at our one row of indexed data */
png_write_row(png_ptr, mainprog_ptr->indexed_data);
mainprog_ptr->retval = 0;
return 0;
}
示例14: write_rgb_alpha_to_rgb_alpha
static void write_rgb_alpha_to_rgb_alpha (png_struct *png, png_byte *data, SLindex_Type num_cols, png_byte *tmpbuf)
{
unsigned char *data_max;
unsigned char *p;
if (Is_Little_Endian)
{
byte_swap32 ((unsigned char *) data, (unsigned char *) tmpbuf, num_cols);
data = tmpbuf;
}
data_max = data + 4 * num_cols;
p = tmpbuf;
/* Change ARGBARGB... to RGBARGBA... */
while (data < data_max)
{
unsigned char a = data[0];
p[0] = data[1];
p[1] = data[2];
p[2] = data[3];
p[3] = a;
data += 4;
p += 4;
}
png_write_row (png, tmpbuf);
}
示例15: encodePNGAndAppendToBuffer
bool encodePNGAndAppendToBuffer(unsigned char *pixmap, int width, int height, std::vector<char>& output)
{
png_structp png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
png_infop info_ptr = png_create_info_struct(png_ptr);
if (setjmp(png_jmpbuf(png_ptr)))
{
png_destroy_write_struct(&png_ptr, NULL);
return false;
}
png_set_IHDR(png_ptr, info_ptr, width, height, 8, PNG_COLOR_TYPE_RGB_ALPHA, PNG_INTERLACE_NONE, PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT);
png_set_write_fn(png_ptr, &output, user_write_fn, user_flush_fn);
png_set_write_status_fn(png_ptr, user_write_status_fn);
png_write_info(png_ptr, info_ptr);
for (int y = 0; y < height; ++y)
png_write_row(png_ptr, pixmap + y * width * 4);
png_write_end(png_ptr, info_ptr);
png_destroy_write_struct(&png_ptr, NULL);
return true;
}