Skip to content

Commit

Permalink
switch to using size_t and i_img_dim strictly
Browse files Browse the repository at this point in the history
Also, use double instead of float where the value is used in
calculating a co-ordinate, since float may not be able to represent an
image ordinate with sufficient precision
  • Loading branch information
tonycoz committed Aug 8, 2011
1 parent bd80e51 commit 8d14daa
Show file tree
Hide file tree
Showing 98 changed files with 5,108 additions and 1,859 deletions.
34 changes: 34 additions & 0 deletions Changes
Original file line number Diff line number Diff line change
@@ -1,5 +1,39 @@
Imager release history. Older releases can be found in Changes.old

Imager 0.85
===========

Massive types re-work:

- the type used internally for pixel co-ordinates and image sizes is
now 64-bit on 64-bit platforms (at least sane ones).

- size_t is now used consistently for memory block sizes.

- since this changes the binary interface, the Imager API version has
been incremented. Any module that uses the API will need to be
rebuilt. In most cases that will be enough, but calls to any APIs
that take a pointer to image sizes may need source changes.

- you should be able to create very large images on 64-bit systems,
if you have enough memory. Successfully created a 32768 x 49192 x
3 channel image, filled with a tiled image and scaled it. The
unscaled image was also successfully saved to a JPEG.

- check the image size before attempting to write BMP, GIF, JPEG,
PNG, SGI, TGA, TIFF images.

- correctly handle reading TGA images over 32767 pixels wide or tall.

Incidental changes:

- the gif_left and gif_top tags are now clamped to non-negative
values when writing a GIF image.

- removed dead callback read/write code

The default maximum memory size when reading files is now 1G.

Imager 0.84 - 20 Jun 2011
===========

Expand Down
3 changes: 2 additions & 1 deletion CountColor/CountColor.xs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ DEFINE_IMAGER_CALLBACKS;

