static Bool
readPngFileToImage (FILE *file,
		    int  *width,
		    int  *height,
		    void **data)
{
    unsigned char png_sig[PNG_SIG_SIZE];
    int		  sig_bytes;
    png_struct	  *png;
    png_info	  *info;
    Bool	  status;

    sig_bytes = fread (png_sig, 1, PNG_SIG_SIZE, file);
    if (png_check_sig (png_sig, sig_bytes) == 0)
	return FALSE;

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

    info = png_create_info_struct (png);
    if (!info)
    {
	png_destroy_read_struct (&png, NULL, NULL);

	return FALSE;
    }

    png_init_io (png, file);
    png_set_sig_bytes (png, sig_bytes);

    status = readPngData (png, info, data, width, height);

    png_destroy_read_struct (&png, &info, NULL);

    return status;
}
static Bool
readPngBuffer (const unsigned char *buffer,
	       char		   **data,
	       unsigned int	   *width,
	       unsigned int	   *height)
{
    unsigned char	png_sig[PNG_SIG_SIZE];
    png_struct		*png;
    png_info		*info;
    const unsigned char *b = buffer + PNG_SIG_SIZE;
    Bool		status;

    memcpy (png_sig, buffer, PNG_SIG_SIZE);
    if (png_check_sig (png_sig, PNG_SIG_SIZE) == 0)
	return FALSE;

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

    info = png_create_info_struct (png);
    if (!info)
    {
	png_destroy_read_struct (&png, NULL, NULL);
	return FALSE;
    }

    png_set_read_fn (png, (void *) &b, userReadData);
    png_set_sig_bytes (png, PNG_SIG_SIZE);

    status = readPngData (png, info, data, width, height);

    png_destroy_read_struct (&png, &info, NULL);

    return status;
}
示例#3
0
bool
PngScreen::readPng (std::ifstream &file,
		    CompSize      &size,
		    void          *&data)
{
    unsigned char png_sig[PNG_SIG_SIZE];
    png_struct	  *png;
    png_info	  *info;
    bool	  status;

    file.read ((char *) png_sig, PNG_SIG_SIZE);
    if (file.fail ())
	return false;
    if (png_sig_cmp (png_sig, 0, PNG_SIG_SIZE) != 0)
	return false;

    png = png_create_read_struct (PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
    if (!png)
	return false;

    info = png_create_info_struct (png);
    if (!info)
    {
	png_destroy_read_struct (&png, NULL, NULL);
	return false;
    }

    png_set_read_fn (png, &file, stdioReadFunc);
    png_set_sig_bytes (png, PNG_SIG_SIZE);

    status = readPngData (png, info, data, size);

    png_destroy_read_struct (&png, &info, NULL);

    return status;
}