示例#1
0
文件: pixmap.c 项目: s-cherepanov/elk
static Object P_Create_Pixmap_From_Bitmap_Data (Object win, Object data,
        Object pw, Object ph,
        Object fg, Object bg,
        Object depth) {
    register unsigned int w, h;

    Check_Type (win, T_Window);
    Check_Type (data, T_String);
    w = Get_Integer (pw);
    h = Get_Integer (ph);
    if (w * h > 8 * STRING(data)->size)
        Primitive_Error ("bitmap too small");
    return Make_Pixmap (WINDOW(win)->dpy,
                        XCreatePixmapFromBitmapData (WINDOW(win)->dpy, WINDOW(win)->win,
                                STRING(data)->data, w, h, Get_Pixel (fg), Get_Pixel (bg),
                                Get_Integer (depth)));
}
void Draw_Image(SDL_Surface *surface, int x, int y, Sint8 vx, Sint8 vy)
{
    /* int x = 70, y = 79; */
    /* Sint8 vx = 18, vy = 26; */
    /* int x = 50, y = 22; */
    /* Sint8 vx = 24, vy = 34; */
    int clr = 0;
    Uint8 a, b, c, t;

    glClear(GL_COLOR_BUFFER_BIT);

    Get_Pixel(surface, x, y, &c, &b, &a, &t);
    while(a != 0 || b != 0 || c != 0) {
        //printf("%d %d\n", x, y);
        //printf("%d\n", 54 + (200*y + x)*3);

        if(x >= surface->w || y >= surface->h)
            break;

        vx ^= a;
        vy ^= b;
        clr ^= c;
        if(clr) {
            glBegin(GL_LINES);
            glColor3f(1.0, 1.0, 1.0);
            glVertex2i(x, y);
            glVertex2i(x + vx, y + vy);
            glEnd();
	    printf("%d %d\n", vx, vy);
        }
        x += vx;
        y += vy;
        Get_Pixel(surface, x, y, &c, &b, &a, &t);
#ifdef SLOWLY
        SDL_Delay(10);
        SDL_GL_SwapBuffers();
#endif
    } 

    SDL_GL_SwapBuffers();
}
void Dump_Image(SDL_Surface *surface)
{
    int x,y;
    Uint8 r, g, b, t;

    for (y=0; y < surface->h; y++) {
      for (x=0; x < surface->w; x++) {
        Get_Pixel(surface, x, y, &r, &g, &b, &t);
        printf("(%d,%d):\t%d %d %d\n", x,y, r,g,b);
      }
    }
}
void try_address(SDL_Surface *surface, int x, int y, Sint8 vx, Sint8 vy)
{
    int clr = 0;
    Uint8 a, b, c, t;
    int j = 0;

    Get_Pixel(surface, x, y, &c, &b, &a, &t);
    while(a != 0 || b != 0 || c != 0) {
        printf("%d: %d %d \t at 0x%x\n", j, x, y, 54 + (200*y + x)*3);

        if(x >= surface->w || y >= surface->h)
            break;

        vx ^= a;
        vy ^= b;
        clr ^= c;
        x += vx;
        y += vy;
        Get_Pixel(surface, x, y, &c, &b, &a, &t);
        j++;
    } 
}