| View previous topic :: View next topic |
| Author |
Message |
José Guest
|
Posted: Fri Apr 28, 2006 9:03 pm Post subject: Slow pictures |
|
|
Dear Remy and others
I am writing a program for a slideshow. It shows two different
pictures at once (stereo, yes).
The pictures appear very slowly.
Of course it takes time to load a picture, so that I used two pairs of
control elements, which are alternatively hidden.
The sequence is this:
screen becomes blank
after one second (or more) the left picture appears.
after another second (or more) the right picture appears.
Can anyone help me to get rid of those seconds?
--
José
bool toggle;
void loadphotos()
{ fileL=.....
fileR=.....
TImage * ImageL;
TImage * ImageR;
if(toggle)
{ ImageL=Form1->Image1L; //Image1L, 1R, 2L, 2R are
ImageR=Form1->Image1R; //elements on the form
}
else
{ ImageL=Form1->Image2L;
ImageR=Form1->Image2R;
}
if(ImageL->Visible || ImageR->Visible)
error("error in program"); //does not occur
ImageL->Picture->LoadFromFile(fileL);
ImageR->Picture->LoadFromFile(fileR);
}
//------------------
void exchange(void)
{
Form1->Image1R->Visible=toggle;
Form1->Image1L->Visible=toggle;
Form1->Image2R->Visible=!toggle;
Form1->Image2L->Visible=!toggle;
toggle=!toggle;
}
static int semafoor=0;
void __fastcall TForm1::Timer1Timer(TObject *Sender)
{
exchange(); //display new pics
loadphotos(Sender); //load new pics and wait for Timer
} |
|
| Back to top |
|
 |
Hans Galema Guest
|
Posted: Fri Apr 28, 2006 10:03 pm Post subject: Re: Slow pictures |
|
|
José wrote:
| Quote: | screen becomes blank
|
There is nothing in your code that cares for that. Please explain.
| Quote: | after one second (or more) the left picture appears.
after another second (or more) the right picture appears.
|
bool toggle;
void loadphotos()
Oh. Why are you using a global bool and a standalone function ?
It is much better to make that a classmember of TForm1.
If you do you could also use two forms which display
at the same time.
void exchange(void)
ditto.
__fastcall TForm1::TForm1(TComponent* Owner)
: TFrame(Owner)
{
// set the second set invisible
Image2R->Visible = false;
Image2L->Visible = false;
}
You could as well do all in the timereventhandler.
void __fastcall TForm1::Timer1Timer(TObject *Sender)
{
Timer1->Enabled = false;
Image1R->Visible = ! Image1R->Visible;
Image1L->Visible = ! Image1L->Visible;
Image2R->Visible = ! Image2R->Visible;
Image2L->Visible = ! Image2L->Visible;
Application->ProcessMessages(); // does this have effect ?
FileR = ...
FileL = ...
if ( ! Image1R->Visible ) Image1R->Picture->LoadFromFile(fileR);
if ( ! Image2R->Visible ) Image2R->Picture->LoadFromFile(fileR);
if ( ! Image1L->Visible ) Image1L->Picture->LoadFromFile(fileL);
if ( ! Image2L->Visible ) Image2L->Picture->LoadFromFile(fileL);
Timer1->Enabled = true;
}
pProblems like this where you use a VCL component are better asked in:
borland.public.cppbuilder.vcl.components.using
Hans. |
|
| Back to top |
|
 |
José Guest
|
Posted: Sat Apr 29, 2006 9:03 am Post subject: Re: Slow pictures |
|
|
On Fri, 28 Apr 2006 22:42:08 +0200, Hans Galema <notused (AT) notused (DOT) nl>
wrote in borland.public.cppbuilder.nativeapi:
| Quote: | screen becomes blank
There is nothing in your code that cares for that. Please explain.
|
It happens. I think the TImages are made invisible intantanteously,
but that it takes time to make them visible.
Coding in the other order (first visible, then invisible) makes no
difference.
| Quote: | after one second (or more) the left picture appears.
after another second (or more) the right picture appears.
bool toggle;
void loadphotos()
Oh. Why are you using a global bool and a standalone function ?
|
I always do. Never had any problems with that. But I'll try your
suggestion.
| Quote: | It is much better to make that a classmember of TForm1.
If you do you could also use two forms which display
at the same time.
|
I expect this will make them behave more independently, causing a
worse synchronisation.
--
José |
|
| Back to top |
|
 |
