[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Enigma-cvs] enigma/src/px video.cc,1.10,1.11
From: |
Daniel Heck <address@hidden> |
Subject: |
[Enigma-cvs] enigma/src/px video.cc,1.10,1.11 |
Date: |
Sun, 16 Nov 2003 17:53:32 +0000 |
Update of /cvsroot/enigma/enigma/src/px
In directory subversions:/tmp/cvs-serv14325/src/px
Modified Files:
video.cc
Log Message:
Better implementation of px::Grab(); still need to fix clipping bug
Index: video.cc
===================================================================
RCS file: /cvsroot/enigma/enigma/src/px/video.cc,v
retrieving revision 1.10
retrieving revision 1.11
diff -C2 -d -r1.10 -r1.11
*** video.cc 30 Oct 2003 19:52:31 -0000 1.10
--- video.cc 16 Nov 2003 17:53:30 -0000 1.11
***************
*** 343,347 ****
void
! Surface::blit (const GS &gs, int x, int y, Surface* s, const Rect &r_)
{
Rect r(r_);
--- 343,347 ----
void
! Surface::blit (const GS &gs, int x, int y, const Surface* s, const Rect &r_)
{
Rect r(r_);
***************
*** 356,360 ****
void
! Surface::blit (const GS &gs, int x, int y, Surface* src)
{
blit (gs, x, y, src, src->size());
--- 356,360 ----
void
! Surface::blit (const GS &gs, int x, int y, const Surface* src)
{
blit (gs, x, y, src, src->size());
***************
*** 495,511 ****
Surface *
! px::Duplicate(Surface *s)
{
if (s==0) return 0;
SDL_Surface *sdls = s->get_surface();
! SDL_Surface *copy = SDL_ConvertSurface(sdls, sdls->format, SDL_SWSURFACE);
if (sdls->format->palette != 0)
SDL_SetColors(copy, sdls->format->palette->colors, 0,
sdls->format->palette->ncolors);
return Surface::make_surface(copy);
}
! void
! px::TintRect(Surface *s, Rect rect, Uint8 r, Uint8 g, Uint8 b, Uint8 a)
{
std::auto_ptr<Surface> copy(Grab(s, rect));
--- 495,512 ----
Surface *
! px::Duplicate(const Surface *s)
{
if (s==0) return 0;
SDL_Surface *sdls = s->get_surface();
! SDL_Surface *copy = SDL_ConvertSurface(sdls, sdls->format, sdls->flags);
!
if (sdls->format->palette != 0)
SDL_SetColors(copy, sdls->format->palette->colors, 0,
sdls->format->palette->ncolors);
+
return Surface::make_surface(copy);
}
! void px::TintRect(Surface *s, Rect rect, Uint8 r, Uint8 g, Uint8 b, Uint8 a)
{
std::auto_ptr<Surface> copy(Grab(s, rect));
***************
*** 521,548 ****
Surface *
! px::Grab(Surface *s, Rect r)
{
if (s==0) return 0;
SDL_Surface *sdls = s->get_surface();
- SDL_Surface *copy = SDL_CreateRGBSurface (SDL_SWSURFACE, r.w, r.h,
- sdls->format->BitsPerPixel,
- sdls->format->Rmask,
- sdls->format->Gmask,
- sdls->format->Bmask,
- sdls->format->Amask);
- if (sdls->format->palette != 0)
- {
- SDL_SetColors(copy, sdls->format->palette->colors, 0,
- sdls->format->palette->ncolors);
- }
! Surface *new_s = Surface::make_surface (copy);
! GC gc(new_s);
! blit (gc, 0,0, s, r);
! return new_s;
}
#undef LoadImage
Surface*
px::LoadImage (const char* filename)
--- 522,640 ----
+ /*
+ * (SDL_ConvertSurface with a few changes)
+ */
+
+ static SDL_Surface *CropSurface (SDL_Surface *surface,
+ SDL_Rect rect,
+ SDL_PixelFormat *format,
+ Uint32 flags)
+ {
+ SDL_Surface *convert;
+ Uint32 colorkey = 0;
+ Uint8 alpha = 0;
+ Uint32 surface_flags;
+ SDL_Rect bounds;
+
+ /* Check for empty destination palette! (results in empty image) */
+ if ( format->palette != NULL ) {
+ int i;
+ for ( i=0; i<format->palette->ncolors; ++i ) {
+ if ( (format->palette->colors[i].r != 0) ||
+ (format->palette->colors[i].g != 0) ||
+ (format->palette->colors[i].b != 0) )
+ break;
+ }
+ if ( i == format->palette->ncolors ) {
+ SDL_SetError("Empty destination palette");
+ return(NULL);
+ }
+ }
+
+ /* Create a new surface with the desired format */
+ convert = SDL_CreateRGBSurface(flags,
+ rect.w, rect.h, format->BitsPerPixel,
+ format->Rmask, format->Gmask,
format->Bmask, format->Amask);
+ if ( convert == NULL ) {
+ return(NULL);
+ }
+
+ /* Copy the palette if any */
+ if ( format->palette && convert->format->palette ) {
+ memcpy(convert->format->palette->colors,
+ format->palette->colors,
+ format->palette->ncolors*sizeof(SDL_Color));
+ convert->format->palette->ncolors = format->palette->ncolors;
+ }
+
+ /* Save the original surface color key and alpha */
+ surface_flags = surface->flags;
+ if ( (surface_flags & SDL_SRCCOLORKEY) == SDL_SRCCOLORKEY ) {
+ /* Convert colourkeyed surfaces to RGBA if requested */
+ if((flags & SDL_SRCCOLORKEY) != SDL_SRCCOLORKEY
+ && format->Amask) {
+ surface_flags &= ~SDL_SRCCOLORKEY;
+ } else {
+ colorkey = surface->format->colorkey;
+ SDL_SetColorKey(surface, 0, 0);
+ }
+ }
+ if ( (surface_flags & SDL_SRCALPHA) == SDL_SRCALPHA ) {
+ alpha = surface->format->alpha;
+ SDL_SetAlpha(surface, 0, 0);
+ }
+
+ /* Copy over the image data */
+ bounds.x = 0;
+ bounds.y = 0;
+ bounds.w = rect.w;
+ bounds.h = rect.h;
+ SDL_LowerBlit(surface, &rect, convert, &bounds);
+
+ /* Clean up the original surface, and update converted surface */
+ // if ( convert != NULL ) {
+ // SDL_SetClipRect(convert, &surface->clip_rect);
+ // }
+
+ if ( (surface_flags & SDL_SRCCOLORKEY) == SDL_SRCCOLORKEY ) {
+ Uint32 cflags = surface_flags&(SDL_SRCCOLORKEY|SDL_RLEACCELOK);
+ if ( convert != NULL ) {
+ Uint8 keyR, keyG, keyB;
+
+ SDL_GetRGB(colorkey,surface->format,&keyR,&keyG,&keyB);
+ SDL_SetColorKey(convert, cflags|(flags&SDL_RLEACCELOK),
+ SDL_MapRGB(convert->format, keyR, keyG, keyB));
+ }
+ SDL_SetColorKey(surface, cflags, colorkey);
+ }
+ if ( (surface_flags & SDL_SRCALPHA) == SDL_SRCALPHA ) {
+ Uint32 aflags = surface_flags&(SDL_SRCALPHA|SDL_RLEACCELOK);
+ if ( convert != NULL ) {
+ SDL_SetAlpha(convert, aflags|(flags&SDL_RLEACCELOK),
+ alpha);
+ }
+ SDL_SetAlpha(surface, aflags, alpha);
+ }
+
+ /* We're ready to go! */
+ return(convert);
+ }
+
Surface *
! px::Grab (const Surface *s, Rect r)
{
if (s==0) return 0;
SDL_Surface *sdls = s->get_surface();
! SDL_Rect rect;
! sdl::copy_rect (rect, intersect(r, s->size()));
! SDL_Surface *copy = CropSurface (sdls, rect, sdls->format, sdls->flags);
! return Surface::make_surface (copy);
}
+ // LoadImage is already defined as a macro in some Windows header file
#undef LoadImage
+
+
Surface*
px::LoadImage (const char* filename)
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Enigma-cvs] enigma/src/px video.cc,1.10,1.11,
Daniel Heck <address@hidden> <=