 |
BorlandTalk.com Borland discussion newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Gudni G. Sigurdsson Guest
|
Posted: Sat Oct 29, 2005 11:27 am Post subject: TCanvas::StretchDraw() execution speed |
|
|
Hi.
Thank you Remy Lebeau and Damon Chandler for your comments on my post about
the EOutOfResource exception. Now, I donīt have storage problems any more.
My only complaint now is the execution speed. To display all jpg images in
a certain directory as thumbnails takes 9,90 sec. When I shortcut my call
to StretchDraw:
nBmap->Canvas->StretchDraw(Rect(0,0,nW,nH),jpegimage);
the code runs in 0.13 sec, i.e. 98% of the time is spent inside
StretchDraw(). Programs like Windows Explorer or ACDSee accomplish similar
tasks very quickly. Is there an alternative method for me to use instead of
StretchDraw() ?
Regards,
Gudni
|
|
| Back to top |
|
 |
Hans Galema Guest
|
Posted: Mon Oct 31, 2005 1:33 pm Post subject: Re: TCanvas::StretchDraw() execution speed |
|
|
Gudni G. Sigurdsson wrote:
| Quote: | ... To display all jpg images in
a certain directory as thumbnails takes 9,90 sec.
|
How many jpg's in that directory ?
| Quote: | When I shortcut my call
to StretchDraw:
nBmap->Canvas->StretchDraw(Rect(0,0,nW,nH),jpegimage);
the code runs in 0.13 sec, i.e. 98% of the time is spent inside
StretchDraw(). Programs like Windows Explorer or ACDSee accomplish similar
tasks very quickly. Is there an alternative method for me to use instead of
StretchDraw() ?
|
Please comment on Wiljo's suggestion using the Scale property of
TJPEGImage.
Hans.
|
|
| Back to top |
|
 |
Darren Dwyer Guest
|
Posted: Thu Nov 03, 2005 3:01 pm Post subject: Re: TCanvas::StretchDraw() execution speed |
|
|
i'm curious, post the code here...
"Alfred" <alf (AT) no (DOT) spam.not.valid.email> wrote
| Quote: |
nBmap->Canvas->StretchDraw(Rect(0,0,nW,nH),jpegimage);
the code runs in 0.13 sec, i.e. 98% of the time is spent inside
StretchDraw().
StretchDraw() is slow i seen some times ago. One more speed problem is the
TImage repaint if you use it and if you repaint it 20/30 times for second.
You can rewrite StretchDraw() to speed up your code. I have one routine I
can give you if you need. If i remember well it is more faster then |
StretchDraw but i am not sure, it is a old code. If you want try just
response here and i will post my code..
|
|
| Back to top |
|
 |
Alfred Guest
|
Posted: Fri Nov 04, 2005 10:29 am Post subject: Re: TCanvas::StretchDraw() execution speed |
|
|
| Quote: |
nBmap->Canvas->StretchDraw(Rect(0,0,nW,nH),jpegimage);
the code runs in 0.13 sec, i.e. 98% of the time is spent inside
StretchDraw().
|
StretchDraw() is slow i seen some times ago. One more speed problem is the TImage repaint if you use it and if you repaint it 20/30 times for second.
You can rewrite StretchDraw() to speed up your code. I have one routine I can give you if you need. If i remember well it is more faster then StretchDraw but i am not sure, it is a old code. If you want try just response here and i will post my code..
Alfred
|
|
| Back to top |
|
 |
Alfred Guest
|
Posted: Sat Nov 05, 2005 11:37 am Post subject: Re: TCanvas::StretchDraw() execution speed |
|
|
"Darren Dwyer" <darrend (AT) bcb-tools (DOT) com> wrote:
| Quote: | i'm curious, post the code here...
|
This is a old code i wrote but it work I am now an expert, I am sure someone can speed up it and make it perfect , better than i can do.
I used TBitmap for the original image and anoter one TBitmap for the background, so after i have created it a simple BitBlt and i can draw it on canvas.
I dont like moltiplication/division in the main code, usually they are slow (on slow machine). I like to make my offset so each time i need a lot of calculation, i can calculate it with a simple "+".
Hope this can help you. Any suggestion/comment will be appreciate, so I can learn more...
Graphics::TBitmap *Picture = new Graphics::TBitmap();
Graphics::TBitmap *Background = new Graphics::TBitmap();
void Stretch(int X, int Y, int Width, int Height, Graphics::TBitmap *Picture)
{
RECT XYScreen={0,0,600,600};
// check if the picture is into the screen, at least one part of the picture
if (X > XYScreen.right || X+Width < XYScreen.left || Y > XYScreen.bottom || Y+Height < XYScreen.top)
return;
float OffsetX,OffsetY;
float ValoreX=0,ValoreY=0;
OffsetX = (float)Picture->Width/Width;
OffsetY = (float)Picture->Height/Height;
int a;
int r=0;
int adda;
// clipping , draw only what you can see into the screen
int Xstart = 0;
int Xend = Width;
if (X < XYScreen.left)
{
Xstart = XYScreen.left - X;
Xend = Width - Xstart;
}
if (X+Width > XYScreen.right)
Xend = Width - ((X+Width)-XYScreen.right);
int Ystart = Y;
int Yend = Y+Height;
if (Y < XYScreen.top)
{
Ystart = XYScreen.top;
ValoreY = (XYScreen.top - Y) * OffsetY;
}
if (Y+Height > XYScreen.bottom)
Yend = (Y+Height) - ((Y+Height)-XYScreen.bottom);
// draw it
int r1,g1,b1;
for (int y=Ystart; y<Yend; y++)
{
BYTE* Src = (BYTE*)Picture->ScanLine[ValoreY];
BYTE* Dest = (BYTE*)Background->ScanLine[y];
ValoreX=(float)Xstart * OffsetX*2;
r=(Xstart+X)*3;
for (int x=Xstart; x
{
adda = int(ValoreX)*3;
r1=Src[adda];
g1=Src[adda+1];
b1=Src[adda+2];
if (r1+g1+b1 != 0) // color = 0 then no draw (transparence)
{
Dest[r]=r1;
Dest[r+1]=g1;
Dest[r+2]=b1;
}
ValoreX += OffsetX;
r+=3;
}
ValoreY += OffsetY;
}
}
Alfred
|
|
| Back to top |
|
 |
|
|
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
|
|