]> git.imager.perl.org - imager.git/commitdiff
Removed old cruft from image.* and minor changes to rgb.c.
authorArnar Mar Hrafnkelsson <addi@cpan.org>
Fri, 18 Jan 2002 18:15:14 +0000 (18:15 +0000)
committerArnar Mar Hrafnkelsson <addi@cpan.org>
Fri, 18 Jan 2002 18:15:14 +0000 (18:15 +0000)
image.c
image.h
rgb.c

diff --git a/image.c b/image.c
index 8bad545848dd8e50e406154007b5b97570762419..e97cd5bfdd2f92255a38af761b665b79c360830c 100644 (file)
--- a/image.c
+++ b/image.c
@@ -50,6 +50,8 @@ static int i_glinf_d(i_img *im, int l, int r, int y, i_fcolor *vals);
 static int i_plinf_d(i_img *im, int l, int r, int y, i_fcolor *vals);
 static int i_gsamp_d(i_img *im, int l, int r, int y, i_sample_t *samps, int *chans, int chan_count);
 static int i_gsampf_d(i_img *im, int l, int r, int y, i_fsample_t *samps, int *chans, int chan_count);
+static int i_psamp_d(i_img *im, int l, int r, int y, i_sample_t *samps, int *chans, int chan_count);
+static int i_psampf_d(i_img *im, int l, int r, int y, i_fsample_t *samps, int *chans, int chan_count);
 
 /* 
 =item ICL_new_internal(r, g, b, a)
@@ -483,50 +485,6 @@ int
 i_img_getchannels(i_img *im) { return im->channels; }
 
 
-/*
-=item i_ppix(im, x, y, col)
-
-Sets the pixel at (I<x>,I<y>) in I<im> to I<col>.
-
-Returns true if the pixel could be set, false if x or y is out of
-range.
-
-=cut
-*/
-int
-(i_ppix)(i_img *im, int x, int y, i_color *val) { return im->i_f_ppix(im, x, y, val); }
-
-/*
-=item i_gpix(im, x, y, &col)
-
-Get the pixel at (I<x>,I<y>) in I<im> into I<col>.
-
-Returns true if the pixel could be retrieved, false otherwise.
-
-=cut
-*/
-int
-(i_gpix)(i_img *im, int x, int y, i_color *val) { return im->i_f_gpix(im, x, y, val); }
-
-/*
-=item i_ppix_pch(im, x, y, ch)
-
-Get the value from the channel I<ch> for pixel (I<x>,I<y>) from I<im>
-scaled to [0,1].
-
-Returns zero if x or y is out of range.
-
-Warning: this ignores the vptr interface for images.
-
-=cut
-*/
-float
-i_gpix_pch(i_img *im,int x,int y,int ch) {
-  /* FIXME */
-  if (x>-1 && x<im->xsize && y>-1 && y<im->ysize) return ((float)im->idata[(x+y*im->xsize)*im->channels+ch]/255);
-  else return 0;
-}
-
 
 /*
 =item i_copyto_trans(im, src, x1, y1, x2, y2, tx, ty, trans)
@@ -1286,7 +1244,7 @@ i_count_colors(i_img *im,int maxc) {
 
 symbol_table_t symbol_table={i_has_format,ICL_set_internal,ICL_info,
                             i_img_new,i_img_empty,i_img_empty_ch,i_img_exorcise,
-                            i_img_info,i_img_setmask,i_img_getmask,i_ppix,i_gpix,
+                            i_img_info,i_img_setmask,i_img_getmask,
                             i_box,i_draw,i_arc,i_copyto,i_copyto_trans,i_rubthru};
 
 
diff --git a/image.h b/image.h
index dfaf28297843be521b3122146381631971f20c18..7025b2da593240142ca08cfec94e1726006113de 100644 (file)
--- a/image.h
+++ b/image.h
@@ -69,10 +69,12 @@ int    i_img_getchannels(i_img *im);
 
 /* Base functions */
 
+#if 0
 int i_ppix(i_img *im,int x,int y,i_color *val);
 int i_gpix(i_img *im,int x,int y,i_color *val);
 int i_ppixf(i_img *im,int x,int y,i_color *val);
 int i_gpixf(i_img *im,int x,int y,i_color *val);
+#endif
 
 #define i_ppix(im, x, y, val) (((im)->i_f_ppix)((im), (x), (y), (val)))
 #define i_gpix(im, x, y, val) (((im)->i_f_gpix)((im), (x), (y), (val)))
