Beispiel #1
0
void MixValueOperation::executePixelSampled(float output[4],
                                            float x,
                                            float y,
                                            PixelSampler sampler)
{
  float inputColor1[4];
  float inputColor2[4];
  float inputValue[4];

  this->m_inputValueOperation->readSampled(inputValue, x, y, sampler);
  this->m_inputColor1Operation->readSampled(inputColor1, x, y, sampler);
  this->m_inputColor2Operation->readSampled(inputColor2, x, y, sampler);

  float value = inputValue[0];
  if (this->useValueAlphaMultiply()) {
    value *= inputColor2[3];
  }
  float valuem = 1.0f - value;

  float rH, rS, rV;
  float colH, colS, colV;
  rgb_to_hsv(inputColor1[0], inputColor1[1], inputColor1[2], &rH, &rS, &rV);
  rgb_to_hsv(inputColor2[0], inputColor2[1], inputColor2[2], &colH, &colS, &colV);
  hsv_to_rgb(rH, rS, (valuem * rV + value * colV), &output[0], &output[1], &output[2]);
  output[3] = inputColor1[3];

  clampIfNeeded(output);
}
Beispiel #2
0
uint32 TweenerALLHSV( uint16_t count, uint32 from,uint32 to,uint32 delay) 
{
    int i;
	
	led_color frgb,trgb;
    hsv_color  src, target,result;

	trgb.rgb = to;
	frgb.rgb = from;
	
	src = rgb_to_hsv( frgb ) ;
	target = rgb_to_hsv( trgb );

	result = src;
	
    for( i = 1 ; i < count; i ++ )
    {
        result.h.h = TweenU8toU8(src.h.h, target.h.h, i);
        
      	StripLights_DisplayClearHSV( result );
		
		if(delay){
			CyDelay( delay );
		}
		
        BOOT_CHECK();    
    }
	return result.hsv;
}
Beispiel #3
0
void MixHueOperation::executePixelSampled(float output[4], float x, float y, PixelSampler sampler)
{
  float inputColor1[4];
  float inputColor2[4];
  float inputValue[4];

  this->m_inputValueOperation->readSampled(inputValue, x, y, sampler);
  this->m_inputColor1Operation->readSampled(inputColor1, x, y, sampler);
  this->m_inputColor2Operation->readSampled(inputColor2, x, y, sampler);

  float value = inputValue[0];
  if (this->useValueAlphaMultiply()) {
    value *= inputColor2[3];
  }
  float valuem = 1.0f - value;

  float colH, colS, colV;
  rgb_to_hsv(inputColor2[0], inputColor2[1], inputColor2[2], &colH, &colS, &colV);
  if (colS != 0.0f) {
    float rH, rS, rV;
    float tmpr, tmpg, tmpb;
    rgb_to_hsv(inputColor1[0], inputColor1[1], inputColor1[2], &rH, &rS, &rV);
    hsv_to_rgb(colH, rS, rV, &tmpr, &tmpg, &tmpb);
    output[0] = valuem * (inputColor1[0]) + value * tmpr;
    output[1] = valuem * (inputColor1[1]) + value * tmpg;
    output[2] = valuem * (inputColor1[2]) + value * tmpb;
  }
  else {
    copy_v3_v3(output, inputColor1);
  }
  output[3] = inputColor1[3];

  clampIfNeeded(output);
}
Beispiel #4
0
void worm::render_flip(BITMAP* where, int frame, int _x, int _y)
{
  int r,g,c,R,G,B,i;
  float h1,s1,v1,h,s,v;
  for (i=0;i<skin->img[frame]->w;i++)
  {
    for (r=0;r<skin->img[frame]->h;r++)
    {
      g=getpixel(skin->img[frame],i,r);
      c=getpixel(mask->img[frame],i,r);
      if(g!=makecol(255,0,255))
      {
        if(c!=makecol(255,0,255))
        {
          c=color;
          rgb_to_hsv(getr(c), getg(c), getb(c), &h1, &s1, &v1);
          
          R = getr(g);
          G = getg(g);
          B = getb(g);
          
          rgb_to_hsv(R, G, B, &h, &s, &v);
          h = h1;
          s = s1;
          v -= (1-v1)/1.4;
          if (v<0)v=0;
          
          hsv_to_rgb(h,s,v, &R, &G, &B);
          g = makecol(R,G,B);
          putpixel(where,_x+skin->img[frame]->w-1-i,_y+r,g);
        }else putpixel(where,_x+skin->img[frame]->w-1-i,_y+r,g);
      };
    };
  };
};
Beispiel #5
0
void FadeToColor( uint16_t startx, uint16_t count, uint32 target, uint32 delay, int direction)
{
    int j,i;
	int offset,oldoffset;

	led_color frgb,trgb;
    hsv_color  src,target_hsv,result;

	frgb.rgb = target;

	src = rgb_to_hsv( frgb ) ;

	offset = startx;

	for ( j = 0 ; j < 100 ; j ++ ) {
		
		oldoffset = offset;		
		
	    for( i = 0 ; i < count; i ++ ){
			
			// get colour of current LED at offset
			trgb.rgb = StripLights_GetPixel(offset,0);

			// convert current led color to hsv
			target_hsv = rgb_to_hsv( trgb );
			
			result = target_hsv;
			// tween, what we want to  what it is at percentage i
			result.h.h = TweenU8toU8( target_hsv.h.h, src.h.h, j );
			
			// update pixel
	      	StripLights_PixelHSV(offset, 0, result );
			
			// handle travel direction of pixel
			offset += direction;
			if (offset < (int)StripLights_MIN_X ) offset = startx ;
			if (offset > startx+count ) offset = StripLights_MIN_X ;
	      	
		}
		
		// check bootloader mode
        BOOT_CHECK();    
		
		// if wants a delay, update led strip and delay
		if(delay) {
   			while( StripLights_Ready() == 0);

			StripLights_Trigger(1);
			CyDelay( delay );
		}
			
		offset = oldoffset;		

	}	
}
Beispiel #6
0
uint32 TweenerHSV( uint16_t startx, uint16_t count, uint32 from,uint32 to,uint32 delay,int direction) 
{
    int i;
	int offset;
	led_color frgb,trgb;
    hsv_color  src, target,result;

	trgb.rgb = to;
	frgb.rgb = from;
	
	src = rgb_to_hsv( frgb ) ;
	target = rgb_to_hsv( trgb );

	result = src;
	
	offset = startx;
	
    for( i = 1 ; i < count; i ++ )
    {
        result.h.h = TweenU8toU8(src.h.h, target.h.h, i);
        
      	StripLights_PixelHSV(offset, 0, result );
		
		offset += direction;
		
		if (offset < (int)StripLights_MIN_X ) offset = startx ;
		if (offset > startx+count ) offset = StripLights_MIN_X ;
      	
        BOOT_CHECK();    
		
		if(delay) {
   			while( StripLights_Ready() == 0);

			StripLights_Trigger(1);
			CyDelay( delay );
		}
		
    }
		    
   while( StripLights_Ready() == 0);

	StripLights_Trigger(1);

   CyDelay( 5 );


	return result.hsv;
}
Beispiel #7
0
/* set up the colormap */
static void setupColormap (struct state *st, XWindowAttributes *xgwa)
{
    int n;
    XGCValues gcv;
    XColor *colors = (XColor *) calloc (sizeof (XColor), st->colorCount + 1);

    unsigned short r, g, b;
    int h1, h2;
    double s1, s2, v1, v2;

    r = RAND_FLOAT_01 * 0x10000;
    g = RAND_FLOAT_01 * 0x10000;
    b = RAND_FLOAT_01 * 0x10000;
    rgb_to_hsv (r, g, b, &h1, &s1, &v1);
    v1 = 1.0;
    s1 = 1.0;

    r = RAND_FLOAT_01 * 0x10000;
    g = RAND_FLOAT_01 * 0x10000;
    b = RAND_FLOAT_01 * 0x10000;
    rgb_to_hsv (r, g, b, &h2, &s2, &v2);
    s2 = 0.7;
    v2 = 0.7;
    
    colors[0].pixel = get_pixel_resource (st->dpy, xgwa->colormap,
                                          "background", "Background");
    
    make_color_ramp (xgwa->screen, xgwa->visual, xgwa->colormap,
                     h1, s1, v1, h2, s2, v2,
		     colors + 1, &st->colorCount, False, True, False);

    if (st->colorCount < 1)
    {
        fprintf (stderr, "%s: couldn't allocate any colors\n", progname);
	exit (-1);
    }
    
    st->gcs = (GC *) calloc (sizeof (GC), st->colorCount + 1);

    for (n = 0; n <= st->colorCount; n++) 
    {
	gcv.foreground = colors[n].pixel;
	gcv.line_width = st->lineWidth;
	st->gcs[n] = XCreateGC (st->dpy, st->window, GCForeground | GCLineWidth, &gcv);
    }

    free (colors);
}
static void get_color (gint i, gfloat * r, gfloat * g, gfloat * b)
{
    static GdkRGBA c;
    static bool_t valid = FALSE;
    gfloat h, s, v, n;

    if (! valid)
    {
        /* we want a color that matches the current theme
         * selected color of a GtkEntry should be reasonable */
        GtkStyleContext * style = gtk_style_context_new ();
        GtkWidgetPath * path = gtk_widget_path_new ();
        gtk_widget_path_append_type (path, GTK_TYPE_ENTRY);
        gtk_style_context_set_path (style, path);
        gtk_widget_path_free (path);
        gtk_style_context_get_background_color (style, GTK_STATE_FLAG_SELECTED, & c);
        g_object_unref (style);
        valid = TRUE;
    }

    rgb_to_hsv (c.red, c.green, c.blue, & h, & s, & v);

    if (s < 0.1) /* monochrome theme? use blue instead */
    {
        h = 5;
        s = 0.75;
    }

    n = i / (gfloat) (bands - 1);
    s = 1 - 0.9 * n;
    v = 0.75 + 0.25 * n;

    hsv_to_rgb (h, s, v, r, g, b);
}
Beispiel #9
0
static void do_huecorrect(bNode *node, float *out, float *in)
{
	float hsv[3], f;
	
	rgb_to_hsv(in[0], in[1], in[2], hsv, hsv+1, hsv+2);
	
	/* adjust hue, scaling returned default 0.5 up to 1 */
	f = curvemapping_evaluateF(node->storage, 0, hsv[0]);
	hsv[0] += f-0.5f;
	
	/* adjust saturation, scaling returned default 0.5 up to 1 */
	f = curvemapping_evaluateF(node->storage, 1, hsv[0]);
	hsv[1] *= (f * 2.f);
	
	/* adjust value, scaling returned default 0.5 up to 1 */
	f = curvemapping_evaluateF(node->storage, 2, hsv[0]);
	hsv[2] *= (f * 2.f);
	
	hsv[0] = hsv[0] - floor(hsv[0]); /* mod 1.0 */
	CLAMP(hsv[1], 0.f, 1.f);
	
	/* convert back to rgb */
	hsv_to_rgb(hsv[0], hsv[1], hsv[2], out, out+1, out+2);
	
	out[3]= in[3];
}
Beispiel #10
0
static void
gtk_plot_surface_lighting (GdkColor *a, GdkColor *b, 
                           gdouble normal, gdouble ambient)
{
  gdouble red, green, blue;
  gdouble h, s, v;

  if(normal == 1.0){
   *b = *a;
   return;
  }

  normal = MIN(fabs(normal), 1.0);

  red = a->red;
  green = a->green;
  blue = a->blue;

  rgb_to_hsv(red, green, blue, &h, &s, &v);

  s *= normal;
  v *= normal;

  s += ambient;
  v += ambient;

  hsv_to_rgb(h, MIN(s, 1.0), MIN(v, 1.0), &red, &green, &blue);

  b->red = red;
  b->green = green;
  b->blue = blue;
}
Beispiel #11
0
static void do_huecorrect_fac(bNode *node, float *out, float *in, float *fac)
{
	float hsv[3], rgb[3], f;
	const float mfac = 1.f-*fac;
	
	rgb_to_hsv(in[0], in[1], in[2], hsv, hsv+1, hsv+2);
	
	/* adjust hue, scaling returned default 0.5 up to 1 */
	f = curvemapping_evaluateF(node->storage, 0, hsv[0]);
	hsv[0] += f-0.5f;
	
	/* adjust saturation, scaling returned default 0.5 up to 1 */
	f = curvemapping_evaluateF(node->storage, 1, hsv[0]);
	hsv[1] *= (f * 2.f);
	
	/* adjust value, scaling returned default 0.5 up to 1 */
	f = curvemapping_evaluateF(node->storage, 2, hsv[0]);
	hsv[2] *= (f * 2.f);
	
	hsv[0] = hsv[0] - floor(hsv[0]);  /* mod 1.0 */
	CLAMP(hsv[1], 0.f, 1.f);
	
	/* convert back to rgb */
	hsv_to_rgb(hsv[0], hsv[1], hsv[2], rgb, rgb+1, rgb+2);
	
	out[0]= mfac*in[0] + *fac*rgb[0];
	out[1]= mfac*in[1] + *fac*rgb[1];
	out[2]= mfac*in[2] + *fac*rgb[2];
	out[3]= in[3];
}
Beispiel #12
0
void exposure_image(image im, float sat)
{
    rgb_to_hsv(im);
    scale_image_channel(im, 2, sat);
    hsv_to_rgb(im);
    constrain_image(im);
}
Beispiel #13
0
void saturate_image(image im, float sat)
{
    rgb_to_hsv(im);
    scale_image_channel(im, 1, sat);
    hsv_to_rgb(im);
    constrain_image(im);
}
Beispiel #14
0
	void		setTo(const gif::Palette &pal) override {
		mColors.clear();
		for (const auto& c : pal.mColors) {
			HSV			hsv;
			rgb_to_hsv(c, hsv.h, hsv.s, hsv.v);
			mColors.push_back(Lookup(hsv, c));
		}
	}
