void ColorSpace::LabtoRGB (CoImage* pIn, CoImage* pOut) { assert (pIn->GetType() == MAT_Tfloat); assert (pOut->GetType() == MAT_Tbyte); float* prL = pIn->m_matX.data.fl[0]; float* pra = pIn->m_matY.data.fl[0]; float* prb = pIn->m_matZ.data.fl[0]; BYTE* pbR = pOut->m_matX.data.ptr[0]; BYTE* pbG = pOut->m_matY.data.ptr[0]; BYTE* pbB = pOut->m_matZ.data.ptr[0]; for (int i = 0; i < pIn->GetHeight() * pIn->GetWidth(); i ++) { LabtoRGB(prL[i], pra[i], prb[i], &pbR[i], &pbG[i], &pbB[i]); } }
CGImageRef Image::createAbstraction(float stylization, uint quantization) { pixel4b *rgbPixels = (pixel4b *) CFDataGetMutableBytePtr(_data); // Convert from RGB to Lab colorspace to perform operations on lightness channel. RGBtoLab(rgbPixels, _pixels); // Initial bilateral filter. bilateral(); // Extract edges. pixel3f *edges = createEdges(stylization); // Additional bilateral filtering. bilateral(); bilateral(); // Quantize lightness channel. quantize(quantization); // Overlay edges. overlayEdges(edges); // Convert back to RGB colorspace. LabtoRGB(_pixels, rgbPixels); // Create an image from the modified data. CGContextRef context = CGBitmapContextCreate( rgbPixels, _width, _height, _bitsPerComponent, _bytesPerRow, _colorSpaceRef, _bitmapInfo ); CGImageRef image = CGBitmapContextCreateImage(context); delete[] edges; return image; }