38 static void filtrow(
unsigned char *point,
int x)
40 unsigned int c1, c2, c3,
error;
45 for (
x--;
x > 0;
x--) {
47 c1 += (c2 << 1) + c3 +
error;
54 *point = (c1 + (c2 << 1) + c2 + error) >> 2;
64 for (
x--;
x > 0;
x--) {
72 *point = 0.25f * (c1 + (c2 * 2) + c2);
76 static void filtcolum(
unsigned char *point,
int y,
int skip)
78 unsigned int c1, c2, c3,
error;
79 unsigned char *point2;
85 for (
y--;
y > 0;
y--) {
88 c1 += (c2 << 1) + c3 +
error;
95 *point = (c1 + (c2 << 1) + c2 + error) >> 2;
101 float c1, c2, c3, *point2;
106 for (
y--;
y > 0;
y--) {
115 *point = 0.25f * (c1 + (c2 * 2) + c2);
121 unsigned char *point;
125 point = (
unsigned char *)ibuf->
rect;
162 unsigned char *point;
166 point = (
unsigned char *)ibuf->
rect;
207 const int rowlen = in->
x;
210 for (
int y = 0;
y < in->
y;
y++) {
212 const char *row2 = (
const char *)in->
rect +
y * channels * rowlen;
213 const char *row1 = (
y == 0) ? row2 : row2 - channels * rowlen;
214 const char *row3 = (
y == in->
y - 1) ? row2 : row2 + channels * rowlen;
216 char *cp = (
char *)out->
rect +
y * channels * rowlen;
218 for (
int x = 0;
x < rowlen;
x++) {
219 const char *r11, *r13, *r21, *r23, *r31, *r33;
227 r11 = row1 - channels;
228 r21 = row2 - channels;
229 r31 = row3 - channels;
232 if (
x == rowlen - 1) {
238 r13 = row1 + channels;
239 r23 = row2 + channels;
240 r33 = row3 + channels;
243 cp[0] = (r11[0] + 2 * row1[0] + r13[0] + 2 * r21[0] + 4 * row2[0] + 2 * r23[0] + r31[0] +
244 2 * row3[0] + r33[0]) >>
246 cp[1] = (r11[1] + 2 * row1[1] + r13[1] + 2 * r21[1] + 4 * row2[1] + 2 * r23[1] + r31[1] +
247 2 * row3[1] + r33[1]) >>
249 cp[2] = (r11[2] + 2 * row1[2] + r13[2] + 2 * r21[2] + 4 * row2[2] + 2 * r23[2] + r31[2] +
250 2 * row3[2] + r33[2]) >>
252 cp[3] = (r11[3] + 2 * row1[3] + r13[3] + 2 * r21[3] + 4 * row2[3] + 2 * r23[3] + r31[3] +
253 2 * row3[3] + r33[3]) >>
264 for (
int y = 0;
y < in->
y;
y++) {
266 const float *row2 = (
const float *)in->
rect_float +
y * channels * rowlen;
267 const float *row1 = (
y == 0) ? row2 : row2 - channels * rowlen;
268 const float *row3 = (
y == in->
y - 1) ? row2 : row2 + channels * rowlen;
270 float *cp = (
float *)out->
rect_float +
y * channels * rowlen;
272 for (
int x = 0;
x < rowlen;
x++) {
273 const float *r11, *r13, *r21, *r23, *r31, *r33;
281 r11 = row1 - channels;
282 r21 = row2 - channels;
283 r31 = row3 - channels;
286 if (
x == rowlen - 1) {
292 r13 = row1 + channels;
293 r23 = row2 + channels;
294 r33 = row3 + channels;
297 cp[0] = (r11[0] + 2 * row1[0] + r13[0] + 2 * r21[0] + 4 * row2[0] + 2 * r23[0] + r31[0] +
298 2 * row3[0] + r33[0]) *
300 cp[1] = (r11[1] + 2 * row1[1] + r13[1] + 2 * r21[1] + 4 * row2[1] + 2 * r23[1] + r31[1] +
301 2 * row3[1] + r33[1]) *
303 cp[2] = (r11[2] + 2 * row1[2] + r13[2] + 2 * r21[2] + 4 * row2[2] + 2 * r23[2] + r31[2] +
304 2 * row3[2] + r33[2]) *
306 cp[3] = (r11[3] + 2 * row1[3] + r13[3] + 2 * r21[3] + 4 * row2[3] + 2 * r23[3] + r31[3] +
307 2 * row3[3] + r33[3]) *
326 const char *row1, *row2, *row3;
337 row1 = (
char *)(temprect + (
y - 2) * rowlen);
338 row2 = row1 + rowlen;
339 row3 = row2 + rowlen;
347 for (
x = 0;
x < rowlen;
x++) {
348 if (
mask[((
y - 1) * rowlen) +
x] == 0) {
349 if (*row1 || *row2 || *row3 || *(row1 + 1) || *(row3 + 1)) {
352 else if ((
x != rowlen - 1) && (*(row1 + 2) || *(row2 + 2) || *(row3 + 2))) {
372 for (
x = 0;
x < ibuf->
x;
x++) {
373 for (
y = 0;
y < ibuf->
y;
y++) {
374 if (
mask[ibuf->
x *
y +
x] == val) {
383 for (
x = 0;
x < ibuf->
x;
x++) {
384 for (
y = 0;
y < ibuf->
y;
y++) {
385 if (
mask[ibuf->
x *
y +
x] == val) {
386 char *
col = (
char *)(ibuf->
rect + ibuf->
x *
y +
x);
396 if (x < 0 || x >=
w || y < 0 || y >= h) {
404 const void *
buffer,
const char *
mask,
const int index,
const int depth,
const bool is_float)
409 const int alpha_index = depth * index + (depth - 1);
412 res =
mask[index] != 0 ? 1 : 0;
414 else if ((is_float && ((
const float *)
buffer)[alpha_index] != 0.0f) ||
415 (!is_float && ((
const unsigned char *)
buffer)[alpha_index] != 0)) {
431 const int width = ibuf->
x;
434 const int chsize = ibuf->
rect_float ?
sizeof(
float) :
sizeof(
unsigned char);
435 const size_t bsize = ((size_t)
width) *
height * depth * chsize;
441 char *srcmask =
mask;
442 int cannot_early_out = 1,
r, n, k, i, j,
c;
450 for (i = -n; i <= n; i++) {
451 for (j = -n; j <= n; j++) {
452 weight[k++] =
sqrt((
float)i * i + j * j);
468 for (
r = 0; cannot_early_out == 1 &&
r <
filter;
r++) {
470 cannot_early_out = 0;
480 float acc[4] = {0, 0, 0, 0};
491 for (i = -n; i <= n; i++) {
492 for (j = -n; j <= n; j++) {
493 if (i != 0 || j != 0) {
498 for (
c = 0;
c < depth;
c++) {
499 tmp[
c] = ((
const float *)srcbuf)[depth * tmpindex +
c];
503 for (
c = 0;
c < depth;
c++) {
504 tmp[
c] = (
float)((
const unsigned char *)srcbuf)[depth * tmpindex +
c];
510 for (
c = 0;
c < depth;
c++) {
511 acc[
c] += weight[k] * tmp[
c];
520 for (
c = 0;
c < depth;
c++) {
525 for (
c = 0;
c < depth;
c++) {
526 ((
float *)dstbuf)[depth * index +
c] = acc[
c];
530 for (
c = 0;
c < depth;
c++) {
531 ((
unsigned char *)dstbuf)[depth * index +
c] =
532 acc[
c] > 255 ? 255 : (acc[
c] < 0 ? 0 : (
unsigned char)roundf(acc[
c]));
536 if (dstmask !=
NULL) {
539 cannot_early_out = 1;
547 memcpy(srcbuf, dstbuf, bsize);
548 if (dstmask !=
NULL) {
549 memcpy(srcmask, dstmask, ((
size_t)
width) *
height);
555 if (dstmask !=
NULL) {
570 if (ibuf->
mipmap[curmap]) {
583 ibuf->
miptot = curmap + 2;
584 hbuf = ibuf->
mipmap[curmap];
589 if (!hbuf || (hbuf->
x <= 2 && hbuf->
y <= 2)) {
623 ibuf->
miptot = curmap + 2;
624 hbuf = ibuf->
mipmap[curmap];
627 if (hbuf->
x < 2 && hbuf->
y < 2) {
638 return (level == 0) ? ibuf : ibuf->
mipmap[level - 1];
649 for (
y = 0;
y < h;
y++) {
650 for (
x = 0;
x <
w;
x++, cp += 4) {
658 for (
y = 0;
y < h;
y++) {
659 for (
x = 0;
x <
w;
x++, cp += 4) {
661 cp[0] = (cp[0] * val) >> 8;
662 cp[1] = (cp[1] * val) >> 8;
663 cp[2] = (cp[2] * val) >> 8;
676 for (
y = 0;
y < h;
y++) {
677 for (
x = 0;
x <
w;
x++, cp += 4) {
711 for (
y = 0;
y < h;
y++) {
712 for (
x = 0;
x <
w;
x++, cp += 4) {
720 for (
y = 0;
y < h;
y++) {
721 for (
x = 0;
x <
w;
x++, cp += 4) {
722 val = cp[3] != 0 ? 1.0f / (
float)cp[3] : 1.0f;
738 for (
y = 0;
y < h;
y++) {
739 for (
x = 0;
x <
w;
x++, fp += 4) {
740 val = fp[3] != 0.0f ? 1.0f / fp[3] : 1.0f;
typedef float(TangentPoint)[2]
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum const void *lists _GL_VOID_RET _GL_VOID const GLdouble *equation _GL_VOID_RET _GL_VOID GLdouble GLdouble blue _GL_VOID_RET _GL_VOID GLfloat GLfloat blue _GL_VOID_RET _GL_VOID GLint GLint blue _GL_VOID_RET _GL_VOID GLshort GLshort blue _GL_VOID_RET _GL_VOID GLubyte GLubyte blue _GL_VOID_RET _GL_VOID GLuint GLuint blue _GL_VOID_RET _GL_VOID GLushort GLushort blue _GL_VOID_RET _GL_VOID GLbyte GLbyte GLbyte alpha _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble alpha _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat alpha _GL_VOID_RET _GL_VOID GLint GLint GLint alpha _GL_VOID_RET _GL_VOID GLshort GLshort GLshort alpha _GL_VOID_RET _GL_VOID GLubyte GLubyte GLubyte alpha _GL_VOID_RET _GL_VOID GLuint GLuint GLuint alpha _GL_VOID_RET _GL_VOID GLushort GLushort GLushort alpha _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLint GLsizei GLsizei GLenum type _GL_VOID_RET _GL_VOID GLsizei GLenum GLenum const void *pixels _GL_VOID_RET _GL_VOID const void *pointer _GL_VOID_RET _GL_VOID GLdouble v _GL_VOID_RET _GL_VOID GLfloat v _GL_VOID_RET _GL_VOID GLint GLint i2 _GL_VOID_RET _GL_VOID GLint j _GL_VOID_RET _GL_VOID GLfloat param _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble GLdouble GLdouble zFar _GL_VOID_RET _GL_UINT GLdouble *equation _GL_VOID_RET _GL_VOID GLenum GLint *params _GL_VOID_RET _GL_VOID GLenum GLfloat *v _GL_VOID_RET _GL_VOID GLenum GLfloat *params _GL_VOID_RET _GL_VOID GLfloat *values _GL_VOID_RET _GL_VOID GLushort *values _GL_VOID_RET _GL_VOID GLenum GLfloat *params _GL_VOID_RET _GL_VOID GLenum GLdouble *params _GL_VOID_RET _GL_VOID GLenum GLint *params _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_BOOL GLfloat param _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID GLenum GLfloat param _GL_VOID_RET _GL_VOID GLenum GLint param _GL_VOID_RET _GL_VOID GLushort pattern _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLint const GLdouble *points _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLint GLdouble GLdouble GLint GLint const GLdouble *points _GL_VOID_RET _GL_VOID GLdouble GLdouble u2 _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLdouble GLdouble v2 _GL_VOID_RET _GL_VOID GLenum GLfloat param _GL_VOID_RET _GL_VOID GLenum GLint param _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLdouble GLdouble nz _GL_VOID_RET _GL_VOID GLfloat GLfloat nz _GL_VOID_RET _GL_VOID GLint GLint nz _GL_VOID_RET _GL_VOID GLshort GLshort nz _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_VOID GLsizei const GLfloat *values _GL_VOID_RET _GL_VOID GLsizei const GLushort *values _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID const GLuint const GLclampf *priorities _GL_VOID_RET _GL_VOID GLdouble y _GL_VOID_RET _GL_VOID GLfloat y _GL_VOID_RET _GL_VOID GLint y _GL_VOID_RET _GL_VOID GLshort y _GL_VOID_RET _GL_VOID GLdouble GLdouble z _GL_VOID_RET _GL_VOID GLfloat GLfloat z _GL_VOID_RET _GL_VOID GLint GLint z _GL_VOID_RET _GL_VOID GLshort GLshort z _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble w _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat w _GL_VOID_RET _GL_VOID GLint GLint GLint w _GL_VOID_RET _GL_VOID GLshort GLshort GLshort w _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble y2 _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat y2 _GL_VOID_RET _GL_VOID GLint GLint GLint y2 _GL_VOID_RET _GL_VOID GLshort GLshort GLshort y2 _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble z _GL_VOID_RET _GL_VOID GLdouble GLdouble z _GL_VOID_RET _GL_VOID GLuint *buffer _GL_VOID_RET _GL_VOID GLdouble t _GL_VOID_RET _GL_VOID GLfloat t _GL_VOID_RET _GL_VOID GLint t _GL_VOID_RET _GL_VOID GLshort t _GL_VOID_RET _GL_VOID GLdouble GLdouble r _GL_VOID_RET _GL_VOID GLfloat GLfloat r _GL_VOID_RET _GL_VOID GLint GLint r _GL_VOID_RET _GL_VOID GLshort GLshort r _GL_VOID_RET _GL_VOID GLdouble GLdouble r
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum const void *lists _GL_VOID_RET _GL_VOID const GLdouble *equation _GL_VOID_RET _GL_VOID GLdouble GLdouble blue _GL_VOID_RET _GL_VOID GLfloat GLfloat blue _GL_VOID_RET _GL_VOID GLint GLint blue _GL_VOID_RET _GL_VOID GLshort GLshort blue _GL_VOID_RET _GL_VOID GLubyte GLubyte blue _GL_VOID_RET _GL_VOID GLuint GLuint blue _GL_VOID_RET _GL_VOID GLushort GLushort blue _GL_VOID_RET _GL_VOID GLbyte GLbyte GLbyte alpha _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble alpha _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat alpha _GL_VOID_RET _GL_VOID GLint GLint GLint alpha _GL_VOID_RET _GL_VOID GLshort GLshort GLshort alpha _GL_VOID_RET _GL_VOID GLubyte GLubyte GLubyte alpha _GL_VOID_RET _GL_VOID GLuint GLuint GLuint alpha _GL_VOID_RET _GL_VOID GLushort GLushort GLushort alpha _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLint GLsizei width
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei height
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum const void *lists _GL_VOID_RET _GL_VOID const GLdouble *equation _GL_VOID_RET _GL_VOID GLdouble GLdouble blue _GL_VOID_RET _GL_VOID GLfloat GLfloat blue _GL_VOID_RET _GL_VOID GLint GLint blue _GL_VOID_RET _GL_VOID GLshort GLshort blue _GL_VOID_RET _GL_VOID GLubyte GLubyte blue _GL_VOID_RET _GL_VOID GLuint GLuint blue _GL_VOID_RET _GL_VOID GLushort GLushort blue _GL_VOID_RET _GL_VOID GLbyte GLbyte GLbyte alpha _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble alpha _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat alpha _GL_VOID_RET _GL_VOID GLint GLint GLint alpha _GL_VOID_RET _GL_VOID GLshort GLshort GLshort alpha _GL_VOID_RET _GL_VOID GLubyte GLubyte GLubyte alpha _GL_VOID_RET _GL_VOID GLuint GLuint GLuint alpha _GL_VOID_RET _GL_VOID GLushort GLushort GLushort alpha _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLint y
Function declarations for filter.c.
void imb_onehalf_no_alloc(struct ImBuf *ibuf2, struct ImBuf *ibuf1)
struct ImBuf * IMB_onehalf(struct ImBuf *ibuf1)
struct ImBuf * IMB_allocImBuf(unsigned int x, unsigned int y, unsigned char planes, unsigned int flags)
void IMB_freeImBuf(struct ImBuf *ibuf)
void imb_freemipmapImBuf(struct 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 RGB to Bright Vector Camera CLAMP
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_filtery(struct ImBuf *ibuf)
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)
static void filtrowf(float *point, int x)
void IMB_mask_clear(ImBuf *ibuf, const char *mask, int val)
static void filtcolum(unsigned char *point, int y, int skip)
ImBuf * IMB_getmipmap(ImBuf *ibuf, int level)
void IMB_filter_extend(struct ImBuf *ibuf, char *mask, int filter)
void IMB_premultiply_rect(unsigned int *rect, char planes, int w, int h)
void imb_filterx(struct ImBuf *ibuf)
void IMB_unpremultiply_rect(unsigned int *rect, char planes, int w, int h)
void IMB_filter(struct ImBuf *ibuf)
static void filtrow(unsigned char *point, int x)
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)
DO_INLINE void filter(lfVector *V, fmatrix3x3 *S)
__kernel void ccl_constant KernelData ccl_global void ccl_global char ccl_global int ccl_global char ccl_global unsigned int ccl_global float * buffer
void(* MEM_freeN)(void *vmemh)
void *(* MEM_dupallocN)(const void *vmemh)
MINLINE unsigned char unit_float_to_uchar_clamp(float val)
static void error(const char *str)
struct ImBuf * mipmap[IMB_MIPMAP_LEVELS]
ccl_device_inline float4 mask(const int4 &mask, const float4 &a)