4
« on: January 25, 2012, 07:40:21 pm »
Hi! I did gray-scale effect in SFML 1.6, but it works too slowly (half second).
Here is the code:
void odcien::zrob_obraz(unsigned int x1,unsigned int y1,unsigned int szerokosc,unsigned int wysokosc, RenderWindow & Okno_) {
Okno = &Okno_;
czy_okno = true;
m = Okno_.Capture();
Color stary;
for(int i=y1;i<wysokosc;i++) {
for(int ii=x1;ii<szerokosc;ii++) {
stary = m.GetPixel(ii,i);
int ile = (stary.r + stary.g + stary.b)/3;
if(ile==0)
ile = 1;
m.SetPixel(ii,i,Color(ile * w_r,ile * w_g,ile * w_b));
}
}
sprajt.SetImage(m);
sprajt.SetSubRect(IntRect(x1,y1,x1 + szerokosc, y1 + wysokosc));
sprajt.SetPosition(x1,y1);
Okno_.Draw(sprajt);
Okno_.Display();
}
Problem is a function: Okno.Capture() - it takes 0.4 second!
Class RenderWindow hasn't function SetPixel(). What can I do to make this algorithm run faster?