ManaPlus
Functions
sdlgfxblitfunc.h File Reference

(986a3bf)

Go to the source code of this file.

Functions

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

Function Documentation

◆ 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().