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 / GN5SHOWB.BAS < prev    next >
BASIC Source File  |  1993-01-31  |  4KB  |  88 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 GN5Color (BYVAL Foreground%, BYVAL Background%)
  17.    DECLARE SUB GN5Plot (BYVAL X%, BYVAL Y%)
  18.    DECLARE SUB GN5GetRes (MaxX%, MaxY%)
  19.  
  20.    DECLARE SUB PalBlk0 (BYVAL DSeg%, BYVAL DOfs%, BYVAL Colors%)
  21.  
  22. SUB GN5ShowBMP (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.          GN5GetRes MaxX%, MaxY%
  30.          PWide& = CVL(MID$(Header$, 19, 4))
  31.          PHigh& = CVL(MID$(Header$, 23, 4))
  32.          BitPlanes% = CVI(MID$(Header$, 27, 2))
  33.          ColorBits% = CVI(MID$(Header$, 29, 2))
  34.          IF LEFT$(Header$, 2) <> "BM" THEN
  35.             ErrCode% = -1    ' invalid BMP
  36.          ELSEIF NOT (BitPlanes% = 1 AND ColorBits% = 8) THEN
  37.             ErrCode% = -2    ' color format not supported
  38.          ELSEIF CVL(MID$(Header$, 31, 4)) <> 0& THEN
  39.             ErrCode% = -3    ' compression not supported
  40.          ELSEIF CVL(MID$(Header$, 3, 4)) <> FGetSize&(Handle%) THEN
  41.             ErrCode% = -4    ' incorrect file size
  42.          ELSEIF PWide& < 1& OR PWide& > MaxX% OR PHigh& < 1& OR PHigh& > MaxY% THEN
  43.             ErrCode% = -5    ' ludicrous image size
  44.          END IF
  45.          IF ErrCode% = 0 THEN
  46.             PicWidth% = PWide&
  47.             PicHeight% = PHigh&
  48.             IF OrigX% + PicWidth% > MaxX% OR OrigY% + PicHeight% > MaxY% THEN
  49.                ErrCode% = -6      ' invalid (X,Y) origin specified
  50.             END IF
  51.          END IF
  52.       END IF
  53.  
  54.       '----- set the palette -----
  55.       IF ErrCode% = 0 THEN
  56.          DIM Pal&(0 TO 255)
  57.          DSeg% = VARSEG(Pal&(0))
  58.          DOfs% = VARPTR(Pal&(0))
  59.          Bytes% = 1024            ' 256 * 4 is size of palette block
  60.          FBlockRead Handle%, DSeg%, DOfs%, Bytes%
  61.          ErrCode% = FGetError%(Handle%)
  62.          IF ErrCode% = 0 THEN
  63.             DSeg% = VARSEG(Pal&(0))
  64.             DOfs% = VARPTR(Pal&(0))
  65.             PalBlk0 DSeg%, DOfs%, 256
  66.          END IF
  67.       END IF
  68.  
  69.       '----- draw the picture -----
  70.       IF ErrCode% = 0 THEN
  71.          FLocate Handle%, CVL(MID$(Header$, 11, 4)) + 1&
  72.          Bytes% = ((PicWidth% + 3) \ 4) * 4
  73.          FOR y% = 0 TO PicHeight% - 1
  74.             st$ = FRead$(Handle%, Bytes%)
  75.             ErrCode% = FGetError%(Handle%)
  76.             IF ErrCode% THEN EXIT FOR
  77.             CurrY% = (PicHeight% - y%) + OrigY%
  78.             FOR x% = 0 TO PicWidth% - 1
  79.                GN5Color ASC(MID$(st$, x% + 1, 1)), 0
  80.                GN5Plot x% + OrigX%, CurrY%
  81.             NEXT
  82.          NEXT
  83.       END IF
  84.  
  85.       FClose Handle%
  86.    END IF
  87. END SUB
  88.