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

  1. /*
  2.    Copyright (c) 1991 - 1993 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_dj_gr.c: GNU-C++ (DJ's DOS port) preview part of project "hp2xx",
  25.  **             based on DJ Delorie's grapics lib "gr"
  26.  **
  27.  ** 92/01/29  V 1.00  HWW  Originating
  28.  ** 92/05/19  V 1.01  HWW  Abort if color mode
  29.  ** 92/05/25  V 1.02  HWW  B/W mode also if color; index_from_RowBuf() used
  30.  ** 92/06/12  V 1.02c HWW  getchar(), B/W warning ...
  31.  **
  32.  ** NOTE: This previewer worked fine on my machine. However, I do not intend
  33.  **       to maintain DJ Delorie's go32 DOS extender version of hp2xx in the
  34.  **       future once the extender emx 0.8f (which will support OS/2 as well)
  35.  **       becomes available (which sould be very soon -- 1Q93).
  36.  **
  37.  **       For those of you who don't want to wait, or are familiar with go32
  38.  **       and dont need OS/2 support -- this previewer is what you need.
  39.  **/
  40.  
  41.  
  42. #include <stdio.h>
  43. #include <stdlib.h>
  44. #include <ctype.h>
  45. #include <graphics.h>
  46. #include "bresnham.h"
  47. #include "hp2xx.h"
  48.  
  49.  
  50.  
  51.  
  52. void    PicBuf_to_DJ_GR (PicBuf *picbuf, PAR *p)
  53. {
  54. int    row_c, i, x, xoff, y, yoff, color_index;
  55. RowBuf    *row;
  56.  
  57.   if (!p->quiet)
  58.   {
  59.     fprintf(stderr, "\nDJ_GR preview follows.\n");
  60.     fprintf(stderr, "Press <return> to start and end graphics mode\n");
  61.     SilentWait();
  62.   }
  63.  
  64.   xoff = p->xoff * p->dpi_x / 25.4;
  65.   yoff = p->yoff * p->dpi_y / 25.4;
  66.  
  67.   if ((!p->quiet) &&
  68.       (((picbuf->nb << 3) + xoff > 639) || (picbuf->nr + yoff > 480)) )
  69.   {
  70.     fprintf(stderr, "\n\007WARNING: Picture won't fit on a standard VGA!\n");
  71.     fprintf(stderr, "Current range: (%d..%d) x (%d..%d) pels\n",
  72.         xoff, (picbuf->nb << 3) + xoff, yoff, picbuf->nr + yoff);
  73.     fprintf(stderr, "Continue anyway (y/n)?: ");
  74.     while (getchar() != '\n')
  75.         ;      /* Simple: Chance for ^C */
  76.   }
  77.  
  78.   if (p->is_color)
  79.     GrSetColor(0, 160, 160, 160);
  80.   else
  81.     GrSetColor(0, 180, 180, 180);
  82.  
  83.   GrSetColor(1, 0, 0, 0);
  84.   for (i=2; i < 8; i++)  /* assuming that we indeed get indices 2 ... 7 */
  85.     if (i!=GrAllocColor(p->Clut[i][0], p->Clut[i][1], p->Clut[i][2]))
  86.         fprintf(stderr,"WARNING: Color code %d may yield wrong color!\n", i);
  87.  
  88.   GrSetMode (GR_default_graphics, 800, 600);
  89.  
  90.   for (row_c=0, y=picbuf->nr+yoff-1; row_c < picbuf->nr; row_c++, y--)
  91.   {
  92.     row = get_RowBuf (picbuf, row_c);
  93.     for (x=0; x < picbuf->nc; x++)
  94.     {
  95.         color_index = index_from_RowBuf(row, x, picbuf);
  96.         if (color_index != xxBackground)
  97.             GrPlot(x+xoff, y, color_index);
  98.     }
  99.   }
  100.  
  101.   SilentWait();
  102.   GrSetMode (GR_80_25_text, 80, 25);
  103. }
  104.  
  105.