home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / x / volume5 / xldimage / part01 / misc.c < prev    next >
Encoding:
C/C++ Source or Header  |  1989-11-13  |  4.9 KB  |  153 lines

  1. /* misc.c:
  2.  *
  3.  * miscellaneous funcs
  4.  *
  5.  * jim frost 10.05.89
  6.  *
  7.  * Copyright 1989 Jim Frost.  See included file "copyright.h" for complete
  8.  * copyright information.
  9.  */
  10.  
  11. #include "copyright.h"
  12. #include "xloadimage.h"
  13.  
  14. void usage(name)
  15.      char *name;
  16. {
  17.   printf("Usage: %s [global options] {[image options] image_name ...}\n",
  18.      tail(name));
  19.   printf("Global options:\n");
  20.   printf("  -onroot               - load image onto root window\n");
  21.   printf("  -border colorname     - border image with this color\n");
  22.   printf("  -display dispname     - destination display\n");
  23.   printf("  -geometry WxH+X+Y     - destination size and location\n");
  24.   printf("  -help                 - print this help message\n");
  25.   printf("  -identify             - identify given images\n");
  26.   printf("  -list                 - list images in path\n");
  27.   printf("  -install              - explicitly install colormap\n");
  28.   printf("  -path                 - show image path for loading\n");
  29.   printf("  -quiet                - silence is golden\n");
  30.   printf("  -supported            - show supported image types\n");
  31.   printf("  -verbose              - whistle while you work\n");
  32.   printf("  -view                 - view image in a window\n");
  33.   printf("Image_options:\n");
  34.   printf("  -at X,Y               - load image at location\n");
  35.   printf("  -background colorname - background color for bitmap images\n");
  36.   printf("  -brighten percentage  - specify brightness multiplier\n");
  37.   printf("  -center               - center image\n");
  38.   printf("  -colors number        - specify maximum number of RGB colors\n");
  39.   printf("  -clip X,Y,W,H         - use clipped portion of image\n");
  40.   printf("  -dither               - dither color image to bitmap image\n");
  41.   printf("  -foreground colorname - foreground color for bitmap images\n");
  42.   printf("  -name name            - force next argument to be image name\n");
  43.   printf("  -xzoom percentage     - zoom the X axis by a percentage\n");
  44.   printf("  -yzoom percentage     - zoom the Y axis by a percentage\n");
  45.   printf("  -zoom percentage      - zoom the image by a percentage\n");
  46.   exit(1);
  47. }
  48.  
  49. char *tail(path)
  50.      char *path;
  51. { int   s;
  52.   char *t;
  53.  
  54.   t= path;
  55.   for (s= 0; *(path + s) != '\0'; s++)
  56.     if (*(path + s) == '/')
  57.       t= path + s + 1;
  58.   return(t);
  59. }
  60.  
  61. Image *processImage(disp, scrn, image, options, verbose)
  62.      Display      *disp;
  63.      int           scrn;
  64.      Image        *image;
  65.      ImageOptions *options;
  66.      unsigned int  verbose;
  67. { Image        *tmpimage;
  68.   XColor        xcolor;
  69.   unsigned int  compressed= 0;
  70.  
  71.   goodImage(image);
  72.  
  73.   /* clip the image if requested
  74.    */
  75.  
  76.   if ((options->clipx != 0) || (options->clipy != 0) ||
  77.       (options->clipw != 0) || (options->cliph != 0)) {
  78.     if (!options->clipw)
  79.       options->clipw= image->width;
  80.     if (!options->cliph)
  81.       options->cliph= image->height;
  82.     tmpimage= clip(image, options->clipx, options->clipy, options->clipw,
  83.            options->cliph, verbose);
  84.     freeImage(image);
  85.     image= tmpimage;
  86.   }
  87.  
  88.   if (options->xzoom || options->yzoom) { /* zoom image */
  89.     if (!options->colors && RGBP(image) &&             /* if the image is to */
  90.     (!options->xzoom && (options->yzoom > 100)) || /* be blown up, */
  91.     (!options->yzoom && (options->xzoom > 100)) || /* compress before */
  92.     (options->xzoom + options->yzoom > 200)) {     /* doing it */
  93.       compress(image, verbose);
  94.       compressed= 1;
  95.     }
  96.     tmpimage= zoom(image, options->xzoom, options->yzoom, verbose);
  97.     freeImage(image);
  98.     image= tmpimage;
  99.   }
  100.  
  101.   if (options->bright) /* alter image brightness */
  102.     brighten(image, options->bright, verbose);
  103.  
  104.   /* forcibly reduce colormap
  105.    */
  106.  
  107.   if (options->colors && RGBP(image) && (options->colors < image->rgb.used)) {
  108.     reduce(image, options->colors, verbose);
  109.     image->rgb.size= options->colors; /* lie */
  110.     compressed= 1;
  111.   }
  112.  
  113.   if (options->dither && (image->depth > 1)) { /* image is to be dithered */
  114.     tmpimage= dither(image, verbose);
  115.     freeImage(image);
  116.     image= tmpimage;
  117.     options->clipx *= 4;      /* image was blown up by 4 */
  118.     options->clipy *= 4;
  119.     options->clipw *= 4;
  120.     options->cliph *= 4;
  121.   }
  122.   else if (!compressed)       /* make sure colormap is minimized */
  123.     compress(image, verbose);
  124.  
  125.   /* set foreground and background colors of mono image
  126.    */
  127.  
  128.   xcolor.flags= DoRed | DoGreen | DoBlue;
  129.   if ((image->depth == 1) && options->fg) {
  130.     XParseColor(disp, DefaultColormap(disp, scrn), options->fg, &xcolor);
  131.     *(image->rgb.red + 1)= xcolor.red;
  132.     *(image->rgb.green + 1)= xcolor.green;
  133.     *(image->rgb.blue + 1)= xcolor.blue;
  134.   }
  135.   if ((image->depth == 1) && options->bg) {
  136.     XParseColor(disp, DefaultColormap(disp, scrn), options->bg, &xcolor);
  137.     *image->rgb.red= xcolor.red;
  138.     *image->rgb.green= xcolor.green;
  139.     *image->rgb.blue= xcolor.blue;
  140.   }
  141.   return(image);
  142. }
  143.  
  144. /* this gets called on an I/O error; it really assumes that a KillClient
  145.  * was issued.
  146.  */
  147.  
  148. int ioErrorHandler(disp)
  149.      Display *disp;
  150. {
  151.   exit(0);
  152. }
  153.