]> git.imager.perl.org - imager.git/blobdiff - image.c
Fixed missing myfree() in bmp.c.
[imager.git] / image.c
diff --git a/image.c b/image.c
index 8c6149d72dca75f11704a67a04ae1aaa6f7fa147..0478b987d4241391801115a74e66ddc8e2d6f329 100644 (file)
--- a/image.c
+++ b/image.c
@@ -26,7 +26,7 @@ color objects for Imager.
 
 Some of these functions are internal.
 
-=over 4
+=over
 
 =cut
 */
@@ -202,7 +202,7 @@ static i_img IIM_base_8bit_direct =
 {
   0, /* channels set */
   0, 0, 0, /* xsize, ysize, bytes */
-  ~0, /* ch_mask */
+  ~0U, /* ch_mask */
   i_8_bits, /* bits */
   i_direct_type, /* type */
   0, /* virtual */
@@ -948,7 +948,7 @@ i_scaleaxis(i_img *im, float Value, int Axis) {
   
   new_img = i_img_empty_ch(NULL, hsize, vsize, im->channels);
   
-  /* 1.5 is a magic number, setting it to 2 will cause rather blurred images */
+  /* 1.4 is a magic number, setting it to 2 will cause rather blurred images */
   LanczosWidthFactor = (Value >= 1) ? 1 : (int) (1.4/Value); 
   lMax = LanczosWidthFactor << 1;
   
@@ -982,9 +982,15 @@ i_scaleaxis(i_img *im, float Value, int Axis) {
       
       for (i=0; i<iEnd; i++) {
        for (k=0; k<im->channels; k++) PictureValue[k] = 0.0;
-       for (l=0; l < lMax; l++) {
-         i_gpix(im, T+l+1,      i, &val1);
-         i_gpix(im, T-lMax+l+1, i, &val2);
+       for (l=0; l<lMax; l++) {
+         int mx = T-lMax+l+1;
+         int Mx = T+l+1;
+         mx = (mx < 0) ? 0 : mx;
+         Mx = (Mx >= im->xsize) ? im->xsize-1 : Mx;
+         
+         i_gpix(im, Mx, i, &val1);
+         i_gpix(im, mx, i, &val2);
+         
          for (k=0; k<im->channels; k++) {
            PictureValue[k] += l1[l]        * val1.channel[k];
            PictureValue[k] += l0[lMax-l-1] * val2.channel[k];
@@ -1002,15 +1008,20 @@ i_scaleaxis(i_img *im, float Value, int Axis) {
       for (i=0; i<iEnd; i++) {
        for (k=0; k<im->channels; k++) PictureValue[k] = 0.0;
        for (l=0; l < lMax; l++) {
-         i_gpix(im, i, T+l+1, &val1);
-         i_gpix(im, i, T-lMax+l+1, &val2);
+         int mx = T-lMax+l+1;
+         int Mx = T+l+1;
+         mx = (mx < 0) ? 0 : mx;
+         Mx = (Mx >= im->ysize) ? im->ysize-1 : Mx;
+
+         i_gpix(im, i, Mx, &val1);
+         i_gpix(im, i, mx, &val2);
          for (k=0; k<im->channels; k++) {
-           PictureValue[k] += l1[l] * val1.channel[k];
+           PictureValue[k] += l1[l]        * val1.channel[k];
            PictureValue[k] += l0[lMax-l-1] * val2.channel[k]; 
          }
        }
        for (k=0; k<im->channels; k++) {
-         psave = (short)( PictureValue[k] / LanczosWidthFactor);
+         psave = (short)(0.5+(PictureValue[k] / LanczosWidthFactor));
          val.channel[k] = minmax(0, 255, psave);
        }
        i_ppix(new_img, i, j, &val);
@@ -1299,6 +1310,7 @@ Returns 0 if the pixel could be set, -1 otherwise.
 
 =cut
 */
+static
 int
 i_ppix_d(i_img *im, int x, int y, i_color *val) {
   int ch;
@@ -1324,6 +1336,7 @@ Returns 0 if the pixel could be set, -1 otherwise.
 
 =cut
 */
+static
 int 
 i_gpix_d(i_img *im, int x, int y, i_color *val) {
   int ch;
@@ -1332,6 +1345,7 @@ i_gpix_d(i_img *im, int x, int y, i_color *val) {
        val->channel[ch]=im->idata[(x+y*im->xsize)*im->channels+ch];
     return 0;
   }
+  for(ch=0;ch<im->channels;ch++) val->channel[ch] = 0;
   return -1; /* error was cliped */
 }
 
@@ -1351,6 +1365,7 @@ Returns the number of pixels copied (eg. if r, l or y is out of range)
 
 =cut
 */
+static
 int
 i_glin_d(i_img *im, int l, int r, int y, i_color *vals) {
   int ch, count, i;
@@ -1387,6 +1402,7 @@ Returns the number of pixels copied (eg. if r, l or y is out of range)
 
 =cut
 */
+static
 int
 i_plin_d(i_img *im, int l, int r, int y, i_color *vals) {
   int ch, count, i;
@@ -1415,6 +1431,7 @@ i_plin_d(i_img *im, int l, int r, int y, i_color *vals) {
 
 =cut
 */
+static
 int
 i_ppixf_d(i_img *im, int x, int y, i_fcolor *val) {
   int ch;
@@ -1435,6 +1452,7 @@ i_ppixf_d(i_img *im, int x, int y, i_fcolor *val) {
 
 =cut
 */
+static
 int
 i_gpixf_d(i_img *im, int x, int y, i_fcolor *val) {
   int ch;
@@ -1464,6 +1482,7 @@ Returns the number of pixels copied (eg. if r, l or y is out of range)
 
 =cut
 */
+static
 int
 i_glinf_d(i_img *im, int l, int r, int y, i_fcolor *vals) {
   int ch, count, i;
@@ -1500,6 +1519,7 @@ Returns the number of pixels copied (eg. if r, l or y is out of range)
 
 =cut
 */
+static
 int
 i_plinf_d(i_img *im, int l, int r, int y, i_fcolor *vals) {
   int ch, count, i;
@@ -1534,7 +1554,9 @@ Returns the number of samples read (which should be (r-l) * bits_set(chan_mask)
 
 =cut
 */
-int i_gsamp_d(i_img *im, int l, int r, int y, i_sample_t *samps, 
+static
+int
+i_gsamp_d(i_img *im, int l, int r, int y, i_sample_t *samps, 
               int *chans, int chan_count) {
   int ch, count, i, w;
   unsigned char *data;
@@ -1590,7 +1612,9 @@ Returns the number of samples read (which should be (r-l) * bits_set(chan_mask)
 
 =cut
 */
-int i_gsampf_d(i_img *im, int l, int r, int y, i_fsample_t *samps, 
+static
+int
+i_gsampf_d(i_img *im, int l, int r, int y, i_fsample_t *samps, 
                int *chans, int chan_count) {
   int ch, count, i, w;
   unsigned char *data;
@@ -2035,6 +2059,12 @@ int free_gen_write_data(i_gen_write_data *info, int flush)
 /*
 =back
 
+=head1 AUTHOR
+
+Arnar M. Hrafnkelsson <addi@umich.edu>
+
+Tony Cook <tony@develop-help.com>
+
 =head1 SEE ALSO
 
 L<Imager>, L<gif.c>