public DDSTexture(Image image, int mipMapCount, IMGPixelFormat pixelFormat, bool unkBool1) { this.MipMapCount = mipMapCount; this.PixelFormat = pixelFormat; this.Size = image.Size; this.ChangeImageProbably(image, mipMapCount, pixelFormat, unkBool1); }
public void ChangeImageProbably(Image image_0, int int_2, IMGPixelFormat imgpixelFormat_1, bool bool_0) { MemoryStream memoryStream = new MemoryStream(); BinaryWriter binaryWriter = new BinaryWriter(memoryStream); for (int i = 0; i < int_2; i++) { Bitmap bitmap = KeyGenerator.ScaleImageFixedRatio(image_0, Math.Max(1, image_0.Width >> i), Math.Max(1, image_0.Height >> i)); if (imgpixelFormat_1 == IMGPixelFormat.Bgra32) { BitmapData bitmapData = bitmap.LockBits(new Rectangle(0, 0, bitmap.Width, bitmap.Height), ImageLockMode.ReadWrite, bitmap.PixelFormat); byte[] array = new byte[bitmapData.Stride * bitmap.Height]; Marshal.Copy(bitmapData.Scan0, array, 0, array.Length); bitmap.UnlockBits(bitmapData); binaryWriter.Write(array); } else { zzTextureClass.smethod_16(bitmap, binaryWriter, imgpixelFormat_1, bool_0); } } this.MipMapCount = int_2; this.PixelFormat = imgpixelFormat_1; this.data = memoryStream.ToArray(); }
public void method_1(int int_0, Image image_0, IMGPixelFormat imgpixelFormat_0) { TextureMetadata @class = this.textureList[int_0]; @class.Height = (short)image_0.Height; @class.Width = (short)image_0.Width; @class.Data = new DDSTexture(image_0, (int)@class.MipMapCount, imgpixelFormat_0).ToByteArray(); }
public static void smethod_16(Bitmap bitmap_0, BinaryWriter binaryWriter_0, IMGPixelFormat imgpixelFormat_0, bool bool_1) { int height = bitmap_0.Height; int width = bitmap_0.Width; if (!zzTextureClass.bool_0) { zzTextureClass.smethod_0(); } for (int i = 0; i < height; i += 4) { for (int j = 0; j < width; j += 4) { Color[] array = new Color[16]; int num = 0; for (int k = 0; k < 4; k++) { for (int l = 0; l < 4; l++) { if (j + l < width && i + k < height) { array[num++] = bitmap_0.GetPixel(j + l, i + k); } } } if (imgpixelFormat_0 == IMGPixelFormat.Dxt3) { binaryWriter_0.Write(zzTextureClass.smethod_14(array)); } else if (imgpixelFormat_0 == IMGPixelFormat.Dxt5) { binaryWriter_0.Write(zzTextureClass.smethod_15(array)); } zzTextureClass.smethod_12(array, bool_1).method_0(binaryWriter_0); } } }
private void ImgList_SelectedIndexChanged(object sender, EventArgs e) { if (this.ImgList.SelectedIndex >= 0) { DDSTexture texture = _texFile[this.ImgList.SelectedIndex]; _currentTexturePixelFormat = texture.PixelFormat; BPPTxt.Text = string.Concat(texture.BPP); FormatTxt.Text = ((texture.PixelFormat == IMGPixelFormat.Dxt1) ? "DXT1" : ((texture.PixelFormat == IMGPixelFormat.Dxt3) ? "DXT3" : ((texture.PixelFormat == IMGPixelFormat.Dxt5) ? "DXT5" : "A8R8G8B8"))); MipMapTxt.Text = string.Concat(texture.MipMapCount); WidthTxt.Text = string.Concat(texture.Size.Width); HeightTxt.Text = string.Concat(texture.Size.Height); Image image = texture.GetImage(); this.size_0 = image.Size; if (image.Width > this.ImagePreviewBox.Width || image.Height > this.ImagePreviewBox.Height) { image = KeyGenerator.ScaleImageFixedRatio(image, ImagePreviewBox.Size); } this.ImagePreviewBox.Image = image; this.ImageInfoBox.Enabled = true; return; } this.ImageInfoBox.Enabled = false; }
public static void smethod_17(BinaryReader binaryReader_0, Class219 class219_0, IMGPixelFormat imgpixelFormat_0) { zzTextureClass.Tom[] array = new zzTextureClass.Tom[16]; int num = class219_0.method_1(); int num2 = class219_0.method_0(); for (int i = 0; i < num; i += 4) { for (int j = 0; j < num2; j += 4) { if (imgpixelFormat_0 == IMGPixelFormat.Dxt3) { ushort[] array2 = new ushort[4]; for (int k = 0; k < 4; k++) { for (int l = 0; l < 4; l++) { if (l == 0) { array2[k] = binaryReader_0.ReadUInt16(); } array[k * 4 + l].float_0 = (float)(array2[k] & 15) / 15f; ushort[] expr_74_cp_0 = array2; int expr_74_cp_1 = k; expr_74_cp_0[expr_74_cp_1] = (ushort)(expr_74_cp_0[expr_74_cp_1] >> 4); } } } else if (imgpixelFormat_0 == IMGPixelFormat.Dxt5) { byte[] array3 = binaryReader_0.ReadBytes(2); byte[] array4 = binaryReader_0.ReadBytes(6); float[] array5 = new float[8]; array5[0] = (float)array3[0] / 255f; array5[1] = (float)array3[1] / 255f; int num3 = 4; if (array3[0] > array3[1]) { num3 = 6; } else { array5[6] = 0f; array5[7] = 1f; } float num4 = 1f / (float)(num3 + 1); for (int m = 0; m < num3; m++) { float num5 = (float)(num3 - m) * num4; float num6 = (float)(m + 1) * num4; array5[m + 2] = num5 * (float)array3[0] + num6 * (float)array3[1]; } for (int n = 0; n < 16; n++) { //Console.WriteLine("Broken"); int div = (n * 3) / 8; int rem = (n * 3) % 8; byte b = (byte)((array4[div] >> rem) & 7); if (rem > 5) { byte b2 = (byte)((array4[div + 1] << (8 - rem)) & 0xFF); b |= (byte)(b2 & 7); } array[n].float_0 = array5[b]; } } zzTextureClass.Jerry @struct = zzTextureClass.Jerry.smethod_0(binaryReader_0); zzTextureClass.Tom[] array6 = new zzTextureClass.Tom[4]; array6[0].float_1 = (float)((@struct.ushort_0 & 63488) >> 11) / 31f; array6[0].float_2 = (float)((@struct.ushort_0 & 2016) >> 5) / 63f; array6[0].float_3 = (float)(@struct.ushort_0 & 31) / 31f; array6[1].float_1 = (float)((@struct.ushort_1 & 63488) >> 11) / 31f; array6[1].float_2 = (float)((@struct.ushort_1 & 2016) >> 5) / 63f; array6[1].float_3 = (float)(@struct.ushort_1 & 31) / 31f; if (imgpixelFormat_0 == IMGPixelFormat.Dxt1 && @struct.ushort_0 <= @struct.ushort_1) { array6[2] = zzTextureClass.Tom.smethod_1(zzTextureClass.Tom.smethod_2(array6[0], array6[1]), 0.5f); array6[3] = default(zzTextureClass.Tom); } else { array6[2] = zzTextureClass.Tom.smethod_1(zzTextureClass.Tom.smethod_2(zzTextureClass.Tom.smethod_0(2f, array6[0]), array6[1]), 0.333333343f); array6[3] = zzTextureClass.Tom.smethod_1(zzTextureClass.Tom.smethod_2(array6[0], zzTextureClass.Tom.smethod_0(2f, array6[1])), 0.333333343f); } for (int num9 = 0; num9 < 4; num9++) { for (int num10 = 0; num10 < 4; num10++) { if (j + num10 < num2 && i + num9 < num) { Point point_ = new Point(j + num10, i + num9); uint num11 = @struct.uint_0 & 3u; if (imgpixelFormat_0 == IMGPixelFormat.Dxt1) { class219_0.method_6(point_, Color.FromArgb((int)((byte)(array6[(int)((UIntPtr)num11)].float_0 * 255f)), (int)((byte)(array6[(int)((UIntPtr)num11)].float_1 * 255f)), (int)((byte)(array6[(int)((UIntPtr)num11)].float_2 * 255f)), (int)((byte)(array6[(int)((UIntPtr)num11)].float_3 * 255f)))); } else { class219_0.method_6(point_, Color.FromArgb((int)((byte)(array[num9 * 4 + num10].float_0 * 255f)), (int)((byte)(array6[(int)((UIntPtr)num11)].float_1 * 255f)), (int)((byte)(array6[(int)((UIntPtr)num11)].float_2 * 255f)), (int)((byte)(array6[(int)((UIntPtr)num11)].float_3 * 255f)))); } } @struct.uint_0 >>= 2; } } } } }
public DDSTexture(Image image_0, int int_2, IMGPixelFormat imgpixelFormat_1) : this(image_0, int_2, imgpixelFormat_1, true) { }
private void Load(Stream stream, bool leaveOpen) { BinaryReader binaryReader = new BinaryReader(stream); if (new string(binaryReader.ReadChars(4)) != "DDS ") { throw new FileLoadException("Invalid DDS file"); } DDSTexture.DDSHeader header; header.size = binaryReader.ReadUInt32(); header.flags = binaryReader.ReadUInt32(); header.height = binaryReader.ReadUInt32(); header.width = binaryReader.ReadUInt32(); header.pitchOrLinearSize = binaryReader.ReadUInt32(); header.depth = binaryReader.ReadUInt32(); header.mipMapCount = binaryReader.ReadUInt32(); binaryReader.ReadBytes(44); header.pixelFormat.size = binaryReader.ReadUInt32(); header.pixelFormat.flags = binaryReader.ReadUInt32(); header.pixelFormat.fourCC = binaryReader.ReadUInt32(); header.pixelFormat.rgbBitCount = binaryReader.ReadUInt32(); header.pixelFormat.redBitMask = binaryReader.ReadUInt32(); header.pixelFormat.greenBitMask = binaryReader.ReadUInt32(); header.pixelFormat.BlueBitMask = binaryReader.ReadUInt32(); header.pixelFormat.AlphaBitMask = binaryReader.ReadUInt32(); header.unk1 = binaryReader.ReadUInt32(); header.unk2 = binaryReader.ReadUInt32(); binaryReader.ReadBytes(12); if (header.size == 124u) { if (header.pixelFormat.size == 32u) { if ((header.flags & 131072u) != 0u) { this.MipMapCount = (int)header.mipMapCount; } else { this.MipMapCount = 1; } this.Size = new Size((int)header.width, (int)header.height); if ((header.pixelFormat.flags & 4u) != 0u) { uint uint_ = header.pixelFormat.fourCC; if (uint_ > 116u) { if (uint_ <= 844388420u) { if (uint_ == 827611204u) { this.PixelFormat = IMGPixelFormat.Dxt1; this.BPP = 8; goto IL_3BE; } if (uint_ != 844388420u) { goto IL_2D5; } } else if (uint_ != 861165636u) { if (uint_ != 877942852u && uint_ != 894720068u) { goto IL_2D5; } this.PixelFormat = IMGPixelFormat.Dxt5; this.BPP = 16; goto IL_3BE; } this.PixelFormat = IMGPixelFormat.Dxt3; this.BPP = 16; goto IL_3BE; } if (uint_ <= 28u) { switch (uint_) { case 20u: this.PixelFormat = IMGPixelFormat.Bgr24; this.BPP = 3; goto IL_3BE; case 21u: this.PixelFormat = IMGPixelFormat.Bgra32; this.BPP = 4; goto IL_3BE; case 22u: break; case 23u: this.PixelFormat = IMGPixelFormat.Bgr16; this.BPP = 2; goto IL_3BE; default: if (uint_ == 28u) { this.PixelFormat = IMGPixelFormat.Alpha8; this.BPP = 1; goto IL_3BE; } break; } } else { if (uint_ == 50u) { this.PixelFormat = IMGPixelFormat.Luminance8; this.BPP = 1; goto IL_3BE; } if (uint_ == 113u) { this.PixelFormat = IMGPixelFormat.Rgba64Float; this.BPP = 8; goto IL_3BE; } if (uint_ == 116u) { this.PixelFormat = IMGPixelFormat.Rgba128Float; this.BPP = 16; goto IL_3BE; } } IL_2D5: this.PixelFormat = IMGPixelFormat.Bgra32; this.BPP = 4; } else { if (header.pixelFormat.rgbBitCount == 8u && header.pixelFormat.AlphaBitMask == 255u) { this.PixelFormat = IMGPixelFormat.Alpha8; this.BPP = 1; } if (header.pixelFormat.rgbBitCount == 32u && header.pixelFormat.redBitMask == 16711680u && header.pixelFormat.greenBitMask == 65280u && header.pixelFormat.BlueBitMask == 255u && header.pixelFormat.AlphaBitMask == 4278190080u) { this.PixelFormat = IMGPixelFormat.Bgra32; this.BPP = 4; } if (this.BPP == 0) { throw new FileLoadException("Invalid Texture Format"); } } IL_3BE: byte[] array = new byte[header.width * header.height * (uint)this.BPP]; stream.Read(array, 0, array.Length); this.data = array; if (leaveOpen) { return; } stream.Close(); stream.Dispose(); return; } } throw new FileLoadException("Unable to read DDS file: wrong format"); }