• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C++ png_write_png函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: saveMMBitmapAsPNG

int saveMMBitmapAsPNG(MMBitmapRef bitmap, const char *path)
{
	FILE *fp = fopen(path, "wb");
	PNGWriteInfoRef info;
	if (fp == NULL) return -1;

	if ((info = createPNGWriteInfo(bitmap)) == NULL) {
		fclose(fp);
		return -1;
	}

	png_init_io(info->png_ptr, fp);
	png_write_png(info->png_ptr, info->info_ptr, PNG_TRANSFORM_IDENTITY, NULL);
	fclose(fp);

	destroyPNGWriteInfo(info);
	return 0;
}
开发者ID:mgregson,项目名称:autopy,代码行数:18,代码来源:png_io.c


示例2: assert

uint8_t *createPNGData(MMBitmapRef bitmap, size_t *len)
{
	PNGWriteInfoRef info = NULL;
	struct io_data data = {NULL, 0, 0};

	assert(bitmap != NULL);
	assert(len != NULL);

	if ((info = createPNGWriteInfo(bitmap)) == NULL) return NULL;

	png_set_write_fn(info->png_ptr, &data, &png_append_data, NULL);
	png_write_png(info->png_ptr, info->info_ptr, PNG_TRANSFORM_IDENTITY, NULL);

	destroyPNGWriteInfo(info);

	*len = data.size;
	return data.buffer;
}
开发者ID:mgregson,项目名称:autopy,代码行数:18,代码来源:png_io.c


示例3: savePNGSprite

