コード例 #1
0
ファイル: sIMG.cs プロジェクト: q4a/ToxicRagers
        public void ImportFromBitmap(Bitmap bitmap, CompressionMethod compression = CompressionMethod.RLE)
        {
            if (bitmap.Width <= 32 || bitmap.Height <= 32)
            {
                bitmap = bitmap.Resize(64, 64);
            }

            width  = bitmap.Width;
            height = bitmap.Height;

            int planeCount = 4;// Image.GetPixelFormatSize(bitmap.PixelFormat) / 8;

            if (bitmap.Width < 8 && bitmap.Height < 8)
            {
                planeCount = 1;
            }

            BitmapData bmpdata = bitmap.LockBits(new Rectangle(0, 0, width, height), ImageLockMode.ReadOnly, PixelFormat.Format32bppArgb);

            byte[] iB = new byte[4 * bmpdata.Width * bmpdata.Height];
            Marshal.Copy(bmpdata.Scan0, iB, 0, bmpdata.Stride * bmpdata.Height);
            bitmap.UnlockBits(bmpdata);

            Parallel.For(0, planeCount,
                         i =>
                         //for (int i = 0; i < planeCount; i++)
            {
                Plane plane = new Plane(i)
                {
                    Data = iB.ToList().Every(planeCount, i).ToArray()
                };
                plane.Compress(planeCount > 1 ? compression : CompressionMethod.None);
                planes.Add(plane);
            }
                         );

            switch (planeCount)
            {
            case 1:
                planeFormat = PlaneFormat.Format1planeARGB;
                break;

            case 3:
                planeFormat = PlaneFormat.Format4planeXRGB;
                break;

            case 4:
                planeFormat = PlaneFormat.Format4planeARGB;
                break;
            }
        }
コード例 #2
0
ファイル: sIMG.cs プロジェクト: DevilboxGames/ToxicRagers
        public void ImportFromBitmap(Bitmap bitmap, CompressionMethod compression = CompressionMethod.RLE)
        {
            if (bitmap.Width <= 32 || bitmap.Height <= 32) { bitmap = bitmap.Resize(64, 64); }

            width = bitmap.Width;
            height = bitmap.Height;

            int planeCount = 4;// Image.GetPixelFormatSize(bitmap.PixelFormat) / 8;

            if (bitmap.Width < 8 && bitmap.Height < 8) { planeCount = 1; }

            BitmapData bmpdata = bitmap.LockBits(new Rectangle(0, 0, width, height), ImageLockMode.ReadOnly, PixelFormat.Format32bppArgb);
            byte[] iB = new byte[4 * bmpdata.Width * bmpdata.Height];
            Marshal.Copy(bmpdata.Scan0, iB, 0, bmpdata.Stride * bmpdata.Height);
            bitmap.UnlockBits(bmpdata);

            Parallel.For(0, planeCount,
                i =>
                //for (int i = 0; i < planeCount; i++)
                {
                    var plane = new Plane(i);
                    plane.Data = iB.ToList().Every(planeCount, i).ToArray();
                    plane.Compress(planeCount > 1 ? compression : CompressionMethod.None);
                    planes.Add(plane);
                }
            );

            switch (planeCount)
            {
                case 1:
                    planeFormat = PlaneFormat.Format1planeARGB;
                    break;

                case 3:
                    planeFormat = PlaneFormat.Format4planeXRGB;
                    break;

                case 4:
                    planeFormat = PlaneFormat.Format4planeARGB;
                    break;
            }
        }