diff --git a/ArcFormats/DigitalWorks/ImageTM2.cs b/ArcFormats/DigitalWorks/ImageTM2.cs index 3c20f973..4ee897f8 100644 --- a/ArcFormats/DigitalWorks/ImageTM2.cs +++ b/ArcFormats/DigitalWorks/ImageTM2.cs @@ -34,20 +34,20 @@ namespace GameRes.Formats.DigitalWorks { internal class Tim2MetaData : ImageMetaData { - public int PaletteSize; - public int HeaderSize; - public int Colors; + public int PaletteSize; + public int HeaderSize; + public int Colors; public byte Alpha; } [Export(typeof(ImageFormat))] public class Tim2Format : ImageFormat { - public override string Tag { get { return "TIM2"; } } + public override string Tag { get { return "TIM2"; } } public override string Description { get { return "PlayStation/2 image format"; } } - public override uint Signature { get { return 0x324D4954; } } // 'TIM2' + public override uint Signature { get { return 0x324D4954; } } // 'TIM2' - public Tim2Format() + public Tim2Format () { Extensions = new string[] { "tm2", "ext" }; Settings = new[] { AlphaFormat }; @@ -60,16 +60,16 @@ namespace GameRes.Formats.DigitalWorks ValuesSet = new[] { "No Alpha", "RGBX", "RGBA" }, }; - public override ImageMetaData ReadMetaData(IBinaryStream file) + public override ImageMetaData ReadMetaData (IBinaryStream file) { - var header = file.ReadHeader(0x40); + var header = file.ReadHeader (0x40); byte bpp = header[0x23]; switch (bpp) { case 1: bpp = 16; break; case 2: bpp = 24; break; case 3: bpp = 32; break; - case 4: bpp = 4; break; // 16 color + case 4: bpp = 4; break; //16color case 5: bpp = 8; break; default: return null; } @@ -81,62 +81,60 @@ namespace GameRes.Formats.DigitalWorks case "RGBA": default: alpha = 8; break; } - return new Tim2MetaData - { - Width = header.ToUInt16(0x24), - Height = header.ToUInt16(0x26), - BPP = bpp, - PaletteSize = header.ToInt32(0x14), - HeaderSize = header.ToUInt16(0x1C), - Colors = header.ToUInt16(0x1E), - Alpha = alpha, + return new Tim2MetaData { + Width = header.ToUInt16 (0x24), + Height = header.ToUInt16 (0x26), + BPP = bpp, + PaletteSize = header.ToInt32 (0x14), + HeaderSize = header.ToUInt16 (0x1C), + Colors = header.ToUInt16 (0x1E), + Alpha = alpha, //header.ToUInt16(0x30) == 0?// not so sure, there will be omissions }; } - public override ImageData Read(IBinaryStream file, ImageMetaData info) + public override ImageData Read (IBinaryStream file, ImageMetaData info) { - var reader = new Tim2Reader(file, (Tim2MetaData)info); + var reader = new Tim2Reader (file, (Tim2MetaData)info); var pixels = reader.Unpack(); - return ImageData.Create(info, reader.Format, reader.Palette, pixels); + return ImageData.Create (info, reader.Format, reader.Palette, pixels); } - public override void Write(Stream file, ImageData image) + public override void Write (Stream file, ImageData image) { - throw new System.NotImplementedException("Tim2Format.Write not implemented"); + throw new System.NotImplementedException ("Tim2Format.Write not implemented"); } } internal class Tim2Reader { - IBinaryStream m_input; - Tim2MetaData m_info; + IBinaryStream m_input; + Tim2MetaData m_info; - public PixelFormat Format { get; private set; } + public PixelFormat Format { get; private set; } public BitmapPalette Palette { get; private set; } - public Tim2Reader(IBinaryStream input, Tim2MetaData info) + public Tim2Reader (IBinaryStream input, Tim2MetaData info) { m_input = input; m_info = info; switch (info.BPP) { - case 4: Format = PixelFormats.Indexed4; break; - case 8: Format = PixelFormats.Indexed8; break; + case 4: Format = PixelFormats.Indexed4; break; + case 8: Format = PixelFormats.Indexed8; break; case 16: Format = PixelFormats.Bgr555; break; - case 24: Format = PixelFormats.Bgr24; break; + case 24: Format = PixelFormats.Bgr24; break; case 32: Format = PixelFormats.Bgra32; break; } } - public byte[] Unpack() + public byte[] Unpack () { m_input.Position = 0x10 + m_info.HeaderSize; double pixel_size = (double)m_info.BPP / 8; int image_size = (int)((int)m_info.Width * (int)m_info.Height * pixel_size); - var output = m_input.ReadBytes(image_size); - + var output = m_input.ReadBytes (image_size); if (pixel_size <= 1 && m_info.Colors > 0) // Indexed images - Palette = ReadPalette(m_info.Colors, m_info.Alpha); + Palette = ReadPalette (m_info.Colors, m_info.Alpha); // Handle 24bpp and 32bpp (Direct Color) if (pixel_size == 3 || (pixel_size == 4 && m_info.Alpha == 8)) @@ -145,8 +143,8 @@ namespace GameRes.Formats.DigitalWorks { // Swap R and B channels byte r = output[i]; - output[i] = output[i + 2]; - output[i + 2] = r; + output[i] = output[i+2]; + output[i+2] = r; // Fix Alpha for 32bpp (Double Alpha Scaling) if (pixel_size == 4) @@ -187,9 +185,9 @@ namespace GameRes.Formats.DigitalWorks return output; } - BitmapPalette ReadPalette(int color_num, byte X_A = 8) + BitmapPalette ReadPalette (int color_num, byte X_A = 8) { - var source = ImageFormat.ReadColorMap(m_input.AsStream, + var source = ImageFormat.ReadColorMap (m_input.AsStream, color_num, X_A == 7 ? PaletteFormat.RgbA7 : X_A == 0 ? PaletteFormat.RgbX : PaletteFormat.RgbA); // Scaled Alpha for Indexed Palettes (KID/PS2 Fix) @@ -208,8 +206,7 @@ namespace GameRes.Formats.DigitalWorks var color_map = new Color[color_num]; - if (color_num == 16) - { + if (color_num == 16){ Array.Copy(source, 0, color_map, 0, 16); return new BitmapPalette(color_map); } @@ -225,10 +222,10 @@ namespace GameRes.Formats.DigitalWorks for (int row = 0; row < rows; row++) { int src = (part * rows * blocks + row * rows + block) * colors; - Array.Copy(source, src, color_map, dst, colors); + Array.Copy (source, src, color_map, dst, colors); dst += colors; } - return new BitmapPalette(color_map); + return new BitmapPalette (color_map); } } -} \ No newline at end of file +}