#include #include #include //Creates a 2D-std::vector (y-x-ordered) from a TImage //From http://www.richelbilderbeek.nl/CppImageToVector.htm const std::vector > ImageToVector(const TImage * const image) { assert(image!=0 && "Image must not be NULL"); assert(image->Picture->Bitmap!=0 && "Bitmap must not be NULL"); assert(image->Picture->Bitmap->PixelFormat == pf24bit && "Bitmap must be 24 bit"); const int width = image->Picture->Bitmap->Width; const int height = image->Picture->Bitmap->Height; std::vector > v(height, std::vector(width)); for (int y=0; y!=height; ++y) { assert(y >= 0); assert(y < static_cast(v.size())); std::vector& vLine = v[y]; const unsigned char * const line = static_cast(image->Picture->Bitmap->ScanLine[y]); for (int x=0; x!=width; ++x) { assert(x >= 0); assert(x < static_cast(vLine.size())); const double grey = static_cast(line[x*3+0] + line[x*3+1] + line[x*3+2]) / 3.0; vLine[x] = grey; assert(grey>=0.0 && grey<256.0); } } return v; }