view dmline.c @ 49:033c660c25f5

Restructure module playing, removing 8bit sample mixing (output can still be 8bit, but samples are internally upconverted to 16bit after module loading.) Also prepare for floating point mixing support.
author Matti Hamalainen <ccr@tnsp.org>
date Mon, 01 Oct 2012 02:51:41 +0300
parents 997e26f17946
children 92cc5e1fa180
line wrap: on
line source

/*
 * DMLib
 * -- Arbitrary line drawing functions
 * Programmed and designed by Matti 'ccr' Hamalainen
 * (C) Copyright 2011 Tecnic Software productions (TNSP)
 */
#include "dmlib.h"


/* Clip line coordinates. Return value:
 * = 0  : No clipping needed.
 * > 0  : Clipped. Line partially inside the clipping area.
 * < 0  : Line completely outside the clipping area.
 */
int dmClipLineCoords(int *x0, int *y0, int *x1, int *y1, SDL_Surface *screen)
{
#if 0
    const int clipX0 = screen->clip_rect.x,
              clipY0 = screen->clip_rect.y;
    const int clipX1 = clipX0 + screen->clip_rect.w - 1,
              clipY1 = clipY0 + screen->clip_rect.h - 1;
    const int dx = *x1 - *x0,
              dy = *y1 - *y0;
    DMFixedPoint k, kdx, kdy;

    // Is line completely outside the clipping area?
    if ((*x0 < clipX0 && *x1 < clipX0) || (*x0 > clipX1 && *x1 > clipX1) ||
        (*y0 < clipY0 && *y1 < clipY0) || (*y0 > clipY1 && *y1 > clipY1))
        return -1;
    
    FP_SETHL(kdx, dx);
    FP_SETHL(kdy, dy);
#endif        
    
    return 0;
}


int dmTestLineCoords(int x0, int y0, int x1, int y1, SDL_Surface *screen)
{
    return dmClipLineCoords(&x0, &y0, &x1, &y1, screen);
}


#include "dmlinefunc.h"

static const DMDrawLineFunc dmDrawLineTable[DMD_NMODES][DMD_NBITDEPTHS] =
{
    /* DMD_NONE          */ { dmDrawLine8              , dmDrawLine32 },
#if 0
    /* DMD_TRANSPARENT   */ { dmDrawLine8Transparent   , dmDrawLine32Transparent },
    /* DMD_SATURATE      */ { dmDrawLine8Saturate      , dmDrawLine32Saturate },

    /* DMD_NONE + AA     */ { NULL, NULL },
    /* DMD_TRANSP + AA   */ { NULL, NULL },
    /* DMD_SATURATE + AA */ { dmDrawLine8AASaturate    , dmDrawLine32AASaturate },
#endif
};

static const int ndmDrawLineTable = sizeof(dmDrawLineTable) / sizeof(dmDrawLineTable[0]);


DMDrawLineFunc dmGetDrawLineFunc(SDL_PixelFormat *dst, int mode)
{
    int index;
    if (dst == NULL || mode < 0 || mode >= ndmDrawLineTable)
        return NULL;

    if ((index = dmBitsPerPixel2Index(dst->BitsPerPixel)) < 0)
        return NULL;
    
    return dmDrawLineTable[mode][index];
}


int dmDrawLineAny(SDL_Surface *screen, int x0, int y0, int x1, int y1, const Uint32 col, int mode)
{
    DMDrawLineFunc bfunc = dmGetDrawLineFunc(screen->format, mode);

    if (bfunc == NULL)
        return -15;

    return bfunc(screen, x0, y0, x1, y1, col);
}