Move ScaleAlways to common code.

This commit is contained in:
Unknown W. Brackets 2016-06-19 11:09:10 -07:00
parent 5962093ef5
commit 3db69b87d7
4 changed files with 35 additions and 38 deletions

View File

@ -21,6 +21,7 @@
#endif
#include <algorithm>
#include <cassert>
#include <cstdlib>
#include <cmath>
@ -504,6 +505,37 @@ bool TextureScaler::IsEmptyOrFlat(u32* data, int pixels, int fmt) {
return true;
}
void TextureScaler::ScaleAlways(u32 *&data, u32 &dstFmt, int &width, int &height, int factor) {
if (!Scale(data, dstFmt, width, height, factor)) {
// This means it was a flat texture. Vulkan wants the size up front, so we need to make it happen.
assert(IsEmptyOrFlat(data, width * height, dstFmt));
u32 pixel;
// Since it's flat, one pixel is enough. It might end up pointing to data, though.
u32 *pixelPointer = &pixel;
ConvertTo8888(dstFmt, data, pixelPointer, 1, 1);
if (pixelPointer != &pixel) {
pixel = *pixelPointer;
}
bufOutput.resize(width * height * factor * factor);
dstFmt = Get8888Format();
data = bufOutput.data();
width *= factor;
height *= factor;
// ABCD. If A = D, and AB = CD, then they must all be equal (B = C, etc.)
if ((pixel & 0x000000FF) == (pixel >> 24) && (pixel & 0x0000FFFF) == (pixel >> 16)) {
memset(data, pixel & 0xFF, width * height * sizeof(u32));
} else {
// Let's hope this is vectorized.
for (int i = 0; i < width * height; ++i) {
data[i] = pixel;
}
}
}
}
bool TextureScaler::Scale(u32* &data, u32 &dstFmt, int &width, int &height, int factor) {
// prevent processing empty or flat textures (this happens a lot in some games)
// doesn't hurt the standard case, will be very quick for textures with actual texture

View File

@ -27,12 +27,13 @@ public:
TextureScaler();
~TextureScaler();
bool Scale(u32* &data, u32 &dstfmt, int &width, int &height, int factor);
void ScaleAlways(u32 *&data, u32 &dstFmt, int &width, int &height, int factor);
bool Scale(u32 *&data, u32 &dstfmt, int &width, int &height, int factor);
enum { XBRZ = 0, HYBRID = 1, BICUBIC = 2, HYBRID_BICUBIC = 3 };
protected:
virtual void ConvertTo8888(u32 format, u32* source, u32* &dest, int width, int height) = 0;
virtual void ConvertTo8888(u32 format, u32 *source, u32 *&dest, int width, int height) = 0;
virtual int BytesPerPixel(u32 format) = 0;
virtual u32 Get8888Format() = 0;

View File

@ -44,39 +44,6 @@ u32 TextureScalerVulkan::Get8888Format() {
return VULKAN_8888_FORMAT;
}
void TextureScalerVulkan::ScaleAlways(u32 *&data, u32 &dstFmt, int &width, int &height, int factor) {
if (!Scale(data, dstFmt, width, height, factor)) {
// This means it was a flat texture. Vulkan wants the size up front, so we need to make it happen.
assert(IsEmptyOrFlat(data, width * height, dstFmt));
u32 pixel;
// Since it's flat, one pixel is enough. It might end up pointing to data, though.
u32 *pixelPointer = &pixel;
ConvertTo8888(dstFmt, data, pixelPointer, 1, 1);
if (pixelPointer != &pixel) {
pixel = *pixelPointer;
}
bufOutput.resize(width * height * factor * factor);
dstFmt = Get8888Format();
data = bufOutput.data();
width *= factor;
height *= factor;
// ABCD. If A = D, and AB = CD, then they must all be equal (B = C, etc.)
if ((pixel & 0x000000FF) == (pixel >> 24) && (pixel & 0x0000FFFF) == (pixel >> 16)) {
memset(data, pixel & 0xFF, width * height * sizeof(u32));
} else {
// TODO: Optimize.
for (int y = 0; y < height; ++y) {
for (int x = 0; x < width; ++x) {
data[y * width + x] = pixel;
}
}
}
}
}
void TextureScalerVulkan::ConvertTo8888(u32 format, u32* source, u32* &dest, int width, int height) {
switch (format) {
case VULKAN_8888_FORMAT:

View File

@ -21,9 +21,6 @@
#include "GPU/Common/TextureScalerCommon.h"
class TextureScalerVulkan : public TextureScaler {
public:
void ScaleAlways(u32* &data, u32 &dstFmt, int &width, int &height, int factor);
protected:
void ConvertTo8888(u32 format, u32* source, u32* &dest, int width, int height) override;
int BytesPerPixel(u32 format) override;