ManaPlus
Data Structures | Namespaces | Macros | Functions | Variables
sdlgfxblitfunc.cpp File Reference

(986a3bf)

#include "resources/sdlgfxblitfunc.h"
#include "utils/cast.h"
#include "utils/checkutils.h"
#include <SDL_video.h>
#include "debug.h"

Go to the source code of this file.

Data Structures

struct  anonymous_namespace{sdlgfxblitfunc.cpp}::SDL_gfxBlitInfo
 

Namespaces

 anonymous_namespace{sdlgfxblitfunc.cpp}
 

Macros

#define GFX_DUFFS_LOOP4(pixel_copy_increment, width)
 

Functions

static void _SDL_gfxBlitBlitterRGBA (const SDL_gfxBlitInfo *const info)
 
static int _SDL_gfxBlitRGBACall (const SDL_Surface *const src, const SDL_Rect *const srcrect, const SDL_Surface *const dst, const SDL_Rect *const dstrect)
 
int SDLgfxBlitRGBA (const SDL_Surface *const src, const SDL_Rect *const srcrect, SDL_Surface *const dst, const SDL_Rect *const dstrect)
 

Variables

unsigned int anonymous_namespace{sdlgfxblitfunc.cpp}::GFX_ALPHA_ADJUST_ARRAY [256]
 

Macro Definition Documentation

◆ GFX_DUFFS_LOOP4

#define GFX_DUFFS_LOOP4 (   pixel_copy_increment,
  width 
)
Value:
int n = ((width) + 3) / 4; \
switch ((width) & 3) \
{ \
case 0: do { \
pixel_copy_increment; \
case 3: pixel_copy_increment; \
case 2: pixel_copy_increment; \
case 1: pixel_copy_increment; \
default: ; \
} while (--n > 0 ); \
}

Definition at line 43 of file sdlgfxblitfunc.cpp.

Function Documentation

◆ _SDL_gfxBlitBlitterRGBA()

static void _SDL_gfxBlitBlitterRGBA ( const SDL_gfxBlitInfo *const  info)
static

Definition at line 337 of file sdlgfxblitfunc.cpp.

338 {
339  const int width = info->d_width;
340  int height = info->d_height;
341  Uint8 *src = info->s_pixels;
342  const int srcskip = info->s_skip;
343  Uint8 *dst = info->d_pixels;
344  const int dstskip = info->d_skip;
345  const SDL_PixelFormat *const srcfmt = info->src;
346 
347  while ((height--) != 0)
348  {
350  {
351  Uint32 pixel;
352  uint32_t sR;
353  uint32_t sG;
354  uint32_t sB;
355  uint32_t sA;
356  uint32_t dR;
357  uint32_t dG;
358  uint32_t dB;
359  uint32_t dA;
360  uint32_t sAA;
361 
362  pixel = *(reinterpret_cast<uint32_t *>(src));
363  sR = ((pixel & srcfmt->Rmask) >> srcfmt->Rshift);
364  sG = ((pixel & srcfmt->Gmask) >> srcfmt->Gshift);
365  sB = ((pixel & srcfmt->Bmask) >> srcfmt->Bshift);
366  sA = ((pixel & srcfmt->Amask) >> srcfmt->Ashift);
367 
368  pixel = *(reinterpret_cast<uint32_t *>(dst));
369  dR = pixel & 0xffU;
370  dG = ((pixel & 0xff00U) >> 8);
371  dB = ((pixel & 0xff0000U) >> 16);
372  dA = ((pixel & 0xff000000U) >> 24);
373 
374  sAA = GFX_ALPHA_ADJUST_ARRAY[sA & 255];
375  dR = (((sR - dR) * (sAA)) / 255) + dR;
376  dG = (((sG - dG) * (sAA)) / 255) + dG;
377  dB = (((sB - dB) * (sAA)) / 255) + dB;
378  dA |= sAA;
379 
380  *(reinterpret_cast<uint32_t *>(dst)) = dR |
381  (dG << 8) |
382  (dB << 16) |
383  (dA << 24);
384 
385  src += 4;
386  dst += 4;
387  }, width)
388  src += srcskip;
389  dst += dstskip;
390  }
391 }
bool info(InputEvent &event)
Definition: commands.cpp:57
#define GFX_DUFFS_LOOP4(pixel_copy_increment, width)

References anonymous_namespace{sdlgfxblitfunc.cpp}::GFX_ALPHA_ADJUST_ARRAY, GFX_DUFFS_LOOP4, and Actions::info().

Referenced by _SDL_gfxBlitRGBACall().

◆ _SDL_gfxBlitRGBACall()

static int _SDL_gfxBlitRGBACall ( const SDL_Surface *const  src,
const SDL_Rect *const  srcrect,
const SDL_Surface *const  dst,
const SDL_Rect *const  dstrect 
)
static

Definition at line 393 of file sdlgfxblitfunc.cpp.

