Esempio n. 1
0
        public static Bitmap GetBitmap(byte[] data, int width, int height, PicaDataType dataType, PicaPixelFormat pixelFormat)
        {
            var bitmap  = new Bitmap(width, height);
            var decoder = GetDecoder(dataType, pixelFormat);

            var bmpData    = bitmap.LockBits(new Rectangle(0, 0, bitmap.Width, bitmap.Height), ImageLockMode.WriteOnly, bitmap.PixelFormat);
            var targetData = new byte[bmpData.Height * bmpData.Stride];

            Marshal.Copy(bmpData.Scan0, targetData, 0, targetData.Length);

            using (BinaryReader reader = new BinaryReader(new MemoryStream(data)))
            {
                for (int y = 0; y < height; y += 8)
                {
                    for (int x = 0; x < width; x += 8)
                    {
                        decoder(reader, targetData, x, y, width, height);
                    }
                }
            }

            Marshal.Copy(targetData, 0, bmpData.Scan0, targetData.Length);
            bitmap.UnlockBits(bmpData);

            return(bitmap);
        }
Esempio n. 2
0
 public Codec(PicaDataType dataType, PicaPixelFormat pixelFormat, TileDecoderDelegate decoder, TileEncoderDelegate encoder)
 {
     DataType    = dataType;
     PixelFormat = pixelFormat;
     Decoder     = decoder;
     Encoder     = encoder;
 }
Esempio n. 3
0
        public static TileEncoderDelegate GetEncoder(PicaDataType dataType, PicaPixelFormat picaPixelFormat)
        {
            Codec codec = GetCodec(dataType, picaPixelFormat);

            if (codec.Encoder == null)
            {
                throw new Exception(string.Format("Encoder not found for {0} {1}", dataType, picaPixelFormat));
            }
            return(codec.Encoder);
        }
Esempio n. 4
0
        private static Codec GetCodec(PicaDataType dataType, PicaPixelFormat picaPixelFormat)
        {
            Codec codec = codecs.FirstOrDefault(x => x.DataType == dataType && x.PixelFormat == picaPixelFormat);

            if (codec == null)
            {
                throw new Exception(string.Format("Codec not found for {0} {1}", dataType, picaPixelFormat));
            }
            return(codec);
        }
Esempio n. 5
0
        public static PixelDataFormat GetPixelDataFormat(PicaDataType dataType, PicaPixelFormat pixelFormat)
        {
            Tuple <PicaDataType, PicaPixelFormat> tuple = new Tuple <PicaDataType, PicaPixelFormat>(dataType, pixelFormat);

            if (!formatMapPica.ContainsKey(tuple))
            {
                throw new Exception("No matching pixel data format known");
            }
            return(formatMapPica[tuple]);
        }
Esempio n. 6
0
        protected override Bitmap OnGetBitmap(int imageIndex, int paletteIndex)
        {
            CTXBTexture texture = Textures[imageIndex];

            PicaPixelFormat pixelFormat = texture.PixelFormat;
            PicaDataType    dataType    = ((pixelFormat == PicaPixelFormat.ETC1RGB8NativeDMP || pixelFormat == PicaPixelFormat.ETC1AlphaRGB8A4NativeDMP) ? PicaDataType.UnsignedByte : texture.DataType);

            ImageBinary imageBinary = new ImageBinary();

            imageBinary.Width            = texture.Width;
            imageBinary.Height           = texture.Height;
            imageBinary.InputPixelFormat = N3DS.GetPixelDataFormat(dataType, pixelFormat);
            imageBinary.InputEndianness  = Endian.LittleEndian;
            imageBinary.AddInputPixels(pixelData[imageIndex]);

            return(imageBinary.GetBitmap(0, 0));
        }
Esempio n. 7
0
        public static byte[] GetData(Bitmap bitmap, PicaDataType dataType, PicaPixelFormat pixelFormat)
        {
            var output  = new MemoryStream(32);
            var writer  = new BinaryWriter(output);
            var encoder = GetEncoder(dataType, pixelFormat);

            var bmpData    = bitmap.LockBits(new Rectangle(0, 0, bitmap.Width, bitmap.Height), ImageLockMode.ReadWrite, bitmap.PixelFormat);
            var sourceData = new byte[bmpData.Height * bmpData.Stride];

            Marshal.Copy(bmpData.Scan0, sourceData, 0, sourceData.Length);

            for (int y = 0; y < bitmap.Height; y += 8)
            {
                for (int x = 0; x < bitmap.Width; x += 8)
                {
                    encoder(writer, sourceData, x, y, bitmap.Width, bitmap.Height);
                }
            }

            Marshal.Copy(sourceData, 0, bmpData.Scan0, sourceData.Length);
            bitmap.UnlockBits(bmpData);

            return(output.ToArray());
        }