Commits

Anonymous committed 16e4007

8bit cleanups

Comments (0)

Files changed (4)

 # BREAK = change breaks existing code
 # BUG   = fixed a bug that was crashing
 
+May 10, 2001
+	8bit subsurfaces inherit their parents colormap
+	blit keeps SDL from crashing with alpha onto 8bit
+
 Apr 30, 2001
 	loading Sounds from python objects now works [BUG]
 	loading from python objects now thread safe [BUG]

docs/ref/Surface.html

 rectangle. If a rectangle is given, the blit will use the topleft
 corner of the rectangle as the blit destination position. The
 rectangle sizes will be ignored.
+
+<br>&nbsp;<br>
+Note that blitting alpha surfaces onto an 8bit destination will
+crash SDL. Pygame will disable the alpha when these blits are attempted.
+
 </ul><br>&nbsp;<br>
 
 <a name=convert><font size=+2><b>convert
 	if(type >= SDL_USEREVENT && type < SDL_NUMEVENTS)
 		return "UserEvent";
 
-	return "Unkown";
+	return "Unknown";
 }
 
 
     /*DOC*/    "rectangle. If a rectangle is given, the blit will use the topleft\n"
     /*DOC*/    "corner of the rectangle as the blit destination position. The\n"
     /*DOC*/    "rectangle sizes will be ignored.\n"
+#if 0  /* "" */
+    /*DOC*/    "\n"
+    /*DOC*/    "Note that blitting alpha surfaces onto an 8bit destination will\n"
+    /*DOC*/    "crash SDL. Pygame will disable the alpha when these blits are attempted.\n"
+#endif /* "" */
     /*DOC*/ ;
 
 static PyObject* surf_blit(PyObject* self, PyObject* args)
 	int dx, dy, result;
 	SDL_Rect dest_rect;
 	short sx, sy;
+	int didconvert;
 
 	VIDEO_INIT_CHECK();
 
 	PySurface_Prep(self);
 	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);
+	}
 	result = SDL_BlitSurface(src, (SDL_Rect*)src_rect, dest, &dest_rect);
+	if(didconvert)
+		SDL_FreeSurface(src);
 	Py_END_ALLOW_THREADS
 	PySurface_Unprep(self);
 	PySurface_Unprep(srcobject);
 				surf->pitch, format->Rmask, format->Gmask, format->Bmask, format->Amask);
 
 	PySurface_Unlock(self);
-		
+
 	if(!sub)
 		return RAISE(PyExc_SDLError, SDL_GetError());
 
+	/*copy the colormap if we need it*/
+	if(surf->format->BytesPerPixel == 1 && surf->format->palette)
+		SDL_SetPalette(sub, SDL_LOGPAL, surf->format->palette->colors, 0, surf->format->palette->ncolors);
+
+
 	data = PyMem_New(struct SubSurface_Data, 1);
 	if(!data) return NULL;
 
 	data->pixeloffset = pixeloffset;
 	((PySurfaceObject*)subobj)->subsurface = data;
 
+
+
 	return subobj;
 }