[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [21452] branches/soc-2009-yukishiro/source /blender: light image node preview
Jingyuan Huang
jingyuan.huang at gmail.com
Thu Jul 9 06:37:48 CEST 2009
Revision: 21452
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=21452
Author: yukishiro
Date: 2009-07-09 06:37:48 +0200 (Thu, 09 Jul 2009)
Log Message:
-----------
light image node preview
Modified Paths:
--------------
branches/soc-2009-yukishiro/source/blender/blenkernel/intern/icons.c
branches/soc-2009-yukishiro/source/blender/blenkernel/intern/lightenv.c
branches/soc-2009-yukishiro/source/blender/editors/space_node/drawnode.c
branches/soc-2009-yukishiro/source/blender/nodes/intern/LGT_nodes/LGT_image.c
branches/soc-2009-yukishiro/source/blender/nodes/intern/LGT_util.h
Modified: branches/soc-2009-yukishiro/source/blender/blenkernel/intern/icons.c
===================================================================
--- branches/soc-2009-yukishiro/source/blender/blenkernel/intern/icons.c 2009-07-09 03:25:31 UTC (rev 21451)
+++ branches/soc-2009-yukishiro/source/blender/blenkernel/intern/icons.c 2009-07-09 04:37:48 UTC (rev 21452)
@@ -142,6 +142,7 @@
(*prv)->rect[i] = NULL;
}
}
+ if ((*prv)->rectf) MEM_freeN((*prv)->rectf);
MEM_freeN((*prv));
*prv = NULL;
}
Modified: branches/soc-2009-yukishiro/source/blender/blenkernel/intern/lightenv.c
===================================================================
--- branches/soc-2009-yukishiro/source/blender/blenkernel/intern/lightenv.c 2009-07-09 03:25:31 UTC (rev 21451)
+++ branches/soc-2009-yukishiro/source/blender/blenkernel/intern/lightenv.c 2009-07-09 04:37:48 UTC (rev 21452)
@@ -108,7 +108,14 @@
void free_lightenv(LightEnv *env)
{
+ if (env->nodetree) {
+ ntreeFreeTree(env->nodetree);
+ MEM_freeN(env->nodetree);
+ }
+ if (env->preview) {
+ BKE_previewimg_free(&env->preview);
+ }
}
Modified: branches/soc-2009-yukishiro/source/blender/editors/space_node/drawnode.c
===================================================================
--- branches/soc-2009-yukishiro/source/blender/editors/space_node/drawnode.c 2009-07-09 03:25:31 UTC (rev 21451)
+++ branches/soc-2009-yukishiro/source/blender/editors/space_node/drawnode.c 2009-07-09 04:37:48 UTC (rev 21452)
@@ -2400,7 +2400,7 @@
nodeSetActive(ntree, node);
}
-static int node_buts_lightenv(uiBlock *block, bNodeTree *ntree, bNode *node, rctf *butr)
+static int node_light_buts_lightenv(uiBlock *block, bNodeTree *ntree, bNode *node, rctf *butr)
{
if(block) {
uiBut *bt;
@@ -2435,13 +2435,52 @@
return 30; // XXX
}
+static int node_light_buts_image(uiBlock *block, bNodeTree *ntree, bNode *node, rctf *butr)
+{
+ char *strp;
+ uiBut *bt;
+
+ if (block) {
+ uiBlockBeginAlign(block);
+
+ /* browse button */
+ IMAnames_to_pupstring(&strp, NULL, "LOAD NEW %x32767", &(G.main->image), NULL, NULL);
+ node->menunr= 0;
+ bt= uiDefButS(block, MENU, B_NOP, strp,
+ butr->xmin, butr->ymin, 19, 19,
+ &node->menunr, 0, 0, 0, 0, "Browses existing choices");
+ uiButSetFunc(bt, node_browse_image_cb, ntree, node);
+ if(strp) MEM_freeN(strp);
+
+ /* Add New button */
+ if(node->id==NULL) {
+ bt= uiDefBut(block, BUT, B_NODE_LOADIMAGE, "Load New",
+ butr->xmin+19, butr->ymin, (short)(butr->xmax-butr->xmin-19.0f), 19,
+ NULL, 0.0, 0.0, 0, 0, "Add new Image");
+ uiButSetFunc(bt, node_active_cb, ntree, node);
+ }
+ else {
+ /* name button */
+ short xmin= (short)butr->xmin, xmax= (short)butr->xmax;
+ short width= xmax - xmin - 19;
+
+ bt= uiDefBut(block, TEX, B_NOP, "IM:",
+ xmin+19, butr->ymin, width, 19,
+ node->id->name+2, 0.0, 19.0, 0, 0, "Image name");
+ uiButSetFunc(bt, node_ID_title_cb, node, NULL);
+ }
+ }
+ return 20;
+}
+
static void node_light_set_butfunc(bNodeType *ntype)
{
switch(ntype->type) {
case LGT_NODE_LIGHTENV:
- ntype->butfunc= node_buts_lightenv;
+ ntype->butfunc= node_light_buts_lightenv;
break;
case LGT_NODE_IMAGE:
+ ntype->butfunc= node_light_buts_image;
break;
case LGT_NODE_OUTPUT_FILE:
break;
Modified: branches/soc-2009-yukishiro/source/blender/nodes/intern/LGT_nodes/LGT_image.c
===================================================================
--- branches/soc-2009-yukishiro/source/blender/nodes/intern/LGT_nodes/LGT_image.c 2009-07-09 03:25:31 UTC (rev 21451)
+++ branches/soc-2009-yukishiro/source/blender/nodes/intern/LGT_nodes/LGT_image.c 2009-07-09 04:37:48 UTC (rev 21452)
@@ -36,9 +36,40 @@
static void exec(void *data, bNode *node, bNodeStack **in, bNodeStack **out)
{
- //tex_output(node, in, out[0], &colorfn);
- //
- //tex_do_preview(node, out[0], data);
+ Image *ima= (Image *)node->id;
+ ImageUser *iuser= (ImageUser *)node->storage;
+
+ if(!(node->typeinfo->flag & NODE_PREVIEW))
+ return;
+
+ if( ima ) {
+ ImBuf *ibuf = BKE_image_get_ibuf(ima, iuser);
+ if (ibuf) {
+ int i, j, px, py;
+ float x, y, *input, *result;
+ bNodePreview *preview;
+
+ if( (!ibuf->x) || (!ibuf->y) ) return;
+ if( !ibuf->rect_float ) IMB_float_from_rect(ibuf);
+
+ init_preview(node);
+ preview = node->preview;
+
+ for(i=0; i<preview->xsize; i++) {
+ for(j=0; j<preview->ysize; j++) {
+
+ x = ((float) i / preview->xsize);
+ y = ((float) j / preview->ysize);
+ px = (int)(x * ibuf->x);
+ py = (int)(y * ibuf->y);
+
+ input = ibuf->rect_float + 4 * (ibuf->x * py + px);
+ result = preview->rect + 4 * (preview->xsize*j + i);
+ QUATCOPY(result, input);
+ }
+ }
+ }
+ }
}
static void init(bNode* node)
Modified: branches/soc-2009-yukishiro/source/blender/nodes/intern/LGT_util.h
===================================================================
--- branches/soc-2009-yukishiro/source/blender/nodes/intern/LGT_util.h 2009-07-09 03:25:31 UTC (rev 21451)
+++ branches/soc-2009-yukishiro/source/blender/nodes/intern/LGT_util.h 2009-07-09 04:37:48 UTC (rev 21452)
@@ -36,11 +36,17 @@
#include "MEM_guardedalloc.h"
+#include "BKE_image.h"
+#include "BKE_utildefines.h"
+
#include "DNA_ID.h"
#include "DNA_node_types.h"
#include "DNA_image_types.h"
#include "DNA_lightenv_types.h"
+#include "IMB_imbuf_types.h"
+#include "IMB_imbuf.h"
+
#include "../LGT_node.h"
#include "node_util.h"
More information about the Bf-blender-cvs
mailing list