예제 #1
0
 private bool Equ(ByteArray8 value)
 {
     for (int i = 0; i < data.Length; i += 8)
     {
         if ((BitConverter.ToInt64(data, i) & 0x0F0F0F0F0F0F0F0F) !=
             (BitConverter.ToInt64(value.data, i) & 0x0F0F0F0F0F0F0F0F))
             return(false); }
     }
예제 #2
0
        //

        /*
         * public unsafe static void toRaw(Bitmap bm, string directory, writeRaw _4)//true = 4,false=8
         * {
         *  if (bm.PixelFormat != PixelFormat.Format8bppIndexed)
         *      bm = ConvertGBAImageToBitmapIndexed(bm);
         *  Dictionary<ByteArray, byte> bitmaps = new Dictionary<ByteArray, byte>(256);
         *  BitmapData bd = bm.LockBits(new Rectangle(0, 0, bm.Width, bm.Height),
         *      ImageLockMode.ReadOnly, PixelFormat.Format8bppIndexed);
         *  long* ptr = (long*)bd.Scan0.ToPointer();
         *  ByteArray data = new ByteArray(new long[8]);
         *  byte count = 0;
         *  FileStream fs = new FileStream(string.Concat(directory, "/raw1.raw"), FileMode.Create);
         *  Bitmap result = new Bitmap(8, 128 * 16, PixelFormat.Format8bppIndexed)
         *  {
         *      Palette = bm.Palette
         *  };
         *  for(int y = 0;y < bm.Height >> 3; y++)
         *  {
         *      for (int x = 0, width = (bm.Width >> 3); x < width; x++)
         *      {
         *          int block = y * width * 8 + x;
         *          for (int i = 0; i < 8; i++)
         *          {
         *              data[i] = ptr[block + i * width];
         *          }
         *          if (!bitmaps.TryGetValue(data, out byte v))
         *          {
         *              bitmaps[(ByteArray)data.Clone()] = count;
         *              v = count;
         *              WriteData(result, data.data, count);
         *              count++;
         *          }
         *          //fs.WriteByte(v);
         *          //_4(fs,v,data.data);
         *      }
         *  }
         *  bm.UnlockBits(bd);
         *  bm.Dispose();
         *  fs.Close();
         *  count = (count & 7) == 0 ? count : (byte)(count + 8 - (count & 7));
         *  bm = result.Clone(new Rectangle(0, 0, 8, 8 * count), PixelFormat.Format8bppIndexed);
         *  result.Dispose();
         *  bm.Save(string.Concat(directory, "/tile1.png"), ImageFormat.Png);
         *  bm.Dispose();
         * }
         */
        public unsafe static void toRaw(Bitmap bm, string directory)//true = 4,false=8
        {
            if (bm.PixelFormat != PixelFormat.Format8bppIndexed)
            {
                bm = ConvertGBAImageToBitmapIndexed(bm);
            }
            Dictionary <ByteArray, ushort> bitmaps = new Dictionary <ByteArray, ushort>(0x400);
            BitmapData bd = bm.LockBits(new Rectangle(0, 0, bm.Width, bm.Height),
                                        ImageLockMode.ReadOnly, PixelFormat.Format8bppIndexed);
            long *    ptr    = (long *)bd.Scan0.ToPointer();
            ByteArray data   = new ByteArray8();
            ushort    count  = 0;
            Bitmap    result = new Bitmap(8 * 8, 128 * 8, PixelFormat.Format8bppIndexed)
            {
                Palette = bm.Palette
            };
            BinaryWriter bw = new BinaryWriter(new FileStream(directory + "/raw1.raw", FileMode.Create));

            for (int y = 0; y < bm.Height >> 3; y++)
            {
                for (int x = 0, width = (bm.Width >> 3); x < width; x++)
                {
                    int block = y * width * 8 + x;
                    for (int i = 0; i < 8; i++)
                    {
                        data[i] = ptr[block + i * width];
                    }
                    if (!bitmaps.TryGetValue(data, out ushort v))
                    {
                        bitmaps[(ByteArray)data.Clone()] = count;
                        v = count;
                        data.WriteToTileset(result, count);
                        count++;
                    }
                    v = (ushort)(v | (data.data[0] >> 4 << 12));
                    if (ByteArray8.x_reverse)
                    {
                        v |= ByteArray.X_MASK;
                    }
                    if (ByteArray8.y_reverse)
                    {
                        v |= ByteArray.Y_MASK;
                    }
                    bw.Write(v);
                }
                bw.Flush();
            }
            bm.UnlockBits(bd);
            bw.Close();
            count = (count % 8) == 0 ? count : (ushort)(count + 8 - (count % 8));
            bm    = result.Clone(new Rectangle(0, 0, result.Width, count), PixelFormat.Format8bppIndexed);
            bm.Save(string.Concat(directory, "/tile1.png"), ImageFormat.Png);
        }