mirror of
https://github.com/yuzu-emu/FasTC.git
synced 2025-01-08 21:55:34 +00:00
Deal with this bug once and for all. If we have an image in block stream order, then explicitly reorder it before doing any work. Then keep it that way. I probably could have fixed this in the amount of time I've wasted on it. -____-
This commit is contained in:
parent
4de5f90edf
commit
264e447e80
|
@ -206,6 +206,9 @@ int main(int argc, char **argv) {
|
|||
}
|
||||
|
||||
const Image *img = file.GetImage();
|
||||
if(format == eCompressionFormat_PVRTC) {
|
||||
const_cast<Image *>(img)->SetBlockStreamOrder(false);
|
||||
}
|
||||
|
||||
int numBlocks = (img->GetWidth() * img->GetHeight())/16;
|
||||
BlockStatManager *statManager = NULL;
|
||||
|
@ -247,7 +250,6 @@ int main(int argc, char **argv) {
|
|||
if(format == eCompressionFormat_BPTC) {
|
||||
strcat(basename, "-bc7.png");
|
||||
} else if(format == eCompressionFormat_PVRTC) {
|
||||
cImg.SetBlockStreamOrder(false);
|
||||
strcat(basename, "-pvrtc.png");
|
||||
}
|
||||
|
||||
|
|
|
@ -212,6 +212,9 @@ int _tmain(int argc, _TCHAR* argv[])
|
|||
}
|
||||
|
||||
const Image *img = file.GetImage();
|
||||
if(format == eCompressionFormat_PVRTC) {
|
||||
const_cast<Image *>(img)->SetBlockStreamOrder(false);
|
||||
}
|
||||
|
||||
int numBlocks = (img->GetWidth() * img->GetHeight())/16;
|
||||
BlockStatManager *statManager = NULL;
|
||||
|
@ -253,7 +256,6 @@ int _tmain(int argc, _TCHAR* argv[])
|
|||
if(format == eCompressionFormat_BPTC) {
|
||||
strcat_s(basename, "-bc7.png");
|
||||
} else if(format == eCompressionFormat_PVRTC) {
|
||||
cImg.SetBlockStreamOrder(false);
|
||||
strcat_s(basename, "-pvrtc.png");
|
||||
}
|
||||
|
||||
|
|
|
@ -97,6 +97,8 @@ class CompressedImage {
|
|||
// !FIXME! We should have a function to explicitly return the in/out buf
|
||||
// size for a given compressed image.
|
||||
bool DecompressImage(uint8 *outBuf, uint32 outBufSz) const;
|
||||
|
||||
ECompressionFormat GetFormat() const { return m_Format; }
|
||||
};
|
||||
|
||||
#endif // _COMPRESSED_IMAGE_H_
|
||||
|
|
|
@ -70,7 +70,13 @@ class Image {
|
|||
uint32 GetWidth() const { return m_Width; }
|
||||
uint32 GetHeight() const { return m_Height; }
|
||||
|
||||
void SetBlockStreamOrder(bool flag) { m_bBlockStreamOrder = flag; }
|
||||
void SetBlockStreamOrder(bool flag) {
|
||||
if(flag) {
|
||||
ConvertToBlockStreamOrder();
|
||||
} else {
|
||||
ConvertFromBlockStreamOrder();
|
||||
}
|
||||
}
|
||||
bool GetBlockStreamOrder() const { return m_bBlockStreamOrder; }
|
||||
|
||||
private:
|
||||
|
@ -80,6 +86,9 @@ class Image {
|
|||
bool m_bBlockStreamOrder;
|
||||
|
||||
uint8 *m_PixelData;
|
||||
|
||||
void ConvertToBlockStreamOrder();
|
||||
void ConvertFromBlockStreamOrder();
|
||||
};
|
||||
|
||||
#endif // __TEXCOMP_IMAGE_H__
|
||||
|
|
|
@ -117,6 +117,11 @@ Image::Image(const CompressedImage &ci)
|
|||
fprintf(stderr, "Error decompressing image!\n");
|
||||
return;
|
||||
}
|
||||
|
||||
// !HACK!
|
||||
if(ci.GetFormat() == eCompressionFormat_PVRTC) {
|
||||
m_bBlockStreamOrder = false;
|
||||
}
|
||||
}
|
||||
|
||||
Image::Image(const ImageLoader &loader)
|
||||
|
@ -207,3 +212,55 @@ double Image::ComputePSNR(const CompressedImage &ci) const {
|
|||
delete unCompData;
|
||||
return PSNR;
|
||||
}
|
||||
|
||||
void Image::ConvertToBlockStreamOrder() {
|
||||
if(m_bBlockStreamOrder || !m_PixelData)
|
||||
return;
|
||||
|
||||
uint32 *newPixelData = new uint32[GetWidth() * GetHeight() * 4];
|
||||
for(uint32 j = 0; j < GetHeight(); j+=4) {
|
||||
for(uint32 i = 0; i < GetWidth(); i+=4) {
|
||||
uint32 blockX = i / 4;
|
||||
uint32 blockY = j / 4;
|
||||
uint32 blockIdx = blockY * (GetWidth() / 4) + blockX;
|
||||
|
||||
uint32 offset = blockIdx * 4 * 4;
|
||||
for(uint32 t = 0; t < 16; t++) {
|
||||
uint32 x = i + t % 4;
|
||||
uint32 y = j + t / 4;
|
||||
newPixelData[offset + t] =
|
||||
reinterpret_cast<uint32 *>(m_PixelData)[y*GetWidth() + x];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
delete m_PixelData;
|
||||
m_PixelData = reinterpret_cast<uint8 *>(newPixelData);
|
||||
m_bBlockStreamOrder = true;
|
||||
}
|
||||
|
||||
void Image::ConvertFromBlockStreamOrder() {
|
||||
if(!m_bBlockStreamOrder || !m_PixelData)
|
||||
return;
|
||||
|
||||
uint32 *newPixelData = new uint32[GetWidth() * GetHeight() * 4];
|
||||
for(uint32 j = 0; j < GetHeight(); j+=4) {
|
||||
for(uint32 i = 0; i < GetWidth(); i+=4) {
|
||||
uint32 blockX = i / 4;
|
||||
uint32 blockY = j / 4;
|
||||
uint32 blockIdx = blockY * (GetWidth() / 4) + blockX;
|
||||
|
||||
uint32 offset = blockIdx * 4 * 4;
|
||||
for(uint32 t = 0; t < 16; t++) {
|
||||
uint32 x = i + t % 4;
|
||||
uint32 y = j + t / 4;
|
||||
newPixelData[y*GetWidth() + x] =
|
||||
reinterpret_cast<uint32 *>(m_PixelData)[offset + t];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
delete m_PixelData;
|
||||
m_PixelData = reinterpret_cast<uint8 *>(newPixelData);
|
||||
m_bBlockStreamOrder = false;
|
||||
}
|
||||
|
|
|
@ -137,14 +137,8 @@ namespace PVRTCC {
|
|||
Image img(dcj.height, dcj.width);
|
||||
uint32 nPixels = dcj.height * dcj.width;
|
||||
for(uint32 i = 0; i < nPixels; i++) {
|
||||
// Assume block stream order (whyyyy)
|
||||
uint32 blockIdx = i / 16;
|
||||
uint32 blockWidth = dcj.width / 4;
|
||||
uint32 blockX = blockIdx % blockWidth;
|
||||
uint32 blockY = blockIdx / blockWidth;
|
||||
|
||||
uint32 x = blockX * 4 + (i % 4);
|
||||
uint32 y = blockY * 4 + (i % 16) / 4;
|
||||
uint32 x = i % dcj.width;
|
||||
uint32 y = i / dcj.width;
|
||||
|
||||
const uint32 *pixels = reinterpret_cast<const uint32 *>(dcj.inBuf);
|
||||
img(x, y).UnpackRGBA(pixels[i]);
|
||||
|
|
Loading…
Reference in a new issue