Пример #1
0
        /* creates the light graphic for the mouse pointer, in our magic format */
        static BITMAP create_light_graphic()
        {
            BITMAP bmp;
            int    x, y;
            int    dx, dy;
            int    dist, dir;
            int    r, g, b;

            bmp = create_bitmap_ex(8, 256 * 3, 256);

            /* draw the light (a circular color gradient) */
            for (y = 0; y < 256; y++)
            {
                for (x = 0; x < 256; x++)
                {
                    dx = x - 128;
                    dy = y - 128;

                    dist = fixtoi(fixsqrt(itofix(MID(-32768, dx * dx + dy * dy, 32767))));

                    // TODO: check why it corrupts memory
                    dir = 1; // fixtoi(fixatan2(itofix(dy), itofix(dx)) + itofix(128));

                    hsv_to_rgb(dir * 360.0f / 256.0f, MID(0, (int)(dist / 128.0), 1), 1f, out r, out g, out b);

                    r = r * (128 - dist) / 1024;
                    g = g * (128 - dist) / 1024;
                    b = b * (128 - dist) / 1024;

                    //bmp.line[y][x * 3] = MID(0, r, 7) << 5;
                    //bmp.line[y][x * 3 + 1] = MID(0, g, 7) << 5;
                    //bmp.line[y][x * 3 + 2] = MID(0, b, 7) << 5;

                    ManagedBytePointerArray line = new ManagedBytePointerArray(bmp.line).Offset(y * 3 * 256 * sizeof(byte));
                    line[x * 3]     = (byte)(MID(0, r, 7) << 5);
                    line[x * 3 + 1] = (byte)(MID(0, g, 7) << 5);
                    line[x * 3 + 2] = (byte)(MID(0, b, 7) << 5);
                }
            }

            /* draw some solid pixels as well (a cross in the middle ) */
            for (x = -15; x <= 15; x++)
            {
                for (y = -2; y <= 2; y++)
                {
                    magic_putpix(bmp, 128 + x, 128 + y, x + 15, 15 - x, 0);
                    magic_putpix(bmp, 128 + y, 128 + x, x + 15, x + 15, 15 - x);
                }
            }

            return(bmp);
        }
Пример #2
0
        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;
        }
Пример #3
0
        /* 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);
        }
Пример #4
0
        static void Direct(int bpp)
        {
            //COLOR_MAP _color_map = new COLOR_MAP();

            //for (int x = 0; x < 256; x++)
            //{
            //    for (int y = 0; y < 256; y++)
            //    {
            //        int xc = x & 31;
            //        int yc = y & 31;

            //        int xl = x >> 5;
            //        int yl = y >> 5;

            //        int c = 0;
            //        if (xc > 0)
            //            c = (xc + yc) / 2;
            //        else
            //            c = yc;

            //        int l = xl + yl;
            //        if (l > 7)
            //            l = 7;

            //        _color_map.data[x, y] = (byte)(c | (l << 5));
            //    }
            //}
            //color_map = _color_map;

            //drawing_mode(DRAW_MODE_TRANS, NULL, 0, 0);

            //BITMAP buffer = create_bitmap(256, 256);
            //int step = bpp / 8;
            //for (int y = 0; y < buffer.h; y++)
            //{
            //    for (int x = 0; x < buffer.w; x++)
            //    {
            //        ManagedPointer line = buffer.line.Offset(256 * y * step);
            //        ManagedPointer dot = new ManagedPointer(line.Offset(x * step));
            //        if (bpp == 8)
            //        {
            //            dot.WriteByte(0, (byte)(x % 256));
            //        }
            //        else
            //        {
            //            dot.WriteInt(0, makecol(x % 256, y % 256, 0));
            //        }
            //    }
            //}
            //blit(buffer, screen, 0, 0, 0, 0, 256, 256);

            int    AMBIENT_LIGHT = 0x20;
            int    color         = makecol(255, 0, 0);
            BITMAP bmp           = create_bitmap(90, 30);

            clear_to_color(bmp, 0);
            for (int y = 0; y < bmp.h; y++)
            {
                for (int x = 0; x < bmp.w / 3; x++)
                {
                    int c = getpixel(bmp, x, y);

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

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

                    //ManagedPointer line = new ManagedPointer(bmp.line).Offset(y * bmp.w * sizeof(byte));
                    //line.WriteByte(x * 3 * sizeof(byte), (byte)color);
                    //line.WriteByte((x * 3 + 1) * sizeof(byte), (byte)color);
                    //line.WriteByte((x * 3 + 2) * sizeof(byte), (byte)0);

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

                    //putpixel(bmp, x * 3, y, color);
                    //putpixel(bmp, x * 3 + 1, y, color);
                    //putpixel(bmp, x * 3 + 2, y, color);
                }
            }
            blit(bmp, screen, 0, 0, 0, 0, bmp.w, bmp.h);

            readkey();
        }