file.bmp

Discussions about the BBC BASIC language, with particular reference to BB4W and BBCSDL
Ric
Posts: 200
Joined: Tue 17 Apr 2018, 21:03

file.bmp

Post by Ric »

I have asked this before and with the help of DDRM I managed to get a bitmap file into the format I wished. This involved *DISPLAY and a prior knowledge of the bitmap x and y. This time I have a slightly harder task, I wish to convert the bitmap file without knowing x and y or *DISPLAYing.
1. Is there some way of reading a bitmap file without displaying it?
2. If so , does anyone know what format the file takes, ie does it use the first couple of bytes to record data like x and y.
Yours Hoping

Ric


PS I am still working on my 3D GUI and this question is to allow bitmap textures to be used.
DDRM

Re: file.bmp

Post by DDRM »

Hi RIc,

You can simply *LOAD the file into memory at a known address (DIM some space first!), and then manipulate it from there. You are right that the bitmap has a header block with key information, which depends a bit on which subformat it is. Have a look at Wikipedia. It looks like you can find:
total size at offset 2 (4 bytes)
Location of image data at offset 10 (4 bytes)
width at 18 (2 bytes) :EDIT see below - usually 4 bytes
height at 20 (2 bytes) :EDIT see below - usually 4 bytes at 22

Quite a number of David Williams' programs load bitmaps, so might make a good starting place. I'll have a look at the examples and see if I can find an example - or I'll try to put one together, but that should get you going...

Best wishes,

D
guest

Re: file.bmp

Post by guest »

Code: Select all

      DEF PROCbmpdims(bmp$, RETURN W%, RETURN H%)
      LOCAL F%
      F% = OPENIN(bmp$) : IF F% = 0 ENDPROC
      PTR#F% = 18 : W% = BGET#F% + 256 * BGET#F%
      PTR#F% = 22 : H% = BGET#F% + 256 * BGET#F%
      CLOSE #F%
      ENDPROC

      DEF PROCjpgdims(jpg$, RETURN W%, RETURN H%)
      LOCAL F%
      F% = OPENIN(jpg$) : IF F% = 0 ENDPROC
      PTR#F% = 4
      REPEAT PTR#F% = PTR#F% + 256 * BGET#F% + BGET#F%
      UNTIL BGET#F% = &FF AND (BGET#F% AND &F0) = &C0 OR EOF#F%
      PTR#F% = PTR#F% + 3
      H% = 256 * BGET#F% + BGET#F%
      W% = 256 * BGET#F% + BGET#F%
      CLOSE #F%
      ENDPROC

      DEF PROCpngdims(png$, RETURN W%, RETURN H%)
      LOCAL F%
      F% = OPENIN(png$) : IF F% = 0 ENDPROC
      PTR#F% = 18 : W% = 256 * BGET#F% + BGET#F%
      PTR#F% = 22 : H% = 256 * BGET#F% + BGET#F%
      CLOSE #F%
      ENDPROC

      DEF PROCgifdims(gif$, RETURN W%, RETURN H%)
      LOCAL F%
      F% = OPENIN(gif$) : IF F% = 0 ENDPROC
      PTR#F% = 6 : W% = BGET#F% + 256 * BGET#F%
      PTR#F% = 8 : H% = BGET#F% + 256 * BGET#F%
      CLOSE #F%
      ENDPROC
DDRM

Re: file.bmp

Post by DDRM »

As you will spot if you look carefully at this code, the info I gave is for an unusual header type: typically the width and height are given as 4 byte integers, stored at positions 18 and 22 (it's a bit further down the Wikipedia page!).

That's a neat way to read info from the file before actually loading it, too.

D
Ric
Posts: 200
Joined: Tue 17 Apr 2018, 21:03

Re: file.bmp

Post by Ric »

Thanks D

Ill let you know how I get on
Kind Regards Ric.

6502 back in the day, BB4W 2017 onwards, BBCSDL from 2023
Ric
Posts: 200
Joined: Tue 17 Apr 2018, 21:03

Re: file.bmp

Post by Ric »

Didn't take long to suss :D

Thanks once again D
Kind Regards Ric.

6502 back in the day, BB4W 2017 onwards, BBCSDL from 2023