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

  1. /*    RLE_Read . 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    5/1/91
  33. */
  34.  
  35. #include "header.def"
  36. #include "imagedef.h"
  37.  
  38. #ifndef    StdIconWidth
  39. #define    StdIconWidth    128
  40. #endif
  41.  
  42. read_rle_image(img, loc_map, icon_factor)
  43. U_IMAGE    *img;
  44. cmap_t    *loc_map[3];
  45. {
  46. byte    *read_scan[3], *save_scan[3];
  47. int    i, image_y, ymax=rle_dflt_hdr.ymax, width=img->width;
  48. rle_pixel**    scanline;
  49.  
  50. if (!icon_factor)
  51.     icon_factor = width / (img->icon_width ? img->icon_width : StdIconWidth);
  52. verify_buffer_size(&img->src, width * img->height, img->dpy_channels,
  53.         "rle-src");
  54. if (rle_row_alloc(&rle_dflt_hdr, &scanline))
  55.     return    prgmerr(0, img->name);
  56.  
  57. if (img->channels==1 && rle_dflt_hdr.ncmap)
  58.     rlemap_to_regmap(loc_map, &rle_dflt_hdr);
  59.  
  60. while ((image_y=ymax-rle_getrow(&rle_dflt_hdr, scanline)) >= 0)    {
  61. register byte    *obp = (byte*) img->src +
  62.             image_y * width * img->dpy_channels;
  63.  
  64.     if (img->channels == img->dpy_channels) {    /*    RLE output    */
  65.     if (img->channels > 1)
  66.         if (!img->color_dpy)
  67.         ill_to_gray(obp, scanline[0], scanline[1], scanline[2], width);
  68.         else if (img->color_form == CFM_ILC)
  69.         line_to_cell_color(obp, scanline[0], width, 1);
  70.         else
  71.         memcpy(obp, scanline[0], width),
  72.         memcpy(obp+width, scanline[1], width),
  73.         memcpy(obp+(width<<1), scanline[2], width);
  74.     else {
  75.         if (loc_map[0] && !img->color_dpy)
  76.             map8_gray(obp, *scanline, width, loc_map);
  77.         else    memcpy(obp, *scanline, width);
  78.         obp -= width;
  79.     }
  80.     }
  81.     else if (img->channels == 1 && img->dpy_channels == 3)
  82.     snf_to_rle(obp, *scanline, width, 8, loc_map);
  83.     else
  84.     ill_to_gray(obp, scanline[0], scanline[1], scanline[2], width);
  85. }
  86.  
  87. rle_row_free(&rle_dflt_hdr, scanline);
  88. if (!img->color_dpy || img->dpy_depth==1)
  89.     img->channels = 1;
  90. else    img->channels = img->dpy_channels;
  91.  
  92. return    (ymax - rle_dflt_hdr.ymin - image_y) * width;
  93. }
  94.  
  95.  
  96. #define    map_pixel(pix, cmaplen, cmap)    (pix > cmaplen ? pix : cmap[pix]>>8)
  97.  
  98. gray_to_rle(obp, ibp, img, cmaplen, map)
  99. byte    *obp, *ibp;
  100. U_IMAGE    *img;
  101. unsigned short    *map[];
  102. {
  103. register int    i, width=img->width;
  104. register byte    *cp[3];
  105.  
  106. for (cp[0] = obp, i=1; i<img->dpy_channels; i++)
  107.     cp[i] = cp[i-1] + width;
  108. ibp += img->channels * width;
  109.  
  110. while (width--)    {
  111.     for (i=img->dpy_channels; i--;)
  112.         cp[i][width] = map_pixel(*ibp, cmaplen, map[i]);
  113.     ibp--;
  114. }
  115. }
  116.