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);
105 BLI_assert(out->x == in->x && out->y == in->y);
107 const int channels = in->channels;
108 const int rowlen = in->x;
110 if (in->byte_buffer.data && out->byte_buffer.data) {
111 for (
int y = 0; y < in->y; y++) {
113 const char *row2 = (
const char *)in->byte_buffer.data + y * channels * rowlen;
114 const char *row1 = (y == 0) ? row2 : row2 - channels * rowlen;
115 const char *row3 = (y == in->y - 1) ? row2 : row2 + channels * rowlen;
117 char *cp = (
char *)out->byte_buffer.data + y * channels * rowlen;
119 for (
int x = 0; x < rowlen; x++) {
120 const char *r11, *r13, *r21, *r23, *r31, *r33;
133 if (x == rowlen - 1) {
144 cp[0] = (r11[0] + 2 * row1[0] + r13[0] + 2 * r21[0] + 4 * row2[0] + 2 * r23[0] + r31[0] +
145 2 * row3[0] + r33[0]) >>
147 cp[1] = (r11[1] + 2 * row1[1] + r13[1] + 2 * r21[1] + 4 * row2[1] + 2 * r23[1] + r31[1] +
148 2 * row3[1] + r33[1]) >>
150 cp[2] = (r11[2] + 2 * row1[2] + r13[2] + 2 * r21[2] + 4 * row2[2] + 2 * r23[2] + r31[2] +
151 2 * row3[2] + r33[2]) >>
153 cp[3] = (r11[3] + 2 * row1[3] + r13[3] + 2 * r21[3] + 4 * row2[3] + 2 * r23[3] + r31[3] +
154 2 * row3[3] + r33[3]) >>
164 if (in->float_buffer.data && out->float_buffer.data) {
165 for (
int y = 0; y < in->y; y++) {
167 const float *row2 = (
const float *)in->float_buffer.data + y * channels * rowlen;
168 const float *row1 = (y == 0) ? row2 : row2 - channels * rowlen;
169 const float *row3 = (y == in->y - 1) ? row2 : row2 + channels * rowlen;
171 float *cp = (
float *)out->float_buffer.data + y * channels * rowlen;
173 for (
int x = 0; x < rowlen; x++) {
174 const float *r11, *r13, *r21, *r23, *r31, *r33;
187 if (x == rowlen - 1) {
198 cp[0] = (r11[0] + 2 * row1[0] + r13[0] + 2 * r21[0] + 4 * row2[0] + 2 * r23[0] + r31[0] +
199 2 * row3[0] + r33[0]) *
201 cp[1] = (r11[1] + 2 * row1[1] + r13[1] + 2 * r21[1] + 4 * row2[1] + 2 * r23[1] + r31[1] +
202 2 * row3[1] + r33[1]) *
204 cp[2] = (r11[2] + 2 * row1[2] + r13[2] + 2 * r21[2] + 4 * row2[2] + 2 * r23[2] + r31[2] +
205 2 * row3[2] + r33[2]) *
207 cp[3] = (r11[3] + 2 * row1[3] + r13[3] + 2 * r21[3] + 4 * row2[3] + 2 * r23[3] + r31[3] +
208 2 * row3[3] + r33[3]) *
221 const char *row1, *row2, *row3;
230 for (y = 1; y <= height; y++) {
232 row1 = (
char *)(temprect + (y - 2) * rowlen);
233 row2 = row1 + rowlen;
234 row3 = row2 + rowlen;
238 else if (y == height) {
242 for (x = 0; x < rowlen; x++) {
243 if (mask[((y - 1) * rowlen) + x] == 0) {
244 if (*row1 || *row2 || *row3 || *(row1 + 1) || *(row3 + 1)) {
247 else if ((x != rowlen - 1) && (*(row1 + 2) || *(row2 + 2) || *(row3 + 2))) {
267 for (x = 0; x < ibuf->
x; x++) {
268 for (y = 0; y < ibuf->
y; y++) {
269 if (mask[ibuf->
x * y + x] == val) {
278 for (x = 0; x < ibuf->
x; x++) {
279 for (y = 0; y < ibuf->
y; y++) {
280 if (mask[ibuf->
x * y + x] == val) {
299 const void *buffer,
const char *mask,
const int index,
const int depth,
const bool is_float)
304 const int alpha_index = depth * index + (depth - 1);
306 if (mask !=
nullptr) {
307 res = mask[index] != 0 ? 1 : 0;
309 else if ((is_float && ((
const float *)buffer)[alpha_index] != 0.0f) ||
310 (!is_float && ((
const uchar *)buffer)[alpha_index] != 0))
321 const int width = ibuf->
x;
322 const int height = ibuf->
y;
325 const size_t bsize = size_t(width) * height * depth * chsize;
329 char *dstmask = mask ==
nullptr ? nullptr : (
char *)
MEM_dupallocN(mask);
332 char *srcmask =
mask;
333 int cannot_early_out = 1, r, n, k, i, j, c;
341 for (i = -n; i <= n; i++) {
342 for (j = -n; j <= n; j++) {
343 weight[k++] =
sqrt(
float(i) * i + j * j);
359 for (r = 0; cannot_early_out == 1 && r <
filter; r++) {
361 cannot_early_out = 0;
363 for (y = 0; y < height; y++) {
364 for (x = 0; x < width; x++) {
371 float acc[4] = {0, 0, 0, 0};
383 for (i = -n; i <= n; i++) {
384 for (j = -n; j <= n; j++) {
385 if (i != 0 || j != 0) {
390 for (c = 0; c < depth; c++) {
391 tmp[c] = ((
const float *)srcbuf)[depth * tmpindex + c];
395 for (c = 0; c < depth; c++) {
396 tmp[c] =
float(((
const uchar *)srcbuf)[depth * tmpindex + c]);
402 for (c = 0; c < depth; c++) {
403 acc[c] += weight[k] * tmp[c];
412 for (c = 0; c < depth; c++) {
417 for (c = 0; c < depth; c++) {
418 ((
float *)dstbuf)[depth * index + c] = acc[c];
422 for (c = 0; c < depth; c++) {
423 ((
uchar *)dstbuf)[depth * index + c] = acc[c] > 255 ?
426 uchar(roundf(acc[c])));
430 if (dstmask !=
nullptr) {
433 cannot_early_out = 1;
441 memcpy(srcbuf, dstbuf, bsize);
442 if (dstmask !=
nullptr) {
443 memcpy(srcmask, dstmask,
size_t(width) * height);
449 if (dstmask !=
nullptr) {
463 if (ibuf->
mipmap[curmap]) {
476 ibuf->
miptot = curmap + 2;
477 hbuf = ibuf->
mipmap[curmap];
482 if (!hbuf || (hbuf->
x <= 2 && hbuf->
y <= 2)) {
515 ibuf->
miptot = curmap + 2;
516 hbuf = ibuf->
mipmap[curmap];
519 if (hbuf->
x < 2 && hbuf->
y < 2) {
530 return (level == 0) ? ibuf : ibuf->
mipmap[level - 1];
541 for (y = 0; y < h; y++) {
542 for (x = 0; x <
w; x++, cp += 4) {
550 for (y = 0; y < h; y++) {
551 for (x = 0; x <
w; x++, cp += 4) {
553 cp[0] = (cp[0] * val) >> 8;
554 cp[1] = (cp[1] * val) >> 8;
555 cp[2] = (cp[2] * val) >> 8;
568 for (y = 0; y < h; y++) {
569 for (x = 0; x <
w; x++, cp += 4) {
581 if (ibuf ==
nullptr) {
603 for (y = 0; y < h; y++) {
604 for (x = 0; x <
w; x++, cp += 4) {
612 for (y = 0; y < h; y++) {
613 for (x = 0; x <
w; x++, cp += 4) {
614 val = cp[3] != 0 ? 1.0f /
float(cp[3]) : 1.0f;
630 for (y = 0; y < h; y++) {
631 for (x = 0; x <
w; x++, fp += 4) {
632 val = fp[3] != 0.0f ? 1.0f / fp[3] : 1.0f;
643 if (ibuf ==
nullptr) {
Function declarations for filter.cc.
void imb_onehalf_no_alloc(ImBuf *ibuf2, ImBuf *ibuf1)
ImBuf * IMB_onehalf(ImBuf *ibuf1)
void imb_freemipmapImBuf(ImBuf *ibuf)
#define FILTER_MASK_MARGIN
Contains defines and structs used throughout the imbuf module.
#define IMB_MIPMAP_LEVELS
Read Guarded memory(de)allocation.
Group Output data from inside of a node group A color picker Mix two input colors RGB to Convert a color s luminance to a grayscale value Generate a normal vector and a dot product Brightness Control the brightness and contrast of the input color Vector Map input vector components with curves Camera Retrieve information about the camera and how it relates to the current shading point s position Clamp a value between a minimum and a maximum Vector Perform vector math operation Invert Invert a producing a negative Combine Generate a color from its and blue channels(Deprecated)") DefNode(ShaderNode
in reality light always falls off quadratically Particle Retrieve the data of the particle that spawned the object for example to give variation to multiple instances of an object Point Retrieve information about points in a point cloud Retrieve the edges of an object as it appears to Cycles topology will always appear triangulated Convert a blackbody temperature to an RGB value Normal Generate a perturbed normal from an RGB normal map image Typically used for faking highly detailed surfaces Generate an OSL shader from a file or text data block Image Sample an image file as a texture Gabor Generate Gabor noise Gradient Generate interpolated color and intensity values based on the input vector Magic Generate a psychedelic color texture Voronoi Generate Worley noise based on the distance to random points Typically used to generate textures such as or biological cells Brick Generate a procedural texture producing bricks Texture Retrieve multiple types of texture coordinates nTypically used as inputs for texture nodes Vector Convert a point
SIMD_FORCE_INLINE const btScalar & w() const
Return the w value.
draw_view in_light_buf[] float
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)
struct ImBuf * IMB_allocImBuf(unsigned int, unsigned int, unsigned char, unsigned int)
void IMB_freeImBuf(ImBuf *)
DO_INLINE void filter(lfVector *V, fmatrix3x3 *S)
void MEM_freeN(void *vmemh)
void *(* MEM_dupallocN)(const void *vmemh)
#define unit_float_to_uchar_clamp(val)
ccl_device_inline float4 mask(const int4 mask, const float4 a)
static void error(const char *str)
ImBufFloatBuffer float_buffer
ImBufByteBuffer byte_buffer
ImBuf * mipmap[IMB_MIPMAP_LEVELS]