José Guest
|
Posted: Sat Apr 29, 2006 9:03 am Post subject: Re: Slow pictures |
|
|
On Fri, 28 Apr 2006 22:42:08 +0200, Hans Galema <notused (AT) notused (DOT) nl>
wrote in borland.public.cppbuilder.nativeapi:
| Quote: | Oh. Why are you using a global bool and a standalone function ?
It is much better to make that a classmember of TForm1.
|
It makes no difference. Still too slow.
--
José |
|
| Back to top |
|
 |
Hans Galema Guest
|
Posted: Sat Apr 29, 2006 10:03 am Post subject: Re: Slow pictures |
|
|
José wrote:
| Quote: | Oh. Why are you using a global bool and a standalone function ?
It is much better to make that a classmember of TForm1.
It makes no difference. Still too slow.
|
No that makes no difference in speed of course.
But did you try my code ? You did not even comment
on ProcessMessages().
Hans. |
|
| Back to top |
|
 |
Hans Galema Guest
|
Posted: Sat Apr 29, 2006 10:03 am Post subject: Re: Slow pictures |
|
|
José wrote:
| Quote: | It makes no difference. Still too slow.
|
How big are your pictures ?
Are you still seeing that one picture displays one second before
the other ? How long is your TTimer::Interval ?
Could you post 4 pictures in borland.public.attachments
so we can test in the same way?
Hans. |
|
| Back to top |
|
 |
José Guest
|
Posted: Sat Apr 29, 2006 3:03 pm Post subject: Re: Slow pictures |
|
|
On Sat, 29 Apr 2006 11:04:25 +0200, Hans Galema <notused (AT) notused (DOT) nl>
wrote in borland.public.cppbuilder.nativeapi:
| Quote: | It makes no difference. Still too slow.
How big are your pictures ?
|
Well, 500 kB to 1 MB, and 1000x1000 pixels or bigger. Perhaps I should
make them smaller. But of course I do not want to loose quality, or
I'll have to retain two copies of each picture: a big one for storage
and a small one display.
| Quote: | Are you still seeing that one picture displays one second before
the other ? How long is your TTimer::Interval ?
|
Yes
| Quote: | Could you post 4 pictures in borland.public.attachments
so we can test in the same way?
|
I did.
--
José |
|
| Back to top |
|
 |
José Guest
|
Posted: Sat Apr 29, 2006 3:03 pm Post subject: Re: Slow pictures |
|
|
On Sat, 29 Apr 2006 11:10:14 +0200, Hans Galema <notused (AT) notused (DOT) nl>
wrote in borland.public.cppbuilder.nativeapi:
| Quote: | But did you try my code ? You did not even comment
on ProcessMessages().
|
Sorry, I didn't notice ProcessMessages in your code. I included it
now, but it made no difference.
I don't think there will be much difference between in-linde code and
subroutines, but I prefer subroutines because they are called
elsewhere in the program as well.
--
José |
|
| Back to top |
|
 |
JD Guest
|
Posted: Sat Apr 29, 2006 6:03 pm Post subject: Re: Slow pictures |
|
|
José <jose (AT) 127 (DOT) 0.0.1> wrote:
| Quote: |
Could you post 4 pictures in borland.public.attachments
so we can test in the same way?
I did.
|
Well they're not there.
What I know so far is that you're using TImages and relying
on them to do the painting when speed is an issue for you
you. This is a mistake. You need to be managing the painting
yourself and should be using a TBitmap instead.
The general order of operation should be:
1) Load the image
2) StretchDraw it to a bitmap in the appropriate size
3) Display it
4) While waiting for the timer, repeat 1 & 2 on the next image
5) Timer activates so begin at step 3
I have a print preview that zooms to 400% for 8.5 x 11 paper
and it's a huge bitmap that paints instantly because it uses
StretchDraw to a temporary bitmap that is then painted. If you
use StretchDraw directly to the screen, performance will
suffer greatly and I suspect that this is exactly what you're
doing by setting the Stretched property of the TImage.
~ JD |
|
| Back to top |
|
 |