/*
bool savePNGSprite (FILE * fp, struct spriteBank *sprites, int index, bool sig) {
		
	png_structp png_ptr = png_create_write_struct (PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
	if (!png_ptr) {
		fclose (fp);
		return false;
	}
	
	png_infop info_ptr = png_create_info_struct(png_ptr);
	if (!info_ptr){
		png_destroy_write_struct(&png_ptr, (png_infopp)NULL);
		fclose (fp);
		return false;
	}	
	
	png_init_io(png_ptr, fp);
	
	if (!sig) png_set_sig_bytes(png_ptr, 8);
	
	const int h = 21, w = 21;
	
	png_set_IHDR(png_ptr, info_ptr, w, h,
				 8, PNG_COLOR_TYPE_RGB_ALPHA, PNG_INTERLACE_NONE, PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT);		
	
	unsigned char * row_pointers[h];

	unsigned char data[w*h*4];
	
	for (int i = 0; i < h; i++) {
		row_pointers[i] = data + 4 * i * w;
		if (!(i % 20) || (i > (h-2))) {
			for (int x = 0; x < w; x++) {
				*(unsigned char *)(row_pointers[i]+x*4) = 255;
				*(unsigned char *)(row_pointers[i]+x*4+1) = 0;
				*(unsigned char *)(row_pointers[i]+x*4+2) = 
				*(unsigned char *)(row_pointers[i]+x*4+3) = 255;
			}			
		} else {
			for (int x = 0; x < w; x++) {
				if (x % 20 && x < (w-1)) {
					*(unsigned char *)(row_pointers[i]+x*4) =
					*(unsigned char *)(row_pointers[i]+x*4+1) =
					*(unsigned char *)(row_pointers[i]+x*4+2) = 0;
					*(unsigned char *)(row_pointers[i]+x*4+3) = 0;
				} else {
					*(unsigned char *)(row_pointers[i]+x*4) = 255;
					*(unsigned char *)(row_pointers[i]+x*4+1) = 0;
					*(unsigned char *)(row_pointers[i]+x*4+2) = 255;
					*(unsigned char *)(row_pointers[i]+x*4+3) = 255;
				}
			}
		}			
	}

	
	png_set_rows(png_ptr, info_ptr, row_pointers);	
    png_write_png(png_ptr, info_ptr, PNG_TRANSFORM_IDENTITY, NULL);	
	return true;
}
*/
bool savePNGSprite (FILE * fp, struct spriteBank *sprites, int index, bool sig) {
	
	if (sprites->sprites[index].width < 1) return errorBox ("Error saving", "Can't save a sprite that has no width.");
	if (sprites->sprites[index].height < 1) {
		sprites->sprites[index].height = 1;
		unsigned char * d = new unsigned char [sprites->sprites[index].width*4];
		if (!d) return errorBox ("Error saving", "Out of RAM memory.");
		for (int i = 0; i < sprites->sprites[index].width*4; i++) {
			d[i] = 0;
		}
		delete sprites->sprites[index].data;
		sprites->sprites[index].data = d;
	}
	
	png_structp png_ptr = png_create_write_struct (PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
	if (!png_ptr) {
		fclose (fp);
		return false;
	}
	
	png_infop info_ptr = png_create_info_struct(png_ptr);
	if (!info_ptr){
		png_destroy_write_struct(&png_ptr, (png_infopp)NULL);
		fclose (fp);
		return false;
	}	
	
	png_init_io(png_ptr, fp);
	
	if (!sig) png_set_sig_bytes(png_ptr, 8);
	
	png_set_IHDR(png_ptr, info_ptr, sprites->sprites[index].width, sprites->sprites[index].height,
				 8, PNG_COLOR_TYPE_RGB_ALPHA, PNG_INTERLACE_NONE, PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT);		
	
	unsigned char * row_pointers[sprites->sprites[index].height];
	
	for (int i = 0; i < sprites->sprites[index].height; i++) {
		row_pointers[i] = sprites->sprites[index].data + 4*i*sprites->sprites[index].width;
	}
//.........这里部分代码省略.........
开发者ID:VillainyStudios,项目名称:opensludge,代码行数:101,代码来源:sprites.cpp


示例4: dummyFunc

 int dummyFunc() {

	// For Broken Sword 2.5
 	volatile int i;
	i = clock();
	rename("dummyA", "dummyB");
	
	png_structp png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
	png_set_write_fn(png_ptr, NULL, NULL, NULL);
	png_infop info_ptr;
	png_write_png(png_ptr, info_ptr, PNG_TRANSFORM_IDENTITY, NULL);
	png_destroy_write_struct(&png_ptr, &info_ptr);
	
	// For lua's usage of libc: very heavy usage so it pulls in sockets?
	setsockopt(0, 0, 0, NULL, 0);
	getsockopt(0, 0, 0, NULL, NULL);
	
	return i;
}
开发者ID:bgK,项目名称:scummvm,代码行数:19,代码来源:dummy.cpp


示例5: write_png

void write_png(char* filename, unsigned w, unsigned h,
               unsigned char** data, png_text* comments) {
  FILE* fp = fopen(filename, "wb");
  if (!fp) {
    fprintf(stderr, "ERROR: Could not open output file %s\n", filename);
    exit(-1);
  }
  
  png_structp png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, 0, 0, 0);
   if (!png_ptr) {
     fprintf(stderr, "ERROR: Could not open output file %s\n", filename);
     fclose(fp);
     exit(-1);
   }

   png_infop info_ptr = png_create_info_struct(png_ptr);
   if (!info_ptr) {
     png_destroy_read_struct(&png_ptr, 0, 0);
     fprintf(stderr, "ERROR: Could not open output file %s\n", filename);
     fclose(fp);
     exit(-1);
   }
   
   if (setjmp(png_jmpbuf(png_ptr))) {
     png_destroy_write_struct(&png_ptr, &info_ptr);
     fprintf(stderr, "ERROR: Could not open output file %s\n", filename);
     fclose(fp);
     exit(-1);
   }
   
   png_init_io(png_ptr, fp);
   png_set_IHDR(png_ptr, info_ptr, w, h, 8, PNG_COLOR_TYPE_RGB_ALPHA,
                PNG_INTERLACE_NONE, PNG_COMPRESSION_TYPE_DEFAULT,
                PNG_FILTER_TYPE_DEFAULT);
  png_set_text(png_ptr, info_ptr, comments, 1);
  
   png_set_rows(png_ptr, info_ptr, data);
   png_write_png(png_ptr, info_ptr, PNG_TRANSFORM_IDENTITY, NULL);
   
   fclose(fp);
}
开发者ID:resistor,项目名称:spritepack,代码行数:41,代码来源:main.c


示例6: image_write

void image_write(Image * image, const char *filename)
{
   FILE           *file;
   png_structp     png_ptr;
   png_infop       info_ptr;
   png_bytep      *row_pointers;
   int             i;

   file = fopen(filename, "wb");
   assert(file != NULL);

   png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
   assert(png_ptr != NULL);

   info_ptr = png_create_info_struct(png_ptr);
   assert(info_ptr != NULL);

   assert(setjmp(png_jmpbuf(png_ptr)) == 0);

   png_init_io(png_ptr, file);

   png_set_IHDR(png_ptr, info_ptr, image->width, image->height, 8,
         PNG_COLOR_TYPE_GRAY, PNG_INTERLACE_NONE,
         PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT);

   row_pointers = png_malloc(png_ptr, image->height * sizeof(png_bytep));
   assert(row_pointers != NULL);
   for (i = 0; i < image->height; i++)
      row_pointers[i] = (png_bytep)(&image->pixel[i*image->width]);
   png_set_rows(png_ptr, info_ptr, row_pointers);

   png_write_png(png_ptr, info_ptr, PNG_TRANSFORM_IDENTITY, NULL);

   png_free(png_ptr, row_pointers);

   png_destroy_write_struct(&png_ptr, &info_ptr);

   fclose(file);
}
开发者ID:owenchj,项目名称:SystemC_imag_filter,代码行数:39,代码来源:image.c


示例7: write_image_png

int write_image_png(handle_t handle, picture_t *pic, config_t *config)
{
    png_output_t *h = handle;
    uint8_t *out_data = malloc(config->width * config->height * 4);
    uint8_t **rows = calloc(config->height, sizeof(*rows));
    picture_t pic_out;
    struct SwsContext *sws_ctx;
    int i;

    pic_out.img.plane[0] = out_data;
    pic_out.img.plane[1] = pic_out.img.plane[2] = pic_out.img.plane[3] = NULL;
    pic_out.img.stride[0] = 3 * config->width;
    pic_out.img.stride[1] = pic_out.img.stride[2] = pic_out.img.stride[3] = 0;

    sws_ctx = sws_getContext(config->width, config->height, PIX_FMT_YUV420P,
                             config->width, config->height, PIX_FMT_RGB24,
                             SWS_FAST_BILINEAR | SWS_ACCURATE_RND,
                             NULL, NULL, NULL);

    sws_scale(sws_ctx, pic->img.plane, pic->img.stride, 0, config->height, pic_out.img.plane, pic_out.img.stride);

    __asm__ volatile ("emms\n\t");

    png_set_IHDR(h->png, h->info, config->width, config->height,
                 8, PNG_COLOR_TYPE_RGB, PNG_INTERLACE_NONE,
                 PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT);

    for (i = 0; i < config->height; i++)
        rows[i] = pic_out.img.plane[0] + i * pic_out.img.stride[0];

    png_set_rows(h->png, h->info, rows);

    png_write_png(h->png, h->info, 0, NULL);

    free(rows);
    free(out_data);

    return 0;
}
开发者ID:saintdev,项目名称:frameshot,代码行数:39,代码来源:output.c


示例8: png_set_IHDR

  void PngWriter::Compress(unsigned int width,
                           unsigned int height,
                           unsigned int pitch,
                           PixelFormat format)
  {
    png_set_IHDR(pimpl_->png_, pimpl_->info_, width, height,
                 pimpl_->bitDepth_, pimpl_->colorType_, PNG_INTERLACE_NONE,
                 PNG_COMPRESSION_TYPE_BASE, PNG_FILTER_TYPE_BASE);

    png_write_info(pimpl_->png_, pimpl_->info_);

    if (height > 0)
    {
      switch (format)
      {
      case PixelFormat_Grayscale16:
      case PixelFormat_SignedGrayscale16:
      {
        int transforms = 0;
        if (Toolbox::DetectEndianness() == Endianness_Little)
        {
          transforms = PNG_TRANSFORM_SWAP_ENDIAN;
        }

        png_set_rows(pimpl_->png_, pimpl_->info_, &pimpl_->rows_[0]);
        png_write_png(pimpl_->png_, pimpl_->info_, transforms, NULL);

        break;
      }

      default:
        png_write_image(pimpl_->png_, &pimpl_->rows_[0]);
      }
    }

    png_write_end(pimpl_->png_, NULL);
  }
开发者ID:dhanzhang,项目名称:orthanc,代码行数:37,代码来源:PngWriter.cpp


示例9: writePNG

void writePNG(const char * filename, const uchar3 * imgData, const int width, const int height) {

    FILE * fp = fopen(filename,"wb");

    png_byte* rowPointers[height];

    mainprog_info progInfo;

    png_structp pngPtr = png_create_write_struct(PNG_LIBPNG_VER_STRING, &progInfo, png_error_handler, NULL);
    png_infop infoPtr = png_create_info_struct(pngPtr);

    if (setjmp(png_jmpbuf(pngPtr))) {
        goto png_failure;
    }

    png_set_IHDR( pngPtr,
                  infoPtr,
                  width,
                  height,
                  sizeof(unsigned char)*8,
                  PNG_COLOR_TYPE_RGB,
                  PNG_INTERLACE_NONE,
                  PNG_COMPRESSION_TYPE_DEFAULT,
                  PNG_FILTER_TYPE_DEFAULT);

    for (int y = 0; y<height; ++y) {
        rowPointers[y] = (png_byte*)&imgData[y*width];
    }

    png_init_io(pngPtr, fp);
    png_set_rows(pngPtr,infoPtr,rowPointers);
    png_write_png(pngPtr,infoPtr,PNG_TRANSFORM_SWAP_ENDIAN,NULL);

png_failure:
    png_destroy_write_struct(&pngPtr,&infoPtr);
    fclose(fp);
}
开发者ID:CSE512-15S,项目名称:fp-tws10,代码行数:37,代码来源:image_io.cpp


示例10: wrPng

void wrPng(BYTE *bits, int w, int h, int line, FILE *f)
{
	png_structp png_ptr;
	png_infop info_ptr;

	png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, 0, 0, 0);
	if(png_ptr){
		info_ptr = png_create_info_struct(png_ptr);
		if(info_ptr){
			if(!setjmp(png_jmpbuf(png_ptr))){
				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);
				BYTE **row_pointers = (BYTE**)png_malloc(png_ptr, h*png_sizeof(png_bytep));
				for(int i=0; i<h; i++){
					row_pointers[i]= bits+(h-i-1)*line;
				}
				png_set_rows(png_ptr, info_ptr, row_pointers);
				png_write_png(png_ptr, info_ptr, PNG_TRANSFORM_BGR, 0);
				png_free(png_ptr, row_pointers);
			}
		}
		png_destroy_write_struct(&png_ptr, &info_ptr);
	}
}
开发者ID:kambala-decapitator,项目名称:colorsudoku,代码行数:24,代码来源:sudoku.cpp


