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

C++ png_check_sig函数代码示例

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

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



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

示例1: setup_png_reader

/**
 * Initialize png reader struct.
 */
void setup_png_reader(const char* data, size_t length, png_structp* outpng_ptr, png_infop* out_info_ptr) {
  if (length <= PNG_HEADER_SIZE || !png_check_sig((png_bytep)data, PNG_HEADER_SIZE)) {
    logstream(LOG_ERROR) << "Invalid PNG signature" << std::endl;
    throw(std::string("Invalid PNG file"));
  }

  // Begin setup
  // main png read struct
  png_structp png_ptr = NULL;
  png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, png_error_handler, NULL);
  if(png_ptr == NULL) {
    logstream(LOG_ERROR) << "Fail allocating PNG reader struct" << std::endl;
    throw(std::string("Unexpected libpng error"));
  }

  // png info struct
  png_infop info_ptr = NULL;
  info_ptr = png_create_info_struct(png_ptr);
  if(info_ptr == NULL) {
    // libpng must free file info struct memory before we bail
    png_destroy_read_struct(&png_ptr, NULL, NULL);
    logstream(LOG_ERROR) << "Fail allocating PNG info struct" << std::endl;
    throw(std::string("Unexpected libpng error"));
  }

  *outpng_ptr = png_ptr;
  *out_info_ptr = info_ptr;
}
开发者ID:DreamStudio2015,项目名称:SFrame,代码行数:31,代码来源:png_io.cpp


示例2: ifile

bool PngLoader::load( std::string file )
{
    png_structp png_ptr;
    png_infop info_ptr;
  
    std::ifstream ifile( file.c_str(), std::ios::binary );
 
    if( !ifile.is_open() )
        return false;
 
    char assinatura[8];
    ifile.read( &assinatura[0], 8 * sizeof(char) );
  
    if(!png_check_sig( (png_bytep)assinatura, 8) )
    {
        return false;
    }
 
    png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, 0, 0, 0);
 
    if(png_ptr == 0)
    {
        return false;
    }
 
    info_ptr = png_create_info_struct( png_ptr );
 
    if( info_ptr == 0 )
    {
        png_destroy_read_struct( &png_ptr, 0, 0 );
        return false;
    }
 
    png_set_read_fn( png_ptr, (void*)&ifile, readFileCallback );
 
    png_set_sig_bytes( png_ptr, 8 );
 
    png_read_info( png_ptr, info_ptr );
 
    png_get_IHDR( png_ptr, info_ptr, (png_uint_32*)&width, (png_uint_32*)&height,
                  &depth, &color_type, 0, 0, 0 );
 
    cols = png_get_rowbytes(png_ptr, info_ptr);
 
    png_bytepp row_pp = new png_bytep[height];
    data = new char[ cols * height ];
 
    for( int i = 0; i < height; ++i )
    {
        row_pp[height - i - 1] = (png_bytep)&data[ i * cols ];
    }
 
    png_read_image( png_ptr, row_pp );
    png_read_end( png_ptr, info_ptr );
 
    png_destroy_read_struct( &png_ptr, &info_ptr, 0 );
 
    delete[] row_pp;
    return true;
}
开发者ID:thebracket,项目名称:bgame,代码行数:60,代码来源:PngLoader.cpp


示例3: readpng_init

uint32 readpng_init(FILE *infile)
{
    uint8 sig[8];

    /* first do a quick check that the file really is a PNG image; could
     * have used slightly more general png_sig_cmp() function instead */

    fread(sig, 1, 8, infile);
    if (!png_check_sig(sig, 8))
        return 1;   /* bad signature */

    /* could pass pointers to user-defined error handlers instead of NULLs: */

    png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
    if (!png_ptr)
        return 4;   /* out of memory */

    info_ptr = png_create_info_struct(png_ptr);
    if (!info_ptr) {
        png_destroy_read_struct(&png_ptr, NULL, NULL);
        return 4;   /* out of memory */
    }

    png_init_io(png_ptr, infile);
    png_set_sig_bytes(png_ptr, 8);  /* we already read the 8 signature bytes */

    png_read_info(png_ptr, info_ptr);  /* read all PNG info up to image data */

    /* OK, that's all we need for now; return happy */

    return 0;
}
开发者ID:andressbarajas,项目名称:DCMappy,代码行数:32,代码来源:readpng.c


示例4: get_raw_image_data_from_png

