GRAPHICS: Add 4 byte per pixel support for Normal scalers

This commit is contained in:
Eric Culp 2012-06-14 16:16:09 -04:00 committed by Filippos Karapetis
parent ff6fe4360d
commit 780d5a8689

View file

@ -32,21 +32,24 @@ NormalPlugin::NormalPlugin() {
} }
void NormalPlugin::initialize(Graphics::PixelFormat format) { void NormalPlugin::initialize(Graphics::PixelFormat format) {
_format = format;
} }
/** /**
* Trivial 'scaler' - in fact it doesn't do any scaling but just copies the * Trivial 'scaler' - in fact it doesn't do any scaling but just copies the
* source to the destination. * source to the destination.
*/ */
template<typename pixel>
void Normal1x(const uint8 *srcPtr, uint32 srcPitch, uint8 *dstPtr, uint32 dstPitch, void Normal1x(const uint8 *srcPtr, uint32 srcPitch, uint8 *dstPtr, uint32 dstPitch,
int width, int height) { int width, int height) {
// Spot the case when it can all be done in 1 hit // Spot the case when it can all be done in 1 hit
if ((srcPitch == sizeof(OverlayColor) * (uint)width) && (dstPitch == sizeof(OverlayColor) * (uint)width)) { int BytesPerPixel = sizeof(pixel);
memcpy(dstPtr, srcPtr, sizeof(OverlayColor) * width * height); if ((srcPitch == BytesPerPixel * (uint)width) && (dstPitch == BytesPerPixel * (uint)width)) {
memcpy(dstPtr, srcPtr, BytesPerPixel * width * height);
return; return;
} }
while (height--) { while (height--) {
memcpy(dstPtr, srcPtr, sizeof(OverlayColor) * width); memcpy(dstPtr, srcPtr, BytesPerPixel * width);
srcPtr += srcPitch; srcPtr += srcPitch;
dstPtr += dstPitch; dstPtr += dstPitch;
} }
@ -54,6 +57,31 @@ void Normal1x(const uint8 *srcPtr, uint32 srcPitch, uint8 *dstPtr, uint32 dstPit
#ifdef USE_SCALERS #ifdef USE_SCALERS
/**
* Trivial nearest-neighbor 2x scaler.
*/
template<typename pixel>
void Normal2x(const uint8 *srcPtr, uint32 srcPitch, uint8 *dstPtr, uint32 dstPitch,
int width, int height) {
uint8 *r;
int b = sizeof(pixel);
assert(IS_ALIGNED(dstPtr, 2));
while (height--) {
r = dstPtr;
for (int i = 0; i < width; ++i, r += b * 2) {
pixel color = *(((const pixel*)srcPtr) + i);
*(pixel *)(r) = color;
*(pixel *)(r + b) = color;
*(pixel *)(r + dstPitch) = color;
*(pixel *)(r + b + dstPitch) = color;
}
srcPtr += srcPitch;
dstPtr += dstPitch << 1;
}
}
#ifdef USE_ARM_SCALER_ASM #ifdef USE_ARM_SCALER_ASM
extern "C" void Normal2xARM(const uint8 *srcPtr, extern "C" void Normal2xARM(const uint8 *srcPtr,
@ -63,29 +91,20 @@ extern "C" void Normal2xARM(const uint8 *srcPtr,
int width, int width,
int height); int height);
void Normal2x(const uint8 *srcPtr,
uint32 srcPitch,
uint8 *dstPtr,
uint32 dstPitch,
int width,
int height) {
Normal2xARM(srcPtr, srcPitch, dstPtr, dstPitch, width, height);
}
#else #else
/** /**
* Trivial nearest-neighbor 2x scaler. * Template Specialization that writes 2 pixels at a time.
*/ */
void Normal2x(const uint8 *srcPtr, uint32 srcPitch, uint8 *dstPtr, uint32 dstPitch, template<>
void Normal2x<uint16>(const uint8 *srcPtr, uint32 srcPitch, uint8 *dstPtr, uint32 dstPitch,
int width, int height) { int width, int height) {
uint8 *r; uint8 *r;
assert(IS_ALIGNED(dstPtr, 4)); assert(IS_ALIGNED(dstPtr, 4));
assert(sizeof(OverlayColor) == 2);
while (height--) { while (height--) {
r = dstPtr; r = dstPtr;
for (int i = 0; i < width; ++i, r += 4) { for (int i = 0; i < width; ++i, r += 4) {
uint32 color = *(((const OverlayColor *)srcPtr) + i); uint32 color = *(((const uint16*)srcPtr) + i);
color |= color << 16; color |= color << 16;
@ -101,27 +120,29 @@ void Normal2x(const uint8 *srcPtr, uint32 srcPitch, uint8 *dstPtr, uint32 dstPit
/** /**
* Trivial nearest-neighbor 3x scaler. * Trivial nearest-neighbor 3x scaler.
*/ */
template<typename pixel>
void Normal3x(const uint8 *srcPtr, uint32 srcPitch, uint8 *dstPtr, uint32 dstPitch, void Normal3x(const uint8 *srcPtr, uint32 srcPitch, uint8 *dstPtr, uint32 dstPitch,
int width, int height) { int width, int height) {
uint8 *r; uint8 *r;
const uint32 dstPitch2 = dstPitch * 2; const uint32 dstPitch2 = dstPitch * 2;
const uint32 dstPitch3 = dstPitch * 3; const uint32 dstPitch3 = dstPitch * 3;
int b = sizeof(pixel);
assert(IS_ALIGNED(dstPtr, 2)); assert(IS_ALIGNED(dstPtr, 2));
while (height--) { while (height--) {
r = dstPtr; r = dstPtr;
for (int i = 0; i < width; ++i, r += 6) { for (int i = 0; i < width; ++i, r += b * 3) {
uint16 color = *(((const uint16 *)srcPtr) + i); pixel color = *(((const pixel *)srcPtr) + i);
*(uint16 *)(r + 0) = color; *(pixel *)(r + b * 0) = color;
*(uint16 *)(r + 2) = color; *(pixel *)(r + b * 1) = color;
*(uint16 *)(r + 4) = color; *(pixel *)(r + b * 2) = color;
*(uint16 *)(r + 0 + dstPitch) = color; *(pixel *)(r + b * 0 + dstPitch) = color;
*(uint16 *)(r + 2 + dstPitch) = color; *(pixel *)(r + b * 1 + dstPitch) = color;
*(uint16 *)(r + 4 + dstPitch) = color; *(pixel *)(r + b * 2 + dstPitch) = color;
*(uint16 *)(r + 0 + dstPitch2) = color; *(pixel *)(r + b * 0 + dstPitch2) = color;
*(uint16 *)(r + 2 + dstPitch2) = color; *(pixel *)(r + b * 1 + dstPitch2) = color;
*(uint16 *)(r + 4 + dstPitch2) = color; *(pixel *)(r + b * 2 + dstPitch2) = color;
} }
srcPtr += srcPitch; srcPtr += srcPitch;
dstPtr += dstPitch3; dstPtr += dstPitch3;
@ -131,35 +152,37 @@ void Normal3x(const uint8 *srcPtr, uint32 srcPitch, uint8 *dstPtr, uint32 dstPit
/** /**
* Trivial nearest-neighbor 4x scaler. * Trivial nearest-neighbor 4x scaler.
*/ */
template<typename pixel>
void Normal4x(const uint8 *srcPtr, uint32 srcPitch, uint8 *dstPtr, uint32 dstPitch, void Normal4x(const uint8 *srcPtr, uint32 srcPitch, uint8 *dstPtr, uint32 dstPitch,
int width, int height) { int width, int height) {
uint8 *r; uint8 *r;
const uint32 dstPitch2 = dstPitch * 2; const uint32 dstPitch2 = dstPitch * 2;
const uint32 dstPitch3 = dstPitch * 3; const uint32 dstPitch3 = dstPitch * 3;
const uint32 dstPitch4 = dstPitch * 4; const uint32 dstPitch4 = dstPitch * 4;
int b = sizeof(pixel);
assert(IS_ALIGNED(dstPtr, 2)); assert(IS_ALIGNED(dstPtr, 2));
while (height--) { while (height--) {
r = dstPtr; r = dstPtr;
for (int i = 0; i < width; ++i, r += 8) { for (int i = 0; i < width; ++i, r += b * 4) {
uint16 color = *(((const uint16 *)srcPtr) + i); pixel color = *(((const pixel *)srcPtr) + i);
*(uint16 *)(r + 0) = color; *(pixel *)(r + b * 0) = color;
*(uint16 *)(r + 2) = color; *(pixel *)(r + b * 1) = color;
*(uint16 *)(r + 4) = color; *(pixel *)(r + b * 2) = color;
*(uint16 *)(r + 6) = color; *(pixel *)(r + b * 3) = color;
*(uint16 *)(r + 0 + dstPitch) = color; *(pixel *)(r + b * 0 + dstPitch) = color;
*(uint16 *)(r + 2 + dstPitch) = color; *(pixel *)(r + b * 1 + dstPitch) = color;
*(uint16 *)(r + 4 + dstPitch) = color; *(pixel *)(r + b * 2 + dstPitch) = color;
*(uint16 *)(r + 6 + dstPitch) = color; *(pixel *)(r + b * 3 + dstPitch) = color;
*(uint16 *)(r + 0 + dstPitch2) = color; *(pixel *)(r + b * 0 + dstPitch2) = color;
*(uint16 *)(r + 2 + dstPitch2) = color; *(pixel *)(r + b * 1 + dstPitch2) = color;
*(uint16 *)(r + 4 + dstPitch2) = color; *(pixel *)(r + b * 2 + dstPitch2) = color;
*(uint16 *)(r + 6 + dstPitch2) = color; *(pixel *)(r + b * 3 + dstPitch2) = color;
*(uint16 *)(r + 0 + dstPitch3) = color; *(pixel *)(r + b * 0 + dstPitch3) = color;
*(uint16 *)(r + 2 + dstPitch3) = color; *(pixel *)(r + b * 1 + dstPitch3) = color;
*(uint16 *)(r + 4 + dstPitch3) = color; *(pixel *)(r + b * 2 + dstPitch3) = color;
*(uint16 *)(r + 6 + dstPitch3) = color; *(pixel *)(r + b * 3 + dstPitch3) = color;
} }
srcPtr += srcPitch; srcPtr += srcPitch;
dstPtr += dstPitch4; dstPtr += dstPitch4;
@ -170,22 +193,44 @@ void Normal4x(const uint8 *srcPtr, uint32 srcPitch, uint8 *dstPtr, uint32 dstPit
void NormalPlugin::scale(const uint8 *srcPtr, uint32 srcPitch, void NormalPlugin::scale(const uint8 *srcPtr, uint32 srcPitch,
uint8 *dstPtr, uint32 dstPitch, int width, int height, int x, int y) { uint8 *dstPtr, uint32 dstPitch, int width, int height, int x, int y) {
#ifdef USE_SCALERS #ifdef USE_SCALERS
switch (_factor) { if (_format.bytesPerPixel == 2) {
case 1: switch (_factor) {
Normal1x(srcPtr, srcPitch, dstPtr, dstPitch, width, height); case 1:
break; Normal1x<uint16>(srcPtr, srcPitch, dstPtr, dstPitch, width, height);
case 2: break;
Normal2x(srcPtr, srcPitch, dstPtr, dstPitch, width, height); case 2:
break; #ifdef USE_ARM_SCALER_ASM
case 3: Normal2xARM(srcPtr, srcPitch, dstPtr, dstPitch, width, height);
Normal3x(srcPtr, srcPitch, dstPtr, dstPitch, width, height); #else
break; Normal2x<uint16>(srcPtr, srcPitch, dstPtr, dstPitch, width, height);
case 4: #endif
Normal4x(srcPtr, srcPitch, dstPtr, dstPitch, width, height); break;
break; case 3:
Normal3x<uint16>(srcPtr, srcPitch, dstPtr, dstPitch, width, height);
break;
case 4:
Normal4x<uint16>(srcPtr, srcPitch, dstPtr, dstPitch, width, height);
break;
}
} else {
assert(_format.bytesPerPixel == 4);
switch (_factor) {
case 1:
Normal1x<uint32>(srcPtr, srcPitch, dstPtr, dstPitch, width, height);
break;
case 2:
Normal2x<uint32>(srcPtr, srcPitch, dstPtr, dstPitch, width, height);
break;
case 3:
Normal3x<uint32>(srcPtr, srcPitch, dstPtr, dstPitch, width, height);
break;
case 4:
Normal4x<uint32>(srcPtr, srcPitch, dstPtr, dstPitch, width, height);
break;
}
} }
#else #else
Normal1x(srcPtr, srcPitch, dstPtr, dstPitch, width, height); Normal1x<uint16>(srcPtr, srcPitch, dstPtr, dstPitch, width, height);
#endif #endif
} }