Пример #1
0
UnpackedBitmap *AllocAndLoadBitmap(const char *filename)
{
	size_t length;
	void *bytes=AllocAndLoadFile(filename,&length);
	if(!bytes) return NULL;

	PNGLoader loader;
	InitializePNGLoader(&loader,bytes,length);

	if(!LoadPNGHeader(&loader))
	{
		fprintf(stderr,"Not a valid PNG file.\n");
		free(bytes);
		return NULL;
	}

	UnpackedBitmap *self=malloc(sizeof(UnpackedBitmap)+
	loader.width*loader.height*sizeof(UnpackedPixel));
	if(!self) return NULL;

	self->width=loader.width;
	self->height=loader.height;

	if(!LoadPNGImageData(&loader,self->pixels,sizeof(UnpackedPixel)*loader.width,PixelFunc))
	{
		fprintf(stderr,"Failed while loading PNG data.\n");
		free(bytes);
		free(self);
		return NULL;
	}

	free(bytes);

	return self;
}
Пример #2
0
bool FPngImageWrapper::SetCompressed( const void* InCompressedData, int32 InCompressedSize )
{
	bool bResult = FImageWrapperBase::SetCompressed( InCompressedData, InCompressedSize );

	return bResult && LoadPNGHeader();	// Fetch the variables from the header info
}