Mercurial > sdl-ios-xcode
changeset 1675:d33dcfc3fde7 SDL-1.3
Overlay functions are being replaced by YUV textures.
If the driver doesn't support YUV textures, they can be emulated by backing
the texture with an RGB texture and using the software conversion routines.
Note that it doesn't make sense to lock a portion of a YV12 texture, since
you'd need to return three pixel pointers and pitch values instead of the
one that's available through the API. I'm guessing that's one of the reasons
DirectX 9 doesn't support this format at all.
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Sun, 11 Jun 2006 07:30:16 +0000 |
parents | 7688a73b25b1 |
children | e136f3ffdc1b |
files | include/SDL_compat.h include/SDL_pixels.h include/SDL_video.h src/SDL_compat.c src/video/SDL_sysvideo.h src/video/SDL_yuv.c src/video/SDL_yuvfuncs.h |
diffstat | 7 files changed, 167 insertions(+), 260 deletions(-) [+] |
line wrap: on
line diff
--- a/include/SDL_compat.h Sun Jun 11 05:27:10 2006 +0000 +++ b/include/SDL_compat.h Sun Jun 11 07:30:16 2006 +0000 @@ -79,6 +79,37 @@ SDL_PixelFormat *vfmt; } SDL_VideoInfo; +/* The most common video overlay formats. + For an explanation of these pixel formats, see: + http://www.webartz.com/fourcc/indexyuv.htm + + For information on the relationship between color spaces, see: + http://www.neuro.sfc.keio.ac.jp/~aly/polygon/info/color-space-faq.html + */ +#define SDL_YV12_OVERLAY 0x32315659 /* Planar mode: Y + V + U (3 planes) */ +#define SDL_IYUV_OVERLAY 0x56555949 /* Planar mode: Y + U + V (3 planes) */ +#define SDL_YUY2_OVERLAY 0x32595559 /* Packed mode: Y0+U0+Y1+V0 (1 plane) */ +#define SDL_UYVY_OVERLAY 0x59565955 /* Packed mode: U0+Y0+V0+Y1 (1 plane) */ +#define SDL_YVYU_OVERLAY 0x55595659 /* Packed mode: Y0+V0+Y1+U0 (1 plane) */ + +/* The YUV hardware video overlay */ +typedef struct SDL_Overlay +{ + Uint32 format; /* Read-only */ + int w, h; /* Read-only */ + int planes; /* Read-only */ + Uint16 *pitches; /* Read-only */ + Uint8 **pixels; /* Read-write */ + + /* Hardware-specific surface info */ + struct private_yuvhwfuncs *hwfuncs; + struct private_yuvhwdata *hwdata; + + /* Special flags */ + Uint32 hw_overlay:1; /* Flag: This overlay hardware accelerated? */ + Uint32 UnusedBits:31; +} SDL_Overlay; + typedef enum { SDL_GRAB_QUERY = -1, @@ -114,7 +145,6 @@ extern DECLSPEC int SDLCALL SDL_WM_IconifyWindow(void); extern DECLSPEC int SDLCALL SDL_WM_ToggleFullScreen(SDL_Surface * surface); extern DECLSPEC SDL_GrabMode SDLCALL SDL_WM_GrabInput(SDL_GrabMode mode); -extern DECLSPEC Uint8 SDLCALL SDL_GetAppState(void); extern DECLSPEC int SDLCALL SDL_SetPalette(SDL_Surface * surface, int flags, SDL_Color * colors, int firstcolor, int ncolors); @@ -122,6 +152,18 @@ SDL_Color * colors, int firstcolor, int ncolors); extern DECLSPEC int SDLCALL SDL_GetWMInfo(SDL_SysWMinfo * info); +extern DECLSPEC Uint8 SDLCALL SDL_GetAppState(void); +extern DECLSPEC void SDLCALL SDL_WarpMouse(Uint16 x, Uint16 y); +extern DECLSPEC SDL_Overlay *SDLCALL SDL_CreateYUVOverlay(int width, + int height, + Uint32 format, + SDL_Surface * + display); +extern DECLSPEC int SDLCALL SDL_LockYUVOverlay(SDL_Overlay * overlay); +extern DECLSPEC void SDLCALL SDL_UnlockYUVOverlay(SDL_Overlay * overlay); +extern DECLSPEC int SDLCALL SDL_DisplayYUVOverlay(SDL_Overlay * overlay, + SDL_Rect * dstrect); +extern DECLSPEC void SDLCALL SDL_FreeYUVOverlay(SDL_Overlay * overlay); /* Ends C function definitions when using C++ */ #ifdef __cplusplus @@ -134,4 +176,3 @@ #endif /* _SDL_compat_h */ /* vi: set ts=4 sw=4 expandtab: */ -extern DECLSPEC void SDLCALL SDL_WarpMouse(Uint16 x, Uint16 y);
--- a/include/SDL_pixels.h Sun Jun 11 05:27:10 2006 +0000 +++ b/include/SDL_pixels.h Sun Jun 11 07:30:16 2006 +0000 @@ -95,6 +95,9 @@ SDL_PackedLayout_1010102, }; +#define SDL_DEFINE_PIXELFOURCC(A, B, C, D) \ + ((A) | ((B) << 8) | ((C) << 16) | ((D) << 24)) + #define SDL_DEFINE_PIXELFORMAT(type, order, layout, bits, bytes) \ ((1 << 31) | ((type) << 24) | ((order) << 20) | ((layout) << 16) | \ ((bits) << 8) | ((bytes) << 0)) @@ -167,6 +170,12 @@ SDL_PixelFormat_ARGB2101010 = SDL_DEFINE_PIXELFORMAT(SDL_PixelType_Packed32, SDL_PackedOrder_ARGB, SDL_PackedLayout_2101010, 32, 4), + + SDL_PixelFormat_YV12 = SDL_DEFINE_PIXELFOURCC('Y', 'V', '1', '2'), + SDL_PixelFormat_IYUV = SDL_DEFINE_PIXELFOURCC('I', 'Y', 'U', 'V'), + SDL_PixelFormat_YUY2 = SDL_DEFINE_PIXELFOURCC('Y', 'U', 'Y', '2'), + SDL_PixelFormat_UYVY = SDL_DEFINE_PIXELFOURCC('U', 'Y', 'V', 'Y'), + SDL_PixelFormat_YVYU = SDL_DEFINE_PIXELFOURCC('Y', 'V', 'Y', 'U'), }; typedef struct SDL_Color
--- a/include/SDL_video.h Sun Jun 11 05:27:10 2006 +0000 +++ b/include/SDL_video.h Sun Jun 11 07:30:16 2006 +0000 @@ -274,37 +274,6 @@ struct SDL_Surface * dst, SDL_Rect * dstrect); -/* The most common video overlay formats. - For an explanation of these pixel formats, see: - http://www.webartz.com/fourcc/indexyuv.htm - - For information on the relationship between color spaces, see: - http://www.neuro.sfc.keio.ac.jp/~aly/polygon/info/color-space-faq.html - */ -#define SDL_YV12_OVERLAY 0x32315659 /* Planar mode: Y + V + U (3 planes) */ -#define SDL_IYUV_OVERLAY 0x56555949 /* Planar mode: Y + U + V (3 planes) */ -#define SDL_YUY2_OVERLAY 0x32595559 /* Packed mode: Y0+U0+Y1+V0 (1 plane) */ -#define SDL_UYVY_OVERLAY 0x59565955 /* Packed mode: U0+Y0+V0+Y1 (1 plane) */ -#define SDL_YVYU_OVERLAY 0x55595659 /* Packed mode: Y0+V0+Y1+U0 (1 plane) */ - -/* The YUV hardware video overlay */ -typedef struct SDL_Overlay -{ - Uint32 format; /* Read-only */ - int w, h; /* Read-only */ - int planes; /* Read-only */ - Uint16 *pitches; /* Read-only */ - Uint8 **pixels; /* Read-write */ - - /* Hardware-specific surface info */ - struct private_yuvhwfuncs *hwfuncs; - struct private_yuvhwdata *hwdata; - - /* Special flags */ - Uint32 hw_overlay:1; /* Flag: This overlay hardware accelerated? */ - Uint32 UnusedBits:31; -} SDL_Overlay; - /** * \enum SDL_GLattr * @@ -1341,39 +1310,6 @@ SDL_Surface * dst, SDL_Rect * dstrect); - -/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ -/* YUV video surface overlay functions */ -/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ - -/* This function creates a video output overlay - Calling the returned surface an overlay is something of a misnomer because - the contents of the display surface underneath the area where the overlay - is shown is undefined - it may be overwritten with the converted YUV data. -*/ -extern DECLSPEC SDL_Overlay *SDLCALL SDL_CreateYUVOverlay(int width, - int height, - Uint32 format, - SDL_Surface * - display); - -/* Lock an overlay for direct access, and unlock it when you are done */ -extern DECLSPEC int SDLCALL SDL_LockYUVOverlay(SDL_Overlay * overlay); -extern DECLSPEC void SDLCALL SDL_UnlockYUVOverlay(SDL_Overlay * overlay); - -/* Blit a video overlay to the display surface. - The contents of the video surface underneath the blit destination are - not defined. - The width and height of the destination rectangle may be different from - that of the overlay, but currently only 2x scaling is supported. -*/ -extern DECLSPEC int SDLCALL SDL_DisplayYUVOverlay(SDL_Overlay * overlay, - SDL_Rect * dstrect); - -/* Free a video overlay */ -extern DECLSPEC void SDLCALL SDL_FreeYUVOverlay(SDL_Overlay * overlay); - - /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ /* OpenGL support functions. */ /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
--- a/src/SDL_compat.c Sun Jun 11 05:27:10 2006 +0000 +++ b/src/SDL_compat.c Sun Jun 11 07:30:16 2006 +0000 @@ -1235,4 +1235,119 @@ } } +SDL_Overlay * +SDL_CreateYUVOverlay(int w, int h, Uint32 format, SDL_Surface * display) +{ + SDL_VideoDevice *_this = SDL_GetVideoDevice(); + SDL_Window *window; + const char *yuv_hwaccel; + SDL_Overlay *overlay; + + window = SDL_GetWindowFromSurface(display); + if (window && (window->flags & SDL_WINDOW_OPENGL)) { + SDL_SetError("YUV overlays are not supported in OpenGL mode"); + return NULL; + } + + /* Display directly on video surface, if possible */ + if (SDL_getenv("SDL_VIDEO_YUV_DIRECT")) { + if (window && + ((window->surface->format->BytesPerPixel == 2) || + (window->surface->format->BytesPerPixel == 4))) { + display = window->surface; + } + } + overlay = NULL; + yuv_hwaccel = SDL_getenv("SDL_VIDEO_YUV_HWACCEL"); + if (((display->flags & SDL_SCREEN_SURFACE) && _this->CreateYUVOverlay) && + (!yuv_hwaccel || (SDL_atoi(yuv_hwaccel) > 0))) { + overlay = _this->CreateYUVOverlay(_this, w, h, format, display); + } + /* If hardware YUV overlay failed ... */ + if (overlay == NULL) { + overlay = SDL_CreateYUV_SW(_this, w, h, format, display); + } + return overlay; +} + +int +SDL_LockYUVOverlay(SDL_Overlay * overlay) +{ + SDL_VideoDevice *_this = SDL_GetVideoDevice(); + return overlay->hwfuncs->Lock(_this, overlay); +} + +void +SDL_UnlockYUVOverlay(SDL_Overlay * overlay) +{ + SDL_VideoDevice *_this = SDL_GetVideoDevice(); + overlay->hwfuncs->Unlock(_this, overlay); +} + +int +SDL_DisplayYUVOverlay(SDL_Overlay * overlay, SDL_Rect * dstrect) +{ + SDL_VideoDevice *_this = SDL_GetVideoDevice(); + SDL_Rect src, dst; + int srcx, srcy, srcw, srch; + int dstx, dsty, dstw, dsth; + + /* Clip the rectangle to the screen area */ + srcx = 0; + srcy = 0; + srcw = overlay->w; + srch = overlay->h; + dstx = dstrect->x; + dsty = dstrect->y; + dstw = dstrect->w; + dsth = dstrect->h; + if (dstx < 0) { + srcw += (dstx * overlay->w) / dstrect->w; + dstw += dstx; + srcx -= (dstx * overlay->w) / dstrect->w; + dstx = 0; + } + if ((dstx + dstw) > SDL_VideoSurface->w) { + int extra = (dstx + dstw - SDL_VideoSurface->w); + srcw -= (extra * overlay->w) / dstrect->w; + dstw -= extra; + } + if (dsty < 0) { + srch += (dsty * overlay->h) / dstrect->h; + dsth += dsty; + srcy -= (dsty * overlay->h) / dstrect->h; + dsty = 0; + } + if ((dsty + dsth) > SDL_VideoSurface->h) { + int extra = (dsty + dsth - SDL_VideoSurface->h); + srch -= (extra * overlay->h) / dstrect->h; + dsth -= extra; + } + if (srcw <= 0 || srch <= 0 || srch <= 0 || dsth <= 0) { + return 0; + } + /* Ugh, I can't wait for SDL_Rect to be int values */ + src.x = srcx; + src.y = srcy; + src.w = srcw; + src.h = srch; + dst.x = dstx; + dst.y = dsty; + dst.w = dstw; + dst.h = dsth; + return overlay->hwfuncs->Display(_this, overlay, &src, &dst); +} + +void +SDL_FreeYUVOverlay(SDL_Overlay * overlay) +{ + SDL_VideoDevice *_this = SDL_GetVideoDevice(); + if (overlay) { + if (overlay->hwfuncs) { + overlay->hwfuncs->FreeHW(_this, overlay); + } + SDL_free(overlay); + } +} + /* vi: set ts=4 sw=4 expandtab: */
--- a/src/video/SDL_sysvideo.h Sun Jun 11 05:27:10 2006 +0000 +++ b/src/video/SDL_sysvideo.h Sun Jun 11 07:30:16 2006 +0000 @@ -200,13 +200,6 @@ SDL_bool(*GetWindowWMInfo) (_THIS, SDL_Window * window, SDL_SysWMinfo * info); - /* Create a YUV video surface (possibly overlay) of the given - format. The hardware should be able to perform at least 2x - scaling on display. - */ - SDL_Overlay *(*CreateYUVOverlay) (_THIS, int width, int height, - Uint32 format, SDL_Surface * display); - /* Reverse the effects VideoInit() -- called if VideoInit() fails or if the application is shutting down the video subsystem. */
--- a/src/video/SDL_yuv.c Sun Jun 11 05:27:10 2006 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,147 +0,0 @@ -/* - SDL - Simple DirectMedia Layer - Copyright (C) 1997-2006 Sam Lantinga - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - - Sam Lantinga - slouken@libsdl.org -*/ -#include "SDL_config.h" - -/* This is the implementation of the YUV video surface support */ - -#include "SDL_video.h" -#include "SDL_sysvideo.h" -#include "SDL_yuvfuncs.h" -#include "SDL_yuv_sw_c.h" - - -SDL_Overlay * -SDL_CreateYUVOverlay(int w, int h, Uint32 format, SDL_Surface * display) -{ - SDL_VideoDevice *_this = SDL_GetVideoDevice(); - SDL_Window *window; - const char *yuv_hwaccel; - SDL_Overlay *overlay; - - window = SDL_GetWindowFromSurface(display); - if (window && (window->flags & SDL_WINDOW_OPENGL)) { - SDL_SetError("YUV overlays are not supported in OpenGL mode"); - return NULL; - } - - /* Display directly on video surface, if possible */ - if (SDL_getenv("SDL_VIDEO_YUV_DIRECT")) { - if (window && - ((window->surface->format->BytesPerPixel == 2) || - (window->surface->format->BytesPerPixel == 4))) { - display = window->surface; - } - } - overlay = NULL; - yuv_hwaccel = SDL_getenv("SDL_VIDEO_YUV_HWACCEL"); - if (((display->flags & SDL_SCREEN_SURFACE) && _this->CreateYUVOverlay) && - (!yuv_hwaccel || (SDL_atoi(yuv_hwaccel) > 0))) { - overlay = _this->CreateYUVOverlay(_this, w, h, format, display); - } - /* If hardware YUV overlay failed ... */ - if (overlay == NULL) { - overlay = SDL_CreateYUV_SW(_this, w, h, format, display); - } - return overlay; -} - -int -SDL_LockYUVOverlay(SDL_Overlay * overlay) -{ - SDL_VideoDevice *_this = SDL_GetVideoDevice(); - return overlay->hwfuncs->Lock(_this, overlay); -} - -void -SDL_UnlockYUVOverlay(SDL_Overlay * overlay) -{ - SDL_VideoDevice *_this = SDL_GetVideoDevice(); - overlay->hwfuncs->Unlock(_this, overlay); -} - -int -SDL_DisplayYUVOverlay(SDL_Overlay * overlay, SDL_Rect * dstrect) -{ - SDL_VideoDevice *_this = SDL_GetVideoDevice(); - SDL_Rect src, dst; - int srcx, srcy, srcw, srch; - int dstx, dsty, dstw, dsth; - - /* Clip the rectangle to the screen area */ - srcx = 0; - srcy = 0; - srcw = overlay->w; - srch = overlay->h; - dstx = dstrect->x; - dsty = dstrect->y; - dstw = dstrect->w; - dsth = dstrect->h; - if (dstx < 0) { - srcw += (dstx * overlay->w) / dstrect->w; - dstw += dstx; - srcx -= (dstx * overlay->w) / dstrect->w; - dstx = 0; - } - if ((dstx + dstw) > SDL_VideoSurface->w) { - int extra = (dstx + dstw - SDL_VideoSurface->w); - srcw -= (extra * overlay->w) / dstrect->w; - dstw -= extra; - } - if (dsty < 0) { - srch += (dsty * overlay->h) / dstrect->h; - dsth += dsty; - srcy -= (dsty * overlay->h) / dstrect->h; - dsty = 0; - } - if ((dsty + dsth) > SDL_VideoSurface->h) { - int extra = (dsty + dsth - SDL_VideoSurface->h); - srch -= (extra * overlay->h) / dstrect->h; - dsth -= extra; - } - if (srcw <= 0 || srch <= 0 || srch <= 0 || dsth <= 0) { - return 0; - } - /* Ugh, I can't wait for SDL_Rect to be int values */ - src.x = srcx; - src.y = srcy; - src.w = srcw; - src.h = srch; - dst.x = dstx; - dst.y = dsty; - dst.w = dstw; - dst.h = dsth; - return overlay->hwfuncs->Display(_this, overlay, &src, &dst); -} - -void -SDL_FreeYUVOverlay(SDL_Overlay * overlay) -{ - SDL_VideoDevice *_this = SDL_GetVideoDevice(); - if (overlay) { - if (overlay->hwfuncs) { - overlay->hwfuncs->FreeHW(_this, overlay); - } - SDL_free(overlay); - } -} - -/* vi: set ts=4 sw=4 expandtab: */
--- a/src/video/SDL_yuvfuncs.h Sun Jun 11 05:27:10 2006 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,40 +0,0 @@ -/* - SDL - Simple DirectMedia Layer - Copyright (C) 1997-2006 Sam Lantinga - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - - Sam Lantinga - slouken@libsdl.org -*/ -#include "SDL_config.h" - -/* This is the definition of the YUV video surface function structure */ - -#include "SDL_video.h" -#include "SDL_sysvideo.h" - -#ifndef _THIS -#define _THIS SDL_VideoDevice *_this -#endif -struct private_yuvhwfuncs -{ - int (*Lock) (_THIS, SDL_Overlay * overlay); - void (*Unlock) (_THIS, SDL_Overlay * overlay); - int (*Display) (_THIS, SDL_Overlay * overlay, SDL_Rect * src, - SDL_Rect * dst); - void (*FreeHW) (_THIS, SDL_Overlay * overlay); -}; -/* vi: set ts=4 sw=4 expandtab: */