24 uint c1, c2, c3, error;
31 for (
y--;
y > 0;
y--) {
34 c1 += (c2 << 1) + c3 + error;
41 *point = (c1 + (c2 << 1) + c2 + error) >> 2;
47 float c1, c2, c3, *point2;
52 for (
y--;
y > 0;
y--) {
61 *point = 0.25f * (c1 + (c2 * 2) + c2);
104 const char *row1, *row2, *row3;
111 temprect = MEM_dupalloc(
mask);
113 for (
y = 1;
y <= height;
y++) {
115 row1 =
static_cast<char *
>(temprect + (
y - 2) * rowlen);
116 row2 = row1 + rowlen;
117 row3 = row2 + rowlen;
121 else if (
y == height) {
125 for (
x = 0;
x < rowlen;
x++) {
126 if (
mask[((
y - 1) * rowlen) +
x] == 0) {
127 if (*row1 || *row2 || *row3 || *(row1 + 1) || *(row3 + 1)) {
130 else if ((
x != rowlen - 1) && (*(row1 + 2) || *(row2 + 2) || *(row3 + 2))) {
143 MEM_delete(temprect);
150 for (
x = 0;
x < ibuf->
x;
x++) {
151 for (
y = 0;
y < ibuf->
y;
y++) {
152 if (
mask[ibuf->
x *
y +
x] == val) {
153 float *col = float_data + 4 * (ibuf->
x *
y +
x);
154 col[0] = col[1] = col[2] = col[3] = 0.0f;
162 for (
x = 0;
x < ibuf->
x;
x++) {
163 for (
y = 0;
y < ibuf->
y;
y++) {
164 if (
mask[ibuf->
x *
y +
x] == val) {
165 char *col =
reinterpret_cast<char *
>(byte_data + 4 * ibuf->
x *
y +
x);
166 col[0] = col[1] = col[2] = col[3] = 0;
183 const void *buffer,
const char *
mask,
const int index,
const int depth,
const bool is_float)
188 const int alpha_index = depth *
index + (depth - 1);
190 if (
mask !=
nullptr) {
193 else if ((is_float && (
static_cast<const float *
>(buffer))[alpha_index] != 0.0f) ||
194 (!is_float && (
static_cast<const uchar *
>(buffer))[alpha_index] != 0))
205 const int width = ibuf->
x;
206 const int height = ibuf->
y;
209 const size_t bsize = size_t(width) * height * depth * chsize;
210 const bool is_float = (ibuf->
float_data() !=
nullptr);
212 static_cast<void *
>(MEM_dupalloc(ibuf->
byte_data()));
216 char *srcmask =
mask;
217 int cannot_early_out = 1, r, n, k, i, j, c;
225 for (i = -n; i <= n; i++) {
226 for (j = -n; j <= n; j++) {
227 weight[k++] =
sqrt(
float(i) * i + j * j);
243 for (r = 0; cannot_early_out == 1 && r <
filter; r++) {
245 cannot_early_out = 0;
247 for (
y = 0;
y < height;
y++) {
248 for (
x = 0;
x < width;
x++) {
255 float acc[4] = {0, 0, 0, 0};
267 for (i = -n; i <= n; i++) {
268 for (j = -n; j <= n; j++) {
269 if (i != 0 || j != 0) {
274 for (c = 0; c < depth; c++) {
275 tmp[c] = (
static_cast<const float *
>(srcbuf))[depth * tmpindex + c];
279 for (c = 0; c < depth; c++) {
280 tmp[c] =
float((
static_cast<const uchar *
>(srcbuf))[depth * tmpindex + c]);
286 for (c = 0; c < depth; c++) {
287 acc[c] += weight[k] * tmp[c];
296 for (c = 0; c < depth; c++) {
301 for (c = 0; c < depth; c++) {
302 (
static_cast<float *
>(dstbuf))[depth *
index + c] = acc[c];
306 for (c = 0; c < depth; c++) {
307 (
static_cast<uchar *
>(dstbuf))[depth *
index + c] =
308 acc[c] > 255 ? 255 : (acc[c] < 0 ? 0 :
uchar(
roundf(acc[c])));
312 if (dstmask !=
nullptr) {
315 cannot_early_out = 1;
323 memcpy(srcbuf, dstbuf, bsize);
324 if (dstmask !=
nullptr) {
325 memcpy(srcmask, dstmask,
size_t(width) * height);
331 if (dstmask !=
nullptr) {
344 for (
y = 0;
y < h;
y++) {
345 for (
x = 0;
x <
w;
x++, cp += 4) {
353 for (
y = 0;
y < h;
y++) {
354 for (
x = 0;
x <
w;
x++, cp += 4) {
356 cp[0] = (cp[0] * val) >> 8;
357 cp[1] = (cp[1] * val) >> 8;
358 cp[2] = (cp[2] * val) >> 8;
371 for (
y = 0;
y < h;
y++) {
372 for (
x = 0;
x <
w;
x++, cp += 4) {
384 if (ibuf ==
nullptr) {
406 for (
y = 0;
y < h;
y++) {
407 for (
x = 0;
x <
w;
x++, cp += 4) {
415 for (
y = 0;
y < h;
y++) {
416 for (
x = 0;
x <
w;
x++, cp += 4) {
417 val = cp[3] != 0 ? 1.0f /
float(cp[3]) : 1.0f;
433 for (
y = 0;
y < h;
y++) {
434 for (
x = 0;
x <
w;
x++, fp += 4) {
435 val = fp[3] != 0.0f ? 1.0f / fp[3] : 1.0f;
446 if (ibuf ==
nullptr) {
Function declarations for filter.cc.
#define FILTER_MASK_MARGIN
Read Blender memory allocation and freeing.
SIMD_FORCE_INLINE const btScalar & w() const
Return the w value.
void IMB_mask_filter_extend(char *mask, int width, int height)
MINLINE unsigned char unit_float_to_uchar_clamp(float val)
static int check_pixel_assigned(const void *buffer, const char *mask, const int index, const int depth, const bool is_float)
void IMB_unpremultiply_alpha(ImBuf *ibuf)
void IMB_mask_clear(ImBuf *ibuf, const char *mask, int val)
void IMB_premultiply_rect_float(float *rect_float, int channels, int w, int h)
static void filtcolum(uchar *point, int y, int skip)
void MEM_delete_void(void *vmemh)
void IMB_premultiply_rect(uint8_t *rect, ImColorMode color_mode, int w, int h)
static int filter_make_index(const int x, const int y, const int w, const int h)
static void filtcolumf(float *point, int y, int skip)
void IMB_filter_extend(ImBuf *ibuf, char *mask, int filter)
void IMB_unpremultiply_rect_float(float *rect_float, int channels, int w, int h)
void IMB_unpremultiply_rect(uint8_t *rect, ImColorMode color_mode, int w, int h)
void IMB_filtery(ImBuf *ibuf)
void IMB_premultiply_alpha(ImBuf *ibuf)
KERNEL_FEATURE_LIGHT_PASSES KERNEL_FEATURE_PATH_GUIDING float
const uint8_t * byte_data() const
uint8_t * byte_data_for_write()
const float * float_data() const
float * float_data_for_write()