[C++] Program do nakladania efektów na bitmapy

Mam taki problem. Musze zmienić program, który naklada efekty na bitmapy (np. negatyw, zamiana z RGB na YUV) tak aby działał na wskaźnikach, ponieważ sa działa zbyt wolno. Poniżej kod:

#include 

#pragma hdrstop


#include "grafa_zad1.h"

#include "Unit2.h"

//---------------------------------------------------------------------------

#pragma package(smart_init)

#pragma resource "*.dfm"

TForm1 *Form1;

//---------------------------------------------------------------------------

__fastcall TForm1::TForm1(TComponent* Owner)

	: TForm(Owner)

{

}

//---------------------------------------------------------------------------

void __fastcall TForm1::NegatywClick(TObject *Sender)

{


for (int y = 0; yPicture->Bitmap->Height; y++)

for (int x = 0; xPicture->Bitmap->Width; x++)

{

TColor kolor=Image1->Picture->Bitmap->Canvas->Pixels[x][y];

Byte r=GetRValue(kolor);

Byte g=GetGValue(kolor);

Byte b=GetBValue(kolor);


Image2->Picture->Bitmap->Canvas->Pixels[x][y]=RGB(255-r,255-g,255-b);

}

}

//---------------------------------------------------------------------------


void __fastcall TForm1::SaveAs1Click(TObject *Sender)

{

if (SavePictureDialog1->Execute()){

Image2->Picture->SaveToFile(SavePictureDialog1->FileName);

}

}

//---------------------------------------------------------------------------


void __fastcall TForm1::Open1Click(TObject *Sender)

{

if (OpenPictureDialog1->Execute()){

Image1->Picture->LoadFromFile(OpenPictureDialog1->FileName);

Image2->Picture->LoadFromFile(OpenPictureDialog1->FileName);

}

}

//---------------------------------------------------------------------------


void __fastcall TForm1::Exit1Click(TObject *Sender)

{

exit(1);

}

//---------------------------------------------------------------------------


void __fastcall TForm1::AboutClick(TObject *Sender)

{

	Form2->ShowModal();

}

//---------------------------------------------------------------------------


void __fastcall TForm1::RedClick(TObject *Sender)

{

for (int y = 0; yPicture->Bitmap->Height; y++)

for (int x = 0; xPicture->Bitmap->Width; x++)

{

TColor kolor=Image1->Picture->Bitmap->Canvas->Pixels[x][y];

Byte r=GetRValue(kolor);

Byte g=GetGValue(kolor);

Byte b=GetBValue(kolor);


Image2->Picture->Bitmap->Canvas->Pixels[x][y]=RGB(r,r,r);

}

}

//---------------------------------------------------------------------------


void __fastcall TForm1::GreenClick(TObject *Sender)

{

for (int y = 0; yPicture->Bitmap->Height; y++)

for (int x = 0; xPicture->Bitmap->Width; x++)

{

TColor kolor=Image1->Picture->Bitmap->Canvas->Pixels[x][y];

Byte r=GetRValue(kolor);

Byte g=GetGValue(kolor);

Byte b=GetBValue(kolor);


Image2->Picture->Bitmap->Canvas->Pixels[x][y]=RGB(g,g,g);

}

}

//---------------------------------------------------------------------------


void __fastcall TForm1::BlueClick(TObject *Sender)

{

for (int y = 0; yPicture->Bitmap->Height; y++)

for (int x = 0; xPicture->Bitmap->Width; x++)

{

TColor kolor=Image1->Picture->Bitmap->Canvas->Pixels[x][y];

Byte r=GetRValue(kolor);

Byte g=GetGValue(kolor);

Byte b=GetBValue(kolor);


Image2->Picture->Bitmap->Canvas->Pixels[x][y]=RGB(b,b,b);

}

}

//---------------------------------------------------------------------------


void __fastcall TForm1::Y_luminacjaClick(TObject *Sender)

{


for (int y = 0; yPicture->Bitmap->Height; y++)

for (int x = 0; xPicture->Bitmap->Width; x++)

{

TColor kolor=Image1->Picture->Bitmap->Canvas->Pixels[x][y];

Byte r=GetRValue(kolor);

Byte g=GetGValue(kolor);

Byte b=GetBValue(kolor);

float YY = (0.257 * r) + (0.504 * g) + (0.098 * b) + 16;

Image2->Picture->Bitmap->Canvas->Pixels[x][y]=RGB(YY,YY,YY);

}

}

//---------------------------------------------------------------------------


void __fastcall TForm1::U_chrominacjaClick(TObject *Sender)

{

for (int y = 0; yPicture->Bitmap->Height; y++)

for (int x = 0; xPicture->Bitmap->Width; x++)

{

TColor kolor=Image1->Picture->Bitmap->Canvas->Pixels[x][y];

Byte r=GetRValue(kolor);

Byte g=GetGValue(kolor);

Byte b=GetBValue(kolor);

float UU= -(0.148 * r) - (0.291 * g) + (0.439 * b) + 128;

Image2->Picture->Bitmap->Canvas->Pixels[x][y]=RGB(UU,UU,UU);

}

}

//---------------------------------------------------------------------------


void __fastcall TForm1::V_chrominacjaClick(TObject *Sender)

{

for (int y = 0; yPicture->Bitmap->Height; y++)

for (int x = 0; xPicture->Bitmap->Width; x++)

{

TColor kolor=Image1->Picture->Bitmap->Canvas->Pixels[x][y];

Byte r=GetRValue(kolor);

Byte g=GetGValue(kolor);

Byte b=GetBValue(kolor);

float VV= (0.439 * r) - (0.368 * g) - (0.071 * b) + 128;

Image2->Picture->Bitmap->Canvas->Pixels[x][y]=RGB(VV,VV,VV);

}

}

//---------------------------------------------------------------------------


void __fastcall TForm1::Open2Click(TObject *Sender)

{

  if (OpenPictureDialog1->Execute()){

Image1->Picture->LoadFromFile(OpenPictureDialog1->FileName);

Image2->Picture->LoadFromFile(OpenPictureDialog1->FileName);

}

}

//---------------------------------------------------------------------------


void __fastcall TForm1::SaveAs2Click(TObject *Sender)

{

if (SavePictureDialog1->Execute()){

Image2->Picture->SaveToFile(SavePictureDialog1->FileName);

}

}

//---------------------------------------------------------------------------


void __fastcall TForm1::Exit2Click(TObject *Sender)

{

exit(1);

}

//---------------------------------------------------------------------------


void __fastcall TForm1::Filtr_progowyChange(TObject *Sender)

{

for (int y = 0; yPicture->Bitmap->Height; y++)

for (int x = 0; xPicture->Bitmap->Width; x++)

{

TColor kolor=Image1->Picture->Bitmap->Canvas->Pixels[x][y];

Byte r=GetRValue(kolor);

Byte g=GetGValue(kolor);

Byte b=GetBValue(kolor);

kolor=0.299*r+0.587*g+0.114*b;

if (Filtr_progowy->Position > kolor)

kolor=0;

else

kolor=255;

kolor=RGB(kolor,kolor,kolor);

Image2->Picture->Bitmap->Canvas->Pixels[x][y]=RGB(kolor,kolor,kolor);

}

}

//---------------------------------------------------------------------------

Z tego co widzę to dziergasz to obiektowo (C++ Builder czy coś w ten deseń) Pikselek po pikselku , przebijając się przez warstwę OO abstrakcji (Image2->Picture->Bitmap->Canvas->Pixels[x][y]). Musisz znaleźć lepszy sposób na obsługę obrazków (jakąś bibliotekę, tylko CB to trudniej niż inne kompilatory będzie) np. wczytać do jakiegoś bufora, prostej tablicy i przetworzyć a potem na “raz” wrzucić do obiektu Timage.

Musisz to robić w C++ Builderze?

No w Builderze mi najłatwiej, najbardziej obeznany jestem w nim. Szczerze nie potrafie wymyslec innego sposobu jak tylko robic to pixel po pixelu. Sadzilem, że istnieje jakiś sposób żeby te funkcje przerobić tak aby chodziły na wskaźnikach. Może ktoś ma jakieś pomysły. Znając życie sposób jest banalny tylko trzeba na niego wpaść.