397 {
398  /*
399  * Set up source and destination buffer pointers, then blit
400  */
401  if ((srcrect->w != 0U) && (srcrect->h != 0U))
402  {
403  SDL_gfxBlitInfo info;
404 
405  /*
406  * Set up the blit information
407  */
408  info.s_pixels = static_cast<Uint8 *>(src->pixels) + src->offset +
409  static_cast<Uint16>(srcrect->y) * src->pitch +
410  static_cast<Uint16>(srcrect->x) * src->format->BytesPerPixel;
411  info.s_width = srcrect->w;
412  info.s_height = srcrect->h;
413  info.s_skip = CAST_S32(src->pitch - info.s_width *
414  src->format->BytesPerPixel);
415  info.d_pixels = static_cast<Uint8 *>(dst->pixels) + dst->offset +
416  static_cast<Uint16>(dstrect->y) * dst->pitch +
417  static_cast<Uint16>(dstrect->x) * dst->format->BytesPerPixel;
418  info.d_width = dstrect->w;
419  info.d_height = dstrect->h;
420  info.d_skip = CAST_S32(dst->pitch - info.d_width *
421  dst->format->BytesPerPixel);
422  info.aux_data = nullptr;
423  info.src = src->format;
424  info.table = nullptr;
425  info.dst = dst->format;
426 
427  /*
428  * Run the actual software blitter
429  */
431  return 1;
432  }
433 
434  return 0;
435 }
#define CAST_S32
Definition: cast.h:30
static void _SDL_gfxBlitBlitterRGBA(const SDL_gfxBlitInfo *const info)

References _SDL_gfxBlitBlitterRGBA(), CAST_S32, and Actions::info().

Referenced by SDLgfxBlitRGBA().

◆ SDLgfxBlitRGBA()

int SDLgfxBlitRGBA ( const SDL_Surface *const  src,
const SDL_Rect *const  srcrect,
SDL_Surface *const  dst,
const SDL_Rect *const  dstrect 
)

Definition at line 437 of file sdlgfxblitfunc.cpp.

441 {
442  SDL_Rect sr;
443  SDL_Rect dr;
444  int srcx;
445  int srcy;
446  int w;
447  int h;
448 
449  /*
450  * Make sure the surfaces aren't locked
451  */
452  if (src == nullptr ||
453  dst == nullptr)
454  {
455  reportAlways("SDLgfxBlitRGBA: passed a NULL surface")
456  return -1;
457  }
458 
459  /*
460  * If the destination rectangle is NULL, use the entire dest surface
461  */
462  if (dstrect == nullptr)
463  {
464  dr.x = 0;
465  dr.y = 0;
466  dr.w = CAST_U16(dst->w);
467  dr.h = CAST_U16(dst->h);
468  }
469  else
470  {
471  dr = *dstrect;
472  }
473 
474  /*
475  * Clip the source rectangle to the source surface
476  */
477  if (srcrect != nullptr)
478  {
479  int maxw;
480  int maxh;
481 
482  srcx = srcrect->x;
483  w = srcrect->w;
484  maxw = src->w - srcx;
485  if (maxw < w)
486  w = maxw;
487 
488  srcy = srcrect->y;
489  h = srcrect->h;
490  maxh = src->h - srcy;
491  if (maxh < h)
492  h = maxh;
493  }
494  else
495  {
496  srcx = 0;
497  srcy = 0;
498  w = src->w;
499  h = src->h;
500  }
501 
502  /*
503  * Clip the destination rectangle against the clip rectangle
504  */
505  const SDL_Rect *const clip = &dst->clip_rect;
506  int dx;
507  int dy;
508 
509  dx = clip->x - dr.x;
510  if (dx > 0)
511  {
512  w -= dx;
513  dr.x += dx;
514  srcx += CAST_S16(dx);
515  }
516  dx = dr.x + w - clip->x - clip->w;
517  if (dx > 0)
518  w -= dx;
519 
520  dy = clip->y - dr.y;
521  if (dy > 0)
522  {
523  h -= dy;
524  dr.y += dy;
525  srcy += CAST_S16(dy);
526  }
527  dy = dr.y + h - clip->y - clip->h;
528  if (dy > 0)
529  h -= dy;
530 
531  if (w > 0 && h > 0)
532  {
533  sr.x = CAST_S16(srcx);
534  sr.y = CAST_S16(srcy);
535  sr.w = dr.w = CAST_U16(w);
536  sr.h = dr.h = CAST_U16(h);
537  return _SDL_gfxBlitRGBACall(src, &sr, dst, &dr);
538  }
539 
540  return 0;
541 }
#define CAST_U16
Definition: cast.h:29
#define CAST_S16
Definition: cast.h:28
#define reportAlways(...)
Definition: checkutils.h:253
if(!vert) return
static int _SDL_gfxBlitRGBACall(const SDL_Surface *const src, const SDL_Rect *const srcrect, const SDL_Surface *const dst, const SDL_Rect *const dstrect)

References _SDL_gfxBlitRGBACall(), CAST_S16, CAST_U16, and reportAlways.

Referenced by SDLImageHelper::combineSurface(), and TestLauncher::testBlitSpeed().