51 _orig_x_size = _x_size;
52 _orig_y_size = _y_size;
57 _x_shift = get_reduction_shift(_x_size, _read_x_size);
58 _x_size = _x_size / (1 << _x_shift);
59 _y_shift = get_reduction_shift(_y_size, _read_y_size);
60 _y_size = _y_size / (1 << _y_shift);
99 if (_x_shift == 0 && _y_shift == 0) {
102 for (y = 0; y < _y_size; ++y) {
103 if (!
read_row(array + y * _x_size, alpha + y * _x_size, _x_size, _y_size)) {
110 int x_reduction = (1 << _x_shift);
111 int y_reduction = (1 << _y_shift);
113 int shift = _x_shift + _y_shift;
117 int *accum_row_array = (
int *)alloca(_orig_x_size *
sizeof(
int) * 3);
118 int *accum_row_alpha = (
int *)alloca(_orig_x_size *
sizeof(
int));
122 xel *orig_row_array = (
xel *)alloca(_orig_x_size *
sizeof(
xel));
123 xelval *orig_row_alpha = (xelval *)alloca(_orig_x_size *
sizeof(xelval));
126 for (y = 0; y < _y_size; ++y) {
129 memset(accum_row_array, 0, _x_size *
sizeof(
int) * 3);
131 memset(accum_row_alpha, 0, _x_size *
sizeof(
int));
134 for (
int yi = 0; yi < y_reduction; ++yi) {
136 if (!
read_row(orig_row_array, orig_row_alpha, _orig_x_size, _orig_y_size)) {
143 xel *p = orig_row_array;
144 int *q = accum_row_array;
145 int *qstop = q + _x_size * 3;
147 for (
int xi = 0; xi < x_reduction; ++xi) {
157 xelval *p = orig_row_alpha;
158 int *q = accum_row_alpha;
159 int *qstop = q + _x_size;
161 for (
int xi = 0; xi < x_reduction; ++xi) {
171 xel *target_row_array = array + y * _x_size;
172 xelval *target_row_alpha = alpha + y * _x_size;
174 int *p = accum_row_array;
175 xel *q = target_row_array;
176 xel *qstop = q + _x_size;
178 (*q).r = (*p++) >> shift;
179 (*q).g = (*p++) >> shift;
180 (*q).b = (*p++) >> shift;
185 int *p = accum_row_alpha;
186 xelval *q = target_row_alpha;
187 xelval *qstop = q + _x_size;
189 (*q) = (*p++) >> shift;
247 get_reduction_shift(
int orig_size,
int new_size) {
252 int reduction = std::max(orig_size / new_size, 1);
257 while (r <= reduction) {
262 if ((orig_size % r) != 0) {
virtual bool supports_read_row() const
Returns true if this particular PNMReader is capable of returning the data one row at a time,...
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...
virtual bool supports_stream_read() const
Returns true if this particular PNMReader can read from a general stream (including pipes,...
A hierarchy of directories and files that appears to be one continuous 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...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
virtual bool read_pfm(PfmFile &pfm)
Reads floating-point data directly into the indicated PfmFile.
static void close_read_file(std::istream *stream)
Closes a file opened by a previous call to open_read_file().
bool is_valid() const
Returns true if the PNMReader can be used to read data, false if something is wrong.
Defines a pfm file, a 2-d table of floating-point numbers, either 3-component or 1-component,...
static VirtualFileSystem * get_global_ptr()
Returns the default global VirtualFileSystem.
virtual void prepare_read()
This method will be called before read_data() or read_row() is called.
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...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.