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);
102 const char *row1, *row2, *row3;
111 for (
y = 1;
y <= height;
y++) {
113 row1 = (
char *)(temprect + (
y - 2) * rowlen);
114 row2 = row1 + rowlen;
115 row3 = row2 + rowlen;
119 else if (
y == height) {
123 for (
x = 0;
x < rowlen;
x++) {
124 if (
mask[((
y - 1) * rowlen) +
x] == 0) {
125 if (*row1 || *row2 || *row3 || *(row1 + 1) || *(row3 + 1)) {
128 else if ((
x != rowlen - 1) && (*(row1 + 2) || *(row2 + 2) || *(row3 + 2))) {
148 for (
x = 0;
x < ibuf->
x;
x++) {
149 for (
y = 0;
y < ibuf->
y;
y++) {
150 if (
mask[ibuf->
x *
y +
x] == val) {
159 for (
x = 0;
x < ibuf->
x;
x++) {
160 for (
y = 0;
y < ibuf->
y;
y++) {
161 if (
mask[ibuf->
x *
y +
x] == val) {
180 const void *buffer,
const char *
mask,
const int index,
const int depth,
const bool is_float)
185 const int alpha_index = depth * index + (depth - 1);
187 if (
mask !=
nullptr) {
188 res =
mask[index] != 0 ? 1 : 0;
190 else if ((is_float && ((
const float *)buffer)[alpha_index] != 0.0f) ||
191 (!is_float && ((
const uchar *)buffer)[alpha_index] != 0))
202 const int width = ibuf->
x;
203 const int height = ibuf->
y;
206 const size_t bsize = size_t(width) * height * depth * chsize;
213 char *srcmask =
mask;
214 int cannot_early_out = 1, r, n, k,
i, j, c;
222 for (
i = -n;
i <= n;
i++) {
223 for (j = -n; j <= n; j++) {
224 weight[k++] =
sqrt(
float(
i) *
i + j * j);
240 for (r = 0; cannot_early_out == 1 && r <
filter; r++) {
242 cannot_early_out = 0;
244 for (
y = 0;
y < height;
y++) {
245 for (
x = 0;
x < width;
x++) {
252 float acc[4] = {0, 0, 0, 0};
264 for (
i = -n;
i <= n;
i++) {
265 for (j = -n; j <= n; j++) {
266 if (
i != 0 || j != 0) {
271 for (c = 0; c < depth; c++) {
272 tmp[c] = ((
const float *)srcbuf)[depth * tmpindex + c];
276 for (c = 0; c < depth; c++) {
277 tmp[c] =
float(((
const uchar *)srcbuf)[depth * tmpindex + c]);
283 for (c = 0; c < depth; c++) {
284 acc[c] += weight[k] * tmp[c];
293 for (c = 0; c < depth; c++) {
298 for (c = 0; c < depth; c++) {
299 ((
float *)dstbuf)[depth * index + c] = acc[c];
303 for (c = 0; c < depth; c++) {
304 ((
uchar *)dstbuf)[depth * index + c] = acc[c] > 255 ?
311 if (dstmask !=
nullptr) {
314 cannot_early_out = 1;
322 memcpy(srcbuf, dstbuf, bsize);
323 if (dstmask !=
nullptr) {
324 memcpy(srcmask, dstmask,
size_t(width) * height);
330 if (dstmask !=
nullptr) {
343 for (
y = 0;
y < h;
y++) {
344 for (
x = 0;
x <
w;
x++, cp += 4) {
352 for (
y = 0;
y < h;
y++) {
353 for (
x = 0;
x <
w;
x++, cp += 4) {
355 cp[0] = (cp[0] * val) >> 8;
356 cp[1] = (cp[1] * val) >> 8;
357 cp[2] = (cp[2] * val) >> 8;
370 for (
y = 0;
y < h;
y++) {
371 for (
x = 0;
x <
w;
x++, cp += 4) {
383 if (ibuf ==
nullptr) {
405 for (
y = 0;
y < h;
y++) {
406 for (
x = 0;
x <
w;
x++, cp += 4) {
414 for (
y = 0;
y < h;
y++) {
415 for (
x = 0;
x <
w;
x++, cp += 4) {
416 val = cp[3] != 0 ? 1.0f /
float(cp[3]) : 1.0f;
432 for (
y = 0;
y < h;
y++) {
433 for (
x = 0;
x <
w;
x++, fp += 4) {
434 val = fp[3] != 0.0f ? 1.0f / fp[3] : 1.0f;
445 if (ibuf ==
nullptr) {
Function declarations for filter.cc.
#define FILTER_MASK_MARGIN
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_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)
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