../draw_line_generated_code.c

/*
  packstr_ 
*/
static inline void
packstr__initialize (SV* self, int* psize, char** pptr) {
    SV* self_sv; HV* self_hv; SV** psv; SV* str_ref; SV* string;
    int offset = 0;
    if(!SvOK(self) || !SvROK(self)) goto error;
    self_sv = SvRV(self);
    if(SvTYPE(self_sv) != SVt_PVHV) goto error;
    self_hv = self_sv;
    psv = hv_fetch(self_hv, "ppm_data", strlen("ppm_data"), 0);
    if(psv == NULL) goto error;
    str_ref = *psv;
    if(!SvROK(str_ref)) goto error;
    string = SvRV(str_ref);
    if(!SvPOK(string))  goto error;

    psv = hv_fetch(self_hv, "offset", strlen("offset"), 0);
    if(psv == NULL) goto error;
    offset = SvIV(*psv);

    *pptr  = SvPV(string, (*psize));
    *pptr += offset;
    return;
  error:
    croak("?CONTEXT?: packed_substr's INIT(obj) had difficulty with the given object.");
}
#define packstr_DECL(obj)          int packstr__size; char* packstr__ptr;
#define packstr_INIT(obj)          packstr__initialize((obj),&packstr__size,&packstr__ptr);
#define packstr__PTR               packstr__ptr
#define packstr__SIZE              packstr__size
#define packstr_EXTEND(sz)         /* do nothing */
#define packstr_FETCH(idx)         packstr__PTR[(idx)]
#define packstr_STORE(idx,val)     packstr__PTR[(idx)] = (val)
#define packstr_FETCHSIZE()        packstr__SIZE
#define packstr_STORESIZE(sz)      croak("toy doesn't STORESIZE")
#define packstr_CLEAR()            packstr_STORESIZE(0)
#define packstr_EXISTS(idx)        ((idx) >= (packstr__SIZE -1) && (idx) < packstr__SIZE)
#define packstr_DELETE(idx)        croak("?PACKAGE? doesn't support DELETE")

/*
  folded_
*/
static inline void
folded__initialize (SV* self, HV** pselfhv) {
    SV* self_sv;
    if(!SvOK(self) || !SvROK(self)) goto error;
    self_sv = SvRV(self);
    if(SvTYPE(self_sv) != SVt_PVHV) goto error;
    *pselfhv = self_sv;
    return;
  error:
    croak("toy broken2");
}
#define folded_DECL(obj)             HV* folded__selfhv; int folded__dims[3];\
  packstr_DECL(obj)
#define folded_INIT(obj)             folded__initialize((obj),&folded__selfhv);\
    {   SV ** psv;  IV iv;\
        psv = hv_fetch(folded__selfhv, "height", strlen("height"), 0);\
        if(psv == NULL) goto folded__error;\
        folded__dims[0] = SvIV(*psv);\
        psv = hv_fetch(folded__selfhv, "width", strlen("width"), 0);\
        if(psv == NULL) goto folded__error;\
        folded__dims[1] = SvIV(*psv);\
        psv = hv_fetch(folded__selfhv, "depth", strlen("depth"), 0);\
        if(psv == NULL) goto folded__error;\
        folded__dims[2] = SvIV(*psv);\
        goto folded__no_error;\
      folded__error: croak("toy broken (folding shape)");\
      folded__no_error: ;\
    } \
  packstr_INIT(obj)
#define folded_FETCH3D(i0,i1,i2)     packstr_FETCH(folded__UNWRAP((i0),(i1),(i2)))
#define folded_STORE3D(i0,i1,i2,val) packstr_STORE(folded__UNWRAP((i0),(i1),(i2)),(val))
#define folded_FETCHSIZE3D(dim)      (folded__dims[(dim)]+0)
#define folded__UNWRAP(i0,i1,i2)     ((((i0)*(folded__dims[1]*folded__dims[2]))+((i1)*folded__dims[2])+(i2))*1)

/* 
  toy_api_ImageCMacros
*/
#define DECL(obj)    folded_DECL(obj)
#define INIT(obj)    folded_INIT(obj)
#define SET_R(x,y,r) folded_STORE3D((x),(y),0,(r))
#define SET_G(x,y,g) folded_STORE3D((x),(y),1,(g))
#define SET_B(x,y,b) folded_STORE3D((x),(y),2,(b))
#define GET_R(x,y)   folded_FETCH3D((x),(y),0)
#define GET_G(x,y)   folded_FETCH3D((x),(y),1)
#define GET_B(x,y)   folded_FETCH3D((x),(y),2)
#define HEIGHT()     folded_FETCHSIZE3D(0)
#define WIDTH()      folded_FETCHSIZE3D(1)
#define DEPTH()      folded_FETCHSIZE3D(2)
#define SET_RGB(x,y, r,g,b) (SET_R((x),(y),(r)),SET_G((x),(y),(g)),SET_B((x),(y),(b)))


#define POINTS_OF_LINE(x1, y1, x2, y2)\
{\
    /*\
       Just another 2D Bresenham line walker.\
\
       arguments: int x1, y1, x2, y2\
        requires:  Point(int x, y)     (a proceedure or macro)\
\
       Calls Point(x,y) for each point on the line.\
\
       From DigitalLine.c, Paul Heckbert,\
       "Graphics Gems", Academic Press, 1990\
    */\
    int d, x, y, ax, ay, sx, sy, dx, dy;\
\
    dx = x2-x1;  ax = (dx>=0?dx:-dx)<<1;  sx = (dx>=0?1:-1);\
    dy = y2-y1;  ay = (dy>=0?dy:-dy)<<1;  sy = (dy>=0?1:-1);\
\
    x = x1;\
    y = y1;\
    if (ax>ay) {                /* x dominant */\
        d = ay-(ax>>1);\
        for (;;) {\
            { Point(x, y); }\
            if (x==x2) return;\
            if (d>=0) {\
                y += sy;\
                d -= ax;\
            }\
            x += sx;\
            d += ay;\
        }\
    }\
    else {                      /* y dominant */\
        d = ax-(ay>>1);\
        for (;;) {\
            { Point(x, y); }\
            if (y==y2) return;\
            if (d>=0) {\
                x += sx;\
                d -= ay;\
            }\
            y += sy;\
            d += ax;\
        }\
    }\
}

void draw_line (SV* self,
		int x1, int y1, int x2, int y2,
                int r, int g, int b)
{
    DECL(self);
    INIT(self);
#   define Point(x,y)  SET_RGB(x,y, r,g,b)
    POINTS_OF_LINE(x1, y1, x2, y2);
}

Generated by GNU enscript 1.6.1.