home *** CD-ROM | disk | FTP | other *** search
/ Graphics Plus / Graphics Plus.iso / general / procssng / ccs / ccs-11tl.lha / lbl / lib / to_sep.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-08-31  |  2.8 KB  |  102 lines

  1. /*    any_to_seplane . 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. % AUTHOR:    Jin Guojun - LBL    1/1/92
  33. */
  34.  
  35. #include "header.def"
  36. #include "imagedef.h"
  37.  
  38. any_to_seplane(img, chans, revs, map)
  39. U_IMAGE    *img;
  40. cmap_t*    *map;
  41. {
  42. char    *cnvt;
  43. int    w = img->width, h = img->height;
  44. if (!img->color_dpy)    return    0;
  45. if (img->dpy_channels > 1 || !*map)
  46.     img->in_color = img->mid_type==HIPS ||
  47.     img->in_type==HIPS && !map[0] ?    /* HIPS color is very complicated */
  48.         CFM_ILC : CFM_ILL;
  49. cnvt = nzalloc(w*h, 3L, "to_sep");
  50.  
  51. switch (img->in_color)    {
  52. case CFM_SCF:    pseudo_to_sep(cnvt, img->src, w * h, map);
  53.     break;
  54. case CFM_ILC:    ilc_to_sep(cnvt, img->src, w * h, chans, revs);
  55.     break;
  56. default:
  57. case CFM_ILL:    ill_to_sep(cnvt, img->src, w, h, chans);
  58. }
  59. free(img->src);
  60. return    (int)(img->src = cnvt);
  61. }
  62.  
  63.  
  64. ill_to_sep(r, rle, w, h, chans)
  65. register byte    *r, *rle;
  66. {
  67. register byte    *g=r+w*h, *b=g+w*h;
  68. chans = (chans-3) * w;
  69.     while (h--)    {
  70.     rle += chans;
  71.     memcpy(r, rle, w),    rle += w,    r += w;
  72.     memcpy(g, rle, w),    rle += w,    g += w;
  73.     memcpy(b, rle, w),    rle += w,    b += w;
  74.     }
  75. }
  76.  
  77. ilc_to_sep(r, rgb, fsize, chans, revs)
  78. register byte    *r, *rgb;
  79. register int    fsize;
  80. {
  81. register byte    *g=r+fsize, *b=g+fsize;
  82. chans = chans - 3;
  83. if (revs)    revs = (int)b,    b = r,    r = (byte*)revs;
  84.     while (fsize--)    {
  85.     rgb += chans;
  86.     *r++ = *rgb++;    *g++ = *rgb++;    *b++ = *rgb++;
  87.     }
  88. }
  89.  
  90. pseudo_to_sep(r, ibp, fsize, map)
  91. register byte    *r, *ibp;
  92. cmap_t    *map[];
  93. {
  94. register byte    *g=r+fsize, *b=g+fsize;
  95.     while (fsize--)    {
  96.     *r++ = map[0][*ibp];
  97.     *g++ = map[1][*ibp];
  98.     *b++ = map[2][*ibp++];
  99.     }
  100. }
  101.  
  102.