diff options
author | Strangerke | 2011-06-29 16:15:41 +0200 |
---|---|---|
committer | Strangerke | 2011-06-29 16:15:41 +0200 |
commit | b0c9c9122fc678074aba30068e5b36d347208e65 (patch) | |
tree | 79a99db08ec985f2e5f1e216823b1104d5b753fb /graphics | |
parent | f2f3124246a77036f843dee2d83ad28084234ebc (diff) | |
parent | c32a3ea0d30336771bab460ecccb58c4614e6294 (diff) | |
download | scummvm-rg350-b0c9c9122fc678074aba30068e5b36d347208e65.tar.gz scummvm-rg350-b0c9c9122fc678074aba30068e5b36d347208e65.tar.bz2 scummvm-rg350-b0c9c9122fc678074aba30068e5b36d347208e65.zip |
Merge branch 'master' of github.com:scummvm/scummvm into soltys_wip2
Diffstat (limited to 'graphics')
-rw-r--r-- | graphics/font.cpp | 6 | ||||
-rw-r--r-- | graphics/fonts/winfont.cpp | 20 | ||||
-rw-r--r-- | graphics/fonts/winfont.h | 2 | ||||
-rw-r--r-- | graphics/jpeg.h | 2 | ||||
-rw-r--r-- | graphics/png.cpp | 119 | ||||
-rw-r--r-- | graphics/scaler.cpp | 4 | ||||
-rw-r--r-- | graphics/scaler/Normal2xARM.s | 1 | ||||
-rw-r--r-- | graphics/scaler/aspect.cpp | 27 | ||||
-rw-r--r-- | graphics/scaler/downscaler.cpp | 2 | ||||
-rw-r--r-- | graphics/sjis.cpp | 4 | ||||
-rw-r--r-- | graphics/sjis.h | 2 | ||||
-rw-r--r-- | graphics/surface.cpp | 2 | ||||
-rw-r--r-- | graphics/surface.h | 2 |
13 files changed, 101 insertions, 92 deletions
diff --git a/graphics/font.cpp b/graphics/font.cpp index cdf9090625..0c180ee47d 100644 --- a/graphics/font.cpp +++ b/graphics/font.cpp @@ -214,6 +214,8 @@ int bdf_read_header(Common::SeekableReadStream &fp, NewFontData* pf) { char buf[256]; char facename[256]; char copyright[256]; + memset(facename, 0, sizeof(facename)); + memset(copyright, 0, sizeof(copyright)); /* set certain values to errors for later error checking*/ pf->defaultchar = -1; @@ -235,6 +237,7 @@ int bdf_read_header(Common::SeekableReadStream &fp, NewFontData* pf) { warning("Error: bad 'FONT'"); return 0; } + pf->facename = strdup(facename); continue; } @@ -243,6 +246,7 @@ int bdf_read_header(Common::SeekableReadStream &fp, NewFontData* pf) { warning("Error: bad 'COPYRIGHT'"); return 0; } + pf->copyright = strdup(copyright); continue; } @@ -944,7 +948,7 @@ int Font::wordWrapText(const Common::String &str, int maxWidth, Common::Array<Co if (lineWidth > 0) { wrapper.add(line, lineWidth); // Trim left side - while (tmpStr.size() && isspace(tmpStr[0])) { + while (tmpStr.size() && isspace(static_cast<unsigned char>(tmpStr[0]))) { tmpWidth -= getCharWidth(tmpStr[0]); tmpStr.deleteChar(0); } diff --git a/graphics/fonts/winfont.cpp b/graphics/fonts/winfont.cpp index 0e87769f2f..3bad92236d 100644 --- a/graphics/fonts/winfont.cpp +++ b/graphics/fonts/winfont.cpp @@ -81,7 +81,7 @@ bool WinFont::loadFromFON(const Common::String &fileName, const WinFontDirEntry return true; // Then try loading via the PE code - return loadFromPE(fileName, dirEntry); + return loadFromPE(fileName, dirEntry); } bool WinFont::loadFromNE(const Common::String &fileName, const WinFontDirEntry &dirEntry) { @@ -98,7 +98,7 @@ bool WinFont::loadFromNE(const Common::String &fileName, const WinFontDirEntry & } uint32 fontId = getFontIndex(*fontDirectory, dirEntry); - + delete fontDirectory; // Couldn't match the face name @@ -120,37 +120,43 @@ bool WinFont::loadFromNE(const Common::String &fileName, const WinFontDirEntry & } bool WinFont::loadFromPE(const Common::String &fileName, const WinFontDirEntry &dirEntry) { - Common::PEResources exe; + Common::PEResources *exe = new Common::PEResources(); - if (!exe.loadFromEXE(fileName)) + if (!exe->loadFromEXE(fileName)) { + delete exe; return false; + } // Let's pull out the font directory - Common::SeekableReadStream *fontDirectory = exe.getResource(Common::kPEFontDir, Common::String("FONTDIR")); + Common::SeekableReadStream *fontDirectory = exe->getResource(Common::kPEFontDir, Common::String("FONTDIR")); if (!fontDirectory) { warning("No font directory in '%s'", fileName.c_str()); + delete exe; return false; } uint32 fontId = getFontIndex(*fontDirectory, dirEntry); - + delete fontDirectory; // Couldn't match the face name if (fontId == 0xffffffff) { warning("Could not find face '%s' in '%s'", dirEntry.faceName.c_str(), fileName.c_str()); + delete exe; return false; } // Actually go get our font now... - Common::SeekableReadStream *fontStream = exe.getResource(Common::kPEFont, fontId); + Common::SeekableReadStream *fontStream = exe->getResource(Common::kPEFont, fontId); if (!fontStream) { warning("Could not find font %d in %s", fontId, fileName.c_str()); + delete exe; return false; } bool ok = loadFromFNT(*fontStream); delete fontStream; + delete exe; return ok; } diff --git a/graphics/fonts/winfont.h b/graphics/fonts/winfont.h index b6c1be7064..4382d7ed6b 100644 --- a/graphics/fonts/winfont.h +++ b/graphics/fonts/winfont.h @@ -88,7 +88,7 @@ private: uint16 charWidth; uint32 offset; byte *bitmap; - } *_glyphs; + } *_glyphs; }; } // End of namespace Graphics diff --git a/graphics/jpeg.h b/graphics/jpeg.h index bda0c08240..27b91e8777 100644 --- a/graphics/jpeg.h +++ b/graphics/jpeg.h @@ -72,7 +72,7 @@ private: // Result image for this component Surface surface; }; - + Component *_components; // Scan components diff --git a/graphics/png.cpp b/graphics/png.cpp index e6dceab3fa..2189fd333f 100644 --- a/graphics/png.cpp +++ b/graphics/png.cpp @@ -100,7 +100,7 @@ enum PNGFilters { kFilterPaeth = 4 }; -PNG::PNG() : _compressedBuffer(0), _compressedBufferSize(0), +PNG::PNG() : _compressedBuffer(0), _compressedBufferSize(0), _unfilteredSurface(0), _transparentColorSpecified(false) { } @@ -116,75 +116,76 @@ Graphics::Surface *PNG::getSurface(const PixelFormat &format) { output->create(_unfilteredSurface->w, _unfilteredSurface->h, format); byte *src = (byte *)_unfilteredSurface->pixels; byte a = 0xFF; + byte bpp = _unfilteredSurface->format.bytesPerPixel; if (_header.colorType != kIndexed) { - if (_header.colorType == kTrueColor || _header.colorType == kTrueColorWithAlpha) { - if (_unfilteredSurface->format.bytesPerPixel != 3 && _unfilteredSurface->format.bytesPerPixel != 4) + if (_header.colorType == kTrueColor || + _header.colorType == kTrueColorWithAlpha) { + if (bpp != 3 && bpp != 4) error("Unsupported truecolor PNG format"); - } else if (_header.colorType == kGrayScale || _header.colorType == kGrayScaleWithAlpha) { - if (_unfilteredSurface->format.bytesPerPixel != 1 && _unfilteredSurface->format.bytesPerPixel != 2) + } else if (_header.colorType == kGrayScale || + _header.colorType == kGrayScaleWithAlpha) { + if (bpp != 1 && bpp != 2) error("Unsupported grayscale PNG format"); } for (uint16 i = 0; i < output->h; i++) { for (uint16 j = 0; j < output->w; j++) { - if (format.bytesPerPixel == 2) { // 2bpp - uint16 *dest = ((uint16 *)output->getBasePtr(j, i)); - 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->format.bytesPerPixel == 2) { // Grayscale + alpha - *dest = format.ARGBToColor(src[1], src[0], src[0], src[0]); - } else if (_unfilteredSurface->format.bytesPerPixel == 3) { // RGB - if (_transparentColorSpecified) { - bool isTransparentColor = (src[0] == _transparentColor[0] && - src[1] == _transparentColor[1] && - src[2] == _transparentColor[2]); - a = isTransparentColor ? 0 : 0xFF; - } - *dest = format.ARGBToColor( a, src[0], src[1], src[2]); - } 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->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->format.bytesPerPixel == 2) { // Grayscale + alpha - *dest = format.ARGBToColor(src[1], src[0], src[0], src[0]); - } else if (_unfilteredSurface->format.bytesPerPixel == 3) { // RGB - if (_transparentColorSpecified) { - bool isTransparentColor = (src[0] == _transparentColor[0] && - src[1] == _transparentColor[1] && - src[2] == _transparentColor[2]); - a = isTransparentColor ? 0 : 0xFF; - } - *dest = format.ARGBToColor( a, src[0], src[1], src[2]); - } else if (_unfilteredSurface->format.bytesPerPixel == 4) { // RGBA - *dest = format.ARGBToColor(src[3], src[0], src[1], src[2]); + uint32 result = 0; + + switch (bpp) { + case 1: // Grayscale + if (_transparentColorSpecified) + a = (src[0] == _transparentColor[0]) ? 0 : 0xFF; + result = format.ARGBToColor( a, src[0], src[0], src[0]); + break; + case 2: // Grayscale + alpha + result = format.ARGBToColor(src[1], src[0], src[0], src[0]); + break; + case 3: // RGB + if (_transparentColorSpecified) { + bool isTransparentColor = (src[0] == _transparentColor[0] && + src[1] == _transparentColor[1] && + src[2] == _transparentColor[2]); + a = isTransparentColor ? 0 : 0xFF; } + result = format.ARGBToColor( a, src[0], src[1], src[2]); + break; + case 4: // RGBA + result = format.ARGBToColor(src[3], src[0], src[1], src[2]); + break; } - src += _unfilteredSurface->format.bytesPerPixel; + if (format.bytesPerPixel == 2) // 2bpp + *((uint16 *)output->getBasePtr(j, i)) = (uint16)result; + else // 4bpp + *((uint32 *)output->getBasePtr(j, i)) = result; + + src += bpp; } } } else { byte index, r, g, b; + uint32 mask = (0xff >> (8 - _header.bitDepth)) << (8 - _header.bitDepth); // Convert the indexed surface to the target pixel format for (uint16 i = 0; i < output->h; i++) { - bool otherPixel = false; + int data = 0; + int bitCount = 8; + byte *src1 = src; for (uint16 j = 0; j < output->w; j++) { - if (_header.bitDepth != 4) - index = *src; - else if (!otherPixel) - index = (*src) >> 4; - else - index = (*src) & 0xf; + if (bitCount == 8) { + data = *src; + src++; + } + + index = (data & mask) >> (8 - _header.bitDepth); + data = (data << _header.bitDepth) & 0xff; + bitCount -= _header.bitDepth; + + if (bitCount == 0) + bitCount = 8; r = _palette[index * 4 + 0]; g = _palette[index * 4 + 1]; @@ -195,14 +196,8 @@ Graphics::Surface *PNG::getSurface(const PixelFormat &format) { *((uint16 *)output->getBasePtr(j, i)) = format.ARGBToColor(a, r, g, b); else *((uint32 *)output->getBasePtr(j, i)) = format.ARGBToColor(a, r, g, b); - - if (_header.bitDepth != 4 || otherPixel) - src++; - otherPixel = !otherPixel; } - // The surface is a whole scanline wide, skip the rest of it. - if (_header.bitDepth == 4) - src += output->w / 2; + src = src1 + output->w; } } @@ -236,7 +231,7 @@ bool PNG::read(Common::SeekableReadStream *str) { case kChunkIDAT: if (_compressedBufferSize == 0) { _compressedBufferSize += chunkLength; - _compressedBuffer = new byte[_compressedBufferSize]; + _compressedBuffer = (byte *)malloc(_compressedBufferSize); _stream->read(_compressedBuffer, chunkLength); } else { // Expand the buffer @@ -244,8 +239,8 @@ bool PNG::read(Common::SeekableReadStream *str) { _compressedBufferSize += chunkLength; byte *tmp = new byte[prevSize]; memcpy(tmp, _compressedBuffer, prevSize); - delete[] _compressedBuffer; - _compressedBuffer = new byte[_compressedBufferSize]; + free(_compressedBuffer); + _compressedBuffer = (byte *)malloc(_compressedBufferSize); memcpy(_compressedBuffer, tmp, prevSize); delete[] tmp; _stream->read(_compressedBuffer + prevSize, chunkLength); @@ -282,7 +277,7 @@ bool PNG::read(Common::SeekableReadStream *str) { // Unpack the compressed buffer Common::MemoryReadStream *compData = new Common::MemoryReadStream(_compressedBuffer, _compressedBufferSize, DisposeAfterUse::YES); _imageData = Common::wrapCompressedReadStream(compData); - + // Construct the final image constructImage(); @@ -306,7 +301,7 @@ byte PNG::paethPredictor(int16 a, int16 b, int16 c) { int16 pa = ABS<int16>(b - c); int16 pb = ABS<int16>(a - c); int16 pc = ABS<int16>(a + b - c - c); - + if (pa <= MIN<int16>(pb, pc)) return (byte)a; else if (pb <= pc) diff --git a/graphics/scaler.cpp b/graphics/scaler.cpp index a35fb9046e..9ade0e6c57 100644 --- a/graphics/scaler.cpp +++ b/graphics/scaler.cpp @@ -24,6 +24,7 @@ #include "graphics/scaler/scalebit.h" #include "common/util.h" #include "common/system.h" +#include "common/textconsole.h" int gBitFormat = 565; @@ -90,6 +91,9 @@ void InitLUT(Graphics::PixelFormat format) { if (RGBtoYUV == 0) RGBtoYUV = (uint32 *)malloc(65536 * sizeof(uint32)); + if (!RGBtoYUV) + error("[InitLUT] Cannot allocate memory for YUV/LUT buffers"); + for (int color = 0; color < 65536; ++color) { format.colorToRGB(color, r, g, b); Y = (r + g + b) >> 2; diff --git a/graphics/scaler/Normal2xARM.s b/graphics/scaler/Normal2xARM.s index 9afe3f34f0..e3592295e0 100644 --- a/graphics/scaler/Normal2xARM.s +++ b/graphics/scaler/Normal2xARM.s @@ -44,6 +44,7 @@ Normal2xARM: ADD r3, r3, r6 yloop: SUBS r14,r4, #4 + ADDLT r14,r14, #4 BLT thin xloop: LDRH r6, [r0], #2 diff --git a/graphics/scaler/aspect.cpp b/graphics/scaler/aspect.cpp index 64a1cd1534..b12fac418b 100644 --- a/graphics/scaler/aspect.cpp +++ b/graphics/scaler/aspect.cpp @@ -57,19 +57,6 @@ static inline void interpolate5Line(uint16 *dst, const uint16 *srcA, const uint1 template<typename ColorMask, int scale> static inline void interpolate5Line(uint16 *dst, const uint16 *srcA, const uint16 *srcB, int width) { - // For efficiency reasons we blit two pixels at a time, so it is important - // that makeRectStretchable() guarantees that the width is even and that - // the rect starts on a well-aligned address. (Even where unaligned memory - // access is allowed there may be a speed penalty for it.) - - // These asserts are disabled for maximal speed; but I leave them in here - // in case other people want to test if the memory alignment (to an - // address divisible by 4) is really working properly. - //assert(((int)dst & 3) == 0); - //assert(((int)srcA & 3) == 0); - //assert(((int)srcB & 3) == 0); - //assert((width & 1) == 0); - if (scale == 1) { while (width--) { *dst++ = interpolate16_7_1<ColorMask>(*srcB++, *srcA++); @@ -86,6 +73,18 @@ static inline void interpolate5Line(uint16 *dst, const uint16 *srcA, const uint1 template<typename ColorMask, int scale> static inline void interpolate5Line(uint16 *dst, const uint16 *srcA, const uint16 *srcB, int width) { + // For efficiency reasons we blit two pixels at a time, so it is important + // that makeRectStretchable() guarantees that the width is even and that + // the rect starts on a well-aligned address. (Even where unaligned memory + // access is allowed there may be a speed penalty for it.) + + // These asserts are disabled for maximal speed; but I leave them in here + // in case other people want to test if the memory alignment (to an + // address divisible by 4) is really working properly. + //assert(((int)dst & 3) == 0); + //assert(((int)srcA & 3) == 0); + //assert(((int)srcB & 3) == 0); + //assert((width & 1) == 0); width /= 2; const uint32 *sA = (const uint32 *)srcA; @@ -202,7 +201,7 @@ int stretch200To240(uint8 *buf, uint32 pitch, int width, int height, int srcX, i template<typename ColorMask> void Normal1xAspectTemplate(const uint8 *srcPtr, uint32 srcPitch, uint8 *dstPtr, uint32 dstPitch, int width, int height) { - for (int y = 0; y < height; ++y) { + for (int y = 0; y < (height * 6 / 5); ++y) { #if ASPECT_MODE == kSuperFastAndUglyAspectMode if ((y % 6) == 5) diff --git a/graphics/scaler/downscaler.cpp b/graphics/scaler/downscaler.cpp index fa17490475..65400ccd46 100644 --- a/graphics/scaler/downscaler.cpp +++ b/graphics/scaler/downscaler.cpp @@ -22,7 +22,7 @@ #include "graphics/scaler/downscaler.h" #include "graphics/scaler/intern.h" -#ifdef ARM +#ifdef USE_ARM_SCALER_ASM extern "C" { void DownscaleAllByHalfARM(const uint8 *srcPtr, uint32 srcPitch, uint8 *dstPtr, uint32 dstPitch, int width, int height, int mask, int round); } diff --git a/graphics/sjis.cpp b/graphics/sjis.cpp index 660abf556c..09e1746df4 100644 --- a/graphics/sjis.cpp +++ b/graphics/sjis.cpp @@ -161,7 +161,7 @@ void FontSJISBase::drawChar(void *dst, uint16 ch, int pitch, int bpp, uint32 c1, outlineExtraWidth = 0; outlineXOffset = 1; } - + if (maxH != -1 && maxH < height) { height = maxH; outlineExtraHeight = 0; @@ -191,7 +191,7 @@ void FontSJISBase::drawChar(void *dst, uint16 ch, int pitch, int bpp, uint32 c1, if (_drawMode == kOutlineMode) { blitCharacter<uint8>(outline, width + outlineExtraWidth, height + outlineExtraHeight, (uint8 *)dst, pitch, c2); blitCharacter<uint8>(glyphSource, width - outlineXOffset, height - outlineYOffset, (uint8 *)dst + pitch + 1, pitch, c1); - } else { + } else { if (_drawMode != kDefaultMode) { blitCharacter<uint8>(glyphSource, width - outlineXOffset, height, ((uint8*)dst) + 1, pitch, c2); blitCharacter<uint8>(glyphSource, width, height - outlineYOffset, ((uint8*)dst) + pitch, pitch, c2); diff --git a/graphics/sjis.h b/graphics/sjis.h index 21ced62b1d..0c3b057cc4 100644 --- a/graphics/sjis.h +++ b/graphics/sjis.h @@ -141,7 +141,7 @@ public: void toggleFlippedMode(bool enable) { _flippedMode = enable; } uint getFontHeight() const { return (_drawMode == kOutlineMode) ? 18 : (_drawMode == kDefaultMode ? 16 : 17); } - + uint getMaxFontWidth() const { return (_drawMode == kOutlineMode) ? 18 : (_drawMode == kDefaultMode ? 16 : 17); } uint getCharWidth(uint16 ch) const; diff --git a/graphics/surface.cpp b/graphics/surface.cpp index cee8e61438..0fad25734c 100644 --- a/graphics/surface.cpp +++ b/graphics/surface.cpp @@ -127,7 +127,7 @@ void Surface::vLine(int x, int y, int y2, uint32 color) { *ptr = (uint16)color; ptr += pitch / 2; } - + } else if (format.bytesPerPixel == 4) { uint32 *ptr = (uint32 *)getBasePtr(x, y); while (y++ <= y2) { diff --git a/graphics/surface.h b/graphics/surface.h index 2a0f71955a..018a283aad 100644 --- a/graphics/surface.h +++ b/graphics/surface.h @@ -189,7 +189,7 @@ struct Surface { /** * A deleter for Surface objects which can be used with SharedPtr. - * + * * This deleter assures Surface::free is called on deletion. */ struct SharedPtrSurfaceDeleter { |