WINTERMUTE: Add TFilteringMode to transparent_surface.h

This commit is contained in:
Tobia Tesan 2016-03-31 10:16:19 +02:00
parent 42531fb71a
commit c6ed1625f0
2 changed files with 218 additions and 194 deletions

View File

@ -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,7 +738,7 @@ TransparentSurface *TransparentSurface::rotoscale(const TransformStruct &transfo
dy = sh - dy;
}
#ifdef ENABLE_BILINEAR
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;
@ -777,12 +776,12 @@ TransparentSurface *TransparentSurface::rotoscale(const TransformStruct &transfo
t2 = ((((c11.a - c10.a) * ex) >> 16) + c10.a) & 0xff;
pc->a = (((t2 - t1) * ey) >> 16) + t1;
}
#else
} 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,7 +807,7 @@ 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.
@ -957,7 +957,7 @@ TransparentSurface *TransparentSurface::scale(uint16 newWidth, uint16 newHeight)
delete[] sax;
delete[] say;
#else
} else {
int *scaleCacheX = new int[dstW];
for (int x = 0; x < dstW; x++) {
@ -973,7 +973,7 @@ TransparentSurface *TransparentSurface::scale(uint16 newWidth, uint16 newHeight)
}
delete[] scaleCacheX;
#endif
}
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

View File

@ -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;