@@ -96,6 +98,14 @@ int i_glin_d(i_img *im,int l, int r, int y, i_color *val);
 #define i_gsampf(im, l, r, y, samps, chans, count) \
   (((im)->i_f_gsampf)((im), (l), (r), (y), (samps), (chans), (count)))
 
+#define i_psamp(im, l, r, y, samps, chans, count) \
+  (((im)->i_f_gsamp)((im), (l), (r), (y), (samps), (chans), (count)))
+#define i_psampf(im, l, r, y, samps, chans, count) \
+  (((im)->i_f_gsampf)((im), (l), (r), (y), (samps), (chans), (count)))
+
+
+
+
 #define i_findcolor(im, color, entry) \
   (((im)->i_f_findcolor) ? ((im)->i_f_findcolor)((im), (color), (entry)) : 0)
 
@@ -676,9 +686,10 @@ typedef struct {
   void(*i_img_setmask)(i_img *im,int ch_mask);
   int (*i_img_getmask)(i_img *im);
   
+  /*
   int (*i_ppix)(i_img *im,int x,int y,i_color *val);
   int (*i_gpix)(i_img *im,int x,int y,i_color *val);
-
+  */
   void(*i_box)(i_img *im,int x1,int y1,int x2,int y2,i_color *val);
   void(*i_draw)(i_img *im,int x1,int y1,int x2,int y2,i_color *val);
   void(*i_arc)(i_img *im,int x,int y,float rad,float d1,float d2,i_color *val);
diff --git a/rgb.c b/rgb.c
index 1ef8e0d090e9d41105d92fe662fc8746f4caa21f..b264c5a62400b071e16d08b2353ee881ad0c99c3 100644 (file)
--- a/rgb.c
+++ b/rgb.c
@@ -46,18 +46,12 @@ typedef struct {
   unsigned int colormap;
 } rgb_header;
 
+typedef struct {
+  int start, length;
+} stlen_pair;
 
 typedef enum { NoInit, Raw, Rle } rle_state;
 
-typedef struct {
-  int compressed;
-  int bytepp;
-  rle_state state;
-  unsigned char cval[4];
-  int len;
-  unsigned char hdr;
-  io_glue *ig;
-} rgb_source;
 
 
 typedef struct {
@@ -69,66 +63,6 @@ typedef struct {
 
 
 
-/* 
-    * Packing functions - used for (un)packing
- * datastructures into raw bytes.
- */
-
-
-/*
-=item find_repeat
-
-Helper function for rle compressor to find the next triple repeat of the 
-same pixel value in buffer.
-
-    buf - buffer
-    length - number of pixel values in buffer
-    bytepp - number of bytes in a pixel value
-
-=cut
-*/
-
-static
-int
-find_repeat(unsigned char *buf, int length, int bytepp) {
-  int i = 0;
-  
-  while(i<length-1) {
-    if(memcmp(buf+i*bytepp, buf+(i+1)*bytepp, bytepp) == 0) {
-      if (i == length-2) return -1;
-      if (memcmp(buf+(i+1)*bytepp, buf+(i+2)*bytepp,bytepp) == 0)  
-       return i;
-      else i++;
-    }
-    i++;
-  }
-  return -1;
-}
-
-
-/*
-=item find_span
-
-Helper function for rle compressor to find the length of a span where
-the same pixel value is in the buffer.
-
-    buf - buffer
-    length - number of pixel values in buffer
-    bytepp - number of bytes in a pixel value
-
-=cut
-*/
-
-static
-int
-find_span(unsigned char *buf, int length, int bytepp) {
-  int i = 0;
-  while(i<length) {
-    if(memcmp(buf, buf+(i*bytepp), bytepp) != 0) return i;
-    i++;
-  }
-  return length;
-}
 
 
 /*
@@ -191,62 +125,6 @@ rgb_header_pack(rgb_header *header, unsigned char headbuf[512]) {
 }
 
 
-/*
-=item rgb_source_read(s, buf, pixels)
-
-Reads pixel number of pixels from source s into buffer buf.  Takes
-care of decompressing the stream if needed.
-
-    s - data source 
-    buf - destination buffer
-    pixels - number of pixels to put into buffer
-
-=cut
-*/
-
-static
-int
-rgb_source_read(rgb_source *s, unsigned char *buf, size_t pixels) {
-  int cp = 0, j, k;
-  if (!s->compressed) {
-    if (s->ig->readcb(s->ig, buf, pixels*s->bytepp) != pixels*s->bytepp) return 0;
-    return 1;
-  }
-  
-  while(cp < pixels) {
-    int ml;
-    if (s->len == 0) s->state = NoInit;
-    switch (s->state) {
-    case NoInit:
-      if (s->ig->readcb(s->ig, &s->hdr, 1) != 1) return 0;
-
-      s->len = (s->hdr &~(1<<7))+1;
-      s->state = (s->hdr & (1<<7)) ? Rle : Raw;
-      {
-       static cnt = 0;
-       printf("%04d %s: %d\n", cnt++, s->state==Rle?"RLE":"RAW", s->len);
-      }
-      if (s->state == Rle && s->ig->readcb(s->ig, s->cval, s->bytepp) != s->bytepp) return 0;
-
-      break;
-    case Rle:
-      ml = min(s->len, pixels-cp);
-      for(k=0; k<ml; k++) for(j=0; j<s->bytepp; j++) 
-       buf[(cp+k)*s->bytepp+j] = s->cval[j];
-      cp     += ml;
-      s->len -= ml;
-      break;
-    case Raw:
-      ml = min(s->len, pixels-cp);
-      if (s->ig->readcb(s->ig, buf+cp*s->bytepp, ml*s->bytepp) != ml*s->bytepp) return 0;
-      cp     += ml;
-      s->len -= ml;
-      break;
-    }
-  }
-  return 1;
-}
-
 
 
 
@@ -266,40 +144,7 @@ destination is compressed.
 static
 int
 rgb_dest_write(rgb_dest *s, unsigned char *buf, size_t pixels) {
-  int cp = 0, j, k;
 
-  if (!s->compressed) {
-    if (s->ig->writecb(s->ig, buf, pixels*s->bytepp) != pixels*s->bytepp) return 0;
-    return 1;
-  }
-  
-  while(cp < pixels) {
-    int tlen;
-    int nxtrip = find_repeat(buf+cp*s->bytepp, pixels-cp, s->bytepp);
-    tlen = (nxtrip == -1) ? pixels-cp : nxtrip;
-    while(tlen) {
-      unsigned char clen = (tlen>128) ? 128 : tlen;
-      clen--;
-      if (s->ig->writecb(s->ig, &clen, 1) != 1) return 0;
-      clen++;
-      if (s->ig->writecb(s->ig, buf+cp*s->bytepp, clen*s->bytepp) != clen*s->bytepp) return 0;
-      tlen -= clen;
-      cp += clen;
-    }
-    if (cp >= pixels) break;
-    tlen = find_span(buf+cp*s->bytepp, pixels-cp, s->bytepp);
-    if (tlen <3) continue;
-    while (tlen) {
-      unsigned char clen = (tlen>128) ? 128 : tlen;
-      clen = (clen - 1) | 0x80;
-      if (s->ig->writecb(s->ig, &clen, 1) != 1) return 0;
-      clen = (clen & ~0x80) + 1;
-      if (s->ig->writecb(s->ig, buf+cp*s->bytepp, s->bytepp) != s->bytepp) return 0;
-      tlen -= clen;
-      cp += clen;
-    }
-  }
-  return 1;
 }
 
 
@@ -328,10 +173,11 @@ i_readrgb_wiol(io_glue *ig, int length) {
   int x, y, c,i;
   int width, height, channels;
   unsigned long maxlen;
+
+  int savemask;
   
   char *idstring = NULL;
 
-  rgb_source src;
   rgb_header header;
   unsigned char headbuf[512];
   unsigned char *databuf;
@@ -384,9 +230,32 @@ i_readrgb_wiol(io_glue *ig, int length) {
   
   i_tags_add(&img->tags, "rgb_namestr", 0, header.name, 80, 0);
 
+
   switch (header.storagetype) {
   case 0: /* uncompressed */
     
+    linebuf   = i_mempool_alloc(&mp, width*sizeof(i_color));
+    databuf   = i_mempool_alloc(&mp, width);
+
+    savemask = i_img_getmask(img);
+
+    for(c=0; c<channels; c++) {
+      i_img_setmask(img, 1<<c);
+      for(y=0; y<height; y++) {
+       int x;
+       
+       if (ig->readcb(ig, databuf, width) != width) {
+         i_push_error(0, "SGI rgb: cannot read");
+         goto ErrorReturn;
+       }
+
+       for(x=0; x<width; x++)
+         linebuf[x].channel[c] = databuf[x];
+       
+       i_plin(img, 0, width, height-1-y, linebuf);
+      }
+    }
+    i_img_setmask(img, savemask);
     break;
   case 1: /* RLE compressed */