home *** CD-ROM | disk | FTP | other *** search
/ Media Share 9 / MEDIASHARE_09.ISO / os2 / hpgl312.zip / TO_UIS.C < prev    next >
C/C++ Source or Header  |  1993-04-18  |  4KB  |  149 lines

  1. /*
  2.    Copyright (c) 1992  Heinz W. Werntges.  All rights reserved.
  3.    Distributed by Free Software Foundation, Inc.
  4.  
  5. This file is part of HP2xx.
  6.  
  7. HP2xx is distributed in the hope that it will be useful, but
  8. WITHOUT ANY WARRANTY.  No author or distributor accepts responsibility
  9. to anyone for the consequences of using it or for whether it serves any
  10. particular purpose or works at all, unless he says so in writing.  Refer
  11. to the GNU General Public License, Version 2 or later, for full details.
  12.  
  13. Everyone is granted permission to copy, modify and redistribute
  14. HP2xx, but only under the conditions described in the GNU General Public
  15. License.  A copy of this license is supposed to have been
  16. given to you along with HP2xx so you can know your rights and
  17. responsibilities.  It should be in a file named COPYING.  Among other
  18. things, the copyright notice and this notice must be preserved on all
  19. copies.
  20.  
  21. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  22. */
  23.  
  24. /** to_uis.c: VAX/VMS UIS previewer of project "hp2xx"
  25.  **
  26.  ** 92/04/15  V 1.00  HWW  Originating, based on mandel.c (V 1.02)
  27.  **                        Raw coding, not tested yet!
  28.  ** 92/04/24  V 1.01  HWW  Tested and accelerated on uVAX, VMS 4.7
  29.  ** 92/04/27  V 1.02  HWW  Cleaned up
  30.  ** 92/05/25  V 1.02b HWW  Abort if color mode (due to lack of
  31.  **               test facilities) -- Color support desired!
  32.  **
  33.  ** NOTE: Due to lack of testing facilities, I will not be able to maintain
  34.  **       this file any longer. Volunteers are welcome!
  35.  **       If none will be found, I'll move this file to ../extras soon.
  36.  **/
  37.  
  38.  
  39. #include <stdio.h>
  40. #include <stdlib.h>
  41. #include <ctype.h>
  42. #include <descrip.h>
  43. #include <uisentry.h>
  44. #include <uisusrdef.h>
  45. #include "bresnham.h"
  46. #include "hp2xx.h"
  47.  
  48.  
  49.  
  50. void    PicBuf_to_UIS (PicBuf *picbuf, PAR *p)
  51. {
  52. int        byte_c, xoff, yoff;
  53. unsigned long    row_c, x1, x2, rw, rh, bpp, zero=0, two=2;
  54. RowBuf        *row;
  55.  
  56. float        x0f, y0f, x1f, y1f, w, h;
  57. int        c_old, c_new, i;
  58. unsigned    vd_id, wd_id;
  59. char        *target = "sys$workstation";
  60. static float    intens[2] = {0.0, 1.0};
  61. static unsigned    atb    = 1;
  62.  
  63. struct dsc$descriptor_s    s_desc;
  64.  
  65.  
  66.   if (picbuf->depth > 1)
  67.   {
  68.     fprintf(stderr, "\nUIS preview does not support colors yet -- sorry\n");
  69.     free_PicBuf (picbuf, p->swapfile);
  70.     exit (ERROR);
  71.   }
  72.  
  73.   if (!p->quiet)
  74.   {
  75.     fprintf(stderr, "\nUIS preview follows\n");
  76.     fprintf(stderr, "Press <return> to end\n");
  77.   }
  78.  
  79.   xoff = p->xoff * p->dpi_x / 25.4;
  80.   yoff = p->yoff * p->dpi_y / 25.4;
  81.  
  82.   if ((!p->quiet) &&
  83.       (((picbuf->nb << 3) + xoff > 1024) || (picbuf->nr + yoff > 1024)) )
  84.   {
  85.     fprintf(stderr, "\n\007WARNING: Picture won't fit!\n");
  86.     fprintf(stderr, "Current range: (%d..%d) x (%d..%d) pels\n",
  87.         xoff, (picbuf->nb << 3) + xoff, yoff, picbuf->nr + yoff);
  88.     fprintf(stderr, "Continue anyway (y/n)?: ");
  89.     if (toupper(getchar()) != 'Y')
  90.         return;
  91.   }
  92.  
  93.   x0f = y0f = 0.0;            /* No offsets yet    */
  94.   x1f = (float) (picbuf->nb << 3);
  95.   y1f = (float) picbuf->nr;
  96.   w   = (float) p->width / 10.0;    /* VAX needs cm, not mm */
  97.   h   = (float) p->height/ 10.0;
  98.  
  99.   vd_id = uis$create_display (&x0f, &y0f, &x1f, &y1f,&w, &h);
  100.   uis$disable_display_list (&vd_id);
  101.   uis$set_intensities (&vd_id, &zero, &two, intens);
  102.  
  103.   s_desc.dsc$w_length = strlen (target);
  104.   s_desc.dsc$a_pointer= target;
  105.   s_desc.dsc$b_class  = DSC$K_CLASS_S;
  106.   s_desc.dsc$b_dtype  = DSC$K_DTYPE_T;
  107.   wd_id = uis$create_window (&vd_id,&s_desc);
  108.  
  109.   x1 = 0;
  110.   x2 = picbuf->nc;
  111.   rw = picbuf->nc;
  112.   rh = 1;
  113.   bpp = 1;
  114.  
  115.   for (row_c = 0; row_c < picbuf->nr; row_c++)    /* for all pixel rows */
  116.   {
  117. /**
  118.  ** Unfortunately, we need a bit reversal in each byte here:
  119.  **/
  120.     row = get_RowBuf (picbuf, row_c);
  121.     for (byte_c=0; byte_c < picbuf->nb; byte_c++)
  122.     {
  123.         c_old = row->buf[byte_c];
  124.  
  125.         if (c_old == 0)        /* all white    */
  126.             continue;
  127.         if (c_old == 0xff)    /* all black    */
  128.             continue;
  129.  
  130.         for (i=0, c_new=0; ; )
  131.         {
  132.             if (c_old & 1)
  133.             c_new |= 1;
  134.             if (++i == 8)    /* 8 bits, 7 shifts    */
  135.             break;
  136.             c_new <<= 1;
  137.             c_old >>= 1;
  138.         }
  139.         row->buf[byte_c] = c_new;
  140.     }
  141.  
  142.     uisdc$image(&wd_id, &atb, &x1, &row_c, &x2, &row_c,
  143.             &rw, &rh, &bpp, row->buf);
  144.   }
  145.   getchar();
  146.   uis$delete_display (&vd_id);
  147. }
  148.  
  149.