/// <summary> /// Decompress DXTC /// </summary> /// <param name="reader"></param> /// <param name="width"></param> /// <param name="height"></param> /// <param name="inputFormat"></param> /// <param name="readLength"></param> /// <param name="bUseVitaSwizzled"></param> /// <returns></returns> public static byte[] Decompress(EndianBinaryReader reader, int width, int height, PixelDataFormat inputFormat, long readLength, bool bUseVitaSwizzled = false) { byte[] outPixels = new byte[readLength * 8]; DXTxBlockDecoderDelegate blockDecoder; DXTxBlockLayout blockLayout; PixelDataFormat specialFormat = (inputFormat & PixelDataFormat.MaskSpecial); switch (specialFormat) { case PixelDataFormat.SpecialFormatDXT1: blockDecoder = DecodeDXT1Block; blockLayout = DXTxBlockLayout.Normal; break; case PixelDataFormat.SpecialFormatDXT3: blockDecoder = DecodeDXT3Block; blockLayout = DXTxBlockLayout.Normal; break; case PixelDataFormat.SpecialFormatDXT5: blockDecoder = DecodeDXT5Block; blockLayout = DXTxBlockLayout.Normal; break; case PixelDataFormat.SpecialFormatDXT1_PSP: blockDecoder = DecodeDXT1Block; blockLayout = DXTxBlockLayout.PSP; break; case PixelDataFormat.SpecialFormatDXT3_PSP: blockDecoder = DecodeDXT3Block; blockLayout = DXTxBlockLayout.PSP; break; case PixelDataFormat.SpecialFormatDXT5_PSP: blockDecoder = DecodeDXT5Block; blockLayout = DXTxBlockLayout.PSP; break; default: throw new Exception("Trying to decode DXT with format set to non-DXT"); } for (int y = 0; y < height; y += 4) { for (int x = 0; x < width; x += 4) { byte[] decompressedBlock = blockDecoder(reader, inputFormat, blockLayout); int rx, ry; if (bUseVitaSwizzled) { TextureTool.GetVitaSwizzledTransform(x / 4, y / 4, width / 4, height / 4, out rx, out ry); } else { rx = x / 4; ry = y / 4; } rx *= 4; ry *= 4; for (int py = 0; py < 4; py++) { for (int px = 0; px < 4; px++) { int ix = (rx + px); int iy = (ry + py); if (ix >= width || iy >= height) { continue; } for (int c = 0; c < 4; c++) { outPixels[(((iy * width) + ix) * 4) + c] = decompressedBlock[(((py * 4) + px) * 4) + c]; } } } } } return(outPixels); }