Пример #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));
     }
 }
Пример #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);
        }
Пример #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);
        }
Пример #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;
        }
Пример #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);
        }
Пример #6
0
 public Codec(PicaDataTypes dataType, PicaPixelFormats pixelFormat, TileDecoderDelegate decoder)
 {
     DataType    = dataType;
     PixelFormat = pixelFormat;
     Decoder     = decoder;
 }
Пример #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)));
     }
 }
Пример #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));
        }
Пример #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);
        }