示例11: WritePng

		WritePng(const char *file_name, grid<T> &grd){
			transforms = PNG_TRANSFORM_IDENTITY;
			status = PENDING;
			this->grd = &grd;
			FILE *fp = fopen(file_name, "wb");
			if (!fp){
				status = FILE_ERROR;
				return;
			}

			png_ptr = png_create_write_struct(
				PNG_LIBPNG_VER_STRING, (png_voidp)NULL, NULL, NULL);
    		if (!png_ptr){
       			status = PNG_ERROR;
       			return;
       		}

       		info_ptr = png_create_info_struct(png_ptr);
    		if (!info_ptr){
       			png_destroy_write_struct(&png_ptr, (png_infopp)NULL);
       			status = PNG_ERROR;
       			return;
    		}

    		png_init_io(png_ptr, fp);

    		setup_png();

    		setup_rows();
    		png_set_rows(png_ptr, info_ptr, rows);

			png_write_png(png_ptr, info_ptr, transforms, NULL);
			status = OK;
			fclose(fp);
			return;
		};
开发者ID:stestagg,项目名称:Personal,代码行数:36,代码来源:output.hpp


示例12: buffer_to_png

/**
* RGB byte [8 bits per channel] buffer to PNG file.
*
* @param    uint8_t *buffer
* @param    int width
* @param    int height
* @param    char *path
* @return   -1 on error
**/
int buffer_to_png(uint8_t *buffer, int width, int height, char *path)
{
    int x, y, i;
    int bytes_per_row = width * 3;
    
    /* libpng stuff */
    png_structp png_ptr = NULL;
    png_infop info_ptr = NULL;
    png_byte **row_pointers = NULL;

    FILE *fp = fopen(path, "wb");
    if (!fp) {
        return -1;
    }
    
    /* Initialize */
    png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
    if (png_ptr == NULL) {
        fclose(fp);
        return -1;
    }

    info_ptr = png_create_info_struct(png_ptr);
    if (info_ptr == NULL) {
        png_destroy_write_struct(&png_ptr, NULL);
        fclose(fp);
        return -1;
    }

    /* Error Handling */
    if (setjmp(png_jmpbuf(png_ptr))) {
        png_destroy_write_struct(&png_ptr, &info_ptr);
        fclose(fp);
        return -1;
    }
    
    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);

    /* Copy RGB buffer into PNG buffer */
    row_pointers = png_malloc(png_ptr, height * sizeof(png_byte *));
    i = 0;
    for (y = 0; y < height; ++y) {
        uint8_t *data = png_malloc(png_ptr, sizeof(uint8_t) * bytes_per_row);
        row_pointers[y] = (png_byte *)data;
        
        for (x = 0; x < width; ++x) {
            *data++ = buffer[i++];
            *data++ = buffer[i++];
            *data++ = buffer[i++];
        }
    }

    /* Write file */
    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);

    /* Free memory, cleanup */
    for (y = 0; y < height; y++) {
        png_free(png_ptr, row_pointers[y]);
    }
    
    png_free(png_ptr, row_pointers);
    png_destroy_write_struct(&png_ptr, &info_ptr);
    fclose(fp);
    return 0;
}
开发者ID:cleure,项目名称:TV4X,代码行数:80,代码来源:pngutil.c


