From dc16f33663ae51be2966aba81848c4d139149f60 Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Thu, 10 Oct 2013 20:55:47 +0300 Subject: [PATCH] Add pixel formats with a padding component --- source/graphics/pixelformat.h | 4 +++- source/graphics/png/pngloader.cpp | 5 +---- source/graphics/quartz/quartzloader.cpp | 6 ++++-- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/source/graphics/pixelformat.h b/source/graphics/pixelformat.h index 891ba7c..abb800c 100644 --- a/source/graphics/pixelformat.h +++ b/source/graphics/pixelformat.h @@ -11,8 +11,10 @@ enum PixelFormat LUMINANCE_ALPHA, RGB, RGBA, + RGBX, BGR, - BGRA + BGRA, + BGRX }; } // namespace Graphics diff --git a/source/graphics/png/pngloader.cpp b/source/graphics/png/pngloader.cpp index 50d58b3..35e6a97 100644 --- a/source/graphics/png/pngloader.cpp +++ b/source/graphics/png/pngloader.cpp @@ -80,14 +80,11 @@ void PngLoader::load(Image::Data &data) case PNG_COLOR_TYPE_PALETTE: data.fmt = COLOR_INDEX; break; case PNG_COLOR_TYPE_GRAY: data.fmt = LUMINANCE; break; case PNG_COLOR_TYPE_GRAY_ALPHA: data.fmt = LUMINANCE_ALPHA; break; - case PNG_COLOR_TYPE_RGB: data.fmt = RGB; break; + case PNG_COLOR_TYPE_RGB: data.fmt = (nchans==4 ? RGBX : RGB); break; case PNG_COLOR_TYPE_RGB_ALPHA: data.fmt = RGBA; break; default: throw unsupported_image_format("unknown color type"); } - if(nchans==4 && data.fmt==RGB) - png_set_strip_alpha(priv->png); - data.data = new char[data.stride*data.height]; for(unsigned y=0; ypng, reinterpret_cast(data.data+data.stride*(data.height-1-y)), 0); diff --git a/source/graphics/quartz/quartzloader.cpp b/source/graphics/quartz/quartzloader.cpp index a7c610d..aa11daa 100644 --- a/source/graphics/quartz/quartzloader.cpp +++ b/source/graphics/quartz/quartzloader.cpp @@ -102,7 +102,9 @@ void QuartzLoader::load(Image::Data &data) { if(alpha==kCGImageAlphaLast) data.fmt = RGBA; - else if(alpha==kCGImageAlphaNone || alpha==kCGImageAlphaNoneSkipFirst || alpha==kCGImageAlphaNoneSkipLast) + else if(alpha==kCGImageAlphaNoneSkipLast) + data.fmt = RGBX; + else if(alpha==kCGImageAlphaNone || alpha==kCGImageAlphaNoneSkipFirst) data.fmt = RGB; else throw unsupported_image_format("unknown alpha mode"); @@ -118,7 +120,7 @@ void QuartzLoader::load(Image::Data &data) CFRelease(image); - if(alpha==kCGImageAlphaNoneSkipFirst || alpha==kCGImageAlphaNoneSkipLast) + if(alpha==kCGImageAlphaNoneSkipFirst) { const char *src = data.data; if(alpha==kCGImageAlphaNoneSkipFirst) -- 2.45.2