Beispiel #1
0
        private Bitmap Export(byte[] Texture)
        {

            StructReader Reader = new StructReader(new MemoryStream(Texture));
            CZ3Header Header = new CZ3Header();
            Reader.ReadStruct(ref Header);
         
            if (Header.Signature != "CZ3\x0")
                throw new BadImageFormatException();

            Reader.Seek(Header.HeaderLength, SeekOrigin.Begin);
            Bitmap Picture = new Bitmap(Header.Width, Header.Heigth, PixelFormat.Format32bppArgb);
            if (Header.Colorbits == 4)//4bit
            {
                
            }
            else if (Header.Colorbits == 8)//8bit
            {
               

            }
            else if (Header.Colorbits == 32)//32
            {
                var bytes = Decompress(Reader);
                byte[] data = bytes.ToArray();
                int PixelByteCount = 4;
                ImageFillPartten.LineDiffPattern(ref Picture, Header.Colorblock, PixelByteCount, data,null);
            }
            Reader.Close();
            return Picture;
        }
        //作者:Wetor, Devseed
        //时间:2020.9.8
        private Bitmap Export(byte[] Texture)
        {
            StructReader Reader = new StructReader(new MemoryStream(Texture));
            CZ4Header    Header = new CZ4Header();

            Reader.ReadStruct(ref Header);
            Header.Blockh = (ushort)Math.Ceiling((float)Header.Heigth / (float)Header.Colorblock);
            if (Header.Signature != "CZ4\x0")
            {
                throw new BadImageFormatException();
            }

            Reader.Seek(Header.HeaderLength, SeekOrigin.Begin);
            Bitmap Picture = new Bitmap(Header.Width, Header.Heigth, PixelFormat.Format32bppArgb);

            if (Header.Colorbits == 4)//4bit
            {
            }
            else if (Header.Colorbits == 8)//8bit
            {
            }
            else if (Header.Colorbits == 32)
            {
                var    bytes  = Decompress(Reader);
                int    pcount = Header.Width * Header.Heigth;
                byte[] data   = bytes.ToArray();
                byte[] data2  = new byte[pcount];
                Buffer.BlockCopy(data, pcount * 3, data2, 0, pcount);

                int PixelByteCount = 3;
                ImageFillPartten.LineDiffPattern(ref Picture, Header.Colorblock, PixelByteCount, data, null);

                PixelByteCount = 1;
                ImageFillPartten.LineDiffPattern(ref Picture, Header.Colorblock, PixelByteCount, data2,
                                                 delegate(int x, int y, byte[] curr_line)
                {
                    var pixel = Picture.GetPixel(x, y);
                    Picture.SetPixel(x, y, Color.FromArgb(curr_line[x], pixel.R, pixel.G, pixel.B));
                });
            }
            Reader.Close();
            return(Picture);
        }