home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-386-Vol-2of3.iso / b / baswiz19.zip / BW$BAS.ZIP / G13SHOWB.BAS < prev    next >
BASIC Source File  |  1993-01-31  |  4KB  |  87 lines

  1. '   +----------------------------------------------------------------------+
  2. '   |                                                                      |
  3. '   |        BASWIZ  Copyright (c) 1990-1993  Thomas G. Hanlin III         |
  4. '   |                                                                      |
  5. '   |                      The BASIC Wizard's Library                      |
  6. '   |                                                                      |
  7. '   +----------------------------------------------------------------------+
  8.  
  9.    DECLARE SUB FOpen (File$, FMode$, BufferLen%, Handle%, ErrCode%)
  10.    DECLARE FUNCTION FGetError% (BYVAL Handle%)
  11.    DECLARE FUNCTION FGetSize& (BYVAL Handle%)
  12.    DECLARE SUB FLocate (BYVAL Handle%, Posn&)
  13.    DECLARE SUB FBlockRead (BYVAL Handle%, BYVAL Segm%, BYVAL Ofs%, BYVAL Bytes%)
  14.    DECLARE FUNCTION FRead$ (BYVAL Handle%, BYVAL Bytes%)
  15.    DECLARE SUB FClose (Handle%)
  16.    DECLARE SUB G13Color (BYVAL Foreground%, BYVAL Background%)
  17.    DECLARE SUB G13Plot (BYVAL X%, BYVAL Y%)
  18.    DECLARE SUB VPalette (BYVAL PalReg%, BYVAL Red%, BYVAL Green%, BYVAL Blue%)
  19.  
  20.    DECLARE SUB PalBlk0 (BYVAL DSeg%, BYVAL DOfs%, BYVAL Colors%)
  21.  
  22. SUB G13ShowBMP (File$, OrigX%, OrigY%, ErrCode%)
  23.    ErrCode% = 0
  24.    FOpen File$, "R", 0, Handle%, ErrCode%
  25.    IF ErrCode% = 0 THEN
  26.       Header$ = FRead$(Handle%, 54)
  27.       ErrCode% = FGetError%(Handle%)
  28.       IF ErrCode% = 0 THEN
  29.          PWide& = CVL(MID$(Header$, 19, 4))
  30.          PHigh& = CVL(MID$(Header$, 23, 4))
  31.          BitPlanes% = CVI(MID$(Header$, 27, 2))
  32.          ColorBits% = CVI(MID$(Header$, 29, 2))
  33.          IF LEFT$(Header$, 2) <> "BM" THEN
  34.             ErrCode% = -1    ' invalid BMP
  35.          ELSEIF NOT (BitPlanes% = 1 AND ColorBits% = 8) THEN
  36.             ErrCode% = -2    ' color format not supported
  37.          ELSEIF CVL(MID$(Header$, 31, 4)) <> 0& THEN
  38.             ErrCode% = -3    ' compression not supported
  39.          ELSEIF CVL(MID$(Header$, 3, 4)) <> FGetSize&(Handle%) THEN
  40.             ErrCode% = -4    ' incorrect file size
  41.          ELSEIF PWide& < 1& OR PWide& > 320& OR PHigh& < 1& OR PHigh& > 200& THEN
  42.             ErrCode% = -5    ' ludicrous image size
  43.          END IF
  44.          IF ErrCode% = 0 THEN
  45.             PicWidth% = PWide&
  46.             PicHeight% = PHigh&
  47.             IF OrigX% + PicWidth% > 320 OR OrigY% + PicHeight% > 200 THEN
  48.                ErrCode% = -6      ' invalid (X,Y) origin specified
  49.             END IF
  50.          END IF
  51.       END IF
  52.  
  53.       '----- set the palette -----
  54.       IF ErrCode% = 0 THEN
  55.          DIM Pal&(0 TO 255)
  56.          DSeg% = VARSEG(Pal&(0))
  57.          DOfs% = VARPTR(Pal&(0))
  58.          Bytes% = 1024            ' 256 * 4 is size of palette block
  59.          FBlockRead Handle%, DSeg%, DOfs%, Bytes%
  60.          ErrCode% = FGetError%(Handle%)
  61.          IF ErrCode% = 0 THEN
  62.             DSeg% = VARSEG(Pal&(0))
  63.             DOfs% = VARPTR(Pal&(0))
  64.             PalBlk0 DSeg%, DOfs%, 256
  65.          END IF
  66.       END IF
  67.  
  68.       '----- draw the picture -----
  69.       IF ErrCode% = 0 THEN
  70.          FLocate Handle%, CVL(MID$(Header$, 11, 4)) + 1&
  71.          Bytes% = ((PicWidth% + 3) \ 4) * 4
  72.          FOR y% = 0 TO PicHeight% - 1
  73.             st$ = FRead$(Handle%, Bytes%)
  74.             ErrCode% = FGetError%(Handle%)
  75.             IF ErrCode% THEN EXIT FOR
  76.             CurrY% = (PicHeight% - y%) + OrigY%
  77.             FOR x% = 0 TO PicWidth% - 1
  78.                G13Color ASC(MID$(st$, x% + 1, 1)), 0
  79.                G13Plot x% + OrigX%, CurrY%
  80.             NEXT
  81.          NEXT
  82.       END IF
  83.  
  84.       FClose Handle%
  85.    END IF
  86. END SUB
  87.