Beispiel #1
0
        public override bool import(byte[] file)
        {
            byte[] xdata = new byte[xlen];
            for (int i = 0; i < xdata.Length; i++)
            {
                xdata[i] = 0;
            }
            for (int i = 0; i < 128; i++)
            {
                xdata[i] = (byte)fwidth;
            }
            Bitmap bmp = new Bitmap(new System.IO.MemoryStream(file));

            for (int i = 0; i < 16; i++)
            {
                for (int j = 0; j < 8; j++)
                {
                    int       idx = i * 8 + j;
                    Rectangle rct = new Rectangle(j * 32, i * height, 32, height);
                    byte      wdh = 0;
                    for (int k = 0; k < height; k++)
                    {
                        UInt16 data = 0;
                        UInt16 mask = 0;
                        for (int m = 0; m < 16; m++)
                        {
                            Color dc = bmp.GetPixel(rct.X + m, rct.Y + k);
                            Color mc = bmp.GetPixel(rct.X + 16 + m, rct.Y + k);
                            if (dc.ToArgb() != Color.White.ToArgb())// || mc.ToArgb()!=Color.White.ToArgb())
                            {
                                if (wdh < m + 1)
                                {
                                    wdh = (byte)(m + 1);
                                }
                            }
                            data <<= 1;
                            mask <<= 1;
                            if (dc.ToArgb() != Color.White.ToArgb())
                            {
                                data |= 1;
                            }
                            if (mc.ToArgb() != Color.White.ToArgb())
                            {
                                mask |= 1;
                            }
                        }
                        if (data != 0 || mask != 0)
                        {
                            ByteHelper.WRITE_BE(data, xdata, 128 + idx * height * 4 + (k * 4));
                            ByteHelper.WRITE_BE(mask, xdata, 130 + idx * height * 4 + (k * 4));
                        }
                    }
                    if (wdh != 0)
                    {
                        xdata[idx] = wdh;
                    }
                }
            }
            return(SkyDisk.get().importFile((int)filenum, xdata));
        }
        public byte[] doCompress(byte[] data)
        {
            byte[] buffer = new byte[data.Length];
            ByteHelper.WRITE_BE((uint)0x524e4301, buffer, 0);
            ByteHelper.WRITE_BE((uint)data.Length, buffer, 4);
            ByteHelper.WRITE_BE(RNCCommon.crc(data, 0, data.Length), buffer, 12);
            this.bf = new BitBuffer(buffer, 0x12);
            byte num = 0;

            this.bf.writeBits(0, 2);
            this.ibuf = data;
            this.ipos = 0;
            while (this.ipos < this.ibuf.Length)
            {
                Tuple[] block = this.makeBlock();
                this.writeBlock(block);
                num = (byte)(num + 1);
            }
            this.bf.writeEnd();
            Array.Resize <byte>(ref buffer, this.bf.position);
            ByteHelper.WRITE_BE((uint)(buffer.Length - 0x12), buffer, 8);
            ByteHelper.WRITE_BE(RNCCommon.crc(buffer, 0x12, buffer.Length - 0x12), buffer, 14);
            buffer[0x10] = 0;
            buffer[0x11] = num;
            return(buffer);
        }