mirror of
https://github.com/hrydgard/ppsspp.git
synced 2026-10-01 14:58:14 +00:00
DXT5 fix
This commit is contained in:
1 parent
e59b734b27
commit
3b5770da9b
3 files changed
+22
-21
No files matched your search
@@ -1556,15 +1556,16 @@ static CheckAlphaResult DecodeDXTBlocks(uint8_t *out, int outPitch, uint32_t tex
|
||||
u32 blockIndex = (y / 4) * (bufw / 4);
|
||||
int blockHeight = std::min(h - y, 4);
|
||||
for (int x = 0; x < minw; x += 4) {
|
||||
int blockWidth = std::min(minw - x, 4);
|
||||
switch (n) {
|
||||
case 1:
|
||||
DecodeDXT1Block(dst + outPitch32 * y + x, (const DXT1Block *)src + blockIndex, outPitch32, blockHeight, &alphaSum);
|
||||
DecodeDXT1Block(dst + outPitch32 * y + x, (const DXT1Block *)src + blockIndex, outPitch32, blockWidth, blockHeight, &alphaSum);
|
||||
break;
|
||||
case 3:
|
||||
DecodeDXT3Block(dst + outPitch32 * y + x, (const DXT3Block *)src + blockIndex, outPitch32, blockHeight);
|
||||
DecodeDXT3Block(dst + outPitch32 * y + x, (const DXT3Block *)src + blockIndex, outPitch32, blockWidth, blockHeight);
|
||||
break;
|
||||
case 5:
|
||||
DecodeDXT5Block(dst + outPitch32 * y + x, (const DXT5Block *)src + blockIndex, outPitch32, blockHeight);
|
||||
DecodeDXT5Block(dst + outPitch32 * y + x, (const DXT5Block *)src + blockIndex, outPitch32, blockWidth, blockHeight);
|
||||
break;
|
||||
}
|
||||
blockIndex++;
|
||||
|
||||
@@ -421,9 +421,9 @@ class DXTDecoder {
|
||||
public:
|
||||
inline void DecodeColors(const DXT1Block *src, bool ignore1bitAlpha);
|
||||
inline void DecodeAlphaDXT5(const DXT5Block *src);
|
||||
inline void WriteColorsDXT1(u32 *dst, const DXT1Block *src, int pitch, int height);
|
||||
inline void WriteColorsDXT3(u32 *dst, const DXT3Block *src, int pitch, int height);
|
||||
inline void WriteColorsDXT5(u32 *dst, const DXT5Block *src, int pitch, int height);
|
||||
inline void WriteColorsDXT1(u32 *dst, const DXT1Block *src, int pitch, int width, int height);
|
||||
inline void WriteColorsDXT3(u32 *dst, const DXT3Block *src, int pitch, int width, int height);
|
||||
inline void WriteColorsDXT5(u32 *dst, const DXT5Block *src, int pitch, int width, int height);
|
||||
|
||||
bool AnyNonFullAlpha() const { return anyNonFullAlpha_; }
|
||||
|
||||
@@ -507,11 +507,11 @@ void DXTDecoder::DecodeAlphaDXT5(const DXT5Block *src) {
|
||||
}
|
||||
}
|
||||
|
||||
void DXTDecoder::WriteColorsDXT1(u32 *dst, const DXT1Block *src, int pitch, int height) {
|
||||
void DXTDecoder::WriteColorsDXT1(u32 *dst, const DXT1Block *src, int pitch, int width, int height) {
|
||||
bool anyColor3 = false;
|
||||
for (int y = 0; y < height; y++) {
|
||||
int colordata = src->lines[y];
|
||||
for (int x = 0; x < 4; x++) {
|
||||
for (int x = 0; x < width; x++) {
|
||||
int col = colordata & 3;
|
||||
if (col == 3) {
|
||||
anyColor3 = true;
|
||||
@@ -527,11 +527,11 @@ void DXTDecoder::WriteColorsDXT1(u32 *dst, const DXT1Block *src, int pitch, int
|
||||
}
|
||||
}
|
||||
|
||||
void DXTDecoder::WriteColorsDXT3(u32 *dst, const DXT3Block *src, int pitch, int height) {
|
||||
void DXTDecoder::WriteColorsDXT3(u32 *dst, const DXT3Block *src, int pitch, int width, int height) {
|
||||
for (int y = 0; y < height; y++) {
|
||||
int colordata = src->color.lines[y];
|
||||
u32 alphadata = src->alphaLines[y];
|
||||
for (int x = 0; x < 4; x++) {
|
||||
for (int x = 0; x < width; x++) {
|
||||
dst[x] = colors_[colordata & 3] | (alphadata << 28);
|
||||
colordata >>= 2;
|
||||
alphadata >>= 4;
|
||||
@@ -540,13 +540,13 @@ void DXTDecoder::WriteColorsDXT3(u32 *dst, const DXT3Block *src, int pitch, int
|
||||
}
|
||||
}
|
||||
|
||||
void DXTDecoder::WriteColorsDXT5(u32 *dst, const DXT5Block *src, int pitch, int height) {
|
||||
void DXTDecoder::WriteColorsDXT5(u32 *dst, const DXT5Block *src, int pitch, int width, int height) {
|
||||
// 48 bits, 3 bit index per pixel, 12 bits per line.
|
||||
u64 alphadata = ((u64)(u16)src->alphadata1 << 32) | (u32)src->alphadata2;
|
||||
|
||||
for (int y = 0; y < height; y++) {
|
||||
int colordata = src->color.lines[y];
|
||||
for (int x = 0; x < 4; x++) {
|
||||
for (int x = 0; x < width; x++) {
|
||||
dst[x] = colors_[colordata & 3] | (alpha_[alphadata & 7] << 24);
|
||||
colordata >>= 2;
|
||||
alphadata >>= 3;
|
||||
@@ -619,24 +619,24 @@ uint32_t GetDXT5Texel(const DXT5Block *src, int x, int y) {
|
||||
}
|
||||
|
||||
// This could probably be done faster by decoding two or four blocks at a time with SSE/NEON.
|
||||
void DecodeDXT1Block(u32 *dst, const DXT1Block *src, int pitch, int height, u32 *alpha) {
|
||||
void DecodeDXT1Block(u32 *dst, const DXT1Block *src, int pitch, int width, int height, u32 *alpha) {
|
||||
DXTDecoder dxt;
|
||||
dxt.DecodeColors(src, false);
|
||||
dxt.WriteColorsDXT1(dst, src, pitch, height);
|
||||
dxt.WriteColorsDXT1(dst, src, pitch, width, height);
|
||||
*alpha &= dxt.AnyNonFullAlpha() ? 0 : 1;
|
||||
}
|
||||
|
||||
void DecodeDXT3Block(u32 *dst, const DXT3Block *src, int pitch, int height) {
|
||||
void DecodeDXT3Block(u32 *dst, const DXT3Block *src, int pitch, int width, int height) {
|
||||
DXTDecoder dxt;
|
||||
dxt.DecodeColors(&src->color, true);
|
||||
dxt.WriteColorsDXT3(dst, src, pitch, height);
|
||||
dxt.WriteColorsDXT3(dst, src, pitch, width, height);
|
||||
}
|
||||
|
||||
void DecodeDXT5Block(u32 *dst, const DXT5Block *src, int pitch, int height) {
|
||||
void DecodeDXT5Block(u32 *dst, const DXT5Block *src, int pitch, int width, int height) {
|
||||
DXTDecoder dxt;
|
||||
dxt.DecodeColors(&src->color, true);
|
||||
dxt.DecodeAlphaDXT5(src);
|
||||
dxt.WriteColorsDXT5(dst, src, pitch, height);
|
||||
dxt.WriteColorsDXT5(dst, src, pitch, width, height);
|
||||
}
|
||||
|
||||
#ifdef _M_SSE
|
||||
|
||||
@@ -65,9 +65,9 @@ struct DXT5Block {
|
||||
u8 alpha1; u8 alpha2;
|
||||
};
|
||||
|
||||
void DecodeDXT1Block(u32 *dst, const DXT1Block *src, int pitch, int height, u32 *alpha);
|
||||
void DecodeDXT3Block(u32 *dst, const DXT3Block *src, int pitch, int height);
|
||||
void DecodeDXT5Block(u32 *dst, const DXT5Block *src, int pitch, int height);
|
||||
void DecodeDXT1Block(u32 *dst, const DXT1Block *src, int pitch, int width, int height, u32 *alpha);
|
||||
void DecodeDXT3Block(u32 *dst, const DXT3Block *src, int pitch, int width, int height);
|
||||
void DecodeDXT5Block(u32 *dst, const DXT5Block *src, int pitch, int width, int height);
|
||||
|
||||
uint32_t GetDXT1Texel(const DXT1Block *src, int x, int y);
|
||||
uint32_t GetDXT3Texel(const DXT3Block *src, int x, int y);
|
||||
|
||||
Reference in new issue
Block a user