home *** CD-ROM | disk | FTP | other *** search
/ Graphics Plus / Graphics Plus.iso / general / procssng / ccs / ccs-11.lha / ccs-lib / lib / icc_r.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-10-02  |  3.0 KB  |  96 lines

  1. /*    ICC_R . C
  2. #
  3. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  4.  
  5. This software is copyright (C) by the Lawrence Berkeley Laboratory.
  6. Permission is granted to reproduce this software for non-commercial
  7. purposes provided that this notice is left intact.
  8.  
  9. It is acknowledged that the U.S. Government has rights to this software
  10. under Contract DE-AC03-765F00098 between the U.S.  Department of Energy
  11. and the University of California.
  12.  
  13. This software is provided as a professional and academic contribution
  14. for joint exchange. Thus, it is experimental, and is provided ``as is'',
  15. with no warranties of any kind whatsoever, no support, no promise of
  16. updates, or printed documentation. By using this software, you
  17. acknowledge that the Lawrence Berkeley Laboratory and Regents of the
  18. University of California shall have no liability with respect to the
  19. infringement of other copyrights by any part of this software.
  20.  
  21. For further information about this notice, contact William Johnston,
  22. Bld. 50B, Rm. 2239, Lawrence Berkeley Laboratory, Berkeley, CA, 94720.
  23. (wejohnston@lbl.gov)
  24.  
  25. For further information about this software, contact:
  26.     Jin Guojun
  27.     Bld. 50B, Rm. 2275, Lawrence Berkeley Laboratory, Berkeley, CA, 94720.
  28.     g_jin@lbl.gov
  29.  
  30. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  31. %
  32. %    The input file is an either padded to 8-pixel in width,
  33. %        or any 3-separate-plane images.
  34. %    The output can be:    SGF, ILC, ILL, or SEP.
  35. %
  36. % AUTHOR:    Jin Guojun - LBL    10/01/1991
  37. */
  38.  
  39. #include "header.def"
  40. #include "imagedef.h"
  41.  
  42.  
  43. read_sepplane_image(img, cnt, frames)
  44. U_IMAGE    *img;
  45. {
  46. char    junk[16], *tmp;
  47. register int    ch=img->channels, i=img->color_form;
  48. int    fsize = img->width * img->height, ret, f=0,
  49.     sep_to_sg = img->in_color==CFM_SEPLANE && (i==CFM_SGF || i==CFM_ILC);
  50.  
  51. if (img->in_type != HIPS || !img->src)
  52.     verify_buffer_size(&img->src, fsize, img->dpy_channels, "sep-buf");
  53. tmp = img->src;
  54. if (cnt < 0)    cnt = 0;
  55. if (sep_to_sg)    tmp = nzalloc(ch, fsize, "sep-tmp");
  56.  
  57.     {    register char    *op;    /* The default is to convert to RLE */
  58.     register int    row, inc = img->width * (i==CFM_ILL ? ch : 1);
  59.  
  60.     do {
  61.         op = tmp;
  62.         for (ch=0; ch<img->channels; ch++)    {
  63.         if (img->color_form == CFM_ILL)
  64.             op = tmp + img->width * ch;
  65.         for (row=i=0; row++ < img->height; op+=inc) {
  66.             i += (*img->read)(op, 1, img->width, img->IN_FP);
  67.             if (cnt && !(*img->read)(junk, cnt, 1, img->IN_FP))
  68.                 break;
  69.         }
  70.         if (i != fsize)    {
  71.             prgmerr(DEBUGANY, "[%d] read SEP data[%d] %d", ch, fsize, i);
  72.             break;
  73.         }
  74.         }
  75.         if ((ret = i) < 1)    break;
  76.         if (sep_to_sg)    {
  77.         op = img->src;
  78.         op += f * (i=fsize) * img->dpy_channels;
  79.         if (img->color_form == CFM_SGF)    /* convert 3-channel to 1 */
  80.             ill_to_gray(op, tmp, tmp+i, tmp+(i<<1), i);
  81.         else    {
  82.         register char    *r=tmp, *g=r+i, *b=g+i;
  83.             while (i--)
  84.                 *op++ = *r++,    *op++ = *g++,    *op++ = *b++;
  85.         }
  86.         }
  87.         if (!sep_to_sg)    tmp += fsize * img->dpy_channels;
  88.     } while(++f < frames);
  89.     }
  90.  
  91. if (sep_to_sg)    free(tmp);
  92. if (img->mid_type == RLE)    /* safety for RLE map_scan    */
  93.     img->channels = img->dpy_channels;
  94. return    ret;
  95. }
  96.