home *** CD-ROM | disk | FTP | other *** search
/ C!T ROM 2 / ctrom_ii_b.zip / ctrom_ii_b / PROGRAM / C / ADDPCX / PCXDISP.C < prev    next >
C/C++ Source or Header  |  1988-06-21  |  3KB  |  114 lines

  1. /*    PCXDISP.c   -  Load pictures into RAM and display them
  2. */
  3.  
  4.  
  5. #include "lib.h"
  6. #include "pcx.h"
  7.  
  8. extern int pcx_md;
  9.  
  10. void pcx_load_palette( pic )
  11. PCXPIC *pic;
  12. {
  13.     int p;
  14.  
  15.     if ( pcx_md )
  16.     {  /* this part NOT TESTED */
  17.        VGR_CPAL( pic->hdr.triple[0].red / 16, pic->hdr.triple[1].red / 32 );
  18.        return;
  19.     };
  20.  
  21.     for ( p=0; p < 16; p++ )
  22.        VGR_PALETTE( p, pic->hdr.triple[p].red   / 85,
  23.                        pic->hdr.triple[p].green / 85,
  24.                        pic->hdr.triple[p].blue  / 85 );
  25. }
  26.  
  27.  
  28. void pcx_showpic( pic, hoffs, voffs, load_palette_flg )
  29. int load_palette_flg, hoffs, voffs;
  30. PCXPIC *pic;
  31. {
  32.     int plane, row, nrows, nplan, nbytes;
  33.  
  34.     nrows = pic->hdr.y2 - pic->hdr.y1 +1;
  35.     nplan = pic->hdr.nplanes;
  36.     nbytes= pic->hdr.bpl;
  37.  
  38.     nrows  = nrows  > VGR_VRES ? VGR_VRES : nrows;
  39.     nbytes = nbytes > VGR_NBPL ? VGR_NBPL : nbytes;
  40.  
  41.     for ( plane = 0; plane < nplan; plane++ )
  42.     {  VGR_PLANE(plane ? plane : -0x0f);
  43.        for ( row = 0; row < nrows; row++ )
  44.           VGR_ROW( row, pic->rows[plane][row+voffs] + hoffs, nbytes );
  45.     };
  46.  
  47.     if ( load_palette_flg )
  48.        pcx_load_palette( pic );
  49. }
  50.  
  51. #ifdef PCX_DUMP_PIC
  52.  
  53. void pcx_dump_pic( pic )
  54. PCXPIC *pic;
  55. {
  56. #define err_printf printf
  57. #define XX(x,fmt) err_printf( #x "=" fmt, hdr->x )
  58.  
  59.     int i, j;
  60.     PCXHDR *hdr;
  61.  
  62.     hdr = &pic->hdr;
  63.  
  64.     err_printf("Hex Dump of entire header:\n");
  65.     dumpbuf( (uchar *)hdr, sizeof(*hdr) );
  66.  
  67.     err_printf("hit ESC to quit dump, ENTER for more:");
  68.     while ( (i = conin()) != 27 && i != 13 )
  69.        errbeep();
  70.     err_printf("\n");
  71.     if ( i == 27 )
  72.        return;
  73.  
  74.     XX(maker,"%u  ");
  75.     XX(version,"%u  ");
  76.     XX(code,"%u  ");
  77.     XX(bpp,"%u\n");
  78.     XX(x1,"%u  ");
  79.     XX(y1,"%u  ");
  80.     XX(x2,"%u  ");
  81.     XX(y2,"%u\n");
  82.     XX(hres,"%u  ");
  83.     XX(vres,"%u  ");
  84.     XX(vmode,"%u  ");
  85.     XX(nplanes,"%u  ");
  86.     XX(bpl,"%u\n");
  87.  
  88.     for ( i=0; i < 16; i++ )
  89.        err_printf("%2d: R%02x G%02x B%02x     ",
  90.              i, hdr->triple[i].red, hdr->triple[i].green, hdr->triple[i].blue );
  91.  
  92.     err_printf("\nHit ESC to quit dump, ENTER for more:");
  93.     while ( (i = conin()) != 27 && i != 13 )
  94.        errbeep();
  95.     err_printf("\n");
  96.     if ( i == 27 )
  97.        return;
  98.  
  99.     err_printf("Dumping ROWs, hit ESC to quit dump\n");
  100.     for ( i=0; i < hdr->nplanes; i++ )
  101.        for ( j=0; j < (hdr->y2 - hdr->y1 +1); j++ )
  102.        {  if ( pic->rows[i][j] )
  103.           {  err_printf("Plane %d, Row %d\n", i, j );
  104.              dumpbuf( (UC *)pic->rows[i][j], hdr->bpl );
  105.              if ( constat() && conin() == 27 )
  106.                 return;
  107.           };
  108.        };
  109.     err_printf("hit any key to continue\n");
  110.     conin();
  111. }
  112.  
  113. #endif
  114.