BBC BASIC
« OS-independent equivalent of DIB Section »

Welcome Guest. Please Login or Register.
Jan 20th, 2018, 6:11pm


Cross-platform BBC BASIC (Win32, Linux x86, Android, Mac OS-X, Raspberry Pi)

« Previous Topic | Next Topic »
Pages: 1  Notify Send Topic Print
 thread  Author  Topic: OS-independent equivalent of DIB Section  (Read 241 times)
Richard Russell
Administrator
ImageImageImageImageImage


member is offline

Avatar




Homepage PM


Posts: 689
xx OS-independent equivalent of DIB Section
« Thread started on: Apr 22nd, 2016, 11:37am »

A number of BBC BASIC for Windows programs make use of a Windows DIB Section to provide a memory-mapped display bitmap (for example that can be accessed using assembler code). One such program is MANDEL.BBC, supplied with BB4W, which draws the Mandelbrot Set very quickly (so quickly that you can pan and zoom in real-time).

Those of you who have been fortunate enough to try the SDL2 (Linux or Android) version of BBC BASIC will have seen that a functionally-equivalent MANDEL.BBC is supplied with that version, and you may have asked yourself how that has been achieved in the absence of the Windows API.

The answer is that by leveraging the *MDISPLAY command (or OSCLI "MDISPLAY...") an almost identical functionality to a Windows DIB Section can be achieved in an OS-independent fashion!

Conversion from one to the other is actually quite straightforward. Here is how the bitmap is created in the BB4W version of MANDEL.BBC:

Code:
      DIM bmih{biSize%, biWidth%, biHeight%, biPlanes{l&,h&}, \
      \        biBitCount{l&,h&}, biCompression%, biSizeImage%, \
      \        biXPelsPerMeter%, biYPelsPerMeter%, biClrUsed%, \
      \        biClrImportant%}
      bmih.biSize%   = DIM(bmih{})
      bmih.biWidth%  = Width%
      bmih.biHeight% = Height%
      bmih.biPlanes.l& = 1
      bmih.biBitCount.l& = 32
      bmih.biSizeImage% = Width%*Height%*4

      SYS "CreateDIBSection", @memhdc%, bmih{}, 0, ^Bits%, 0, 0 TO hbm%
      IF hbm% = 0 ERROR 100, "Couldn't create DIBSection"
      SYS "SelectObject", @memhdc%, hbm% TO oldbm%
      SYS "DeleteObject", oldbm% 

Here is how the equivalent bitmap is created in the SDL version:

Code:
      DIM bmfh{bfType{l&,h&}, bfSize%, bfReserved%, bfOffBits%}
      DIM bmih{biSize%, biWidth%, biHeight%, biPlanes{l&,h&}, \
      \        biBitCount{l&,h&}, biCompression%, biSizeImage%, \
      \        biXPelsPerMeter%, biYPelsPerMeter%, biClrUsed%, \
      \        biClrImportant%}
      DIM BMP{bf{}=bmfh{}, bi{}=bmih{}, bits%(Width%*Height%-1)}

      BMP.bf.bfType.l& = ASC"B"
      BMP.bf.bfType.h& = ASC"M"
      BMP.bf.bfSize%       = DIM(BMP{})
      BMP.bf.bfOffBits%    = DIM(bmfh{}) + DIM(bmih{})
      BMP.bi.biSize%       = DIM(bmih{})
      BMP.bi.biWidth%      = Width%
      BMP.bi.biHeight%     = Height%
      BMP.bi.biPlanes.l&   = 1
      BMP.bi.biBitCount.l& = 32
      BMP.bi.biSizeImage%  = Width%*Height%*4

      Bits% = ^BMP.bits%(0) 

In each case the variable Bits% is set to point to the bitmap data in memory, in exactly the same format for both methods.

To 'blit' the bitmap to the screen in the SDL version it is only necessary to issue a *MDISPLAY command as follows:

Code:
          OSCLI "MDISPLAY " + STR$~BMP{} 

So with this knowledge you should easily be able to convert any programs which use DIB Sections to a more generic form.

Richard.
User IP Logged

Pages: 1  Notify Send Topic Print
« Previous Topic | Next Topic »

Donate $6.99 for 50,000 Ad-Free Pageviews!


This forum powered for FREE by Conforums ©
Sign up for your own Free Message Board today!
Terms of Service | Privacy Policy | Conforums Support | Parental Controls