home *** CD-ROM | disk | FTP | other *** search
/ Encyclopedia of Graphics File Formats Companion / GFF_CD.ISO / software / unix / saoimage / sao1_07.tar / irafdisp.c < prev    next >
C/C++ Source or Header  |  1992-10-09  |  8KB  |  246 lines

  1. #ifndef lint
  2. static char SccsId[] = "%W%  %G%";
  3. #endif
  4.  
  5. /* Module:    irafdisp.c (Iraf Display)
  6.  * Purpose:    Respond to input from IRAF meant for Imtool
  7.  * Subroutine:    imtool_reinit()            returns: int
  8.  * Subroutine:    disp_subpiece()            returns: void
  9.  * Subroutine:    set_imtool_scale()        returns: void
  10.  * Subroutine:    set_imtool_color()        returns: void
  11.  * Copyright:    1989 Smithsonian Astrophysical Observatory
  12.  *        You may do anything you like with this file except remove
  13.  *        this copyright.  The Smithsonian Astrophysical Observatory
  14.  *        makes no representations about the suitability of this
  15.  *        software for any purpose.  It is provided "as is" without
  16.  *        express or implied warranty.
  17.  * Modified:    {0} Michael VanHilst                7 Nov 1989
  18.  *        {1} MVH don't set imtool_colors if halftone    24 Nov 1989
  19.  *        {2} FV change scale_max to 199 to insure        9 Oct 1992
  20.  *              unit scaling
  21.  *        {n} <who> -- <does what> -- <when>
  22.  */
  23.  
  24. #ifdef IMTOOL
  25.  
  26. #include <stdio.h>        /* stderr, FILE, NULL, etc. */
  27. #include <X11/Xlib.h>        /* get X types and constants */
  28. #include <X11/Xutil.h>        /* X window manager stuff */
  29. #include "hfiles/constant.h"    /* define codes */
  30. #include "hfiles/struct.h"    /* declare structure types */
  31. #include "hfiles/extern.h"    /* extern main SAOimage parameter structures */
  32. #include "hfiles/scale.h"    /* define scaling constants */
  33.  
  34. /*
  35.  * Subroutine:    imtool_reinit
  36.  * Purpose:    Reinitialize parameters after any buffer size change and
  37.  *        before loading new
  38.  */
  39. void imtool_reinit ( width, height )
  40.      int width, height;
  41. {
  42.   void init_img(), init_dispcen(), d_transform(), new_panbox();
  43.   int init_imagebuf();
  44.  
  45.   img.fiX1 = 1;
  46.   img.fiY1 = 1;
  47.   img.fiX2 = width;
  48.   img.fiY2 = height;
  49.   /* force default of display center on new size, else use current center */
  50.   if( (img.filecols != width) || (img.filerows != height) ) {
  51.     img.filecols = width;
  52.     img.filerows = height;
  53.     img.fdcenX = 0.0;
  54.     img.fdcenY = 0.0;
  55.     img.fdblock = 0;
  56.   } else {
  57.     float fdx, fdy;
  58.     /* translate from file to img coords */
  59.     d_transform(&coord.imgtofile, coord.id.cenX, coord.id.cenY, &fdx, &fdy);
  60.     img.fdcenX = (double)fdx;
  61.     img.fdcenY = (double)fdy;
  62.     img.fdblock = coord.id.block;
  63.   }
  64.   /* initialize imaging parameters */
  65.   if( control.IRAF_out.protocol == IOP_PROS )
  66.     img.file_type = SOP_PROS;
  67.   else
  68.     img.file_type = SOP_Imtool;
  69.   /* imtool packets are 8bit (for now, anyway) */
  70.   img.bytepix = 1;
  71.   init_img(&img, &coord);
  72.   init_dispcen(&img, &coord);
  73.   (void)init_imagebuf();
  74.   /* don't flag that buffer must be loaded, it's not that kind of load */
  75.   coord.buferror = 0;
  76.   buffer.load_filebuf = 0;
  77.   /* set up the panbox accordingly */
  78.   new_panbox(1);
  79. }
  80.  
  81. /*
  82.  * Subroutine:    disp_subpiece
  83.  * Purpose:    Map and display a sub-section of the full buffer.
  84.  */
  85. void disp_subpiece ( x1, y1, x2, y2 )
  86.      int x1, y1, x2, y2;    /* i: coordinates in buffer.shortbuf */
  87. {
  88.   float dx1, dy1, dx2, dy2;
  89.   float iX1, iY1, iX2, iY2;
  90.   Coordsys disp;
  91.   Edges bd;
  92.   int dy, dh;
  93.   int bh, block, py_off;
  94.   char *data;
  95.   short *sb, *pb;
  96.   void d_transform(), set_edges(), map_dispbox(), disp_dispbox();
  97.   void set_dispoff(), new_panimage();
  98.  
  99.   /* set box to map only the given section */
  100.   bcopy((char *)&coord.disp, (char *)&disp, sizeof(Coordsys));
  101.   bcopy((char *)&coord.bd, (char *)&bd, sizeof(Edges));
  102.   d_transform(&coord.buftoimg, (double)x1, (double)y1, &iX1, &iY1);
  103.   d_transform(&coord.imgtodisp, (double)iX1, (double)iY1, &dx1, &dy1);
  104.   d_transform(&coord.buftoimg,
  105.           (double)(x2 + 1), (double)(y2 + 1), &iX2, &iY2);
  106.   d_transform(&coord.imgtodisp, (double)iX2, (double)iY2, &dx2, &dy2);
  107.   /* ignore if section is not visible in the display window */
  108.   if( (dx1 <= (float)dispbox.width) && (dx2 > 1.0) &&
  109.       (dy1 <= (float)dispbox.height) && (dy2 > 1.0) ) {
  110.     /* clip edges to the display window */
  111.     if( dx1 < 0.0 )
  112.       dx1 = 0.0;
  113.     if( dx2 > (float)dispbox.width )
  114.       dx2 = (float)dispbox.width;
  115.     if( dy1 < 0.0 )
  116.       dy1 = 0.0;
  117.     if( dy2 > (float)dispbox.height )
  118.       dy2 = (float)dispbox.height;
  119.     coord.disp.X1 = dx1;
  120.     coord.disp.Y1 = dy1;
  121.     coord.disp.X2 = dx2;
  122.     coord.disp.Y2 = dy2;
  123.     coord.disp.Y1i = (int)dy1;
  124.     coord.disp.Y2i = (int)dy2 - 1;
  125.     coord.disp.Yhght = 1 + coord.disp.Y2i - coord.disp.Y1i;
  126.     set_edges(&coord.disptobuf, &coord.buf, &coord.disp, &coord.bd);
  127.     /* redefine the edges in the display window if at edge of buffer */
  128.     if( coord.bd.block < 0 )
  129.       set_dispoff(&coord.disptobuf, &coord.disp, &coord.bd);
  130.     map_dispbox();
  131.     bcopy((char *)&disp, (char *)&coord.disp, sizeof(Coordsys));
  132.     bcopy((char *)&bd, (char *)&coord.bd, sizeof(Edges));
  133.     /* set box to only draw the given section */
  134.     dy = dispbox.yzero;
  135.     dh = dispbox.yheight;
  136.     data = dispbox.image.data;
  137.     dispbox.yzero = dy1;
  138.     dispbox.yheight = (int)(0.5 + dy2 - dy1);
  139.     /* note this works for halftone (bit/pixel) and color (byte/pixel) */
  140.     dispbox.image.data += (dispbox.yzero * dispbox.image.bytes_per_line);
  141.     disp_dispbox();
  142.     dispbox.yzero = dy;
  143.     dispbox.yheight = dh;
  144.     dispbox.image.data = data;
  145.   }
  146.   /* replace the panbox with a new one */
  147.   block = (int)coord.pantoimg.inx_outx;
  148.   bh = coord.pan.Yhght;
  149.   dh = panbox.yheight;
  150.   dy = panbox.yzero;
  151.   data = panbox.image.data;
  152.   pb = buffer.panbuf;
  153.   sb = buffer.shortbuf;
  154.   /* this should always be true, since imtool doesn't do less than 512 */
  155.   if( block >= 1 ) {
  156.     y1 = (y1 / block) * block;
  157.     y2 = (((y2 / block) + 1) * block) - 1;
  158.     if( y2 >= coord.buf.Yhght )
  159.       y2 = coord.buf.Yhght - 1;
  160.     py_off = y1 / block;
  161.     buffer.shortbuf += (y1 * coord.buf.width);
  162.     buffer.panbuf += (py_off * coord.pan.Xwdth);
  163.     coord.pan.Yhght = (1 + y2 - y1) / block;
  164.     panbox.yzero = py_off;
  165.     panbox.yheight = coord.pan.Yhght;
  166.     panbox.image.data += (panbox.yzero * panbox.image.bytes_per_line);
  167.   } else
  168.     py_off = -1;
  169.   new_panimage();
  170.   disp_panbox();
  171.   if( py_off >= 0 ) {
  172.     buffer.shortbuf = sb;
  173.     buffer.panbuf = pb;
  174.     panbox.yzero = dy;
  175.     panbox.yheight = dh;
  176.     panbox.image.data = data;
  177.   }
  178.   coord.pan.Yhght = bh;
  179. }
  180.  
  181. /*
  182.  * Subroutine:    set_imtool_scale
  183.  * Purpose:    Force the scalemap to match the range of imtool image data
  184.  */
  185. void set_imtool_scale()
  186. {
  187.   void set_imtool_colors(), make_scalemap(), touch_submenu_button();
  188.  
  189.   /* identify min and max used by imtool */
  190.   buffer.clipmin = 1;
  191.   buffer.clipmax = 200;
  192.   buffer.scale_min = 0;
  193.   buffer.scale_max = 199;
  194.   /* force new scaling, but not hisotgram equalize if it would be invoked */
  195.   if( (color.scale.mode == SOP_HistEq) &&
  196.       (color.ncolors < 200) && (color.ncolors > 1) ) {
  197.     color.scale.mode = SOP_Linear;
  198.     touch_submenu_button(SOP, SOP_Linear);
  199.   }
  200.   if( color.ncolors == 1 ) {
  201.     color.ncolors = 256;
  202.     make_scalemap(0, 199);
  203.     color.ncolors = 1;
  204.   } else {
  205.     make_scalemap(0, 199);
  206.     set_imtool_colors();
  207.   }
  208. }
  209.  
  210. /*
  211.  * Subroutine:    set_imtool_colors
  212.  * Purpose:    Map colors used as graphics options in imtool
  213.  */
  214. void set_imtool_colors ()
  215. {
  216.   unsigned char *lookup;
  217.  
  218.   lookup = buffer.scalemap + SCALEOFF;
  219.   /* imtool cursor color */
  220.   lookup[201] = (unsigned char)color.gcset.draw.foreground;
  221.   lookup[202] = (unsigned char)color.hard.true_black;
  222.   lookup[203] = (unsigned char)color.hard.true_white;
  223.   lookup[204] = (unsigned char)color.hard.red;
  224.   lookup[205] = (unsigned char)color.hard.green;
  225.   lookup[206] = (unsigned char)color.hard.blue;
  226.   lookup[207] = (unsigned char)color.hard.yellow;
  227.   lookup[208] = (unsigned char)color.hard.std_black;    /* imtool cyan */
  228.   lookup[209] = (unsigned char)color.hard.std_white;    /* imtool magenta */
  229.   lookup[210] = (unsigned char)color.hard.yellow;    /* imtool coral */
  230.   lookup[211] = (unsigned char)color.hard.red;        /* imtool maroon */
  231.   lookup[212] = (unsigned char)color.hard.yellow;    /* imtool orange */
  232.   lookup[213] = (unsigned char)color.hard.std_white;    /* imtool khaki */
  233.   lookup[214] = (unsigned char)color.hard.red;        /* imtool orchid */
  234.   lookup[215] = (unsigned char)color.hard.green;    /* imtool turquoise */
  235.   lookup[216] = (unsigned char)color.hard.blue;        /* imtool violet */
  236.   lookup[217] = (unsigned char)color.hard.std_white;    /* imtool wheat */
  237. }
  238.  
  239. #endif
  240.            
  241.                                                                
  242.                                                               
  243.  
  244.                                                                
  245.                                                              
  246.