José Guest
|
Posted: Sat Apr 29, 2006 7:03 pm Post subject: Re: Slow pictures |
|
|
On 29 Apr 2006 10:30:12 -0700, "JD" <nospam (AT) nospam (DOT) com> wrote in
borland.public.cppbuilder.nativeapi:
| Quote: | Could you post 4 pictures in borland.public.attachments
so we can test in the same way?
I did.
Well they're not there.
|
I tried. The server rejects files which are bigger than 1 MB (small
MB). Mine are approximately that size.
--
José |
|
| Back to top |
|
 |
Hans Galema Guest
|
Posted: Sat Apr 29, 2006 10:03 pm Post subject: Re: Slow pictures |
|
|
José wrote:
| Quote: | I tried. The server rejects files which are bigger than 1 MB (small
MB). Mine are approximately that size.
|
Jpg or bmp ?
Hans. |
|
| Back to top |
|
 |
José Guest
|
Posted: Sat Apr 29, 2006 10:03 pm Post subject: Re: Slow pictures |
|
|
On Sat, 29 Apr 2006 23:10:36 +0200, Hans Galema <notused (AT) notused (DOT) nl>
wrote in borland.public.cppbuilder.nativeapi:
| Quote: | I tried. The server rejects files which are bigger than 1 MB (small
MB). Mine are approximately that size.
Jpg or bmp ?
|
JPG. But of course you mean to say that 1MB is a lot for a JPG file.
Well, I thin that smaller files will be faster indeed, but it amazes
me that it takes time to make a picture visible, when it has already
been loaded.
I modified the program to skip loading new images, so that the program
shows the same pictures all the time. This was a lot quicker, but
there is still a noticeble delay. So there is obviously a delay in
Visible=true.
Perhaps I should try smaller files.
--
José |
|
| Back to top |
|
 |
Hans Galema Guest
|
Posted: Sat Apr 29, 2006 10:03 pm Post subject: Re: Slow pictures |
|
|
José wrote:
| Quote: | JPG. But of course you mean to say that 1MB is a lot for a JPG file.
|
No.
| Quote: | Well, I thin that smaller files will be faster indeed, but it amazes
me that it takes time to make a picture visible, when it has already
been loaded.
|
No, making visible does not take time here. The timeconsuming factor
is in the loading.
| Quote: | I modified the program to skip loading new images, so that the program
shows the same pictures all the time. This was a lot quicker, but
there is still a noticeble delay.
|
I did that too. But no delay.
But when loading the invisible set there was delay between the left and
right that were shown. I do not understand that. The delay about 1/3 s.
Hans. |
|
| Back to top |
|
 |
José Guest
|
Posted: Sun Apr 30, 2006 11:03 am Post subject: Re: Slow pictures |
|
|
On Sat, 29 Apr 2006 23:39:42 +0200, Hans Galema <notused (AT) notused (DOT) nl>
wrote in borland.public.cppbuilder.nativeapi:
| Quote: | No, making visible does not take time here. The timeconsuming factor
is in the loading.
|
This was my modified program:
wait 10 seconds.
make pictures 1 and 2 invisible
make pictures 3 and 4 visible
wait 10 seconds.
make pictures 1 and 2 visible
make pictures 3 and 4 invisible
repeat
Note that no files were loaded. The pictures disappeared immediately,
and then it took approximately a second for the other two pictures to
appear, one by one.
| Quote: | I modified the program to skip loading new images, so that the program
shows the same pictures all the time. This was a lot quicker, but
there is still a noticeble delay.
I did that too. But no delay.
But when loading the invisible set there was delay between the left and
right that were shown. I do not understand that. The delay about 1/3 s.
|
As I say.
--
José |
|
| Back to top |
|
 |
Hans Galema Guest
|
Posted: Sun Apr 30, 2006 12:03 pm Post subject: Re: Slow pictures |
|
|
José wrote:
| Quote: | wait 10 seconds.
make pictures 1 and 2 invisible
make pictures 3 and 4 visible
wait 10 seconds.
make pictures 1 and 2 visible
make pictures 3 and 4 invisible
repeat
|
Please in such case show actual code that compiles and links.
Like I did.
You are forcing people who want to help you do produce
code that would handle that. As that can be coded
in many ways one might look at different outputs.
Hans. |
|
| Back to top |
|
 |
|