home *** CD-ROM | disk | FTP | other *** search
- /* RLE_Read . C
- %
- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-
- This software is copyright (C) by the Lawrence Berkeley Laboratory.
- Permission is granted to reproduce this software for non-commercial
- purposes provided that this notice is left intact.
-
- It is acknowledged that the U.S. Government has rights to this software
- under Contract DE-AC03-765F00098 between the U.S. Department of Energy
- and the University of California.
-
- This software is provided as a professional and academic contribution
- for joint exchange. Thus, it is experimental, and is provided ``as is'',
- with no warranties of any kind whatsoever, no support, no promise of
- updates, or printed documentation. By using this software, you
- acknowledge that the Lawrence Berkeley Laboratory and Regents of the
- University of California shall have no liability with respect to the
- infringement of other copyrights by any part of this software.
-
- For further information about this notice, contact William Johnston,
- Bld. 50B, Rm. 2239, Lawrence Berkeley Laboratory, Berkeley, CA, 94720.
- (wejohnston@lbl.gov)
-
- For further information about this software, contact:
- Jin Guojun
- Bld. 50B, Rm. 2275, Lawrence Berkeley Laboratory, Berkeley, CA, 94720
- g_jin@lbl.gov
-
- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- %
- % AUTHOR: Jin Guojun - LBL 5/1/91
- */
-
- #include "header.def"
- #include "imagedef.h"
-
- #ifndef StdIconWidth
- #define StdIconWidth 128
- #endif
-
- read_rle_image(img, loc_map, icon_factor)
- U_IMAGE *img;
- cmap_t *loc_map[3];
- {
- byte *read_scan[3], *save_scan[3];
- int i, image_y, ymax=rle_dflt_hdr.ymax, width=img->width;
- rle_pixel** scanline;
-
- if (!icon_factor)
- icon_factor = width / (img->icon_width ? img->icon_width : StdIconWidth);
- verify_buffer_size(&img->src, width * img->height, img->dpy_channels,
- "rle-src");
- if (rle_row_alloc(&rle_dflt_hdr, &scanline))
- return prgmerr(0, img->name);
-
- if (img->channels==1 && rle_dflt_hdr.ncmap)
- rlemap_to_regmap(loc_map, &rle_dflt_hdr);
-
- while ((image_y=ymax-rle_getrow(&rle_dflt_hdr, scanline)) >= 0) {
- register byte *obp = (byte*) img->src +
- image_y * width * img->dpy_channels;
-
- if (img->channels == img->dpy_channels) { /* RLE output */
- if (img->channels > 1)
- if (!img->color_dpy)
- ill_to_gray(obp, scanline[0], scanline[1], scanline[2], width);
- else if (img->color_form == CFM_ILC)
- line_to_cell_color(obp, scanline[0], width, 1);
- else
- memcpy(obp, scanline[0], width),
- memcpy(obp+width, scanline[1], width),
- memcpy(obp+(width<<1), scanline[2], width);
- else {
- if (loc_map[0] && !img->color_dpy)
- map8_gray(obp, *scanline, width, loc_map);
- else memcpy(obp, *scanline, width);
- obp -= width;
- }
- }
- else if (img->channels == 1 && img->dpy_channels == 3)
- snf_to_rle(obp, *scanline, width, 8, loc_map);
- else
- ill_to_gray(obp, scanline[0], scanline[1], scanline[2], width);
- }
-
- rle_row_free(&rle_dflt_hdr, scanline);
- if (!img->color_dpy || img->dpy_depth==1)
- img->channels = 1;
- else img->channels = img->dpy_channels;
-
- return (ymax - rle_dflt_hdr.ymin - image_y) * width;
- }
-
-
- #define map_pixel(pix, cmaplen, cmap) (pix > cmaplen ? pix : cmap[pix]>>8)
-
- gray_to_rle(obp, ibp, img, cmaplen, map)
- byte *obp, *ibp;
- U_IMAGE *img;
- unsigned short *map[];
- {
- register int i, width=img->width;
- register byte *cp[3];
-
- for (cp[0] = obp, i=1; i<img->dpy_channels; i++)
- cp[i] = cp[i-1] + width;
- ibp += img->channels * width;
-
- while (width--) {
- for (i=img->dpy_channels; i--;)
- cp[i][width] = map_pixel(*ibp, cmaplen, map[i]);
- ibp--;
- }
- }
-