Nadesłany przez Tomasz Lubiński, 24 lutego 2009 01:00
Kod przedstawiony poniżej przedstawia główną część rozwiązania problemu.Pobierz pełne rozwiązanie.
Jeżeli nie odpowiada Ci sposób formatowania kodu przez autora skorzystaj z pretty printer'a i dostosuj go automatycznie do siebie.
3D Anaglify - C++/anaglyph.cpp:
//--------------------------------------------------------------------------- // Anaglify - tworzenie obrazow 3D // www.algorytm.org // (c) 2009 by Tomasz Lubinski #include <vcl.h> #pragma hdrstop #include "anaglyph.h" //--------------------------------------------------------------------------- #pragma package(smart_init) #pragma resource "*.dfm" TForm1 *Form1; //--------------------------------------------------------------------------- __fastcall TForm1::TForm1(TComponent* Owner) : TForm(Owner) { } //--------------------------------------------------------------------------- void __fastcall TForm1::Button1Click(TObject *Sender) { int lr, lg, lb; int rr, rg, rb; int r, g, b; Byte *lP, *rP, *lrP, *rrP, *P; int i, j; left->Picture->Bitmap->PixelFormat = pf32bit; right->Picture->Bitmap->PixelFormat = pf32bit; left_result->Canvas->Rectangle(0, 0, left_result->Width, left_result->Height); left_result->Picture->Bitmap->PixelFormat = pf32bit; right_result->Canvas->Rectangle(0, 0, right_result->Width, right_result->Height); right_result->Picture->Bitmap->PixelFormat = pf32bit; result->Canvas->Rectangle(0, 0, result->Width, result->Height); result->Picture->Bitmap->PixelFormat = pf32bit; for (int i=0; i<left->Picture->Bitmap->Height; i++) { lP = (Byte *)left->Picture->Bitmap->ScanLine[i]; rP = (Byte *)right->Picture->Bitmap->ScanLine[i]; lrP = (Byte *)left_result->Picture->Bitmap->ScanLine[i]; rrP = (Byte *)right_result->Picture->Bitmap->ScanLine[i]; P = (Byte *)result->Picture->Bitmap->ScanLine[i]; for (int j=0; j<left->Picture->Bitmap->Width; j++) { /* get RGB from left eye */ lb = *lP; *lP++; lg = *lP; *lP++; lr = *lP; *lP++; *lP++; /* get RGB from right eye */ rb = *rP; *rP++; rg = *rP; *rP++; rr = *rP; *rP++; *rP++; if (method_mono->Checked) { r = (int)((double)lr*0.299+(double)lg*0.587+(double)lb*0.114); g = (int)((double)rr*0.299+(double)rg*0.587+(double)rb*0.114); b = (int)((double)rr*0.299+(double)rg*0.587+(double)rb*0.114); } else if (method_ps->Checked) { r = lr; g = rg; b = rb; } else if (method_psM->Checked) { r = (int)((double)lr*0.299+(double)lg*0.587+(double)lb*0.114);; g = rg; b = rb; } else { r = (int)(0.456100*(double)lr + 0.500484*(double)lg + 0.176381*(double)lb - 0.0434706*(double)rr - 0.0879388*(double)rg - 0.00155529*(double)rb); if (r > 255) r = 255; else if (r < 0) r = 0; g = (int)(-0.0400822*(double)lr - 0.0378246*(double)lg - 0.0157589*(double)lb + 0.378476*(double)rr + 0.73364*(double)rg - 0.0184503*(double)rb); if (g > 255) g = 255; else if (g < 0) g = 0; b = (int)(-0.0152161*(double)lr - 0.0205971*(double)lg - 0.00546856*(double)lb - 0.0721527*(double)rr - 0.112961*(double)rg + 1.2264*(double)rb); if (b > 255) b = 255; else if (b < 0) b = 0; } /* show result for left eye */ *lrP = 0; lrP++; *lrP = 0; lrP++; *lrP = r; lrP++; lrP++; /* show result for right eye */ *rrP = b; rrP++; *rrP = g; rrP++; *rrP = 0; rrP++; rrP++; /* show result for both eyes */ *P = b; P++; *P = g; P++; *P = r; P++; P++; } } } //---------------------------------------------------------------------------