Apply patch [#23755] Sequencer: small code cleanup using existing color math functions

By Luca Bonavita (mindrones)

From detailed description: This patch doesnt change functionality, but uses the existing color math functions from math_color.c into
sequencer_draw.c.
This commit is contained in:
Nathan Letwory 2010-09-15 11:58:19 +00:00
parent 8a25c33fca
commit d97d727d09
3 changed files with 52 additions and 34 deletions

@ -87,6 +87,9 @@ void linearrgb_to_srgb_rgba_rgba_buf(float *col_to, float *col_from, int tot);
int constrain_rgb(float *r, float *g, float *b);
void minmax_rgb(short c[3]);
void rgb_float_set_hue_float_offset(float * rgb, float hue_offset);
void rgb_byte_set_hue_float_offset(char * rgb, float hue_offset);
/***************** lift/gamma/gain / ASC-CDL conversion *****************/
void lift_gamma_gain_to_asc_cdl(float *lift, float *gamma, float *gain, float *offset, float *slope, float *power);

@ -464,3 +464,28 @@ void lift_gamma_gain_to_asc_cdl(float *lift, float *gamma, float *gain, float *o
}
}
/* ******************************************** other ************************************************* */
/* Applies an hue offset to a float rgb color */
void rgb_float_set_hue_float_offset(float rgb[3], float hue_offset)
{
float hsv[3];
rgb_to_hsv(rgb[0], rgb[1], rgb[2], hsv, hsv+1, hsv+2);
hsv[0]+= hue_offset;
if(hsv[0]>1.0) hsv[0]-=1.0;
else if(hsv[0]<0.0) hsv[0]+= 1.0;
hsv_to_rgb(hsv[0], hsv[1], hsv[2], rgb, rgb+1, rgb+2);
}
/* Applies an hue offset to a byte rgb color */
void rgb_byte_set_hue_float_offset(char rgb[3], float hue_offset)
{
float rgb_float[3];
rgb_byte_to_float(rgb, rgb_float);
rgb_float_set_hue_float_offset(rgb_float, hue_offset);
rgb_float_to_byte(rgb_float, rgb);
}

