mirror of
https://github.com/yuzu-emu/FasTC
synced 2024-11-22 17:03:44 +00:00
Fix bugs and get tests passing
This commit is contained in:
parent
84f25a353b
commit
ade1f77fe4
2 changed files with 35 additions and 6 deletions
|
@ -672,17 +672,20 @@ static void IDCT(Image<IPixel> *img) {
|
||||||
for (unsigned int u = 0; u < img->GetWidth(); ++u) {
|
for (unsigned int u = 0; u < img->GetWidth(); ++u) {
|
||||||
float fu = static_cast<float>(u);
|
float fu = static_cast<float>(u);
|
||||||
float fv = static_cast<float>(v);
|
float fv = static_cast<float>(v);
|
||||||
new_img(x, y) += (*img)(u, v)
|
|
||||||
|
float idct = (*img)(u, v)
|
||||||
* cos(((2*fx + 1) * fu * M_PI) / (2 * N))
|
* cos(((2*fx + 1) * fu * M_PI) / (2 * N))
|
||||||
* cos(((2*fy + 1) * fv * M_PI) / (2 * M));
|
* cos(((2*fy + 1) * fv * M_PI) / (2 * M));
|
||||||
|
|
||||||
if (u == 0 && v == 0) {
|
if (u == 0 && v == 0) {
|
||||||
new_img(x, y) /= N;
|
idct /= N;
|
||||||
} else if (u == 0 || v == 0) {
|
} else if (u == 0 || v == 0) {
|
||||||
new_img(x, y) /= sqrt(2) / N;
|
idct *= sqrt(2) / N;
|
||||||
} else {
|
} else {
|
||||||
new_img(x, y) *= 2 / N;
|
idct *= 2 / N;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
new_img(x, y) += FasTC::IPixel(idct);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -213,6 +213,33 @@ TEST(Image, SplitImage) {
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(Image, DCT) {
|
TEST(Image, DCT) {
|
||||||
|
const uint32 w = 32;
|
||||||
|
const uint32 h = 32;
|
||||||
|
|
||||||
|
FasTC::Image<FasTC::IPixel> img(w, h);
|
||||||
|
for (uint32 j = 0; j < h; ++j) {
|
||||||
|
for (uint32 i = 0; i < w; ++i) {
|
||||||
|
img(i, j) = static_cast<FasTC::IPixel>(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Make sure that taking the DCT and inverse DCT returns
|
||||||
|
// the same image...
|
||||||
|
FasTC::DiscreteCosineXForm(&img, 8);
|
||||||
|
|
||||||
|
// First make sure they're different
|
||||||
|
for (uint32 j = 0; j < h; ++j) {
|
||||||
|
for (uint32 i = 0; i < w; ++i) {
|
||||||
|
if ( (i % 8) == 0 && (j % 8) == 0 ) {
|
||||||
|
EXPECT_NEAR(img(i, j), 8.0f, 1e-5);
|
||||||
|
} else {
|
||||||
|
EXPECT_NEAR(img(i, j), 0.0f, 1e-5);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(Image, IDCT) {
|
||||||
|
|
||||||
const uint32 w = 32;
|
const uint32 w = 32;
|
||||||
const uint32 h = 32;
|
const uint32 h = 32;
|
||||||
|
@ -221,7 +248,6 @@ TEST(Image, DCT) {
|
||||||
for (uint32 j = 0; j < h; ++j) {
|
for (uint32 j = 0; j < h; ++j) {
|
||||||
for (uint32 i = 0; i < w; ++i) {
|
for (uint32 i = 0; i < w; ++i) {
|
||||||
img(i, j) = static_cast<FasTC::IPixel>(i + j);
|
img(i, j) = static_cast<FasTC::IPixel>(i + j);
|
||||||
// img(i, j) = static_cast<FasTC::IPixel>(1);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -242,7 +268,7 @@ TEST(Image, DCT) {
|
||||||
|
|
||||||
for (uint32 j = 0; j < h; ++j) {
|
for (uint32 j = 0; j < h; ++j) {
|
||||||
for (uint32 i = 0; i < w; ++i) {
|
for (uint32 i = 0; i < w; ++i) {
|
||||||
EXPECT_NEAR(img(i, j), orig(i, j), 1e-5);
|
EXPECT_NEAR(img(i, j), orig(i, j), 1e-4);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue