Witam mam problem z optymalizacją programu w borland C++: Robi on 2 screenshoty po czym porownoje ze soba za pomoca scanline po czym podaje wynik w ilu % zmienia sie ekran (wykrywa czy odtwarzany jest film)
int GetDifference (int z )
{
Graphics::TBitmap *Bmp1 = new Graphics::TBitmap;
Graphics::TBitmap *Bmp2 = new Graphics::TBitmap;
TCanvas &PulpitCanvas = *new TCanvas();
TCanvas &Pulpit2Canvas = *new TCanvas();
PulpitCanvas.Handle = GetDC(0);
Bmp1->Width = Screen->Width;
Bmp1->Height = Screen->Height;
Bmp1->Canvas->CopyRect(Rect(0, 0, Bmp1->Width, Bmp1->Height), &PulpitCanvas, Rect(0, 0, Bmp1->Width, Bmp1->Height));
//screenshot1
::Sleep(1000);
Pulpit2Canvas.Handle = GetDC(0);
Bmp2->Width = Screen->Width;
Bmp2->Height = Screen->Height;
Bmp2->Canvas->CopyRect(Rect(0, 0, Bmp2->Width, Bmp2->Height), &Pulpit2Canvas, Rect(0, 0, Bmp2->Width, Bmp2->Height));
//screenshot2
//W tym momencie pojawia się problem nie wiem jak uwolnic tcanvas
//TRGBTriple* Pixel1, *Pixel2;
TRGBTriple *Pixel1, *Pixel2;
int x, y ,df, perc;
Bmp1->PixelFormat=pf24bit;
Bmp2->PixelFormat=pf24bit;
for(y=0; y<Bmp1->Height; ++y)
{
Pixel1 =(TRGBTriple*)Bmp1->ScanLine[y];
Pixel2 = (TRGBTriple*)Bmp2->ScanLine[y];
for( x=0; x<Bmp1->Width; ++x)
{
++df; //zliczanie wszystkich pixeli
if( (Pixel1->rgbtRed!=Pixel2->rgbtRed) ||
(Pixel1->rgbtGreen!=Pixel2->rgbtGreen)||
(Pixel1->rgbtBlue!=Pixel2->rgbtBlue) ) {
++z;
//zliczanie zmienionych pixeli
}
++Pixel1;
++Pixel2;
}
}
perc=z*100/df;
//obliczanie wyniku w %
DeleteObject(Bmp1);
DeleteObject(Bmp2);
Pixel1 = NULL;
Pixel2 = NULL;
return(perc);
}