#include "regmach.h"
#include "imextdef.h"
#include "imextpltypes.h"
+#include "imperlio.h"
#include <float.h>
#if i_int_hlines_testing()
/*
+Context object management
+
+*/
+
+typedef im_context_t Imager__Context;
+
+#define im_context_DESTROY(ctx) im_context_refdec((ctx), "DESTROY")
+
+#ifdef PERL_IMPLICIT_CONTEXT
+
+#define MY_CXT_KEY "Imager::_context" XS_VERSION
+
+typedef struct {
+ im_context_t ctx;
+} my_cxt_t;
+
+START_MY_CXT
+
+im_context_t fallback_context;
+
+static void
+start_context(pTHX) {
+ dMY_CXT;
+ MY_CXT.ctx = im_context_new();
+ sv_setref_pv(get_sv("Imager::_context", GV_ADD), "Imager::Context", MY_CXT.ctx);
+
+ /* Ideally we'd free this reference, but the error message memory
+ was never released on exit, so the associated memory here is reasonable
+ to keep.
+ With logging enabled we always need at least one context, since
+ objects may be released fairly late and attempt to get the log file.
+ */
+ im_context_refinc(MY_CXT.ctx, "start_context");
+ fallback_context = MY_CXT.ctx;
+}
+
+static im_context_t
+perl_get_context(void) {
+ dTHX;
+ dMY_CXT;
+
+ return MY_CXT.ctx ? MY_CXT.ctx : fallback_context;
+}
+
+#else
+
+static im_context_t perl_context;
+
+static void
+start_context(pTHX) {
+ perl_context = im_context_new();
+ im_context_refinc(perl_context, "start_context");
+}
+
+static im_context_t
+perl_get_context(void) {
+ return perl_context;
+}
+
+#endif
+
+/* used to represent channel lists parameters */
+typedef struct i_channel_list_tag {
+ int *channels;
+ int count;
+} i_channel_list;
+
+typedef struct {
+ size_t count;
+ const i_sample_t *samples;
+} i_sample_list;
+
+typedef struct {
+ size_t count;
+ const i_fsample_t *samples;
+} i_fsample_list;
+
+/*
+
Allocate memory that will be discarded when mortals are discarded.
*/
return SvPVX(sv);
}
+static void *
+calloc_temp(pTHX_ size_t size) {
+ void *result = malloc_temp(aTHX_ size);
+ memset(result, 0, size);
+
+ return result;
+}
+
+/* for use with the T_AVARRAY typemap */
+#define doublePtr(size) ((double *)calloc_temp(aTHX_ sizeof(double) * (size)))
+#define SvDouble(sv, pname) (SvNV(sv))
+
+#define intPtr(size) ((int *)calloc_temp(aTHX_ sizeof(int) * (size)))
+#define SvInt(sv, pname) (SvIV(sv))
+
+#define i_img_dimPtr(size) ((i_img_dim *)calloc_temp(aTHX_ sizeof(i_img_dim) * (size)))
+#define SvI_img_dim(sv, pname) (SvIV(sv))
+
+#define i_colorPtr(size) ((i_color *)calloc_temp(aTHX_ sizeof(i_color *) * (size)))
+
+#define SvI_color(sv, pname) S_sv_to_i_color(aTHX_ sv, pname)
+
+static i_color
+S_sv_to_i_color(pTHX_ SV *sv, const char *pname) {
+ if (!sv_derived_from(sv, "Imager::Color")) {
+ croak("%s: not a color object");
+ }
+ return *INT2PTR(i_color *, SvIV((SV *)SvRV(sv)));
+}
+
/* These functions are all shared - then comes platform dependant code */
static int getstr(void *hv_t,char *key,char **store) {
dTHX;
SV *data;
dSP;
- if (!SvOK(cbd->readcb))
+ if (!SvOK(cbd->readcb)) {
+ mm_log((1, "read callback called but no readcb supplied\n"));
+ i_push_error(0, "read callback called but no readcb supplied");
return -1;
+ }
ENTER;
SAVETMPS;
off_t result;
dSP;
- if (!SvOK(cbd->seekcb))
+ if (!SvOK(cbd->seekcb)) {
+ mm_log((1, "seek callback called but no seekcb supplied\n"));
+ i_push_error(0, "seek callback called but no seekcb supplied");
return -1;
+ }
ENTER;
SAVETMPS;
dSP;
bool success;
- if (!SvOK(cbd->writecb))
+ if (!SvOK(cbd->writecb)) {
+ mm_log((1, "write callback called but no writecb supplied\n"));
+ i_push_error(0, "write callback called but no writecb supplied");
return -1;
+ }
ENTER;
SAVETMPS;
return io_new_buffer(data, length, my_SvREFCNT_dec, data_sv);
}
+static const char *
+describe_sv(SV *sv) {
+ if (SvOK(sv)) {
+ if (SvROK(sv)) {
+ svtype type = SvTYPE(SvRV(sv));
+ switch (type) {
+ case SVt_PVCV: return "CV";
+ case SVt_PVGV: return "GV";
+ case SVt_PVLV: return "LV";
+ default: return "some reference";
+ }
+ }
+ else {
+ return "non-reference scalar";
+ }
+ }
+ else {
+ return "undef";
+ }
+}
+
static i_io_glue_t *
do_io_new_cb(pTHX_ SV *writecb, SV *readcb, SV *seekcb, SV *closecb) {
struct cbdata *cbd;
cbd->seekcb = newSVsv(seekcb);
cbd->closecb = newSVsv(closecb);
+ mm_log((1, "do_io_new_cb(writecb %p (%s), readcb %p (%s), seekcb %p (%s), closecb %p (%s))\n", writecb, describe_sv(writecb), readcb, describe_sv(readcb), seekcb, describe_sv(seekcb), closecb, describe_sv(closecb)));
+
return io_new_cb(cbd, io_reader, io_writer, io_seeker, io_closer,
io_destroyer);
}
}
}
-
/* I don't think ICLF_* names belong at the C interface
this makes the XS code think we have them, to let us avoid
putting function bodies in the XS code
#define PERL_PL_SET_GLOBAL_CALLBACKS \
sv_setiv(get_sv(PERL_PL_FUNCTION_TABLE_NAME, 1), PTR2IV(&im_perl_funcs));
+#define IIM_new i_img_8_new
+#define IIM_DESTROY i_img_destroy
+typedef int SysRet;
+
#ifdef IMEXIF_ENABLE
#define i_exif_enabled() 1
#else
Imager::Color cl
PPCODE:
EXTEND(SP, 4);
- PUSHs(sv_2mortal(newSVnv(cl->rgba.r)));
- PUSHs(sv_2mortal(newSVnv(cl->rgba.g)));
- PUSHs(sv_2mortal(newSVnv(cl->rgba.b)));
- PUSHs(sv_2mortal(newSVnv(cl->rgba.a)));
+ PUSHs(sv_2mortal(newSViv(cl->rgba.r)));
+ PUSHs(sv_2mortal(newSViv(cl->rgba.g)));
+ PUSHs(sv_2mortal(newSViv(cl->rgba.b)));
+ PUSHs(sv_2mortal(newSViv(cl->rgba.a)));
Imager::Color
i_hsv_to_rgb(c)
PUSHs(sv_2mortal(newSVuv(bytes)));
}
+bool
+i_int_check_image_file_limits(width, height, channels, sample_size)
+ i_img_dim width
+ i_img_dim height
+ int channels
+ size_t sample_size
+ PROTOTYPE: DISABLE
+
MODULE = Imager PACKAGE = Imager::IO PREFIX = io_
Imager::IO
OUTPUT:
RETVAL
+Imager::IO
+io__new_perlio(class, io)
+ PerlIO *io
+ CODE:
+ RETVAL = im_io_new_perlio(aTHX_ io);
+ OUTPUT:
+ RETVAL
+
SV *
io_slurp(class, ig)
Imager::IO ig
void *data;
STRLEN size;
CODE:
-#ifdef SvUTF8
- if (SvUTF8(data_sv)) {
- data_sv = sv_2mortal(newSVsv(data_sv));
- /* yes, we want this to croak() if the SV can't be downgraded */
- sv_utf8_downgrade(data_sv, FALSE);
- }
-#endif
- data = SvPV(data_sv, size);
+ data = SvPVbyte(data_sv, size);
RETVAL = i_io_raw_write(ig, data, size);
OUTPUT:
RETVAL
void *data;
STRLEN size;
CODE:
-#ifdef SvUTF8
- if (SvUTF8(data_sv)) {
- data_sv = sv_2mortal(newSVsv(data_sv));
- /* yes, we want this to croak() if the SV can't be downgraded */
- sv_utf8_downgrade(data_sv, FALSE);
- }
-#endif
- data = SvPV(data_sv, size);
+ data = SvPVbyte(data_sv, size);
RETVAL = i_io_write(ig, data, size);
OUTPUT:
RETVAL
PUSHs(sv_2mortal(newSVpv(item,0)));
}
-Imager::ImgRaw
-i_img_new()
-
-Imager::ImgRaw
-i_img_empty(im,x,y)
- Imager::ImgRaw im
- i_img_dim x
- i_img_dim y
-
-Imager::ImgRaw
-i_img_empty_ch(im,x,y,ch)
- Imager::ImgRaw im
- i_img_dim x
- i_img_dim y
- int ch
-
Imager::ImgRaw
i_sametype(im, x, y)
Imager::ImgRaw im
int
i_log_enabled()
-void
-i_img_exorcise(im)
- Imager::ImgRaw im
-
-void
-i_img_destroy(im)
- Imager::ImgRaw im
-
void
i_img_info(im)
Imager::ImgRaw im
void
-i_bezier_multi(im,xc,yc,val)
+i_bezier_multi(im,x,y,val)
Imager::ImgRaw im
- Imager::Color val
- PREINIT:
- double *x,*y;
- int len;
- AV *av1;
- AV *av2;
- SV *sv1;
- SV *sv2;
- int i;
- PPCODE:
- ICL_info(val);
- if (!SvROK(ST(1))) croak("Imager: Parameter 1 to i_bezier_multi must be a reference to an array\n");
- if (SvTYPE(SvRV(ST(1))) != SVt_PVAV) croak("Imager: Parameter 1 to i_bezier_multi must be a reference to an array\n");
- if (!SvROK(ST(2))) croak("Imager: Parameter 2 to i_bezier_multi must be a reference to an array\n");
- if (SvTYPE(SvRV(ST(2))) != SVt_PVAV) croak("Imager: Parameter 2 to i_bezier_multi must be a reference to an array\n");
- av1=(AV*)SvRV(ST(1));
- av2=(AV*)SvRV(ST(2));
- if (av_len(av1) != av_len(av2)) croak("Imager: x and y arrays to i_bezier_multi must be equal length\n");
- len=av_len(av1)+1;
- x=mymalloc( len*sizeof(double) );
- y=mymalloc( len*sizeof(double) );
- for(i=0;i<len;i++) {
- sv1=(*(av_fetch(av1,i,0)));
- sv2=(*(av_fetch(av2,i,0)));
- x[i]=(double)SvNV(sv1);
- y[i]=(double)SvNV(sv2);
- }
- i_bezier_multi(im,len,x,y,val);
- myfree(x);
- myfree(y);
-
+ double *x
+ double *y
+ Imager::Color val
+ PREINIT:
+ STRLEN size_x;
+ STRLEN size_y;
+ PPCODE:
+ if (size_x != size_y)
+ croak("Imager: x and y arrays to i_bezier_multi must be equal length\n");
+ i_bezier_multi(im,size_x,x,y,val);
int
-i_poly_aa(im,xc,yc,val)
+i_poly_aa(im,x,y,val)
Imager::ImgRaw im
- Imager::Color val
- PREINIT:
- double *x,*y;
- int len;
- AV *av1;
- AV *av2;
- SV *sv1;
- SV *sv2;
- int i;
- CODE:
- ICL_info(val);
- if (!SvROK(ST(1))) croak("Imager: Parameter 1 to i_poly_aa must be a reference to an array\n");
- if (SvTYPE(SvRV(ST(1))) != SVt_PVAV) croak("Imager: Parameter 1 to i_poly_aa must be a reference to an array\n");
- if (!SvROK(ST(2))) croak("Imager: Parameter 1 to i_poly_aa must be a reference to an array\n");
- if (SvTYPE(SvRV(ST(2))) != SVt_PVAV) croak("Imager: Parameter 1 to i_poly_aa must be a reference to an array\n");
- av1=(AV*)SvRV(ST(1));
- av2=(AV*)SvRV(ST(2));
- if (av_len(av1) != av_len(av2)) croak("Imager: x and y arrays to i_poly_aa must be equal length\n");
- len=av_len(av1)+1;
- x=mymalloc( len*sizeof(double) );
- y=mymalloc( len*sizeof(double) );
- for(i=0;i<len;i++) {
- sv1=(*(av_fetch(av1,i,0)));
- sv2=(*(av_fetch(av2,i,0)));
- x[i]=(double)SvNV(sv1);
- y[i]=(double)SvNV(sv2);
- }
- RETVAL = i_poly_aa(im,len,x,y,val);
- myfree(x);
- myfree(y);
- OUTPUT:
- RETVAL
+ double *x
+ double *y
+ Imager::Color val
+ PREINIT:
+ STRLEN size_x;
+ STRLEN size_y;
+ CODE:
+ if (size_x != size_y)
+ croak("Imager: x and y arrays to i_poly_aa must be equal length\n");
+ RETVAL = i_poly_aa(im, size_x, x, y, val);
+ OUTPUT:
+ RETVAL
int
-i_poly_aa_cfill(im,xc,yc,fill)
+i_poly_aa_cfill(im, x, y, fill)
Imager::ImgRaw im
- Imager::FillHandle fill
- PREINIT:
- double *x,*y;
- int len;
- AV *av1;
- AV *av2;
- SV *sv1;
- SV *sv2;
- int i;
- CODE:
- if (!SvROK(ST(1))) croak("Imager: Parameter 1 to i_poly_aa_cfill must be a reference to an array\n");
- if (SvTYPE(SvRV(ST(1))) != SVt_PVAV) croak("Imager: Parameter 1 to i_poly_aa_cfill must be a reference to an array\n");
- if (!SvROK(ST(2))) croak("Imager: Parameter 1 to i_poly_aa_cfill must be a reference to an array\n");
- if (SvTYPE(SvRV(ST(2))) != SVt_PVAV) croak("Imager: Parameter 1 to i_poly_aa_cfill must be a reference to an array\n");
- av1=(AV*)SvRV(ST(1));
- av2=(AV*)SvRV(ST(2));
- if (av_len(av1) != av_len(av2)) croak("Imager: x and y arrays to i_poly_aa_cfill must be equal length\n");
- len=av_len(av1)+1;
- x=mymalloc( len*sizeof(double) );
- y=mymalloc( len*sizeof(double) );
- for(i=0;i<len;i++) {
- sv1=(*(av_fetch(av1,i,0)));
- sv2=(*(av_fetch(av2,i,0)));
- x[i]=(double)SvNV(sv1);
- y[i]=(double)SvNV(sv2);
- }
- RETVAL = i_poly_aa_cfill(im,len,x,y,fill);
- myfree(x);
- myfree(y);
- OUTPUT:
- RETVAL
-
-
+ double *x
+ double *y
+ Imager::FillHandle fill
+ PREINIT:
+ STRLEN size_x;
+ STRLEN size_y;
+ CODE:
+ if (size_x != size_y)
+ croak("Imager: x and y arrays to i_poly_aa_cfill must be equal length\n");
+ RETVAL = i_poly_aa_cfill(im, size_x, x, y, fill);
+ OUTPUT:
+ RETVAL
undef_int
i_flood_fill(im,seedx,seedy,dcol)
RETVAL
Imager::ImgRaw
-i_matrix_transform(im, xsize, ysize, matrix, ...)
+i_matrix_transform(im, xsize, ysize, matrix_av, ...)
Imager::ImgRaw im
- i_img_dim xsize
- i_img_dim ysize
- PREINIT:
- double matrix[9];
- AV *av;
- IV len;
- SV *sv1;
- int i;
- i_color *backp = NULL;
- i_fcolor *fbackp = NULL;
- CODE:
- if (!SvROK(ST(3)) || SvTYPE(SvRV(ST(3))) != SVt_PVAV)
- croak("i_matrix_transform: parameter 4 must be an array ref\n");
- av=(AV*)SvRV(ST(3));
- len=av_len(av)+1;
- if (len > 9)
- len = 9;
- for (i = 0; i < len; ++i) {
- sv1=(*(av_fetch(av,i,0)));
- matrix[i] = SvNV(sv1);
- }
- for (; i < 9; ++i)
- matrix[i] = 0;
- /* extract the bg colors if any */
- /* yes, this is kind of strange */
- for (i = 4; i < items; ++i) {
- sv1 = ST(i);
- if (sv_derived_from(sv1, "Imager::Color")) {
- IV tmp = SvIV((SV*)SvRV(sv1));
- backp = INT2PTR(i_color *, tmp);
- }
- else if (sv_derived_from(sv1, "Imager::Color::Float")) {
- IV tmp = SvIV((SV*)SvRV(sv1));
- fbackp = INT2PTR(i_fcolor *, tmp);
- }
- }
- RETVAL = i_matrix_transform_bg(im, xsize, ysize, matrix, backp, fbackp);
- OUTPUT:
- RETVAL
+ i_img_dim xsize
+ i_img_dim ysize
+ AV *matrix_av
+ PREINIT:
+ double matrix[9];
+ STRLEN len;
+ SV *sv1;
+ int i;
+ i_color *backp = NULL;
+ i_fcolor *fbackp = NULL;
+ CODE:
+ len=av_len(matrix_av)+1;
+ if (len > 9)
+ len = 9;
+ for (i = 0; i < len; ++i) {
+ sv1=(*(av_fetch(matrix_av,i,0)));
+ matrix[i] = SvNV(sv1);
+ }
+ for (; i < 9; ++i)
+ matrix[i] = 0;
+ /* extract the bg colors if any */
+ /* yes, this is kind of strange */
+ for (i = 4; i < items; ++i) {
+ sv1 = ST(i);
+ if (sv_derived_from(sv1, "Imager::Color")) {
+ IV tmp = SvIV((SV*)SvRV(sv1));
+ backp = INT2PTR(i_color *, tmp);
+ }
+ else if (sv_derived_from(sv1, "Imager::Color::Float")) {
+ IV tmp = SvIV((SV*)SvRV(sv1));
+ fbackp = INT2PTR(i_fcolor *, tmp);
+ }
+ }
+ RETVAL = i_matrix_transform_bg(im, xsize, ysize, matrix, backp, fbackp);
+ OUTPUT:
+ RETVAL
undef_int
i_gaussian(im,stdev)
if (len > inchan)
inchan = len;
}
+ else {
+ i_push_errorf(0, "invalid matrix: element %d is not an array ref", j);
+ XSRETURN(0);
+ }
}
coeff = mymalloc(sizeof(double) * outchan * inchan);
for (j = 0; j < outchan; ++j) {
RETVAL
-void
-i_map(im, pmaps)
+undef_int
+i_map(im, pmaps_av)
Imager::ImgRaw im
- PREINIT:
- unsigned int mask = 0;
- AV *avmain;
- AV *avsub;
- SV **temp;
- int len;
- int i, j;
- unsigned char (*maps)[256];
- CODE:
- if (!SvROK(ST(1)) || SvTYPE(SvRV(ST(1))) != SVt_PVAV)
- croak("i_map: parameter 2 must be an arrayref\n");
- avmain = (AV*)SvRV(ST(1));
- len = av_len(avmain)+1;
- if (im->channels < len) len = im->channels;
-
- maps = mymalloc( len * sizeof(unsigned char [256]) );
-
- for (j=0; j<len ; j++) {
- temp = av_fetch(avmain, j, 0);
- if (temp && SvROK(*temp) && (SvTYPE(SvRV(*temp)) == SVt_PVAV) ) {
- avsub = (AV*)SvRV(*temp);
- if(av_len(avsub) != 255) continue;
- mask |= 1<<j;
- for (i=0; i<256 ; i++) {
- int val;
- temp = av_fetch(avsub, i, 0);
- val = temp ? SvIV(*temp) : 0;
- if (val<0) val = 0;
- if (val>255) val = 255;
- maps[j][i] = val;
- }
- }
- }
- i_map(im, maps, mask);
- myfree(maps);
-
-
+ AV *pmaps_av
+ PREINIT:
+ unsigned int mask = 0;
+ AV *avmain;
+ AV *avsub;
+ SV **temp;
+ int len;
+ int i, j;
+ unsigned char (*maps)[256];
+ CODE:
+ len = av_len(pmaps_av)+1;
+ if (im->channels < len)
+ len = im->channels;
+ maps = mymalloc( len * sizeof(unsigned char [256]) );
+ for (j=0; j<len ; j++) {
+ temp = av_fetch(pmaps_av, j, 0);
+ if (temp && SvROK(*temp) && (SvTYPE(SvRV(*temp)) == SVt_PVAV) ) {
+ avsub = (AV*)SvRV(*temp);
+ if(av_len(avsub) != 255)
+ continue;
+ mask |= 1<<j;
+ for (i=0; i<256 ; i++) {
+ int val;
+ temp = av_fetch(avsub, i, 0);
+ val = temp ? SvIV(*temp) : 0;
+ if (val<0) val = 0;
+ if (val>255) val = 255;
+ maps[j][i] = val;
+ }
+ }
+ }
+ i_map(im, maps, mask);
+ myfree(maps);
+ RETVAL = 1;
+ OUTPUT:
+ RETVAL
float
i_img_diff(im1,im2)
undef_int
-i_tt_text(handle,im,xb,yb,cl,points,str_sv,len_ignored,smooth,utf8,align=1)
+i_tt_text(handle,im,xb,yb,cl,points,str_sv,smooth,utf8,align=1)
Imager::Font::TT handle
Imager::ImgRaw im
i_img_dim xb
char *str;
STRLEN len;
CODE:
+ str = SvPV(str_sv, len);
#ifdef SvUTF8
if (SvUTF8(str_sv))
utf8 = 1;
#endif
- str = SvPV(str_sv, len);
RETVAL = i_tt_text(handle, im, xb, yb, cl, points, str,
len, smooth, utf8, align);
OUTPUT:
undef_int
-i_tt_cp(handle,im,xb,yb,channel,points,str_sv,len_ignored,smooth,utf8,align=1)
+i_tt_cp(handle,im,xb,yb,channel,points,str_sv,smooth,utf8,align=1)
Imager::Font::TT handle
Imager::ImgRaw im
i_img_dim xb
char *str;
STRLEN len;
CODE:
+ str = SvPV(str_sv, len);
#ifdef SvUTF8
if (SvUTF8(str_sv))
utf8 = 1;
#endif
- str = SvPV(str_sv, len);
RETVAL = i_tt_cp(handle, im, xb, yb, channel, points, str, len,
smooth, utf8, align);
OUTPUT:
void
-i_tt_bbox(handle,point,str_sv,len_ignored, utf8)
+i_tt_bbox(handle,point,str_sv,utf8)
Imager::Font::TT handle
double point
SV* str_sv
STRLEN len;
int i;
PPCODE:
+ str = SvPV(str_sv, len);
#ifdef SvUTF8
if (SvUTF8(ST(2)))
utf8 = 1;
#endif
- str = SvPV(str_sv, len);
if ((rc=i_tt_bbox(handle,point,str,len,cords, utf8))) {
EXTEND(SP, rc);
for (i = 0; i < rc; ++i) {
size_t count;
size_t i;
PPCODE:
+ i_clear_error();
+ text = SvPV(text_sv, len);
#ifdef SvUTF8
if (SvUTF8(text_sv))
utf8 = 1;
#endif
- text = SvPV(text_sv, len);
work = mymalloc(len);
count = i_tt_has_chars(handle, text, len, utf8, work);
if (GIMME_V == G_ARRAY) {
size_t len;
size_t outsize;
char name[255];
+ SSize_t count = 0;
PPCODE:
+ i_clear_error();
+ text = SvPV(text_sv, work_len);
#ifdef SvUTF8
if (SvUTF8(text_sv))
utf8 = 1;
#endif
- text = SvPV(text_sv, work_len);
len = work_len;
while (len) {
unsigned long ch;
ch = i_utf8_advance(&text, &len);
if (ch == ~0UL) {
i_push_error(0, "invalid UTF8 character");
- break;
+ XSRETURN_EMPTY;
}
}
else {
ch = *text++;
--len;
}
- EXTEND(SP, 1);
+ EXTEND(SP, count+1);
if ((outsize = i_tt_glyph_name(handle, ch, name, sizeof(name))) != 0) {
- PUSHs(sv_2mortal(newSVpv(name, 0)));
+ ST(count) = sv_2mortal(newSVpv(name, 0));
}
else {
- PUSHs(&PL_sv_undef);
- }
+ ST(count) = &PL_sv_undef;
+ }
+ ++count;
}
+ XSRETURN(count);
#endif
void
-i_transform(im,opx,opy,parm)
+i_transform(im, opx, opy, parm)
Imager::ImgRaw im
+ int *opx
+ int *opy
+ double *parm
PREINIT:
- double* parm;
- int *opx;
- int *opy;
- int opxl;
- int opyl;
- int parmlen;
- AV* av;
- SV* sv1;
- int i;
+ STRLEN size_opx, size_opy, size_parm;
i_img *result;
PPCODE:
- if (!SvROK(ST(1))) croak("Imager: Parameter 1 must be a reference to an array\n");
- if (!SvROK(ST(2))) croak("Imager: Parameter 2 must be a reference to an array\n");
- if (!SvROK(ST(3))) croak("Imager: Parameter 3 must be a reference to an array\n");
- if (SvTYPE(SvRV(ST(1))) != SVt_PVAV) croak("Imager: Parameter 1 must be a reference to an array\n");
- if (SvTYPE(SvRV(ST(2))) != SVt_PVAV) croak("Imager: Parameter 2 must be a reference to an array\n");
- if (SvTYPE(SvRV(ST(3))) != SVt_PVAV) croak("Imager: Parameter 3 must be a reference to an array\n");
- av=(AV*)SvRV(ST(1));
- opxl=av_len(av)+1;
- opx=mymalloc( opxl*sizeof(int) );
- for(i=0;i<opxl;i++) {
- sv1=(*(av_fetch(av,i,0)));
- opx[i]=(int)SvIV(sv1);
- }
- av=(AV*)SvRV(ST(2));
- opyl=av_len(av)+1;
- opy=mymalloc( opyl*sizeof(int) );
- for(i=0;i<opyl;i++) {
- sv1=(*(av_fetch(av,i,0)));
- opy[i]=(int)SvIV(sv1);
- }
- av=(AV*)SvRV(ST(3));
- parmlen=av_len(av)+1;
- parm=mymalloc( parmlen*sizeof(double) );
- for(i=0;i<parmlen;i++) { /* FIXME: Bug? */
- sv1=(*(av_fetch(av,i,0)));
- parm[i]=(double)SvNV(sv1);
- }
- result=i_transform(im,opx,opxl,opy,opyl,parm,parmlen);
- myfree(parm);
- myfree(opy);
- myfree(opx);
+ result=i_transform(im,opx,size_opx,opy,size_opy,parm,size_parm);
if (result) {
SV *result_sv = sv_newmortal();
EXTEND(SP, 1);
void
-i_gradgen(im, ...)
+i_gradgen(im, xo, yo, ac, dmeasure)
Imager::ImgRaw im
+ i_img_dim *xo
+ i_img_dim *yo
+ i_color *ac
+ int dmeasure
PREINIT:
- int num;
- i_img_dim *xo;
- i_img_dim *yo;
- i_color *ival;
- int dmeasure;
- int i;
- SV *sv;
- AV *axx;
- AV *ayy;
- AV *ac;
+ STRLEN size_xo;
+ STRLEN size_yo;
+ STRLEN size_ac;
CODE:
- if (items != 5)
- croak("Usage: i_gradgen(im, xo, yo, ival, dmeasure)");
- if (!SvROK(ST(1)) || ! SvTYPE(SvRV(ST(1))))
- croak("i_gradgen: Second argument must be an array ref");
- if (!SvROK(ST(2)) || ! SvTYPE(SvRV(ST(2))))
- croak("i_gradgen: Third argument must be an array ref");
- if (!SvROK(ST(3)) || ! SvTYPE(SvRV(ST(3))))
- croak("i_gradgen: Fourth argument must be an array ref");
- axx = (AV *)SvRV(ST(1));
- ayy = (AV *)SvRV(ST(2));
- ac = (AV *)SvRV(ST(3));
- dmeasure = (int)SvIV(ST(4));
-
- num = av_len(axx) < av_len(ayy) ? av_len(axx) : av_len(ayy);
- num = num <= av_len(ac) ? num : av_len(ac);
- num++;
- if (num < 2) croak("Usage: i_gradgen array refs must have more than 1 entry each");
- xo = mymalloc( sizeof(i_img_dim) * num );
- yo = mymalloc( sizeof(i_img_dim) * num );
- ival = mymalloc( sizeof(i_color) * num );
- for(i = 0; i<num; i++) {
- xo[i] = (i_img_dim)SvIV(* av_fetch(axx, i, 0));
- yo[i] = (i_img_dim)SvIV(* av_fetch(ayy, i, 0));
- sv = *av_fetch(ac, i, 0);
- if ( !sv_derived_from(sv, "Imager::Color") ) {
- free(axx); free(ayy); free(ac);
- croak("i_gradgen: Element of fourth argument is not derived from Imager::Color");
- }
- ival[i] = *INT2PTR(i_color *, SvIV((SV *)SvRV(sv)));
- }
- i_gradgen(im, num, xo, yo, ival, dmeasure);
- myfree(xo);
- myfree(yo);
- myfree(ival);
+ if (size_xo != size_yo || size_xo != size_ac)
+ croak("i_gradgen: x, y and color arrays must be the same size");
+ if (size_xo < 2)
+ croak("Usage: i_gradgen array refs must have more than 1 entry each");
+ i_gradgen(im, size_xo, xo, yo, ac, dmeasure);
Imager::ImgRaw
i_diff_image(im, im2, mindist=0)
DSO_call(handle,func_index,hv)
void* handle
int func_index
- PREINIT:
- HV* hv;
+ HV *hv
PPCODE:
- if (!SvROK(ST(2))) croak("Imager: Parameter 2 must be a reference to a hash\n");
- hv=(HV*)SvRV(ST(2));
- if (SvTYPE(hv)!=SVt_PVHV) croak("Imager: Parameter 2 must be a reference to a hash\n");
DSO_call( (DSO_handle *)handle,func_index,hv);
-SV *
+Imager::Color
i_get_pixel(im, x, y)
Imager::ImgRaw im
i_img_dim x
i_img_dim y;
- PREINIT:
- i_color *color;
CODE:
- color = (i_color *)mymalloc(sizeof(i_color));
- if (i_gpix(im, x, y, color) == 0) {
- RETVAL = NEWSV(0, 0);
- sv_setref_pv(RETVAL, "Imager::Color", (void *)color);
- }
- else {
- myfree(color);
- RETVAL = &PL_sv_undef;
+ RETVAL = (i_color *)mymalloc(sizeof(i_color));
+ if (i_gpix(im, x, y, RETVAL) != 0) {
+ myfree(RETVAL);
+ XSRETURN_UNDEF;
}
OUTPUT:
RETVAL
}
else {
myfree(imgs);
- croak("Image %d is not an image object", i+1);
+ croak("Image %d is not an image object", (int)i+1);
}
}
memset(&quant, 0, sizeof(quant));
OUTPUT:
RETVAL
-SV *
+SysRet
i_addcolors(im, ...)
Imager::ImgRaw im
PREINIT:
- int index;
i_color *colors;
int i;
CODE:
croak("i_addcolor: pixels must be Imager::Color objects");
}
}
- index = i_addcolors(im, colors, items-1);
- myfree(colors);
- if (index == 0) {
- RETVAL = newSVpv("0 but true", 0);
- }
- else if (index == -1) {
- RETVAL = &PL_sv_undef;
- }
- else {
- RETVAL = newSViv(index);
- }
+ RETVAL = i_addcolors(im, colors, items-1);
OUTPUT:
RETVAL
RETVAL
void
-i_getcolors(im, index, ...)
+i_getcolors(im, index, count=1)
Imager::ImgRaw im
int index
+ int count
PREINIT:
i_color *colors;
- int count = 1;
int i;
PPCODE:
- if (items > 3)
- croak("i_getcolors: too many arguments");
- if (items == 3)
- count = SvIV(ST(2));
if (count < 1)
croak("i_getcolors: count must be positive");
- colors = mymalloc(sizeof(i_color) * count);
+ colors = malloc_temp(aTHX_ sizeof(i_color) * count);
if (i_getcolors(im, index, colors, count)) {
+ EXTEND(SP, count);
for (i = 0; i < count; ++i) {
SV *sv = make_i_color_sv(aTHX_ colors+i);
PUSHs(sv);
}
}
- myfree(colors);
-
undef_neg_int
i_colorcount(im)
i_maxcolors(im)
Imager::ImgRaw im
-SV *
+i_palidx
i_findcolor(im, color)
Imager::ImgRaw im
Imager::Color color
- PREINIT:
- i_palidx index;
CODE:
- if (i_findcolor(im, color, &index)) {
- RETVAL = newSViv(index);
- }
- else {
- RETVAL = &PL_sv_undef;
+ if (!i_findcolor(im, color, &RETVAL)) {
+ XSRETURN_UNDEF;
}
OUTPUT:
RETVAL
Imager::ImgRaw im
void
-i_gsamp(im, l, r, y, ...)
+i_gsamp(im, l, r, y, channels)
Imager::ImgRaw im
i_img_dim l
i_img_dim r
i_img_dim y
+ i_channel_list channels
PREINIT:
- int *chans;
- int chan_count;
i_sample_t *data;
i_img_dim count, i;
PPCODE:
- if (items < 5)
- croak("No channel numbers supplied to g_samp()");
if (l < r) {
- chan_count = items - 4;
- chans = mymalloc(sizeof(int) * chan_count);
- for (i = 0; i < chan_count; ++i)
- chans[i] = SvIV(ST(i+4));
- data = mymalloc(sizeof(i_sample_t) * (r-l) * chan_count); /* XXX: memleak? */
- count = i_gsamp(im, l, r, y, data, chans, chan_count);
- myfree(chans);
+ data = mymalloc(sizeof(i_sample_t) * (r-l) * channels.count);
+ count = i_gsamp(im, l, r, y, data, channels.channels, channels.count);
if (GIMME_V == G_ARRAY) {
EXTEND(SP, count);
for (i = 0; i < count; ++i)
}
else {
if (GIMME_V != G_ARRAY) {
- EXTEND(SP, 1);
- PUSHs(&PL_sv_undef);
+ XSRETURN_UNDEF;
}
}
undef_neg_int
-i_gsamp_bits(im, l, r, y, bits, target, offset, ...)
+i_gsamp_bits(im, l, r, y, bits, target, offset, channels)
Imager::ImgRaw im
i_img_dim l
i_img_dim r
int bits
AV *target
STRLEN offset
+ i_channel_list channels
PREINIT:
- int *chans;
- int chan_count;
unsigned *data;
i_img_dim count, i;
CODE:
if (items < 8)
croak("No channel numbers supplied to g_samp()");
if (l < r) {
- chan_count = items - 7;
- chans = mymalloc(sizeof(int) * chan_count);
- for (i = 0; i < chan_count; ++i)
- chans[i] = SvIV(ST(i+7));
- data = mymalloc(sizeof(unsigned) * (r-l) * chan_count);
- count = i_gsamp_bits(im, l, r, y, data, chans, chan_count, bits);
- myfree(chans);
+ data = mymalloc(sizeof(unsigned) * (r-l) * channels.count);
+ count = i_gsamp_bits(im, l, r, y, data, channels.channels, channels.count, bits);
for (i = 0; i < count; ++i) {
av_store(target, i+offset, newSVuv(data[i]));
}
RETVAL
undef_neg_int
-i_psamp_bits(im, l, y, bits, channels_sv, data_av, data_offset = 0, pixel_count = -1)
+i_psamp_bits(im, l, y, bits, channels, data_av, data_offset = 0, pixel_count = -1)
Imager::ImgRaw im
i_img_dim l
i_img_dim y
int bits
- SV *channels_sv
+ i_channel_list channels
AV *data_av
- int data_offset
- int pixel_count
+ i_img_dim data_offset
+ i_img_dim pixel_count
PREINIT:
- int chan_count;
- int *channels;
STRLEN data_count;
size_t data_used;
unsigned *data;
ptrdiff_t i;
CODE:
i_clear_error();
- if (SvOK(channels_sv)) {
- AV *channels_av;
- if (!SvROK(channels_sv) || SvTYPE(SvRV(channels_sv)) != SVt_PVAV) {
- croak("channels is not an array ref");
- }
- channels_av = (AV *)SvRV(channels_sv);
- chan_count = av_len(channels_av) + 1;
- if (chan_count < 1) {
- croak("i_psamp_bits: no channels provided");
- }
- channels = mymalloc(sizeof(int) * chan_count);
- for (i = 0; i < chan_count; ++i)
- channels[i] = SvIV(*av_fetch(channels_av, i, 0));
- }
- else {
- chan_count = im->channels;
- channels = NULL;
- }
data_count = av_len(data_av) + 1;
if (data_offset < 0) {
- croak("data_offset must by non-negative");
+ croak("data_offset must be non-negative");
}
if (data_offset > data_count) {
croak("data_offset greater than number of samples supplied");
}
if (pixel_count == -1 ||
- data_offset + pixel_count * chan_count > data_count) {
- pixel_count = (data_count - data_offset) / chan_count;
+ data_offset + pixel_count * channels.count > data_count) {
+ pixel_count = (data_count - data_offset) / channels.count;
}
- data_used = pixel_count * chan_count;
+ data_used = pixel_count * channels.count;
data = mymalloc(sizeof(unsigned) * data_count);
for (i = 0; i < data_used; ++i)
data[i] = SvUV(*av_fetch(data_av, data_offset + i, 0));
- RETVAL = i_psamp_bits(im, l, l + pixel_count, y, data, channels,
- chan_count, bits);
+ RETVAL = i_psamp_bits(im, l, l + pixel_count, y, data, channels.channels,
+ channels.count, bits);
if (data)
myfree(data);
- if (channels)
- myfree(channels);
OUTPUT:
RETVAL
+undef_neg_int
+i_psamp(im, x, y, channels, data, offset = 0, width = -1)
+ Imager::ImgRaw im
+ i_img_dim x
+ i_img_dim y
+ i_channel_list channels
+ i_sample_list data
+ i_img_dim offset
+ i_img_dim width
+ PREINIT:
+ i_img_dim r;
+ CODE:
+ i_clear_error();
+ if (offset < 0) {
+ i_push_error(0, "offset must be non-negative");
+ XSRETURN_UNDEF;
+ }
+ if (offset > 0) {
+ if (offset > data.count) {
+ i_push_error(0, "offset greater than number of samples supplied");
+ XSRETURN_UNDEF;
+ }
+ data.samples += offset;
+ data.count -= offset;
+ }
+ if (width == -1 ||
+ width * channels.count > data.count) {
+ width = data.count / channels.count;
+ }
+ r = x + width;
+ RETVAL = i_psamp(im, x, r, y, data.samples, channels.channels, channels.count);
+ OUTPUT:
+ RETVAL
+
+undef_neg_int
+i_psampf(im, x, y, channels, data, offset = 0, width = -1)
+ Imager::ImgRaw im
+ i_img_dim x
+ i_img_dim y
+ i_channel_list channels
+ i_fsample_list data
+ i_img_dim offset
+ i_img_dim width
+ PREINIT:
+ i_img_dim r;
+ CODE:
+ i_clear_error();
+ if (offset < 0) {
+ i_push_error(0, "offset must be non-negative");
+ XSRETURN_UNDEF;
+ }
+ if (offset > 0) {
+ if (offset > data.count) {
+ i_push_error(0, "offset greater than number of samples supplied");
+ XSRETURN_UNDEF;
+ }
+ data.samples += offset;
+ data.count -= offset;
+ }
+ if (width == -1 ||
+ width * channels.count > data.count) {
+ width = data.count / channels.count;
+ }
+ r = x + width;
+ RETVAL = i_psampf(im, x, r, y, data.samples, channels.channels, channels.count);
+ OUTPUT:
+ RETVAL
+
Imager::ImgRaw
i_img_masked_new(targ, mask, x, y, w, h)
Imager::ImgRaw targ
Imager::Color::Float cl
void
-i_gsampf(im, l, r, y, ...)
+i_gsampf(im, l, r, y, channels)
Imager::ImgRaw im
i_img_dim l
i_img_dim r
i_img_dim y
+ i_channel_list channels
PREINIT:
- int *chans;
- int chan_count;
i_fsample_t *data;
i_img_dim count, i;
PPCODE:
- if (items < 5)
- croak("No channel numbers supplied to g_sampf()");
if (l < r) {
- chan_count = items - 4;
- chans = mymalloc(sizeof(int) * chan_count);
- for (i = 0; i < chan_count; ++i)
- chans[i] = SvIV(ST(i+4));
- data = mymalloc(sizeof(i_fsample_t) * (r-l) * chan_count);
- count = i_gsampf(im, l, r, y, data, chans, chan_count);
- myfree(chans);
+ data = mymalloc(sizeof(i_fsample_t) * (r-l) * channels.count);
+ count = i_gsampf(im, l, r, y, data, channels.channels, channels.count);
if (GIMME_V == G_ARRAY) {
EXTEND(SP, count);
for (i = 0; i < count; ++i)
}
else {
if (GIMME_V != G_ARRAY) {
- EXTEND(SP, 1);
- PUSHs(&PL_sv_undef);
+ XSRETURN_UNDEF;
}
}
OUTPUT:
RETVAL
-SV *
+Imager::Color::Float
i_gpixf(im, x, y)
Imager::ImgRaw im
i_img_dim x
i_img_dim y;
- PREINIT:
- i_fcolor *color;
CODE:
- color = (i_fcolor *)mymalloc(sizeof(i_fcolor));
- if (i_gpixf(im, x, y, color) == 0) {
- RETVAL = NEWSV(0,0);
- sv_setref_pv(RETVAL, "Imager::Color::Float", (void *)color);
- }
- else {
- myfree(color);
- RETVAL = &PL_sv_undef;
+ RETVAL = (i_fcolor *)mymalloc(sizeof(i_fcolor));
+ if (i_gpixf(im, x, y, RETVAL) != 0) {
+ myfree(RETVAL);
+ XSRETURN_UNDEF;
}
OUTPUT:
RETVAL
myfree(vals);
}
+Imager::ImgRaw
+i_img_8_new(x, y, ch)
+ i_img_dim x
+ i_img_dim y
+ int ch
+
Imager::ImgRaw
i_img_16_new(x, y, ch)
i_img_dim x
Imager::ImgRaw im
undef_int
-i_tags_addn(im, name, code, idata)
+i_tags_addn(im, name_sv, code, idata)
Imager::ImgRaw im
+ SV *name_sv
int code
int idata
PREINIT:
char *name;
STRLEN len;
CODE:
- if (SvOK(ST(1)))
- name = SvPV(ST(1), len);
+ SvGETMAGIC(name_sv);
+ if (SvOK(name_sv))
+ name = SvPV_nomg(name_sv, len);
else
name = NULL;
RETVAL = i_tags_addn(&im->tags, name, code, idata);
RETVAL
undef_int
-i_tags_add(im, name, code, data, idata)
+i_tags_add(im, name_sv, code, data_sv, idata)
Imager::ImgRaw im
+ SV *name_sv
int code
+ SV *data_sv
int idata
PREINIT:
char *name;
char *data;
STRLEN len;
CODE:
- if (SvOK(ST(1)))
- name = SvPV(ST(1), len);
+ SvGETMAGIC(name_sv);
+ if (SvOK(name_sv))
+ name = SvPV_nomg(name_sv, len);
else
name = NULL;
- if (SvOK(ST(3)))
- data = SvPV(ST(3), len);
+ SvGETMAGIC(data_sv);
+ if (SvOK(data_sv))
+ data = SvPV(data_sv, len);
else {
data = NULL;
len = 0;
OUTPUT:
RETVAL
-SV *
+SysRet
i_tags_find(im, name, start)
Imager::ImgRaw im
char *name
int entry;
CODE:
if (i_tags_find(&im->tags, name, start, &entry)) {
- if (entry == 0)
- RETVAL = newSVpv("0 but true", 0);
- else
- RETVAL = newSViv(entry);
+ RETVAL = entry;
} else {
- RETVAL = &PL_sv_undef;
+ XSRETURN_UNDEF;
}
OUTPUT:
RETVAL
-SV *
+SysRet
i_tags_findn(im, code, start)
Imager::ImgRaw im
int code
int entry;
CODE:
if (i_tags_findn(&im->tags, code, start, &entry)) {
- if (entry == 0)
- RETVAL = newSVpv("0 but true", 0);
- else
- RETVAL = newSViv(entry);
+ RETVAL = entry;
}
else {
- RETVAL = &PL_sv_undef;
+ XSRETURN_UNDEF;
}
OUTPUT:
RETVAL
int combine
Imager::FillHandle
-i_new_fill_hatch(fg, bg, combine, hatch, cust_hatch, dx, dy)
+i_new_fill_hatch(fg, bg, combine, hatch, cust_hatch_sv, dx, dy)
Imager::Color fg
Imager::Color bg
int combine
int hatch
+ SV *cust_hatch_sv
i_img_dim dx
i_img_dim dy
PREINIT:
unsigned char *cust_hatch;
STRLEN len;
CODE:
- if (SvOK(ST(4))) {
- cust_hatch = (unsigned char *)SvPV(ST(4), len);
+ SvGETMAGIC(cust_hatch_sv);
+ if (SvOK(cust_hatch_sv)) {
+ cust_hatch = (unsigned char *)SvPV_nomg(cust_hatch_sv, len);
}
else
cust_hatch = NULL;
RETVAL
Imager::FillHandle
-i_new_fill_hatchf(fg, bg, combine, hatch, cust_hatch, dx, dy)
+i_new_fill_hatchf(fg, bg, combine, hatch, cust_hatch_sv, dx, dy)
Imager::Color::Float fg
Imager::Color::Float bg
int combine
int hatch
+ SV *cust_hatch_sv
i_img_dim dx
i_img_dim dy
PREINIT:
unsigned char *cust_hatch;
STRLEN len;
CODE:
- if (SvOK(ST(4))) {
- cust_hatch = (unsigned char *)SvPV(ST(4), len);
+ SvGETMAGIC(cust_hatch_sv);
+ if (SvOK(cust_hatch_sv)) {
+ cust_hatch = (unsigned char *)SvPV(cust_hatch_sv, len);
}
else
cust_hatch = NULL;
RETVAL
Imager::FillHandle
-i_new_fill_image(src, matrix, xoff, yoff, combine)
+i_new_fill_image(src, matrix_sv, xoff, yoff, combine)
Imager::ImgRaw src
+ SV *matrix_sv
i_img_dim xoff
i_img_dim yoff
int combine
SV *sv1;
int i;
CODE:
- if (!SvOK(ST(1))) {
+ SvGETMAGIC(matrix_sv);
+ if (!SvOK(matrix_sv)) {
matrixp = NULL;
}
else {
- if (!SvROK(ST(1)) || SvTYPE(SvRV(ST(1))) != SVt_PVAV)
- croak("i_new_fill_image: parameter must be an arrayref");
- av=(AV*)SvRV(ST(1));
+ if (!SvROK(matrix_sv) || SvTYPE(SvRV(matrix_sv)) != SVt_PVAV)
+ croak("i_new_fill_image: matrix parameter must be an arrayref or undef");
+ av=(AV*)SvRV(matrix_sv);
len=av_len(av)+1;
if (len > 9)
len = 9;
#endif
+MODULE = Imager PACKAGE = Imager::Context PREFIX=im_context_
+
+void
+im_context_DESTROY(ctx)
+ Imager::Context ctx
+
+#ifdef PERL_IMPLICIT_CONTEXT
+
+void
+im_context_CLONE(...)
+ CODE:
+ MY_CXT_CLONE;
+ (void)items;
+ /* the following sv_setref_pv() will free this inc */
+ im_context_refinc(MY_CXT.ctx, "CLONE");
+ MY_CXT.ctx = im_context_clone(MY_CXT.ctx, "CLONE");
+ sv_setref_pv(get_sv("Imager::_context", GV_ADD), "Imager::Context", MY_CXT.ctx);
+
+#endif
+
BOOT:
PERL_SET_GLOBAL_CALLBACKS;
PERL_PL_SET_GLOBAL_CALLBACKS;
+#ifdef PERL_IMPLICIT_CONTEXT
+ {
+ MY_CXT_INIT;
+ (void)MY_CXT;
+ }
+#endif
+ start_context(aTHX);
+ im_get_context = perl_get_context;
+#ifdef HAVE_LIBTT
+ i_tt_start();
+#endif