Commit 2d3422d0 authored by hybrid's avatar hybrid

Add correct gamma handling to image loaders

git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@3718 dfc29bdd-3216-0410-991c-e03cc46cb475
parent b5b254e1
...@@ -209,6 +209,7 @@ IImage* CImageLoaderJPG::loadImage(io::IReadFile* file) const ...@@ -209,6 +209,7 @@ IImage* CImageLoaderJPG::loadImage(io::IReadFile* file) const
cinfo.out_color_space=JCS_RGB; cinfo.out_color_space=JCS_RGB;
cinfo.out_color_components=3; cinfo.out_color_components=3;
} }
cinfo.output_gamma=2.2;
cinfo.do_fancy_upsampling=FALSE; cinfo.do_fancy_upsampling=FALSE;
// Start decompressor // Start decompressor
......
...@@ -184,19 +184,6 @@ IImage* CImageLoaderPng::loadImage(io::IReadFile* file) const ...@@ -184,19 +184,6 @@ IImage* CImageLoaderPng::loadImage(io::IReadFile* file) const
if (ColorType==PNG_COLOR_TYPE_GRAY || ColorType==PNG_COLOR_TYPE_GRAY_ALPHA) if (ColorType==PNG_COLOR_TYPE_GRAY || ColorType==PNG_COLOR_TYPE_GRAY_ALPHA)
png_set_gray_to_rgb(png_ptr); png_set_gray_to_rgb(png_ptr);
// Update the changes
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 // Convert RGBA to BGRA
if (ColorType==PNG_COLOR_TYPE_RGB_ALPHA) if (ColorType==PNG_COLOR_TYPE_RGB_ALPHA)
{ {
...@@ -207,7 +194,22 @@ IImage* CImageLoaderPng::loadImage(io::IReadFile* file) const ...@@ -207,7 +194,22 @@ IImage* CImageLoaderPng::loadImage(io::IReadFile* file) const
#endif #endif
} }
int intent;
const double screen_gamma = 2.2;
if (png_get_sRGB(png_ptr, info_ptr, &intent))
png_set_gamma(png_ptr, screen_gamma, 0.45455);
else
{
double image_gamma;
if (png_get_gAMA(png_ptr, info_ptr, &image_gamma))
png_set_gamma(png_ptr, screen_gamma, image_gamma);
else
png_set_gamma(png_ptr, screen_gamma, 0.45455);
}
// Update the changes // Update the changes
png_read_update_info(png_ptr, info_ptr);
{ {
// Use temporary variables to avoid passing casted pointers // Use temporary variables to avoid passing casted pointers
png_uint_32 w,h; png_uint_32 w,h;
......
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