示例13: RE_SavePNG

int RE_SavePNG( const char *filename, byte *buf, size_t width, size_t height, int byteDepth ) {
	fileHandle_t fp;
	png_structp png_ptr = NULL;
	png_infop info_ptr = NULL;
	unsigned int x, y;
	png_byte ** row_pointers = NULL;
	/* "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 depth = 8;

	fp = ri->FS_FOpenFileWrite( filename );
	if ( !fp ) {
		goto fopen_failed;
	}

	png_ptr = png_create_write_struct (PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
	if (png_ptr == NULL) {
		goto png_create_write_struct_failed;
	}

	info_ptr = png_create_info_struct (png_ptr);
	if (info_ptr == NULL) {
		goto png_create_info_struct_failed;
	}

	/* Set up error handling. */

	if (setjmp (png_jmpbuf (png_ptr))) {
		goto png_failure;
	}

	/* Set image attributes. */

	png_set_IHDR (png_ptr,
		info_ptr,
		width,
		height,
		depth,
		PNG_COLOR_TYPE_RGB,
		PNG_INTERLACE_NONE,
		PNG_COMPRESSION_TYPE_DEFAULT,
		PNG_FILTER_TYPE_DEFAULT);

	/* Initialize rows of PNG. */

	row_pointers = (png_byte **)png_malloc (png_ptr, height * sizeof (png_byte *));
	for ( y=0; y<height; ++y ) {
		png_byte *row = (png_byte *)png_malloc (png_ptr, sizeof (uint8_t) * width * byteDepth);
		row_pointers[height-y-1] = row;
		for (x = 0; x < width; ++x) {
			byte *px = buf + (width * y + x)*3;
			*row++ = px[0];
			*row++ = px[1];
			*row++ = px[2];
		}
	}

	/* Write the image data to "fp". */

//	png_init_io (png_ptr, fp);
	png_set_write_fn( png_ptr, (png_voidp)&fp, user_write_data, user_flush_data );
	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. */

	status = 0;

	for (y = 0; y < height; y++) {
		png_free (png_ptr, row_pointers[y]);
	}
	png_free (png_ptr, row_pointers);

png_failure:
png_create_info_struct_failed:
	png_destroy_write_struct (&png_ptr, &info_ptr);
png_create_write_struct_failed:
	ri->FS_FCloseFile( fp );
fopen_failed:
	return status;
}
开发者ID:Resuru,项目名称:JediKnightGalaxies,代码行数:88,代码来源:tr_image_png.cpp


示例14: rgb24_to_png

