[Bf-committers] Patch Levels/histogram composit node submited
David Millán Escrivá
david at artresnet.com
Mon Mar 13 09:20:10 CET 2006
Hi:
I post a levels/histogram compositor node. Could test the patch.
Thanks. Damiles.
-------------- next part --------------
? blender.lnk
? source/creator/winbuildinfo.h
? tools/Blender.pyc
? tools/__init__.pyc
? tools/bcolors.pyc
? tools/btools.pyc
Index: source/blender/blenkernel/BKE_node.h
===================================================================
RCS file: /cvsroot/bf-blender/blender/source/blender/blenkernel/BKE_node.h,v
retrieving revision 1.12
diff -u -r1.12 BKE_node.h
--- source/blender/blenkernel/BKE_node.h 20 Feb 2006 18:33:55 -0000 1.12
+++ source/blender/blenkernel/BKE_node.h 5 Mar 2006 11:39:53 -0000
@@ -223,7 +223,7 @@
#define CMP_NODE_TEXTURE 224
#define CMP_NODE_TRANSLATE 225
#define CMP_NODE_ZCOMBINE 226
-
+#define CMP_NODE_HISTOGRAM 227
/* filter types */
#define CMP_FILT_SOFT 0
Index: source/blender/blenkernel/intern/node.c
===================================================================
RCS file: /cvsroot/bf-blender/blender/source/blender/blenkernel/intern/node.c,v
retrieving revision 1.26
diff -u -r1.26 node.c
--- source/blender/blenkernel/intern/node.c 25 Feb 2006 11:56:08 -0000 1.26
+++ source/blender/blenkernel/intern/node.c 5 Mar 2006 11:41:26 -0000
@@ -789,8 +789,22 @@
node->storage= nbd;
nbd->samples= 32;
nbd->fac= 1.0f;
- }
- else if(type==CMP_NODE_HUE_SAT) {
+ }else if(CMP_NODE_HISTOGRAM){
+ NodeHistogramData *nhd= MEM_callocN(sizeof(NodeHistogramData), "node histogram data");
+ node->storage=nhd;
+ nhd->limitmax=255;
+ nhd->limitmaxR=255;
+ nhd->limitmaxG=255;
+ nhd->limitmaxB=255;
+ nhd->limitmin=0;
+ nhd->limitminR=0;
+ nhd->limitminG=0;
+ nhd->limitminB=0;
+ nhd->center=126;
+ nhd->centerR=126;
+ nhd->centerG=126;
+ nhd->centerB=126;
+ }else if(type==CMP_NODE_HUE_SAT) {
NodeHueSat *nhs= MEM_callocN(sizeof(NodeHueSat), "node hue sat");
node->storage= nhs;
nhs->hue= 0.5f;
Index: source/blender/blenkernel/intern/node_composite.c
===================================================================
RCS file: /cvsroot/bf-blender/blender/source/blender/blenkernel/intern/node_composite.c,v
retrieving revision 1.35
diff -u -r1.35 node_composite.c
--- source/blender/blenkernel/intern/node_composite.c 28 Feb 2006 16:24:25 -0000 1.35
+++ source/blender/blenkernel/intern/node_composite.c 6 Mar 2006 12:30:03 -0000
@@ -2837,6 +2837,175 @@
};
+/* **************** histogram ******************** */
+static bNodeSocketType cmp_node_histogram_in[]= {
+ { SOCK_RGBA, 1, "Image", 0.8f, 0.8f, 0.8f, 1.0f, 0.0f, 1.0f},
+ { -1, 0, "" }
+};
+static bNodeSocketType cmp_node_histogram_out[]= {
+ { SOCK_RGBA, 0, "Image", 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f},
+ { -1, 0, "" }
+};
+
+static float distributionHistogram(int min, int center, int max, float val1){
+ float val, val2, val3, desp;
+
+ val2=(float)(max-min);
+ val3=((float)min)/255;
+ desp=((float)center/255)-0.5;
+ val=((val1-val3)/(val2/255))+desp;
+ return(val);
+}
+
+static void node_composit_exec_histogram(void *data, bNode *node, bNodeStack **in, bNodeStack **out)
+{
+ CompBuf *new, *img= in[0]->data;
+ NodeHistogramData *nhd= node->storage;
+ int outx, outy,x,y;
+ int out_pix, out_stride,src_pix,src_stride,posH;
+ float *outfp, *srcfp, *out_data, *src_data,val,val1,val2,val3,valR,valG,valB,Y,U,V,desp;
+
+ if(img==NULL || out[0]->hasoutput==0)
+ return;
+
+ //Clear and Init histogram data
+ src_pix= img->type;
+ src_stride=img->x;
+ src_data= img->rect;
+ nhd->total=0;
+ nhd->max=0;
+ nhd->totalR=0;
+ nhd->maxR=0;
+ nhd->totalG=0;
+ nhd->maxG=0;
+ nhd->totalB=0;
+ nhd->maxB=0;
+
+ for(y=0;y<256;y++){
+ nhd->data[y]=0;
+ nhd->dataR[y]=0;
+ nhd->dataG[y]=0;
+ nhd->dataB[y]=0;
+ }
+ //Make histogram
+ for(y=0;y<img->y;y++){
+ srcfp= src_data + src_pix*y*src_stride;
+ for(x=0;x<img->x;x++){
+ val=((0.299*srcfp[0]+0.587*srcfp[1]+0.114*srcfp[2]));
+ posH=(int)(val*255);
+ if(posH>255)
+ posH=255;
+
+ if(srcfp[3]!=0){
+ nhd->data[posH]++;
+ nhd->total++;
+ }
+ //Red
+ val=srcfp[0];
+ posH=(int)(val*255);
+ if(posH>255)
+ posH=255;
+
+ if(srcfp[3]!=0){
+ nhd->dataR[posH]++;
+ nhd->totalR++;
+ }
+ //Green
+ val=srcfp[1];
+ posH=(int)(val*255);
+ if(posH>255)
+ posH=255;
+
+ if(srcfp[3]!=0){
+ nhd->dataG[posH]++;
+ nhd->totalG++;
+ }
+ //Blue
+ val=srcfp[2];
+ posH=(int)(val*255);
+ if(posH>255)
+ posH=255;
+
+ if(srcfp[3]!=0){
+ nhd->dataB[posH]++;
+ nhd->totalB++;
+ }
+
+ srcfp += src_pix;
+
+ }
+ }
+
+ for(y=0;y<256;y++){
+ nhd->data[y]=nhd->data[y]/nhd->total;
+ if(nhd->data[y]>nhd->max)
+ nhd->max=nhd->data[y];
+ nhd->dataR[y]=nhd->dataR[y]/nhd->totalR;
+ if(nhd->dataR[y]>nhd->maxR)
+ nhd->maxR=nhd->dataR[y];
+ nhd->dataG[y]=nhd->dataG[y]/nhd->totalG;
+ if(nhd->dataG[y]>nhd->maxG)
+ nhd->maxG=nhd->dataG[y];
+ nhd->dataB[y]=nhd->dataB[y]/nhd->totalB;
+ if(nhd->dataB[y]>nhd->maxB)
+ nhd->maxB=nhd->dataB[y];
+ }
+ //end estadistics
+
+
+
+ new= alloc_compbuf(img->x, img->y, CB_RGBA, 1); // allocs
+ outx= new->x;
+ outy= new->y;
+ out_pix= new->type;
+ out_stride=new->x;
+ out_data= new->rect;
+ for(y=0;y<outy;y++){
+ srcfp= src_data + src_pix*y*src_stride;
+ outfp= out_data + out_pix*y*out_stride;
+ for(x=0;x<outx;x++){
+ //First correct intensity
+ val1=((0.299*srcfp[0]+0.587*srcfp[1]+0.114*srcfp[2]));
+ Y=val1;
+ U=-0.147*srcfp[0]- 0.289*srcfp[1]+ 0.436*srcfp[2];
+ V=0.615*srcfp[0] - 0.515*srcfp[1] - 0.100*srcfp[2];
+ val2=(float)(nhd->limitmax-nhd->limitmin);
+ val3=((float)nhd->limitmin)/255;
+ desp=((float)nhd->center/255)-0.5;
+ val=((val1-val3)/(val2/255))+desp;
+
+ valR=val+1.140*V;
+ valG=val-0.395*U-0.581*V;
+ valB=val+2.032*U;
+ //Correct Red Green and Blue
+ outfp[0]=distributionHistogram(nhd->limitminR,nhd->centerR,nhd->limitmaxR,valR);
+ outfp[1]=distributionHistogram(nhd->limitminG,nhd->centerG,nhd->limitmaxG,valG);
+ outfp[2]=distributionHistogram(nhd->limitminB,nhd->centerB,nhd->limitmaxB,valB);
+
+ outfp[3]=srcfp[3];
+
+ srcfp += src_pix;
+ outfp += out_pix;
+ }
+ }
+
+ out[0]->data= new;
+}
+
+/* custom1: itterations, custom2: maxspeed (0 = nolimit) */
+static bNodeType cmp_node_histogram= {
+ /* type code */ CMP_NODE_HISTOGRAM,
+ /* name */ "Histogram",
+ /* width+range */ 150, 100, 200,
+ /* class+opts */ NODE_CLASS_OP_COLOR, NODE_OPTIONS,
+ /* input sock */ cmp_node_histogram_in,
+ /* output sock */ cmp_node_histogram_out,
+ /* storage */ "NodeHistogramData",
+ /* execfunc */ node_composit_exec_histogram
+
+};
+
+
/* ****************** types array for all shaders ****************** */
bNodeType *node_all_composit[]= {
@@ -2867,6 +3036,7 @@
&cmp_node_texture,
&cmp_node_translate,
&cmp_node_zcombine,
+ &cmp_node_histogram,
NULL
};
Index: source/blender/include/BIF_interface.h
===================================================================
RCS file: /cvsroot/bf-blender/blender/source/blender/include/BIF_interface.h,v
retrieving revision 1.39
diff -u -r1.39 BIF_interface.h
--- source/blender/include/BIF_interface.h 28 Jan 2006 18:33:13 -0000 1.39
+++ source/blender/include/BIF_interface.h 5 Mar 2006 11:45:47 -0000
@@ -163,6 +163,7 @@
#define BUT_COLORBAND (30<<9)
#define BUT_NORMAL (31<<9)
#define BUT_CURVE (32<<9)
+#define BUT_HISTOGRAM (33<<9)
#define BUTTYPE (63<<9)
Index: source/blender/makesdna/DNA_node_types.h
===================================================================
RCS file: /cvsroot/bf-blender/blender/source/blender/makesdna/DNA_node_types.h,v
retrieving revision 1.9
diff -u -r1.9 DNA_node_types.h
--- source/blender/makesdna/DNA_node_types.h 20 Feb 2006 13:43:40 -0000 1.9
+++ source/blender/makesdna/DNA_node_types.h 5 Mar 2006 11:58:39 -0000
@@ -197,5 +197,19 @@
float hue, sat;
} NodeHueSat;
+typedef struct NodeHistogramData {
+ int limitmax,limitmin,center;
+ int limitmaxR,limitminR,centerR;
+ int limitmaxG,limitminG,centerG;
+ int limitmaxB,limitminB,centerB;
+ float data[256];
+ float dataR[256];
+ float dataG[256];
+ float dataB[256];
+ int total,totalR,totalG,totalB;
+ float max,maxR,maxG,maxB;
+ int Y;
+}NodeHistogramData;
+
#endif
Index: source/blender/src/drawnode.c
===================================================================
RCS file: /cvsroot/bf-blender/blender/source/blender/src/drawnode.c,v
retrieving revision 1.20
diff -u -r1.20 drawnode.c
--- source/blender/src/drawnode.c 23 Feb 2006 15:39:01 -0000 1.20
+++ source/blender/src/drawnode.c 5 Mar 2006 11:48:39 -0000
@@ -974,6 +974,26 @@
return 38;
}
+static int node_composit_buts_histogram(uiBlock *block, bNodeTree *ntree, bNode *node, rctf *butr)
+{
+
+ if(block) {
+ NodeHistogramData *nhd= node->storage;
+ uiDefBut(block, BUT_HISTOGRAM, B_NODE_EXEC+node->nr, "",
+ butr->xmin, butr->ymin+24, butr->xmax-butr->xmin, butr->ymax-butr->ymin-24,
+ nhd, 0.0f, 1.0f, 0, 0, "");
+ uiDefButI(block, ROW, B_NODE_EXEC+node->nr, "Y",
+ butr->xmin, butr->ymin+6, 16, 16, &nhd->Y, 0.0, 0.0, 0.0, 0.0, "");
+ uiDefButI(block, ROW, B_NODE_EXEC+node->nr, "R",
+ butr->xmin+16, butr->ymin+6, 16, 16, &nhd->Y, 0.0, 1.0, 0.0, 0.0, "");
+ uiDefButI(block, ROW, B_NODE_EXEC+node->nr, "G",
+ butr->xmin+32, butr->ymin+6, 16, 16, &nhd->Y, 0.0, 2.0, 0.0, 0.0, "");
+ uiDefButI(block, ROW, B_NODE_EXEC+node->nr, "B",
+ butr->xmin+48, butr->ymin+6, 16, 16, &nhd->Y, 0.0, 3.0, 0.0, 0.0, "");
+
+ }
+ return 150;
+}
/* only once called */
static void node_composit_set_butfunc(bNodeType *ntype)
@@ -1032,6 +1052,9 @@
break;
case CMP_NODE_TEXTURE:
ntype->butfunc= node_buts_texture;
+ break;
+ case CMP_NODE_HISTOGRAM:
+ ntype->butfunc= node_composit_buts_histogram;
break;
default:
ntype->butfunc= NULL;
Index: source/blender/src/interface.c
===================================================================
RCS file: /cvsroot/bf-blender/blender/source/blender/src/interface.c,v
retrieving revision 1.225
diff -u -r1.225 interface.c
--- source/blender/src/interface.c 19 Feb 2006 14:55:16 -0000 1.225
+++ source/blender/src/interface.c 5 Mar 2006 11:50:56 -0000
@@ -72,6 +72,7 @@
#include "DNA_object_types.h"
#include "DNA_texture_types.h"
#include "DNA_vfont_types.h"
+#include "DNA_node_types.h"
#include "BKE_blender.h"
#include "BKE_colortools.h"
@@ -3555,6 +3556,71 @@
return retval;
}
+/* **************************************** */
+static int ui_do_but_HISTOGRAM(uiBut *but){
+
+ NodeHistogramData *nhd= (NodeHistogramData *)but->poin;
+ short mval[2], mvalo[2];
+ int w,aux,retval= but->retval;
+ int *lmin, *lmax,*lc;
+
+ if(nhd->Y==0){
+ lmin=&nhd->limitmin;
+ lmax=&nhd->limitmax;
+ lc=&nhd->center;
+ }else if(nhd->Y==1){
+ lmin=&nhd->limitminR;
+ lmax=&nhd->limitmaxR;
+ lc=&nhd->centerR;
+ }else if(nhd->Y==2){
+ lmin=&nhd->limitminG;
+ lmax=&nhd->limitmaxG;
+ lc=&nhd->centerG;
+ }else if(nhd->Y==3){
+ lmin=&nhd->limitminB;
+ lmax=&nhd->limitmaxB;
+ lc=&nhd->centerB;
+ }
+
+ uiGetMouse(mywinget(), mval);
+ while(get_mbut() & L_MOUSE) {
+ uiGetMouse(mywinget(), mvalo);
+ w=but->x2-but->x1;
+ if((mvalo[0]>but->x1)&&(mvalo[0]<but->x2)){
+ //limit min
+ aux=((*lmin*w)/255)+1+but->x1;
+ if((mvalo[0]>(aux-5))&&(mvalo[0]<(aux+5))){
+ if(*lmin<(&lc-5))
+ *lmin=((mvalo[0]-but->x1)/w)*255;
+ else
+ *lmin=*lc-6;
+ }
+ //limit center
+ aux=((*lc*w)/255)+1+but->x1;
+ if((mvalo[0]>(aux-5))&&(mvalo[0]<(aux+5))){
+ if((*lc<(*lmax-5))&&(*lc>(*lmin+5)))
+ *lc=((mvalo[0]-but->x1)/w)*255;
+
+ }
+ //limit max
+ aux=((*lmax*w)/255)+1+but->x1;
+ if((mvalo[0]>(aux-5))&&(mvalo[0]<(aux+5))){
+ if(*lmax>(*lc+5))
+ *lmax=((mvalo[0]-but->x1)/w)*255;
+ else
+ *lmax=*lc+6;
+ }
+ }
+
+ ui_draw_but(but);
+ ui_block_flush_back(but->block);
+ }
+
+ ui_draw_but(but);
+ ui_block_flush_back(but->block);
+ return retval;
+}
+
/* ************************************************ */
void uiSetButLock(int val, char *lockstr)
@@ -3757,6 +3823,9 @@
break;
case BUT_CURVE:
retval= ui_do_but_CURVE(but);
+ break;
+ case BUT_HISTOGRAM:
+ retval= ui_do_but_HISTOGRAM(but);
break;
#ifdef INTERNATIONAL
Index: source/blender/src/interface_draw.c
===================================================================
RCS file: /cvsroot/bf-blender/blender/source/blender/src/interface_draw.c,v
retrieving revision 1.53
diff -u -r1.53 interface_draw.c
--- source/blender/src/interface_draw.c 14 Feb 2006 11:28:13 -0000 1.53
+++ source/blender/src/interface_draw.c 5 Mar 2006 11:53:28 -0000
@@ -64,6 +64,7 @@
#include "DNA_userdef_types.h"
#include "DNA_vec_types.h"
#include "DNA_vfont_types.h"
+#include "DNA_node_types.h"
#include "BKE_blender.h"
#include "BKE_colortools.h"
@@ -2201,6 +2202,155 @@
}
+static void ui_draw_but_HISTOGRAM(uiBut *but)
+{
+ NodeHistogramData *nhd= (NodeHistogramData *)but->poin;
+ int i,desf,*lmin, *lmax,*lc;
+ float w,x1,yh,h;
+ float fx, fy, dx, dy, fac[2], zoomx, zoomy, offsx, offsy;
+ GLint scissor[4];
+ //printf("Damiles-> Llamada a dibujar el histograma\n");
+ /* need scissor test, curve can draw outside of boundary */
+ glGetIntegerv(GL_VIEWPORT, scissor);
+ fx= but->x1; fy= but->y1;
+ ui_graphics_to_window(but->win, &fx, &fy);
+ dx= but->x2; dy= but->y2;
+ ui_graphics_to_window(but->win, &dx, &dy);
+ glScissor((int)floor(fx), (int)floor(fy), (int)ceil(dx-fx), (int)ceil(dy-fy));
+
+ BIF_ThemeColorShade(TH_BUT_NEUTRAL, -20);
+ glRectf(but->x1, but->y1, but->x2, but->y2);
+
+ if(nhd->Y==0){
+ lmin=&nhd->limitmin;
+ lmax=&nhd->limitmax;
+ lc=&nhd->center;
+ }else if(nhd->Y==1){
+ lmin=&nhd->limitminR;
+ lmax=&nhd->limitmaxR;
+ lc=&nhd->centerR;
+ }else if(nhd->Y==2){
+ lmin=&nhd->limitminG;
+ lmax=&nhd->limitmaxG;
+ lc=&nhd->centerG;
+ }else if(nhd->Y==3){
+ lmin=&nhd->limitminB;
+ lmax=&nhd->limitmaxB;
+ lc=&nhd->centerB;
+ }
+
+ /*axes*/
+ if(nhd==NULL){
+ //printf("damiles-> Error en nhd al dibujar\n");
+ BIF_ThemeColor(TH_WIRE);
+ glBegin(GL_LINES);
+ glVertex2f(but->x1, but->y1 );
+ glVertex2f(but->x2, but->y2);
+ glEnd();
+ }else{
+ //printf("damiles-> nhd dibujando\n");
+
+ h=but->y2-but->y1;
+ w=but->x2-but->x1-1;
+
+ desf=6;
+
+ if(nhd->Y==0){
+ BIF_ThemeColor(TH_WIRE);
+ for(i=0;i<256;i++){
+ x1=((i*w)/255)+1;
+ yh=((h*nhd->data[i])/nhd->max);
+ glBegin(GL_LINES);
+ glVertex2f(x1+but->x1, but->y1+desf );
+ glVertex2f(x1+but->x1, yh+but->y1+desf);
+ glEnd();
+ }
+ }else if(nhd->Y==1){
+ glColor3ub(150, 0, 0);
+ for(i=0;i<256;i++){
+ x1=((i*w)/255)+1;
+ yh=((h*nhd->dataR[i])/nhd->maxR);
+ glBegin(GL_LINES);
+ glVertex2f(x1+but->x1, but->y1+desf );
+ glVertex2f(x1+but->x1, yh+but->y1+desf);
+ glEnd();
+ }
+ }else if(nhd->Y==2){
+ glColor3ub(0, 150, 0);
+ for(i=0;i<256;i++){
+ x1=((i*w)/255)+1;
+ yh=((h*nhd->dataG[i])/nhd->maxG);
+ glBegin(GL_LINES);
+ glVertex2f(x1+but->x1, but->y1+desf );
+ glVertex2f(x1+but->x1, yh+but->y1+desf);
+ glEnd();
+ }
+ }else if(nhd->Y==3){
+ glColor3ub(0, 0, 150);
+ for(i=0;i<256;i++){
+ x1=((i*w)/255)+1;
+ yh=((h*nhd->dataB[i])/nhd->maxB);
+ glBegin(GL_LINES);
+ glVertex2f(x1+but->x1, but->y1+desf );
+ glVertex2f(x1+but->x1, yh+but->y1+desf);
+ glEnd();
+ }
+ }
+
+
+
+ //printf("damiles-> fin nhd dibujando ancho=%f alto=%f\n",w,h);
+ }
+
+
+ //limit 1
+ x1=((*lmin*w)/255)+1;
+ BIF_ThemeColor(TH_BUT_OUTLINE);
+ glBegin(GL_LINES);
+ glVertex2f(x1+but->x1, but->y1+desf);
+ glVertex2f(x1+but->x1, h+but->y1+desf);
+ glEnd();
+ BIF_ThemeColor(TH_WIRE);
+ glBegin(GL_POLYGON);
+ glVertex2f(x1+but->x1-5, but->y1-6+desf);
+ glVertex2f(x1+but->x1, but->y1-1+desf);
+ glVertex2f(x1+but->x1+5, but->y1-6+desf);
+ glEnd();
+
+ //center
+ BIF_ThemeColor(TH_BUT_OUTLINE);
+ x1=((*lc*w)/255)+1;
+ glBegin(GL_LINES);
+ glVertex2f(x1+but->x1, but->y1 );
+ glVertex2f(x1+but->x1, h+but->y1);
+ glEnd();
+ BIF_ThemeColor(TH_WIRE);
+ glBegin(GL_POLYGON);
+ glVertex2f(x1+but->x1-5, but->y1-6+desf );
+ glVertex2f(x1+but->x1, but->y1-1+desf);
+ glVertex2f(x1+but->x1+5, but->y1-6+desf);
+ glEnd();
+ //limit max
+ BIF_ThemeColor(TH_BUT_OUTLINE);
+ x1=((*lmax*w)/255)+1;
+ glBegin(GL_LINES);
+ glVertex2f(x1+but->x1, but->y1 );
+ glVertex2f(x1+but->x1, h+but->y1);
+ glEnd();
+ BIF_ThemeColor(TH_WIRE);
+ glBegin(GL_POLYGON);
+ glVertex2f(x1+but->x1-5, but->y1-6 +desf);
+ glVertex2f(x1+but->x1, but->y1-1+desf);
+ glVertex2f(x1+but->x1+5, but->y1-6+desf);
+ glEnd();
+
+ /* restore scissortest */
+ glScissor(scissor[0], scissor[1], scissor[2], scissor[3]);
+ /* outline */
+ BIF_ThemeColor(TH_BUT_OUTLINE);
+ fdrawbox(but->x1, but->y1, but->x2, but->y2);
+}
+
static void ui_draw_roundbox(uiBut *but)
{
glEnable(GL_BLEND);
@@ -2326,7 +2476,9 @@
case BUT_CURVE:
ui_draw_but_CURVE(but);
break;
-
+ case BUT_HISTOGRAM:
+ ui_draw_but_HISTOGRAM(but);
+ break;
default:
but->embossfunc(but->type, but->themecol, but->aspect, but->x1, but->y1, but->x2, but->y2, but->flag);
ui_draw_text_icon(but);
More information about the Bf-committers
mailing list