RawImageData get_raw_image_data_from_png(const void* png_data, const int png_data_size)
{
	assert(png_data != NULL && png_data_size > 8);
	assert(png_check_sig((void*)png_data, 8));

	png_structp png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
	assert(png_ptr != NULL);
	png_infop info_ptr = png_create_info_struct(png_ptr);
	assert(info_ptr != NULL);

	ReadDataHandle png_data_handle = (ReadDataHandle) {{png_data, png_data_size}, 0};
	png_set_read_fn(png_ptr, &png_data_handle, read_png_data_callback);

	if (setjmp(png_jmpbuf(png_ptr)))
    {
		CRASH("Error reading PNG file!");
	}

	const PngInfo png_info = read_and_update_info(png_ptr, info_ptr);
	const DataHandle raw_image = read_entire_png_image(png_ptr, info_ptr, png_info.height);

	png_read_end(png_ptr, info_ptr);
	png_destroy_read_struct(&png_ptr, &info_ptr, NULL);

	return (RawImageData)
    {
        png_info.width,
        png_info.height,
        raw_image.size,
        get_gl_color_format(png_info.color_type),
        raw_image.data
    };
}
开发者ID:googler2013,项目名称:tappy-plane,代码行数:33,代码来源:image.c


示例5: isALoadableFileFormat

//! returns true if the file maybe is able to be loaded by this class
bool CImageLoaderPng::isALoadableFileFormat(engine::io::IReadFile* file)
{
#ifdef _engine_COMPILE_WITH_LIBPNG_

	if (!file)
		return false;

	// Read the first few bytes of the PNG file
	if (file->read(&g_png_load_buffer, 8) != 8)
	{
		//os::Printer::log("Not a PNG file: can't read file\n", file->getFileName(), ELL_ERROR);
		return false;
	}

	// CHeck if it really is a PNG file
	if (!png_check_sig((png_bytep)g_png_load_buffer, 8))
	{
		//os::Printer::log("Not a PNG file: wrong header\n", file->getFileName(),ELL_ERROR);
		return false;
	}

	return true; //if we are here then it must be a png

#else
	return false;
#endif // _engine_COMPILE_WITH_LIBPNG_
}
开发者ID:jduranmaster,项目名称:ltegameengine,代码行数:28,代码来源:CImageLoaderPNG.cpp


示例6: fopen

int FilePNG::check_sig(Asset *asset)
{
	FILE *stream = fopen(asset->path, "rb");

	if(stream)
	{

//printf("FilePNG::check_sig 1\n");
		char test[16];
		fread(test, 16, 1, stream);
		fclose(stream);

		if(png_check_sig((unsigned char*)test, 8))
		{
//printf("FilePNG::check_sig 1\n");
			return 1;
		}
		else
		if(test[0] == 'P' && test[1] == 'N' && test[2] == 'G' && 
			test[3] == 'L' && test[4] == 'I' && test[5] == 'S' && test[6] == 'T')
		{
//printf("FilePNG::check_sig 1\n");
			return 1;
		}
	}
	return 0;
}
开发者ID:rasilon,项目名称:cinelerra-cv,代码行数:27,代码来源:filepng.C


示例7: readpng_init

int readpng_init(FILE *infile, long *pWidth, long *pHeight)
{
    uch sig[8];


    /* first do a quick check that the file really is a PNG image; could
     * have used slightly more general png_sig_cmp() function instead */

    fread(sig, 1, 8, infile);
    if (!png_check_sig(sig, 8))
        return 1;   /* bad signature */


    /* could pass pointers to user-defined error handlers instead of NULLs: */

    png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
    if (!png_ptr)
        return 4;   /* out of memory */

    info_ptr = png_create_info_struct(png_ptr);
    if (!info_ptr) {
        png_destroy_read_struct(&png_ptr, NULL, NULL);
        return 4;   /* out of memory */
    }


    /* we could create a second info struct here (end_info), but it's only
     * useful if we want to keep pre- and post-IDAT chunk info separated
     * (mainly for PNG-aware image editors and converters) */


    /* setjmp() must be called in every function that calls a PNG-reading
     * libpng function */

    if (setjmp(png_ptr->jmpbuf)) {
        png_destroy_read_struct(&png_ptr, &info_ptr, NULL);
        return 2;
    }


    png_init_io(png_ptr, infile);
    png_set_sig_bytes(png_ptr, 8);  /* we already read the 8 signature bytes */

    png_read_info(png_ptr, info_ptr);  /* read all PNG info up to image data */


    /* alternatively, could make separate calls to png_get_image_width(),
     * etc., but want bit_depth and color_type for later [don't care about
     * compression_type and filter_type => NULLs] */

    png_get_IHDR(png_ptr, info_ptr, &width, &height, &bit_depth, &color_type,
      NULL, NULL, NULL);
    *pWidth = width;
    *pHeight = height;


    /* OK, that's all we need for now; return happy */

    return 0;
}
开发者ID:sharkcz,项目名称:xtrkcad,代码行数:60,代码来源:readpng.c