/**
* Save PNG file from RGB24 buffer
*
* @param    uint32_t *buffer
* @param    int width
* @param    int height
* @param    char *path
* @return   -1 on error
**/
int rgb24_to_png(uint32_t *buffer, int width, int height, char *path)
{
    int x, y;
    int bytes_per_row = width * 3;
    
    uint8_t r, g, b;
    uint32_t *in = buffer;
    
    /* libpng stuff */
    png_structp png_ptr = NULL;
    png_infop info_ptr = NULL;
    png_byte **row_pointers = NULL;

    FILE *fp = fopen(path, "wb");
    if (!fp) {
        return -1;
    }
    
    /* Initialize */
    png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
    if (png_ptr == NULL) {
        fclose(fp);
        return -1;
    }

    info_ptr = png_create_info_struct(png_ptr);
    if (info_ptr == NULL) {
        png_destroy_write_struct(&png_ptr, NULL);
        fclose(fp);
        return -1;
    }

    /* Error Handling */
    if (setjmp(png_jmpbuf(png_ptr))) {
        png_destroy_write_struct(&png_ptr, &info_ptr);
        fclose(fp);
        return -1;
    }
    
    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);

    /* Copy RGB buffer into PNG buffer */
    row_pointers = png_malloc(png_ptr, height * sizeof(png_byte *));
    
    for (y = 0; y < height; y++) {
        /* Allocate */
        row_pointers[y] = png_malloc(png_ptr, sizeof(uint8_t) * bytes_per_row);
        
        for (x = 0; x < width; x++) {
            /* Unpack pixels */
            UNPACK_RGB(r, g, b, tvxx_rgb_format_rgb24, *in);
            /*UNPACK_RGB(r, g, b, tvxx_rgb_format_rgb15, *in);
            
            r *= (255/31);
            g *= (255/31);
            b *= (255/31);*/
            
            /* Copy */
            row_pointers[y][(x * 3) + 0] = r;
            row_pointers[y][(x * 3) + 1] = g;
            row_pointers[y][(x * 3) + 2] = b;
            
            /* Increment RGB24 pointer */
            in++;
        }
    }

    /* Write file */
    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);

    /* Free memory, cleanup */
    for (y = 0; y < height; y++) {
        png_free(png_ptr, row_pointers[y]);
    }
    
    png_free(png_ptr, row_pointers);
    png_destroy_write_struct(&png_ptr, &info_ptr);
    fclose(fp);
    return 0;
}
开发者ID:cleure,项目名称:TV4X,代码行数:95,代码来源:pngutil.c


示例15: save_heightmap_png

bool save_heightmap_png(long double lat, long double lon, long double span_h, long double span_w, const char *outfile)
{
   int x1, x2, y1, y2;
   bool ret = false;
   FILE *fp = NULL;
   png_structp png_ptr = NULL;
   png_infop info_ptr = NULL;
   size_t x, y, w, h, skip;
   png_bytepp row_pointers;
   png_bytep row;
   int16_t elevation, height;

   /* Pointer to humongous (7GB) S_MAPW x S_MAPH 16-bit map data (see map.c) */
   int16_t *mapp = (int16_t *)map[0];

   /* Map longitude/latidude to pixel coordinates in source image */
   x1 = ((lon + 180.0) / (long double)360) * S_MAPW;
   x2 = (((lon + span_w) + 180.0) / (long double)360) * S_MAPW - 1;
   y1 = ((90 - lat) / (long double)180) * S_MAPH;
   y2 = ((90 - (lat - span_h)) / (long double)180) * S_MAPH - 1;

   w = x2 - x1 + 1;
   h = y2 - y1 + 1;

   printf("%s: %dx%d ... ", outfile, (int)w, (int)h);
   fflush(stdout);

   /* Advance mapp to first pixel */
   mapp += (uint64_t)x1 + (uint64_t)S_MAPW * (uint64_t)y1;

   /* Skip this many int16_t:s to get to next line */
   skip = S_MAPW - w;

   /* libpng stuff below */

   png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
   if (png_ptr == NULL) {
      goto out;
   }

   info_ptr = png_create_info_struct(png_ptr);
   if (info_ptr == NULL) {
      png_destroy_write_struct(&png_ptr, NULL);
      goto out;
   }

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

   /* Specify 16-bit grayscale in png header */
   png_set_IHDR(png_ptr, info_ptr,
                w, h,
                16,
                PNG_COLOR_TYPE_GRAY,
                PNG_INTERLACE_NONE, PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT);


   /* Alloc mem for png image data */
   row_pointers = (png_bytepp)png_malloc(png_ptr, h * png_sizeof(png_bytep));
   for (y = 0; y < h; y++) {
      row_pointers[y] = png_malloc(png_ptr, w * 2);
   }

   /* Copy image data from mapp to row_pointers */
   for (y = 0; y < h; y++) {
      row = row_pointers[y];
      for (x = 0; x < w; x++) {

         /* Read 2 big endian source bytes */
         elevation = *mapp++;

         /* Clamp negative heights to 0 */
         height = ntohs(elevation); /* swap bytes if little endian */
         if (height < 0) {
            elevation = 0;
         }

         /* Write 2 bytes to destination */
         *row++ = (png_byte)(elevation & 0xff);
         *row++ = (png_byte)(elevation >> 8);
      }
      mapp += skip;
   }

   /* Write image data to fp */

   if (!(fp = fopen(outfile, "w"))) {
      perror(outfile);
      goto out2;
   }

   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);

   ret = true;

 out2:
