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


C++ png_write_png函数代码示例

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


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


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