From: Shawn Hargreaves Newsgroups: comp.os.msdos.djgpp Subject: Re: Quick question re: Allegro BITMAPs Date: Wed, 21 May 1997 20:36:29 +0100 Organization: None Distribution: world Message-ID: References: <33832989 DOT 12988254 AT news DOT cis DOT yale DOT edu> NNTP-Posting-Host: talula.demon.co.uk MIME-Version: 1.0 Lines: 58 To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Precedence: bulk jon writes: >I could easily use the built-in drawing functions to do most of what I >want, but I still want (and might need) to know how I can access the >data in an Allegro BITMAP directly. See the "video memory access" section in the Allegro documentation. >For example, I am used to thinking of a 320x200 bitmap as an array from >0 to 64000. Allegro seems to use the much more intuitive x=0,320 and >y=0,200 (in a 320x200 BITMAP) representation in all of it's functions, >which is certainly handy. It's pretty much essential if you want to support more than a single size of bitmap! :-) >But how can I also pretend a given BITMAP is actually just a simple >variable array I can read to and write from, as in the above example >buffer[(y*320)+x] ? The trouble is, this isn't always possible. The BITMAP structure can be used to represent the hardware video memory as well as normal blocks of RAM, and SVGA screen memory is often non-linear in layout (it is organised into banks, usually 64k in size, and a single 64k range of memory addresses is used to access various bits of the screen depending on how you've set up the bank switch registers in the card). If you know that a bitmap lives in regular memory (ie. you got it by calling create_bitmap()), then it is indeed just a 1-D array, but if it might be a screen bitmap you will have to take care of bank switching and the possibility that it might not live in your data segment so you need to use farptr functions to access it... > void *dat; /* memory we allocated for the bitmap */ [snip] > int seg; /* bitmap segment */ > unsigned char *line[0]; /* pointers to the start of each line */ >} BITMAP; > >"void *dat" seems key... but in my lack of comprehension, I don't know >how to get at it! In the system I am used to, I would expect it to be >buffer[0]. But I don't think it is that simple. The dat field is _not_ the one you want: it's only set for some bitmaps, and is just so I know what memory to free when you later call destroy_bitmap(). If you know the thing is a memory bitmap, line[0] is the start address of the data, and you can access the rest of it with offsets from that. If it might be a screen bitmap, you'll need to use farptr functions with bmp->seg as the selector, and if it might be a banked bitmap (ie. an SVGA mode on a card that doesn't provide a linear framebuffer) then you have to call the bmp_write_line() function rather than accessing the line pointers directly. But if you're sure it's a regular memory bitmap, line[0] will work just fine... -- Shawn Hargreaves - shawn AT talula DOT demon DOT co DOT uk - http://www.talula.demon.co.uk/ Beauty is a French phonetic corruption of a short cloth neck ornament.