//.........这里部分代码省略.........
开发者ID:AlbertVeli,项目名称:heightmap,代码行数:101,代码来源:hmpng.c


示例16: png_create_write_struct


//.........这里部分代码省略.........
	// Set info
	switch(image->getColorFormat())
	{
		case ECF_A8R8G8B8:
		case ECF_A1R5G5B5:
			png_set_IHDR(png_ptr, info_ptr,
				image->getDimension().Width, image->getDimension().Height,
				8, PNG_COLOR_TYPE_RGB_ALPHA, PNG_INTERLACE_NONE,
				PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT);
		break;
		default:
			png_set_IHDR(png_ptr, info_ptr,
				image->getDimension().Width, image->getDimension().Height,
				8, PNG_COLOR_TYPE_RGB, PNG_INTERLACE_NONE,
				PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT);
	}

	s32 lineWidth=image->getDimension().Width;
	switch(image->getColorFormat())
	{
	case ECF_R8G8B8:
	case ECF_R5G6B5:
		lineWidth*=3;
		break;
	case ECF_A8R8G8B8:
	case ECF_A1R5G5B5:
		lineWidth*=4;
		break;
	}
	u8* tmpImage = new u8[image->getDimension().Height*lineWidth];
	if (!tmpImage)
	{
		os::Printer::log("PNGWriter: Internal PNG create image failure\n", file->getFileName(), ELL_ERROR);
		png_destroy_write_struct(&png_ptr, &info_ptr);
		return false;
	}

	u8* data = (u8*)image->lock();
	switch(image->getColorFormat())
	{
	case ECF_R8G8B8:
		CColorConverter::convert_R8G8B8toR8G8B8(data,image->getDimension().Height*image->getDimension().Width,tmpImage);
		break;
	case ECF_A8R8G8B8:
		CColorConverter::convert_A8R8G8B8toA8R8G8B8(data,image->getDimension().Height*image->getDimension().Width,tmpImage);
		break;
	case ECF_R5G6B5:
		CColorConverter::convert_R5G6B5toR8G8B8(data,image->getDimension().Height*image->getDimension().Width,tmpImage);
		break;
	case ECF_A1R5G5B5:
		CColorConverter::convert_A1R5G5B5toA8R8G8B8(data,image->getDimension().Height*image->getDimension().Width,tmpImage);
		break;
	}
	image->unlock();

	// Create array of pointers to rows in image data

	//Used to point to image rows
	u8** RowPointers = new png_bytep[image->getDimension().Height];
	if (!RowPointers)
	{
		os::Printer::log("PNGWriter: Internal PNG create row pointers failure\n", file->getFileName(), ELL_ERROR);
		png_destroy_write_struct(&png_ptr, &info_ptr);
		delete [] tmpImage;
		return false;
	}

	data=tmpImage;
	// Fill array of pointers to rows in image data
	for (u32 i=0; i<image->getDimension().Height; ++i)
	{
		RowPointers[i]=data;
		data += lineWidth;
	}
	// for proper error handling
	if (setjmp(png_jmpbuf(png_ptr)))
	{
		png_destroy_write_struct(&png_ptr, &info_ptr);
		delete [] RowPointers;
		delete [] tmpImage;
		return false;
	}

	png_set_rows(png_ptr, info_ptr, RowPointers);

	if (image->getColorFormat()==ECF_A8R8G8B8 || image->getColorFormat()==ECF_A1R5G5B5)
		png_write_png(png_ptr, info_ptr, PNG_TRANSFORM_BGR, NULL);
	else
	{
		png_write_png(png_ptr, info_ptr, PNG_TRANSFORM_IDENTITY, NULL);
	}

	delete [] RowPointers;
	delete [] tmpImage;
	png_destroy_write_struct(&png_ptr, &info_ptr);
	return true;
#else
	return false;
#endif
}
开发者ID:344717871,项目名称:STK_android,代码行数:101,代码来源:CImageWriterPNG.cpp