示例8: GetImageInfo

   virtual bool GetImageInfo(dword header, int limit_size_x, int limit_size_y, C_fixed limit_ratio){

      if(!png_check_sig((byte*)&header, 4))
         return false;
      png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, this, PNG_Error, PNG_Error);
      if(!png_ptr)
         return false;
      //E_LOADER_RESULT ret = IMGLOAD_READ_ERROR;
      info_ptr = png_create_info_struct(png_ptr);
      if(!info_ptr)
         return false;

      png_set_bgr(png_ptr);
      png_set_expand(png_ptr);
      png_set_palette_to_rgb(png_ptr);
      png_set_strip_16(png_ptr);

      png_set_gray_to_rgb(png_ptr);
      png_set_read_fn(png_ptr, (void*)fl, &ReadFromCache);
      if(!png_read_info(png_ptr, info_ptr))
         return false;

      bpp = (info_ptr->pixel_depth+7) / 8;
      if(info_ptr->pixel_depth>32)
         bpp /= 2;
      //if(info_ptr->num_palette && info_ptr->bit_depth==8)
        // pf->bytes_per_pixel = 1;
                              //if 8-bit grayscale, consider it as RGB
      size_original_x = size_x = info_ptr->width;
      size_original_y = size_y = info_ptr->height;

      return true;
   }
开发者ID:turbanoff,项目名称:X-plore,代码行数:33,代码来源:ImgLoadPNG.cpp


示例9: Probe

static DFBResult
Probe( IDirectFBImageProvider_ProbeContext *ctx )
{
     if (png_check_sig( ctx->header, 8 ))
          return DFB_OK;

     return DFB_UNSUPPORTED;
}
开发者ID:maxupunk,项目名称:DIR685,代码行数:8,代码来源:idirectfbimageprovider_png.c


示例10: check_for_png

int check_for_png (FILE *png_file) 
{
  rewind (png_file);
  if (fread (sigbytes, 1, sizeof(sigbytes), png_file) !=
      sizeof(sigbytes) ||
      (!png_check_sig (sigbytes, sizeof(sigbytes))))
    return 0;
  else
    return 1;
}
开发者ID:BackupTheBerlios,项目名称:texlive,代码行数:10,代码来源:pngimage.c


示例11: png_image_get_IHDR

bool png_image_get_IHDR(const char *fn, uint32_t *width, uint32_t *height, uint8_t *bpp)
{
	stack_chain_iterate_t sci = { 0 };
	BYTE *file_buffer = nullptr;
	file_buffer_t file = { 0 };

	json_t *chain = resolve_chain_game(fn);

	if (json_array_size(chain)) {
		log_printf("(PNG) Resolving %s...", json_array_get_string(chain, 0));
		while (file_buffer == nullptr && stack_chain_iterate(&sci, chain, SCI_BACKWARDS, nullptr) != 0) {
			file_buffer = (BYTE*)patch_file_load(sci.patch_info, sci.fn, &file.size);
		}
	}
	if (!file_buffer) {
		log_print("not found\n");
		json_decref(chain);
		return false;
	}
	patch_print_fn(sci.patch_info, sci.fn);
	log_print("\n");
	json_decref(chain);
	file.buffer = file_buffer;

	if (!png_check_sig(file.buffer, 8)) {
		log_print("Bad PNG signature!\n");
		free(file_buffer);
		return false;
	}
	file.buffer += 8;
	file.size -= 8;

	png_structp png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, png_error_callback, png_warning_callback);
	png_infop info_ptr = png_create_info_struct(png_ptr);
	if (setjmp(png_jmpbuf(png_ptr))) {
		png_destroy_read_struct(&png_ptr, &info_ptr, NULL);
		free(file_buffer);
		return false;
	}
	png_set_read_fn(png_ptr, &file, read_bytes);
	png_set_sig_bytes(png_ptr, 8);
	png_read_info(png_ptr, info_ptr);

	int color_type;
	png_get_IHDR(png_ptr, info_ptr, width, height, NULL, &color_type, NULL, NULL, NULL);
	if (bpp) {
		*bpp = (color_type & PNG_COLOR_MASK_ALPHA) ? 32 : 24;
	}

	png_destroy_read_struct(&png_ptr, &info_ptr, NULL);
	free(file_buffer);
	return true;
}
开发者ID:thpatch,项目名称:thcrap,代码行数:53,代码来源:png.cpp


