mirror of
https://github.com/yuzu-emu/FasTC.git
synced 2025-03-08 10:10:51 +00:00
Make sure to preserve bit depth when bilinearly upscaling
This commit is contained in:
parent
3f4ffa61b5
commit
4bbd80aab2
|
@ -96,6 +96,17 @@ Image::~Image() {
|
|||
delete [] m_Pixels;
|
||||
}
|
||||
|
||||
#ifndef NDEBUG
|
||||
static bool CompareBitDepths(const uint8 (&depth1)[4],
|
||||
const uint8 (&depth2)[4]) {
|
||||
bool ok = true;
|
||||
for(uint32 i = 0; i < 4; i++) {
|
||||
ok = ok && depth1[i] == depth2[i];
|
||||
}
|
||||
return ok;
|
||||
}
|
||||
#endif
|
||||
|
||||
void Image::BilinearUpscale(uint32 times, EWrapMode wrapMode) {
|
||||
const uint32 newWidth = m_Width << times;
|
||||
const uint32 newHeight = m_Height << times;
|
||||
|
@ -125,6 +136,23 @@ void Image::BilinearUpscale(uint32 times, EWrapMode wrapMode) {
|
|||
const Pixel &bottomLeft = GetPixel(lowXIdx, highYIdx, wrapMode);
|
||||
const Pixel &bottomRight = GetPixel(highXIdx, highYIdx, wrapMode);
|
||||
|
||||
// Make sure the bit depth matches the original...
|
||||
uint8 bitDepth[4];
|
||||
topLeft.GetBitDepth(bitDepth);
|
||||
p.ChangeBitDepth(bitDepth);
|
||||
#ifndef NDEBUG
|
||||
uint8 debugDepth[4];
|
||||
|
||||
topRight.GetBitDepth(debugDepth);
|
||||
assert(CompareBitDepths(bitDepth, debugDepth));
|
||||
|
||||
bottomLeft.GetBitDepth(debugDepth);
|
||||
assert(CompareBitDepths(bitDepth, debugDepth));
|
||||
|
||||
bottomRight.GetBitDepth(debugDepth);
|
||||
assert(CompareBitDepths(bitDepth, debugDepth));
|
||||
#endif //NDEBUG
|
||||
|
||||
// bilerp each channel....
|
||||
for(uint32 c = 0; c < 4; c++) {
|
||||
const uint16 left =
|
||||
|
|
|
@ -151,6 +151,13 @@ TEST(Image, BilinearUpscale) {
|
|||
|
||||
TEST(Image, BilinearUpscaleWrapped) {
|
||||
PVRTCC::Pixel pxs[16];
|
||||
|
||||
// Make sure that our bit depth is less than full...
|
||||
for(int i = 0; i < 16; i++) {
|
||||
const uint8 newBitDepth[4] = { 6, 5, 6, 5 };
|
||||
pxs[i].ChangeBitDepth(newBitDepth);
|
||||
}
|
||||
|
||||
for(int i = 0; i < 4; i++) {
|
||||
for(int j = 0; j < 4; j++) {
|
||||
pxs[j*4 + i].R() = i*4;
|
||||
|
@ -166,6 +173,16 @@ TEST(Image, BilinearUpscaleWrapped) {
|
|||
for(uint32 i = 0; i < img.GetWidth(); i++) {
|
||||
for(uint32 j = 0; j < img.GetHeight(); j++) {
|
||||
const PVRTCC::Pixel &p = img(i, j);
|
||||
|
||||
// First make sure that the bit depth didn't change
|
||||
uint8 depth[4];
|
||||
p.GetBitDepth(depth);
|
||||
EXPECT_EQ(depth[0], 6);
|
||||
EXPECT_EQ(depth[1], 5);
|
||||
EXPECT_EQ(depth[2], 6);
|
||||
EXPECT_EQ(depth[3], 5);
|
||||
|
||||
// Now make sure that the values are correct.
|
||||
if(i == 0) {
|
||||
EXPECT_EQ(p.R(), 6);
|
||||
} else if(i == 1) {
|
||||
|
|
Loading…
Reference in a new issue