示例17: impl_save_png

        void impl_save_png (
            const std::string& file_name,
            std::vector<unsigned char*>& row_pointers,
            const long width,
            const png_type type,
            const int bit_depth
        )
        {

            FILE *fp;
            png_structp png_ptr;
            png_infop info_ptr;

            /* Open the file */
            fp = fopen(file_name.c_str(), "wb");
            if (fp == NULL)
                throw image_save_error("Unable to open " + file_name + " for writing.");

            /* 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, NULL, &png_reader_user_error_fn_silent, &png_reader_user_warning_fn_silent);

            if (png_ptr == NULL)
            {
                fclose(fp);
                throw image_save_error("Error while writing PNG file " + file_name);
            }

            /* Allocate/initialize the image information data.  REQUIRED */
            info_ptr = png_create_info_struct(png_ptr);
            if (info_ptr == NULL)
            {
                fclose(fp);
                png_destroy_write_struct(&png_ptr,  NULL);
                throw image_save_error("Error while writing PNG file " + file_name);
            }

            /* Set error handling.  REQUIRED if you aren't supplying your own
            * error handling functions in the png_create_write_struct() call.
            */
            if (setjmp(png_jmpbuf(png_ptr)))
            {
                /* If we get here, we had a problem writing the file */
                fclose(fp);
                png_destroy_write_struct(&png_ptr, &info_ptr);
                throw image_save_error("Error while writing PNG file " + file_name);
            }

            int color_type = 0;
            switch(type)
            {
                case png_type_rgb:       color_type = PNG_COLOR_TYPE_RGB; break;
                case png_type_rgb_alpha: color_type = PNG_COLOR_TYPE_RGB_ALPHA; break;
                case png_type_gray:      color_type = PNG_COLOR_TYPE_GRAY; break;
                default:
                    {
                        fclose(fp);
                        png_destroy_write_struct(&png_ptr, &info_ptr);
                        throw image_save_error("Invalid color type");
                    }
            }


            /* Set up the output control if you are using standard C streams */
            png_init_io(png_ptr, fp);


            const int png_transforms = PNG_TRANSFORM_IDENTITY;
            const long height = row_pointers.size();


            png_set_IHDR(png_ptr, info_ptr, width, height, bit_depth, color_type, PNG_INTERLACE_NONE, PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT);
            png_set_rows(png_ptr, info_ptr, &row_pointers[0]);
            png_write_png(png_ptr, info_ptr, png_transforms, NULL);

            /* Clean up after the write, and free any memory allocated */
            png_destroy_write_struct(&png_ptr, &info_ptr);

            /* Close the file */
            fclose(fp);
        }
开发者ID:Firfi,项目名称:kelpi_rs,代码行数:85,代码来源:save_png.cpp


示例18: save_as_png

void save_as_png(T1 & file,
                 T2 const& image,
                 int compression = Z_DEFAULT_COMPRESSION,
                 int strategy = Z_DEFAULT_STRATEGY,
                 int alpha = false,
                 bool use_miniz = false)
{
    if (use_miniz) {
        MiniZ::PNGWriter writer(compression);
        if (alpha) {
            writer.writeIHDR(image.width(), image.height(), 32);
            writer.writeIDAT(image);
        } else {
            writer.writeIHDR(image.width(), image.height(), 24);
            writer.writeIDATStripAlpha(image);
        }
        writer.writeIEND();
        writer.toStream(file);
        return;
    }

    png_voidp error_ptr=0;
    png_structp png_ptr=png_create_write_struct(PNG_LIBPNG_VER_STRING,
                        error_ptr,0, 0);

    if (!png_ptr) return;

    // switch on optimization only if supported
#if defined(PNG_LIBPNG_VER) && (PNG_LIBPNG_VER >= 10200) && defined(PNG_MMX_CODE_SUPPORTED)
    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
    png_set_filter(png_ptr, PNG_FILTER_TYPE_BASE, PNG_FILTER_NONE);
    png_infop info_ptr = png_create_info_struct(png_ptr);
    if (!info_ptr)
    {
        png_destroy_write_struct(&png_ptr,(png_infopp)0);
        return;
    }
    jmp_buf* jmp_context = (jmp_buf*) png_get_error_ptr(png_ptr);
    if (jmp_context)
    {
        png_destroy_write_struct(&png_ptr, &info_ptr);
        return;
    }
    png_set_write_fn (png_ptr, &file, &write_data<T1>, &flush_data<T1>);

    png_set_compression_level(png_ptr, compression);
    png_set_compression_strategy(png_ptr, strategy);
    png_set_compression_buffer_size(png_ptr, 32768);

    png_set_IHDR(png_ptr, info_ptr, image.width(), image.height(), 8,
                 alpha ? PNG_COLOR_TYPE_RGB_ALPHA : PNG_COLOR_TYPE_RGB,
                 PNG_INTERLACE_NONE, PNG_COMPRESSION_TYPE_DEFAULT,
                 PNG_FILTER_TYPE_DEFAULT);

    png_bytep row_pointers[image.height()];
    for (unsigned int i = 0; i < image.height(); i++) {
        row_pointers[i] = (png_bytep)image.getRow(i);
    }
    png_set_rows(png_ptr, info_ptr, (png_bytepp)&row_pointers);
    png_write_png(png_ptr, info_ptr, alpha ? PNG_TRANSFORM_IDENTITY : PNG_TRANSFORM_STRIP_FILLER_AFTER, NULL);
    png_destroy_write_struct(&png_ptr, &info_ptr);
}
开发者ID:zeke,项目名称:node-blend,代码行数:66,代码来源:png_io.hpp


示例19: SavePng

