Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions docs/reST/c_api/surface.rst
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,11 @@ Header file: src_c/include/pygame.h
This is a macro. Argument *x* is assumed to be a Surface, or subclass of
Surface, instance.

.. c:function:: int pgSurface_Blit(PyObject *dstobj, PyObject *srcobj, SDL_Rect *dstrect, SDL_Rect *srcrect, int the_args)
.. c:function:: int pgSurface_Blit(PyObject *dstobj, PyObject *srcobj, SDL_Rect *dstrect, SDL_Rect *srcrect, int blend_flags)

Blit the *srcrect* portion of Surface *srcobj* onto Surface *dstobj* at *srcobj*

Argument *the_args* indicates the type of blit to perform:
Argument *blend_flags* indicates the type of blit to perform:
Normal blit (``0``), ``PYGAME_BLEND_ADD``, ``PYGAME_BLEND_SUB``,
``PYGAME_BLEND_SUB``, ``PYGAME_BLEND_MULT``, ``PYGAME_BLEND_MIN``,
``PYGAME_BLEND_MAX``, ``PYGAME_BLEND_RGBA_ADD``, ``PYGAME_BLEND_RGBA_SUB``,
Expand Down
18 changes: 9 additions & 9 deletions src_c/alphablit.c
Original file line number Diff line number Diff line change
Expand Up @@ -116,15 +116,15 @@ blit_blend_premultiplied_mmx(SDL_BlitInfo *info);

static int
SoftBlitPyGame(SDL_Surface *src, SDL_Rect *srcrect, SDL_Surface *dst,
SDL_Rect *dstrect, int the_args);
SDL_Rect *dstrect, int blend_flags);
extern int
SDL_RLESurface(SDL_Surface *surface);
extern void
SDL_UnRLESurface(SDL_Surface *surface, int recode);

