From 77833847eee49b1810d650d3c94ebfbdb96602be Mon Sep 17 00:00:00 2001 From: Matt Ebb Date: Fri, 9 Apr 2010 00:44:35 +0000 Subject: [PATCH] Patch from Xavier Thomas: Use vertex arrays for drawing image editor vector scope too, making it a lot more efficient. Also fixed issue with scopes height not being stored in file properly. --- source/blender/blenkernel/BKE_blender.h | 2 +- source/blender/blenkernel/intern/colortools.c | 222 +++++++----------- source/blender/blenloader/intern/readfile.c | 13 +- .../editors/interface/interface_draw.c | 219 +++++------------ source/blender/makesdna/DNA_color_types.h | 6 +- 5 files changed, 164 insertions(+), 298 deletions(-) diff --git a/source/blender/blenkernel/BKE_blender.h b/source/blender/blenkernel/BKE_blender.h index 64c5823f06f..7ac5815943a 100644 --- a/source/blender/blenkernel/BKE_blender.h +++ b/source/blender/blenkernel/BKE_blender.h @@ -45,7 +45,7 @@ struct Scene; struct Main; #define BLENDER_VERSION 252 -#define BLENDER_SUBVERSION 4 +#define BLENDER_SUBVERSION 5 #define BLENDER_MINVERSION 250 #define BLENDER_MINSUBVERSION 0 diff --git a/source/blender/blenkernel/intern/colortools.c b/source/blender/blenkernel/intern/colortools.c index 2da527d467a..353adf932a5 100644 --- a/source/blender/blenkernel/intern/colortools.c +++ b/source/blender/blenkernel/intern/colortools.c @@ -899,8 +899,16 @@ DO_INLINE int get_bin_float(float f) return bin; } -DO_INLINE void save_sample_line(Scopes *scopes, const int idx, const float fx, float *rgb, float *ycc, float *ycc709) +DO_INLINE void save_sample_line(Scopes *scopes, const int idx, const float fx, float *rgb, float *ycc) { + float yuv[3]; + + /* vectorscope*/ + rgb_to_yuv(rgb[0], rgb[1], rgb[2], &yuv[0], &yuv[1], &yuv[2]); + scopes->vecscope[idx + 0] = yuv[1]; + scopes->vecscope[idx + 1] = yuv[2]; + + /* waveform */ switch (scopes->wavefrm_mode) { case SCOPES_WAVEFRM_RGB: scopes->waveform_1[idx + 0] = fx; @@ -912,35 +920,17 @@ DO_INLINE void save_sample_line(Scopes *scopes, const int idx, const float fx, f break; case SCOPES_WAVEFRM_LUM: scopes->waveform_1[idx + 0] = fx; - scopes->waveform_1[idx + 1] = 0.299*rgb[0] + 0.587*rgb[1] + 0.114*rgb[2]; + scopes->waveform_1[idx + 1] = ycc[0]; break; case SCOPES_WAVEFRM_YCC_JPEG: - scopes->waveform_1[idx + 0] = fx; - scopes->waveform_1[idx + 1] = ycc[0] * INV_255; - scopes->waveform_2[idx + 0] = fx; - scopes->waveform_2[idx + 1] = ycc[1] * INV_255; - scopes->waveform_3[idx + 0] = fx; - scopes->waveform_3[idx + 1] = ycc[2] * INV_255; - break; case SCOPES_WAVEFRM_YCC_709: - scopes->waveform_1[idx + 0] = fx; - scopes->waveform_1[idx + 1] = ycc709[0] * INV_255; - scopes->waveform_2[idx + 0] = fx; - scopes->waveform_2[idx + 1] = ycc709[1] * INV_255; - scopes->waveform_3[idx + 0] = fx; - scopes->waveform_3[idx + 1] = ycc709[2] * INV_255; - break; case SCOPES_WAVEFRM_YCC_601: - { - float ycc601[3]; - rgb_to_ycc(rgb[0], rgb[1], rgb[2], &ycc601[0], &ycc601[1], &ycc601[2], BLI_YCC_ITU_BT601); scopes->waveform_1[idx + 0] = fx; - scopes->waveform_1[idx + 1] = ycc601[0] * INV_255; + scopes->waveform_1[idx + 1] = ycc[0]; scopes->waveform_2[idx + 0] = fx; - scopes->waveform_2[idx + 1] = ycc601[1] * INV_255; + scopes->waveform_2[idx + 1] = ycc[1]; scopes->waveform_3[idx + 0] = fx; - scopes->waveform_3[idx + 1] = ycc601[2] * INV_255; - } + scopes->waveform_3[idx + 1] = ycc[2]; break; } } @@ -949,11 +939,12 @@ void scopes_update(Scopes *scopes, ImBuf *ibuf, int use_color_management) { int x, y, c, n, nl; double div, divl; - float *rf, *drf; - unsigned char *rc, *drc; + float *rf; + unsigned char *rc; unsigned int *bin_r, *bin_g, *bin_b, *bin_lum; int savedlines, saveline; - float rgb[3], ycc[3], ycc709[3]; + float rgb[3], ycc[3]; + int ycc_mode; if (scopes->ok == 1 ) return; @@ -964,6 +955,22 @@ void scopes_update(Scopes *scopes, ImBuf *ibuf, int use_color_management) scopes->hist.channels = 3; scopes->hist.x_resolution = 256; + switch (scopes->wavefrm_mode) { + case SCOPES_WAVEFRM_RGB: + ycc_mode = -1; + break; + case SCOPES_WAVEFRM_LUM: + case SCOPES_WAVEFRM_YCC_JPEG: + ycc_mode = BLI_YCC_JFIF_0_255; + break; + case SCOPES_WAVEFRM_YCC_601: + ycc_mode = BLI_YCC_ITU_BT601; + break; + case SCOPES_WAVEFRM_YCC_709: + ycc_mode = BLI_YCC_ITU_BT709; + break; + } + /* temp table to count pix value for histo */ bin_r = MEM_callocN(256 * sizeof(unsigned int), "temp historgram bins"); bin_g = MEM_callocN(256 * sizeof(unsigned int), "temp historgram bins"); @@ -976,19 +983,11 @@ void scopes_update(Scopes *scopes, ImBuf *ibuf, int use_color_management) if (scopes->sample_full) scopes->sample_lines = ibuf->y; - if( scopes->samples_ibuf) { - IMB_freeImBuf(scopes->samples_ibuf); - scopes->samples_ibuf=NULL; - } /* scan the image */ savedlines=0; for (c=0; c<3; c++) { - scopes->rgbminmax[c][0]=100.0f; - scopes->rgbminmax[c][1]=-100.0f; - scopes->yccminmax[c][0]=25500.0f; - scopes->yccminmax[c][1]=-25500.0f; - scopes->ycc709minmax[c][0]=25500.0f; - scopes->ycc709minmax[c][1]=-25500.0f; + scopes->minmax[c][0]=25500.0f; + scopes->minmax[c][1]=-25500.0f; } scopes->waveform_tot = ibuf->x*scopes->sample_lines; @@ -999,114 +998,68 @@ void scopes_update(Scopes *scopes, ImBuf *ibuf, int use_color_management) MEM_freeN(scopes->waveform_2); if (scopes->waveform_3) MEM_freeN(scopes->waveform_3); + if (scopes->vecscope) + MEM_freeN(scopes->vecscope); scopes->waveform_1= MEM_callocN(scopes->waveform_tot * 2 * sizeof(float), "waveform point channel 1"); scopes->waveform_2= MEM_callocN(scopes->waveform_tot * 2 * sizeof(float), "waveform point channel 2"); scopes->waveform_3= MEM_callocN(scopes->waveform_tot * 2 * sizeof(float), "waveform point channel 3"); + scopes->vecscope= MEM_callocN(scopes->waveform_tot * 2 * sizeof(float), "vectorscope point channel"); - if (ibuf->rect_float) { - scopes->samples_ibuf = IMB_allocImBuf(ibuf->x, scopes->sample_lines, 32, IB_rectfloat, 0 ); + if (ibuf->rect_float) rf = ibuf->rect_float; - drf= scopes->samples_ibuf->rect_float; - - for (y = 0; y < ibuf->y; y++) { - if (savedlinessample_lines && y>=((savedlines)*ibuf->y)/(scopes->sample_lines+1)) { - saveline=1; - } else saveline=0; - for (x = 0; x < ibuf->x; x++) { - + else if (ibuf->rect) + rc = (unsigned char *)ibuf->rect; + + for (y = 0; y < ibuf->y; y++) { + if (savedlinessample_lines && y>=((savedlines)*ibuf->y)/(scopes->sample_lines+1)) { + saveline=1; + } else saveline=0; + for (x = 0; x < ibuf->x; x++) { + + if (ibuf->rect_float) { if (use_color_management) linearrgb_to_srgb_v3_v3(rgb, rf); else copy_v3_v3(rgb, rf); - - rgb_to_ycc(rgb[0],rgb[1],rgb[2],&ycc[0],&ycc[1],&ycc[2],BLI_YCC_JFIF_0_255); - rgb_to_ycc(rgb[0],rgb[1],rgb[2],&ycc709[0],&ycc709[1],&ycc709[2],BLI_YCC_ITU_BT709); - - /* check for min max */ - for (c=0; c<3; c++) { - if (rgb[c] < scopes->rgbminmax[c][0]) scopes->rgbminmax[c][0] = rgb[c]; - if (rgb[c] > scopes->rgbminmax[c][1]) scopes->rgbminmax[c][1] = rgb[c]; - if (ycc[c] < scopes->yccminmax[c][0]) scopes->yccminmax[c][0] = ycc[c]; - if (ycc[c] > scopes->yccminmax[c][1]) scopes->yccminmax[c][1] = ycc[c]; - if (ycc709[c] < scopes->ycc709minmax[c][0]) scopes->ycc709minmax[c][0] = ycc709[c]; - if (ycc709[c] > scopes->ycc709minmax[c][1]) scopes->ycc709minmax[c][1] = ycc709[c]; - } - /* increment count for histo*/ - bin_r[ get_bin_float(rgb[0]) ] += 1; - bin_g[ get_bin_float(rgb[1]) ] += 1; - bin_b[ get_bin_float(rgb[2]) ] += 1; - bin_lum[ get_bin_float(ycc[0] * INV_255) ] += 1; - - /* save sample if needed */ - if(saveline) { - const float fx = (float)x / (float)ibuf->x; - const int idx = 2*(ibuf->x*savedlines+x); - - save_sample_line(scopes, idx, fx, rgb, ycc, ycc709); - - drf[0]=rgb[0]; - drf[1]=rgb[1]; - drf[2]=rgb[2]; - drf+= scopes->samples_ibuf->channels; - } - rf+= ibuf->channels; } - if (saveline) - savedlines +=1; - } - - } - else if (ibuf->rect) { - scopes->samples_ibuf = IMB_allocImBuf(ibuf->x, scopes->sample_lines, 32, IB_rect, 0 ); - rc = (unsigned char *)ibuf->rect; - drc= (unsigned char *) scopes->samples_ibuf->rect; - - for (y = 0; y < ibuf->y; y++) { - if (savedlinessample_lines && y>=((savedlines)*ibuf->y)/(scopes->sample_lines+1)) { - saveline=1; - } else saveline=0; - - for (x = 0; x < ibuf->x; x++) { - + else if (ibuf->rect) { for (c=0; c<3; c++) - rgb[c] = rc[c] * INV_255; - rgb_to_ycc(rgb[0],rgb[1],rgb[2],&ycc[0],&ycc[1],&ycc[2],BLI_YCC_JFIF_0_255); - rgb_to_ycc(rgb[0],rgb[1],rgb[2],&ycc709[0],&ycc709[1],&ycc709[2],BLI_YCC_ITU_BT709); - - /* check for min max */ - for (c=0; c<3; c++) { - if (rgb[c] < scopes->rgbminmax[c][0]) scopes->rgbminmax[c][0] = rgb[c]; - if (rgb[c] > scopes->rgbminmax[c][1]) scopes->rgbminmax[c][1] = rgb[c]; - if (ycc[c] < scopes->yccminmax[c][0]) scopes->yccminmax[c][0] = ycc[c]; - if (ycc[c] > scopes->yccminmax[c][1]) scopes->yccminmax[c][1] = ycc[c]; - if (ycc709[c] < scopes->ycc709minmax[c][0]) scopes->ycc709minmax[c][0] = ycc709[c]; - if (ycc709[c] > scopes->ycc709minmax[c][1]) scopes->ycc709minmax[c][1] = ycc709[c]; - } - - /* increment count for histo */ - bin_r[ rc[0] ] += 1; - bin_g[ rc[1] ] += 1; - bin_b[ rc[2] ] += 1; - bin_lum[ get_bin_float(ycc[0] * INV_255) ] += 1; - - /* save sample if needed */ - if(saveline) { - const float fx = (float)x / (float)ibuf->x; - const int idx = 2*(ibuf->x*savedlines+x); - - save_sample_line(scopes, idx, fx, rgb, ycc, ycc709); - - drc[0]=rc[0]; - drc[1]=rc[1]; - drc[2]=rc[2]; - drc+= 4; - } - rc += ibuf->channels; + rgb[c] = rc[c] * INV_255; } - if (saveline) - savedlines +=1; + /* check for min max */ + if(ycc_mode == -1 ) { + for (c=0; c<3; c++) { + if (rgb[c] < scopes->minmax[c][0]) scopes->minmax[c][0] = rgb[c]; + if (rgb[c] > scopes->minmax[c][1]) scopes->minmax[c][1] = rgb[c]; + } + } + else { + rgb_to_ycc(rgb[0],rgb[1],rgb[2],&ycc[0],&ycc[1],&ycc[2], ycc_mode); + for (c=0; c<3; c++) { + ycc[c] *=INV_255; + if (ycc[c] < scopes->minmax[c][0]) scopes->minmax[c][0] = ycc[c]; + if (ycc[c] > scopes->minmax[c][1]) scopes->minmax[c][1] = ycc[c]; + } + } + /* increment count for histo*/ + bin_r[ get_bin_float(rgb[0]) ] += 1; + bin_g[ get_bin_float(rgb[1]) ] += 1; + bin_b[ get_bin_float(rgb[2]) ] += 1; + bin_lum[ get_bin_float(ycc[0]) ] += 1; + + /* save sample if needed */ + if(saveline) { + const float fx = (float)x / (float)ibuf->x; + const int idx = 2*(ibuf->x*savedlines+x); + save_sample_line(scopes, idx, fx, rgb, ycc); + } + + rf+= ibuf->channels; + rc+= ibuf->channels; } + if (saveline) + savedlines +=1; } /* convert hist data to float (proportional to max count) */ @@ -1152,9 +1105,8 @@ void scopes_free(Scopes *scopes) MEM_freeN(scopes->waveform_3); scopes->waveform_3 = NULL; } - - if( scopes->samples_ibuf) { - IMB_freeImBuf(scopes->samples_ibuf); - scopes->samples_ibuf=NULL; + if (scopes->vecscope) { + MEM_freeN(scopes->vecscope); + scopes->vecscope = NULL; } -} \ No newline at end of file +} diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c index 689faac505a..3196de4243c 100644 --- a/source/blender/blenloader/intern/readfile.c +++ b/source/blender/blenloader/intern/readfile.c @@ -4834,10 +4834,10 @@ void lib_link_screen_restore(Main *newmain, bScreen *curscreen, Scene *curscene) sima->image= restore_pointer_by_name(newmain, (ID *)sima->image, 1); - sima->scopes.samples_ibuf = NULL; sima->scopes.waveform_1 = NULL; sima->scopes.waveform_2 = NULL; sima->scopes.waveform_3 = NULL; + sima->scopes.vecscope = NULL; sima->scopes.ok = 0; /* NOTE: pre-2.5, this was local data not lib data, but now we need this as lib data @@ -5111,10 +5111,10 @@ static void direct_link_screen(FileData *fd, bScreen *sc) sima->iuser.scene= NULL; sima->iuser.ok= 1; - sima->scopes.samples_ibuf = NULL; sima->scopes.waveform_1 = NULL; sima->scopes.waveform_2 = NULL; sima->scopes.waveform_3 = NULL; + sima->scopes.vecscope = NULL; sima->scopes.ok = 0; /* WARNING: gpencil data is no longer stored directly in sima after 2.5 @@ -10737,8 +10737,7 @@ static void do_versions(FileData *fd, Library *lib, Main *main) do_version_old_trackto_to_constraints(ob); } - /* put 2.50 compatibility code here until next subversion bump */ - { + if (main->versionfile < 252 || (main->versionfile == 252 && main->subversionfile < 5)) { bScreen *sc; /* Image editor scopes */ @@ -10754,12 +10753,18 @@ static void do_versions(FileData *fd, Library *lib, Main *main) sima->scopes.wavefrm_alpha=0.3; sima->scopes.vecscope_alpha=0.3; sima->scopes.wavefrm_height= 100; + sima->scopes.vecscope_height= 100; sima->scopes.hist.height= 100; } } } } } + + /* put 2.50 compatibility code here until next subversion bump */ + { + + } /* WATCH IT!!!: pointers from libdata have not been converted yet here! */ /* WATCH IT 2!: Userdef struct init has to be in editors/interface/resources.c! */ diff --git a/source/blender/editors/interface/interface_draw.c b/source/blender/editors/interface/interface_draw.c index 574bb87f963..aa111bffaa9 100644 --- a/source/blender/editors/interface/interface_draw.c +++ b/source/blender/editors/interface/interface_draw.c @@ -688,6 +688,32 @@ static void ui_draw_but_CHARTAB(uiBut *but) #endif // INTERNATIONAL #endif +static void draw_scope_end(rctf *rect, GLint *scissor) +{ + float scaler_x1, scaler_x2; + + /* restore scissortest */ + glScissor(scissor[0], scissor[1], scissor[2], scissor[3]); + + glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA); + + /* scale widget */ + scaler_x1 = rect->xmin + (rect->xmax - rect->xmin)/2 - SCOPE_RESIZE_PAD; + scaler_x2 = rect->xmin + (rect->xmax - rect->xmin)/2 + SCOPE_RESIZE_PAD; + + glColor4f(0.f, 0.f, 0.f, 0.25f); + fdrawline(scaler_x1, rect->ymin-4, scaler_x2, rect->ymin-4); + fdrawline(scaler_x1, rect->ymin-7, scaler_x2, rect->ymin-7); + glColor4f(1.f, 1.f, 1.f, 0.25f); + fdrawline(scaler_x1, rect->ymin-5, scaler_x2, rect->ymin-5); + fdrawline(scaler_x1, rect->ymin-8, scaler_x2, rect->ymin-8); + + /* outline */ + glColor4f(0.f, 0.f, 0.f, 0.5f); + uiSetRoundBox(15); + gl_round_box(GL_LINE_LOOP, rect->xmin-1, rect->ymin, rect->xmax+1, rect->ymax+1, 3.0f); +} + void histogram_draw_one(float r, float g, float b, float alpha, float x, float y, float w, float h, float *data, int res) { int i; @@ -728,7 +754,6 @@ void ui_draw_but_HISTOGRAM(ARegion *ar, uiBut *but, uiWidgetColors *wcol, rcti * rctf rect; int i; float w, h; - float scaler_x1, scaler_x2; //float alpha; GLint scissor[4]; @@ -740,8 +765,7 @@ void ui_draw_but_HISTOGRAM(ARegion *ar, uiBut *but, uiWidgetColors *wcol, rcti * rect.ymax = (float)recti->ymax-1; w = rect.xmax - rect.xmin; - h = rect.ymax - rect.ymin; - h *= hist->ymax; + h = (rect.ymax - rect.ymin) * hist->ymax; glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA); @@ -771,27 +795,9 @@ void ui_draw_but_HISTOGRAM(ARegion *ar, uiBut *but, uiWidgetColors *wcol, rcti * if (hist->mode == HISTO_MODE_RGB || hist->mode == HISTO_MODE_B) histogram_draw_one(0.0, 0.0, 1.0, 0.75, rect.xmin, rect.ymin, w, h, hist->data_b, res); } - /* restore scissortest */ - glScissor(scissor[0], scissor[1], scissor[2], scissor[3]); - glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA); - - /* height scaling widget */ - scaler_x1 = rect.xmin + w/2 - SCOPE_RESIZE_PAD; - scaler_x2 = rect.xmin + w/2 + SCOPE_RESIZE_PAD; - - glColor4f(0.f, 0.f, 0.f, 0.25f); - fdrawline(scaler_x1, rect.ymin-4, scaler_x2, rect.ymin-4); - fdrawline(scaler_x1, rect.ymin-7, scaler_x2, rect.ymin-7); - glColor4f(1.f, 1.f, 1.f, 0.25f); - fdrawline(scaler_x1, rect.ymin-5, scaler_x2, rect.ymin-5); - fdrawline(scaler_x1, rect.ymin-8, scaler_x2, rect.ymin-8); - - glColor4f(0.f, 0.f, 0.f, 0.5f); - uiSetRoundBox(15); - gl_round_box(GL_LINE_LOOP, rect.xmin-1, rect.ymin, rect.xmax+1, rect.ymax+1, 3.0f); - - glDisable(GL_BLEND); + /* outline, scale gripper */ + draw_scope_end(&rect, scissor); } void ui_draw_but_WAVEFORM(ARegion *ar, uiBut *but, uiWidgetColors *wcol, rcti *recti) @@ -805,9 +811,8 @@ void ui_draw_but_WAVEFORM(ARegion *ar, uiBut *but, uiWidgetColors *wcol, rcti *r float colorsycc[3][3] = {{1,0,1},{1,1,0},{0,1,1}}; float colors_alpha[3][3], colorsycc_alpha[3][3]; /* colors pre multiplied by alpha for speed up */ float min, max; - float scaler_x1, scaler_x2; - if (scopes==NULL || scopes->samples_ibuf==NULL) return; + if (scopes==NULL) return; rect.xmin = (float)recti->xmin+1; rect.xmax = (float)recti->xmax-1; @@ -815,9 +820,9 @@ void ui_draw_but_WAVEFORM(ARegion *ar, uiBut *but, uiWidgetColors *wcol, rcti *r rect.ymax = (float)recti->ymax-1; if (scopes->wavefrm_yfac < 0.5f ) - scopes->wavefrm_yfac =1.0f; + scopes->wavefrm_yfac =0.98f; w = rect.xmax - rect.xmin-7; - h = (rect.ymax - rect.ymin)/scopes->wavefrm_yfac; + h = (rect.ymax - rect.ymin)*scopes->wavefrm_yfac; yofs= rect.ymin + (rect.ymax - rect.ymin -h)/2.0f; w3=w/3.0f; @@ -839,7 +844,7 @@ void ui_draw_but_WAVEFORM(ARegion *ar, uiBut *but, uiWidgetColors *wcol, rcti *r gl_round_box(GL_POLYGON, rect.xmin-1, rect.ymin-1, rect.xmax+1, rect.ymax+1, 3.0f); - /* need scissor test, histogram can draw outside of boundary */ + /* need scissor test, waveform 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)); @@ -861,6 +866,7 @@ void ui_draw_but_WAVEFORM(ARegion *ar, uiBut *but, uiWidgetColors *wcol, rcti *r fdrawline(rect.xmin+i*w3, rect.ymin, rect.xmin+i*w3, rect.ymax); } } + /* separate min max zone on the right */ fdrawline(rect.xmin+w, rect.ymin, rect.xmin+w, rect.ymax); /* 16-235-240 level in case of ITU-R BT601/709 */ @@ -871,7 +877,9 @@ void ui_draw_but_WAVEFORM(ARegion *ar, uiBut *but, uiWidgetColors *wcol, rcti *r fdrawline(rect.xmin+3*w3, yofs+h*235.0f/255.0f, rect.xmax+1, yofs+h*235.0f/255.0f); fdrawline(rect.xmin+w3, yofs+h*240.0f/255.0f, rect.xmax+1, yofs+h*240.0f/255.0f); } - + /* 7.5 IRE black point level for NTSC */ + if (scopes->wavefrm_mode== SCOPES_WAVEFRM_LUM) + fdrawline(rect.xmin, yofs+h*0.075f, rect.xmax+1, yofs+h*0.075f); /* LUMA (1 channel) */ glBlendFunc(GL_ONE,GL_ONE); @@ -881,23 +889,20 @@ void ui_draw_but_WAVEFORM(ARegion *ar, uiBut *but, uiWidgetColors *wcol, rcti *r glBlendFunc(GL_ONE,GL_ONE); glPushMatrix(); - glEnableClientState(GL_VERTEX_ARRAY); glTranslatef(rect.xmin, yofs, 0.f); glScalef(w, h, 0.f); - glVertexPointer(2, GL_FLOAT, 0, scopes->waveform_1); glDrawArrays(GL_POINTS, 0, scopes->waveform_tot); glDisableClientState(GL_VERTEX_ARRAY); - glPopMatrix(); /* min max */ glColor3f(.5f, .5f, .5f); - min= yofs+scopes->yccminmax[0][0]*h/255.0f; - max= yofs+scopes->yccminmax[0][1]*h/255.0f; + min= yofs+scopes->minmax[0][0]*h; + max= yofs+scopes->minmax[0][1]*h; CLAMP(min, rect.ymin, rect.ymax); CLAMP(max, rect.ymin, rect.ymax); fdrawline(rect.xmax-3,min,rect.xmax-3,max); @@ -910,103 +915,45 @@ void ui_draw_but_WAVEFORM(ARegion *ar, uiBut *but, uiWidgetColors *wcol, rcti *r glBlendFunc(GL_ONE,GL_ONE); glPushMatrix(); - glEnableClientState(GL_VERTEX_ARRAY); glTranslatef(rect.xmin, yofs, 0.f); glScalef(w3, h, 0.f); glColor3fv((rgb)?colors_alpha[0]:colorsycc_alpha[0]); - glVertexPointer(2, GL_FLOAT, 0, scopes->waveform_1); glDrawArrays(GL_POINTS, 0, scopes->waveform_tot); glTranslatef(1.f, 0.f, 0.f); glColor3fv((rgb)?colors_alpha[1]:colorsycc_alpha[1]); - glVertexPointer(2, GL_FLOAT, 0, scopes->waveform_2); glDrawArrays(GL_POINTS, 0, scopes->waveform_tot); glTranslatef(1.f, 0.f, 0.f); glColor3fv((rgb)?colors_alpha[2]:colorsycc_alpha[2]); - glVertexPointer(2, GL_FLOAT, 0, scopes->waveform_3); glDrawArrays(GL_POINTS, 0, scopes->waveform_tot); glDisableClientState(GL_VERTEX_ARRAY); - glPopMatrix(); /* min max */ - if (scopes->wavefrm_mode == SCOPES_WAVEFRM_RGB) { - for (c=0; c<3; c++) { + for (c=0; c<3; c++) { + if (scopes->wavefrm_mode == SCOPES_WAVEFRM_RGB) glColor3f(colors[c][0]*0.75, colors[c][1]*0.75, colors[c][2]*0.75); - min= yofs+scopes->rgbminmax[c][0]*h; - max= yofs+scopes->rgbminmax[c][1]*h; - CLAMP(min, rect.ymin, rect.ymax); - CLAMP(max, rect.ymin, rect.ymax); - fdrawline(rect.xmin+w+2+c*2,min,rect.xmin+w+2+c*2,max); - } - } else { - if (ELEM(scopes->wavefrm_mode, SCOPES_WAVEFRM_YCC_601, SCOPES_WAVEFRM_YCC_JPEG)) { - for (c=0; c<3; c++) { - glColor3f(colorsycc[c][0]*0.75, colorsycc[c][1]*0.75, colorsycc[c][2]*0.75); - /* we get ITU 601 min max from remapping JPEG*/ - if (scopes->wavefrm_mode== SCOPES_WAVEFRM_YCC_601) { - if(c==0) { - min= yofs+(16+(219*scopes->yccminmax[c][0]/255))*h/255.0f; - max= yofs+(16+(219*scopes->yccminmax[c][1]/255))*h/255.0f; - } - else { - min= yofs+(16+(224*scopes->yccminmax[c][0]/255))*h/255.0f; - max= yofs+(16+(224*scopes->yccminmax[c][1]/255))*h/255.0f; - } - } - /* rescale ycc to 0-1*/ - else { - min= yofs+scopes->yccminmax[c][0]*h/255.0f; - max= yofs+scopes->yccminmax[c][1]*h/255.0f; - } - CLAMP(min, rect.ymin, rect.ymax); - CLAMP(max, rect.ymin, rect.ymax); - fdrawline(rect.xmin+2+w+c*2,min,rect.xmin+2+w+c*2,max); - } - } - else if (scopes->wavefrm_mode== SCOPES_WAVEFRM_YCC_709) { - for (c=0; c<3; c++) { - glColor3f(colorsycc[c][0]*0.75, colorsycc[c][1]*0.75, colorsycc[c][2]*0.75); - min= yofs+scopes->ycc709minmax[c][0]*h/255.0f; - max= yofs+scopes->ycc709minmax[c][1]*h/255.0f; - CLAMP(min, rect.ymin, rect.ymax); - CLAMP(max, rect.ymin, rect.ymax); - fdrawline(rect.xmin+2+w+c*2,min,rect.xmin+2+w+c*2,max); - } - } + else + glColor3f(colorsycc[c][0]*0.75, colorsycc[c][1]*0.75, colorsycc[c][2]*0.75); + min= yofs+scopes->minmax[c][0]*h; + max= yofs+scopes->minmax[c][1]*h; + CLAMP(min, rect.ymin, rect.ymax); + CLAMP(max, rect.ymin, rect.ymax); + fdrawline(rect.xmin+w+2+c*2,min,rect.xmin+w+2+c*2,max); } } - /* restore scissortest */ - glScissor(scissor[0], scissor[1], scissor[2], scissor[3]); - - glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA); - - /* height scaling widget */ - scaler_x1 = rect.xmin + w/2 - SCOPE_RESIZE_PAD; - scaler_x2 = rect.xmin + w/2 + SCOPE_RESIZE_PAD; - - glColor4f(0.f, 0.f, 0.f, 0.25f); - fdrawline(scaler_x1, rect.ymin-4, scaler_x2, rect.ymin-4); - fdrawline(scaler_x1, rect.ymin-7, scaler_x2, rect.ymin-7); - glColor4f(1.f, 1.f, 1.f, 0.25f); - fdrawline(scaler_x1, rect.ymin-5, scaler_x2, rect.ymin-5); - fdrawline(scaler_x1, rect.ymin-8, scaler_x2, rect.ymin-8); - - 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); + /* outline, scale gripper */ + draw_scope_end(&rect, scissor); } float polar_to_x(float center, float diam, float ampli, float angle) @@ -1076,18 +1023,14 @@ void ui_draw_but_VECTORSCOPE(ARegion *ar, uiBut *but, uiWidgetColors *wcol, rcti { Scopes *scopes = (Scopes *)but->poin; rctf rect; - int i, j, x, y; + int i, j; int skina= 123; /* angle in degree of the skin tone line */ float w, h, centerx, centery, diam; float alpha; float colors[6][3]={{.75,0,0},{.75,.75,0},{0,.75,0},{0,.75,.75},{0,0,.75},{.75,0,.75}}; - unsigned char *rc; - float *rf; GLint scissor[4]; - float u, v; - float scaler_x1, scaler_x2; - if (scopes==NULL || scopes->samples_ibuf==NULL) return; + if (scopes==NULL) return; rect.xmin = (float)recti->xmin+1; rect.xmax = (float)recti->xmax-1; @@ -1098,8 +1041,7 @@ void ui_draw_but_VECTORSCOPE(ARegion *ar, uiBut *but, uiWidgetColors *wcol, rcti h = rect.ymax - rect.ymin; centerx = rect.xmin + w/2; centery = rect.ymin + h/2; - diam= h; - if (wvecscope_alpha*scopes->vecscope_alpha*scopes->vecscope_alpha; @@ -1136,55 +1078,24 @@ void ui_draw_but_VECTORSCOPE(ARegion *ar, uiBut *but, uiWidgetColors *wcol, rcti /* saturation points */ for(i=0; i<6; i++) vectorscope_draw_target(centerx, centery, diam, colors[i][0], colors[i][1], colors[i][2]); - + /* pixel point cloud */ glBlendFunc(GL_ONE,GL_ONE); - glBegin(GL_POINTS); glColor4f(alpha, alpha, alpha, alpha); - if (scopes->samples_ibuf->rect_float) { - rf = scopes->samples_ibuf->rect_float; - for (y=0; ysamples_ibuf->y; y++) { - for (x=0; xsamples_ibuf->x; x++) { - u=-0.147f*rf[0] - 0.289f*rf[1] + 0.436f*rf[2]; - v= 0.615f*rf[0] - 0.515f*rf[1] - 0.100f*rf[2]; - glVertex2f(centerx+u*diam, centery+v*diam); - rf+=scopes->samples_ibuf->channels; - } - } - } - else if(scopes->samples_ibuf->rect) { - rc = (unsigned char *)(scopes->samples_ibuf->rect); - for (y=0; ysamples_ibuf->y; y++) { - for (x=0; xsamples_ibuf->x; x++) { - u=-0.147f*rc[0]/255.0f - 0.289f*rc[1]/255.0f + 0.436f*rc[2]/255.0f; - v= 0.615f*rc[0]/255.0f - 0.515f*rc[1]/255.0f - 0.100f*rc[2]/255.0f; - glVertex2f(centerx+u*diam, centery+v*diam); - rc+=4; - } - } - } - glEnd(); - - /* restore scissortest */ - glScissor(scissor[0], scissor[1], scissor[2], scissor[3]); - - glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA); - - /* height scaling widget */ - scaler_x1 = rect.xmin + w/2 - SCOPE_RESIZE_PAD; - scaler_x2 = rect.xmin + w/2 + SCOPE_RESIZE_PAD; + glPushMatrix(); + glEnableClientState(GL_VERTEX_ARRAY); - glColor4f(0.f, 0.f, 0.f, 0.25f); - fdrawline(scaler_x1, rect.ymin-4, scaler_x2, rect.ymin-4); - fdrawline(scaler_x1, rect.ymin-7, scaler_x2, rect.ymin-7); - glColor4f(1.f, 1.f, 1.f, 0.25f); - fdrawline(scaler_x1, rect.ymin-5, scaler_x2, rect.ymin-5); - fdrawline(scaler_x1, rect.ymin-8, scaler_x2, rect.ymin-8); + glTranslatef(centerx, centery, 0.f); + glScalef(diam, diam, 0.f); + glVertexPointer(2, GL_FLOAT, 0, scopes->vecscope); + glDrawArrays(GL_POINTS, 0, scopes->waveform_tot); - glColor4f(0.f, 0.f, 0.f, 0.5f); - uiSetRoundBox(15); - gl_round_box(GL_LINE_LOOP, rect.xmin-1, rect.ymin, rect.xmax+1, rect.ymax+1, 3.0f); + glDisableClientState(GL_VERTEX_ARRAY); + glPopMatrix(); + + /* outline, scale gripper */ + draw_scope_end(&rect, scissor); glDisable(GL_BLEND); } diff --git a/source/blender/makesdna/DNA_color_types.h b/source/blender/makesdna/DNA_color_types.h index dd31c349615..2881ec127c8 100644 --- a/source/blender/makesdna/DNA_color_types.h +++ b/source/blender/makesdna/DNA_color_types.h @@ -122,14 +122,12 @@ typedef struct Scopes { int wavefrm_height; float vecscope_alpha; int vecscope_height; - float rgbminmax[3][2]; - float yccminmax[3][2]; - float ycc709minmax[3][2]; - struct ImBuf *samples_ibuf; + float minmax[3][2]; struct Histogram hist; float *waveform_1; float *waveform_2; float *waveform_3; + float *vecscope; int waveform_tot; int pad; } Scopes;