src/osd/sdl/effect_func.h
| r2151 | r2152 | |
| 1 | | #include "texsrc.h" |
| 2 | | |
| 3 | | // texcopy function prototype |
| 4 | | void FUNC_NAME(texcopy)(texture_info *texture, const render_texinfo *texsource); |
| 5 | | |
| 6 | | void EFFECT_FUNC_NAME(texture_info *texture, const render_texinfo *texsource) |
| 7 | | { |
| 8 | | int y; |
| 9 | | DEST_TYPE *dst = (DEST_TYPE *)texture->data + texture->borderpix * texture->rawwidth; |
| 10 | | TEXSRC_TYPE *src = (TEXSRC_TYPE *)texsource->base; |
| 11 | | #ifndef SRC_EQUALS_DEST |
| 12 | | int x; |
| 13 | | DEST_TYPE *tmp, *effectbuf0, *effectbuf1, *effectbuf2; |
| 14 | | #endif |
| 15 | | |
| 16 | | switch ((texture->xprescale << 8) | texture->yprescale) |
| 17 | | { |
| 18 | | case 0x0101: |
| 19 | | case 0x0102: |
| 20 | | case 0x0103: |
| 21 | | case 0x0201: |
| 22 | | case 0x0301: |
| 23 | | FUNC_NAME(texcopy)(texture, texsource); |
| 24 | | return; |
| 25 | | } |
| 26 | | |
| 27 | | #ifndef SRC_EQUALS_DEST |
| 28 | | // First convert to a temporary buffer so that we do not convert each |
| 29 | | // pixel 4 times |
| 30 | | effectbuf1 = (DEST_TYPE *)texture->effectbuf; |
| 31 | | effectbuf2 = (DEST_TYPE *)texture->effectbuf + texsource->width; |
| 32 | | effectbuf0 = (DEST_TYPE *)texture->effectbuf + 2 * texsource->width; |
| 33 | | |
| 34 | | tmp = effectbuf1; |
| 35 | | for (x = 0; x < texsource->width; x++) |
| 36 | | { |
| 37 | | *tmp++ = TEXSRC_TO_DEST(*src); |
| 38 | | src++; |
| 39 | | } |
| 40 | | |
| 41 | | src = (TEXSRC_TYPE *)texsource->base + texsource->rowpixels; |
| 42 | | tmp = effectbuf2; |
| 43 | | for (x = 0; x < texsource->width; x++) |
| 44 | | { |
| 45 | | *tmp++ = TEXSRC_TO_DEST(*src); |
| 46 | | src++; |
| 47 | | } |
| 48 | | EFFECT_DEST_NAME(&dst, effectbuf1, effectbuf1, effectbuf2, texture, |
| 49 | | texsource); |
| 50 | | #else |
| 51 | | EFFECT_DEST_NAME(&dst, src, src, src + texsource->rowpixels, |
| 52 | | texture, texsource); |
| 53 | | #endif |
| 54 | | |
| 55 | | // loop over Y |
| 56 | | for (y = 1; y < (texsource->height-1); y++) |
| 57 | | { |
| 58 | | dst += texture->rawwidth; |
| 59 | | #ifndef SRC_EQUALS_DEST |
| 60 | | // First convert to a temporary buffer so that we do not |
| 61 | | // convert each pixel 4 times |
| 62 | | src = (TEXSRC_TYPE *)texsource->base + |
| 63 | | (y + 1) * texsource->rowpixels; |
| 64 | | tmp = effectbuf0; |
| 65 | | effectbuf0 = effectbuf1; |
| 66 | | effectbuf1 = effectbuf2; |
| 67 | | effectbuf2 = tmp; |
| 68 | | for (x = 0; x < texsource->width; x++) |
| 69 | | { |
| 70 | | *tmp++ = TEXSRC_TO_DEST(*src); |
| 71 | | src++; |
| 72 | | } |
| 73 | | EFFECT_DEST_NAME(&dst, effectbuf0, effectbuf1, effectbuf2, texture, texsource); |
| 74 | | #else |
| 75 | | src += texsource->rowpixels; |
| 76 | | EFFECT_DEST_NAME(&dst, src - texsource->rowpixels, src, |
| 77 | | src + texsource->rowpixels, texture, texsource); |
| 78 | | #endif |
| 79 | | } |
| 80 | | |
| 81 | | // last line |
| 82 | | dst += texture->rawwidth; |
| 83 | | #ifndef SRC_EQUALS_DEST |
| 84 | | EFFECT_DEST_NAME(&dst, effectbuf1, effectbuf2, effectbuf2, texture, texsource); |
| 85 | | #else |
| 86 | | EFFECT_DEST_NAME(&dst, src, src + texsource->rowpixels, src + texsource->rowpixels, texture, texsource); |
| 87 | | #endif |
| 88 | | } |
| 89 | | |
| 90 | | #undef SDL_TEXFORMAT |
src/osd/sdl/sdlmisc.h
| r2151 | r2152 | |
| 1 | | /* Miscelancelous utility functions |
| 2 | | |
| 3 | | Copyright 2000 Hans de Goede |
| 4 | | |
| 5 | | This file and the acompanying files in this directory are free software; |
| 6 | | you can redistribute them and/or modify them under the terms of the GNU |
| 7 | | Library General Public License as published by the Free Software Foundation; |
| 8 | | either version 2 of the License, or (at your option) any later version. |
| 9 | | |
| 10 | | These files are distributed in the hope that they will be useful, |
| 11 | | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 13 | | Library General Public License for more details. |
| 14 | | |
| 15 | | You should have received a copy of the GNU Library General Public |
| 16 | | License along with these files; see the file COPYING.LIB. If not, |
| 17 | | write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
| 18 | | Boston, MA 02111-1307, USA. |
| 19 | | */ |
| 20 | | |
| 21 | | #ifndef __SDLMISC_H |
| 22 | | #define __SDLMISC_H |
| 23 | | |
| 24 | | /* clock stuff */ |
| 25 | | typedef long uclock_t; |
| 26 | | uclock_t uclock(void); |
| 27 | | #define UCLOCKS_PER_SEC 1000000 |
| 28 | | |
| 29 | | #if !(defined __USE_BSD || defined __USE_ISOC99 || defined __USE_UNIX98) |
| 30 | | int snprintf(char *s, size_t maxlen, const char *fmt, ...); |
| 31 | | #endif |
| 32 | | |
| 33 | | #endif /* ifndef __SDLMISC_H */ |
src/osd/sdl/yuv_blit.c
| r2151 | r2152 | |
| 1 | | |
| 2 | | // YUV Blitters |
| 3 | | // |
| 4 | | // This should be included at the end of drawsdl.c |
| 5 | | |
| 6 | | |
| 7 | | #define CU_CLAMP(v, a, b) ((v < a)? a: ((v > b)? b: v)) |
| 8 | | #define RGB2YUV_F(r,g,b,y,u,v) \ |
| 9 | | (y) = (0.299*(r) + 0.587*(g) + 0.114*(b) ); \ |
| 10 | | (u) = (-0.169*(r) - 0.331*(g) + 0.5*(b) + 128); \ |
| 11 | | (v) = (0.5*(r) - 0.419*(g) - 0.081*(b) + 128); \ |
| 12 | | (y) = CU_CLAMP(y,0,255); \ |
| 13 | | (u) = CU_CLAMP(u,0,255); \ |
| 14 | | (v) = CU_CLAMP(v,0,255) |
| 15 | | |
| 16 | | #define RGB2YUV(r,g,b,y,u,v) \ |
| 17 | | (y) = (( 8453*(r) + 16594*(g) + 3223*(b) + 524288) >> 15); \ |
| 18 | | (u) = (( -4878*(r) - 9578*(g) + 14456*(b) + 4210688) >> 15); \ |
| 19 | | (v) = (( 14456*(r) - 12105*(g) - 2351*(b) + 4210688) >> 15) |
| 20 | | |
| 21 | | #ifdef LSB_FIRST |
| 22 | | #define Y1MASK 0x000000FF |
| 23 | | #define UMASK 0x0000FF00 |
| 24 | | #define Y2MASK 0x00FF0000 |
| 25 | | #define VMASK 0xFF000000 |
| 26 | | #define Y1SHIFT 0 |
| 27 | | #define USHIFT 8 |
| 28 | | #define Y2SHIFT 16 |
| 29 | | #define VSHIFT 24 |
| 30 | | #else |
| 31 | | #define Y1MASK 0xFF000000 |
| 32 | | #define UMASK 0x00FF0000 |
| 33 | | #define Y2MASK 0x0000FF00 |
| 34 | | #define VMASK 0x000000FF |
| 35 | | #define Y1SHIFT 24 |
| 36 | | #define USHIFT 16 |
| 37 | | #define Y2SHIFT 8 |
| 38 | | #define VSHIFT 0 |
| 39 | | #endif |
| 40 | | |
| 41 | | #define YMASK (Y1MASK|Y2MASK) |
| 42 | | #define UVMASK (UMASK|VMASK) |
| 43 | | |
| 44 | | |
| 45 | | static void yuv_lookup_set(sdl_window_info *window, unsigned int pen, unsigned char red, |
| 46 | | unsigned char green, unsigned char blue) |
| 47 | | { |
| 48 | | UINT32 y,u,v; |
| 49 | | |
| 50 | | RGB2YUV(red,green,blue,y,u,v); |
| 51 | | |
| 52 | | /* Storing this data in YUYV order simplifies using the data for |
| 53 | | YUY2, both with and without smoothing... */ |
| 54 | | window->yuv_lookup[pen]=(y<<Y1SHIFT)|(u<<USHIFT)|(y<<Y2SHIFT)|(v<<VSHIFT); |
| 55 | | } |
| 56 | | |
| 57 | | void drawsdl_yuv_init(sdl_window_info *window) |
| 58 | | { |
| 59 | | unsigned char r,g,b; |
| 60 | | if (window->yuv_lookup == NULL) |
| 61 | | window->yuv_lookup = malloc_or_die(65536*sizeof(UINT32)); |
| 62 | | for (r = 0; r < 32; r++) |
| 63 | | for (g = 0; g < 32; g++) |
| 64 | | for (b = 0; b < 32; b++) |
| 65 | | { |
| 66 | | int idx = (r << 10) | (g << 5) | b; |
| 67 | | yuv_lookup_set(window, idx, |
| 68 | | (r << 3) | (r >> 2), |
| 69 | | (g << 3) | (g >> 2), |
| 70 | | (b << 3) | (b >> 2)); |
| 71 | | } |
| 72 | | } |
| 73 | | |
| 74 | | static void yuv_RGB_to_YV12(UINT16 *bitmap, int bw, sdl_window_info *window) |
| 75 | | { |
| 76 | | int x, y; |
| 77 | | UINT8 *dest_y; |
| 78 | | UINT8 *dest_u; |
| 79 | | UINT8 *dest_v; |
| 80 | | UINT16 *src; |
| 81 | | UINT16 *src2; |
| 82 | | UINT32 *lookup = window->yuv_lookup; |
| 83 | | int yuv_pitch = window->yuvsurf->pitches[0]; |
| 84 | | int u1,v1,y1,u2,v2,y2,u3,v3,y3,u4,v4,y4; /* 12 */ |
| 85 | | |
| 86 | | for(y=0;y<window->yuv_ovl_height;y+=2) |
| 87 | | { |
| 88 | | src=bitmap + (y * bw) ; |
| 89 | | src2=src + bw; |
| 90 | | |
| 91 | | dest_y = window->yuvsurf->pixels[0] + y * window->yuvsurf->pitches[0]; |
| 92 | | dest_v = window->yuvsurf->pixels[1] + (y>>1) * window->yuvsurf->pitches[1]; |
| 93 | | dest_u = window->yuvsurf->pixels[2] + (y>>1) * window->yuvsurf->pitches[2]; |
| 94 | | |
| 95 | | for(x=0;x<window->yuv_ovl_width;x+=2) |
| 96 | | { |
| 97 | | v1 = lookup[src[x]]; |
| 98 | | y1 = (v1>>Y1SHIFT) & 0xff; |
| 99 | | u1 = (v1>>USHIFT) & 0xff; |
| 100 | | v1 = (v1>>VSHIFT) & 0xff; |
| 101 | | |
| 102 | | v2 = lookup[src[x+1]]; |
| 103 | | y2 = (v2>>Y1SHIFT) & 0xff; |
| 104 | | u2 = (v2>>USHIFT) & 0xff; |
| 105 | | v2 = (v2>>VSHIFT) & 0xff; |
| 106 | | |
| 107 | | v3 = lookup[src2[x]]; |
| 108 | | y3 = (v3>>Y1SHIFT) & 0xff; |
| 109 | | u3 = (v3>>USHIFT) & 0xff; |
| 110 | | v3 = (v3>>VSHIFT) & 0xff; |
| 111 | | |
| 112 | | v4 = lookup[src2[x+1]]; |
| 113 | | y4 = (v4>>Y1SHIFT) & 0xff; |
| 114 | | u4 = (v4>>USHIFT) & 0xff; |
| 115 | | v4 = (v4>>VSHIFT) & 0xff; |
| 116 | | |
| 117 | | dest_y[x] = y1; |
| 118 | | dest_y[x+yuv_pitch] = y3; |
| 119 | | dest_y[x+1] = y2; |
| 120 | | dest_y[x+yuv_pitch+1] = y4; |
| 121 | | |
| 122 | | dest_u[x>>1] = (u1+u2+u3+u4)/4; |
| 123 | | dest_v[x>>1] = (v1+v2+v3+v4)/4; |
| 124 | | |
| 125 | | } |
| 126 | | } |
| 127 | | } |
| 128 | | |
| 129 | | static void yuv_RGB_to_YV12X2(UINT16 *bitmap, int bw, sdl_window_info *window) |
| 130 | | { /* this one is used when scale==2 */ |
| 131 | | unsigned int x,y; |
| 132 | | UINT16 *dest_y; |
| 133 | | UINT8 *dest_u; |
| 134 | | UINT8 *dest_v; |
| 135 | | UINT16 *src; |
| 136 | | int yuv_pitch = window->yuvsurf->pitches[0]; |
| 137 | | int u1,v1,y1; |
| 138 | | |
| 139 | | for(y=0;y<window->yuv_ovl_height;y++) |
| 140 | | { |
| 141 | | src=bitmap + (y * bw) ; |
| 142 | | |
| 143 | | dest_y = (UINT16 *)(window->yuvsurf->pixels[0] + 2*y * window->yuvsurf->pitches[0]); |
| 144 | | dest_v = window->yuvsurf->pixels[1] + y * window->yuvsurf->pitches[1]; |
| 145 | | dest_u = window->yuvsurf->pixels[2] + y * window->yuvsurf->pitches[2]; |
| 146 | | for(x=0;x<window->yuv_ovl_width;x++) |
| 147 | | { |
| 148 | | v1 = window->yuv_lookup[src[x]]; |
| 149 | | y1 = (v1>>Y1SHIFT) & 0xff; |
| 150 | | u1 = (v1>>USHIFT) & 0xff; |
| 151 | | v1 = (v1>>VSHIFT) & 0xff; |
| 152 | | |
| 153 | | dest_y[x+yuv_pitch/2]=y1<<8|y1; |
| 154 | | dest_y[x]=y1<<8|y1; |
| 155 | | dest_u[x] = u1; |
| 156 | | dest_v[x] = v1; |
| 157 | | } |
| 158 | | } |
| 159 | | } |
| 160 | | |
| 161 | | static void yuv_RGB_to_YUY2(UINT16 *bitmap, int bw, sdl_window_info *window) |
| 162 | | { /* this one is used when scale==2 */ |
| 163 | | unsigned int y; |
| 164 | | UINT32 *dest; |
| 165 | | UINT16 *src; |
| 166 | | UINT16 *end; |
| 167 | | UINT32 p1,p2,uv; |
| 168 | | UINT32 *lookup = window->yuv_lookup; |
| 169 | | int yuv_pitch = window->yuvsurf->pitches[0]/4; |
| 170 | | |
| 171 | | for(y=0;y<window->yuv_ovl_height;y++) |
| 172 | | { |
| 173 | | src=bitmap + (y * bw) ; |
| 174 | | end=src+window->yuv_ovl_width; |
| 175 | | |
| 176 | | dest = (UINT32 *) window->yuvsurf->pixels[0]; |
| 177 | | dest += y * yuv_pitch; |
| 178 | | for(; src<end; src+=2) |
| 179 | | { |
| 180 | | p1 = lookup[src[0]]; |
| 181 | | p2 = lookup[src[1]]; |
| 182 | | uv = (p1&UVMASK)>>1; |
| 183 | | uv += (p2&UVMASK)>>1; |
| 184 | | *dest++ = (p1&Y1MASK)|(p2&Y2MASK)|(uv&UVMASK); |
| 185 | | } |
| 186 | | } |
| 187 | | } |
| 188 | | |
| 189 | | static void yuv_RGB_to_YUY2X2(UINT16 *bitmap, int bw, sdl_window_info *window) |
| 190 | | { /* this one is used when scale==2 */ |
| 191 | | unsigned int y; |
| 192 | | UINT32 *dest; |
| 193 | | UINT16 *src; |
| 194 | | UINT16 *end; |
| 195 | | UINT32 *lookup = window->yuv_lookup; |
| 196 | | int yuv_pitch = window->yuvsurf->pitches[0]/4; |
| 197 | | |
| 198 | | for(y=0;y<window->yuv_ovl_height;y++) |
| 199 | | { |
| 200 | | src=bitmap + (y * bw) ; |
| 201 | | end=src+window->yuv_ovl_width; |
| 202 | | |
| 203 | | dest = (UINT32 *) window->yuvsurf->pixels[0]; |
| 204 | | dest += (y * yuv_pitch); |
| 205 | | for(; src<end; src++) |
| 206 | | { |
| 207 | | dest[0] = lookup[src[0]]; |
| 208 | | dest++; |
| 209 | | } |
| 210 | | } |
| 211 | | } |
| 212 | | |