Beispiel #15
0
unsigned char getBright(unsigned short color)
{
	float h,s,v;

	rgb_to_hsv(GET16R(color),GET16G(color),GET16B(color),&h,&s,&v);

	return v*255;
}
Beispiel #16
0
unsigned char getBright(unsigned int color)
{
	float h,s,v;

	rgb_to_hsv(GET32R(color),GET32G(color),GET32B(color),&h,&s,&v);

	return v*255;
}
Beispiel #17
0
byte V_Colorize (byte *playpal, int cr, byte source, boolean keepgray109)
{
    vect rgb, hsv;

    // [crispy] preserve gray drop shadow in IWAD status bar numbers
    if (cr == CR_NONE || (keepgray109 && source == 109))
	return source;

    rgb.x = playpal[3 * source + 0] / 255.;
    rgb.y = playpal[3 * source + 1] / 255.;
    rgb.z = playpal[3 * source + 2] / 255.;

    rgb_to_hsv(&rgb, &hsv);

    if (cr == CR_DARK)
	hsv.z *= 0.5;
    else
    if (cr == CR_GRAY)
	hsv.y = 0;
    else
    {
	// [crispy] hack colors to full saturation
	hsv.y = 1.0;

	if (cr == CR_GREEN)
	{
//	    hsv.x = 135./360.;
	    hsv.x = (150. * hsv.z + 120. * (1. - hsv.z))/360.;
	}
	else
	if (cr == CR_GOLD)
	{
//	    hsv.x = 45./360.;
//	    hsv.x = (50. * hsv.z + 30. * (1. - hsv.z))/360.;
	    hsv.x = (7.0 + 53. * hsv.z)/360.;
	    hsv.y = 1.0 - 0.4 * hsv.z;
	    hsv.z = 0.2 + 0.8 * hsv.z;
	}
	else
	if (cr == CR_RED)
	{
	    hsv.x = 0.;
	}
	else
	if (cr == CR_BLUE)
	{
	    hsv.x = 240./360.;
	}
    }

    hsv_to_rgb(&hsv, &rgb);

    rgb.x *= 255.;
    rgb.y *= 255.;
    rgb.z *= 255.;

    return I_GetPaletteIndex2(playpal, (int) rgb.x, (int) rgb.y, (int) rgb.z);
}
Beispiel #18
0
HSVControl::HSVControl(BPoint position, rgb_color c)
    :	VisualColorControl(position,c,"H","S","V","A")
{
    float red = value.bytes[2];
    float green = value.bytes[1];
    float blue = value.bytes[0];

    rgb_to_hsv(red,green,blue,&h_value,&s_value,&v_value);
}
Beispiel #19
0
byte V_Colorize (byte *playpal, int cr, byte source, boolean keepgray109)
{
    vect rgb, hsv;
    extern int FindNearestColor(byte *palette, int r, int g, int b);

    // [crispy] preserve gray drop shadow in IWAD status bar numbers
    if (cr == CR_NONE || (keepgray109 && source == 109))
	return source;

    rgb.x = playpal[3 * source + 0] / 255.;
    rgb.y = playpal[3 * source + 1] / 255.;
    rgb.z = playpal[3 * source + 2] / 255.;

    rgb_to_hsv(&rgb, &hsv);

    if (cr == CR_DARK)
	hsv.z *= 0.5;
    else
    if (cr == CR_GRAY)
	hsv.y = 0;
    else
    {
	// [crispy] hack colors to full saturation
	hsv.y = 1.0;

	if (cr == CR_GREEN)
	{
//	    hsv.x = ((16.216 * hsv.z) + 100.784)/360.;
	    hsv.x = 135./360.;
	}
	else
	if (cr == CR_GOLD)
	{
//	    hsv.x = ((51.351 * hsv.z) + 8.648)/360.;
	    hsv.x = 45./360.;
	}
	else
	if (cr == CR_RED)
	{
	    hsv.x = 0.;
	}
	else
	if (cr == CR_BLUE)
	{
	    hsv.x = 240./360.;
	}
    }

    hsv_to_rgb(&hsv, &rgb);

    rgb.x *= 255.;
    rgb.y *= 255.;
    rgb.z *= 255.;

    return FindNearestColor(playpal, (int) rgb.x, (int) rgb.y, (int) rgb.z);
}
Beispiel #20
0
int main(int argc, char* argv[]) {
    struct rgb_color rgb;
    struct hsv_color hsv;
    rgb.r = (unsigned char)atoi(argv[1]);
    rgb.g = (unsigned char)atoi(argv[2]);
    rgb.b = (unsigned char)atoi(argv[3]);
    hsv = rgb_to_hsv(rgb);
    printf("Hue: %d\nSaturation: %d\nValue: %d\n\n", hsv.hue, hsv.sat, hsv.val);
    return 0;
}
Beispiel #21
0
static void do_sephsva(bNode *UNUSED(node), float *out, float *in)
{
	float h, s, v;
	
	rgb_to_hsv(in[0], in[1], in[2], &h, &s, &v);
	
	out[0]= h;
	out[1]= s;
	out[2]= v;
	out[3]= in[3];
}
static PyObject *Color_channel_hsv_get(ColorObject *self, void *type)
{
	float hsv[3];
	int i = GET_INT_FROM_POINTER(type);

	if (BaseMath_ReadCallback(self) == -1)
		return NULL;

	rgb_to_hsv(self->col[0], self->col[1], self->col[2], &(hsv[0]), &(hsv[1]), &(hsv[2]));

	return PyFloat_FromDouble(hsv[i]);
}
Beispiel #23
0
static void hue_correct_apply_threaded(int width, int height, unsigned char *rect, float *rect_float,
                                unsigned char *mask_rect, float *mask_rect_float, void *data_v)
{
	CurveMapping *curve_mapping = (CurveMapping *) data_v;
	int x, y;

	for (y = 0; y < height; y++) {
		for (x = 0; x < width; x++) {
			int pixel_index = (y * width + x) * 4;
			float pixel[3], result[3], mask[3] = {1.0f, 1.0f, 1.0f};
			float hsv[3], f;

			if (rect_float)
				copy_v3_v3(pixel, rect_float + pixel_index);
			else
				rgb_uchar_to_float(pixel, rect + pixel_index);

			rgb_to_hsv(pixel[0], pixel[1], pixel[2], hsv, hsv + 1, hsv + 2);

			/* adjust hue, scaling returned default 0.5 up to 1 */
			f = curvemapping_evaluateF(curve_mapping, 0, hsv[0]);
			hsv[0] += f - 0.5f;

			/* adjust saturation, scaling returned default 0.5 up to 1 */
			f = curvemapping_evaluateF(curve_mapping, 1, hsv[0]);
			hsv[1] *= (f * 2.0f);

			/* adjust value, scaling returned default 0.5 up to 1 */
			f = curvemapping_evaluateF(curve_mapping, 2, hsv[0]);
			hsv[2] *= (f * 2.f);

			hsv[0] = hsv[0] - floorf(hsv[0]); /* mod 1.0 */
			CLAMP(hsv[1], 0.0f, 1.0f);

			/* convert back to rgb */
			hsv_to_rgb(hsv[0], hsv[1], hsv[2], result, result + 1, result + 2);

			if (mask_rect_float)
				copy_v3_v3(mask, mask_rect_float + pixel_index);
			else if (mask_rect)
				rgb_uchar_to_float(mask, mask_rect + pixel_index);

			result[0] = pixel[0] * (1.0f - mask[0]) + result[0] * mask[0];
			result[1] = pixel[1] * (1.0f - mask[1]) + result[1] * mask[1];
			result[2] = pixel[2] * (1.0f - mask[2]) + result[2] * mask[2];

			if (rect_float)
				copy_v3_v3(rect_float + pixel_index, result);
			else
				rgb_float_to_uchar(rect + pixel_index, result);
		}
	}
}
Beispiel #24
0
void HSVControl::SetValue(int32 val)
{
    value.word = val;
    float red = value.bytes[2];
    float green = value.bytes[1];
    float blue = value.bytes[0];

    rgb_to_hsv(red,green,blue,&h_value,&s_value,&v_value);

    CalcRamps();
    Draw(Bounds());
}
Beispiel #25
0
unsigned int changeBright(unsigned int color,unsigned char bright)
{
	float h,s,v;
	int r,g,b;

	rgb_to_hsv(GET32R(color),GET32G(color),GET32B(color),&h,&s,&v);
	v=(float)bright/255.0;
	hsv_to_rgb(h,s,v,&r,&g,&b);

	return REFC32(r,g,b);

}
Beispiel #26
0
struct hsv_color pointit_get_color(int x, int y) {
    struct rgb_color rgb;
    
