Commit f80a8cd0 authored by hybrid's avatar hybrid

Fix png loader warning, also reordered transform calls such that only one test...

Fix png loader warning, also reordered transform calls such that only one test requires a late place after the read_update call. Added a test case which tests paletted png file loading and rendering.

git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@3725 dfc29bdd-3216-0410-991c-e03cc46cb475
parent f1440ebb
......@@ -184,30 +184,6 @@ IImage* CImageLoaderPng::loadImage(io::IReadFile* file) const
if (ColorType==PNG_COLOR_TYPE_GRAY || ColorType==PNG_COLOR_TYPE_GRAY_ALPHA)
png_set_gray_to_rgb(png_ptr);
// Update the changes in between, as we need to get the new color type
// for proper processing of the RGBA type
png_read_update_info(png_ptr, info_ptr);
{
// Use temporary variables to avoid passing casted pointers
png_uint_32 w,h;
// Extract info
png_get_IHDR(png_ptr, info_ptr,
&w, &h,
&BitDepth, &ColorType, NULL, NULL, NULL);
Width=w;
Height=h;
}
// Convert RGBA to BGRA
if (ColorType==PNG_COLOR_TYPE_RGB_ALPHA)
{
#ifdef __BIG_ENDIAN__
png_set_swap_alpha(png_ptr);
#else
png_set_bgr(png_ptr);
#endif
}
int intent;
const double screen_gamma = 2.2;
......@@ -222,7 +198,8 @@ IImage* CImageLoaderPng::loadImage(io::IReadFile* file) const
png_set_gamma(png_ptr, screen_gamma, 0.45455);
}
// Update the changes now with all changes
// Update the changes in between, as we need to get the new color type
// for proper processing of the RGBA type
png_read_update_info(png_ptr, info_ptr);
{
// Use temporary variables to avoid passing casted pointers
......@@ -235,6 +212,16 @@ IImage* CImageLoaderPng::loadImage(io::IReadFile* file) const
Height=h;
}
// Convert RGBA to BGRA
if (ColorType==PNG_COLOR_TYPE_RGB_ALPHA)
{
#ifdef __BIG_ENDIAN__
png_set_swap_alpha(png_ptr);
#else
png_set_bgr(png_ptr);
#endif
}
// Create the image structure to be filled by png data
if (ColorType==PNG_COLOR_TYPE_RGB_ALPHA)
image = new CImage(ECF_A8R8G8B8, core::dimension2d<u32>(Width, Height));
......
......@@ -2,7 +2,10 @@
using namespace irr;
static bool testWithRenderTarget(video::E_DRIVER_TYPE driverType)
namespace
{
bool testWithRenderTarget(video::E_DRIVER_TYPE driverType)
{
// create device
......@@ -15,13 +18,13 @@ static bool testWithRenderTarget(video::E_DRIVER_TYPE driverType)
video::ITexture* RenderTarget=driver->addRenderTargetTexture(core::dimension2d<u32>(64,64), "BASEMAP");
video::ITexture *Image=driver->getTexture("../media/water.jpg");
video::ITexture *tex=driver->getTexture("../media/water.jpg");
driver->beginScene(true, true, video::SColor(255,255,0,255));//Backbuffer background is pink
//draw the 256x256 water image on the rendertarget:
driver->setRenderTarget(RenderTarget,true,true,video::SColor(255,0,0,255));//Rendertarget background is blue
driver->draw2DImage(Image, core::position2d<s32>(0,0), core::recti(0,0,32,32));
driver->draw2DImage(tex, core::position2d<s32>(0,0), core::recti(0,0,32,32));
driver->setRenderTarget(0, false);
//draw the rendertarget on screen:
......@@ -38,6 +41,35 @@ static bool testWithRenderTarget(video::E_DRIVER_TYPE driverType)
return result;
}
// draws a complex (interlaced, paletted, alpha) png image
bool testWithPNG(video::E_DRIVER_TYPE driverType)
{
// create device
IrrlichtDevice *device = createDevice(driverType, core::dimension2d<u32>(160,120));
if (device == 0)
return true; // could not create selected driver.
video::IVideoDriver* driver = device->getVideoDriver();
video::ITexture *tex=driver->getTexture("media/RedbrushAlpha-0.25.png");
driver->beginScene(true, true, video::SColor(255,40,40,255));//Backbuffer background is blue
driver->draw2DImage(tex, core::recti(0,0,160,120), core::recti(0,0,256,256), 0, 0, true);
driver->endScene();
bool result = takeScreenshotAndCompareAgainstReference(driver, "-draw2DImagePNG.png");
device->closeDevice();
device->run();
device->drop();
return result;
}
}
bool draw2DImage()
{
bool result = testWithRenderTarget(video::EDT_DIRECT3D9);
......@@ -45,5 +77,9 @@ bool draw2DImage()
result &= testWithRenderTarget(video::EDT_OPENGL);
result &= testWithRenderTarget(video::EDT_BURNINGSVIDEO);
result &= testWithRenderTarget(video::EDT_SOFTWARE);
result &= testWithPNG(video::EDT_DIRECT3D9);
result &= testWithPNG(video::EDT_OPENGL);
return result;
}
All assets of this test suite, except where noted below, are tkane from the main Irrlicht repository and are copyright/licensed as stated there. The source code is copyright by the authors, except where stated differently inside the files.
title_font.xml and its png files are taken from SuperTuxKart. They are in the public domain.
The image RedbrushAlpha-0.25.png is Copyright 1999 Pieter S. van der Meulen. This image, including the alpha channel, may be used, edited and reproduced freely.
Taken from http://www.libpng.org/pub/png/png-RedbrushAlpha.html
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment