Page MenuHome

image_scopes4.diff

File Metadata

Author
Xavier Thomas (xat)
Created
Nov 13 2013, 2:34 PM

image_scopes4.diff

Index: release/scripts/ui/space_image.py
===================================================================
--- release/scripts/ui/space_image.py (révision 27845)
+++ release/scripts/ui/space_image.py (copie de travail)
@@ -406,6 +406,41 @@
layout.template_histogram(sima, "histogram")
+class IMAGE_PT_view_waveform(bpy.types.Panel):
+ bl_space_type = 'IMAGE_EDITOR'
+ bl_region_type = 'PREVIEW'
+ bl_label = "Waveform"
+
+ def poll(self, context):
+ sima = context.space_data
+ return (sima and sima.image)
+
+ def draw(self, context):
+ layout = self.layout
+
+ sima = context.space_data
+ row = layout.row(align=True)
+ row.prop(sima.waveform, "alpha")
+ row.prop(sima.waveform, "mode", text="")
+ layout.template_waveform(sima, "scope_sample_buffer", sima, "waveform")
+
+
+class IMAGE_PT_view_vectorscope(bpy.types.Panel):
+ bl_space_type = 'IMAGE_EDITOR'
+ bl_region_type = 'PREVIEW'
+ bl_label = "Vectorscope"
+
+ def poll(self, context):
+ sima = context.space_data
+ return (sima and sima.image)
+
+ def draw(self, context):
+ layout = self.layout
+
+ sima = context.space_data
+ layout.prop(sima.vectorscope, "alpha")
+ layout.template_vectorscope(sima, "scope_sample_buffer", sima, "vectorscope")
+
class IMAGE_PT_sample_line(bpy.types.Panel):
bl_space_type = 'IMAGE_EDITOR'
bl_region_type = 'PREVIEW'
@@ -421,6 +456,25 @@
sima = context.space_data
layout.template_histogram(sima, "sample_histogram")
+class IMAGE_PT_scope_sample(bpy.types.Panel):
+ bl_space_type = 'IMAGE_EDITOR'
+ bl_region_type = 'PREVIEW'
+ bl_label = "Scope Samples"
+
+ def poll(self, context):
+ sima = context.space_data
+ return sima
+
+ def draw(self, context):
+ layout = self.layout
+ sima = context.space_data
+ sbuf = sima.scope_sample_buffer
+ layout.prop(sbuf, "use_full_resolution")
+ col = layout.column(align=True)
+ col.active = not sbuf.use_full_resolution
+ col.prop(sbuf, "sizex")
+ col.prop(sbuf, "sizey")
+
class IMAGE_PT_view_properties(bpy.types.Panel):
bl_space_type = 'IMAGE_EDITOR'
bl_region_type = 'UI'
@@ -607,7 +661,10 @@
IMAGE_PT_game_properties,
IMAGE_PT_view_properties,
IMAGE_PT_view_histogram,
- IMAGE_PT_sample_line]
+ IMAGE_PT_view_waveform,
+ IMAGE_PT_view_vectorscope,
+ IMAGE_PT_sample_line,
+ IMAGE_PT_scope_sample]
def register():
Index: source/blender/blenkernel/intern/colortools.c
===================================================================
--- source/blender/blenkernel/intern/colortools.c (révision 27845)
+++ source/blender/blenkernel/intern/colortools.c (copie de travail)
@@ -971,3 +971,57 @@
hist->ok=1;
}
+
+void samplebuf_update(SampleBuf *sb, ImBuf *ibuf)
+{
+ int x, y, sizex, sizey;
+ float xfac, yfac;
+ unsigned char *dest, *rc;
+ float *rf;
+
+ if (sb->ok == 1 ) return;
+
+ if (sb->x > ibuf->x) sb->x=ibuf->x;
+ if (sb->y > ibuf->y) sb->y=ibuf->y;
+ sizex= sb->x;
+ sizey= sb->y;
+ if (sb->fullres) {
+ sizex = ibuf->x;
+ sizey = ibuf->y;
+ }
+
+ xfac= (float)ibuf->x/sizex;
+ yfac= (float)ibuf->y/sizey;
+
+ if( sb->ibuf) IMB_freeImBuf(sb->ibuf);
+ sb->ibuf = IMB_allocImBuf(sizex, sizey, 32, IB_rect, 0 );
+
+ dest= (unsigned char *) sb->ibuf->rect;
+
+ if(ibuf->rect_float) {
+
+ for(y=0; y<sb->ibuf->y; y++) {
+ for (x=0; x<sb->ibuf->x; x++) {
+ rf= ibuf->rect_float + ibuf->channels *((int)(y*yfac)*ibuf->x + (int)(x*xfac));
+ dest[0] = rf[0]*255;
+ dest[1] = rf[1]*255;
+ dest[2] = rf[2]*255;
+ dest +=4;
+ }
+ }
+
+ } else if (ibuf->rect) {
+
+ for(y=0; y<sb->ibuf->y; y++) {
+ for (x=0; x<sb->ibuf->x; x++) {
+ rc= (unsigned char *)(ibuf->rect + (int)(y*yfac)*ibuf->x + (int)(x*xfac));
+ dest[0] = rc[0];
+ dest[1] = rc[1];
+ dest[2] = rc[2];
+ dest +=4;
+ }
+ }
+ }
+
+ sb->ok = 1;
+}
Index: source/blender/blenkernel/BKE_colortools.h
===================================================================
--- source/blender/blenkernel/BKE_colortools.h (révision 27845)
+++ source/blender/blenkernel/BKE_colortools.h (copie de travail)
@@ -32,6 +32,7 @@
struct CurveMapping;
struct CurveMap;
struct Histogram;
+struct SampleBuf;
struct ImBuf;
struct rctf;
@@ -75,6 +76,7 @@
void colorcorrection_do_ibuf(struct ImBuf *ibuf, const char *profile);
void histogram_update(struct Histogram *hist, struct ImBuf *ibuf);
+void samplebuf_update(struct SampleBuf *wfrm, struct ImBuf *ibuf);
#endif
Index: source/blender/makesdna/DNA_space_types.h
===================================================================
--- source/blender/makesdna/DNA_space_types.h (révision 27845)
+++ source/blender/makesdna/DNA_space_types.h (copie de travail)
@@ -45,6 +45,9 @@
struct ImBuf;
struct Image;
struct Histogram;
+struct SampleBuf;
+struct Waveform;
+struct Vectorscope;
struct SpaceIpo;
struct BlendHandle;
struct RenderInfo;
@@ -260,7 +263,11 @@
struct bGPdata *gpd; /* grease pencil data */
struct Histogram hist; /* viewer histogram */
+ struct SampleBuf scopebuf; /* under sampled buffer for scopes */
+ struct Waveform wavefrm;
+ struct Vectorscope vecscope;
struct Histogram sample_line_hist; /* sample line histogram */
+
} SpaceImage;
typedef struct SpaceNla {
Index: source/blender/makesdna/DNA_color_types.h
===================================================================
--- source/blender/makesdna/DNA_color_types.h (révision 27845)
+++ source/blender/makesdna/DNA_color_types.h (copie de travail)
@@ -101,5 +101,30 @@
int flag;
} Histogram;
+struct ImBuf;
+
+typedef struct SampleBuf {
+ int ok,fullres;
+ int x;
+ int y;
+ struct ImBuf *ibuf;
+} SampleBuf;
+
+typedef struct Waveform {
+ int mode;
+ float alpha;
+} Waveform;
+
+/* waveform->mode */
+#define WAVEFRM_LUM 0
+#define WAVEFRM_RGB 1
+#define WAVEFRM_YCC 2
+
+typedef struct Vectorscope {
+ int mode;
+ float alpha;
+} Vectorscope;
+
+
#endif
Index: source/blender/makesrna/intern/rna_ui_api.c
===================================================================
--- source/blender/makesrna/intern/rna_ui_api.c (révision 27845)
+++ source/blender/makesrna/intern/rna_ui_api.c (copie de travail)
@@ -335,6 +335,20 @@
api_ui_item_rna_common(func);
RNA_def_boolean(func, "expand", 0, "", "Expand button to show more detail.");
+ func= RNA_def_function(srna, "template_waveform", "uiTemplateWaveform");
+ api_ui_item_rna_common(func);
+ parm= RNA_def_pointer(func, "waveform_data", "AnyType", "", "Data from which to take property.");
+ RNA_def_property_flag(parm, PROP_RNAPTR);
+ parm= RNA_def_string(func, "waveform_property", "", 0, "", "Identifier of property in data.");
+ RNA_def_boolean(func, "expand", 0, "", "Expand button to show more detail.");
+
+ func= RNA_def_function(srna, "template_vectorscope", "uiTemplateVectorscope");
+ api_ui_item_rna_common(func);
+ parm= RNA_def_pointer(func, "vectorscope_data", "AnyType", "", "Data from which to take property.");
+ RNA_def_property_flag(parm, PROP_RNAPTR);
+ parm= RNA_def_string(func, "vectorscope_property", "", 0, "", "Identifier of property in data.");
+ RNA_def_boolean(func, "expand", 0, "", "Expand button to show more detail.");
+
func= RNA_def_function(srna, "template_layers", "uiTemplateLayers");
api_ui_item_rna_common(func);
parm= RNA_def_pointer(func, "used_layers_data", "AnyType", "", "Data from which to take property.");
Index: source/blender/makesrna/intern/rna_color.c
===================================================================
--- source/blender/makesrna/intern/rna_color.c (révision 27845)
+++ source/blender/makesrna/intern/rna_color.c (copie de travail)
@@ -269,6 +269,11 @@
}
}
+static void rna_SampleBuffer_update(Main *bmain, Scene *scene, PointerRNA *ptr)
+{
+ SampleBuf *sb= (SampleBuf*)ptr->data;
+ sb->ok = 0;
+}
#else
@@ -449,6 +454,71 @@
}
+static void rna_def_samplebuf(BlenderRNA *brna)
+{
+ StructRNA *srna;
+ PropertyRNA *prop;
+
+ srna= RNA_def_struct(brna, "SampleBuffer", NULL);
+ RNA_def_struct_ui_text(srna, "Sample Buffer", "Samples of an image");
+
+ prop= RNA_def_property(srna, "use_full_resolution", PROP_BOOLEAN, PROP_NONE);
+ RNA_def_property_boolean_sdna(prop, "SampleBuf", "fullres", 1);
+ RNA_def_property_ui_text(prop, "Full Resolution", "Sample every pixel of the image");
+ RNA_def_property_update(prop, 0, "rna_SampleBuffer_update");
+
+ prop= RNA_def_property(srna, "sizex", PROP_INT, PROP_NONE);
+ RNA_def_property_int_sdna(prop, "SampleBuf", "x");
+ RNA_def_property_range(prop, 64, 1024);
+ RNA_def_property_ui_text(prop, "X Size", "Number of horizontal samples");
+ RNA_def_property_update(prop, 0, "rna_SampleBuffer_update");
+
+ prop= RNA_def_property(srna, "sizey", PROP_INT, PROP_NONE);
+ RNA_def_property_int_sdna(prop, "SampleBuf", "y");
+ RNA_def_property_range(prop, 16, 1024);
+ RNA_def_property_ui_text(prop, "Y Size", "Number of vertical samples");
+ RNA_def_property_update(prop, 0, "rna_SampleBuffer_update");
+}
+
+static void rna_def_waveform(BlenderRNA *brna)
+{
+ StructRNA *srna;
+ PropertyRNA *prop;
+
+ static EnumPropertyItem prop_mode_items[] = {
+ {WAVEFRM_LUM, "LUMINANCE", 0, "Luminance", ""},
+ {WAVEFRM_RGB, "RGB", 0, "Red Green Blue", ""},
+ {WAVEFRM_YCC, "YCBCR", 0, "YCbCr", ""},
+ {0, NULL, 0, NULL, NULL}};
+
+ srna= RNA_def_struct(brna, "Waveform", NULL);
+ RNA_def_struct_ui_text(srna, "Waveform", "Statistical view of the levels of color in an image");
+
+ prop= RNA_def_property(srna, "mode", PROP_ENUM, PROP_NONE);
+ RNA_def_property_enum_sdna(prop, NULL, "mode");
+ RNA_def_property_enum_items(prop, prop_mode_items);
+ RNA_def_property_ui_text(prop, "Mode", "");
+
+ prop= RNA_def_property(srna, "alpha", PROP_FLOAT, PROP_PERCENTAGE);
+ RNA_def_property_float_sdna(prop, NULL, "alpha");
+ RNA_def_property_range(prop, 0, 1);
+ RNA_def_property_ui_text(prop, "Opacity", "Opacity of the points");
+}
+
+static void rna_def_vectorscope(BlenderRNA *brna)
+{
+ StructRNA *srna;
+ PropertyRNA *prop;
+
+ srna= RNA_def_struct(brna, "Vectorscope", NULL);
+ RNA_def_struct_ui_text(srna, "Vectorscope", "Statistical view of the levels of color in an image");
+
+ prop= RNA_def_property(srna, "alpha", PROP_FLOAT, PROP_PERCENTAGE);
+ RNA_def_property_float_sdna(prop, NULL, "alpha");
+ RNA_def_property_range(prop, 0, 1);
+ RNA_def_property_ui_text(prop, "Opacity", "Opacity of the points");
+}
+
void RNA_def_color(BlenderRNA *brna)
{
rna_def_curvemappoint(brna);
@@ -457,6 +527,9 @@
rna_def_color_ramp_element(brna);
rna_def_color_ramp(brna);
rna_def_histogram(brna);
+ rna_def_samplebuf(brna);
+ rna_def_waveform(brna);
+ rna_def_vectorscope(brna);
}
#endif
Index: source/blender/makesrna/intern/rna_space.c
===================================================================
--- source/blender/makesrna/intern/rna_space.c (révision 27845)
+++ source/blender/makesrna/intern/rna_space.c (copie de travail)
@@ -442,6 +442,19 @@
ED_space_image_release_buffer(sima, lock);
}
+static void rna_SpaceImageEditor_scope_sample_buffer_update(Main *bmain, Scene *scene, PointerRNA *ptr)
+{
+ SpaceImage *sima= (SpaceImage*)ptr->data;
+ ImBuf *ibuf;
+ void *lock;
+
+ ibuf= ED_space_image_acquire_buffer(sima, &lock);
+ if(ibuf) {
+ samplebuf_update(&sima->scopebuf, ibuf);
+ WM_main_add_notifier(NC_IMAGE, sima->image);
+ }
+ ED_space_image_release_buffer(sima, lock);
+}
/* Space Text Editor */
@@ -1182,6 +1195,22 @@
RNA_def_property_ui_text(prop, "Histogram", "Histogram for viewing image statistics");
RNA_def_property_update(prop, NC_SPACE|ND_SPACE_IMAGE, "rna_SpaceImageEditor_histogram_update");
+ prop= RNA_def_property(srna, "scope_sample_buffer", PROP_POINTER, PROP_NONE);
+ RNA_def_property_pointer_sdna(prop, NULL, "scopebuf");
+ RNA_def_property_struct_type(prop, "SampleBuffer");
+ RNA_def_property_ui_text(prop, "Sample Buffer", "Buffer of sample of the image for scopes");
+ RNA_def_property_update(prop, NC_SPACE|ND_SPACE_IMAGE, "rna_SpaceImageEditor_scope_sample_buffer_update");
+
+ prop= RNA_def_property(srna, "waveform", PROP_POINTER, PROP_NONE);
+ RNA_def_property_pointer_sdna(prop, NULL, "wavefrm");
+ RNA_def_property_struct_type(prop, "Waveform");
+ RNA_def_property_ui_text(prop, "Waveform", "Waveform for viewing image statistics");
+
+ prop= RNA_def_property(srna, "vectorscope", PROP_POINTER, PROP_NONE);
+ RNA_def_property_pointer_sdna(prop, NULL, "vecscope");
+ RNA_def_property_struct_type(prop, "Vectorscope");
+ RNA_def_property_ui_text(prop, "Vectorscope", "Vectorscope for viewing image statistics");
+
prop= RNA_def_property(srna, "image_pin", PROP_BOOLEAN, PROP_NONE);
RNA_def_property_boolean_sdna(prop, NULL, "pin", 0);
RNA_def_property_ui_text(prop, "Image Pin", "Display current image regardless of object selection");
Index: source/blender/makesrna/RNA_access.h
===================================================================
--- source/blender/makesrna/RNA_access.h (révision 27845)
+++ source/blender/makesrna/RNA_access.h (copie de travail)
@@ -378,6 +378,7 @@
extern StructRNA RNA_RenderSettings;
extern StructRNA RNA_RGBANodeSocket;
extern StructRNA RNA_RigidBodyJointConstraint;
+extern StructRNA RNA_SampleBuffer;
extern StructRNA RNA_Scene;
extern StructRNA RNA_SceneGameData;
extern StructRNA RNA_SceneRenderLayer;
@@ -540,12 +541,14 @@
extern StructRNA RNA_ValueNodeSocket;
extern StructRNA RNA_VectorFont;
extern StructRNA RNA_VectorNodeSocket;
+extern StructRNA RNA_Vectorscope;
extern StructRNA RNA_VertexGroup;
extern StructRNA RNA_VertexGroupElement;
extern StructRNA RNA_VertexPaint;
extern StructRNA RNA_VoronoiTexture;
extern StructRNA RNA_VoxelData;
extern StructRNA RNA_VoxelDataTexture;
+extern StructRNA RNA_Waveform;
extern StructRNA RNA_WaveModifier;
extern StructRNA RNA_Window;
extern StructRNA RNA_WindowManager;
Index: source/blender/editors/include/UI_interface.h
===================================================================
--- source/blender/editors/include/UI_interface.h (révision 27845)
+++ source/blender/editors/include/UI_interface.h (copie de travail)
@@ -218,6 +218,8 @@
#define HOTKEYEVT (45<<9)
#define BUT_IMAGE (46<<9)
#define HISTOGRAM (47<<9)
+#define WAVEFORM (48<<9)
+#define VECTORSCOPE (49<<9)
#define BUTTYPE (63<<9)
@@ -676,6 +678,8 @@
void uiTemplatePreview(uiLayout *layout, struct ID *id, struct ID *parent, struct MTex *slot);
void uiTemplateColorRamp(uiLayout *layout, struct PointerRNA *ptr, char *propname, int expand);
void uiTemplateHistogram(uiLayout *layout, struct PointerRNA *ptr, char *propname, int expand);
+void uiTemplateWaveform(uiLayout *layout, struct PointerRNA *ptr, char *propname, struct PointerRNA *wfptr, char *vspropname, int expand);
+void uiTemplateVectorscope(uiLayout *layout, struct PointerRNA *ptr, char *propname, struct PointerRNA *vsptr, char *vspropname, int expand);
void uiTemplateCurveMapping(uiLayout *layout, struct PointerRNA *ptr, char *propname, int type, int levels, int brush);
void uiTemplateColorWheel(uiLayout *layout, struct PointerRNA *ptr, char *propname, int value_slider, int lock);
void uiTemplateTriColorSet(uiLayout *layout, struct PointerRNA *ptr, char *propname);
Index: source/blender/editors/space_image/space_image.c
===================================================================
--- source/blender/editors/space_image/space_image.c (révision 27845)
+++ source/blender/editors/space_image/space_image.c (copie de travail)
@@ -47,6 +47,7 @@
#include "BKE_screen.h"
#include "BKE_utildefines.h"
+#include "IMB_imbuf.h"
#include "IMB_imbuf_types.h"
#include "ED_mesh.h"
@@ -98,6 +99,7 @@
WM_event_add_notifier(C, NC_GEOM|ND_DATA, obedit->data);
ED_area_tag_redraw(CTX_wm_area(C));
+
}
}
@@ -304,6 +306,20 @@
sima->hist.ok=0;
}
+static void image_scope_samplebuf_tag_refresh(ScrArea *sa)
+{
+ SpaceImage *sima= (SpaceImage *)sa->spacedata.first;
+ ARegion *ar;
+
+ /* only while scopes are visible */
+ for (ar=sa->regionbase.first; ar; ar=ar->next) {
+ if (ar->regiontype == RGN_TYPE_PREVIEW && ar->flag & RGN_FLAG_HIDDEN)
+ return;
+ }
+
+ sima->scopebuf.ok=0;
+}
+
/* ******************** manage regions ********************* */
ARegion *image_has_buttons_region(ScrArea *sa)
@@ -358,6 +374,7 @@
arnew->flag = RGN_FLAG_HIDDEN;
image_histogram_tag_refresh(sa);
+ image_scope_samplebuf_tag_refresh(sa);
return arnew;
}
@@ -401,6 +418,11 @@
ar->alignment= RGN_ALIGN_RIGHT;
ar->flag = RGN_FLAG_HIDDEN;
+ simage->scopebuf.x=1024;
+ simage->scopebuf.y=16;
+ simage->wavefrm.alpha=1.0;
+ simage->vecscope.alpha=1.0;
+
/* main area */
ar= MEM_callocN(sizeof(ARegion), "main area for image");
@@ -419,7 +441,8 @@
curvemapping_free(simage->cumap);
// if(simage->gpd)
// XXX free_gpencil_data(simage->gpd);
-
+ if(simage->scopebuf.ibuf)
+ IMB_freeImBuf(simage->scopebuf.ibuf);
}
@@ -591,14 +614,17 @@
switch(wmn->data) {
case ND_FRAME:
image_histogram_tag_refresh(sa);
+ image_scope_samplebuf_tag_refresh(sa);
ED_area_tag_refresh(sa);
ED_area_tag_redraw(sa);
break;
case ND_MODE:
case ND_RENDER_RESULT:
case ND_COMPO_RESULT:
- if (ED_space_image_show_render(sima))
+ if (ED_space_image_show_render(sima)) {
image_histogram_tag_refresh(sa);
+ image_scope_samplebuf_tag_refresh(sa);
+ }
ED_area_tag_refresh(sa);
ED_area_tag_redraw(sa);
break;
@@ -607,6 +633,7 @@
case NC_IMAGE:
if (wmn->reference == sima->image || !wmn->reference) {
image_histogram_tag_refresh(sa);
+ image_scope_samplebuf_tag_refresh(sa);
ED_area_tag_refresh(sa);
ED_area_tag_redraw(sa);
}
@@ -614,6 +641,8 @@
case NC_SPACE:
if(wmn->data == ND_SPACE_IMAGE) {
image_histogram_tag_refresh(sa);
+ image_histogram_tag_refresh(sa);
+ image_scope_samplebuf_tag_refresh(sa);
ED_area_tag_redraw(sa);
}
break;
@@ -823,8 +852,10 @@
SpaceImage *sima= CTX_wm_space_image(C);
void *lock;
ImBuf *ibuf= ED_space_image_acquire_buffer(sima, &lock);
- if(ibuf)
+ if(ibuf) {
histogram_update(&sima->hist, ibuf);
+ samplebuf_update(&sima->scopebuf, ibuf);
+ }
ED_space_image_release_buffer(sima, lock);
ED_region_panels(C, ar, 1, NULL, -1);
Index: source/blender/editors/interface/interface_draw.c
===================================================================
--- source/blender/editors/interface/interface_draw.c (révision 27845)
+++ source/blender/editors/interface/interface_draw.c (copie de travail)
@@ -774,7 +774,217 @@
glDisable(GL_BLEND);
}
+void ui_draw_but_WAVEFORM(ARegion *ar, uiBut *but, uiWidgetColors *wcol, rcti *recti)
+{
+ SampleBuf *sb = (SampleBuf *)but->poin;
+ rctf rect;
+ int i, x, y, c;
+ float w, h, posx, posy, lum, alpha;
+ float ycc[3];
+ unsigned char *rc;
+ GLint scissor[4];
+ float colors[3][3] = {{0.33,0,0},{0,0.33,0},{0,0,0.33}};
+ float colorsycc[3][3] = {{0.25,0,0.25},{0.25,0.25,0},{0,0.25,0.25}};
+
+ if (sb==NULL) { printf("sb is null \n"); return; }
+
+ rect.xmin = (float)recti->xmin;
+ rect.xmax = (float)recti->xmax;
+ rect.ymin = (float)recti->ymin;
+ rect.ymax = (float)recti->ymax;
+
+ w = rect.xmax - rect.xmin;
+ h = rect.ymax - rect.ymin;
+
+ alpha = but->a2*0.05;
+ for(c=0; c<3; c++) {
+ colors[0][c] *= alpha;
+ colors[1][c] *= alpha;
+ colors[2][c] *= alpha;
+ colorsycc[0][c] *= alpha;
+ colorsycc[1][c] *= alpha;
+ colorsycc[2][c] *= alpha;
+ }
+
+ glEnable(GL_BLEND);
+ glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
+
+ glColor4f(0.f, 0.f, 0.f, 0.3f);
+ uiSetRoundBox(15);
+ gl_round_box(GL_POLYGON, rect.xmin-1, rect.ymin-1, rect.xmax+1, rect.ymax+1, 3.0f);
+
+ glColor4f(1.f, 1.f, 1.f, 0.08f);
+ /* draw grid lines here */
+ for (i=1; i<4; i++) {
+ fdrawline(rect.xmin, rect.ymin+(i/4.f)*h, rect.xmax, rect.ymin+(i/4.f)*h);
+ if (but->a1==0) fdrawline(rect.xmin+(i/4.f)*w, rect.ymin, rect.xmin+(i/4.f)*w, rect.ymax);
+ else if (i<3) fdrawline(rect.xmin+(i/3.f)*w, rect.ymin, rect.xmin+(i/3.f)*w, rect.ymax);
+ }
+
+ /* need scissor test, histogram can draw outside of boundary */
+ glGetIntegerv(GL_VIEWPORT, scissor);
+ glScissor(ar->winrct.xmin + (rect.xmin-1), ar->winrct.ymin+(rect.ymin-1), (rect.xmax+1)-(rect.xmin-1), (rect.ymax+1)-(rect.ymin-1));
+
+ glBlendFunc(GL_ONE,GL_ONE);
+ glBegin(GL_POINTS);
+
+ /* luminance */
+ glColor3f(alpha, alpha, alpha);
+ if (but->a1== WAVEFRM_LUM){
+ for (y=0; y<sb->ibuf->y; y++) {
+ for (x=0; x<sb->ibuf->x; x++) {
+ rc = (unsigned char *)(sb->ibuf->rect + y*sb->ibuf->x + x);
+ lum= (0.299*rc[0] + 0.587*rc[1] + 0.114*rc[2])/255.0;
+ posx = rect.xmin + ((float)x/sb->ibuf->x) * w;
+ posy = rect.ymin + lum * h;
+ glVertex2f(posx, posy);
+ }
+ }
+ }
+ /* separate colors*/
+ else if (but->a1== WAVEFRM_RGB){
+ for (y=0; y<sb->ibuf->y; y++) {
+ for (x=0; x<sb->ibuf->x; x++) {
+ rc = (unsigned char *)(sb->ibuf->rect + y*sb->ibuf->x + x);
+ for (c=0; c<3; c++) {
+ posx = rect.xmin + c*w/3.0 + (((float)x/sb->ibuf->x) * w/3.0);
+ posy = rect.ymin + rc[c] * h/255.0;
+ glColor3f(colors[c][0], colors[c][1], colors[c][2]);
+ glVertex2f(posx, posy);
+ }
+ }
+ }
+ }
+ /* YCC */
+ else if (but->a1== WAVEFRM_YCC){
+ for (y=0; y<sb->ibuf->y; y++) {
+ for (x=0; x<sb->ibuf->x; x++) {
+ rc = (unsigned char *)(sb->ibuf->rect + y*sb->ibuf->x + x);
+ rgb_to_ycc(rc[0]/255.0f, rc[1]/255.0f, rc[2]/255.0f, &ycc[0], &ycc[1], &ycc[2]);
+ for (c=0; c<3; c++) {
+ posx = rect.xmin + c*w/3.0 + (((float)x/sb->ibuf->x) * w/3.0);
+ posy = rect.ymin + ycc[c] * h/255.0;
+ glColor3f(colorsycc[c][0], colorsycc[c][1], colorsycc[c][2]);
+ glVertex2f(posx, posy);
+ }
+ }
+ }
+ }
+ glEnd();
+
+ /* restore scissortest */
+ glScissor(scissor[0], scissor[1], scissor[2], scissor[3]);
+
+ glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
+ glColor4f(0.f, 0.f, 0.f, 0.5f);
+ uiSetRoundBox(15);
+ gl_round_box(GL_LINE_LOOP, rect.xmin-1, rect.ymin-1, rect.xmax+1, rect.ymax+1, 3.0f);
+
+ glDisable(GL_BLEND);
+}
+void ui_draw_but_VECTORSCOPE(ARegion *ar, uiBut *but, uiWidgetColors *wcol, rcti *recti)
+{
+ SampleBuf *sb = (SampleBuf *)but->poin;
+ rctf rect;
+ int i, x, y;
+ int skina= 125; /* angle in degree of the skin tone line */
+ float w, h, centerx, centery, rad, diam;
+ float posx, posy, sqrsize=0.03;
+ double alpha;
+ float lum, cb, cr;
+ float colors[6][3]={{1,0,0},{1,1,0},{0,1,0},{0,1,1},{0,0,1},{1,0,1}};
+ unsigned char *rc;
+ GLint scissor[4];
+
+ if (sb==NULL) { printf("sb is null \n"); return; }
+
+ rect.xmin = (float)recti->xmin;
+ rect.xmax = (float)recti->xmax;
+ rect.ymin = (float)recti->ymin;
+ rect.ymax = (float)recti->ymax;
+
+ w = rect.xmax - rect.xmin;
+ h = rect.ymax - rect.ymin;
+ centerx = rect.xmin + w/2;
+ centery = rect.ymin + h/2;
+ diam= h;
+ if (w<diam) diam=w;
+ rad= diam/2.0;
+
+ alpha = but->a1*0.02;
+
+ glEnable(GL_BLEND);
+ glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
+
+ glColor4f(0.f, 0.f, 0.f, 0.3f);
+ uiSetRoundBox(15);
+ gl_round_box(GL_POLYGON, rect.xmin-1, rect.ymin-1, rect.xmax+1, rect.ymax+1, 3.0f);
+
+
+ glColor4f(1.f, 1.f, 1.f, 0.08f);
+ /* draw grid elements */
+ /* cross */
+ fdrawline(centerx - rad, centery, centerx + rad, centery);
+ fdrawline(centerx, centery - rad, centerx, centery + rad);
+ /* circle */
+ glBegin(GL_LINE_STRIP);
+ for(i=0; i<=360; i=i+15) {
+ float a= i*M_PI/180.0;
+ float si= sinf(a);
+ float co= cosf(a);
+ glVertex2f( centerx + co*rad, centery + si*rad);
+ }
+ glEnd();
+ /* skin tone line */
+ glColor4f(1.f, 1.f, 1.f, 0.07f);
+ fdrawline(centerx, centery, centerx + cosf(skina*M_PI/180.0)*rad, centery + sinf(skina*M_PI/180.0)*rad);
+ /* saturation points */
+ for(i=0; i<7; i++) {
+ if(i==6) {
+ rgb_to_ycc(colors[0][0], colors[0][1], colors[0][2], &lum, &cb, &cr);
+ glColor4f(colors[0][0], colors[0][1], colors[0][2], 0.2f);
+ }
+ else {
+ rgb_to_ycc(colors[i][0], colors[i][1], colors[i][2], &lum, &cb, &cr);
+ glColor4f(colors[i][0], colors[i][1], colors[i][2], 0.2f);
+ }
+ posx = centerx + ((cb/255.0)-0.5) * rad*2;
+ posy = centery + ((cr/255.0)-0.5) * rad*2;
+ fdrawbox(posx+rad*sqrsize, posy+rad*sqrsize, posx-rad*sqrsize, posy-rad*sqrsize);
+ }
+
+ /* need scissor test, histogram can draw outside of boundary */
+ glGetIntegerv(GL_VIEWPORT, scissor);
+ glScissor(ar->winrct.xmin + (rect.xmin-1), ar->winrct.ymin+(rect.ymin-1), (rect.xmax+1)-(rect.xmin-1), (rect.ymax+1)-(rect.ymin-1));
+
+ glBlendFunc(GL_ONE,GL_ONE);
+ glColor3d(alpha, alpha, alpha);
+ glBegin(GL_POINTS);
+
+ for (y=0; y<sb->ibuf->y; y++) {
+ for (x=0; x<sb->ibuf->x; x++) {
+ rc = (unsigned char *)(sb->ibuf->rect + y*sb->ibuf->x + x);
+ rgb_to_ycc(rc[0]/255.0f, rc[1]/255.0f, rc[2]/255.0f, &lum, &cb, &cr);
+ posx = centerx + ((cb/255.0)-0.5) * rad*2;
+ posy = centery + ((cr/255.0)-0.5) * rad*2;
+ glVertex2f(posx, posy);
+ }
+ }
+
+ glEnd();
+
+ /* restore scissortest */
+ glScissor(scissor[0], scissor[1], scissor[2], scissor[3]);
+
+ glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
+ glColor4f(0.f, 0.f, 0.f, 0.5f);
+ uiSetRoundBox(15);
+ gl_round_box(GL_LINE_LOOP, rect.xmin-1, rect.ymin-1, rect.xmax+1, rect.ymax+1, 3.0f);
+
+ glDisable(GL_BLEND);
+}
+
void ui_draw_but_COLORBAND(uiBut *but, uiWidgetColors *wcol, rcti *rect)
{
ColorBand *coba;
Index: source/blender/editors/interface/interface_templates.c
===================================================================
--- source/blender/editors/interface/interface_templates.c (révision 27845)
+++ source/blender/editors/interface/interface_templates.c (copie de travail)
@@ -1595,6 +1595,94 @@
MEM_freeN(cb);
}
+/********************* Waveform Template ************************/
+
+void uiTemplateWaveform(uiLayout *layout, PointerRNA *ptr, char *propname, PointerRNA *wfptr, char *wfpropname, int expand)
+{
+ PropertyRNA *sbprop= RNA_struct_find_property(ptr, propname);
+ PropertyRNA *wfprop= RNA_struct_find_property(wfptr, wfpropname);
+ PointerRNA sbcptr, wfcptr;
+ RNAUpdateCb *cb;
+ uiBlock *block;
+ uiBut *bt;
+ SampleBuf *sb;
+ Waveform *wf;
+ rctf rect;
+
+ if(!sbprop || RNA_property_type(sbprop) != PROP_POINTER)
+ return;
+ if(!wfprop || RNA_property_type(sbprop) != PROP_POINTER)
+ return;
+
+ sbcptr= RNA_property_pointer_get(ptr, sbprop);
+ if(!sbcptr.data || !RNA_struct_is_a(sbcptr.type, &RNA_SampleBuffer))
+ return;
+ wfcptr= RNA_property_pointer_get(wfptr, wfprop);
+ if(!wfcptr.data || !RNA_struct_is_a(wfcptr.type, &RNA_Waveform))
+ return;
+
+ cb= MEM_callocN(sizeof(RNAUpdateCb), "RNAUpdateCb");
+ cb->ptr= *ptr;
+ cb->prop= sbprop;
+
+ rect.xmin= 0; rect.xmax= 200;
+ rect.ymin= 0; rect.ymax= 190;
+
+ sb = (SampleBuf *)sbcptr.data;
+ wf = (Waveform *)wfcptr.data;
+
+ block= uiLayoutAbsoluteBlock(layout);
+
+ bt= uiDefBut(block, WAVEFORM, 0, "", rect.xmin, rect.ymin, rect.xmax-rect.xmin, 100.0f, sb, 0, 0, wf->mode, wf->alpha, "");
+ uiButSetNFunc(bt, rna_update_cb, MEM_dupallocN(cb), NULL);
+
+ MEM_freeN(cb);
+}
+
+/********************* Vectorscope Template ************************/
+
+void uiTemplateVectorscope(uiLayout *layout, PointerRNA *ptr, char *propname, PointerRNA *vsptr, char *vspropname, int expand)
+{
+ PropertyRNA *sbprop= RNA_struct_find_property(ptr, propname);
+ PropertyRNA *vsprop= RNA_struct_find_property(vsptr, vspropname);
+ PointerRNA sbcptr, vscptr;
+ RNAUpdateCb *cb;
+ uiBlock *block;
+ uiBut *bt;
+ SampleBuf *sb;
+ Vectorscope *vs;
+ rctf rect;
+
+ if(!sbprop || RNA_property_type(sbprop) != PROP_POINTER)
+ return;
+ if(!vsprop || RNA_property_type(vsprop) != PROP_POINTER)
+ return;
+
+ sbcptr= RNA_property_pointer_get(ptr, sbprop);
+ if(!sbcptr.data || !RNA_struct_is_a(sbcptr.type, &RNA_SampleBuffer))
+ return;
+ vscptr= RNA_property_pointer_get(ptr, vsprop);
+ if(!vscptr.data || !RNA_struct_is_a(vscptr.type, &RNA_Vectorscope))
+ return;
+
+ cb= MEM_callocN(sizeof(RNAUpdateCb), "RNAUpdateCb");
+ cb->ptr= *ptr;
+ cb->prop= sbprop;
+
+ rect.xmin= 0; rect.xmax= 200;
+ rect.ymin= 0; rect.ymax= 190;
+
+ block= uiLayoutAbsoluteBlock(layout);
+
+ sb = (SampleBuf *)sbcptr.data;
+ vs = (Vectorscope *)vscptr.data;
+
+ bt= uiDefBut(block, VECTORSCOPE, 0, "", rect.xmin, rect.ymin, rect.xmax-rect.xmin, 150.0f, sb, 0, 0, vs->alpha, 0, "");
+ uiButSetNFunc(bt, rna_update_cb, MEM_dupallocN(cb), NULL);
+
+ MEM_freeN(cb);
+}
+
/********************* CurveMapping Template ************************/
#include "BKE_colortools.h"
Index: source/blender/editors/interface/interface_intern.h
===================================================================
--- source/blender/editors/interface/interface_intern.h (révision 27845)
+++ source/blender/editors/interface/interface_intern.h (copie de travail)
@@ -440,6 +440,8 @@
void ui_draw_gradient(rcti *rect, float *rgb, int type, float alpha);
void ui_draw_but_HISTOGRAM(ARegion *ar, uiBut *but, struct uiWidgetColors *wcol, rcti *rect);
+void ui_draw_but_WAVEFORM(ARegion *ar, uiBut *but, struct uiWidgetColors *wcol, rcti *rect);
+void ui_draw_but_VECTORSCOPE(ARegion *ar, uiBut *but, struct uiWidgetColors *wcol, rcti *rect);
void ui_draw_but_COLORBAND(uiBut *but, struct uiWidgetColors *wcol, rcti *rect);
void ui_draw_but_NORMAL(uiBut *but, struct uiWidgetColors *wcol, rcti *rect);
void ui_draw_but_CURVE(ARegion *ar, uiBut *but, struct uiWidgetColors *wcol, rcti *rect);
Index: source/blender/editors/interface/interface_widgets.c
===================================================================
--- source/blender/editors/interface/interface_widgets.c (révision 27845)
+++ source/blender/editors/interface/interface_widgets.c (copie de travail)
@@ -2709,6 +2709,14 @@
ui_draw_but_HISTOGRAM(ar, but, &tui->wcol_regular, rect);
break;
+ case WAVEFORM:
+ ui_draw_but_WAVEFORM(ar, but, &tui->wcol_regular, rect);
+ break;
+
+ case VECTORSCOPE:
+ ui_draw_but_VECTORSCOPE(ar, but, &tui->wcol_regular, rect);
+ break;
+
case BUT_CURVE:
ui_draw_but_CURVE(ar, but, &tui->wcol_regular, rect);
break;

Event Timeline