- explicitly document there are no PNG specific tags.
- more examples in Imager::Draw
- minor cleanup of Imager::Fill
+- eliminate unused variables and static functions
+- simplify some XS code by adding another typemap entry
=================================================================
typedef i_color* Imager__Color;
typedef i_fcolor* Imager__Color__Float;
typedef i_img* Imager__ImgRaw;
+typedef int undef_neg_int;
#ifdef HAVE_LIBTT
typedef TT_Fonthandle* Imager__Font__TT;
{ "custom", od_custom, },
};
+#if 0
static int
hv_fetch_bool(HV *hv, char *name, int def) {
SV **sv;
else
return def;
}
+#endif
/* look through the hash for quantization options */
static void handle_quant_opts(i_quantize *quant, HV *hv)
*/
int i, j;
AV *aseg;
- SV *sv;
i_fountain_seg *segs;
double work[3];
int worki[2];
RETVAL
-undef_int
+void
i_tt_bbox(handle,point,str_sv,len_ignored, utf8)
Imager::Font::TT handle
float point
i_readgif_callback(...)
PROTOTYPE: &
PREINIT:
- char* data;
- int length;
int* colour_table;
int colours, q, w;
i_img* rimg;
-# this is mostly for testing...
-# this function results in 'RETVAL' : unreferenced local variable
-# in VC++, and might be subtley wrong
-# the most obvious change may result in a double free so I'm leaving it
-# for now
SV *
i_get_pixel(im, x, y)
Imager::ImgRaw im
CODE:
color = (i_color *)mymalloc(sizeof(i_color));
if (i_gpix(im, x, y, color) == 0) {
- ST(0) = sv_newmortal();
- sv_setref_pv(ST(0), "Imager::Color", (void *)color);
+ RETVAL = NEWSV(0, 0);
+ sv_setref_pv(RETVAL, "Imager::Color", (void *)color);
}
else {
myfree(color);
- ST(0) = &PL_sv_undef;
+ RETVAL = &PL_sv_undef;
}
+ OUTPUT:
+ RETVAL
int
index = i_addcolors(im, colors, items-1);
myfree(colors);
if (index == 0) {
- ST(0) = sv_2mortal(newSVpv("0 but true", 0));
+ RETVAL = newSVpv("0 but true", 0);
}
else if (index == -1) {
- ST(0) = &PL_sv_undef;
+ RETVAL = &PL_sv_undef;
}
else {
- ST(0) = sv_2mortal(newSViv(index));
+ RETVAL = newSViv(index);
}
+ OUTPUT:
+ RETVAL
undef_int
i_setcolors(im, index, ...)
myfree(colors);
-SV *
+undef_neg_int
i_colorcount(im)
Imager::ImgRaw im
- PREINIT:
- int count;
- CODE:
- count = i_colorcount(im);
- if (count >= 0) {
- ST(0) = sv_2mortal(newSViv(count));
- }
- else {
- ST(0) = &PL_sv_undef;
- }
-SV *
+undef_neg_int
i_maxcolors(im)
Imager::ImgRaw im
- PREINIT:
- int count;
- CODE:
- count = i_maxcolors(im);
- if (count >= 0) {
- ST(0) = sv_2mortal(newSViv(count));
- }
- else {
- ST(0) = &PL_sv_undef;
- }
SV *
i_findcolor(im, color)
i_palidx index;
CODE:
if (i_findcolor(im, color, &index)) {
- ST(0) = sv_2mortal(newSViv(index));
+ RETVAL = newSViv(index);
}
else {
- ST(0) = &PL_sv_undef;
+ RETVAL = &PL_sv_undef;
}
+ OUTPUT:
+ RETVAL
int
i_img_bits(im)
CODE:
color = (i_fcolor *)mymalloc(sizeof(i_fcolor));
if (i_gpixf(im, x, y, color) == 0) {
- ST(0) = sv_newmortal();
- sv_setref_pv(ST(0), "Imager::Color::Float", (void *)color);
+ RETVAL = NEWSV(0,0);
+ sv_setref_pv(RETVAL, "Imager::Color::Float", (void *)color);
}
else {
myfree(color);
- ST(0) = &PL_sv_undef;
+ RETVAL = &PL_sv_undef;
}
-
+ OUTPUT:
+ RETVAL
+
void
i_glin(im, l, r, y)
Imager::ImgRaw im
CODE:
if (i_tags_find(&im->tags, name, start, &entry)) {
if (entry == 0)
- ST(0) = sv_2mortal(newSVpv("0 but true", 0));
+ RETVAL = newSVpv("0 but true", 0);
else
- ST(0) = sv_2mortal(newSViv(entry));
+ RETVAL = newSViv(entry);
} else {
- ST(0) = &PL_sv_undef;
+ RETVAL = &PL_sv_undef;
}
+ OUTPUT:
+ RETVAL
SV *
i_tags_findn(im, code, start)
CODE:
if (i_tags_findn(&im->tags, code, start, &entry)) {
if (entry == 0)
- ST(0) = sv_2mortal(newSVpv("0 but true", 0));
+ RETVAL = newSVpv("0 but true", 0);
else
- ST(0) = sv_2mortal(newSViv(entry));
+ RETVAL = newSViv(entry);
}
- else
- ST(0) = &PL_sv_undef;
+ else {
+ RETVAL = &PL_sv_undef;
+ }
+ OUTPUT:
+ RETVAL
int
i_tags_delete(im, entry)
write_8bit_data(io_glue *ig, i_img *im) {
i_palidx *line;
int line_size = im->xsize;
- int x, y;
+ int y;
/* round up to nearest multiple of four */
line_size = (line_size + 3) / 4 * 4;
write_24bit_data(io_glue *ig, i_img *im) {
int *chans;
unsigned char *samples;
- int x, y;
+ int y;
int line_size = 3 * im->xsize;
line_size = (line_size + 3) / 4 * 4;
i_palidx *line, *p;
unsigned char *packed;
int line_size = (xsize + 7)/8;
- int byte, bit;
+ int bit;
unsigned char *in;
long base_offset;
}
else if (compression == BI_RLE4) {
int read_size;
- int want_high;
int count;
i_tags_add(&im->tags, "bmp_compression_name", 0, "BI_RLE4", -1, 0);
int compression, long offbits) {
i_img *im;
int x, y, lasty, yinc;
- i_palidx *line, *p;
+ i_palidx *line;
int line_size = xsize;
- unsigned char *in;
long base_offset;
line_size = (line_size+3) / 4 * 4;
}
else if (compression == BI_RLE8) {
int read_size;
- int want_high;
int count;
unsigned char packed[2];
i_img *im;
int x, y, lasty, yinc;
i_color *line, *p;
- unsigned char *in;
int pix_size = bit_count / 8;
int line_size = xsize * pix_size;
struct bm_masks masks;
polar_to_plane(x, y, angle, radius, &sx, &sy);
for(angle = 0.0; angle<361; angle +=astep) {
- float alpha;
lx = sx; ly = sy;
polar_to_plane(x, y, angle, radius, &cx, &cy);
sx = cx; sy = cy;
make_minmax_list(&dot, x, y, rad);
for(ly = 0; ly<im->ysize; ly++) {
- int ix, cy, cnt = 0, minx = INT_MAX, maxx = INT_MIN;
+ int ix, cy, minx = INT_MAX, maxx = INT_MIN;
/* Find the left/rightmost set subpixels */
for(cy = 0; cy<16; cy++) {
int x, y;
int dx, dy;
int p;
- unsigned char *cp;
dx = x2 - x1;
dy = y2 - y1;
int x, y;
int dx, dy;
int p;
- unsigned char *cp;
dx = x2 - x1;
dy = y2 - y1;
int i_mmarray_gmin(i_mmarray *ar,int y);
int i_mmarray_getm(i_mmarray *ar,int y);
void i_mmarray_render(i_img *im,i_mmarray *ar,i_color *val);
-static void i_arcdraw(int x1, int y1, int x2, int y2, i_mmarray *ar);
void i_mmarray_info(i_mmarray *ar);
void i_arc(i_img *im,int x,int y,float rad,float d1,float d2,i_color *val);
void i_box(i_img *im,int x0,int y0,int x1,int y1,i_color *val);
i_color *data) {
struct i_fill_image_t *f = (struct i_fill_image_t *)fill;
int i = 0;
- i_color c;
i_color *out = data;
if (f->has_matrix) {
i_fcolor *data) {
struct i_fill_image_t *f = (struct i_fill_image_t *)fill;
int i = 0;
- i_fcolor c;
if (f->has_matrix) {
/* the hard way */
int ch;
while (count--) {
- i_color c = *in;
double mult[MAXCHANNELS];
mult[3] = in->channel[3];
for (ch = 0; ch < (channels); ++ch) {
}
static void combine_dissolve(i_color *out, i_color *in, int channels, int count) {
- int ch;
-
while (count--) {
if (in->channel[3] > rand() * (255.0 / RAND_MAX))
COMBINE(*out, *in, channels);
}
static void combine_dissolvef(i_fcolor *out, i_fcolor *in, int channels, int count) {
- int ch;
-
while (count--) {
if (in->channel[3] > rand() * (1.0 / RAND_MAX))
COMBINEF(*out, *in, channels);
i_img *out;
int outchans, diffchans;
int xsize, ysize;
- i_img temp;
i_clear_error();
if (im1->channels != im2->channels) {
while (len) {
unsigned long c;
- int index;
if (utf8) {
c = i_utf8_advance(&text, &len);
if (c == ~0UL) {
i_tt_has_chars(TT_Fonthandle *handle, char const *text, int len, int utf8,
char *out) {
int count = 0;
- int inst;
mm_log((1, "i_tt_has_chars(handle %p, text %p, len %d, utf8 %d)\n",
handle, text, len, utf8));
TT_Raster_Map *small_bit, int cords[6],
char const* txt, int len, int smooth, int utf8 ) {
unsigned long j;
- int i;
TT_F26Dot6 x,y;
mm_log((1,"i_tt_render_all_glyphs( handle 0x%X, inst %d, bit 0x%X, small_bit 0x%X, txt '%.*s', len %d, smooth %d, utf8 %d)\n",
FT_Error error;
FT2_Fonthandle *result;
FT_Face face;
- double matrix[6] = { 1, 0, 0,
- 0, 1, 0 };
int i, j;
FT_Encoding encoding;
int score;
void ft2_transform_box(FT2_Fonthandle *handle, int bbox[4]) {
double work[8];
double *matrix = handle->matrix;
- int i;
work[0] = matrix[0] * bbox[0] + matrix[1] * bbox[1];
work[1] = matrix[3] * bbox[0] + matrix[4] * bbox[1];
int ascent = 0, descent = 0;
int glyph_ascent, glyph_descent;
FT_Glyph_Metrics *gm;
- int start = 0;
int work[4];
int bounds[4];
double x = 0, y = 0;
int i;
FT_GlyphSlot slot;
- int advx, advy;
int loadFlags = FT_LOAD_DEFAULT;
if (vlayout)
i_img **i_readgif_multi_low(GifFileType *GifFile, int *count) {
i_img *img;
- int i, j, Size, Width, Height, ExtCode, Count, x;
+ int i, j, Size, Width, Height, ExtCode, Count;
int ImageNum = 0, BackGround = 0, ColorMapSize = 0;
ColorMapObject *ColorMap;
has_common_palette(i_img **imgs, int count, i_quantize *quant,
int want_trans) {
int size = quant->mc_count;
- int i, j;
+ int i;
int imgn;
- int x, y;
char used[256];
/* we try to build a common palette here, if we can manage that, then
i_color *orig_colors = quant->mc_colors;
i_color *glob_colors = NULL;
int glob_color_count;
- int glob_map_size;
int glob_want_trans;
int glob_paletted; /* the global map was made from the image palettes */
int colors_paletted;
return buf;
}
-
-
-
-
-
-
void*
myrealloc_file_line(void *ptr, size_t newsize, char* file, int line) {
char *buf;
return buf;
}
-
-
-
static
void
bndcheck(int idx) {
mymalloc(int size) {
void *buf;
+ if (size < 0) {
+ fprintf(stderr, "Attempt to allocate size %d\n", size);
+ exit(3);
+ }
+
if ( (buf = malloc(size)) == NULL ) {
mm_log((1, "mymalloc: unable to malloc %d\n", size));
fprintf(stderr,"Unable to malloc %d.\n", size); exit(3);
ssize_t
buffer_read(io_glue *ig, void *buf, size_t count) {
io_ex_buffer *ieb = ig->exdata;
- char *cbuf = buf;
IOL_DEB( printf("buffer_read: fd = %d, ier->cpos = %ld, buf = %p, count = %d\n", fd, (long) ier->cpos, buf, count) );
undef_int
i_writejpeg_wiol(i_img *im, io_glue *ig, int qfactor) {
- struct stat stbuf;
JSAMPLE *image_buffer;
int quality;
i_map(i_img *im, unsigned char (*maps)[256], unsigned int mask) {
i_color *vals;
int x, y;
- int mapno, i, ch;
+ int i, ch;
int minset = -1, maxset;
mm_log((1,"i_map(im %p, maps %p, chmask %u)\n", im, maps, mask));
*/
static int i_plin_masked(i_img *im, int l, int r, int y, i_color *vals) {
i_img_mask_ext *ext = MASKEXT(im);
- int result;
if (y >= 0 && y < im->ysize && l < im->xsize && l >= 0) {
if (r > im->xsize)
*/
int i_img_to_rgb_inplace(i_img *im) {
i_img temp;
- i_color *pal;
- int palsize;
if (im->virtual)
return 0;
=cut
*/
static int i_plin_p(i_img *im, int l, int r, int y, i_color *vals) {
- int ch, count, i;
+ int count, i;
i_palidx *data;
i_palidx which;
if (y >=0 && y < im->ysize && l < im->xsize && l >= 0) {
volatile int cspace,channels;
double xres, yres;
int aspect_only, have_res;
- double offx, offy;
- char offunit[20] = "pixel";
io_glue_commit_types(ig);
mm_log((1,"i_writepng(im %p ,ig %p)\n", im, ig));
i_writeppm_wiol(i_img *im, io_glue *ig) {
char header[255];
int rc;
- writep write_func;
mm_log((1,"i_writeppm(im %p, ig %p)\n", im, ig));
i_clear_error();
unsigned char *data = mymalloc(3 * im->xsize);
if (data != NULL) {
int y = 0;
- int x, ch;
- unsigned char *p;
static int rgb_chan[3] = { 0, 1, 2 };
rc = 0;
unsigned char *data = mymalloc(im->xsize);
if (data != NULL) {
int y = 0;
- int x, ch;
int chan = 0;
- unsigned char *p;
rc = 0;
while (y < im->ysize && rc >= 0) {
return pset;
}
+#if 0
static
void
p_line_dump(p_line *l) {
printf("%d (%d,%d)->(%d,%d) [%d-%d,%d-%d]\n", l->n, l->x1, l->y1, l->x2, l->y2,
l->minx, l->maxx, l->miny, l->maxy);
}
-
+#endif
static
void
return count;
}
+#if 0
static
int
lines_in_interval_old(p_line *lset, int l, p_slice *tllist, pcord cc) {
}
return count;
}
+#endif
/* marks the up variable for all lines in a slice */
double lycross, rycross;
int l, r;
- double xs, ys;
-
if (!line->updown) {
l = r = 0;
} else {
int thin; /* boolean for thin/thick segment */
int startpix; /* temporary variable for "start of this interval" */
int stoppix; /* temporary variable for "end of this interval" */
- int step2end; /* temporary variable to mark where step2 ends */
/* Find the y bounds of scanline_slice */
}
-
+#if 0
static
void
render_slice_scanline_old(ss_scanline *ss, int y, p_line *l, p_line *r) {
int thin; /* boolean for thin/thick segment */
int startpix; /* temporary variable for "start of this interval" */
int stoppix; /* temporary variable for "end of this interval" */
- int step2end; /* temporary variable to mark where step2 ends */
/* Find the y bounds of scanline_slice */
ss->line[cpix] += (16.0)*(maxy-miny) - pixel_coverage(r, cpix*16, cpix*16+16, miny, maxy);
}
-
-
-
-
-
+#endif
/* Antialiasing polygon algorithm
specs:
i_poly_aa_low(i_img *im, int l, double *x, double *y, void *ctx, scanline_flusher flusher) {
int i ,k; /* Index variables */
int clc; /* Lines inside current interval */
- pcord miny ,maxy; /* Min and max values of the current slice in the subcord system */
pcord tempy;
int cscl; /* Current scanline */
for(i=0; i<l-1; i++) {
int startscan = i_max( coarse(pset[i].y), 0);
int stopscan = i_min( coarse(pset[i+1].y+15), im->ysize);
- pcord cc = (pset[i].y + pset[i+1].y)/2;
if (pset[i].y == pset[i+1].y) {
POLY_DEB( printf("current slice thickness = 0 => skipping\n") );
POLY_DEB( printf("Interval contains %d lines\n", clc) );
for(k=0; k<clc; k++) {
- int lno = tllist[k].n;
- p_line *ln = lset+lno;
POLY_DEB(
printf("%d: line #%2d: (%2d, %2d)->(%2d, %2d) (%2d/%2d, %2d/%2d) -> (%2d/%2d, %2d/%2d) alignment=%s\n",
k, lno, ln->x1, ln->y1, ln->x2, ln->y2,
static void
scanline_flush_cfill(i_img *im, ss_scanline *ss, int y, void *ctx) {
int x, ch, tv;
- i_color t;
int pos;
int left, right;
struct poly_cfill_state *state = (struct poly_cfill_state *)ctx;
}
}
-#ifdef HAVE_LIBGIF
-static void translate_giflib(i_quantize *, i_img *, i_palidx *);
-#endif
static void translate_closest(i_quantize *, i_img *, i_palidx *);
static void translate_errdiff(i_quantize *, i_img *, i_palidx *);
static void translate_addi(i_quantize *, i_img *, i_palidx *);
return rand()/(RAND_MAX+1.0);
}
+#ifdef NOTEF
static
int
eucl_d(cvec* cv,i_color *cl) { return PWR2(cv->r-cl->channel[0])+PWR2(cv->g-cl->channel[1])+PWR2(cv->b-cl->channel[2]); }
+#endif
static
int
welcome.
*/
static void hbsetup(i_quantize *quant, hashbox *hb) {
- long *dists, mind, maxd, cd;
+ long *dists, mind, maxd;
int cr, cb, cg, hbnum, i;
i_color cenc;
#ifdef HB_SORT
int errw;
int difftotal;
int x, y, dx, dy;
- int minr, maxr, ming, maxg, minb, maxb, cr, cg, cb;
- i_color find;
int bst_idx;
CF_VARS;
return(0);
}
} else {
- int y;
-
if (im->type == i_direct_type) {
/* just save it as 8-bits, maybe support saving higher bit count
raw images later */
i_img *
i_readrgb_wiol(io_glue *ig, int length) {
i_img *img;
- int x, y, c,i;
+ int y, c,i;
int width, height, channels;
unsigned long maxlen;
int savemask;
- char *idstring = NULL;
-
rgb_header header;
unsigned char headbuf[512];
unsigned char *databuf;
- unsigned char *reorderbuf;
unsigned long *starttab, *lengthtab;
i_color *linebuf = NULL;
i_mempool mp;
int ch;
int i, j;
double sx, sy, sz;
- double out[3];
if (src->type == i_direct_type) {
if (src->bits == i_8_bits) {
}
static int parse_long(char *data, char **end, long *out) {
-#if 0
- /* I wrote this without thinking about strtol */
- long x = 0;
- int neg = *data == '-';
-
- if (neg)
- ++data;
- if (!isdigit(*data))
- return 0;
- while (isdigit(*data)) {
- /* this check doesn't guarantee we don't overflow, but it helps */
- if (x > LONG_MAX / 10)
- return 0;
- x = x * 10 + *data - '0';
- ++data;
- }
- if (neg)
- x = -x;
-
- *end = data;
-
- return 1;
-#else
long result;
int savederr = errno;
char *myend;
result = strtol(data, &myend, 10);
if ((result == LONG_MIN || result == LONG_MAX) && errno == ERANGE
|| myend == data) {
+ errno = savederr;
return 0;
}
+ errno = savederr;
*out = result;
*end = myend;
return 1;
-#endif
}
/* parse a comma-separated list of integers
static
int
tga_dest_write(tga_dest *s, unsigned char *buf, size_t pixels) {
- int cp = 0, j, k;
+ int cp = 0, j;
if (!s->compressed) {
if (s->ig->writecb(s->ig, buf, pixels*s->bytepp) != pixels*s->bytepp) return 0;
i_img *
i_readtga_wiol(io_glue *ig, int length) {
i_img* img = NULL;
- int x, y, i;
+ int x, y;
int width, height, channels;
int mapped;
char *idstring = NULL;
tga_header header;
unsigned char headbuf[18];
unsigned char *databuf;
- unsigned char *reorderbuf;
i_color *linebuf = NULL;
i_clear_error();
mapped = 1;
switch (header.datatypecode) {
- int tbpp;
case 2: /* Uncompressed, rgb images */
case 10: /* Compressed, rgb images */
mapped = 0;
undef_int
i_writetga_wiol(i_img *img, io_glue *ig, int wierdpack, int compress, char *idstring, size_t idlen) {
- static int rgb_chan[] = { 2, 1, 0, 3 };
tga_header header;
tga_dest dest;
unsigned char headbuf[18];
io_glue_commit_types(ig);
- header.idlength;
header.idlength = idlen;
header.colourmaptype = mapped ? 1 : 0;
header.datatypecode = mapped ? 1 : img->channels == 1 ? 3 : 2;
mm_log((1, "dest.bytepp = %d\n", dest.bytepp));
if (img->type == i_palette_type) {
- int i;
- int bytepp = bpp_to_bytes(bitspp);
if (!tga_palette_write(ig, img, bitspp, i_colorcount(img))) return 0;
if (!img->virtual && !dest.compressed) {
=cut
*/
-
#define byteswap_macro(x) \
((((x) & 0xff000000) >> 24) | (((x) & 0x00ff0000) >> 8) | \
(((x) & 0x0000ff00) << 8) | (((x) & 0x000000ff) << 24))
uint32 y;
int rc;
uint32 x;
- int luma_mask;
uint32 rowsperstrip;
float vres = fine ? 196 : 98;
int luma_chan;
tsize_t linebytes;
int ch, ci, rc;
uint32 x;
- int got_xres, got_yres, got_aspectonly, aspect_only, resunit;
+ int got_xres, got_yres, aspect_only, resunit;
double xres, yres;
uint16 bitspersample = 8;
uint16 samplesperpixel;
i_color c;
int count = i_colorcount(im);
int size;
- int bits;
int ch, i;
samplesperpixel = 1;
undef_int
i_writetiff_wiol(i_img *img, io_glue *ig) {
TIFF* tif;
- int i;
io_glue_commit_types(ig);
i_clear_error();
undef_int
i_writetiff_wiol_faxable(i_img *im, io_glue *ig, int fine) {
TIFF* tif;
- int i;
io_glue_commit_types(ig);
i_clear_error();
float T_FLOAT
float* T_ARRAY
undef_int T_IV_U
+undef_neg_int T_IV_NEGU
HASH T_HVREF
utf8_str T_UTF8_STR
#############################################################################
T_IV_U
if ($var == 0) $arg=&PL_sv_undef;
else sv_setiv($arg, (IV)$var);
+T_IV_NEGU
+ if ($var < 0) $arg=&PL_sv_undef;
+ else sv_setiv($arg, (IV)$var);
T_PTR_NULL
sv_setiv($arg, (IV)$var);