TINYGL: Expect colorKey in the same pixel format as surface.

So caller does not have to depend on the pixel format used internally to
BlitImage.
Update callers which do request for color keying (GRIM/EMI only).
Also, remove a special-casing of transparent color when converting image
format which sets a color in a packed format independent from actual
destination format.
Also, in GfxTinyGL::createTextObject, prefer changing invisible colorKey
value than actually-visible color.
This commit is contained in:
Vincent Pelletier 2016-07-21 16:17:32 +02:00
parent 31517c227c
commit 7c1a15c6e8
3 changed files with 11 additions and 18 deletions

View file

@ -481,11 +481,7 @@ void BitmapData::convertToColorFormat(int num, const Graphics::PixelFormat &form
Graphics::PixelBuffer dst(format, _width * _height, DisposeAfterUse::NO);
for (int i = 0; i < _width * _height; ++i) {
if (_data[num].getValueAt(i) == 0xf81f) { //transparency
dst.setPixelAt(i, 0xf81f);
} else {
dst.setPixelAt(i, _data[num]);
}
dst.setPixelAt(i, _data[num]);
}
_data[num].free();
_data[num] = dst;

View file

@ -943,6 +943,7 @@ void GfxTinyGL::turnOffLight(int lightId) {
}
void GfxTinyGL::createBitmap(BitmapData *bitmap) {
const int colorKeyValue = _pixelFormat.ARGBToColor(0, 255, 0, 255);
if (bitmap->_format == 1) {
bitmap->convertToColorFormat(_pixelFormat);
}
@ -975,7 +976,6 @@ void GfxTinyGL::createBitmap(BitmapData *bitmap) {
Graphics::tglUploadBlitImage(imgs[pic], sourceSurface, 0, false);
}
} else {
const int colorKeyValue = 0xFFFF00FF;
for (int i = 0; i < bitmap->_numImages; ++i) {
imgs[i] = Graphics::tglGenBlitImage();
const Graphics::PixelBuffer &imageBuffer = bitmap->getImageData(i);
@ -1076,6 +1076,12 @@ void GfxTinyGL::createTextObject(TextObject *text) {
const Color &fgColor = text->getFGColor();
TextObjectData *userData = new TextObjectData[numLines];
text->setUserData(userData);
uint32 kKitmapColorkey = _pixelFormat.RGBToColor(0, 255, 0);
const uint32 blackColor = _pixelFormat.RGBToColor(0, 0, 0);
const uint32 color = _pixelFormat.RGBToColor(fgColor.getRed(), fgColor.getGreen(), fgColor.getBlue());
while (color == kKitmapColorkey || blackColor == kKitmapColorkey) {
kKitmapColorkey += 1;
}
for (int j = 0; j < numLines; j++) {
const Common::String &currentLine = lines[j];
@ -1109,21 +1115,14 @@ void GfxTinyGL::createTextObject(TextObject *text) {
Graphics::PixelBuffer buf(_pixelFormat, width * height, DisposeAfterUse::YES);
uint8 *bitmapData = _textBitmap;
uint8 r = fgColor.getRed();
uint8 g = fgColor.getGreen();
uint8 b = fgColor.getBlue();
uint32 color = _zb->cmode.RGBToColor(r, g, b);
if (color == 0xf81f)
color = 0xf81e;
int txData = 0;
for (int i = 0; i < width * height; i++, txData++, bitmapData++) {
byte pixel = *bitmapData;
if (pixel == 0x00) {
buf.setPixelAt(txData, 0xf81f);
buf.setPixelAt(txData, kKitmapColorkey);
} else if (pixel == 0x80) {
buf.setPixelAt(txData, 0);
buf.setPixelAt(txData, blackColor);
} else if (pixel == 0xFF) {
buf.setPixelAt(txData, color);
}
@ -1132,8 +1131,6 @@ void GfxTinyGL::createTextObject(TextObject *text) {
userData[j].width = width;
userData[j].height = height;
const int kKitmapColorkey = 0xFFFF00FF;
Graphics::Surface sourceSurface;
sourceSurface.setPixels(buf.getRawBuffer());
sourceSurface.format = buf.getFormat();

View file

@ -52,7 +52,7 @@ public:
if (applyColorKey) {
for (int x = 0; x < surface.w; x++) {
for (int y = 0; y < surface.h; y++) {
uint32 pixel = dataBuffer.getValueAt(y * surface.w + x);
uint32 pixel = buffer.getValueAt(y * surface.w + x);
if (pixel == colorKey) {
// Color keyed pixels become transparent white.
dataBuffer.setPixelAt(y * surface.w + x, 0, 255, 255, 255);