/// <summary> /// Returns the uncompressed image as a bytarray in the 32pppRGBA-Format /// </summary> private byte[] GetImageBytes(int w, int h, byte[] data) { byte[] pic; switch (encoding) { case 1: pic = GetPictureUncompressedByteArray(w, h, data); break; case 2: var flag = (alphaDepth > 1) ? ((alphaEncoding == 7) ? (int)DXTDecompression.DXTFlags.DXT5 : (int)DXTDecompression.DXTFlags.DXT3) : (int)DXTDecompression.DXTFlags.DXT1; pic = DXTDecompression.DecompressImage(w, h, data, flag); break; case 3: pic = data; break; default: pic = new byte[0]; break; } return(pic); }
/// <summary> /// Returns the uncompressed image as a bytarray in the 32pppRGBA-Format /// </summary> private byte[] GetImageBytes(int w, int h, byte[] data) { switch (colorEncoding) { case 1: return(GetPictureUncompressedByteArray(w, h, data)); case 2: DXTDecompression.DXTFlags flag = (alphaDepth > 1) ? ((alphaEncoding == 7) ? DXTDecompression.DXTFlags.DXT5 : DXTDecompression.DXTFlags.DXT3) : DXTDecompression.DXTFlags.DXT1; return(DXTDecompression.DecompressImage(w, h, data, flag)); case 3: return(data); default: return(new byte[0]); } }
/// <summary> /// Returns the uncompressed image as a byte array in the 32pppRGBA-Format /// </summary> private byte[] GetImageBytes(int w, int h, byte[] data) { switch (colorEncoding) { case BlpColorEncoding.Jpeg: { using (var img = SixLabors.ImageSharp.Image.Load <Rgba32>(data)) { if (img.TryGetSinglePixelSpan(out var pixels)) { return(MemoryMarshal.AsBytes(pixels).ToArray()); } throw new Exception("img.TryGetSinglePixelSpan failed"); } //using (var img = SixLabors.ImageSharp.Image.Load<Rgba32>(data)) //{ // var map = img.GetPixelSpan(); // byte[] rgba = new byte[width * height * 4]; // for (int i = 0; i < rgba.Length; i += 4) // { // rgba[i + 0] = map[i / 4].R; // rgba[i + 1] = map[i / 4].G; // rgba[i + 2] = map[i / 4].B; // rgba[i + 3] = map[i / 4].A; // } // return rgba; //} } case BlpColorEncoding.Palette: return(GetPictureUncompressedByteArray(w, h, data)); case BlpColorEncoding.Dxt: DXTDecompression.DXTFlags flag = (alphaSize > 1) ? ((preferredFormat == BlpPixelFormat.Dxt5) ? DXTDecompression.DXTFlags.DXT5 : DXTDecompression.DXTFlags.DXT3) : DXTDecompression.DXTFlags.DXT1; return(DXTDecompression.DecompressImage(w, h, data, flag)); case BlpColorEncoding.Argb8888: return(data); default: return(new byte[0]); } }
/// <summary> /// Returns the uncompressed image as a bytarray in the 32pppRGBA-Format /// </summary> /// <param name="MipmapLevel">The desired Mipmap-Level. If the given level is invalid, the smallest available level is choosen</param> /// <returns></returns> public byte[] getImageBytes(int MipmapLevel) { byte[] pic; if (this.encoding == 2) { // Determine the correct DXT-Format int flag = (this.alphaDepth > 1) ? ((this.alphaEncoding == 7) ? (int)DXTDecompression.DXTFlags.DXT5 : (int)DXTDecompression.DXTFlags.DXT3) : (int)DXTDecompression.DXTFlags.DXT1; // Decompress the picture DXTDecompression.decompressImage(out pic, (this.width / (int)(Math.Pow(2, MipmapLevel))), (this.height / (int)(Math.Pow(2, MipmapLevel))), this.getPictureData(MipmapLevel), flag); } else { // Using the palette to determine the color pic = this.getPictureUncompressedByteArray(MipmapLevel); } return(pic); }