Cleaned up io.h, io.c which had functions not used any more, removed unused
authorArnar Mar Hrafnkelsson <addi@cpan.org>
Tue, 23 Oct 2001 02:04:59 +0000 (02:04 +0000)
committerArnar Mar Hrafnkelsson <addi@cpan.org>
Tue, 23 Oct 2001 02:04:59 +0000 (02:04 +0000)
and dated code from pnm.c.  Moved functions specific to raw images to raw.c
from io.c

imio.h
io.c
pnm.c
raw.c

diff --git a/imio.h b/imio.h
index fff5a1ac25b21f8fce5d29761ad8be3c43b85608..4d352d94adaf9836d226be1d3fcd0b144f0ed49e 100644 (file)
--- a/imio.h
+++ b/imio.h
@@ -41,12 +41,9 @@ void* myrealloc(void *p, size_t newsize);
 #undef max
 #endif
 
-/* XXX Shouldn't all of these go away */
+/* XXX Shouldn't these go away? */
 
 int min(int a,int b);
 int max(int x,int y);
-int myread(int fd,void *buf,int len);
-int mywrite(int fd,void *buf,int len);
-void interleave(unsigned char *inbuffer,unsigned char *outbuffer,int rowsize,int channels);
 
 #endif
diff --git a/io.c b/io.c
index 9b2aedb62926eca8d7ba0edb058a5051835b4464..1a56e14bd1d9a55e0affb19faf6ba787dcfbbf51 100644 (file)
--- a/io.c
+++ b/io.c
@@ -259,7 +259,7 @@ myrealloc(void *block, size_t size) {
 
 
 
-
+/* Should these really be here? */
 
 #undef min
 #undef max
@@ -274,34 +274,3 @@ max(int a,int b) {
   if (a>b) return a; else return b;
 }
 
-int
-myread(int fd,void *buf,int len) {
-  unsigned char* bufc;
-  int bc,rc;
-  bufc = (unsigned char*)buf;
-  bc=0;
-  while( ((rc=read(fd,bufc+bc,len-bc))>0 ) && (bc!=len) ) bc+=rc;
-  if ( rc < 0 ) return rc;
-  else return bc;
-}
-
-int
-mywrite(int fd,void *buf,int len) {
-  unsigned char* bufc;
-  int bc,rc;
-  bufc=(unsigned char*)buf;
-  bc=0;
-  while(((rc=write(fd,bufc+bc,len-bc))>0) && (bc!=len)) bc+=rc;
-  if (rc<0) return rc;
-  else return bc;
-}
-
-void
-interleave(unsigned char *inbuffer,unsigned char *outbuffer,int rowsize,int channels) {
-  int ch,ind,i;
-  i=0;
-  if ( inbuffer==outbuffer ) return; /* Check if data is already in interleaved format */
-  for( ind=0; ind<rowsize; ind++) for (ch=0; ch<channels; ch++) outbuffer[i++] = inbuffer[rowsize*ch+ind]; 
-}
-
-
diff --git a/pnm.c b/pnm.c
index 2765c4c7006514fb8c6cb1c42f89c859b156162d..aadf3b323df364178fbb924971dfbf91b1d2b5af 100644 (file)
--- a/pnm.c
+++ b/pnm.c
@@ -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) {
diff --git a/raw.c b/raw.c
index 6b1766948eb5d6913c9e744a8af879af3ae1fa2a..e87bf98f267fb1350f560dcfade89f2991751371 100644 (file)
--- a/raw.c
+++ b/raw.c
@@ -8,10 +8,6 @@
 #include <errno.h>
 
 
-#define TRUE 1
-#define FALSE 0
-
-#define BSIZ 100*BUFSIZ
 
 /*
 
 
 */
 
+static
 void
-expandchannels(unsigned char *inbuffer,unsigned char *outbuffer,int chunks,int datachannels,int storechannels) {
+interleave(unsigned char *inbuffer,unsigned char *outbuffer,int rowsize,int channels) {
+  int ch,ind,i;
+  i=0;
+  if (inbuffer == outbuffer) return; /* Check if data is already in interleaved format */
+  for (ind=0; ind<rowsize; ind++) 
+    for (ch=0; ch<channels; ch++) 
+      outbuffer[i++] = inbuffer[rowsize*ch+ind]; 
+}
+
+static
+void
+expandchannels(unsigned char *inbuffer, unsigned char *outbuffer, 
+              int chunks, int datachannels, int storechannels) {
   int ch,i;
-  if (inbuffer==outbuffer) return; /* Check if data is already in expanded format */
-  for(ch=0;ch<chunks;ch++) for (i=0;i<storechannels;i++) outbuffer[ch*storechannels+i]=inbuffer[ch*datachannels+i];
+  if (inbuffer == outbuffer) return; /* Check if data is already in expanded format */
+  for(ch=0; ch<chunks; ch++) 
+    for (i=0; i<storechannels; i++) 
+      outbuffer[ch*storechannels+i] = inbuffer[ch*datachannels+i];
 }
 
 i_img *
@@ -61,23 +72,26 @@ i_readraw_wiol(io_glue *ig, int x, int y, int datachannels, int storechannels, i
   inbuffer = (unsigned char*)mymalloc(inbuflen);
   mm_log((1,"inbuflen: %d, ilbuflen: %d, exbuflen: %d.\n",inbuflen,ilbuflen,exbuflen));
 
-  if (intrl==0) ilbuffer=inbuffer; else ilbuffer=(unsigned char*)mymalloc(inbuflen);
-  if (datachannels==storechannels) exbuffer=ilbuffer; else exbuffer=(unsigned char*)mymalloc(exbuflen);
+  if (intrl==0) ilbuffer = inbuffer; 
+  else ilbuffer=mymalloc(inbuflen);
 
+  if (datachannels==storechannels) exbuffer=ilbuffer; 
+  else exbuffer= mymalloc(exbuflen);
+  
   k=0;
-  while(k<im->ysize) {
+  while( k<im->ysize ) {
     rc = ig->readcb(ig, inbuffer, inbuflen);
-    if (rc!=inbuflen) { fprintf(stderr,"Premature end of file.\n"); exit(2); }
+    if (rc != inbuflen) { fprintf(stderr,"Premature end of file.\n"); exit(2); }
     interleave(inbuffer,ilbuffer,im->xsize,datachannels);
     expandchannels(ilbuffer,exbuffer,im->xsize,datachannels,storechannels);
-    /* FIXME? Do we ever want to save to a virtual image? */
+    /* FIXME: Do we ever want to save to a virtual image? */
     memcpy(&(im->idata[im->xsize*storechannels*k]),exbuffer,exbuflen);
     k++;
   }
 
   myfree(inbuffer);
-  if (intrl!=0) myfree(ilbuffer);
-  if (datachannels!=storechannels) myfree(exbuffer);
+  if (intrl != 0) myfree(ilbuffer);
+  if (datachannels != storechannels) myfree(exbuffer);
   return im;
 }
 
@@ -93,14 +107,13 @@ i_writeraw_wiol(i_img* im, io_glue *ig) {
   
   if (im == NULL) { mm_log((1,"Image is empty\n")); return(0); }
   if (!im->virtual) {
-    rc=ig->writecb(ig,im->idata,im->bytes);
-    if (rc!=im->bytes) { 
+    rc = ig->writecb(ig,im->idata,im->bytes);
+    if (rc != im->bytes) { 
       i_push_error(errno, "Could not write to file");
       mm_log((1,"i_writeraw: Couldn't write to file\n")); 
       return(0);
     }
-  }
-  else {
+  } else {
     int y;
     
     if (im->type == i_direct_type) {
@@ -116,8 +129,7 @@ i_writeraw_wiol(i_img* im, io_glue *ig) {
           rc = ig->writecb(ig, data, line_size);
           ++y;
         }
-      }
-      else {
+      } else {
         i_push_error(0, "Out of memory");
         return 0;
       }
@@ -125,8 +137,7 @@ i_writeraw_wiol(i_img* im, io_glue *ig) {
         i_push_error(errno, "write error");
         return 0;
       }
-    }
-    else {
+    } else {
       /* paletted image - assumes the caller puts the palette somewhere 
          else
       */
@@ -141,8 +152,7 @@ i_writeraw_wiol(i_img* im, io_glue *ig) {
           ++y;
         }
         myfree(data);
-      }
-      else {
+      } else {
         i_push_error(0, "Out of memory");
         return 0;
       }
@@ -152,6 +162,5 @@ i_writeraw_wiol(i_img* im, io_glue *ig) {
       }
     }
   }
-
   return(1);
 }