15 #include "pnmReader.h"
16 #include "virtualFileSystem.h"
36 _file = (istream *)NULL;
59 _orig_x_size = _x_size;
60 _orig_y_size = _y_size;
65 _x_shift = get_reduction_shift(_x_size, _read_x_size);
66 _x_size = _x_size / (1 << _x_shift);
67 _y_shift = get_reduction_shift(_y_size, _read_y_size);
68 _y_size = _y_size / (1 << _y_shift);
116 if (_x_shift == 0 && _y_shift == 0) {
119 for (y = 0; y < _y_size; ++y) {
120 if (!
read_row(array + y * _x_size, alpha + y * _x_size, _x_size, _y_size)) {
127 int x_reduction = (1 << _x_shift);
128 int y_reduction = (1 << _y_shift);
130 int shift = _x_shift + _y_shift;
134 int *accum_row_array = (
int *)alloca(_orig_x_size *
sizeof(
int) * 3);
135 int *accum_row_alpha = (
int *)alloca(_orig_x_size *
sizeof(
int));
139 xel *orig_row_array = (
xel *)alloca(_orig_x_size *
sizeof(
xel));
140 xelval *orig_row_alpha = (xelval *)alloca(_orig_x_size *
sizeof(xelval));
143 for (y = 0; y < _y_size; ++y) {
146 memset(accum_row_array, 0, _x_size *
sizeof(
int) * 3);
148 memset(accum_row_alpha, 0, _x_size *
sizeof(
int));
151 for (
int yi = 0; yi < y_reduction; ++yi) {
153 if (!
read_row(orig_row_array, orig_row_alpha, _orig_x_size, _orig_y_size)) {
160 xel *p = orig_row_array;
161 int *q = accum_row_array;
162 int *qstop = q + _x_size * 3;
164 for (
int xi = 0; xi < x_reduction; ++xi) {
174 xelval *p = orig_row_alpha;
175 int *q = accum_row_alpha;
176 int *qstop = q + _x_size;
178 for (
int xi = 0; xi < x_reduction; ++xi) {
189 xel *target_row_array = array + y * _x_size;
190 xelval *target_row_alpha = alpha + y * _x_size;
192 int *p = accum_row_array;
193 xel *q = target_row_array;
194 xel *qstop = q + _x_size;
196 (*q).r = (*p++) >> shift;
197 (*q).g = (*p++) >> shift;
198 (*q).b = (*p++) >> shift;
203 int *p = accum_row_alpha;
204 xelval *q = target_row_alpha;
205 xelval *qstop = q + _x_size;
207 (*q) = (*p++) >> shift;
282 get_reduction_shift(
int orig_size,
int new_size) {
287 int reduction = max(orig_size / new_size, 1);
292 while (r <= reduction) {
297 if ((orig_size % r) != 0) {
virtual int read_data(xel *array, xelval *alpha)
Reads in an entire image all at once, storing it in the pre-allocated _x_size * _y_size array and alp...
A hierarchy of directories and files that appears to be one continuous file system, even though the files may originate from several different sources that may not be related to the actual OS's file system.
virtual bool is_floating_point()
Returns true if this PNMFileType represents a floating-point image type, false if it is a normal...
static void consider_yield()
Possibly suspends the current thread for the rest of the current epoch, if it has run for enough this...
static void close_read_file(istream *stream)
Closes a file opened by a previous call to open_read_file().
virtual bool supports_stream_read() const
Returns true if this particular PNMReader can read from a general stream (including pipes...
virtual bool read_pfm(PfmFile &pfm)
Reads floating-point data directly into the indicated PfmFile.
Defines a pfm file, a 2-d table of floating-point numbers, either 3-component or 1-component, or with a special extension, 2- or 4-component.
static VirtualFileSystem * get_global_ptr()
Returns the default global VirtualFileSystem.
bool is_valid() const
Returns true if the PNMReader can be used to read data, false if something is wrong.
virtual void prepare_read()
This method will be called before read_data() or read_row() is called.
virtual bool supports_read_row() const
Returns true if this particular PNMReader is capable of returning the data one row at a time...
virtual bool read_row(xel *array, xelval *alpha, int x_size, int y_size)
If supports_read_row(), above, returns true, this function may be called repeatedly to read the image...