Beispiel #1
0
 public static Bitmap ToBitmap(PicaDataTypes dataType, PicaPixelFormats pixelFormat, int width, int height, byte[] data)
 {
     using (MemoryStream inputStream = new MemoryStream(data))
     {
         return ToBitmap(dataType, pixelFormat, width, height, new BinaryReader(inputStream));
     }
 }
Beispiel #2
0
        public static TileDecoderDelegate GetDecoder(PicaDataTypes dataType, PicaPixelFormats picaPixelFormat)
        {
            Codec codec = GetCodec(dataType, picaPixelFormat);

            if (codec.Decoder == null)
            {
                throw new Exception(string.Format("Decoder not found for {0} {1}", dataType, picaPixelFormat));
            }
            return(codec.Decoder);
        }
Beispiel #3
0
        private static Codec GetCodec(PicaDataTypes dataType, PicaPixelFormats 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);
        }
Beispiel #4
0
        public static Bitmap ToBitmap(PicaDataTypes dataType, PicaPixelFormats pixelFormat, int width, int height, BinaryReader reader)
        {
            TileDecoderDelegate decoder = TileCodecs.GetDecoder(dataType, pixelFormat);

            Bitmap bitmap = new Bitmap(width, height, PixelFormat.Format32bppArgb);

            BitmapData bmpData = bitmap.LockBits(new Rectangle(0, 0, bitmap.Width, bitmap.Height), ImageLockMode.ReadWrite, bitmap.PixelFormat);
            byte[] targetData = new byte[bmpData.Height * bmpData.Stride];
            Marshal.Copy(bmpData.Scan0, targetData, 0, targetData.Length);

            for (int y = 0; y < height; y += 8)
                for (int x = 0; x < width; x += 8)
                    decoder(reader, targetData, x, y, (int)width, (int)height);

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

            return bitmap;
        }
Beispiel #5
0
        public static Texture2D ToTexture2D(PicaDataTypes dataType, PicaPixelFormats pixelFormat, int width, int height, BinaryReader reader)
        {
            TileDecoderDelegate decoder = TileCodecs.GetDecoder(dataType, pixelFormat);
            Texture2D           tex     = new Texture2D(width, height, TextureFormat.BGRA32, false);

            byte[] targetData = new byte[height * width * 4];

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

            tex.LoadRawTextureData(targetData);
            tex.Apply();

            return(tex);
        }
Beispiel #6
0
 public Codec(PicaDataTypes dataType, PicaPixelFormats pixelFormat, TileDecoderDelegate decoder)
 {
     DataType    = dataType;
     PixelFormat = pixelFormat;
     Decoder     = decoder;
 }
Beispiel #7
0
 public static Texture2D ToTexture2D(PicaDataTypes dataType, PicaPixelFormats pixelFormat, int width, int height, byte[] data)
 {
     using (MemoryStream inputStream = new MemoryStream(data)) {
         return(ToTexture2D(dataType, pixelFormat, width, height, new BinaryReader(inputStream)));
     }
 }
Beispiel #8
0
        public static Texture2D ToTexture2D(PicaDataTypes dataType, PicaPixelFormats pixelFormat, int width, int height, Stream inputStream)
        {
            BinaryReader reader = new BinaryReader(inputStream);

            return(ToTexture2D(dataType, pixelFormat, width, height, reader));
        }
Beispiel #9
0
        public static Bitmap ToBitmap(PicaDataTypes dataType, PicaPixelFormats pixelFormat, int width, int height, Stream inputStream)
        {
            BinaryReader reader = new BinaryReader(inputStream);

            return ToBitmap(dataType, pixelFormat, width, height, reader);
        }