コード例 #1
0
ファイル: Y64.cs プロジェクト: IanusInferus/cmdt
        //高速绘制Bitmap,不进行裁剪,图片宽、高分别是W、H的整数倍
        public unsafe Bitmap DrawAllWithoutCrop(RGBPalette rgb)
        {
            //width、height不一定能被64整除
            int W = (width >> 6) + ((width & 63) != 0 ? 1 : 0);
            int H = (height >> 6) + ((height & 63) != 0 ? 1 : 0);

            Bitmap bmp = new Bitmap(W * 64, H * 64, PixelFormat.Format32bppArgb);

            BitmapData bmpdata = bmp.LockBits(new Rectangle(0, 0, W * 64, H * 64), ImageLockMode.WriteOnly, PixelFormat.Format32bppArgb);

            IntPtr ptr   = bmpdata.Scan0;                       //Bitmap象素指针
            int    pitch = bmpdata.Stride / 4;                  //一行多少个象素,而不是一行多少字节!

            //依次绘制每一个64*64图块
            for (int h = 0; h < H; h++)
            {
                for (int w = 0; w < W; w++)
                {
                    int *line = (int *)ptr + h * 64 * pitch + w * 64;                    //定位block

                    Block b = blocks[h, w];
                    if (b == null)                     //用粉红色绘制所有的null block
                    {
                        int pink = Color.Fuchsia.ToArgb();
                        for (int y = 0; y < 64; y++, line += pitch)
                        {
                            for (int x = 0; x < 64; x++)
                            {
                                line[x] = pink;                                //粉色填充
                            }
                        }
                    }
                    else
                    {
                        //依次绘制每一个8*8子图块
                        for (int sh = 0; sh < 8; sh++)
                        {
                            for (int sw = 0; sw < 8; sw++)
                            {
                                SubBlock sb = b.subs[sh, sw];
                                int *    p  = line + sh * 8 * pitch + sw * 8;                            //定位subblock
                                //依次绘制8*8子图块中的每一个象素
                                for (int y = 0; y < 8; y++, p += pitch)
                                {
                                    for (int x = 0; x < 8; x++)
                                    {
                                        p[x] = (int)rgb.RGB32[sb.pixels[y, x]];
                                    }
                                }
                            }
                        }
                    }
                }
            }

            bmp.UnlockBits(bmpdata);

            return(bmp);
        }
コード例 #2
0
ファイル: Y64.cs プロジェクト: IanusInferus/cmdt
        //以指定格式保存图片
        public void SaveToFile(string fn, ImageFormat format, RGBPalette rgb)
        {
            Bitmap bmp = DrawAllWithCrop(rgb);

            bmp.Save(fn, format);
            bmp.Dispose();

            //对DrawAll生成的W*64-H*64进行真实尺寸Crop,貌似代价还是很高,最好用定义的Draw来实现
            //Bitmap dest = bmp.Clone(new Rectangle(0, 0, width, height), PixelFormat.Format32bppArgb);
            //bmp.Dispose();

            //dest.Save(fn, format);
            //dest.Dispose();
        }
コード例 #3
0
ファイル: Y64.cs プロジェクト: IanusInferus/cmdt
        public Y64(string fn)         //ok
        {
            fs = new FileStream(fn, FileMode.Open, FileAccess.Read);
            br = new BinaryReader(fs);

            //检测Y74的6字节文件标志46 43 44 45 00 00
            int id = br.ReadInt32();

            Debug.Assert(id == 0x45444346);
            id = br.ReadInt16();
            Debug.Assert(id == 0);

            //版本标志:commandos 2 or commandos 3
            version = br.ReadInt16();
            Debug.Assert(version >= 2 && version <= 4);
            if (version > 2)
            {
                version = 3;
            }

            //获得YCrCb色板和RGB色板
            if (version == 2)
            {
                palette = new YCrCbPalette(br, 48);
            }
            else
            {
                palette = new YCrCbPalette(br, 113);
            }
            rgb = new RGBPalette(palette);

            //获得视角数和每视角的图片数
            num_view         = br.ReadInt32();
            num_pic_per_view = br.ReadInt32();

            //获得每一图片的起始位置
            ptr_pics = new long[num_view, num_pic_per_view];
            for (int i = 0; i < num_view; i++)
            {
                for (int j = 0; j < num_pic_per_view; j++)
                {
                    ptr_pics[i, j] = br.ReadInt32();
                }
            }
        }