示例12: ImageFormatReaderHelper

//
// Constructor
//
PNGReader::PNGReader(const QString & ext, MemoryFile & file)
	: ImageFormatReaderHelper(file)
{
	if (file.size() < 8)
		return;

	byte buf[8];
	if (!tryReadFile(buf, sizeof(buf)))
		return;

	if (png_check_sig((png_bytep)buf, sizeof(buf)))
		m_IsValid = true;
}
开发者ID:ashuron,项目名称:superplex3d_prototype,代码行数:16,代码来源:png_reader.cpp


示例13: validate

bool validate(SprigFile *pngFile) {
    
    //Allocate a buffer of 8 bytes, where we can put the file signature.
    png_byte header[8];
    
    fread(&header, 8, sizeof(png_byte), pngFile->file);
    rewind(pngFile->file);//rewind to prepare for reading the file
    
    if(!png_check_sig(header, 8))
    {
        return false;
    }
    
    return true;
}
开发者ID:meroon,项目名称:Sprig,代码行数:15,代码来源:SprigImageEncoding.cpp


示例14: opendata

	virtual bool opendata(const unsigned char *data, size_t size)
	{
		if (m_png_ptr)
			return false;
		if (size < 8)
			return false;
		if (png_check_sig(data, 8)){
			m_png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
			m_info_ptr = png_create_info_struct(m_png_ptr);
			m_data_ptr = new PNGData;
			m_data_ptr->pdata = (const unsigned char *)data;
			m_data_ptr->size = size;
			png_set_read_fn(m_png_ptr, m_data_ptr, data_from_memory);
			png_read_info(m_png_ptr, m_info_ptr);
			return true;
		}
		return false;
	}
开发者ID:maoenpei,项目名称:project_of_utils,代码行数:18,代码来源:LibPNG.cpp


示例15: check_png

/* check to see if a file is a png file using png_check_sig() */
int check_png(char * file_name)
{
   FILE *fp;
   char buf[8];
   int ret;

   fp = fopen(file_name, "rb");
   if (!fp)
      return 0;
   ret = fread(buf, 1, 8, fp);
   fclose(fp);

   if (ret != 8)
      return 0;

   ret = png_check_sig(buf, 8);

   return (ret);
}
开发者ID:deepmatrix,项目名称:blaxxun-cc3d,代码行数:20,代码来源:example.c


示例16: read_image

static int read_image(const char *filename, png24_image *image)
{
    int retval=1;
    bool using_stdin = false;
    FILE *fh;
    unsigned char buffer[8];

    if (0 == strcmp("-", filename)) {
        using_stdin = true;
        fh = stdin;
    } else {
        fh = fopen(filename, "rb");
        if (!fh) {
            return 1;
        }
    }

    setvbuf(fh, (char *)buffer, _IOFBF, 8);

    // the first read fills the buffer up, but put char back on after
    int c = fgetc(fh);
    ungetc(c, fh);

    // the png number is not really precise but I guess the situation where this would falsely pass is almost equal to 0
    if (png_check_sig(buffer, 8))
    {
        /*
         Reads image into png24_image struct. Returns non-zero on error
         */
        retval = rwpng_read_image24(fh, image, 0);
    }
#ifdef USE_LIBJPEG
    else
    {
        retval=read_image_jpeg(fh,image);
    }
#endif
    if(!using_stdin) {
        fclose(fh);
    }
    return retval;
}
开发者ID:pornel,项目名称:dssim,代码行数:42,代码来源:main.c


示例17: openfile

	virtual bool openfile(const char *filename)
	{
		if (m_png_ptr)
			return false;
		FILE *f = fopen(filename, "rb");
		if (f){
			unsigned char head[8];
			fread(head, 1, 8, f);
			if (png_check_sig(head, 8)){
				m_png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
				m_info_ptr = png_create_info_struct(m_png_ptr);
				png_init_io(m_png_ptr, f);
				png_set_sig_bytes(m_png_ptr, 8);
				png_read_info(m_png_ptr, m_info_ptr);
				m_file_ptr = f;
				return true;
			}
			fclose(f);
		}
		return false;
	}
