mirror of
				https://github.com/libsdl-org/SDL.git
				synced 2025-10-26 12:27:44 +00:00 
			
		
		
		
	Simplified SDL_Surface
SDL_Surface has been simplified and internal details are no longer in the public structure. The `format` member of SDL_Surface is now an enumerated pixel format value. You can get the full details of the pixel format by calling `SDL_GetPixelFormatDetails(surface->format)`. You can get the palette associated with the surface by calling SDL_GetSurfacePalette(). You can get the clip rectangle by calling SDL_GetSurfaceClipRect(). SDL_PixelFormat has been renamed SDL_PixelFormatDetails and just describes the pixel format, it does not include a palette for indexed pixel types. SDL_PixelFormatEnum has been renamed SDL_PixelFormat and is used instead of Uint32 for API functions that refer to pixel format by enumerated value. SDL_MapRGB(), SDL_MapRGBA(), SDL_GetRGB(), and SDL_GetRGBA() take an optional palette parameter for indexed color lookups.
This commit is contained in:
		| @@ -31,7 +31,7 @@ static void SDL_DrawLine1(SDL_Surface *dst, int x1, int y1, int x2, int y2, Uint | ||||
| { | ||||
|     if (y1 == y2) { | ||||
|         int length; | ||||
|         int pitch = (dst->pitch / dst->format->bytes_per_pixel); | ||||
|         int pitch = (dst->pitch / dst->internal->format->bytes_per_pixel); | ||||
|         Uint8 *pixel; | ||||
|         if (x1 <= x2) { | ||||
|             pixel = (Uint8 *)dst->pixels + y1 * pitch + x1; | ||||
| @@ -64,8 +64,8 @@ static void SDL_DrawLine2(SDL_Surface *dst, int x1, int y1, int x2, int y2, Uint | ||||
|         DLINE(Uint16, DRAW_FASTSETPIXEL2, draw_end); | ||||
|     } else { | ||||
|         Uint8 _r, _g, _b, _a; | ||||
|         const SDL_PixelFormat *fmt = dst->format; | ||||
|         SDL_GetRGBA(color, fmt, &_r, &_g, &_b, &_a); | ||||
|         const SDL_PixelFormatDetails *fmt = dst->internal->format; | ||||
|         SDL_GetRGBA(color, fmt, dst->internal->palette, &_r, &_g, &_b, &_a); | ||||
|         if (fmt->Rmask == 0x7C00) { | ||||
|             AALINE(x1, y1, x2, y2, | ||||
|                    DRAW_FASTSETPIXELXY2, DRAW_SETPIXELXY_BLEND_RGB555, | ||||
| @@ -93,8 +93,8 @@ static void SDL_DrawLine4(SDL_Surface *dst, int x1, int y1, int x2, int y2, Uint | ||||
|         DLINE(Uint32, DRAW_FASTSETPIXEL4, draw_end); | ||||
|     } else { | ||||
|         Uint8 _r, _g, _b, _a; | ||||
|         const SDL_PixelFormat *fmt = dst->format; | ||||
|         SDL_GetRGBA(color, fmt, &_r, &_g, &_b, &_a); | ||||
|         const SDL_PixelFormatDetails *fmt = dst->internal->format; | ||||
|         SDL_GetRGBA(color, fmt, dst->internal->palette, &_r, &_g, &_b, &_a); | ||||
|         if (fmt->Rmask == 0x00FF0000) { | ||||
|             if (!fmt->Amask) { | ||||
|                 AALINE(x1, y1, x2, y2, | ||||
| @@ -117,7 +117,7 @@ typedef void (*DrawLineFunc)(SDL_Surface *dst, | ||||
|                              int x1, int y1, int x2, int y2, | ||||
|                              Uint32 color, SDL_bool draw_end); | ||||
|  | ||||
| static DrawLineFunc SDL_CalculateDrawLineFunc(const SDL_PixelFormat *fmt) | ||||
| static DrawLineFunc SDL_CalculateDrawLineFunc(const SDL_PixelFormatDetails *fmt) | ||||
| { | ||||
|     switch (fmt->bytes_per_pixel) { | ||||
|     case 1: | ||||
| @@ -137,18 +137,18 @@ int SDL_DrawLine(SDL_Surface *dst, int x1, int y1, int x2, int y2, Uint32 color) | ||||
| { | ||||
|     DrawLineFunc func; | ||||
|  | ||||
|     if (!dst) { | ||||
|     if (!SDL_SurfaceValid(dst)) { | ||||
|         return SDL_InvalidParamError("SDL_DrawLine(): dst"); | ||||
|     } | ||||
|  | ||||
|     func = SDL_CalculateDrawLineFunc(dst->format); | ||||
|     func = SDL_CalculateDrawLineFunc(dst->internal->format); | ||||
|     if (!func) { | ||||
|         return SDL_SetError("SDL_DrawLine(): Unsupported surface format"); | ||||
|     } | ||||
|  | ||||
|     /* Perform clipping */ | ||||
|     /* FIXME: We don't actually want to clip, as it may change line slope */ | ||||
|     if (!SDL_GetRectAndLineIntersection(&dst->clip_rect, &x1, &y1, &x2, &y2)) { | ||||
|     if (!SDL_GetRectAndLineIntersection(&dst->internal->clip_rect, &x1, &y1, &x2, &y2)) { | ||||
|         return 0; | ||||
|     } | ||||
|  | ||||
| @@ -165,11 +165,11 @@ int SDL_DrawLines(SDL_Surface *dst, const SDL_Point *points, int count, | ||||
|     SDL_bool draw_end; | ||||
|     DrawLineFunc func; | ||||
|  | ||||
|     if (!dst) { | ||||
|     if (!SDL_SurfaceValid(dst)) { | ||||
|         return SDL_InvalidParamError("SDL_DrawLines(): dst"); | ||||
|     } | ||||
|  | ||||
|     func = SDL_CalculateDrawLineFunc(dst->format); | ||||
|     func = SDL_CalculateDrawLineFunc(dst->internal->format); | ||||
|     if (!func) { | ||||
|         return SDL_SetError("SDL_DrawLines(): Unsupported surface format"); | ||||
|     } | ||||
| @@ -182,7 +182,7 @@ int SDL_DrawLines(SDL_Surface *dst, const SDL_Point *points, int count, | ||||
|  | ||||
|         /* Perform clipping */ | ||||
|         /* FIXME: We don't actually want to clip, as it may change line slope */ | ||||
|         if (!SDL_GetRectAndLineIntersection(&dst->clip_rect, &x1, &y1, &x2, &y2)) { | ||||
|         if (!SDL_GetRectAndLineIntersection(&dst->internal->clip_rect, &x1, &y1, &x2, &y2)) { | ||||
|             continue; | ||||
|         } | ||||
|  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Sam Lantinga
					Sam Lantinga