Ejemplo n.º 1
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="colorFormat"></param>
 /// <param name="value"></param>
 /// <returns></returns>
 public static Color Encode(ColorFormat colorFormat, uint value)
 {
     return(Color.FromArgb(
                (int)BitUtils.ExtractScaled(value, colorFormat.Alpha.Offset, colorFormat.Alpha.Size, 255),
                (int)BitUtils.ExtractScaled(value, colorFormat.Red.Offset, colorFormat.Red.Size, 255),
                (int)BitUtils.ExtractScaled(value, colorFormat.Green.Offset, colorFormat.Green.Size, 255),
                (int)BitUtils.ExtractScaled(value, colorFormat.Blue.Offset, colorFormat.Blue.Size, 255)
                ));
 }
 public static OutputPixel Decode_RGBA_5650_Pixel(ushort value)
 {
     return(new OutputPixel
     {
         R = (byte)BitUtils.ExtractScaled(value, 0, 5, 255),
         G = (byte)BitUtils.ExtractScaled(value, 5, 6, 255),
         B = (byte)BitUtils.ExtractScaled(value, 11, 5, 255),
         A = 0xFF,
     });
 }
 public static OutputPixel Decode_RGBA_4444_Pixel(ushort value)
 {
     return(new OutputPixel
     {
         R = (byte)BitUtils.ExtractScaled(value, 0, 4, 255),
         G = (byte)BitUtils.ExtractScaled(value, 4, 4, 255),
         B = (byte)BitUtils.ExtractScaled(value, 8, 4, 255),
         A = (byte)BitUtils.ExtractScaled(value, 12, 4, 255),
     });
 }
 public static OutputPixel Decode_RGBA_5551_Pixel(ushort value)
 {
     return(new OutputPixel
     {
         R = (byte)BitUtils.ExtractScaled(value, 0, 5, 255),
         G = (byte)BitUtils.ExtractScaled(value, 5, 5, 255),
         B = (byte)BitUtils.ExtractScaled(value, 10, 5, 255),
         A = (byte)BitUtils.ExtractScaled(value, 15, 1, 255),
     });
 }
Ejemplo n.º 5
0
            private Bitmap _GenerateBitmap()
            {
                var Bitmap = new Bitmap(Width, Height);

                switch (ImageEntry.ImageFileFormat.TextureFormat)
                {
                case GPUTEXTUREFORMAT.GPUTEXTUREFORMAT_4_4_4_4:
                    _GenerateBitmapDecode(Bitmap, (byte[] Bytes, int m) =>
                    {
                        var Data = (uint)(((Bytes[m++] << 8) | Bytes[m++]));
                        return(new ARGB_Rev()
                        {
                            B = (byte)BitUtils.ExtractScaled(Data, 0, 4, 255),
                            R = (byte)BitUtils.ExtractScaled(Data, 8, 4, 255),
                            G = (byte)BitUtils.ExtractScaled(Data, 4, 4, 255),
                            A = (byte)BitUtils.ExtractScaled(Data, 12, 4, 255),
                        });
                    });
                    break;

                case GPUTEXTUREFORMAT.GPUTEXTUREFORMAT_8_8_8_8:
                    _GenerateBitmapDecode(Bitmap, (byte[] Bytes, int m) =>
                    {
                        var Data = (uint)(((Bytes[m++] << 24) | (Bytes[m++] << 16) | (Bytes[m++] << 8) | Bytes[m++]));
                        return(new ARGB_Rev()
                        {
                            B = (byte)BitUtils.ExtractScaled(Data, 0, 8, 255),
                            G = (byte)BitUtils.ExtractScaled(Data, 8, 8, 255),
                            R = (byte)BitUtils.ExtractScaled(Data, 16, 8, 255),
                            A = (byte)BitUtils.ExtractScaled(Data, 24, 8, 255),
                        });
                    });

                    break;

                case GPUTEXTUREFORMAT.GPUTEXTUREFORMAT_DXT4_5:
                    //case GPUTEXTUREFORMAT.GPUTEXTUREFORMAT_DXT5A:
                    return((new DXT5()).LoadSwizzled2D(this.SliceStream, Width, Height, this.Tiled));

                case GPUTEXTUREFORMAT.GPUTEXTUREFORMAT_DXT1:
                    return((new DXT1()).LoadSwizzled2D(this.SliceStream, Width, Height, this.Tiled));

#if false
                case GPUTEXTUREFORMAT.GPUTEXTUREFORMAT_1:
                    Console.Error.Write("Unimplemented GPUTEXTUREFORMAT_1");
                    Graphics.FromImage(Bitmap).DrawString("Unimplemented GPUTEXTUREFORMAT_1", new Font("Arial", 20), new SolidBrush(Color.Red), new Point(16, 16));
                    break;
#endif
                default:
                    throw (new NotImplementedException("[Surface2DEntryInfo] Not implemented format : " + ImageEntry.ImageFileFormat.TextureFormat));
                }

                return(Bitmap);
            }