Mercurial > hg > dmlib
diff dmdrawline.h @ 0:32250b436bca
Initial re-import.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Fri, 28 Sep 2012 01:54:23 +0300 |
parents | |
children | 997e26f17946 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/dmdrawline.h Fri Sep 28 01:54:23 2012 +0300 @@ -0,0 +1,86 @@ + +#ifdef DM_USE_SIMD +static int DM_DRAWLINE_NAME_ASM (SDL_Surface *screen, int x0, int y0, int x1, int y1, const Uint32 col); +#endif + +#ifdef DM_USE_C +static int DM_DRAWLINE_NAME_C (SDL_Surface *screen, int x0, int y0, int x1, int y1, const Uint32 col) +{ + int dx, dy, xstep, ystep; + const int qpitch = screen->pitch / DM_DRAWLINE_DST_BYTES; + + // Clipping + if (dmClipLineCoords(&x0, &y0, &x1, &y1, screen)) + return -1; + + // Compute initial deltas + dx = (x1 - x0) * 2; + dy = (y1 - y0) * 2; + + if (dx < 0) + { + dx = -dx; + xstep = -1; + } + else + xstep = 1; + + if (dy < 0) + { + dy = -dy; + ystep = -qpitch; + } + else + ystep = qpitch; + + // Compute offsets + y0 *= qpitch; + y1 *= qpitch; + + DM_DRAWLINE_DST_TYPE *pix = screen->pixels; + + // Continue based on which delta is larger + if (dx > dy) + { + int afrac = dy - (dx / 2); + while (x0 != x1) + { + if (afrac >= 0) + { + y0 += ystep; + afrac -= dx; + } + + x0 += xstep; + afrac += dy; + + DM_DRAWLINE_INNER + } + } + else + { + int afrac = dx - (dy / 2); + while (y0 != y1) + { + if (afrac >= 0) + { + x0 += xstep; + afrac -= dy; + } + + y0 += ystep; + afrac += dx; + + DM_DRAWLINE_INNER + } + } + + return 0; +} +#endif + +#undef DM_DRAWLINE_NAME +#undef DM_DRAWLINE_NAME_ASM +#undef DM_DRAWLINE_NAME_C +#undef DM_DRAWLINE_DST_BYTES +#undef DM_DRAWLINE_DST_TYPE