38 static void read_packed(
unsigned char *data,
int size, std::ifstream &f) {
42 for (
int pos = 0; pos < size; pos++) {
47 data[pos] = (c >> bitshift) & 1;
52 static void write_packed(
unsigned char *data,
int size, std::ofstream &f) {
56 for (
int pos = 0; pos < size; pos++) {
57 c = c | (data[pos] << bitshift);
59 if ((bitshift == -1) || (pos == size-1)) {
68 static void pnm_read(std::ifstream &file,
char *buf) {
74 file.getline(doc, BUF_SIZE);
88 std::ifstream file(name, std::ios::in | std::ios::binary);
90 if (strncmp(buf,
"P4", 2))
94 int width = atoi(buf);
96 int height = atoi(buf);
100 for (
int i = 0; i < height; i++)
107 int width = im->
width();
108 int height = im->
height();
109 std::ofstream file(name, std::ios::out | std::ios::binary);
111 file <<
"P4\n" << width <<
" " << height <<
"\n";
112 for (
int i = 0; i < height; i++)
120 std::ifstream file(name, std::ios::in | std::ios::binary);
122 if (strncmp(buf,
"P5", 2))
126 int width = atoi(buf);
128 int height = atoi(buf);
131 if (atoi(buf) > UCHAR_MAX)
136 file.read((
char *)
imPtr(im, 0, 0), width * height *
sizeof(
uchar));
142 int width = im->
width();
143 int height = im->
height();
144 std::ofstream file(name, std::ios::out | std::ios::binary);
146 file <<
"P5\n" << width <<
" " << height <<
"\n" << UCHAR_MAX <<
"\n";
147 file.write((
char *)
imPtr(im, 0, 0), width * height *
sizeof(
uchar));
154 std::ifstream file(name, std::ios::in | std::ios::binary);
156 if (strncmp(buf,
"P6", 2))
160 int width = atoi(buf);
162 int height = atoi(buf);
165 if (atoi(buf) > UCHAR_MAX)
170 file.read((
char *)
imPtr(im, 0, 0), width * height *
sizeof(
rgb));
176 int width = im->
width();
177 int height = im->
height();
178 std::ofstream file(name, std::ios::out | std::ios::binary);
180 file <<
"P6\n" << width <<
" " << height <<
"\n" << UCHAR_MAX <<
"\n";
181 file.write((
char *)
imPtr(im, 0, 0), width * height *
sizeof(
rgb));
189 std::ifstream file(name, std::ios::in | std::ios::binary);
191 if (strncmp(buf,
"VLIB", 9))
195 int width = atoi(buf);
197 int height = atoi(buf);
201 file.read((
char *)
imPtr((*im), 0, 0), width * height *
sizeof(T));
206 int width = im->
width();
207 int height = im->
height();
208 std::ofstream file(name, std::ios::out | std::ios::binary);
210 file <<
"VLIB\n" << width <<
" " << height <<
"\n";
211 file.write((
char *)
imPtr(im, 0, 0), width * height *
sizeof(T));