1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597
|
/* ScummVM - Graphic Adventure Engine
*
* ScummVM is the legal property of its developers, whose names
* are too numerous to list here. Please refer to the COPYRIGHT
* file distributed with this source distribution.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
*/
#include "graphics/managed_surface.h"
#include "common/algorithm.h"
#include "common/textconsole.h"
namespace Graphics {
const int SCALE_THRESHOLD = 0x100;
ManagedSurface::ManagedSurface() :
w(_innerSurface.w), h(_innerSurface.h), pitch(_innerSurface.pitch), format(_innerSurface.format),
_disposeAfterUse(DisposeAfterUse::NO), _owner(nullptr),
_transparentColor(0),_transparentColorSet(false), _paletteSet(false) {
Common::fill(&_palette[0], &_palette[256], 0);
}
ManagedSurface::ManagedSurface(const ManagedSurface &surf) :
w(_innerSurface.w), h(_innerSurface.h), pitch(_innerSurface.pitch), format(_innerSurface.format),
_disposeAfterUse(DisposeAfterUse::NO), _owner(nullptr),
_transparentColor(0), _transparentColorSet(false), _paletteSet(false) {
Common::fill(&_palette[0], &_palette[256], 0);
*this = surf;
}
ManagedSurface::ManagedSurface(int width, int height) :
w(_innerSurface.w), h(_innerSurface.h), pitch(_innerSurface.pitch), format(_innerSurface.format),
_disposeAfterUse(DisposeAfterUse::NO), _owner(nullptr),
_transparentColor(0), _transparentColorSet(false), _paletteSet(false) {
Common::fill(&_palette[0], &_palette[256], 0);
create(width, height);
}
ManagedSurface::ManagedSurface(int width, int height, const Graphics::PixelFormat &pixelFormat) :
w(_innerSurface.w), h(_innerSurface.h), pitch(_innerSurface.pitch), format(_innerSurface.format),
_disposeAfterUse(DisposeAfterUse::NO), _owner(nullptr),
_transparentColor(0), _transparentColorSet(false), _paletteSet(false) {
Common::fill(&_palette[0], &_palette[256], 0);
create(width, height, pixelFormat);
}
ManagedSurface::ManagedSurface(ManagedSurface &surf, const Common::Rect &bounds) :
w(_innerSurface.w), h(_innerSurface.h), pitch(_innerSurface.pitch), format(_innerSurface.format),
_disposeAfterUse(DisposeAfterUse::NO), _owner(nullptr),
_transparentColor(0), _transparentColorSet(false), _paletteSet(false) {
Common::fill(&_palette[0], &_palette[256], 0);
create(surf, bounds);
}
ManagedSurface::~ManagedSurface() {
free();
}
ManagedSurface &ManagedSurface::operator=(const ManagedSurface &surf) {
// Free any current surface
free();
if (surf._disposeAfterUse == DisposeAfterUse::YES) {
// Create a new surface and copy the pixels from the source surface
create(surf.w, surf.h, surf.format);
Common::copy((const byte *)surf.getPixels(), (const byte *)surf.getPixels() +
surf.w * surf.h * surf.format.bytesPerPixel, (byte *)this->getPixels());
} else {
// Source isn't managed, so simply copy its fields
_owner = surf._owner;
_offsetFromOwner = surf._offsetFromOwner;
void *srcPixels = const_cast<void *>(surf._innerSurface.getPixels());
_innerSurface.setPixels(srcPixels);
_innerSurface.w = surf.w;
_innerSurface.h = surf.h;
_innerSurface.pitch = surf.pitch;
this->format = surf.format;
// Copy miscellaneous properties
_transparentColorSet = surf._transparentColorSet;
_transparentColor = surf._transparentColor;
_paletteSet = surf._paletteSet;
Common::copy(&surf._palette[0], &surf._palette[256], _palette);
}
return *this;
}
void ManagedSurface::setPixels(void *newPixels) {
free();
_innerSurface.setPixels(newPixels);
}
void ManagedSurface::create(uint16 width, uint16 height) {
create(width, height, PixelFormat::createFormatCLUT8());
}
void ManagedSurface::create(uint16 width, uint16 height, const PixelFormat &pixelFormat) {
free();
_innerSurface.create(width, height, pixelFormat);
_disposeAfterUse = DisposeAfterUse::YES;
markAllDirty();
}
void ManagedSurface::create(ManagedSurface &surf, const Common::Rect &bounds) {
free();
_offsetFromOwner = Common::Point(bounds.left, bounds.top);
_innerSurface.setPixels(surf.getBasePtr(bounds.left, bounds.top));
_innerSurface.pitch = surf.pitch;
_innerSurface.format = surf.format;
_innerSurface.w = bounds.width();
_innerSurface.h = bounds.height();
_owner = &surf;
_disposeAfterUse = DisposeAfterUse::NO;
// Copy miscellaneous properties
_transparentColorSet = surf._transparentColorSet;
_transparentColor = surf._transparentColor;
_paletteSet = surf._paletteSet;
Common::copy(&surf._palette[0], &surf._palette[256], _palette);
}
void ManagedSurface::free() {
if (_disposeAfterUse == DisposeAfterUse::YES)
_innerSurface.free();
_disposeAfterUse = DisposeAfterUse::NO;
_owner = nullptr;
_offsetFromOwner = Common::Point(0, 0);
_transparentColorSet = false;
_paletteSet = false;
}
void ManagedSurface::copyFrom(const ManagedSurface &surf) {
// Surface::copyFrom frees pixel pointer so let's free up ManagedSurface to be coherent
free();
// Copy the surface
_innerSurface.copyFrom(surf._innerSurface);
markAllDirty();
// Pixels data is now owned by us
_disposeAfterUse = DisposeAfterUse::YES;
// Copy miscellaneous properties
_transparentColorSet = surf._transparentColorSet;
_transparentColor = surf._transparentColor;
_paletteSet = surf._paletteSet;
Common::copy(&surf._palette[0], &surf._palette[256], _palette);
}
bool ManagedSurface::clip(Common::Rect &srcBounds, Common::Rect &destBounds) {
if (destBounds.left >= this->w || destBounds.top >= this->h ||
destBounds.right <= 0 || destBounds.bottom <= 0)
return false;
// Clip the bounds if necessary to fit on-screen
if (destBounds.right > this->w) {
srcBounds.right -= destBounds.right - this->w;
destBounds.right = this->w;
}
if (destBounds.bottom > this->h) {
srcBounds.bottom -= destBounds.bottom - this->h;
destBounds.bottom = this->h;
}
if (destBounds.top < 0) {
srcBounds.top += -destBounds.top;
destBounds.top = 0;
}
if (destBounds.left < 0) {
srcBounds.left += -destBounds.left;
destBounds.left = 0;
}
return true;
}
void ManagedSurface::blitFrom(const Surface &src) {
blitFrom(src, Common::Rect(0, 0, src.w, src.h), Common::Point(0, 0));
}
void ManagedSurface::blitFrom(const Surface &src, const Common::Point &destPos) {
blitFrom(src, Common::Rect(0, 0, src.w, src.h), destPos);
}
void ManagedSurface::blitFrom(const Surface &src, const Common::Rect &srcRect,
const Common::Point &destPos) {
blitFromInner(src, srcRect, destPos, nullptr);
}
void ManagedSurface::blitFrom(const ManagedSurface &src) {
blitFrom(src, Common::Rect(0, 0, src.w, src.h), Common::Point(0, 0));
}
void ManagedSurface::blitFrom(const ManagedSurface &src, const Common::Point &destPos) {
blitFrom(src, Common::Rect(0, 0, src.w, src.h), destPos);
}
void ManagedSurface::blitFrom(const ManagedSurface &src, const Common::Rect &srcRect,
const Common::Point &destPos) {
if (src._transparentColorSet)
transBlitFrom(src, srcRect, destPos);
else
blitFromInner(src._innerSurface, srcRect, destPos, src._paletteSet ? &src._palette[0] : nullptr);
}
void ManagedSurface::blitFromInner(const Surface &src, const Common::Rect &srcRect,
const Common::Point &destPos, const uint32 *palette) {
Common::Rect srcBounds = srcRect;
Common::Rect destBounds(destPos.x, destPos.y, destPos.x + srcRect.width(),
destPos.y + srcRect.height());
uint destPixel;
byte rSrc, gSrc, bSrc, aSrc;
byte rDest = 0, gDest = 0, bDest = 0;
double alpha;
if (!srcRect.isValidRect() || !clip(srcBounds, destBounds))
return;
if (format != src.format) {
// When the pixel format differs, the destination must be 2 or 4 bytes per pixel,
// and the source be 2/4 bytes as well or be paletted
assert(format.bytesPerPixel == 2 || format.bytesPerPixel == 4);
assert(src.format.bytesPerPixel == 2 || src.format.bytesPerPixel == 4
|| (src.format.bytesPerPixel == 1 && palette));
}
for (int y = 0; y < srcBounds.height(); ++y) {
const byte *srcP = (const byte *)src.getBasePtr(srcBounds.left, srcBounds.top + y);
byte *destP = (byte *)getBasePtr(destBounds.left, destBounds.top + y);
if (src.format == format) {
// Matching surface formats, so we can do a straight copy
Common::copy(srcP, srcP + srcBounds.width() * format.bytesPerPixel, destP);
} else {
for (int x = 0; x < srcBounds.width(); ++x,
srcP += src.format.bytesPerPixel,
destP += format.bytesPerPixel) {
if (src.format.bytesPerPixel == 1) {
// Get the palette color
const uint32 col = palette[*srcP];
rSrc = col & 0xff;
gSrc = (col >> 8) & 0xff;
bSrc = (col >> 16) & 0xff;
aSrc = (col >> 24) & 0xff;
} else {
// Use the src's pixel format to split up the source pixel
src.format.colorToARGB(src.format.bytesPerPixel == 2
? *(const uint16 *)srcP : *(const uint32 *)srcP,
aSrc, rSrc, gSrc, bSrc);
}
if (aSrc == 0) {
// Completely transparent, so skip
continue;
} else if (aSrc == 0xff) {
// Completely opaque, so copy RGB values over
rDest = rSrc;
gDest = gSrc;
bDest = bSrc;
} else {
// Partially transparent, so calculate new pixel colors
alpha = (double)aSrc / 255.0;
rDest = static_cast<byte>((rSrc * alpha) + (rDest * (1.0 - alpha)));
gDest = static_cast<byte>((gSrc * alpha) + (gDest * (1.0 - alpha)));
bDest = static_cast<byte>((bSrc * alpha) + (bDest * (1.0 - alpha)));
}
destPixel = format.ARGBToColor(0xff, rDest, gDest, bDest);
if (format.bytesPerPixel == 2)
*(uint16 *)destP = destPixel;
else
*(uint32 *)destP = destPixel;
}
}
}
addDirtyRect(Common::Rect(0, 0, this->w, this->h));
}
void ManagedSurface::transBlitFrom(const Surface &src, uint transColor, bool flipped,
uint overrideColor, uint srcAlpha) {
transBlitFrom(src, Common::Rect(0, 0, src.w, src.h), Common::Rect(0, 0, this->w, this->h),
transColor, flipped, overrideColor, srcAlpha);
}
void ManagedSurface::transBlitFrom(const Surface &src, const Common::Point &destPos,
uint transColor, bool flipped, uint overrideColor, uint srcAlpha) {
transBlitFrom(src, Common::Rect(0, 0, src.w, src.h), Common::Rect(destPos.x, destPos.y,
destPos.x + src.w, destPos.y + src.h), transColor, flipped, overrideColor, srcAlpha);
}
void ManagedSurface::transBlitFrom(const Surface &src, const Common::Point &destPos,
const ManagedSurface &mask) {
transBlitFrom(src, Common::Rect(0, 0, src.w, src.h), Common::Rect(destPos.x, destPos.y,
destPos.x + src.w, destPos.y + src.h), 0, false, 0, 0xff, &mask._innerSurface, true);
}
void ManagedSurface::transBlitFrom(const Surface &src, const Common::Point &destPos,
const Surface &mask) {
transBlitFrom(src, Common::Rect(0, 0, src.w, src.h), Common::Rect(destPos.x, destPos.y,
destPos.x + src.w, destPos.y + src.h), 0, false, 0, 0xff, &mask, true);
}
void ManagedSurface::transBlitFrom(const Surface &src, const Common::Rect &srcRect,
const Common::Point &destPos, uint transColor, bool flipped, uint overrideColor, uint srcAlpha) {
transBlitFrom(src, srcRect, Common::Rect(destPos.x, destPos.y,
destPos.x + srcRect.width(), destPos.y + srcRect.height()), transColor, flipped, overrideColor, srcAlpha);
}
void ManagedSurface::transBlitFrom(const Surface &src, const Common::Rect &srcRect,
const Common::Rect &destRect, uint transColor, bool flipped, uint overrideColor, uint srcAlpha,
const Surface *mask, bool maskOnly) {
transBlitFromInner(src, srcRect, destRect, transColor, flipped, overrideColor, srcAlpha,
nullptr, nullptr, mask, maskOnly);
}
void ManagedSurface::transBlitFrom(const ManagedSurface &src, uint transColor, bool flipped,
uint overrideColor, uint srcAlpha) {
transBlitFrom(src, Common::Rect(0, 0, src.w, src.h), Common::Rect(0, 0, this->w, this->h),
transColor, flipped, overrideColor, srcAlpha);
}
void ManagedSurface::transBlitFrom(const ManagedSurface &src, const Common::Point &destPos,
uint transColor, bool flipped, uint overrideColor, uint srcAlpha) {
transBlitFrom(src, Common::Rect(0, 0, src.w, src.h), Common::Rect(destPos.x, destPos.y,
destPos.x + src.w, destPos.y + src.h), transColor, flipped, overrideColor, srcAlpha);
}
void ManagedSurface::transBlitFrom(const ManagedSurface &src, const Common::Point &destPos,
const ManagedSurface &mask) {
transBlitFrom(src, Common::Rect(0, 0, src.w, src.h), Common::Rect(destPos.x, destPos.y,
destPos.x + src.w, destPos.y + src.h), 0, false, 0, 0xff, &mask._innerSurface, true);
}
void ManagedSurface::transBlitFrom(const ManagedSurface &src, const Common::Rect &srcRect,
const Common::Point &destPos, uint transColor, bool flipped, uint overrideColor, uint srcAlpha) {
uint tColor = !transColor && src._transparentColorSet ? src._transparentColor : transColor;
transBlitFrom(src, srcRect, Common::Rect(destPos.x, destPos.y, destPos.x + srcRect.width(),
destPos.y + srcRect.height()), tColor, flipped, overrideColor, srcAlpha);
}
void ManagedSurface::transBlitFrom(const ManagedSurface &src, const Common::Rect &srcRect,
const Common::Rect &destRect, uint transColor, bool flipped, uint overrideColor, uint srcAlpha,
const Surface *mask, bool maskOnly) {
if (transColor == (uint)-1 && src._transparentColorSet)
transColor = src._transparentColor;
const uint32 *srcPalette = src._paletteSet ? src._palette : nullptr;
const uint32 *dstPalette = _paletteSet ? _palette : nullptr;
transBlitFromInner(src._innerSurface, srcRect, destRect, transColor, flipped, overrideColor,
srcAlpha, srcPalette, dstPalette, mask, maskOnly);
}
static uint findBestColor(const uint32 *palette, byte cr, byte cg, byte cb) {
uint bestColor = 0;
double min = 0xFFFFFFFF;
for (uint i = 0; i < 256; ++i) {
uint col = palette[i];
int rmean = ((col & 0xff) + cr) / 2;
int r = (col & 0xff) - cr;
int g = ((col >> 8) & 0xff) - cg;
int b = ((col >> 16) & 0xff) - cb;
double dist = sqrt((((512 + rmean) * r * r) >> 8) + 4 * g * g + (((767 - rmean) * b * b) >> 8));
if (min > dist) {
bestColor = i;
min = dist;
}
}
return bestColor;
}
static byte *createPaletteLookup(const uint32 *srcPalette, const uint32 *dstPalette) {
byte *lookup = new byte[256];
for (int i = 0; i < 256; i++) {
uint col = srcPalette[i];
if (col == dstPalette[i]) {
lookup[i] = i;
} else {
lookup[i] = findBestColor(dstPalette, col & 0xff, (col >> 8) & 0xff, (col >> 16) & 0xff);
}
}
return lookup;
}
template<typename TSRC, typename TDEST>
void transBlitPixel(TSRC srcVal, TDEST &destVal, const Graphics::PixelFormat &srcFormat, const Graphics::PixelFormat &destFormat,
uint overrideColor, uint srcAlpha, const uint32 *srcPalette, const byte *lookup) {
if (srcFormat == destFormat && srcAlpha == 0xff) {
// Matching formats, so we can do a straight copy
destVal = overrideColor ? overrideColor : srcVal;
return;
}
// Otherwise we have to manually decode and re-encode each pixel
byte aSrc, rSrc, gSrc, bSrc;
if (srcFormat.bytesPerPixel == 1) {
assert(srcPalette != nullptr); // Catch the cases when palette is missing
// Get the palette color
const uint32 col = srcPalette[srcVal];
rSrc = col & 0xff;
gSrc = (col >> 8) & 0xff;
bSrc = (col >> 16) & 0xff;
aSrc = (col >> 24) & 0xff;
} else {
srcFormat.colorToARGB(srcVal, aSrc, rSrc, gSrc, bSrc);
}
byte rDest, gDest, bDest;
destFormat.colorToRGB(destVal, rDest, gDest, bDest);
if (srcAlpha != 0xff) {
aSrc = aSrc * srcAlpha / 255;
}
if (aSrc == 0) {
// Completely transparent, so skip
return;
} else if (aSrc == 0xff) {
// Completely opaque, so copy RGB values over
rDest = rSrc;
gDest = gSrc;
bDest = bSrc;
} else {
// Partially transparent, so calculate new pixel colors
double alpha = (double)aSrc / 255.0;
rDest = static_cast<byte>((rSrc * alpha) + (rDest * (1.0 - alpha)));
gDest = static_cast<byte>((gSrc * alpha) + (gDest * (1.0 - alpha)));
bDest = static_cast<byte>((bSrc * alpha) + (bDest * (1.0 - alpha)));
}
destVal = destFormat.ARGBToColor(0xff, rDest, gDest, bDest);
}
template<>
void transBlitPixel<byte, byte>(byte srcVal, byte &destVal, const Graphics::PixelFormat &srcFormat, const Graphics::PixelFormat &destFormat,
uint overrideColor, uint srcAlpha, const uint32 *srcPalette, const byte *lookup) {
if (srcAlpha == 0) {
// Completely transparent, so skip
return;
}
destVal = overrideColor ? overrideColor : srcVal;
if (lookup)
destVal = lookup[destVal];
}
template<typename TSRC, typename TDEST>
void transBlit(const Surface &src, const Common::Rect &srcRect, Surface &dest, const Common::Rect &destRect,
TSRC transColor, bool flipped, uint overrideColor, uint srcAlpha, const uint32 *srcPalette,
const uint32 *dstPalette, const Surface *mask, bool maskOnly) {
int scaleX = SCALE_THRESHOLD * srcRect.width() / destRect.width();
int scaleY = SCALE_THRESHOLD * srcRect.height() / destRect.height();
byte *lookup = nullptr;
if (srcPalette && dstPalette)
lookup = createPaletteLookup(srcPalette, dstPalette);
// Loop through drawing output lines
for (int destY = destRect.top, scaleYCtr = 0; destY < destRect.bottom; ++destY, scaleYCtr += scaleY) {
if (destY < 0 || destY >= dest.h)
continue;
const TSRC *srcLine = (const TSRC *)src.getBasePtr(srcRect.left, scaleYCtr / SCALE_THRESHOLD + srcRect.top);
const TSRC *mskLine = nullptr;
if (mask)
mskLine = (const TSRC *)mask->getBasePtr(srcRect.left, scaleYCtr / SCALE_THRESHOLD + srcRect.top);
TDEST *destLine = (TDEST *)dest.getBasePtr(destRect.left, destY);
// Loop through drawing the pixels of the row
for (int destX = destRect.left, xCtr = 0, scaleXCtr = 0; destX < destRect.right; ++destX, ++xCtr, scaleXCtr += scaleX) {
if (destX < 0 || destX >= dest.w)
continue;
TSRC srcVal = srcLine[flipped ? src.w - scaleXCtr / SCALE_THRESHOLD - 1 : scaleXCtr / SCALE_THRESHOLD];
if (srcVal == transColor && !maskOnly)
continue;
if (mask) {
TSRC mskVal = mskLine[flipped ? src.w - scaleXCtr / SCALE_THRESHOLD - 1 : scaleXCtr / SCALE_THRESHOLD];
if (!mskVal)
continue;
transBlitPixel<TSRC, TDEST>(srcVal, destLine[xCtr], src.format, dest.format, overrideColor, mskVal, srcPalette, lookup);
} else {
transBlitPixel<TSRC, TDEST>(srcVal, destLine[xCtr], src.format, dest.format, overrideColor, srcAlpha, srcPalette, lookup);
}
}
}
delete[] lookup;
}
#define HANDLE_BLIT(SRC_BYTES, DEST_BYTES, SRC_TYPE, DEST_TYPE) \
if (src.format.bytesPerPixel == SRC_BYTES && format.bytesPerPixel == DEST_BYTES) \
transBlit<SRC_TYPE, DEST_TYPE>(src, srcRect, _innerSurface, destRect, transColor, flipped, overrideColor, srcAlpha, srcPalette, dstPalette, mask, maskOnly); \
else
void ManagedSurface::transBlitFromInner(const Surface &src, const Common::Rect &srcRect,
const Common::Rect &destRect, uint transColor, bool flipped, uint overrideColor,
uint srcAlpha, const uint32 *srcPalette, const uint32 *dstPalette, const Surface *mask, bool maskOnly) {
if (src.w == 0 || src.h == 0 || destRect.width() == 0 || destRect.height() == 0)
return;
if (mask) {
if (mask->w != src.w || mask->h != src.h)
error("Surface::transBlitFrom: mask dimensions do not match src");
}
HANDLE_BLIT(1, 1, byte, byte)
HANDLE_BLIT(1, 2, byte, uint16)
HANDLE_BLIT(1, 4, byte, uint32)
HANDLE_BLIT(2, 2, uint16, uint16)
HANDLE_BLIT(4, 4, uint32, uint32)
HANDLE_BLIT(2, 4, uint16, uint32)
HANDLE_BLIT(4, 2, uint32, uint16)
error("Surface::transBlitFrom: bytesPerPixel must be 1, 2, or 4");
// Mark the affected area
addDirtyRect(destRect);
}
#undef HANDLE_BLIT
void ManagedSurface::markAllDirty() {
addDirtyRect(Common::Rect(0, 0, this->w, this->h));
}
void ManagedSurface::addDirtyRect(const Common::Rect &r) {
if (_owner) {
Common::Rect bounds = r;
bounds.clip(Common::Rect(0, 0, this->w, this->h));
bounds.translate(_offsetFromOwner.x, _offsetFromOwner.y);
_owner->addDirtyRect(bounds);
}
}
void ManagedSurface::clear(uint color) {
if (!empty())
fillRect(getBounds(), color);
}
void ManagedSurface::setPalette(const byte *colors, uint start, uint num) {
assert(start < 256 && (start + num) <= 256);
uint32 *dest = &_palette[start];
for (; num > 0; --num, colors += 3) {
*dest++ = colors[0] | (colors[1] << 8) | (colors[2] << 16) | (0xff << 24);
}
_paletteSet = true;
if (_owner)
_owner->setPalette(colors, start, num);
}
void ManagedSurface::setPalette(const uint32 *colors, uint start, uint num) {
assert(start < 256 && (start + num) <= 256);
Common::copy(colors, colors + num, &_palette[start]);
_paletteSet = true;
if (_owner)
_owner->setPalette(colors, start, num);
}
} // End of namespace Graphics
|