Permalink
Browse files

switch to using size_t and i_img_dim strictly

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 Jun 14, 2011
1 parent bd80e51 commit 8d14daabc32a4346d5c20dbe864acc65ca66315b
Showing with 5,108 additions and 1,859 deletions.
  1. +34 −0 Changes
  2. +2 −1 CountColor/CountColor.xs
  3. +2 −5 DynTest/linstretch.c
  4. +15 −14 FT2/FT2.xs
  5. +27 −24 FT2/freetyp2.c
  6. +12 −7 FT2/imft2.h
  7. +3 −3 Flines/Flines.xs
  8. +25 −14 GIF/imgif.c
  9. +88 −0 GIF/t/t40limit.t
  10. +259 −332 Imager.xs
  11. +1 −0 JPEG/imexif.c
  12. +12 −3 JPEG/imjpeg.c
  13. +54 −0 JPEG/t/t20limit.t
  14. +5 −0 MANIFEST
  15. +22 −0 Makefile.PL
  16. +2 −1 Mandelbrot/mandel.c
  17. +8 −1 PNG/impng.c
  18. +8 −0 SGI/imsgi.c
  19. +52 −0 SGI/t/30limit.t
  20. +8 −8 T1/T1.xs
  21. +14 −13 T1/imt1.c
  22. +3 −3 T1/imt1.h
  23. +63 −53 TIFF/imtiff.c
  24. +2 −0 W32/W32.pm
  25. +11 −11 W32/W32.xs
  26. +5 −5 W32/imw32.h
  27. +28 −18 W32/win32.c
  28. +5 −1 apidocs.perl
  29. +68 −30 bmp.c
  30. +25 −22 compose.im
  31. +4 −4 conv.im
  32. +3 −2 convert.im
  33. +103 −46 datatypes.c
  34. +139 −133 draw.c
  35. +9 −8 draw.h
  36. +8 −6 dynaload.c
  37. +4 −4 dynfilt/dt2.c
  38. +7 −5 dynfilt/dyntest.c
  39. +5 −5 dynfilt/flines.c
  40. +9 −9 dynfilt/mandelbrot.c
  41. +7 −3 error.c
  42. +5 −0 fileformatdocs/other.txt
  43. +2,476 −0 fileformatdocs/spec-gif89a.txt
  44. BIN fileformatdocs/tga_specs.pdf
  45. BIN fileformatdocs/tgaffs.pdf
  46. +20 −19 fills.c
  47. +140 −173 filters.im
  48. +5 −5 flip.im
  49. +81 −79 font.c
  50. +11 −10 gaussian.im
  51. +16 −16 hlines.c
  52. +101 −81 image.c
  53. +92 −114 imager.h
  54. +17 −16 imageri.h
  55. +89 −43 imdatatypes.h
  56. +1 −1 imerror.h
  57. +20 −20 imext.c
  58. +7 −0 imext.h
  59. +51 −46 imexttypes.h
  60. +64 −51 img16.c
  61. +51 −41 img8.c
  62. +53 −42 imgdouble.c
  63. +28 −22 io.c
  64. +13 −13 iolayer.c
  65. +1 −0 iolayert.h
  66. +167 −3 lib/Imager/APIRef.pod
  67. +1 −1 lib/Imager/Cookbook.pod
  68. +5 −5 lib/Imager/Files.pod
  69. +45 −18 limits.c
  70. +1 −0 log.c
  71. +2 −1 log.h
  72. +1 −1 map.c
  73. +46 −46 maskimg.c
  74. +30 −30 palimg.c
  75. +14 −11 paste.im
  76. +22 −17 pnm.c
  77. +12 −17 polygon.c
  78. +19 −16 quant.c
  79. +19 −15 raw.c
  80. +6 −6 regmach.c
  81. +7 −1 render.im
  82. +21 −21 rotate.c
  83. +15 −15 rubthru.im
  84. +27 −23 scale.im
  85. +1 −1 t/t01introvert.t
  86. +2 −2 t/t021sixteen.t
  87. +1 −1 t/t022double.t
  88. +2 −2 t/t023palette.t
  89. +2 −2 t/t1000files.t
  90. +16 −1 t/t104ppm.t
  91. +3 −2 t/t107bmp.t
  92. +78 −1 t/t108tga.t
  93. +4 −1 t/t64copyflip.t
  94. +5 −0 testimg/tootall.ppm
  95. +5 −0 testimg/toowide.ppm
  96. +18 −11 tga.c
  97. +2 −2 trans2.c
  98. +6 −0 typemap
View
34 Changes
@@ -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
===========
View
@@ -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;
View
@@ -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);
View
@@ -22,6 +22,7 @@ FT2_DESTROY(font)
int
FT2_CLONE_SKIP(...)
CODE:
+ (void)items;
RETVAL = 1;
OUTPUT:
RETVAL
@@ -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;
@@ -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
@@ -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
@@ -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
@@ -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);
@@ -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))
@@ -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) {
View
@@ -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;
@@ -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)
@@ -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.
@@ -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;
@@ -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;
@@ -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.
@@ -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;
@@ -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;
@@ -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;
@@ -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",
@@ -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);
@@ -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;
}
View
@@ -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,
@@ -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
View
@@ -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);
Oops, something went wrong.

0 comments on commit 8d14daa

Please sign in to comment.