/**********************/ /**** Constructors ****/ /**********************/ public TMXFile(Bitmap bitmap, PS2PixelFormat pixelFormat = PS2PixelFormat.PSMT8, string comment = "") { Width = (ushort)bitmap.Width; Height = (ushort)bitmap.Height; PixelFormat = pixelFormat; _wrapModes = byte.MaxValue; UserComment = comment; switch (pixelFormat) { case PS2PixelFormat.PSMCT32: case PS2PixelFormat.PSMCT24: case PS2PixelFormat.PSMCT16: case PS2PixelFormat.PSMCT16S: // Non-indexed PaletteFormat = 0; Pixels = BitmapHelper.GetColors(bitmap); _bitmap = bitmap; break; case PS2PixelFormat.PSMT8: case PS2PixelFormat.PSMT8H: SetupIndexedBitmap(bitmap, 256); break; case PS2PixelFormat.PSMT4: case PS2PixelFormat.PSMT4HL: case PS2PixelFormat.PSMT4HH: SetupIndexedBitmap(bitmap, 16); break; default: throw new ArgumentException("This pixel format is not supported for encoding."); } }
/// <summary> /// Initialize a new instance of <see cref="RWRasterData"/> using given palette, pixel indices and pixel format. /// </summary> /// <param name="palette">Palette of the texture.</param> /// <param name="indices">Per-Pixel indices into the palette colors of the texture.</param> /// <param name="pixelFormat">PS2 pixel format of the given texture data.</param> public RWRasterData(Color[] palette, byte[] indices, PS2PixelFormat pixelFormat) : base(RWNodeType.Struct) { _indices = indices; _palette = palette; _mipMapData = new byte[0]; }
public static int GetTexelDataSize(PS2PixelFormat fmt, int width, int height) { switch (fmt) { case PS2PixelFormat.PSMTC32: case PS2PixelFormat.PSMTC24: case PS2PixelFormat.PSMZ32: case PS2PixelFormat.PSMZ24: return((width * height) * 4); case PS2PixelFormat.PSMTC16: case PS2PixelFormat.PSMTC16S: case PS2PixelFormat.PSMZ16: case PS2PixelFormat.PSMZ16S: return((width * height) * 2); case PS2PixelFormat.PSMT8: case PS2PixelFormat.PSMT8H: return((width * height) * 1); case PS2PixelFormat.PSMT4: case PS2PixelFormat.PSMT4HL: case PS2PixelFormat.PSMT4HH: return((width * height) / 2); // 4 bit index only takes up half a texel default: throw new ArgumentException(EXCEPTION_INVALID_PXFORMAT, "fmt"); } }
public static int GetPixelFormatDepth(PS2PixelFormat fmt) { switch (fmt) { case PS2PixelFormat.PSMTC32: case PS2PixelFormat.PSMZ32: case PS2PixelFormat.PSMZ24: return(32); case PS2PixelFormat.PSMTC24: return(24); case PS2PixelFormat.PSMTC16: case PS2PixelFormat.PSMTC16S: case PS2PixelFormat.PSMZ16: case PS2PixelFormat.PSMZ16S: return(16); case PS2PixelFormat.PSMT8: case PS2PixelFormat.PSMT8H: return(8); case PS2PixelFormat.PSMT4: case PS2PixelFormat.PSMT4HL: case PS2PixelFormat.PSMT4HH: return(4); default: throw new ArgumentException(EXCEPTION_INVALID_PXFORMAT, "fmt"); } }
/**********************/ /**** Constructors ****/ /**********************/ public TmxFile(Bitmap bitmap, PS2PixelFormat pixelFormat = PS2PixelFormat.PSMT8, string comment = "") { Width = (ushort)bitmap.Width; Height = (ushort)bitmap.Height; PixelFormat = pixelFormat; mWrapModes = byte.MaxValue; UserComment = comment; switch (pixelFormat) { case PS2PixelFormat.PSMTC32: case PS2PixelFormat.PSMTC24: case PS2PixelFormat.PSMTC16: case PS2PixelFormat.PSMTC16S: // Non-indexed PaletteFormat = 0; Pixels = BitmapHelper.GetColors(bitmap); mBitmap = bitmap; break; case PS2PixelFormat.PSMT8: case PS2PixelFormat.PSMT8H: SetupIndexedBitmap(bitmap, 256); break; case PS2PixelFormat.PSMT4: case PS2PixelFormat.PSMT4HL: case PS2PixelFormat.PSMT4HH: SetupIndexedBitmap(bitmap, 16); break; default: throw new ArgumentException("This pixel format is not supported for encoding."); } }
/// <summary> /// Initialize a new instance of <see cref="RwRasterDataStructNode"/> using given palette, pixel indices and pixel format. /// </summary> /// <param name="palette">Palette of the texture.</param> /// <param name="indices">Per-Pixel indices into the palette colors of the texture.</param> /// <param name="pixelFormat">PS2 pixel format of the given texture data.</param> public RwRasterDataStructNode(Color[] palette, byte[] indices, PS2PixelFormat pixelFormat) : base(RwNodeId.RwStructNode) { mIndices = indices; mPalette = palette; mMipMapData = new byte[0]; }
public static PixelDataFormat GetPixelDataFormat(PS2PixelFormat pixelFormat) { if (!formatMap.ContainsKey(pixelFormat)) { throw new Exception("No matching pixel data format known"); } return(formatMap[pixelFormat]); }
public Tex0Register( PS2PixelFormat txFmt, int txWidth, int txHeight) : this() { TextureBufferWidth = (ulong)GetBufferWidth(txWidth, txFmt); TexturePixelFormat = txFmt; TextureWidth = (ulong)txWidth; TextureHeight = (ulong)txHeight; }
public static byte[] ReadPaletteData(EndianBinaryReader reader, PS2PixelFormat pixelFormat, PS2PixelFormat paletteFormat) { int colorCount = (pixelFormat == PS2PixelFormat.PSMT4 ? 16 : (pixelFormat == PS2PixelFormat.PSMT8 ? 256 : 0)); byte[] tempPalette = new byte[colorCount * 4]; byte r, g, b, a; for (int i = 0; i < tempPalette.Length; i += 4) { if (paletteFormat == PS2PixelFormat.PSMCT32) { uint color = reader.ReadUInt32(); r = (byte)color; g = (byte)(color >> 8); b = (byte)(color >> 16); a = ScaleAlpha((byte)(color >> 24)); } else { ushort color = reader.ReadUInt16(); r = (byte)((color & 0x001F) << 3); g = (byte)(((color & 0x03E0) >> 5) << 3); b = (byte)(((color & 0x7C00) >> 10) << 3); a = ScaleAlpha((byte)(i == 0 ? 0 : 0x80)); } tempPalette[i + 0] = a; tempPalette[i + 1] = r; tempPalette[i + 2] = g; tempPalette[i + 3] = b; } byte[] paletteData; if (colorCount == 256) { paletteData = new byte[tempPalette.Length]; for (int i = 0; i < paletteData.Length; i += (32 * 4)) { Buffer.BlockCopy(tempPalette, i + (0 * 4), paletteData, i + (0 * 4), (8 * 4)); Buffer.BlockCopy(tempPalette, i + (8 * 4), paletteData, i + (16 * 4), (8 * 4)); Buffer.BlockCopy(tempPalette, i + (16 * 4), paletteData, i + (8 * 4), (8 * 4)); Buffer.BlockCopy(tempPalette, i + (24 * 4), paletteData, i + (24 * 4), (8 * 4)); } } else { paletteData = tempPalette; } return(paletteData); }
public static void WritePixelData <T>(PS2PixelFormat fmt, BinaryWriter writer, int width, int height, T[] array) { if (IsIndexedPixelFormat(fmt)) { WritePixelIndicesDelegate writePixelIndices = GetWritePixelIndicesDelegate(fmt); writePixelIndices(writer, width, height, array as byte[]); } else { WritePixelColorDelegate writePixels = GetWritePixelColorDelegate(fmt); writePixels(writer, width, height, array as Color[]); } }
// helper methods to get info about the pixel format public static int GetPaletteDimension(PS2PixelFormat imageFmt) { int paletteWH = 16; if (imageFmt == PS2PixelFormat.PSMT4 || imageFmt == PS2PixelFormat.PSMT4HH || imageFmt == PS2PixelFormat.PSMT4HL) { paletteWH = 4; } return(paletteWH); }
public TMXPalette(BinaryReader reader, PS2PixelFormat format) { Format = GetPixelFormat(format); if (Format == PixelFormats.Indexed8) { Pallete = new BitmapPalette(TilePalette(Utilities.Utilities.ReadPalette(reader, 256))); } else if (Format == PixelFormats.Indexed4) { Pallete = new BitmapPalette(Utilities.Utilities.ReadPalette(reader, 16)); } }
public static bool IsIndexedPixelFormat(PS2PixelFormat fmt) { switch (fmt) { case PS2PixelFormat.PSMT8: case PS2PixelFormat.PSMT4: case PS2PixelFormat.PSMT8H: case PS2PixelFormat.PSMT4HL: case PS2PixelFormat.PSMT4HH: return(true); } return(false); }
/// <summary> /// Initialize a new instanc eof <see cref="RWRasterData"/> 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 RWRasterData(Bitmap bitmap, PS2PixelFormat pixelFormat) : base(RWNodeType.Struct) { if (PS2PixelFormatHelper.IsIndexedPixelFormat(pixelFormat)) { BitmapHelper.QuantizeBitmap(bitmap, PS2PixelFormatHelper.GetIndexedColorCount(pixelFormat), out _indices, out _palette); } else { _pixels = BitmapHelper.GetColors(bitmap); } _mipMapData = new byte[0]; }
/// <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]; }
// generic read/write methods public static void ReadPixelData <T>(PS2PixelFormat fmt, BinaryReader reader, int width, int height, out T[] array) { if (IsIndexedPixelFormat(fmt)) { ReadPixelIndicesDelegate readPixelIndices = GetReadPixelIndicesDelegate(fmt); byte[] pixelIndices; readPixelIndices(reader, width, height, out pixelIndices); array = pixelIndices as T[]; } else { ReadPixelColorDelegate readPixels = GetReadPixelColorDelegate(fmt); Color[] pixels; readPixels(reader, width, height, out pixels); array = pixels as T[]; } }
private int CalculatePixelDataSize(int width, int height, PS2PixelFormat format) { switch (format) { case PS2PixelFormat.PSMCT32: return((width * height) * 4); case PS2PixelFormat.PSMCT24: return((width * height) * 3); case PS2PixelFormat.PSMCT16: return((width * height) * 2); case PS2PixelFormat.PSMT8: return(width * height); case PS2PixelFormat.PSMT4: return((width * height) / 2); default: throw new Exception("Unknown PS2 pixel format"); } }
public static WritePixelIndicesDelegate GetWritePixelIndicesDelegate(PS2PixelFormat fmt) { switch (fmt) { case PS2PixelFormat.PSMT8: case PS2PixelFormat.PSMT8H: return(WritePSMT8); case PS2PixelFormat.PSMT4: case PS2PixelFormat.PSMT4HL: case PS2PixelFormat.PSMT4HH: return(WritePSMT4); default: throw new ArgumentException(EXCEPTION_INVALID_PXFORMAT, "fmt"); } }
public static int GetIndexedColorCount(PS2PixelFormat fmt) { switch (fmt) { case PS2PixelFormat.PSMT8: case PS2PixelFormat.PSMT8H: return(256); case PS2PixelFormat.PSMT4: case PS2PixelFormat.PSMT4HL: case PS2PixelFormat.PSMT4HH: return(16); default: throw new ArgumentException(EXCEPTION_INVALID_PXFORMAT, "fmt"); } }
internal static int GetBufferWidth(int width, PS2PixelFormat pixelFormat) { int divisor; switch (pixelFormat) { case PS2PixelFormat.PSMTC32: case PS2PixelFormat.PSMTC24: divisor = 256; // this might be wrong break; case PS2PixelFormat.PSMT8: case PS2PixelFormat.PSMT8H: divisor = 64; break; case PS2PixelFormat.PSMT4: case PS2PixelFormat.PSMT4HL: case PS2PixelFormat.PSMT4HH: divisor = 32; // because every pixel only takes up half a texel break; default: throw new ArgumentException(); } int bufferWidth = width / divisor; if (bufferWidth < 1) { bufferWidth = 1; } else if (bufferWidth == 1) { bufferWidth = 2; } else { bufferWidth = (int)Math.Ceiling((double)bufferWidth); } return(bufferWidth); }
/// <summary> /// Initializes an <see cref="RwTextureNativeNode"/> instance using a bitmap, name and a PS2 pixel format to encode to. /// </summary> /// <param name="name">Name of the texture used for material references.</param> /// <param name="bitmap">Source bitmap used to encode.</param> /// <param name="pixelFormat">PS2 Pixel format to encode the bitmap to.</param> public RwTextureNativeNode(string name, Bitmap bitmap, PS2PixelFormat pixelFormat) : base(RwNodeId.RwTextureNativeNode) { if (bitmap.Width % 2 != 0 || bitmap.Height % 2 != 0) { throw new ArgumentException(EXCEPTION_NOT_POW2); } if (bitmap.Width > 1024 || bitmap.Width > 1024) { throw new ArgumentException(EXCEPTION_DIMENSION_TOO_BIG); } mStructNode = new RwTextureNativeStructNode(this); mName = new RwStringNode(name, this); mMaskName = new RwStringNode(string.Empty, this); mRasterStructNode = new RwRasterStructNode(bitmap, pixelFormat, this); mExtensionNode = new RwExtensionNode(this, new RwSkyMipMapValueNode()); }
public static PixelFormat GetPixelFormat(PS2PixelFormat fmt) { switch (fmt) { case PS2PixelFormat.PSMT8: case PS2PixelFormat.PSMT8H: return(PixelFormats.Indexed8); case PS2PixelFormat.PSMT4: case PS2PixelFormat.PSMT4HL: case PS2PixelFormat.PSMT4HH: return(PixelFormats.Indexed4); case PS2PixelFormat.PSMTC24: return(PixelFormats.Rgb24); case PS2PixelFormat.PSMTC32: return(PixelFormats.Pbgra32); default: return(PixelFormats.Default); } }
public static WritePixelColorDelegate GetWritePixelColorDelegate(PS2PixelFormat fmt) { switch (fmt) { case PS2PixelFormat.PSMTC32: case PS2PixelFormat.PSMZ32: return(WritePSMCT32); case PS2PixelFormat.PSMZ24: case PS2PixelFormat.PSMTC24: return(WritePSMCT24); case PS2PixelFormat.PSMTC16: case PS2PixelFormat.PSMZ16: return(WritePSMCT16); case PS2PixelFormat.PSMZ16S: case PS2PixelFormat.PSMTC16S: return(WritePSMCT16S); default: throw new ArgumentException(EXCEPTION_INVALID_PXFORMAT, "fmt"); } }
/// <summary> /// Initializes an <see cref="RwTextureNativeNode"/> instance using a name, width, height, palette, indices and a PS2 pixel format to encode to. /// </summary> /// <param name="name">Name of the texture used for material references.</param> /// <param name="width">Width of the texture.</param> /// <param name="height">Height of the texture.</param> /// <param name="palette">Texture palette data.</param> /// <param name="indices">Texture pixel indices into the palette.</param> /// <param name="pixelFormat">PS2 Pixel format to encode the bitmap to.</param> public RwTextureNativeNode(string name, int width, int height, Color[] palette, byte[] indices, PS2PixelFormat pixelFormat) : base(RwNodeId.RwTextureNativeNode) { if (width % 2 != 0 || height % 2 != 0) { throw new ArgumentException(EXCEPTION_NOT_POW2); } if (width > 1024 || width > 1024) { throw new ArgumentException(EXCEPTION_DIMENSION_TOO_BIG); } mStructNode = new RwTextureNativeStructNode(this); mName = new RwStringNode(name, this); mMaskName = new RwStringNode(string.Empty, this); mRasterStructNode = new RwRasterStructNode(width, height, palette, indices, pixelFormat, this); mExtensionNode = new RwExtensionNode(this, new RwSkyMipMapValueNode()); }
/// <summary> /// Initializes an <see cref="RwTextureNativeNode"/> instance using a path to a bitmap and a PS2 pixel format to encode to. /// </summary> /// <param name="path">Path to a bitmap.</param> /// <param name="pixelFormat">PS2 Pixel format to encode the bitmap to.</param> public RwTextureNativeNode(string path, PS2PixelFormat pixelFormat) : this(Path.GetFileNameWithoutExtension(path), new Bitmap(path), pixelFormat) { }
public TMXFile(string path, PS2PixelFormat pixelFormat = PS2PixelFormat.PSMT8, string comment = "") : this(new Bitmap(path), pixelFormat, comment) { }
public TMXFile(Stream stream, PS2PixelFormat pixelFormat = PS2PixelFormat.PSMT8, string comment = "") : this(new Bitmap(stream), pixelFormat, comment) { }
public TmxFile(Stream stream, PS2PixelFormat pixelFormat = PS2PixelFormat.PSMT8, string comment = "") : this(new Bitmap(stream), pixelFormat, comment) { }
/// <summary> /// Initializes an <see cref="RWTextureNative"/> instance using a bitmap, name and a PS2 pixel format to encode to. /// </summary> /// <param name="name">Name of the texture used for material references.</param> /// <param name="bitmap">Source bitmap used to encode.</param> /// <param name="pixelFormat">PS2 Pixel format to encode the bitmap to.</param> public RWTextureNative(string name, Bitmap bitmap, PS2PixelFormat pixelFormat) : base(RWNodeType.TextureNative) { if (bitmap.Width % 2 != 0 || bitmap.Height % 2 != 0) { throw new ArgumentException(EXCEPTION_NOT_POW2); } if (bitmap.Width > 1024 || bitmap.Width > 1024) { throw new ArgumentException(EXCEPTION_DIMENSION_TOO_BIG); } _struct = new RWTextureNativeStruct(this); _name = new RWString(name, this); _maskName = new RWString(string.Empty, this); _raster = new RWRaster(bitmap, pixelFormat, this); _extension = new RWExtension(new RWSkyMipMapValue()); _extension.Parent = this; }
public static bool IsFormatIndexed(PS2PixelFormat pixelFormat) { /* TODO: turn into Dictionary as well? */ return(pixelFormat != PS2PixelFormat.PSMCT32 && pixelFormat != PS2PixelFormat.PSMCT24 && pixelFormat != PS2PixelFormat.PSMCT16 && pixelFormat != PS2PixelFormat.PSMCT16S); }
/// <summary> /// Sets the appropriate raster info values based on the width, height and pixel format of the texture. /// </summary> /// <param name="width">Width of the texture.</param> /// <param name="height">Height of the texture.</param> /// <param name="pixelFormat">PS2 pixel format of the given texture data.</param> private void CreateRasterInfo(int width, int height, PS2PixelFormat pixelFormat) { _width = width; _height = height; _depth = PS2PixelFormatHelper.GetPixelFormatDepth(pixelFormat); _rasterFormat = GetRasterFormatFromDepth(_depth); _tex0 = new Tex0Register(pixelFormat, width, height); _tex1 = new Tex1Register(); // default settings int texSize = width * height; if (texSize < 16384) // because yes { _tex1.MaxMipLevel = 7; _tex1.MipMinFilter = PS2FilterMode.None; if (texSize <= 4096) { _tex1.MipMaxFilter = PS2FilterMode.None; } else { _tex1.MipMaxFilter = PS2FilterMode.Nearest; } } _mip1 = new MipTBPRegister(); // default settings _mip2 = new MipTBPRegister(); // default settings _texelDataLength = (uint)PS2PixelFormatHelper.GetTexelDataSize(pixelFormat, width, height); // Add image header size to the length if there is one if (_rasterFormat.HasFlagUnchecked(RWRasterFormats.HasHeaders)) _texelDataLength += PS2StandardImageHeader.Size; _paletteDataLength = 0; // set to 0 if there's no palette present // division by 2 might only apply for 8 bit.. int transferWidth = width / 2; int transferHeight = height / 2; _gpuAlignedLength = (uint)(transferWidth * transferHeight); // Calculate the palette data length for indexed textures if (_depth == 4 || _depth == 8) { int numColors = 256; if (_depth == 4) { numColors = 16; } _paletteDataLength = (uint)(numColors * 4); // division by 4 might only apply for 8 bit.. _gpuAlignedLength += _paletteDataLength / 4; // Add image header size to the length if there is one if (_rasterFormat.HasFlagUnchecked(RWRasterFormats.HasHeaders)) _paletteDataLength += PS2StandardImageHeader.Size; } // align to pages of 2048 _gpuAlignedLength = (uint)AlignmentHelper.Align(_gpuAlignedLength, 2048); }
/// <summary> /// Initializes an <see cref="RWTextureNative"/> instance using a name, width, height, palette, indices and a PS2 pixel format to encode to. /// </summary> /// <param name="name">Name of the texture used for material references.</param> /// <param name="width">Width of the texture.</param> /// <param name="height">Height of the texture.</param> /// <param name="palette">Texture palette data.</param> /// <param name="indices">Texture pixel indices into the palette.</param> /// <param name="pixelFormat">PS2 Pixel format to encode the bitmap to.</param> public RWTextureNative(string name, int width, int height, Color[] palette, byte[] indices, PS2PixelFormat pixelFormat) : base(RWNodeType.TextureNative) { if (width % 2 != 0 || height % 2 != 0) { throw new ArgumentException(EXCEPTION_NOT_POW2); } if (width > 1024 || width > 1024) { throw new ArgumentException(EXCEPTION_DIMENSION_TOO_BIG); } _struct = new RWTextureNativeStruct(this); _name = new RWString(name, this); _maskName = new RWString(string.Empty, this); _raster = new RWRaster(width, height, palette, indices, pixelFormat, this); _extension = new RWExtension(new RWSkyMipMapValue()); _extension.Parent = this; }
/// <summary> /// Sets the appropriate rasterStructNode info values based on the width, height and pixel format of the texture. /// </summary> /// <param name="width">Width of the texture.</param> /// <param name="height">Height of the texture.</param> /// <param name="pixelFormat">PS2 pixel format of the given texture data.</param> private void CreateRasterInfo(int width, int height, PS2PixelFormat pixelFormat) { Width = width; Height = height; Depth = PS2PixelFormatHelper.GetPixelFormatDepth(pixelFormat); Format = GetRasterFormatFromDepth(Depth); Tex0Register = new Tex0Register(pixelFormat, width, height); Tex1Register = new Tex1Register(); // default settings int texSize = width * height; if (texSize < 16384) // because yes { Tex1Register.MaxMipLevel = 7; Tex1Register.MipMinFilter = PS2FilterMode.None; if (texSize <= 4096) { Tex1Register.MipMaxFilter = PS2FilterMode.None; } else { Tex1Register.MipMaxFilter = PS2FilterMode.Nearest; } } MipTBP1Register = new MipTbpRegister(); // default settings MipTBP2Register = new MipTbpRegister(); // default settings TexelDataLength = (uint)PS2PixelFormatHelper.GetTexelDataSize(pixelFormat, width, height); // Add image header size to the length if there is one if (Format.HasFlagUnchecked(RwRasterFormats.HasHeaders)) { TexelDataLength += PS2StandardImageHeader.Size; } PaletteDataLength = 0; // set to 0 if there's no palette present // division by 2 might only apply for 8 bit.. int transferWidth = width / 2; int transferHeight = height / 2; GpuAlignedLength = (uint)(transferWidth * transferHeight); // Calculate the palette data length for indexed textures if (Depth == 4 || Depth == 8) { int numColors = 256; if (Depth == 4) { numColors = 16; } PaletteDataLength = (uint)(numColors * 4); // division by 4 might only apply for 8 bit.. GpuAlignedLength += PaletteDataLength / 4; // Add image header size to the length if there is one if (Format.HasFlagUnchecked(RwRasterFormats.HasHeaders)) { PaletteDataLength += PS2StandardImageHeader.Size; } } // align to pages of 2048 GpuAlignedLength = (uint)AlignmentHelper.Align(GpuAlignedLength, 2048); }
/// <summary> /// Initialize a new instance of <see cref="RWRasterInfo"/> with properties set using a given width, height and <see cref="PS2.Graphics.PS2PixelFormat"/>. /// </summary> /// <param name="width"></param> /// <param name="height"></param> /// <param name="pixelFormat">PS2 pixel format of the given texture data.</param> public RWRasterInfo(int width, int height, PS2PixelFormat pixelFormat) : base(RWNodeType.Struct) { CreateRasterInfo(width, height, pixelFormat); }
/// <summary> /// Initialize a new instance of <see cref="RwRasterInfoStructNode"/> with properties set using a given width, height and <see cref="PS2.Graphics.PS2PixelFormat"/>. /// </summary> /// <param name="width"></param> /// <param name="height"></param> /// <param name="pixelFormat">PS2 pixel format of the given texture data.</param> public RwRasterInfoStructNode(int width, int height, PS2PixelFormat pixelFormat) : base(RwNodeId.RwStructNode) { CreateRasterInfo(width, height, pixelFormat); }
/// <summary> /// Initializes an <see cref="RWTextureNative"/> instance using a path to a bitmap and a PS2 pixel format to encode to. /// </summary> /// <param name="path">Path to a bitmap.</param> /// <param name="pixelFormat">PS2 Pixel format to encode the bitmap to.</param> public RWTextureNative(string path, PS2PixelFormat pixelFormat) : this(Path.GetFileNameWithoutExtension(path), new Bitmap(path), pixelFormat) { }
public TmxFile(string path, short userId = 0, PS2PixelFormat pixelFormat = PS2PixelFormat.PSMT8, string comment = "") : this(new Bitmap(path), userId, pixelFormat, comment) { }
internal static int GetBufferWidth(int width, PS2PixelFormat pixelFormat) { int divisor; switch (pixelFormat) { case PS2PixelFormat.PSMCT32: case PS2PixelFormat.PSMCT24: divisor = 256; // this might be wrong break; case PS2PixelFormat.PSMT8: case PS2PixelFormat.PSMT8H: divisor = 64; break; case PS2PixelFormat.PSMT4: case PS2PixelFormat.PSMT4HL: case PS2PixelFormat.PSMT4HH: divisor = 32; // because every pixel only takes up half a texel break; default: throw new ArgumentException(); } int bufferWidth = width / divisor; if (bufferWidth < 1) { bufferWidth = 1; } else if (bufferWidth == 1) { bufferWidth = 2; } else { bufferWidth = (int)Math.Ceiling((double)bufferWidth); } return bufferWidth; }