view src/dmdrawline.h @ 2576:812b16ee49db

I had been living under apparent false impression that "realfft.c" on which the FFT implementation in DMLIB was basically copied from was released in public domain at some point, but it could very well be that it never was. Correct license is (or seems to be) GNU GPL. Thus I removing the code from DMLIB, and profusely apologize to the author, Philip Van Baren. It was never my intention to distribute code based on his original work under a more liberal license than originally intended.
author Matti Hamalainen <ccr@tnsp.org>
date Fri, 11 Mar 2022 16:32:50 +0200
parents e06abfde6c39
children
line wrap: on
line source

/*
 * DMLib
 * -- Simple Bresenham's style line drawing
 * Programmed and designed by Matti 'ccr' Hamalainen
 * (C) Copyright 2011-2015 Tecnic Software productions (TNSP)
 */

int DM_DRAWLINE_NAME (SDL_Surface *screen, DMFloat fx0, DMFloat fy0, DMFloat fx1, DMFloat fy1, const Uint32 col
#ifdef DM_DRAWLINE_ARGS
    DM_DRAWLINE_ARGS
#endif
)
#ifdef DM_HEADER
;
#else
{
    int dx, dy, xstep, ystep;
    const int qpitch = screen->pitch / DM_DRAWLINE_DST_BYTES;
    (void) qpitch;
    (void) col;

    // Clipping
    if (dmClipLineCoordsFloat(screen, &fx0, &fy0, &fx1, &fy1) < 0)
        return -1;

    int x0 = fx0, y0 = fy0, x1 = fx1, y1 = fy1;

    // 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 = -1;
    }
    else
        ystep = 1;

#ifndef DM_DRAWLINE_SPEC
    // Compute offsets
    y0 *= qpitch;
    y1 *= qpitch;
    ystep *= qpitch;
#endif

#ifdef DM_DRAWLINE_INIT
    DM_DRAWLINE_INIT
#endif

    DM_DRAWLINE_DST_TYPE *pix = (DM_DRAWLINE_DST_TYPE *) screen->pixels;
    (void) pix;

    // Continue based on which delta is larger
    if (dx > dy)
    {
        int afrac = dy - (dx / 2.0);
        while (x0 != x1)
        {
            if (afrac >= 0)
            {
                y0 += ystep;
                afrac -= dx;
            }

            x0 += xstep;
            afrac += dy;

            DM_DRAWLINE_INNER
        }
    }
    else
    {
        int afrac = dx - (dy / 2.0);
        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_ARGS
#undef DM_DRAWLINE_DST_BYTES
#undef DM_DRAWLINE_DST_TYPE
#undef DM_DRAWLINE_INIT
#undef DM_DRAWLINE_INNER