int
count_color(i_img *im, i_color *color) {
int x, y, chan;
i_img_dim x, y;
int chan;
i_color c;
int count = 0;

Expand Down
7 changes: 2 additions & 5 deletions DynTest/linstretch.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,11 @@ saturate(int in) {
void lin_stretch(i_img *im, int a, int b) {

i_color rcolor;
int i,bytes,x,y;
int info[4];
i_img_dim x,y;
int i;


/* fprintf(stderr,"parameters: (im 0x%x,a %d,b %d)\n",im,a,b);*/
bytes=im->bytes;

i_img_info(im,info);

for(y=0;y<im->ysize;y++) for(x=0;x<im->xsize;x++) {
i_gpix(im,x,y,&rcolor);
Expand Down
29 changes: 15 additions & 14 deletions FT2/FT2.xs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ FT2_DESTROY(font)
int
FT2_CLONE_SKIP(...)
CODE:
(void)items;
RETVAL = 1;
OUTPUT:
RETVAL
Expand Down Expand Up @@ -90,7 +91,7 @@ i_ft2_bbox(font, cheight, cwidth, text_sv, utf8)
SV *text_sv
int utf8
PREINIT:
int bbox[BOUNDING_BOX_COUNT];
i_img_dim bbox[BOUNDING_BOX_COUNT];
int i;
char *text;
STRLEN text_len;
Expand All @@ -117,7 +118,7 @@ i_ft2_bbox_r(font, cheight, cwidth, text, vlayout, utf8)
int vlayout
int utf8
PREINIT:
int bbox[8];
i_img_dim bbox[8];
int i;
PPCODE:
#ifdef SvUTF8
Expand All @@ -135,8 +136,8 @@ undef_int
i_ft2_text(font, im, tx, ty, cl, cheight, cwidth, text, align, aa, vlayout, utf8)
Imager::Font::FT2x font
Imager::ImgRaw im
int tx
int ty
i_img_dim tx
i_img_dim ty
Imager::Color cl
double cheight
double cwidth
Expand All @@ -163,8 +164,8 @@ undef_int
i_ft2_cp(font, im, tx, ty, channel, cheight, cwidth, text_sv, align, aa, vlayout, utf8)
Imager::Font::FT2x font
Imager::ImgRaw im
int tx
int ty
i_img_dim tx
i_img_dim ty
int channel
double cheight
double cwidth
Expand All @@ -190,12 +191,12 @@ i_ft2_cp(font, im, tx, ty, channel, cheight, cwidth, text_sv, align, aa, vlayout
void
ft2_transform_box(font, x0, x1, x2, x3)
Imager::Font::FT2x font
int x0
int x1
int x2
int x3
i_img_dim x0
i_img_dim x1
i_img_dim x2
i_img_dim x3
PREINIT:
int box[4];
i_img_dim box[4];
PPCODE:
box[0] = x0; box[1] = x1; box[2] = x2; box[3] = x3;
ft2_transform_box(font, box);
Expand All @@ -214,8 +215,8 @@ i_ft2_has_chars(handle, text_sv, utf8)
char *text;
STRLEN len;
char *work;
int count;
int i;
size_t count;
size_t i;
PPCODE:
#ifdef SvUTF8
if (SvUTF8(text_sv))
Expand All @@ -241,7 +242,7 @@ i_ft2_face_name(handle)
Imager::Font::FT2x handle
PREINIT:
char name[255];
int len;
size_t len;
PPCODE:
len = i_ft2_face_name(handle, name, sizeof(name));
if (len) {
Expand Down
51 changes: 27 additions & 24 deletions FT2/freetyp2.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ freetyp2.c - font support via the FreeType library version 2.
if (!i_ft2_getdpi(font, &xdpi, &ydpi)) { error }
double matrix[6];
if (!i_ft2_settransform(font, matrix)) { error }
int bbox[BOUNDING_BOX_COUNT];
i_img_dim bbox[BOUNDING_BOX_COUNT];
if (!i_ft2_bbox(font, cheight, cwidth, text, length, bbox, utf8)) { error }
i_img *im = ...;
i_color cl;
Expand Down Expand Up @@ -52,8 +52,8 @@ static void ft2_push_message(int code);
static int ft2_initialized = 0;
static FT_Library library;

static int i_min(int a, int b);
static int i_max(int a, int b);
static i_img_dim i_min(i_img_dim a, i_img_dim b);
static i_img_dim i_max(i_img_dim a, i_img_dim b);

/*
=item i_ft2_init(void)
Expand Down Expand Up @@ -318,7 +318,7 @@ int i_ft2_sethinting(FT2_Fonthandle *handle, int hinting) {
}

/*
=item i_ft2_bbox(FT2_Fonthandle *handle, double cheight, double cwidth, char *text, size_t len, int *bbox)
=item i_ft2_bbox(FT2_Fonthandle *handle, double cheight, double cwidth, char *text, size_t len, i_img_dim *bbox)
Retrieves bounding box information for the font at the given
character width and height. This ignores the transformation matrix.
Expand All @@ -329,9 +329,9 @@ Returns non-zero on success.
*/
int
i_ft2_bbox(FT2_Fonthandle *handle, double cheight, double cwidth,
char const *text, size_t len, int *bbox, int utf8) {
char const *text, size_t len, i_img_dim *bbox, int utf8) {
FT_Error error;
int width;
i_img_dim width;
int index;
int first;
int ascent = 0, descent = 0;
Expand Down Expand Up @@ -439,7 +439,7 @@ too much hard work.
=cut
*/
void ft2_transform_box(FT2_Fonthandle *handle, int bbox[4]) {
void ft2_transform_box(FT2_Fonthandle *handle, i_img_dim bbox[4]) {
double work[8];
double *matrix = handle->matrix;

Expand All @@ -466,15 +466,15 @@ bounding box in bbox[] that encloses both.
=cut
*/
static void expand_bounds(int bbox[4], int bbox2[4]) {
static void expand_bounds(i_img_dim bbox[4], i_img_dim bbox2[4]) {
bbox[0] = i_min(bbox[0], bbox2[0]);
bbox[1] = i_min(bbox[1], bbox2[1]);
bbox[2] = i_max(bbox[2], bbox2[2]);
bbox[3] = i_max(bbox[3], bbox2[3]);
}

/*
=item i_ft2_bbox_r(FT2_Fonthandle *handle, double cheight, double cwidth, char *text, size_t len, int vlayout, int utf8, int *bbox)
=item i_ft2_bbox_r(FT2_Fonthandle *handle, double cheight, double cwidth, char *text, size_t len, int vlayout, int utf8, i_img_dim *bbox)
Retrieves bounding box information for the font at the given
character width and height.
Expand All @@ -495,16 +495,16 @@ Returns non-zero on success.
*/
int
i_ft2_bbox_r(FT2_Fonthandle *handle, double cheight, double cwidth,
char const *text, size_t len, int vlayout, int utf8, int *bbox) {
char const *text, size_t len, int vlayout, int utf8, i_img_dim *bbox) {
FT_Error error;
int width;
i_img_dim width;
int index;
int first;
int ascent = 0, descent = 0;
i_img_dim ascent = 0, descent = 0;
int glyph_ascent, glyph_descent;
FT_Glyph_Metrics *gm;
int work[4];
int bounds[4];
i_img_dim work[4];
i_img_dim bounds[4];
double x = 0, y = 0;
int i;
FT_GlyphSlot slot;
Expand Down Expand Up @@ -641,13 +641,13 @@ Returns non-zero on success.
=cut
*/
int
i_ft2_text(FT2_Fonthandle *handle, i_img *im, int tx, int ty, const i_color *cl,
i_ft2_text(FT2_Fonthandle *handle, i_img *im, i_img_dim tx, i_img_dim ty, const i_color *cl,
double cheight, double cwidth, char const *text, size_t len,
int align, int aa, int vlayout, int utf8) {
FT_Error error;
int index;
FT_Glyph_Metrics *gm;
int bbox[BOUNDING_BOX_COUNT];
i_img_dim bbox[BOUNDING_BOX_COUNT];
FT_GlyphSlot slot;
int x, y;
unsigned char *bmp;
Expand Down Expand Up @@ -790,10 +790,10 @@ Returns non-zero on success.
*/

int
i_ft2_cp(FT2_Fonthandle *handle, i_img *im, int tx, int ty, int channel,
i_ft2_cp(FT2_Fonthandle *handle, i_img *im, i_img_dim tx, i_img_dim ty, int channel,
double cheight, double cwidth, char const *text, size_t len, int align,
int aa, int vlayout, int utf8) {
int bbox[8];
i_img_dim bbox[8];
i_img *work;
i_color cl, cl2;
int x, y;
Expand Down Expand Up @@ -843,7 +843,8 @@ Returns the number of characters that were checked.
=cut
*/
int i_ft2_has_chars(FT2_Fonthandle *handle, char const *text, size_t len,
size_t
i_ft2_has_chars(FT2_Fonthandle *handle, char const *text, size_t len,
int utf8, char *out) {
int count = 0;
mm_log((1, "i_ft2_has_chars(handle %p, text %p, len %d, utf8 %d)\n",
Expand Down Expand Up @@ -953,10 +954,12 @@ make_bmp_map(FT_Bitmap *bitmap, unsigned char *map) {
Fills the given buffer with the Postscript Face name of the font,
if there is one.
Returns the number of bytes copied, including the terminating NUL.
=cut
*/

int
size_t
i_ft2_face_name(FT2_Fonthandle *handle, char *name_buf, size_t name_buf_size) {
#if IM_HAS_FACE_NAME
char const *name = FT_Get_Postscript_Name(handle->face);
Expand Down Expand Up @@ -1134,13 +1137,13 @@ i_ft2_set_mm_coords(FT2_Fonthandle *handle, int coord_count, const long *coords)
#endif
}

static int
i_min(int a, int b) {
static i_img_dim
i_min(i_img_dim a, i_img_dim b) {
return a < b ? a : b;
}

static int
i_max(int a, int b) {
static i_img_dim
i_max(i_img_dim a, i_img_dim b) {
return a > b ? a : b;
}

Expand Down
19 changes: 12 additions & 7 deletions FT2/imft2.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,23 @@ extern int i_ft2_getdpi(FT2_Fonthandle *handle, int *xdpi, int *ydpi);
extern int i_ft2_settransform(FT2_Fonthandle *handle, const double *matrix);
extern int i_ft2_sethinting(FT2_Fonthandle *handle, int hinting);
extern int i_ft2_bbox(FT2_Fonthandle *handle, double cheight, double cwidth,
char const *text, size_t len, int *bbox, int utf8);
char const *text, size_t len, i_img_dim *bbox, int utf8);
extern int i_ft2_bbox_r(FT2_Fonthandle *handle, double cheight, double cwidth,
char const *text, size_t len, int vlayout, int utf8, int *bbox);
extern int i_ft2_text(FT2_Fonthandle *handle, i_img *im, int tx, int ty,
char const *text, size_t len, int vlayout, int utf8, i_img_dim *bbox);
extern int i_ft2_text(FT2_Fonthandle *handle, i_img *im, i_img_dim tx, i_img_dim ty,
const i_color *cl, double cheight, double cwidth,
char const *text, size_t len, int align, int aa,
int vlayout, int utf8);
extern int i_ft2_cp(FT2_Fonthandle *handle, i_img *im, int tx, int ty,
extern int i_ft2_cp(FT2_Fonthandle *handle, i_img *im, i_img_dim tx, i_img_dim ty,
int channel, double cheight, double cwidth,
char const *text, size_t len, int align, int aa,
int vlayout, int utf8);
extern int i_ft2_has_chars(FT2_Fonthandle *handle, char const *text, size_t len,
extern size_t
i_ft2_has_chars(FT2_Fonthandle *handle, char const *text, size_t len,
int utf8, char *work);
extern int i_ft2_face_name(FT2_Fonthandle *handle, char *name_buf,
size_t name_buf_size);
extern size_t
i_ft2_face_name(FT2_Fonthandle *handle, char *name_buf,
size_t name_buf_size);
extern int i_ft2_can_face_name(void);
extern int i_ft2_glyph_name(FT2_Fonthandle *handle, unsigned long ch,
char *name_buf, size_t name_buf_size,
Expand All @@ -43,5 +45,8 @@ extern int
i_ft2_is_multiple_master(FT2_Fonthandle *handle);
extern int
i_ft2_set_mm_coords(FT2_Fonthandle *handle, int coord_count, const long *coords);

void ft2_transform_box(FT2_Fonthandle *handle, i_img_dim bbox[4]);

#endif

6 changes: 3 additions & 3 deletions Flines/Flines.xs
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,19 @@ saturate(int in) {
void
flines(i_img *im) {
i_color vl;
int x,y;
i_img_dim x,y;

for(y = 0; y < im->ysize; y ++) {
for(x = 0; x < im->xsize; x ++ ) {
i_gpix(im,x,y,&vl);
if (!(y%2)) {
float yf = y/(float)im->ysize;
float yf = y/(double)im->ysize;
float mf = 1.2-0.8*yf;
vl.rgb.r = saturate(vl.rgb.r*mf);
vl.rgb.g = saturate(vl.rgb.g*mf);
vl.rgb.b = saturate(vl.rgb.b*mf);
} else {
float yf = (im->ysize-y)/(float)im->ysize;
float yf = (im->ysize-y)/(double)im->ysize;
float mf = 1.2-0.8*yf;
vl.rgb.r = saturate(vl.rgb.r*mf);
vl.rgb.g = saturate(vl.rgb.g*mf);
Expand Down
Loading

0 comments on commit 8d14daa

Please sign in to comment.