81 : m_sampler_valid(
false),
85 m_x_resolution = aperture_bitmap_access.get_x_resolution();
86 m_y_resolution = aperture_bitmap_access.get_y_resolution();
88 if((m_x_resolution > 0) && (m_y_resolution > 0))
90 const size_t num_pixels =
size_t(m_x_resolution) *
size_t(m_y_resolution);
91 m_pixel_weight.resize(num_pixels);
92 m_y_selection_cdf.resize(m_y_resolution);
93 m_x_selection_cdf.resize(num_pixels);
95 double original_bitmap_weight = 0.0f;
98 double cdf_entire_bitmap = 0.0;
99 for(
size_t y = 0, pixel_index = 0; y < m_y_resolution; ++y)
102 double cdf_current_row = 0.0;
103 for(
unsigned int x = 0;
x < m_x_resolution; ++
x, ++pixel_index)
106 const RGBValue original_pixel_value = aperture_bitmap_access.get_pixel_value(
x,
static_cast<unsigned int>(y));
108 const RGBValue pixel_value_with_bias = apply_center_bias(original_pixel_value, center_bias,
x,
static_cast<unsigned int>(y), m_x_resolution, m_y_resolution);
111 const float pixel_sampling_weight = get_sampling_weight(pixel_value_with_bias);
112 cdf_current_row += pixel_sampling_weight;
113 m_x_selection_cdf[pixel_index] =
static_cast<float>(cdf_current_row);
114 m_pixel_weight[pixel_index] = pixel_value_with_bias;
117 original_bitmap_weight += get_sampling_weight(original_pixel_value);
121 cdf_entire_bitmap += cdf_current_row;
122 m_y_selection_cdf[y] =
static_cast<float>(cdf_entire_bitmap);
126 if(cdf_entire_bitmap > 0.0f)
129 for(
size_t y = 0; y < m_y_resolution; ++y)
131 if(m_y_selection_cdf[y] > 0.0f)
133 const float row_total_cdf = m_x_selection_cdf[(y * m_x_resolution) + m_x_resolution - 1];
134 if(row_total_cdf > 0.0f)
136 for(
size_t x = 0, pixel_index = y * m_x_resolution;
x < m_x_resolution; ++
x, ++pixel_index)
138 m_x_selection_cdf[pixel_index] /= row_total_cdf;
139 assert(m_x_selection_cdf[pixel_index] <= 1.0f);
143 m_y_selection_cdf[y] /= m_y_selection_cdf[m_y_resolution - 1];
144 assert(m_y_selection_cdf[y] <= 1.0f);
149 double global_bitmap_weight = 1.0;
150 if(bitmap_affects_exposure)
155 global_bitmap_weight *= 1.0 / (M_PI * (0.5 * 0.5));
159 global_bitmap_weight *= original_bitmap_weight / cdf_entire_bitmap;
165 const double bitmap_average_pixel_value = cdf_entire_bitmap / num_pixels;
166 global_bitmap_weight /= bitmap_average_pixel_value;
170 for(
size_t y = 0, pixel_index = 0; y < m_y_resolution; ++y)
173 const float previous_y_cdf = (y > 0) ? m_y_selection_cdf[y - 1] : 0.0f;
174 const float y_sampling_prob = m_y_selection_cdf[y] - previous_y_cdf;
176 for(
unsigned int x = 0;
x < m_x_resolution; ++
x, ++pixel_index)
179 m_pixel_weight[pixel_index] *=
static_cast<const float>(global_bitmap_weight);
182 const float previous_x_cdf = (
x > 0) ? m_x_selection_cdf[pixel_index - 1] : 0.0f;
183 const float x_sampling_prob = m_x_selection_cdf[pixel_index] - previous_x_cdf;
186 const double pixel_sampling_prob = double(x_sampling_prob) * double(y_sampling_prob);
191 const double uniform_sampling_probability = (1.0 / num_pixels);
192 const double sample_compensation = (pixel_sampling_prob > 0.0f) ? (uniform_sampling_probability / pixel_sampling_prob) : 0.0;
193 m_pixel_weight[pixel_index] *=
static_cast<const float>(sample_compensation);
197 m_sampler_valid =
true;
controller mat max min numsubs x z controller keys x z controller keys x
Definition: generics.inl:212
#define assert(expr)
Definition: assert1.h:81
MAXMEM_EXTERN_C UtilExport size_t(__cdecl *MAX_msize)(void *memblock)