inline value_type convert(const value_type& v, ColorSpaceType input, ColorSpaceType output) {
			if (input == ColorSpaceRGB) {
				if (output == ColorSpaceRGB) return v;
				if (output == ColorSpaceYUV) return rgb_to_yuv(v);
				if (output == ColorSpaceLAB) return rgb_to_lab(v);
			}
			if (input == ColorSpaceYUV) {
				if (output == ColorSpaceRGB) return yuv_to_rgb(v);
				if (output == ColorSpaceYUV) return v;
				if (output == ColorSpaceLAB) return yuv_to_lab(v);
			}
			if (input == ColorSpaceLAB) {
				if (output == ColorSpaceRGB) return lab_to_rgb(v);
				if (output == ColorSpaceYUV) return lab_to_yuv(v);
				if (output == ColorSpaceLAB) return v;
			}
			return value_type::Zero();
		}
Example #2
0
static gstack_t* rectify_rgb(grd5_grad_custom_t* gradc, pssvg_opt_t opt)
{
  grd5_colour_stop_t *grd5_stop = gradc->colour.stops;
  int n = gradc->colour.n;

  if (n<2)
    {
      btrace("input (grd5) has %i rgb stop(s)", n);
      return NULL;
    }

  for (int i = 0 ; i < n ; i++)
    {
      grd5_colour_stop_t *stop = grd5_stop + i;

      switch(stop->type)
	{
	case GRD5_MODEL_RGB:
	  break;

	case GRD5_MODEL_GRSC:
	  grsc_to_rgb(stop);
	  break;

	case GRD5_MODEL_HSB:
	  hsb_to_rgb(stop);
	  break;

	case GRD5_MODEL_CMYC:
	  cmyc_to_rgb(stop);
	  break;

	case GRD5_MODEL_LAB:
	  lab_to_rgb(stop);
	  break;

	case GRD5_MODEL_BCKC:
	  stop->u.rgb.Rd  = opt.bg.red;
	  stop->u.rgb.Grn = opt.bg.green;
	  stop->u.rgb.Bl  = opt.bg.blue;
	  stop->type = GRD5_MODEL_RGB;
	  break;

	case GRD5_MODEL_FRGC:
	  stop->u.rgb.Rd  = opt.fg.red;
	  stop->u.rgb.Grn = opt.fg.green;
	  stop->u.rgb.Bl  = opt.fg.blue;
	  stop->type = GRD5_MODEL_RGB;
	  break;

	case GRD5_MODEL_BOOK:
	  btrace("stop %i (book colour) not converted", i);
	  return NULL;

	default:
	  btrace("stop %i unknown colour type %i", i, stop->type);
	  return NULL;
	}

      if (stop->type != GRD5_MODEL_RGB)
	{
	  btrace("stop %i is non-RGB (type %i)", i, stop->type);
	  return NULL;
	}
    }

  gstack_t *stack = gstack_new(sizeof(rgb_stop_t), 2*n, n);

  if (stack != NULL)
    {
      if (rectify_rgb2(gradc, stack, opt) == 0)
	return stack;

      gstack_destroy(stack);
    }

  return NULL;
}
		inline value_type lab_to_yuv(const value_type& v) {
			return rgb_to_yuv(lab_to_rgb(v));
		}
Example #4
0
 rgb_color& from_lab(const color_lab& lab) {
     lab_to_rgb(lab, this);
     return *this;
 }