[Scummvm-cvs-logs] SF.net SVN: scummvm:[53917] scummvm/trunk/backends/platform/psp

bluddy at users.sourceforge.net bluddy at users.sourceforge.net
Fri Oct 29 09:08:24 CEST 2010


Revision: 53917
          http://scummvm.svn.sourceforge.net/scummvm/?rev=53917&view=rev
Author:   bluddy
Date:     2010-10-29 07:08:24 +0000 (Fri, 29 Oct 2010)

Log Message:
-----------
PSP: corrected png loader to use bit depth rather than palette size

Sometimes we can have an 8bit file for example that has a palette of 16 colors or less, so we need to go by the bit depth rather than inferring the bit depth from the palette size.

Modified Paths:
--------------
    scummvm/trunk/backends/platform/psp/png_loader.cpp
    scummvm/trunk/backends/platform/psp/png_loader.h

Modified: scummvm/trunk/backends/platform/psp/png_loader.cpp
===================================================================
--- scummvm/trunk/backends/platform/psp/png_loader.cpp	2010-10-29 00:40:57 UTC (rev 53916)
+++ scummvm/trunk/backends/platform/psp/png_loader.cpp	2010-10-29 07:08:24 UTC (rev 53917)
@@ -36,25 +36,27 @@
 
 PngLoader::Status PngLoader::allocate() {
 	DEBUG_ENTER_FUNC();
+	
 	if (!findImageDimensions()) {
 		PSP_ERROR("failed to get image dimensions\n");
 		return BAD_FILE;
 	}
 
-	
 	_buffer->setSize(_width, _height, _sizeBy);
 
+	uint32 bitsPerPixel = _bitDepth * _channels;
+	
 	if (_paletteSize) {	// 8 or 4-bit image
-		if (_paletteSize <= 16) { 					// 4 bit
+		if (bitsPerPixel == 4) {
 			_buffer->setPixelFormat(PSPPixelFormat::Type_Palette_4bit);
 			_palette->setPixelFormats(PSPPixelFormat::Type_4444, PSPPixelFormat::Type_Palette_4bit);
-			_paletteSize = 16;
-		} else if (_paletteSize <= 256) {			// 8-bit image
-			_paletteSize = 256;
+			_paletteSize = 16;	// round up
+		} else if (bitsPerPixel == 8) {			// 8-bit image
 			_buffer->setPixelFormat(PSPPixelFormat::Type_Palette_8bit);
 			_palette->setPixelFormats(PSPPixelFormat::Type_4444, PSPPixelFormat::Type_Palette_8bit);
+			_paletteSize = 256; // round up
 		} else {
-			PSP_ERROR("palette of %d too big!\n", _paletteSize);
+			PSP_ERROR("too many bits per pixel[%d] for a palette\n", bitsPerPixel);
 			return BAD_FILE;
 		}
 
@@ -127,7 +129,8 @@
 	int interlaceType;
 	png_get_IHDR(_pngPtr, _infoPtr, (png_uint_32 *)&_width, (png_uint_32 *)&_height, &_bitDepth,
 		&_colorType, &interlaceType, int_p_NULL, int_p_NULL);
-
+	_channels = png_get_channels(_pngPtr, _infoPtr);
+		
 	if (_colorType & PNG_COLOR_MASK_PALETTE)
 		_paletteSize = _infoPtr->num_palette;
 
@@ -140,7 +143,7 @@
 
 	bool status = basicImageLoad(); 
 
-	PSP_DEBUG_PRINT("width[%d], height[%d], paletteSize[%d], bitDepth[%d], rowBytes[%d]\n", _width, _height, _paletteSize, _bitDepth, _infoPtr->rowbytes);
+	PSP_DEBUG_PRINT("width[%d], height[%d], paletteSize[%d], bitDepth[%d], channels[%d], rowBytes[%d]\n", _width, _height, _paletteSize, _bitDepth, _channels, _infoPtr->rowbytes);
 	png_destroy_read_struct(&_pngPtr, &_infoPtr, png_infopp_NULL);
 	return status;
 }
@@ -160,7 +163,7 @@
 	if (_paletteSize) {
 		// Copy the palette
 		png_colorp srcPal = _infoPtr->palette;
-		for (int i = 0; i < (int)_paletteSize; i++) {
+		for (int i = 0; i < _infoPtr->num_palette; i++) {
 			unsigned char alphaVal = (i < _infoPtr->num_trans) ? _infoPtr->trans[i] : 0xFF;	// Load alpha if it's there
 			_palette->setSingleColorRGBA(i, srcPal->red, srcPal->green, srcPal->blue, alphaVal);
 			srcPal++;
@@ -171,21 +174,19 @@
 		if (png_get_valid(_pngPtr, _infoPtr, PNG_INFO_tRNS))
 			png_set_tRNS_to_alpha(_pngPtr);		// Convert trans channel to alpha for 32 bits
 
-		//png_set_filler(_pngPtr, 0xff, PNG_FILLER_AFTER);	// Filler for alpha if none exists
 		png_set_add_alpha(_pngPtr, 0xff, PNG_FILLER_AFTER);		// Filler for alpha if none exists
 	}
 
 	uint32 rowBytes = png_get_rowbytes(_pngPtr, _infoPtr);
-	uint32 channels = png_get_channels(_pngPtr, _infoPtr);
 	
-	// there seems to be a bug in libpng where it doesn't increase the rowbytes or the channel even after we add the
-	// alpha channel
-	if (channels == 3 && (rowBytes / _width) == 3) {
-		channels = 4;
-		rowBytes = _width * channels;		
+	// there seems to be a bug in libpng where it doesn't increase the rowbytes or the 
+	// channel even after we add the alpha channel
+	if (_channels == 3 && (rowBytes / _width) == 3) {
+		_channels = 4;
+		rowBytes = _width * _channels;		
 	}	
 	
-	PSP_DEBUG_PRINT("rowBytes[%d], channels[%d]\n", rowBytes, channels);
+	PSP_DEBUG_PRINT("rowBytes[%d], channels[%d]\n", rowBytes, _channels);
 	
 	unsigned char *line = (unsigned char*) malloc(rowBytes);
 	if (!line) {

Modified: scummvm/trunk/backends/platform/psp/png_loader.h
===================================================================
--- scummvm/trunk/backends/platform/psp/png_loader.h	2010-10-29 00:40:57 UTC (rev 53916)
+++ scummvm/trunk/backends/platform/psp/png_loader.h	2010-10-29 07:08:24 UTC (rev 53917)
@@ -44,11 +44,14 @@
 	uint32 _width;
 	uint32 _height;
 	uint32 _paletteSize;
+	Buffer::HowToSize _sizeBy;
+
+	// PNG lib values
 	int _bitDepth;
-	Buffer::HowToSize _sizeBy;
 	png_structp _pngPtr;
 	png_infop _infoPtr;
 	int _colorType;
+	uint32 _channels;
 
 public:
 	enum Status {
@@ -61,7 +64,8 @@
 		Buffer::HowToSize sizeBy = Buffer::kSizeByTextureSize) :
 			_file(file), _buffer(&buffer), _palette(&palette),
 			_width(0), _height(0), _paletteSize(0),
-			_bitDepth(0), _sizeBy(sizeBy), _pngPtr(0), _infoPtr(0), _colorType(0) {}
+			_bitDepth(0), _sizeBy(sizeBy), _pngPtr(0), 
+			_infoPtr(0), _colorType(0), _channels(0) {}
 
 	PngLoader::Status allocate();
 	bool load();


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.




More information about the Scummvm-git-logs mailing list