comparison src/video/SDL_yuv_sw.c @ 1662:782fd950bd46 SDL-1.3

Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API. WARNING: None of the video drivers have been updated for the new API yet! The API is still under design and very fluid. The code is now run through a consistent indent format: indent -i4 -nut -nsc -br -ce The headers are being converted to automatically generate doxygen documentation.
author Sam Lantinga <slouken@libsdl.org>
date Sun, 28 May 2006 13:04:16 +0000
parents 8a858076f39d
children 4da1ee79c9af
comparison
equal deleted inserted replaced
1661:281d3f4870e5 1662:782fd950bd46
89 #include "SDL_yuvfuncs.h" 89 #include "SDL_yuvfuncs.h"
90 #include "SDL_yuv_sw_c.h" 90 #include "SDL_yuv_sw_c.h"
91 91
92 /* The functions used to manipulate software video overlays */ 92 /* The functions used to manipulate software video overlays */
93 static struct private_yuvhwfuncs sw_yuvfuncs = { 93 static struct private_yuvhwfuncs sw_yuvfuncs = {
94 SDL_LockYUV_SW, 94 SDL_LockYUV_SW,
95 SDL_UnlockYUV_SW, 95 SDL_UnlockYUV_SW,
96 SDL_DisplayYUV_SW, 96 SDL_DisplayYUV_SW,
97 SDL_FreeYUV_SW 97 SDL_FreeYUV_SW
98 }; 98 };
99 99
100 /* RGB conversion lookup tables */ 100 /* RGB conversion lookup tables */
101 struct private_yuvhwdata { 101 struct private_yuvhwdata
102 SDL_Surface *stretch; 102 {
103 SDL_Surface *display; 103 SDL_Surface *stretch;
104 Uint8 *pixels; 104 SDL_Surface *display;
105 int *colortab; 105 Uint8 *pixels;
106 Uint32 *rgb_2_pix; 106 int *colortab;
107 void (*Display1X)(int *colortab, Uint32 *rgb_2_pix, 107 Uint32 *rgb_2_pix;
108 unsigned char *lum, unsigned char *cr, 108 void (*Display1X) (int *colortab, Uint32 * rgb_2_pix,
109 unsigned char *cb, unsigned char *out, 109 unsigned char *lum, unsigned char *cr,
110 int rows, int cols, int mod ); 110 unsigned char *cb, unsigned char *out,
111 void (*Display2X)(int *colortab, Uint32 *rgb_2_pix, 111 int rows, int cols, int mod);
112 unsigned char *lum, unsigned char *cr, 112 void (*Display2X) (int *colortab, Uint32 * rgb_2_pix,
113 unsigned char *cb, unsigned char *out, 113 unsigned char *lum, unsigned char *cr,
114 int rows, int cols, int mod ); 114 unsigned char *cb, unsigned char *out,
115 115 int rows, int cols, int mod);
116 /* These are just so we don't have to allocate them separately */ 116
117 Uint16 pitches[3]; 117 /* These are just so we don't have to allocate them separately */
118 Uint8 *planes[3]; 118 Uint16 pitches[3];
119 Uint8 *planes[3];
119 }; 120 };
120 121
121 122
122 /* The colorspace conversion functions */ 123 /* The colorspace conversion functions */
123 124
124 #if 0 /*defined(__GNUC__) && defined(__i386__) && SDL_ASSEMBLY_ROUTINES*/ 125 #if 0 /*defined(__GNUC__) && defined(__i386__) && SDL_ASSEMBLY_ROUTINES */
125 extern void Color565DitherYV12MMX1X( int *colortab, Uint32 *rgb_2_pix, 126 extern void Color565DitherYV12MMX1X (int *colortab, Uint32 * rgb_2_pix,
126 unsigned char *lum, unsigned char *cr, 127 unsigned char *lum, unsigned char *cr,
127 unsigned char *cb, unsigned char *out, 128 unsigned char *cb, unsigned char *out,
128 int rows, int cols, int mod ); 129 int rows, int cols, int mod);
129 extern void ColorRGBDitherYV12MMX1X( int *colortab, Uint32 *rgb_2_pix, 130 extern void ColorRGBDitherYV12MMX1X (int *colortab, Uint32 * rgb_2_pix,
130 unsigned char *lum, unsigned char *cr, 131 unsigned char *lum, unsigned char *cr,
131 unsigned char *cb, unsigned char *out, 132 unsigned char *cb, unsigned char *out,
132 int rows, int cols, int mod ); 133 int rows, int cols, int mod);
133 #endif 134 #endif
134 135
135 static void Color16DitherYV12Mod1X( int *colortab, Uint32 *rgb_2_pix, 136 static void
136 unsigned char *lum, unsigned char *cr, 137 Color16DitherYV12Mod1X (int *colortab, Uint32 * rgb_2_pix,
137 unsigned char *cb, unsigned char *out, 138 unsigned char *lum, unsigned char *cr,
138 int rows, int cols, int mod ) 139 unsigned char *cb, unsigned char *out,
139 { 140 int rows, int cols, int mod)
140 unsigned short* row1; 141 {
141 unsigned short* row2; 142 unsigned short *row1;
142 unsigned char* lum2; 143 unsigned short *row2;
144 unsigned char *lum2;
143 int x, y; 145 int x, y;
144 int cr_r; 146 int cr_r;
145 int crb_g; 147 int crb_g;
146 int cb_b; 148 int cb_b;
147 int cols_2 = cols / 2; 149 int cols_2 = cols / 2;
148 150
149 row1 = (unsigned short*) out; 151 row1 = (unsigned short *) out;
150 row2 = row1 + cols + mod; 152 row2 = row1 + cols + mod;
151 lum2 = lum + cols; 153 lum2 = lum + cols;
152 154
153 mod += cols + mod; 155 mod += cols + mod;
154 156
155 y = rows / 2; 157 y = rows / 2;
156 while( y-- ) 158 while (y--) {
157 {
158 x = cols_2; 159 x = cols_2;
159 while( x-- ) 160 while (x--) {
160 {
161 register int L; 161 register int L;
162 162
163 cr_r = 0*768+256 + colortab[ *cr + 0*256 ]; 163 cr_r = 0 * 768 + 256 + colortab[*cr + 0 * 256];
164 crb_g = 1*768+256 + colortab[ *cr + 1*256 ] 164 crb_g = 1 * 768 + 256 + colortab[*cr + 1 * 256]
165 + colortab[ *cb + 2*256 ]; 165 + colortab[*cb + 2 * 256];
166 cb_b = 2*768+256 + colortab[ *cb + 3*256 ]; 166 cb_b = 2 * 768 + 256 + colortab[*cb + 3 * 256];
167 ++cr; ++cb; 167 ++cr;
168 ++cb;
168 169
169 L = *lum++; 170 L = *lum++;
170 *row1++ = (unsigned short)(rgb_2_pix[ L + cr_r ] | 171 *row1++ = (unsigned short) (rgb_2_pix[L + cr_r] |
171 rgb_2_pix[ L + crb_g ] | 172 rgb_2_pix[L + crb_g] |
172 rgb_2_pix[ L + cb_b ]); 173 rgb_2_pix[L + cb_b]);
173 174
174 L = *lum++; 175 L = *lum++;
175 *row1++ = (unsigned short)(rgb_2_pix[ L + cr_r ] | 176 *row1++ = (unsigned short) (rgb_2_pix[L + cr_r] |
176 rgb_2_pix[ L + crb_g ] | 177 rgb_2_pix[L + crb_g] |
177 rgb_2_pix[ L + cb_b ]); 178 rgb_2_pix[L + cb_b]);
178 179
179 180
180 /* Now, do second row. */ 181 /* Now, do second row. */
181 182
182 L = *lum2++; 183 L = *lum2++;
183 *row2++ = (unsigned short)(rgb_2_pix[ L + cr_r ] | 184 *row2++ = (unsigned short) (rgb_2_pix[L + cr_r] |
184 rgb_2_pix[ L + crb_g ] | 185 rgb_2_pix[L + crb_g] |
185 rgb_2_pix[ L + cb_b ]); 186 rgb_2_pix[L + cb_b]);
186 187
187 L = *lum2++; 188 L = *lum2++;
188 *row2++ = (unsigned short)(rgb_2_pix[ L + cr_r ] | 189 *row2++ = (unsigned short) (rgb_2_pix[L + cr_r] |
189 rgb_2_pix[ L + crb_g ] | 190 rgb_2_pix[L + crb_g] |
190 rgb_2_pix[ L + cb_b ]); 191 rgb_2_pix[L + cb_b]);
191 } 192 }
192 193
193 /* 194 /*
194 * These values are at the start of the next line, (due 195 * These values are at the start of the next line, (due
195 * to the ++'s above),but they need to be at the start 196 * to the ++'s above),but they need to be at the start
196 * of the line after that. 197 * of the line after that.
197 */ 198 */
198 lum += cols; 199 lum += cols;
199 lum2 += cols; 200 lum2 += cols;
200 row1 += mod; 201 row1 += mod;
201 row2 += mod; 202 row2 += mod;
202 } 203 }
203 } 204 }
204 205
205 static void Color24DitherYV12Mod1X( int *colortab, Uint32 *rgb_2_pix, 206 static void
206 unsigned char *lum, unsigned char *cr, 207 Color24DitherYV12Mod1X (int *colortab, Uint32 * rgb_2_pix,
207 unsigned char *cb, unsigned char *out, 208 unsigned char *lum, unsigned char *cr,
208 int rows, int cols, int mod ) 209 unsigned char *cb, unsigned char *out,
210 int rows, int cols, int mod)
209 { 211 {
210 unsigned int value; 212 unsigned int value;
211 unsigned char* row1; 213 unsigned char *row1;
212 unsigned char* row2; 214 unsigned char *row2;
213 unsigned char* lum2; 215 unsigned char *lum2;
214 int x, y; 216 int x, y;
215 int cr_r; 217 int cr_r;
216 int crb_g; 218 int crb_g;
217 int cb_b; 219 int cb_b;
218 int cols_2 = cols / 2; 220 int cols_2 = cols / 2;
219 221
220 row1 = out; 222 row1 = out;
221 row2 = row1 + cols*3 + mod*3; 223 row2 = row1 + cols * 3 + mod * 3;
222 lum2 = lum + cols; 224 lum2 = lum + cols;
223 225
224 mod += cols + mod; 226 mod += cols + mod;
225 mod *= 3; 227 mod *= 3;
226 228
227 y = rows / 2; 229 y = rows / 2;
228 while( y-- ) 230 while (y--) {
229 {
230 x = cols_2; 231 x = cols_2;
231 while( x-- ) 232 while (x--) {
232 {
233 register int L; 233 register int L;
234 234
235 cr_r = 0*768+256 + colortab[ *cr + 0*256 ]; 235 cr_r = 0 * 768 + 256 + colortab[*cr + 0 * 256];
236 crb_g = 1*768+256 + colortab[ *cr + 1*256 ] 236 crb_g = 1 * 768 + 256 + colortab[*cr + 1 * 256]
237 + colortab[ *cb + 2*256 ]; 237 + colortab[*cb + 2 * 256];
238 cb_b = 2*768+256 + colortab[ *cb + 3*256 ]; 238 cb_b = 2 * 768 + 256 + colortab[*cb + 3 * 256];
239 ++cr; ++cb; 239 ++cr;
240 ++cb;
240 241
241 L = *lum++; 242 L = *lum++;
242 value = (rgb_2_pix[ L + cr_r ] | 243 value = (rgb_2_pix[L + cr_r] |
243 rgb_2_pix[ L + crb_g ] | 244 rgb_2_pix[L + crb_g] | rgb_2_pix[L + cb_b]);
244 rgb_2_pix[ L + cb_b ]); 245 *row1++ = (value) & 0xFF;
245 *row1++ = (value ) & 0xFF; 246 *row1++ = (value >> 8) & 0xFF;
246 *row1++ = (value >> 8) & 0xFF;
247 *row1++ = (value >> 16) & 0xFF; 247 *row1++ = (value >> 16) & 0xFF;
248 248
249 L = *lum++; 249 L = *lum++;
250 value = (rgb_2_pix[ L + cr_r ] | 250 value = (rgb_2_pix[L + cr_r] |
251 rgb_2_pix[ L + crb_g ] | 251 rgb_2_pix[L + crb_g] | rgb_2_pix[L + cb_b]);
252 rgb_2_pix[ L + cb_b ]); 252 *row1++ = (value) & 0xFF;
253 *row1++ = (value ) & 0xFF; 253 *row1++ = (value >> 8) & 0xFF;
254 *row1++ = (value >> 8) & 0xFF;
255 *row1++ = (value >> 16) & 0xFF; 254 *row1++ = (value >> 16) & 0xFF;
256 255
257 256
258 /* Now, do second row. */ 257 /* Now, do second row. */
259 258
260 L = *lum2++; 259 L = *lum2++;
261 value = (rgb_2_pix[ L + cr_r ] | 260 value = (rgb_2_pix[L + cr_r] |
262 rgb_2_pix[ L + crb_g ] | 261 rgb_2_pix[L + crb_g] | rgb_2_pix[L + cb_b]);
263 rgb_2_pix[ L + cb_b ]); 262 *row2++ = (value) & 0xFF;
264 *row2++ = (value ) & 0xFF; 263 *row2++ = (value >> 8) & 0xFF;
265 *row2++ = (value >> 8) & 0xFF;
266 *row2++ = (value >> 16) & 0xFF; 264 *row2++ = (value >> 16) & 0xFF;
267 265
268 L = *lum2++; 266 L = *lum2++;
269 value = (rgb_2_pix[ L + cr_r ] | 267 value = (rgb_2_pix[L + cr_r] |
270 rgb_2_pix[ L + crb_g ] | 268 rgb_2_pix[L + crb_g] | rgb_2_pix[L + cb_b]);
271 rgb_2_pix[ L + cb_b ]); 269 *row2++ = (value) & 0xFF;
272 *row2++ = (value ) & 0xFF; 270 *row2++ = (value >> 8) & 0xFF;
273 *row2++ = (value >> 8) & 0xFF;
274 *row2++ = (value >> 16) & 0xFF; 271 *row2++ = (value >> 16) & 0xFF;
275 } 272 }
276 273
277 /* 274 /*
278 * These values are at the start of the next line, (due 275 * These values are at the start of the next line, (due
279 * to the ++'s above),but they need to be at the start 276 * to the ++'s above),but they need to be at the start
280 * of the line after that. 277 * of the line after that.
281 */ 278 */
282 lum += cols; 279 lum += cols;
283 lum2 += cols; 280 lum2 += cols;
284 row1 += mod; 281 row1 += mod;
285 row2 += mod; 282 row2 += mod;
286 } 283 }
287 } 284 }
288 285
289 static void Color32DitherYV12Mod1X( int *colortab, Uint32 *rgb_2_pix, 286 static void
290 unsigned char *lum, unsigned char *cr, 287 Color32DitherYV12Mod1X (int *colortab, Uint32 * rgb_2_pix,
291 unsigned char *cb, unsigned char *out, 288 unsigned char *lum, unsigned char *cr,
292 int rows, int cols, int mod ) 289 unsigned char *cb, unsigned char *out,
293 { 290 int rows, int cols, int mod)
294 unsigned int* row1; 291 {
295 unsigned int* row2; 292 unsigned int *row1;
296 unsigned char* lum2; 293 unsigned int *row2;
294 unsigned char *lum2;
297 int x, y; 295 int x, y;
298 int cr_r; 296 int cr_r;
299 int crb_g; 297 int crb_g;
300 int cb_b; 298 int cb_b;
301 int cols_2 = cols / 2; 299 int cols_2 = cols / 2;
302 300
303 row1 = (unsigned int*) out; 301 row1 = (unsigned int *) out;
304 row2 = row1 + cols + mod; 302 row2 = row1 + cols + mod;
305 lum2 = lum + cols; 303 lum2 = lum + cols;
306 304
307 mod += cols + mod; 305 mod += cols + mod;
308 306
309 y = rows / 2; 307 y = rows / 2;
310 while( y-- ) 308 while (y--) {
311 {
312 x = cols_2; 309 x = cols_2;
313 while( x-- ) 310 while (x--) {
314 {
315 register int L; 311 register int L;
316 312
317 cr_r = 0*768+256 + colortab[ *cr + 0*256 ]; 313 cr_r = 0 * 768 + 256 + colortab[*cr + 0 * 256];
318 crb_g = 1*768+256 + colortab[ *cr + 1*256 ] 314 crb_g = 1 * 768 + 256 + colortab[*cr + 1 * 256]
319 + colortab[ *cb + 2*256 ]; 315 + colortab[*cb + 2 * 256];
320 cb_b = 2*768+256 + colortab[ *cb + 3*256 ]; 316 cb_b = 2 * 768 + 256 + colortab[*cb + 3 * 256];
321 ++cr; ++cb; 317 ++cr;
318 ++cb;
322 319
323 L = *lum++; 320 L = *lum++;
324 *row1++ = (rgb_2_pix[ L + cr_r ] | 321 *row1++ = (rgb_2_pix[L + cr_r] |
325 rgb_2_pix[ L + crb_g ] | 322 rgb_2_pix[L + crb_g] | rgb_2_pix[L + cb_b]);
326 rgb_2_pix[ L + cb_b ]);
327 323
328 L = *lum++; 324 L = *lum++;
329 *row1++ = (rgb_2_pix[ L + cr_r ] | 325 *row1++ = (rgb_2_pix[L + cr_r] |
330 rgb_2_pix[ L + crb_g ] | 326 rgb_2_pix[L + crb_g] | rgb_2_pix[L + cb_b]);
331 rgb_2_pix[ L + cb_b ]);
332 327
333 328
334 /* Now, do second row. */ 329 /* Now, do second row. */
335 330
336 L = *lum2++; 331 L = *lum2++;
337 *row2++ = (rgb_2_pix[ L + cr_r ] | 332 *row2++ = (rgb_2_pix[L + cr_r] |
338 rgb_2_pix[ L + crb_g ] | 333 rgb_2_pix[L + crb_g] | rgb_2_pix[L + cb_b]);
339 rgb_2_pix[ L + cb_b ]);
340 334
341 L = *lum2++; 335 L = *lum2++;
342 *row2++ = (rgb_2_pix[ L + cr_r ] | 336 *row2++ = (rgb_2_pix[L + cr_r] |
343 rgb_2_pix[ L + crb_g ] | 337 rgb_2_pix[L + crb_g] | rgb_2_pix[L + cb_b]);
344 rgb_2_pix[ L + cb_b ]);
345 } 338 }
346 339
347 /* 340 /*
348 * These values are at the start of the next line, (due 341 * These values are at the start of the next line, (due
349 * to the ++'s above),but they need to be at the start 342 * to the ++'s above),but they need to be at the start
350 * of the line after that. 343 * of the line after that.
351 */ 344 */
352 lum += cols; 345 lum += cols;
353 lum2 += cols; 346 lum2 += cols;
354 row1 += mod; 347 row1 += mod;
355 row2 += mod; 348 row2 += mod;
356 } 349 }
357 } 350 }
359 /* 352 /*
360 * In this function I make use of a nasty trick. The tables have the lower 353 * In this function I make use of a nasty trick. The tables have the lower
361 * 16 bits replicated in the upper 16. This means I can write ints and get 354 * 16 bits replicated in the upper 16. This means I can write ints and get
362 * the horisontal doubling for free (almost). 355 * the horisontal doubling for free (almost).
363 */ 356 */
364 static void Color16DitherYV12Mod2X( int *colortab, Uint32 *rgb_2_pix, 357 static void
365 unsigned char *lum, unsigned char *cr, 358 Color16DitherYV12Mod2X (int *colortab, Uint32 * rgb_2_pix,
366 unsigned char *cb, unsigned char *out, 359 unsigned char *lum, unsigned char *cr,
367 int rows, int cols, int mod ) 360 unsigned char *cb, unsigned char *out,
368 { 361 int rows, int cols, int mod)
369 unsigned int* row1 = (unsigned int*) out; 362 {
370 const int next_row = cols+(mod/2); 363 unsigned int *row1 = (unsigned int *) out;
371 unsigned int* row2 = row1 + 2*next_row; 364 const int next_row = cols + (mod / 2);
372 unsigned char* lum2; 365 unsigned int *row2 = row1 + 2 * next_row;
366 unsigned char *lum2;
373 int x, y; 367 int x, y;
374 int cr_r; 368 int cr_r;
375 int crb_g; 369 int crb_g;
376 int cb_b; 370 int cb_b;
377 int cols_2 = cols / 2; 371 int cols_2 = cols / 2;
378 372
379 lum2 = lum + cols; 373 lum2 = lum + cols;
380 374
381 mod = (next_row * 3) + (mod/2); 375 mod = (next_row * 3) + (mod / 2);
382 376
383 y = rows / 2; 377 y = rows / 2;
384 while( y-- ) 378 while (y--) {
385 {
386 x = cols_2; 379 x = cols_2;
387 while( x-- ) 380 while (x--) {
388 {
389 register int L; 381 register int L;
390 382
391 cr_r = 0*768+256 + colortab[ *cr + 0*256 ]; 383 cr_r = 0 * 768 + 256 + colortab[*cr + 0 * 256];
392 crb_g = 1*768+256 + colortab[ *cr + 1*256 ] 384 crb_g = 1 * 768 + 256 + colortab[*cr + 1 * 256]
393 + colortab[ *cb + 2*256 ]; 385 + colortab[*cb + 2 * 256];
394 cb_b = 2*768+256 + colortab[ *cb + 3*256 ]; 386 cb_b = 2 * 768 + 256 + colortab[*cb + 3 * 256];
395 ++cr; ++cb; 387 ++cr;
388 ++cb;
396 389
397 L = *lum++; 390 L = *lum++;
398 row1[0] = row1[next_row] = (rgb_2_pix[ L + cr_r ] | 391 row1[0] = row1[next_row] = (rgb_2_pix[L + cr_r] |
399 rgb_2_pix[ L + crb_g ] | 392 rgb_2_pix[L + crb_g] |
400 rgb_2_pix[ L + cb_b ]); 393 rgb_2_pix[L + cb_b]);
401 row1++; 394 row1++;
402 395
403 L = *lum++; 396 L = *lum++;
404 row1[0] = row1[next_row] = (rgb_2_pix[ L + cr_r ] | 397 row1[0] = row1[next_row] = (rgb_2_pix[L + cr_r] |
405 rgb_2_pix[ L + crb_g ] | 398 rgb_2_pix[L + crb_g] |
406 rgb_2_pix[ L + cb_b ]); 399 rgb_2_pix[L + cb_b]);
407 row1++; 400 row1++;
408 401
409 402
410 /* Now, do second row. */ 403 /* Now, do second row. */
411 404
412 L = *lum2++; 405 L = *lum2++;
413 row2[0] = row2[next_row] = (rgb_2_pix[ L + cr_r ] | 406 row2[0] = row2[next_row] = (rgb_2_pix[L + cr_r] |
414 rgb_2_pix[ L + crb_g ] | 407 rgb_2_pix[L + crb_g] |
415 rgb_2_pix[ L + cb_b ]); 408 rgb_2_pix[L + cb_b]);
416 row2++; 409 row2++;
417 410
418 L = *lum2++; 411 L = *lum2++;
419 row2[0] = row2[next_row] = (rgb_2_pix[ L + cr_r ] | 412 row2[0] = row2[next_row] = (rgb_2_pix[L + cr_r] |
420 rgb_2_pix[ L + crb_g ] | 413 rgb_2_pix[L + crb_g] |
421 rgb_2_pix[ L + cb_b ]); 414 rgb_2_pix[L + cb_b]);
422 row2++; 415 row2++;
423 } 416 }
424 417
425 /* 418 /*
426 * These values are at the start of the next line, (due 419 * These values are at the start of the next line, (due
427 * to the ++'s above),but they need to be at the start 420 * to the ++'s above),but they need to be at the start
428 * of the line after that. 421 * of the line after that.
429 */ 422 */
430 lum += cols; 423 lum += cols;
431 lum2 += cols; 424 lum2 += cols;
432 row1 += mod; 425 row1 += mod;
433 row2 += mod; 426 row2 += mod;
434 } 427 }
435 } 428 }
436 429
437 static void Color24DitherYV12Mod2X( int *colortab, Uint32 *rgb_2_pix, 430 static void
438 unsigned char *lum, unsigned char *cr, 431 Color24DitherYV12Mod2X (int *colortab, Uint32 * rgb_2_pix,
439 unsigned char *cb, unsigned char *out, 432 unsigned char *lum, unsigned char *cr,
440 int rows, int cols, int mod ) 433 unsigned char *cb, unsigned char *out,
434 int rows, int cols, int mod)
441 { 435 {
442 unsigned int value; 436 unsigned int value;
443 unsigned char* row1 = out; 437 unsigned char *row1 = out;
444 const int next_row = (cols*2 + mod) * 3; 438 const int next_row = (cols * 2 + mod) * 3;
445 unsigned char* row2 = row1 + 2*next_row; 439 unsigned char *row2 = row1 + 2 * next_row;
446 unsigned char* lum2; 440 unsigned char *lum2;
447 int x, y; 441 int x, y;
448 int cr_r; 442 int cr_r;
449 int crb_g; 443 int crb_g;
450 int cb_b; 444 int cb_b;
451 int cols_2 = cols / 2; 445 int cols_2 = cols / 2;
452 446
453 lum2 = lum + cols; 447 lum2 = lum + cols;
454 448
455 mod = next_row*3 + mod*3; 449 mod = next_row * 3 + mod * 3;
456 450
457 y = rows / 2; 451 y = rows / 2;
458 while( y-- ) 452 while (y--) {
459 {
460 x = cols_2; 453 x = cols_2;
461 while( x-- ) 454 while (x--) {
462 {
463 register int L; 455 register int L;
464 456
465 cr_r = 0*768+256 + colortab[ *cr + 0*256 ]; 457 cr_r = 0 * 768 + 256 + colortab[*cr + 0 * 256];
466 crb_g = 1*768+256 + colortab[ *cr + 1*256 ] 458 crb_g = 1 * 768 + 256 + colortab[*cr + 1 * 256]
467 + colortab[ *cb + 2*256 ]; 459 + colortab[*cb + 2 * 256];
468 cb_b = 2*768+256 + colortab[ *cb + 3*256 ]; 460 cb_b = 2 * 768 + 256 + colortab[*cb + 3 * 256];
469 ++cr; ++cb; 461 ++cr;
462 ++cb;
470 463
471 L = *lum++; 464 L = *lum++;
472 value = (rgb_2_pix[ L + cr_r ] | 465 value = (rgb_2_pix[L + cr_r] |
473 rgb_2_pix[ L + crb_g ] | 466 rgb_2_pix[L + crb_g] | rgb_2_pix[L + cb_b]);
474 rgb_2_pix[ L + cb_b ]); 467 row1[0 + 0] = row1[3 + 0] = row1[next_row + 0] =
475 row1[0+0] = row1[3+0] = row1[next_row+0] = row1[next_row+3+0] = 468 row1[next_row + 3 + 0] = (value) & 0xFF;
476 (value ) & 0xFF; 469 row1[0 + 1] = row1[3 + 1] = row1[next_row + 1] =
477 row1[0+1] = row1[3+1] = row1[next_row+1] = row1[next_row+3+1] = 470 row1[next_row + 3 + 1] = (value >> 8) & 0xFF;
478 (value >> 8) & 0xFF; 471 row1[0 + 2] = row1[3 + 2] = row1[next_row + 2] =
479 row1[0+2] = row1[3+2] = row1[next_row+2] = row1[next_row+3+2] = 472 row1[next_row + 3 + 2] = (value >> 16) & 0xFF;
480 (value >> 16) & 0xFF; 473 row1 += 2 * 3;
481 row1 += 2*3;
482 474
483 L = *lum++; 475 L = *lum++;
484 value = (rgb_2_pix[ L + cr_r ] | 476 value = (rgb_2_pix[L + cr_r] |
485 rgb_2_pix[ L + crb_g ] | 477 rgb_2_pix[L + crb_g] | rgb_2_pix[L + cb_b]);
486 rgb_2_pix[ L + cb_b ]); 478 row1[0 + 0] = row1[3 + 0] = row1[next_row + 0] =
487 row1[0+0] = row1[3+0] = row1[next_row+0] = row1[next_row+3+0] = 479 row1[next_row + 3 + 0] = (value) & 0xFF;
488 (value ) & 0xFF; 480 row1[0 + 1] = row1[3 + 1] = row1[next_row + 1] =
489 row1[0+1] = row1[3+1] = row1[next_row+1] = row1[next_row+3+1] = 481 row1[next_row + 3 + 1] = (value >> 8) & 0xFF;
490 (value >> 8) & 0xFF; 482 row1[0 + 2] = row1[3 + 2] = row1[next_row + 2] =
491 row1[0+2] = row1[3+2] = row1[next_row+2] = row1[next_row+3+2] = 483 row1[next_row + 3 + 2] = (value >> 16) & 0xFF;
492 (value >> 16) & 0xFF; 484 row1 += 2 * 3;
493 row1 += 2*3;
494 485
495 486
496 /* Now, do second row. */ 487 /* Now, do second row. */
497 488
498 L = *lum2++; 489 L = *lum2++;
499 value = (rgb_2_pix[ L + cr_r ] | 490 value = (rgb_2_pix[L + cr_r] |
500 rgb_2_pix[ L + crb_g ] | 491 rgb_2_pix[L + crb_g] | rgb_2_pix[L + cb_b]);
501 rgb_2_pix[ L + cb_b ]); 492 row2[0 + 0] = row2[3 + 0] = row2[next_row + 0] =
502 row2[0+0] = row2[3+0] = row2[next_row+0] = row2[next_row+3+0] = 493 row2[next_row + 3 + 0] = (value) & 0xFF;
503 (value ) & 0xFF; 494 row2[0 + 1] = row2[3 + 1] = row2[next_row + 1] =
504 row2[0+1] = row2[3+1] = row2[next_row+1] = row2[next_row+3+1] = 495 row2[next_row + 3 + 1] = (value >> 8) & 0xFF;
505 (value >> 8) & 0xFF; 496 row2[0 + 2] = row2[3 + 2] = row2[next_row + 2] =
506 row2[0+2] = row2[3+2] = row2[next_row+2] = row2[next_row+3+2] = 497 row2[next_row + 3 + 2] = (value >> 16) & 0xFF;
507 (value >> 16) & 0xFF; 498 row2 += 2 * 3;
508 row2 += 2*3;
509 499
510 L = *lum2++; 500 L = *lum2++;
511 value = (rgb_2_pix[ L + cr_r ] | 501 value = (rgb_2_pix[L + cr_r] |
512 rgb_2_pix[ L + crb_g ] | 502 rgb_2_pix[L + crb_g] | rgb_2_pix[L + cb_b]);
513 rgb_2_pix[ L + cb_b ]); 503 row2[0 + 0] = row2[3 + 0] = row2[next_row + 0] =
514 row2[0+0] = row2[3+0] = row2[next_row+0] = row2[next_row+3+0] = 504 row2[next_row + 3 + 0] = (value) & 0xFF;
515 (value ) & 0xFF; 505 row2[0 + 1] = row2[3 + 1] = row2[next_row + 1] =
516 row2[0+1] = row2[3+1] = row2[next_row+1] = row2[next_row+3+1] = 506 row2[next_row + 3 + 1] = (value >> 8) & 0xFF;
517 (value >> 8) & 0xFF; 507 row2[0 + 2] = row2[3 + 2] = row2[next_row + 2] =
518 row2[0+2] = row2[3+2] = row2[next_row+2] = row2[next_row+3+2] = 508 row2[next_row + 3 + 2] = (value >> 16) & 0xFF;
519 (value >> 16) & 0xFF; 509 row2 += 2 * 3;
520 row2 += 2*3;
521 } 510 }
522 511
523 /* 512 /*
524 * These values are at the start of the next line, (due 513 * These values are at the start of the next line, (due
525 * to the ++'s above),but they need to be at the start 514 * to the ++'s above),but they need to be at the start
526 * of the line after that. 515 * of the line after that.
527 */ 516 */
528 lum += cols; 517 lum += cols;
529 lum2 += cols; 518 lum2 += cols;
530 row1 += mod; 519 row1 += mod;
531 row2 += mod; 520 row2 += mod;
532 } 521 }
533 } 522 }
534 523
535 static void Color32DitherYV12Mod2X( int *colortab, Uint32 *rgb_2_pix, 524 static void
536 unsigned char *lum, unsigned char *cr, 525 Color32DitherYV12Mod2X (int *colortab, Uint32 * rgb_2_pix,
537 unsigned char *cb, unsigned char *out, 526 unsigned char *lum, unsigned char *cr,
538 int rows, int cols, int mod ) 527 unsigned char *cb, unsigned char *out,
539 { 528 int rows, int cols, int mod)
540 unsigned int* row1 = (unsigned int*) out; 529 {
541 const int next_row = cols*2+mod; 530 unsigned int *row1 = (unsigned int *) out;
542 unsigned int* row2 = row1 + 2*next_row; 531 const int next_row = cols * 2 + mod;
543 unsigned char* lum2; 532 unsigned int *row2 = row1 + 2 * next_row;
533 unsigned char *lum2;
544 int x, y; 534 int x, y;
545 int cr_r; 535 int cr_r;
546 int crb_g; 536 int crb_g;
547 int cb_b; 537 int cb_b;
548 int cols_2 = cols / 2; 538 int cols_2 = cols / 2;
550 lum2 = lum + cols; 540 lum2 = lum + cols;
551 541
552 mod = (next_row * 3) + mod; 542 mod = (next_row * 3) + mod;
553 543
554 y = rows / 2; 544 y = rows / 2;
555 while( y-- ) 545 while (y--) {
556 {
557 x = cols_2; 546 x = cols_2;
558 while( x-- ) 547 while (x--) {
559 {
560 register int L; 548 register int L;
561 549
562 cr_r = 0*768+256 + colortab[ *cr + 0*256 ]; 550 cr_r = 0 * 768 + 256 + colortab[*cr + 0 * 256];
563 crb_g = 1*768+256 + colortab[ *cr + 1*256 ] 551 crb_g = 1 * 768 + 256 + colortab[*cr + 1 * 256]
564 + colortab[ *cb + 2*256 ]; 552 + colortab[*cb + 2 * 256];
565 cb_b = 2*768+256 + colortab[ *cb + 3*256 ]; 553 cb_b = 2 * 768 + 256 + colortab[*cb + 3 * 256];
566 ++cr; ++cb; 554 ++cr;
555 ++cb;
567 556
568 L = *lum++; 557 L = *lum++;
569 row1[0] = row1[1] = row1[next_row] = row1[next_row+1] = 558 row1[0] = row1[1] = row1[next_row] = row1[next_row + 1] =
570 (rgb_2_pix[ L + cr_r ] | 559 (rgb_2_pix[L + cr_r] |
571 rgb_2_pix[ L + crb_g ] | 560 rgb_2_pix[L + crb_g] | rgb_2_pix[L + cb_b]);
572 rgb_2_pix[ L + cb_b ]);
573 row1 += 2; 561 row1 += 2;
574 562
575 L = *lum++; 563 L = *lum++;
576 row1[0] = row1[1] = row1[next_row] = row1[next_row+1] = 564 row1[0] = row1[1] = row1[next_row] = row1[next_row + 1] =
577 (rgb_2_pix[ L + cr_r ] | 565 (rgb_2_pix[L + cr_r] |
578 rgb_2_pix[ L + crb_g ] | 566 rgb_2_pix[L + crb_g] | rgb_2_pix[L + cb_b]);
579 rgb_2_pix[ L + cb_b ]);
580 row1 += 2; 567 row1 += 2;
581 568
582 569
583 /* Now, do second row. */ 570 /* Now, do second row. */
584 571
585 L = *lum2++; 572 L = *lum2++;
586 row2[0] = row2[1] = row2[next_row] = row2[next_row+1] = 573 row2[0] = row2[1] = row2[next_row] = row2[next_row + 1] =
587 (rgb_2_pix[ L + cr_r ] | 574 (rgb_2_pix[L + cr_r] |
588 rgb_2_pix[ L + crb_g ] | 575 rgb_2_pix[L + crb_g] | rgb_2_pix[L + cb_b]);
589 rgb_2_pix[ L + cb_b ]);
590 row2 += 2; 576 row2 += 2;
591 577
592 L = *lum2++; 578 L = *lum2++;
593 row2[0] = row2[1] = row2[next_row] = row2[next_row+1] = 579 row2[0] = row2[1] = row2[next_row] = row2[next_row + 1] =
594 (rgb_2_pix[ L + cr_r ] | 580 (rgb_2_pix[L + cr_r] |
595 rgb_2_pix[ L + crb_g ] | 581 rgb_2_pix[L + crb_g] | rgb_2_pix[L + cb_b]);
596 rgb_2_pix[ L + cb_b ]);
597 row2 += 2; 582 row2 += 2;
598 } 583 }
599 584
600 /* 585 /*
601 * These values are at the start of the next line, (due 586 * These values are at the start of the next line, (due
602 * to the ++'s above),but they need to be at the start 587 * to the ++'s above),but they need to be at the start
603 * of the line after that. 588 * of the line after that.
604 */ 589 */
605 lum += cols; 590 lum += cols;
606 lum2 += cols; 591 lum2 += cols;
607 row1 += mod; 592 row1 += mod;
608 row2 += mod; 593 row2 += mod;
609 } 594 }
610 } 595 }
611 596
612 static void Color16DitherYUY2Mod1X( int *colortab, Uint32 *rgb_2_pix, 597 static void
613 unsigned char *lum, unsigned char *cr, 598 Color16DitherYUY2Mod1X (int *colortab, Uint32 * rgb_2_pix,
614 unsigned char *cb, unsigned char *out, 599 unsigned char *lum, unsigned char *cr,
615 int rows, int cols, int mod ) 600 unsigned char *cb, unsigned char *out,
616 { 601 int rows, int cols, int mod)
617 unsigned short* row; 602 {
603 unsigned short *row;
618 int x, y; 604 int x, y;
619 int cr_r; 605 int cr_r;
620 int crb_g; 606 int crb_g;
621 int cb_b; 607 int cb_b;
622 int cols_2 = cols / 2; 608 int cols_2 = cols / 2;
623 609
624 row = (unsigned short*) out; 610 row = (unsigned short *) out;
625 611
626 y = rows; 612 y = rows;
627 while( y-- ) 613 while (y--) {
628 {
629 x = cols_2; 614 x = cols_2;
630 while( x-- ) 615 while (x--) {
631 {
632 register int L; 616 register int L;
633 617
634 cr_r = 0*768+256 + colortab[ *cr + 0*256 ]; 618 cr_r = 0 * 768 + 256 + colortab[*cr + 0 * 256];
635 crb_g = 1*768+256 + colortab[ *cr + 1*256 ] 619 crb_g = 1 * 768 + 256 + colortab[*cr + 1 * 256]
636 + colortab[ *cb + 2*256 ]; 620 + colortab[*cb + 2 * 256];
637 cb_b = 2*768+256 + colortab[ *cb + 3*256 ]; 621 cb_b = 2 * 768 + 256 + colortab[*cb + 3 * 256];
638 cr += 4; cb += 4; 622 cr += 4;
639 623 cb += 4;
640 L = *lum; lum += 2; 624
641 *row++ = (unsigned short)(rgb_2_pix[ L + cr_r ] | 625 L = *lum;
642 rgb_2_pix[ L + crb_g ] | 626 lum += 2;
643 rgb_2_pix[ L + cb_b ]); 627 *row++ = (unsigned short) (rgb_2_pix[L + cr_r] |
644 628 rgb_2_pix[L + crb_g] |
645 L = *lum; lum += 2; 629 rgb_2_pix[L + cb_b]);
646 *row++ = (unsigned short)(rgb_2_pix[ L + cr_r ] | 630
647 rgb_2_pix[ L + crb_g ] | 631 L = *lum;
648 rgb_2_pix[ L + cb_b ]); 632 lum += 2;
633 *row++ = (unsigned short) (rgb_2_pix[L + cr_r] |
634 rgb_2_pix[L + crb_g] |
635 rgb_2_pix[L + cb_b]);
649 636
650 } 637 }
651 638
652 row += mod; 639 row += mod;
653 } 640 }
654 } 641 }
655 642
656 static void Color24DitherYUY2Mod1X( int *colortab, Uint32 *rgb_2_pix, 643 static void
657 unsigned char *lum, unsigned char *cr, 644 Color24DitherYUY2Mod1X (int *colortab, Uint32 * rgb_2_pix,
658 unsigned char *cb, unsigned char *out, 645 unsigned char *lum, unsigned char *cr,
659 int rows, int cols, int mod ) 646 unsigned char *cb, unsigned char *out,
647 int rows, int cols, int mod)
660 { 648 {
661 unsigned int value; 649 unsigned int value;
662 unsigned char* row; 650 unsigned char *row;
663 int x, y; 651 int x, y;
664 int cr_r; 652 int cr_r;
665 int crb_g; 653 int crb_g;
666 int cb_b; 654 int cb_b;
667 int cols_2 = cols / 2; 655 int cols_2 = cols / 2;
668 656
669 row = (unsigned char*) out; 657 row = (unsigned char *) out;
670 mod *= 3; 658 mod *= 3;
671 y = rows; 659 y = rows;
672 while( y-- ) 660 while (y--) {
673 {
674 x = cols_2; 661 x = cols_2;
675 while( x-- ) 662 while (x--) {
676 {
677 register int L; 663 register int L;
678 664
679 cr_r = 0*768+256 + colortab[ *cr + 0*256 ]; 665 cr_r = 0 * 768 + 256 + colortab[*cr + 0 * 256];
680 crb_g = 1*768+256 + colortab[ *cr + 1*256 ] 666 crb_g = 1 * 768 + 256 + colortab[*cr + 1 * 256]
681 + colortab[ *cb + 2*256 ]; 667 + colortab[*cb + 2 * 256];
682 cb_b = 2*768+256 + colortab[ *cb + 3*256 ]; 668 cb_b = 2 * 768 + 256 + colortab[*cb + 3 * 256];
683 cr += 4; cb += 4; 669 cr += 4;
684 670 cb += 4;
685 L = *lum; lum += 2; 671
686 value = (rgb_2_pix[ L + cr_r ] | 672 L = *lum;
687 rgb_2_pix[ L + crb_g ] | 673 lum += 2;
688 rgb_2_pix[ L + cb_b ]); 674 value = (rgb_2_pix[L + cr_r] |
689 *row++ = (value ) & 0xFF; 675 rgb_2_pix[L + crb_g] | rgb_2_pix[L + cb_b]);
690 *row++ = (value >> 8) & 0xFF; 676 *row++ = (value) & 0xFF;
677 *row++ = (value >> 8) & 0xFF;
691 *row++ = (value >> 16) & 0xFF; 678 *row++ = (value >> 16) & 0xFF;
692 679
693 L = *lum; lum += 2; 680 L = *lum;
694 value = (rgb_2_pix[ L + cr_r ] | 681 lum += 2;
695 rgb_2_pix[ L + crb_g ] | 682 value = (rgb_2_pix[L + cr_r] |
696 rgb_2_pix[ L + cb_b ]); 683 rgb_2_pix[L + crb_g] | rgb_2_pix[L + cb_b]);
697 *row++ = (value ) & 0xFF; 684 *row++ = (value) & 0xFF;
698 *row++ = (value >> 8) & 0xFF; 685 *row++ = (value >> 8) & 0xFF;
699 *row++ = (value >> 16) & 0xFF; 686 *row++ = (value >> 16) & 0xFF;
700 687
701 } 688 }
702 row += mod; 689 row += mod;
703 } 690 }
704 } 691 }
705 692
706 static void Color32DitherYUY2Mod1X( int *colortab, Uint32 *rgb_2_pix, 693 static void
707 unsigned char *lum, unsigned char *cr, 694 Color32DitherYUY2Mod1X (int *colortab, Uint32 * rgb_2_pix,
708 unsigned char *cb, unsigned char *out, 695 unsigned char *lum, unsigned char *cr,
709 int rows, int cols, int mod ) 696 unsigned char *cb, unsigned char *out,
710 { 697 int rows, int cols, int mod)
711 unsigned int* row; 698 {
699 unsigned int *row;
712 int x, y; 700 int x, y;
713 int cr_r; 701 int cr_r;
714 int crb_g; 702 int crb_g;
715 int cb_b; 703 int cb_b;
716 int cols_2 = cols / 2; 704 int cols_2 = cols / 2;
717 705
718 row = (unsigned int*) out; 706 row = (unsigned int *) out;
719 y = rows; 707 y = rows;
720 while( y-- ) 708 while (y--) {
721 {
722 x = cols_2; 709 x = cols_2;
723 while( x-- ) 710 while (x--) {
724 {
725 register int L; 711 register int L;
726 712
727 cr_r = 0*768+256 + colortab[ *cr + 0*256 ]; 713 cr_r = 0 * 768 + 256 + colortab[*cr + 0 * 256];
728 crb_g = 1*768+256 + colortab[ *cr + 1*256 ] 714 crb_g = 1 * 768 + 256 + colortab[*cr + 1 * 256]
729 + colortab[ *cb + 2*256 ]; 715 + colortab[*cb + 2 * 256];
730 cb_b = 2*768+256 + colortab[ *cb + 3*256 ]; 716 cb_b = 2 * 768 + 256 + colortab[*cb + 3 * 256];
731 cr += 4; cb += 4; 717 cr += 4;
732 718 cb += 4;
733 L = *lum; lum += 2; 719
734 *row++ = (rgb_2_pix[ L + cr_r ] | 720 L = *lum;
735 rgb_2_pix[ L + crb_g ] | 721 lum += 2;
736 rgb_2_pix[ L + cb_b ]); 722 *row++ = (rgb_2_pix[L + cr_r] |
737 723 rgb_2_pix[L + crb_g] | rgb_2_pix[L + cb_b]);
738 L = *lum; lum += 2; 724
739 *row++ = (rgb_2_pix[ L + cr_r ] | 725 L = *lum;
740 rgb_2_pix[ L + crb_g ] | 726 lum += 2;
741 rgb_2_pix[ L + cb_b ]); 727 *row++ = (rgb_2_pix[L + cr_r] |
728 rgb_2_pix[L + crb_g] | rgb_2_pix[L + cb_b]);
742 729
743 730
744 } 731 }
745 row += mod; 732 row += mod;
746 } 733 }
749 /* 736 /*
750 * In this function I make use of a nasty trick. The tables have the lower 737 * In this function I make use of a nasty trick. The tables have the lower
751 * 16 bits replicated in the upper 16. This means I can write ints and get 738 * 16 bits replicated in the upper 16. This means I can write ints and get
752 * the horisontal doubling for free (almost). 739 * the horisontal doubling for free (almost).
753 */ 740 */
754 static void Color16DitherYUY2Mod2X( int *colortab, Uint32 *rgb_2_pix, 741 static void
755 unsigned char *lum, unsigned char *cr, 742 Color16DitherYUY2Mod2X (int *colortab, Uint32 * rgb_2_pix,
756 unsigned char *cb, unsigned char *out, 743 unsigned char *lum, unsigned char *cr,
757 int rows, int cols, int mod ) 744 unsigned char *cb, unsigned char *out,
758 { 745 int rows, int cols, int mod)
759 unsigned int* row = (unsigned int*) out; 746 {
760 const int next_row = cols+(mod/2); 747 unsigned int *row = (unsigned int *) out;
748 const int next_row = cols + (mod / 2);
761 int x, y; 749 int x, y;
762 int cr_r; 750 int cr_r;
763 int crb_g; 751 int crb_g;
764 int cb_b; 752 int cb_b;
765 int cols_2 = cols / 2; 753 int cols_2 = cols / 2;
766 754
767 y = rows; 755 y = rows;
768 while( y-- ) 756 while (y--) {
769 {
770 x = cols_2; 757 x = cols_2;
771 while( x-- ) 758 while (x--) {
772 {
773 register int L; 759 register int L;
774 760
775 cr_r = 0*768+256 + colortab[ *cr + 0*256 ]; 761 cr_r = 0 * 768 + 256 + colortab[*cr + 0 * 256];
776 crb_g = 1*768+256 + colortab[ *cr + 1*256 ] 762 crb_g = 1 * 768 + 256 + colortab[*cr + 1 * 256]
777 + colortab[ *cb + 2*256 ]; 763 + colortab[*cb + 2 * 256];
778 cb_b = 2*768+256 + colortab[ *cb + 3*256 ]; 764 cb_b = 2 * 768 + 256 + colortab[*cb + 3 * 256];
779 cr += 4; cb += 4; 765 cr += 4;
780 766 cb += 4;
781 L = *lum; lum += 2; 767
782 row[0] = row[next_row] = (rgb_2_pix[ L + cr_r ] | 768 L = *lum;
783 rgb_2_pix[ L + crb_g ] | 769 lum += 2;
784 rgb_2_pix[ L + cb_b ]); 770 row[0] = row[next_row] = (rgb_2_pix[L + cr_r] |
771 rgb_2_pix[L + crb_g] |
772 rgb_2_pix[L + cb_b]);
785 row++; 773 row++;
786 774
787 L = *lum; lum += 2; 775 L = *lum;
788 row[0] = row[next_row] = (rgb_2_pix[ L + cr_r ] | 776 lum += 2;
789 rgb_2_pix[ L + crb_g ] | 777 row[0] = row[next_row] = (rgb_2_pix[L + cr_r] |
790 rgb_2_pix[ L + cb_b ]); 778 rgb_2_pix[L + crb_g] |
779 rgb_2_pix[L + cb_b]);
791 row++; 780 row++;
792 781
793 } 782 }
794 row += next_row; 783 row += next_row;
795 } 784 }
796 } 785 }
797 786
798 static void Color24DitherYUY2Mod2X( int *colortab, Uint32 *rgb_2_pix, 787 static void
799 unsigned char *lum, unsigned char *cr, 788 Color24DitherYUY2Mod2X (int *colortab, Uint32 * rgb_2_pix,
800 unsigned char *cb, unsigned char *out, 789 unsigned char *lum, unsigned char *cr,
801 int rows, int cols, int mod ) 790 unsigned char *cb, unsigned char *out,
791 int rows, int cols, int mod)
802 { 792 {
803 unsigned int value; 793 unsigned int value;
804 unsigned char* row = out; 794 unsigned char *row = out;
805 const int next_row = (cols*2 + mod) * 3; 795 const int next_row = (cols * 2 + mod) * 3;
806 int x, y; 796 int x, y;
807 int cr_r; 797 int cr_r;
808 int crb_g; 798 int crb_g;
809 int cb_b; 799 int cb_b;
810 int cols_2 = cols / 2; 800 int cols_2 = cols / 2;
811 y = rows; 801 y = rows;
812 while( y-- ) 802 while (y--) {
813 {
814 x = cols_2; 803 x = cols_2;
815 while( x-- ) 804 while (x--) {
816 {
817 register int L; 805 register int L;
818 806
819 cr_r = 0*768+256 + colortab[ *cr + 0*256 ]; 807 cr_r = 0 * 768 + 256 + colortab[*cr + 0 * 256];
820 crb_g = 1*768+256 + colortab[ *cr + 1*256 ] 808 crb_g = 1 * 768 + 256 + colortab[*cr + 1 * 256]
821 + colortab[ *cb + 2*256 ]; 809 + colortab[*cb + 2 * 256];
822 cb_b = 2*768+256 + colortab[ *cb + 3*256 ]; 810 cb_b = 2 * 768 + 256 + colortab[*cb + 3 * 256];
823 cr += 4; cb += 4; 811 cr += 4;
824 812 cb += 4;
825 L = *lum; lum += 2; 813
826 value = (rgb_2_pix[ L + cr_r ] | 814 L = *lum;
827 rgb_2_pix[ L + crb_g ] | 815 lum += 2;
828 rgb_2_pix[ L + cb_b ]); 816 value = (rgb_2_pix[L + cr_r] |
829 row[0+0] = row[3+0] = row[next_row+0] = row[next_row+3+0] = 817 rgb_2_pix[L + crb_g] | rgb_2_pix[L + cb_b]);
830 (value ) & 0xFF; 818 row[0 + 0] = row[3 + 0] = row[next_row + 0] =
831 row[0+1] = row[3+1] = row[next_row+1] = row[next_row+3+1] = 819 row[next_row + 3 + 0] = (value) & 0xFF;
832 (value >> 8) & 0xFF; 820 row[0 + 1] = row[3 + 1] = row[next_row + 1] =
833 row[0+2] = row[3+2] = row[next_row+2] = row[next_row+3+2] = 821 row[next_row + 3 + 1] = (value >> 8) & 0xFF;
834 (value >> 16) & 0xFF; 822 row[0 + 2] = row[3 + 2] = row[next_row + 2] =
835 row += 2*3; 823 row[next_row + 3 + 2] = (value >> 16) & 0xFF;
836 824 row += 2 * 3;
837 L = *lum; lum += 2; 825
838 value = (rgb_2_pix[ L + cr_r ] | 826 L = *lum;
839 rgb_2_pix[ L + crb_g ] | 827 lum += 2;
840 rgb_2_pix[ L + cb_b ]); 828 value = (rgb_2_pix[L + cr_r] |
841 row[0+0] = row[3+0] = row[next_row+0] = row[next_row+3+0] = 829 rgb_2_pix[L + crb_g] | rgb_2_pix[L + cb_b]);
842 (value ) & 0xFF; 830 row[0 + 0] = row[3 + 0] = row[next_row + 0] =
843 row[0+1] = row[3+1] = row[next_row+1] = row[next_row+3+1] = 831 row[next_row + 3 + 0] = (value) & 0xFF;
844 (value >> 8) & 0xFF; 832 row[0 + 1] = row[3 + 1] = row[next_row + 1] =
845 row[0+2] = row[3+2] = row[next_row+2] = row[next_row+3+2] = 833 row[next_row + 3 + 1] = (value >> 8) & 0xFF;
846 (value >> 16) & 0xFF; 834 row[0 + 2] = row[3 + 2] = row[next_row + 2] =
847 row += 2*3; 835 row[next_row + 3 + 2] = (value >> 16) & 0xFF;
836 row += 2 * 3;
848 837
849 } 838 }
850 row += next_row; 839 row += next_row;
851 } 840 }
852 } 841 }
853 842
854 static void Color32DitherYUY2Mod2X( int *colortab, Uint32 *rgb_2_pix, 843 static void
855 unsigned char *lum, unsigned char *cr, 844 Color32DitherYUY2Mod2X (int *colortab, Uint32 * rgb_2_pix,
856 unsigned char *cb, unsigned char *out, 845 unsigned char *lum, unsigned char *cr,
857 int rows, int cols, int mod ) 846 unsigned char *cb, unsigned char *out,
858 { 847 int rows, int cols, int mod)
859 unsigned int* row = (unsigned int*) out; 848 {
860 const int next_row = cols*2+mod; 849 unsigned int *row = (unsigned int *) out;
850 const int next_row = cols * 2 + mod;
861 int x, y; 851 int x, y;
862 int cr_r; 852 int cr_r;
863 int crb_g; 853 int crb_g;
864 int cb_b; 854 int cb_b;
865 int cols_2 = cols / 2; 855 int cols_2 = cols / 2;
866 mod+=mod; 856 mod += mod;
867 y = rows; 857 y = rows;
868 while( y-- ) 858 while (y--) {
869 {
870 x = cols_2; 859 x = cols_2;
871 while( x-- ) 860 while (x--) {
872 {
873 register int L; 861 register int L;
874 862
875 cr_r = 0*768+256 + colortab[ *cr + 0*256 ]; 863 cr_r = 0 * 768 + 256 + colortab[*cr + 0 * 256];
876 crb_g = 1*768+256 + colortab[ *cr + 1*256 ] 864 crb_g = 1 * 768 + 256 + colortab[*cr + 1 * 256]
877 + colortab[ *cb + 2*256 ]; 865 + colortab[*cb + 2 * 256];
878 cb_b = 2*768+256 + colortab[ *cb + 3*256 ]; 866 cb_b = 2 * 768 + 256 + colortab[*cb + 3 * 256];
879 cr += 4; cb += 4; 867 cr += 4;
880 868 cb += 4;
881 L = *lum; lum += 2; 869
882 row[0] = row[1] = row[next_row] = row[next_row+1] = 870 L = *lum;
883 (rgb_2_pix[ L + cr_r ] | 871 lum += 2;
884 rgb_2_pix[ L + crb_g ] | 872 row[0] = row[1] = row[next_row] = row[next_row + 1] =
885 rgb_2_pix[ L + cb_b ]); 873 (rgb_2_pix[L + cr_r] |
874 rgb_2_pix[L + crb_g] | rgb_2_pix[L + cb_b]);
886 row += 2; 875 row += 2;
887 876
888 L = *lum; lum += 2; 877 L = *lum;
889 row[0] = row[1] = row[next_row] = row[next_row+1] = 878 lum += 2;
890 (rgb_2_pix[ L + cr_r ] | 879 row[0] = row[1] = row[next_row] = row[next_row + 1] =
891 rgb_2_pix[ L + crb_g ] | 880 (rgb_2_pix[L + cr_r] |
892 rgb_2_pix[ L + cb_b ]); 881 rgb_2_pix[L + crb_g] | rgb_2_pix[L + cb_b]);
893 row += 2; 882 row += 2;
894 883
895 884
896 } 885 }
897 886
901 890
902 /* 891 /*
903 * How many 1 bits are there in the Uint32. 892 * How many 1 bits are there in the Uint32.
904 * Low performance, do not call often. 893 * Low performance, do not call often.
905 */ 894 */
906 static int number_of_bits_set( Uint32 a ) 895 static int
907 { 896 number_of_bits_set (Uint32 a)
908 if(!a) return 0; 897 {
909 if(a & 1) return 1 + number_of_bits_set(a >> 1); 898 if (!a)
910 return(number_of_bits_set(a >> 1)); 899 return 0;
900 if (a & 1)
901 return 1 + number_of_bits_set (a >> 1);
902 return (number_of_bits_set (a >> 1));
911 } 903 }
912 904
913 /* 905 /*
914 * How many 0 bits are there at least significant end of Uint32. 906 * How many 0 bits are there at least significant end of Uint32.
915 * Low performance, do not call often. 907 * Low performance, do not call often.
916 */ 908 */
917 static int free_bits_at_bottom( Uint32 a ) 909 static int
918 { 910 free_bits_at_bottom (Uint32 a)
919 /* assume char is 8 bits */ 911 {
920 if(!a) return sizeof(Uint32) * 8; 912 /* assume char is 8 bits */
921 if(((Sint32)a) & 1l) return 0; 913 if (!a)
922 return 1 + free_bits_at_bottom ( a >> 1); 914 return sizeof (Uint32) * 8;
923 } 915 if (((Sint32) a) & 1l)
924 916 return 0;
925 917 return 1 + free_bits_at_bottom (a >> 1);
926 SDL_Overlay *SDL_CreateYUV_SW(_THIS, int width, int height, Uint32 format, SDL_Surface *display) 918 }
927 { 919
928 SDL_Overlay *overlay; 920
929 struct private_yuvhwdata *swdata; 921 SDL_Overlay *
930 int *Cr_r_tab; 922 SDL_CreateYUV_SW (_THIS, int width, int height, Uint32 format,
931 int *Cr_g_tab; 923 SDL_Surface * display)
932 int *Cb_g_tab; 924 {
933 int *Cb_b_tab; 925 SDL_Overlay *overlay;
934 Uint32 *r_2_pix_alloc; 926 struct private_yuvhwdata *swdata;
935 Uint32 *g_2_pix_alloc; 927 int *Cr_r_tab;
936 Uint32 *b_2_pix_alloc; 928 int *Cr_g_tab;
937 int i; 929 int *Cb_g_tab;
938 int CR, CB; 930 int *Cb_b_tab;
939 Uint32 Rmask, Gmask, Bmask; 931 Uint32 *r_2_pix_alloc;
940 932 Uint32 *g_2_pix_alloc;
941 /* Only RGB packed pixel conversion supported */ 933 Uint32 *b_2_pix_alloc;
942 if ( (display->format->BytesPerPixel != 2) && 934 int i;
943 (display->format->BytesPerPixel != 3) && 935 int CR, CB;
944 (display->format->BytesPerPixel != 4) ) { 936 Uint32 Rmask, Gmask, Bmask;
945 SDL_SetError("Can't use YUV data on non 16/24/32 bit surfaces"); 937
946 return(NULL); 938 /* Only RGB packed pixel conversion supported */
947 } 939 if ((display->format->BytesPerPixel != 2) &&
948 940 (display->format->BytesPerPixel != 3) &&
949 /* Verify that we support the format */ 941 (display->format->BytesPerPixel != 4)) {
950 switch (format) { 942 SDL_SetError ("Can't use YUV data on non 16/24/32 bit surfaces");
951 case SDL_YV12_OVERLAY: 943 return (NULL);
952 case SDL_IYUV_OVERLAY: 944 }
953 case SDL_YUY2_OVERLAY: 945
954 case SDL_UYVY_OVERLAY: 946 /* Verify that we support the format */
955 case SDL_YVYU_OVERLAY: 947 switch (format) {
956 break; 948 case SDL_YV12_OVERLAY:
957 default: 949 case SDL_IYUV_OVERLAY:
958 SDL_SetError("Unsupported YUV format"); 950 case SDL_YUY2_OVERLAY:
959 return(NULL); 951 case SDL_UYVY_OVERLAY:
960 } 952 case SDL_YVYU_OVERLAY:
961 953 break;
962 /* Create the overlay structure */ 954 default:
963 overlay = (SDL_Overlay *)SDL_malloc(sizeof *overlay); 955 SDL_SetError ("Unsupported YUV format");
964 if ( overlay == NULL ) { 956 return (NULL);
965 SDL_OutOfMemory(); 957 }
966 return(NULL); 958
967 } 959 /* Create the overlay structure */
968 SDL_memset(overlay, 0, (sizeof *overlay)); 960 overlay = (SDL_Overlay *) SDL_malloc (sizeof *overlay);
969 961 if (overlay == NULL) {
970 /* Fill in the basic members */ 962 SDL_OutOfMemory ();
971 overlay->format = format; 963 return (NULL);
972 overlay->w = width; 964 }
973 overlay->h = height; 965 SDL_memset (overlay, 0, (sizeof *overlay));
974 966
975 /* Set up the YUV surface function structure */ 967 /* Fill in the basic members */
976 overlay->hwfuncs = &sw_yuvfuncs; 968 overlay->format = format;
977 969 overlay->w = width;
978 /* Create the pixel data and lookup tables */ 970 overlay->h = height;
979 swdata = (struct private_yuvhwdata *)SDL_malloc(sizeof *swdata); 971
980 overlay->hwdata = swdata; 972 /* Set up the YUV surface function structure */
981 if ( swdata == NULL ) { 973 overlay->hwfuncs = &sw_yuvfuncs;
982 SDL_OutOfMemory(); 974
983 SDL_FreeYUVOverlay(overlay); 975 /* Create the pixel data and lookup tables */
984 return(NULL); 976 swdata = (struct private_yuvhwdata *) SDL_malloc (sizeof *swdata);
985 } 977 overlay->hwdata = swdata;
986 swdata->stretch = NULL; 978 if (swdata == NULL) {
987 swdata->display = display; 979 SDL_OutOfMemory ();
988 swdata->pixels = (Uint8 *) SDL_malloc(width*height*2); 980 SDL_FreeYUVOverlay (overlay);
989 swdata->colortab = (int *)SDL_malloc(4*256*sizeof(int)); 981 return (NULL);
990 Cr_r_tab = &swdata->colortab[0*256]; 982 }
991 Cr_g_tab = &swdata->colortab[1*256]; 983 swdata->stretch = NULL;
992 Cb_g_tab = &swdata->colortab[2*256]; 984 swdata->display = display;
993 Cb_b_tab = &swdata->colortab[3*256]; 985 swdata->pixels = (Uint8 *) SDL_malloc (width * height * 2);
994 swdata->rgb_2_pix = (Uint32 *)SDL_malloc(3*768*sizeof(Uint32)); 986 swdata->colortab = (int *) SDL_malloc (4 * 256 * sizeof (int));
995 r_2_pix_alloc = &swdata->rgb_2_pix[0*768]; 987 Cr_r_tab = &swdata->colortab[0 * 256];
996 g_2_pix_alloc = &swdata->rgb_2_pix[1*768]; 988 Cr_g_tab = &swdata->colortab[1 * 256];
997 b_2_pix_alloc = &swdata->rgb_2_pix[2*768]; 989 Cb_g_tab = &swdata->colortab[2 * 256];
998 if ( ! swdata->pixels || ! swdata->colortab || ! swdata->rgb_2_pix ) { 990 Cb_b_tab = &swdata->colortab[3 * 256];
999 SDL_OutOfMemory(); 991 swdata->rgb_2_pix = (Uint32 *) SDL_malloc (3 * 768 * sizeof (Uint32));
1000 SDL_FreeYUVOverlay(overlay); 992 r_2_pix_alloc = &swdata->rgb_2_pix[0 * 768];
1001 return(NULL); 993 g_2_pix_alloc = &swdata->rgb_2_pix[1 * 768];
1002 } 994 b_2_pix_alloc = &swdata->rgb_2_pix[2 * 768];
1003 995 if (!swdata->pixels || !swdata->colortab || !swdata->rgb_2_pix) {
1004 /* Generate the tables for the display surface */ 996 SDL_OutOfMemory ();
1005 for (i=0; i<256; i++) { 997 SDL_FreeYUVOverlay (overlay);
1006 /* Gamma correction (luminescence table) and chroma correction 998 return (NULL);
1007 would be done here. See the Berkeley mpeg_play sources. 999 }
1008 */ 1000
1009 CB = CR = (i-128); 1001 /* Generate the tables for the display surface */
1010 Cr_r_tab[i] = (int) ( (0.419/0.299) * CR); 1002 for (i = 0; i < 256; i++) {
1011 Cr_g_tab[i] = (int) (-(0.299/0.419) * CR); 1003 /* Gamma correction (luminescence table) and chroma correction
1012 Cb_g_tab[i] = (int) (-(0.114/0.331) * CB); 1004 would be done here. See the Berkeley mpeg_play sources.
1013 Cb_b_tab[i] = (int) ( (0.587/0.331) * CB); 1005 */
1014 } 1006 CB = CR = (i - 128);
1015 1007 Cr_r_tab[i] = (int) ((0.419 / 0.299) * CR);
1016 /* 1008 Cr_g_tab[i] = (int) (-(0.299 / 0.419) * CR);
1017 * Set up entries 0-255 in rgb-to-pixel value tables. 1009 Cb_g_tab[i] = (int) (-(0.114 / 0.331) * CB);
1018 */ 1010 Cb_b_tab[i] = (int) ((0.587 / 0.331) * CB);
1019 Rmask = display->format->Rmask; 1011 }
1020 Gmask = display->format->Gmask; 1012
1021 Bmask = display->format->Bmask; 1013 /*
1022 for ( i=0; i<256; ++i ) { 1014 * Set up entries 0-255 in rgb-to-pixel value tables.
1023 r_2_pix_alloc[i+256] = i >> (8 - number_of_bits_set(Rmask)); 1015 */
1024 r_2_pix_alloc[i+256] <<= free_bits_at_bottom(Rmask); 1016 Rmask = display->format->Rmask;
1025 g_2_pix_alloc[i+256] = i >> (8 - number_of_bits_set(Gmask)); 1017 Gmask = display->format->Gmask;
1026 g_2_pix_alloc[i+256] <<= free_bits_at_bottom(Gmask); 1018 Bmask = display->format->Bmask;
1027 b_2_pix_alloc[i+256] = i >> (8 - number_of_bits_set(Bmask)); 1019 for (i = 0; i < 256; ++i) {
1028 b_2_pix_alloc[i+256] <<= free_bits_at_bottom(Bmask); 1020 r_2_pix_alloc[i + 256] = i >> (8 - number_of_bits_set (Rmask));
1029 } 1021 r_2_pix_alloc[i + 256] <<= free_bits_at_bottom (Rmask);
1030 1022 g_2_pix_alloc[i + 256] = i >> (8 - number_of_bits_set (Gmask));
1031 /* 1023 g_2_pix_alloc[i + 256] <<= free_bits_at_bottom (Gmask);
1032 * If we have 16-bit output depth, then we double the value 1024 b_2_pix_alloc[i + 256] = i >> (8 - number_of_bits_set (Bmask));
1033 * in the top word. This means that we can write out both 1025 b_2_pix_alloc[i + 256] <<= free_bits_at_bottom (Bmask);
1034 * pixels in the pixel doubling mode with one op. It is 1026 }
1035 * harmless in the normal case as storing a 32-bit value 1027
1036 * through a short pointer will lose the top bits anyway. 1028 /*
1037 */ 1029 * If we have 16-bit output depth, then we double the value
1038 if( display->format->BytesPerPixel == 2 ) { 1030 * in the top word. This means that we can write out both
1039 for ( i=0; i<256; ++i ) { 1031 * pixels in the pixel doubling mode with one op. It is
1040 r_2_pix_alloc[i+256] |= (r_2_pix_alloc[i+256]) << 16; 1032 * harmless in the normal case as storing a 32-bit value
1041 g_2_pix_alloc[i+256] |= (g_2_pix_alloc[i+256]) << 16; 1033 * through a short pointer will lose the top bits anyway.
1042 b_2_pix_alloc[i+256] |= (b_2_pix_alloc[i+256]) << 16; 1034 */
1043 } 1035 if (display->format->BytesPerPixel == 2) {
1044 } 1036 for (i = 0; i < 256; ++i) {
1045 1037 r_2_pix_alloc[i + 256] |= (r_2_pix_alloc[i + 256]) << 16;
1046 /* 1038 g_2_pix_alloc[i + 256] |= (g_2_pix_alloc[i + 256]) << 16;
1047 * Spread out the values we have to the rest of the array so that 1039 b_2_pix_alloc[i + 256] |= (b_2_pix_alloc[i + 256]) << 16;
1048 * we do not need to check for overflow. 1040 }
1049 */ 1041 }
1050 for ( i=0; i<256; ++i ) { 1042
1051 r_2_pix_alloc[i] = r_2_pix_alloc[256]; 1043 /*
1052 r_2_pix_alloc[i+512] = r_2_pix_alloc[511]; 1044 * Spread out the values we have to the rest of the array so that
1053 g_2_pix_alloc[i] = g_2_pix_alloc[256]; 1045 * we do not need to check for overflow.
1054 g_2_pix_alloc[i+512] = g_2_pix_alloc[511]; 1046 */
1055 b_2_pix_alloc[i] = b_2_pix_alloc[256]; 1047 for (i = 0; i < 256; ++i) {
1056 b_2_pix_alloc[i+512] = b_2_pix_alloc[511]; 1048 r_2_pix_alloc[i] = r_2_pix_alloc[256];
1057 } 1049 r_2_pix_alloc[i + 512] = r_2_pix_alloc[511];
1058 1050 g_2_pix_alloc[i] = g_2_pix_alloc[256];
1059 /* You have chosen wisely... */ 1051 g_2_pix_alloc[i + 512] = g_2_pix_alloc[511];
1060 switch (format) { 1052 b_2_pix_alloc[i] = b_2_pix_alloc[256];
1061 case SDL_YV12_OVERLAY: 1053 b_2_pix_alloc[i + 512] = b_2_pix_alloc[511];
1062 case SDL_IYUV_OVERLAY: 1054 }
1063 if ( display->format->BytesPerPixel == 2 ) { 1055
1064 #if 0 /*defined(__GNUC__) && defined(__i386__) && SDL_ASSEMBLY_ROUTINES*/ 1056 /* You have chosen wisely... */
1065 /* inline assembly functions */ 1057 switch (format) {
1066 if ( SDL_HasMMX() && (Rmask == 0xF800) && 1058 case SDL_YV12_OVERLAY:
1067 (Gmask == 0x07E0) && 1059 case SDL_IYUV_OVERLAY:
1068 (Bmask == 0x001F) && 1060 if (display->format->BytesPerPixel == 2) {
1069 (width & 15) == 0) { 1061 #if 0 /*defined(__GNUC__) && defined(__i386__) && SDL_ASSEMBLY_ROUTINES */
1062 /* inline assembly functions */
1063 if (SDL_HasMMX () && (Rmask == 0xF800) &&
1064 (Gmask == 0x07E0) && (Bmask == 0x001F) && (width & 15) == 0) {
1070 /*printf("Using MMX 16-bit 565 dither\n");*/ 1065 /*printf("Using MMX 16-bit 565 dither\n");*/
1071 swdata->Display1X = Color565DitherYV12MMX1X; 1066 swdata->Display1X = Color565DitherYV12MMX1X;
1072 } else { 1067 } else {
1073 /*printf("Using C 16-bit dither\n");*/ 1068 /*printf("Using C 16-bit dither\n");*/
1074 swdata->Display1X = Color16DitherYV12Mod1X; 1069 swdata->Display1X = Color16DitherYV12Mod1X;
1075 } 1070 }
1076 #else 1071 #else
1077 swdata->Display1X = Color16DitherYV12Mod1X; 1072 swdata->Display1X = Color16DitherYV12Mod1X;
1078 #endif 1073 #endif
1079 swdata->Display2X = Color16DitherYV12Mod2X; 1074 swdata->Display2X = Color16DitherYV12Mod2X;
1080 } 1075 }
1081 if ( display->format->BytesPerPixel == 3 ) { 1076 if (display->format->BytesPerPixel == 3) {
1082 swdata->Display1X = Color24DitherYV12Mod1X; 1077 swdata->Display1X = Color24DitherYV12Mod1X;
1083 swdata->Display2X = Color24DitherYV12Mod2X; 1078 swdata->Display2X = Color24DitherYV12Mod2X;
1084 } 1079 }
1085 if ( display->format->BytesPerPixel == 4 ) { 1080 if (display->format->BytesPerPixel == 4) {
1086 #if 0 /*defined(__GNUC__) && defined(__i386__) && SDL_ASSEMBLY_ROUTINES*/ 1081 #if 0 /*defined(__GNUC__) && defined(__i386__) && SDL_ASSEMBLY_ROUTINES */
1087 /* inline assembly functions */ 1082 /* inline assembly functions */
1088 if ( SDL_HasMMX() && (Rmask == 0x00FF0000) && 1083 if (SDL_HasMMX () && (Rmask == 0x00FF0000) &&
1089 (Gmask == 0x0000FF00) && 1084 (Gmask == 0x0000FF00) &&
1090 (Bmask == 0x000000FF) && 1085 (Bmask == 0x000000FF) && (width & 15) == 0) {
1091 (width & 15) == 0) {
1092 /*printf("Using MMX 32-bit dither\n");*/ 1086 /*printf("Using MMX 32-bit dither\n");*/
1093 swdata->Display1X = ColorRGBDitherYV12MMX1X; 1087 swdata->Display1X = ColorRGBDitherYV12MMX1X;
1094 } else { 1088 } else {
1095 /*printf("Using C 32-bit dither\n");*/ 1089 /*printf("Using C 32-bit dither\n");*/
1096 swdata->Display1X = Color32DitherYV12Mod1X; 1090 swdata->Display1X = Color32DitherYV12Mod1X;
1097 } 1091 }
1098 #else 1092 #else
1099 swdata->Display1X = Color32DitherYV12Mod1X; 1093 swdata->Display1X = Color32DitherYV12Mod1X;
1100 #endif 1094 #endif
1101 swdata->Display2X = Color32DitherYV12Mod2X; 1095 swdata->Display2X = Color32DitherYV12Mod2X;
1102 } 1096 }
1103 break; 1097 break;
1104 case SDL_YUY2_OVERLAY: 1098 case SDL_YUY2_OVERLAY:
1105 case SDL_UYVY_OVERLAY: 1099 case SDL_UYVY_OVERLAY:
1106 case SDL_YVYU_OVERLAY: 1100 case SDL_YVYU_OVERLAY:
1107 if ( display->format->BytesPerPixel == 2 ) { 1101 if (display->format->BytesPerPixel == 2) {
1108 swdata->Display1X = Color16DitherYUY2Mod1X; 1102 swdata->Display1X = Color16DitherYUY2Mod1X;
1109 swdata->Display2X = Color16DitherYUY2Mod2X; 1103 swdata->Display2X = Color16DitherYUY2Mod2X;
1110 } 1104 }
1111 if ( display->format->BytesPerPixel == 3 ) { 1105 if (display->format->BytesPerPixel == 3) {
1112 swdata->Display1X = Color24DitherYUY2Mod1X; 1106 swdata->Display1X = Color24DitherYUY2Mod1X;
1113 swdata->Display2X = Color24DitherYUY2Mod2X; 1107 swdata->Display2X = Color24DitherYUY2Mod2X;
1114 } 1108 }
1115 if ( display->format->BytesPerPixel == 4 ) { 1109 if (display->format->BytesPerPixel == 4) {
1116 swdata->Display1X = Color32DitherYUY2Mod1X; 1110 swdata->Display1X = Color32DitherYUY2Mod1X;
1117 swdata->Display2X = Color32DitherYUY2Mod2X; 1111 swdata->Display2X = Color32DitherYUY2Mod2X;
1118 } 1112 }
1119 break; 1113 break;
1120 default: 1114 default:
1121 /* We should never get here (caught above) */ 1115 /* We should never get here (caught above) */
1122 break; 1116 break;
1123 } 1117 }
1124 1118
1125 /* Find the pitch and offset values for the overlay */ 1119 /* Find the pitch and offset values for the overlay */
1126 overlay->pitches = swdata->pitches; 1120 overlay->pitches = swdata->pitches;
1127 overlay->pixels = swdata->planes; 1121 overlay->pixels = swdata->planes;
1128 switch (format) { 1122 switch (format) {
1129 case SDL_YV12_OVERLAY: 1123 case SDL_YV12_OVERLAY:
1130 case SDL_IYUV_OVERLAY: 1124 case SDL_IYUV_OVERLAY:
1131 overlay->pitches[0] = overlay->w; 1125 overlay->pitches[0] = overlay->w;
1132 overlay->pitches[1] = overlay->pitches[0] / 2; 1126 overlay->pitches[1] = overlay->pitches[0] / 2;
1133 overlay->pitches[2] = overlay->pitches[0] / 2; 1127 overlay->pitches[2] = overlay->pitches[0] / 2;
1134 overlay->pixels[0] = swdata->pixels; 1128 overlay->pixels[0] = swdata->pixels;
1135 overlay->pixels[1] = overlay->pixels[0] + 1129 overlay->pixels[1] = overlay->pixels[0] +
1136 overlay->pitches[0] * overlay->h; 1130 overlay->pitches[0] * overlay->h;
1137 overlay->pixels[2] = overlay->pixels[1] + 1131 overlay->pixels[2] = overlay->pixels[1] +
1138 overlay->pitches[1] * overlay->h / 2; 1132 overlay->pitches[1] * overlay->h / 2;
1139 overlay->planes = 3; 1133 overlay->planes = 3;
1140 break; 1134 break;
1141 case SDL_YUY2_OVERLAY: 1135 case SDL_YUY2_OVERLAY:
1142 case SDL_UYVY_OVERLAY: 1136 case SDL_UYVY_OVERLAY:
1143 case SDL_YVYU_OVERLAY: 1137 case SDL_YVYU_OVERLAY:
1144 overlay->pitches[0] = overlay->w*2; 1138 overlay->pitches[0] = overlay->w * 2;
1145 overlay->pixels[0] = swdata->pixels; 1139 overlay->pixels[0] = swdata->pixels;
1146 overlay->planes = 1; 1140 overlay->planes = 1;
1147 break; 1141 break;
1148 default: 1142 default:
1149 /* We should never get here (caught above) */ 1143 /* We should never get here (caught above) */
1150 break; 1144 break;
1151 } 1145 }
1152 1146
1153 /* We're all done.. */ 1147 /* We're all done.. */
1154 return(overlay); 1148 return (overlay);
1155 } 1149 }
1156 1150
1157 int SDL_LockYUV_SW(_THIS, SDL_Overlay *overlay) 1151 int
1158 { 1152 SDL_LockYUV_SW (_THIS, SDL_Overlay * overlay)
1159 return(0); 1153 {
1160 } 1154 return (0);
1161 1155 }
1162 void SDL_UnlockYUV_SW(_THIS, SDL_Overlay *overlay) 1156
1163 { 1157 void
1164 return; 1158 SDL_UnlockYUV_SW (_THIS, SDL_Overlay * overlay)
1165 } 1159 {
1166 1160 return;
1167 int SDL_DisplayYUV_SW(_THIS, SDL_Overlay *overlay, SDL_Rect *src, SDL_Rect *dst) 1161 }
1168 { 1162
1169 struct private_yuvhwdata *swdata; 1163 int
1170 int stretch; 1164 SDL_DisplayYUV_SW (_THIS, SDL_Overlay * overlay, SDL_Rect * src,
1171 int scale_2x; 1165 SDL_Rect * dst)
1172 SDL_Surface *display; 1166 {
1173 Uint8 *lum, *Cr, *Cb; 1167 struct private_yuvhwdata *swdata;
1174 Uint8 *dstp; 1168 int stretch;
1175 int mod; 1169 int scale_2x;
1176 1170 SDL_Surface *display;
1177 swdata = overlay->hwdata; 1171 Uint8 *lum, *Cr, *Cb;
1178 stretch = 0; 1172 Uint8 *dstp;
1179 scale_2x = 0; 1173 int mod;
1180 if ( src->x || src->y || src->w < overlay->w || src->h < overlay->h ) { 1174
1181 /* The source rectangle has been clipped. 1175 swdata = overlay->hwdata;
1182 Using a scratch surface is easier than adding clipped 1176 stretch = 0;
1183 source support to all the blitters, plus that would 1177 scale_2x = 0;
1184 slow them down in the general unclipped case. 1178 if (src->x || src->y || src->w < overlay->w || src->h < overlay->h) {
1185 */ 1179 /* The source rectangle has been clipped.
1186 stretch = 1; 1180 Using a scratch surface is easier than adding clipped
1187 } else if ( (src->w != dst->w) || (src->h != dst->h) ) { 1181 source support to all the blitters, plus that would
1188 if ( (dst->w == 2*src->w) && 1182 slow them down in the general unclipped case.
1189 (dst->h == 2*src->h) ) { 1183 */
1190 scale_2x = 1; 1184 stretch = 1;
1191 } else { 1185 } else if ((src->w != dst->w) || (src->h != dst->h)) {
1192 stretch = 1; 1186 if ((dst->w == 2 * src->w) && (dst->h == 2 * src->h)) {
1193 } 1187 scale_2x = 1;
1194 } 1188 } else {
1195 if ( stretch ) { 1189 stretch = 1;
1196 if ( ! swdata->stretch ) { 1190 }
1197 display = swdata->display; 1191 }
1198 swdata->stretch = SDL_CreateRGBSurface( 1192 if (stretch) {
1199 SDL_SWSURFACE, 1193 if (!swdata->stretch) {
1200 overlay->w, overlay->h, 1194 display = swdata->display;
1201 display->format->BitsPerPixel, 1195 swdata->stretch = SDL_CreateRGBSurface (SDL_SWSURFACE,
1202 display->format->Rmask, 1196 overlay->w,
1203 display->format->Gmask, 1197 overlay->h,
1204 display->format->Bmask, 0); 1198 display->format->
1205 if ( ! swdata->stretch ) { 1199 BitsPerPixel,
1206 return(-1); 1200 display->format->
1207 } 1201 Rmask,
1208 } 1202 display->format->
1209 display = swdata->stretch; 1203 Gmask,
1210 } else { 1204 display->format->
1211 display = swdata->display; 1205 Bmask, 0);
1212 } 1206 if (!swdata->stretch) {
1213 switch (overlay->format) { 1207 return (-1);
1214 case SDL_YV12_OVERLAY: 1208 }
1215 lum = overlay->pixels[0]; 1209 }
1216 Cr = overlay->pixels[1]; 1210 display = swdata->stretch;
1217 Cb = overlay->pixels[2]; 1211 } else {
1218 break; 1212 display = swdata->display;
1219 case SDL_IYUV_OVERLAY: 1213 }
1220 lum = overlay->pixels[0]; 1214 switch (overlay->format) {
1221 Cr = overlay->pixels[2]; 1215 case SDL_YV12_OVERLAY:
1222 Cb = overlay->pixels[1]; 1216 lum = overlay->pixels[0];
1223 break; 1217 Cr = overlay->pixels[1];
1224 case SDL_YUY2_OVERLAY: 1218 Cb = overlay->pixels[2];
1225 lum = overlay->pixels[0]; 1219 break;
1226 Cr = lum + 3; 1220 case SDL_IYUV_OVERLAY:
1227 Cb = lum + 1; 1221 lum = overlay->pixels[0];
1228 break; 1222 Cr = overlay->pixels[2];
1229 case SDL_UYVY_OVERLAY: 1223 Cb = overlay->pixels[1];
1230 lum = overlay->pixels[0]+1; 1224 break;
1231 Cr = lum + 1; 1225 case SDL_YUY2_OVERLAY:
1232 Cb = lum - 1; 1226 lum = overlay->pixels[0];
1233 break; 1227 Cr = lum + 3;
1234 case SDL_YVYU_OVERLAY: 1228 Cb = lum + 1;
1235 lum = overlay->pixels[0]; 1229 break;
1236 Cr = lum + 1; 1230 case SDL_UYVY_OVERLAY:
1237 Cb = lum + 3; 1231 lum = overlay->pixels[0] + 1;
1238 break; 1232 Cr = lum + 1;
1239 default: 1233 Cb = lum - 1;
1240 SDL_SetError("Unsupported YUV format in blit"); 1234 break;
1241 return(-1); 1235 case SDL_YVYU_OVERLAY:
1242 } 1236 lum = overlay->pixels[0];
1243 if ( SDL_MUSTLOCK(display) ) { 1237 Cr = lum + 1;
1244 if ( SDL_LockSurface(display) < 0 ) { 1238 Cb = lum + 3;
1245 return(-1); 1239 break;
1246 } 1240 default:
1247 } 1241 SDL_SetError ("Unsupported YUV format in blit");
1248 if ( stretch ) { 1242 return (-1);
1249 dstp = (Uint8 *)swdata->stretch->pixels; 1243 }
1250 } else { 1244 if (SDL_MUSTLOCK (display)) {
1251 dstp = (Uint8 *)display->pixels 1245 if (SDL_LockSurface (display) < 0) {
1252 + dst->x * display->format->BytesPerPixel 1246 return (-1);
1253 + dst->y * display->pitch; 1247 }
1254 } 1248 }
1255 mod = (display->pitch / display->format->BytesPerPixel); 1249 if (stretch) {
1256 1250 dstp = (Uint8 *) swdata->stretch->pixels;
1257 if ( scale_2x ) { 1251 } else {
1258 mod -= (overlay->w * 2); 1252 dstp = (Uint8 *) display->pixels
1259 swdata->Display2X(swdata->colortab, swdata->rgb_2_pix, 1253 + dst->x * display->format->BytesPerPixel
1260 lum, Cr, Cb, dstp, overlay->h, overlay->w, mod); 1254 + dst->y * display->pitch;
1261 } else { 1255 }
1262 mod -= overlay->w; 1256 mod = (display->pitch / display->format->BytesPerPixel);
1263 swdata->Display1X(swdata->colortab, swdata->rgb_2_pix, 1257
1264 lum, Cr, Cb, dstp, overlay->h, overlay->w, mod); 1258 if (scale_2x) {
1265 } 1259 mod -= (overlay->w * 2);
1266 if ( SDL_MUSTLOCK(display) ) { 1260 swdata->Display2X (swdata->colortab, swdata->rgb_2_pix,
1267 SDL_UnlockSurface(display); 1261 lum, Cr, Cb, dstp, overlay->h, overlay->w, mod);
1268 } 1262 } else {
1269 if ( stretch ) { 1263 mod -= overlay->w;
1270 display = swdata->display; 1264 swdata->Display1X (swdata->colortab, swdata->rgb_2_pix,
1271 SDL_SoftStretch(swdata->stretch, src, display, dst); 1265 lum, Cr, Cb, dstp, overlay->h, overlay->w, mod);
1272 } 1266 }
1273 SDL_UpdateRects(display, 1, dst); 1267 if (SDL_MUSTLOCK (display)) {
1274 1268 SDL_UnlockSurface (display);
1275 return(0); 1269 }
1276 } 1270 if (stretch) {
1277 1271 display = swdata->display;
1278 void SDL_FreeYUV_SW(_THIS, SDL_Overlay *overlay) 1272 SDL_SoftStretch (swdata->stretch, src, display, dst);
1279 { 1273 }
1280 struct private_yuvhwdata *swdata; 1274 SDL_UpdateRects (display, 1, dst);
1281 1275
1282 swdata = overlay->hwdata; 1276 return (0);
1283 if ( swdata ) { 1277 }
1284 if ( swdata->stretch ) { 1278
1285 SDL_FreeSurface(swdata->stretch); 1279 void
1286 } 1280 SDL_FreeYUV_SW (_THIS, SDL_Overlay * overlay)
1287 if ( swdata->pixels ) { 1281 {
1288 SDL_free(swdata->pixels); 1282 struct private_yuvhwdata *swdata;
1289 } 1283
1290 if ( swdata->colortab ) { 1284 swdata = overlay->hwdata;
1291 SDL_free(swdata->colortab); 1285 if (swdata) {
1292 } 1286 if (swdata->stretch) {
1293 if ( swdata->rgb_2_pix ) { 1287 SDL_FreeSurface (swdata->stretch);
1294 SDL_free(swdata->rgb_2_pix); 1288 }
1295 } 1289 if (swdata->pixels) {
1296 SDL_free(swdata); 1290 SDL_free (swdata->pixels);
1297 } 1291 }
1298 } 1292 if (swdata->colortab) {
1293 SDL_free (swdata->colortab);
1294 }
1295 if (swdata->rgb_2_pix) {
1296 SDL_free (swdata->rgb_2_pix);
1297 }
1298 SDL_free (swdata);
1299 }
1300 }
1301
1302 /* vi: set ts=4 sw=4 expandtab: */