 |
Bsoft
2.1.0
Bernard's software package
|
Go to the documentation of this file.
18 while ( !isspace(*aptr) ) aptr++;
20 while ( isspace(*aptr) ) aptr++;
22 while ( *aptr ==
'#' ) {
23 while ( *aptr !=
'\n' ) aptr++;
25 while ( isspace(*aptr) ) aptr++;
37 long x, y, new_x = (p->
sizeX()-1)/8 + 1;
40 unsigned short* usdata = (
unsigned short *) data;
44 while ( fimg->getline(aline,
MAXLINELEN) && i < imgsize ) {
46 for ( aptr = aline; *aptr !=
'\n' && aptr < aline + len; ) {
47 if ( sscanf(aptr,
"%ld%n", &v, &n) ) {
52 data[y*new_x+x/8] |= 0x80 >> x%8;
82 cout <<
"DEBUG readPNM: Filename = " << p->
file_name() << endl;
90 if ( ext.find(
"pbm") != string::npos ) p->
data_type(
Bit);
92 else if ( ext.find(
"ppm") != string::npos ) {
96 cerr <<
"Error: File with extension " << ext <<
" not recognized!" << endl;
100 ifstream* fimg =
new ifstream;
102 if ( fimg->fail() )
return -1;
105 cout <<
"DEBUG readPNM: File opened" << endl;
111 fimg->seekg(0, ios_base::end);
112 int len = fimg->tellg();
115 cout <<
"DEBUG readPNM: File length = " << len << endl;
118 if ( !fimg->read(aline, len) )
return -2;
119 sscanf(aline,
"P%d", &magic);
131 p->
sizeX(atoi(aptr));
133 p->
sizeY(atoi(aptr));
142 while ( !isspace(*aptr) ) aptr++;
163 fimg->read((
char *)data, readsize);
171 cout <<
"DEBUG readPNM: File read: type = " << magic << endl;
193 if ( fimg.fail() )
return -1;
199 if ( p->
data_type() ==
UShort && max <= UCHAR_MAX ) max = UCHAR_MAX + 1;
203 cout <<
"DEBUG writePNM: datatype=" << p->
data_type() << endl;
205 for ( n=0; n<p->
images(); n++, data += imgsize ) {
209 else cerr <<
"Error: Compound type " << p->
compound_type() <<
" not supported!" << endl;
210 fimg << p->
sizeX() <<
" " << p->
sizeY() << endl;
213 else cerr <<
"Error: Data type " << p->
data_type() <<
" not supported!" << endl;
215 fimg.write((
char *)data, imgsize);
unsigned char * pnm_read_data(ifstream *fimg, Bimage *p)
char * pnm_next_item(char *aptr)
Vector3< long > page_size()
Vector3< long > size() const
long data_type_size() const
Returns the size of the datatype in bytes.
int writePNM(Bimage *p)
Writing a PNM type file. A simple image format.
int readPNM(Bimage *p, int readdata, int img_select)
Reading a PNM type file. A simple image format. PBM bit image format. PGM grayscale image format....
General image parameter class.
CompoundType compound_type()
unsigned char * data_alloc()
void color_to_simple()
A color image is converted to a simple image.
Header file for general utilities.
void change_type(char letter)
Get the data type indicated by a single letter code.
string extension(string filename)
unsigned char * data_pointer()
Header file for reading and writing PNM files.