static int
SoftBlitPyGame(SDL_Surface *src, SDL_Rect *srcrect, SDL_Surface *dst,
SDL_Rect *dstrect, int the_args)
SDL_Rect *dstrect, int blend_flags)
{
int okay;
int src_locked;
Expand Down Expand Up @@ -202,13 +202,13 @@ SoftBlitPyGame(SDL_Surface *src, SDL_Rect *srcrect, SDL_Surface *dst,
}
/* Convert alpha multiply blends to regular blends if either of
the surfaces don't have alpha channels */
if (the_args == PYGAME_BLEND_RGBA_MULT &&
if (blend_flags == PYGAME_BLEND_RGBA_MULT &&
(info.src_blend == SDL_BLENDMODE_NONE ||
info.dst_blend == SDL_BLENDMODE_NONE)) {
the_args = PYGAME_BLEND_MULT;
blend_flags = PYGAME_BLEND_MULT;
}

switch (the_args) {
switch (blend_flags) {
case 0: {
if (info.src_blend != SDL_BLENDMODE_NONE &&
src->format->Amask) {
Expand Down Expand Up @@ -2839,7 +2839,7 @@ alphablit_solid(SDL_BlitInfo *info)
/*we assume the "dst" has pixel alpha*/
int
pygame_Blit(SDL_Surface *src, SDL_Rect *srcrect, SDL_Surface *dst,
SDL_Rect *dstrect, int the_args)
SDL_Rect *dstrect, int blend_flags)
{
SDL_Rect fulldst;
int srcx, srcy, w, h;
Expand Down Expand Up @@ -2925,17 +2925,17 @@ pygame_Blit(SDL_Surface *src, SDL_Rect *srcrect, SDL_Surface *dst,
sr.y = srcy;
sr.w = dstrect->w = w;
sr.h = dstrect->h = h;
return SoftBlitPyGame(src, &sr, dst, dstrect, the_args);
return SoftBlitPyGame(src, &sr, dst, dstrect, blend_flags);
}
dstrect->w = dstrect->h = 0;
return 0;
}

int
pygame_AlphaBlit(SDL_Surface *src, SDL_Rect *srcrect, SDL_Surface *dst,
SDL_Rect *dstrect, int the_args)
SDL_Rect *dstrect, int blend_flags)
{
return pygame_Blit(src, srcrect, dst, dstrect, the_args);
return pygame_Blit(src, srcrect, dst, dstrect, blend_flags);
}

int
Expand Down
31 changes: 16 additions & 15 deletions src_c/surface.c
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ typedef struct pg_BlitMap {

int
pgSurface_Blit(pgSurfaceObject *dstobj, pgSurfaceObject *srcobj,
SDL_Rect *dstrect, SDL_Rect *srcrect, int the_args);
SDL_Rect *dstrect, SDL_Rect *srcrect, int blend_flags);

/* statics */
static pgSurfaceObject *
Expand Down Expand Up @@ -1829,12 +1829,12 @@ surf_blit(pgSurfaceObject *self, PyObject *args, PyObject *keywds)
int dx, dy, result;
SDL_Rect dest_rect;
int sx, sy;
int the_args = 0;
int blend_flags = 0;

static char *kwids[] = {"source", "dest", "area", "special_flags", NULL};
if (!PyArg_ParseTupleAndKeywords(args, keywds, "O!O|Oi", kwids,
&pgSurface_Type, &srcobject, &argpos,
&argrect, &the_args))
&argrect, &blend_flags))
return NULL;

src = pgSurface_AsSurface(srcobject);
Expand Down Expand Up @@ -1868,10 +1868,11 @@ surf_blit(pgSurfaceObject *self, PyObject *args, PyObject *keywds)
dest_rect.w = src_rect->w;
dest_rect.h = src_rect->h;

if (!the_args)
the_args = 0;
if (!blend_flags)
blend_flags = 0;

result = pgSurface_Blit(self, srcobject, &dest_rect, src_rect, the_args);
result =
pgSurface_Blit(self, srcobject, &dest_rect, src_rect, blend_flags);

if (result != 0)
return NULL;
Expand Down Expand Up @@ -1899,7 +1900,7 @@ surf_blits(pgSurfaceObject *self, PyObject *args, PyObject *keywds)
int dx, dy, result;
SDL_Rect dest_rect;
int sx, sy;
int the_args = 0;
int blend_flags = 0;

PyObject *blitsequence;
PyObject *iterator = NULL;
Expand Down Expand Up @@ -1965,7 +1966,7 @@ surf_blits(pgSurfaceObject *self, PyObject *args, PyObject *keywds)
}
argrect = NULL;
special_flags = NULL;
the_args = 0;
blend_flags = 0;

/* We know that there will be at least two items due to the
conditional at the start of the loop */
Expand Down Expand Up @@ -2033,14 +2034,14 @@ surf_blits(pgSurfaceObject *self, PyObject *args, PyObject *keywds)
dest_rect.h = src_rect->h;

if (special_flags) {
if (!pg_IntFromObj(special_flags, &the_args)) {
if (!pg_IntFromObj(special_flags, &blend_flags)) {
bliterrornum = BLITS_ERR_MUST_ASSIGN_NUMERIC;
goto bliterror;
}
}

result = pgSurface_Blit(self, (pgSurfaceObject *)srcobject, &dest_rect,
src_rect, the_args);
src_rect, blend_flags);

if (result != 0) {
bliterrornum = BLITS_ERR_BLIT_FAIL;
Expand Down Expand Up @@ -3792,7 +3793,7 @@ surface_do_overlap(SDL_Surface *src, SDL_Rect *srcrect, SDL_Surface *dst,
/*this internal blit function is accessible through the C api*/
int
pgSurface_Blit(pgSurfaceObject *dstobj, pgSurfaceObject *srcobj,
SDL_Rect *dstrect, SDL_Rect *srcrect, int the_args)
SDL_Rect *dstrect, SDL_Rect *srcrect, int blend_flags)
{
SDL_Surface *src = pgSurface_AsSurface(srcobj);
SDL_Surface *dst = pgSurface_AsSurface(dstobj);
Expand Down Expand Up @@ -3837,7 +3838,7 @@ pgSurface_Blit(pgSurfaceObject *dstobj, pgSurfaceObject *srcobj,

pgSurface_Prep(srcobj);

if ((the_args != 0 && the_args != PYGAME_BLEND_ALPHA_SDL2) ||
if ((blend_flags != 0 && blend_flags != PYGAME_BLEND_ALPHA_SDL2) ||
((SDL_GetColorKey(src, &key) == 0 || _PgSurface_SrcAlpha(src) == 1) &&
/* This simplification is possible because a source subsurface
is converted to its owner with a clip rect and a dst
Expand All @@ -3847,7 +3848,7 @@ pgSurface_Blit(pgSurfaceObject *dstobj, pgSurfaceObject *srcobj,
dst->pixels == src->pixels && srcrect != NULL &&
surface_do_overlap(src, srcrect, dst, dstrect))) {
/* Py_BEGIN_ALLOW_THREADS */
result = pygame_Blit(src, srcrect, dst, dstrect, the_args);
result = pygame_Blit(src, srcrect, dst, dstrect, blend_flags);
/* Py_END_ALLOW_THREADS */
}
/* can't blit alpha to 8bit, crashes SDL */
Expand Down Expand Up @@ -3888,7 +3889,7 @@ pgSurface_Blit(pgSurfaceObject *dstobj, pgSurfaceObject *srcobj,
}
/* Py_END_ALLOW_THREADS */
}
else if (the_args != PYGAME_BLEND_ALPHA_SDL2 &&
else if (blend_flags != PYGAME_BLEND_ALPHA_SDL2 &&
!(pg_EnvShouldBlendAlphaSDL2()) &&
SDL_GetColorKey(src, &key) != 0 &&
(dst->format->BytesPerPixel == 4 ||
Expand All @@ -3900,7 +3901,7 @@ pgSurface_Blit(pgSurfaceObject *dstobj, pgSurfaceObject *srcobj,
/* If we have a 32bit source surface with per pixel alpha
and no RLE we'll use pygame_Blit so we can mimic how SDL1
behaved */
result = pygame_Blit(src, srcrect, dst, dstrect, the_args);
result = pygame_Blit(src, srcrect, dst, dstrect, blend_flags);
}
else {
/* Py_BEGIN_ALLOW_THREADS */
Expand Down
4 changes: 2 additions & 2 deletions src_c/surface.h
Original file line number Diff line number Diff line change
Expand Up @@ -346,11 +346,11 @@ surface_respect_clip_rect(SDL_Surface *surface, SDL_Rect *rect);

int
pygame_AlphaBlit(SDL_Surface *src, SDL_Rect *srcrect, SDL_Surface *dst,
SDL_Rect *dstrect, int the_args);
SDL_Rect *dstrect, int blend_flags);

int
pygame_Blit(SDL_Surface *src, SDL_Rect *srcrect, SDL_Surface *dst,
SDL_Rect *dstrect, int the_args);
SDL_Rect *dstrect, int blend_flags);

int
premul_surf_color_by_alpha(SDL_Surface *src, SDL_Surface *dst);
Expand Down