@ -75,19 +75,21 @@ static void draw_shadedstrip(Sequence *seq, char *col, float x1, float y1, float
static void get_seq_color3ubv(Scene *curscene, Sequence *seq, char *col)
{
char blendcol[3];
float hsv[3], rgb[3];
SolidColorVars *colvars = (SolidColorVars *)seq->effectdata;
switch(seq->type) {
case SEQ_IMAGE:
UI_GetThemeColor3ubv(TH_SEQ_IMAGE, col);
break;
case SEQ_META:
UI_GetThemeColor3ubv(TH_SEQ_META, col);
break;
case SEQ_MOVIE:
UI_GetThemeColor3ubv(TH_SEQ_MOVIE, col);
break;
case SEQ_SCENE:
UI_GetThemeColor3ubv(TH_SEQ_SCENE, col);
@ -100,19 +102,12 @@ static void get_seq_color3ubv(Scene *curscene, Sequence *seq, char *col)
case SEQ_CROSS:
case SEQ_GAMCROSS:
case SEQ_WIPE:
/* slightly offset hue to distinguish different effects */
UI_GetThemeColor3ubv(TH_SEQ_TRANSITION, col);
rgb[0] = col[0]/255.0; rgb[1] = col[1]/255.0; rgb[2] = col[2]/255.0;
rgb_to_hsv(rgb[0], rgb[1], rgb[2], hsv, hsv+1, hsv+2);
if (seq->type == SEQ_CROSS) hsv[0]+= 0.04;
if (seq->type == SEQ_GAMCROSS) hsv[0]+= 0.08;
if (seq->type == SEQ_WIPE) hsv[0]+= 0.12;
if(hsv[0]>1.0) hsv[0]-=1.0; else if(hsv[0]<0.0) hsv[0]+= 1.0;
hsv_to_rgb(hsv[0], hsv[1], hsv[2], rgb, rgb+1, rgb+2);
col[0] = (char)(rgb[0]*255); col[1] = (char)(rgb[1]*255); col[2] = (char)(rgb[2]*255);
/* slightly offset hue to distinguish different effects */
if (seq->type == SEQ_CROSS) rgb_byte_set_hue_float_offset(col,0.04);
if (seq->type == SEQ_GAMCROSS) rgb_byte_set_hue_float_offset(col,0.08);
if (seq->type == SEQ_WIPE) rgb_byte_set_hue_float_offset(col,0.12);
break;
/* effects */
@ -126,42 +121,37 @@ static void get_seq_color3ubv(Scene *curscene, Sequence *seq, char *col)
case SEQ_OVERDROP:
case SEQ_GLOW:
case SEQ_MULTICAM:
/* slightly offset hue to distinguish different effects */
UI_GetThemeColor3ubv(TH_SEQ_EFFECT, col);
rgb[0] = col[0]/255.0; rgb[1] = col[1]/255.0; rgb[2] = col[2]/255.0;
rgb_to_hsv(rgb[0], rgb[1], rgb[2], hsv, hsv+1, hsv+2);
if (seq->type == SEQ_ADD) hsv[0]+= 0.04;
if (seq->type == SEQ_SUB) hsv[0]+= 0.08;
if (seq->type == SEQ_MUL) hsv[0]+= 0.12;
if (seq->type == SEQ_ALPHAOVER) hsv[0]+= 0.16;
if (seq->type == SEQ_ALPHAUNDER) hsv[0]+= 0.20;
if (seq->type == SEQ_OVERDROP) hsv[0]+= 0.24;
if (seq->type == SEQ_GLOW) hsv[0]+= 0.28;
if (seq->type == SEQ_TRANSFORM) hsv[0]+= 0.36;
if(hsv[0]>1.0) hsv[0]-=1.0; else if(hsv[0]<0.0) hsv[0]+= 1.0;
hsv_to_rgb(hsv[0], hsv[1], hsv[2], rgb, rgb+1, rgb+2);
col[0] = (char)(rgb[0]*255); col[1] = (char)(rgb[1]*255); col[2] = (char)(rgb[2]*255);
/* slightly offset hue to distinguish different effects */
if (seq->type == SEQ_ADD) rgb_byte_set_hue_float_offset(col,0.04);
if (seq->type == SEQ_SUB) rgb_byte_set_hue_float_offset(col,0.08);
if (seq->type == SEQ_MUL) rgb_byte_set_hue_float_offset(col,0.12);
if (seq->type == SEQ_ALPHAOVER) rgb_byte_set_hue_float_offset(col,0.16);
if (seq->type == SEQ_ALPHAUNDER) rgb_byte_set_hue_float_offset(col,0.20);
if (seq->type == SEQ_OVERDROP) rgb_byte_set_hue_float_offset(col,0.24);
if (seq->type == SEQ_GLOW) rgb_byte_set_hue_float_offset(col,0.28);
if (seq->type == SEQ_TRANSFORM) rgb_byte_set_hue_float_offset(col,0.36);
break;
case SEQ_COLOR:
if (colvars->col) {
col[0]= (char)(colvars->col[0]*255);
col[1]= (char)(colvars->col[1]*255);
col[2]= (char)(colvars->col[2]*255);
rgb_float_to_byte(colvars->col, col);
} else {
col[0] = col[1] = col[2] = 128;
}
break;
case SEQ_PLUGIN:
UI_GetThemeColor3ubv(TH_SEQ_PLUGIN, col);
break;
case SEQ_SOUND:
UI_GetThemeColor3ubv(TH_SEQ_AUDIO, col);
blendcol[0] = blendcol[1] = blendcol[2] = 128;
if(seq->flag & SEQ_MUTE) UI_GetColorPtrBlendShade3ubv(col, blendcol, col, 0.5, 20);
break;
default:
col[0] = 10; col[1] = 255; col[2] = 40;
}