sub get_toy_api_ImageCMacros { return <<'END_OF_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))) END_OF_C }