From 8fdfda9b50e0dcee50652c502825783e8794815f Mon Sep 17 00:00:00 2001
From: thickbrick
Date: Wed, 24 Nov 2010 23:48:10 +0200
Subject: Fix #729: Some PNG images lose alpha channel

Ignore the background color specified in PNG's bKGD chunk, since it's only
there as a fallback.
---
 linden/indra/llimage/llpngwrapper.cpp | 18 ++++--------------
 linden/indra/llimage/llpngwrapper.h   |  3 ---
 2 files changed, 4 insertions(+), 17 deletions(-)

diff --git a/linden/indra/llimage/llpngwrapper.cpp b/linden/indra/llimage/llpngwrapper.cpp
index 0dd991a..2274a38 100644
--- a/linden/indra/llimage/llpngwrapper.cpp
+++ b/linden/indra/llimage/llpngwrapper.cpp
@@ -56,8 +56,6 @@ LLPngWrapper::LLPngWrapper()
 	  mCompressionType( 0 ),
 	  mFilterMethod( 0 ),
 	  mFinalSize( 0 ),
-	  mHasBKGD(false),
-	  mBackgroundColor(),
 	  mGamma(0.f)
 {
 }
@@ -117,9 +115,9 @@ void LLPngWrapper::writeFlush(png_structp png_ptr)
 }
 
 // Read the PNG file using the libpng.  The low-level interface is used here
-// because we want to do various transformations (including setting the
-// matte background if any, and applying gama) which can't be done with
-// the high-level interface. The scanline also begins at the bottom of
+// because we want to do various transformations (including applying gama)
+// which can't be done with the high-level interface.
+// The scanline also begins at the bottom of
 // the image (per SecondLife conventions) instead of at the top, so we
 // must assign row-pointers in "reverse" order.
 BOOL LLPngWrapper::readPng(U8* src, LLImageRaw* rawImage, ImageInfo *infop)
@@ -207,8 +205,7 @@ void LLPngWrapper::normalizeImage()
 	//		2. Convert grayscales to RGB
 	//		3. Create alpha layer from transparency
 	//		4. Ensure 8-bpp for all images
-	//		5. Apply background matte if any
-	//		6. Set (or guess) gamma
+	//		5. Set (or guess) gamma
 
 	if (mColorType == PNG_COLOR_TYPE_PALETTE)
 	{
@@ -235,12 +232,6 @@ void LLPngWrapper::normalizeImage()
 	{
 		png_set_strip_16(mReadPngPtr);
 	}
-	mHasBKGD = png_get_bKGD(mReadPngPtr, mReadInfoPtr, &mBackgroundColor);
-	if (mHasBKGD)
-	{
-		png_set_background(mReadPngPtr, mBackgroundColor,
-			PNG_BACKGROUND_GAMMA_FILE, 1, 1.0);
-	}
 
 #if LL_DARWIN
 	const F64 SCREEN_GAMMA = 1.8;
@@ -267,7 +258,6 @@ void LLPngWrapper::updateMetaData()
     mBitDepth = png_get_bit_depth(mReadPngPtr, mReadInfoPtr);
     mColorType = png_get_color_type(mReadPngPtr, mReadInfoPtr);
 	mChannels = png_get_channels(mReadPngPtr, mReadInfoPtr);
-	mHasBKGD = png_get_bKGD(mReadPngPtr, mReadInfoPtr, &mBackgroundColor);
 }
 
 // Method to write raw image into PNG at dest. The raw scanline begins
diff --git a/linden/indra/llimage/llpngwrapper.h b/linden/indra/llimage/llpngwrapper.h
index 2e6c1dc..0c3168c 100644
--- a/linden/indra/llimage/llpngwrapper.h
+++ b/linden/indra/llimage/llpngwrapper.h
@@ -94,9 +94,6 @@ private:
 
 	U32 mFinalSize;
 
-	bool mHasBKGD;
-	png_color_16p mBackgroundColor;
-
 	F64 mGamma;
 
 	std::string mErrorMessage;
-- 
cgit v1.1