Obtener valores RGB y RGBA sin 32 bits

Estoy mirando en Internet y en manual de SDL y hay una cosa que no entiendo.
Teniendo_

SDL_Surface *escenario;

Tanto si “escenario” es una surface en la que luego pintamos cosas como si
cargamos una imagen en ella; ?hay alguna forma de obtener los valores RGB y
RGBA de una coordenada XY cualquiera, que no este necesariamente en 32 bit?.

Lo mas parecido que he encontrado en Internet es:

Uint32 get_pixel32( SDL_Surface *surface, int x, int y )
{
//Convert the pixels to 32 bit

Uint32 *pixels = (Uint32 *)surface->pixels;
//Get the requested pixel
return pixels[ ( y * surface->w ) + x ];
}

void put_pixel32( SDL_Surface *surface, int x, int y, Uint32 pixel )
{
//Convert the pixels to 32 bit

Uint32 *pixels = (Uint32 *)surface->pixels;

//Set the pixel
pixels[ ( y * surface->w ) + x ] = pixel;
}

Pero de esta forma lo que obtenemos, si lo he entendido bien, son los
valores RGBA de unas coordenadas XY de una surface que esta a 32 bit.

Por tanto; asumiendo que la imagen tiene mas de 8 bit, y puede que tenga
menos de 32 bit, ?es posible obtener los RGB y RGBA de un pixel cualquiera
de esa surface?

Por cierto, estoy usando SDL 1.2.9, la estable por aquel entonces.

Gracias.

ALTAIR - wrote:

?hay alguna forma de obtener los valores RGB y
RGBA de una coordenada XY cualquiera, que no este necesariamente en 32 bit?

If I’m understanding you correctly (and I may not be, since I don’t
speak Spanish), you’re asking for something like the examples on
http://www.libsdl.org/cgi/docwiki.cgi/SDL_5fPixelFormat. You should be
able to piece these together to a universal getPixel() function.

Uint32 get_pixel32( SDL_Surface *surface, int x, int y )
{
//Convert the pixels to 32 bit

Uint32 *pixels = (Uint32 *)surface->pixels;
//Get the requested pixel
return pixels[ ( y * surface->w ) + x ];
}

This doesn’t work (in general). You should use surface->pitch, not
surface->w. The proper address at which to find pixel (x,y) is something
like (Uint8 )surface->pixels + ysurface->pitch +
x*surface->format->bytesPerPixel) .

-Christian

Por tanto; asumiendo que la imagen tiene mas de 8 bit, y puede que tenga
menos de 32 bit, ?es posible obtener los RGB y RGBA de un pixel cualquiera
de esa surface?

Si, vete este ejemplo (DrawPixel):
http://www.libsdl.org/intro.es/usingvideo.html

Buena suerte. :slight_smile:
-Sam Lantinga, Senior Software Engineer, Blizzard Entertainment

You will get a lot more responses if you write your questions in
english, since everyone will understand them. And it’s more polite, too.
As you can guess, I have absolutely no problems with messages written in
spanish, but I’d feel uncomfortable if people in the list started asking
questions in chinese/russian/whatever and getting responses I also
wouldn’t understand. You’d probably feel that way too.

Gracias,

    --Gabriel

El dom, 16-07-2006 a las 08:25 +0000, ALTAIR - escribi?:> Estoy mirando en Internet y en manual de SDL y hay una cosa que no entiendo.


Gabriel Gambetta
Mystery Studio - http://www.mysterystudio.com
Gabriel on Graphics - http://gabrielongraphics.blogspot.com

En ingles te responderia mas gente, pero aqui tienes una funcion (q me hice
hace un tiempo ya) q obtiene el color en una coordenada concreta, da igual q
la imagen sea 8, 15, 16, 24 o 32 bits, espero q te sirva :slight_smile:

Uint32 getPixel(SDL_Surface* src, Sint16 x, Sint16 y)
{
Uint32 color = 0;

/* Lock the surface */
if (SDL_MUSTLOCK(src))
  if (SDL_LockSurface(src) < 0)
    return 0;

/* First Check if this new pixel is in the surface */
if (x >= clip_xmin(src) && x <= clip_xmax(src) && y >= clip_ymin(src) &&

y <= clip_ymax(src))
color = *((Uint8 )src->pixels + y * src->pitch + x);
{
switch (src->format->BytesPerPixel)
{
case 1:
/
Assuming 8-bpp */
color = *((Uint8 *)src->pixels + y * src->pitch + x);
break;

  case 2:
    /* Probably 15-bpp or 16-bpp */
    color = *((Uint8 *)src->pixels + y * src->pitch / 2 + x);
    break;

  case 3:
    /* Slow 24-bpp mode, usually not used */
    color = *((Uint8 *)src->pixels + y * src->pitch + x);
    break;

  case 4:
    /* Probably 32-bpp */
    color = *((Uint32 *)src->pixels + y * src->pitch / 4 + x);
    break;
  }
}

/* Unlock the surface */
if (SDL_MUSTLOCK(src))
  SDL_UnlockSurface(src);

return color;

}On 7/16/06, ALTAIR - wrote:

Estoy mirando en Internet y en manual de SDL y hay una cosa que no
entiendo.
Teniendo_

SDL_Surface *escenario;

Tanto si “escenario” es una surface en la que luego pintamos cosas como si
cargamos una imagen en ella; ?hay alguna forma de obtener los valores RGB
y
RGBA de una coordenada XY cualquiera, que no este necesariamente en 32
bit?.

Lo mas parecido que he encontrado en Internet es:

Uint32 get_pixel32( SDL_Surface *surface, int x, int y )
{
//Convert the pixels to 32 bit

Uint32 *pixels = (Uint32 *)surface->pixels;
//Get the requested pixel
return pixels[ ( y * surface->w ) + x ];
}

void put_pixel32( SDL_Surface *surface, int x, int y, Uint32 pixel )
{
//Convert the pixels to 32 bit

Uint32 *pixels = (Uint32 *)surface->pixels;

//Set the pixel
pixels[ ( y * surface->w ) + x ] = pixel;
}

Pero de esta forma lo que obtenemos, si lo he entendido bien, son los
valores RGBA de unas coordenadas XY de una surface que esta a 32 bit.

Por tanto; asumiendo que la imagen tiene mas de 8 bit, y puede que tenga
menos de 32 bit, ?es posible obtener los RGB y RGBA de un pixel cualquiera
de esa surface?

Por cierto, estoy usando SDL 1.2.9, la estable por aquel entonces.

Gracias.


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl