That’s what I use to build a cursor from a surface (no dithering):
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;
}
Andre de Leiradella
http://www.geocities.com/andre_leiradella/