home *** CD-ROM | disk | FTP | other *** search
/ Graphics Plus / Graphics Plus.iso / general / procssng / ccs / ccs-11tl.lha / lbl / lib / c_to_c.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-04-30  |  3.1 KB  |  129 lines

  1. /*    Color_to_Color . c
  2. %
  3. %    RLE to rast or invesely.
  4. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  5.  
  6. This software is copyright (C) by the Lawrence Berkeley Laboratory.
  7. Permission is granted to reproduce this software for non-commercial
  8. purposes provided that this notice is left intact.
  9.  
  10. It is acknowledged that the U.S. Government has rights to this software
  11. under Contract DE-AC03-765F00098 between the U.S.  Department of Energy
  12. and the University of California.
  13.  
  14. This software is provided as a professional and academic contribution
  15. for joint exchange. Thus, it is experimental, and is provided ``as is'',
  16. with no warranties of any kind whatsoever, no support, no promise of
  17. updates, or printed documentation. By using this software, you
  18. acknowledge that the Lawrence Berkeley Laboratory and Regents of the
  19. University of California shall have no liability with respect to the
  20. infringement of other copyrights by any part of this software.
  21.  
  22. For further information about this notice, contact William Johnston,
  23. Bld. 50B, Rm. 2239, Lawrence Berkeley Laboratory, Berkeley, CA, 94720.
  24. (wejohnston@lbl.gov)
  25.  
  26. For further information about this software, contact:
  27.     Jin Guojun
  28.     Bld. 50B, Rm. 2275, Lawrence Berkeley Laboratory, Berkeley, CA, 94720.
  29.     g_jin@lbl.gov
  30.  
  31. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  32. %
  33. % AUTHOR:    Jin Guojun - LBL    1/1/90
  34. */
  35.  
  36. #include "imagedef.h"
  37.  
  38. #define    Next_Sample(bit_shift, bitspsmp, p)    \
  39. {    if (!bit_shift)    {    bit_shift = 8,    p++;    }    \
  40.     bit_shift -= bitspsmp;    }
  41.  
  42. ras8_to_rle(obp, ibp, w, img, cmap, h)
  43. byte    *obp, *ibp;
  44. int    w;
  45. U_IMAGE    *img;
  46. cmap_t*    cmap[3];
  47. {
  48. register int    i, c;
  49. register byte    *cp[3];
  50.  
  51. while (h--)    {
  52.     for (cp[0]=obp, i=0, c=img->dpy_channels; i++<c;)
  53.         cp[i] = cp[i-1] + w;
  54.     obp += (i=w) * c;
  55.     while (i--) for (c=img->dpy_channels; c--; cp[c][i] = cmap[c][ibp[i]]);
  56.     ibp += w;
  57. }
  58. }
  59.  
  60.  
  61. snf_to_rle(obp, ibp, w, bps, cmp)
  62. byte    *obp, *ibp, *cmp[];
  63. {
  64. register byte    *cp[3], pxl;
  65. register int    shift = 8;
  66.     cp[0] = obp;
  67.     cp[1] = obp + w;
  68.     cp[2] = cp[1] + w;
  69.     if (cmp) while (w--)    {
  70.         Next_Sample(shift, bps, ibp);
  71.         pxl = *ibp >> shift;
  72.         *cp[0]++ = cmp[0][pxl];
  73.         *cp[1]++ = cmp[1][pxl];
  74.         *cp[2]++ = cmp[2][pxl];
  75.     } else    while (w--)    *cp[0]++ = *cp[1]++ = *cp[2]++ = *ibp++;
  76. }
  77.  
  78.  
  79. any_ilc_to_rle(obp, ibp, img, channels, revs)
  80. byte    *obp, *ibp;
  81. U_IMAGE    *img;
  82. {
  83. register int    i, w=img->width;
  84. register byte    *cp[3];
  85. bool    alpha = channels==4;
  86.  
  87. for (cp[0] = obp, i=1; i<img->dpy_channels; i++)
  88.     cp[i] = cp[i-1] + w;
  89. ibp += channels * w;
  90.  
  91. if (revs) while (w--)    {
  92.     for (i=0; i<img->dpy_channels; i++)
  93.         cp[i][w] = *(--ibp);
  94.     if (alpha)    ibp--;
  95. } else while (w--)    {
  96.     for (i=img->dpy_channels; i--;)
  97.         cp[i][w] = *(--ibp);
  98.     if (alpha)    ibp--;
  99.     }
  100. }
  101.  
  102. line_to_cell_color(obp, r, w, h)
  103. register char    *obp, *r;
  104. register int    h;
  105. {
  106. register int    col;
  107. register char    *g, *b=r;
  108.     while (h--) {
  109.     r=b;    g=r+w;    b=g+w;
  110.     for (col=w; col--;) {
  111.         *obp++ = *r++,
  112.         *obp++ = *g++,
  113.         *obp++ = *b++;
  114.     }
  115.     }
  116. }
  117.  
  118. ilc_transfer(op, ip, w, inch, rev, och)
  119. char    *op, *ip;
  120. register int    w, rev;
  121. {
  122. register int    oe=0;
  123. if (!rev)    rev = 2;    else    rev = oe,    oe = 2;
  124. if (inch > 3)    ip++;
  125. if (och > 3)    op++;
  126. for (; w--; ip+=inch, op+=och)
  127.     *op = ip[oe],    op[1] = ip[1],    op[2] = ip[rev];
  128. }
  129.