示例#1
0
Image ColorConvert::apply(Image im, string from, string to) {
    // check for the trivial case
    assert(from != to, "color conversion from %s to %s is pointless\n", from.c_str(), to.c_str());

    // unsupported destination color spaces
    if (to == "yuyv" ||
        to == "uyvy") {
        panic("Unsupported destination color space: %s\n", to.c_str());
    }

    // direct conversions that don't have to go via rgb
    if (from == "yuyv" && to == "yuv") {
        return yuyv2yuv(im);
    } else if (from == "uyvy" && to == "yuv") {
        return uyvy2yuv(im);
    } else if (from == "xyz" && to == "lab") {
        return xyz2lab(im);
    } else if (from == "lab" && to == "xyz") {
        return lab2xyz(im);
    } else if (from == "argb" && to == "xyz") {
        return argb2xyz(im);
    } else if (from == "xyz" && to == "argb") {
        return xyz2argb(im);
    } else if (from != "rgb" && to != "rgb") {
        // conversions that go through rgb
        Image halfway = apply(im, from, "rgb");
        return apply(halfway, "rgb", to);
    } else if (from == "rgb") { // from rgb
        if (to == "hsv" || to == "hsl" || to == "hsb") {
            return rgb2hsv(im);
        } else if (to == "yuv") {
            return rgb2yuv(im);
        } else if (to == "xyz") {
            return rgb2xyz(im);
        } else if (to == "y" || to == "gray" ||
                   to == "grayscale" || to == "luminance") {
            return rgb2y(im);
        } else if (to == "lab") {
            return rgb2lab(im);
        } else if (to == "argb") {
            return rgb2argb(im);
        } else {
            panic("Unknown color space %s\n", to.c_str());
        }
    } else { //(to == "rgb")
        if (from == "hsv" || from == "hsl" || from == "hsb") {
            return hsv2rgb(im);
        } else if (from == "yuv") {
            return yuv2rgb(im);
        } else if (from == "xyz") {
            return xyz2rgb(im);
        } else if (from == "y" || from == "gray" ||
                   from == "grayscale" || from == "luminance") {
            return y2rgb(im);
        } else if (from == "lab") {
            return lab2rgb(im);
        } else if (from == "uyvy") {
            return uyvy2rgb(im);
        } else if (from == "yuyv") {
            return yuyv2rgb(im);
        } else if (from == "argb") {
            return argb2rgb(im);
        } else {
            panic("Unknown color space %s\n", from.c_str());
        }
    }

    // keep the compiler happy
    return Image();

}
示例#2
0
Image ColorConvert::rgb2lab(Image im) {
    assert(im.channels == 3, "Image does not have 3 channels\n");
    return xyz2lab(rgb2xyz(im));
}
示例#3
0
文件: square.c 项目: svkampen/square
double *rgb2lab(double arr[]) {
	double *xyz = rgb2xyz(arr);
	double *lab = xyz2lab(xyz);
	free(xyz);
	return lab;
}