gpt4 book ai didi

java - 试图解压缩 BC1 纹理压缩的加扰 block

转载 作者:行者123 更新时间:2023-12-04 10:49:14 28 4
gpt4 key购买 nike

我一直在尝试用 Java 实现 BC1 (DXT1) 解压算法。一切似乎都非常精确,但我遇到了透明块周围的一些块的问题。我一直试图解决它几个小时但没有成功。

简而言之,在解压缩所有块之后,除了透明块周围的块外,一切看起来都很好。在开发过程中,我一直在用 C++ 编写的 DirectXTex (texconv) 的结果检查结果。

这是我与 DirectXTex 相比的结果:
enter image description here

这是我正在使用的代码:

BufferedImage decompress(byte[] buffer, int width, int height)

和实现:
  BufferedImage result = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
int[] scanline = new int[4 * width]; //stores 4 horizontal lines (width/4 blocks)

RGBA[] blockPalette = new RGBA[4]; //stores RGBA values of current block

int bufferOffset = 0;

for (int row = 0; row < height / 4; row++) {
for (int col = 0; col < width / 4; col++) {

short rgb0 = Short.reverseBytes(Bytes.getShort(buffer, bufferOffset));
short rgb1 = Short.reverseBytes(Bytes.getShort(buffer, bufferOffset + 2));
int bitmap = Integer.reverseBytes(Bytes.getInt(buffer, bufferOffset + 4));
bufferOffset += 8;

blockPalette[0] = R5G6B5.decode(rgb0);
blockPalette[1] = R5G6B5.decode(rgb1);

if(rgb0 <= rgb1) {
int c2r = (blockPalette[0].getRed() + blockPalette[1].getRed()) / 2;
int c2g = (blockPalette[0].getGreen() + blockPalette[1].getGreen()) / 2;
int c2b = (blockPalette[0].getBlue() + blockPalette[1].getBlue()) / 2;

blockPalette[2] = new RGBA(c2r, c2g, c2b, 255);
blockPalette[3] = new RGBA(0, 0, 0, 0);

} else {
int c2r = (2 * blockPalette[0].getRed() + blockPalette[1].getRed()) / 3;
int c2g = (2 * blockPalette[0].getGreen() + blockPalette[1].getGreen()) / 3;
int c2b = (2 * blockPalette[0].getBlue() + blockPalette[1].getBlue()) / 3;

int c3r = (blockPalette[0].getRed() + 2 * blockPalette[1].getRed()) / 3;
int c3g = (blockPalette[0].getGreen() + 2 * blockPalette[1].getGreen()) / 3;
int c3b = (blockPalette[0].getBlue() + 2 * blockPalette[1].getBlue()) / 3;


blockPalette[2] = new RGBA(c2r, c2g, c2b, 255);
blockPalette[3] = new RGBA(c3r, c3g, c3b, 255);

}

for (int i = 0; i < 16; i++, bitmap >>= 2) {
int pi = (i / 4) * width + (col * 4 + i % 4);
int index = bitmap & 3;
scanline[pi] = A8R8G8B8.encode(blockPalette[index]);
}
}
//copy scanline to buffered image
result.setRGB(0, row * 4, width, 4, scanline, 0, width);
}
return result;

有谁知道问题出在哪里?我一直在做与规范完全相同的步骤: Block Compression (Direct3D 10)

最佳答案

是不是blockPalette[2].set(c2r, c2g, c2b);应该是 blockPalette[2].set(c2r, c2g, c2b, 255); ? (两个地点)

关于java - 试图解压缩 BC1 纹理压缩的加扰 block ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59567528/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com