Commits

Anonymous committed 6546a6b

special case alpha fixes

  • Participants
  • Parent commits 2eb9d1b

Comments (0)

Files changed (3)

 # BREAK = change breaks existing code
 # BUG	= fixed a bug that was (or could have been) crashing
 
+May 10, 2003
+	fix Derek Simkowiak's find of problem alphas
+
 March 10, 2003
 	add OPENGL support to image.tostring()
 
         int typeflag=0, formatflag=0;
         SDL_Surface *surf;
         Uint32 rmask, gmask, bmask, amask;
-        int depth, doalpha=0;
+        int i, depth, doalpha=0;
         unsigned char *pixels;
         PyObject *data;
-        int i;
 
+        surf = SDL_GetVideoSurface();
+    
         pyopengl = PyImport_ImportModule("OpenGL.GL");
         if(pyopengl)
         {
 	PyObject* surfobj, *file;
 	SDL_Surface *surf;
 	SDL_Surface *temp = NULL;
-	int i, result;
+	int result;
 	
 	if(!PyArg_ParseTuple(arg, "O!O", &PySurface_Type, &surfobj, &file))
 		return NULL;

File src/surface.c

 	Uint32 flags = 0;
 	PyObject* alpha_obj = NULL, *intobj=NULL;
 	Uint8 alpha;
-	int result, alphaval=0, hasalpha=0;
+	int result, alphaval=255, hasalpha=0;
 
 	if(!PyArg_ParseTuple(args, "|Oi", &alpha_obj, &flags))
 		return NULL;
     }
 
     /*see if we should handle alpha ourselves*/
-    if(dst->format->Amask && dst->flags&SDL_SRCALPHA &&
+    if(dst->format->Amask && (dst->flags&SDL_SRCALPHA) &&
+                !(src->format->Amask && !(src->flags&SDL_SRCALPHA)) && /*special case, SDL works*/
                 (dst->format->BytesPerPixel == 2 || dst->format->BytesPerPixel==4))
     {
         result = pygame_AlphaBlit(src, srcrect, dst, dstrect);
 	dest_rect.y = (short)dy;
 	dest_rect.w = (unsigned short)src_rect->w;
 	dest_rect.h = (unsigned short)src_rect->h;
-#if 1
 	
 	result = PySurface_Blit(self, srcobject, &dest_rect, (SDL_Rect*)src_rect);
 	if(result != 0)
 	    return NULL;
 	
-#else
-	
-	/*passthrough blits to the real surface*/
-	if(((PySurfaceObject*)self)->subsurface)
-	{
-		PyObject *owner;
-		struct SubSurface_Data *subdata;
-		
-		subdata = ((PySurfaceObject*)self)->subsurface;
-		owner = subdata->owner;
-            	subsurface = PySurface_AsSurface(owner);
-		suboffsetx = subdata->offsetx;
-		suboffsety = subdata->offsety;
-		
-		while(((PySurfaceObject*)owner)->subsurface)
-		{
-		    subdata = ((PySurfaceObject*)owner)->subsurface;
-    		    owner = subdata->owner;
-	            subsurface = PySurface_AsSurface(owner);
-	    	    suboffsetx += subdata->offsetx;
-    	    	    suboffsety += subdata->offsety;
-		}
-		
-	        SDL_GetClipRect(subsurface, &orig_clip);
-	        SDL_GetClipRect(dest, &sub_clip);
-	        sub_clip.x += suboffsetx;
-	        sub_clip.y += suboffsety;
-	        SDL_SetClipRect(subsurface, &sub_clip);
-	        dest_rect.x += suboffsetx;
-	        dest_rect.y += suboffsety;
-	        dest = subsurface;
-	}
-	else
-	{
-	        PySurface_Prep(self);
-	        subsurface = NULL;
-	}
-	PySurface_Prep(srcobject);
-	Py_BEGIN_ALLOW_THREADS
-
-	/*can't blit alpha to 8bit, crashes SDL*/
-	if(dest->format->BytesPerPixel==1 && (src->format->Amask || src->flags&SDL_SRCALPHA))
-	{
-		didconvert = 1;
-		src = SDL_DisplayFormat(src);
-	}
-
-        /*see if we should handle alpha ourselves*/
-        if(dest->format->Amask && dest->flags&SDL_SRCALPHA &&
-                    (dest->format->BytesPerPixel == 2 || dest->format->BytesPerPixel==4))
-	{
-            result = pygame_AlphaBlit(src, (SDL_Rect*)src_rect, dest, &dest_rect);
-	}
-        else
-	{
-            result = SDL_BlitSurface(src, (SDL_Rect*)src_rect, dest, &dest_rect);
-        }
-
-        
-	if(didconvert)
-		SDL_FreeSurface(src);
-
-	Py_END_ALLOW_THREADS
-	if(subsurface)
-	{
-	        SDL_SetClipRect(subsurface, &orig_clip);
-	        dest_rect.x -= suboffsetx;
-		dest_rect.y -= suboffsety;
-	}
-	else
-	    PySurface_Unprep(self);
-	PySurface_Unprep(srcobject);
-
-
-	if(result == -1)
-		return RAISE(PyExc_SDLError, SDL_GetError());
-	if(result == -2)
-		return RAISE(PyExc_SDLError, "Surface was lost");
-#endif
 	return PyRect_New((GAME_Rect*)&dest_rect);
 }