public Bitmap export(int w, int h, string pal) { Bitmap bmp = new Bitmap(w, h, System.Drawing.Imaging.PixelFormat.Format8bppIndexed); ColorPalette tmppal = bmp.Palette; LureConfig.LurePalette p = LureConfig.get().getPalette(pal); for (int i = 0; i < 256; i++) { tmppal.Entries[i] = p.cols[i]; } byte[] tdata = new byte[w * h]; int xlen = xdata.Length; if (w * h < xlen) { xlen = w * h; } Array.Copy(xdata, 0, tdata, 0, xlen); unused = xdata.Length - xlen; while (xlen < tdata.Length) { tdata[xlen++] = 0; } bmp.Palette = tmppal; BitmapData bd = bmp.LockBits(new Rectangle(0, 0, w, h), ImageLockMode.WriteOnly, bmp.PixelFormat); for (int i = 0; i < bd.Height; i++) { System.Runtime.InteropServices.Marshal.Copy(tdata, i * bd.Width, new IntPtr(bd.Scan0.ToInt64() + i * bd.Stride), bd.Width); } bmp.UnlockBits(bd); return(bmp); }
public void import(Bitmap bmp) { if (bmp.Width != width || bmp.Height != height) { throw new Exception(String.Format("Wrong bmp size {0}x{1} (need {2}x{3})", bmp.Width, bmp.Height, width, height)); } ColorPalette pal = bmp.Palette; LureConfig.LurePalette xpal = LureConfig.get().getPalette(palette); for (int i = 0; i < 256; i++) { if (pal.Entries[i].ToArgb() != xpal.cols[i].ToArgb()) { throw new Exception("Palette differs"); } } byte[] res = new byte[width * height]; BitmapData bd = bmp.LockBits(new Rectangle(0, 0, width, height), ImageLockMode.ReadWrite, bmp.PixelFormat); for (int i = 0; i < height; i++) { System.Runtime.InteropServices.Marshal.Copy(new IntPtr(bd.Scan0.ToInt64() + i * bd.Stride), res, i * bd.Width, bd.Width); } bmp.UnlockBits(bd); byte[] nr = Compressor.compress(res); LureDisks.setResource(resnum, nr); }
public Bitmap export(string pal) { byte[] tdata = new byte[xlen]; int iOfs = xlen; Array.Copy(xdata, 0, tdata, 0, xlen); List <byte[]> imgs = new List <byte[]>(); imgs.Add((byte[])tdata.Clone()); int cOfs = 0; while (cOfs < cdata.Length && iOfs < xdata.Length) { int sOfs = 0; while (sOfs < xlen) { UInt16 len = cdata[cOfs++]; if (len == 0) { len = BinaryHelper.readU16_LE(cdata, cOfs); cOfs += 2; } if (len > 0) { Array.Copy(xdata, iOfs, tdata, sOfs, len); iOfs += len; sOfs += len; } len = cdata[cOfs++]; if (len == 0) { len = BinaryHelper.readU16_LE(cdata, cOfs); cOfs += 2; } sOfs += len; } //next screen imgs.Add((byte[])tdata.Clone()); } Bitmap bmp = new Bitmap(320, 200 * imgs.Count, System.Drawing.Imaging.PixelFormat.Format8bppIndexed); ColorPalette tmppal = bmp.Palette; LureConfig.LurePalette p = LureConfig.get().getPalette(pal); for (int i = 0; i < 256; i++) { tmppal.Entries[i] = p.cols[i]; } bmp.Palette = tmppal; BitmapData bd = bmp.LockBits(new Rectangle(0, 0, 320, 200 * imgs.Count), ImageLockMode.WriteOnly, bmp.PixelFormat); for (int i = 0; i < bd.Height; i++) { System.Runtime.InteropServices.Marshal.Copy(imgs[i / 200], (i % 200) * bd.Width, new IntPtr(bd.Scan0.ToInt64() + i * bd.Stride), bd.Width); } bmp.UnlockBits(bd); return(bmp); }
public void import(Bitmap bmp) { if (bmp.Width != 320 || bmp.Height % 200 != 0) { throw new Exception(String.Format("Wrong bmp size {0}x{1} (need 320x200n)", bmp.Width, bmp.Height)); } ColorPalette pal = bmp.Palette; LureConfig.LurePalette xpal = LureConfig.get().getPalette(palette); for (int i = 0; i < 256; i++) { if (pal.Entries[i].ToArgb() != xpal.cols[i].ToArgb()) { throw new Exception("Palette differs"); } } byte[] data = new byte[320 * bmp.Height]; BitmapData bd = bmp.LockBits(new Rectangle(0, 0, 320, bmp.Height), ImageLockMode.ReadWrite, bmp.PixelFormat); for (int i = 0; i < bmp.Height; i++) { System.Runtime.InteropServices.Marshal.Copy(new IntPtr(bd.Scan0.ToInt64() + i * bd.Stride), data, i * bd.Width, bd.Width); } bmp.UnlockBits(bd); int screens = bmp.Height / 200; byte[] dt2 = new byte[xlen]; byte[] cmd = new byte[0]; int rOfs = xlen; int cOfs = 0; Array.Copy(data, dt2, xlen); for (int i = 1; i < screens; i++) { byte[] pix; byte[] code; compressScreen(data, i, out pix, out code); Array.Resize <byte>(ref dt2, dt2.Length + pix.Length); Array.Copy(pix, 0, dt2, rOfs, pix.Length); rOfs += pix.Length; Array.Resize <byte>(ref cmd, cmd.Length + code.Length); Array.Copy(code, 0, cmd, cOfs, code.Length); cOfs += code.Length; } data = null; byte[] nr = Compressor.compress(dt2); LureDisks.setResource(resnum, nr); LureDisks.setResource(resnum + 1, cmd); }