]> git.imager.perl.org - imager.git/blobdiff - pnm.c
Fixed missing myfree() in bmp.c.
[imager.git] / pnm.c
diff --git a/pnm.c b/pnm.c
index 2765c4c7006514fb8c6cb1c42f89c859b156162d..3083eef98ff8e739d93a7756f441f760b944f1b1 100644 (file)
--- a/pnm.c
+++ b/pnm.c
@@ -30,7 +30,7 @@ or an entire memory mapped buffer.
 
 Some of these functions are internal.
 
-=over 4
+=over
 
 =cut
 */
@@ -366,7 +366,7 @@ i_readpnm_wiol(io_glue *ig, int length) {
     
   case 4: /* binary pbm */
     for(y=0;y<height;y++) for(x=0; x<width; x+=8) {
-      if ( (uc = gnext(&buf)) ) {
+      if ( (uc = (unsigned char*)gnext(&buf)) ) {
        int xt;
        int pc = width-x < 8 ? width-x : 8;
        /*      mm_log((1,"i_readpnm: y=%d x=%d pc=%d\n", y, x, pc)); */
@@ -385,7 +385,7 @@ i_readpnm_wiol(io_glue *ig, int length) {
   case 6: /* binary ppm */
     for(y=0;y<height;y++) for(x=0; x<width; x++) {
       for(ch=0; ch<channels; ch++) {
-       if ( (uc = gnext(&buf)) ) val.channel[ch] = *uc;
+       if ( (uc = (unsigned char*)gnext(&buf)) ) val.channel[ch] = *uc;
        else {
          mm_log((1,"i_readpnm: gnext() returned false in data\n"));
          return im;
@@ -401,100 +401,6 @@ i_readpnm_wiol(io_glue *ig, int length) {
   return im;
 }
 
-undef_int
-i_writeppm(i_img *im,int fd) {
-  char header[255];
-  int rc;
-
-  mm_log((1,"i_writeppm(im* 0x%x,fd %d)\n",im,fd));
-  
-  i_clear_error();
-
-  if (im->channels==3) {
-    sprintf(header,"P6\n#CREATOR: Imager\n%d %d\n255\n",im->xsize,im->ysize);
-
-    if (mywrite(fd,header,strlen(header))<0) {
-      i_push_error(errno, "could not write ppm header");
-      mm_log((1,"i_writeppm: unable to write ppm header.\n"));
-      return(0);
-    }
-    
-    if (!im->virtual && im->bits == i_8_bits && im->type == i_direct_type) {
-      rc=mywrite(fd,im->idata,im->bytes);
-    }
-    else {
-      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;
-        while (y < im->ysize && rc >= 0) {
-          i_gsamp(im, 0, im->xsize, y, data, rgb_chan, 3);
-          rc = mywrite(fd, data, im->xsize * 3);
-        }
-        myfree(data);
-      }
-      else {
-        i_push_error(0, "Out of memory");
-        return 0;
-      }
-    }
-    if (rc<0) {
-      i_push_error(errno, "could not write ppm data");
-      mm_log((1,"i_writeppm: unable to write ppm data.\n"));
-      return(0);
-    }
-  }
-  else if (im->channels == 1) {
-    sprintf(header, "P5\n#CREATOR: Imager\n%d %d\n255\n",
-           im->xsize, im->ysize);
-    if (mywrite(fd,header, strlen(header)) < 0) {
-      i_push_error(errno, "could not write pgm header");
-      mm_log((1,"i_writeppm: unable to write pgm header.\n"));
-      return(0);
-    }
-
-    if (!im->virtual && im->bits == i_8_bits && im->type == i_direct_type) {
-      rc=mywrite(fd,im->idata,im->bytes);
-    }
-    else {
-      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) {
-          i_gsamp(im, 0, im->xsize, y, data, &chan, 1);
-          rc = mywrite(fd, data, im->xsize);
-        }
-        myfree(data);
-      }
-      else {
-        i_push_error(0, "Out of memory");
-        return 0;
-      }
-    }
-    if (rc<0) {
-      i_push_error(errno, "could not write pgm data");
-      mm_log((1,"i_writeppm: unable to write pgm data.\n"));
-      return(0);
-    }
-  }
-  else {
-    i_push_error(0, "can only save 1 or 3 channel images to pnm");
-    mm_log((1,"i_writeppm: ppm/pgm is 1 or 3 channel only (current image is %d)\n",im->channels));
-    return(0);
-  }
-  
-  return(1);
-}
-
 
 undef_int
 i_writeppm_wiol(i_img *im, io_glue *ig) {
@@ -593,3 +499,17 @@ i_writeppm_wiol(i_img *im, io_glue *ig) {
 
   return(1);
 }
+
+/*
+=back
+
+=head1 AUTHOR
+
+Arnar M. Hrafnkelsson <addi@umich.edu>
+
+=head1 SEE ALSO
+
+Imager(3)
+
+=cut
+*/