Dosvidanya, old compositor!

You served well and now desired retirement, but you'll always live in our hearts.

And for sure -- monument!

       +-------------------------------------------+
      /   ++==+   .  ..   .   ...    .  ..     .  /
     /   //    ++==++  ++  ++     ++==++ ++==++  /
    /   //    //  //  //\\//\\   //  // //  //  /
   /   ++==+ ++==++  //      \\ //==++ ++==++  /
  /  .    ...   ..    .       //  ..  ...     /
 +-------------------------------------------+

Some notes:
- Removed all code which was from inside ifdef WITH_COMPOSITOR_LEGACY
- Removed some functions which were used by old compositor only but
  weren't ported to new color management
- Removed WITH_COMPOSITOR_LEGACY from build systems
- node_composite_util.h was in fatc used by compo nodes specification
  files, so added it back to cmake.

  Could be cleaned up by moving header files to files where they're
  actually needed but would consider this is a separate task.

- Should be no functional changes!
This commit is contained in:
Sergey Sharybin
2013-01-14 15:53:17 +00:00
parent 9e612235e2
commit 5781859753
74 changed files with 4 additions and 11241 deletions

View File

@@ -135,7 +135,6 @@ option(WITH_GAMEENGINE "Enable Game Engine" ON)
option(WITH_PLAYER "Build Player" OFF)
option(WITH_OPENCOLORIO "Enable OpenColorIO color management" ON)
option(WITH_COMPOSITOR "Enable the tile based nodal compositor" ON)
option(WITH_COMPOSITOR_LEGACY "Enable legacy compositor" OFF)
# GHOST Windowing Library Options
option(WITH_GHOST_DEBUG "Enable debugging output for the GHOST library" OFF)

View File

@@ -108,7 +108,7 @@ def validate_arguments(args, bc):
'WITH_BF_STATICFFMPEG', 'BF_FFMPEG_LIB_STATIC',
'WITH_BF_OGG', 'BF_OGG', 'BF_OGG_LIB',
'WITH_BF_FRAMESERVER',
'WITH_BF_COMPOSITOR', 'WITH_BF_COMPOSITOR_LEGACY',
'WITH_BF_COMPOSITOR',
'WITH_BF_JPEG', 'BF_JPEG', 'BF_JPEG_INC', 'BF_JPEG_LIB', 'BF_JPEG_LIBPATH', 'WITH_BF_STATICJPEG', 'BF_JPEG_LIB_STATIC',
'WITH_BF_OPENJPEG', 'BF_OPENJPEG', 'BF_OPENJPEG_INC', 'BF_OPENJPEG_LIB', 'BF_OPENJPEG_LIBPATH',
'WITH_BF_REDCODE', 'BF_REDCODE', 'BF_REDCODE_INC', 'BF_REDCODE_LIB', 'BF_REDCODE_LIBPATH',
@@ -599,7 +599,6 @@ def read_opts(env, cfg, args):
('BF_BOOST_LIB_STATIC', 'Boost static library', ''),
(BoolVariable('WITH_GHOST_XDND', 'Build with drag-n-drop support on Linux platforms using XDND protocol', True)),
(BoolVariable('WITH_BF_COMPOSITOR_LEGACY', 'Enable the legacy compositor', False)),
(BoolVariable('WITH_BF_CYCLES_OSL', 'Build with OSL sypport in Cycles', False)),
(BoolVariable('WITH_BF_STATICOSL', 'Staticly link to OSL', False)),

View File

@@ -123,6 +123,7 @@ set(SRC
composite/nodes/node_composite_pixelate.c
composite/node_composite_tree.c
composite/node_composite_util.h
shader/nodes/node_shader_camera.c
shader/nodes/node_shader_common.c
@@ -235,13 +236,6 @@ set(SRC
intern/node_common.h
)
if(WITH_COMPOSITOR_LEGACY)
list(APPEND SRC
composite/node_composite_util.h
composite/node_composite_util.c
)
endif()
if(WITH_PYTHON)
list(APPEND INC
../python
@@ -267,8 +261,4 @@ if(WITH_COMPOSITOR)
add_definitions(-DWITH_COMPOSITOR)
endif()
if(WITH_COMPOSITOR_LEGACY)
add_definitions(-DWITH_COMPOSITOR_LEGACY)
endif()
blender_add_lib(bf_nodes "${SRC}" "${INC}" "${INC_SYS}")

View File

@@ -66,9 +66,6 @@ if env['WITH_BF_COMPOSITOR']:
incs += ' ../compositor '
defs.append("WITH_COMPOSITOR")
if env['WITH_BF_COMPOSITOR_LEGACY']:
defs.append("WITH_COMPOSITOR_LEGACY")
env.BlenderLib ( libname = 'bf_nodes', sources = sources, includes = Split(incs), defines = defs, libtype=['core','player'], priority = [190,105] )
env.BlenderLib ( libname = 'bf_cmpnodes', sources = cmpsources, includes = Split(incs), defines = defs, libtype=['core','player'], priority = [175,101] )
env.BlenderLib ( libname = 'bf_shdnodes', sources = shdsources, includes = Split(incs), defines = defs, libtype=['core','player'], priority = [175,101] )

View File

@@ -95,9 +95,6 @@ static void free_node_cache(bNodeTree *UNUSED(ntree), bNode *node)
for (sock= node->outputs.first; sock; sock= sock->next) {
if (sock->cache) {
#ifdef WITH_COMPOSITOR_LEGACY
free_compbuf(sock->cache);
#endif
sock->cache= NULL;
}
}
@@ -161,9 +158,6 @@ static void localize(bNodeTree *localtree, bNodeTree *ntree)
for (sock= node->outputs.first; sock; sock= sock->next) {
sock->new_sock->cache= sock->cache;
#ifdef WITH_COMPOSITOR_LEGACY
compbuf_set_node(sock->new_sock->cache, node->new_node);
#endif
sock->cache= NULL;
sock->new_sock->new_sock= sock;
}
@@ -239,9 +233,6 @@ static void local_merge(bNodeTree *localtree, bNodeTree *ntree)
for (lsock= lnode->outputs.first; lsock; lsock= lsock->next) {
if (ntreeOutputExists(lnode->new_node, lsock->new_sock)) {
lsock->new_sock->cache= lsock->cache;
#ifdef WITH_COMPOSITOR_LEGACY
compbuf_set_node(lsock->new_sock->cache, lnode->new_node);
#endif
lsock->cache= NULL;
lsock->new_sock= NULL;
}
@@ -363,335 +354,6 @@ void ntreeCompositEndExecTree(bNodeTreeExec *exec, int use_tree_data)
}
}
#ifdef WITH_COMPOSITOR
#ifdef WITH_COMPOSITOR_LEGACY
/* ***************************** threaded version for execute composite nodes ************* */
/* these are nodes without input, only giving values */
/* or nodes with only value inputs */
static int node_only_value(bNode *node)
{
bNodeSocket *sock;
if (ELEM3(node->type, CMP_NODE_TIME, CMP_NODE_VALUE, CMP_NODE_RGB))
return 1;
/* doing this for all node types goes wrong. memory free errors */
if (node->inputs.first && node->type==CMP_NODE_MAP_VALUE) {
int retval= 1;
for (sock= node->inputs.first; sock; sock= sock->next) {
if (sock->link)
retval &= node_only_value(sock->link->fromnode);
}
return retval;
}
return 0;
}
/* not changing info, for thread callback */
typedef struct ThreadData {
bNodeStack *stack;
RenderData *rd;
} ThreadData;
static void *exec_composite_node(void *nodeexec_v)
{
bNodeStack *nsin[MAX_SOCKET]; /* arbitrary... watch this */
bNodeStack *nsout[MAX_SOCKET]; /* arbitrary... watch this */
bNodeExec *nodeexec= nodeexec_v;
bNode *node= nodeexec->node;
ThreadData *thd= (ThreadData *)node->threaddata;
node_get_stack(node, thd->stack, nsin, nsout);
if (node->typeinfo->execfunc)
node->typeinfo->execfunc(thd->rd, node, nsin, nsout);
else if (node->typeinfo->newexecfunc)
node->typeinfo->newexecfunc(thd->rd, 0, node, nodeexec->data, nsin, nsout);
node->exec |= NODE_READY;
return NULL;
}
/* return total of executable nodes, for timecursor */
static int setExecutableNodes(bNodeTreeExec *exec, ThreadData *thd)
{
bNodeTree *ntree = exec->nodetree;
bNodeStack *nsin[MAX_SOCKET]; /* arbitrary... watch this */
bNodeStack *nsout[MAX_SOCKET]; /* arbitrary... watch this */
bNodeExec *nodeexec;
bNode *node;
bNodeSocket *sock;
int n, totnode= 0, group_edit= 0;
/* if we are in group edit, viewer nodes get skipped when group has viewer */
for (node= ntree->nodes.first; node; node= node->next)
if (node->type==NODE_GROUP && (node->flag & NODE_GROUP_EDIT))
if (ntreeHasType((bNodeTree *)node->id, CMP_NODE_VIEWER))
group_edit= 1;
/* NB: using the exec data list here to have valid dependency sort */
for (n=0, nodeexec=exec->nodeexec; n < exec->totnodes; ++n, ++nodeexec) {
int a;
node = nodeexec->node;
node_get_stack(node, exec->stack, nsin, nsout);
/* test the outputs */
/* skip value-only nodes (should be in type!) */
if (!node_only_value(node)) {
for (a=0, sock= node->outputs.first; sock; sock= sock->next, a++) {
if (nsout[a]->data==NULL && nsout[a]->hasoutput) {
node->need_exec= 1;
break;
}
}
}
/* test the inputs */
for (a=0, sock= node->inputs.first; sock; sock= sock->next, a++) {
/* skip viewer nodes in bg render or group edit */
if ( ELEM(node->type, CMP_NODE_VIEWER, CMP_NODE_SPLITVIEWER) && (G.background || group_edit))
node->need_exec= 0;
/* is sock in use? */
else if (sock->link) {
bNodeLink *link= sock->link;
/* this is the test for a cyclic case */
if (link->fromnode==NULL || link->tonode==NULL);
else if (link->fromnode->level >= link->tonode->level && link->tonode->level!=0xFFF) {
if (link->fromnode->need_exec) {
node->need_exec= 1;
break;
}
}
else {
node->need_exec= 0;
printf("Node %s skipped, cyclic dependency\n", node->name);
}
}
}
if (node->need_exec) {
/* free output buffers */
for (a=0, sock= node->outputs.first; sock; sock= sock->next, a++) {
if (nsout[a]->data) {
free_compbuf(nsout[a]->data);
nsout[a]->data= NULL;
}
}
totnode++;
/* printf("node needs exec %s\n", node->name); */
/* tag for getExecutableNode() */
node->exec= 0;
}
else {
/* tag for getExecutableNode() */
node->exec= NODE_READY|NODE_FINISHED|NODE_SKIPPED;
}
}
/* last step: set the stack values for only-value nodes */
/* just does all now, compared to a full buffer exec this is nothing */
if (totnode) {
for (n=0, nodeexec=exec->nodeexec; n < exec->totnodes; ++n, ++nodeexec) {
node = nodeexec->node;
if (node->need_exec==0 && node_only_value(node)) {
if (node->typeinfo->execfunc) {
node_get_stack(node, exec->stack, nsin, nsout);
node->typeinfo->execfunc(thd->rd, node, nsin, nsout);
}
}
}
}
return totnode;
}
/* while executing tree, free buffers from nodes that are not needed anymore */
static void freeExecutableNode(bNodeTreeExec *exec)
{
/* node outputs can be freed when:
* - not a render result or image node
* - when node outputs go to nodes all being set NODE_FINISHED
*/
bNodeTree *ntree = exec->nodetree;
bNodeExec *nodeexec;
bNode *node;
bNodeSocket *sock;
int n;
/* set exec flag for finished nodes that might need freed */
for (node= ntree->nodes.first; node; node= node->next) {
if (node->type!=CMP_NODE_R_LAYERS)
if (node->exec & NODE_FINISHED)
node->exec |= NODE_FREEBUFS;
}
/* clear this flag for input links that are not done yet.
* Using the exec data for valid dependency sort.
*/
for (n=0, nodeexec=exec->nodeexec; n < exec->totnodes; ++n, ++nodeexec) {
node = nodeexec->node;
if ((node->exec & NODE_FINISHED)==0) {
for (sock= node->inputs.first; sock; sock= sock->next)
if (sock->link)
sock->link->fromnode->exec &= ~NODE_FREEBUFS;
}
}
/* now we can free buffers */
for (node= ntree->nodes.first; node; node= node->next) {
if (node->exec & NODE_FREEBUFS) {
for (sock= node->outputs.first; sock; sock= sock->next) {
bNodeStack *ns= node_get_socket_stack(exec->stack, sock);
if (ns && ns->data) {
free_compbuf(ns->data);
ns->data= NULL;
// printf("freed buf node %s\n", node->name);
}
}
}
}
}
static bNodeExec *getExecutableNode(bNodeTreeExec *exec)
{
bNodeExec *nodeexec;
bNodeSocket *sock;
int n;
for (n=0, nodeexec=exec->nodeexec; n < exec->totnodes; ++n, ++nodeexec) {
if (nodeexec->node->exec==0) {
/* input sockets should be ready */
for (sock= nodeexec->node->inputs.first; sock; sock= sock->next) {
if (sock->link && sock->link->fromnode)
if ((sock->link->fromnode->exec & NODE_READY)==0)
break;
}
if (sock==NULL)
return nodeexec;
}
}
return NULL;
}
/* check if texture nodes need exec or end */
static void ntree_composite_texnode(bNodeTree *ntree, int init)
{
bNode *node;
for (node= ntree->nodes.first; node; node= node->next) {
if (node->type==CMP_NODE_TEXTURE && node->id) {
Tex *tex= (Tex *)node->id;
if (tex->nodetree && tex->use_nodes) {
/* has internal flag to detect it only does it once */
if (init) {
if (!tex->nodetree->execdata)
tex->nodetree->execdata = ntreeTexBeginExecTree(tex->nodetree, 1);
}
else
ntreeTexEndExecTree(tex->nodetree->execdata, 1);
tex->nodetree->execdata = NULL;
}
}
}
}
/* optimized tree execute test for compositing */
static void ntreeCompositExecTreeOld(bNodeTree *ntree, RenderData *rd, int do_preview)
{
bNodeExec *nodeexec;
bNode *node;
ListBase threads;
ThreadData thdata;
int totnode, curnode, rendering = TRUE, n;
bNodeTreeExec *exec = ntree->execdata;
if (do_preview)
ntreeInitPreview(ntree, 0, 0);
if (!ntree->execdata) {
/* XXX this is the top-level tree, so we use the ntree->execdata pointer. */
exec = ntreeCompositBeginExecTree(ntree, 1);
}
ntree_composite_texnode(ntree, 1);
/* prevent unlucky accidents */
if (G.background)
rd->scemode &= ~R_COMP_CROP;
/* setup callerdata for thread callback */
thdata.rd= rd;
thdata.stack= exec->stack;
/* fixed seed, for example noise texture */
BLI_srandom(rd->cfra);
/* sets need_exec tags in nodes */
curnode = totnode= setExecutableNodes(exec, &thdata);
BLI_init_threads(&threads, exec_composite_node, rd->threads);
while (rendering) {
if (BLI_available_threads(&threads)) {
nodeexec= getExecutableNode(exec);
if (nodeexec) {
node = nodeexec->node;
if (ntree->progress && totnode)
ntree->progress(ntree->prh, (1.0f - curnode/(float)totnode));
if (ntree->stats_draw) {
char str[128];
BLI_snprintf(str, sizeof(str), "Compositing %d %s", curnode, node->name);
ntree->stats_draw(ntree->sdh, str);
}
curnode--;
node->threaddata = &thdata;
node->exec= NODE_PROCESSING;
BLI_insert_thread(&threads, nodeexec);
}
else
PIL_sleep_ms(50);
}
else
PIL_sleep_ms(50);
rendering= 0;
/* test for ESC */
if (ntree->test_break && ntree->test_break(ntree->tbh)) {
for (node= ntree->nodes.first; node; node= node->next)
node->exec |= NODE_READY;
}
/* check for ready ones, and if we need to continue */
for (n=0, nodeexec=exec->nodeexec; n < exec->totnodes; ++n, ++nodeexec) {
node = nodeexec->node;
if (node->exec & NODE_READY) {
if ((node->exec & NODE_FINISHED)==0) {
BLI_remove_thread(&threads, nodeexec); /* this waits for running thread to finish btw */
node->exec |= NODE_FINISHED;
/* freeing unused buffers */
if (rd->scemode & R_COMP_FREE)
freeExecutableNode(exec);
}
}
else rendering= 1;
}
}
BLI_end_threads(&threads);
/* XXX top-level tree uses the ntree->execdata pointer */
ntreeCompositEndExecTree(exec, 1);
}
#endif /* WITH_COMPOSITOR_LEGACY */
#endif /* WITH_COMPOSITOR */
void *COM_linker_hack = NULL;
void ntreeCompositExecTree(bNodeTree *ntree, RenderData *rd, int rendering, int do_preview,
@@ -699,16 +361,7 @@ void ntreeCompositExecTree(bNodeTree *ntree, RenderData *rd, int rendering, int
const ColorManagedDisplaySettings *display_settings)
{
#ifdef WITH_COMPOSITOR
#ifdef WITH_COMPOSITOR_LEGACY
if (G.debug_value == 200)
{
ntreeCompositExecTreeOld(ntree, rd, do_preview);
}
else
#endif
{
COM_execute(rd, ntree, rendering, view_settings, display_settings);
}
COM_execute(rd, ntree, rendering, view_settings, display_settings);
#else
(void)ntree, (void)rd, (void)rendering, (void)do_preview;
(void)view_settings, (void)display_settings;

File diff suppressed because it is too large Load Diff

View File

@@ -33,177 +33,30 @@
#ifndef __NODE_COMPOSITE_UTIL_H__
#define __NODE_COMPOSITE_UTIL_H__
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include "MEM_guardedalloc.h"
#include "DNA_camera_types.h" /* qdn: defocus node, need camera info */
#include "DNA_color_types.h"
#include "DNA_ID.h"
#include "DNA_image_types.h"
#include "DNA_material_types.h"
#include "DNA_movieclip_types.h"
#include "DNA_node_types.h"
#include "DNA_object_types.h"
#include "DNA_scene_types.h"
#include "DNA_texture_types.h"
#include "BLI_math.h"
#include "BLI_blenlib.h"
#include "BLI_rand.h"
#include "BLI_threads.h"
#include "BLI_utildefines.h"
#include "BLI_utildefines.h"
#include "BLF_translation.h"
#include "BKE_blender.h"
#include "BKE_camera.h"
#include "BKE_colortools.h"
#include "BKE_global.h"
#include "BKE_image.h"
#include "BKE_main.h"
#include "BKE_material.h"
#include "BKE_movieclip.h"
#include "BKE_node.h"
#include "BKE_texture.h"
#include "BKE_tracking.h"
#include "BKE_library.h"
#include "BKE_object.h"
#include "node_util.h"
#include "IMB_imbuf_types.h"
#include "IMB_imbuf.h"
#include "RE_pipeline.h"
#include "RE_shader_ext.h"
#include "RE_render_ext.h"
/* only for forward declarations */
#include "NOD_composite.h"
#define CMP_SCALE_MAX 12000
#ifdef WITH_COMPOSITOR_LEGACY
/* *************************** operations support *************************** */
/* general signal that's in output sockets, and goes over the wires */
typedef struct CompBuf {
float *rect;
int x, y, xrad, yrad;
short type, malloc;
rcti disprect; /* cropped part of image */
int xof, yof; /* relative to center of target image */
void (*rect_procedural)(struct CompBuf *, float *, float, float);
float procedural_size[3], procedural_offset[3];
int procedural_type;
bNode *node; /* only in use for procedural bufs */
struct CompBuf *next, *prev; /* for pass-on, works nicer than reference counting */
} CompBuf;
/* defines also used for pixel size */
#define CB_RGBA 4
#define CB_VEC4 4
#define CB_VEC3 3
#define CB_VEC2 2
#define CB_VAL 1
/* defines for RGBA channels */
#define CHAN_R 0
#define CHAN_G 1
#define CHAN_B 2
#define CHAN_A 3
CompBuf *alloc_compbuf(int sizex, int sizey, int type, int alloc);
CompBuf *dupalloc_compbuf(CompBuf *cbuf);
CompBuf *pass_on_compbuf(CompBuf *cbuf);
void free_compbuf(CompBuf *cbuf);
void print_compbuf(char *str, CompBuf *cbuf);
void compbuf_set_node(struct CompBuf *cbuf, struct bNode *node);
CompBuf *get_cropped_compbuf(rcti *drect, float *rectf, int rectx, int recty, int type);
CompBuf *scalefast_compbuf(CompBuf *inbuf, int newx, int newy);
CompBuf *typecheck_compbuf(CompBuf *inbuf, int type);
void typecheck_compbuf_color(float *out, float *in, int outtype, int intype);
/* **************************************************** */
float *compbuf_get_pixel(CompBuf *cbuf, float *defcol, float *use, int x, int y, int xrad, int yrad);
/* Pixel-to-Pixel operation, 1 Image in, 1 out */
void composit1_pixel_processor(bNode *node, CompBuf *out, CompBuf *src_buf, float *src_col,
void (*func)(bNode *, float *, float *),
int src_type);
/* Pixel-to-Pixel operation, 2 Images in, 1 out */
void composit2_pixel_processor(bNode *node, CompBuf *out, CompBuf *src_buf, float *src_col,
CompBuf *fac_buf, float *fac, void (*func)(bNode *, float *, float *, float *),
int src_type, int fac_type);
/* Pixel-to-Pixel operation, 3 Images in, 1 out */
void composit3_pixel_processor(bNode *node, CompBuf *out, CompBuf *src1_buf, float *src1_col, CompBuf *src2_buf, float *src2_col,
CompBuf *fac_buf, float *fac, void (*func)(bNode *, float *, float *, float *, float *),
int src1_type, int src2_type, int fac_type);
/* Pixel-to-Pixel operation, 4 Images in, 1 out */
void composit4_pixel_processor(bNode *node, CompBuf *out, CompBuf *src1_buf, float *src1_col, CompBuf *fac1_buf, float *fac1,
CompBuf *src2_buf, float *src2_col, CompBuf *fac2_buf, float *fac2,
void (*func)(bNode *, float *, float *, float *, float *, float *),
int src1_type, int fac1_type, int src2_type, int fac2_type);
CompBuf *valbuf_from_rgbabuf(CompBuf *cbuf, int channel);
void valbuf_to_rgbabuf(CompBuf *valbuf, CompBuf *cbuf, int channel);
void generate_preview(void *data, bNode *node, CompBuf *stackbuf);
void do_copy_rgba(bNode *node, float *out, float *in);
void do_copy_rgb(bNode *node, float *out, float *in);
void do_copy_value(bNode *node, float *out, float *in);
void do_copy_a_rgba(bNode *node, float *out, float *in, float *fac);
void do_rgba_to_yuva(bNode *node, float *out, float *in);
void do_rgba_to_hsva(bNode *node, float *out, float *in);
void do_rgba_to_ycca(bNode *node, float *out, float *in);
void do_yuva_to_rgba(bNode *node, float *out, float *in);
void do_hsva_to_rgba(bNode *node, float *out, float *in);
void do_ycca_to_rgba(bNode *node, float *out, float *in);
void gamma_correct_compbuf(CompBuf *img, int inversed);
void premul_compbuf(CompBuf *img, int inversed);
void convolve(CompBuf* dst, CompBuf* in1, CompBuf* in2);
extern void node_ID_title_cb(void *node_v, void *unused_v);
/* utility functions used by glare, tonemap and lens distortion */
/* soms macros for color handling */
typedef float fRGB[4];
/* multiply c2 by color rgb, rgb as separate arguments */
#define fRGB_rgbmult(c, r, g, b) { c[0]*=(r); c[1]*=(g); c[2]*=(b); } (void)0
void qd_getPixel(CompBuf* src, int x, int y, float* col);
void qd_setPixel(CompBuf* src, int x, int y, float* col);
void qd_addPixel(CompBuf* src, int x, int y, float* col);
void qd_multPixel(CompBuf* src, int x, int y, float f);
void qd_getPixelLerpWrap(CompBuf* src, float u, float v, float* col);
void qd_getPixelLerp(CompBuf* src, float u, float v, float* col);
void qd_getPixelLerpChan(CompBuf* src, float u, float v, int chan, float* out);
CompBuf* qd_downScaledCopy(CompBuf* src, int scale);
void IIR_gauss(CompBuf* src, float sigma, int chan, int xy);
/* end utility funcs */
/* transformations */
CompBuf* node_composit_transform(CompBuf *cbuf, float x, float y, float angle, float scale, int filter_type);
float *node_composit_get_float_buffer(RenderData *rd, ImBuf *ibuf, int *alloc);
#endif
#endif /* WITH_COMPOSITOR_LEGACY */
#endif /* __NODE_COMPOSITE_UTIL_H__ */

View File

@@ -43,103 +43,6 @@ static bNodeSocketTemplate cmp_node_alphaover_out[] = {
{ -1, 0, "" }
};
#ifdef WITH_COMPOSITOR_LEGACY
static void do_alphaover_premul(bNode *UNUSED(node), float *out, float *src, float *over, float *fac)
{
/* Zero alpha values should still permit an add of RGB data */
if (over[3]<0.0f) {
copy_v4_v4(out, src);
}
else if (fac[0]==1.0f && over[3]>=1.0f) {
copy_v4_v4(out, over);
}
else {
float mul= 1.0f - fac[0]*over[3];
out[0] = (mul*src[0]) + fac[0]*over[0];
out[1] = (mul*src[1]) + fac[0]*over[1];
out[2] = (mul*src[2]) + fac[0]*over[2];
out[3] = (mul*src[3]) + fac[0]*over[3];
}
}
/* result will be still premul, but the over part is premulled */
static void do_alphaover_key(bNode *UNUSED(node), float *out, float *src, float *over, float *fac)
{
if (over[3]<=0.0f) {
copy_v4_v4(out, src);
}
else if (fac[0]==1.0f && over[3]>=1.0f) {
copy_v4_v4(out, over);
}
else {
float premul= fac[0]*over[3];
float mul= 1.0f - premul;
out[0] = (mul*src[0]) + premul*over[0];
out[1] = (mul*src[1]) + premul*over[1];
out[2] = (mul*src[2]) + premul*over[2];
out[3] = (mul*src[3]) + fac[0]*over[3];
}
}
/* result will be still premul, but the over part is premulled */
static void do_alphaover_mixed(bNode *node, float *out, float *src, float *over, float *fac)
{
if (over[3]<=0.0f) {
copy_v4_v4(out, src);
}
else if (fac[0]==1.0f && over[3]>=1.0f) {
copy_v4_v4(out, over);
}
else {
NodeTwoFloats *ntf= node->storage;
float addfac= 1.0f - ntf->x + over[3]*ntf->x;
float premul= fac[0]*addfac;
float mul= 1.0f - fac[0]*over[3];
out[0] = (mul*src[0]) + premul*over[0];
out[1] = (mul*src[1]) + premul*over[1];
out[2] = (mul*src[2]) + premul*over[2];
out[3] = (mul*src[3]) + fac[0]*over[3];
}
}
static void node_composit_exec_alphaover(void *UNUSED(data), bNode *node, bNodeStack **in, bNodeStack **out)
{
/* stack order in: col col */
/* stack order out: col */
if (out[0]->hasoutput==0)
return;
/* input no image? then only color operation */
if (in[1]->data==NULL && in[2]->data==NULL) {
do_alphaover_premul(node, out[0]->vec, in[1]->vec, in[2]->vec, in[0]->vec);
}
else {
/* make output size of input image */
CompBuf *cbuf= in[1]->data?in[1]->data:in[2]->data;
CompBuf *stackbuf= alloc_compbuf(cbuf->x, cbuf->y, CB_RGBA, 1); /* allocs */
NodeTwoFloats *ntf= node->storage;
if (ntf->x != 0.0f)
composit3_pixel_processor(node, stackbuf, in[1]->data, in[1]->vec, in[2]->data, in[2]->vec, in[0]->data, in[0]->vec, do_alphaover_mixed, CB_RGBA, CB_RGBA, CB_VAL);
else if (node->custom1)
composit3_pixel_processor(node, stackbuf, in[1]->data, in[1]->vec, in[2]->data, in[2]->vec, in[0]->data, in[0]->vec, do_alphaover_key, CB_RGBA, CB_RGBA, CB_VAL);
else
composit3_pixel_processor(node, stackbuf, in[1]->data, in[1]->vec, in[2]->data, in[2]->vec, in[0]->data, in[0]->vec, do_alphaover_premul, CB_RGBA, CB_RGBA, CB_VAL);
out[0]->data= stackbuf;
}
}
#endif /* WITH_COMPOSITOR_LEGACY */
static void node_alphaover_init(bNodeTree *UNUSED(ntree), bNode *node, bNodeTemplate *UNUSED(ntemp))
{
node->storage= MEM_callocN(sizeof(NodeTwoFloats), "NodeTwoFloats");
@@ -154,9 +57,6 @@ void register_node_type_cmp_alphaover(bNodeTreeType *ttype)
node_type_size(&ntype, 80, 40, 120);
node_type_init(&ntype, node_alphaover_init);
node_type_storage(&ntype, "NodeTwoFloats", node_free_standard_storage, node_copy_standard_storage);
#ifdef WITH_COMPOSITOR_LEGACY
node_type_exec(&ntype, node_composit_exec_alphaover);
#endif
nodeRegisterType(ttype, &ntype);
}

View File

@@ -43,221 +43,6 @@ static bNodeSocketTemplate cmp_node_bilateralblur_out[] = {
{ -1, 0, "" }
};
#ifdef WITH_COMPOSITOR_LEGACY
#define INIT_C3 \
mean0 = 1; \
mean1[0] = src[0]; \
mean1[1] = src[1]; \
mean1[2] = src[2]; \
mean1[3] = src[3]; \
(void)0
/* finds color distances */
#define COLOR_DISTANCE_C3(c1, c2) \
((c1[0] - c2[0]) * (c1[0] - c2[0]) + \
(c1[1] - c2[1]) * (c1[1] - c2[1]) + \
(c1[2] - c2[2]) * (c1[2] - c2[2]) + \
(c1[3] - c2[3]) * (c1[3] - c2[3]))
/* this is the main kernel function for comparing color distances
* and adding them weighted to the final color */
#define KERNEL_ELEMENT_C3(k) \
temp_color = src + deltas[k]; \
ref_color = ref + deltas[k]; \
w = weight_tab[k] + \
(double)COLOR_DISTANCE_C3(ref, ref_color) * i2sigma_color; \
w = 1.0 / (w * w + 1); \
mean0 += w; \
mean1[0] += (double)temp_color[0] * w; \
mean1[1] += (double)temp_color[1] * w; \
mean1[2] += (double)temp_color[2] * w; \
mean1[3] += (double)temp_color[3] * w; \
(void)0
/* write blurred values to image */
#define UPDATE_OUTPUT_C3 \
mean0 = 1.0 / mean0; \
dest[x * pix + 0] = mean1[0] * mean0; \
dest[x * pix + 1] = mean1[1] * mean0; \
dest[x * pix + 2] = mean1[2] * mean0; \
dest[x * pix + 3] = mean1[3] * mean0; \
(void)0
/* initializes deltas for fast access to neighbor pixels */
#define INIT_3X3_DELTAS(deltas, step, nch) \
((deltas)[0] = (nch), (deltas)[1] = -(step) + (nch), \
(deltas)[2] = -(step), (deltas)[3] = -(step) - (nch), \
(deltas)[4] = -(nch), (deltas)[5] = (step) - (nch), \
(deltas)[6] = (step), (deltas)[7] = (step) + (nch)); \
(void)0
/* code of this node was heavily inspired by the smooth function of opencv library.
* The main change is an optional image input */
static void node_composit_exec_bilateralblur(void *UNUSED(data), bNode *node, bNodeStack **in, bNodeStack **out)
{
NodeBilateralBlurData *nbbd = node->storage;
CompBuf *new, *source, *img = in[0]->data, *refimg = in[1]->data;
double mean0, w, i2sigma_color, i2sigma_space;
double mean1[4];
double weight_tab[8];
float *src, *dest, *ref, *temp_color, *ref_color;
float sigma_color, sigma_space;
int imgx, imgy, x, y, pix, i, step;
int deltas[8];
short found_determinator = 0;
if (img == NULL || out[0]->hasoutput == 0)
return;
if (img->type != CB_RGBA) {
img = typecheck_compbuf(in[0]->data, CB_RGBA);
}
imgx = img->x;
imgy = img->y;
pix = img->type;
step = pix * imgx;
if (refimg) {
if (refimg->x == imgx && refimg->y == imgy) {
if (ELEM3(refimg->type, CB_VAL, CB_VEC2, CB_VEC3)) {
refimg = typecheck_compbuf(in[1]->data, CB_RGBA);
found_determinator = 1;
}
}
}
else {
refimg = img;
}
/* allocs */
source = dupalloc_compbuf(img);
new = alloc_compbuf(imgx, imgy, pix, 1);
/* accept image offsets from other nodes */
new->xof = img->xof;
new->yof = img->yof;
/* bilateral code properties */
sigma_color = nbbd->sigma_color;
sigma_space = nbbd->sigma_space;
i2sigma_color = 1.0f / (sigma_color * sigma_color);
i2sigma_space = 1.0f / (sigma_space * sigma_space);
INIT_3X3_DELTAS(deltas, step, pix);
weight_tab[0] = weight_tab[2] = weight_tab[4] = weight_tab[6] = i2sigma_space;
weight_tab[1] = weight_tab[3] = weight_tab[5] = weight_tab[7] = i2sigma_space * 2;
/* iterations */
for (i = 0; i < nbbd->iter; i++) {
src = source->rect;
ref = refimg->rect;
dest = new->rect;
/*goes through image, there are more loops for 1st/last line and all other lines*/
/*kernel element accumulates surrounding colors, which are then written with the update_output function*/
for (x = 0; x < imgx; x++, src += pix, ref += pix) {
INIT_C3;
KERNEL_ELEMENT_C3(6);
if (x > 0) {
KERNEL_ELEMENT_C3(5);
KERNEL_ELEMENT_C3(4);
}
if (x < imgx - 1) {
KERNEL_ELEMENT_C3(7);
KERNEL_ELEMENT_C3(0);
}
UPDATE_OUTPUT_C3;
}
dest += step;
for (y = 1; y < imgy - 1; y++, dest += step, src += pix, ref += pix) {
x = 0;
INIT_C3;
KERNEL_ELEMENT_C3(0);
KERNEL_ELEMENT_C3(1);
KERNEL_ELEMENT_C3(2);
KERNEL_ELEMENT_C3(6);
KERNEL_ELEMENT_C3(7);
UPDATE_OUTPUT_C3;
src += pix;
ref += pix;
for (x = 1; x < imgx - 1; x++, src += pix, ref += pix) {
INIT_C3;
KERNEL_ELEMENT_C3(0);
KERNEL_ELEMENT_C3(1);
KERNEL_ELEMENT_C3(2);
KERNEL_ELEMENT_C3(3);
KERNEL_ELEMENT_C3(4);
KERNEL_ELEMENT_C3(5);
KERNEL_ELEMENT_C3(6);
KERNEL_ELEMENT_C3(7);
UPDATE_OUTPUT_C3;
}
INIT_C3;
KERNEL_ELEMENT_C3(2);
KERNEL_ELEMENT_C3(3);
KERNEL_ELEMENT_C3(4);
KERNEL_ELEMENT_C3(5);
KERNEL_ELEMENT_C3(6);
UPDATE_OUTPUT_C3;
}
for (x = 0; x < imgx; x++, src += pix, ref += pix) {
INIT_C3;
KERNEL_ELEMENT_C3(2);
if (x > 0) {
KERNEL_ELEMENT_C3(3);
KERNEL_ELEMENT_C3(4);
}
if (x < imgx - 1) {
KERNEL_ELEMENT_C3(1);
KERNEL_ELEMENT_C3(0);
}
UPDATE_OUTPUT_C3;
}
if (node->exec & NODE_BREAK) break;
SWAP(CompBuf, *source, *new);
}
if (img != in[0]->data)
free_compbuf(img);
if (found_determinator == 1) {
if (refimg != in[1]->data)
free_compbuf(refimg);
}
out[0]->data = source;
free_compbuf(new);
}
#endif /* WITH_COMPOSITOR_LEGACY */
static void node_composit_init_bilateralblur(bNodeTree *UNUSED(ntree), bNode *node, bNodeTemplate *UNUSED(ntemp))
{
NodeBilateralBlurData *nbbd = MEM_callocN(sizeof(NodeBilateralBlurData), "node bilateral blur data");
@@ -275,9 +60,6 @@ void register_node_type_cmp_bilateralblur(bNodeTreeType *ttype)
node_type_size(&ntype, 150, 120, 200);
node_type_init(&ntype, node_composit_init_bilateralblur);
node_type_storage(&ntype, "NodeBilateralBlurData", node_free_standard_storage, node_copy_standard_storage);
#ifdef WITH_COMPOSITOR_LEGACY
node_type_exec(&ntype, node_composit_exec_bilateralblur);
#endif
nodeRegisterType(ttype, &ntype);
}

View File

@@ -44,686 +44,6 @@ static bNodeSocketTemplate cmp_node_blur_out[] = {
{ -1, 0, "" }
};
#ifdef WITH_COMPOSITOR_LEGACY
static float *make_gausstab(int filtertype, int rad)
{
float *gausstab, sum, val;
int i, n;
n = 2 * rad + 1;
gausstab = (float *) MEM_mallocN(n * sizeof(float), "gauss");
sum = 0.0f;
for (i = -rad; i <= rad; i++) {
val = RE_filter_value(filtertype, (float)i / (float)rad);
sum += val;
gausstab[i + rad] = val;
}
sum = 1.0f / sum;
for (i = 0; i < n; i++)
gausstab[i] *= sum;
return gausstab;
}
static float *make_bloomtab(int rad)
{
float *bloomtab, val;
int i, n;
n = 2 * rad + 1;
bloomtab = (float *) MEM_mallocN(n * sizeof(float), "bloom");
for (i = -rad; i <= rad; i++) {
val = powf(1.0f - fabsf((float)i) / ((float)rad), 4.0f);
bloomtab[i + rad] = val;
}
return bloomtab;
}
/* both input images of same type, either 4 or 1 channel */
static void blur_single_image(bNode *node, CompBuf *new, CompBuf *img, float scale)
{
NodeBlurData *nbd = node->storage;
CompBuf *work;
register float sum, val;
float rval, gval, bval, aval;
float *gausstab, *gausstabcent;
int rad, imgx = img->x, imgy = img->y;
int x, y, pix = img->type;
int i, bigstep;
float *src, *dest;
/* helper image */
work = alloc_compbuf(imgx, imgy, img->type, 1); /* allocs */
/* horizontal */
if (nbd->sizex == 0) {
memcpy(work->rect, img->rect, sizeof(float) * img->type * imgx * imgy);
}
else {
rad = scale * (float)nbd->sizex;
if (rad > imgx / 2)
rad = imgx / 2;
else if (rad < 1)
rad = 1;
gausstab = make_gausstab(nbd->filtertype, rad);
gausstabcent = gausstab + rad;
for (y = 0; y < imgy; y++) {
float *srcd = img->rect + pix * (y * img->x);
dest = work->rect + pix * (y * img->x);
for (x = 0; x < imgx; x++) {
int minr = x - rad < 0 ? -x : -rad;
int maxr = x + rad > imgx ? imgx - x : rad;
src = srcd + pix * (x + minr);
sum = gval = rval = bval = aval = 0.0f;
for (i = minr; i < maxr; i++) {
val = gausstabcent[i];
sum += val;
rval += val * (*src++);
if (pix == 4) {
gval += val * (*src++);
bval += val * (*src++);
aval += val * (*src++);
}
}
sum = 1.0f / sum;
*dest++ = rval * sum;
if (pix == 4) {
*dest++ = gval * sum;
*dest++ = bval * sum;
*dest++ = aval * sum;
}
}
if (node->exec & NODE_BREAK)
break;
}
/* vertical */
MEM_freeN(gausstab);
}
if (nbd->sizey == 0) {
memcpy(new->rect, work->rect, sizeof(float) * img->type * imgx * imgy);
}
else {
rad = scale * (float)nbd->sizey;
if (rad > imgy / 2)
rad = imgy / 2;
else if (rad < 1)
rad = 1;
gausstab = make_gausstab(nbd->filtertype, rad);
gausstabcent = gausstab + rad;
bigstep = pix * imgx;
for (x = 0; x < imgx; x++) {
float *srcd = work->rect + pix * x;
dest = new->rect + pix * x;
for (y = 0; y < imgy; y++) {
int minr = y - rad < 0 ? -y : -rad;
int maxr = y + rad > imgy ? imgy - y : rad;
src = srcd + bigstep * (y + minr);
sum = gval = rval = bval = aval = 0.0f;
for (i = minr; i < maxr; i++) {
val = gausstabcent[i];
sum += val;
rval += val * src[0];
if (pix == 4) {
gval += val * src[1];
bval += val * src[2];
aval += val * src[3];
}
src += bigstep;
}
sum = 1.0f / sum;
dest[0] = rval * sum;
if (pix == 4) {
dest[1] = gval * sum;
dest[2] = bval * sum;
dest[3] = aval * sum;
}
dest += bigstep;
}
if (node->exec & NODE_BREAK)
break;
}
MEM_freeN(gausstab);
}
free_compbuf(work);
}
/* reference has to be mapped 0-1, and equal in size */
static void bloom_with_reference(CompBuf *new, CompBuf *img, CompBuf *UNUSED(ref), float UNUSED(fac), NodeBlurData *nbd)
{
CompBuf *wbuf;
register float val;
float radxf, radyf;
float **maintabs;
float *gausstabx, *gausstabcenty;
float *gausstaby, *gausstabcentx;
int radx, rady, imgx = img->x, imgy = img->y;
int x, y;
int i, j;
float *src, *dest, *wb;
wbuf = alloc_compbuf(imgx, imgy, CB_VAL, 1);
/* horizontal */
radx = (float)nbd->sizex;
if (radx > imgx / 2)
radx = imgx / 2;
else if (radx < 1)
radx = 1;
/* vertical */
rady = (float)nbd->sizey;
if (rady > imgy / 2)
rady = imgy / 2;
else if (rady < 1)
rady = 1;
x = MAX2(radx, rady);
maintabs = MEM_mallocN(x * sizeof(void *), "gauss array");
for (i = 0; i < x; i++)
maintabs[i] = make_bloomtab(i + 1);
/* vars to store before we go */
// refd= ref->rect;
src = img->rect;
radxf = (float)radx;
radyf = (float)rady;
for (y = 0; y < imgy; y++) {
for (x = 0; x < imgx; x++, src += 4) { //, refd++) {
// int refradx= (int)(refd[0]*radxf);
// int refrady= (int)(refd[0]*radyf);
int refradx = (int)(radxf * 0.3f * src[3] * (src[0] + src[1] + src[2]));
int refrady = (int)(radyf * 0.3f * src[3] * (src[0] + src[1] + src[2]));
if (refradx > radx) refradx = radx;
else if (refradx < 1) refradx = 1;
if (refrady > rady) refrady = rady;
else if (refrady < 1) refrady = 1;
if (refradx == 1 && refrady == 1) {
wb = wbuf->rect + (y * imgx + x);
dest = new->rect + 4 * (y * imgx + x);
wb[0] += 1.0f;
dest[0] += src[0];
dest[1] += src[1];
dest[2] += src[2];
dest[3] += src[3];
}
else {
int minxr = x - refradx < 0 ? -x : -refradx;
int maxxr = x + refradx > imgx ? imgx - x : refradx;
int minyr = y - refrady < 0 ? -y : -refrady;
int maxyr = y + refrady > imgy ? imgy - y : refrady;
float *destd = new->rect + 4 * ( (y + minyr) * imgx + x + minxr);
float *wbufd = wbuf->rect + ( (y + minyr) * imgx + x + minxr);
gausstabx = maintabs[refradx - 1];
gausstabcentx = gausstabx + refradx;
gausstaby = maintabs[refrady - 1];
gausstabcenty = gausstaby + refrady;
for (i = minyr; i < maxyr; i++, destd += 4 * imgx, wbufd += imgx) {
dest = destd;
wb = wbufd;
for (j = minxr; j < maxxr; j++, dest += 4, wb++) {
val = gausstabcenty[i] * gausstabcentx[j];
wb[0] += val;
dest[0] += val * src[0];
dest[1] += val * src[1];
dest[2] += val * src[2];
dest[3] += val * src[3];
}
}
}
}
}
x = imgx * imgy;
dest = new->rect;
wb = wbuf->rect;
while (x--) {
val = 1.0f / wb[0];
dest[0] *= val;
dest[1] *= val;
dest[2] *= val;
dest[3] *= val;
wb++;
dest += 4;
}
free_compbuf(wbuf);
x = MAX2(radx, rady);
for (i = 0; i < x; i++)
MEM_freeN(maintabs[i]);
MEM_freeN(maintabs);
}
#if 0
static float hexagon_filter(float fi, float fj)
{
fi = fabs(fi);
fj = fabs(fj);
if (fj > 0.33f) {
fj = (fj - 0.33f) / 0.66f;
if (fi + fj > 1.0f)
return 0.0f;
else
return 1.0f;
}
else return 1.0f;
}
#endif
/* uses full filter, no horizontal/vertical optimize possible */
/* both images same type, either 1 or 4 channels */
static void bokeh_single_image(bNode *node, CompBuf *new, CompBuf *img, float fac)
{
NodeBlurData *nbd = node->storage;
register float val;
float radxf, radyf;
float *gausstab, *dgauss;
int radx, rady, imgx = img->x, imgy = img->y;
int x, y, pix = img->type;
int i, j, n;
float *src = NULL, *dest, *srcd = NULL;
/* horizontal */
radxf = fac * (float)nbd->sizex;
if (radxf > imgx / 2.0f)
radxf = imgx / 2.0f;
else if (radxf < 1.0f)
radxf = 1.0f;
/* vertical */
radyf = fac * (float)nbd->sizey;
if (radyf > imgy / 2.0f)
radyf = imgy / 2.0f;
else if (radyf < 1.0f)
radyf = 1.0f;
radx = ceil(radxf);
rady = ceil(radyf);
n = (2 * radx + 1) * (2 * rady + 1);
/* create a full filter image */
gausstab = MEM_mallocN(sizeof(float) * n, "filter tab");
dgauss = gausstab;
val = 0.0f;
for (j = -rady; j <= rady; j++) {
for (i = -radx; i <= radx; i++, dgauss++) {
float fj = (float)j / radyf;
float fi = (float)i / radxf;
float dist = sqrt(fj * fj + fi * fi);
// *dgauss= hexagon_filter(fi, fj);
*dgauss = RE_filter_value(nbd->filtertype, dist);
val += *dgauss;
}
}
if (val != 0.0f) {
val = 1.0f / val;
for (j = n - 1; j >= 0; j--)
gausstab[j] *= val;
}
else gausstab[4] = 1.0f;
for (y = -rady + 1; y < imgy + rady - 1; y++) {
if (y <= 0) srcd = img->rect;
else if (y < imgy) srcd += pix * imgx;
else srcd = img->rect + pix * (imgy - 1) * imgx;
for (x = -radx + 1; x < imgx + radx - 1; x++) {
int minxr = x - radx < 0 ? -x : -radx;
int maxxr = x + radx >= imgx ? imgx - x - 1 : radx;
int minyr = y - rady < 0 ? -y : -rady;
int maxyr = y + rady > imgy - 1 ? imgy - y - 1 : rady;
float *destd = new->rect + pix * ( (y + minyr) * imgx + x + minxr);
float *dgausd = gausstab + (minyr + rady) * (2 * radx + 1) + minxr + radx;
if (x <= 0) src = srcd;
else if (x < imgx) src += pix;
else src = srcd + pix * (imgx - 1);
for (i = minyr; i <= maxyr; i++, destd += pix * imgx, dgausd += 2 * radx + 1) {
dest = destd;
dgauss = dgausd;
for (j = minxr; j <= maxxr; j++, dest += pix, dgauss++) {
val = *dgauss;
if (val != 0.0f) {
dest[0] += val * src[0];
if (pix > 1) {
dest[1] += val * src[1];
dest[2] += val * src[2];
dest[3] += val * src[3];
}
}
}
}
}
if (node->exec & NODE_BREAK)
break;
}
MEM_freeN(gausstab);
}
/* reference has to be mapped 0-1, and equal in size */
static void blur_with_reference(bNode *node, CompBuf *new, CompBuf *img, CompBuf *ref)
{
NodeBlurData *nbd = node->storage;
CompBuf *blurbuf, *ref_use;
register float sum, val;
float rval, gval, bval, aval, radxf, radyf;
float **maintabs;
float *gausstabx, *gausstabcenty;
float *gausstaby, *gausstabcentx;
int radx, rady, imgx = img->x, imgy = img->y;
int x, y, pix = img->type;
int i, j;
float *src, *dest, *refd, *blurd;
float defcol[4] = {1.0f, 1.0f, 1.0f, 1.0f}; /* default color for compbuf_get_pixel */
float proccol[4]; /* local color if compbuf is procedural */
int refradx, refrady;
if (ref->x != img->x || ref->y != img->y)
return;
ref_use = typecheck_compbuf(ref, CB_VAL);
/* trick is; we blur the reference image... but only works with clipped values*/
blurbuf = alloc_compbuf(imgx, imgy, CB_VAL, 1);
blurbuf->xof = ref_use->xof;
blurbuf->yof = ref_use->yof;
blurd = blurbuf->rect;
refd = ref_use->rect;
for (x = imgx * imgy; x > 0; x--, refd++, blurd++) {
if (refd[0] < 0.0f) blurd[0] = 0.0f;
else if (refd[0] > 1.0f) blurd[0] = 1.0f;
else blurd[0] = refd[0];
}
blur_single_image(node, blurbuf, blurbuf, 1.0f);
/* horizontal */
radx = (float)nbd->sizex;
if (radx > imgx / 2)
radx = imgx / 2;
else if (radx < 1)
radx = 1;
/* vertical */
rady = (float)nbd->sizey;
if (rady > imgy / 2)
rady = imgy / 2;
else if (rady < 1)
rady = 1;
x = MAX2(radx, rady);
maintabs = MEM_mallocN(x * sizeof(void *), "gauss array");
for (i = 0; i < x; i++)
maintabs[i] = make_gausstab(nbd->filtertype, i + 1);
dest = new->rect;
radxf = (float)radx;
radyf = (float)rady;
for (y = 0; y < imgy; y++) {
for (x = 0; x < imgx; x++, dest += pix) {
refd = compbuf_get_pixel(blurbuf, defcol, proccol, x - blurbuf->xrad, y - blurbuf->yrad, blurbuf->xrad, blurbuf->yrad);
refradx = (int)(refd[0] * radxf);
refrady = (int)(refd[0] * radyf);
if (refradx > radx) refradx = radx;
else if (refradx < 1) refradx = 1;
if (refrady > rady) refrady = rady;
else if (refrady < 1) refrady = 1;
if (refradx == 1 && refrady == 1) {
src = img->rect + pix * (y * imgx + x);
if (pix == 1)
dest[0] = src[0];
else
copy_v4_v4(dest, src);
}
else {
int minxr = x - refradx < 0 ? -x : -refradx;
int maxxr = x + refradx > imgx ? imgx - x : refradx;
int minyr = y - refrady < 0 ? -y : -refrady;
int maxyr = y + refrady > imgy ? imgy - y : refrady;
float *srcd = img->rect + pix * ( (y + minyr) * imgx + x + minxr);
gausstabx = maintabs[refradx - 1];
gausstabcentx = gausstabx + refradx;
gausstaby = maintabs[refrady - 1];
gausstabcenty = gausstaby + refrady;
sum = gval = rval = bval = aval = 0.0f;
for (i = minyr; i < maxyr; i++, srcd += pix * imgx) {
src = srcd;
for (j = minxr; j < maxxr; j++, src += pix) {
val = gausstabcenty[i] * gausstabcentx[j];
sum += val;
rval += val * src[0];
if (pix > 1) {
gval += val * src[1];
bval += val * src[2];
aval += val * src[3];
}
}
}
sum = 1.0f / sum;
dest[0] = rval * sum;
if (pix > 1) {
dest[1] = gval * sum;
dest[2] = bval * sum;
dest[3] = aval * sum;
}
}
}
if (node->exec & NODE_BREAK)
break;
}
free_compbuf(blurbuf);
x = MAX2(radx, rady);
for (i = 0; i < x; i++)
MEM_freeN(maintabs[i]);
MEM_freeN(maintabs);
if (ref_use != ref)
free_compbuf(ref_use);
}
static void node_composit_exec_blur(void *data, bNode *node, bNodeStack **in, bNodeStack **out)
{
CompBuf *new, *img = in[0]->data;
NodeBlurData *nbd = node->storage;
if (img == NULL) return;
/* store image in size that is needed for absolute/relative conversions on ui level */
nbd->image_in_width = img->x;
nbd->image_in_height = img->y;
if (out[0]->hasoutput == 0) return;
if (nbd->relative) {
if (nbd->aspect == CMP_NODE_BLUR_ASPECT_NONE) {
nbd->sizex = (int)(nbd->percentx * 0.01f * nbd->image_in_width);
nbd->sizey = (int)(nbd->percenty * 0.01f * nbd->image_in_height);
}
else if (nbd->aspect == CMP_NODE_BLUR_ASPECT_Y) {
nbd->sizex = (int)(nbd->percentx * 0.01f * nbd->image_in_width);
nbd->sizey = (int)(nbd->percenty * 0.01f * nbd->image_in_width);
}
else if (nbd->aspect == CMP_NODE_BLUR_ASPECT_X) {
nbd->sizex = (int)(nbd->percentx * 0.01f * nbd->image_in_height);
nbd->sizey = (int)(nbd->percenty * 0.01f * nbd->image_in_height);
}
}
if (nbd->sizex == 0 && nbd->sizey == 0) {
new = pass_on_compbuf(img);
out[0]->data = new;
}
else if (nbd->filtertype == R_FILTER_FAST_GAUSS) {
if (in[1]->vec[0] < 0.001f) { /* time node inputs can be a tiny value */
new = pass_on_compbuf(img);
}
else {
// TODO: can this be mapped with reference, too?
const float sx = ((float)nbd->sizex * in[1]->vec[0]) / 2.0f, sy = ((float)nbd->sizey * in[1]->vec[0]) / 2.0f;
int c;
if ((img == NULL) || (out[0]->hasoutput == 0)) return;
if (img->type == CB_VEC2)
new = typecheck_compbuf(img, CB_VAL);
else if (img->type == CB_VEC3)
new = typecheck_compbuf(img, CB_RGBA);
else
new = dupalloc_compbuf(img);
if ((sx == sy) && (sx > 0.f)) {
for (c = 0; c < new->type; ++c)
IIR_gauss(new, sx, c, 3);
}
else {
if (sx > 0.f) {
for (c = 0; c < new->type; ++c)
IIR_gauss(new, sx, c, 1);
}
if (sy > 0.f) {
for (c = 0; c < new->type; ++c)
IIR_gauss(new, sy, c, 2);
}
}
}
out[0]->data = new;
}
else {
/* All non fast gauss blur methods */
if (img->type == CB_VEC2 || img->type == CB_VEC3) {
img = typecheck_compbuf(in[0]->data, CB_RGBA);
}
/* if fac input, we do it different */
if (in[1]->data) {
CompBuf *gammabuf;
/* make output size of input image */
new = alloc_compbuf(img->x, img->y, img->type, 1); /* allocs */
/* accept image offsets from other nodes */
new->xof = img->xof;
new->yof = img->yof;
if (nbd->gamma) {
gammabuf = dupalloc_compbuf(img);
gamma_correct_compbuf(gammabuf, 0);
}
else gammabuf = img;
blur_with_reference(node, new, gammabuf, in[1]->data);
if (nbd->gamma) {
gamma_correct_compbuf(new, 1);
free_compbuf(gammabuf);
}
if (node->exec & NODE_BREAK) {
free_compbuf(new);
new = NULL;
}
out[0]->data = new;
}
else {
if (in[1]->vec[0] <= 0.001f) { /* time node inputs can be a tiny value */
new = pass_on_compbuf(img);
}
else {
CompBuf *gammabuf;
/* make output size of input image */
new = alloc_compbuf(img->x, img->y, img->type, 1); /* allocs */
/* accept image offsets from other nodes */
new->xof = img->xof;
new->yof = img->yof;
if (nbd->gamma) {
gammabuf = dupalloc_compbuf(img);
gamma_correct_compbuf(gammabuf, 0);
}
else gammabuf = img;
if (nbd->bokeh)
bokeh_single_image(node, new, gammabuf, in[1]->vec[0]);
else if (1)
blur_single_image(node, new, gammabuf, in[1]->vec[0]);
else /* bloom experimental... */
bloom_with_reference(new, gammabuf, NULL, in[1]->vec[0], nbd);
if (nbd->gamma) {
gamma_correct_compbuf(new, 1);
free_compbuf(gammabuf);
}
if (node->exec & NODE_BREAK) {
free_compbuf(new);
new = NULL;
}
}
out[0]->data = new;
}
if (img != in[0]->data)
free_compbuf(img);
}
generate_preview(data, node, out[0]->data);
}
#endif /* WITH_COMPOSITOR_LEGACY */
static void node_composit_init_blur(bNodeTree *UNUSED(ntree), bNode *node, bNodeTemplate *UNUSED(ntemp))
{
NodeBlurData *data = MEM_callocN(sizeof(NodeBlurData), "node blur data");
@@ -740,9 +60,6 @@ void register_node_type_cmp_blur(bNodeTreeType *ttype)
node_type_size(&ntype, 120, 80, 200);
node_type_init(&ntype, node_composit_init_blur);
node_type_storage(&ntype, "NodeBlurData", node_free_standard_storage, node_copy_standard_storage);
#ifdef WITH_COMPOSITOR_LEGACY
node_type_exec(&ntype, node_composit_exec_blur);
#endif
nodeRegisterType(ttype, &ntype);
}

View File

@@ -47,54 +47,6 @@ static bNodeSocketTemplate cmp_node_brightcontrast_out[] = {
{ -1, 0, "" }
};
#ifdef WITH_COMPOSITOR_LEGACY
static void do_brightnesscontrast(bNode *UNUSED(node), float *out, float *in, float *in_brightness, float *in_contrast)
{
float i;
int c;
float a, b, v;
float brightness = (*in_brightness) / 100.0f;
float contrast = *in_contrast;
float delta = contrast / 200.0f;
a = 1.0f - delta * 2.0f;
/*
* The algorithm is by Werner D. Streidt
* (http://visca.com/ffactory/archives/5-99/msg00021.html)
* Extracted of OpenCV demhist.c
*/
if (contrast > 0) {
a = 1.0f / a;
b = a * (brightness - delta);
}
else {
delta *= -1;
b = a * (brightness + delta);
}
for (c=0; c<3; c++) {
i = in[c];
v = a*i + b;
out[c] = v;
}
}
static void node_composit_exec_brightcontrast(void *UNUSED(data), bNode *node, bNodeStack **in, bNodeStack **out)
{
if (out[0]->hasoutput==0)
return;
if (in[0]->data) {
CompBuf *stackbuf, *cbuf= typecheck_compbuf(in[0]->data, CB_RGBA);
stackbuf= dupalloc_compbuf(cbuf);
composit3_pixel_processor(node, stackbuf, in[0]->data, in[0]->vec, in[1]->data, in[1]->vec, in[2]->data, in[2]->vec, do_brightnesscontrast, CB_RGBA, CB_VAL, CB_VAL);
out[0]->data = stackbuf;
if (cbuf != in[0]->data)
free_compbuf(cbuf);
}
}
#endif /* WITH_COMPOSITOR_LEGACY */
void register_node_type_cmp_brightcontrast(bNodeTreeType *ttype)
{
@@ -103,9 +55,6 @@ void register_node_type_cmp_brightcontrast(bNodeTreeType *ttype)
node_type_base(ttype, &ntype, CMP_NODE_BRIGHTCONTRAST, "Bright/Contrast", NODE_CLASS_OP_COLOR, NODE_OPTIONS);
node_type_socket_templates(&ntype, cmp_node_brightcontrast_in, cmp_node_brightcontrast_out);
node_type_size(&ntype, 140, 100, 320);
#ifdef WITH_COMPOSITOR_LEGACY
node_type_exec(&ntype, node_composit_exec_brightcontrast);
#endif
nodeRegisterType(ttype, &ntype);
}

View File

@@ -45,153 +45,6 @@ static bNodeSocketTemplate cmp_node_channel_matte_out[] ={
{-1, 0, ""}
};
#ifdef WITH_COMPOSITOR_LEGACY
static void do_normalized_rgba_to_ycca2(bNode *UNUSED(node), float *out, float *in)
{
/*normalize to the range 0.0 to 1.0) */
rgb_to_ycc(in[0], in[1], in[2], &out[0], &out[1], &out[2], BLI_YCC_ITU_BT601);
out[0]=(out[0])/255.0f;
out[1]=(out[1])/255.0f;
out[2]=(out[2])/255.0f;
out[3]=in[3];
}
static void do_normalized_ycca_to_rgba2(bNode *UNUSED(node), float *out, float *in)
{
/*un-normalize the normalize from above */
in[0]=in[0]*255.0f;
in[1]=in[1]*255.0f;
in[2]=in[2]*255.0f;
ycc_to_rgb(in[0], in[1], in[2], &out[0], &out[1], &out[2], BLI_YCC_ITU_BT601);
out[3]=in[3];
}
static void do_channel_matte(bNode *node, float *out, float *in)
{
NodeChroma *c=(NodeChroma *)node->storage;
float alpha=0.0;
switch (c->algorithm) {
case 0: { /* Alpha=key_channel-limit channel */
int key_channel=node->custom2-1;
int limit_channel=c->channel-1;
alpha=in[key_channel]-in[limit_channel];
break;
}
case 1: { /* Alpha=G-MAX(R, B) */
switch (node->custom2) {
case 1:
{
alpha=in[0]-MAX2(in[1], in[2]);
break;
}
case 2:
{
alpha=in[1]-MAX2(in[0], in[2]);
break;
}
case 3:
{
alpha=in[2]-MAX2(in[0], in[1]);
break;
}
default:
break;
}
break;
}
default:
break;
}
/*flip because 0.0 is transparent, not 1.0*/
alpha=1-alpha;
/* test range*/
if (alpha>c->t1) {
alpha=in[3]; /*whatever it was prior */
}
else if (alpha<c->t2) {
alpha=0.0;
}
else {/*blend */
alpha=(alpha-c->t2)/(c->t1-c->t2);
}
/* don't make something that was more transparent less transparent */
if (alpha<in[3]) {
out[3]=alpha;
}
else {
out[3]=in[3];
}
}
static void node_composit_exec_channel_matte(void *data, bNode *node, bNodeStack **in, bNodeStack **out)
{
CompBuf *cbuf;
CompBuf *outbuf;
if (in[0]->hasinput==0) return;
if (in[0]->data==NULL) return;
if (out[0]->hasoutput==0 && out[1]->hasoutput==0) return;
cbuf=typecheck_compbuf(in[0]->data, CB_RGBA);
outbuf=dupalloc_compbuf(cbuf);
/*convert to colorspace*/
switch (node->custom1) {
case CMP_NODE_CHANNEL_MATTE_CS_RGB:
break;
case CMP_NODE_CHANNEL_MATTE_CS_HSV: /*HSV*/
composit1_pixel_processor(node, outbuf, cbuf, in[1]->vec, do_rgba_to_hsva, CB_RGBA);
break;
case CMP_NODE_CHANNEL_MATTE_CS_YUV: /*YUV*/
composit1_pixel_processor(node, outbuf, cbuf, in[1]->vec, do_rgba_to_yuva, CB_RGBA);
break;
case CMP_NODE_CHANNEL_MATTE_CS_YCC: /*YCC*/
composit1_pixel_processor(node, outbuf, cbuf, in[1]->vec, do_normalized_rgba_to_ycca2, CB_RGBA);
break;
default:
break;
}
/*use the selected channel information to do the key */
composit1_pixel_processor(node, outbuf, outbuf, in[1]->vec, do_channel_matte, CB_RGBA);
/*convert back to RGB colorspace in place*/
switch (node->custom1) {
case CMP_NODE_CHANNEL_MATTE_CS_RGB: /*RGB*/
break;
case CMP_NODE_CHANNEL_MATTE_CS_HSV: /*HSV*/
composit1_pixel_processor(node, outbuf, outbuf, in[1]->vec, do_hsva_to_rgba, CB_RGBA);
break;
case CMP_NODE_CHANNEL_MATTE_CS_YUV: /*YUV*/
composit1_pixel_processor(node, outbuf, outbuf, in[1]->vec, do_yuva_to_rgba, CB_RGBA);
break;
case CMP_NODE_CHANNEL_MATTE_CS_YCC: /*YCC*/
composit1_pixel_processor(node, outbuf, outbuf, in[1]->vec, do_normalized_ycca_to_rgba2, CB_RGBA);
break;
default:
break;
}
generate_preview(data, node, outbuf);
out[0]->data=outbuf;
if (out[1]->hasoutput)
out[1]->data=valbuf_from_rgbabuf(outbuf, CHAN_A);
if (cbuf!=in[0]->data)
free_compbuf(cbuf);
}
#endif /* WITH_COMPOSITOR_LEGACY */
static void node_composit_init_channel_matte(bNodeTree *UNUSED(ntree), bNode *node, bNodeTemplate *UNUSED(ntemp))
{
NodeChroma *c= MEM_callocN(sizeof(NodeChroma), "node chroma");
@@ -216,9 +69,6 @@ void register_node_type_cmp_channel_matte(bNodeTreeType *ttype)
node_type_size(&ntype, 200, 80, 250);
node_type_init(&ntype, node_composit_init_channel_matte);
node_type_storage(&ntype, "NodeChroma", node_free_standard_storage, node_copy_standard_storage);
#ifdef WITH_COMPOSITOR_LEGACY
node_type_exec(&ntype, node_composit_exec_channel_matte);
#endif
nodeRegisterType(ttype, &ntype);
}

View File

@@ -45,136 +45,6 @@ static bNodeSocketTemplate cmp_node_chroma_out[] = {
{-1, 0, ""}
};
#ifdef WITH_COMPOSITOR_LEGACY
static void do_rgba_to_ycca_normalized(bNode *UNUSED(node), float *out, float *in)
{
rgb_to_ycc(in[0], in[1], in[2], &out[0], &out[1], &out[2], BLI_YCC_ITU_BT601);
//normalize to 0..1.0
out[0]=out[0]/255.0f;
out[1]=out[1]/255.0f;
out[2]=out[2]/255.0f;
//rescale to -1.0..1.0
out[0]=(out[0]*2.0f)-1.0f;
out[1]=(out[1]*2.0f)-1.0f;
out[2]=(out[2]*2.0f)-1.0f;
// out[0]=((out[0])-16)/255.0;
// out[1]=((out[1])-128)/255.0;
// out[2]=((out[2])-128)/255.0;
out[3]=in[3];
}
static void do_ycca_to_rgba_normalized(bNode *UNUSED(node), float *out, float *in)
{
/*un-normalize the normalize from above */
in[0]=(in[0]+1.0f)/2.0f;
in[1]=(in[1]+1.0f)/2.0f;
in[2]=(in[2]+1.0f)/2.0f;
in[0]=(in[0]*255.0f);
in[1]=(in[1]*255.0f);
in[2]=(in[2]*255.0f);
// in[0]=(in[0]*255.0)+16;
// in[1]=(in[1]*255.0)+128;
// in[2]=(in[2]*255.0)+128;
ycc_to_rgb(in[0], in[1], in[2], &out[0], &out[1], &out[2], BLI_YCC_ITU_BT601);
out[3]=in[3];
}
static void do_chroma_key(bNode *node, float *out, float *in)
{
NodeChroma *c;
float x, z, alpha;
float theta, beta, angle, angle2;
float kfg;
c=node->storage;
/* Algorithm from book "Video Demistified," does not include the spill reduction part */
/* find theta, the angle that the color space should be rotated based on key chroma values*/
theta=atan2(c->key[2], c->key[1]);
/*rotate the cb and cr into x/z space */
x=in[1]*cosf(theta)+in[2]*sinf(theta);
z=in[2]*cosf(theta)-in[1]*sinf(theta);
/*if within the acceptance angle */
angle=c->t1; /* t1 is radians. */
/* if kfg is <0 then the pixel is outside of the key color */
kfg= x-(fabsf(z)/tanf(angle/2.0f));
copy_v3_v3(out, in);
if (kfg>0.0f) { /* found a pixel that is within key color */
beta=atan2(z, x);
angle2=c->t2; /* t2 is radians. */
/* if beta is within the cutoff angle */
if (fabsf(beta) < (angle2/2.0f)) {
alpha=0.0;
}
else {
alpha=1.0f-(kfg/c->fstrength);
}
/* don't make something that was more transparent less transparent */
if (alpha<in[3]) {
out[3]=alpha;
}
else {
out[3]=in[3];
}
}
else { /* make pixel just as transparent as it was before */
out[3]=in[3];
}
}
static void node_composit_exec_chroma_matte(void *data, bNode *node, bNodeStack **in, bNodeStack **out)
{
CompBuf *cbuf;
CompBuf *chromabuf;
NodeChroma *c;
if (in[0]->hasinput==0) return;
if (in[0]->data==NULL) return;
if (out[0]->hasoutput==0 && out[1]->hasoutput==0) return;
cbuf= typecheck_compbuf(in[0]->data, CB_RGBA);
chromabuf= dupalloc_compbuf(cbuf);
c=node->storage;
/*convert rgbbuf to normalized chroma space*/
composit1_pixel_processor(node, chromabuf, cbuf, in[0]->vec, do_rgba_to_ycca_normalized, CB_RGBA);
/*convert key to normalized chroma color space */
do_rgba_to_ycca_normalized(node, c->key, in[1]->vec);
/*per pixel chroma key*/
composit1_pixel_processor(node, chromabuf, chromabuf, in[0]->vec, do_chroma_key, CB_RGBA);
/*convert back*/
composit1_pixel_processor(node, chromabuf, chromabuf, in[0]->vec, do_ycca_to_rgba_normalized, CB_RGBA);
out[0]->data= chromabuf;
if (out[1]->hasoutput)
out[1]->data= valbuf_from_rgbabuf(chromabuf, CHAN_A);
generate_preview(data, node, chromabuf);
if (cbuf!=in[0]->data)
free_compbuf(cbuf);
}
#endif /* WITH_COMPOSITOR_LEGACY */
static void node_composit_init_chroma_matte(bNodeTree *UNUSED(ntree), bNode *node, bNodeTemplate *UNUSED(ntemp))
{
NodeChroma *c= MEM_callocN(sizeof(NodeChroma), "node chroma");
@@ -195,9 +65,6 @@ void register_node_type_cmp_chroma_matte(bNodeTreeType *ttype)
node_type_size(&ntype, 200, 80, 300);
node_type_init(&ntype, node_composit_init_chroma_matte);
node_type_storage(&ntype, "NodeChroma", node_free_standard_storage, node_copy_standard_storage);
#ifdef WITH_COMPOSITOR_LEGACY
node_type_exec(&ntype, node_composit_exec_chroma_matte);
#endif
nodeRegisterType(ttype, &ntype);
}

View File

@@ -45,77 +45,6 @@ static bNodeSocketTemplate cmp_node_color_out[] = {
{-1, 0, ""}
};
#ifdef WITH_COMPOSITOR_LEGACY
static void do_color_key(bNode *node, float *out, float *in)
{
float h_wrap;
NodeChroma *c;
c=node->storage;
copy_v3_v3(out, in);
if (
/* do hue last because it needs to wrap, and does some more checks */
/* sat */ (fabsf(in[1]-c->key[1]) < c->t2) &&
/* val */ (fabsf(in[2]-c->key[2]) < c->t3) &&
/* multiply by 2 because it wraps on both sides of the hue,
* otherwise 0.5 would key all hue's */
/* hue */ ((h_wrap= 2.0f * fabsf(in[0]-c->key[0])) < c->t1 || (2.0f - h_wrap) < c->t1)
) {
out[3]=0.0; /*make transparent*/
}
else { /*pixel is outside key color */
out[3]=in[3]; /* make pixel just as transparent as it was before */
}
}
static void node_composit_exec_color_matte(void *data, bNode *node, bNodeStack **in, bNodeStack **out)
{
CompBuf *cbuf;
CompBuf *colorbuf;
NodeChroma *c;
if (in[0]->hasinput==0) return;
if (in[0]->data==NULL) return;
if (out[0]->hasoutput==0 && out[1]->hasoutput==0) return;
cbuf= typecheck_compbuf(in[0]->data, CB_RGBA);
colorbuf= dupalloc_compbuf(cbuf);
c=node->storage;
/*convert rgbbuf to hsv*/
composit1_pixel_processor(node, colorbuf, cbuf, in[0]->vec, do_rgba_to_hsva, CB_RGBA);
/*convert key to hsv*/
do_rgba_to_hsva(node, c->key, in[1]->vec);
/*per pixel color key*/
composit1_pixel_processor(node, colorbuf, colorbuf, in[0]->vec, do_color_key, CB_RGBA);
/*convert back*/
composit1_pixel_processor(node, colorbuf, colorbuf, in[0]->vec, do_hsva_to_rgba, CB_RGBA);
out[0]->data= colorbuf;
if (out[1]->hasoutput)
out[1]->data= valbuf_from_rgbabuf(colorbuf, CHAN_A);
generate_preview(data, node, colorbuf);
if (cbuf!=in[0]->data)
free_compbuf(cbuf);
}
#endif /* WITH_COMPOSITOR_LEGACY */
static void node_composit_init_color_matte(bNodeTree *UNUSED(ntree), bNode *node, bNodeTemplate *UNUSED(ntemp))
{
NodeChroma *c= MEM_callocN(sizeof(NodeChroma), "node color");
@@ -136,9 +65,6 @@ void register_node_type_cmp_color_matte(bNodeTreeType *ttype)
node_type_size(&ntype, 200, 80, 300);
node_type_init(&ntype, node_composit_init_color_matte);
node_type_storage(&ntype, "NodeChroma", node_free_standard_storage, node_copy_standard_storage);
#ifdef WITH_COMPOSITOR_LEGACY
node_type_exec(&ntype, node_composit_exec_color_matte);
#endif
nodeRegisterType(ttype, &ntype);
}

View File

@@ -43,281 +43,6 @@ static bNodeSocketTemplate cmp_node_color_spill_out[] = {
{-1, 0, ""}
};
#ifdef WITH_COMPOSITOR_LEGACY
#define AVG(a, b) ((a + b) / 2)
static void do_simple_spillmap_red(bNode *node, float* out, float *in)
{
NodeColorspill *ncs;
ncs=node->storage;
out[0]=in[0]-( ncs->limscale * in[ncs->limchan] );
}
static void do_simple_spillmap_red_fac(bNode *node, float* out, float *in, float *fac)
{
NodeColorspill *ncs;
ncs=node->storage;
out[0] = *fac * (in[0]-( ncs->limscale * in[ncs->limchan]));
}
static void do_simple_spillmap_green(bNode *node, float* out, float *in)
{
NodeColorspill *ncs;
ncs=node->storage;
out[0]=in[1]-( ncs->limscale * in[ncs->limchan] );
}
static void do_simple_spillmap_green_fac(bNode *node, float* out, float *in, float *fac)
{
NodeColorspill *ncs;
ncs=node->storage;
out[0] = *fac * (in[1]-( ncs->limscale * in[ncs->limchan]));
}
static void do_simple_spillmap_blue(bNode *node, float* out, float *in)
{
NodeColorspill *ncs;
ncs=node->storage;
out[0]=in[2]-( ncs->limscale * in[ncs->limchan] );
}
static void do_simple_spillmap_blue_fac(bNode *node, float* out, float *in, float *fac)
{
NodeColorspill *ncs;
ncs=node->storage;
out[0] = *fac * (in[2]-( ncs->limscale * in[ncs->limchan]));
}
static void do_average_spillmap_red(bNode *node, float* out, float *in)
{
NodeColorspill *ncs;
ncs=node->storage;
out[0]=in[0]-(ncs->limscale * AVG(in[1], in[2]) );
}
static void do_average_spillmap_red_fac(bNode *node, float* out, float *in, float *fac)
{
NodeColorspill *ncs;
ncs=node->storage;
out[0] = *fac * (in[0]-(ncs->limscale * AVG(in[1], in[2]) ));
}
static void do_average_spillmap_green(bNode *node, float* out, float *in)
{
NodeColorspill *ncs;
ncs=node->storage;
out[0]=in[1]-(ncs->limscale * AVG(in[0], in[2]) );
}
static void do_average_spillmap_green_fac(bNode *node, float* out, float *in, float *fac)
{
NodeColorspill *ncs;
ncs=node->storage;
out[0] = *fac * (in[0]-(ncs->limscale * AVG(in[0], in[2]) ));
}
static void do_average_spillmap_blue(bNode *node, float* out, float *in)
{
NodeColorspill *ncs;
ncs=node->storage;
out[0]=in[2]-(ncs->limscale * AVG(in[0], in[1]) );
}
static void do_average_spillmap_blue_fac(bNode *node, float* out, float *in, float *fac)
{
NodeColorspill *ncs;
ncs=node->storage;
out[0] = *fac * (in[0]-(ncs->limscale * AVG(in[0], in[1]) ));
}
static void do_apply_spillmap_red(bNode *node, float* out, float *in, float *map)
{
NodeColorspill *ncs;
ncs=node->storage;
if (map[0]>0) {
out[0]=in[0]-(ncs->uspillr*map[0]);
out[1]=in[1]+(ncs->uspillg*map[0]);
out[2]=in[2]+(ncs->uspillb*map[0]);
}
else {
out[0]=in[0];
out[1]=in[1];
out[2]=in[2];
}
}
static void do_apply_spillmap_green(bNode *node, float* out, float *in, float *map)
{
NodeColorspill *ncs;
ncs=node->storage;
if (map[0]>0) {
out[0]=in[0]+(ncs->uspillr*map[0]);
out[1]=in[1]-(ncs->uspillg*map[0]);
out[2]=in[2]+(ncs->uspillb*map[0]);
}
else {
out[0]=in[0];
out[1]=in[1];
out[2]=in[2];
}
}
static void do_apply_spillmap_blue(bNode *node, float* out, float *in, float *map)
{
NodeColorspill *ncs;
ncs=node->storage;
if (map[0]>0) {
out[0]=in[0]+(ncs->uspillr*map[0]);
out[1]=in[1]+(ncs->uspillg*map[0]);
out[2]=in[2]-(ncs->uspillb*map[0]);
}
else {
out[0]=in[0];
out[1]=in[1];
out[2]=in[2];
}
}
static void node_composit_exec_color_spill(void *UNUSED(data), bNode *node, bNodeStack **in, bNodeStack **out)
{
/* Originally based on the information from the book "The Art and Science of Digital Composition" and
* discussions from vfxtalk.com .*/
CompBuf *cbuf;
/* CompBuf *mask; */ /* UNUSED */
CompBuf *rgbbuf;
CompBuf *spillmap;
NodeColorspill *ncs;
ncs=node->storage;
/* early out for missing connections */
if (out[0]->hasoutput==0 ) return;
if (in[0]->hasinput==0) return;
if (in[0]->data==NULL) return;
cbuf=typecheck_compbuf(in[0]->data, CB_RGBA);
/* mask= */ /* UNUSED */ typecheck_compbuf(in[1]->data, CB_VAL);
spillmap=alloc_compbuf(cbuf->x, cbuf->y, CB_VAL, 1);
rgbbuf=dupalloc_compbuf(cbuf);
switch (node->custom1) {
case 1: /*red spill*/
{
switch (node->custom2) {
case 0: /* simple limit */
{
if ((in[1]->data==NULL) && (in[1]->vec[0] >= 1.f)) {
composit1_pixel_processor(node, spillmap, cbuf, in[0]->vec, do_simple_spillmap_red, CB_RGBA);
}
else {
composit2_pixel_processor(node, spillmap, cbuf, in[0]->vec, in[1]->data, in[1]->vec, do_simple_spillmap_red_fac, CB_RGBA, CB_VAL);
}
break;
}
case 1: /* average limit */
{
if ((in[1]->data==NULL) && (in[1]->vec[0] >= 1.f)) {
composit1_pixel_processor(node, spillmap, cbuf, in[0]->vec, do_average_spillmap_red, CB_RGBA);
}
else {
composit2_pixel_processor(node, spillmap, cbuf, in[0]->vec, in[1]->data, in[1]->vec, do_average_spillmap_red_fac, CB_RGBA, CB_VAL);
}
break;
}
}
if (ncs->unspill==0) {
ncs->uspillr=1.0f;
ncs->uspillg=0.0f;
ncs->uspillb=0.0f;
}
composit2_pixel_processor(node, rgbbuf, cbuf, in[0]->vec, spillmap, NULL, do_apply_spillmap_red, CB_RGBA, CB_VAL);
break;
}
case 2: /*green spill*/
{
switch (node->custom2) {
case 0: /* simple limit */
{
if ((in[1]->data==NULL) && (in[1]->vec[0] >= 1.f)) {
composit1_pixel_processor(node, spillmap, cbuf, in[0]->vec, do_simple_spillmap_green, CB_RGBA);
}
else {
composit2_pixel_processor(node, spillmap, cbuf, in[0]->vec, in[1]->data, in[1]->vec, do_simple_spillmap_green_fac, CB_RGBA, CB_VAL);
}
break;
}
case 1: /* average limit */
{
if ((in[1]->data==NULL) && (in[1]->vec[0] >= 1.f)) {
composit1_pixel_processor(node, spillmap, cbuf, in[0]->vec, do_average_spillmap_green, CB_RGBA);
}
else {
composit2_pixel_processor(node, spillmap, cbuf, in[0]->vec, in[1]->data, in[1]->vec, do_average_spillmap_green_fac, CB_RGBA, CB_VAL);
}
break;
}
}
if (ncs->unspill==0) {
ncs->uspillr=0.0f;
ncs->uspillg=1.0f;
ncs->uspillb=0.0f;
}
composit2_pixel_processor(node, rgbbuf, cbuf, in[0]->vec, spillmap, NULL, do_apply_spillmap_green, CB_RGBA, CB_VAL);
break;
}
case 3: /*blue spill*/
{
switch (node->custom2) {
case 0: /* simple limit */
{
if ((in[1]->data==NULL) && (in[1]->vec[0] >= 1.f)) {
composit1_pixel_processor(node, spillmap, cbuf, in[0]->vec, do_simple_spillmap_blue, CB_RGBA);
}
else {
composit2_pixel_processor(node, spillmap, cbuf, in[0]->vec, in[1]->data, in[1]->vec, do_simple_spillmap_blue_fac, CB_RGBA, CB_VAL);
}
break;
}
case 1: /* average limit */
{
if ((in[1]->data==NULL) && (in[1]->vec[0] >= 1.f)) {
composit1_pixel_processor(node, spillmap, cbuf, in[0]->vec, do_average_spillmap_blue, CB_RGBA);
}
else {
composit2_pixel_processor(node, spillmap, cbuf, in[0]->vec, in[1]->data, in[1]->vec, do_average_spillmap_blue_fac, CB_RGBA, CB_VAL);
}
break;
}
}
if (ncs->unspill==0) {
ncs->uspillr=0.0f;
ncs->uspillg=0.0f;
ncs->uspillb=1.0f;
}
composit2_pixel_processor(node, rgbbuf, cbuf, in[0]->vec, spillmap, NULL, do_apply_spillmap_blue, CB_RGBA, CB_VAL);
break;
}
default:
break;
}
out[0]->data=rgbbuf;
if (cbuf!=in[0]->data)
free_compbuf(cbuf);
free_compbuf(spillmap);
}
#endif /* WITH_COMPOSITOR_LEGACY */
static void node_composit_init_color_spill(bNodeTree *UNUSED(ntree), bNode *node, bNodeTemplate *UNUSED(ntemp))
{
NodeColorspill *ncs= MEM_callocN(sizeof(NodeColorspill), "node colorspill");
@@ -338,9 +63,6 @@ void register_node_type_cmp_color_spill(bNodeTreeType *ttype)
node_type_size(&ntype, 140, 80, 200);
node_type_init(&ntype, node_composit_init_color_spill);
node_type_storage(&ntype, "NodeColorspill", node_free_standard_storage, node_copy_standard_storage);
#ifdef WITH_COMPOSITOR_LEGACY
node_type_exec(&ntype, node_composit_exec_color_spill);
#endif
nodeRegisterType(ttype, &ntype);
}

View File

@@ -46,138 +46,6 @@ static bNodeSocketTemplate cmp_node_colorbalance_out[] = {
{-1, 0, ""}
};
#ifdef WITH_COMPOSITOR_LEGACY
/* this function implements ASC-CDL according to the spec at http://www.asctech.org/
* Slope
* S = in * slope
* Offset
* O = S + offset
* = (in * slope) + offset
* Power
* out = Clamp(O) ^ power
* = Clamp((in * slope) + offset) ^ power
*/
BLI_INLINE float colorbalance_cdl(float in, float offset, float power, float slope)
{
float x = in * slope + offset;
/* prevent NaN */
CLAMP(x, 0.0f, 1.0f);
return powf(x, power);
}
/* note: lift_lgg is just 2-lift, gamma_inv is 1.0/gamma */
BLI_INLINE float colorbalance_lgg(float in, float lift_lgg, float gamma_inv, float gain)
{
/* 1:1 match with the sequencer with linear/srgb conversions, the conversion isn't pretty
* but best keep it this way, since testing for durian shows a similar calculation
* without lin/srgb conversions gives bad results (over-saturated shadows) with colors
* slightly below 1.0. some correction can be done but it ends up looking bad for shadows or lighter tones - campbell */
float x= (((linearrgb_to_srgb(in) - 1.0f) * lift_lgg) + 1.0f) * gain;
/* prevent NaN */
if (x < 0.f) x = 0.f;
return powf(srgb_to_linearrgb(x), gamma_inv);
}
static void do_colorbalance_cdl(bNode *node, float* out, float *in)
{
NodeColorBalance *n= (NodeColorBalance *)node->storage;
out[0] = colorbalance_cdl(in[0], n->lift[0], n->gamma[0], n->gain[0]);
out[1] = colorbalance_cdl(in[1], n->lift[1], n->gamma[1], n->gain[1]);
out[2] = colorbalance_cdl(in[2], n->lift[2], n->gamma[2], n->gain[2]);
out[3] = in[3];
}
static void do_colorbalance_cdl_fac(bNode *node, float* out, float *in, float *fac)
{
NodeColorBalance *n= (NodeColorBalance *)node->storage;
const float mfac= 1.0f - *fac;
out[0] = mfac*in[0] + *fac * colorbalance_cdl(in[0], n->lift[0], n->gamma[0], n->gain[0]);
out[1] = mfac*in[1] + *fac * colorbalance_cdl(in[1], n->lift[1], n->gamma[1], n->gain[1]);
out[2] = mfac*in[2] + *fac * colorbalance_cdl(in[2], n->lift[2], n->gamma[2], n->gain[2]);
out[3] = in[3];
}
static void do_colorbalance_lgg(bNode *node, float* out, float *in)
{
NodeColorBalance *n= (NodeColorBalance *)node->storage;
out[0] = colorbalance_lgg(in[0], n->lift_lgg[0], n->gamma_inv[0], n->gain[0]);
out[1] = colorbalance_lgg(in[1], n->lift_lgg[1], n->gamma_inv[1], n->gain[1]);
out[2] = colorbalance_lgg(in[2], n->lift_lgg[2], n->gamma_inv[2], n->gain[2]);
out[3] = in[3];
}
static void do_colorbalance_lgg_fac(bNode *node, float* out, float *in, float *fac)
{
NodeColorBalance *n= (NodeColorBalance *)node->storage;
const float mfac= 1.0f - *fac;
out[0] = mfac*in[0] + *fac * colorbalance_lgg(in[0], n->lift_lgg[0], n->gamma_inv[0], n->gain[0]);
out[1] = mfac*in[1] + *fac * colorbalance_lgg(in[1], n->lift_lgg[1], n->gamma_inv[1], n->gain[1]);
out[2] = mfac*in[2] + *fac * colorbalance_lgg(in[2], n->lift_lgg[2], n->gamma_inv[2], n->gain[2]);
out[3] = in[3];
}
static void node_composit_exec_colorbalance(void *UNUSED(data), bNode *node, bNodeStack **in, bNodeStack **out)
{
CompBuf *cbuf= in[1]->data;
CompBuf *stackbuf;
/* stack order input: fac, image */
/* stack order output: image */
if (out[0]->hasoutput==0) return;
if (in[0]->vec[0] == 0.f && in[0]->data == NULL) {
out[0]->data = pass_on_compbuf(cbuf);
return;
}
{
NodeColorBalance *n= (NodeColorBalance *)node->storage;
int c;
for (c = 0; c < 3; c++) {
n->lift_lgg[c] = 2.0f - n->lift[c];
n->gamma_inv[c] = (n->gamma[c] != 0.0f) ? 1.0f/n->gamma[c] : 1000000.0f;
}
}
if (cbuf) {
stackbuf= alloc_compbuf(cbuf->x, cbuf->y, CB_RGBA, 1); /* create output based on image input */
if (node->custom1 == 0) {
/* lift gamma gain */
if ((in[0]->data==NULL) && (in[0]->vec[0] >= 1.f)) {
composit1_pixel_processor(node, stackbuf, in[1]->data, in[1]->vec, do_colorbalance_lgg, CB_RGBA);
}
else {
composit2_pixel_processor(node, stackbuf, in[1]->data, in[1]->vec, in[0]->data, in[0]->vec, do_colorbalance_lgg_fac, CB_RGBA, CB_VAL);
}
}
else {
/* offset/power/slope : ASC-CDL */
if ((in[0]->data==NULL) && (in[0]->vec[0] >= 1.f)) {
composit1_pixel_processor(node, stackbuf, in[1]->data, in[1]->vec, do_colorbalance_cdl, CB_RGBA);
}
else {
composit2_pixel_processor(node, stackbuf, in[1]->data, in[1]->vec, in[0]->data, in[0]->vec, do_colorbalance_cdl_fac, CB_RGBA, CB_VAL);
}
}
out[0]->data=stackbuf;
}
}
#endif /* WITH_COMPOSITOR_LEGACY */
static void node_composit_init_colorbalance(bNodeTree *UNUSED(ntree), bNode *node, bNodeTemplate *UNUSED(ntemp))
{
NodeColorBalance *n= node->storage= MEM_callocN(sizeof(NodeColorBalance), "node colorbalance");
@@ -196,9 +64,6 @@ void register_node_type_cmp_colorbalance(bNodeTreeType *ttype)
node_type_size(&ntype, 400, 200, 400);
node_type_init(&ntype, node_composit_init_colorbalance);
node_type_storage(&ntype, "NodeColorBalance", node_free_standard_storage, node_copy_standard_storage);
#ifdef WITH_COMPOSITOR_LEGACY
node_type_exec(&ntype, node_composit_exec_colorbalance);
#endif
nodeRegisterType(ttype, &ntype);
}

View File

@@ -183,9 +183,6 @@ static void group_free_internal(bNodeTreeExec *gexec)
for (i = 0, ns = gexec->stack; i < gexec->stacksize; ++i, ++ns) {
if (!ns->external && !ns->is_copy) {
if (ns->data) {
#ifdef WITH_COMPOSITOR_LEGACY
free_compbuf(ns->data);
#endif
ns->data = NULL;
}
}

View File

@@ -39,65 +39,6 @@ static bNodeSocketTemplate cmp_node_composite_in[] = {
{ -1, 0, "" }
};
#ifdef WITH_COMPOSITOR_LEGACY
/* applies to render pipeline */
static void node_composit_exec_composite(void *data, bNode *node, bNodeStack **in, bNodeStack **UNUSED(out))
{
/* image assigned to output */
/* stack order input sockets: col, alpha, z */
if (node->flag & NODE_DO_OUTPUT) { /* only one works on out */
Scene *scene= (Scene *)node->id;
RenderData *rd= data;
if (scene && (rd->scemode & R_DOCOMP)) {
Render *re= RE_GetRender(scene->id.name);
RenderResult *rr= RE_AcquireResultWrite(re);
if (rr) {
CompBuf *outbuf, *zbuf=NULL;
if (rr->rectf)
MEM_freeN(rr->rectf);
outbuf= alloc_compbuf(rr->rectx, rr->recty, CB_RGBA, 1);
if (in[1]->data==NULL)
composit1_pixel_processor(node, outbuf, in[0]->data, in[0]->vec, do_copy_rgba, CB_RGBA);
else
composit2_pixel_processor(node, outbuf, in[0]->data, in[0]->vec, in[1]->data, in[1]->vec, do_copy_a_rgba, CB_RGBA, CB_VAL);
if (in[2]->data) {
if (rr->rectz)
MEM_freeN(rr->rectz);
zbuf= alloc_compbuf(rr->rectx, rr->recty, CB_VAL, 1);
composit1_pixel_processor(node, zbuf, in[2]->data, in[2]->vec, do_copy_value, CB_VAL);
rr->rectz= zbuf->rect;
zbuf->malloc= 0;
free_compbuf(zbuf);
}
generate_preview(data, node, outbuf);
/* we give outbuf to rr... */
rr->rectf= outbuf->rect;
outbuf->malloc= 0;
free_compbuf(outbuf);
/* signal for imageviewer to refresh (it converts to byte rects...) */
BKE_image_signal(BKE_image_verify_viewer(IMA_TYPE_R_RESULT, "Render Result"), NULL, IMA_SIGNAL_FREE);
RE_ReleaseResult(re);
return;
}
else
RE_ReleaseResult(re);
}
}
if (in[0]->data)
generate_preview(data, node, in[0]->data);
}
#endif /* WITH_COMPOSITOR_LEGACY */
void register_node_type_cmp_composite(bNodeTreeType *ttype)
{
static bNodeType ntype;
@@ -105,9 +46,6 @@ void register_node_type_cmp_composite(bNodeTreeType *ttype)
node_type_base(ttype, &ntype, CMP_NODE_COMPOSITE, "Composite", NODE_CLASS_OUTPUT, NODE_PREVIEW);
node_type_socket_templates(&ntype, cmp_node_composite_in, NULL);
node_type_size(&ntype, 80, 60, 200);
#ifdef WITH_COMPOSITOR_LEGACY
node_type_exec(&ntype, node_composit_exec_composite);
#endif
/* Do not allow muting for this node. */
node_type_internal_links(&ntype, NULL);

View File

@@ -43,68 +43,6 @@ static bNodeSocketTemplate cmp_node_crop_out[] = {
{ -1, 0, "" }
};
#ifdef WITH_COMPOSITOR_LEGACY
static void node_composit_exec_crop(void *UNUSED(data), bNode *node, bNodeStack **in, bNodeStack **out)
{
if (in[0]->data) {
NodeTwoXYs *ntxy= node->storage;
CompBuf *cbuf= in[0]->data;
CompBuf *stackbuf;
int x, y;
float *srcfp, *outfp;
rcti outputrect;
if (node->custom2) {
ntxy->x1= cbuf->x* ntxy->fac_x1;
ntxy->x2= cbuf->x* ntxy->fac_x2;
ntxy->y1= cbuf->y* ntxy->fac_y1;
ntxy->y2= cbuf->y* ntxy->fac_y2;
}
/* check input image size */
if (cbuf->x <= ntxy->x1 + 1)
ntxy->x1= cbuf->x - 1;
if (cbuf->y <= ntxy->y1 + 1)
ntxy->y1= cbuf->y - 1;
if (cbuf->x <= ntxy->x2 + 1)
ntxy->x2= cbuf->x - 1;
if (cbuf->y <= ntxy->y2 + 1)
ntxy->y2= cbuf->y - 1;
/* figure out the minimums and maximums */
outputrect.xmax=MAX2(ntxy->x1, ntxy->x2) + 1;
outputrect.xmin=MIN2(ntxy->x1, ntxy->x2);
outputrect.ymax=MAX2(ntxy->y1, ntxy->y2) + 1;
outputrect.ymin=MIN2(ntxy->y1, ntxy->y2);
if (node->custom1) {
/* this option crops the image size too */
stackbuf= get_cropped_compbuf(&outputrect, cbuf->rect, cbuf->x, cbuf->y, cbuf->type);
}
else {
/* this option won't crop the size of the image as well */
/* allocate memory for the output image */
stackbuf = alloc_compbuf(cbuf->x, cbuf->y, cbuf->type, 1);
/* select the cropped part of the image and set it to the output */
for (y=outputrect.ymin; y<outputrect.ymax; y++) {
srcfp= cbuf->rect + (y * cbuf->x + outputrect.xmin) * cbuf->type;
outfp= stackbuf->rect + (y * stackbuf->x + outputrect.xmin) * stackbuf->type;
for (x=outputrect.xmin; x<outputrect.xmax; x++, outfp+= stackbuf->type, srcfp+= cbuf->type)
memcpy(outfp, srcfp, sizeof(float)*stackbuf->type);
}
}
out[0]->data= stackbuf;
}
}
#endif /* WITH_COMPOSITOR_LEGACY */
static void node_composit_init_crop(bNodeTree *UNUSED(ntree), bNode *node, bNodeTemplate *UNUSED(ntemp))
{
NodeTwoXYs *nxy= MEM_callocN(sizeof(NodeTwoXYs), "node xy data");
@@ -124,9 +62,6 @@ void register_node_type_cmp_crop(bNodeTreeType *ttype)
node_type_size(&ntype, 140, 100, 320);
node_type_init(&ntype, node_composit_init_crop);
node_type_storage(&ntype, "NodeTwoXYs", node_free_standard_storage, node_copy_standard_storage);
#ifdef WITH_COMPOSITOR_LEGACY
node_type_exec(&ntype, node_composit_exec_crop);
#endif
nodeRegisterType(ttype, &ntype);
}

View File

@@ -41,25 +41,6 @@ static bNodeSocketTemplate cmp_node_time_out[] = {
{ -1, 0, "" }
};
#ifdef WITH_COMPOSITOR_LEGACY
static void node_composit_exec_curves_time(void *data, bNode *node, bNodeStack **UNUSED(in), bNodeStack **out)
{
RenderData *rd= data;
/* stack order output: fac */
float fac= 0.0f;
if (node->custom1 < node->custom2)
fac= (rd->cfra - node->custom1)/(float)(node->custom2-node->custom1);
curvemapping_initialize(node->storage);
fac = curvemapping_evaluateF(node->storage, 0, fac);
out[0]->vec[0] = CLAMPIS(fac, 0.0f, 1.0f);
}
#endif /* WITH_COMPOSITOR_LEGACY */
static void node_composit_init_curves_time(bNodeTree *UNUSED(ntree), bNode *node, bNodeTemplate *UNUSED(ntemp))
{
node->custom1= 1;
@@ -76,9 +57,6 @@ void register_node_type_cmp_curve_time(bNodeTreeType *ttype)
node_type_size(&ntype, 140, 100, 320);
node_type_init(&ntype, node_composit_init_curves_time);
node_type_storage(&ntype, "CurveMapping", node_free_curves, node_copy_curves);
#ifdef WITH_COMPOSITOR_LEGACY
node_type_exec(&ntype, node_composit_exec_curves_time);
#endif
nodeRegisterType(ttype, &ntype);
}
@@ -96,19 +74,6 @@ static bNodeSocketTemplate cmp_node_curve_vec_out[] = {
{ -1, 0, "" }
};
#ifdef WITH_COMPOSITOR_LEGACY
static void node_composit_exec_curve_vec(void *UNUSED(data), bNode *node, bNodeStack **in, bNodeStack **out)
{
/* stack order input: vec */
/* stack order output: vec */
curvemapping_initialize(node->storage);
curvemapping_evaluate_premulRGBF(node->storage, out[0]->vec, in[0]->vec);
}
#endif /* WITH_COMPOSITOR_LEGACY */
static void node_composit_init_curve_vec(bNodeTree *UNUSED(ntree), bNode *node, bNodeTemplate *UNUSED(ntemp))
{
node->storage= curvemapping_add(3, -1.0f, -1.0f, 1.0f, 1.0f);
@@ -123,9 +88,6 @@ void register_node_type_cmp_curve_vec(bNodeTreeType *ttype)
node_type_size(&ntype, 200, 140, 320);
node_type_init(&ntype, node_composit_init_curve_vec);
node_type_storage(&ntype, "CurveMapping", node_free_curves, node_copy_curves);
#ifdef WITH_COMPOSITOR_LEGACY
node_type_exec(&ntype, node_composit_exec_curve_vec);
#endif
nodeRegisterType(ttype, &ntype);
}
@@ -145,67 +107,6 @@ static bNodeSocketTemplate cmp_node_curve_rgb_out[] = {
{ -1, 0, "" }
};
#ifdef WITH_COMPOSITOR_LEGACY
static void do_curves(bNode *node, float *out, float *in)
{
curvemapping_initialize(node->storage);
curvemapping_evaluate_premulRGBF(node->storage, out, in);
out[3] = in[3];
}
static void do_curves_fac(bNode *node, float *out, float *in, float *fac)
{
curvemapping_initialize(node->storage);
if (*fac >= 1.0f)
curvemapping_evaluate_premulRGBF(node->storage, out, in);
else if (*fac <= 0.0f) {
copy_v3_v3(out, in);
}
else {
float col[4], mfac= 1.0f-*fac;
curvemapping_evaluate_premulRGBF(node->storage, col, in);
out[0] = mfac*in[0] + *fac*col[0];
out[1] = mfac*in[1] + *fac*col[1];
out[2] = mfac*in[2] + *fac*col[2];
}
out[3] = in[3];
}
static void node_composit_exec_curve_rgb(void *UNUSED(data), bNode *node, bNodeStack **in, bNodeStack **out)
{
/* stack order input: fac, image, black level, white level */
/* stack order output: image */
if (out[0]->hasoutput==0)
return;
curvemapping_initialize(node->storage);
/* input no image? then only color operation */
if (in[1]->data==NULL) {
curvemapping_evaluateRGBF(node->storage, out[0]->vec, in[1]->vec);
}
else {
/* make output size of input image */
CompBuf *cbuf= in[1]->data;
CompBuf *stackbuf= alloc_compbuf(cbuf->x, cbuf->y, CB_RGBA, 1); /* allocs */
curvemapping_set_black_white(node->storage, in[2]->vec, in[3]->vec);
if (in[0]->data==NULL && in[0]->vec[0] == 1.0f)
composit1_pixel_processor(node, stackbuf, in[1]->data, in[1]->vec, do_curves, CB_RGBA);
else
composit2_pixel_processor(node, stackbuf, in[1]->data, in[1]->vec, in[0]->data, in[0]->vec, do_curves_fac, CB_RGBA, CB_VAL);
out[0]->data= stackbuf;
}
}
#endif /* WITH_COMPOSITOR_LEGACY */
static void node_composit_init_curve_rgb(bNodeTree *UNUSED(ntree), bNode *node, bNodeTemplate *UNUSED(ntemp))
{
node->storage= curvemapping_add(4, 0.0f, 0.0f, 1.0f, 1.0f);
@@ -220,9 +121,6 @@ void register_node_type_cmp_curve_rgb(bNodeTreeType *ttype)
node_type_size(&ntype, 200, 140, 320);
node_type_init(&ntype, node_composit_init_curve_rgb);
node_type_storage(&ntype, "CurveMapping", node_free_curves, node_copy_curves);
#ifdef WITH_COMPOSITOR_LEGACY
node_type_exec(&ntype, node_composit_exec_curve_rgb);
#endif
nodeRegisterType(ttype, &ntype);
}

View File

@@ -44,830 +44,6 @@ static bNodeSocketTemplate cmp_node_defocus_out[] = {
{ -1, 0, "" }
};
#ifdef WITH_COMPOSITOR_LEGACY
// line coefs for point sampling & scancon. data.
typedef struct BokehCoeffs {
float x0, y0, dx, dy;
float ls_x, ls_y;
float min_x, min_y, max_x, max_y;
} BokehCoeffs;
// returns array of BokehCoeffs
// returns length of array in 'len_bkh',
// radius squared of inscribed disk in 'inradsq', needed in getWeight() test,
// BKH[8] is the data returned for the bokeh shape & bkh_b[4] is it's 2d bound
static void makeBokeh(char bktype, char ro, int* len_bkh, float* inradsq, BokehCoeffs BKH[8], float bkh_b[4])
{
float x0, x1, y0, y1, dx, dy, iDxy;
/* ro now is in radians. */
float w = MAX2(1e-6f, ro); // never reported stangely enough, but a zero offset causes missing center line...
float wi = DEG2RADF(360.f/bktype);
int i, ov, nv;
// bktype must be at least 3 & <= 8
bktype = (bktype<3) ? 3 : ((bktype>8) ? 8 : bktype);
*len_bkh = bktype;
*inradsq = -1.f;
for (i=0; i<(*len_bkh); i++) {
x0 = cos(w);
y0 = sin(w);
w += wi;
x1 = cos(w);
y1 = sin(w);
if ((*inradsq)<0.f) {
// radius squared of inscribed disk
float idx=(x0+x1)*0.5f, idy=(y0+y1)*0.5f;
*inradsq = idx*idx + idy*idy;
}
BKH[i].x0 = x0;
BKH[i].y0 = y0;
dx = x1-x0, dy = y1-y0;
iDxy = 1.f / sqrtf(dx*dx + dy*dy);
dx *= iDxy;
dy *= iDxy;
BKH[i].dx = dx;
BKH[i].dy = dy;
}
// precalc scanconversion data
// bokeh bound, not transformed, for scanconvert
bkh_b[0] = bkh_b[2] = 1e10f; // xmin/ymin
bkh_b[1] = bkh_b[3] = -1e10f; // xmax/ymax
ov = (*len_bkh) - 1;
for (nv=0; nv<(*len_bkh); nv++) {
bkh_b[0] = MIN2(bkh_b[0], BKH[nv].x0); // xmin
bkh_b[1] = MAX2(bkh_b[1], BKH[nv].x0); // xmax
bkh_b[2] = MIN2(bkh_b[2], BKH[nv].y0); // ymin
bkh_b[3] = MAX2(bkh_b[3], BKH[nv].y0); // ymax
BKH[nv].min_x = MIN2(BKH[ov].x0, BKH[nv].x0);
BKH[nv].max_x = MAX2(BKH[ov].x0, BKH[nv].x0);
BKH[nv].min_y = MIN2(BKH[ov].y0, BKH[nv].y0);
BKH[nv].max_y = MAX2(BKH[ov].y0, BKH[nv].y0);
dy = BKH[nv].y0 - BKH[ov].y0;
BKH[nv].ls_x = (BKH[nv].x0 - BKH[ov].x0) / ((dy==0.f) ? 1.f : dy);
BKH[nv].ls_y = (BKH[nv].ls_x==0.f) ? 1.f : (1.f/BKH[nv].ls_x);
ov = nv;
}
}
// test if u/v inside shape & returns weight value
static float getWeight(BokehCoeffs* BKH, int len_bkh, float u, float v, float rad, float inradsq)
{
BokehCoeffs* bc = BKH;
float cdist, irad = (rad==0.f) ? 1.f : (1.f/rad);
u *= irad;
v *= irad;
// early out test1: if point outside outer unit disk, it cannot be inside shape
cdist = u*u + v*v;
if (cdist>1.f) return 0.f;
// early out test2: if point inside or on inner disk, point must be inside shape
if (cdist<=inradsq) return 1.f;
while (len_bkh--) {
if ((bc->dy*(u - bc->x0) - bc->dx*(v - bc->y0)) > 0.f) return 0.f;
bc++;
}
return 1.f;
}
// QMC.seq. for sampling, A.Keller, EMS
static float RI_vdC(unsigned int bits, unsigned int r)
{
bits = ( bits << 16) | ( bits >> 16);
bits = ((bits & 0x00ff00ff) << 8) | ((bits & 0xff00ff00) >> 8);
bits = ((bits & 0x0f0f0f0f) << 4) | ((bits & 0xf0f0f0f0) >> 4);
bits = ((bits & 0x33333333) << 2) | ((bits & 0xcccccccc) >> 2);
bits = ((bits & 0x55555555) << 1) | ((bits & 0xaaaaaaaa) >> 1);
bits ^= r;
return (float)((double)bits / 4294967296.0);
}
// single channel IIR gaussian filtering
// much faster than anything else, constant time independent of width
// should extend to multichannel and make this a node, could be useful
// note: this is an almost exact copy of 'IIR_gauss'
static void IIR_gauss_single(CompBuf *buf, float sigma)
{
double q, q2, sc, cf[4], tsM[9], tsu[3], tsv[3];
float *X, *Y, *W;
const unsigned int src_width = buf->x;
const unsigned int src_height = buf->y;
unsigned int i, x, y, sz;
// single channel only for now
if (buf->type != CB_VAL) return;
// <0.5 not valid, though can have a possibly useful sort of sharpening effect
if (sigma < 0.5f) return;
// see "Recursive Gabor Filtering" by Young/VanVliet
// all factors here in double.prec. Required, because for single.prec it seems to blow up if sigma > ~200
if (sigma >= 3.556f)
q = 0.9804f * (sigma - 3.556f) + 2.5091f;
else // sigma >= 0.5
q = (0.0561f * sigma + 0.5784f) * sigma - 0.2568f;
q2 = q * q;
sc = (1.1668 + q) * (3.203729649 + (2.21566 + q) * q);
// no gabor filtering here, so no complex multiplies, just the regular coefs.
// all negated here, so as not to have to recalc Triggs/Sdika matrix
cf[1] = q * (5.788961737 + (6.76492 + 3.0 * q) * q) / sc;
cf[2] = -q2 * (3.38246 + 3.0 * q) / sc;
// 0 & 3 unchanged
cf[3] = q2 * q / sc;
cf[0] = 1.0 - cf[1] - cf[2] - cf[3];
// Triggs/Sdika border corrections,
// it seems to work, not entirely sure if it is actually totally correct,
// Besides J.M.Geusebroek's anigauss.c (see http://www.science.uva.nl/~mark),
// found one other implementation by Cristoph Lampert,
// but neither seem to be quite the same, result seems to be ok so far anyway.
// Extra scale factor here to not have to do it in filter,
// though maybe this had something to with the precision errors
sc = cf[0] / ((1.0 + cf[1] - cf[2] + cf[3]) * (1.0 - cf[1] - cf[2] - cf[3]) * (1.0 + cf[2] + (cf[1] - cf[3]) * cf[3]));
tsM[0] = sc * (-cf[3] * cf[1] + 1.0 - cf[3] * cf[3] - cf[2]);
tsM[1] = sc * ((cf[3] + cf[1]) * (cf[2] + cf[3] * cf[1]));
tsM[2] = sc * (cf[3] * (cf[1] + cf[3] * cf[2]));
tsM[3] = sc * (cf[1] + cf[3] * cf[2]);
tsM[4] = sc * (-(cf[2] - 1.0) * (cf[2] + cf[3] * cf[1]));
tsM[5] = sc * (-(cf[3] * cf[1] + cf[3] * cf[3] + cf[2] - 1.0) * cf[3]);
tsM[6] = sc * (cf[3] * cf[1] + cf[2] + cf[1] * cf[1] - cf[2] * cf[2]);
tsM[7] = sc * (cf[1] * cf[2] + cf[3] * cf[2] * cf[2] - cf[1] * cf[3] * cf[3] - cf[3] * cf[3] * cf[3] - cf[3] * cf[2] + cf[3]);
tsM[8] = sc * (cf[3] * (cf[1] + cf[3] * cf[2]));
#define YVV(L) \
{ \
W[0] = cf[0] * X[0] + cf[1] * X[0] + cf[2] * X[0] + cf[3] * X[0]; \
W[1] = cf[0] * X[1] + cf[1] * W[0] + cf[2] * X[0] + cf[3] * X[0]; \
W[2] = cf[0] * X[2] + cf[1] * W[1] + cf[2] * W[0] + cf[3] * X[0]; \
for (i = 3; i < L; i++) { \
W[i] = cf[0] * X[i] + cf[1] * W[i - 1] + cf[2] * W[i - 2] + cf[3] * W[i - 3]; \
} \
tsu[0] = W[L - 1] - X[L - 1]; \
tsu[1] = W[L - 2] - X[L - 1]; \
tsu[2] = W[L - 3] - X[L - 1]; \
tsv[0] = tsM[0] * tsu[0] + tsM[1] * tsu[1] + tsM[2] * tsu[2] + X[L - 1]; \
tsv[1] = tsM[3] * tsu[0] + tsM[4] * tsu[1] + tsM[5] * tsu[2] + X[L - 1]; \
tsv[2] = tsM[6] * tsu[0] + tsM[7] * tsu[1] + tsM[8] * tsu[2] + X[L - 1]; \
Y[L - 1] = cf[0] * W[L - 1] + cf[1] * tsv[0] + cf[2] * tsv[1] + cf[3] * tsv[2]; \
Y[L - 2] = cf[0] * W[L - 2] + cf[1] * Y[L - 1] + cf[2] * tsv[0] + cf[3] * tsv[1]; \
Y[L - 3] = cf[0] * W[L - 3] + cf[1] * Y[L - 2] + cf[2] * Y[L - 1] + cf[3] * tsv[0]; \
/* 'i != UINT_MAX' is really 'i >= 0', but necessary for unsigned int wrapping */ \
for (i = L - 4; i != UINT_MAX; i--) { \
Y[i] = cf[0] * W[i] + cf[1] * Y[i + 1] + cf[2] * Y[i + 2] + cf[3] * Y[i + 3]; \
} \
} (void)0
// intermediate buffers
sz = MAX2(src_width, src_height);
Y = MEM_callocN(sz * sizeof(float), "IIR_gauss Y buf");
W = MEM_callocN(sz * sizeof(float), "IIR_gauss W buf");
// H
for (y = 0; y < src_height; y++) {
X = &buf->rect[y * src_width];
YVV(src_width);
memcpy(X, Y, sizeof(float) * src_width);
}
// V
X = MEM_callocN(src_height * sizeof(float), "IIR_gauss X buf");
for (x = 0; x < src_width; x++) {
for (y = 0; y < src_height; y++)
X[y] = buf->rect[x + y * src_width];
YVV(src_height);
for (y = 0; y < src_height; y++)
buf->rect[x + y * src_width] = Y[y];
}
MEM_freeN(X);
MEM_freeN(W);
MEM_freeN(Y);
#undef YVV
}
static void defocus_blur(bNode *node, CompBuf *new, CompBuf *img, CompBuf *zbuf, float inpval, int no_zbuf)
{
NodeDefocus *nqd = node->storage;
CompBuf *wts; // weights buffer
CompBuf *crad; // CoC radius buffer
BokehCoeffs BKH[8]; // bokeh shape data, here never > 8 pts.
float bkh_b[4] = {0}; // shape 2D bound
float cam_fdist=1, cam_invfdist=1, cam_lens=35;
float cam_sensor = DEFAULT_SENSOR_WIDTH;
float dof_sp, maxfgc, bk_hn_theta=0, inradsq=0;
int y, len_bkh=0, ydone = FALSE;
float aspect, aperture;
int minsz;
//float bcrad, nmaxc, scf;
// get some required params from the current scene camera
// (ton) this is wrong, needs fixed
Scene *scene= (Scene*)node->id;
Object* camob = (scene)? scene->camera: NULL;
if (camob && camob->type==OB_CAMERA) {
Camera* cam = (Camera*)camob->data;
cam_lens = cam->lens;
cam_fdist = BKE_camera_object_dof_distance(camob);
cam_sensor = BKE_camera_sensor_size(cam->sensor_fit, cam->sensor_x, cam->sensor_y);
if (cam_fdist == 0.0f) cam_fdist = 1e10f; /* if the dof is 0.0 then set it be be far away */
cam_invfdist = 1.f / cam_fdist;
}
// guess work here.. best match with raytraced result
minsz = MIN2(img->x, img->y);
dof_sp = (float)minsz / ((cam_sensor / 2.0f) / cam_lens); // <- == aspect * MIN2(img->x, img->y) / tan(0.5f * fov);
// aperture
aspect = (img->x > img->y) ? (img->y / (float)img->x) : (img->x / (float)img->y);
aperture = 0.5f * (cam_lens / (aspect * cam_sensor)) / nqd->fstop;
// if not disk, make bokeh coefficients and other needed data
if (nqd->bktype!=0) {
makeBokeh(nqd->bktype, nqd->rotation, &len_bkh, &inradsq, BKH, bkh_b);
bk_hn_theta = 0.5 * nqd->bktype * sin(2.0 * M_PI / nqd->bktype); // weight factor
}
// accumulated weights
wts = alloc_compbuf(img->x, img->y, CB_VAL, 1);
// CoC radius buffer
crad = alloc_compbuf(img->x, img->y, CB_VAL, 1);
// if 'no_zbuf' flag set (which is always set if input is not an image),
// values are instead interpreted directly as blur radius values
if (no_zbuf) {
// to prevent *reaaallly* big radius values and impossible calculation times,
// limit the maximum to half the image width or height, whichever is smaller
float maxr = 0.5f*(float)MIN2(img->x, img->y);
unsigned int p;
for (p=0; p<(unsigned int)(img->x*img->y); p++) {
crad->rect[p] = zbuf ? (zbuf->rect[p]*nqd->scale) : inpval;
// bug #5921, limit minimum
crad->rect[p] = MAX2(1e-5f, crad->rect[p]);
crad->rect[p] = MIN2(crad->rect[p], maxr);
// if maxblur!=0, limit maximum
if (nqd->maxblur != 0.f) crad->rect[p] = MIN2(crad->rect[p], nqd->maxblur);
}
}
else {
float wt;
// actual zbuffer.
// separate foreground from background CoC's
// then blur background and blend in again with foreground,
// improves the 'blurred foreground overlapping in-focus midground' sharp boundary problem.
// wts buffer here used for blendmask
maxfgc = 0.f; // maximum foreground CoC radius
for (y=0; y<img->y; y++) {
unsigned int p = y * img->x;
int x;
for (x=0; x<img->x; x++) {
unsigned int px = p + x;
float iZ = (zbuf->rect[px]==0.f) ? 0.f : (1.f/zbuf->rect[px]);
crad->rect[px] = 0.5f*(aperture*(dof_sp*(cam_invfdist - iZ) - 1.f));
if (crad->rect[px] <= 0.f) {
wts->rect[px] = 1.f;
crad->rect[px] = -crad->rect[px];
if (crad->rect[px] > maxfgc) maxfgc = crad->rect[px];
}
else crad->rect[px] = wts->rect[px] = 0;
}
}
// fast blur...
// bug #6656 part 1, probably when previous node_composite.c was split into separate files, it was not properly updated
// to include recent cvs commits (well, at least not defocus node), so this part was missing...
wt = min_ff(nqd->maxblur, aperture * 128.0f);
IIR_gauss_single(crad, wt);
IIR_gauss_single(wts, wt);
// bug #6656 part 2a, although foreground blur is not based anymore on closest object,
// the rescaling op below was still based on that anyway, and unlike the comment in below code,
// the difference is therefore not always that small at all...
// so for now commented out, not sure if this is going to cause other future problems, lets just wait and see...
/*
// find new maximum to scale it back to original
// (could skip this, not strictly necessary, in general, difference is quite small, but just in case...)
nmaxc = 0;
for (p=0; p<(img->x*img->y); p++)
if (crad->rect[p] > nmaxc) nmaxc = crad->rect[p];
// rescale factor
scf = (nmaxc==0.f) ? 1.f: (maxfgc / nmaxc);
*/
// and blend...
for (y=0; y<img->y; y++) {
unsigned int p = y*img->x;
int x;
for (x=0; x<img->x; x++) {
unsigned px = p + x;
if (zbuf->rect[px]!=0.f) {
float iZ = (zbuf->rect[px]==0.f) ? 0.f : (1.f/zbuf->rect[px]);
// bug #6656 part 2b, do not rescale
/*
bcrad = 0.5f*fabs(aperture*(dof_sp*(cam_invfdist - iZ) - 1.f));
// scale crad back to original maximum and blend
crad->rect[px] = bcrad + wts->rect[px]*(scf*crad->rect[px] - bcrad);
*/
crad->rect[px] = 0.5f*fabsf(aperture*(dof_sp*(cam_invfdist - iZ) - 1.f));
// 'bug' #6615, limit minimum radius to 1 pixel, not really a solution, but somewhat mitigates the problem
crad->rect[px] = MAX2(crad->rect[px], 0.5f);
// if maxblur!=0, limit maximum
if (nqd->maxblur != 0.f) crad->rect[px] = MIN2(crad->rect[px], nqd->maxblur);
}
else crad->rect[px] = 0.f;
// clear weights for next part
wts->rect[px] = 0.f;
}
// esc set by main calling process
if (node->exec & NODE_BREAK)
break;
}
}
//------------------------------------------------------------------
// main loop
#ifndef __APPLE__ /* can crash on Mac, see bug #22856, disabled for now */
#ifdef __INTEL_COMPILER /* icc doesn't like the compound statement -- internal error: 0_1506 */
#pragma omp parallel for private(y) if (!nqd->preview) schedule(guided)
#else
#pragma omp parallel for private(y) if (!nqd->preview && img->y*img->x > 16384) schedule(guided)
#endif
#endif
for (y=0; y<img->y; y++) {
unsigned int p, p4, zp, cp, cp4;
float *ctcol, u, v, ct_crad, cR2=0;
int x, sx, sy;
// some sort of visual feedback would be nice, or at least this text in the renderwin header
// but for now just print some info in the console every 8 scanlines.
#pragma omp critical
{
if (((ydone & 7)==0) || (ydone==(img->y-1))) {
if (G.background==0) {
printf("\rdefocus: Processing Line %d of %d ... ", ydone+1, img->y);
fflush(stdout);
}
}
ydone++;
}
// esc set by main calling process. don't break because openmp doesn't
// allow it, just continue and do nothing
if (node->exec & NODE_BREAK)
continue;
zp = y * img->x;
for (x=0; x<img->x; x++) {
cp = zp + x;
cp4 = cp * img->type;
// Circle of Confusion radius for current pixel
cR2 = ct_crad = crad->rect[cp];
// skip if zero (border render)
if (ct_crad==0.f) {
// related to bug #5921, forgot output image when skipping 0 radius values
new->rect[cp4] = img->rect[cp4];
if (new->type != CB_VAL) {
new->rect[cp4+1] = img->rect[cp4+1];
new->rect[cp4+2] = img->rect[cp4+2];
new->rect[cp4+3] = img->rect[cp4+3];
}
continue;
}
cR2 *= cR2;
// pixel color
ctcol = &img->rect[cp4];
if (!nqd->preview) {
int xs, xe, ys, ye;
float lwt, wtcol[4] = {0}, aacol[4] = {0};
float wt;
// shape weight
if (nqd->bktype==0) // disk
wt = 1.f/((float)M_PI*cR2);
else
wt = 1.f/(cR2*bk_hn_theta);
// weighted color
wtcol[0] = wt*ctcol[0];
if (new->type != CB_VAL) {
wtcol[1] = wt*ctcol[1];
wtcol[2] = wt*ctcol[2];
wtcol[3] = wt*ctcol[3];
}
// macro for background blur overlap test
// unfortunately, since this is done per pixel,
// it has a very significant negative impact on processing time...
// (eg. aa disk blur without test: 112 sec, vs with test: 176 sec...)
// iff center blur radius > threshold
// and if overlap pixel in focus, do nothing, else add color/weigbt
// (threshold constant is dependent on amount of blur)
#define TESTBG1(c, w) {\
if (ct_crad > nqd->bthresh) {\
if (crad->rect[p] > nqd->bthresh) {\
new->rect[p] += c[0];\
wts->rect[p] += w;\
}\
}\
else {\
new->rect[p] += c[0];\
wts->rect[p] += w;\
}\
}
#define TESTBG4(c, w) {\
if (ct_crad > nqd->bthresh) {\
if (crad->rect[p] > nqd->bthresh) {\
new->rect[p4] += c[0];\
new->rect[p4+1] += c[1];\
new->rect[p4+2] += c[2];\
new->rect[p4+3] += c[3];\
wts->rect[p] += w;\
}\
}\
else {\
new->rect[p4] += c[0];\
new->rect[p4+1] += c[1];\
new->rect[p4+2] += c[2];\
new->rect[p4+3] += c[3];\
wts->rect[p] += w;\
}\
}
if (nqd->bktype == 0) {
// Disk
int _x, i, j, di;
float Dj, T;
// AA pixel
#define AAPIX(a, b) {\
int _ny = b;\
if ((_ny >= 0) && (_ny < new->y)) {\
int _nx = a;\
if ((_nx >=0) && (_nx < new->x)) {\
p = _ny*new->x + _nx;\
if (new->type==CB_VAL) {\
TESTBG1(aacol, lwt);\
}\
else {\
p4 = p * new->type;\
TESTBG4(aacol, lwt);\
}\
}\
}\
}
// circle scanline
#define CSCAN(a, b) {\
int _ny = y + b;\
if ((_ny >= 0) && (_ny < new->y)) {\
xs = x - a + 1;\
if (xs < 0) xs = 0;\
xe = x + a;\
if (xe > new->x) xe = new->x;\
p = _ny*new->x + xs;\
if (new->type==CB_VAL) {\
for (_x=xs; _x<xe; _x++, p++) TESTBG1(wtcol, wt);\
}\
else {\
p4 = p * new->type;\
for (_x=xs; _x<xe; _x++, p++, p4+=new->type) TESTBG4(wtcol, wt);\
}\
}\
}
i = ceil(ct_crad);
j = 0;
T = 0;
while (i > j) {
Dj = sqrt(cR2 - j*j);
Dj -= floorf(Dj);
di = 0;
if (Dj > T) { i--; di = 1; }
T = Dj;
aacol[0] = wtcol[0]*Dj;
if (new->type != CB_VAL) {
aacol[1] = wtcol[1]*Dj;
aacol[2] = wtcol[2]*Dj;
aacol[3] = wtcol[3]*Dj;
}
lwt = wt*Dj;
if (i!=j) {
// outer pixels
AAPIX(x+j, y+i)
AAPIX(x+j, y-i)
if (j) {
AAPIX(x-j, y+i) // BL
AAPIX(x-j, y-i) // TL
}
if (di) { // only when i changed, interior of outer section
CSCAN(j, i) // bottom
CSCAN(j, -i) // top
}
}
// lower mid section
AAPIX(x+i, y+j)
if (i) AAPIX(x-i, y+j)
CSCAN(i, j)
// upper mid section
if (j) {
AAPIX(x+i, y-j)
if (i) AAPIX(x-i, y-j)
CSCAN(i, -j)
}
j++;
}
#undef CSCAN
#undef AAPIX
}
else {
// n-agonal
int ov, nv;
float mind, maxd, lwt;
ys = max_ii((int)floor(bkh_b[2] * ct_crad + y), 0);
ye = min_ii((int)ceil(bkh_b[3] * ct_crad + y), new->y - 1);
for (sy=ys; sy<=ye; sy++) {
float fxs = 1e10f, fxe = -1e10f;
float yf = (sy - y)/ct_crad;
int found = 0;
ov = len_bkh - 1;
mind = maxd = 0;
for (nv=0; nv<len_bkh; nv++) {
if ((BKH[nv].max_y >= yf) && (BKH[nv].min_y <= yf)) {
float tx = BKH[ov].x0 + BKH[nv].ls_x*(yf - BKH[ov].y0);
if (tx < fxs) { fxs = tx; mind = BKH[nv].ls_x; }
if (tx > fxe) { fxe = tx; maxd = BKH[nv].ls_x; }
if (++found == 2) break;
}
ov = nv;
}
if (found) {
fxs = fxs*ct_crad + x;
fxe = fxe*ct_crad + x;
xs = (int)floor(fxs), xe = (int)ceil(fxe);
// AA hack for first and last x pixel, near vertical edges only
if (fabsf(mind) <= 1.f) {
if ((xs >= 0) && (xs < new->x)) {
lwt = 1.f-(fxs - xs);
aacol[0] = wtcol[0]*lwt;
p = xs + sy*new->x;
if (new->type==CB_VAL) {
lwt *= wt;
TESTBG1(aacol, lwt);
}
else {
p4 = p * new->type;
aacol[1] = wtcol[1]*lwt;
aacol[2] = wtcol[2]*lwt;
aacol[3] = wtcol[3]*lwt;
lwt *= wt;
TESTBG4(aacol, lwt);
}
}
}
if (fabsf(maxd) <= 1.f) {
if ((xe >= 0) && (xe < new->x)) {
lwt = 1.f-(xe - fxe);
aacol[0] = wtcol[0]*lwt;
p = xe + sy*new->x;
if (new->type==CB_VAL) {
lwt *= wt;
TESTBG1(aacol, lwt);
}
else {
p4 = p * new->type;
aacol[1] = wtcol[1]*lwt;
aacol[2] = wtcol[2]*lwt;
aacol[3] = wtcol[3]*lwt;
lwt *= wt;
TESTBG4(aacol, lwt);
}
}
}
xs = MAX2(xs+1, 0);
xe = MIN2(xe, new->x);
// remaining interior scanline
p = sy*new->x + xs;
if (new->type==CB_VAL) {
for (sx=xs; sx<xe; sx++, p++) TESTBG1(wtcol, wt);
}
else {
p4 = p * new->type;
for (sx=xs; sx<xe; sx++, p++, p4+=new->type) TESTBG4(wtcol, wt);
}
}
}
// now traverse in opposite direction, y scanlines,
// but this time only draw the near horizontal edges,
// applying same AA hack as above
xs = MAX2((int)floor(bkh_b[0]*ct_crad + x), 0);
xe = MIN2((int)ceil(bkh_b[1]*ct_crad + x), img->x - 1);
for (sx=xs; sx<=xe; sx++) {
float xf = (sx - x)/ct_crad;
float fys = 1e10f, fye = -1e10f;
int found = 0;
ov = len_bkh - 1;
mind = maxd = 0;
for (nv=0; nv<len_bkh; nv++) {
if ((BKH[nv].max_x >= xf) && (BKH[nv].min_x <= xf)) {
float ty = BKH[ov].y0 + BKH[nv].ls_y*(xf - BKH[ov].x0);
if (ty < fys) { fys = ty; mind = BKH[nv].ls_y; }
if (ty > fye) { fye = ty; maxd = BKH[nv].ls_y; }
if (++found == 2) break;
}
ov = nv;
}
if (found) {
fys = fys*ct_crad + y;
fye = fye*ct_crad + y;
// near horizontal edges only, line slope <= 1
if (fabsf(mind) <= 1.f) {
int iys = (int)floor(fys);
if ((iys >= 0) && (iys < new->y)) {
lwt = 1.f - (fys - iys);
aacol[0] = wtcol[0]*lwt;
p = sx + iys*new->x;
if (new->type==CB_VAL) {
lwt *= wt;
TESTBG1(aacol, lwt);
}
else {
p4 = p * new->type;
aacol[1] = wtcol[1]*lwt;
aacol[2] = wtcol[2]*lwt;
aacol[3] = wtcol[3]*lwt;
lwt *= wt;
TESTBG4(aacol, lwt);
}
}
}
if (fabsf(maxd) <= 1.f) {
int iye = ceil(fye);
if ((iye >= 0) && (iye < new->y)) {
lwt = 1.f - (iye - fye);
aacol[0] = wtcol[0]*lwt;
p = sx + iye*new->x;
if (new->type==CB_VAL) {
lwt *= wt;
TESTBG1(aacol, lwt);
}
else {
p4 = p * new->type;
aacol[1] = wtcol[1]*lwt;
aacol[2] = wtcol[2]*lwt;
aacol[3] = wtcol[3]*lwt;
lwt *= wt;
TESTBG4(aacol, lwt);
}
}
}
}
}
}
#undef TESTBG4
#undef TESTBG1
}
else {
// sampled, simple rejection sampling here, good enough
unsigned int maxsam, s, ui = BLI_rand()*BLI_rand();
float wcor, cpr = BLI_frand(), lwt;
if (no_zbuf)
maxsam = nqd->samples; // no zbuffer input, use sample value directly
else {
// depth adaptive sampling hack, the more out of focus, the more samples taken, 16 minimum.
maxsam = (int)(0.5f + nqd->samples*(1.f-(float)exp(-fabs(zbuf->rect[cp] - cam_fdist))));
if (maxsam < 16) maxsam = 16;
}
wcor = 1.f/(float)maxsam;
for (s=0; s<maxsam; ++s) {
u = ct_crad*(2.f*RI_vdC(s, ui) - 1.f);
v = ct_crad*(2.f*(s + cpr)/(float)maxsam - 1.f);
sx = (int)(x + u + 0.5f), sy = (int)(y + v + 0.5f);
if ((sx<0) || (sx >= new->x) || (sy<0) || (sy >= new->y)) continue;
p = sx + sy*new->x;
p4 = p * new->type;
if (nqd->bktype==0) // Disk
lwt = ((u*u + v*v)<=cR2) ? wcor : 0.f;
else /* AA not needed here */
lwt = wcor * getWeight(BKH, len_bkh, u, v, ct_crad, inradsq);
// prevent background bleeding onto in-focus pixels, user-option
if (ct_crad > nqd->bthresh) { // if center blur > threshold
if (crad->rect[p] > nqd->bthresh) { // if overlap pixel in focus, do nothing, else add color/weigbt
new->rect[p4] += ctcol[0] * lwt;
if (new->type != CB_VAL) {
new->rect[p4+1] += ctcol[1] * lwt;
new->rect[p4+2] += ctcol[2] * lwt;
new->rect[p4+3] += ctcol[3] * lwt;
}
wts->rect[p] += lwt;
}
}
else {
new->rect[p4] += ctcol[0] * lwt;
if (new->type != CB_VAL) {
new->rect[p4+1] += ctcol[1] * lwt;
new->rect[p4+2] += ctcol[2] * lwt;
new->rect[p4+3] += ctcol[3] * lwt;
}
wts->rect[p] += lwt;
}
}
}
}
}
// finally, normalize
for (y=0; y<new->y; y++) {
unsigned int p = y * new->x;
unsigned int p4 = p * new->type;
int x;
for (x=0; x<new->x; x++) {
float dv = (wts->rect[p]==0.f) ? 1.f : (1.f/wts->rect[p]);
new->rect[p4] *= dv;
if (new->type!=CB_VAL) {
new->rect[p4+1] *= dv;
new->rect[p4+2] *= dv;
new->rect[p4+3] *= dv;
}
p++;
p4 += new->type;
}
}
free_compbuf(crad);
free_compbuf(wts);
printf("Done\n");
}
static void node_composit_exec_defocus(void *UNUSED(data), bNode *node, bNodeStack **in, bNodeStack **out)
{
CompBuf *new, *old, *zbuf_use = NULL, *img = in[0]->data, *zbuf = in[1]->data;
NodeDefocus *nqd = node->storage;
int no_zbuf = nqd->no_zbuf;
if ((img==NULL) || (out[0]->hasoutput==0)) return;
// if image not valid type or fstop==infinite (128), nothing to do, pass in to out
if (((img->type!=CB_RGBA) && (img->type!=CB_VAL)) || ((no_zbuf==0) && (nqd->fstop==128.f))) {
out[0]->data = pass_on_compbuf(img);
return;
}
if (zbuf!=NULL) {
// Zbuf input, check to make sure, single channel, same size
// doesn't have to be actual zbuffer, but must be value type
if ((zbuf->x != img->x) || (zbuf->y != img->y)) {
// could do a scale here instead...
printf("Z input must be same size as image !\n");
return;
}
zbuf_use = typecheck_compbuf(zbuf, CB_VAL);
}
else no_zbuf = 1; // no zbuffer input
// ok, process
old = img;
if (nqd->gamco) {
// gamma correct, blender func is simplified, fixed value & RGBA only,
// should make user param. also depremul and premul afterwards, gamma
// correction can't work with premul alpha
old = dupalloc_compbuf(img);
premul_compbuf(old, 1);
gamma_correct_compbuf(old, 0);
premul_compbuf(old, 0);
}
new = alloc_compbuf(old->x, old->y, old->type, 1);
defocus_blur(node, new, old, zbuf_use, in[1]->vec[0]*nqd->scale, no_zbuf);
if (nqd->gamco) {
premul_compbuf(new, 1);
gamma_correct_compbuf(new, 1);
premul_compbuf(new, 0);
free_compbuf(old);
}
if (node->exec & NODE_BREAK) {
free_compbuf(new);
new= NULL;
}
out[0]->data = new;
if (zbuf_use && (zbuf_use != zbuf)) free_compbuf(zbuf_use);
}
#endif /* WITH_COMPOSITOR_LEGACY */
static void node_composit_init_defocus(bNodeTree *UNUSED(ntree), bNode *node, bNodeTemplate *UNUSED(ntemp))
{
/* qdn: defocus node */
@@ -894,9 +70,6 @@ void register_node_type_cmp_defocus(bNodeTreeType *ttype)
node_type_size(&ntype, 150, 120, 200);
node_type_init(&ntype, node_composit_init_defocus);
node_type_storage(&ntype, "NodeDefocus", node_free_standard_storage, node_copy_standard_storage);
#ifdef WITH_COMPOSITOR_LEGACY
node_type_exec(&ntype, node_composit_exec_defocus);
#endif
nodeRegisterType(ttype, &ntype);
}

View File

@@ -42,15 +42,6 @@ static bNodeSocketTemplate cmp_node_despeckle_out[] = {
{ -1, 0, "" }
};
#ifdef WITH_COMPOSITOR_LEGACY
static void node_composit_exec_despeckle(void *UNUSED(data), bNode *UNUSED(node), bNodeStack **UNUSED(in), bNodeStack **UNUSED(out))
{
/* pass */
}
#endif /* WITH_COMPOSITOR_LEGACY */
static void node_composit_init_despeckle(bNodeTree *UNUSED(ntree), bNode *node, bNodeTemplate *UNUSED(ntemp))
{
node->custom3 = 0.5f;
@@ -65,9 +56,6 @@ void register_node_type_cmp_despeckle(bNodeTreeType *ttype)
node_type_socket_templates(&ntype, cmp_node_despeckle_in, cmp_node_despeckle_out);
node_type_size(&ntype, 80, 40, 120);
node_type_init(&ntype, node_composit_init_despeckle);
#ifdef WITH_COMPOSITOR_LEGACY
node_type_exec(&ntype, node_composit_exec_despeckle);
#endif
nodeRegisterType(ttype, &ntype);
}

View File

@@ -45,91 +45,6 @@ static bNodeSocketTemplate cmp_node_diff_matte_out[] = {
{-1, 0, ""}
};
#ifdef WITH_COMPOSITOR_LEGACY
static void do_diff_matte(bNode *node, float *outColor, float *inColor1, float *inColor2)
{
NodeChroma *c= (NodeChroma *)node->storage;
float tolerance=c->t1;
float fper=c->t2;
/* get falloff amount over tolerance size */
float falloff=(1.0f-fper) * tolerance;
float difference;
float alpha;
float maxInputAlpha;
/* average together the distances */
difference= fabs(inColor2[0]-inColor1[0]) +
fabs(inColor2[1]-inColor1[1]) +
fabs(inColor2[2]-inColor1[2]);
difference=difference/3.0f;
copy_v3_v3(outColor, inColor1);
if (difference <= tolerance) {
if (difference <= falloff) {
alpha = 0.0f;
}
else {
/* alpha as percent (distance / tolerance), each modified by falloff amount (in pixels)*/
alpha=(difference-falloff)/(tolerance-falloff);
}
/*only change if more transparent than either image */
maxInputAlpha=max_ff(inColor1[3], inColor2[3]);
if (alpha < maxInputAlpha) {
/*clamp*/
if (alpha < 0.0f) alpha = 0.0f;
if (alpha > 1.0f) alpha = 1.0f;
outColor[3] = alpha;
}
else { /* leave as before */
outColor[3]=maxInputAlpha;
}
}
}
static void node_composit_exec_diff_matte(void *data, bNode *node, bNodeStack **in, bNodeStack **out)
{
CompBuf *outbuf= NULL;
CompBuf *imbuf1= NULL;
CompBuf *imbuf2= NULL;
/* NodeChroma *c; */ /* UNUSED */
/*is anything connected?*/
if (out[0]->hasoutput==0 && out[1]->hasoutput==0) return;
/*must have an image imput*/
if (in[0]->data==NULL) return;
imbuf1=typecheck_compbuf(in[0]->data, CB_RGBA);
/* if there's an image, use that, if not use the color */
if (in[1]->data) {
imbuf2=typecheck_compbuf(in[1]->data, CB_RGBA);
}
/* c=node->storage; */ /* UNUSED */
outbuf=dupalloc_compbuf(imbuf1);
/* note, processor gets a keyvals array passed on as buffer constant */
composit2_pixel_processor(node, outbuf, imbuf1, in[0]->vec, imbuf2, in[1]->vec, do_diff_matte, CB_RGBA, CB_RGBA);
out[0]->data=outbuf;
if (out[1]->hasoutput)
out[1]->data=valbuf_from_rgbabuf(outbuf, CHAN_A);
generate_preview(data, node, outbuf);
if (imbuf1!=in[0]->data)
free_compbuf(imbuf1);
if (imbuf2!=in[1]->data)
free_compbuf(imbuf2);
}
#endif /* WITH_COMPOSITOR_LEGACY */
static void node_composit_init_diff_matte(bNodeTree *UNUSED(ntree), bNode *node, bNodeTemplate *UNUSED(ntemp))
{
NodeChroma *c= MEM_callocN(sizeof(NodeChroma), "node chroma");
@@ -147,9 +62,6 @@ void register_node_type_cmp_diff_matte(bNodeTreeType *ttype)
node_type_size(&ntype, 200, 80, 250);
node_type_init(&ntype, node_composit_init_diff_matte);
node_type_storage(&ntype, "NodeChroma", node_free_standard_storage, node_copy_standard_storage);
#ifdef WITH_COMPOSITOR_LEGACY
node_type_exec(&ntype, node_composit_exec_diff_matte);
#endif
nodeRegisterType(ttype, &ntype);
}

View File

@@ -44,112 +44,6 @@ static bNodeSocketTemplate cmp_node_dilateerode_out[] = {
{ -1, 0, "" }
};
#ifdef WITH_COMPOSITOR_LEGACY
static void morpho_dilate(CompBuf *cbuf)
{
int x, y;
float *p, *rectf = cbuf->rect;
for (y = 0; y < cbuf->y; y++) {
for (x = 0; x < cbuf->x - 1; x++) {
p = rectf + cbuf->x * y + x;
*p = max_ff(*p, *(p + 1));
}
}
for (y = 0; y < cbuf->y; y++) {
for (x = cbuf->x - 1; x >= 1; x--) {
p = rectf + cbuf->x * y + x;
*p = max_ff(*p, *(p - 1));
}
}
for (x = 0; x < cbuf->x; x++) {
for (y = 0; y < cbuf->y - 1; y++) {
p = rectf + cbuf->x * y + x;
*p = max_ff(*p, *(p + cbuf->x));
}
}
for (x = 0; x < cbuf->x; x++) {
for (y = cbuf->y - 1; y >= 1; y--) {
p = rectf + cbuf->x * y + x;
*p = max_ff(*p, *(p - cbuf->x));
}
}
}
static void morpho_erode(CompBuf *cbuf)
{
int x, y;
float *p, *rectf = cbuf->rect;
for (y = 0; y < cbuf->y; y++) {
for (x = 0; x < cbuf->x - 1; x++) {
p = rectf + cbuf->x * y + x;
*p = min_ff(*p, *(p + 1));
}
}
for (y = 0; y < cbuf->y; y++) {
for (x = cbuf->x - 1; x >= 1; x--) {
p = rectf + cbuf->x * y + x;
*p = min_ff(*p, *(p - 1));
}
}
for (x = 0; x < cbuf->x; x++) {
for (y = 0; y < cbuf->y - 1; y++) {
p = rectf + cbuf->x * y + x;
*p = min_ff(*p, *(p + cbuf->x));
}
}
for (x = 0; x < cbuf->x; x++) {
for (y = cbuf->y - 1; y >= 1; y--) {
p = rectf + cbuf->x * y + x;
*p = min_ff(*p, *(p - cbuf->x));
}
}
}
static void node_composit_exec_dilateerode(void *UNUSED(data), bNode *node, bNodeStack **in, bNodeStack **out)
{
/* stack order in: mask */
/* stack order out: mask */
if (out[0]->hasoutput == 0)
return;
/* input no image? then only color operation */
if (in[0]->data == NULL) {
zero_v4(out[0]->vec);
}
else {
/* make output size of input image */
CompBuf *cbuf = typecheck_compbuf(in[0]->data, CB_VAL);
CompBuf *stackbuf = dupalloc_compbuf(cbuf);
short i;
if (node->custom2 > 0) { // positive, dilate
for (i = 0; i < node->custom2; i++)
morpho_dilate(stackbuf);
}
else if (node->custom2 < 0) { // negative, erode
for (i = 0; i > node->custom2; i--)
morpho_erode(stackbuf);
}
if (cbuf != in[0]->data)
free_compbuf(cbuf);
out[0]->data = stackbuf;
}
}
#endif /* WITH_COMPOSITOR_LEGACY */
static void node_composit_init_dilateerode(bNodeTree *UNUSED(ntree), bNode *node, bNodeTemplate *UNUSED(ntemp))
{
NodeDilateErode *data = MEM_callocN(sizeof(NodeDilateErode), "NodeDilateErode");
@@ -165,9 +59,6 @@ void register_node_type_cmp_dilateerode(bNodeTreeType *ttype)
node_type_socket_templates(&ntype, cmp_node_dilateerode_in, cmp_node_dilateerode_out);
node_type_size(&ntype, 130, 100, 320);
node_type_init(&ntype, node_composit_init_dilateerode);
#ifdef WITH_COMPOSITOR_LEGACY
node_type_exec(&ntype, node_composit_exec_dilateerode);
#endif
node_type_storage(&ntype, "NodeDilateErode", node_free_standard_storage, node_copy_standard_storage);

View File

@@ -42,90 +42,6 @@ static bNodeSocketTemplate cmp_node_dblur_out[] = {
{ -1, 0, "" }
};
#ifdef WITH_COMPOSITOR_LEGACY
static CompBuf *dblur(bNode *node, CompBuf *img, int iterations, int wrap,
float center_x, float center_y, float dist, float angle, float spin, float zoom)
{
if ((dist != 0.f) || (spin != 0.f) || (zoom != 0.f)) {
void (*getpix)(CompBuf *, float, float, float *) = wrap ? qd_getPixelLerpWrap : qd_getPixelLerp;
const float a = angle;
const float itsc = 1.f / powf(2.f, (float)iterations);
float D;
float center_x_pix, center_y_pix;
float tx, ty;
float sc, rot;
CompBuf *tmp;
int i, j;
tmp = dupalloc_compbuf(img);
D = dist * sqrtf(img->x * img->x + img->y * img->y);
center_x_pix = center_x * img->x;
center_y_pix = center_y * img->y;
tx = itsc * D * cosf(a);
ty = -itsc * D * sinf(a);
sc = itsc * zoom;
rot = itsc * spin;
/* blur the image */
for (i = 0; i < iterations; ++i) {
const float cs = cosf(rot), ss = sinf(rot);
const float isc = 1.f / (1.f + sc);
unsigned int x, y;
float col[4] = {0, 0, 0, 0};
for (y = 0; y < img->y; ++y) {
const float v = isc * (y - center_y_pix) + ty;
for (x = 0; x < img->x; ++x) {
const float u = isc * (x - center_x_pix) + tx;
unsigned int p = (x + y * img->x) * img->type;
getpix(tmp, cs * u + ss * v + center_x_pix, cs * v - ss * u + center_y_pix, col);
/* mix img and transformed tmp */
for (j = 0; j < 4; ++j) {
img->rect[p + j] = 0.5f * (img->rect[p + j] + col[j]);
}
}
}
/* copy img to tmp */
if (i != (iterations - 1))
memcpy(tmp->rect, img->rect, sizeof(float) * img->x * img->y * img->type);
/* double transformations */
tx *= 2.f, ty *= 2.f;
sc *= 2.f, rot *= 2.f;
if (node->exec & NODE_BREAK) break;
}
free_compbuf(tmp);
}
return img;
}
static void node_composit_exec_dblur(void *UNUSED(data), bNode *node, bNodeStack **in, bNodeStack **out)
{
NodeDBlurData *ndbd = node->storage;
CompBuf *new, *img = in[0]->data;
if ((img == NULL) || (out[0]->hasoutput == 0)) return;
if (img->type != CB_RGBA)
new = typecheck_compbuf(img, CB_RGBA);
else
new = dupalloc_compbuf(img);
out[0]->data = dblur(node, new, ndbd->iter, ndbd->wrap, ndbd->center_x, ndbd->center_y, ndbd->distance, ndbd->angle, ndbd->spin, ndbd->zoom);
}
#endif /* WITH_COMPOSITOR_LEGACY */
static void node_composit_init_dblur(bNodeTree *UNUSED(ntree), bNode *node, bNodeTemplate *UNUSED(ntemp))
{
NodeDBlurData *ndbd = MEM_callocN(sizeof(NodeDBlurData), "node dblur data");
@@ -143,9 +59,6 @@ void register_node_type_cmp_dblur(bNodeTreeType *ttype)
node_type_size(&ntype, 150, 120, 200);
node_type_init(&ntype, node_composit_init_dblur);
node_type_storage(&ntype, "NodeDBlurData", node_free_standard_storage, node_copy_standard_storage);
#ifdef WITH_COMPOSITOR_LEGACY
node_type_exec(&ntype, node_composit_exec_dblur);
#endif
nodeRegisterType(ttype, &ntype);
}

View File

@@ -47,145 +47,6 @@ static bNodeSocketTemplate cmp_node_displace_out[] = {
{ -1, 0, "" }
};
#ifdef WITH_COMPOSITOR_LEGACY
/* minimum distance (in pixels) a pixel has to be displaced
* in order to take effect */
#define DISPLACE_EPSILON 0.01f
static void do_displace(bNode *node, CompBuf *stackbuf, CompBuf *cbuf, CompBuf *vecbuf, float *UNUSED(veccol), CompBuf *xbuf, CompBuf *ybuf, float *xscale, float *yscale)
{
ImBuf *ibuf;
int x, y;
float p_dx, p_dy; /* main displacement in pixel space */
float d_dx, d_dy;
float dxt, dyt;
float u, v;
float xs, ys;
float vec[3], vecdx[3], vecdy[3];
float col[3];
ibuf= IMB_allocImBuf(cbuf->x, cbuf->y, 32, 0);
ibuf->rect_float= cbuf->rect;
for (y=0; y < stackbuf->y; y++) {
for (x=0; x < stackbuf->x; x++) {
/* calc pixel coordinates */
qd_getPixel(vecbuf, x-vecbuf->xof, y-vecbuf->yof, vec);
if (xbuf)
qd_getPixel(xbuf, x-xbuf->xof, y-xbuf->yof, &xs);
else
xs = xscale[0];
if (ybuf)
qd_getPixel(ybuf, x-ybuf->xof, y-ybuf->yof, &ys);
else
ys = yscale[0];
/* clamp x and y displacement to triple image resolution -
* to prevent hangs from huge values mistakenly plugged in eg. z buffers */
CLAMP(xs, -stackbuf->x*4, stackbuf->x*4);
CLAMP(ys, -stackbuf->y*4, stackbuf->y*4);
p_dx = vec[0] * xs;
p_dy = vec[1] * ys;
/* if no displacement, then just copy this pixel */
if (fabsf(p_dx) < DISPLACE_EPSILON && fabsf(p_dy) < DISPLACE_EPSILON) {
qd_getPixel(cbuf, x-cbuf->xof, y-cbuf->yof, col);
qd_setPixel(stackbuf, x, y, col);
continue;
}
/* displaced pixel in uv coords, for image sampling */
u = (x - cbuf->xof - p_dx + 0.5f) / (float)stackbuf->x;
v = (y - cbuf->yof - p_dy + 0.5f) / (float)stackbuf->y;
/* calc derivatives */
qd_getPixel(vecbuf, x-vecbuf->xof+1, y-vecbuf->yof, vecdx);
qd_getPixel(vecbuf, x-vecbuf->xof, y-vecbuf->yof+1, vecdy);
d_dx = vecdx[0] * xs;
d_dy = vecdy[1] * ys;
/* clamp derivatives to minimum displacement distance in UV space */
dxt = p_dx - d_dx;
dyt = p_dy - d_dy;
dxt = signf(dxt)*max_ff(fabsf(dxt), DISPLACE_EPSILON)/(float)stackbuf->x;
dyt = signf(dyt)*max_ff(fabsf(dyt), DISPLACE_EPSILON)/(float)stackbuf->y;
ibuf_sample(ibuf, u, v, dxt, dyt, col);
qd_setPixel(stackbuf, x, y, col);
if (node->exec & NODE_BREAK) break;
}
if (node->exec & NODE_BREAK) break;
}
IMB_freeImBuf(ibuf);
/* simple method for reference, linear interpolation */
#if 0
int x, y;
float dx, dy;
float u, v;
float vec[3];
float col[3];
for (y=0; y < stackbuf->y; y++) {
for (x=0; x < stackbuf->x; x++) {
qd_getPixel(vecbuf, x, y, vec);
dx = vec[0] * (xscale[0]);
dy = vec[1] * (yscale[0]);
u = (x - dx + 0.5f) / (float)stackbuf->x;
v = (y - dy + 0.5f) / (float)stackbuf->y;
qd_getPixelLerp(cbuf, u*cbuf->x - 0.5f, v*cbuf->y - 0.5f, col);
qd_setPixel(stackbuf, x, y, col);
}
}
#endif
}
static void node_composit_exec_displace(void *UNUSED(data), bNode *node, bNodeStack **in, bNodeStack **out)
{
if (out[0]->hasoutput==0)
return;
if (in[0]->data && in[1]->data) {
CompBuf *cbuf= in[0]->data;
CompBuf *vecbuf= in[1]->data;
CompBuf *xbuf= in[2]->data;
CompBuf *ybuf= in[3]->data;
CompBuf *stackbuf;
cbuf= typecheck_compbuf(cbuf, CB_RGBA);
vecbuf= typecheck_compbuf(vecbuf, CB_VEC3);
xbuf= typecheck_compbuf(xbuf, CB_VAL);
ybuf= typecheck_compbuf(ybuf, CB_VAL);
stackbuf= alloc_compbuf(cbuf->x, cbuf->y, CB_RGBA, 1); /* allocs */
do_displace(node, stackbuf, cbuf, vecbuf, in[1]->vec, xbuf, ybuf, in[2]->vec, in[3]->vec);
out[0]->data= stackbuf;
if (cbuf!=in[0]->data)
free_compbuf(cbuf);
if (vecbuf!=in[1]->data)
free_compbuf(vecbuf);
}
}
#endif /* WITH_COMPOSITOR_LEGACY */
void register_node_type_cmp_displace(bNodeTreeType *ttype)
{
static bNodeType ntype;
@@ -193,9 +54,6 @@ void register_node_type_cmp_displace(bNodeTreeType *ttype)
node_type_base(ttype, &ntype, CMP_NODE_DISPLACE, "Displace", NODE_CLASS_DISTORT, NODE_OPTIONS);
node_type_socket_templates(&ntype, cmp_node_displace_in, cmp_node_displace_out);
node_type_size(&ntype, 140, 100, 320);
#ifdef WITH_COMPOSITOR_LEGACY
node_type_exec(&ntype, node_composit_exec_displace);
#endif
nodeRegisterType(ttype, &ntype);
}

View File

@@ -45,147 +45,6 @@ static bNodeSocketTemplate cmp_node_distance_matte_out[] = {
{-1, 0, ""}
};
#ifdef WITH_COMPOSITOR_LEGACY
/* note, keyvals is passed on from caller as stack array */
/* might have been nicer as temp struct though... */
static void do_distance_matte(bNode *node, float *out, float *in)
{
NodeChroma *c= (NodeChroma *)node->storage;
float tolerance=c->t1;
float fper=c->t2;
/* get falloff amount over tolerance size */
float falloff=(1.0f-fper) * tolerance;
float distance;
float alpha;
distance=sqrt((c->key[0]-in[0])*(c->key[0]-in[0]) +
(c->key[1]-in[1])*(c->key[1]-in[1]) +
(c->key[2]-in[2])*(c->key[2]-in[2]));
copy_v3_v3(out, in);
if (distance <= tolerance) {
if (distance <= falloff) {
alpha = 0.0f;
}
else {
/* alpha as percent (distance / tolerance), each modified by falloff amount (in pixels)*/
alpha=(distance-falloff)/(tolerance-falloff);
}
/*only change if more transparent than before */
if (alpha < in[3]) {
/*clamp*/
if (alpha < 0.0f) alpha = 0.0f;
if (alpha > 1.0f) alpha = 1.0f;
out[3]=alpha;
}
else { /* leave as before */
out[3]=in[3];
}
}
}
static void do_chroma_distance_matte(bNode *node, float *out, float *in)
{
NodeChroma *c= (NodeChroma *)node->storage;
float tolerance=c->t1;
float fper=c->t2;
/* get falloff amount over tolerance size */
float falloff=(1.0f-fper) * tolerance;
float y_key, cb_key, cr_key;
float y_pix, cb_pix, cr_pix;
float distance;
float alpha;
/*convert key to chroma colorspace */
rgb_to_ycc(c->key[0], c->key[1], c->key[2], &y_key, &cb_key, &cr_key, BLI_YCC_JFIF_0_255);
/* normalize the values */
cb_key=cb_key/255.0f;
cr_key=cr_key/255.0f;
/*convert pixel to chroma colorspace */
rgb_to_ycc(in[0], in[1], in[2], &y_pix, &cb_pix, &cr_pix, BLI_YCC_JFIF_0_255);
/*normalize the values */
cb_pix=cb_pix/255.0f;
cr_pix=cr_pix/255.0f;
distance=sqrt((cb_key-cb_pix)*(cb_key-cb_pix) +
(cr_key-cr_pix)*(cr_key-cr_pix));
copy_v3_v3(out, in);
if (distance <= tolerance) {
if (distance <= falloff) {
alpha = 0.0f;
}
else {
/* alpha as percent (distance / tolerance), each modified by falloff amount (in pixels)*/
alpha=(distance-falloff)/(tolerance-falloff);
}
/*only change if more transparent than before */
if (alpha < in[3]) {
/*clamp*/
if (alpha < 0.0f) alpha = 0.0f;
if (alpha > 1.0f) alpha = 1.0f;
out[3]=alpha;
}
else { /* leave as before */
out[3]=in[3];
}
}
}
static void node_composit_exec_distance_matte(void *data, bNode *node, bNodeStack **in, bNodeStack **out)
{
/*
* Loosely based on the Sequencer chroma key plug-in, but enhanced to work in other color spaces and
* uses a different difference function (suggested in forums of vfxtalk.com).
*/
CompBuf *workbuf;
CompBuf *inbuf;
NodeChroma *c;
/*is anything connected?*/
if (out[0]->hasoutput==0 && out[1]->hasoutput==0) return;
/*must have an image imput*/
if (in[0]->data==NULL) return;
inbuf=typecheck_compbuf(in[0]->data, CB_RGBA);
c=node->storage;
workbuf=dupalloc_compbuf(inbuf);
/*use the input color*/
c->key[0] = in[1]->vec[0];
c->key[1] = in[1]->vec[1];
c->key[2] = in[1]->vec[2];
/* work in RGB color space */
if (c->channel == 1) {
/* note, processor gets a keyvals array passed on as buffer constant */
composit1_pixel_processor(node, workbuf, workbuf, in[0]->vec, do_distance_matte, CB_RGBA);
}
/* work in YCbCr color space */
else {
composit1_pixel_processor(node, workbuf, workbuf, in[0]->vec, do_chroma_distance_matte, CB_RGBA);
}
out[0]->data=workbuf;
if (out[1]->hasoutput)
out[1]->data=valbuf_from_rgbabuf(workbuf, CHAN_A);
generate_preview(data, node, workbuf);
if (inbuf!=in[0]->data)
free_compbuf(inbuf);
}
#endif /* WITH_COMPOSITOR_LEGACY */
static void node_composit_init_distance_matte(bNodeTree *UNUSED(ntree), bNode *node, bNodeTemplate *UNUSED(ntemp))
{
NodeChroma *c= MEM_callocN(sizeof(NodeChroma), "node chroma");
@@ -204,9 +63,6 @@ void register_node_type_cmp_distance_matte(bNodeTreeType *ttype)
node_type_size(&ntype, 200, 80, 250);
node_type_init(&ntype, node_composit_init_distance_matte);
node_type_storage(&ntype, "NodeChroma", node_free_standard_storage, node_copy_standard_storage);
#ifdef WITH_COMPOSITOR_LEGACY
node_type_exec(&ntype, node_composit_exec_distance_matte);
#endif
nodeRegisterType(ttype, &ntype);
}

View File

@@ -43,186 +43,6 @@ static bNodeSocketTemplate cmp_node_filter_out[] = {
{ -1, 0, "" }
};
#ifdef WITH_COMPOSITOR_LEGACY
static void do_filter_edge(CompBuf *out, CompBuf *in, float *filter, float fac)
{
float *row1, *row2, *row3;
float *fp, f1, f2, mfac= 1.0f-fac;
int rowlen, x, y, c, pix= in->type;
rowlen= in->x;
for (y=0; y<in->y; y++) {
/* setup rows */
if (y==0) row1= in->rect;
else row1= in->rect + pix*(y-1)*rowlen;
row2= in->rect + y*pix*rowlen;
if (y==in->y-1) row3= row2;
else row3= row2 + pix*rowlen;
fp= out->rect + pix*y*rowlen;
if (pix==CB_RGBA) {
copy_v4_v4(fp, row2);
fp+= pix;
for (x=2; x<rowlen; x++) {
for (c=0; c<3; c++) {
f1= filter[0]*row1[0] + filter[1]*row1[4] + filter[2]*row1[8] + filter[3]*row2[0] + filter[4]*row2[4] + filter[5]*row2[8] + filter[6]*row3[0] + filter[7]*row3[4] + filter[8]*row3[8];
f2= filter[0]*row1[0] + filter[3]*row1[4] + filter[6]*row1[8] + filter[1]*row2[0] + filter[4]*row2[4] + filter[7]*row2[8] + filter[2]*row3[0] + filter[5]*row3[4] + filter[8]*row3[8];
fp[0] = mfac*row2[4] + fac*sqrt(f1*f1 + f2*f2);
fp++; row1++; row2++; row3++;
}
fp[0] = row2[4];
/* no alpha... will clear it completely */
fp++; row1++; row2++; row3++;
}
copy_v4_v4(fp, row2+4);
}
else if (pix==CB_VAL) {
fp+= pix;
for (x=2; x<rowlen; x++) {
f1= filter[0]*row1[0] + filter[1]*row1[1] + filter[2]*row1[2] + filter[3]*row2[0] + filter[4]*row2[1] + filter[5]*row2[2] + filter[6]*row3[0] + filter[7]*row3[1] + filter[8]*row3[2];
f2= filter[0]*row1[0] + filter[3]*row1[1] + filter[6]*row1[2] + filter[1]*row2[0] + filter[4]*row2[1] + filter[7]*row2[2] + filter[2]*row3[0] + filter[5]*row3[1] + filter[8]*row3[2];
fp[0] = mfac*row2[1] + fac*sqrt(f1*f1 + f2*f2);
fp++; row1++; row2++; row3++;
}
}
}
}
static void do_filter3(CompBuf *out, CompBuf *in, float *filter, float fac)
{
float *row1, *row2, *row3;
float *fp, mfac= 1.0f-fac;
int rowlen, x, y, c;
int pixlen= in->type;
rowlen= in->x;
for (y=0; y<in->y; y++) {
/* setup rows */
if (y==0) row1= in->rect;
else row1= in->rect + pixlen*(y-1)*rowlen;
row2= in->rect + y*pixlen*rowlen;
if (y==in->y-1) row3= row2;
else row3= row2 + pixlen*rowlen;
fp= out->rect + pixlen*(y)*rowlen;
if (pixlen==1) {
fp[0] = row2[0];
fp+= 1;
for (x=2; x<rowlen; x++) {
fp[0] = mfac*row2[1] + fac*(filter[0]*row1[0] + filter[1]*row1[1] + filter[2]*row1[2] + filter[3]*row2[0] + filter[4]*row2[1] + filter[5]*row2[2] + filter[6]*row3[0] + filter[7]*row3[1] + filter[8]*row3[2]);
fp++; row1++; row2++; row3++;
}
fp[0] = row2[1];
}
else if (pixlen==2) {
fp[0] = row2[0];
fp[1] = row2[1];
fp+= 2;
for (x=2; x<rowlen; x++) {
for (c=0; c<2; c++) {
fp[0] = mfac*row2[2] + fac*(filter[0]*row1[0] + filter[1]*row1[2] + filter[2]*row1[4] + filter[3]*row2[0] + filter[4]*row2[2] + filter[5]*row2[4] + filter[6]*row3[0] + filter[7]*row3[2] + filter[8]*row3[4]);
fp++; row1++; row2++; row3++;
}
}
fp[0] = row2[2];
fp[1] = row2[3];
}
else if (pixlen==3) {
copy_v3_v3(fp, row2);
fp+= 3;
for (x=2; x<rowlen; x++) {
for (c=0; c<3; c++) {
fp[0] = mfac*row2[3] + fac*(filter[0]*row1[0] + filter[1]*row1[3] + filter[2]*row1[6] + filter[3]*row2[0] + filter[4]*row2[3] + filter[5]*row2[6] + filter[6]*row3[0] + filter[7]*row3[3] + filter[8]*row3[6]);
fp++; row1++; row2++; row3++;
}
}
copy_v3_v3(fp, row2+3);
}
else {
copy_v4_v4(fp, row2);
fp+= 4;
for (x=2; x<rowlen; x++) {
for (c=0; c<4; c++) {
fp[0] = mfac*row2[4] + fac*(filter[0]*row1[0] + filter[1]*row1[4] + filter[2]*row1[8] + filter[3]*row2[0] + filter[4]*row2[4] + filter[5]*row2[8] + filter[6]*row3[0] + filter[7]*row3[4] + filter[8]*row3[8]);
fp++; row1++; row2++; row3++;
}
}
copy_v4_v4(fp, row2+4);
}
}
}
static void node_composit_exec_filter(void *data, bNode *node, bNodeStack **in, bNodeStack **out)
{
static float soft[9] = {1/16.0f, 2/16.0f, 1/16.0f, 2/16.0f, 4/16.0f, 2/16.0f, 1/16.0f, 2/16.0f, 1/16.0f};
float sharp[9] = {-1, -1, -1, -1, 9, -1, -1, -1, -1};
float laplace[9] = {-1/8.0f, -1/8.0f, -1/8.0f, -1/8.0f, 1.0f, -1/8.0f, -1/8.0f, -1/8.0f, -1/8.0f};
float sobel[9] = {1, 2, 1, 0, 0, 0, -1, -2, -1};
float prewitt[9] = {1, 1, 1, 0, 0, 0, -1, -1, -1};
float kirsch[9] = {5, 5, 5, -3, -3, -3, -2, -2, -2};
float shadow[9] = {1, 2, 1, 0, 1, 0, -1, -2, -1};
if (out[0]->hasoutput==0) return;
/* stack order in: Image */
/* stack order out: Image */
if (in[1]->data) {
/* make output size of first available input image */
CompBuf *cbuf= in[1]->data;
CompBuf *stackbuf= alloc_compbuf(cbuf->x, cbuf->y, cbuf->type, 1); /* allocs */
/* warning note: xof and yof are applied in pixelprocessor, but should be copied otherwise? */
stackbuf->xof= cbuf->xof;
stackbuf->yof= cbuf->yof;
switch (node->custom1) {
case CMP_FILT_SOFT:
do_filter3(stackbuf, cbuf, soft, in[0]->vec[0]);
break;
case CMP_FILT_SHARP:
do_filter3(stackbuf, cbuf, sharp, in[0]->vec[0]);
break;
case CMP_FILT_LAPLACE:
do_filter3(stackbuf, cbuf, laplace, in[0]->vec[0]);
break;
case CMP_FILT_SOBEL:
do_filter_edge(stackbuf, cbuf, sobel, in[0]->vec[0]);
break;
case CMP_FILT_PREWITT:
do_filter_edge(stackbuf, cbuf, prewitt, in[0]->vec[0]);
break;
case CMP_FILT_KIRSCH:
do_filter_edge(stackbuf, cbuf, kirsch, in[0]->vec[0]);
break;
case CMP_FILT_SHADOW:
do_filter3(stackbuf, cbuf, shadow, in[0]->vec[0]);
break;
}
out[0]->data= stackbuf;
generate_preview(data, node, out[0]->data);
}
}
#endif /* WITH_COMPOSITOR_LEGACY */
void register_node_type_cmp_filter(bNodeTreeType *ttype)
{
static bNodeType ntype;
@@ -231,9 +51,6 @@ void register_node_type_cmp_filter(bNodeTreeType *ttype)
node_type_socket_templates(&ntype, cmp_node_filter_in, cmp_node_filter_out);
node_type_size(&ntype, 80, 40, 120);
node_type_label(&ntype, node_filter_label);
#ifdef WITH_COMPOSITOR_LEGACY
node_type_exec(&ntype, node_composit_exec_filter);
#endif
nodeRegisterType(ttype, &ntype);
}

View File

@@ -43,55 +43,6 @@ static bNodeSocketTemplate cmp_node_flip_out[] = {
{ -1, 0, "" }
};
#ifdef WITH_COMPOSITOR_LEGACY
static void node_composit_exec_flip(void *UNUSED(data), bNode *node, bNodeStack **in, bNodeStack **out)
{
if (in[0]->data) {
CompBuf *cbuf= in[0]->data;
CompBuf *stackbuf= alloc_compbuf(cbuf->x, cbuf->y, cbuf->type, 1); /* note, this returns zero'd image */
int i, src_pix, src_width, src_height, srcydelt, outydelt, x, y;
float *srcfp, *outfp;
src_pix= cbuf->type;
src_width= cbuf->x;
src_height= cbuf->y;
srcfp= cbuf->rect;
outfp= stackbuf->rect;
srcydelt= src_width*src_pix;
outydelt= srcydelt;
if (node->custom1) { /*set up output pointer for y flip*/
outfp+= (src_height-1)*outydelt;
outydelt= -outydelt;
}
for (y=0; y<src_height; y++) {
if (node->custom1 == 1) { /* no x flip so just copy line*/
memcpy(outfp, srcfp, sizeof(float) * src_pix * src_width);
srcfp+=srcydelt;
}
else {
outfp += (src_width-1)*src_pix;
for (x=0; x<src_width; x++) {
for (i=0; i<src_pix; i++) {
outfp[i] = srcfp[i];
}
outfp -= src_pix;
srcfp += src_pix;
}
outfp += src_pix;
}
outfp += outydelt;
}
out[0]->data= stackbuf;
}
}
#endif /* WITH_COMPOSITOR_LEGACY */
void register_node_type_cmp_flip(bNodeTreeType *ttype)
{
static bNodeType ntype;
@@ -99,9 +50,6 @@ void register_node_type_cmp_flip(bNodeTreeType *ttype)
node_type_base(ttype, &ntype, CMP_NODE_FLIP, "Flip", NODE_CLASS_DISTORT, NODE_OPTIONS);
node_type_socket_templates(&ntype, cmp_node_flip_in, cmp_node_flip_out);
node_type_size(&ntype, 140, 100, 320);
#ifdef WITH_COMPOSITOR_LEGACY
node_type_exec(&ntype, node_composit_exec_flip);
#endif
nodeRegisterType(ttype, &ntype);
}

View File

@@ -45,40 +45,6 @@ static bNodeSocketTemplate cmp_node_gamma_out[] = {
{ -1, 0, "" }
};
#ifdef WITH_COMPOSITOR_LEGACY
static void do_gamma(bNode *UNUSED(node), float *out, float *in, float *fac)
{
int i=0;
for (i=0; i<3; i++) {
/* check for negative to avoid nan's */
out[i] = (in[i] > 0.0f)? powf(in[i], fac[0]): in[i];
}
out[3] = in[3];
}
static void node_composit_exec_gamma(void *UNUSED(data), bNode *node, bNodeStack **in, bNodeStack **out)
{
/* stack order in: Fac, Image */
/* stack order out: Image */
if (out[0]->hasoutput==0) return;
/* input no image? then only color operation */
if (in[0]->data==NULL) {
do_gamma(node, out[0]->vec, in[0]->vec, in[1]->vec);
}
else {
/* make output size of input image */
CompBuf *cbuf= in[0]->data;
CompBuf *stackbuf= alloc_compbuf(cbuf->x, cbuf->y, CB_RGBA, 1); // allocs
composit2_pixel_processor(node, stackbuf, cbuf, in[0]->vec, in[1]->data, in[1]->vec, do_gamma, CB_RGBA, CB_VAL);
out[0]->data= stackbuf;
}
}
#endif /* WITH_COMPOSITOR_LEGACY */
void register_node_type_cmp_gamma(bNodeTreeType *ttype)
{
static bNodeType ntype;
@@ -86,9 +52,6 @@ void register_node_type_cmp_gamma(bNodeTreeType *ttype)
node_type_base(ttype, &ntype, CMP_NODE_GAMMA, "Gamma", NODE_CLASS_OP_COLOR, NODE_OPTIONS);
node_type_socket_templates(&ntype, cmp_node_gamma_in, cmp_node_gamma_out);
node_type_size(&ntype, 140, 100, 320);
#ifdef WITH_COMPOSITOR_LEGACY
node_type_exec(&ntype, node_composit_exec_gamma);
#endif
nodeRegisterType(ttype, &ntype);
}

View File

@@ -41,442 +41,6 @@ static bNodeSocketTemplate cmp_node_glare_out[] = {
{ -1, 0, "" }
};
#ifdef WITH_COMPOSITOR_LEGACY
// mix two images, src buffer does not have to be same size,
static void mixImages(CompBuf *dst, CompBuf *src, float mix)
{
int x, y;
fRGB c1, c2, *dcolp, *scolp;
const float mf = 2.f - 2.f*fabsf(mix - 0.5f);
if ((dst->x == src->x) && (dst->y == src->y)) {
for (y=0; y<dst->y; y++) {
dcolp = (fRGB*)&dst->rect[y*dst->x*dst->type];
scolp = (fRGB*)&src->rect[y*dst->x*dst->type];
for (x=0; x<dst->x; x++) {
copy_v3_v3(c1, dcolp[x]);
copy_v3_v3(c2, scolp[x]);
c1[0] += mix*(c2[0] - c1[0]);
c1[1] += mix*(c2[1] - c1[1]);
c1[2] += mix*(c2[2] - c1[2]);
if (c1[0] < 0.f) c1[0] = 0.f;
if (c1[1] < 0.f) c1[1] = 0.f;
if (c1[2] < 0.f) c1[2] = 0.f;
mul_v3_fl(c1, mf);
copy_v3_v3(dcolp[x], c1);
}
}
}
else {
float xr = src->x / (float)dst->x;
float yr = src->y / (float)dst->y;
for (y=0; y<dst->y; y++) {
dcolp = (fRGB*)&dst->rect[y*dst->x*dst->type];
for (x=0; x<dst->x; x++) {
copy_v3_v3(c1, dcolp[x]);
qd_getPixelLerp(src, (x + 0.5f)*xr - 0.5f, (y + 0.5f)*yr - 0.5f, c2);
c1[0] += mix*(c2[0] - c1[0]);
c1[1] += mix*(c2[1] - c1[1]);
c1[2] += mix*(c2[2] - c1[2]);
if (c1[0] < 0.f) c1[0] = 0.f;
if (c1[1] < 0.f) c1[1] = 0.f;
if (c1[2] < 0.f) c1[2] = 0.f;
mul_v3_fl(c1, mf);
copy_v3_v3(dcolp[x], c1);
}
}
}
}
// adds src to dst image, must be of same size
static void addImage(CompBuf* dst, CompBuf* src, float scale)
{
if ((dst->x == src->x) && (dst->y == src->y)) {
int p = dst->x*dst->y*dst->type;
float *dcol = dst->rect, *scol = src->rect;
while (p--) *dcol++ += *scol++ * scale;
}
}
// returns possibly downscaled copy of all pixels above threshold
static CompBuf* BTP(CompBuf* src, float threshold, int scaledown)
{
int x, y;
CompBuf* bsrc = qd_downScaledCopy(src, scaledown);
float* cr = bsrc->rect;
for (y=0; y<bsrc->y; ++y)
for (x=0; x<bsrc->x; ++x, cr+=4) {
if (rgb_to_luma_y(cr) >= threshold) {
cr[0] -= threshold, cr[1] -= threshold, cr[2] -= threshold;
cr[0] = MAX2(cr[0], 0.f);
cr[1] = MAX2(cr[1], 0.f);
cr[2] = MAX2(cr[2], 0.f);
}
else cr[0] = cr[1] = cr[2] = 0.f;
}
return bsrc;
}
//--------------------------------------------------------------------------------------------
// simple 4-point star filter
static void star4(NodeGlare* ndg, CompBuf* dst, CompBuf* src)
{
int x, y, i, xm, xp, ym, yp;
float c[4] = {0, 0, 0, 0}, tc[4] = {0, 0, 0, 0};
CompBuf *tbuf1, *tbuf2, *tsrc;
const float f1 = 1.f - ndg->fade, f2 = (1.f - f1)*0.5f;
//const float t3 = ndg->threshold*3.f;
const float sc = (float)(1 << ndg->quality);
const float isc = 1.f/sc;
tsrc = BTP(src, ndg->threshold, (int)sc);
tbuf1 = dupalloc_compbuf(tsrc);
tbuf2 = dupalloc_compbuf(tsrc);
for (i=0; i<ndg->iter; i++) {
// (x || x-1, y-1) to (x || x+1, y+1)
// F
for (y=0; y<tbuf1->y; y++) {
ym = y - i;
yp = y + i;
for (x=0; x<tbuf1->x; x++) {
xm = x - i;
xp = x + i;
qd_getPixel(tbuf1, x, y, c);
mul_v3_fl(c, f1);
qd_getPixel(tbuf1, (ndg->angle ? xm : x), ym, tc);
madd_v3_v3fl(c, tc, f2);
qd_getPixel(tbuf1, (ndg->angle ? xp : x), yp, tc);
madd_v3_v3fl(c, tc, f2);
qd_setPixel(tbuf1, x, y, c);
}
}
// B
for (y=tbuf1->y-1; y>=0; y--) {
ym = y - i;
yp = y + i;
for (x=tbuf1->x-1; x>=0; x--) {
xm = x - i;
xp = x + i;
qd_getPixel(tbuf1, x, y, c);
mul_v3_fl(c, f1);
qd_getPixel(tbuf1, (ndg->angle ? xm : x), ym, tc);
madd_v3_v3fl(c, tc, f2);
qd_getPixel(tbuf1, (ndg->angle ? xp : x), yp, tc);
madd_v3_v3fl(c, tc, f2);
qd_setPixel(tbuf1, x, y, c);
}
}
// (x-1, y || y+1) to (x+1, y || y-1)
// F
for (y=0; y<tbuf2->y; y++) {
ym = y - i;
yp = y + i;
for (x=0; x<tbuf2->x; x++) {
xm = x - i;
xp = x + i;
qd_getPixel(tbuf2, x, y, c);
mul_v3_fl(c, f1);
qd_getPixel(tbuf2, xm, (ndg->angle ? yp : y), tc);
madd_v3_v3fl(c, tc, f2);
qd_getPixel(tbuf2, xp, (ndg->angle ? ym : y), tc);
madd_v3_v3fl(c, tc, f2);
qd_setPixel(tbuf2, x, y, c);
}
}
// B
for (y=tbuf2->y-1; y>=0; y--) {
ym = y - i;
yp = y + i;
for (x=tbuf2->x-1; x>=0; x--) {
xm = x - i;
xp = x + i;
qd_getPixel(tbuf2, x, y, c);
mul_v3_fl(c, f1);
qd_getPixel(tbuf2, xm, (ndg->angle ? yp : y), tc);
madd_v3_v3fl(c, tc, f2);
qd_getPixel(tbuf2, xp, (ndg->angle ? ym : y), tc);
madd_v3_v3fl(c, tc, f2);
qd_setPixel(tbuf2, x, y, c);
}
}
}
for (y=0; y<tbuf1->y; ++y)
for (x=0; x<tbuf1->x; ++x) {
unsigned int p = (x + y*tbuf1->x)*tbuf1->type;
tbuf1->rect[p] += tbuf2->rect[p];
tbuf1->rect[p+1] += tbuf2->rect[p+1];
tbuf1->rect[p+2] += tbuf2->rect[p+2];
}
for (y=0; y<dst->y; ++y) {
const float m = 0.5f + 0.5f*ndg->mix;
for (x=0; x<dst->x; ++x) {
unsigned int p = (x + y*dst->x)*dst->type;
qd_getPixelLerp(tbuf1, x*isc, y*isc, tc);
dst->rect[p] = src->rect[p] + m*(tc[0] - src->rect[p]);
dst->rect[p+1] = src->rect[p+1] + m*(tc[1] - src->rect[p+1]);
dst->rect[p+2] = src->rect[p+2] + m*(tc[2] - src->rect[p+2]);
}
}
free_compbuf(tbuf1);
free_compbuf(tbuf2);
free_compbuf(tsrc);
}
//--------------------------------------------------------------------------------------------
// streak filter
static void streaks(NodeGlare* ndg, CompBuf* dst, CompBuf* src)
{
CompBuf *bsrc, *tsrc, *tdst, *sbuf;
int x, y, n;
unsigned int nump=0;
fRGB c1, c2, c3, c4;
float a, ang = DEG2RADF(360.0f)/(float)ndg->angle;
bsrc = BTP(src, ndg->threshold, 1 << ndg->quality);
tsrc = dupalloc_compbuf(bsrc); // sample from buffer
tdst = alloc_compbuf(tsrc->x, tsrc->y, tsrc->type, 1); // sample to buffer
sbuf = alloc_compbuf(tsrc->x, tsrc->y, tsrc->type, 1); // streak sum buffer
for (a=0.f; a<DEG2RADF(360.0f); a+=ang) {
const float an = a + ndg->angle_ofs;
const float vx = cos((double)an), vy = sin((double)an);
for (n=0; n<ndg->iter; ++n) {
const float p4 = pow(4.0, (double)n);
const float vxp = vx*p4, vyp = vy*p4;
const float wt = pow((double)ndg->fade, (double)p4);
const float cmo = 1.f - (float)pow((double)ndg->colmod, (double)n+1); // colormodulation amount relative to current pass
float* tdstcol = tdst->rect;
for (y=0; y<tsrc->y; ++y) {
for (x=0; x<tsrc->x; ++x, tdstcol+=4) {
// first pass no offset, always same for every pass, exact copy,
// otherwise results in uneven brightness, only need once
if (n==0) qd_getPixel(tsrc, x, y, c1); else c1[0]=c1[1]=c1[2]=0;
qd_getPixelLerp(tsrc, x + vxp, y + vyp, c2);
qd_getPixelLerp(tsrc, x + vxp*2.f, y + vyp*2.f, c3);
qd_getPixelLerp(tsrc, x + vxp*3.f, y + vyp*3.f, c4);
// modulate color to look vaguely similar to a color spectrum
fRGB_rgbmult(c2, 1.f, cmo, cmo);
fRGB_rgbmult(c3, cmo, cmo, 1.f);
fRGB_rgbmult(c4, cmo, 1.f, cmo);
tdstcol[0] = 0.5f*(tdstcol[0] + c1[0] + wt*(c2[0] + wt*(c3[0] + wt*c4[0])));
tdstcol[1] = 0.5f*(tdstcol[1] + c1[1] + wt*(c2[1] + wt*(c3[1] + wt*c4[1])));
tdstcol[2] = 0.5f*(tdstcol[2] + c1[2] + wt*(c2[2] + wt*(c3[2] + wt*c4[2])));
}
}
memcpy(tsrc->rect, tdst->rect, sizeof(float)*tdst->x*tdst->y*tdst->type);
}
addImage(sbuf, tsrc, 1.f/(float)(6 - ndg->iter));
memset(tdst->rect, 0, tdst->x*tdst->y*tdst->type*sizeof(float));
memcpy(tsrc->rect, bsrc->rect, bsrc->x*bsrc->y*bsrc->type*sizeof(float));
nump++;
}
mixImages(dst, sbuf, 0.5f + 0.5f*ndg->mix);
free_compbuf(tsrc);
free_compbuf(tdst);
free_compbuf(sbuf);
free_compbuf(bsrc);
}
//--------------------------------------------------------------------------------------------
// Ghosts (lensflare)
static float smoothMask(float x, float y)
{
float t;
x = 2.f*x - 1.f, y = 2.f*y - 1.f;
if ((t = 1.f - sqrtf(x*x + y*y)) <= 0.f) return 0.f;
return t;
}
static void ghosts(NodeGlare* ndg, CompBuf* dst, CompBuf* src)
{
// colormodulation and scale factors (cm & scalef) for 16 passes max: 64
int x, y, n, p, np;
fRGB c, tc, cm[64];
float sc, isc, u, v, sm, s, t, ofs, scalef[64];
CompBuf *tbuf1, *tbuf2, *gbuf;
const float cmo = 1.f - ndg->colmod;
const int qt = 1 << ndg->quality;
const float s1 = 4.f/(float)qt, s2 = 2.f*s1;
gbuf = BTP(src, ndg->threshold, qt);
tbuf1 = dupalloc_compbuf(gbuf);
IIR_gauss(tbuf1, s1, 0, 3);
IIR_gauss(tbuf1, s1, 1, 3);
IIR_gauss(tbuf1, s1, 2, 3);
tbuf2 = dupalloc_compbuf(tbuf1);
IIR_gauss(tbuf2, s2, 0, 3);
IIR_gauss(tbuf2, s2, 1, 3);
IIR_gauss(tbuf2, s2, 2, 3);
if (ndg->iter & 1) ofs = 0.5f; else ofs = 0.f;
for (x=0; x<(ndg->iter*4); x++) {
y = x & 3;
cm[x][0] = cm[x][1] = cm[x][2] = 1;
if (y==1) fRGB_rgbmult(cm[x], 1.f, cmo, cmo);
if (y==2) fRGB_rgbmult(cm[x], cmo, cmo, 1.f);
if (y==3) fRGB_rgbmult(cm[x], cmo, 1.f, cmo);
scalef[x] = 2.1f*(1.f-(x+ofs)/(float)(ndg->iter*4));
if (x & 1) scalef[x] = -0.99f/scalef[x];
}
sc = 2.13;
isc = -0.97;
for (y=0; y<gbuf->y; y++) {
v = (float)(y+0.5f) / (float)gbuf->y;
for (x=0; x<gbuf->x; x++) {
u = (float)(x+0.5f) / (float)gbuf->x;
s = (u-0.5f)*sc + 0.5f, t = (v-0.5f)*sc + 0.5f;
qd_getPixelLerp(tbuf1, s*gbuf->x, t*gbuf->y, c);
sm = smoothMask(s, t);
mul_v3_fl(c, sm);
s = (u-0.5f)*isc + 0.5f, t = (v-0.5f)*isc + 0.5f;
qd_getPixelLerp(tbuf2, s*gbuf->x - 0.5f, t*gbuf->y - 0.5f, tc);
sm = smoothMask(s, t);
madd_v3_v3fl(c, tc, sm);
qd_setPixel(gbuf, x, y, c);
}
}
memset(tbuf1->rect, 0, tbuf1->x*tbuf1->y*tbuf1->type*sizeof(float));
for (n=1; n<ndg->iter; n++) {
for (y=0; y<gbuf->y; y++) {
v = (float)(y+0.5f) / (float)gbuf->y;
for (x=0; x<gbuf->x; x++) {
u = (float)(x+0.5f) / (float)gbuf->x;
tc[0] = tc[1] = tc[2] = 0.f;
for (p=0;p<4;p++) {
np = (n<<2) + p;
s = (u-0.5f)*scalef[np] + 0.5f;
t = (v-0.5f)*scalef[np] + 0.5f;
qd_getPixelLerp(gbuf, s*gbuf->x - 0.5f, t*gbuf->y - 0.5f, c);
mul_v3_v3(c, cm[np]);
sm = smoothMask(s, t)*0.25f;
madd_v3_v3fl(tc, c, sm);
}
p = (x + y*tbuf1->x)*tbuf1->type;
tbuf1->rect[p] += tc[0];
tbuf1->rect[p+1] += tc[1];
tbuf1->rect[p+2] += tc[2];
}
}
memcpy(gbuf->rect, tbuf1->rect, tbuf1->x*tbuf1->y*tbuf1->type*sizeof(float));
}
free_compbuf(tbuf1);
free_compbuf(tbuf2);
mixImages(dst, gbuf, 0.5f + 0.5f*ndg->mix);
free_compbuf(gbuf);
}
//--------------------------------------------------------------------------------------------
// Fog glow (convolution with kernel of exponential falloff)
static void fglow(NodeGlare* ndg, CompBuf* dst, CompBuf* src)
{
int x, y;
float scale, u, v, r, w, d;
fRGB fcol;
CompBuf *tsrc, *ckrn;
unsigned int sz = 1 << ndg->size;
const float cs_r = 1.f, cs_g = 1.f, cs_b = 1.f;
// temp. src image
tsrc = BTP(src, ndg->threshold, 1 << ndg->quality);
// make the convolution kernel
ckrn = alloc_compbuf(sz, sz, CB_RGBA, 1);
scale = 0.25f*sqrtf(sz*sz);
for (y=0; y<sz; ++y) {
v = 2.f*(y / (float)sz) - 1.f;
for (x=0; x<sz; ++x) {
u = 2.f*(x / (float)sz) - 1.f;
r = (u*u + v*v)*scale;
d = -sqrtf(sqrtf(sqrtf(r)))*9.f;
fcol[0] = expf(d*cs_r), fcol[1] = expf(d*cs_g), fcol[2] = expf(d*cs_b);
// linear window good enough here, visual result counts, not scientific analysis
//w = (1.f-fabs(u))*(1.f-fabs(v));
// actually, Hanning window is ok, cos^2 for some reason is slower
w = (0.5f + 0.5f*cos((double)u*M_PI))*(0.5f + 0.5f*cos((double)v*M_PI));
mul_v3_fl(fcol, w);
qd_setPixel(ckrn, x, y, fcol);
}
}
convolve(tsrc, tsrc, ckrn);
free_compbuf(ckrn);
mixImages(dst, tsrc, 0.5f + 0.5f*ndg->mix);
free_compbuf(tsrc);
}
//--------------------------------------------------------------------------------------------
static void node_composit_exec_glare(void *UNUSED(data), bNode *node, bNodeStack **in, bNodeStack **out)
{
CompBuf *new, *src, *img = in[0]->data;
NodeGlare* ndg = node->storage;
if ((img == NULL) || (out[0]->hasoutput == 0)) return;
if (img->type != CB_RGBA) {
new = typecheck_compbuf(img, CB_RGBA);
src = typecheck_compbuf(img, CB_RGBA);
}
else {
new = dupalloc_compbuf(img);
src = dupalloc_compbuf(img);
}
{
int x, y;
for (y=0; y<new->y; ++y) {
fRGB* col = (fRGB*)&new->rect[y*new->x*new->type];
for (x=0; x<new->x; ++x) {
col[x][0] = MAX2(col[x][0], 0.f);
col[x][1] = MAX2(col[x][1], 0.f);
col[x][2] = MAX2(col[x][2], 0.f);
}
}
}
switch (ndg->type) {
case 0:
star4(ndg, new, src);
break;
case 1:
fglow(ndg, new, src);
break;
case 3:
ghosts(ndg, new, src);
break;
case 2:
default:
streaks(ndg, new, src);
break;
}
free_compbuf(src);
out[0]->data = new;
}
#endif /* WITH_COMPOSITOR_LEGACY */
static void node_composit_init_glare(bNodeTree *UNUSED(ntree), bNode *node, bNodeTemplate *UNUSED(ntemp))
{
NodeGlare *ndg = MEM_callocN(sizeof(NodeGlare), "node glare data");
@@ -502,9 +66,6 @@ void register_node_type_cmp_glare(bNodeTreeType *ttype)
node_type_size(&ntype, 150, 120, 200);
node_type_init(&ntype, node_composit_init_glare);
node_type_storage(&ntype, "NodeGlare", node_free_standard_storage, node_copy_standard_storage);
#ifdef WITH_COMPOSITOR_LEGACY
node_type_exec(&ntype, node_composit_exec_glare);
#endif
nodeRegisterType(ttype, &ntype);
}

View File

@@ -44,59 +44,6 @@ static bNodeSocketTemplate cmp_node_hue_sat_out[] = {
{ -1, 0, "" }
};
#ifdef WITH_COMPOSITOR_LEGACY
static void do_hue_sat_fac(bNode *node, float *out, float *in, float *fac)
{
NodeHueSat *nhs= node->storage;
if (*fac!=0.0f && (nhs->hue!=0.5f || nhs->sat!=1.0f || nhs->val!=1.0f)) {
float col[3], hsv[3], mfac= 1.0f - *fac;
rgb_to_hsv(in[0], in[1], in[2], hsv, hsv+1, hsv+2);
hsv[0]+= (nhs->hue - 0.5f);
if (hsv[0]>1.0f) hsv[0]-=1.0f; else if (hsv[0]<0.0f) hsv[0]+= 1.0f;
hsv[1]*= nhs->sat;
hsv[2]*= nhs->val;
hsv_to_rgb(hsv[0], hsv[1], hsv[2], col, col+1, col+2);
out[0] = mfac*in[0] + *fac*col[0];
out[1] = mfac*in[1] + *fac*col[1];
out[2] = mfac*in[2] + *fac*col[2];
out[3] = in[3];
}
else {
copy_v4_v4(out, in);
}
}
static void node_composit_exec_hue_sat(void *UNUSED(data), bNode *node, bNodeStack **in, bNodeStack **out)
{
/* stack order in: Fac, Image */
/* stack order out: Image */
if (out[0]->hasoutput==0) return;
/* input no image? then only color operation */
if (in[1]->data==NULL) {
do_hue_sat_fac(node, out[0]->vec, in[1]->vec, in[0]->vec);
}
else {
/* make output size of input image */
CompBuf *cbuf= dupalloc_compbuf(in[1]->data);
CompBuf *stackbuf=typecheck_compbuf(cbuf, CB_RGBA);
composit2_pixel_processor(node, stackbuf, stackbuf, in[1]->vec, in[0]->data, in[0]->vec, do_hue_sat_fac, CB_RGBA, CB_VAL);
out[0]->data= stackbuf;
/* get rid of intermediary cbuf if it's extra */
if (stackbuf!=cbuf)
free_compbuf(cbuf);
}
}
#endif /* WITH_COMPOSITOR_LEGACY */
static void node_composit_init_hue_sat(bNodeTree *UNUSED(ntree), bNode *node, bNodeTemplate *UNUSED(ntemp))
{
NodeHueSat *nhs= MEM_callocN(sizeof(NodeHueSat), "node hue sat");
@@ -115,9 +62,6 @@ void register_node_type_cmp_hue_sat(bNodeTreeType *ttype)
node_type_size(&ntype, 150, 80, 250);
node_type_init(&ntype, node_composit_init_hue_sat);
node_type_storage(&ntype, "NodeHueSat", node_free_standard_storage, node_copy_standard_storage);
#ifdef WITH_COMPOSITOR_LEGACY
node_type_exec(&ntype, node_composit_exec_hue_sat);
#endif
nodeRegisterType(ttype, &ntype);
}

View File

@@ -43,106 +43,6 @@ static bNodeSocketTemplate cmp_node_huecorrect_out[] = {
{ -1, 0, "" }
};
#ifdef WITH_COMPOSITOR_LEGACY
static void do_huecorrect(bNode *node, float *out, float *in)
{
float hsv[3], f;
rgb_to_hsv(in[0], in[1], in[2], hsv, hsv+1, hsv+2);
curvemapping_initialize(node->storage);
/* adjust hue, scaling returned default 0.5 up to 1 */
f = curvemapping_evaluateF(node->storage, 0, hsv[0]);
hsv[0] += f-0.5f;
/* adjust saturation, scaling returned default 0.5 up to 1 */
f = curvemapping_evaluateF(node->storage, 1, hsv[0]);
hsv[1] *= (f * 2.f);
/* adjust value, scaling returned default 0.5 up to 1 */
f = curvemapping_evaluateF(node->storage, 2, hsv[0]);
hsv[2] *= (f * 2.f);
hsv[0] = hsv[0] - floorf(hsv[0]); /* mod 1.0 */
CLAMP(hsv[1], 0.f, 1.f);
/* convert back to rgb */
hsv_to_rgb(hsv[0], hsv[1], hsv[2], out, out+1, out+2);
out[3] = in[3];
}
static void do_huecorrect_fac(bNode *node, float *out, float *in, float *fac)
{
float hsv[3], rgb[3], f;
const float mfac = 1.f-*fac;
rgb_to_hsv(in[0], in[1], in[2], hsv, hsv+1, hsv+2);
curvemapping_initialize(node->storage);
/* adjust hue, scaling returned default 0.5 up to 1 */
f = curvemapping_evaluateF(node->storage, 0, hsv[0]);
hsv[0] += f-0.5f;
/* adjust saturation, scaling returned default 0.5 up to 1 */
f = curvemapping_evaluateF(node->storage, 1, hsv[0]);
hsv[1] *= (f * 2.f);
/* adjust value, scaling returned default 0.5 up to 1 */
f = curvemapping_evaluateF(node->storage, 2, hsv[0]);
hsv[2] *= (f * 2.f);
hsv[0] = hsv[0] - floorf(hsv[0]); /* mod 1.0 */
CLAMP(hsv[1], 0.f, 1.f);
/* convert back to rgb */
hsv_to_rgb(hsv[0], hsv[1], hsv[2], rgb, rgb+1, rgb+2);
out[0] = mfac*in[0] + *fac*rgb[0];
out[1] = mfac*in[1] + *fac*rgb[1];
out[2] = mfac*in[2] + *fac*rgb[2];
out[3] = in[3];
}
static void node_composit_exec_huecorrect(void *UNUSED(data), bNode *node, bNodeStack **in, bNodeStack **out)
{
CompBuf *cbuf= in[1]->data;
CompBuf *stackbuf;
/* stack order input: fac, image, black level, white level */
/* stack order output: image */
if (out[0]->hasoutput==0)
return;
if (in[0]->vec[0] == 0.f && in[0]->data == NULL) {
out[0]->data = pass_on_compbuf(cbuf);
return;
}
/* input no image? then only color operation */
if (in[1]->data==NULL) {
do_huecorrect_fac(node, out[0]->vec, in[1]->vec, in[0]->vec);
}
if (cbuf) {
stackbuf= alloc_compbuf(cbuf->x, cbuf->y, CB_RGBA, 1); /* make output size of input image */
if ((in[0]->data==NULL) && (in[0]->vec[0] >= 1.f))
composit1_pixel_processor(node, stackbuf, in[1]->data, in[1]->vec, do_huecorrect, CB_RGBA);
else
composit2_pixel_processor(node, stackbuf, in[1]->data, in[1]->vec, in[0]->data, in[0]->vec, do_huecorrect_fac, CB_RGBA, CB_VAL);
out[0]->data= stackbuf;
}
}
#endif /* WITH_COMPOSITOR_LEGACY */
static void node_composit_init_huecorrect(bNodeTree *UNUSED(ntree), bNode *node, bNodeTemplate *UNUSED(ntemp))
{
CurveMapping *cumapping = node->storage= curvemapping_add(1, 0.0f, 0.0f, 1.0f, 1.0f);
@@ -168,9 +68,6 @@ void register_node_type_cmp_huecorrect(bNodeTreeType *ttype)
node_type_size(&ntype, 320, 140, 400);
node_type_init(&ntype, node_composit_init_huecorrect);
node_type_storage(&ntype, "CurveMapping", node_free_curves, node_copy_curves);
#ifdef WITH_COMPOSITOR_LEGACY
node_type_exec(&ntype, node_composit_exec_huecorrect);
#endif
nodeRegisterType(ttype, &ntype);
}

View File

@@ -44,72 +44,6 @@ static bNodeSocketTemplate cmp_node_idmask_out[] = {
{ -1, 0, "" }
};
#ifdef WITH_COMPOSITOR_LEGACY
/* stackbuf should be zeroed */
static void do_idmask(CompBuf *stackbuf, CompBuf *cbuf, float idnr)
{
float *rect;
int x;
char *abuf= MEM_mapallocN(cbuf->x*cbuf->y, "anti ali buf");
rect= cbuf->rect;
for (x= cbuf->x*cbuf->y - 1; x>=0; x--)
if (rect[x]==idnr)
abuf[x] = 255;
antialias_tagbuf(cbuf->x, cbuf->y, abuf);
rect= stackbuf->rect;
for (x= cbuf->x*cbuf->y - 1; x>=0; x--)
if (abuf[x]>1)
rect[x] = (1.0f/255.0f)*(float)abuf[x];
MEM_freeN(abuf);
}
/* full sample version */
static void do_idmask_fsa(CompBuf *stackbuf, CompBuf *cbuf, float idnr)
{
float *rect, *rs;
int x;
rect= cbuf->rect;
rs= stackbuf->rect;
for (x= cbuf->x*cbuf->y - 1; x>=0; x--)
if (rect[x]==idnr)
rs[x] = 1.0f;
}
static void node_composit_exec_idmask(void *data, bNode *node, bNodeStack **in, bNodeStack **out)
{
RenderData *rd= data;
if (out[0]->hasoutput==0)
return;
if (in[0]->data) {
CompBuf *cbuf= in[0]->data;
CompBuf *stackbuf;
if (cbuf->type!=CB_VAL)
return;
stackbuf= alloc_compbuf(cbuf->x, cbuf->y, CB_VAL, 1); /* allocs */;
if ((rd->scemode & R_FULL_SAMPLE) || node->custom2 == 0)
do_idmask_fsa(stackbuf, cbuf, (float)node->custom1);
else
do_idmask(stackbuf, cbuf, (float)node->custom1);
out[0]->data= stackbuf;
}
}
#endif /* WITH_COMPOSITOR_LEGACY */
void register_node_type_cmp_idmask(bNodeTreeType *ttype)
{
static bNodeType ntype;
@@ -117,9 +51,6 @@ void register_node_type_cmp_idmask(bNodeTreeType *ttype)
node_type_base(ttype, &ntype, CMP_NODE_ID_MASK, "ID Mask", NODE_CLASS_CONVERTOR, NODE_OPTIONS);
node_type_socket_templates(&ntype, cmp_node_idmask_in, cmp_node_idmask_out);
node_type_size(&ntype, 140, 100, 320);
#ifdef WITH_COMPOSITOR_LEGACY
node_type_exec(&ntype, node_composit_exec_idmask);
#endif
nodeRegisterType(ttype, &ntype);
}

View File

@@ -29,7 +29,6 @@
* \ingroup cmpnodes
*/
#include "node_composite_util.h"
/* **************** IMAGE (and RenderResult, multilayer image) ******************** */
@@ -285,242 +284,6 @@ static void cmp_node_image_update(bNodeTree *ntree, bNode *node)
cmp_node_image_verify_outputs(ntree, node);
}
#ifdef WITH_COMPOSITOR_LEGACY
/* float buffer from the image with matching color management */
float *node_composit_get_float_buffer(RenderData *rd, ImBuf *ibuf, int *alloc)
{
float *rect;
*alloc= FALSE;
/* OCIO_TODO: this is a part of legacy compositor system, don't bother with porting this code
* to new color management system since this code would likely be simply removed soon
*/
if (rd->color_mgt_flag & R_COLOR_MANAGEMENT) {
rect= ibuf->rect_float;
}
else {
rect= MEM_mapallocN(sizeof(float) * 4 * ibuf->x * ibuf->y, "node_composit_get_image");
IMB_buffer_float_from_float(rect, ibuf->rect_float,
4, IB_PROFILE_SRGB, IB_PROFILE_LINEAR_RGB, TRUE,
ibuf->x, ibuf->y, ibuf->x, ibuf->x);
*alloc= TRUE;
}
return rect;
}
/* note: this function is used for multilayer too, to ensure uniform
* handling with BKE_image_acquire_ibuf() */
static CompBuf *node_composit_get_image(RenderData *rd, Image *ima, ImageUser *iuser)
{
ImBuf *ibuf;
CompBuf *stackbuf;
int type;
float *rect;
int alloc= FALSE;
ibuf= BKE_image_acquire_ibuf(ima, iuser, NULL);
if (ibuf==NULL || (ibuf->rect==NULL && ibuf->rect_float==NULL)) {
return NULL;
}
if (ibuf->rect_float == NULL) {
IMB_float_from_rect(ibuf);
}
/* now we need a float buffer from the image with matching color management */
/* XXX weak code, multilayer is excluded from this */
if (ibuf->channels == 4 && ima->rr==NULL) {
rect= node_composit_get_float_buffer(rd, ibuf, &alloc);
}
else {
/* non-rgba passes can't use color profiles */
rect= ibuf->rect_float;
}
/* done coercing into the correct color management */
type= ibuf->channels;
if (rd->scemode & R_COMP_CROP) {
stackbuf= get_cropped_compbuf(&rd->disprect, rect, ibuf->x, ibuf->y, type);
if (alloc)
MEM_freeN(rect);
}
else {
/* we put imbuf copy on stack, cbuf knows rect is from other ibuf when freed! */
stackbuf= alloc_compbuf(ibuf->x, ibuf->y, type, FALSE);
stackbuf->rect= rect;
stackbuf->malloc= alloc;
}
/* code to respect the premul flag of images; I'm
* not sure if this is a good idea for multilayer images,
* since it never worked before for them.
*/
#if 0
if (type==CB_RGBA && ima->flag & IMA_DO_PREMUL) {
//premul the image
int i;
float *pixel = stackbuf->rect;
for (i=0; i<stackbuf->x*stackbuf->y; i++, pixel += 4) {
pixel[0] *= pixel[3];
pixel[1] *= pixel[3];
pixel[2] *= pixel[3];
}
}
#endif
BKE_image_release_ibuf(ima, ibuf, NULL);
return stackbuf;
}
static CompBuf *node_composit_get_zimage(bNode *node, RenderData *rd)
{
ImBuf *ibuf= BKE_image_acquire_ibuf((Image *)node->id, node->storage, NULL);
CompBuf *zbuf= NULL;
if (ibuf && ibuf->zbuf_float) {
if (rd->scemode & R_COMP_CROP) {
zbuf= get_cropped_compbuf(&rd->disprect, ibuf->zbuf_float, ibuf->x, ibuf->y, CB_VAL);
}
else {
zbuf= alloc_compbuf(ibuf->x, ibuf->y, CB_VAL, 0);
zbuf->rect= ibuf->zbuf_float;
}
}
BKE_image_release_ibuf((Image *)node->id, ibuf, NULL);
return zbuf;
}
/* check if layer is available, returns pass buffer */
static CompBuf *compbuf_multilayer_get(RenderData *rd, RenderLayer *rl, Image *ima, ImageUser *iuser, int passindex)
{
RenderPass *rpass = BLI_findlink(&rl->passes, passindex);
if (rpass) {
CompBuf *cbuf;
iuser->pass = passindex;
BKE_image_multilayer_index(ima->rr, iuser);
cbuf = node_composit_get_image(rd, ima, iuser);
return cbuf;
}
return NULL;
}
static void node_composit_exec_image(void *data, bNode *node, bNodeStack **UNUSED(in), bNodeStack **out)
{
/* image assigned to output */
/* stack order input sockets: col, alpha */
if (node->id) {
RenderData *rd= data;
Image *ima= (Image *)node->id;
ImageUser *iuser= (ImageUser *)node->storage;
ImBuf *ibuf = NULL;
/* first set the right frame number in iuser */
BKE_image_user_frame_calc(iuser, rd->cfra, 0);
/* force a load, we assume iuser index will be set OK anyway */
if (ima->type==IMA_TYPE_MULTILAYER)
ibuf = BKE_image_acquire_ibuf(ima, iuser, NULL);
if (ima->type==IMA_TYPE_MULTILAYER && ima->rr) {
RenderLayer *rl= BLI_findlink(&ima->rr->layers, iuser->layer);
if (rl) {
bNodeSocket *sock;
NodeImageLayer *sockdata;
int out_index;
CompBuf *combinedbuf= NULL, *firstbuf= NULL;
for (sock=node->outputs.first, out_index=0; sock; sock=sock->next, ++out_index) {
sockdata = sock->storage;
if (out[out_index]->hasoutput) {
CompBuf *stackbuf = out[out_index]->data = compbuf_multilayer_get(rd, rl, ima, iuser, sockdata->pass_index);
if (stackbuf) {
/* preview policy: take first 'Combined' pass if available,
* otherwise just use the first layer.
*/
if (!firstbuf) {
firstbuf = stackbuf;
}
if (!combinedbuf &&
(strcmp(sock->name, "Combined") == 0 || strcmp(sock->name, "Image") == 0))
{
combinedbuf = stackbuf;
}
}
}
}
/* preview */
if (combinedbuf)
generate_preview(data, node, combinedbuf);
else if (firstbuf)
generate_preview(data, node, firstbuf);
}
}
else {
CompBuf *stackbuf = node_composit_get_image(rd, ima, iuser);
if (stackbuf) {
int num_outputs = BLI_countlist(&node->outputs);
/*respect image premul option*/
if (stackbuf->type==CB_RGBA && ima->flag & IMA_DO_PREMUL) {
int i;
float *pixel;
/* first duplicate stackbuf->rect, since it's just a pointer
* to the source imbuf, and we don't want to change that.*/
stackbuf->rect = MEM_dupallocN(stackbuf->rect);
/* since stackbuf now has allocated memory, rather than just a pointer,
* mark it as allocated so it can be freed properly */
stackbuf->malloc=1;
/*premul the image*/
pixel = stackbuf->rect;
for (i=0; i<stackbuf->x*stackbuf->y; i++, pixel += 4) {
pixel[0] *= pixel[3];
pixel[1] *= pixel[3];
pixel[2] *= pixel[3];
}
}
/* put image on stack */
if (num_outputs > 0)
out[0]->data= stackbuf;
/* alpha output */
if (num_outputs > 1 && out[1]->hasoutput)
out[1]->data= valbuf_from_rgbabuf(stackbuf, CHAN_A);
/* Z output */
if (num_outputs > 2 && out[2]->hasoutput)
out[2]->data= node_composit_get_zimage(node, rd);
/* preview */
generate_preview(data, node, stackbuf);
}
}
BKE_image_release_ibuf(ima, ibuf, NULL);
}
}
#endif /* WITH_COMPOSITOR_LEGACY */
static void node_composit_init_image(bNodeTree *ntree, bNode *node, bNodeTemplate *UNUSED(ntemp))
{
ImageUser *iuser= MEM_callocN(sizeof(ImageUser), "node image user");
@@ -565,9 +328,6 @@ void register_node_type_cmp_image(bNodeTreeType *ttype)
node_type_init(&ntype, node_composit_init_image);
node_type_storage(&ntype, "ImageUser", node_composit_free_image, node_composit_copy_image);
node_type_update(&ntype, cmp_node_image_update, NULL);
#ifdef WITH_COMPOSITOR_LEGACY
node_type_exec(&ntype, node_composit_exec_image);
#endif
nodeRegisterType(ttype, &ntype);
}
@@ -575,141 +335,6 @@ void register_node_type_cmp_image(bNodeTreeType *ttype)
/* **************** RENDER RESULT ******************** */
#ifdef WITH_COMPOSITOR_LEGACY
static CompBuf *compbuf_from_pass(RenderData *rd, RenderLayer *rl, int rectx, int recty, int passcode)
{
float *fp= RE_RenderLayerGetPass(rl, passcode);
if (fp) {
CompBuf *buf;
int buftype= CB_VEC3;
if (ELEM4(passcode, SCE_PASS_Z, SCE_PASS_INDEXOB, SCE_PASS_MIST, SCE_PASS_INDEXMA))
buftype= CB_VAL;
else if (passcode==SCE_PASS_VECTOR)
buftype= CB_VEC4;
else if (ELEM(passcode, SCE_PASS_COMBINED, SCE_PASS_RGBA))
buftype= CB_RGBA;
if (rd->scemode & R_COMP_CROP)
buf= get_cropped_compbuf(&rd->disprect, fp, rectx, recty, buftype);
else {
buf= alloc_compbuf(rectx, recty, buftype, 0);
buf->rect= fp;
}
return buf;
}
return NULL;
}
static void node_composit_rlayers_out(RenderData *rd, RenderLayer *rl, bNodeStack **out, int rectx, int recty)
{
if (out[RRES_OUT_Z]->hasoutput)
out[RRES_OUT_Z]->data= compbuf_from_pass(rd, rl, rectx, recty, SCE_PASS_Z);
if (out[RRES_OUT_VEC]->hasoutput)
out[RRES_OUT_VEC]->data= compbuf_from_pass(rd, rl, rectx, recty, SCE_PASS_VECTOR);
if (out[RRES_OUT_NORMAL]->hasoutput)
out[RRES_OUT_NORMAL]->data= compbuf_from_pass(rd, rl, rectx, recty, SCE_PASS_NORMAL);
if (out[RRES_OUT_UV]->hasoutput)
out[RRES_OUT_UV]->data= compbuf_from_pass(rd, rl, rectx, recty, SCE_PASS_UV);
if (out[RRES_OUT_RGBA]->hasoutput)
out[RRES_OUT_RGBA]->data= compbuf_from_pass(rd, rl, rectx, recty, SCE_PASS_RGBA);
if (out[RRES_OUT_DIFF]->hasoutput)
out[RRES_OUT_DIFF]->data= compbuf_from_pass(rd, rl, rectx, recty, SCE_PASS_DIFFUSE);
if (out[RRES_OUT_SPEC]->hasoutput)
out[RRES_OUT_SPEC]->data= compbuf_from_pass(rd, rl, rectx, recty, SCE_PASS_SPEC);
if (out[RRES_OUT_SHADOW]->hasoutput)
out[RRES_OUT_SHADOW]->data= compbuf_from_pass(rd, rl, rectx, recty, SCE_PASS_SHADOW);
if (out[RRES_OUT_AO]->hasoutput)
out[RRES_OUT_AO]->data= compbuf_from_pass(rd, rl, rectx, recty, SCE_PASS_AO);
if (out[RRES_OUT_REFLECT]->hasoutput)
out[RRES_OUT_REFLECT]->data= compbuf_from_pass(rd, rl, rectx, recty, SCE_PASS_REFLECT);
if (out[RRES_OUT_REFRACT]->hasoutput)
out[RRES_OUT_REFRACT]->data= compbuf_from_pass(rd, rl, rectx, recty, SCE_PASS_REFRACT);
if (out[RRES_OUT_INDIRECT]->hasoutput)
out[RRES_OUT_INDIRECT]->data= compbuf_from_pass(rd, rl, rectx, recty, SCE_PASS_INDIRECT);
if (out[RRES_OUT_INDEXOB]->hasoutput)
out[RRES_OUT_INDEXOB]->data= compbuf_from_pass(rd, rl, rectx, recty, SCE_PASS_INDEXOB);
if (out[RRES_OUT_INDEXMA]->hasoutput)
out[RRES_OUT_INDEXMA]->data= compbuf_from_pass(rd, rl, rectx, recty, SCE_PASS_INDEXMA);
if (out[RRES_OUT_MIST]->hasoutput)
out[RRES_OUT_MIST]->data= compbuf_from_pass(rd, rl, rectx, recty, SCE_PASS_MIST);
if (out[RRES_OUT_EMIT]->hasoutput)
out[RRES_OUT_EMIT]->data= compbuf_from_pass(rd, rl, rectx, recty, SCE_PASS_EMIT);
if (out[RRES_OUT_ENV]->hasoutput)
out[RRES_OUT_ENV]->data= compbuf_from_pass(rd, rl, rectx, recty, SCE_PASS_ENVIRONMENT);
if (out[RRES_OUT_DIFF_DIRECT]->hasoutput)
out[RRES_OUT_DIFF_DIRECT]->data= compbuf_from_pass(rd, rl, rectx, recty, SCE_PASS_DIFFUSE_DIRECT);
if (out[RRES_OUT_DIFF_INDIRECT]->hasoutput)
out[RRES_OUT_DIFF_INDIRECT]->data= compbuf_from_pass(rd, rl, rectx, recty, SCE_PASS_DIFFUSE_INDIRECT);
if (out[RRES_OUT_DIFF_COLOR]->hasoutput)
out[RRES_OUT_DIFF_COLOR]->data= compbuf_from_pass(rd, rl, rectx, recty, SCE_PASS_DIFFUSE_COLOR);
if (out[RRES_OUT_GLOSSY_DIRECT]->hasoutput)
out[RRES_OUT_GLOSSY_DIRECT]->data= compbuf_from_pass(rd, rl, rectx, recty, SCE_PASS_GLOSSY_DIRECT);
if (out[RRES_OUT_GLOSSY_INDIRECT]->hasoutput)
out[RRES_OUT_GLOSSY_INDIRECT]->data= compbuf_from_pass(rd, rl, rectx, recty, SCE_PASS_GLOSSY_INDIRECT);
if (out[RRES_OUT_GLOSSY_COLOR]->hasoutput)
out[RRES_OUT_GLOSSY_COLOR]->data= compbuf_from_pass(rd, rl, rectx, recty, SCE_PASS_GLOSSY_COLOR);
if (out[RRES_OUT_TRANSM_DIRECT]->hasoutput)
out[RRES_OUT_TRANSM_DIRECT]->data= compbuf_from_pass(rd, rl, rectx, recty, SCE_PASS_TRANSM_DIRECT);
if (out[RRES_OUT_TRANSM_INDIRECT]->hasoutput)
out[RRES_OUT_TRANSM_INDIRECT]->data= compbuf_from_pass(rd, rl, rectx, recty, SCE_PASS_TRANSM_INDIRECT);
if (out[RRES_OUT_TRANSM_COLOR]->hasoutput)
out[RRES_OUT_TRANSM_COLOR]->data= compbuf_from_pass(rd, rl, rectx, recty, SCE_PASS_TRANSM_COLOR);
}
static void node_composit_exec_rlayers(void *data, bNode *node, bNodeStack **UNUSED(in), bNodeStack **out)
{
Scene *sce= (Scene *)node->id;
Render *re= (sce)? RE_GetRender(sce->id.name): NULL;
RenderData *rd= data;
RenderResult *rr= NULL;
if (re)
rr= RE_AcquireResultRead(re);
if (rr) {
SceneRenderLayer *srl= BLI_findlink(&sce->r.layers, node->custom1);
if (srl) {
RenderLayer *rl= RE_GetRenderLayer(rr, srl->name);
if (rl && rl->rectf) {
CompBuf *stackbuf;
/* we put render rect on stack, cbuf knows rect is from other ibuf when freed! */
if (rd->scemode & R_COMP_CROP)
stackbuf= get_cropped_compbuf(&rd->disprect, rl->rectf, rr->rectx, rr->recty, CB_RGBA);
else {
stackbuf= alloc_compbuf(rr->rectx, rr->recty, CB_RGBA, 0);
stackbuf->rect= rl->rectf;
}
if (stackbuf==NULL) {
printf("Error; Preview Panel in UV Window returns zero sized image\n");
}
else {
stackbuf->xof= rr->xof;
stackbuf->yof= rr->yof;
/* put on stack */
out[RRES_OUT_IMAGE]->data= stackbuf;
if (out[RRES_OUT_ALPHA]->hasoutput)
out[RRES_OUT_ALPHA]->data= valbuf_from_rgbabuf(stackbuf, CHAN_A);
node_composit_rlayers_out(rd, rl, out, rr->rectx, rr->recty);
generate_preview(data, node, stackbuf);
}
}
}
}
if (re)
RE_ReleaseResult(re);
}
#endif /* WITH_COMPOSITOR_LEGACY */
void register_node_type_cmp_rlayers(bNodeTreeType *ttype)
{
static bNodeType ntype;
@@ -717,9 +342,6 @@ void register_node_type_cmp_rlayers(bNodeTreeType *ttype)
node_type_base(ttype, &ntype, CMP_NODE_R_LAYERS, "Render Layers", NODE_CLASS_INPUT, NODE_PREVIEW|NODE_OPTIONS);
node_type_socket_templates(&ntype, NULL, cmp_node_rlayers_out);
node_type_size(&ntype, 150, 100, 300);
#ifdef WITH_COMPOSITOR_LEGACY
node_type_exec(&ntype, node_composit_exec_rlayers);
#endif
nodeRegisterType(ttype, &ntype);
}

View File

@@ -44,15 +44,6 @@ static bNodeSocketTemplate cmp_node_inpaint_out[] = {
{ -1, 0, "" }
};
#ifdef WITH_COMPOSITOR_LEGACY
static void node_composit_exec_inpaint(void *UNUSED(data), bNode *UNUSED(node), bNodeStack **UNUSED(in), bNodeStack **UNUSED(out))
{
/* pass */
}
#endif /* WITH_COMPOSITOR_LEGACY */
void register_node_type_cmp_inpaint(bNodeTreeType *ttype)
{
static bNodeType ntype;
@@ -60,9 +51,6 @@ void register_node_type_cmp_inpaint(bNodeTreeType *ttype)
node_type_base(ttype, &ntype, CMP_NODE_INPAINT, "Inpaint", NODE_CLASS_OP_FILTER, NODE_OPTIONS);
node_type_socket_templates(&ntype, cmp_node_inpaint_in, cmp_node_inpaint_out);
node_type_size(&ntype, 130, 100, 320);
#ifdef WITH_COMPOSITOR_LEGACY
node_type_exec(&ntype, node_composit_exec_inpaint);
#endif
nodeRegisterType(ttype, &ntype);
}

View File

@@ -43,82 +43,6 @@ static bNodeSocketTemplate cmp_node_invert_out[] = {
{ -1, 0, "" }
};
#ifdef WITH_COMPOSITOR_LEGACY
static void do_invert(bNode *node, float *out, float *in)
{
if (node->custom1 & CMP_CHAN_RGB) {
out[0] = 1.0f - in[0];
out[1] = 1.0f - in[1];
out[2] = 1.0f - in[2];
}
else {
copy_v3_v3(out, in);
}
if (node->custom1 & CMP_CHAN_A)
out[3] = 1.0f - in[3];
else
out[3] = in[3];
}
static void do_invert_fac(bNode *node, float *out, float *in, float *fac)
{
float col[4], facm;
do_invert(node, col, in);
/* blend inverted result against original input with fac */
facm = 1.0f - fac[0];
if (node->custom1 & CMP_CHAN_RGB) {
col[0] = fac[0]*col[0] + (facm*in[0]);
col[1] = fac[0]*col[1] + (facm*in[1]);
col[2] = fac[0]*col[2] + (facm*in[2]);
}
if (node->custom1 & CMP_CHAN_A)
col[3] = fac[0]*col[3] + (facm*in[3]);
copy_v4_v4(out, col);
}
static void node_composit_exec_invert(void *UNUSED(data), bNode *node, bNodeStack **in, bNodeStack **out)
{
/* stack order in: fac, Image, Image */
/* stack order out: Image */
float *fac= in[0]->vec;
if (out[0]->hasoutput==0) return;
/* input no image? then only color operation */
if (in[1]->data==NULL && in[0]->data==NULL) {
do_invert_fac(node, out[0]->vec, in[1]->vec, fac);
}
else {
/* make output size of first available input image, or then size of fac */
CompBuf *cbuf= in[1]->data?in[1]->data:in[0]->data;
/* if neither RGB or A toggled on, pass through */
if (node->custom1 != 0) {
CompBuf *stackbuf= alloc_compbuf(cbuf->x, cbuf->y, CB_RGBA, 1); /* allocs */
if (fac[0] < 1.0f || in[0]->data!=NULL)
composit2_pixel_processor(node, stackbuf, in[1]->data, in[1]->vec, in[0]->data, fac, do_invert_fac, CB_RGBA, CB_VAL);
else
composit1_pixel_processor(node, stackbuf, in[1]->data, in[1]->vec, do_invert, CB_RGBA);
out[0]->data= stackbuf;
return;
}
else {
out[0]->data = pass_on_compbuf(cbuf);
return;
}
}
}
#endif /* WITH_COMPOSITOR_LEGACY */
static void node_composit_init_invert(bNodeTree *UNUSED(ntree), bNode *node, bNodeTemplate *UNUSED(ntemp))
{
node->custom1 |= CMP_CHAN_RGB;
@@ -133,9 +57,6 @@ void register_node_type_cmp_invert(bNodeTreeType *ttype)
node_type_socket_templates(&ntype, cmp_node_invert_in, cmp_node_invert_out);
node_type_size(&ntype, 120, 120, 140);
node_type_init(&ntype, node_composit_init_invert);
#ifdef WITH_COMPOSITOR_LEGACY
node_type_exec(&ntype, node_composit_exec_invert);
#endif
nodeRegisterType(ttype, &ntype);
}

View File

@@ -60,13 +60,6 @@ static bNodeSocketTemplate cmp_node_keying_out[] = {
{ -1, 0, "" }
};
#ifdef WITH_COMPOSITOR_LEGACY
static void node_composit_exec_keying(void *UNUSED(data), bNode *UNUSED(node), bNodeStack **UNUSED(in), bNodeStack **UNUSED(out))
{
/* pass */
}
#endif /* WITH_COMPOSITOR_LEGACY */
static void node_composit_init_keying(bNodeTree *UNUSED(ntree), bNode *node, bNodeTemplate *UNUSED(ntemp))
{
NodeKeyingData *data;
@@ -94,9 +87,6 @@ void register_node_type_cmp_keying(bNodeTreeType *ttype)
node_type_size(&ntype, 140, 100, 320);
node_type_init(&ntype, node_composit_init_keying);
node_type_storage(&ntype, "NodeKeyingData", node_free_standard_storage, node_copy_standard_storage);
#ifdef WITH_COMPOSITOR_LEGACY
node_type_exec(&ntype, node_composit_exec_keying);
#endif
nodeRegisterType(ttype, &ntype);
}

View File

@@ -50,140 +50,6 @@ static bNodeSocketTemplate cmp_node_keyingscreen_out[] = {
{ -1, 0, "" }
};
#ifdef WITH_COMPOSITOR_LEGACY
static void compute_gradient_screen(RenderData *rd, NodeKeyingScreenData *keyingscreen_data, MovieClip *clip, CompBuf *screenbuf)
{
MovieClipUser user = {0};
MovieTracking *tracking = &clip->tracking;
MovieTrackingTrack *track;
VoronoiTriangulationPoint *triangulated_points;
VoronoiSite *sites;
ImBuf *ibuf;
ListBase *tracksbase;
ListBase edges = {NULL, NULL};
int sites_total, triangulated_points_total, triangles_total;
int (*triangles)[3];
int i, x, y;
float *rect = screenbuf->rect;
if (keyingscreen_data->tracking_object[0]) {
MovieTrackingObject *object = BKE_tracking_object_get_named(tracking, keyingscreen_data->tracking_object);
if (!object)
return;
tracksbase = BKE_tracking_object_get_tracks(tracking, object);
}
else
tracksbase = BKE_tracking_get_active_tracks(tracking);
sites_total = BLI_countlist(tracksbase);
if (!sites_total)
return;
BKE_movieclip_user_set_frame(&user, rd->cfra);
ibuf = BKE_movieclip_get_ibuf(clip, &user);
sites = MEM_callocN(sizeof(VoronoiSite) * sites_total, "keyingscreen voronoi sites");
track = tracksbase->first;
i = 0;
while (track) {
VoronoiSite *site = &sites[i];
MovieTrackingMarker *marker = BKE_tracking_marker_get(track, rd->cfra);
ImBuf *pattern_ibuf = BKE_tracking_get_pattern_imbuf(ibuf, track, marker, TRUE, FALSE);
int j;
zero_v3(site->color);
if (pattern_ibuf) {
for (j = 0; j < pattern_ibuf->x * pattern_ibuf->y; j++) {
if (pattern_ibuf->rect_float) {
add_v3_v3(site->color, &pattern_ibuf->rect_float[4 * j]);
}
else {
unsigned char *rrgb = (unsigned char *)pattern_ibuf->rect;
site->color[0] += srgb_to_linearrgb((float)rrgb[4 * j + 0] / 255.0f);
site->color[1] += srgb_to_linearrgb((float)rrgb[4 * j + 1] / 255.0f);
site->color[2] += srgb_to_linearrgb((float)rrgb[4 * j + 2] / 255.0f);
}
}
mul_v3_fl(site->color, 1.0f / (pattern_ibuf->x * pattern_ibuf->y));
IMB_freeImBuf(pattern_ibuf);
}
site->co[0] = marker->pos[0] * screenbuf->x;
site->co[1] = marker->pos[1] * screenbuf->y;
track = track->next;
i++;
}
IMB_freeImBuf(ibuf);
BLI_voronoi_compute(sites, sites_total, screenbuf->x, screenbuf->y, &edges);
BLI_voronoi_triangulate(sites, sites_total, &edges, screenbuf->x, screenbuf->y,
&triangulated_points, &triangulated_points_total,
&triangles, &triangles_total);
for (y = 0; y < screenbuf->y; y++) {
for (x = 0; x < screenbuf->x; x++) {
int index = 4 * (y * screenbuf->x + x);
rect[index + 0] = rect[index + 1] = rect[index + 2] = 0.0f;
rect[index + 3] = 1.0f;
for (i = 0; i < triangles_total; i++) {
int *triangle = triangles[i];
VoronoiTriangulationPoint *a = &triangulated_points[triangle[0]],
*b = &triangulated_points[triangle[1]],
*c = &triangulated_points[triangle[2]];
float co[2] = {x, y}, w[3];
if (barycentric_coords_v2(a->co, b->co, c->co, co, w)) {
if (barycentric_inside_triangle_v2(w)) {
rect[index + 0] += a->color[0] * w[0] + b->color[0] * w[1] + c->color[0] * w[2];
rect[index + 1] += a->color[1] * w[0] + b->color[1] * w[1] + c->color[1] * w[2];
rect[index + 2] += a->color[2] * w[0] + b->color[2] * w[1] + c->color[2] * w[2];
}
}
}
}
}
MEM_freeN(triangulated_points);
MEM_freeN(triangles);
MEM_freeN(sites);
BLI_freelistN(&edges);
}
static void node_composit_exec_keyingscreen(void *data, bNode *node, bNodeStack **UNUSED(in), bNodeStack **out)
{
NodeKeyingScreenData *keyingscreen_data = node->storage;
RenderData *rd = data;
CompBuf *screenbuf = NULL;
if (node->id) {
MovieClip *clip = (MovieClip *) node->id;
MovieClipUser user = {0};
int width, height;
BKE_movieclip_user_set_frame(&user, rd->cfra);
BKE_movieclip_get_size(clip, &user, &width, &height);
screenbuf = alloc_compbuf(width, height, CB_RGBA, TRUE);
compute_gradient_screen(rd, keyingscreen_data, clip, screenbuf);
}
out[0]->data = screenbuf;
}
#endif /* WITH_COMPOSITOR_LEGACY */
static void node_composit_init_keyingscreen(bNodeTree *UNUSED(ntree), bNode *node, bNodeTemplate *UNUSED(ntemp))
{
NodeKeyingScreenData *data;
@@ -202,9 +68,6 @@ void register_node_type_cmp_keyingscreen(bNodeTreeType *ttype)
node_type_size(&ntype, 140, 100, 320);
node_type_init(&ntype, node_composit_init_keyingscreen);
node_type_storage(&ntype, "NodeKeyingScreenData", node_free_standard_storage, node_copy_standard_storage);
#ifdef WITH_COMPOSITOR_LEGACY
node_type_exec(&ntype, node_composit_exec_keyingscreen);
#endif
nodeRegisterType(ttype, &ntype);
}

View File

@@ -43,149 +43,6 @@ static bNodeSocketTemplate cmp_node_lensdist_out[] = {
{ -1, 0, "" }
};
#ifdef WITH_COMPOSITOR_LEGACY
/* assumes *dst is type RGBA */
static void lensDistort(CompBuf *dst, CompBuf *src, float kr, float kg, float kb, int jit, int proj, int fit)
{
int x, y, z;
const float cx = 0.5f*(float)dst->x, cy = 0.5f*(float)dst->y;
if (proj) {
// shift
CompBuf *tsrc = dupalloc_compbuf(src);
for (z=0; z<tsrc->type; ++z)
IIR_gauss(tsrc, (kr+0.5f)*(kr+0.5f), z, 1);
kr *= 20.f;
for (y=0; y<dst->y; y++) {
fRGB *colp = (fRGB*)&dst->rect[y*dst->x*dst->type];
const float v = (y + 0.5f)/(float)dst->y;
for (x=0; x<dst->x; x++) {
const float u = (x + 0.5f)/(float)dst->x;
qd_getPixelLerpChan(tsrc, (u*dst->x + kr) - 0.5f, v*dst->y - 0.5f, 0, colp[x]);
if (tsrc->type == CB_VAL)
colp[x][1] = tsrc->rect[x + y*tsrc->x];
else
colp[x][1] = tsrc->rect[(x + y*tsrc->x)*tsrc->type + 1];
qd_getPixelLerpChan(tsrc, (u*dst->x - kr) - 0.5f, v*dst->y - 0.5f, 2, colp[x]+2);
/* set alpha */
colp[x][3] = 1.0f;
}
}
free_compbuf(tsrc);
}
else {
// Spherical
// Scale factor to make bottom/top & right/left sides fit in window after deform
// so in the case of pincushion (kn < 0), corners will be outside window.
// Now also optionally scales image such that black areas are not visible when distort factor is positive
// (makes distorted corners match window corners, but really only valid if mk<=0.5)
const float mk = max_fff(kr, kg, kb);
const float sc = (fit && (mk > 0.f)) ? (1.f/(1.f + 2.f*mk)) : (1.f/(1.f + mk));
const float drg = 4.f*(kg - kr), dgb = 4.f*(kb - kg);
kr *= 4.f, kg *= 4.f, kb *= 4.f;
for (y=0; y<dst->y; y++) {
fRGB *colp = (fRGB*)&dst->rect[y*dst->x*dst->type];
const float v = sc*((y + 0.5f) - cy)/cy;
for (x=0; x<dst->x; x++) {
int dr = 0, dg = 0, db = 0;
float d, t, ln[6] = {0, 0, 0, 0, 0, 0};
fRGB c1, tc = {0, 0, 0, 0};
const float u = sc*((x + 0.5f) - cx)/cx;
const float uv_dot = u * u + v * v;
int sta = 0, mid = 0, end = 0;
if ((t = 1.f - kr*uv_dot) >= 0.f) {
d = 1.f/(1.f + sqrtf(t));
ln[0] = (u*d + 0.5f)*dst->x - 0.5f, ln[1] = (v*d + 0.5f)*dst->y - 0.5f;
sta = 1;
}
if ((t = 1.f - kg*uv_dot) >= 0.f) {
d = 1.f/(1.f + sqrtf(t));
ln[2] = (u*d + 0.5f)*dst->x - 0.5f, ln[3] = (v*d + 0.5f)*dst->y - 0.5f;
mid = 1;
}
if ((t = 1.f - kb*uv_dot) >= 0.f) {
d = 1.f/(1.f + sqrtf(t));
ln[4] = (u*d + 0.5f)*dst->x - 0.5f, ln[5] = (v*d + 0.5f)*dst->y - 0.5f;
end = 1;
}
if (sta && mid && end) {
// RG
const int dx = ln[2] - ln[0], dy = ln[3] - ln[1];
const float dsf = sqrtf(dx*dx + dy*dy) + 1.f;
const int ds = (int)(jit ? ((dsf < 4.f) ? 2.f : sqrtf(dsf)) : dsf);
const float sd = 1.f/(float)ds;
for (z=0; z<ds; ++z) {
const float tz = ((float)z + (jit ? BLI_frand() : 0.5f))*sd;
t = 1.f - (kr + tz*drg)*uv_dot;
d = 1.f / (1.f + sqrtf(t));
qd_getPixelLerp(src, (u*d + 0.5f)*dst->x - 0.5f, (v*d + 0.5f)*dst->y - 0.5f, c1);
if (src->type == CB_VAL) c1[1] = c1[2] = c1[0];
tc[0] += (1.f-tz)*c1[0], tc[1] += tz*c1[1];
dr++, dg++;
}
// GB
{
const int dx = ln[4] - ln[2], dy = ln[5] - ln[3];
const float dsf = sqrtf(dx*dx + dy*dy) + 1.f;
const int ds = (int)(jit ? ((dsf < 4.f) ? 2.f : sqrtf(dsf)) : dsf);
const float sd = 1.f/(float)ds;
for (z=0; z<ds; ++z) {
const float tz = ((float)z + (jit ? BLI_frand() : 0.5f))*sd;
t = 1.f - (kg + tz*dgb)*uv_dot;
d = 1.f / (1.f + sqrtf(t));
qd_getPixelLerp(src, (u*d + 0.5f)*dst->x - 0.5f, (v*d + 0.5f)*dst->y - 0.5f, c1);
if (src->type == CB_VAL) c1[1] = c1[2] = c1[0];
tc[1] += (1.f-tz)*c1[1], tc[2] += tz*c1[2];
dg++, db++;
}
}
}
if (dr) colp[x][0] = 2.f*tc[0] / (float)dr;
if (dg) colp[x][1] = 2.f*tc[1] / (float)dg;
if (db) colp[x][2] = 2.f*tc[2] / (float)db;
/* set alpha */
colp[x][3] = 1.0f;
}
}
}
}
static void node_composit_exec_lensdist(void *UNUSED(data), bNode *node, bNodeStack **in, bNodeStack **out)
{
CompBuf *new, *img = in[0]->data;
NodeLensDist *nld = node->storage;
const float k = MAX2(MIN2(in[1]->vec[0], 1.f), -0.999f);
// smaller dispersion range for somewhat more control
const float d = 0.25f*MAX2(MIN2(in[2]->vec[0], 1.f), 0.f);
const float kr = MAX2(MIN2((k+d), 1.f), -0.999f), kb = MAX2(MIN2((k-d), 1.f), -0.999f);
if ((img==NULL) || (out[0]->hasoutput==0)) return;
new = alloc_compbuf(img->x, img->y, CB_RGBA, 1);
lensDistort(new, img, (nld->proj ? d : kr), k, kb, nld->jit, nld->proj, nld->fit);
out[0]->data = new;
}
#endif /* WITH_COMPOSITOR_LEGACY */
static void node_composit_init_lensdist(bNodeTree *UNUSED(ntree), bNode *node, bNodeTemplate *UNUSED(ntemp))
{
NodeLensDist *nld = MEM_callocN(sizeof(NodeLensDist), "node lensdist data");
@@ -203,9 +60,6 @@ void register_node_type_cmp_lensdist(bNodeTreeType *ttype)
node_type_size(&ntype, 150, 120, 200);
node_type_init(&ntype, node_composit_init_lensdist);
node_type_storage(&ntype, "NodeLensDist", node_free_standard_storage, node_copy_standard_storage);
#ifdef WITH_COMPOSITOR_LEGACY
node_type_exec(&ntype, node_composit_exec_lensdist);
#endif
nodeRegisterType(ttype, &ntype);
}

View File

@@ -45,274 +45,6 @@ static bNodeSocketTemplate cmp_node_view_levels_out[] = {
{-1, 0, ""}
};
#ifdef WITH_COMPOSITOR_LEGACY
static void fill_bins(bNode *node, CompBuf* in, int* bins)
{
float value[4];
int ivalue=0;
int x, y;
/*fill bins */
for (y=0; y<in->y; y++) {
for (x=0; x<in->x; x++) {
/* get the pixel */
qd_getPixel(in, x, y, value);
if (value[3] > 0.0f) { /* don't count transparent pixels */
switch (node->custom1) {
case 1: { /* all colors */
value[0] = rgb_to_bw(value);
value[0]=value[0]*255; /* scale to 0-255 range */
ivalue=(int)value[0];
break;
}
case 2: { /* red channel */
value[0]=value[0]*255; /* scale to 0-255 range */
ivalue=(int)value[0];
break;
}
case 3: { /* green channel */
value[1]=value[1]*255; /* scale to 0-255 range */
ivalue=(int)value[1];
break;
}
case 4: /*blue channel */
{
value[2]=value[2]*255; /* scale to 0-255 range */
ivalue=(int)value[2];
break;
}
case 5: /* luminence */
{
rgb_to_yuv(value[0], value[1], value[2], &value[0], &value[1], &value[2]);
value[0]=value[0]*255; /* scale to 0-255 range */
ivalue=(int)value[0];
break;
}
} /*end switch */
/*clip*/
if (ivalue<0) ivalue=0;
if (ivalue>255) ivalue=255;
/*put in the correct bin*/
bins[ivalue]+=1;
} /*end if alpha */
}
}
}
static float brightness_mean(bNode *node, CompBuf* in)
{
float sum=0.0;
int numPixels=0.0;
int x, y;
float value[4];
for (x=0; x< in->x; x++) {
for (y=0; y < in->y; y++) {
/* get the pixel */
qd_getPixel(in, x, y, value);
if (value[3] > 0.0f) { /* don't count transparent pixels */
numPixels++;
switch (node->custom1) {
case 1:
{
value[0] = rgb_to_bw(value);
sum+=value[0];
break;
}
case 2:
{
sum+=value[0];
break;
}
case 3:
{
sum+=value[1];
break;
}
case 4:
{
sum+=value[2];
break;
}
case 5:
{
rgb_to_yuv(value[0], value[1], value[2], &value[0], &value[1], &value[2]);
sum+=value[0];
break;
}
}
}
}
}
return sum/numPixels;
}
static float brightness_standard_deviation(bNode *node, CompBuf* in, float mean)
{
float sum=0.0;
int numPixels=0.0;
int x, y;
float value[4];
for (x=0; x< in->x; x++) {
for (y=0; y < in->y; y++) {
/* get the pixel */
qd_getPixel(in, x, y, value);
if (value[3] > 0.0f) { /* don't count transparent pixels */
numPixels++;
switch (node->custom1) {
case 1:
{
value[0] = rgb_to_bw(value);
sum+=(value[0]-mean)*(value[0]-mean);
break;
}
case 2:
{
sum+=value[0];
sum+=(value[0]-mean)*(value[0]-mean);
break;
}
case 3:
{
sum+=value[1];
sum+=(value[1]-mean)*(value[1]-mean);
break;
}
case 4:
{
sum+=value[2];
sum+=(value[2]-mean)*(value[2]-mean);
break;
}
case 5:
{
rgb_to_yuv(value[0], value[1], value[2], &value[0], &value[1], &value[2]);
sum+=(value[0]-mean)*(value[0]-mean);
break;
}
}
}
}
}
return sqrt(sum/(float)(numPixels-1));
}
static void draw_histogram(bNode *node, CompBuf *out, int* bins)
{
int x, y;
float color[4];
float value;
int max;
/* find max value */
max=0;
for (x=0; x<256; x++) {
if (bins[x]>max) max=bins[x];
}
/*draw histogram in buffer */
for (x=0; x<out->x; x++) {
for (y=0;y<out->y; y++) {
/* get normalized value (0..255) */
value=((float)bins[x]/(float)max)*255.0f;
if (y < (int)value) { /*if the y value is below the height of the bar for this line then draw with the color */
switch (node->custom1) {
case 1: { /* draw in black */
color[0]=0.0; color[1]=0.0; color[2]=0.0; color[3]=1.0;
break;
}
case 2: { /* draw in red */
color[0]=1.0; color[1]=0.0; color[2]=0.0; color[3]=1.0;
break;
}
case 3: { /* draw in green */
color[0]=0.0; color[1]=1.0; color[2]=0.0; color[3]=1.0;
break;
}
case 4: { /* draw in blue */
color[0]=0.0; color[1]=0.0; color[2]=1.0; color[3]=1.0;
break;
}
case 5: { /* draw in white */
color[0]=1.0; color[1]=1.0; color[2]=1.0; color[3]=1.0;
break;
}
}
}
else {
color[0]=0.8; color[1]=0.8; color[2]=0.8; color[3]=1.0;
}
/* set the color */
qd_setPixel(out, x, y, color);
}
}
}
static void node_composit_exec_view_levels(void *data, bNode *node, bNodeStack **in, bNodeStack **out)
{
CompBuf* cbuf;
CompBuf* histogram;
float mean, std_dev;
int bins[256];
int x;
if (in[0]->hasinput==0) return;
if (in[0]->data==NULL) return;
histogram=alloc_compbuf(256, 256, CB_RGBA, 1);
cbuf=typecheck_compbuf(in[0]->data, CB_RGBA);
/*initalize bins*/
for (x=0; x<256; x++) {
bins[x]=0;
}
/*fill bins */
fill_bins(node, in[0]->data, bins);
/* draw the histogram chart */
draw_histogram(node, histogram, bins);
/* calculate the average brightness and contrast */
mean=brightness_mean(node, in[0]->data);
std_dev=brightness_standard_deviation(node, in[0]->data, mean);
/* Printf debuging ;) */
#if 0
printf("Mean: %f\n", mean);
printf("Std Dev: %f\n", std_dev);
#endif
if (out[0]->hasoutput)
out[0]->vec[0] = mean;
if (out[1]->hasoutput)
out[1]->vec[0] = std_dev;
generate_preview(data, node, histogram);
if (cbuf!=in[0]->data)
free_compbuf(cbuf);
free_compbuf(histogram);
}
#endif /* WITH_COMPOSITOR_LEGACY */
static void node_composit_init_view_levels(bNodeTree *UNUSED(ntree), bNode *node, bNodeTemplate *UNUSED(ntemp))
{
node->custom1=1; /*All channels*/
@@ -327,9 +59,6 @@ void register_node_type_cmp_view_levels(bNodeTreeType *ttype)
node_type_size(&ntype, 140, 100, 320);
node_type_init(&ntype, node_composit_init_view_levels);
node_type_storage(&ntype, "ImageUser", NULL, NULL);
#ifdef WITH_COMPOSITOR_LEGACY
node_type_exec(&ntype, node_composit_exec_view_levels);
#endif
nodeRegisterType(ttype, &ntype);
}

View File

@@ -45,61 +45,6 @@ static bNodeSocketTemplate cmp_node_luma_matte_out[] = {
{-1, 0, ""}
};
#ifdef WITH_COMPOSITOR_LEGACY
static void do_luma_matte(bNode *node, float *out, float *in)
{
NodeChroma *c=(NodeChroma *)node->storage;
float alpha;
/* test range*/
if (in[0]>c->t1) {
alpha=1.0;
}
else if (in[0]<c->t2) {
alpha=0.0;
}
else {/*blend */
alpha=(in[0]-c->t2)/(c->t1-c->t2);
}
/* don't make something that was more transparent less transparent */
if (alpha<in[3]) {
out[3]=alpha;
}
else {
out[3]=in[3];
}
}
static void node_composit_exec_luma_matte(void *data, bNode *node, bNodeStack **in, bNodeStack **out)
{
CompBuf *cbuf;
CompBuf *outbuf;
if (in[0]->hasinput==0) return;
if (in[0]->data==NULL) return;
if (out[0]->hasoutput==0 && out[1]->hasoutput==0) return;
cbuf=typecheck_compbuf(in[0]->data, CB_RGBA);
outbuf=dupalloc_compbuf(cbuf);
composit1_pixel_processor(node, outbuf, cbuf, in[1]->vec, do_rgba_to_yuva, CB_RGBA);
composit1_pixel_processor(node, outbuf, outbuf, in[1]->vec, do_luma_matte, CB_RGBA);
composit1_pixel_processor(node, outbuf, outbuf, in[1]->vec, do_yuva_to_rgba, CB_RGBA);
generate_preview(data, node, outbuf);
out[0]->data=outbuf;
if (out[1]->hasoutput)
out[1]->data=valbuf_from_rgbabuf(outbuf, CHAN_A);
if (cbuf!=in[0]->data)
free_compbuf(cbuf);
}
#endif /* WITH_COMPOSITOR_LEGACY */
static void node_composit_init_luma_matte(bNodeTree *UNUSED(ntree), bNode *node, bNodeTemplate *UNUSED(ntemp))
{
NodeChroma *c= MEM_callocN(sizeof(NodeChroma), "node chroma");
@@ -117,9 +62,6 @@ void register_node_type_cmp_luma_matte(bNodeTreeType *ttype)
node_type_size(&ntype, 200, 80, 250);
node_type_init(&ntype, node_composit_init_luma_matte);
node_type_storage(&ntype, "NodeChroma", node_free_standard_storage, node_copy_standard_storage);
#ifdef WITH_COMPOSITOR_LEGACY
node_type_exec(&ntype, node_composit_exec_luma_matte);
#endif
nodeRegisterType(ttype, &ntype);
}

View File

@@ -44,128 +44,6 @@ static bNodeSocketTemplate cmp_node_mapuv_out[] = {
{ -1, 0, "" }
};
#ifdef WITH_COMPOSITOR_LEGACY
/* foreach UV, use these values to read in cbuf and write to stackbuf */
/* stackbuf should be zeroed */
static void do_mapuv(CompBuf *stackbuf, CompBuf *cbuf, CompBuf *uvbuf, float threshold)
{
ImBuf *ibuf;
float *out= stackbuf->rect, *uv, *uvnext, *uvprev;
float dx, dy, alpha;
int x, y, sx, sy, row= 3*stackbuf->x;
/* ibuf needed for sampling */
ibuf= IMB_allocImBuf(cbuf->x, cbuf->y, 32, 0);
ibuf->rect_float= cbuf->rect;
/* vars for efficient looping */
uv= uvbuf->rect;
uvnext= uv+row;
uvprev= uv-row;
sx= stackbuf->x;
sy= stackbuf->y;
for (y=0; y<sy; y++) {
for (x=0; x<sx; x++, out+=4, uv+=3, uvnext+=3, uvprev+=3) {
if (x>0 && x<sx-1 && y>0 && y<sy-1) {
if (uv[2]!=0.0f) {
float uv_l, uv_r;
/* adaptive sampling, red (U) channel */
/* prevent alpha zero UVs to be used */
uv_l= uv[-1]!=0.0f? fabsf(uv[0]-uv[-3]) : 0.0f;
uv_r= uv[ 5]!=0.0f? fabsf(uv[0]-uv[ 3]) : 0.0f;
//dx= 0.5f*(fabs(uv[0]-uv[-3]) + fabs(uv[0]-uv[3]));
dx= 0.5f*(uv_l + uv_r);
uv_l= uvprev[-1]!=0.0f? fabsf(uv[0]-uvprev[-3]) : 0.0f;
uv_r= uvnext[-1]!=0.0f? fabsf(uv[0]-uvnext[-3]) : 0.0f;
//dx+= 0.25f*(fabs(uv[0]-uvprev[-3]) + fabs(uv[0]-uvnext[-3]));
dx+= 0.25f*(uv_l + uv_r);
uv_l= uvprev[ 5]!=0.0f? fabsf(uv[0]-uvprev[+3]) : 0.0f;
uv_r= uvnext[ 5]!=0.0f? fabsf(uv[0]-uvnext[+3]) : 0.0f;
//dx+= 0.25f*(fabs(uv[0]-uvprev[+3]) + fabs(uv[0]-uvnext[+3]));
dx+= 0.25f*(uv_l + uv_r);
/* adaptive sampling, green (V) channel */
uv_l= uv[-row+2]!=0.0f? fabsf(uv[1]-uv[-row+1]) : 0.0f;
uv_r= uv[ row+2]!=0.0f? fabsf(uv[1]-uv[ row+1]) : 0.0f;
//dy= 0.5f*(fabs(uv[1]-uv[-row+1]) + fabs(uv[1]-uv[row+1]));
dy= 0.5f*(uv_l + uv_r);
uv_l= uvprev[-1]!=0.0f? fabsf(uv[1]-uvprev[+1-3]) : 0.0f;
uv_r= uvnext[-1]!=0.0f? fabsf(uv[1]-uvnext[+1-3]) : 0.0f;
//dy+= 0.25f*(fabs(uv[1]-uvprev[+1-3]) + fabs(uv[1]-uvnext[+1-3]));
dy+= 0.25f*(uv_l + uv_r);
uv_l= uvprev[ 5]!=0.0f? fabsf(uv[1]-uvprev[+1+3]) : 0.0f;
uv_r= uvnext[ 5]!=0.0f? fabsf(uv[1]-uvnext[+1+3]) : 0.0f;
//dy+= 0.25f*(fabs(uv[1]-uvprev[+1+3]) + fabs(uv[1]-uvnext[+1+3]));
dy+= 0.25f*(uv_l + uv_r);
/* UV to alpha threshold */
alpha= 1.0f - threshold*(dx+dy);
if (alpha<0.0f) alpha= 0.0f;
else alpha*= uv[2];
/* should use mipmap */
if (dx > 0.20f) dx= 0.20f;
if (dy > 0.20f) dy= 0.20f;
ibuf_sample(ibuf, uv[0], uv[1], dx, dy, out);
/* premul */
if (alpha<1.0f) {
out[0]*= alpha;
out[1]*= alpha;
out[2]*= alpha;
out[3]*= alpha;
}
}
}
}
}
IMB_freeImBuf(ibuf);
}
static void node_composit_exec_mapuv(void *UNUSED(data), bNode *node, bNodeStack **in, bNodeStack **out)
{
if (out[0]->hasoutput==0)
return;
if (in[0]->data && in[1]->data) {
CompBuf *cbuf= in[0]->data;
CompBuf *uvbuf= in[1]->data;
CompBuf *stackbuf;
cbuf= typecheck_compbuf(cbuf, CB_RGBA);
uvbuf= typecheck_compbuf(uvbuf, CB_VEC3);
stackbuf= alloc_compbuf(uvbuf->x, uvbuf->y, CB_RGBA, 1); /* allocs */;
do_mapuv(stackbuf, cbuf, uvbuf, 0.05f*(float)node->custom1);
out[0]->data= stackbuf;
if (cbuf!=in[0]->data)
free_compbuf(cbuf);
if (uvbuf!=in[1]->data)
free_compbuf(uvbuf);
}
}
#endif /* WITH_COMPOSITOR_LEGACY */
void register_node_type_cmp_mapuv(bNodeTreeType *ttype)
{
static bNodeType ntype;
@@ -173,9 +51,6 @@ void register_node_type_cmp_mapuv(bNodeTreeType *ttype)
node_type_base(ttype, &ntype, CMP_NODE_MAP_UV, "Map UV", NODE_CLASS_DISTORT, NODE_OPTIONS);
node_type_socket_templates(&ntype, cmp_node_mapuv_in, cmp_node_mapuv_out);
node_type_size(&ntype, 140, 100, 320);
#ifdef WITH_COMPOSITOR_LEGACY
node_type_exec(&ntype, node_composit_exec_mapuv);
#endif
nodeRegisterType(ttype, &ntype);
}

View File

@@ -42,44 +42,6 @@ static bNodeSocketTemplate cmp_node_map_value_out[] = {
{ -1, 0, "" }
};
#ifdef WITH_COMPOSITOR_LEGACY
static void do_map_value(bNode *node, float *out, float *src)
{
TexMapping *texmap= node->storage;
out[0] = (src[0] + texmap->loc[0])*texmap->size[0];
if (texmap->flag & TEXMAP_CLIP_MIN)
if (out[0]<texmap->min[0])
out[0] = texmap->min[0];
if (texmap->flag & TEXMAP_CLIP_MAX)
if (out[0]>texmap->max[0])
out[0] = texmap->max[0];
}
static void node_composit_exec_map_value(void *UNUSED(data), bNode *node, bNodeStack **in, bNodeStack **out)
{
/* stack order in: valbuf */
/* stack order out: valbuf */
if (out[0]->hasoutput==0) return;
/* input no image? then only value operation */
if (in[0]->data==NULL) {
do_map_value(node, out[0]->vec, in[0]->vec);
}
else {
/* make output size of input image */
CompBuf *cbuf= in[0]->data;
CompBuf *stackbuf= alloc_compbuf(cbuf->x, cbuf->y, CB_VAL, 1); /* allocs */
composit1_pixel_processor(node, stackbuf, in[0]->data, in[0]->vec, do_map_value, CB_VAL);
out[0]->data= stackbuf;
}
}
#endif /* WITH_COMPOSITOR_LEGACY */
static void node_composit_init_map_value(bNodeTree *UNUSED(ntree), bNode *node, bNodeTemplate *UNUSED(ntemp))
{
node->storage= add_tex_mapping();
@@ -94,9 +56,6 @@ void register_node_type_cmp_map_value(bNodeTreeType *ttype)
node_type_size(&ntype, 100, 60, 150);
node_type_init(&ntype, node_composit_init_map_value);
node_type_storage(&ntype, "TexMapping", node_free_standard_storage, node_copy_standard_storage);
#ifdef WITH_COMPOSITOR_LEGACY
node_type_exec(&ntype, node_composit_exec_map_value);
#endif
nodeRegisterType(ttype, &ntype);
}

View File

@@ -45,48 +45,6 @@ static bNodeSocketTemplate cmp_node_mask_out[] = {
{ -1, 0, "" }
};
#ifdef WITH_COMPOSITOR_LEGACY
static void node_composit_exec_mask(void *data, bNode *node, bNodeStack **UNUSED(in), bNodeStack **out)
{
if (node->id) {
Mask *mask = (Mask *)node->id;
MaskRasterHandle *mr_handle;
CompBuf *stackbuf;
RenderData *rd = data;
float *res;
int sx, sy;
if (!out[0]->hasoutput) {
/* the node's output socket is not connected to anything...
* do not execute any further, just exit the node immediately
*/
return;
}
sx = (rd->size * rd->xsch) / 100;
sy = (rd->size * rd->ysch) / 100;
/* allocate the output buffer */
stackbuf = alloc_compbuf(sx, sy, CB_VAL, TRUE);
res = stackbuf->rect;
/* mask raster begin */
mr_handle = BKE_maskrasterize_handle_new();
BKE_maskrasterize_handle_init(mr_handle, mask,
sx, sy,
TRUE,
(node->custom1 & CMP_NODEFLAG_MASK_AA) != 0,
(node->custom1 & CMP_NODEFLAG_MASK_NO_FEATHER) == 0);
BKE_maskrasterize_buffer(mr_handle, sx, sy, res);
BKE_maskrasterize_handle_free(mr_handle);
/* mask raster end */
/* pass on output and free */
out[0]->data = stackbuf;
}
}
#endif /* WITH_COMPOSITOR_LEGACY */
static void node_composit_init_mask(bNodeTree *UNUSED(ntree), bNode *node, bNodeTemplate *UNUSED(ntemp))
{
NodeMask *data = MEM_callocN(sizeof(NodeMask), STRINGIFY(NodeMask));
@@ -105,9 +63,6 @@ void register_node_type_cmp_mask(bNodeTreeType *ttype)
node_type_socket_templates(&ntype, NULL, cmp_node_mask_out);
node_type_size(&ntype, 140, 100, 320);
node_type_init(&ntype, node_composit_init_mask);
#ifdef WITH_COMPOSITOR_LEGACY
node_type_exec(&ntype, node_composit_exec_mask);
#endif
node_type_storage(&ntype, "NodeMask", node_free_standard_storage, node_copy_standard_storage);

View File

@@ -44,161 +44,6 @@ static bNodeSocketTemplate cmp_node_math_out[] = {
{ -1, 0, "" }
};
#ifdef WITH_COMPOSITOR_LEGACY
static void do_math(bNode *node, float *out, float *in, float *in2)
{
switch (node->custom1) {
case 0: /* Add */
out[0] = in[0] + in2[0];
break;
case 1: /* Subtract */
out[0] = in[0] - in2[0];
break;
case 2: /* Multiply */
out[0] = in[0] * in2[0];
break;
case 3: /* Divide */
{
if (in2[0]==0) /* We don't want to divide by zero. */
out[0] = 0.0;
else
out[0] = in[0] / in2[0];
}
break;
case 4: /* Sine */
out[0] = sin(in[0]);
break;
case 5: /* Cosine */
out[0] = cos(in[0]);
break;
case 6: /* Tangent */
out[0] = tan(in[0]);
break;
case 7: /* Arc-Sine */
{
/* Can't do the impossible... */
if (in[0] <= 1 && in[0] >= -1 )
out[0] = asin(in[0]);
else
out[0] = 0.0;
}
break;
case 8: /* Arc-Cosine */
{
/* Can't do the impossible... */
if ( in[0] <= 1 && in[0] >= -1 )
out[0] = acos(in[0]);
else
out[0] = 0.0;
}
break;
case 9: /* Arc-Tangent */
out[0] = atan(in[0]);
break;
case 10: /* Power */
{
/* Only raise negative numbers by full integers */
if ( in[0] >= 0 ) {
out[0] = pow(in[0], in2[0]);
}
else {
float y_mod_1 = fabsf(fmodf(in2[0], 1.0f));
/* if input value is not nearly an integer, fall back to zero, nicer than straight rounding */
if (y_mod_1 > 0.999f || y_mod_1 < 0.001f) {
out[0] = powf(in[0], floorf(in2[0] + 0.5f));
}
else {
out[0] = 0.0f;
}
}
}
break;
case 11: /* Logarithm */
{
/* Don't want any imaginary numbers... */
if ( in[0] > 0 && in2[0] > 0 )
out[0] = log(in[0]) / log(in2[0]);
else
out[0] = 0.0;
}
break;
case 12: /* Minimum */
{
if ( in[0] < in2[0] )
out[0] = in[0];
else
out[0] = in2[0];
}
break;
case 13: /* Maximum */
{
if ( in[0] > in2[0] )
out[0] = in[0];
else
out[0] = in2[0];
}
break;
case 14: /* Round */
{
/* round by the second value */
if ( in2[0] != 0.0f )
out[0] = floorf(in[0] / in2[0] + 0.5f) * in2[0];
else
out[0] = floorf(in[0] + 0.5f);
}
break;
case 15: /* Less Than */
{
if ( in[0] < in2[0] )
out[0] = 1.0f;
else
out[0] = 0.0f;
}
break;
case 16: /* Greater Than */
{
if ( in[0] > in2[0] )
out[0] = 1.0f;
else
out[0] = 0.0f;
}
break;
}
}
static void node_composit_exec_math(void *UNUSED(data), bNode *node, bNodeStack **in, bNodeStack **out)
{
CompBuf *cbuf=in[0]->data;
CompBuf *cbuf2=in[1]->data;
CompBuf *stackbuf;
/* check for inputs and outputs for early out*/
if (out[0]->hasoutput==0) return;
/* no image-color operation */
if (in[0]->data==NULL && in[1]->data==NULL) {
do_math(node, out[0]->vec, in[0]->vec, in[1]->vec);
return;
}
/* create output based on first input */
if (cbuf) {
stackbuf=alloc_compbuf(cbuf->x, cbuf->y, CB_VAL, 1);
}
/* and if it doesn't exist use the second input since we
* know that one of them must exist at this point*/
else {
stackbuf=alloc_compbuf(cbuf2->x, cbuf2->y, CB_VAL, 1);
}
/* operate in case there's valid size */
composit2_pixel_processor(node, stackbuf, in[0]->data, in[0]->vec, in[1]->data, in[1]->vec, do_math, CB_VAL, CB_VAL);
out[0]->data= stackbuf;
}
#endif /* WITH_COMPOSITOR_LEGACY */
void register_node_type_cmp_math(bNodeTreeType *ttype)
{
@@ -208,9 +53,6 @@ void register_node_type_cmp_math(bNodeTreeType *ttype)
node_type_socket_templates(&ntype, cmp_node_math_in, cmp_node_math_out);
node_type_size(&ntype, 120, 110, 160);
node_type_label(&ntype, node_math_label);
#ifdef WITH_COMPOSITOR_LEGACY
node_type_exec(&ntype, node_composit_exec_math);
#endif
nodeRegisterType(ttype, &ntype);
}

View File

@@ -43,48 +43,6 @@ static bNodeSocketTemplate cmp_node_mix_rgb_out[] = {
{ -1, 0, "" }
};
#ifdef WITH_COMPOSITOR_LEGACY
static void do_mix_rgb(bNode *node, float *out, float *in1, float *in2, float *fac)
{
float col[3];
copy_v3_v3(col, in1);
if (node->custom2)
ramp_blend(node->custom1, col, in2[3]*fac[0], in2);
else
ramp_blend(node->custom1, col, fac[0], in2);
copy_v3_v3(out, col);
out[3] = in1[3];
}
static void node_composit_exec_mix_rgb(void *data, bNode *node, bNodeStack **in, bNodeStack **out)
{
/* stack order in: fac, Image, Image */
/* stack order out: Image */
float *fac= in[0]->vec;
if (out[0]->hasoutput==0) return;
/* input no image? then only color operation */
if (in[1]->data==NULL && in[2]->data==NULL) {
do_mix_rgb(node, out[0]->vec, in[1]->vec, in[2]->vec, fac);
}
else {
/* make output size of first available input image */
CompBuf *cbuf= in[1]->data?in[1]->data:in[2]->data;
CompBuf *stackbuf= alloc_compbuf(cbuf->x, cbuf->y, CB_RGBA, 1); /* allocs */
composit3_pixel_processor(node, stackbuf, in[1]->data, in[1]->vec, in[2]->data, in[2]->vec, in[0]->data, fac, do_mix_rgb, CB_RGBA, CB_RGBA, CB_VAL);
out[0]->data= stackbuf;
generate_preview(data, node, out[0]->data);
}
}
#endif /* WITH_COMPOSITOR_LEGACY */
/* custom1 = mix type */
void register_node_type_cmp_mix_rgb(bNodeTreeType *ttype)
{
@@ -94,9 +52,6 @@ void register_node_type_cmp_mix_rgb(bNodeTreeType *ttype)
node_type_socket_templates(&ntype, cmp_node_mix_rgb_in, cmp_node_mix_rgb_out);
node_type_size(&ntype, 110, 60, 120);
node_type_label(&ntype, node_blend_label);
#ifdef WITH_COMPOSITOR_LEGACY
node_type_exec(&ntype, node_composit_exec_mix_rgb);
#endif
nodeRegisterType(ttype, &ntype);
}

View File

@@ -42,106 +42,6 @@ static bNodeSocketTemplate cmp_node_movieclip_out[] = {
{ -1, 0, "" }
};
#ifdef WITH_COMPOSITOR_LEGACY
static CompBuf *node_composit_get_movieclip(RenderData *rd, MovieClip *clip, MovieClipUser *user)
{
ImBuf *orig_ibuf, *ibuf;
CompBuf *stackbuf;
int type;
float *rect;
int alloc = FALSE;
orig_ibuf = BKE_movieclip_get_ibuf(clip, user);
if (orig_ibuf == NULL || (orig_ibuf->rect == NULL && orig_ibuf->rect_float == NULL)) {
IMB_freeImBuf(orig_ibuf);
return NULL;
}
ibuf = IMB_dupImBuf(orig_ibuf);
IMB_freeImBuf(orig_ibuf);
if (ibuf->rect_float == NULL || (ibuf->userflags & IB_RECT_INVALID)) {
IMB_float_from_rect(ibuf);
ibuf->userflags &= ~IB_RECT_INVALID;
}
/* now we need a float buffer from the image with matching color management */
if (ibuf->channels == 4) {
rect = node_composit_get_float_buffer(rd, ibuf, &alloc);
}
else {
/* non-rgba passes can't use color profiles */
rect = ibuf->rect_float;
}
/* done coercing into the correct color management */
if (!alloc) {
rect = MEM_dupallocN(rect);
alloc = TRUE;
}
type = ibuf->channels;
if (rd->scemode & R_COMP_CROP) {
stackbuf = get_cropped_compbuf(&rd->disprect, rect, ibuf->x, ibuf->y, type);
if (alloc)
MEM_freeN(rect);
}
else {
/* we put imbuf copy on stack, cbuf knows rect is from other ibuf when freed! */
stackbuf = alloc_compbuf(ibuf->x, ibuf->y, type, FALSE);
stackbuf->rect = rect;
stackbuf->malloc = alloc;
}
IMB_freeImBuf(ibuf);
return stackbuf;
}
static void node_composit_exec_movieclip(void *data, bNode *node, bNodeStack **UNUSED(in), bNodeStack **out)
{
if (node->id) {
RenderData *rd = data;
MovieClip *clip = (MovieClip *)node->id;
MovieClipUser *user = (MovieClipUser *)node->storage;
CompBuf *stackbuf = NULL;
BKE_movieclip_user_set_frame(user, rd->cfra);
stackbuf = node_composit_get_movieclip(rd, clip, user);
if (stackbuf) {
MovieTrackingStabilization *stab = &clip->tracking.stabilization;
/* put image on stack */
out[0]->data = stackbuf;
if (stab->flag & TRACKING_2D_STABILIZATION) {
float loc[2], scale, angle;
int clip_framenr = BKE_movieclip_remap_scene_to_clip_frame(clip, rd->cfra);
BKE_tracking_stabilization_data_get(&clip->tracking, clip_framenr, stackbuf->x, stackbuf->y,
loc, &scale, &angle);
out[1]->vec[0] = loc[0];
out[2]->vec[0] = loc[1];
out[3]->vec[0] = scale;
out[4]->vec[0] = angle;
}
/* generate preview */
generate_preview(data, node, stackbuf);
}
}
}
#endif /* WITH_COMPOSITOR_LEGACY */
static void init(bNodeTree *UNUSED(ntree), bNode *node, bNodeTemplate *UNUSED(ntemp))
{
MovieClipUser *user = MEM_callocN(sizeof(MovieClipUser), "node movie clip user");
@@ -159,9 +59,6 @@ void register_node_type_cmp_movieclip(bNodeTreeType *ttype)
node_type_size(&ntype, 120, 80, 300);
node_type_init(&ntype, init);
node_type_storage(&ntype, "MovieClipUser", node_free_standard_storage, node_copy_standard_storage);
#ifdef WITH_COMPOSITOR_LEGACY
node_type_exec(&ntype, node_composit_exec_movieclip);
#endif
nodeRegisterType(ttype, &ntype);
}

View File

@@ -30,9 +30,6 @@
* \ingroup cmpnodes
*/
#include "BLF_translation.h"
#include "node_composite_util.h"
/* **************** Translate ******************** */
@@ -47,66 +44,6 @@ static bNodeSocketTemplate cmp_node_moviedistortion_out[] = {
{ -1, 0, "" }
};
#ifdef WITH_COMPOSITOR_LEGACY
static void node_composit_exec_moviedistortion(void *data, bNode *node, bNodeStack **in, bNodeStack **out)
{
if (in[0]->data) {
if (node->id) {
MovieClip *clip = (MovieClip *)node->id;
CompBuf *cbuf = typecheck_compbuf(in[0]->data, CB_RGBA);
CompBuf *stackbuf = alloc_compbuf(cbuf->x, cbuf->y, CB_RGBA, 0);
ImBuf *ibuf;
ibuf = IMB_allocImBuf(cbuf->x, cbuf->y, 32, 0);
if (ibuf) {
RenderData *rd = data;
ImBuf *obuf;
MovieTracking *tracking = &clip->tracking;
int width, height;
float overscan = 0.0f;
MovieClipUser user = {0};
BKE_movieclip_user_set_frame(&user, rd->cfra);
ibuf->rect_float = cbuf->rect;
BKE_movieclip_get_size(clip, &user, &width, &height);
if (!node->storage)
node->storage = BKE_tracking_distortion_new();
if (node->custom1 == 0)
obuf = BKE_tracking_distortion_exec(node->storage, tracking, ibuf, width, height, overscan, 1);
else
obuf = BKE_tracking_distortion_exec(node->storage, tracking, ibuf, width, height, overscan, 0);
stackbuf->rect = obuf->rect_float;
stackbuf->malloc = TRUE;
obuf->mall &= ~IB_rectfloat;
obuf->rect_float = NULL;
IMB_freeImBuf(ibuf);
IMB_freeImBuf(obuf);
}
/* pass on output and free */
out[0]->data = stackbuf;
if (cbuf != in[0]->data)
free_compbuf(cbuf);
}
else {
CompBuf *cbuf = in[0]->data;
CompBuf *stackbuf = pass_on_compbuf(cbuf);
out[0]->data = stackbuf;
}
}
}
#endif /* WITH_COMPOSITOR_LEGACY */
static const char *label(bNode *node)
{
if (node->custom1 == 0)
@@ -137,9 +74,6 @@ void register_node_type_cmp_moviedistortion(bNodeTreeType *ttype)
node_type_socket_templates(&ntype, cmp_node_moviedistortion_in, cmp_node_moviedistortion_out);
node_type_size(&ntype, 140, 100, 320);
node_type_label(&ntype, label);
#ifdef WITH_COMPOSITOR_LEGACY
node_type_exec(&ntype, node_composit_exec_moviedistortion);
#endif
node_type_storage(&ntype, NULL, storage_free, storage_copy);

View File

@@ -45,44 +45,6 @@ static bNodeSocketTemplate cmp_node_normal_out[] = {
{ -1, 0, "" }
};
#ifdef WITH_COMPOSITOR_LEGACY
static void do_normal(bNode *node, float *out, float *in)
{
bNodeSocket *sock= node->outputs.first;
float *nor= ((bNodeSocketValueVector*)sock->default_value)->value;
/* render normals point inside... the widget points outside */
out[0] = -dot_v3v3(nor, in);
}
/* generates normal, does dot product */
static void node_composit_exec_normal(void *UNUSED(data), bNode *node, bNodeStack **in, bNodeStack **out)
{
bNodeSocket *sock= node->outputs.first;
float *nor= ((bNodeSocketValueVector*)sock->default_value)->value;
/* stack order input: normal */
/* stack order output: normal, value */
/* input no image? then only vector op */
if (in[0]->data==NULL) {
copy_v3_v3(out[0]->vec, nor);
/* render normals point inside... the widget points outside */
out[1]->vec[0] = -dot_v3v3(out[0]->vec, in[0]->vec);
}
else if (out[1]->hasoutput) {
/* make output size of input image */
CompBuf *cbuf= in[0]->data;
CompBuf *stackbuf= alloc_compbuf(cbuf->x, cbuf->y, CB_VAL, 1); /* allocs */
composit1_pixel_processor(node, stackbuf, in[0]->data, in[0]->vec, do_normal, CB_VEC3);
out[1]->data= stackbuf;
}
}
#endif /* WITH_COMPOSITOR_LEGACY */
static void init(bNodeTree *UNUSED(ntree), bNode *node, bNodeTemplate *UNUSED(ntemp))
{
bNodeSocket *sock= node->outputs.first;
@@ -101,9 +63,6 @@ void register_node_type_cmp_normal(bNodeTreeType *ttype)
node_type_socket_templates(&ntype, cmp_node_normal_in, cmp_node_normal_out);
node_type_init(&ntype, init);
node_type_size(&ntype, 100, 60, 200);
#ifdef WITH_COMPOSITOR_LEGACY
node_type_exec(&ntype, node_composit_exec_normal);
#endif
nodeRegisterType(ttype, &ntype);
}

View File

@@ -43,69 +43,6 @@ static bNodeSocketTemplate cmp_node_normalize_out[] = {
{ -1, 0, "" }
};
#ifdef WITH_COMPOSITOR_LEGACY
static void do_normalize(bNode *UNUSED(node), float *out, float *src, float *min, float *mult)
{
float res;
res = (src[0] - min[0]) * mult[0];
if (res > 1.0f) {
out[0] = 1.0f;
}
else if (res < 0.0f) {
out[0] = 0.0f;
}
else {
out[0] = res;
}
}
/* The code below assumes all data is inside range +- this, and that input buffer is single channel */
#define BLENDER_ZMAX 10000.0f
static void node_composit_exec_normalize(void *UNUSED(data), bNode *node, bNodeStack **in, bNodeStack **out)
{
/* stack order in: valbuf */
/* stack order out: valbuf */
if (out[0]->hasoutput==0) return;
/* Input has no image buffer? Then pass the value */
if (in[0]->data==NULL) {
copy_v4_v4(out[0]->vec, in[0]->vec);
}
else {
float min = 1.0f+BLENDER_ZMAX;
float max = -1.0f-BLENDER_ZMAX;
float mult = 1.0f;
float *val;
/* make output size of input image */
CompBuf *cbuf= in[0]->data;
int tot= cbuf->x*cbuf->y;
CompBuf *stackbuf= alloc_compbuf(cbuf->x, cbuf->y, CB_VAL, 1); /* allocs */
for (val = cbuf->rect; tot; tot--, val++) {
if ((*val > max) && (*val <= BLENDER_ZMAX)) {
max = *val;
}
if ((*val < min) && (*val >= -BLENDER_ZMAX)) {
min = *val;
}
}
/* In the rare case of flat buffer, which would cause a divide by 0, just pass the input to the output */
if ((max-min) != 0.0f) {
mult = 1.0f/(max-min);
composit3_pixel_processor(node, stackbuf, in[0]->data, in[0]->vec, NULL, &min, NULL, &mult, do_normalize, CB_VAL, CB_VAL, CB_VAL);
}
else {
memcpy(stackbuf->rect, cbuf->rect, sizeof(float) * cbuf->x * cbuf->y);
}
out[0]->data= stackbuf;
}
}
#endif /* WITH_COMPOSITOR_LEGACY */
void register_node_type_cmp_normalize(bNodeTreeType *ttype)
{
static bNodeType ntype;
@@ -113,9 +50,6 @@ void register_node_type_cmp_normalize(bNodeTreeType *ttype)
node_type_base(ttype, &ntype, CMP_NODE_NORMALIZE, "Normalize", NODE_CLASS_OP_VECTOR, NODE_OPTIONS);
node_type_socket_templates(&ntype, cmp_node_normalize_in, cmp_node_normalize_out);
node_type_size(&ntype, 100, 60, 150);
#ifdef WITH_COMPOSITOR_LEGACY
node_type_exec(&ntype, node_composit_exec_normalize);
#endif
nodeRegisterType(ttype, &ntype);
}

View File

@@ -225,183 +225,6 @@ static void update_output_file(bNodeTree *UNUSED(ntree), bNode *node)
}
}
#ifdef WITH_COMPOSITOR_LEGACY
/* write input data into individual files */
static void exec_output_file_singlelayer(RenderData *rd, bNode *node, bNodeStack **in)
{
Main *bmain= G.main; /* TODO, have this passed along */
NodeImageMultiFile *nimf= node->storage;
bNodeSocket *sock;
int i;
int has_preview = 0;
for (sock=node->inputs.first, i=0; sock; sock=sock->next, ++i) {
if (in[i]->data) {
NodeImageMultiFileSocket *sockdata = sock->storage;
ImageFormatData *format = (sockdata->use_node_format ? &nimf->format : &sockdata->format);
char path[FILE_MAX];
char filename[FILE_MAX];
CompBuf *cbuf = NULL;
ImBuf *ibuf;
switch (format->planes) {
case R_IMF_PLANES_BW:
cbuf = typecheck_compbuf(in[i]->data, CB_VAL);
break;
case R_IMF_PLANES_RGB:
cbuf = typecheck_compbuf(in[i]->data, CB_VEC3);
break;
case R_IMF_PLANES_RGBA:
cbuf = typecheck_compbuf(in[i]->data, CB_RGBA);
break;
}
ibuf = IMB_allocImBuf(cbuf->x, cbuf->y, format->planes, 0);
/* XXX have to set this explicitly it seems */
switch (format->planes) {
case R_IMF_PLANES_BW: ibuf->channels = 1; break;
case R_IMF_PLANES_RGB: ibuf->channels = 3; break;
case R_IMF_PLANES_RGBA: ibuf->channels = 4; break;
}
ibuf->rect_float = cbuf->rect;
ibuf->dither = rd->dither_intensity;
/* get full path */
BLI_join_dirfile(path, FILE_MAX, nimf->base_path, sockdata->path);
BKE_makepicstring(filename, path, bmain->name, rd->cfra, format, (rd->scemode & R_EXTENSION), TRUE);
if (0 == BKE_imbuf_write(ibuf, filename, format))
printf("Cannot save Node File Output to %s\n", filename);
else
printf("Saved: %s\n", filename);
IMB_freeImBuf(ibuf);
/* simply pick the first valid input for preview */
if (!has_preview) {
generate_preview(rd, node, cbuf);
has_preview = 1;
}
if (in[i]->data != cbuf)
free_compbuf(cbuf);
}
}
}
/* write input data into layers */
static void exec_output_file_multilayer(RenderData *rd, bNode *node, bNodeStack **in)
{
Main *bmain= G.main; /* TODO, have this passed along */
NodeImageMultiFile *nimf= node->storage;
void *exrhandle= IMB_exr_get_handle();
char filename[FILE_MAX];
bNodeSocket *sock;
int i;
/* Must have consistent pixel size for exr file, simply take the first valid input size. */
int rectx = -1;
int recty = -1;
int has_preview = 0;
BKE_makepicstring_from_type(filename, nimf->base_path, bmain->name, rd->cfra, R_IMF_IMTYPE_MULTILAYER, (rd->scemode & R_EXTENSION), TRUE);
BLI_make_existing_file(filename);
for (sock=node->inputs.first, i=0; sock; sock=sock->next, ++i) {
if (in[i]->data) {
NodeImageMultiFileSocket *sockdata = sock->storage;
CompBuf *cbuf = in[i]->data;
char channelname[EXR_TOT_MAXNAME]; /* '.' and single character channel name is appended */
char *channelname_ext;
if (cbuf->rect_procedural) {
printf("Error writing multilayer EXR: Procedural buffer not supported\n");
continue;
}
if (rectx < 0) {
rectx = cbuf->x;
recty = cbuf->y;
}
else if (cbuf->x != rectx || cbuf->y != recty) {
printf("Error: Multilayer EXR output node %s expects same resolution for all input buffers. Layer %s skipped.\n", node->name, sock->name);
continue;
}
BLI_strncpy(channelname, sockdata->layer, sizeof(channelname)-2);
channelname_ext = channelname + strlen(channelname);
/* create channels */
switch (cbuf->type) {
case CB_VAL:
strcpy(channelname_ext, ".V");
IMB_exr_add_channel(exrhandle, NULL, channelname, 1, rectx, cbuf->rect);
break;
case CB_VEC2:
strcpy(channelname_ext, ".X");
IMB_exr_add_channel(exrhandle, NULL, channelname, 2, 2*rectx, cbuf->rect);
strcpy(channelname_ext, ".Y");
IMB_exr_add_channel(exrhandle, NULL, channelname, 2, 2*rectx, cbuf->rect+1);
break;
case CB_VEC3:
strcpy(channelname_ext, ".X");
IMB_exr_add_channel(exrhandle, NULL, channelname, 3, 3*rectx, cbuf->rect);
strcpy(channelname_ext, ".Y");
IMB_exr_add_channel(exrhandle, NULL, channelname, 3, 3*rectx, cbuf->rect+1);
strcpy(channelname_ext, ".Z");
IMB_exr_add_channel(exrhandle, NULL, channelname, 3, 3*rectx, cbuf->rect+2);
break;
case CB_RGBA:
strcpy(channelname_ext, ".R");
IMB_exr_add_channel(exrhandle, NULL, channelname, 4, 4*rectx, cbuf->rect);
strcpy(channelname_ext, ".G");
IMB_exr_add_channel(exrhandle, NULL, channelname, 4, 4*rectx, cbuf->rect+1);
strcpy(channelname_ext, ".B");
IMB_exr_add_channel(exrhandle, NULL, channelname, 4, 4*rectx, cbuf->rect+2);
strcpy(channelname_ext, ".A");
IMB_exr_add_channel(exrhandle, NULL, channelname, 4, 4*rectx, cbuf->rect+3);
break;
}
/* simply pick the first valid input for preview */
if (!has_preview) {
generate_preview(rd, node, cbuf);
has_preview = 1;
}
}
}
/* when the filename has no permissions, this can fail */
if (IMB_exr_begin_write(exrhandle, filename, rectx, recty, nimf->format.exr_codec)) {
IMB_exr_write_channels(exrhandle);
}
else {
/* TODO, get the error from openexr's exception */
/* XXX nice way to do report? */
printf("Error Writing Render Result, see console\n");
}
IMB_exr_close(exrhandle);
}
static void node_composit_exec_outputfile(void *data, bNode *node, bNodeStack **in, bNodeStack **UNUSED(out))
{
RenderData *rd= data;
NodeImageMultiFile *nimf= node->storage;
if (G.is_rendering == FALSE) {
/* only output files when rendering a sequence -
* otherwise, it overwrites the output files just
* scrubbing through the timeline when the compositor updates */
return;
}
if (nimf->format.imtype==R_IMF_IMTYPE_MULTILAYER)
exec_output_file_multilayer(rd, node, in);
else
exec_output_file_singlelayer(rd, node, in);
}
#endif /* WITH_COMPOSITOR_LEGACY */
void register_node_type_cmp_output_file(bNodeTreeType *ttype)
{
static bNodeType ntype;
@@ -412,9 +235,6 @@ void register_node_type_cmp_output_file(bNodeTreeType *ttype)
node_type_init(&ntype, init_output_file);
node_type_storage(&ntype, "NodeImageMultiFile", free_output_file, copy_output_file);
node_type_update(&ntype, update_output_file, NULL);
#ifdef WITH_COMPOSITOR_LEGACY
node_type_exec(&ntype, node_composit_exec_outputfile);
#endif
nodeRegisterType(ttype, &ntype);
}

View File

@@ -44,27 +44,6 @@ static bNodeSocketTemplate cmp_node_premulkey_out[] = {
{ -1, 0, "" }
};
#ifdef WITH_COMPOSITOR_LEGACY
static void node_composit_exec_premulkey(void *UNUSED(data), bNode *node, bNodeStack **in, bNodeStack **out)
{
if (out[0]->hasoutput==0)
return;
if (in[0]->data) {
CompBuf *stackbuf, *cbuf= typecheck_compbuf(in[0]->data, CB_RGBA);
stackbuf= dupalloc_compbuf(cbuf);
premul_compbuf(stackbuf, node->custom1 == 1);
out[0]->data = stackbuf;
if (cbuf != in[0]->data)
free_compbuf(cbuf);
}
}
#endif /* WITH_COMPOSITOR_LEGACY */
void register_node_type_cmp_premulkey(bNodeTreeType *ttype)
{
static bNodeType ntype;
@@ -72,9 +51,6 @@ void register_node_type_cmp_premulkey(bNodeTreeType *ttype)
node_type_base(ttype, &ntype, CMP_NODE_PREMULKEY, "Alpha Convert", NODE_CLASS_CONVERTOR, NODE_OPTIONS);
node_type_socket_templates(&ntype, cmp_node_premulkey_in, cmp_node_premulkey_out);
node_type_size(&ntype, 140, 100, 320);
#ifdef WITH_COMPOSITOR_LEGACY
node_type_exec(&ntype, node_composit_exec_premulkey);
#endif
nodeRegisterType(ttype, &ntype);
}

View File

@@ -39,18 +39,6 @@ static bNodeSocketTemplate cmp_node_rgb_out[] = {
{ -1, 0, "" }
};
#ifdef WITH_COMPOSITOR_LEGACY
static void node_composit_exec_rgb(void *UNUSED(data), bNode *node, bNodeStack **UNUSED(in), bNodeStack **out)
{
bNodeSocket *sock= node->outputs.first;
float *col= ((bNodeSocketValueRGBA*)sock->default_value)->value;
copy_v4_v4(out[0]->vec, col);
}
#endif /* WITH_COMPOSITOR_LEGACY */
static void node_composit_init_rgb(bNodeTree *UNUSED(ntree), bNode *node, bNodeTemplate *UNUSED(ntemp))
{
bNodeSocket *sock= node->outputs.first;
@@ -70,9 +58,6 @@ void register_node_type_cmp_rgb(bNodeTreeType *ttype)
node_type_socket_templates(&ntype, NULL, cmp_node_rgb_out);
node_type_init(&ntype, node_composit_init_rgb);
node_type_size(&ntype, 140, 80, 140);
#ifdef WITH_COMPOSITOR_LEGACY
node_type_exec(&ntype, node_composit_exec_rgb);
#endif
nodeRegisterType(ttype, &ntype);
}

View File

@@ -44,87 +44,6 @@ static bNodeSocketTemplate cmp_node_rotate_out[] = {
{ -1, 0, "" }
};
#ifdef WITH_COMPOSITOR_LEGACY
/* only supports RGBA nodes now */
static void node_composit_exec_rotate(void *UNUSED(data), bNode *node, bNodeStack **in, bNodeStack **out)
{
if (out[0]->hasoutput==0)
return;
if (in[0]->data) {
CompBuf *cbuf= typecheck_compbuf(in[0]->data, CB_RGBA);
CompBuf *stackbuf= alloc_compbuf(cbuf->x, cbuf->y, CB_RGBA, 1); /* note, this returns zero'd image */
float rad, u, v, s, c, centx, centy, miny, maxy, minx, maxx;
int x, y, yo, xo;
ImBuf *ibuf, *obuf;
rad= in[1]->vec[0];
s= sin(rad);
c= cos(rad);
centx= cbuf->x/2;
centy= cbuf->y/2;
minx= -centx;
maxx= -centx + (float)cbuf->x;
miny= -centy;
maxy= -centy + (float)cbuf->y;
ibuf=IMB_allocImBuf(cbuf->x, cbuf->y, 32, 0);
obuf=IMB_allocImBuf(stackbuf->x, stackbuf->y, 32, 0);
if (ibuf && obuf) {
ibuf->rect_float=cbuf->rect;
obuf->rect_float=stackbuf->rect;
for (y=miny; y<maxy; y++) {
yo= y+(int)centy;
for (x=minx; x<maxx;x++) {
u=c*x + y*s + centx;
v=-s*x + c*y + centy;
xo= x+(int)centx;
switch (node->custom1) {
case 0:
nearest_interpolation(ibuf, obuf, u, v, xo, yo);
break;
case 1:
bilinear_interpolation(ibuf, obuf, u, v, xo, yo);
break;
case 2:
bicubic_interpolation(ibuf, obuf, u, v, xo, yo);
break;
}
}
}
/* rotate offset vector too, but why negative rad, ehh?? Has to be replaced with [3][3] matrix once (ton) */
s= sin(-rad);
c= cos(-rad);
centx= (float)cbuf->xof; centy= (float)cbuf->yof;
stackbuf->xof= (int)( c*centx + s*centy);
stackbuf->yof= (int)(-s*centx + c*centy);
IMB_freeImBuf(ibuf);
IMB_freeImBuf(obuf);
}
/* pass on output and free */
out[0]->data= stackbuf;
if (cbuf!=in[0]->data) {
free_compbuf(cbuf);
}
}
}
#endif /* WITH_COMPOSITOR_LEGACY */
static void node_composit_init_rotate(bNodeTree *UNUSED(ntree), bNode *node, bNodeTemplate *UNUSED(ntemp))
{
node->custom1= 1; /* Bilinear Filter*/
@@ -138,9 +57,6 @@ void register_node_type_cmp_rotate(bNodeTreeType *ttype)
node_type_socket_templates(&ntype, cmp_node_rotate_in, cmp_node_rotate_out);
node_type_size(&ntype, 140, 100, 320);
node_type_init(&ntype, node_composit_init_rotate);
#ifdef WITH_COMPOSITOR_LEGACY
node_type_exec(&ntype, node_composit_exec_rotate);
#endif
nodeRegisterType(ttype, &ntype);
}

View File

@@ -45,147 +45,6 @@ static bNodeSocketTemplate cmp_node_scale_out[] = {
{ -1, 0, "" }
};
#ifdef WITH_COMPOSITOR_LEGACY
/* only supports RGBA nodes now */
/* node->custom1 stores if input values are absolute or relative scale */
static void node_composit_exec_scale(void *data, bNode *node, bNodeStack **in, bNodeStack **out)
{
if (out[0]->hasoutput == 0)
return;
if (in[0]->data) {
RenderData *rd = data;
CompBuf *stackbuf, *cbuf = typecheck_compbuf(in[0]->data, CB_RGBA);
ImBuf *ibuf;
int newx, newy;
float ofsx = 0.0f, ofsy = 0.0f;
if (node->custom1 == CMP_SCALE_RELATIVE) {
newx = MAX2((int)(in[1]->vec[0] * cbuf->x), 1);
newy = MAX2((int)(in[2]->vec[0] * cbuf->y), 1);
}
else if (node->custom1 == CMP_SCALE_SCENEPERCENT) {
newx = cbuf->x * (rd->size / 100.0f);
newy = cbuf->y * (rd->size / 100.0f);
}
else if (node->custom1 == CMP_SCALE_RENDERPERCENT) {
if (node->custom3 != 0.0f || node->custom4 != 0.0f) {
const float w_dst = (rd->xsch * rd->size) / 100;
const float h_dst = (rd->ysch * rd->size) / 100;
if (w_dst > h_dst) {
ofsx = node->custom3 * w_dst;
ofsy = node->custom4 * w_dst;
}
else {
ofsx = node->custom3 * h_dst;
ofsy = node->custom4 * h_dst;
}
}
/* supports framing options */
if (node->custom2 & CMP_SCALE_RENDERSIZE_FRAME_ASPECT) {
/* apply aspect from clip */
const float w_src = cbuf->x;
const float h_src = cbuf->y;
/* destination aspect is already applied from the camera frame */
const float w_dst = (rd->xsch * rd->size) / 100;
const float h_dst = (rd->ysch * rd->size) / 100;
const float asp_src = w_src / h_src;
const float asp_dst = w_dst / h_dst;
if (fabsf(asp_src - asp_dst) >= FLT_EPSILON) {
if ((asp_src > asp_dst) == ((node->custom2 & CMP_SCALE_RENDERSIZE_FRAME_CROP) != 0)) {
/* fit X */
const float div = asp_src / asp_dst;
newx = w_dst * div;
newy = h_dst;
}
else {
/* fit Y */
const float div = asp_dst / asp_src;
newx = w_dst;
newy = h_dst * div;
}
}
else {
/* same as below - no aspect correction needed */
newx = w_dst;
newy = h_dst;
}
}
else {
/* stretch */
newx = (rd->xsch * rd->size) / 100;
newy = (rd->ysch * rd->size) / 100;
}
}
else { /* CMP_SCALE_ABSOLUTE */
newx = MAX2((int)in[1]->vec[0], 1);
newy = MAX2((int)in[2]->vec[0], 1);
}
newx = MIN2(newx, CMP_SCALE_MAX);
newy = MIN2(newy, CMP_SCALE_MAX);
ibuf = IMB_allocImBuf(cbuf->x, cbuf->y, 32, 0);
if (ibuf) {
ibuf->rect_float = cbuf->rect;
IMB_scaleImBuf(ibuf, newx, newy);
if (ibuf->rect_float == cbuf->rect) {
/* no scaling happened. */
stackbuf = pass_on_compbuf(in[0]->data);
}
else {
stackbuf = alloc_compbuf(newx, newy, CB_RGBA, 0);
stackbuf->rect = ibuf->rect_float;
stackbuf->malloc = 1;
}
ibuf->rect_float = NULL;
ibuf->mall &= ~IB_rectfloat;
IMB_freeImBuf(ibuf);
/* also do the translation vector */
stackbuf->xof = (int)(ofsx + (((float)newx / (float)cbuf->x) * (float)cbuf->xof));
stackbuf->yof = (int)(ofsy + (((float)newy / (float)cbuf->y) * (float)cbuf->yof));
}
else {
stackbuf = dupalloc_compbuf(cbuf);
printf("Scaling to %dx%d failed\n", newx, newy);
}
out[0]->data = stackbuf;
if (cbuf != in[0]->data)
free_compbuf(cbuf);
}
else if (node->custom1 == CMP_SCALE_ABSOLUTE) {
CompBuf *stackbuf;
int a, x, y;
float *fp;
x = MAX2((int)in[1]->vec[0], 1);
y = MAX2((int)in[2]->vec[0], 1);
stackbuf = alloc_compbuf(x, y, CB_RGBA, 1);
fp = stackbuf->rect;
a = stackbuf->x * stackbuf->y;
while (a--) {
copy_v4_v4(fp, in[0]->vec);
fp += 4;
}
out[0]->data = stackbuf;
}
}
#endif /* WITH_COMPOSITOR_LEGACY */
void register_node_type_cmp_scale(bNodeTreeType *ttype)
{
static bNodeType ntype;
@@ -193,9 +52,6 @@ void register_node_type_cmp_scale(bNodeTreeType *ttype)
node_type_base(ttype, &ntype, CMP_NODE_SCALE, "Scale", NODE_CLASS_DISTORT, NODE_OPTIONS);
node_type_socket_templates(&ntype, cmp_node_scale_in, cmp_node_scale_out);
node_type_size(&ntype, 140, 100, 320);
#ifdef WITH_COMPOSITOR_LEGACY
node_type_exec(&ntype, node_composit_exec_scale);
#endif
nodeRegisterType(ttype, &ntype);
}

View File

@@ -46,63 +46,6 @@ static bNodeSocketTemplate cmp_node_sephsva_out[] = {
{ -1, 0, "" }
};
#ifdef WITH_COMPOSITOR_LEGACY
static void do_sephsva(bNode *UNUSED(node), float *out, float *in)
{
float h, s, v;
rgb_to_hsv(in[0], in[1], in[2], &h, &s, &v);
out[0] = h;
out[1] = s;
out[2] = v;
out[3] = in[3];
}
static void node_composit_exec_sephsva(void *UNUSED(data), bNode *node, bNodeStack **in, bNodeStack **out)
{
/* stack order out: bw channels */
/* stack order in: col */
/* input no image? then only color operation */
if (in[0]->data==NULL) {
float h, s, v;
rgb_to_hsv(in[0]->vec[0], in[0]->vec[1], in[0]->vec[2], &h, &s, &v);
out[0]->vec[0] = h;
out[1]->vec[0] = s;
out[2]->vec[0] = v;
out[3]->vec[0] = in[0]->vec[3];
}
else if ((out[0]->hasoutput) || (out[1]->hasoutput) || (out[2]->hasoutput) || (out[3]->hasoutput)) {
/* create new buffer so input buffer doesn't get corrupted */
CompBuf *cbuf= dupalloc_compbuf(in[0]->data);
CompBuf *cbuf2= typecheck_compbuf(cbuf, CB_RGBA);
/* convert the RGB stackbuf to an HSV representation */
composit1_pixel_processor(node, cbuf2, cbuf2, in[0]->vec, do_sephsva, CB_RGBA);
/* separate each of those channels */
if (out[0]->hasoutput)
out[0]->data= valbuf_from_rgbabuf(cbuf2, CHAN_R);
if (out[1]->hasoutput)
out[1]->data= valbuf_from_rgbabuf(cbuf2, CHAN_G);
if (out[2]->hasoutput)
out[2]->data= valbuf_from_rgbabuf(cbuf2, CHAN_B);
if (out[3]->hasoutput)
out[3]->data= valbuf_from_rgbabuf(cbuf2, CHAN_A);
/*not used anymore */
if (cbuf2!=cbuf)
free_compbuf(cbuf2);
free_compbuf(cbuf);
}
}
#endif /* WITH_COMPOSITOR_LEGACY */
void register_node_type_cmp_sephsva(bNodeTreeType *ttype)
{
static bNodeType ntype;
@@ -110,9 +53,6 @@ void register_node_type_cmp_sephsva(bNodeTreeType *ttype)
node_type_base(ttype, &ntype, CMP_NODE_SEPHSVA, "Separate HSVA", NODE_CLASS_CONVERTOR, 0);
node_type_socket_templates(&ntype, cmp_node_sephsva_in, cmp_node_sephsva_out);
node_type_size(&ntype, 80, 40, 140);
#ifdef WITH_COMPOSITOR_LEGACY
node_type_exec(&ntype, node_composit_exec_sephsva);
#endif
nodeRegisterType(ttype, &ntype);
}
@@ -131,53 +71,6 @@ static bNodeSocketTemplate cmp_node_combhsva_out[] = {
{ -1, 0, "" }
};
#ifdef WITH_COMPOSITOR_LEGACY
static void do_comb_hsva(bNode *UNUSED(node), float *out, float *in1, float *in2, float *in3, float *in4)
{
float r, g, b;
hsv_to_rgb(in1[0], in2[0], in3[0], &r, &g, &b);
out[0] = r;
out[1] = g;
out[2] = b;
out[3] = in4[0];
}
static void node_composit_exec_combhsva(void *UNUSED(data), bNode *node, bNodeStack **in, bNodeStack **out)
{
/* stack order out: 1 rgba channels */
/* stack order in: 4 value channels */
/* input no image? then only color operation in HSV */
if ((in[0]->data==NULL) && (in[1]->data==NULL) && (in[2]->data==NULL) && (in[3]->data==NULL)) {
hsv_to_rgb(in[0]->vec[0], in[1]->vec[0], in[2]->vec[0],
&out[0]->vec[0], &out[0]->vec[1], &out[0]->vec[2]);
out[0]->vec[3] = in[3]->vec[0];
}
else {
/* make output size of first available input image */
CompBuf *cbuf;
CompBuf *stackbuf;
/* allocate a CompBuf the size of the first available input */
if (in[0]->data) cbuf = in[0]->data;
else if (in[1]->data) cbuf = in[1]->data;
else if (in[2]->data) cbuf = in[2]->data;
else cbuf = in[3]->data;
stackbuf = alloc_compbuf(cbuf->x, cbuf->y, CB_RGBA, 1); /* allocs */
composit4_pixel_processor(node, stackbuf, in[0]->data, in[0]->vec, in[1]->data, in[1]->vec,
in[2]->data, in[2]->vec, in[3]->data, in[3]->vec,
do_comb_hsva, CB_VAL, CB_VAL, CB_VAL, CB_VAL);
out[0]->data= stackbuf;
}
}
#endif /* WITH_COMPOSITOR_LEGACY */
void register_node_type_cmp_combhsva(bNodeTreeType *ttype)
{
static bNodeType ntype;
@@ -185,9 +78,6 @@ void register_node_type_cmp_combhsva(bNodeTreeType *ttype)
node_type_base(ttype, &ntype, CMP_NODE_COMBHSVA, "Combine HSVA", NODE_CLASS_CONVERTOR, NODE_OPTIONS);
node_type_socket_templates(&ntype, cmp_node_combhsva_in, cmp_node_combhsva_out);
node_type_size(&ntype, 80, 40, 140);
#ifdef WITH_COMPOSITOR_LEGACY
node_type_exec(&ntype, node_composit_exec_combhsva);
#endif
nodeRegisterType(ttype, &ntype);
}

View File

@@ -45,42 +45,6 @@ static bNodeSocketTemplate cmp_node_seprgba_out[] = {
{ -1, 0, "" }
};
#ifdef WITH_COMPOSITOR_LEGACY
static void node_composit_exec_seprgba(void *UNUSED(data), bNode *UNUSED(node), bNodeStack **in, bNodeStack **out)
{
/* stack order out: bw channels */
/* stack order in: col */
/* input no image? then only color operation */
if (in[0]->data==NULL) {
out[0]->vec[0] = in[0]->vec[0];
out[1]->vec[0] = in[0]->vec[1];
out[2]->vec[0] = in[0]->vec[2];
out[3]->vec[0] = in[0]->vec[3];
}
else {
/* make sure we get right rgba buffer */
CompBuf *cbuf= typecheck_compbuf(in[0]->data, CB_RGBA);
/* don't do any pixel processing, just copy the stack directly (faster, I presume) */
if (out[0]->hasoutput)
out[0]->data= valbuf_from_rgbabuf(cbuf, CHAN_R);
if (out[1]->hasoutput)
out[1]->data= valbuf_from_rgbabuf(cbuf, CHAN_G);
if (out[2]->hasoutput)
out[2]->data= valbuf_from_rgbabuf(cbuf, CHAN_B);
if (out[3]->hasoutput)
out[3]->data= valbuf_from_rgbabuf(cbuf, CHAN_A);
if (cbuf!=in[0]->data)
free_compbuf(cbuf);
}
}
#endif /* WITH_COMPOSITOR_LEGACY */
void register_node_type_cmp_seprgba(bNodeTreeType *ttype)
{
static bNodeType ntype;
@@ -88,9 +52,6 @@ void register_node_type_cmp_seprgba(bNodeTreeType *ttype)
node_type_base(ttype, &ntype, CMP_NODE_SEPRGBA, "Separate RGBA", NODE_CLASS_CONVERTOR, 0);
node_type_socket_templates(&ntype, cmp_node_seprgba_in, cmp_node_seprgba_out);
node_type_size(&ntype, 80, 40, 140);
#ifdef WITH_COMPOSITOR_LEGACY
node_type_exec(&ntype, node_composit_exec_seprgba);
#endif
nodeRegisterType(ttype, &ntype);
}
@@ -110,51 +71,6 @@ static bNodeSocketTemplate cmp_node_combrgba_out[] = {
{ -1, 0, "" }
};
#ifdef WITH_COMPOSITOR_LEGACY
static void do_combrgba(bNode *UNUSED(node), float *out, float *in1, float *in2, float *in3, float *in4)
{
out[0] = in1[0];
out[1] = in2[0];
out[2] = in3[0];
out[3] = in4[0];
}
static void node_composit_exec_combrgba(void *UNUSED(data), bNode *node, bNodeStack **in, bNodeStack **out)
{
/* stack order out: 1 rgba channels */
/* stack order in: 4 value channels */
/* input no image? then only color operation */
if ((in[0]->data==NULL) && (in[1]->data==NULL) && (in[2]->data==NULL) && (in[3]->data==NULL)) {
out[0]->vec[0] = in[0]->vec[0];
out[0]->vec[1] = in[1]->vec[0];
out[0]->vec[2] = in[2]->vec[0];
out[0]->vec[3] = in[3]->vec[0];
}
else {
/* make output size of first available input image */
CompBuf *cbuf;
CompBuf *stackbuf;
/* allocate a CompBuf the size of the first available input */
if (in[0]->data) cbuf = in[0]->data;
else if (in[1]->data) cbuf = in[1]->data;
else if (in[2]->data) cbuf = in[2]->data;
else cbuf = in[3]->data;
stackbuf = alloc_compbuf(cbuf->x, cbuf->y, CB_RGBA, 1); /* allocs */
composit4_pixel_processor(node, stackbuf, in[0]->data, in[0]->vec, in[1]->data, in[1]->vec,
in[2]->data, in[2]->vec, in[3]->data, in[3]->vec,
do_combrgba, CB_VAL, CB_VAL, CB_VAL, CB_VAL);
out[0]->data= stackbuf;
}
}
#endif /* WITH_COMPOSITOR_LEGACY */
void register_node_type_cmp_combrgba(bNodeTreeType *ttype)
{
static bNodeType ntype;
@@ -162,9 +78,6 @@ void register_node_type_cmp_combrgba(bNodeTreeType *ttype)
node_type_base(ttype, &ntype, CMP_NODE_COMBRGBA, "Combine RGBA", NODE_CLASS_CONVERTOR, NODE_OPTIONS);
node_type_socket_templates(&ntype, cmp_node_combrgba_in, cmp_node_combrgba_out);
node_type_size(&ntype, 80, 40, 140);
#ifdef WITH_COMPOSITOR_LEGACY
node_type_exec(&ntype, node_composit_exec_combrgba);
#endif
nodeRegisterType(ttype, &ntype);
}

View File

@@ -46,109 +46,6 @@ static bNodeSocketTemplate cmp_node_sepycca_out[] = {
{ -1, 0, "" }
};
#ifdef WITH_COMPOSITOR_LEGACY
static void do_sepycca_601(bNode *UNUSED(node), float *out, float *in)
{
float y, cb, cr;
rgb_to_ycc(in[0], in[1], in[2], &y, &cb, &cr, BLI_YCC_ITU_BT601);
/*divided by 255 to normalize for viewing in */
out[0] = y/255.0f;
out[1] = cb/255.0f;
out[2] = cr/255.0f;
out[3] = in[3];
}
static void do_sepycca_709(bNode *UNUSED(node), float *out, float *in)
{
float y, cb, cr;
rgb_to_ycc(in[0], in[1], in[2], &y, &cb, &cr, BLI_YCC_ITU_BT709);
/*divided by 255 to normalize for viewing in */
out[0] = y/255.0f;
out[1] = cb/255.0f;
out[2] = cr/255.0f;
out[3] = in[3];
}
static void do_sepycca_jfif(bNode *UNUSED(node), float *out, float *in)
{
float y, cb, cr;
rgb_to_ycc(in[0], in[1], in[2], &y, &cb, &cr, BLI_YCC_JFIF_0_255);
/*divided by 255 to normalize for viewing in */
out[0] = y/255.0f;
out[1] = cb/255.0f;
out[2] = cr/255.0f;
out[3] = in[3];
}
static void node_composit_exec_sepycca(void *UNUSED(data), bNode *node, bNodeStack **in, bNodeStack **out)
{
/* input no image? then only color operation */
if (in[0]->data==NULL) {
float y, cb, cr;
switch (node->custom1) {
case 1:
rgb_to_ycc(in[0]->vec[0], in[0]->vec[1], in[0]->vec[2], &y, &cb, &cr, BLI_YCC_ITU_BT709);
break;
case 2:
rgb_to_ycc(in[0]->vec[0], in[0]->vec[1], in[0]->vec[2], &y, &cb, &cr, BLI_YCC_JFIF_0_255);
break;
case 0:
default:
rgb_to_ycc(in[0]->vec[0], in[0]->vec[1], in[0]->vec[2], &y, &cb, &cr, BLI_YCC_ITU_BT601);
break;
}
/*divided by 255 to normalize for viewing in */
out[0]->vec[0] = y/255.0f;
out[1]->vec[0] = cb/255.0f;
out[2]->vec[0] = cr/255.0f;
out[3]->vec[0] = in[0]->vec[3];
}
else if ((out[0]->hasoutput) || (out[1]->hasoutput) || (out[2]->hasoutput) || (out[3]->hasoutput)) {
/* make copy of buffer so input buffer doesn't get corrupted */
CompBuf *cbuf= dupalloc_compbuf(in[0]->data);
CompBuf *cbuf2=typecheck_compbuf(cbuf, CB_RGBA);
/* convert the RGB stackbuf to an HSV representation */
switch (node->custom1) {
case 1:
composit1_pixel_processor(node, cbuf2, cbuf2, in[0]->vec, do_sepycca_709, CB_RGBA);
break;
case 2:
composit1_pixel_processor(node, cbuf2, cbuf2, in[0]->vec, do_sepycca_jfif, CB_RGBA);
break;
case 0:
default:
composit1_pixel_processor(node, cbuf2, cbuf2, in[0]->vec, do_sepycca_601, CB_RGBA);
break;
}
/* separate each of those channels */
if (out[0]->hasoutput)
out[0]->data= valbuf_from_rgbabuf(cbuf2, CHAN_R);
if (out[1]->hasoutput)
out[1]->data= valbuf_from_rgbabuf(cbuf2, CHAN_G);
if (out[2]->hasoutput)
out[2]->data= valbuf_from_rgbabuf(cbuf2, CHAN_B);
if (out[3]->hasoutput)
out[3]->data= valbuf_from_rgbabuf(cbuf2, CHAN_A);
/*not used anymore */
if (cbuf2!=cbuf)
free_compbuf(cbuf2);
free_compbuf(cbuf);
}
}
#endif /* WITH_COMPOSITOR_LEGACY */
void register_node_type_cmp_sepycca(bNodeTreeType *ttype)
{
@@ -157,9 +54,6 @@ void register_node_type_cmp_sepycca(bNodeTreeType *ttype)
node_type_base(ttype, &ntype, CMP_NODE_SEPYCCA, "Separate YCbCrA", NODE_CLASS_CONVERTOR, NODE_OPTIONS);
node_type_socket_templates(&ntype, cmp_node_sepycca_in, cmp_node_sepycca_out);
node_type_size(&ntype, 80, 40, 140);
#ifdef WITH_COMPOSITOR_LEGACY
node_type_exec(&ntype, node_composit_exec_sepycca);
#endif
nodeRegisterType(ttype, &ntype);
}
@@ -179,128 +73,6 @@ static bNodeSocketTemplate cmp_node_combycca_out[] = {
{ -1, 0, "" }
};
#ifdef WITH_COMPOSITOR_LEGACY
static void do_comb_ycca_601(bNode *UNUSED(node), float *out, float *in1, float *in2, float *in3, float *in4)
{
float r, g, b;
float y, cb, cr;
/*need to un-normalize the data*/
y=in1[0]*255;
cb=in2[0]*255;
cr=in3[0]*255;
ycc_to_rgb(y, cb, cr, &r, &g, &b, BLI_YCC_ITU_BT601);
out[0] = r;
out[1] = g;
out[2] = b;
out[3] = in4[0];
}
static void do_comb_ycca_709(bNode *UNUSED(node), float *out, float *in1, float *in2, float *in3, float *in4)
{
float r, g, b;
float y, cb, cr;
/*need to un-normalize the data*/
y=in1[0]*255;
cb=in2[0]*255;
cr=in3[0]*255;
ycc_to_rgb(y, cb, cr, &r, &g, &b, BLI_YCC_ITU_BT709);
out[0] = r;
out[1] = g;
out[2] = b;
out[3] = in4[0];
}
static void do_comb_ycca_jfif(bNode *UNUSED(node), float *out, float *in1, float *in2, float *in3, float *in4)
{
float r, g, b;
float y, cb, cr;
/*need to un-normalize the data*/
y=in1[0]*255;
cb=in2[0]*255;
cr=in3[0]*255;
ycc_to_rgb(y, cb, cr, &r, &g, &b, BLI_YCC_JFIF_0_255);
out[0] = r;
out[1] = g;
out[2] = b;
out[3] = in4[0];
}
static void node_composit_exec_combycca(void *UNUSED(data), bNode *node, bNodeStack **in, bNodeStack **out)
{
/* stack order out: 1 ycca channels */
/* stack order in: 4 value channels */
/* input no image? then only color operation */
if ((in[0]->data==NULL) && (in[1]->data==NULL) && (in[2]->data==NULL) && (in[3]->data==NULL)) {
float y = in[0]->vec[0] * 255;
float cb = in[1]->vec[0] * 255;
float cr = in[2]->vec[0] * 255;
switch (node->custom1) {
case 1:
ycc_to_rgb(y, cb, cr, &out[0]->vec[0], &out[0]->vec[1], &out[0]->vec[2], BLI_YCC_ITU_BT709);
break;
case 2:
ycc_to_rgb(y, cb, cr, &out[0]->vec[0], &out[0]->vec[1], &out[0]->vec[2], BLI_YCC_JFIF_0_255);
break;
case 0:
default:
ycc_to_rgb(y, cb, cr, &out[0]->vec[0], &out[0]->vec[1], &out[0]->vec[2], BLI_YCC_ITU_BT601);
break;
}
out[0]->vec[3] = in[3]->vec[0];
}
else {
/* make output size of first available input image */
CompBuf *cbuf;
CompBuf *stackbuf;
/* allocate a CompBuf the size of the first available input */
if (in[0]->data) cbuf = in[0]->data;
else if (in[1]->data) cbuf = in[1]->data;
else if (in[2]->data) cbuf = in[2]->data;
else cbuf = in[3]->data;
stackbuf = alloc_compbuf(cbuf->x, cbuf->y, CB_RGBA, 1); /* allocs */
switch (node->custom1) {
case 1:
composit4_pixel_processor(node, stackbuf, in[0]->data, in[0]->vec, in[1]->data, in[1]->vec,
in[2]->data, in[2]->vec, in[3]->data, in[3]->vec,
do_comb_ycca_709, CB_VAL, CB_VAL, CB_VAL, CB_VAL);
break;
case 2:
composit4_pixel_processor(node, stackbuf, in[0]->data, in[0]->vec, in[1]->data, in[1]->vec,
in[2]->data, in[2]->vec, in[3]->data, in[3]->vec,
do_comb_ycca_jfif, CB_VAL, CB_VAL, CB_VAL, CB_VAL);
break;
case 0:
default:
composit4_pixel_processor(node, stackbuf, in[0]->data, in[0]->vec, in[1]->data, in[1]->vec,
in[2]->data, in[2]->vec, in[3]->data, in[3]->vec,
do_comb_ycca_601, CB_VAL, CB_VAL, CB_VAL, CB_VAL);
break;
}
out[0]->data= stackbuf;
}
}
#endif /* WITH_COMPOSITOR_LEGACY */
void register_node_type_cmp_combycca(bNodeTreeType *ttype)
{
static bNodeType ntype;
@@ -308,9 +80,6 @@ void register_node_type_cmp_combycca(bNodeTreeType *ttype)
node_type_base(ttype, &ntype, CMP_NODE_COMBYCCA, "Combine YCbCrA", NODE_CLASS_CONVERTOR, NODE_OPTIONS);
node_type_socket_templates(&ntype, cmp_node_combycca_in, cmp_node_combycca_out);
node_type_size(&ntype, 80, 40, 140);
#ifdef WITH_COMPOSITOR_LEGACY
node_type_exec(&ntype, node_composit_exec_combycca);
#endif
nodeRegisterType(ttype, &ntype);
}

View File

@@ -46,63 +46,6 @@ static bNodeSocketTemplate cmp_node_sepyuva_out[] = {
{ -1, 0, "" }
};
#ifdef WITH_COMPOSITOR_LEGACY
static void do_sepyuva(bNode *UNUSED(node), float *out, float *in)
{
float y, u, v;
rgb_to_yuv(in[0], in[1], in[2], &y, &u, &v);
out[0] = y;
out[1] = u;
out[2] = v;
out[3] = in[3];
}
static void node_composit_exec_sepyuva(void *UNUSED(data), bNode *node, bNodeStack **in, bNodeStack **out)
{
/* stack order out: bw channels */
/* stack order in: col */
/* input no image? then only color operation */
if (in[0]->data==NULL) {
float y, u, v;
rgb_to_yuv(in[0]->vec[0], in[0]->vec[1], in[0]->vec[2], &y, &u, &v);
out[0]->vec[0] = y;
out[1]->vec[0] = u;
out[2]->vec[0] = v;
out[3]->vec[0] = in[0]->vec[3];
}
else if ((out[0]->hasoutput) || (out[1]->hasoutput) || (out[2]->hasoutput) || (out[3]->hasoutput)) {
/* make copy of buffer so input image doesn't get corrupted */
CompBuf *cbuf= dupalloc_compbuf(in[0]->data);
CompBuf *cbuf2=typecheck_compbuf(cbuf, CB_RGBA);
/* convert the RGB stackbuf to an YUV representation */
composit1_pixel_processor(node, cbuf2, cbuf2, in[0]->vec, do_sepyuva, CB_RGBA);
/* separate each of those channels */
if (out[0]->hasoutput)
out[0]->data= valbuf_from_rgbabuf(cbuf2, CHAN_R);
if (out[1]->hasoutput)
out[1]->data= valbuf_from_rgbabuf(cbuf2, CHAN_G);
if (out[2]->hasoutput)
out[2]->data= valbuf_from_rgbabuf(cbuf2, CHAN_B);
if (out[3]->hasoutput)
out[3]->data= valbuf_from_rgbabuf(cbuf2, CHAN_A);
/*not used anymore */
if (cbuf2!=cbuf)
free_compbuf(cbuf2);
free_compbuf(cbuf);
}
}
#endif /* WITH_COMPOSITOR_LEGACY */
void register_node_type_cmp_sepyuva(bNodeTreeType *ttype)
{
@@ -111,9 +54,6 @@ void register_node_type_cmp_sepyuva(bNodeTreeType *ttype)
node_type_base(ttype, &ntype, CMP_NODE_SEPYUVA, "Separate YUVA", NODE_CLASS_CONVERTOR, 0);
node_type_socket_templates(&ntype, cmp_node_sepyuva_in, cmp_node_sepyuva_out);
node_type_size(&ntype, 80, 40, 140);
#ifdef WITH_COMPOSITOR_LEGACY
node_type_exec(&ntype, node_composit_exec_sepyuva);
#endif
nodeRegisterType(ttype, &ntype);
}
@@ -133,54 +73,6 @@ static bNodeSocketTemplate cmp_node_combyuva_out[] = {
{ -1, 0, "" }
};
#ifdef WITH_COMPOSITOR_LEGACY
static void do_comb_yuva(bNode *UNUSED(node), float *out, float *in1, float *in2, float *in3, float *in4)
{
float r, g, b;
yuv_to_rgb(in1[0], in2[0], in3[0], &r, &g, &b);
out[0] = r;
out[1] = g;
out[2] = b;
out[3] = in4[0];
}
static void node_composit_exec_combyuva(void *UNUSED(data), bNode *node, bNodeStack **in, bNodeStack **out)
{
/* stack order out: 1 rgba channels */
/* stack order in: 4 value channels */
/* input no image? then only color operation */
if ((in[0]->data==NULL) && (in[1]->data==NULL) && (in[2]->data==NULL) && (in[3]->data==NULL)) {
out[0]->vec[0] = in[0]->vec[0];
out[0]->vec[1] = in[1]->vec[0];
out[0]->vec[2] = in[2]->vec[0];
out[0]->vec[3] = in[3]->vec[0];
}
else {
/* make output size of first available input image */
CompBuf *cbuf;
CompBuf *stackbuf;
/* allocate a CompBuf the size of the first available input */
if (in[0]->data) cbuf = in[0]->data;
else if (in[1]->data) cbuf = in[1]->data;
else if (in[2]->data) cbuf = in[2]->data;
else cbuf = in[3]->data;
stackbuf = alloc_compbuf(cbuf->x, cbuf->y, CB_RGBA, 1); /* allocs */
composit4_pixel_processor(node, stackbuf, in[0]->data, in[0]->vec, in[1]->data, in[1]->vec,
in[2]->data, in[2]->vec, in[3]->data, in[3]->vec,
do_comb_yuva, CB_VAL, CB_VAL, CB_VAL, CB_VAL);
out[0]->data= stackbuf;
}
}
#endif /* WITH_COMPOSITOR_LEGACY */
void register_node_type_cmp_combyuva(bNodeTreeType *ttype)
{
static bNodeType ntype;
@@ -188,9 +80,6 @@ void register_node_type_cmp_combyuva(bNodeTreeType *ttype)
node_type_base(ttype, &ntype, CMP_NODE_COMBYUVA, "Combine YUVA", NODE_CLASS_CONVERTOR, NODE_OPTIONS);
node_type_socket_templates(&ntype, cmp_node_combyuva_in, cmp_node_combyuva_out);
node_type_size(&ntype, 80, 40, 140);
#ifdef WITH_COMPOSITOR_LEGACY
node_type_exec(&ntype, node_composit_exec_combyuva);
#endif
nodeRegisterType(ttype, &ntype);
}

View File

@@ -43,41 +43,6 @@ static bNodeSocketTemplate cmp_node_setalpha_out[] = {
{ -1, 0, "" }
};
#ifdef WITH_COMPOSITOR_LEGACY
static void node_composit_exec_setalpha(void *UNUSED(data), bNode *node, bNodeStack **in, bNodeStack **out)
{
/* stack order out: RGBA image */
/* stack order in: col, alpha */
/* input no image? then only color operation */
if (in[0]->data==NULL && in[1]->data==NULL) {
out[0]->vec[0] = in[0]->vec[0];
out[0]->vec[1] = in[0]->vec[1];
out[0]->vec[2] = in[0]->vec[2];
out[0]->vec[3] = in[1]->vec[0];
}
else {
/* make output size of input image */
CompBuf *cbuf= in[0]->data?in[0]->data:in[1]->data;
CompBuf *stackbuf= alloc_compbuf(cbuf->x, cbuf->y, CB_RGBA, 1); /* allocs */
if (in[1]->data==NULL && in[1]->vec[0]==1.0f) {
/* pass on image */
composit1_pixel_processor(node, stackbuf, in[0]->data, in[0]->vec, do_copy_rgb, CB_RGBA);
}
else {
/* send an compbuf or a value to set as alpha - composit2_pixel_processor handles choosing the right one */
composit2_pixel_processor(node, stackbuf, in[0]->data, in[0]->vec, in[1]->data, in[1]->vec, do_copy_a_rgba, CB_RGBA, CB_VAL);
}
out[0]->data= stackbuf;
}
}
#endif /* WITH_COMPOSITOR_LEGACY */
void register_node_type_cmp_setalpha(bNodeTreeType *ttype)
{
static bNodeType ntype;
@@ -85,9 +50,6 @@ void register_node_type_cmp_setalpha(bNodeTreeType *ttype)
node_type_base(ttype, &ntype, CMP_NODE_SETALPHA, "Set Alpha", NODE_CLASS_CONVERTOR, NODE_OPTIONS);
node_type_socket_templates(&ntype, cmp_node_setalpha_in, cmp_node_setalpha_out);
node_type_size(&ntype, 120, 40, 140);
#ifdef WITH_COMPOSITOR_LEGACY
node_type_exec(&ntype, node_composit_exec_setalpha);
#endif
nodeRegisterType(ttype, &ntype);
}

View File

@@ -39,110 +39,6 @@ static bNodeSocketTemplate cmp_node_splitviewer_in[] = {
{ -1, 0, "" }
};
#ifdef WITH_COMPOSITOR_LEGACY
static void do_copy_split_rgba(bNode *UNUSED(node), float *out, float *in1, float *in2, float *fac)
{
if (*fac==0.0f) {
copy_v4_v4(out, in1);
}
else {
copy_v4_v4(out, in2);
}
}
static void node_composit_exec_splitviewer(void *data, bNode *node, bNodeStack **in, bNodeStack **UNUSED(out))
{
/* image assigned to output */
/* stack order input sockets: image image */
if (in[0]->data==NULL || in[1]->data==NULL)
return;
if (node->id && (node->flag & NODE_DO_OUTPUT)) { /* only one works on out */
Image *ima= (Image *)node->id;
RenderData *rd= data;
ImBuf *ibuf;
CompBuf *cbuf, *buf1, *buf2, *mask;
int x, y;
float offset;
void *lock;
buf1= typecheck_compbuf(in[0]->data, CB_RGBA);
buf2= typecheck_compbuf(in[1]->data, CB_RGBA);
BKE_image_user_frame_calc(node->storage, rd->cfra, 0);
/* always returns for viewer image, but we check nevertheless */
ibuf= BKE_image_acquire_ibuf(ima, node->storage, &lock);
if (ibuf==NULL) {
printf("node_composit_exec_viewer error\n");
BKE_image_release_ibuf(ima, ibuf, lock);
return;
}
/* free all in ibuf */
imb_freerectImBuf(ibuf);
imb_freerectfloatImBuf(ibuf);
IMB_freezbuffloatImBuf(ibuf);
/* make ibuf, and connect to ima */
ibuf->x= buf1->x;
ibuf->y= buf1->y;
imb_addrectfloatImBuf(ibuf);
ima->ok= IMA_OK_LOADED;
/* output buf */
cbuf= alloc_compbuf(buf1->x, buf1->y, CB_RGBA, 0); /* no alloc*/
cbuf->rect= ibuf->rect_float;
/* mask buf */
mask= alloc_compbuf(buf1->x, buf1->y, CB_VAL, 1);
/* Check which offset mode is selected and limit offset if needed */
if (node->custom2 == 0) {
offset = buf1->x / 100.0f * node->custom1;
CLAMP(offset, 0, buf1->x);
}
else {
offset = buf1->y / 100.0f * node->custom1;
CLAMP(offset, 0, buf1->y);
}
if (node->custom2 == 0) {
for (y=0; y<buf1->y; y++) {
float *fac= mask->rect + y*buf1->x;
for (x=offset; x>0; x--, fac++)
*fac= 1.0f;
}
}
else {
for (y=0; y<offset; y++) {
float *fac= mask->rect + y*buf1->x;
for (x=buf1->x; x>0; x--, fac++)
*fac= 1.0f;
}
}
composit3_pixel_processor(node, cbuf, buf1, in[0]->vec, buf2, in[1]->vec, mask, NULL, do_copy_split_rgba, CB_RGBA, CB_RGBA, CB_VAL);
BKE_image_release_ibuf(ima, ibuf, lock);
generate_preview(data, node, cbuf);
free_compbuf(cbuf);
free_compbuf(mask);
if (in[0]->data != buf1)
free_compbuf(buf1);
if (in[1]->data != buf2)
free_compbuf(buf2);
}
}
#endif /* WITH_COMPOSITOR_LEGACY */
static void node_composit_init_splitviewer(bNodeTree *UNUSED(ntree), bNode *node, bNodeTemplate *UNUSED(ntemp))
{
ImageUser *iuser= MEM_callocN(sizeof(ImageUser), "node image user");
@@ -162,9 +58,6 @@ void register_node_type_cmp_splitviewer(bNodeTreeType *ttype)
node_type_size(&ntype, 140, 100, 320);
node_type_init(&ntype, node_composit_init_splitviewer);
node_type_storage(&ntype, "ImageUser", node_free_standard_storage, node_copy_standard_storage);
#ifdef WITH_COMPOSITOR_LEGACY
node_type_exec(&ntype, node_composit_exec_splitviewer);
#endif
/* Do not allow muting for this node. */
node_type_internal_links(&ntype, NULL);

View File

@@ -45,32 +45,6 @@ static bNodeSocketTemplate cmp_node_stabilize2d_out[] = {
{ -1, 0, "" }
};
#ifdef WITH_COMPOSITOR_LEGACY
static void node_composit_exec_stabilize2d(void *data, bNode *node, bNodeStack **in, bNodeStack **out)
{
if (in[0]->data && node->id) {
RenderData *rd = data;
MovieClip *clip = (MovieClip *)node->id;
CompBuf *cbuf = typecheck_compbuf(in[0]->data, CB_RGBA);
CompBuf *stackbuf;
float loc[2], scale, angle;
int clip_framenr = BKE_movieclip_remap_scene_to_clip_frame(clip, rd->cfra);
BKE_tracking_stabilization_data_get(&clip->tracking, clip_framenr, cbuf->x, cbuf->y, loc, &scale, &angle);
stackbuf = node_composit_transform(cbuf, loc[0], loc[1], angle, scale, node->custom1);
/* pass on output and free */
out[0]->data = stackbuf;
if (cbuf != in[0]->data)
free_compbuf(cbuf);
}
}
#endif /* WITH_COMPOSITOR_LEGACY */
void register_node_type_cmp_stabilize2d(bNodeTreeType *ttype)
{
static bNodeType ntype;
@@ -78,9 +52,6 @@ void register_node_type_cmp_stabilize2d(bNodeTreeType *ttype)
node_type_base(ttype, &ntype, CMP_NODE_STABILIZE2D, "Stabilize 2D", NODE_CLASS_DISTORT, NODE_OPTIONS);
node_type_socket_templates(&ntype, cmp_node_stabilize2d_in, cmp_node_stabilize2d_out);
node_type_size(&ntype, 140, 100, 320);
#ifdef WITH_COMPOSITOR_LEGACY
node_type_exec(&ntype, node_composit_exec_stabilize2d);
#endif
nodeRegisterType(ttype, &ntype);
}

View File

@@ -44,108 +44,6 @@ static bNodeSocketTemplate cmp_node_texture_out[] = {
{ -1, 0, "" }
};
#ifdef WITH_COMPOSITOR_LEGACY
/* called without rect allocated */
static void texture_procedural(CompBuf *cbuf, float *out, float xco, float yco)
{
bNode *node= cbuf->node;
TexResult texres= {0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0, NULL};
float vec[3], *size, nor[3] = {0.0f, 0.0f, 0.0f}, col[4];
int retval, type= cbuf->procedural_type;
size= cbuf->procedural_size;
vec[0] = size[0]*(xco + cbuf->procedural_offset[0]);
vec[1] = size[1]*(yco + cbuf->procedural_offset[1]);
vec[2] = size[2]*cbuf->procedural_offset[2];
retval= multitex_ext((Tex *)node->id, vec, NULL, NULL, 0, &texres);
if (type==CB_VAL) {
if (texres.talpha)
col[0] = texres.ta;
else
col[0] = texres.tin;
}
else if (type==CB_RGBA) {
if (texres.talpha)
col[3] = texres.ta;
else
col[3] = texres.tin;
if ((retval & TEX_RGB)) {
copy_v3_v3(col, &texres.tr);
}
else {
copy_v3_fl(col, col[3]);
}
}
else {
copy_v3_v3(col, nor);
}
typecheck_compbuf_color(out, col, cbuf->type, cbuf->procedural_type);
}
/* texture node outputs get a small rect, to make sure all other nodes accept it */
/* only the pixel-processor nodes do something with it though */
static void node_composit_exec_texture(void *data, bNode *node, bNodeStack **in, bNodeStack **out)
{
/* outputs: value, color, normal */
if (node->id) {
RenderData *rd= data;
short sizex, sizey;
/* first make the preview image */
CompBuf *prevbuf= alloc_compbuf(140, 140, CB_RGBA, 1); /* alloc */
prevbuf->rect_procedural= texture_procedural;
prevbuf->node= node;
copy_v3_v3(prevbuf->procedural_offset, in[0]->vec);
copy_v3_v3(prevbuf->procedural_size, in[1]->vec);
prevbuf->procedural_type= CB_RGBA;
composit1_pixel_processor(node, prevbuf, prevbuf, out[0]->vec, do_copy_rgba, CB_RGBA);
generate_preview(data, node, prevbuf);
free_compbuf(prevbuf);
/* texture procedural buffer type doesnt work well, we now render a buffer in scene size */
sizex = (rd->size*rd->xsch)/100;
sizey = (rd->size*rd->ysch)/100;
if (out[0]->hasoutput) {
CompBuf *stackbuf= alloc_compbuf(sizex, sizey, CB_VAL, 1); /* alloc */
stackbuf->rect_procedural= texture_procedural;
stackbuf->node= node;
copy_v3_v3(stackbuf->procedural_offset, in[0]->vec);
copy_v3_v3(stackbuf->procedural_size, in[1]->vec);
stackbuf->procedural_type= CB_VAL;
composit1_pixel_processor(node, stackbuf, stackbuf, out[0]->vec, do_copy_value, CB_VAL);
stackbuf->rect_procedural= NULL;
out[0]->data= stackbuf;
}
if (out[1]->hasoutput) {
CompBuf *stackbuf= alloc_compbuf(sizex, sizey, CB_RGBA, 1); /* alloc */
stackbuf->rect_procedural= texture_procedural;
stackbuf->node= node;
copy_v3_v3(stackbuf->procedural_offset, in[0]->vec);
copy_v3_v3(stackbuf->procedural_size, in[1]->vec);
stackbuf->procedural_type= CB_RGBA;
composit1_pixel_processor(node, stackbuf, stackbuf, out[0]->vec, do_copy_rgba, CB_RGBA);
stackbuf->rect_procedural= NULL;
out[1]->data= stackbuf;
}
}
}
#endif /* WITH_COMPOSITOR_LEGACY */
void register_node_type_cmp_texture(bNodeTreeType *ttype)
{
static bNodeType ntype;
@@ -153,9 +51,6 @@ void register_node_type_cmp_texture(bNodeTreeType *ttype)
node_type_base(ttype, &ntype, CMP_NODE_TEXTURE, "Texture", NODE_CLASS_INPUT, NODE_OPTIONS|NODE_PREVIEW);
node_type_socket_templates(&ntype, cmp_node_texture_in, cmp_node_texture_out);
node_type_size(&ntype, 120, 80, 240);
#ifdef WITH_COMPOSITOR_LEGACY
node_type_exec(&ntype, node_composit_exec_texture);
#endif
nodeRegisterType(ttype, &ntype);
}

View File

@@ -41,114 +41,6 @@ static bNodeSocketTemplate cmp_node_tonemap_out[] = {
{ -1, 0, "" }
};
#ifdef WITH_COMPOSITOR_LEGACY
static float avgLogLum(CompBuf *src, float* auto_key, float* Lav, float* Cav)
{
float lsum = 0;
int p = src->x*src->y;
fRGB* bc = (fRGB*)src->rect;
float avl, maxl = -1e10f, minl = 1e10f;
const float sc = 1.f/(src->x*src->y);
*Lav = 0.f;
while (p--) {
float L = rgb_to_luma_y(bc[0]);
*Lav += L;
add_v3_v3(Cav, bc[0]);
lsum += (float)log((double)MAX2(L, 0.0) + 1e-5);
maxl = (L > maxl) ? L : maxl;
minl = (L < minl) ? L : minl;
bc++;
}
*Lav *= sc;
mul_v3_fl(Cav, sc);
maxl = log((double)maxl + 1e-5); minl = log((double)minl + 1e-5f); avl = lsum*sc;
*auto_key = (maxl > minl) ? ((maxl - avl) / (maxl - minl)) : 1.f;
return exp((double)avl);
}
static void tonemap(NodeTonemap* ntm, CompBuf* dst, CompBuf* src)
{
int x, y;
float dr, dg, db, al, igm = (ntm->gamma==0.f) ? 1 : (1.f / ntm->gamma);
float auto_key, Lav, Cav[3] = {0, 0, 0};
al = avgLogLum(src, &auto_key, &Lav, Cav);
al = (al == 0.f) ? 0.f : (ntm->key / al);
if (ntm->type == 1) {
// Reinhard/Devlin photoreceptor
const float f = exp((double)-ntm->f);
const float m = (ntm->m > 0.f) ? ntm->m : (0.3f + 0.7f*pow((double)auto_key, 1.4));
const float ic = 1.f - ntm->c, ia = 1.f - ntm->a;
if (ntm->m == 0.f) printf("tonemap node, M: %g\n", m);
for (y=0; y<src->y; ++y) {
fRGB* sp = (fRGB*)&src->rect[y*src->x*src->type];
fRGB* dp = (fRGB*)&dst->rect[y*src->x*src->type];
for (x=0; x<src->x; ++x) {
const float L = rgb_to_luma_y(sp[x]);
float I_l = sp[x][0] + ic*(L - sp[x][0]);
float I_g = Cav[0] + ic*(Lav - Cav[0]);
float I_a = I_l + ia*(I_g - I_l);
dp[x][0] /= (dp[x][0] + pow((double)f*I_a, (double)m));
I_l = sp[x][1] + ic*(L - sp[x][1]);
I_g = Cav[1] + ic*(Lav - Cav[1]);
I_a = I_l + ia*(I_g - I_l);
dp[x][1] /= (dp[x][1] + pow((double)f*I_a, (double)m));
I_l = sp[x][2] + ic*(L - sp[x][2]);
I_g = Cav[2] + ic*(Lav - Cav[2]);
I_a = I_l + ia*(I_g - I_l);
dp[x][2] /= (dp[x][2] + pow((double)f*I_a, (double)m));
}
}
return;
}
// Reinhard simple photographic tm (simplest, not using whitepoint var)
for (y=0; y<src->y; y++) {
fRGB* sp = (fRGB*)&src->rect[y*src->x*src->type];
fRGB* dp = (fRGB*)&dst->rect[y*src->x*src->type];
for (x=0; x<src->x; x++) {
copy_v4_v4(dp[x], sp[x]);
mul_v3_fl(dp[x], al);
dr = dp[x][0] + ntm->offset;
dg = dp[x][1] + ntm->offset;
db = dp[x][2] + ntm->offset;
dp[x][0] /= ((dr == 0.f) ? 1.f : dr);
dp[x][1] /= ((dg == 0.f) ? 1.f : dg);
dp[x][2] /= ((db == 0.f) ? 1.f : db);
if (igm != 0.f) {
dp[x][0] = pow((double)MAX2(dp[x][0], 0.0), igm);
dp[x][1] = pow((double)MAX2(dp[x][1], 0.0), igm);
dp[x][2] = pow((double)MAX2(dp[x][2], 0.0), igm);
}
}
}
}
static void node_composit_exec_tonemap(void *UNUSED(data), bNode *node, bNodeStack **in, bNodeStack **out)
{
CompBuf *new, *img = in[0]->data;
if ((img==NULL) || (out[0]->hasoutput==0)) return;
if (img->type != CB_RGBA)
img = typecheck_compbuf(img, CB_RGBA);
new = dupalloc_compbuf(img);
tonemap(node->storage, new, img);
out[0]->data = new;
if (img!=in[0]->data)
free_compbuf(img);
}
#endif /* WITH_COMPOSITOR_LEGACY */
static void node_composit_init_tonemap(bNodeTree *UNUSED(ntree), bNode *node, bNodeTemplate *UNUSED(ntemp))
{
NodeTonemap *ntm = MEM_callocN(sizeof(NodeTonemap), "node tonemap data");
@@ -174,9 +66,6 @@ void register_node_type_cmp_tonemap(bNodeTreeType *ttype)
node_type_size(&ntype, 150, 120, 200);
node_type_init(&ntype, node_composit_init_tonemap);
node_type_storage(&ntype, "NodeTonemap", node_free_standard_storage, node_copy_standard_storage);
#ifdef WITH_COMPOSITOR_LEGACY
node_type_exec(&ntype, node_composit_exec_tonemap);
#endif
nodeRegisterType(ttype, &ntype);
}

View File

@@ -39,15 +39,6 @@ static bNodeSocketTemplate cmp_node_trackpos_out[] = {
{ -1, 0, "" }
};
#ifdef WITH_COMPOSITOR_LEGACY
static void node_composit_exec_trackpos(void *UNUSED(data), bNode *UNUSED(node), bNodeStack **UNUSED(in), bNodeStack **UNUSED(out))
{
/* pass */
}
#endif /* WITH_COMPOSITOR_LEGACY */
static void init(bNodeTree *UNUSED(ntree), bNode *node, bNodeTemplate *UNUSED(ntemp))
{
NodeTrackPosData *data = MEM_callocN(sizeof(NodeTrackPosData), "node track position data");
@@ -64,9 +55,6 @@ void register_node_type_cmp_trackpos(bNodeTreeType *ttype)
node_type_size(&ntype, 120, 80, 300);
node_type_init(&ntype, init);
node_type_storage(&ntype, "NodeTrackPosData", node_free_standard_storage, node_copy_standard_storage);
#ifdef WITH_COMPOSITOR_LEGACY
node_type_exec(&ntype, node_composit_exec_trackpos);
#endif
nodeRegisterType(ttype, &ntype);
}

View File

@@ -48,89 +48,6 @@ static bNodeSocketTemplate cmp_node_transform_out[] = {
{ -1, 0, "" }
};
#ifdef WITH_COMPOSITOR_LEGACY
CompBuf* node_composit_transform(CompBuf *cbuf, float x, float y, float angle, float scale, int filter_type)
{
CompBuf *stackbuf = alloc_compbuf(cbuf->x, cbuf->y, CB_RGBA, TRUE);
ImBuf *ibuf, *obuf;
float mat[4][4], lmat[4][4], rmat[4][4], smat[4][4], cmat[4][4], icmat[4][4];
float svec[3] = {scale, scale, scale}, loc[2] = {x, y};
unit_m4(rmat);
unit_m4(lmat);
unit_m4(smat);
unit_m4(cmat);
/* image center as rotation center */
cmat[3][0] = (float)cbuf->x/2.0f;
cmat[3][1] = (float)cbuf->y/2.0f;
invert_m4_m4(icmat, cmat);
size_to_mat4(smat, svec); /* scale matrix */
add_v2_v2(lmat[3], loc); /* tranlation matrix */
rotate_m4(rmat, 'Z', angle); /* rotation matrix */
/* compose transformation matrix */
mul_serie_m4(mat, lmat, cmat, rmat, smat, icmat, NULL, NULL, NULL);
invert_m4(mat);
ibuf = IMB_allocImBuf(cbuf->x, cbuf->y, 32, 0);
obuf = IMB_allocImBuf(stackbuf->x, stackbuf->y, 32, 0);
if (ibuf && obuf) {
int i, j;
ibuf->rect_float = cbuf->rect;
obuf->rect_float = stackbuf->rect;
for (j = 0; j < cbuf->y; j++) {
for (i = 0; i < cbuf->x; i++) {
float vec[3] = {i, j, 0};
mul_v3_m4v3(vec, mat, vec);
switch (filter_type) {
case 0:
nearest_interpolation(ibuf, obuf, vec[0], vec[1], i, j);
break;
case 1:
bilinear_interpolation(ibuf, obuf, vec[0], vec[1], i, j);
break;
case 2:
bicubic_interpolation(ibuf, obuf, vec[0], vec[1], i, j);
break;
}
}
}
IMB_freeImBuf(ibuf);
IMB_freeImBuf(obuf);
}
/* pass on output and free */
return stackbuf;
}
static void node_composit_exec_transform(void *UNUSED(data), bNode *node, bNodeStack **in, bNodeStack **out)
{
if (in[0]->data) {
CompBuf *cbuf = typecheck_compbuf(in[0]->data, CB_RGBA);
CompBuf *stackbuf;
stackbuf = node_composit_transform(cbuf, in[1]->vec[0], in[2]->vec[0], in[3]->vec[0], in[4]->vec[0], node->custom1);
/* pass on output and free */
out[0]->data = stackbuf;
if (cbuf != in[0]->data)
free_compbuf(cbuf);
}
}
#endif /* WITH_COMPOSITOR_LEGACY */
void register_node_type_cmp_transform(bNodeTreeType *ttype)
{
static bNodeType ntype;
@@ -138,9 +55,6 @@ void register_node_type_cmp_transform(bNodeTreeType *ttype)
node_type_base(ttype, &ntype, CMP_NODE_TRANSFORM, "Transform", NODE_CLASS_DISTORT, NODE_OPTIONS);
node_type_socket_templates(&ntype, cmp_node_transform_in, cmp_node_transform_out);
node_type_size(&ntype, 140, 100, 320);
#ifdef WITH_COMPOSITOR_LEGACY
node_type_exec(&ntype, node_composit_exec_transform);
#endif
nodeRegisterType(ttype, &ntype);
}

View File

@@ -46,23 +46,6 @@ static bNodeSocketTemplate cmp_node_translate_out[] = {
{ -1, 0, "" }
};
#ifdef WITH_COMPOSITOR_LEGACY
static void node_composit_exec_translate(void *UNUSED(data), bNode *UNUSED(node), bNodeStack **in, bNodeStack **out)
{
if (in[0]->data) {
CompBuf *cbuf= in[0]->data;
CompBuf *stackbuf= pass_on_compbuf(cbuf);
stackbuf->xof+= (int)floor(in[1]->vec[0]);
stackbuf->yof+= (int)floor(in[2]->vec[0]);
out[0]->data= stackbuf;
}
}
#endif /* WITH_COMPOSITOR_LEGACY */
void register_node_type_cmp_translate(bNodeTreeType *ttype)
{
static bNodeType ntype;
@@ -70,9 +53,6 @@ void register_node_type_cmp_translate(bNodeTreeType *ttype)
node_type_base(ttype, &ntype, CMP_NODE_TRANSLATE, "Translate", NODE_CLASS_DISTORT, NODE_OPTIONS);
node_type_socket_templates(&ntype, cmp_node_translate_in, cmp_node_translate_out);
node_type_size(&ntype, 140, 100, 320);
#ifdef WITH_COMPOSITOR_LEGACY
node_type_exec(&ntype, node_composit_exec_translate);
#endif
nodeRegisterType(ttype, &ntype);
}

View File

@@ -44,44 +44,6 @@ static bNodeSocketTemplate cmp_node_valtorgb_out[] = {
{ -1, 0, "" }
};
#ifdef WITH_COMPOSITOR_LEGACY
static void do_colorband_composit(bNode *node, float *out, float *in)
{
do_colorband(node->storage, in[0], out);
}
static void node_composit_exec_valtorgb(void *UNUSED(data), bNode *node, bNodeStack **in, bNodeStack **out)
{
/* stack order in: fac */
/* stack order out: col, alpha */
if (out[0]->hasoutput==0 && out[1]->hasoutput==0)
return;
if (node->storage) {
/* input no image? then only color operation */
if (in[0]->data==NULL) {
do_colorband(node->storage, in[0]->vec[0], out[0]->vec);
}
else {
/* make output size of input image */
CompBuf *cbuf= in[0]->data;
CompBuf *stackbuf= alloc_compbuf(cbuf->x, cbuf->y, CB_RGBA, 1); /* allocs */
composit1_pixel_processor(node, stackbuf, in[0]->data, in[0]->vec, do_colorband_composit, CB_VAL);
out[0]->data= stackbuf;
if (out[1]->hasoutput)
out[1]->data= valbuf_from_rgbabuf(stackbuf, CHAN_A);
}
}
}
#endif /* WITH_COMPOSITOR_LEGACY */
static void node_composit_init_valtorgb(bNodeTree *UNUSED(ntree), bNode *node, bNodeTemplate *UNUSED(ntemp))
{
node->storage= add_colorband(1);
@@ -96,9 +58,6 @@ void register_node_type_cmp_valtorgb(bNodeTreeType *ttype)
node_type_size(&ntype, 240, 200, 300);
node_type_init(&ntype, node_composit_init_valtorgb);
node_type_storage(&ntype, "ColorBand", node_free_standard_storage, node_copy_standard_storage);
#ifdef WITH_COMPOSITOR_LEGACY
node_type_exec(&ntype, node_composit_exec_valtorgb);
#endif
nodeRegisterType(ttype, &ntype);
}
@@ -115,38 +74,6 @@ static bNodeSocketTemplate cmp_node_rgbtobw_out[] = {
{ -1, 0, "" }
};
#ifdef WITH_COMPOSITOR_LEGACY
static void do_rgbtobw(bNode *UNUSED(node), float *out, float *in)
{
out[0] = rgb_to_bw(in);
}
static void node_composit_exec_rgbtobw(void *UNUSED(data), bNode *node, bNodeStack **in, bNodeStack **out)
{
/* stack order out: bw */
/* stack order in: col */
if (out[0]->hasoutput==0)
return;
/* input no image? then only color operation */
if (in[0]->data==NULL) {
do_rgbtobw(node, out[0]->vec, in[0]->vec);
}
else {
/* make output size of input image */
CompBuf *cbuf= in[0]->data;
CompBuf *stackbuf= alloc_compbuf(cbuf->x, cbuf->y, CB_VAL, 1); /* allocs */
composit1_pixel_processor(node, stackbuf, in[0]->data, in[0]->vec, do_rgbtobw, CB_RGBA);
out[0]->data= stackbuf;
}
}
#endif /* WITH_COMPOSITOR_LEGACY */
void register_node_type_cmp_rgbtobw(bNodeTreeType *ttype)
{
static bNodeType ntype;
@@ -154,9 +81,6 @@ void register_node_type_cmp_rgbtobw(bNodeTreeType *ttype)
node_type_base(ttype, &ntype, CMP_NODE_RGBTOBW, "RGB to BW", NODE_CLASS_CONVERTOR, 0);
node_type_socket_templates(&ntype, cmp_node_rgbtobw_in, cmp_node_rgbtobw_out);
node_type_size(&ntype, 80, 40, 120);
#ifdef WITH_COMPOSITOR_LEGACY
node_type_exec(&ntype, node_composit_exec_rgbtobw);
#endif
nodeRegisterType(ttype, &ntype);
}

View File

@@ -49,18 +49,6 @@ static void node_composit_init_value(bNodeTree *UNUSED(ntree), bNode *node, bNod
dval->max = FLT_MAX;
}
#ifdef WITH_COMPOSITOR_LEGACY
static void node_composit_exec_value(void *UNUSED(data), bNode *node, bNodeStack **UNUSED(in), bNodeStack **out)
{
bNodeSocket *sock= node->outputs.first;
float val= ((bNodeSocketValueFloat*)sock->default_value)->value;
out[0]->vec[0] = val;
}
#endif /* WITH_COMPOSITOR_LEGACY */
void register_node_type_cmp_value(bNodeTreeType *ttype)
{
static bNodeType ntype;
@@ -69,9 +57,6 @@ void register_node_type_cmp_value(bNodeTreeType *ttype)
node_type_socket_templates(&ntype, NULL, cmp_node_value_out);
node_type_init(&ntype, node_composit_init_value);
node_type_size(&ntype, 80, 40, 120);
#ifdef WITH_COMPOSITOR_LEGACY
node_type_exec(&ntype, node_composit_exec_value);
#endif
nodeRegisterType(ttype, &ntype);
}

View File

@@ -45,48 +45,6 @@ static bNodeSocketTemplate cmp_node_vecblur_out[] = {
{ -1, 0, "" }
};
#ifdef WITH_COMPOSITOR_LEGACY
static void node_composit_exec_vecblur(void *UNUSED(data), bNode *node, bNodeStack **in, bNodeStack **out)
{
NodeBlurData *nbd = node->storage;
CompBuf *new, *img = in[0]->data, *vecbuf = in[2]->data, *zbuf = in[1]->data;
if (img == NULL || vecbuf == NULL || zbuf == NULL || out[0]->hasoutput == 0)
return;
if (vecbuf->x != img->x || vecbuf->y != img->y) {
printf("ERROR: cannot do different sized vecbuf yet\n");
return;
}
if (vecbuf->type != CB_VEC4) {
printf("ERROR: input should be vecbuf\n");
return;
}
if (zbuf->type != CB_VAL) {
printf("ERROR: input should be zbuf\n");
return;
}
if (zbuf->x != img->x || zbuf->y != img->y) {
printf("ERROR: cannot do different sized zbuf yet\n");
return;
}
/* allow the input image to be of another type */
img = typecheck_compbuf(in[0]->data, CB_RGBA);
new = dupalloc_compbuf(img);
/* call special zbuffer version */
RE_zbuf_accumulate_vecblur(nbd, img->x, img->y, new->rect, img->rect, vecbuf->rect, zbuf->rect);
out[0]->data = new;
if (img != in[0]->data)
free_compbuf(img);
}
#endif /* WITH_COMPOSITOR_LEGACY */
static void node_composit_init_vecblur(bNodeTree *UNUSED(ntree), bNode *node, bNodeTemplate *UNUSED(ntemp))
{
NodeBlurData *nbd = MEM_callocN(sizeof(NodeBlurData), "node blur data");
@@ -105,9 +63,6 @@ void register_node_type_cmp_vecblur(bNodeTreeType *ttype)
node_type_size(&ntype, 120, 80, 200);
node_type_init(&ntype, node_composit_init_vecblur);
node_type_storage(&ntype, "NodeBlurData", node_free_standard_storage, node_copy_standard_storage);
#ifdef WITH_COMPOSITOR_LEGACY
node_type_exec(&ntype, node_composit_exec_vecblur);
#endif
nodeRegisterType(ttype, &ntype);
}

View File

@@ -41,90 +41,6 @@ static bNodeSocketTemplate cmp_node_viewer_in[] = {
{ -1, 0, "" }
};
#ifdef WITH_COMPOSITOR_LEGACY
static void node_composit_exec_viewer(void *data, bNode *node, bNodeStack **in, bNodeStack **UNUSED(out))
{
/* image assigned to output */
/* stack order input sockets: col, alpha, z */
if (node->id && (node->flag & NODE_DO_OUTPUT)) { /* only one works on out */
RenderData *rd = data;
Image *ima = (Image *)node->id;
ImBuf *ibuf;
CompBuf *cbuf, *tbuf;
int rectx, recty;
void *lock;
BKE_image_user_frame_calc(node->storage, rd->cfra, 0);
/* always returns for viewer image, but we check nevertheless */
ibuf = BKE_image_acquire_ibuf(ima, node->storage, &lock);
if (ibuf == NULL) {
printf("node_composit_exec_viewer error\n");
BKE_image_release_ibuf(ima, ibuf, lock);
return;
}
/* free all in ibuf */
imb_freerectImBuf(ibuf);
imb_freerectfloatImBuf(ibuf);
IMB_freezbuffloatImBuf(ibuf);
/* get size */
tbuf = in[0]->data ? in[0]->data : (in[1]->data ? in[1]->data : in[2]->data);
if (tbuf == NULL) {
rectx = 320; recty = 256;
}
else {
rectx = tbuf->x;
recty = tbuf->y;
}
/* make ibuf, and connect to ima */
ibuf->x = rectx;
ibuf->y = recty;
imb_addrectfloatImBuf(ibuf);
ima->ok = IMA_OK_LOADED;
/* now we combine the input with ibuf */
cbuf = alloc_compbuf(rectx, recty, CB_RGBA, 0); /* no alloc*/
cbuf->rect = ibuf->rect_float;
/* when no alpha, we can simply copy */
if (in[1]->data == NULL) {
composit1_pixel_processor(node, cbuf, in[0]->data, in[0]->vec, do_copy_rgba, CB_RGBA);
}
else
composit2_pixel_processor(node, cbuf, in[0]->data, in[0]->vec, in[1]->data, in[1]->vec, do_copy_a_rgba, CB_RGBA, CB_VAL);
/* zbuf option */
if (in[2]->data) {
CompBuf *zbuf = alloc_compbuf(rectx, recty, CB_VAL, 1);
ibuf->zbuf_float = zbuf->rect;
ibuf->mall |= IB_zbuffloat;
composit1_pixel_processor(node, zbuf, in[2]->data, in[2]->vec, do_copy_value, CB_VAL);
/* free compbuf, but not the rect */
zbuf->malloc = 0;
free_compbuf(zbuf);
}
BKE_image_release_ibuf(ima, ibuf, lock);
generate_preview(data, node, cbuf);
free_compbuf(cbuf);
}
else if (in[0]->data) {
generate_preview(data, node, in[0]->data);
}
}
#endif /* WITH_COMPOSITOR_LEGACY */
static void node_composit_init_viewer(bNodeTree *UNUSED(ntree), bNode *node, bNodeTemplate *UNUSED(ntemp))
{
ImageUser *iuser = MEM_callocN(sizeof(ImageUser), "node image user");
@@ -145,9 +61,6 @@ void register_node_type_cmp_viewer(bNodeTreeType *ttype)
node_type_size(&ntype, 80, 60, 200);
node_type_init(&ntype, node_composit_init_viewer);
node_type_storage(&ntype, "ImageUser", node_free_standard_storage, node_copy_standard_storage);
#ifdef WITH_COMPOSITOR_LEGACY
node_type_exec(&ntype, node_composit_exec_viewer);
#endif
node_type_internal_links(&ntype, NULL);

View File

@@ -48,183 +48,6 @@ static bNodeSocketTemplate cmp_node_zcombine_out[] = {
{ -1, 0, "" }
};
#ifdef WITH_COMPOSITOR_LEGACY
static void do_zcombine(bNode *node, float *out, float *src1, float *z1, float *src2, float *z2)
{
float alpha;
float malpha;
if (*z1 <= *z2) {
if (node->custom1) {
// use alpha in combine operation
alpha= src1[3];
malpha= 1.0f - alpha;
out[0] = malpha*src2[0] + alpha*src1[0];
out[1] = malpha*src2[1] + alpha*src1[1];
out[2] = malpha*src2[2] + alpha*src1[2];
out[3] = malpha*src2[3] + alpha*src1[3];
}
else {
// do combination based solely on z value
copy_v4_v4(out, src1);
}
}
else {
if (node->custom1) {
// use alpha in combine operation
alpha= src2[3];
malpha= 1.0f - alpha;
out[0] = malpha*src1[0] + alpha*src2[0];
out[1] = malpha*src1[1] + alpha*src2[1];
out[2] = malpha*src1[2] + alpha*src2[2];
out[3] = malpha*src1[3] + alpha*src2[3];
}
else {
// do combination based solely on z value
copy_v4_v4(out, src1);
}
if (node->custom2)
*z1= *z2;
}
}
static void do_zcombine_mask(bNode *node, float *out, float *z1, float *z2)
{
if (*z1 > *z2) {
*out= 1.0f;
if (node->custom2)
*z1= *z2;
}
}
static void do_zcombine_add(bNode *node, float *out, float *col1, float *col2, float *acol)
{
float alpha;
float malpha;
if (node->custom1) {
// use alpha in combine operation, antialiased mask in used here just as hint for the z value
if (*acol>0.0f) {
alpha= col2[3];
malpha= 1.0f - alpha;
out[0] = malpha*col1[0] + alpha*col2[0];
out[1] = malpha*col1[1] + alpha*col2[1];
out[2] = malpha*col1[2] + alpha*col2[2];
out[3] = malpha*col1[3] + alpha*col2[3];
}
else {
alpha= col1[3];
malpha= 1.0f - alpha;
out[0] = malpha*col2[0] + alpha*col1[0];
out[1] = malpha*col2[1] + alpha*col1[1];
out[2] = malpha*col2[2] + alpha*col1[2];
out[3] = malpha*col2[3] + alpha*col1[3];
}
}
else {
// do combination based solely on z value but with antialiased mask
alpha = *acol;
malpha= 1.0f - alpha;
out[0] = malpha*col1[0] + alpha*col2[0];
out[1] = malpha*col1[1] + alpha*col2[1];
out[2] = malpha*col1[2] + alpha*col2[2];
out[3] = malpha*col1[3] + alpha*col2[3];
}
}
static void node_composit_exec_zcombine(void *data, bNode *node, bNodeStack **in, bNodeStack **out)
{
RenderData *rd= data;
CompBuf *cbuf= in[0]->data;
CompBuf *zbuf;
/* stack order in: col z col z */
/* stack order out: col z */
if (out[0]->hasoutput==0 && out[1]->hasoutput==0)
return;
/* no input image; do nothing now */
if (in[0]->data==NULL) {
return;
}
if (out[1]->hasoutput) {
/* copy or make a buffer for for the first z value, here we write result in */
if (in[1]->data)
zbuf= dupalloc_compbuf(in[1]->data);
else {
float *zval;
int tot= cbuf->x*cbuf->y;
zbuf= alloc_compbuf(cbuf->x, cbuf->y, CB_VAL, 1);
for (zval= zbuf->rect; tot; tot--, zval++)
*zval= in[1]->vec[0];
}
/* lazy coder hack */
node->custom2= 1;
out[1]->data= zbuf;
}
else {
node->custom2= 0;
zbuf= in[1]->data;
}
if (rd->scemode & R_FULL_SAMPLE) {
/* make output size of first input image */
CompBuf *stackbuf= alloc_compbuf(cbuf->x, cbuf->y, CB_RGBA, 1); // allocs
composit4_pixel_processor(node, stackbuf, in[0]->data, in[0]->vec, zbuf, in[1]->vec, in[2]->data, in[2]->vec,
in[3]->data, in[3]->vec, do_zcombine, CB_RGBA, CB_VAL, CB_RGBA, CB_VAL);
out[0]->data= stackbuf;
}
else {
/* make output size of first input image */
CompBuf *stackbuf= alloc_compbuf(cbuf->x, cbuf->y, CB_RGBA, 1); /* allocs */
CompBuf *mbuf;
float *fp;
int x;
char *aabuf;
/* make a mask based on comparison, optionally write zvalue */
mbuf= alloc_compbuf(cbuf->x, cbuf->y, CB_VAL, 1);
composit2_pixel_processor(node, mbuf, zbuf, in[1]->vec, in[3]->data, in[3]->vec, do_zcombine_mask, CB_VAL, CB_VAL);
/* convert to char */
aabuf= MEM_mallocN(cbuf->x*cbuf->y, "aa buf");
fp= mbuf->rect;
for (x= cbuf->x*cbuf->y-1; x>=0; x--)
if (fp[x]==0.0f) aabuf[x] = 0;
else aabuf[x] = 255;
antialias_tagbuf(cbuf->x, cbuf->y, aabuf);
/* convert to float */
fp= mbuf->rect;
for (x= cbuf->x*cbuf->y-1; x>=0; x--)
if (aabuf[x]>1)
fp[x] = (1.0f/255.0f)*(float)aabuf[x];
composit3_pixel_processor(node, stackbuf, in[0]->data, in[0]->vec, in[2]->data, in[2]->vec, mbuf, NULL,
do_zcombine_add, CB_RGBA, CB_RGBA, CB_VAL);
/* free */
free_compbuf(mbuf);
MEM_freeN(aabuf);
out[0]->data= stackbuf;
}
}
#endif /* WITH_COMPOSITOR_LEGACY */
void register_node_type_cmp_zcombine(bNodeTreeType *ttype)
{
static bNodeType ntype;
@@ -232,9 +55,6 @@ void register_node_type_cmp_zcombine(bNodeTreeType *ttype)
node_type_base(ttype, &ntype, CMP_NODE_ZCOMBINE, "Z Combine", NODE_CLASS_OP_COLOR, NODE_OPTIONS);
node_type_socket_templates(&ntype, cmp_node_zcombine_in, cmp_node_zcombine_out);
node_type_size(&ntype, 80, 40, 120);
#ifdef WITH_COMPOSITOR_LEGACY
node_type_exec(&ntype, node_composit_exec_zcombine);
#endif
nodeRegisterType(ttype, &ntype);
}