use an inline function for rgb -> bw conversion.

This commit is contained in:
2012-06-22 07:49:44 +00:00
parent ec3399efa6
commit 226c86ae58
12 changed files with 26 additions and 26 deletions

View File

@@ -2396,7 +2396,7 @@ int BKE_tracking_context_step(MovieTrackingContext *context)
ImBuf *destination_ibuf;
int frame_delta = context->backwards ? -1 : 1;
int curfra = BKE_movieclip_remap_scene_to_clip_frame(context->clip, context->user.framenr);
int nextfra;
/* int nextfra; */ /* UNUSED */
int a, ok = FALSE, map_size;
int frame_width, frame_height;
@@ -2414,7 +2414,7 @@ int BKE_tracking_context_step(MovieTrackingContext *context)
if (!destination_ibuf)
return FALSE;
nextfra = curfra + frame_delta;
/* nextfra = curfra + frame_delta; */ /* UNUSED */
frame_width = destination_ibuf->x;
frame_height = destination_ibuf->y;

View File

@@ -222,6 +222,12 @@ MINLINE void cpack_cpy_3ub(unsigned char r_col[3], const unsigned int pack)
r_col[2] = ((pack) >> 16) & 0xFF;
}
/* XXX - investigate when/why rgb_to_bw & rgb_to_grayscale are different,
* and why we use both! whats the purpose of this? */
MINLINE float rgb_to_bw(const float rgb[3])
{
return 0.35f * rgb[0] + 0.45f * rgb[1] + 0.2f * rgb[2];
}
MINLINE float rgb_to_grayscale(const float rgb[3])
{

View File

@@ -97,7 +97,7 @@ void CalculateMeanOperation::calculateMean(MemoryBuffer *tile)
{
case 1:
{
sum += buffer[offset] * 0.35f + buffer[offset + 1] * 0.45f + buffer[offset + 2] * 0.2f;
sum += rgb_to_bw(&buffer[offset]);
break;
}
case 2:

View File

@@ -56,7 +56,7 @@ void *CalculateStandardDeviationOperation::initializeTileData(rcti *rect, Memory
{
case 1:
{
float value = buffer[offset] * 0.35f + buffer[offset + 1] * 0.45f + buffer[offset + 2] * 0.2f;
float value = rgb_to_bw(&buffer[offset]);
sum += (value - mean) * (value - mean);
break;
}

View File

@@ -38,7 +38,7 @@ void ConvertColorToBWOperation::executePixel(float *outputValue, float x, float
{
float inputColor[4];
inputOperation->read(&inputColor[0], x, y, sampler, inputBuffers);
outputValue[0] = inputColor[0] * 0.35f + inputColor[1] * 0.45f + inputColor[2] * 0.2f;
outputValue[0] = rgb_to_bw(inputColor);
}
void ConvertColorToBWOperation::deinitExecution()

View File

@@ -1438,7 +1438,7 @@ void ui_draw_but_CURVE(ARegion *ar, uiBut *but, uiWidgetColors *wcol, rcti *rect
glEnd();
}
else if (cumap->cur == 3) {
float lum = cumap->sample[0] * 0.35f + cumap->sample[1] * 0.45f + cumap->sample[2] * 0.2f;
float lum = rgb_to_bw(cumap->sample);
glColor3ub(240, 240, 240);
glBegin(GL_LINES);

View File

@@ -207,7 +207,7 @@ void typecheck_compbuf_color(float *out, float *in, int outtype, int intype)
*out= 0.333333f*(in[0]+in[1]+in[2]);
}
else if (intype==CB_RGBA) {
*out= in[0]*0.35f + in[1]*0.45f + in[2]*0.2f;
*out = rgb_to_bw(in);
}
}
else if (outtype==CB_VEC2) {
@@ -300,7 +300,7 @@ CompBuf *typecheck_compbuf(CompBuf *inbuf, int type)
}
else if (inbuf->type==CB_RGBA) {
for (; x>0; x--, outrf+= 1, inrf+= 4)
*outrf= inrf[0]*0.35f + inrf[1]*0.45f + inrf[2]*0.2f;
*outrf = rgb_to_bw(inrf);
}
}
else if (type==CB_VEC2) {

View File

@@ -45,11 +45,6 @@ static bNodeSocketTemplate cmp_node_view_levels_out[]={
{-1, 0, ""}
};
static void rgb_tobw(float r, float g, float b, float* out)
{
*out= r*0.35f + g*0.45f + b*0.2f;
}
static void fill_bins(bNode* node, CompBuf* in, int* bins)
{
float value[4];
@@ -66,7 +61,7 @@ static void fill_bins(bNode* node, CompBuf* in, int* bins)
if (value[3] > 0.0f) { /* don't count transparent pixels */
switch (node->custom1) {
case 1: { /* all colors */
rgb_tobw(value[0], value[1], value[2], &value[0]);
value[0] = rgb_to_bw(value);
value[0]=value[0]*255; /* scale to 0-255 range */
ivalue=(int)value[0];
break;
@@ -125,7 +120,7 @@ static float brightness_mean(bNode* node, CompBuf* in)
switch (node->custom1) {
case 1:
{
rgb_tobw(value[0], value[1], value[2], &value[0]);
value[0] = rgb_to_bw(value);
sum+=value[0];
break;
}
@@ -176,7 +171,7 @@ static float brightness_standard_deviation(bNode* node, CompBuf* in, float mean)
switch (node->custom1) {
case 1:
{
rgb_tobw(value[0], value[1], value[2], &value[0]);
value[0] = rgb_to_bw(value);
sum+=(value[0]-mean)*(value[0]-mean);
break;
}

View File

@@ -111,7 +111,7 @@ static bNodeSocketTemplate cmp_node_rgbtobw_out[]= {
static void do_rgbtobw(bNode *UNUSED(node), float *out, float *in)
{
out[0]= in[0]*0.35f + in[1]*0.45f + in[2]*0.2f;
out[0] = rgb_to_bw(in);
}
static void node_composit_exec_rgbtobw(void *UNUSED(data), bNode *node, bNodeStack **in, bNodeStack **out)

View File

@@ -104,7 +104,7 @@ static void node_shader_exec_rgbtobw(void *UNUSED(data), bNode *UNUSED(node), bN
/* stack order out: bw */
/* stack order in: col */
out[0]->vec[0]= in[0]->vec[0]*0.35f + in[0]->vec[1]*0.45f + in[0]->vec[2]*0.2f;
out[0]->vec[0] = rgb_to_bw(in[0]->vec);
}
static int gpu_shader_rgbtobw(GPUMaterial *mat, bNode *UNUSED(node), GPUNodeStack *in, GPUNodeStack *out)

View File

@@ -91,8 +91,7 @@ static void rgbtobw_valuefn(float *out, TexParams *p, bNode *UNUSED(node), bNode
{
float cin[4];
tex_input_rgba(cin, in[0], p, thread);
*out = cin[0] * 0.35f + cin[1] * 0.45f + cin[2] * 0.2f;
*out = rgb_to_bw(cin);
}
static void rgbtobw_exec(void *data, bNode *node, bNodeStack **in, bNodeStack **out)

View File

@@ -2852,7 +2852,7 @@ void do_halo_tex(HaloRen *har, float xn, float yn, float col_r[4])
/* texture output */
if (rgb && (mtex->texflag & MTEX_RGBTOINT)) {
texres.tin= (0.35f*texres.tr+0.45f*texres.tg+0.2f*texres.tb);
texres.tin = rgb_to_bw(&texres.tr);
rgb= 0;
}
if (mtex->texflag & MTEX_NEGATIVE) {
@@ -2919,7 +2919,7 @@ void do_halo_tex(HaloRen *har, float xn, float yn, float col_r[4])
if (mtex->mapto & MAP_ALPHA) {
if (rgb) {
if (texres.talpha) texres.tin= texres.ta;
else texres.tin= (0.35f*texres.tr+0.45f*texres.tg+0.2f*texres.tb);
else texres.tin = rgb_to_bw(&texres.tr);
}
col_r[3]*= texres.tin;
@@ -3051,7 +3051,7 @@ void do_sky_tex(const float rco[3], float lo[3], const float dxyview[2], float h
/* texture output */
if (rgb && (mtex->texflag & MTEX_RGBTOINT)) {
texres.tin= (0.35f*texres.tr+0.45f*texres.tg+0.2f*texres.tb);
texres.tin = rgb_to_bw(&texres.tr);
rgb= 0;
}
if (mtex->texflag & MTEX_NEGATIVE) {
@@ -3124,7 +3124,7 @@ void do_sky_tex(const float rco[3], float lo[3], const float dxyview[2], float h
}
}
if (mtex->mapto & WOMAP_BLEND) {
if (rgb) texres.tin= (0.35f*texres.tr+0.45f*texres.tg+0.2f*texres.tb);
if (rgb) texres.tin = rgb_to_bw(&texres.tr);
*blend= texture_value_blend(mtex->def_var, *blend, texres.tin, mtex->blendfac, mtex->blendtype);
}
@@ -3264,7 +3264,7 @@ void do_lamp_tex(LampRen *la, const float lavec[3], ShadeInput *shi, float col_r
/* texture output */
if (rgb && (mtex->texflag & MTEX_RGBTOINT)) {
texres.tin= (0.35f*texres.tr+0.45f*texres.tg+0.2f*texres.tb);
texres.tin = rgb_to_bw(&texres.tr);
rgb= 0;
}
if (mtex->texflag & MTEX_NEGATIVE) {
@@ -3358,7 +3358,7 @@ int externtex(MTex *mtex, const float vec[3], float *tin, float *tr, float *tg,
rgb= multitex(tex, texvec, dxt, dyt, 0, &texr, thread, mtex->which_output);
if (rgb) {
texr.tin= (0.35f*texr.tr+0.45f*texr.tg+0.2f*texr.tb);
texr.tin = rgb_to_bw(&texr.tr);
}
else {
texr.tr= mtex->r;