开发者ID:maoenpei,项目名称:project_of_utils,代码行数:21,代码来源:LibPNG.cpp


示例18: querypng

static gboolean querypng(FILE *f, int *w, int *h)
{
  png_struct *png_ptr = NULL;
  png_info *info_ptr = NULL;
  png_byte buf[8];
  png_uint_32 width;
  png_uint_32 height;
  int bit_depth;
  int color_type;

  /* is it a PNG file? */
  if( fread( buf,1,8,f ) != 8 ) return FALSE;
  if( ! png_check_sig( buf,8 ) ) return FALSE;

  png_ptr = png_create_read_struct( PNG_LIBPNG_VER_STRING,NULL,NULL,NULL);
  if( !png_ptr ) return FALSE;

  info_ptr = png_create_info_struct( png_ptr );
  if( !info_ptr ){
    png_destroy_read_struct( &png_ptr,NULL,NULL );
    return FALSE;
    }

  if( setjmp( png_jmpbuf(png_ptr) ) ){
    png_destroy_read_struct( &png_ptr,&info_ptr,NULL );
    return FALSE;
    }

  png_init_io( png_ptr,f );
  png_set_sig_bytes( png_ptr,8 );
  png_read_info( png_ptr,info_ptr );

  png_get_IHDR( png_ptr,info_ptr,&width,&height,&bit_depth,
                &color_type,NULL,NULL,NULL);
  *w = width;
  *h = height;

  png_destroy_read_struct( &png_ptr,&info_ptr,NULL );
  return TRUE;
}
开发者ID:ev3dev,项目名称:grx,代码行数:40,代码来源:png2ctx.c


示例19: readpng_init

void * readpng_init(FILE *infile)
{
    uint8 sig[8];
    readpng_structs_t * strs = malloc(sizeof(readpng_structs_t));
    memset(strs, 0, sizeof(readpng_structs_t));

    /* first do a quick check that the file really is a PNG image; could
     * have used slightly more general png_sig_cmp() function instead */

    fread(sig, 1, 8, infile);
    if (!png_check_sig(sig, 8)) {
        free(strs);
        return NULL;   /* bad signature */
    }

    /* could pass pointers to user-defined error handlers instead of NULLs: */

    strs->png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
    if (!strs->png_ptr) {
        free(strs);
        return NULL;   /* out of memory */
    }

    strs->info_ptr = png_create_info_struct(strs->png_ptr);
    if (!strs->info_ptr) {
        png_destroy_read_struct(&strs->png_ptr, NULL, NULL);
        free(strs);
        return NULL;   /* out of memory */
    }

    png_init_io(strs->png_ptr, infile);
    png_set_sig_bytes(strs->png_ptr, 8);  /* we already read the 8 signature bytes */

    png_read_info(strs->png_ptr, strs->info_ptr);  /* read all PNG info up to image data */

    /* OK, that's all we need for now; return happy */

    return (void *)strs;
}
开发者ID:foreverlikeyou9999,项目名称:kos-ports,代码行数:39,代码来源:readpng.c


示例20: loadimage

int loadimage(char *filename)
{
	infile = fopen(filename, "rb");

	unsigned char sig[8];
  
    fread(sig, 1, 8, infile);
    if (!png_check_sig(sig, 8))
        return 1;   /* bad signature */

    png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL,
      NULL);
    if (!png_ptr)
        return 4;   /* out of memory */
  
    info_ptr = png_create_info_struct(png_ptr);
    if (!info_ptr) {
        png_destroy_read_struct(&png_ptr, NULL, NULL);
        return 4;   /* out of memory */
    }

    if (setjmp(png_ptr->jmpbuf)) {
        png_destroy_read_struct(&png_ptr, &info_ptr, NULL);
        return 2;
    }

	png_init_io(png_ptr, infile);
    png_set_sig_bytes(png_ptr, 8);
    png_read_info(png_ptr, info_ptr);



    //png_get_IHDR(png_ptr, info_ptr, &pwidth, &pheight, &bit_depth,
    //  &color_type, NULL, NULL, NULL);
    //*width = pwidth;
    //*height = pheight;
  
    return 0;
}
开发者ID:hmc-cs-jsealand,项目名称:line_drawing,代码行数:39,代码来源:load-image.c



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
C++ png_crc_finish函数代码示例发布时间:2022-05-30
下一篇:
C++ pneigh_lookup函数代码示例发布时间: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