Exemple #1
0
    private static void Main()
    {
        int remainingTestCases = int.Parse(Console.ReadLine());

        while (remainingTestCases-- > 0)
        {
            int[] line        = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
            int   rowCount    = line[0];
            int   columnCount = line[1];

            string[] zeroOneRows = new string[rowCount];
            for (int r = 0; r < rowCount; ++r)
            {
                zeroOneRows[r] = Console.ReadLine();
            }

            var output = new StringBuilder();
            int?[,] nearestWhitePixelDistances = BITMAP.Solve(rowCount, columnCount, zeroOneRows);
            for (int r = 0; r < rowCount; ++r)
            {
                output.Append(nearestWhitePixelDistances[r, 0]);
                for (int c = 1; c < columnCount; ++c)
                {
                    output.Append($" {nearestWhitePixelDistances[r, c]}");
                }
                output.AppendLine();
            }

            Console.Write(output);
            Console.ReadLine();
        }
    }
        //一定時間ごとにスクショを保存する。
        void GetPict()
        {
            BITMAP bitmap = DisplayCapt.CaptureWindow(_hwnd);

            if (bitmap == null)
            {
                _exception = new InvalidHandleException();
                _isRun     = false;
                return;
            }

            if (bitmap.Width != _defBitmap.Width || bitmap.Height != _defBitmap.Height)
            {
                _exception = new ChangeSizeException();
                _isRun     = false;
                return;
            }


            BitmapData bdata = bitmap.Bitmap.LockBits(new Rectangle(0, 0, _defBitmap.Width, _defBitmap.Height),
                                                      ImageLockMode.ReadOnly, _defBitmap.PixelFormat);

            byte[] buf = new byte[_defBitmap.Size];

            Marshal.Copy(bdata.Scan0, buf, 0, _defBitmap.Size);

            bitmap.Bitmap.UnlockBits(bdata);

            _pictureBuf.Add(buf);
        }
Exemple #3
0
        static BitmapSource CreateBitmapSourceFromHandle(IntPtr bitmapHandle, BITMAP bitmap)
        {
            var bitmapSource = Imaging.CreateBitmapSourceFromHBitmap(bitmapHandle, IntPtr.Zero, new Int32Rect(0, 0, bitmap.Width, bitmap.Height), BitmapSizeOptions.FromWidthAndHeight(bitmap.Width, bitmap.Height));

            bitmapSource.Freeze();
            return(bitmapSource);
        }
Exemple #4
0
        /* draw a line (for wireframe display) */
        static void wire(BITMAP b, VTX v1, VTX v2)
        {
            int col = MID(128, 255 - fixtoi(v1.z + v2.z) / 16, 255);

            line(b, fixtoi(v1.x), fixtoi(v1.y), fixtoi(v2.x), fixtoi(v2.y),
                 palette_color[col]);
        }
Exemple #5
0
        private static void Main(string[] args)
        {
            //var r = CaptureUtil.DefGetCaptureData(ref offset, ref width, ref height);
            IntPtr hwnd = IntPtr.Zero;
            IntPtr hdc  = IntPtr.Zero;

            if (CaptureUtil.GetWindowHDC(ref hwnd, ref hdc))
            {
                int x = 0;
                int y = 0;
                CaptureUtil.GetWindowSize(hwnd, ref x, ref y);

                // 4k / 4 = 1k
                // sqrt(1024) = 32
                int       num        = 0;
                const int blockSize  = 128;
                var       bitmap     = new BITMAP();
                var       bitmapSize = CaptureUtil.DefGetCaptureBlockBitmap(hwnd, hdc, 0, 0, blockSize, blockSize, ref bitmap);
                int       blockSizeW = (x + blockSize - 1) / blockSize;
                int       blockSizeH = (y + blockSize - 1) / blockSize;
                for (int i = 0; i < blockSizeW; ++i)
                {
                    for (int j = 0; j < blockSizeH; ++j)
                    {
                        var r      = CaptureUtil.DefGetCaptureData(hwnd, hdc, bitmapSize, bitmap, i * blockSize, j * blockSize, blockSize, blockSize);
                        var result = CaptureUtil.ConvertBmpToJpeg(r);
                        using (FileStream fs = new FileStream(@"D:\Test\test" + num + @".jpg", FileMode.Create, FileAccess.Write))
                        {
                            fs.Write(result, 0, result.Length);
                        }
                        ++num;
                    }
                }
            }
        }
Exemple #6
0
        /* cull backfaces and draw cubes */
        static void draw_cube(BITMAP buffer, V3D_f[] x1, V3D_f[] x2)
        {
            int i;

            for (i = 0; i < 6; i++)
            {
                V3D_f vtx1, vtx2, vtx3, vtx4;

                vtx1 = x1[faces[i].v1];
                vtx2 = x1[faces[i].v2];
                vtx3 = x1[faces[i].v3];
                vtx4 = x1[faces[i].v4];
                if (polygon_z_normal_f(ref vtx1, ref vtx2, ref vtx3) > 0)
                {
                    quad3d_f(buffer, POLYTYPE_GCOL | POLYTYPE_ZBUF, NULL,
                             ref vtx1, ref vtx2, ref vtx3, ref vtx4);
                }

                vtx1 = x2[faces[i].v1];
                vtx2 = x2[faces[i].v2];
                vtx3 = x2[faces[i].v3];
                vtx4 = x2[faces[i].v4];
                if (polygon_z_normal_f(ref vtx1, ref vtx2, ref vtx3) > 0)
                {
                    quad3d_f(buffer, POLYTYPE_GCOL | POLYTYPE_ZBUF, NULL,
                             ref vtx1, ref vtx2, ref vtx3, ref vtx4);
                }
            }
        }
Exemple #7
0
        public void WritePixelsDirect(int[] pixels, int byteOffset = 0)
        {
            if (m_hBitmap == IntPtr.Zero)
            {
                throw new ObjectDisposedException(nameof(DibBitmap));
            }
            if (pixels == null)
            {
                throw new ArgumentNullException(nameof(pixels));
            }
            if (byteOffset < 0)
            {
                throw new ArgumentOutOfRangeException(nameof(byteOffset));
            }

            BITMAP bitmap = new BITMAP();
            int    size   = Marshal.SizeOf(bitmap);

            GetObject(m_hBitmap, size, out bitmap);
            if (bitmap.bmBits != IntPtr.Zero)
            {
                // invert y axis
                for (int y = 0; y < m_Height; y++)
                {
                    int srcPos = (byteOffset / 4) + (y * m_Width);
                    int dstPos = ((m_Height - y) * m_Width * 4);
                    // dstPos = 0;
                    Marshal.Copy(pixels, srcPos, bitmap.bmBits + dstPos, m_Width);
                }

                // Marshal.Copy(pixels, byteOffset / 4, bitmap.bmBits, m_Width * m_Height);
            }
        }
Exemple #8
0
        /* draw the shapes calculated by translate_shapes() */
        static void draw_shapes(BITMAP b)
        {
            int c;

            QUAD[] face = output_faces;
            VTX    v1, v2, v3, v4;

            /* depth sort */
            Array.Sort(output_faces);

            for (c = 0; c < NUM_FACES * NUM_SHAPES; c++)
            {
                /* find the vertices used by the face */
                v1 = face[c].vtxlist[face[c].v1];
                v2 = face[c].vtxlist[face[c].v2];
                v3 = face[c].vtxlist[face[c].v3];
                v4 = face[c].vtxlist[face[c].v4];

                /* draw the face */
                if (_render_mode == render_mode.wireframe)
                {
                    wire(b, v1, v2);
                    wire(b, v2, v3);
                    wire(b, v3, v4);
                    wire(b, v4, v1);
                }
                else
                {
                    draw_quad(b, v1, v2, v3, v4, render_type[(int)_render_mode]);
                }
            }
        }
        /* main animation control loop */
        static void triple_buffer(BITMAP page1, BITMAP page2, BITMAP page3)
        {
            BITMAP active_page = page1;
            int    page        = 0;

            do
            {
                /* draw a frame */
                draw(active_page);

                /* make sure the last flip request has actually happened */
                do
                {
                } while (poll_scroll());

                /* post a request to display the page we just drew */
                request_video_bitmap(active_page);

                /* update counters to point to the next page */
                switch (page)
                {
                case 0: page = 1; active_page = page2; break;

                case 1: page = 2; active_page = page3; break;

                case 2: page = 0; active_page = page1; break;
                }
            } while (!keypressed());

            clear_keybuf();
        }
Exemple #10
0
        /* draw a quad */
        static void draw_quad(BITMAP b, VTX v1, VTX v2, VTX v3, VTX v4, int mode)
        {
            int col;

            /* four vertices */
            V3D vtx1 = new V3D(0, 0, 0, 0, 0, 0);
            V3D vtx2 = new V3D(0, 0, 0, 32 << 16, 0, 0);
            V3D vtx3 = new V3D(0, 0, 0, 32 << 16, 32 << 16, 0);
            V3D vtx4 = new V3D(0, 0, 0, 0, 32 << 16, 0);

            vtx1.x = v1.x; vtx1.y = v1.y; vtx1.z = v1.z;
            vtx2.x = v2.x; vtx2.y = v2.y; vtx2.z = v2.z;
            vtx3.x = v3.x; vtx3.y = v3.y; vtx3.z = v3.z;
            vtx4.x = v4.x; vtx4.y = v4.y; vtx4.z = v4.z;

            /* cull backfaces */
            if ((mode != POLYTYPE_ATEX_MASK) && (mode != POLYTYPE_PTEX_MASK) &&
                (mode != POLYTYPE_ATEX_MASK_LIT) && (mode != POLYTYPE_PTEX_MASK_LIT) &&
                (polygon_z_normal(ref vtx1, ref vtx2, ref vtx3) < 0))
            {
                return;
            }

            /* set up the vertex color, differently for each rendering mode */
            switch (mode)
            {
            case POLYTYPE_FLAT:
                col    = MID(128, 255 - fixtoi(v1.z + v2.z) / 16, 255);
                vtx1.c = vtx2.c = vtx3.c = vtx4.c = palette_color[col];
                break;

            case POLYTYPE_GCOL:
                vtx1.c = palette_color[0xD0];
                vtx2.c = palette_color[0x80];
                vtx3.c = palette_color[0xB0];
                vtx4.c = palette_color[0xFF];
                break;

            case POLYTYPE_GRGB:
                vtx1.c = 0x000000;
                vtx2.c = 0x7F0000;
                vtx3.c = 0xFF0000;
                vtx4.c = 0x7F0000;
                break;

            case POLYTYPE_ATEX_LIT:
            case POLYTYPE_PTEX_LIT:
            case POLYTYPE_ATEX_MASK_LIT:
            case POLYTYPE_PTEX_MASK_LIT:
                vtx1.c = MID(0, 255 - fixtoi(v1.z) / 4, 255);
                vtx2.c = MID(0, 255 - fixtoi(v2.z) / 4, 255);
                vtx3.c = MID(0, 255 - fixtoi(v3.z) / 4, 255);
                vtx4.c = MID(0, 255 - fixtoi(v4.z) / 4, 255);
                break;
            }

            /* draw the quad */
            quad3d(b, mode, texture, ref vtx1, ref vtx2, ref vtx3, ref vtx4);
        }
Exemple #11
0
        /* draws a set of objects that demonstrate whats going on. It consists
         * of a cube, an arrow showing the 'to' orientation, an another arrow
         * showing the 'from' orientation, and another arrow showing the
         * interpolated orientation.
         */
        static void render_demo_box(BITMAP b, ref MATRIX_f from, ref MATRIX_f _in, ref MATRIX_f to, int col1, int col2, int col3)
        {
            float[,] tmp_points = new float[8, 3];

            render_wireframe_object(ref _in, b, box_points, tmp_points, box_edges, 8, 12, col1);
            render_wireframe_object(ref from, b, arrow_points, tmp_points, arrow_edges, 4, 3, col3);
            render_wireframe_object(ref to, b, arrow_points, tmp_points, arrow_edges, 4, 3, col3);
            render_wireframe_object(ref _in, b, arrow_points, tmp_points, arrow_edges, 4, 3, col2);
        }
Exemple #12
0
        public Image GetImageFromHBitmap(IntPtr hBitmap)
        {
            var bitmapStruct = new BITMAP();

            GetObjectBitmap(hBitmap, Marshal.SizeOf(bitmapStruct), ref bitmapStruct);
            var image = new Bitmap(bitmapStruct.bmWidth, bitmapStruct.bmHeight, bitmapStruct.bmWidth * 4, System.Drawing.Imaging.PixelFormat.Format32bppArgb, bitmapStruct.bmBits);

            return(image);
        }
        /* this merges 'bmp' into 'back'. This is how the trails work */
        static void blur_12(BITMAP bmp, BITMAP back)
        {
            int x, y, r1, g1, b1, r2, g2, b2, c1, c2;

            // TODO: check why I had to add "2 *"
            for (y = 0; y < 2 * bmp.h; y++)
            {
                ManagedPointerArray backline = back.line[y];
                ManagedPointerArray bmpline  = bmp.line[y];

                for (x = 0; x < bmp.w / 2; x++)
                {
                    /* first get the pixel from each bitmap, then move the first
                     * colour value slightly towards the second.
                     */
                    c1 = bmpline[x];
                    c2 = backline[x];
                    r1 = c1 & 0xF00;
                    r2 = c2 & 0xF00;
                    if (r1 < r2)
                    {
                        c1 += 0x100;
                    }
                    else if (r1 > r2)
                    {
                        c1 -= 0x100;
                    }

                    b1 = c1 & 0xF0;
                    b2 = c2 & 0xF0;
                    if (b1 < b2)
                    {
                        c1 += 0x10;
                    }
                    else if (b1 > b2)
                    {
                        c1 -= 0x10;
                    }

                    g1 = c1 & 0x0F;
                    g2 = c2 & 0x0F;
                    if (g1 < g2)
                    {
                        c1 += 0x01;
                    }
                    else if (g1 > g2)
                    {
                        c1 -= 0x01;
                    }

                    /* then put it back in the bitmap */
                    bmpline[x] = (ushort)c1;
                }
            }
        }
Exemple #14
0
 /* helper to draw four mirrored versions of a triangle */
 static void kalid(BITMAP bmp, int x1, int y1, int x2, int y2, int x3, int y3,
                   int r, int g, int b)
 {
     triangle(bmp, SCREEN_W / 2 + x1, SCREEN_H / 2 + y1, SCREEN_W / 2 + x2, SCREEN_H / 2 + y2,
              SCREEN_W / 2 + x3, SCREEN_H / 2 + y3, makecol(r, g, b));
     triangle(bmp, SCREEN_W / 2 - x1, SCREEN_H / 2 + y1, SCREEN_W / 2 - x2, SCREEN_H / 2 + y2,
              SCREEN_W / 2 - x3, SCREEN_H / 2 + y3, makecol(r, g, b));
     triangle(bmp, SCREEN_W / 2 - x1, SCREEN_H / 2 - y1, SCREEN_W / 2 - x2, SCREEN_H / 2 - y2,
              SCREEN_W / 2 - x3, SCREEN_H / 2 - y3, makecol(r, g, b));
     triangle(bmp, SCREEN_W / 2 + x1, SCREEN_H / 2 - y1, SCREEN_W / 2 + x2, SCREEN_H / 2 - y2,
              SCREEN_W / 2 + x3, SCREEN_H / 2 - y3, makecol(r, g, b));
 }
Exemple #15
0
 public BITMAP ProcessStack(BITMAP src)
 {
     return(src.Clone
            (
                dc =>
     {
         foreach (var xform in _Transforms)
         {
             xform?.Invoke(dc);
         }
     }
            ));
 }
Exemple #16
0
        //-------------------------------------------------------------------
        //
        //  Public Methods
        //
        //-------------------------------------------------------------------

        public void Open()
        {
            IntPtr hInstance = Marshal.GetHINSTANCE(typeof(SplashScreen).Module);

            BITMAP bitmapInfo         = new BITMAP();
            IntPtr splashScreenBitmap = GetHBitmapFromResource(hInstance, SplashScreenResourceType, SplashScreenResourceId);

            GetBitmapInformation(splashScreenBitmap, Marshal.SizeOf(typeof(BITMAP)), ref bitmapInfo);
            int top, left;

            CreateWindow(hInstance, bitmapInfo.bmWidth, bitmapInfo.bmHeight, out left, out top);
            SelectBitmap(splashScreenBitmap, bitmapInfo.bmWidth, bitmapInfo.bmHeight, left, top);
        }
Exemple #17
0
        public void CreateDIBitmapTest()
        {
            var bits = new byte[128 * 4];

            byte[] rlebits = { 2, 0, 0, 0, 2, 1, 0, 1 };

            using SafeHDC hdc = GetDC();

            BITMAPINFO bmi = new();

            bmi.bmiHeader.biSize          = (uint)Marshal.SizeOf <BITMAPINFOHEADER>();
            bmi.bmiHeader.biWidth         = 2;
            bmi.bmiHeader.biHeight        = 2;
            bmi.bmiHeader.biPlanes        = 1;
            bmi.bmiHeader.biBitCount      = 16;
            bmi.bmiHeader.biCompression   = BitmapCompressionMode.BI_RGB;
            bmi.bmiHeader.biSizeImage     = 0;
            bmi.bmiHeader.biXPelsPerMeter = 1;
            bmi.bmiHeader.biYPelsPerMeter = 1;
            bmi.bmiHeader.biClrUsed       = 0;
            bmi.bmiHeader.biClrImportant  = 0;

            SafeHBITMAP hbmp = CreateDIBitmap(hdc, bmi.bmiHeader, CBM.CBM_INIT, bits, bmi, DIBColorMode.DIB_RGB_COLORS);

            Assert.That(hbmp, ResultIs.ValidHandle);

            BITMAP bitmap = GetObject <BITMAP>(hbmp);

            Assert.IsTrue(bitmap.bmType == 0);
            Assert.IsTrue(bitmap.bmWidth == 2);
            Assert.IsTrue(bitmap.bmHeight == 2);
            Assert.That(bitmap.bmWidthBytes, Is.EqualTo(8));
            Assert.IsTrue(bitmap.bmPlanes == 1);
            Assert.IsTrue(bitmap.bmBitsPixel == GetDeviceCaps(hdc, DeviceCap.BITSPIXEL));
            Assert.IsTrue(bitmap.bmBits == IntPtr.Zero);

            bmi.bmiHeader.biCompression = BitmapCompressionMode.BI_RLE8;
            bmi.bmiHeader.biBitCount    = 8;
            bmi.bmiHeader.biSizeImage   = 8;
            bmi.bmiHeader.biClrUsed     = 1;
            Assert.That(hbmp            = CreateDIBitmap(hdc, bmi.bmiHeader, CBM.CBM_INIT, rlebits, new SafeBITMAPINFO(bmi), DIBColorMode.DIB_PAL_COLORS), ResultIs.ValidHandle);

            bitmap = GetObject <BITMAP>(hbmp);
            Assert.IsTrue(bitmap.bmType == 0);
            Assert.IsTrue(bitmap.bmWidth == 2);
            Assert.IsTrue(bitmap.bmHeight == 2);
            Assert.That(bitmap.bmWidthBytes, Is.EqualTo(8));
            Assert.IsTrue(bitmap.bmPlanes == 1);
            Assert.IsTrue(bitmap.bmBitsPixel == GetDeviceCaps(hdc, DeviceCap.BITSPIXEL));
            Assert.IsTrue(bitmap.bmBits == IntPtr.Zero);
        }
        /* helper function to draw a hand on the clock */
        static void draw_hand(BITMAP bmp, int value, int range, int v2, int range2, int length, int color)
        {
            int angle;
            int x, y;
            int w, h;

            angle = ((itofix(value) * 256) / range) +
                    ((itofix(v2) * 256) / (range * range2)) - itofix(64);

            x = fixmul(fixcos(angle), length);
            y = fixmul(fixsin(angle), length);
            w = bmp.w / 2;
            h = bmp.h / 2;

            line(bmp, w, h, w + fixtoi(x * w), h + fixtoi(y * h), color);
        }
        //初期化
        void Initialize(PixelFormat pixelFormat)
        {
            _defBitmap = DisplayCapt.CaptureWindow(_hwnd);

            if (_defBitmap == null)
            {
                throw new InvalidHandleException();
            }

            _defBitmap.PixelFormat = pixelFormat;
            BitmapData bitmapData = _defBitmap.Bitmap.LockBits(new Rectangle(0, 0, _defBitmap.Width, _defBitmap.Height), ImageLockMode.ReadOnly, _defBitmap.PixelFormat);

            _defBitmap.Stride = bitmapData.Stride;
            _defBitmap.Size   = _defBitmap.Stride * _defBitmap.Height;
            _defBitmap.Bitmap.UnlockBits(bitmapData);
        }
        public byte[] GetIcon(string path, bool allowThumbnails, int dimensions = 256)
        {
            var bitmapHandle = IntPtr.Zero;

            var uniqueId = new Guid("43826d1e-e718-42ee-bc55-a1e261c37bfe");

            IShellItem rawFactory;
            SHCreateItemFromParsingName(path, IntPtr.Zero, uniqueId, out rawFactory);

            var factory = (IShellItemImageFactory)rawFactory;

            var iconOnlyScope = SIIGBF.SIIGBF_ICONONLY;
            var sizeScope = SIIGBF.SIIGBF_BIGGERSIZEOK;
            var scope = (allowThumbnails ? SIIGBF.SIIGBF_THUMBNAILONLY : iconOnlyScope) | sizeScope;

            try
            {
                factory.GetImage(new SIZE(dimensions, dimensions), scope, ref bitmapHandle);
            }
            catch (COMException ex) when (ex.ErrorCode == -2147175936 && allowThumbnails)
            {
                //no thumbnail available. fetch the icon instead.
                factory.GetImage(new SIZE(dimensions, dimensions), iconOnlyScope | sizeScope, ref bitmapHandle);
            }

            if (bitmapHandle != IntPtr.Zero)
            {
                var bitmap = new BITMAP();
                var bufferSize = Marshal.SizeOf(bitmap);

                GetObject(bitmapHandle, bufferSize, out bitmap);

                var bytes = new byte[bitmap.WidthBytes * bitmap.Height];
                Marshal.Copy(bitmap.Bits, bytes, 0, bytes.Length);

                DeleteObject(bitmapHandle);

                return bytes;
            }
            else
            {

                //the handle is 0, assume that the data comes from Windows itself.
                return null;

            }
        }
Exemple #21
0
        public static byte[] DefGetCaptureData(IntPtr hwnd, IntPtr hdc, uint size, BITMAP bmp, int x, int y, int w, int h)
        {
            uint offset = 0;

            byte[] data = new byte[size];
            offset = AppendBitmapHeader(ref data[0], ref bmp);

            if (offset == 0)
            {
                return(null);
            }
            if (GetCaptureData(hwnd, hdc, x, y, w, h, ref data[offset]) == 0)
            {
                return(null);
            }
            return(data);
        }
            public rodent(BITMAP bmp)
            {
                x = rand.Next() % (SCREEN_W - bmp.w);
                y = rand.Next() % (SCREEN_H - bmp.h);

                do
                {
                    delta_x = (rand.Next() % 11) - 5;
                } while (delta_x == 0);

                do
                {
                    delta_y = (rand.Next() % 11) - 5;
                } while (delta_y == 0);

                sprite = bmp;
            }
        byte[] GenerateByteArrayFromBitmapHandle(IntPtr bitmapHandle)
        {
            var bitmap = new BITMAP();
            AllocateBitmapSpace(bitmapHandle, ref bitmap);

            try
            {
                FillBitmapBitsIntoHandle(bitmap);

                var bitmapSource = CreateBitmapSourceFromHandle(bitmapHandle, bitmap);
                return imagePersistenceService.ConvertBitmapSourceToByteArray(bitmapSource);
            }
            finally
            {
                DeleteObject(bitmapHandle);
            }
        }
Exemple #24
0
        /* draws a frame of the animation */
        static void draw(BITMAP b)
        {
            int c;
            //char message[1024];
            string message;

            acquire_bitmap(b);

            clear_bitmap(b);

            for (c = 0; c < NUM_SHAPES; c++)
            {
                triangle(b,
                         fixtoi(shapes[c].x + fixmul(shapes[c].dist1,
                                                     fixcos(shapes[c].dir1))),
                         fixtoi(shapes[c].y + fixmul(shapes[c].dist1,
                                                     fixsin(shapes[c].dir1))),
                         fixtoi(shapes[c].x + fixmul(shapes[c].dist2,
                                                     fixcos(shapes[c].dir2))),
                         fixtoi(shapes[c].y + fixmul(shapes[c].dist2,
                                                     fixsin(shapes[c].dir2))),
                         fixtoi(shapes[c].x + fixmul(shapes[c].dist3,
                                                     fixcos(shapes[c].dir3))),
                         fixtoi(shapes[c].y + fixmul(shapes[c].dist3,
                                                     fixsin(shapes[c].dir3))),
                         shapes[c].color);

                move_shape(shapes[c]);
            }

            if (triplebuffer_not_available)
            {
                //ustrzcpy(message, sizeof message, "Simulated triple buffering");
                message = "Simulated triple buffering";
            }
            else
            {
                //ustrzcpy(message, sizeof message, "Real triple buffering");
                message = "Real triple buffering";
            }

            textout_ex(b, font, message, 0, 0, 255, -1);

            release_bitmap(b);
        }
Exemple #25
0
        byte[] GenerateByteArrayFromBitmapHandle(IntPtr bitmapHandle)
        {
            var bitmap = new BITMAP();

            AllocateBitmapSpace(bitmapHandle, ref bitmap);

            try
            {
                FillBitmapBitsIntoHandle(bitmap);

                var bitmapSource = CreateBitmapSourceFromHandle(bitmapHandle, bitmap);
                return(imagePersistenceService.ConvertBitmapSourceToByteArray(bitmapSource));
            }
            finally
            {
                DeleteObject(bitmapHandle);
            }
        }
        static void magic_putpix(BITMAP bmp, int x, int y, int r, int g, int b)
        {
            //bmp.line[y][(x) * 3] &= 0xE0;
            //bmp.line[y][(x) * 3 + 1] &= 0xE0;
            //bmp.line[y][(x) * 3 + 2] &= 0xE0;
            ManagedBytePointerArray line = new ManagedBytePointerArray(bmp.line).Offset(y * 3 * 256 * sizeof(byte));

            line[x * 3]     &= 0xE0;
            line[x * 3 + 1] &= 0xE0;
            line[x * 3 + 2] &= 0xE0;

            //bmp.line[y][(x) * 3] |= r;
            //bmp.line[y][(x) * 3 + 1] |= g;
            //bmp.line[y][(x) * 3 + 2] |= b;
            line[x * 3]     |= (byte)r;
            line[x * 3 + 1] |= (byte)g;
            line[x * 3 + 2] |= (byte)b;
        }
Exemple #27
0
        public static void _3D()
        {
            BITMAP buffer = create_bitmap(SCREEN_W, SCREEN_H);

            create_scene(24, 6);
            set_projection_viewport(0, 0, SCREEN_W, SCREEN_H);
            MATRIX_f matrix = new MATRIX_f(), matrix_r = new MATRIX_f(), matrix_t = new MATRIX_f();
            int      rx = 0, ry = 0, tz = 40;
            int      rot = 0, inc = 1;
            int      k = 1;

            while (!key[KEY_ESC])
            {
                clear_bitmap(buffer);
                clear_scene(buffer);

                get_rotation_matrix_f(ref matrix_r, rx, ry, 0);

                get_translation_matrix_f(ref matrix_t, 0, 0, tz + k * 40);

                matrix_mul_f(ref matrix_r, ref matrix_t, out matrix);

                matrix = matrix_r;

                draw_cube(ref matrix);

                render_scene();

                tz -= 2;
                if (tz == 0)
                {
                    tz = 40;
                }
                rx  += 4;
                ry  += 4;
                rot += inc;
                if ((rot >= 25) || (rot <= -25))
                {
                    inc = -inc;
                }
            }
            destroy_bitmap(buffer);
            destroy_scene();
        }
Exemple #28
0
        static void Main()
        {
            allegro_init();
            if (install_keyboard() != 0)
            {
                return;
            }
            install_mouse();
            install_timer();

            int bpp = 32;

            set_color_depth(bpp);
            if (set_gfx_mode(GFX_AUTODETECT_WINDOWED, 640, 480, 0, 0) != 0)
            {
                allegro_message("Error: " + allegro_error);
            }

            //Allegro();
            //Gui();
            //Menu();
            //_3D();
            //Direct(bpp);
            //Fixed();

            BITMAP source = create_bitmap(24, 48);

            clear_to_color(source, makecol(0, 0, 255));
            RLE_SPRITE      sprite   = get_rle_sprite(source);
            COMPILED_SPRITE compiled = get_compiled_sprite(source, FALSE);

            draw_sprite(screen, source, 64, 64);
            draw_rle_sprite(screen, sprite, 32, 32);
            rectfill(screen, 96, 96, 128, 128, makecol(255, 0, 0));
            draw_compiled_sprite(screen, compiled, 160, 160);

            readkey();

            //world game = new world();
            //game.Dispose();

            allegro_exit();
        }
        /* converts a bitmap from the normal Allegro format into our magic layout */
        static BITMAP get_magic_bitmap_format(BITMAP orig, PALETTE pal)
        {
            BITMAP bmp;
            int    c, r, g, b;
            int    x, y;
            int    bpp;

            /* create an 8 bpp image, three times as wide as the original */
            bmp = create_bitmap_ex(8, orig.w * 3, orig.h);

            /* store info about the original bitmap format */
            bpp = bitmap_color_depth(orig);
            //select_palette(pal);

            /* convert the data */
            for (y = 0; y < orig.h; y++)
            {
                for (x = 0; x < orig.w; x++)
                {
                    c = getpixel(orig, x, y);

                    r = getr_depth(bpp, c);
                    g = getg_depth(bpp, c);
                    b = getb_depth(bpp, c);

                    //bmp->line[y][x*3] = r*31/255 | AMBIENT_LIGHT;
                    //bmp->line[y][x*3+1] = g*31/255 | AMBIENT_LIGHT;
                    //bmp->line[y][x*3+2] = b*31/255 | AMBIENT_LIGHT;

                    r = (r * 31 / 255) | AMBIENT_LIGHT;
                    g = (g * 31 / 255) | AMBIENT_LIGHT;
                    b = (b * 31 / 255) | AMBIENT_LIGHT;

                    ManagedBytePointerArray line = new ManagedBytePointerArray(bmp.line).Offset(y * 3 * orig.w * sizeof(byte));
                    line[x * 3]     = (byte)r;
                    line[x * 3 + 1] = (byte)g;
                    line[x * 3 + 2] = (byte)b;
                }
            }

            /* return our new, magic format version of the image */
            return(bmp);
        }
Exemple #30
0
        static void draw_pattern(BITMAP bitmap, string message, int color)
        {
            BITMAP pattern;

            acquire_bitmap(bitmap);

            /* create a pattern bitmap */
            pattern = create_bitmap(text_length(font, message), text_height(font));
            clear_to_color(pattern, bitmap_mask_color(pattern));
            textout_ex(pattern, font, message, 0, 0, palette_color[255], bitmap_mask_color(screen));

            /* cover the bitmap with the pattern */
            drawing_mode(DRAW_MODE_MASKED_PATTERN, pattern, 0, 0);
            rectfill(bitmap, 0, 0, bitmap.w, bitmap.h, palette_color[color]);
            solid_mode();

            /* destroy the pattern bitmap */
            destroy_bitmap(pattern);

            release_bitmap(bitmap);
        }
Exemple #31
0
        protected override BITMAP Evaluate()
        {
            if (Source == null)
            {
                return(null);
            }

            var target = new BITMAP(Source.Width, Source.Height);

            foreach (var layer in Layers.Where(l => l != null))
            {
                using (var clone = layer.ProcessStack(Source))
                {
                    target.Mutate(dc => dc.DrawImage(clone, layer.Mode, layer.Opacity));
                }
            }

            Source.Dispose();

            return(target);
        }
        /* generates some nice RGB scales onto the specified bitmap */
        static void rgb_scales_12(BITMAP bmp, int ox, int oy, int w, int h)
        {
            int x, y;

            for (y = 0; y < h; y++)
            {
                for (x = 0; x < w; x++)
                {
                    putpixel(bmp, ox + x, oy + y, makecol12(x * 256 / w, y * 256 / h, 0));
                }
            }

            for (y = 0; y < h; y++)
            {
                for (x = 0; x < w; x++)
                {
                    putpixel(bmp, ox + x + w, oy + y, makecol12(x * 256 / w, 0, y * 256 / h));
                }
            }

            for (y = 0; y < h; y++)
            {
                for (x = 0; x < w; x++)
                {
                    putpixel(bmp, ox + x, oy + y + h, makecol12(0, x * 256 / w, y * 256 / h));
                }
            }

            for (y = 0; y < h; y++)
            {
                for (x = 0; x < w; x++)
                {
                    putpixel(bmp, ox + x + w, oy + y + h, makecol12(x * 128 / w + y * 128 / h,
                                                                    x * 128 / w + y * 128 / h,
                                                                    x * 128 / w + y * 128 / h));
                }
            }
        }
		private static extern int GetObjectBitmap(IntPtr hObject, int nCount, ref       BITMAP lpObject);
 static void FillBitmapBitsIntoHandle(BITMAP bitmap)
 {
     var bytes = new byte[bitmap.WidthBytes * bitmap.Height];
     Marshal.Copy(bitmap.Bits, bytes, 0, bytes.Length);
 }
 public static extern int GetObject(HBITMAP hbmp, int cb, ref BITMAP bm);
 static BitmapSource CreateBitmapSourceFromHandle(IntPtr bitmapHandle, BITMAP bitmap)
 {
     var bitmapSource = Imaging.CreateBitmapSourceFromHBitmap(bitmapHandle, IntPtr.Zero, new Int32Rect(0, 0, bitmap.Width, bitmap.Height), BitmapSizeOptions.FromWidthAndHeight(bitmap.Width, bitmap.Height));
     bitmapSource.Freeze();
     return bitmapSource;
 }
Exemple #37
0
 public static extern int GetObject(IntPtr hObj, int cb, ref BITMAP obj);
 static void AllocateBitmapSpace(IntPtr bitmapHandle, ref BITMAP bitmap)
 {
     var bufferSize = Marshal.SizeOf(bitmap);
     GetObject(bitmapHandle, bufferSize, out bitmap);
 }
Exemple #39
0
 public static extern int GetObject(IntPtr hgdiobj, int cbBuffer, ref BITMAP lpvObject);
 internal static extern int GetObject(
     IntPtr hgdiobj,
     int cbBuffer,
     out BITMAP lpvObject
     );
 int IIconNativeApi.GetObject(IntPtr hgdiobj, int cbBuffer, out BITMAP lpvObject)
 {
     return GetObject(hgdiobj, cbBuffer, out lpvObject);
 }
		/// <summary>
		/// Converts a Windows DIBSection object to a Bitmap.
		/// </summary>
		/// <param name="hDib">Handle to a Windows DIBSection.</param>
		/// <returns>Bitmap containing the DIBSection picture.</returns>
		public static Bitmap DibToBitmap(IntPtr hDib) {

			BITMAP tBM = new BITMAP();
			GetObjectBitmap(hDib, Marshal.SizeOf(tBM), ref tBM);
			Bitmap bm = new Bitmap(tBM.bmWidth, tBM.bmHeight);

			// set the bitmap's data to the data from
			// the DIB:
			if (tBM.bmBitsPixel == 32) {
				// Bizarre but true: you *must* clone the newly created
				// bitmap to get one with the correct pixel format, even
				// if you attempted to create the original one with the 
				// correct format...
				bm = bm.Clone(new Rectangle(0, 0, tBM.bmWidth, tBM.bmHeight), PixelFormat.Format32bppArgb);

				// Lock the bitmap bits
				BitmapData destData = bm.LockBits(new Rectangle(0, 0, bm.Width, bm.Height), ImageLockMode.ReadWrite, PixelFormat.Format32bppArgb);
				int destWidth = destData.Stride;
				IntPtr destScan0 = destData.Scan0;

				unsafe {
					byte* pDest = (byte*)(void*)destScan0;
					// The DIB is upside down compared to a GDI+ bitmap
					pDest += ((bm.Width * 4) * (bm.Height - 1));
					byte* pSrc = (byte*)(void*)tBM.bmBits;

					for (int y = 0; y < bm.Height; ++y) {
						for (int x = 0; x < bm.Width; ++x) {
							pDest[0] = pSrc[0]; // blue
							pDest[1] = pSrc[1]; // green
							pDest[2] = pSrc[2]; // red
							pDest[3] = pSrc[3]; // alpha

							// Move to next BGRA
							pDest += 4;
							pSrc += 4;
						}
						pDest -= (bm.Width * 8);
					}
				}

				bm.UnlockBits(destData);
			}
			else {
				// Easier to just copy src -> dst using GDI.

				// Put the DIB into a DC:
				IntPtr hWndDesktop = GetDesktopWindow();
				IntPtr hDCComp = GetDC(hWndDesktop);
				IntPtr hDCSrc = CreateCompatibleDC(hDCComp);

				ReleaseDC(hWndDesktop, hDCComp);
				
				IntPtr hBmpOld = SelectObject(hDCSrc, hDib);

				Graphics gfx = Graphics.FromImage(bm);
				IntPtr hDCDest = gfx.GetHdc();
				
				BitBlt(hDCDest, 0, 0, tBM.bmWidth, tBM.bmHeight, hDCSrc, 0, 0, SRCCOPY);
				gfx.ReleaseHdc(hDCDest);

				SelectObject(hDCSrc, hBmpOld);
				DeleteDC(hDCSrc);
			}


			return bm;

		}