home *** CD-ROM | disk | FTP | other *** search
/ Graphics Plus / Graphics Plus.iso / general / procssng / ccs / ccs-11tl.lha / lbl / x11 / lib / init_img.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-03-10  |  3.8 KB  |  143 lines

  1. /*
  2. %    INIT_IMG . C
  3. %
  4. %    initialize and build image.
  5. %
  6. % AUTHOR:    Jin, Guojun - LBL
  7. */
  8.  
  9. #include "panel.h"
  10. #include "imagedef.h"
  11.  
  12. #ifndef    VERS_TUNER
  13. #define    VERS_TUNER    "A8-2"
  14. #endif
  15.  
  16. int    stingy_flag;
  17.  
  18.  
  19. void
  20. init_img_info(i, dpy, mid_ver, color_dpy) /*    extracted from x_window.c */
  21. image_information *i;
  22. Display    *dpy;
  23. {
  24.     if (dpy)    i->dpy = dpy;
  25.     i->lvls = specified_levels;
  26.     i->window = i->icn_window = NULL;
  27.     i->gc = i->icn_gc = NULL;
  28.     i->image = i->icn_image = NULL;
  29.     i->colormap = NULL;
  30.     if (mid_ver > 0)
  31.         format_init(i, IMAGE_INIT_TYPE, mid_ver, -1, Progname, VERS_TUNER);
  32.     i->marray = ZALLOC(sizeof(*(i->marray)), 3, "m_3channel");
  33.     i->pixmap_failed = False;
  34.  
  35.     i->name = i->title = NULL;
  36.     i->img_num = i->sub_img = i->img_channels = 0;
  37.     i->scan_data = NULL;
  38.     i->map_scanline = NULL;
  39.     i->MAG_scanline = NULL;
  40.     i->x = i->y =
  41.     i->w = i->h =
  42.     i->icn_w = i->icn_h = 0;
  43.  
  44.     i->mag_x = i->mag_x =
  45.     i->mag_w = i->mag_h = 0;
  46.     i->mag_fact = i->save_mag_fact = 1;
  47.     i->mag_mode = False;
  48.  
  49.     i->binary_img = i->dither_img = i->mono_img = False;
  50.     i->rw_cmap = i->sep_colors = i->mono_color = False;
  51.     i->color_dpy = color_dpy < 0 ? True : color_dpy;
  52.  
  53.     i->in_cmap = NULL;
  54.     if (mid_ver > HIPS) {
  55.         i->gamma = 0.0;
  56.         i->ncmap = i->cmlen = 0;
  57.         i->pix_info_window = NULL;
  58.         i->pixmap = i->icn_pixmap = i->mag_pixmap = NULL;
  59.         i->modN = i->divN = i->pixel_table = NULL;
  60.         i->dm16 = NULL;
  61.         if (!i->visual_class)
  62.             i->visual_class = -1;
  63.     }
  64. }
  65.  
  66. BuildColorImage(img, previous_img, window_geometry, icon_factor)
  67. image_information    *img, *previous_img;
  68. char    *window_geometry;
  69. int    *icon_factor;
  70. {
  71. extern XImage    *get_XImage();
  72. extern int    eq_cmap();
  73.  
  74.     if (!img->title) {
  75.         img->title = malloc(strlen(img->name) + sizeof(HELP_INFO) + 8);
  76.         sprintf(img->title, "%s(%d) %s", img->name,
  77.         (img->in_type!=RLE ? img->RGB : img->img_num) + 1, HELP_INFO);
  78.     }
  79.  
  80.     get_dither_colors(img);
  81.     if (!previous_img)    /* Get X color map */
  82.         init_color(img);
  83.     /*
  84.     * If we are running movie, we need to be nasty here. img->w, img->h
  85.     * and img->img_channels must match the previous one. Otherwise, it can
  86.     * be screwed up.
  87.     */
  88.     if (previous_img && previous_img != img) {
  89.         if (img->w != previous_img->w || img->h != previous_img->h ||
  90.         img->img_channels != previous_img->img_channels){
  91.         prgmerr(0, "Images %s & %s dont match in size or channels",
  92.             previous_img->title, img->title);
  93.         return    FATAL_FAILURE;
  94.         }
  95.         if ((img->mono_color &&
  96.         !eq_cmap(previous_img->in_cmap, previous_img->cmlen,
  97.             img->in_cmap, img->cmlen)))    {
  98.         prgmerr(0, "Images %s and %s have different colormaps",
  99.             previous_img->title, img->title);
  100.         return    FATAL_FAILURE;
  101.         }
  102.     }
  103.     else {    /* only dick with the icon if it isn't a moive    */
  104.         *icon_factor = get_iconsize(img, 0);
  105.         if (!img->icn_image)
  106.             img->icn_image = get_XImage(img, img->icn_w, img->icn_h, 1);
  107.  
  108.         if (!img->icn_image) {
  109.             prgmerr(0, "malloc for fancy icon");
  110.             return    (MALLOC_FAILURE);
  111.         }
  112.     }
  113.     /*
  114.     * If we have to conserve memory on the client side and not allocate a
  115.     * new Ximage structure with associated memory for image data.  Also, if
  116.     * the server was unable to supply us with a pixmap in previous_img,
  117.     * we need to save a XImage there. If the slow mode is used, then we
  118.     * will save images in server side for movies.
  119.     */
  120.     if (!previous_img || previous_img==img || previous_img->pixmap==NULL) {
  121.         if (img->image &&
  122.         (img->w+1 != img->image->width || img->h != img->image->height))
  123.         free(img->image->data),    XDestroyImage(img->image),
  124.         img->image = NULL;
  125.         if (!img->image)
  126.         img->image = get_XImage(img, img->w+1, img->h, True);
  127.  
  128.         if (img->image == NULL) {
  129.         prgmerr(0, "get XImage");
  130.         return    MALLOC_FAILURE;
  131.         }
  132.     }
  133.     else    img->image = previous_img->image;
  134.  
  135.     create_windows(img, window_geometry, stingy_flag);
  136.     set_watch_cursor(img->window);
  137.     if (!img->map_scanline)
  138.         choose_scanline_converter(img);    /* map_scan L102 */
  139.     XMapWindow(img->dpy, img->frame);
  140.     XMapWindow(img->dpy, img->window);
  141. return    SUCCESS;
  142. }
  143.