aboutsummaryrefslogtreecommitdiff
path: root/graphics/png.cpp
diff options
context:
space:
mode:
authorJohannes Schickel2011-05-01 16:54:45 +0200
committerJohannes Schickel2011-05-01 16:54:45 +0200
commit71bdb86e028db9556611f88b3686ce93312a8131 (patch)
tree3c24233044a8e72bd8ecd73b981f50c725d5d282 /graphics/png.cpp
parent89b63e3adb4692c9659f8b133727ccc1e2af75b4 (diff)
parent8ff527ac4ef4237e63c0802a22eb0f942089e6c4 (diff)
downloadscummvm-rg350-71bdb86e028db9556611f88b3686ce93312a8131.tar.gz
scummvm-rg350-71bdb86e028db9556611f88b3686ce93312a8131.tar.bz2
scummvm-rg350-71bdb86e028db9556611f88b3686ce93312a8131.zip
Merge pull request #16 "Add a PixelFormat to Graphics::Surface.".
For further discussion check here: https://github.com/scummvm/scummvm/pull/16 Conflicts: graphics/png.cpp
Diffstat (limited to 'graphics/png.cpp')
-rw-r--r--graphics/png.cpp29
1 files changed, 15 insertions, 14 deletions
diff --git a/graphics/png.cpp b/graphics/png.cpp
index 46e3c2523b..3cdb9f7cca 100644
--- a/graphics/png.cpp
+++ b/graphics/png.cpp
@@ -113,16 +113,16 @@ PNG::~PNG() {
Graphics::Surface *PNG::getSurface(const PixelFormat &format) {
Graphics::Surface *output = new Graphics::Surface();
- output->create(_unfilteredSurface->w, _unfilteredSurface->h, format.bytesPerPixel);
+ output->create(_unfilteredSurface->w, _unfilteredSurface->h, format);
byte *src = (byte *)_unfilteredSurface->pixels;
byte a = 0xFF;
if (_header.colorType != kIndexed) {
if (_header.colorType == kTrueColor || _header.colorType == kTrueColorWithAlpha) {
- if (_unfilteredSurface->bytesPerPixel != 3 && _unfilteredSurface->bytesPerPixel != 4)
+ if (_unfilteredSurface->format.bytesPerPixel != 3 && _unfilteredSurface->format.bytesPerPixel != 4)
error("Unsupported truecolor PNG format");
} else if (_header.colorType == kGrayScale || _header.colorType == kGrayScaleWithAlpha) {
- if (_unfilteredSurface->bytesPerPixel != 1 && _unfilteredSurface->bytesPerPixel != 2)
+ if (_unfilteredSurface->format.bytesPerPixel != 1 && _unfilteredSurface->format.bytesPerPixel != 2)
error("Unsupported grayscale PNG format");
}
@@ -130,13 +130,13 @@ Graphics::Surface *PNG::getSurface(const PixelFormat &format) {
for (uint16 j = 0; j < output->w; j++) {
if (format.bytesPerPixel == 2) { // 2bpp
uint16 *dest = ((uint16 *)output->getBasePtr(j, i));
- if (_unfilteredSurface->bytesPerPixel == 1) { // Grayscale
+ if (_unfilteredSurface->format.bytesPerPixel == 1) { // Grayscale
if (_transparentColorSpecified)
a = (src[0] == _transparentColor[0]) ? 0 : 0xFF;
*dest = format.ARGBToColor( a, src[0], src[0], src[0]);
- } else if (_unfilteredSurface->bytesPerPixel == 2) { // Grayscale + alpha
+ } else if (_unfilteredSurface->format.bytesPerPixel == 2) { // Grayscale + alpha
*dest = format.ARGBToColor(src[1], src[0], src[0], src[0]);
- } else if (_unfilteredSurface->bytesPerPixel == 3) { // RGB
+ } else if (_unfilteredSurface->format.bytesPerPixel == 3) { // RGB
if (_transparentColorSpecified) {
bool isTransparentColor = (src[0] == _transparentColor[0] &&
src[1] == _transparentColor[1] &&
@@ -144,18 +144,18 @@ Graphics::Surface *PNG::getSurface(const PixelFormat &format) {
a = isTransparentColor ? 0 : 0xFF;
}
*dest = format.ARGBToColor( a, src[0], src[1], src[2]);
- } else if (_unfilteredSurface->bytesPerPixel == 4) { // RGBA
+ } else if (_unfilteredSurface->format.bytesPerPixel == 4) { // RGBA
*dest = format.ARGBToColor(src[3], src[0], src[1], src[2]);
}
} else { // 4bpp
uint32 *dest = ((uint32 *)output->getBasePtr(j, i));
- if (_unfilteredSurface->bytesPerPixel == 1) { // Grayscale
+ if (_unfilteredSurface->format.bytesPerPixel == 1) { // Grayscale
if (_transparentColorSpecified)
a = (src[0] == _transparentColor[0]) ? 0 : 0xFF;
*dest = format.ARGBToColor( a, src[0], src[0], src[0]);
- } else if (_unfilteredSurface->bytesPerPixel == 2) { // Grayscale + alpha
+ } else if (_unfilteredSurface->format.bytesPerPixel == 2) { // Grayscale + alpha
*dest = format.ARGBToColor(src[1], src[0], src[0], src[0]);
- } else if (_unfilteredSurface->bytesPerPixel == 3) { // RGB
+ } else if (_unfilteredSurface->format.bytesPerPixel == 3) { // RGB
if (_transparentColorSpecified) {
bool isTransparentColor = (src[0] == _transparentColor[0] &&
src[1] == _transparentColor[1] &&
@@ -163,12 +163,12 @@ Graphics::Surface *PNG::getSurface(const PixelFormat &format) {
a = isTransparentColor ? 0 : 0xFF;
}
*dest = format.ARGBToColor( a, src[0], src[1], src[2]);
- } else if (_unfilteredSurface->bytesPerPixel == 4) { // RGBA
+ } else if (_unfilteredSurface->format.bytesPerPixel == 4) { // RGBA
*dest = format.ARGBToColor(src[3], src[0], src[1], src[2]);
}
}
- src += _unfilteredSurface->bytesPerPixel;
+ src += _unfilteredSurface->format.bytesPerPixel;
}
}
} else {
@@ -391,7 +391,8 @@ void PNG::constructImage() {
delete _unfilteredSurface;
}
_unfilteredSurface = new Graphics::Surface();
- _unfilteredSurface->create(_header.width, _header.height, (getNumColorChannels() * _header.bitDepth + 7) / 8);
+ // TODO/FIXME: It seems we can not properly determine the format here. But maybe there is a way...
+ _unfilteredSurface->create(_header.width, _header.height, PixelFormat((getNumColorChannels() * _header.bitDepth + 7) / 8, 0, 0, 0, 0, 0, 0, 0, 0));
scanLine = new byte[_unfilteredSurface->pitch];
dest = (byte *)_unfilteredSurface->getBasePtr(0, 0);
@@ -400,7 +401,7 @@ void PNG::constructImage() {
for (uint16 y = 0; y < _unfilteredSurface->h; y++) {
filterType = _imageData->readByte();
_imageData->read(scanLine, scanLineWidth);
- unfilterScanLine(dest, scanLine, prevLine, _unfilteredSurface->bytesPerPixel, filterType, scanLineWidth);
+ unfilterScanLine(dest, scanLine, prevLine, _unfilteredSurface->format.bytesPerPixel, filterType, scanLineWidth);
prevLine = dest;
dest += _unfilteredSurface->pitch;
}