BBC BASIC
« OS-independent equivalent of DIB Section »

Welcome Guest. Please Login or Register.
Mar 31st, 2018, 10:44pm



ATTENTION MEMBERS: Conforums will be closing it doors and discontinuing its service on April 15, 2018.
We apologize Conforums does not have any export functions to migrate data.
Ad-Free has been deactivated. Outstanding Ad-Free credits will be reimbursed to respective payment methods.

Thank you Conforums members.
Cross-platform BBC BASIC (Windows, Linux x86, Mac OS-X, Android, iOS, Raspberry Pi)
BBC BASIC Resources
BBC BASIC Help Documentation
BBC BASIC for Windows Home Page
BBC BASIC Programmers' Reference
BBC BASIC Beginners' Tutorial
BBC BASIC for SDL 2.0 Home Page
BBC BASIC Discussion Group

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


member is offline

Avatar




Homepage PM


Posts: 803
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 »

| |

This forum powered for FREE by Conforums ©
Terms of Service | Privacy Policy | Conforums Support | Parental Controls