aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTobia Tesan2016-03-31 10:16:19 +0200
committerTobia Tesan2016-12-26 12:28:51 +0100
commitc6ed1625f0027700964feb9c081efa20cbffd8cb (patch)
tree148d35c5d29c5aaf5c490241ec52873f8fc20d54
parent42531fb71a3710e190f933c347110e7a468c28e6 (diff)
downloadscummvm-rg350-c6ed1625f0027700964feb9c081efa20cbffd8cb.tar.gz
scummvm-rg350-c6ed1625f0027700964feb9c081efa20cbffd8cb.tar.bz2
scummvm-rg350-c6ed1625f0027700964feb9c081efa20cbffd8cb.zip
WINTERMUTE: Add TFilteringMode to transparent_surface.h
-rw-r--r--graphics/transparent_surface.cpp382
-rw-r--r--graphics/transparent_surface.h10
2 files changed, 208 insertions, 184 deletions
diff --git a/graphics/transparent_surface.cpp b/graphics/transparent_surface.cpp
index 7ef7d00286..2a5decf4e2 100644
--- a/graphics/transparent_surface.cpp
+++ b/graphics/transparent_surface.cpp
@@ -37,8 +37,6 @@
#include "graphics/transparent_surface.h"
#include "graphics/transform_tools.h"
-//#define ENABLE_BILINEAR
-
namespace Graphics {
static const int kBModShift = 0;//img->format.bShift;
@@ -677,6 +675,7 @@ systems.
+template <TFilteringMode filteringMode>
TransparentSurface *TransparentSurface::rotoscale(const TransformStruct &transform) const {
assert(transform._angle != 0); // This would not be ideal; rotoscale() should never be called in conditional branches where angle = 0 anyway.
@@ -739,50 +738,50 @@ TransparentSurface *TransparentSurface::rotoscale(const TransformStruct &transfo
dy = sh - dy;
}
-#ifdef ENABLE_BILINEAR
- if ((dx > -1) && (dy > -1) && (dx < sw) && (dy < sh)) {
- const tColorRGBA *sp = (const tColorRGBA *)getBasePtr(dx, dy);
- tColorRGBA c00, c01, c10, c11, cswap;
- c00 = *sp;
- sp += 1;
- c01 = *sp;
- sp += (this->pitch / 4);
- c11 = *sp;
- sp -= 1;
- c10 = *sp;
- if (flipx) {
- cswap = c00; c00=c01; c01=cswap;
- cswap = c10; c10=c11; c11=cswap;
+ if (filteringMode == FILTER_BILINEAR) {
+ if ((dx > -1) && (dy > -1) && (dx < sw) && (dy < sh)) {
+ const tColorRGBA *sp = (const tColorRGBA *)getBasePtr(dx, dy);
+ tColorRGBA c00, c01, c10, c11, cswap;
+ c00 = *sp;
+ sp += 1;
+ c01 = *sp;
+ sp += (this->pitch / 4);
+ c11 = *sp;
+ sp -= 1;
+ c10 = *sp;
+ if (flipx) {
+ cswap = c00; c00=c01; c01=cswap;
+ cswap = c10; c10=c11; c11=cswap;
+ }
+ if (flipy) {
+ cswap = c00; c00=c10; c10=cswap;
+ cswap = c01; c01=c11; c11=cswap;
+ }
+ /*
+ * Interpolate colors
+ */
+ int ex = (sdx & 0xffff);
+ int ey = (sdy & 0xffff);
+ int t1, t2;
+ t1 = ((((c01.r - c00.r) * ex) >> 16) + c00.r) & 0xff;
+ t2 = ((((c11.r - c10.r) * ex) >> 16) + c10.r) & 0xff;
+ pc->r = (((t2 - t1) * ey) >> 16) + t1;
+ t1 = ((((c01.g - c00.g) * ex) >> 16) + c00.g) & 0xff;
+ t2 = ((((c11.g - c10.g) * ex) >> 16) + c10.g) & 0xff;
+ pc->g = (((t2 - t1) * ey) >> 16) + t1;
+ t1 = ((((c01.b - c00.b) * ex) >> 16) + c00.b) & 0xff;
+ t2 = ((((c11.b - c10.b) * ex) >> 16) + c10.b) & 0xff;
+ pc->b = (((t2 - t1) * ey) >> 16) + t1;
+ t1 = ((((c01.a - c00.a) * ex) >> 16) + c00.a) & 0xff;
+ t2 = ((((c11.a - c10.a) * ex) >> 16) + c10.a) & 0xff;
+ pc->a = (((t2 - t1) * ey) >> 16) + t1;
}
- if (flipy) {
- cswap = c00; c00=c10; c10=cswap;
- cswap = c01; c01=c11; c11=cswap;
+ } else {
+ if ((dx >= 0) && (dy >= 0) && (dx < srcW) && (dy < srcH)) {
+ const tColorRGBA *sp = (const tColorRGBA *)getBasePtr(dx, dy);
+ *pc = *sp;
}
- /*
- * Interpolate colors
- */
- int ex = (sdx & 0xffff);
- int ey = (sdy & 0xffff);
- int t1, t2;
- t1 = ((((c01.r - c00.r) * ex) >> 16) + c00.r) & 0xff;
- t2 = ((((c11.r - c10.r) * ex) >> 16) + c10.r) & 0xff;
- pc->r = (((t2 - t1) * ey) >> 16) + t1;
- t1 = ((((c01.g - c00.g) * ex) >> 16) + c00.g) & 0xff;
- t2 = ((((c11.g - c10.g) * ex) >> 16) + c10.g) & 0xff;
- pc->g = (((t2 - t1) * ey) >> 16) + t1;
- t1 = ((((c01.b - c00.b) * ex) >> 16) + c00.b) & 0xff;
- t2 = ((((c11.b - c10.b) * ex) >> 16) + c10.b) & 0xff;
- pc->b = (((t2 - t1) * ey) >> 16) + t1;
- t1 = ((((c01.a - c00.a) * ex) >> 16) + c00.a) & 0xff;
- t2 = ((((c11.a - c10.a) * ex) >> 16) + c10.a) & 0xff;
- pc->a = (((t2 - t1) * ey) >> 16) + t1;
- }
-#else
- if ((dx >= 0) && (dy >= 0) && (dx < srcW) && (dy < srcH)) {
- const tColorRGBA *sp = (const tColorRGBA *)getBasePtr(dx, dy);
- *pc = *sp;
}
-#endif
sdx += icosx;
sdy += isiny;
pc++;
@@ -791,6 +790,7 @@ TransparentSurface *TransparentSurface::rotoscale(const TransformStruct &transfo
return target;
}
+template <TFilteringMode filteringMode>
TransparentSurface *TransparentSurface::scale(uint16 newWidth, uint16 newHeight) const {
Common::Rect srcRect(0, 0, (int16)w, (int16)h);
@@ -807,173 +807,173 @@ TransparentSurface *TransparentSurface::scale(uint16 newWidth, uint16 newHeight)
target->create((uint16)dstW, (uint16)dstH, this->format);
-#ifdef ENABLE_BILINEAR
+ if (filteringMode == FILTER_BILINEAR) {
- // NB: The actual order of these bytes may not be correct, but
- // since all values are treated equal, that does not matter.
- struct tColorRGBA { byte r; byte g; byte b; byte a; };
+ // NB: The actual order of these bytes may not be correct, but
+ // since all values are treated equal, that does not matter.
+ struct tColorRGBA { byte r; byte g; byte b; byte a; };
- bool flipx = false, flipy = false; // TODO: See mirroring comment in RenderTicket ctor
+ bool flipx = false, flipy = false; // TODO: See mirroring comment in RenderTicket ctor
+
+
+ int *sax = new int[dstW + 1];
+ int *say = new int[dstH + 1];
+ assert(sax && say);
+ /*
+ * Precalculate row increments
+ */
+ int spixelw = (srcW - 1);
+ int spixelh = (srcH - 1);
+ int sx = (int) (65536.0f * (float) spixelw / (float) (dstW - 1));
+ int sy = (int) (65536.0f * (float) spixelh / (float) (dstH - 1));
+
+ /* Maximum scaled source size */
+ int ssx = (srcW << 16) - 1;
+ int ssy = (srcH << 16) - 1;
+
+ /* Precalculate horizontal row increments */
+ int csx = 0;
+ int *csax = sax;
+ for (int x = 0; x <= dstW; x++) {
+ *csax = csx;
+ csax++;
+ csx += sx;
- int *sax = new int[dstW + 1];
- int *say = new int[dstH + 1];
- assert(sax && say);
-
- /*
- * Precalculate row increments
- */
- int spixelw = (srcW - 1);
- int spixelh = (srcH - 1);
- int sx = (int) (65536.0f * (float) spixelw / (float) (dstW - 1));
- int sy = (int) (65536.0f * (float) spixelh / (float) (dstH - 1));
-
- /* Maximum scaled source size */
- int ssx = (srcW << 16) - 1;
- int ssy = (srcH << 16) - 1;
-
- /* Precalculate horizontal row increments */
- int csx = 0;
- int *csax = sax;
- for (int x = 0; x <= dstW; x++) {
- *csax = csx;
- csax++;
- csx += sx;
-
- /* Guard from overflows */
- if (csx > ssx) {
- csx = ssx;
+ /* Guard from overflows */
+ if (csx > ssx) {
+ csx = ssx;
+ }
}
- }
- /* Precalculate vertical row increments */
- int csy = 0;
- int *csay = say;
- for (int y = 0; y <= dstH; y++) {
- *csay = csy;
- csay++;
- csy += sy;
-
- /* Guard from overflows */
- if (csy > ssy) {
- csy = ssy;
+ /* Precalculate vertical row increments */
+ int csy = 0;
+ int *csay = say;
+ for (int y = 0; y <= dstH; y++) {
+ *csay = csy;
+ csay++;
+ csy += sy;
+
+ /* Guard from overflows */
+ if (csy > ssy) {
+ csy = ssy;
+ }
}
- }
- const tColorRGBA *sp = (const tColorRGBA *) getBasePtr(0, 0);
- tColorRGBA *dp = (tColorRGBA *) target->getBasePtr(0, 0);
- int spixelgap = srcW;
+ const tColorRGBA *sp = (const tColorRGBA *) getBasePtr(0, 0);
+ tColorRGBA *dp = (tColorRGBA *) target->getBasePtr(0, 0);
+ int spixelgap = srcW;
- if (flipx) {
- sp += spixelw;
- }
- if (flipy) {
- sp += spixelgap * spixelh;
- }
+ if (flipx) {
+ sp += spixelw;
+ }
+ if (flipy) {
+ sp += spixelgap * spixelh;
+ }
- csay = say;
- for (int y = 0; y < dstH; y++) {
- const tColorRGBA *csp = sp;
- csax = sax;
- for (int x = 0; x < dstW; x++) {
- /*
- * Setup color source pointers
- */
- int ex = (*csax & 0xffff);
- int ey = (*csay & 0xffff);
- int cx = (*csax >> 16);
- int cy = (*csay >> 16);
-
- const tColorRGBA *c00, *c01, *c10, *c11;
- c00 = sp;
- c01 = sp;
- c10 = sp;
- if (cy < spixelh) {
- if (flipy) {
- c10 -= spixelgap;
- } else {
- c10 += spixelgap;
+ csay = say;
+ for (int y = 0; y < dstH; y++) {
+ const tColorRGBA *csp = sp;
+ csax = sax;
+ for (int x = 0; x < dstW; x++) {
+ /*
+ * Setup color source pointers
+ */
+ int ex = (*csax & 0xffff);
+ int ey = (*csay & 0xffff);
+ int cx = (*csax >> 16);
+ int cy = (*csay >> 16);
+
+ const tColorRGBA *c00, *c01, *c10, *c11;
+ c00 = sp;
+ c01 = sp;
+ c10 = sp;
+ if (cy < spixelh) {
+ if (flipy) {
+ c10 -= spixelgap;
+ } else {
+ c10 += spixelgap;
+ }
}
- }
- c11 = c10;
- if (cx < spixelw) {
+ c11 = c10;
+ if (cx < spixelw) {
+ if (flipx) {
+ c01--;
+ c11--;
+ } else {
+ c01++;
+ c11++;
+ }
+ }
+
+ /*
+ * Draw and interpolate colors
+ */
+ int t1, t2;
+ t1 = ((((c01->r - c00->r) * ex) >> 16) + c00->r) & 0xff;
+ t2 = ((((c11->r - c10->r) * ex) >> 16) + c10->r) & 0xff;
+ dp->r = (((t2 - t1) * ey) >> 16) + t1;
+ t1 = ((((c01->g - c00->g) * ex) >> 16) + c00->g) & 0xff;
+ t2 = ((((c11->g - c10->g) * ex) >> 16) + c10->g) & 0xff;
+ dp->g = (((t2 - t1) * ey) >> 16) + t1;
+ t1 = ((((c01->b - c00->b) * ex) >> 16) + c00->b) & 0xff;
+ t2 = ((((c11->b - c10->b) * ex) >> 16) + c10->b) & 0xff;
+ dp->b = (((t2 - t1) * ey) >> 16) + t1;
+ t1 = ((((c01->a - c00->a) * ex) >> 16) + c00->a) & 0xff;
+ t2 = ((((c11->a - c10->a) * ex) >> 16) + c10->a) & 0xff;
+ dp->a = (((t2 - t1) * ey) >> 16) + t1;
+
+ /*
+ * Advance source pointer x
+ */
+ int *salastx = csax;
+ csax++;
+ int sstepx = (*csax >> 16) - (*salastx >> 16);
if (flipx) {
- c01--;
- c11--;
+ sp -= sstepx;
} else {
- c01++;
- c11++;
+ sp += sstepx;
}
- }
-
- /*
- * Draw and interpolate colors
- */
- int t1, t2;
- t1 = ((((c01->r - c00->r) * ex) >> 16) + c00->r) & 0xff;
- t2 = ((((c11->r - c10->r) * ex) >> 16) + c10->r) & 0xff;
- dp->r = (((t2 - t1) * ey) >> 16) + t1;
- t1 = ((((c01->g - c00->g) * ex) >> 16) + c00->g) & 0xff;
- t2 = ((((c11->g - c10->g) * ex) >> 16) + c10->g) & 0xff;
- dp->g = (((t2 - t1) * ey) >> 16) + t1;
- t1 = ((((c01->b - c00->b) * ex) >> 16) + c00->b) & 0xff;
- t2 = ((((c11->b - c10->b) * ex) >> 16) + c10->b) & 0xff;
- dp->b = (((t2 - t1) * ey) >> 16) + t1;
- t1 = ((((c01->a - c00->a) * ex) >> 16) + c00->a) & 0xff;
- t2 = ((((c11->a - c10->a) * ex) >> 16) + c10->a) & 0xff;
- dp->a = (((t2 - t1) * ey) >> 16) + t1;
+ /*
+ * Advance destination pointer x
+ */
+ dp++;
+ }
/*
- * Advance source pointer x
+ * Advance source pointer y
*/
- int *salastx = csax;
- csax++;
- int sstepx = (*csax >> 16) - (*salastx >> 16);
- if (flipx) {
- sp -= sstepx;
+ int *salasty = csay;
+ csay++;
+ int sstepy = (*csay >> 16) - (*salasty >> 16);
+ sstepy *= spixelgap;
+ if (flipy) {
+ sp = csp - sstepy;
} else {
- sp += sstepx;
+ sp = csp + sstepy;
}
-
- /*
- * Advance destination pointer x
- */
- dp++;
- }
- /*
- * Advance source pointer y
- */
- int *salasty = csay;
- csay++;
- int sstepy = (*csay >> 16) - (*salasty >> 16);
- sstepy *= spixelgap;
- if (flipy) {
- sp = csp - sstepy;
- } else {
- sp = csp + sstepy;
}
- }
- delete[] sax;
- delete[] say;
+ delete[] sax;
+ delete[] say;
-#else
-
- int *scaleCacheX = new int[dstW];
- for (int x = 0; x < dstW; x++) {
- scaleCacheX[x] = (x * srcW) / dstW;
- }
+ } else {
- for (int y = 0; y < dstH; y++) {
- uint32 *destP = (uint32 *)target->getBasePtr(0, y);
- const uint32 *srcP = (const uint32 *)getBasePtr(0, (y * srcH) / dstH);
+ int *scaleCacheX = new int[dstW];
for (int x = 0; x < dstW; x++) {
- *destP++ = srcP[scaleCacheX[x]];
+ scaleCacheX[x] = (x * srcW) / dstW;
}
- }
- delete[] scaleCacheX;
-#endif
+ for (int y = 0; y < dstH; y++) {
+ uint32 *destP = (uint32 *)target->getBasePtr(0, y);
+ const uint32 *srcP = (const uint32 *)getBasePtr(0, (y * srcH) / dstH);
+ for (int x = 0; x < dstW; x++) {
+ *destP++ = srcP[scaleCacheX[x]];
+ }
+ }
+ delete[] scaleCacheX;
+
+ }
return target;
@@ -1057,4 +1057,18 @@ TransparentSurface *TransparentSurface::convertTo(const PixelFormat &dstFormat,
return surface;
}
+
+template TransparentSurface *TransparentSurface::rotoscale<FILTER_NEAREST>(const TransformStruct &transform) const;
+template TransparentSurface *TransparentSurface::rotoscale<FILTER_BILINEAR>(const TransformStruct &transform) const;
+template TransparentSurface *TransparentSurface::scale<FILTER_NEAREST>(uint16 newWidth, uint16 newHeight) const;
+template TransparentSurface *TransparentSurface::scale<FILTER_BILINEAR>(uint16 newWidth, uint16 newHeight) const;
+
+TransparentSurface *TransparentSurface::rotoscale(const TransformStruct &transform) const {
+ return rotoscale<FILTER_BILINEAR>(transform);
+}
+
+TransparentSurface *TransparentSurface::scale(uint16 newWidth, uint16 newHeight) const {
+ return scale<FILTER_NEAREST>(newWidth, newHeight);
+}
+
} // End of namespace Graphics
diff --git a/graphics/transparent_surface.h b/graphics/transparent_surface.h
index 8654183548..83c65766fb 100644
--- a/graphics/transparent_surface.h
+++ b/graphics/transparent_surface.h
@@ -68,6 +68,11 @@ enum AlphaType {
ALPHA_FULL = 2
};
+enum TFilteringMode {
+ FILTER_NEAREST = 0,
+ FILTER_BILINEAR = 1
+};
+
/**
* A transparent graphics surface, which implements alpha blitting.
*/
@@ -141,8 +146,10 @@ struct TransparentSurface : public Graphics::Surface {
* @param newHeight the resulting height.
* @see TransformStruct
*/
+ template <TFilteringMode filteringMode>
TransparentSurface *scale(uint16 newWidth, uint16 newHeight) const;
+ TransparentSurface *scale(uint16 newWidth, uint16 newHeight) const;
/**
* @brief Rotoscale function; this returns a transformed version of this surface after rotation and
* scaling. Please do not use this if angle == 0, use plain old scaling function.
@@ -150,6 +157,9 @@ struct TransparentSurface : public Graphics::Surface {
* @param transform a TransformStruct wrapping the required info. @see TransformStruct
*
*/
+ template <TFilteringMode filteringMode>
+ TransparentSurface *rotoscale(const TransformStruct &transform) const;
+
TransparentSurface *rotoscale(const TransformStruct &transform) const;
TransparentSurface *convertTo(const PixelFormat &dstFormat, const byte *palette = 0) const;