54 std::array<float, 4> accPixels;
61 area.size = area.size - (area.size & 1);
64 if (!area.isVertical) {
65 if (
static_cast<int>(area.offset) +
static_cast<int>(area.size) >
67 ThrowRDE(
"Offset + size is larger than height of image");
68 for (
uint32_t y = area.offset;
y < area.offset + area.size;
y++) {
70 accPixels[((
y & 1) << 1) | (
x & 1)] += img(
y,
x);
73 totalpixels += area.size *
dim.x;
77 if (area.isVertical) {
78 if (
static_cast<int>(area.offset) +
static_cast<int>(area.size) >
80 ThrowRDE(
"Offset + size is larger than width of image");
82 for (
uint32_t x = area.offset;
x < area.size + area.offset;
x++) {
83 accPixels[((
y & 1) << 1) | (
x & 1)] += img(
y,
x);
86 totalpixels += area.size *
dim.y;
94 for (
int& i : blackLevelSeparate1D)
104 for (
int i = 0; i < 4; i++) {
105 blackLevelSeparate1D(i) =
static_cast<int>(
113 for (
int i : blackLevelSeparate1D)
115 for (
int& i : blackLevelSeparate1D)
116 i = (total + 2) >> 2;
180 std::array<float, 4> values;
182 std::array<float, 4> dist = {{}};
183 std::array<float, 4> weight;
188 int step =
isCFA ? 2 : 1;
191 int x_find =
static_cast<int>(
x) - step;
193 while (x_find >= 0 && values[curr] < 0) {
194 if (0 == ((bad(
y, x_find >> 3) >> (x_find & 7)) & 1)) {
195 values[curr] = img(
y, x_find + component);
196 dist[curr] =
static_cast<float>(
static_cast<int>(
x) - x_find);
201 x_find =
static_cast<int>(
x) + step;
204 if (0 == ((bad(
y, x_find >> 3) >> (x_find & 7)) & 1)) {
205 values[curr] = img(
y, x_find + component);
206 dist[curr] =
static_cast<float>(x_find -
static_cast<int>(
x));
212 int y_find =
static_cast<int>(
y) - step;
214 while (y_find >= 0 && values[curr] < 0) {
215 if (0 == ((bad(y_find,
x >> 3) >> (
x & 7)) & 1)) {
216 values[curr] = img(y_find,
x + component);
217 dist[curr] =
static_cast<float>(
static_cast<int>(
y) - y_find);
222 y_find =
static_cast<int>(
y) + step;
225 if (0 == ((bad(y_find,
x >> 3) >> (
x & 7)) & 1)) {
226 values[curr] = img(y_find,
x + component);
227 dist[curr] =
static_cast<float>(y_find -
static_cast<int>(
y));
232 float total_div = 0.000001F;
235 if (
float total_dist_x = dist[0] + dist[1]; std::abs(total_dist_x) > 0) {
236 weight[0] = dist[0] > 0.0F ? (total_dist_x - dist[0]) / total_dist_x : 0;
237 weight[1] = 1.0F - weight[0];
242 if (
float total_dist_y = dist[2] + dist[3]; std::abs(total_dist_y) > 0) {
243 weight[2] = dist[2] > 0.0F ? (total_dist_y - dist[2]) / total_dist_y : 0;
244 weight[3] = 1.0F - weight[2];
248 float total_pixel = 0;
249 for (
int i = 0; i < 4; i++)
251 total_pixel += values[i] * weight[i];
253 total_pixel /= total_div;
254 img(
y,
x + component) = total_pixel;
257 if (
cpp > 1 && component == 0)
258 for (
int i = 1; i <
cpp; i++)