diff options
Diffstat (limited to 'graphics')
-rw-r--r-- | graphics/font.cpp | 100 | ||||
-rw-r--r-- | graphics/font.h | 10 | ||||
-rw-r--r-- | graphics/iff.h | 2 | ||||
-rw-r--r-- | graphics/palette.h | 2 | ||||
-rw-r--r-- | graphics/pict.cpp | 4 | ||||
-rw-r--r-- | graphics/scaler.cpp | 6 | ||||
-rw-r--r-- | graphics/surface.cpp | 48 | ||||
-rw-r--r-- | graphics/yuv_to_rgb.cpp | 63 |
8 files changed, 133 insertions, 102 deletions
diff --git a/graphics/font.cpp b/graphics/font.cpp index 5f5a9b2fca..cdf9090625 100644 --- a/graphics/font.cpp +++ b/graphics/font.cpp @@ -30,23 +30,23 @@ namespace Graphics { -void free_font(NewFontData* pf); +void free_font(NewFontData *pf); NewFont::~NewFont() { - if (font) { - free_font(font); + if (_font) { + free_font(_font); } } int NewFont::getCharWidth(byte chr) const { // If no width table is specified, return the maximum width - if (!desc.width) - return desc.maxwidth; + if (!_desc.width) + return _desc.maxwidth; // If this character is not included in the font, use the default char. - if (chr < desc.firstchar || desc.firstchar + desc.size < chr) { - chr = desc.defaultchar; + if (chr < _desc.firstchar || _desc.firstchar + _desc.size < chr) { + chr = _desc.defaultchar; } - return desc.width[chr - desc.firstchar]; + return _desc.width[chr - _desc.firstchar]; } @@ -74,38 +74,38 @@ void drawCharIntern(byte *ptr, uint pitch, const bitmap_t *src, int h, int minX, void NewFont::drawChar(Surface *dst, byte chr, const int tx, const int ty, const uint32 color) const { assert(dst != 0); - assert(desc.bits != 0 && desc.maxwidth <= 16); + assert(_desc.bits != 0 && _desc.maxwidth <= 16); assert(dst->format.bytesPerPixel == 1 || dst->format.bytesPerPixel == 2); // If this character is not included in the font, use the default char. - if (chr < desc.firstchar || chr >= desc.firstchar + desc.size) { - chr = desc.defaultchar; + if (chr < _desc.firstchar || chr >= _desc.firstchar + _desc.size) { + chr = _desc.defaultchar; } - chr -= desc.firstchar; + chr -= _desc.firstchar; int bbw, bbh, bbx, bby; // Get the bounding box of the character - if (!desc.bbx) { - bbw = desc.fbbw; - bbh = desc.fbbh; - bbx = desc.fbbx; - bby = desc.fbby; + if (!_desc.bbx) { + bbw = _desc.fbbw; + bbh = _desc.fbbh; + bbx = _desc.fbbx; + bby = _desc.fbby; } else { - bbw = desc.bbx[chr].w; - bbh = desc.bbx[chr].h; - bbx = desc.bbx[chr].x; - bby = desc.bbx[chr].y; + bbw = _desc.bbx[chr].w; + bbh = _desc.bbx[chr].h; + bbx = _desc.bbx[chr].x; + bby = _desc.bbx[chr].y; } - byte *ptr = (byte *)dst->getBasePtr(tx + bbx, ty + desc.ascent - bby - bbh); + byte *ptr = (byte *)dst->getBasePtr(tx + bbx, ty + _desc.ascent - bby - bbh); - const bitmap_t *tmp = desc.bits + (desc.offset ? desc.offset[chr] : (chr * desc.fbbh)); + const bitmap_t *tmp = _desc.bits + (_desc.offset ? _desc.offset[chr] : (chr * _desc.fbbh)); - int y = MIN(bbh, ty + desc.ascent - bby); + int y = MIN(bbh, ty + _desc.ascent - bby); tmp += bbh - y; - y -= MAX(0, ty + desc.ascent - bby - dst->h); + y -= MAX(0, ty + _desc.ascent - bby - dst->h); if (dst->format.bytesPerPixel == 1) drawCharIntern<byte>(ptr, dst->pitch, tmp, y, MAX(0, -(tx + bbx)), MIN(bbw, dst->w - tx - bbx), color); @@ -615,47 +615,47 @@ bool NewFont::cacheFontData(const NewFont &font, const Common::String &filename) return false; } - cacheFile.writeUint16BE(font.desc.maxwidth); - cacheFile.writeUint16BE(font.desc.height); - cacheFile.writeUint16BE(font.desc.fbbw); - cacheFile.writeUint16BE(font.desc.fbbh); - cacheFile.writeSint16BE(font.desc.fbbx); - cacheFile.writeSint16BE(font.desc.fbby); - cacheFile.writeUint16BE(font.desc.ascent); - cacheFile.writeUint16BE(font.desc.firstchar); - cacheFile.writeUint16BE(font.desc.size); - cacheFile.writeUint16BE(font.desc.defaultchar); - cacheFile.writeUint32BE(font.desc.bits_size); + cacheFile.writeUint16BE(font._desc.maxwidth); + cacheFile.writeUint16BE(font._desc.height); + cacheFile.writeUint16BE(font._desc.fbbw); + cacheFile.writeUint16BE(font._desc.fbbh); + cacheFile.writeSint16BE(font._desc.fbbx); + cacheFile.writeSint16BE(font._desc.fbby); + cacheFile.writeUint16BE(font._desc.ascent); + cacheFile.writeUint16BE(font._desc.firstchar); + cacheFile.writeUint16BE(font._desc.size); + cacheFile.writeUint16BE(font._desc.defaultchar); + cacheFile.writeUint32BE(font._desc.bits_size); - for (long i = 0; i < font.desc.bits_size; ++i) { - cacheFile.writeUint16BE(font.desc.bits[i]); + for (long i = 0; i < font._desc.bits_size; ++i) { + cacheFile.writeUint16BE(font._desc.bits[i]); } - if (font.desc.offset) { + if (font._desc.offset) { cacheFile.writeByte(1); - for (int i = 0; i < font.desc.size; ++i) { - cacheFile.writeUint32BE(font.desc.offset[i]); + for (int i = 0; i < font._desc.size; ++i) { + cacheFile.writeUint32BE(font._desc.offset[i]); } } else { cacheFile.writeByte(0); } - if (font.desc.width) { + if (font._desc.width) { cacheFile.writeByte(1); - for (int i = 0; i < font.desc.size; ++i) { - cacheFile.writeByte(font.desc.width[i]); + for (int i = 0; i < font._desc.size; ++i) { + cacheFile.writeByte(font._desc.width[i]); } } else { cacheFile.writeByte(0); } - if (font.desc.bbx) { + if (font._desc.bbx) { cacheFile.writeByte(1); - for (int i = 0; i < font.desc.size; ++i) { - cacheFile.writeByte(font.desc.bbx[i].w); - cacheFile.writeByte(font.desc.bbx[i].h); - cacheFile.writeByte(font.desc.bbx[i].x); - cacheFile.writeByte(font.desc.bbx[i].y); + for (int i = 0; i < font._desc.size; ++i) { + cacheFile.writeByte(font._desc.bbx[i].w); + cacheFile.writeByte(font._desc.bbx[i].h); + cacheFile.writeByte(font._desc.bbx[i].x); + cacheFile.writeByte(font._desc.bbx[i].y); } } else { cacheFile.writeByte(0); diff --git a/graphics/font.h b/graphics/font.h index f68f49175f..7a992674d2 100644 --- a/graphics/font.h +++ b/graphics/font.h @@ -157,15 +157,15 @@ struct NewFontData; class NewFont : public Font { protected: - FontDesc desc; - NewFontData *font; + FontDesc _desc; + NewFontData *_font; public: - NewFont(const FontDesc &d, NewFontData *font_ = 0) : desc(d), font(font_) {} + NewFont(const FontDesc &desc, NewFontData *font = 0) : _desc(desc), _font(font) {} ~NewFont(); - virtual int getFontHeight() const { return desc.height; } - virtual int getMaxCharWidth() const { return desc.maxwidth; } + virtual int getFontHeight() const { return _desc.height; } + virtual int getMaxCharWidth() const { return _desc.maxwidth; } virtual int getCharWidth(byte chr) const; virtual void drawChar(Surface *dst, byte chr, int x, int y, uint32 color) const; diff --git a/graphics/iff.h b/graphics/iff.h index 761c57c932..4d88148372 100644 --- a/graphics/iff.h +++ b/graphics/iff.h @@ -111,7 +111,7 @@ void decodePBM(Common::ReadStream &input, Surface &surface, byte *colors); * Decode a given PackBits encoded stream. * * PackBits is an RLE compression algorithm introduced by Apple. It is also - * used to encode ILBM and PBM subtypes of IFF files, and some flavours of + * used to encode ILBM and PBM subtypes of IFF files, and some flavors of * TIFF. * * As there is no compression across row boundaries in the above formats, diff --git a/graphics/palette.h b/graphics/palette.h index 7eedb0f78d..77891c3fdc 100644 --- a/graphics/palette.h +++ b/graphics/palette.h @@ -55,7 +55,7 @@ public: * @param start the first palette entry to be updated * @param num the number of palette entries to be updated * - * @note It is an error if start+num exceeds 256, behaviour is undefined + * @note It is an error if start+num exceeds 256, behavior is undefined * in that case (the backend may ignore it silently or assert). * @note It is an error if this function gets called when the pixel format * in use (the return value of getScreenFormat) has more than one diff --git a/graphics/pict.cpp b/graphics/pict.cpp index 9779d3231c..80bcb7a71e 100644 --- a/graphics/pict.cpp +++ b/graphics/pict.cpp @@ -324,8 +324,8 @@ void PictDecoder::outputPixelBuffer(byte *&out, byte value, byte bitsPerPixel) { } // Compressed QuickTime details can be found here: -// http://developer.apple.com/documentation/QuickTime/Rm/CompressDecompress/ImageComprMgr/B-Chapter/2TheImageCompression.html -// http://developer.apple.com/documentation/QuickTime/Rm/CompressDecompress/ImageComprMgr/F-Chapter/6WorkingwiththeImage.html +// http://developer.apple.com/legacy/mac/library/#documentation/QuickTime/Rm/CompressDecompress/ImageComprMgr/B-Chapter/2TheImageCompression.html +// http://developer.apple.com/legacy/mac/library/#documentation/QuickTime/Rm/CompressDecompress/ImageComprMgr/F-Chapter/6WorkingwiththeImage.html // I'm just ignoring that because Myst ME uses none of that extra stuff. The offset is always the same. void PictDecoder::decodeCompressedQuickTime(Common::SeekableReadStream *stream) { diff --git a/graphics/scaler.cpp b/graphics/scaler.cpp index 8038e2089e..a35fb9046e 100644 --- a/graphics/scaler.cpp +++ b/graphics/scaler.cpp @@ -196,7 +196,7 @@ void Normal2x(const uint8 *srcPtr, #else /** - * Trivial nearest-neighbour 2x scaler. + * Trivial nearest-neighbor 2x scaler. */ void Normal2x(const uint8 *srcPtr, uint32 srcPitch, uint8 *dstPtr, uint32 dstPitch, int width, int height) { @@ -221,7 +221,7 @@ void Normal2x(const uint8 *srcPtr, uint32 srcPitch, uint8 *dstPtr, uint32 dstPit #endif /** - * Trivial nearest-neighbour 3x scaler. + * Trivial nearest-neighbor 3x scaler. */ void Normal3x(const uint8 *srcPtr, uint32 srcPitch, uint8 *dstPtr, uint32 dstPitch, int width, int height) { @@ -254,7 +254,7 @@ void Normal3x(const uint8 *srcPtr, uint32 srcPitch, uint8 *dstPtr, uint32 dstPit #define interpolate_1_1_1_1 interpolate16_1_1_1_1<ColorMask> /** - * Trivial nearest-neighbour 1.5x scaler. + * Trivial nearest-neighbor 1.5x scaler. */ template<typename ColorMask> void Normal1o5xTemplate(const uint8 *srcPtr, uint32 srcPitch, uint8 *dstPtr, uint32 dstPitch, diff --git a/graphics/surface.cpp b/graphics/surface.cpp index 3f53ce56f4..cee8e61438 100644 --- a/graphics/surface.cpp +++ b/graphics/surface.cpp @@ -42,8 +42,10 @@ void Surface::drawLine(int x0, int y0, int x1, int y1, uint32 color) { Graphics::drawLine(x0, y0, x1, y1, color, plotPoint<byte>, this); else if (format.bytesPerPixel == 2) Graphics::drawLine(x0, y0, x1, y1, color, plotPoint<uint16>, this); + else if (format.bytesPerPixel == 4) + Graphics::drawLine(x0, y0, x1, y1, color, plotPoint<uint32>, this); else - error("Surface::drawLine: bytesPerPixel must be 1 or 2"); + error("Surface::drawLine: bytesPerPixel must be 1, 2, or 4"); } void Surface::create(uint16 width, uint16 height, const PixelFormat &f) { @@ -88,12 +90,15 @@ void Surface::hLine(int x, int y, int x2, uint32 color) { if (format.bytesPerPixel == 1) { byte *ptr = (byte *)getBasePtr(x, y); - memset(ptr, (byte)color, x2-x+1); + memset(ptr, (byte)color, x2 - x + 1); } else if (format.bytesPerPixel == 2) { uint16 *ptr = (uint16 *)getBasePtr(x, y); - Common::set_to(ptr, ptr + (x2-x+1), (uint16)color); + Common::set_to(ptr, ptr + (x2 - x + 1), (uint16)color); + } else if (format.bytesPerPixel == 4) { + uint32 *ptr = (uint32 *)getBasePtr(x, y); + Common::set_to(ptr, ptr + (x2 - x + 1), color); } else { - error("Surface::hLine: bytesPerPixel must be 1 or 2"); + error("Surface::hLine: bytesPerPixel must be 1, 2, or 4"); } } @@ -120,10 +125,17 @@ void Surface::vLine(int x, int y, int y2, uint32 color) { uint16 *ptr = (uint16 *)getBasePtr(x, y); while (y++ <= y2) { *ptr = (uint16)color; - ptr += pitch/2; + ptr += pitch / 2; + } + + } else if (format.bytesPerPixel == 4) { + uint32 *ptr = (uint32 *)getBasePtr(x, y); + while (y++ <= y2) { + *ptr = color; + ptr += pitch / 4; } } else { - error("Surface::vLine: bytesPerPixel must be 1 or 2"); + error("Surface::vLine: bytesPerPixel must be 1, 2, or 4"); } } @@ -145,7 +157,7 @@ void Surface::fillRect(Common::Rect r, uint32 color) { } else if (format.bytesPerPixel == 4) { useMemset = false; } else if (format.bytesPerPixel != 1) { - error("Surface::fillRect: bytesPerPixel must be 1, 2 or 4"); + error("Surface::fillRect: bytesPerPixel must be 1, 2, or 4"); } if (useMemset) { @@ -159,7 +171,7 @@ void Surface::fillRect(Common::Rect r, uint32 color) { uint16 *ptr = (uint16 *)getBasePtr(r.left, r.top); while (height--) { Common::set_to(ptr, ptr + width, (uint16)color); - ptr += pitch/2; + ptr += pitch / 2; } } else { uint32 *ptr = (uint32 *)getBasePtr(r.left, r.top); @@ -172,10 +184,10 @@ void Surface::fillRect(Common::Rect r, uint32 color) { } void Surface::frameRect(const Common::Rect &r, uint32 color) { - hLine(r.left, r.top, r.right-1, color); - hLine(r.left, r.bottom-1, r.right-1, color); - vLine(r.left, r.top, r.bottom-1, color); - vLine(r.right-1, r.top, r.bottom-1, color); + hLine(r.left, r.top, r.right - 1, color); + hLine(r.left, r.bottom - 1, r.right - 1, color); + vLine(r.left, r.top, r.bottom - 1, color); + vLine(r.right - 1, r.top, r.bottom - 1, color); } void Surface::move(int dx, int dy, int height) { @@ -183,8 +195,8 @@ void Surface::move(int dx, int dy, int height) { if ((dx == 0 && dy == 0) || height <= 0) return; - if (format.bytesPerPixel != 1 && format.bytesPerPixel != 2) - error("Surface::move: bytesPerPixel must be 1 or 2"); + if (format.bytesPerPixel != 1 && format.bytesPerPixel != 2 && format.bytesPerPixel != 4) + error("Surface::move: bytesPerPixel must be 1, 2, or 4"); byte *src, *dst; int x, y; @@ -223,6 +235,10 @@ void Surface::move(int dx, int dy, int height) { *(uint16 *)dst = *(const uint16 *)src; src -= 2; dst -= 2; + } else if (format.bytesPerPixel == 4) { + *(uint32 *)dst = *(const uint32 *)src; + src -= 4; + dst -= 4; } } src += pitch + (pitch - dx * format.bytesPerPixel); @@ -240,6 +256,10 @@ void Surface::move(int dx, int dy, int height) { *(uint16 *)dst = *(const uint16 *)src; src += 2; dst += 2; + } else if (format.bytesPerPixel == 4) { + *(uint32 *)dst = *(const uint32 *)src; + src += 4; + dst += 4; } } src += pitch - (pitch + dx * format.bytesPerPixel); diff --git a/graphics/yuv_to_rgb.cpp b/graphics/yuv_to_rgb.cpp index 831736cd75..037ea9a007 100644 --- a/graphics/yuv_to_rgb.cpp +++ b/graphics/yuv_to_rgb.cpp @@ -196,52 +196,63 @@ DECLARE_SINGLETON(Graphics::YUVToRGBManager); namespace Graphics { #define PUT_PIXEL(s, d) \ - L = &lookup->_rgbToPix[(s)]; \ - if (dst->format.bytesPerPixel == 2) \ - *((uint16 *)(d)) = (L[cr_r] | L[crb_g] | L[cb_b]); \ - else \ - *((uint32 *)(d)) = (L[cr_r] | L[crb_g] | L[cb_b]) - -void convertYUV420ToRGB(Graphics::Surface *dst, const byte *ySrc, const byte *uSrc, const byte *vSrc, int yWidth, int yHeight, int yPitch, int uvPitch) { - // Sanity checks - assert(dst && dst->pixels); - assert(dst->format.bytesPerPixel == 2 || dst->format.bytesPerPixel == 4); - assert(ySrc && uSrc && vSrc); - assert((yWidth & 1) == 0); - assert((yHeight & 1) == 0); - - const YUVToRGBLookup *lookup = YUVToRGBMan.getLookup(dst->format); - - byte *dstPtr = (byte *)dst->pixels; + L = &rgbToPix[(s)]; \ + *((PixelInt *)(d)) = (L[cr_r] | L[crb_g] | L[cb_b]) +template<typename PixelInt> +void convertYUV420ToRGB(byte *dstPtr, int dstPitch, const YUVToRGBLookup *lookup, const byte *ySrc, const byte *uSrc, const byte *vSrc, int yWidth, int yHeight, int yPitch, int uvPitch) { int halfHeight = yHeight >> 1; int halfWidth = yWidth >> 1; + // Keep the tables in pointers here to avoid a dereference on each pixel + const int16 *Cr_r_tab = lookup->_colorTab; + const int16 *Cr_g_tab = Cr_r_tab + 256; + const int16 *Cb_g_tab = Cr_g_tab + 256; + const int16 *Cb_b_tab = Cb_g_tab + 256; + const uint32 *rgbToPix = lookup->_rgbToPix; + for (int h = 0; h < halfHeight; h++) { for (int w = 0; w < halfWidth; w++) { - register uint32 *L; + register const uint32 *L; - int16 cr_r = lookup->_colorTab[*vSrc + 0 * 256]; - int16 crb_g = lookup->_colorTab[*vSrc + 1 * 256] + lookup->_colorTab[*uSrc + 2 * 256]; - int16 cb_b = lookup->_colorTab[*uSrc + 3 * 256]; + int16 cr_r = Cr_r_tab[*vSrc]; + int16 crb_g = Cr_g_tab[*vSrc] + Cb_g_tab[*uSrc]; + int16 cb_b = Cb_b_tab[*uSrc]; ++uSrc; ++vSrc; PUT_PIXEL(*ySrc, dstPtr); - PUT_PIXEL(*(ySrc + yPitch), dstPtr + dst->pitch); + PUT_PIXEL(*(ySrc + yPitch), dstPtr + dstPitch); ySrc++; - dstPtr += dst->format.bytesPerPixel; + dstPtr += sizeof(PixelInt); PUT_PIXEL(*ySrc, dstPtr); - PUT_PIXEL(*(ySrc + yPitch), dstPtr + dst->pitch); + PUT_PIXEL(*(ySrc + yPitch), dstPtr + dstPitch); ySrc++; - dstPtr += dst->format.bytesPerPixel; + dstPtr += sizeof(PixelInt); } - dstPtr += dst->pitch; + dstPtr += dstPitch; ySrc += (yPitch << 1) - yWidth; uSrc += uvPitch - halfWidth; vSrc += uvPitch - halfWidth; } } +void convertYUV420ToRGB(Graphics::Surface *dst, const byte *ySrc, const byte *uSrc, const byte *vSrc, int yWidth, int yHeight, int yPitch, int uvPitch) { + // Sanity checks + assert(dst && dst->pixels); + assert(dst->format.bytesPerPixel == 2 || dst->format.bytesPerPixel == 4); + assert(ySrc && uSrc && vSrc); + assert((yWidth & 1) == 0); + assert((yHeight & 1) == 0); + + const YUVToRGBLookup *lookup = YUVToRGBMan.getLookup(dst->format); + + // Use a templated function to avoid an if check on every pixel + if (dst->format.bytesPerPixel == 2) + convertYUV420ToRGB<uint16>((byte *)dst->pixels, dst->pitch, lookup, ySrc, uSrc, vSrc, yWidth, yHeight, yPitch, uvPitch); + else + convertYUV420ToRGB<uint32>((byte *)dst->pixels, dst->pitch, lookup, ySrc, uSrc, vSrc, yWidth, yHeight, yPitch, uvPitch); +} + } // End of namespace Graphics |