/// <summary> /// Inherited from <see cref="RwNode"/>. Writes the data beyond the header. /// </summary> /// <param name="writer">The <see cref="BinaryWriter"/> to write the data with.</param> protected internal override void WriteBody(BinaryWriter writer) { if (RasterInfoStructNode.Format.HasFlagUnchecked(RwRasterFormats.HasHeaders)) { writer.Write(mImageHeader.GetBytes()); } if (PS2PixelFormatHelper.IsIndexedPixelFormat(RasterInfoStructNode.Tex0Register.TexturePixelFormat)) { WriteIndices(writer); if (RasterInfoStructNode.Format.HasFlagUnchecked(RwRasterFormats.HasHeaders)) { writer.Write(mPaletteHeader.GetBytes()); } WritePalette(writer); } else { WritePixels(writer); } writer.Write(mMipMapData); }
/// <summary> /// Initializer only to be called by the <see cref="RwNodeFactory"/>. /// </summary> internal RwRasterDataStructNode(RwNodeFactory.RwNodeHeader header, BinaryReader reader) : base(header) { long start = reader.BaseStream.Position; if (RasterInfoStructNode.Format.HasFlagUnchecked(RwRasterFormats.HasHeaders)) { mImageHeader = new PS2StandardImageHeader(reader); } if (PS2PixelFormatHelper.IsIndexedPixelFormat(RasterInfoStructNode.Tex0Register.TexturePixelFormat)) { ReadIndices(reader); if (RasterInfoStructNode.Format.HasFlagUnchecked(RwRasterFormats.HasHeaders)) { mPaletteHeader = new PS2StandardImageHeader(reader); } ReadPalette(reader); } else { ReadPixels(reader); } long end = reader.BaseStream.Position; mMipMapData = reader.ReadBytes((int)((start + Size) - end)); }
/// <summary> /// Initialize a new instanc eof <see cref="RwRasterDataStructNode"/> using a given bitmap and a PS2 <see cref="PS2.Graphics.PS2PixelFormat"/> to encode the bitmap to. /// </summary> /// <param name="bitmap">Bitmap to be encoded using the given pixel format.</param> /// <param name="pixelFormat">The pixel format the bitmap will be encoded to and stored in the texture data.</param> public RwRasterDataStructNode(Bitmap bitmap, PS2PixelFormat pixelFormat) : base(RwNodeId.RwStructNode) { if (PS2PixelFormatHelper.IsIndexedPixelFormat(pixelFormat)) { BitmapHelper.QuantizeBitmap(bitmap, PS2PixelFormatHelper.GetIndexedColorCount(pixelFormat), out mIndices, out mPalette); } else { mPixels = BitmapHelper.GetColors(bitmap) .Select(x => Color.FromArgb(PS2PixelFormatHelper.ScaleFullRangeAlphaToHalfRange(x.A), x.R, x.G, x.B)) .ToArray(); } mMipMapData = new byte[0]; }