[SDL] Problem on x86_64 with latest CVS (sdl12 with gcc-2.95)

Sam Lantinga slouken at devolution.com
Tue Jan 18 10:37:44 PST 2005


Some months ago somebody posted the following code to convert a surface
to a mouse cursor. But there is some problem, the image isnt displayed
properly, just an small part of it repeated. Can somebody tell me whats
wrong with it? Is it for some fixed color depth or something? 


SDL_Cursor *SurfaceToCursor(SDL_Surface *image, int hx, int hy) {
 int             w, x, y;
 Uint8           *data, *mask, *d, *m, r, g, b;
 Uint32          color;
 SDL_Cursor      *cursor;

         w = (image->w + 7) / 8;
         data = (Uint8 *)alloca(w * image->h * 2);
         if (data == NULL)
                 return NULL;
         memset(data, 0, w * image->h * 2);
         mask = data + w * image->h;
         if (SDL_MUSTLOCK(image))
                 SDL_LockSurface(image);
         for (y = 0; y < image->h; y++) {
                 d = data + y * w;
                 m = mask + y * w;
                 for (x = 0; x < image->w; x++) {
                         color = getpixel(image, x, y);
                         if ((image->flags & SDL_SRCCOLORKEY) == 0 ||
color != image->format->colorkey) {
                                 SDL_GetRGB(color, image->format, &r,
&g, &b);
                                 color = (r + g + b) / 3;
                                 m[x / 8] |= 128 >> (x & 7);
                                 if (color < 128)
                                         d[x / 8] |= 128 >> (x & 7);
                         }
                 }
         }
         if (SDL_MUSTLOCK(image))
                 SDL_UnlockSurface(image);
         cursor = SDL_CreateCursor(data, mask, w, image->h, hx, hy);
         return cursor;
 }



-- 
Roger D. Vargas
Linux user #180787
ICQ: 117641572
* No hay nada tan importante que no pueda ser olvidado *
Alzheimer





More information about the SDL mailing list