comparison dmblitfunc.h @ 95:0430f484641b

Add unscaled blitting functions.
author Matti Hamalainen <ccr@tnsp.org>
date Tue, 02 Oct 2012 18:51:16 +0300
parents e5796ffce131
children afa28947e400
comparison
equal deleted inserted replaced
94:4bbfc0274b29 95:0430f484641b
307 #endif 307 #endif
308 308
309 #include "dmscaledblit.h" 309 #include "dmscaledblit.h"
310 310
311 311
312 // ======================================================================= 312
313 // ======================================================================= 313 // =======================================================================
314 // =======================================================================
315
316
317
318 // =======================================================================
319 // DMD_NONE
320 // =======================================================================
321
322 #define DM_BLITFUNC_NAME dmUnscaledBlitSurface8to8
323 #define DM_BLITFUNC_SRC_BYTES 1
324 #define DM_BLITFUNC_DST_BYTES 1
325 #define DM_BLITFUNC_SRC_TYPE Uint8
326 #define DM_BLITFUNC_DST_TYPE Uint8
327
328 #define DM_BLITFUNC_INNER *dp++ = sp[xv];
329
330 #include "dmunscaledblit.h"
331
332 // -----------------------------------------------------------------------
333
334 #define DM_BLITFUNC_NAME dmUnscaledBlitSurface8to32
335 #define DM_BLITFUNC_SRC_BYTES 1
336 #define DM_BLITFUNC_DST_BYTES 4
337 #define DM_BLITFUNC_SRC_TYPE Uint8
338 #define DM_BLITFUNC_DST_TYPE Uint32
339
340 #define DM_BLITFUNC_VARS const Uint32 *pal;
341 #define DM_BLITFUNC_INIT \
342 if (src->format->palette == NULL || src->format->palette->ncolors < 256) return -2; \
343 pal = (Uint32 *) src->format->palette->colors;
344
345 #define DM_BLITFUNC_INNER *dp++ = pal[sp[xv]];
346
347 #include "dmunscaledblit.h"
348
349 // -----------------------------------------------------------------------
350
351 #define DM_BLITFUNC_NAME dmUnscaledBlitSurface32to32
352 #define DM_BLITFUNC_SRC_BYTES 4
353 #define DM_BLITFUNC_DST_BYTES 4
354 #define DM_BLITFUNC_SRC_TYPE Uint32
355 #define DM_BLITFUNC_DST_TYPE Uint32
356 #define DM_BLITFUNC_INIT
357 #define DM_BLITFUNC_INNER *dp++ = sp[xv];
358
359 #include "dmunscaledblit.h"
360
361
362 // =======================================================================
363 // DMD_TRANSPARENT
364 // =======================================================================
365
366 #define DM_BLITFUNC_NAME dmUnscaledBlitSurface8to8Transparent
367 #define DM_BLITFUNC_SRC_BYTES 1
368 #define DM_BLITFUNC_DST_BYTES 1
369 #define DM_BLITFUNC_SRC_TYPE Uint8
370 #define DM_BLITFUNC_DST_TYPE Uint8
371
372 #define DM_BLITFUNC_INNER \
373 *dp = sp[xv] ? sp[xv] : *dp; dp++;
374
375 #include "dmunscaledblit.h"
376
377 // -----------------------------------------------------------------------
378
379 #define DM_BLITFUNC_NAME dmUnscaledBlitSurface8to32Transparent
380 #define DM_BLITFUNC_SRC_BYTES 1
381 #define DM_BLITFUNC_DST_BYTES 4
382 #define DM_BLITFUNC_SRC_TYPE Uint8
383 #define DM_BLITFUNC_DST_TYPE DMRGBA32
384 #define DM_BLITFUNC_VARS const DMRGBA32 *pal;
385 #define DM_BLITFUNC_INIT \
386 if (src->format->palette == NULL || src->format->palette->ncolors < 256) return -2; \
387 pal = (DMRGBA32 *) src->format->palette->colors;
388
389 #define DM_BLITFUNC_INNER \
390 const DMRGBA32 q = pal[sp[xv]]; \
391 dp->r += ((q.r - dp->r) * q.a) >> 8; \
392 dp->g += ((q.g - dp->g) * q.a) >> 8; \
393 dp->b += ((q.b - dp->b) * q.a) >> 8; \
394 dp->a = q.a; \
395 dp++;
396
397 #include "dmunscaledblit.h"
398
399
400 // -----------------------------------------------------------------------
401
402 #define DM_BLITFUNC_NAME dmUnscaledBlitSurface32to32Transparent
403 #define DM_BLITFUNC_SRC_BYTES 4
404 #define DM_BLITFUNC_DST_BYTES 4
405
406 #ifdef DM_USE_SIMD
407 #define DM_BLITFUNC_VARS \
408 const Uint32 qpdmask = 0xff000000; \
409 const Uint64 qpdrm = 0xff00ff00ff00ffULL;
410
411 #define DM_BLITFUNC_SRC_TYPE Uint32
412 #define DM_BLITFUNC_DST_TYPE Uint32
413 #define DM_BLITFUNC_INNER \
414 asm( \
415 "movd %2, %%mm1\n" \
416 \
417 "movd %3, %%mm2\n" \
418 "movq %%mm1, %%mm5\n" \
419 "pand %%mm2, %%mm5\n" \
420 "psrlw $8, %%mm5\n" \
421 "punpcklwd %%mm5, %%mm5\n" \
422 "punpckhwd %%mm5, %%mm5\n" \
423 \
424 "pxor %%mm2, %%mm2\n" \
425 "movd %1, %%mm3\n" \
426 "punpcklbw %%mm2, %%mm1\n" \
427 "punpcklbw %%mm2, %%mm3\n" \
428 \
429 "psubw %%mm3, %%mm1\n" \
430 "pmullw %%mm5, %%mm1\n" \
431 "psraw $8, %%mm1\n" \
432 "paddw %%mm3, %%mm1\n" \
433 "pand %4, %%mm1\n" \
434 "packuswb %%mm2, %%mm1\n" \
435 "movd %%mm1, %0\n" \
436 : "=m" (*dp) \
437 : "m" (*dp), "m" (sp[xv]), "m" (qpdmask), "m" (qpdrm) \
438 : "memory", "%mm1", "%mm2", "%mm3", "%mm4", "%mm5" ); dp++;
439
440 #define DM_BLITFUNC_FINISH asm("emms\n");
441
442 #else
443
444 #define DM_BLITFUNC_SRC_TYPE DMRGBA32
445 #define DM_BLITFUNC_DST_TYPE DMRGBA32
446 #define DM_BLITFUNC_INNER \
447 const DMRGBA32 q = sp[xv]; \
448 dp->r += ((q.r - dp->r) * q.a) >> 8; \
449 dp->g += ((q.g - dp->g) * q.a) >> 8; \
450 dp->b += ((q.b - dp->b) * q.a) >> 8; \
451 dp->a = q.a; \
452 dp++;
453 #endif
454
455 #include "dmunscaledblit.h"
456
457
458 // =======================================================================
459 // DMD_SATURATE
460 // =======================================================================
461
462 #define DM_BLITFUNC_NAME dmUnscaledBlitSurface8to8Saturate
463 #define DM_BLITFUNC_SRC_BYTES 1
464 #define DM_BLITFUNC_DST_BYTES 1
465 #define DM_BLITFUNC_SRC_TYPE Uint8
466 #define DM_BLITFUNC_DST_TYPE Uint8
467 #define DM_BLITFUNC_INNER \
468 const int q = sp[xv] + *dp; \
469 *(dp++) = q < 256 ? q : 255;
470
471 #include "dmunscaledblit.h"
472
473 // -----------------------------------------------------------------------
474
475 #define DM_BLITFUNC_NAME dmUnscaledBlitSurface8to32Saturate
476 #define DM_BLITFUNC_SRC_BYTES 1
477 #define DM_BLITFUNC_DST_BYTES 4
478 #define DM_BLITFUNC_SRC_TYPE Uint8
479 #define DM_BLITFUNC_DST_TYPE DMRGBA32
480 #define DM_BLITFUNC_VARS const DMRGBA32 *pal;
481 #define DM_BLITFUNC_INIT \
482 if (src->format->palette == NULL || src->format->palette->ncolors < 256) return -2; \
483 pal = (DMRGBA32 *) src->format->palette->colors;
484
485 #ifdef DM_USE_SIMD
486 #define DM_BLITFUNC_INNER \
487 asm("movd %2, %%mm1\n" \
488 "movd %1, %%mm2\n" \
489 "paddusb %%mm2, %%mm1\n" \
490 "movd %%mm1, %0\n" \
491 : "=m" (*dp) \
492 : "m" (*dp), "m" (pal[sp[xv]]) \
493 : "memory", "%mm1", "%mm2" ); dp++;
494
495 #define DM_BLITFUNC_FINISH asm("emms\n");
496 #else
497 #define DM_BLITFUNC_INNER \
498 const DMRGBA32 q = pal[sp[xv]]; \
499 const int qr = dp->r + q.r, qg = dp->g + q.g, qb = dp->b + q.b; \
500 dp->r = qr < 256 ? qr : 255; \
501 dp->g = qg < 256 ? qg : 255; \
502 dp->b = qb < 256 ? qb : 255; \
503 dp->a = q.a; \
504 dp++;
505 #endif
506
507 #include "dmunscaledblit.h"
508
509 // -----------------------------------------------------------------------
510
511 #define DM_BLITFUNC_NAME dmUnscaledBlitSurface32to32Saturate
512 #define DM_BLITFUNC_SRC_BYTES 4
513 #define DM_BLITFUNC_DST_BYTES 4
514 #define DM_BLITFUNC_INIT
515
516 #ifdef DM_USE_SIMD
517 #define DM_BLITFUNC_SRC_TYPE Uint32
518 #define DM_BLITFUNC_DST_TYPE Uint32
519 #define DM_BLITFUNC_INNER \
520 asm("movd %2, %%mm1\n" \
521 "movd %1, %%mm2\n" \
522 "paddusb %%mm2, %%mm1\n" \
523 "movd %%mm1, %0\n" \
524 : "=m" (*dp) \
525 : "m" (*dp), "m" (sp[xv]) \
526 : "memory", "%mm1", "%mm2" ); dp++;
527
528 #define DM_BLITFUNC_FINISH asm("emms\n");
529 #else
530 #define DM_BLITFUNC_SRC_TYPE DMRGBA32
531 #define DM_BLITFUNC_DST_TYPE DMRGBA32
532 #define DM_BLITFUNC_INNER \
533 const DMRGBA32 q = sp[xv]; \
534 const int qr = dp->r + q.r, qg = dp->g + q.g, qb = dp->b + q.b; \
535 dp->r = qr < 256 ? qr : 255; \
536 dp->g = qg < 256 ? qg : 255; \
537 dp->b = qb < 256 ? qb : 255; \
538 dp->a = q.a; \
539 dp++;
540 #endif
541
542 #include "dmunscaledblit.h"
543
544
545 // =======================================================================