29 for (
y--;
y > 0;
y--) {
32 c1 += (c2 << 1) + c3 +
error;
39 *point = (c1 + (c2 << 1) + c2 + error) >> 2;
45 float c1, c2, c3, *point2;
50 for (
y--;
y > 0;
y--) {
59 *point = 0.25f * (c1 + (c2 * 2) + c2);
105 const int channels =
in->channels;
106 const int rowlen =
in->x;
108 if (
in->byte_buffer.data &&
out->byte_buffer.data) {
109 for (
int y = 0;
y <
in->y;
y++) {
111 const char *row2 = (
const char *)
in->byte_buffer.data +
y * channels * rowlen;
112 const char *row1 = (
y == 0) ? row2 : row2 - channels * rowlen;
113 const char *row3 = (
y ==
in->y - 1) ? row2 : row2 + channels * rowlen;
115 char *cp = (
char *)
out->byte_buffer.data +
y * channels * rowlen;
117 for (
int x = 0;
x < rowlen;
x++) {
118 const char *r11, *r13, *r21, *r23, *r31, *r33;
126 r11 = row1 - channels;
127 r21 = row2 - channels;
128 r31 = row3 - channels;
131 if (
x == rowlen - 1) {
137 r13 = row1 + channels;
138 r23 = row2 + channels;
139 r33 = row3 + channels;
142 cp[0] = (r11[0] + 2 * row1[0] + r13[0] + 2 * r21[0] + 4 * row2[0] + 2 * r23[0] + r31[0] +
143 2 * row3[0] + r33[0]) >>
145 cp[1] = (r11[1] + 2 * row1[1] + r13[1] + 2 * r21[1] + 4 * row2[1] + 2 * r23[1] + r31[1] +
146 2 * row3[1] + r33[1]) >>
148 cp[2] = (r11[2] + 2 * row1[2] + r13[2] + 2 * r21[2] + 4 * row2[2] + 2 * r23[2] + r31[2] +
149 2 * row3[2] + r33[2]) >>
151 cp[3] = (r11[3] + 2 * row1[3] + r13[3] + 2 * r21[3] + 4 * row2[3] + 2 * r23[3] + r31[3] +
152 2 * row3[3] + r33[3]) >>
162 if (
in->float_buffer.data &&
out->float_buffer.data) {
163 for (
int y = 0;
y <
in->y;
y++) {
165 const float *row2 = (
const float *)
in->float_buffer.data +
y * channels * rowlen;
166 const float *row1 = (
y == 0) ? row2 : row2 - channels * rowlen;
167 const float *row3 = (
y ==
in->y - 1) ? row2 : row2 + channels * rowlen;
169 float *cp =
out->float_buffer.data +
y * channels * rowlen;
171 for (
int x = 0;
x < rowlen;
x++) {
172 const float *r11, *r13, *r21, *r23, *r31, *r33;
180 r11 = row1 - channels;
181 r21 = row2 - channels;
182 r31 = row3 - channels;
185 if (
x == rowlen - 1) {
191 r13 = row1 + channels;
192 r23 = row2 + channels;
193 r33 = row3 + channels;
196 cp[0] = (r11[0] + 2 * row1[0] + r13[0] + 2 * r21[0] + 4 * row2[0] + 2 * r23[0] + r31[0] +
197 2 * row3[0] + r33[0]) *
199 cp[1] = (r11[1] + 2 * row1[1] + r13[1] + 2 * r21[1] + 4 * row2[1] + 2 * r23[1] + r31[1] +
200 2 * row3[1] + r33[1]) *
202 cp[2] = (r11[2] + 2 * row1[2] + r13[2] + 2 * r21[2] + 4 * row2[2] + 2 * r23[2] + r31[2] +
203 2 * row3[2] + r33[2]) *
205 cp[3] = (r11[3] + 2 * row1[3] + r13[3] + 2 * r21[3] + 4 * row2[3] + 2 * r23[3] + r31[3] +
206 2 * row3[3] + r33[3]) *
219 const char *row1, *row2, *row3;
228 for (
y = 1;
y <= height;
y++) {
230 row1 = (
char *)(temprect + (
y - 2) * rowlen);
231 row2 = row1 + rowlen;
232 row3 = row2 + rowlen;
236 else if (
y == height) {
240 for (
x = 0;
x < rowlen;
x++) {
241 if (
mask[((
y - 1) * rowlen) +
x] == 0) {
242 if (*row1 || *row2 || *row3 || *(row1 + 1) || *(row3 + 1)) {
245 else if ((
x != rowlen - 1) && (*(row1 + 2) || *(row2 + 2) || *(row3 + 2))) {
265 for (
x = 0;
x < ibuf->
x;
x++) {
266 for (
y = 0;
y < ibuf->
y;
y++) {
267 if (
mask[ibuf->
x *
y +
x] == val) {
276 for (
x = 0;
x < ibuf->
x;
x++) {
277 for (
y = 0;
y < ibuf->
y;
y++) {
278 if (
mask[ibuf->
x *
y +
x] == val) {
297 const void *buffer,
const char *
mask,
const int index,
const int depth,
const bool is_float)
302 const int alpha_index = depth * index + (depth - 1);
304 if (
mask !=
nullptr) {
305 res =
mask[index] != 0 ? 1 : 0;
307 else if ((is_float && ((
const float *)buffer)[alpha_index] != 0.0f) ||
308 (!is_float && ((
const uchar *)buffer)[alpha_index] != 0))
319 const int width = ibuf->
x;
320 const int height = ibuf->
y;
323 const size_t bsize = size_t(width) * height * depth * chsize;
330 char *srcmask =
mask;
331 int cannot_early_out = 1, r, n, k,
i, j, c;
339 for (
i = -n;
i <= n;
i++) {
340 for (j = -n; j <= n; j++) {
341 weight[k++] =
sqrt(
float(
i) *
i + j * j);
357 for (r = 0; cannot_early_out == 1 && r <
filter; r++) {
359 cannot_early_out = 0;
361 for (
y = 0;
y < height;
y++) {
362 for (
x = 0;
x < width;
x++) {
369 float acc[4] = {0, 0, 0, 0};
381 for (
i = -n;
i <= n;
i++) {
382 for (j = -n; j <= n; j++) {
383 if (
i != 0 || j != 0) {
388 for (c = 0; c < depth; c++) {
389 tmp[c] = ((
const float *)srcbuf)[depth * tmpindex + c];
393 for (c = 0; c < depth; c++) {
394 tmp[c] = float(((
const uchar *)srcbuf)[depth * tmpindex + c]);
400 for (c = 0; c < depth; c++) {
401 acc[c] += weight[k] * tmp[c];
410 for (c = 0; c < depth; c++) {
415 for (c = 0; c < depth; c++) {
416 ((
float *)dstbuf)[depth * index + c] = acc[c];
420 for (c = 0; c < depth; c++) {
421 ((
uchar *)dstbuf)[depth * index + c] = acc[c] > 255 ?
424 uchar(roundf(acc[c])));
428 if (dstmask !=
nullptr) {
431 cannot_early_out = 1;
439 memcpy(srcbuf, dstbuf, bsize);
440 if (dstmask !=
nullptr) {
441 memcpy(srcmask, dstmask,
size_t(width) * height);
447 if (dstmask !=
nullptr) {
461 if (ibuf->
mipmap[curmap]) {
474 ibuf->
miptot = curmap + 2;
475 hbuf = ibuf->
mipmap[curmap];
480 if (!hbuf || (hbuf->
x <= 2 && hbuf->
y <= 2)) {
513 ibuf->
miptot = curmap + 2;
514 hbuf = ibuf->
mipmap[curmap];
517 if (hbuf->
x < 2 && hbuf->
y < 2) {
528 return (level == 0) ? ibuf : ibuf->
mipmap[level - 1];
539 for (
y = 0;
y < h;
y++) {
540 for (
x = 0;
x <
w;
x++, cp += 4) {
548 for (
y = 0;
y < h;
y++) {
549 for (
x = 0;
x <
w;
x++, cp += 4) {
551 cp[0] = (cp[0] * val) >> 8;
552 cp[1] = (cp[1] * val) >> 8;
553 cp[2] = (cp[2] * val) >> 8;
566 for (
y = 0;
y < h;
y++) {
567 for (
x = 0;
x <
w;
x++, cp += 4) {
579 if (ibuf ==
nullptr) {
601 for (
y = 0;
y < h;
y++) {
602 for (
x = 0;
x <
w;
x++, cp += 4) {
610 for (
y = 0;
y < h;
y++) {
611 for (
x = 0;
x <
w;
x++, cp += 4) {
612 val = cp[3] != 0 ? 1.0f / float(cp[3]) : 1.0f;
628 for (
y = 0;
y < h;
y++) {
629 for (
x = 0;
x <
w;
x++, fp += 4) {
630 val = fp[3] != 0.0f ? 1.0f / fp[3] : 1.0f;
641 if (ibuf ==
nullptr) {
Function declarations for filter.cc.
void imb_onehalf_no_alloc(ImBuf *ibuf2, ImBuf *ibuf1)
ImBuf * IMB_onehalf(ImBuf *ibuf1)
#define FILTER_MASK_MARGIN
void IMB_freeImBuf(ImBuf *ibuf)
ImBuf * IMB_allocImBuf(unsigned int x, unsigned int y, unsigned char planes, unsigned int flags)
void IMB_free_mipmaps(ImBuf *ibuf)
#define IMB_MIPMAP_LEVELS
Read Guarded memory(de)allocation.
SIMD_FORCE_INLINE const btScalar & w() const
Return the w value.
void IMB_premultiply_alpha(ImBuf *ibuf)
void IMB_unpremultiply_rect_float(float *rect_float, int channels, int w, int h)
void IMB_premultiply_rect_float(float *rect_float, int channels, int w, int h)
void IMB_mask_filter_extend(char *mask, int width, int height)
void IMB_makemipmap(ImBuf *ibuf, int use_filter)
static void imb_filterN(ImBuf *out, ImBuf *in)
void IMB_remakemipmap(ImBuf *ibuf, int use_filter)
void IMB_unpremultiply_alpha(ImBuf *ibuf)
static void filtcolumf(float *point, int y, int skip)
void IMB_mask_clear(ImBuf *ibuf, const char *mask, int val)
static void filtcolum(uchar *point, int y, int skip)
void IMB_filtery(ImBuf *ibuf)
void IMB_unpremultiply_rect(uint8_t *rect, char planes, int w, int h)
void IMB_premultiply_rect(uint8_t *rect, char planes, int w, int h)
void IMB_filter_extend(ImBuf *ibuf, char *mask, int filter)
ImBuf * IMB_getmipmap(ImBuf *ibuf, int level)
static int filter_make_index(const int x, const int y, const int w, const int h)
static int check_pixel_assigned(const void *buffer, const char *mask, const int index, const int depth, const bool is_float)
void * MEM_dupallocN(const void *vmemh)
void MEM_freeN(void *vmemh)
MINLINE unsigned char unit_float_to_uchar_clamp(float val)
ccl_device_inline float2 mask(const MaskType mask, const float2 a)
static void error(const char *str)
ImBufFloatBuffer float_buffer
ImBufByteBuffer byte_buffer
ImBuf * mipmap[IMB_MIPMAP_LEVELS]