protected override Bitmap OnGetBitmap(int imageIndex, int paletteIndex) { List <PSSGNode> allTextures = RootNode.FindNodes("TEXTURE"); PSSGNode texNode = allTextures[imageIndex]; Int32 width = Convert.ToInt32(texNode.Attributes["width"].Value); Int32 height = Convert.ToInt32(texNode.Attributes["height"].Value); Int32 numBlocks = Convert.ToInt32(texNode.Attributes["imageBlockCount"].Value); string texelFormat = texNode.Attributes["texelFormat"].Value; PixelDataFormat pixelFormat = PixelDataFormat.Undefined; bool flipY = false; List <PSSGNode> texImageBlocks = texNode.FindNodes("TEXTUREIMAGEBLOCK"); switch (texelFormat) { case "ui8x4": pixelFormat = PixelDataFormat.FormatArgb8888 | PixelDataFormat.PixelOrderingLinear; flipY = true; break; case "u8x4": pixelFormat = PixelDataFormat.FormatAbgr8888 | PixelDataFormat.PixelOrderingLinear; flipY = true; break; case "dxt1": pixelFormat = PixelDataFormat.FormatDXT1Rgba; flipY = true; break; case "dxt5": pixelFormat = PixelDataFormat.FormatDXT5; flipY = true; break; default: throw new NotSupportedException(String.Format("Unsupported PSSG texel Format: {0}", texelFormat)); } /* find out how many raw data blocks there are */ if (numBlocks > 1) { throw new NotSupportedException("Loading PSSG cube maps is not yet supported"); } else { /* we only have a single block. use that */ ImageBinary imgbin = new ImageBinary(); imgbin.Width = width; imgbin.Height = height; imgbin.InputPixelFormat = pixelFormat; imgbin.InputEndianness = Endian.LittleEndian; imgbin.AddInputPixels(texImageBlocks[0].FindNodes("TEXTUREIMAGEBLOCKDATA")[0].Data); Bitmap bmp = imgbin.GetBitmap(); if (flipY) { bmp.RotateFlip(RotateFlipType.RotateNoneFlipY); } return(bmp); } }
protected override void OnOpen(EndianBinaryReader reader) { MagicNumber = Encoding.ASCII.GetString(reader.ReadBytes(4)); reader.Endianness = Endian.BigEndian; FileSize = reader.ReadInt32(); AttributeInfoCount = reader.ReadInt32(); NodeInfoCount = reader.ReadInt32(); AttributeInfo = new PSSGAttributeInfo[AttributeInfoCount]; NodeInfo = new PSSGNodeInfo[NodeInfoCount]; for (int i = 0; i < NodeInfoCount; i++) { NodeInfo[i] = new PSSGNodeInfo(reader); foreach (PSSGAttributeInfo ai in NodeInfo[i].AttributeInfo.Values) { AttributeInfo[ai.ID - 1] = ai; } } RootNode = new PSSGNode(reader, this); }