void SavePng(const Image<unsigned char>& image, const pangolin::PixelFormat& fmt, const std::string& filename, bool top_line_first)
{
    PANGOLIN_UNUSED(image);
    PANGOLIN_UNUSED(filename);
    PANGOLIN_UNUSED(top_line_first);

    // Check image has supported bit depth
    for(unsigned int i=1; i < fmt.channels; ++i) {
        if( fmt.channel_bits[i] != fmt.channel_bits[0] ) {
            throw std::runtime_error("PNG Saving only supported for images where each channel has the same bit depth.");
        }
    }

#ifdef HAVE_PNG
    FILE *fp;
    png_structp png_ptr;
    png_infop info_ptr;

    // Open file for writing (binary mode)
    fp = fopen(filename.c_str(), "wb");
    if (fp == NULL) {
        throw std::runtime_error( "PNG Error: Could not open file '" + filename + "' for writing" );
    }

    // Initialize write structure
    png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
    if (png_ptr == NULL) {
        fclose(fp);
        throw std::runtime_error( "PNG Error: Could not allocate write struct." );
    }

    // Initialize info structure
    info_ptr = png_create_info_struct(png_ptr);
    if (info_ptr == NULL) {
        png_destroy_write_struct(&png_ptr, (png_infopp)NULL);
        fclose(fp);
        throw std::runtime_error( "PNG Error: Could not allocate info struct." );
    }

    // Setup Exception handling
    if (setjmp(png_jmpbuf(png_ptr))) {
        png_free_data(png_ptr, info_ptr, PNG_FREE_ALL, -1);
        png_destroy_write_struct(&png_ptr, (png_infopp)NULL);
        fclose(fp);
        throw std::runtime_error( "PNG Error: Error during png creation." );
    }

    png_init_io(png_ptr, fp);

    const int bit_depth = fmt.channel_bits[0];

    int colour_type;
    switch (fmt.channels) {
    case 1: colour_type = PNG_COLOR_TYPE_GRAY; break;
    case 2: colour_type = PNG_COLOR_TYPE_GRAY_ALPHA; break;
    case 3: colour_type = PNG_COLOR_TYPE_RGB; break;
    case 4: colour_type = PNG_COLOR_TYPE_RGBA; break;
    default:
        throw std::runtime_error( "PNG Error: unexpected image channel number");
    }

    // Write header
    png_set_IHDR(
        png_ptr, info_ptr, (png_uint_32)image.w, (png_uint_32)image.h, bit_depth, colour_type,
        PNG_INTERLACE_NONE, PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT
    );

    // Setup rows to write:
    std::vector<png_bytep> rows(image.h);
    if(top_line_first) {
        for (unsigned int y = 0; y< image.h; y++) {
            rows[y] = image.ptr + y*image.pitch;
        }
    }else{
        for (unsigned int y = 0; y< image.h; y++) {
            rows[y] = image.ptr + (image.h-1-y)*image.pitch;
        }
    }
    png_set_rows(png_ptr,info_ptr, &rows[0]);

    // Write image data: switch to little-endian byte order, to match host.
    png_write_png(png_ptr,info_ptr, PNG_TRANSFORM_SWAP_ENDIAN, 0);

    // Free resources
    fclose(fp);
    png_free_data(png_ptr, info_ptr, PNG_FREE_ALL, -1);
    png_destroy_write_struct(&png_ptr, (png_infopp)NULL);

#else
    throw std::runtime_error("PNG Support not enabled. Please rebuild Pangolin.");
#endif
}
开发者ID:amarburg,项目名称:Pangolin,代码行数:92,代码来源:image_io.cpp


示例20: save_png

/* Save the two dimensional array as a png image
 * Arguments:
 *   double *data is a pointer to an array of nx*ny values
 *   int nx is the number of COLUMNS to be written
 *   int ny is the number of ROWS to be written
 *   char *fname is the name of the picture
 *   char lang is either 'c' or 'f' denoting the memory
 *             layout. That is, if 'f' is given, then rows
 *             and columns are swapped.
 */
int save_png(double *data, const int height, const int width,
             const char *fname, const char lang)
{
    FILE *fp;
    png_structp pngstruct_ptr = NULL;
    png_infop pnginfo_ptr = NULL;
    png_byte **row_pointers = NULL;
    int i, j;

    /* Default return status is failure */
    int status = -1;

    int pixel_size = 3;
    int depth = 8;

    fp = fopen(fname, "wb");
    if (fp == NULL)
        goto fopen_failed;

    pngstruct_ptr =
        png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);

    if (pngstruct_ptr == NULL)
        goto pngstruct_create_failed;

    pnginfo_ptr = png_create_info_struct(pngstruct_ptr);

    if (pnginfo_ptr == NULL)
        goto pnginfo_create_failed;

    if (setjmp(png_jmpbuf(pngstruct_ptr)))
        goto setjmp_failed;

    png_set_IHDR(pngstruct_ptr, pnginfo_ptr, (size_t) width,
                 (size_t) height, depth, PNG_COLOR_TYPE_RGB,
                 PNG_INTERLACE_NONE,
                 PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT);

    row_pointers = png_malloc(pngstruct_ptr, height * sizeof(png_byte *));

    for (i = 0; i < height; i++) {
        png_byte *row = png_malloc(pngstruct_ptr,
                                   sizeof(uint8_t) * width * pixel_size);
        row_pointers[i] = row;

        // Branch according to the memory layout
        if (lang == 'c' || lang == 'C') {
            for (j = 0; j < width; j++) {
                pixel_t pixel;
                // Scale the values so that values between
                // 0 and 100 degrees are mapped to values
                // between 0 and 255
                cmap(data[j + i * width], 2.55, 0.0, &pixel);
                *row++ = pixel.red;
                * 

鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ png_write_row函数代码示例发布时间:2022-05-30
下一篇:
C++ png_write_info函数代码示例发布时间:2022-05-30
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap