Mailing Lists: Apple Mailing Lists
Image of Mac OS face in stamp
Fastest way to convert between RGB and Lab
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Fastest way to convert between RGB and Lab



Hello list,

I am working a bit with images and I need to perform some calculations
in Lab color space. For this reason I need to perform lots of
conversations between RGB and Lab.
Currently I am using ColorSync methods to achieve this:

<<<<< code snippet >>>>>
// source
        CMBitmap bm = {};
	bm.image = (char*)_rgbPixels;
	bm.width = _width;
	bm.height = _height;
	bm.rowBytes = bm.width*[_nsImageColorSpace numberOfColorComponents];
	bm.pixelSize = 8*[_nsImageColorSpace numberOfColorComponents];
	bm.space = cmRGB24Space;

// result
	CMBitmap bmrez = {};
	bmrez.image = (char*)_labPixels;
	bmrez.width = _width;
	bmrez.height = _height;
	bmrez.rowBytes = bmrez.width*[_nsLabColorSpace numberOfColorComponents];
	bmrez.pixelSize = 8*[_nsLabColorSpace numberOfColorComponents];
	bmrez.space = cmLAB24Space;


        CMError		err = noErr;
	CMWorldRef	localCW = nil;

	err = NCWNewColorWorld(&localCW, fromProfile, toProfile); ///
fromProfile  and toProfile are CMProfileRef vars

	if (localCW)
		err = CWMatchBitmap(localCW, bitmap, nil, nil, toBitmap);
	else
	{
		CMBitmap* dest = (toBitmap) ? toBitmap : bitmap;

		if (bitmap->image     != dest->image  &&
			bitmap->width     == dest->width  &&
			bitmap->height    == dest->height &&
			bitmap->rowBytes  == dest->rowBytes &&
			bitmap->pixelSize == dest->pixelSize &&
			bitmap->space     == dest->space)
			memmove(dest->image, bitmap->image, bitmap->rowBytes*bitmap->height);
		else
		{
			err = unimpErr; // too much work
		}
	}
<<<<<----------------------------->>>>>>>
This code works fine. But is very slow with a bit larger images. My
question would be - is there any way to convert RGB into Lab faster?

I have found a way to do this manually by converting RGB to XYZ (
http://www.brucelindbloom.com/index.html?Eqn_RGB_to_XYZ.html ) and
then XYZ to Lab (
http://www.brucelindbloom.com/index.html?Eqn_XYZ_to_Lab.html ). I
haven't tried this yet, because I do not know how to get required
constants from exact ICC profile (
http://www.brucelindbloom.com/index.html?Eqn_RGB_XYZ_Matrix.html ).

Any kind of help is very appreciate.

Regards,

Rimas M.
 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Colorsync-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2011 Apple Inc. All rights reserved.