public DDS(ParsedBitmap.BitmapInfo bmInfo, FileStream fs) { this.classType = classTypes.DDS; this.BitsPerPixel = bmInfo.bitsPerPixel; this.Width = bmInfo.width; this.Height = bmInfo.height; this.Depth = bmInfo.depth; this.Format = bmInfo.format; this.FormatName = bmInfo.formatname; this.Compressed = bmInfo.format.ToString().ToUpper().Contains("DXT"); this.Swizzle = bmInfo.swizzle; this.MipMapCount = bmInfo.mipMapCount; this.stream = fs; this.streamOffset = (int)fs.Position; this.streamSize = (int)fs.Length; }
public DDS(ParsedBitmap.BitmapInfo bmInfo, FileStream fs) { this.classType = classTypes.DDS; this.BitsPerPixel = bmInfo.bitsPerPixel; this.Width = bmInfo.width; this.Height = bmInfo.height; this.Depth = bmInfo.depth; this.Format = bmInfo.format; this.FormatName = bmInfo.formatname; this.Compressed = bmInfo.format.ToString().ToUpper().Contains("DXT"); this.Swizzle = bmInfo.swizzle; this.MipMapCount = bmInfo.mipMapCount; this.stream = fs; this.streamOffset = (int)fs.Position; this.streamSize = (int)fs.Length; }
public void loadDDSInfo(string filename, ParsedBitmap pb) { FileStream fs = new FileStream(filename, FileMode.Open); BinaryReader br = new BinaryReader(fs); dds.ReadStruct(ref br); // Determine Format Type ParsedBitmap.BitmapType bitmapType = ParsedBitmap.BitmapType.BITM_TYPE_2D; if (((int)DDS.DDSEnum.DDSCAPS2_VOLUME & dds.ddsd.ddsCaps.caps2) > 0) { bitmapType = ParsedBitmap.BitmapType.BITM_TYPE_3D; } else if (((int)DDS.DDSEnum.DDSCAPS2_CUBEMAP & dds.ddsd.ddsCaps.caps2) > 0) { bitmapType = ParsedBitmap.BitmapType.BITM_TYPE_CUBEMAP; } // Used to display external (file) bitmap to be injected int tempsize = dds.ddsd.width * dds.ddsd.height; switch (dds.ddsd.ddfPixelFormat.FourCC) { case "DXT1": tempsize /= 2; break; case "DXT2": case "DXT3": case "DXT4": case "DXT5": // tempsize /= 1; break; // for non-compressed default: tempsize *= dds.ddsd.ddfPixelFormat.RGBBitCount >> 3; break; } int widthPad = 0; if (dds.ddsd.width % 16 != 0) { widthPad = 16 - dds.ddsd.width % 16; } int byteStep = dds.ddsd.ddfPixelFormat.RGBBitCount / 8; /* * int totalSize = tempsize + (dds.ddsd.height * widthPad * byteStep); * if (bitmapType == ParsedBitmap.BitmapType.BITM_TYPE_CUBEMAP) * totalSize *= 6; * byte[] guh = new byte[totalSize]; */ byte[] guh = new byte[br.BaseStream.Length - br.BaseStream.Position]; // + (widthPad * dds.ddsd.height * byteStep)]; br.BaseStream.Read(guh, 0, guh.Length); // Determine DDS Format ParsedBitmap.BitmapFormat bmf = DDS.getBitmapFormat(dds); // G8B8 same as A8Y8 (found as A8Y8), but adjusted to 128 as center if (bmf == ParsedBitmap.BitmapFormat.BITM_FORMAT_A8Y8 && pb.Properties[0].formatname == ParsedBitmap.BitmapFormat.BITM_FORMAT_G8B8) { for (int ii = 0; ii < guh.Length; ii++) { guh[ii] += 128; } bmf = ParsedBitmap.BitmapFormat.BITM_FORMAT_G8B8; } pbSourceDDS.Image = ParsedBitmap.DecodeBitm( guh, dds.ddsd.height, dds.ddsd.width, dds.ddsd.depth, dds.ddsd.ddfPixelFormat.RGBBitCount, bitmapType, bmf, false, null, -1, -1); br.Close(); fs.Close(); #region Fill the source info box with the DDS information this.lbSourceDDS.Items.Add("Aspect : " + dds.ddsd.width + "x" + dds.ddsd.height); this.lbSourceDDS.Items.Add("w/ Pad : " + (dds.ddsd.width + widthPad) + "x" + dds.ddsd.height); int bpp = 32; string format = string.Empty; switch (dds.ddsd.ddfPixelFormat.FourCC) { case "DXT1": format = "DXT1"; break; case "DXT2": case "DXT3": format = "DXT2AND3"; break; case "DXT4": case "DXT5": format = "DXT4AND5"; break; default: bpp = dds.ddsd.ddfPixelFormat.RGBBitCount; int aCount = 0; int rCount = 0; int gCount = 0; int bCount = 0; for (int i = 0; i < bpp; i++) { // # of alpha bits if ((dds.ddsd.ddfPixelFormat.RGBAlphaBitMask & (1 << i)) != 0) { aCount++; } // # of red bits if ((dds.ddsd.ddfPixelFormat.RBitMask & (1 << i)) != 0) { rCount++; } // # of green bits if ((dds.ddsd.ddfPixelFormat.GBitMask & (1 << i)) != 0) { gCount++; } // # of blue bits if ((dds.ddsd.ddfPixelFormat.BBitMask & (1 << i)) != 0) { bCount++; } } if ((aCount > 0) && ((dds.ddsd.ddfPixelFormat.Flags & 0x03) > 0)) { format += "A" + aCount; } else if (bpp - (rCount + gCount + bCount) > 0) { format += "X" + (bpp - (rCount + gCount + bCount)); } if (rCount > 0) { format += "R" + rCount; } if (gCount > 0) { format += "G" + gCount; } if (bCount > 0) { format += "B" + bCount; } break; } lbSourceDDS.Items.Add("BPP : " + bpp); lbSourceDDS.Items.Add("Type : " + bitmapType.ToString().Substring(10)); lbSourceDDS.Items.Add("Format : " + format); // remove "BITMAP_FORMAT_" lbSourceDDS.Items.Add("# Mips : " + Math.Max(dds.ddsd.MipMapCount - 1, 0)); #endregion }