첫 번째 픽셀을 얻을 수 있지만 다른 픽셀을 얻는 방법은 무엇입니까?Vala/Genie를 사용하여 SDL Surface의 픽셀 색상을 얻으십시오.
def get_alpha (x:uint8,y:uint8): uchar
r:uchar
g:uchar
b:uchar
a:uchar
dire:uint32*
r=0
g=0
b=0
a=0
Image.do_lock()
dire=Image.pixels
Image.format.get_rgba (*dire, ref r,ref g,ref b,ref a)
Image.unlock()
print "En x= %d y=%d ,%d %d %d %d",x,y,r,g,b,a
return a
픽셀을 얻는 데 필요한 SDL Wiki의 C 코드입니다. 나는 단지 (3과 4 바이트)를 필요로한다. 나는 surface.pixels + y * surface.pitch * surface.format.BytesPerPixel 할 수있는 위치로 이동하는 것을 볼 수 있지만 문제가 오순절이. 첫 번째 위치는 좋지만 모든 흰색 표면의 마지막 위치는 나에게 다른 색상을 제공합니다. 내 조치가 좋지 않다고 생각해.
// Nota, código obtenido del wiki de SDL
// http://www.libsdl.org/cgi/docwiki.cgi/Pixel_20Access
Uint32 getpixel(SDL_Surface *surface, int x, int y)
{
int bpp = surface->format->BytesPerPixel;
/* Here p is the address to the pixel we want to retrieve */
Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp;
switch(bpp) {
case 1:
return *p;
case 2:
return *(Uint16 *)p;
case 3:
if(SDL_BYTEORDER == SDL_BIG_ENDIAN)
return p[0] << 16 | p[1] << 8 | p[2];
else
return p[0] | p[1] << 8 | p[2] << 16;
case 4:
return *(Uint32 *)p;
default:
return 0; /* shouldn't happen, but avoids warnings */
}
}
수행하려는 내용이나 픽셀 형식에 대한 설명이 있습니까? 원시 픽셀 데이터를 처리하는 방법을 알기에는 SDL에 익숙하지 않습니다. – nemequ