30 #ifndef _D_IMAGE_IO_PBM_H
31 #define _D_IMAGE_IO_PBM_H
36 #include "Core/include/private/DTypes.hpp"
37 #include "Core/include/private/DImage.hpp"
38 #include "IO/include/private/DImageIO.hpp"
47 RES_T readNetPBMFileInfo(ifstream &fp, ImageFileInfo &fInfo,
48 unsigned int &maxval);
49 RES_T readNetPBMFileInfo(
const char *filename, ImageFileInfo &fInfo,
50 unsigned int &maxval);
52 template <
class T>
class Image;
54 template <
class T =
void>
62 virtual RES_T getFileInfo(
const char *filename,
ImageFileInfo &fInfo)
65 fInfo.filename = filename;
66 return readNetPBMFileInfo(filename, fInfo, dum);
69 virtual RES_T read(
const char *filename,
Image<T> &image)
73 virtual RES_T write(
const Image<T> &image,
const char *filename)
79 template <
class T =
void>
87 virtual RES_T getFileInfo(
const char *filename,
ImageFileInfo &fInfo)
90 return readNetPBMFileInfo(filename, fInfo, dum);
93 virtual RES_T read(
const char *filename,
Image<T> &image)
96 ifstream fp(filename, ios_base::binary);
99 cout <<
"Cannot open file " << filename << endl;
105 ASSERT(readNetPBMFileInfo(fp, fInfo, dum) == RES_OK, RES_ERR_IO);
106 ASSERT(fInfo.colorType == ImageFileInfo::COLOR_TYPE_BINARY,
107 "Not an binary image", RES_ERR_IO);
109 size_t width = fInfo.width;
110 size_t height = fInfo.height;
112 ASSERT((image.
setSize(width, height) == RES_OK), RES_ERR_BAD_ALLOCATION);
114 if (fInfo.fileType == ImageFileInfo::FILE_TYPE_BINARY) {
115 typename ImDtTypes<T>::sliceType lines = image.
getLines();
121 for (
size_t j = 0; j < height; j++) {
122 typename ImDtTypes<T>::lineType pixels = lines[j];
124 for (
size_t i = 0; i < width; i++) {
133 typename ImDtTypes<T>::lineType pixels = image.
getPixels();
146 virtual RES_T write(
const Image<T> &image,
const char *filename)
159 inline RES_T PBMImageFileHandler<void>::write(
const Image<void> &,
166 IMAGEFILEHANDLER_TEMP_SPEC(PGM, UINT8);
169 IMAGEFILEHANDLER_TEMP_SPEC(PGM, RGB);
size_t getPixelCount() const
Get the number of pixels.
Definition: DBaseImage.h:160
Definition: DImageIO.hpp:45
Main Image class.
Definition: DImage.hpp:57
lineType getPixels() const
Get the pixels as a 1D array.
Definition: DImage.hpp:105
sliceType getLines() const
Get an array containing the start offset of each line.
Definition: DImage.hpp:111
virtual RES_T setSize(size_t w, size_t h, size_t d=1, bool doAllocate=true)
Set the size of image.
Definition: DImageIO_PBM.hpp:81
Definition: DImageIO_PBM.hpp:56
Definition: DTypes.hpp:88
Definition: DCommonIO.h:72