18 #include "visiontransfer/imagepair.h" 23 #include <arpa/inet.h> 27 if(imageNumber < 0 || imageNumber >1) {
28 throw std::runtime_error(
"Illegal image number!");
31 std::fstream strm(fileName, std::ios::out | std::ios::binary);
34 int maxVal, bytesPixel;
43 strm <<
"P5 " << width <<
" " << height <<
" " << maxVal << std::endl;
46 for(
int y = 0; y < height; y++) {
47 for(
int x = 0; x < width; x++) {
48 unsigned char* pixel = &data[imageNumber][y*rowStride[imageNumber] + x*bytesPixel];
51 *
reinterpret_cast<unsigned short*
>(pixel)
52 = htons(*reinterpret_cast<unsigned short*>(pixel));
54 strm.write(reinterpret_cast<char*>(pixel), bytesPixel);
void writePgmFile(int imageNumber, const char *fileName)
Writes one image of the pair to a PGM file.