Home || Architecture || Video Search || Visual Search || Scripts || Applications || Important Messages || OGL || Src

WritePgm.h

Go to the documentation of this file.
00001 #ifndef Impala_Core_Array_WritePgm_h
00002 #define Impala_Core_Array_WritePgm_h
00003 
00004 #include <vector>
00005 #include "Core/Array/Element/TypeString.h"
00006 #include "Basis/NativeTypeFormats.h"
00007 
00008 namespace Impala
00009 {
00010 namespace Core
00011 {
00012 namespace Array
00013 {
00014 
00015 
00016 // Handles images only if pixels represent grey value [0-255]
00017 // (in case of vector images only the first channel is written)
00018 template<class ArrayT>
00019 inline void
00020 WritePgm(ArrayT* src, std::string fileName)
00021 {
00022     typedef typename ArrayT::StorType StorT;
00023 
00024     int width = src->CW();
00025     int height = src->CH();
00026     int elemSize = ArrayT::ElemSize();
00027     FILE* fp = fopen(fileName.c_str(), "wb");
00028     fprintf(fp, "P5\n%d %d\n255\n", width, height);
00029     std::string fs = NativeTypeFormat<StorT>(0) + std::string(" ");
00030     for (int i=0 ; i<height ; i++)
00031     {
00032         StorT* srcPtr = src->CPB(0, i);
00033         for(int j=0 ; j<width ; j++)
00034         {
00035             fputc(*srcPtr, fp);
00036             for (int k=0 ; k<elemSize ; k++)
00037                 srcPtr++;
00038         }
00039     }
00040     fclose(fp);
00041 }
00042 
00043 } // namespace Array
00044 } // namespace Core
00045 } // namespace Impala
00046 
00047 #endif

Generated on Fri Mar 19 09:31:03 2010 for ImpalaSrc by  doxygen 1.5.1