mirror of
https://github.com/yuzu-emu/FasTC.git
synced 2025-01-09 15:15:38 +00:00
Force PSNR comparison between images to use the same pixeltype
This commit is contained in:
parent
72697f650c
commit
654ee23446
|
@ -95,10 +95,7 @@ namespace FasTC {
|
||||||
}
|
}
|
||||||
bool GetBlockStreamOrder() const { return m_bBlockStreamOrder; }
|
bool GetBlockStreamOrder() const { return m_bBlockStreamOrder; }
|
||||||
|
|
||||||
template<typename OtherPixelType>
|
double ComputePSNR(Image<PixelType> *other);
|
||||||
double ComputePSNR(Image<OtherPixelType> *other) {
|
|
||||||
return FasTC::ComputePSNR(this, other);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Function to allow derived classes to populate the pixel array.
|
// Function to allow derived classes to populate the pixel array.
|
||||||
// This may involve decompressing a compressed image or otherwise
|
// This may involve decompressing a compressed image or otherwise
|
||||||
|
|
|
@ -166,28 +166,28 @@ const PixelType & Image<PixelType>::operator()(uint32 i, uint32 j) const {
|
||||||
return m_Pixels[j * GetWidth() + i];
|
return m_Pixels[j * GetWidth() + i];
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename PixelTypeOne, typename PixelTypeTwo>
|
template<typename PixelType>
|
||||||
double ComputePSNR(Image<PixelTypeOne> *img1, Image<PixelTypeTwo> *img2) {
|
double Image<PixelType>::ComputePSNR(Image<PixelType> *other) {
|
||||||
if(!img1 || !img2)
|
if(!other)
|
||||||
return -1.0;
|
return -1.0;
|
||||||
|
|
||||||
if(img1->GetWidth() != img2->GetWidth() ||
|
if(GetWidth() != other->GetWidth() ||
|
||||||
img1->GetHeight() != img2->GetHeight()) {
|
GetHeight() != other->GetHeight()) {
|
||||||
return -1.0;
|
return -1.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Compute raw 8-bit RGBA data...
|
// Compute raw 8-bit RGBA data...
|
||||||
img1->ComputePixels();
|
ComputePixels();
|
||||||
img2->ComputePixels();
|
other->ComputePixels();
|
||||||
|
|
||||||
const PixelTypeOne *ourPixels = img1->GetPixels();
|
const PixelType *ourPixels = GetPixels();
|
||||||
const PixelTypeTwo *otherPixels = img2->GetPixels();
|
const PixelType *otherPixels = other->GetPixels();
|
||||||
|
|
||||||
// const double w[3] = { 0.2126, 0.7152, 0.0722 };
|
// const double w[3] = { 0.2126, 0.7152, 0.0722 };
|
||||||
const double w[3] = { 1.0, 1.0, 1.0 };
|
const double w[3] = { 1.0, 1.0, 1.0 };
|
||||||
|
|
||||||
double mse = 0.0;
|
double mse = 0.0;
|
||||||
const uint32 imageSz = img1->GetNumPixels();
|
const uint32 imageSz = GetNumPixels();
|
||||||
for(uint32 i = 0; i < imageSz; i++) {
|
for(uint32 i = 0; i < imageSz; i++) {
|
||||||
|
|
||||||
uint32 ourPixel = ourPixels[i].Pack();
|
uint32 ourPixel = ourPixels[i].Pack();
|
||||||
|
@ -211,15 +211,13 @@ double ComputePSNR(Image<PixelTypeOne> *img1, Image<PixelTypeTwo> *img2) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
mse /= img1->GetWidth() * img1->GetHeight();
|
mse /= GetWidth() * GetHeight();
|
||||||
|
|
||||||
const double C = 255.0 * 255.0;
|
const double C = 255.0 * 255.0;
|
||||||
double maxi = (w[0]*w[0] + w[1]*w[1] + w[2]*w[2]) * C;
|
double maxi = (w[0]*w[0] + w[1]*w[1] + w[2]*w[2]) * C;
|
||||||
return 10 * log10(maxi/mse);
|
return 10 * log10(maxi/mse);
|
||||||
}
|
}
|
||||||
|
|
||||||
template double ComputePSNR(Image<Pixel> *, Image<Pixel> *);
|
|
||||||
|
|
||||||
// !FIXME! These won't work for non-RGBA8 data.
|
// !FIXME! These won't work for non-RGBA8 data.
|
||||||
template<typename PixelType>
|
template<typename PixelType>
|
||||||
void Image<PixelType>::ConvertToBlockStreamOrder() {
|
void Image<PixelType>::ConvertToBlockStreamOrder() {
|
||||||
|
|
Loading…
Reference in a new issue