aboutsummaryrefslogtreecommitdiff
path: root/graphics
diff options
context:
space:
mode:
Diffstat (limited to 'graphics')
-rw-r--r--graphics/VectorRendererSpec.cpp38
-rw-r--r--graphics/font.cpp6
-rw-r--r--graphics/fonts/scummfont.cpp4
-rw-r--r--graphics/fonts/winfont.cpp8
-rw-r--r--graphics/iff.cpp2
-rw-r--r--graphics/imagedec.cpp2
-rw-r--r--graphics/jpeg.cpp4
-rw-r--r--graphics/pict.cpp2
-rw-r--r--graphics/png.cpp29
-rw-r--r--graphics/scaler/thumbnail_intern.cpp18
-rw-r--r--graphics/sjis.cpp2
-rw-r--r--graphics/surface.cpp56
-rw-r--r--graphics/surface.h16
-rw-r--r--graphics/thumbnail.cpp10
14 files changed, 100 insertions, 97 deletions
diff --git a/graphics/VectorRendererSpec.cpp b/graphics/VectorRendererSpec.cpp
index 3eef1b11a9..3eb8b1345f 100644
--- a/graphics/VectorRendererSpec.cpp
+++ b/graphics/VectorRendererSpec.cpp
@@ -276,7 +276,7 @@ copyFrame(OSystem *sys, const Common::Rect &r) {
sys->copyRectToOverlay(
(const OverlayColor *)_activeSurface->getBasePtr(r.left, r.top),
- _activeSurface->pitch / _activeSurface->bytesPerPixel,
+ _activeSurface->pitch / _activeSurface->format.bytesPerPixel,
r.left, r.top, r.width(), r.height()
);
}
@@ -336,8 +336,8 @@ blitAlphaBitmap(const Graphics::Surface *source, const Common::Rect &r) {
PixelType *dst_ptr = (PixelType *)_activeSurface->getBasePtr(x, y);
const PixelType *src_ptr = (const PixelType *)source->getBasePtr(0, 0);
- int dst_pitch = _activeSurface->pitch / _activeSurface->bytesPerPixel;
- int src_pitch = source->pitch / source->bytesPerPixel;
+ int dst_pitch = _activeSurface->pitch / _activeSurface->format.bytesPerPixel;
+ int src_pitch = source->pitch / source->format.bytesPerPixel;
int w, h = source->h;
@@ -484,7 +484,7 @@ drawLine(int x1, int y1, int x2, int y2) {
return;
PixelType *ptr = (PixelType *)_activeSurface->getBasePtr(x1, y1);
- int pitch = _activeSurface->pitch / _activeSurface->bytesPerPixel;
+ int pitch = _activeSurface->pitch / _activeSurface->format.bytesPerPixel;
int st = Base::_strokeWidth >> 1;
if (dy == 0) { // horizontal lines
@@ -732,7 +732,7 @@ void VectorRendererSpec<PixelType>::
drawTabAlg(int x1, int y1, int w, int h, int r, PixelType color, VectorRenderer::FillMode fill_m, int baseLeft, int baseRight) {
int f, ddF_x, ddF_y;
int x, y, px, py;
- int pitch = _activeSurface->pitch / _activeSurface->bytesPerPixel;
+ int pitch = _activeSurface->pitch / _activeSurface->format.bytesPerPixel;
int sw = 0, sp = 0, hp = 0;
PixelType *ptr_tl = (PixelType *)Base::_activeSurface->getBasePtr(x1 + r, y1 + r);
@@ -830,7 +830,7 @@ drawTabAlg(int x1, int y1, int w, int h, int r, PixelType color, VectorRenderer:
template<typename PixelType>
void VectorRendererSpec<PixelType>::
drawBevelTabAlg(int x, int y, int w, int h, int bevel, PixelType top_color, PixelType bottom_color, int baseLeft, int baseRight) {
- int pitch = _activeSurface->pitch / _activeSurface->bytesPerPixel;
+ int pitch = _activeSurface->pitch / _activeSurface->format.bytesPerPixel;
int i, j;
PixelType *ptr_left = (PixelType *)_activeSurface->getBasePtr(x, y);
@@ -875,7 +875,7 @@ template<typename PixelType>
void VectorRendererSpec<PixelType>::
drawSquareAlg(int x, int y, int w, int h, PixelType color, VectorRenderer::FillMode fill_m) {
PixelType *ptr = (PixelType *)_activeSurface->getBasePtr(x, y);
- int pitch = _activeSurface->pitch / _activeSurface->bytesPerPixel;
+ int pitch = _activeSurface->pitch / _activeSurface->format.bytesPerPixel;
int max_h = h;
if (fill_m != kFillDisabled) {
@@ -907,7 +907,7 @@ drawSquareAlg(int x, int y, int w, int h, PixelType color, VectorRenderer::FillM
template<typename PixelType>
void VectorRendererSpec<PixelType>::
drawBevelSquareAlg(int x, int y, int w, int h, int bevel, PixelType top_color, PixelType bottom_color, bool fill) {
- int pitch = _activeSurface->pitch / _activeSurface->bytesPerPixel;
+ int pitch = _activeSurface->pitch / _activeSurface->format.bytesPerPixel;
int height = h;
PixelType *ptr_fill = (PixelType *)_activeSurface->getBasePtr(x, y);
@@ -964,7 +964,7 @@ template<typename PixelType>
void VectorRendererSpec<PixelType>::
drawLineAlg(int x1, int y1, int x2, int y2, int dx, int dy, PixelType color) {
PixelType *ptr = (PixelType *)_activeSurface->getBasePtr(x1, y1);
- int pitch = _activeSurface->pitch / _activeSurface->bytesPerPixel;
+ int pitch = _activeSurface->pitch / _activeSurface->format.bytesPerPixel;
int xdir = (x2 > x1) ? 1 : -1;
*ptr = (PixelType)color;
@@ -1012,7 +1012,7 @@ template<typename PixelType>
void VectorRendererSpec<PixelType>::
drawTriangleVertAlg(int x1, int y1, int w, int h, bool inverted, PixelType color, VectorRenderer::FillMode fill_m) {
int dx = w >> 1, dy = h, gradient_h = 0;
- int pitch = _activeSurface->pitch / _activeSurface->bytesPerPixel;
+ int pitch = _activeSurface->pitch / _activeSurface->format.bytesPerPixel;
PixelType *ptr_right = 0, *ptr_left = 0;
if (inverted) {
@@ -1093,7 +1093,7 @@ drawTriangleVertAlg(int x1, int y1, int w, int h, bool inverted, PixelType color
template<typename PixelType>
void VectorRendererSpec<PixelType>::
drawTriangleFast(int x1, int y1, int size, bool inverted, PixelType color, VectorRenderer::FillMode fill_m) {
- int pitch = _activeSurface->pitch / _activeSurface->bytesPerPixel;
+ int pitch = _activeSurface->pitch / _activeSurface->format.bytesPerPixel;
int hstep = 0, dy = size;
bool grad = (fill_m == kFillGradient);
@@ -1142,7 +1142,7 @@ void VectorRendererSpec<PixelType>::
drawRoundedSquareAlg(int x1, int y1, int r, int w, int h, PixelType color, VectorRenderer::FillMode fill_m) {
int f, ddF_x, ddF_y;
int x, y, px, py;
- int pitch = _activeSurface->pitch / _activeSurface->bytesPerPixel;
+ int pitch = _activeSurface->pitch / _activeSurface->format.bytesPerPixel;
int sw = 0, sp = 0, hp = h * pitch;
PixelType *ptr_tl = (PixelType *)Base::_activeSurface->getBasePtr(x1 + r, y1 + r);
@@ -1233,7 +1233,7 @@ void VectorRendererSpec<PixelType>::
drawCircleAlg(int x1, int y1, int r, PixelType color, VectorRenderer::FillMode fill_m) {
int f, ddF_x, ddF_y;
int x, y, px, py, sw = 0;
- int pitch = _activeSurface->pitch / _activeSurface->bytesPerPixel;
+ int pitch = _activeSurface->pitch / _activeSurface->format.bytesPerPixel;
PixelType *ptr = (PixelType *)Base::_activeSurface->getBasePtr(x1, y1);
if (fill_m == kFillDisabled) {
@@ -1283,7 +1283,7 @@ template<typename PixelType>
void VectorRendererSpec<PixelType>::
drawSquareShadow(int x, int y, int w, int h, int blur) {
PixelType *ptr = (PixelType *)_activeSurface->getBasePtr(x + w - 1, y + blur);
- int pitch = _activeSurface->pitch / _activeSurface->bytesPerPixel;
+ int pitch = _activeSurface->pitch / _activeSurface->format.bytesPerPixel;
int i, j;
i = h - blur;
@@ -1320,7 +1320,7 @@ void VectorRendererSpec<PixelType>::
drawRoundedSquareShadow(int x1, int y1, int r, int w, int h, int blur) {
int f, ddF_x, ddF_y;
int x, y, px, py;
- int pitch = _activeSurface->pitch / _activeSurface->bytesPerPixel;
+ int pitch = _activeSurface->pitch / _activeSurface->format.bytesPerPixel;
int alpha = 102;
x1 += blur;
@@ -1367,7 +1367,7 @@ template<typename PixelType>
void VectorRendererSpec<PixelType>::
drawRoundedSquareFakeBevel(int x1, int y1, int r, int w, int h, int amount) {
int x, y;
- const int pitch = _activeSurface->pitch / _activeSurface->bytesPerPixel;
+ const int pitch = _activeSurface->pitch / _activeSurface->format.bytesPerPixel;
int px, py;
int sw = 0, sp = 0;
@@ -1437,7 +1437,7 @@ void VectorRendererAA<PixelType>::
drawLineAlg(int x1, int y1, int x2, int y2, int dx, int dy, PixelType color) {
PixelType *ptr = (PixelType *)Base::_activeSurface->getBasePtr(x1, y1);
- int pitch = Base::_activeSurface->pitch / Base::_activeSurface->bytesPerPixel;
+ int pitch = Base::_activeSurface->pitch / Base::_activeSurface->format.bytesPerPixel;
int xdir = (x2 > x1) ? 1 : -1;
uint16 error_tmp, error_acc, gradient;
uint8 alpha;
@@ -1488,7 +1488,7 @@ template<typename PixelType>
void VectorRendererAA<PixelType>::
drawRoundedSquareAlg(int x1, int y1, int r, int w, int h, PixelType color, VectorRenderer::FillMode fill_m) {
int x, y;
- const int pitch = Base::_activeSurface->pitch / Base::_activeSurface->bytesPerPixel;
+ const int pitch = Base::_activeSurface->pitch / Base::_activeSurface->format.bytesPerPixel;
int px, py;
int sw = 0, sp = 0, hp = h * pitch;
@@ -1565,7 +1565,7 @@ template<typename PixelType>
void VectorRendererAA<PixelType>::
drawCircleAlg(int x1, int y1, int r, PixelType color, VectorRenderer::FillMode fill_m) {
int x, y, sw = 0;
- const int pitch = Base::_activeSurface->pitch / Base::_activeSurface->bytesPerPixel;
+ const int pitch = Base::_activeSurface->pitch / Base::_activeSurface->format.bytesPerPixel;
int px, py;
uint32 rsq = r*r;
diff --git a/graphics/font.cpp b/graphics/font.cpp
index 9d450e881c..7fa39d07db 100644
--- a/graphics/font.cpp
+++ b/graphics/font.cpp
@@ -78,7 +78,7 @@ void NewFont::drawChar(Surface *dst, byte chr, const int tx, const int ty, const
assert(dst != 0);
assert(desc.bits != 0 && desc.maxwidth <= 16);
- assert(dst->bytesPerPixel == 1 || dst->bytesPerPixel == 2);
+ 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) {
@@ -110,9 +110,9 @@ void NewFont::drawChar(Surface *dst, byte chr, const int tx, const int ty, const
tmp += bbh - y;
y -= MAX(0, ty + desc.ascent - bby - dst->h);
- if (dst->bytesPerPixel == 1)
+ if (dst->format.bytesPerPixel == 1)
drawCharIntern<byte>(ptr, dst->pitch, tmp, y, MAX(0, -(tx + bbx)), MIN(bbw, dst->w - tx - bbx), color);
- else if (dst->bytesPerPixel == 2)
+ else if (dst->format.bytesPerPixel == 2)
drawCharIntern<uint16>(ptr, dst->pitch, tmp, y, MAX(0, -(tx + bbx)), MIN(bbw, dst->w - tx - bbx), color);
}
diff --git a/graphics/fonts/scummfont.cpp b/graphics/fonts/scummfont.cpp
index ea1935cea5..3331b72c47 100644
--- a/graphics/fonts/scummfont.cpp
+++ b/graphics/fonts/scummfont.cpp
@@ -303,9 +303,9 @@ void ScummFont::drawChar(Surface *dst, byte chr, int tx, int ty, uint32 color) c
}
c = ((buffer & mask) != 0);
if (c) {
- if (dst->bytesPerPixel == 1)
+ if (dst->format.bytesPerPixel == 1)
ptr[x] = color;
- else if (dst->bytesPerPixel == 2)
+ else if (dst->format.bytesPerPixel == 2)
((uint16 *)ptr)[x] = color;
}
}
diff --git a/graphics/fonts/winfont.cpp b/graphics/fonts/winfont.cpp
index 18866b4f6f..7db9a233f6 100644
--- a/graphics/fonts/winfont.cpp
+++ b/graphics/fonts/winfont.cpp
@@ -323,7 +323,7 @@ bool WinFont::loadFromFNT(Common::SeekableReadStream &stream) {
void WinFont::drawChar(Surface *dst, byte chr, int x, int y, uint32 color) const {
assert(dst);
- assert(dst->bytesPerPixel == 1 || dst->bytesPerPixel == 2 || dst->bytesPerPixel == 4);
+ assert(dst->format.bytesPerPixel == 1 || dst->format.bytesPerPixel == 2 || dst->format.bytesPerPixel == 4);
assert(_glyphs);
GlyphEntry &glyph = _glyphs[characterToIndex(chr)];
@@ -331,11 +331,11 @@ void WinFont::drawChar(Surface *dst, byte chr, int x, int y, uint32 color) const
for (uint16 i = 0; i < _pixHeight; i++) {
for (uint16 j = 0; j < glyph.charWidth; j++) {
if (glyph.bitmap[j + i * glyph.charWidth]) {
- if (dst->bytesPerPixel == 1)
+ if (dst->format.bytesPerPixel == 1)
*((byte *)dst->getBasePtr(x + j, y + i)) = color;
- else if (dst->bytesPerPixel == 2)
+ else if (dst->format.bytesPerPixel == 2)
*((uint16 *)dst->getBasePtr(x + j, y + i)) = color;
- else if (dst->bytesPerPixel == 4)
+ else if (dst->format.bytesPerPixel == 4)
*((uint32 *)dst->getBasePtr(x + j, y + i)) = color;
}
}
diff --git a/graphics/iff.cpp b/graphics/iff.cpp
index a1f4e8aa6a..fee71de485 100644
--- a/graphics/iff.cpp
+++ b/graphics/iff.cpp
@@ -208,7 +208,7 @@ struct PBMLoader {
case ID_BODY:
if (_surface) {
- _surface->create(_decoder._header.width, _decoder._header.height, 1);
+ _surface->create(_decoder._header.width, _decoder._header.height, PixelFormat::createFormatCLUT8());
_decoder.loadBitmap((byte*)_surface->pixels, chunk._stream);
}
return true; // stop the parser
diff --git a/graphics/imagedec.cpp b/graphics/imagedec.cpp
index 91da83cc63..f45f0ce5ef 100644
--- a/graphics/imagedec.cpp
+++ b/graphics/imagedec.cpp
@@ -118,7 +118,7 @@ Surface *BMPDecoder::decodeImage(Common::SeekableReadStream &stream, const Pixel
uint8 r = 0, g = 0, b = 0;
Surface *newSurf = new Surface;
assert(newSurf);
- newSurf->create(info.width, info.height, sizeof(OverlayColor));
+ newSurf->create(info.width, info.height, format);
assert(newSurf->pixels);
OverlayColor *curPixel = (OverlayColor*)newSurf->pixels + (newSurf->h-1) * newSurf->w;
int pitchAdd = info.width % 4;
diff --git a/graphics/jpeg.cpp b/graphics/jpeg.cpp
index 2d990b9b0e..f1dcd4ac0c 100644
--- a/graphics/jpeg.cpp
+++ b/graphics/jpeg.cpp
@@ -96,7 +96,7 @@ Surface *JPEG::getSurface(const PixelFormat &format) {
Graphics::Surface *vComponent = getComponent(3);
Graphics::Surface *output = new Graphics::Surface();
- output->create(yComponent->w, yComponent->h, format.bytesPerPixel);
+ output->create(yComponent->w, yComponent->h, format);
for (uint16 i = 0; i < output->h; i++) {
for (uint16 j = 0; j < output->w; j++) {
@@ -444,7 +444,7 @@ bool JPEG::readSOS() {
// Initialize the scan surfaces
for (uint16 c = 0; c < _numScanComp; c++) {
- _scanComp[c]->surface.create(xMCU * _maxFactorH * 8, yMCU * _maxFactorV * 8, 1);
+ _scanComp[c]->surface.create(xMCU * _maxFactorH * 8, yMCU * _maxFactorV * 8, PixelFormat::createFormatCLUT8());
}
bool ok = true;
diff --git a/graphics/pict.cpp b/graphics/pict.cpp
index b61b000acd..acade48515 100644
--- a/graphics/pict.cpp
+++ b/graphics/pict.cpp
@@ -212,7 +212,7 @@ void PictDecoder::decodeDirectBitsRect(Common::SeekableReadStream *stream, bool
bytesPerPixel = directBitsData.pixMap.pixelSize / 8;
_outputSurface = new Graphics::Surface();
- _outputSurface->create(width, height, (bytesPerPixel == 1) ? 1 : _pixelFormat.bytesPerPixel);
+ _outputSurface->create(width, height, (bytesPerPixel == 1) ? PixelFormat::createFormatCLUT8() : _pixelFormat);
byte *buffer = new byte[width * height * bytesPerPixel];
// Read in amount of data per row
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;
}
diff --git a/graphics/scaler/thumbnail_intern.cpp b/graphics/scaler/thumbnail_intern.cpp
index 4b460b29ce..d78648c325 100644
--- a/graphics/scaler/thumbnail_intern.cpp
+++ b/graphics/scaler/thumbnail_intern.cpp
@@ -100,12 +100,12 @@ static bool grabScreen565(Graphics::Surface *surf) {
if (!screen)
return false;
- assert(screen->bytesPerPixel == 1 || screen->bytesPerPixel == 2);
+ assert(screen->format.bytesPerPixel == 1 || screen->format.bytesPerPixel == 2);
assert(screen->pixels != 0);
Graphics::PixelFormat screenFormat = g_system->getScreenFormat();
- surf->create(screen->w, screen->h, 2);
+ surf->create(screen->w, screen->h, Graphics::PixelFormat(2, 5, 6, 5, 0, 11, 5, 0, 0));
byte *palette = 0;
if (screenFormat.bytesPerPixel == 1) {
@@ -147,7 +147,7 @@ static bool createThumbnail(Graphics::Surface &out, Graphics::Surface &in) {
// center MM NES screen
Graphics::Surface newscreen;
- newscreen.create(width, in.h, in.bytesPerPixel);
+ newscreen.create(width, in.h, in.format);
uint8 *dst = (uint8 *)newscreen.getBasePtr((320 - in.w) / 2, 0);
const uint8 *src = (const uint8 *)in.getBasePtr(0, 0);
@@ -172,13 +172,13 @@ static bool createThumbnail(Graphics::Surface &out, Graphics::Surface &in) {
// cut off menu and so on..
Graphics::Surface newscreen;
- newscreen.create(width, 400, in.bytesPerPixel);
+ newscreen.create(width, 400, in.format);
uint8 *dst = (uint8 *)newscreen.getBasePtr(0, (400 - 240) / 2);
const uint8 *src = (const uint8 *)in.getBasePtr(41, 28);
for (int y = 0; y < 240; ++y) {
- memcpy(dst, src, 640 * in.bytesPerPixel);
+ memcpy(dst, src, 640 * in.format.bytesPerPixel);
dst += newscreen.pitch;
src += in.pitch;
}
@@ -191,9 +191,9 @@ static bool createThumbnail(Graphics::Surface &out, Graphics::Surface &in) {
inHeight = 480;
Graphics::Surface newscreen;
- newscreen.create(width, 480, in.bytesPerPixel);
+ newscreen.create(width, 480, in.format);
- memcpy(newscreen.getBasePtr(0, 0), in.getBasePtr(0, 0), width * 440 * in.bytesPerPixel);
+ memcpy(newscreen.getBasePtr(0, 0), in.getBasePtr(0, 0), width * 440 * in.format.bytesPerPixel);
in.free();
in = newscreen;
@@ -201,7 +201,7 @@ static bool createThumbnail(Graphics::Surface &out, Graphics::Surface &in) {
uint16 newHeight = !(inHeight % 240) ? kThumbnailHeight2 : kThumbnailHeight1;
- out.create(kThumbnailWidth, newHeight, sizeof(uint16));
+ out.create(kThumbnailWidth, newHeight, Graphics::PixelFormat(2, 5, 6, 5, 0, 11, 5, 0, 0));
createThumbnail((const uint8 *)in.pixels, width * sizeof(uint16), (uint8 *)out.pixels, out.pitch, width, inHeight);
in.free();
@@ -224,7 +224,7 @@ bool createThumbnail(Graphics::Surface *surf, const uint8 *pixels, int w, int h,
assert(surf);
Graphics::Surface screen;
- screen.create(w, h, 2);
+ screen.create(w, h, Graphics::PixelFormat(2, 5, 6, 5, 0, 11, 5, 0, 0));
for (uint y = 0; y < screen.h; ++y) {
for (uint x = 0; x < screen.w; ++x) {
diff --git a/graphics/sjis.cpp b/graphics/sjis.cpp
index 13ea339375..caa53a4f63 100644
--- a/graphics/sjis.cpp
+++ b/graphics/sjis.cpp
@@ -58,7 +58,7 @@ FontSJIS *FontSJIS::createFont(const Common::Platform platform) {
}
void FontSJIS::drawChar(Graphics::Surface &dst, uint16 ch, int x, int y, uint32 c1, uint32 c2) const {
- drawChar(dst.getBasePtr(x, y), ch, dst.pitch, dst.bytesPerPixel, c1, c2, dst.w - x, dst.h - y);
+ drawChar(dst.getBasePtr(x, y), ch, dst.pitch, dst.format.bytesPerPixel, c1, c2, dst.w - x, dst.h - y);
}
template<typename Color>
diff --git a/graphics/surface.cpp b/graphics/surface.cpp
index 271e32fc0c..88bdcfc822 100644
--- a/graphics/surface.cpp
+++ b/graphics/surface.cpp
@@ -41,23 +41,23 @@ static void plotPoint(int x, int y, int color, void *data) {
}
void Surface::drawLine(int x0, int y0, int x1, int y1, uint32 color) {
- if (bytesPerPixel == 1)
+ if (format.bytesPerPixel == 1)
Graphics::drawLine(x0, y0, x1, y1, color, plotPoint<byte>, this);
- else if (bytesPerPixel == 2)
+ else if (format.bytesPerPixel == 2)
Graphics::drawLine(x0, y0, x1, y1, color, plotPoint<uint16>, this);
else
error("Surface::drawLine: bytesPerPixel must be 1 or 2");
}
-void Surface::create(uint16 width, uint16 height, uint8 bytesPP) {
+void Surface::create(uint16 width, uint16 height, const PixelFormat &f) {
free();
w = width;
h = height;
- bytesPerPixel = bytesPP;
- pitch = w * bytesPP;
+ format = f;
+ pitch = w * format.bytesPerPixel;
- pixels = calloc(width * height, bytesPP);
+ pixels = calloc(width * height, format.bytesPerPixel);
assert(pixels);
}
@@ -65,11 +65,11 @@ void Surface::free() {
::free(pixels);
pixels = 0;
w = h = pitch = 0;
- bytesPerPixel = 0;
+ format = PixelFormat();
}
void Surface::copyFrom(const Surface &surf) {
- create(surf.w, surf.h, surf.bytesPerPixel);
+ create(surf.w, surf.h, surf.format);
memcpy(pixels, surf.pixels, h * pitch);
}
@@ -89,10 +89,10 @@ void Surface::hLine(int x, int y, int x2, uint32 color) {
if (x2 < x)
return;
- if (bytesPerPixel == 1) {
+ if (format.bytesPerPixel == 1) {
byte *ptr = (byte *)getBasePtr(x, y);
memset(ptr, (byte)color, x2-x+1);
- } else if (bytesPerPixel == 2) {
+ } else if (format.bytesPerPixel == 2) {
uint16 *ptr = (uint16 *)getBasePtr(x, y);
Common::set_to(ptr, ptr + (x2-x+1), (uint16)color);
} else {
@@ -113,13 +113,13 @@ void Surface::vLine(int x, int y, int y2, uint32 color) {
if (y2 >= h)
y2 = h - 1;
- if (bytesPerPixel == 1) {
+ if (format.bytesPerPixel == 1) {
byte *ptr = (byte *)getBasePtr(x, y);
while (y++ <= y2) {
*ptr = (byte)color;
ptr += pitch;
}
- } else if (bytesPerPixel == 2) {
+ } else if (format.bytesPerPixel == 2) {
uint16 *ptr = (uint16 *)getBasePtr(x, y);
while (y++ <= y2) {
*ptr = (uint16)color;
@@ -141,13 +141,13 @@ void Surface::fillRect(Common::Rect r, uint32 color) {
int height = r.height();
bool useMemset = true;
- if (bytesPerPixel == 2) {
+ if (format.bytesPerPixel == 2) {
lineLen *= 2;
if ((uint16)color != ((color & 0xff) | (color & 0xff) << 8))
useMemset = false;
- } else if (bytesPerPixel == 4) {
+ } else if (format.bytesPerPixel == 4) {
useMemset = false;
- } else if (bytesPerPixel != 1) {
+ } else if (format.bytesPerPixel != 1) {
error("Surface::fillRect: bytesPerPixel must be 1, 2 or 4");
}
@@ -158,7 +158,7 @@ void Surface::fillRect(Common::Rect r, uint32 color) {
ptr += pitch;
}
} else {
- if (bytesPerPixel == 2) {
+ if (format.bytesPerPixel == 2) {
uint16 *ptr = (uint16 *)getBasePtr(r.left, r.top);
while (height--) {
Common::set_to(ptr, ptr + width, (uint16)color);
@@ -186,7 +186,7 @@ void Surface::move(int dx, int dy, int height) {
if ((dx == 0 && dy == 0) || height <= 0)
return;
- if (bytesPerPixel != 1 && bytesPerPixel != 2)
+ if (format.bytesPerPixel != 1 && format.bytesPerPixel != 2)
error("Surface::move: bytesPerPixel must be 1 or 2");
byte *src, *dst;
@@ -216,37 +216,37 @@ void Surface::move(int dx, int dy, int height) {
// horizontal movement
if (dx > 0) {
// move right - copy from right to left
- dst = (byte *)pixels + (pitch - bytesPerPixel);
- src = dst - (dx * bytesPerPixel);
+ dst = (byte *)pixels + (pitch - format.bytesPerPixel);
+ src = dst - (dx * format.bytesPerPixel);
for (y = 0; y < height; y++) {
for (x = dx; x < w; x++) {
- if (bytesPerPixel == 1) {
+ if (format.bytesPerPixel == 1) {
*dst-- = *src--;
- } else if (bytesPerPixel == 2) {
+ } else if (format.bytesPerPixel == 2) {
*(uint16 *)dst = *(const uint16 *)src;
src -= 2;
dst -= 2;
}
}
- src += pitch + (pitch - dx * bytesPerPixel);
- dst += pitch + (pitch - dx * bytesPerPixel);
+ src += pitch + (pitch - dx * format.bytesPerPixel);
+ dst += pitch + (pitch - dx * format.bytesPerPixel);
}
} else if (dx < 0) {
// move left - copy from left to right
dst = (byte *)pixels;
- src = dst - (dx * bytesPerPixel);
+ src = dst - (dx * format.bytesPerPixel);
for (y = 0; y < height; y++) {
for (x = -dx; x < w; x++) {
- if (bytesPerPixel == 1) {
+ if (format.bytesPerPixel == 1) {
*dst++ = *src++;
- } else if (bytesPerPixel == 2) {
+ } else if (format.bytesPerPixel == 2) {
*(uint16 *)dst = *(const uint16 *)src;
src += 2;
dst += 2;
}
}
- src += pitch - (pitch + dx * bytesPerPixel);
- dst += pitch - (pitch + dx * bytesPerPixel);
+ src += pitch - (pitch + dx * format.bytesPerPixel);
+ dst += pitch - (pitch + dx * format.bytesPerPixel);
}
}
}
diff --git a/graphics/surface.h b/graphics/surface.h
index 92c7b7e899..1b54690aa9 100644
--- a/graphics/surface.h
+++ b/graphics/surface.h
@@ -31,6 +31,8 @@ namespace Common {
struct Rect;
}
+#include "graphics/pixelformat.h"
+
namespace Graphics {
/**
@@ -68,14 +70,14 @@ struct Surface {
void *pixels;
/**
- * How many bytes a single pixel occupies.
+ * The pixel format of the surface.
*/
- uint8 bytesPerPixel;
+ PixelFormat format;
/**
* Construct a simple Surface object.
*/
- Surface() : w(0), h(0), pitch(0), pixels(0), bytesPerPixel(0) {
+ Surface() : w(0), h(0), pitch(0), pixels(0), format() {
}
/**
@@ -86,7 +88,7 @@ struct Surface {
* @return Pointer to the pixel.
*/
inline const void *getBasePtr(int x, int y) const {
- return (const byte *)(pixels) + y * pitch + x * bytesPerPixel;
+ return (const byte *)(pixels) + y * pitch + x * format.bytesPerPixel;
}
/**
@@ -97,7 +99,7 @@ struct Surface {
* @return Pointer to the pixel.
*/
inline void *getBasePtr(int x, int y) {
- return static_cast<byte *>(pixels) + y * pitch + x * bytesPerPixel;
+ return static_cast<byte *>(pixels) + y * pitch + x * format.bytesPerPixel;
}
/**
@@ -108,9 +110,9 @@ struct Surface {
*
* @param width Width of the surface object.
* @param height Height of the surface object.
- * @param bytePP The number of bytes a single pixel uses.
+ * @param format The pixel format the surface should use.
*/
- void create(uint16 width, uint16 height, uint8 bytesPP);
+ void create(uint16 width, uint16 height, const PixelFormat &format);
/**
* Release the memory used by the pixels memory of this surface. This is the
diff --git a/graphics/thumbnail.cpp b/graphics/thumbnail.cpp
index fa906ca517..32ab04ed24 100644
--- a/graphics/thumbnail.cpp
+++ b/graphics/thumbnail.cpp
@@ -108,10 +108,10 @@ bool loadThumbnail(Common::SeekableReadStream &in, Graphics::Surface &to) {
return false;
}
- to.create(header.width, header.height, sizeof(OverlayColor));
+ Graphics::PixelFormat format = g_system->getOverlayFormat();
+ to.create(header.width, header.height, format);
OverlayColor *pixels = (OverlayColor *)to.pixels;
- Graphics::PixelFormat format = g_system->getOverlayFormat();
for (int y = 0; y < to.h; ++y) {
for (int x = 0; x < to.w; ++x) {
uint8 r, g, b;
@@ -140,18 +140,18 @@ bool saveThumbnail(Common::WriteStream &out) {
}
bool saveThumbnail(Common::WriteStream &out, const Graphics::Surface &thumb) {
- if (thumb.bytesPerPixel != 2) {
+ if (thumb.format.bytesPerPixel != 2) {
warning("trying to save thumbnail with bpp different than 2");
return false;
}
ThumbnailHeader header;
header.type = MKTAG('T','H','M','B');
- header.size = ThumbnailHeaderSize + thumb.w*thumb.h*thumb.bytesPerPixel;
+ header.size = ThumbnailHeaderSize + thumb.w*thumb.h*thumb.format.bytesPerPixel;
header.version = THMB_VERSION;
header.width = thumb.w;
header.height = thumb.h;
- header.bpp = thumb.bytesPerPixel;
+ header.bpp = thumb.format.bytesPerPixel;
out.writeUint32BE(header.type);
out.writeUint32BE(header.size);