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


C++ png_check_sig函数代码示例

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


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


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