English Amiga Board


Go Back   English Amiga Board > Coders > Coders. Language > Coders. C/C++

 
 
Thread Tools
Old 10 January 2024, 17:59   #1
Steffest
Registered User
 
Join Date: Jan 2017
Location: Antwerp / Belgium
Posts: 189
Efficiënt loading and displaying image slices

Hey!

I'm working in system friendly C.
I have some questions about loading images and displaying (parts of them) on screen.
I landed on my "solution" because it was the only way I found that worked, but I have a feeling I'm doing all sorts of super inefficient things.

Currently I store the images as uncompressed bitplane data in an external file.
When I want to "blit" pieces on screen I know the data has to be in Chip Ram.
Chipram is valuable though, and limited.
So I first load them in Fast Ram at the preload stage.
Then when I need them, I copy the data to Chip ram and construct a Bitmap that I can use.

To "contruct the bitmap" the only way that I know how to do that, is to first setup an "image", because I can directly assign a memory pointer to the bitplanes data.
Then I construct a bitmap, initiate a rastport for the bitmap, initiate all the bitplanes and then use "DrawImage" to draw the entire image on the rastport of the bitmap.
Then I can free the original memory and the bitmap, keeping only the rastport (and attached bitmap)

This feels super inefficient because in this process I have to hold the entire image in chipram twice for a short time.
Anyone knows a way or knows an example how I can just point the .planes pointers of the bitmap directly to a memory location?
That should work, no?

To illustrate my current approach, I made a standalone example, available at https://github.com/steffest/amiga-c/...tToChip/main.c

Any help appreciated, I'm just throwing stuff on the wall until something sticks :-)
Steffest is offline  
Old 10 January 2024, 22:31   #2
Steffest
Registered User
 
Join Date: Jan 2017
Location: Antwerp / Belgium
Posts: 189
Sometimes it helps to just to write a situation down on a forum and create an example, just to get things clear in your head.

I didn't realize yet that AllocRaster is very similar to AllocMemory and that the .planes array of the bitmap is "nothing more" then pointers to the allocated chip memory, so I can just CopyMem the data from Fast ram to those pointers.

Works! en much simpeler.
Reworked (better) example on https://github.com/steffest/amiga-c/...oChip/better.c
Steffest is offline  
Old 11 January 2024, 03:34   #3
tygre
Returning fan!
 
tygre's Avatar
 
Join Date: Jan 2011
Location: Montréal, QC, Canada
Posts: 1,434
Nice work
tygre is offline  
Old 12 January 2024, 02:01   #4
bwldrbst
Registered User
 
bwldrbst's Avatar
 
Join Date: Nov 2015
Location: Perth, Australia
Posts: 73
I've been working on an OS friendly game and have spent some time thinking about this.

I have a data file that contains definitions for game structures - such as Items, Monsters and anything else. One of these types is an "ImageSet" - a collection of related images or animation frames. The data file is loaded into - preferably fast - memory where it can be accessed as a tree of C structs.

Source graphics are processed and stored in other files as raw interleaved bitplanes.

The ImageSet struct contains an embedded BitMap that initially has its planes set to NULL. The first time the game needs to render one of the frames, it will load the bitplane data into chip ram and set the plane pointers on the BitMap of the ImageSet. Then I can use BltBitMapRastPort or BltMaskBitMapRastPort to draw the frame to a RastPort.

Right now, I simply load the image data into chip ram but my plan is to make the game a bit smarter and cache it in fast ram, copying it in and out of chip ram as needed.
bwldrbst is offline  
Old 12 January 2024, 10:41   #5
Steffest
Registered User
 
Join Date: Jan 2017
Location: Antwerp / Belgium
Posts: 189
Quote:
Originally Posted by bwldrbst View Post

Source graphics are processed and stored in other files as raw interleaved bitplanes.
Thanks for the input, bwldrbst,
Yes, that's a similar setup as what I'm aiming for.

One question: does storing the data as interleaved bitplanes has any benefits? (as oposed to non interleaved)
Steffest is offline  
Old 12 January 2024, 13:13   #6
hooverphonique
ex. demoscener "Bigmama"
 
Join Date: Jun 2012
Location: Fyn / Denmark
Posts: 1,624
Quote:
Originally Posted by Steffest View Post
One question: does storing the data as interleaved bitplanes has any benefits? (as oposed to non interleaved)
Yes, interleaved bitmaps can support blitting all bitplanes in a single blit when the dimensions of the source and destination bitmaps are different (when they are the same dimensions, non-interleaved can also support single-blitting).
hooverphonique is offline  
Old 13 January 2024, 02:24   #7
bwldrbst
Registered User
 
bwldrbst's Avatar
 
Join Date: Nov 2015
Location: Perth, Australia
Posts: 73
Quote:
Originally Posted by hooverphonique View Post
Yes, interleaved bitmaps can support blitting all bitplanes in a single blit when the dimensions of the source and destination bitmaps are different (when they are the same dimensions, non-interleaved can also support single-blitting).

Yep, pretty much this. Using interleaved bitmaps can reduce the time spent setting up the blitter because it's only done once instead of for each plane. However, the trade off is that for masked blits you will need a mask the same size as the source.
bwldrbst is offline  
 


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Similar Threads
Thread Thread Starter Forum Replies Last Post
Amiga 1200 problems, displaying only scanlines over a black image Liam Hallows support.Hardware 3 28 November 2020 09:47
Most efficient way of storing x/y values over frames mcgeezer Coders. General 13 07 October 2020 02:18
Questions re: Efficient blitting earok Coders. Blitz Basic 11 01 January 2017 06:41
possible bug in image loading DaveMB support.FS-UAE 6 28 October 2013 21:07
[REQ:ASM] Loading a static image and its palette jman Coders. Tutorials 3 04 June 2011 14:08

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 19:32.

Top

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Page generated in 0.08193 seconds with 15 queries