Alpha

Hi,

does anyone know of (or have) a blit function which blits (copys) 

a rect region from src to dst BUT instead of doing the alpha blend and
drawing to the dst surface it copies the colour information and it also
transfers the alpha across to the dst surfaces alpha layer?

ie. it behaves like a blit/surface copy hybrid.

if this makes no sense :) please tell me and i'll try harder to 

explain.

-dv

Daniel wrote:

Hi,

    does anyone know of (or have) a blit function which blits (copys)

a rect region from src to dst BUT instead of doing the alpha blend and
drawing to the dst surface it copies the colour information and it also
transfers the alpha across to the dst surfaces alpha layer?

    ie. it behaves like a blit/surface copy hybrid.

    if this makes no sense :) please tell me and i'll try harder to

explain.

-dv

I was asking about exactly the same thing in #sdl last
weekend.
A few people agreed it would be useful, but
no code was forthcoming… :slight_smile:

It’d be easy for SWSURFACE’s: just duplicate the standard
non-alpha blit code. For hardware, that’s another story.

-Ray

does anyone know of (or have) a blit function which blits (copys)
a rect region from src to dst BUT instead of doing the alpha blend and
drawing to the dst surface it copies the colour information and it also
transfers the alpha across to the dst surfaces alpha layer?

Hello, try this. Its working for me, although ts not quite general or nice
:). Both surfaces must already be created and must be in 32bit format. It
just copies the rawdata of source to dest (the *pixels of the surface that
is) and then the pixel format info. No clipping there, so be careful. You
can easily adjust it for 16 bit images. I am using it under windows, with
HWSURFACE flag, it must wotk for SWSURFACE too.

Let me know if it works.

// Copies the raw data and pixelformat from src to dst.
// Both surfaces must be 32bit. No clipping is done.
int CopySurfaceData(SDL_Surface *src, SDL_Rect *srcrect, SDL_Surface *dst,
SDL_Rect *dstrect) {
Sint32 x,y,dstX,dstY;
Uint32 pixel;

if (SDL_MUSTLOCK(src)!=0) {
SDL_LockSurface(src);
printf(“Locked src”);
}
if (SDL_MUSTLOCK(dst)!=0) {
SDL_LockSurface(dst);
printf(“Locked dst”);
}

for (y=srcrect->y; y<=srcrect->h-1; y++) {
for (x=srcrect->x; x<=srcrect->w-1; x++) {
pixel=*((Uint32 )src->pixels + ysrc->pitch/4 + x);
dstY=y-srcrect->y+dstrect->y;
dstX=x-srcrect->x+dstrect->x;
*((Uint32 )dst->pixels + dstYdst->pitch/4 + dstX)=pixel;
}
}

dst->format->Rloss=src->format->Rloss;
dst->format->Gloss=src->format->Gloss;
dst->format->Bloss=src->format->Bloss;
dst->format->Aloss=src->format->Aloss;
dst->format->Rshift=src->format->Rshift;
dst->format->Gshift=src->format->Gshift;
dst->format->Bshift=src->format->Bshift;
dst->format->Ashift=src->format->Ashift;
dst->format->Rmask=src->format->Rmask;
dst->format->Gmask=src->format->Gmask;
dst->format->Bmask=src->format->Bmask;
dst->format->Amask=src->format->Amask;

if (SDL_MUSTLOCK(src)!=0) {
SDL_UnlockSurface(src);
printf(“UnLocked src”);
}
if (SDL_MUSTLOCK(dst)!=0) {
SDL_UnlockSurface(dst);
printf(“UnLocked dst”);
}

return(1);
}