    /* Mirrored x */
    int mx = abs(cam_width - x);

    rgb.r = rgb_img[(mx * 3) + (y * cam_width * 3)];
    rgb.g = rgb_img[(mx * 3) + (y * cam_width * 3) + 1];
    rgb.b = rgb_img[(mx * 3) + (y * cam_width * 3) + 2];

    return rgb_to_hsv(rgb);
}
Beispiel #27
0
static void calc_hsv_image_from_bgra(hsv_color_t *hsv, uint8_t *img, int pitch, int width, int height) {
  pitch *= 4;
  while (height--) {
    uint8_t *i = img;
    int w = width;
    while (w--) {
      rgb_to_hsv(hsv, i[2], i[1], i[0]);
      ++hsv;
      i += 4;
    }
    img += pitch;
  }
}
Beispiel #28
0
static void
color_rotate (GeglProperties *o,
              gfloat         *input,
              gfloat         *output)
{
  gfloat   h, s, v;
  gboolean skip = FALSE;

  rgb_to_hsv (input[0], input[1], input[2],
              &h, &s, &v);

  if (is_gray (s, o->threshold))
    {
      if (o->gray_mode == GEGL_COLOR_ROTATE_GRAY_TREAT_AS)
        {
          if (angle_inside_slice (o->hue, o->src_from, o->src_to,
                                  o->src_clockwise) <= 1)
            {
              h = DEG_TO_RAD (o->hue) / TWO_PI;
              s = o->saturation;
            }
          else
            {
              skip = TRUE;
            }
        }
      else
        {
          skip = TRUE;

          h = DEG_TO_RAD (o->hue) / TWO_PI;
          s = o->saturation;
        }
    }

  if (! skip)
    {
      h = linear (left_end (o->src_from, o->src_to, o->src_clockwise),
                  right_end (o->src_from, o->src_to, o->src_clockwise),
                  left_end (o->dest_from, o->dest_to, o->dest_clockwise),
                  right_end (o->dest_from, o->dest_to, o->dest_clockwise),
                  h * TWO_PI);

      h = angle_mod_2PI (h) / TWO_PI;
    }

  hsv_to_rgb (h, s, v,
              output, output + 1, output + 2);
}
Beispiel #29
0
void shiftHSVExcept(GPU_Image* image, int hue, int saturation, int value, int notHue, int notSat, int notVal, int range)
{
    SDL_Surface* surface = GPU_CopySurfaceFromImage(image);
    Uint8* pixels = surface->pixels;
    
    int x,y,i;
	int r, g, b, h, s, v;
    for(y = 0; y < surface->h; y++)
    {
        for(x = 0; x < surface->w; x++)
        {
            i = y*surface->pitch + x*surface->format->BytesPerPixel;
            
            if(surface->format->BytesPerPixel == 4 && pixels[i+3] == 0)
                continue;

            r = pixels[i];
            g = pixels[i+1];
            b = pixels[i+2];
            rgb_to_hsv(r, g, b, &h, &s, &v);
            h += hue;
            s += saturation;
            v += value;
            // Wrap hue
            while(h < 0)
                h += 256;
            while(h > 255)
                h -= 256;

            // Clamp
            s = clamp(s, 0, 255);
            v = clamp(v, 0, 255);

            hsv_to_rgb(h, s, v, &r, &g, &b);
                        
            if(notHue - range <= h && notHue + range >= h
                    && notSat - range <= s && notSat + range >= s
                    && notVal - range <= v && notVal + range >= v)
                    continue;

            pixels[i] = r;
            pixels[i+1] = g;
            pixels[i+2] = b;
        }
    }
    
    GPU_UpdateImage(image, NULL, surface, NULL);
    SDL_FreeSurface(surface);
}
Beispiel #30
0
// rgb to hsv and back
pixel_t rgb_to_hsv( const pixel_t& src)
{
	Imath::Color3f c( boost::gil::get_color( src, boost::gil::red_t()),
						boost::gil::get_color( src, boost::gil::green_t()),
						boost::gil::get_color( src, boost::gil::blue_t()));

	c = rgb_to_hsv( c);

    pixel_t result;
    boost::gil::get_color( result, boost::gil::red_t())   = c.x;
    boost::gil::get_color( result, boost::gil::green_t()) = c.y;
    boost::gil::get_color( result, boost::gil::blue_t())  = c.z;
    boost::gil::get_color( result, boost::gil::alpha_t()) = boost::gil::get_color( src, boost::gil::alpha_t());
    return result;
}