PDA

View Full Version : 8 bit bitmaps rendering speed



peterbone
30-05-2004, 08:04 PM
At the moment I'm using 24bit bitmaps for my game (Downfall). Would the program be speeded up much if I used 8 bit bitmaps? Does the Draw procedure render an 8 bit bitmap to the screen faster than a 24 bit bitmap?
Thanks

Peter

TheLion
30-05-2004, 08:21 PM
I'm not entirely sure, but I think 32 bits are faster than 24 bits, because CPUs are 32 bits and since 24 bits is hell to read/calculate...

On 8bits I'm not sure, if your primary surface is 32/24/16 bits then I would have to say probably not, since well the 8bit bitmap colours have to be converted to the color settings of the surface/display, since otherwise it would look crappy, however if your primary surface is set to 8bits then I think it would be faster! :)

Harry Hunt
30-05-2004, 10:39 PM
I'm pretty sure using 8 bit won't make it faster and I also don't think that in this case, 32 bit is faster than 24 bit (even though in most cases it would actually be faster).

However, if you want more speed, here's an idea:

Make your backbuffer half the size of your playfield. Draw all the things half as big as you do now using scanlines (which is extremely fast). Basically you'll be plotting individual pixels. Then when you "flip" the backbuffer onto the screen, stretchblt it to 200% of the buffers size. You will get the same result but faster.

peterbone
31-05-2004, 12:35 PM
ok thanks, I'll try the StretchDraw thing. I thought of that myself but wasn't sure it would be faster because in my experience StretchDraw is a lot slower than Draw (is StretchDraw the same as StretchBlt?)
It's like you know my source-code but you've only seen the executable!

I have a question about scanlines. When setting a single pixel, is it faster to use Canvas.Pixels or use ScanLine. I know ScanLine is a lot faster when setting multiple pixels in the same row, but is it faster if I'm just changing 1 pixel?

thanks

Peter

Harry Hunt
31-05-2004, 09:39 PM
StretchDraw is faster than Draw just like StretchBlt is faster than BitBlt. Don't ask me why though... I've read it somewhere, did some benchmarking and it's true...

ScanLines are much faster than the Pixels property even for plotting single pixels. If you want to achieve the ultimate in speed, only use the scanline property once to get a pointer to the pixel memory and then move to the pixel you want to change by increasing the pointer accordingly.

Be sure to check out this page and read the part that says "Optimization".

http://homepages.borland.com/efg2lab/ImageProcessing/Scanline.htm#Optimization


By the way, I tried to do even faster pixel access by using DIBSections and accessing the memory with inline assembler calls but I couldn't beat the speed of Scanline... so Scanline should be pretty much as fast as it gets (obviously accessing video memory through DirectX would still be faster).

Alimonster
01-06-2004, 08:24 AM
Canvas.Draw ends up calling StretchBlt in the end (via TBitmap.Draw), after about 20 lines of preparatory code (checking palettes and so on).

But don't use Canvas.Pixels, it's really slow. I seem to remember that earlier versions of Delphi actually had a warning in the help files indicating that it wasn't for production use, or something like that. Also, you'll notice a sarcastic comment in the help files for its example: "This example draws a red line (very slowly)". ;)

WILL
01-06-2004, 09:26 AM
I seem to remember that earlier versions of Delphi actually had a warning in the help files indicating that it wasn't for production use, or something like that. Also, you'll notice a sarcastic comment in the help files for its example: "This example draws a red line (very slowly)". ;)

Really? What version?

Ultra
01-06-2004, 04:30 PM
Straight from the help files in Delphi 3 (and it looks the same in Delphi 6):


This example draws a red line (very slowly) when a button is pressed. Attach the following code to the button?¢_Ts OnClick event handler:

procedure TForm1.Button1Click(Sender: TObject);

var
W: Word;
begin
for W := 10 to 200 do
Canvas.Pixels[W, 10] := clRed;
end;