Skip to content

Commit

Permalink
Merge pull request #418 from pygame/aaline-requires-alpha
Browse files Browse the repository at this point in the history
draw.aaline should work with ARGB surfaces (like on mac).
  • Loading branch information
illume committed Mar 19, 2018
2 parents 7561a36 + 1d02d61 commit a29d7e4
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 14 deletions.
4 changes: 2 additions & 2 deletions docs/reST/ref/draw.rst
Expand Up @@ -150,6 +150,6 @@ object around the draw calls.
:alt: draw module example

Example code for draw module.

.. literalinclude:: code_examples/draw_module_example.py

35 changes: 23 additions & 12 deletions src/draw.c
Expand Up @@ -932,19 +932,18 @@ static int set_at(SDL_Surface* surf, int x, int y, Uint32 color)
return 1;
}


#define DRAWPIX32(pixel,colorptr,br,blend) \
if(SDL_BYTEORDER == SDL_BIG_ENDIAN) color <<= 8; \
if(blend) { \
int x; \
float nbr = 1.0-br; \
x = colorptr[0]*br+pixel[0]*nbr; \
pixel[0]= (x>254) ? 255: x; \
x = colorptr[1]*br+pixel[1]*nbr; \
pixel[1]= (x>254) ? 255: x; \
x = colorptr[2]*br+pixel[2]*nbr; \
pixel[2]= (x>254) ? 255: x; \
if(hasalpha) pixel[3] = pixel[0]+(br*255) - (pixel[3]*br); \
if (blend) { \
SDL_GetRGBA(*pixel, surf->format, &pixel_r, &pixel_g, &pixel_b, &pixel_a); \
tmp_r = color_r * br + pixel_r * nbr; \
tmp_g = color_g * br + pixel_g * nbr; \
tmp_b = color_b * br + pixel_b * nbr; \
tmp_a = color_a * br + pixel_a * nbr; \
*((Uint32*)pixel) = SDL_MapRGBA(surf->format, \
(Uint8)((tmp_r>254) ? 255: tmp_r), \
(Uint8)((tmp_g>254) ? 255: tmp_g), \
(Uint8)((tmp_b>254) ? 255: tmp_b), \
(Uint8)((tmp_a>254) ? 255: tmp_a)); \
} else { \
pixel[0]=(Uint8)(colorptr[0]*br); \
pixel[1]=(Uint8)(colorptr[1]*br); \
Expand All @@ -960,11 +959,23 @@ static void drawaaline(SDL_Surface* surf, Uint32 color, float x1, float y1, floa
float swaptmp;
int x, y, ix1, ix2, iy1, iy2;
int pixx, pixy;

/* for D-RAWPIX32 */
int tmp_r, tmp_g, tmp_b, tmp_a;
float nbr = 0.0f;
Uint8 pixel_r, pixel_g, pixel_b, pixel_a;
Uint8 color_r, color_g, color_b, color_a;

Uint8* pixel;
Uint8* pm = (Uint8*)surf->pixels;
Uint8* colorptr = (Uint8*)&color;
const int hasalpha = surf->format->Amask;

if (hasalpha) {
SDL_GetRGBA(color, surf->format, &color_r, &color_g, &color_b, &color_a);
} else {
SDL_GetRGB(color, surf->format, &color_r, &color_g, &color_b);
}
pixx = surf->format->BytesPerPixel;
pixy = surf->pitch;

Expand Down

0 comments on commit a29d7e4

Please sign in to comment.