示例#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
        long address;                           //64*64图块在Y64文件中的起始位置

        public Block(BinaryReader br, long address)
        {
            this.address = address;
            br.BaseStream.Seek(address, SeekOrigin.Begin);

            //跳过Seperator,它不一定是0xffffffffffffffff!
            br.BaseStream.Seek(8, SeekOrigin.Current);

            subs = new SubBlock[8, 8];
            for (int h = 0; h < 8; h++)
            {
                for (int w = 0; w < 8; w++)
                {
                    //依次计算各8*8子图块的起始位置,并生成各子图块
                    long off = address + 8 + 56 * (h * 8 + w);                     //每个subblock长56字节
                    subs[h, w] = new SubBlock(br, off);
                }
            }
        }