BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Faster than Pixels[x][y]=clBlack?

 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> C++ Builder (Graphics)
View previous topic :: View next topic  
Author Message
Nicholas Gessler
Guest





PostPosted: Sun Apr 22, 2007 8:37 pm    Post subject: Faster than Pixels[x][y]=clBlack? Reply with quote



I am working with a particularly large cellular automata that
mimics a computer with a moving tape. I have it working now
with PaintBox->Canvas->Pixels and despite all attempts at op-
timizing the code it is still too slow.

I know there are alternatives to Pixels[x][y] which work much
faster. Can someone please provide an example or point me to
a reference or two? I recall something about "bit blasting?"
and there's also DirectX. Are these compatible with a VCL ap-
plication?

Any help would be appreciated.

Thanks in advance,
Nick
http://gessler.bol.ucla.edu
Back to top
Clayton Arends
Guest





PostPosted: Sun Apr 22, 2007 8:43 pm    Post subject: Re: Faster than Pixels[x][y]=clBlack? Reply with quote



Quote:
Can someone please provide an example or point me to
a reference or two?

Take a look at Scanline. It is much faster to access rows of data that way.
Be aware that the data is in the color format of the bitmap (8-bit palette,
16, 24, 32-bit, etc).

Quote:
I recall something about "bit blasting?"

I am unfamiliar with this terminology.

Quote:
and there's also DirectX. Are these compatible with a VCL ap-
plication?

http://bcb-tools.com/

- Clayton
Back to top
Nick Gessler
Guest





PostPosted: Sun Apr 22, 2007 9:04 pm    Post subject: Re: Faster than Pixels[x][y]=clBlack? Reply with quote



Clayton,

I'll look at Scanline. My "image" is about 500 x 800 pixels.
I only have to replace less than 1% of the pixels at any
iteration. Would Scanline still be faster since it replaces
much more than I need at any one time?

I looked up BitBlt in the old Help and although I have a
Ph.D. I can't make much sense of it. If that is likely
to be fast, could anyone post a short 5 x 5 pixel example?
Then I could scale it up.

I'll try working on this, off and on with interruptions,
today.

Thanks,
Nick
Back to top
Ron Sawyer
Guest





PostPosted: Mon Apr 23, 2007 12:51 am    Post subject: Re: Faster than Pixels[x][y]=clBlack? Reply with quote

Basically you create a memory bitmap, you manipulate that, then you bitblt
it to the screen. However, if I'm not mistaken the canvas' draw method uses
bitblt underneath, so I don't think you will gain anything unless you are
currently trying to manipulate the screen image.

"Nick Gessler" <gessler (AT) ucla (DOT) edu> wrote in message
news:462b877e (AT) newsgroups (DOT) borland.com...
Quote:

Clayton,

I'll look at Scanline. My "image" is about 500 x 800 pixels.
I only have to replace less than 1% of the pixels at any
iteration. Would Scanline still be faster since it replaces
much more than I need at any one time?

I looked up BitBlt in the old Help and although I have a
Ph.D. I can't make much sense of it. If that is likely
to be fast, could anyone post a short 5 x 5 pixel example?
Then I could scale it up.

I'll try working on this, off and on with interruptions,
today.

Thanks,
Nick
Back to top
Clayton Arends
Guest





PostPosted: Mon Apr 23, 2007 5:02 am    Post subject: Re: Faster than Pixels[x][y]=clBlack? Reply with quote

First, I need to say that I rushed my post. For a canvas there is no
ScanLine property. That is a property of TBitmap. If you find yourself
using an in memory bitmap then you should consider using ScanLine.

Quote:
Would Scanline still be faster since it replaces
much more than I need at any one time?

With ScanLine you are simply accessing the raw data pointer not replacing
entire rows. There is no copying going on. It is conceptually the same as
this:

TColor buffer[500][800]; // 800 wide x 500 tall

TColor* row = buffer[200]; // ie. ScanLine[200]

row[5] = clBlack; // ie. Pixels[5][200] = clBlack
row[6] = clBlack; // ie. Pixels[6][200] = clBlack

- Clayton
Back to top
Nick Gessler
Guest





PostPosted: Mon Apr 23, 2007 7:51 am    Post subject: Re: Faster than Pixels[x][y]=clBlack? Reply with quote

Gentlemen,

Thank you for your patience and your ideas. I've put the
project I'm working on on my website:
http://www.sscnet.ucla.edu/geog/gessler/borland/ca.htm
It's an interesting configuration of Conway's rules that builds
what one might call, a "computer."

It's taken me most of the day to get it working to my satis-
faction, albeit working slow. Tomorrow I'll try your sugges-
tions.

I confess, not only do I need a crash couse in strings, but
I'm not familiar with creating a bitmap in memory. I wonder,
could I impose on you to give me a small example so that I
can scale it up to about 500 by 800?

Good night for now. I'll be at it again in the morning.

Cheers, Nick
Back to top
Bruce Salzman
Guest





PostPosted: Mon Apr 23, 2007 8:10 am    Post subject: Re: Faster than Pixels[x][y]=clBlack? Reply with quote

"Nick Gessler" <gessler (AT) ucla (DOT) edu> wrote in message
news:462c1f38$1 (AT) newsgroups (DOT) borland.com...
Quote:

Gentlemen,

Thank you for your patience and your ideas. I've put the
project I'm working on on my website:
http://www.sscnet.ucla.edu/geog/gessler/borland/ca.htm
It's an interesting configuration of Conway's rules that builds
what one might call, a "computer."

It's taken me most of the day to get it working to my satis-
faction, albeit working slow. Tomorrow I'll try your sugges-
tions.

I confess, not only do I need a crash couse in strings, but
I'm not familiar with creating a bitmap in memory. I wonder,
could I impose on you to give me a small example so that I
can scale it up to about 500 by 800?


Hi, Nick

Something along these lines, perhaps:

// declare in the TForm class definition
Graphics::TBitmap* bm;

// in the form's contructor
bm = new Graphics::TBitmap();
bm->PixelFormat = pf32bit;
bm->Width = 500;
bm->Height = 800;
....
// render next generation
DWORD* p; // this assumes a pf32bit format bitmap
// loop through each scanline pixel and assign a color
for (int y = 0; y < bm->Height; y++){
p = (DWORD *)bm->ScanLine[y];
for (int x = 0; x < bm->Width; x++)
p[x] = desiredcolor;
}
PaintBox1->Repaint();
....
void __fastcall TForm1::PaintBox1Paint(TObject *Sender)
{
Canvas1->Draw(0,0, bm);
}

--
Bruce
Back to top
Bruce Larrabee
Guest





PostPosted: Mon Apr 23, 2007 1:25 pm    Post subject: Re: Faster than Pixels[x][y]=clBlack? Reply with quote

Hello Nick,

Well I'm no expert but I use the Pixels[][] method quite
often for a variety of uses. My guess based on the description
you've provided is that if you really a need major increase
in display rendering speed DirectX is probably the way to go.

Based on what you have said I would be surprised if Scanline gave
you much of a performance boost. Understand that I may be way
wrong about this though.. I have never tried it. In fact I'd be most
interested in your results if you do try it in this application
please post some stats if you are able to do so?

I have researched DirectX. And tested it on our favorite lil'
compiler with no problems (not an exhaustive set of tests though..)

The tricky part is understanding it...

If you want to try it and what to email me about that part please
feel free to do so.

HTH,

Bruce
Back to top
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> C++ Builder (Graphics) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.