def cms_do_bitmap_transform(transform, image, in_mode, out_mode): """Provides PIL images support for color management. Currently supports L, RGB, CMYK and LAB modes only. :param transform: valid lcms transformation handle :param image: valid PIL image object :param in_mode: valid lcms or PIL mode :param out_mode: valid lcms or PIL mode :return: new PIL image object in out_mode colorspace """ if image.mode not in uc2const.IMAGE_COLORSPACES: raise CmsError('Unsupported image type: %s' % image.mode) if in_mode not in uc2const.IMAGE_COLORSPACES: raise CmsError('Unsupported in_mode type: %s' % in_mode) if out_mode not in uc2const.IMAGE_COLORSPACES: raise CmsError('unsupported out_mode type: %s' % out_mode) w, h = image.size image.load() new_image = Image.new(out_mode, (w, h)) _cms.transformBitmap(transform, image.im, new_image.im, w, h) return new_image
def cms_do_bitmap_transform(hTransform, inImage, inMode, outMode): """ The method provides PIL images support for color management. hTransform - a valid lcms transformation handle inImage - a valid PIL image object inMode, outMode - - predefined string constant (i.e. valid PIL mode) Currently supports L, RGB, CMYK and LAB modes only. Returns new PIL image object in outMode colorspace. """ if not inImage.mode in uc2const.IMAGE_COLORSPACES: raise CmsError, 'unsupported image type: %s' % inImage.mode if not inMode in uc2const.IMAGE_COLORSPACES: raise CmsError, 'unsupported inMode type: %s' % inMode if not outMode in uc2const.IMAGE_COLORSPACES: raise CmsError, 'unsupported outMode type: %s' % outMode w, h = inImage.size inImage.load() outImage = Image.new(outMode, (w, h)) _cms.transformBitmap(hTransform, inImage.im, outImage.im, w, h) return outImage
def cmsDoBitmapTransform(hTransform, inImage, inMode, outMode): """ The method provides PIL images support for color management. hTransform - a valid lcms transformation handle inImage - a valid PIL image object inMode, outMode - - predefined string constant (i.e. TYPE_RGB_8, TYPE_RGBA_8, TYPE_CMYK_8) or valid PIL mode Currently supports RGB, RGBA and CMYK modes only. Returns new PIL image object in outMode colorspace. """ if not inImage.mode == inMode: raise cmsError, "incorrect inMode" if not inImage.mode in [TYPE_RGB_8, TYPE_RGBA_8, TYPE_CMYK_8]: raise cmsError, "unsupported image type: %s" % inImage.mode if not inMode in [TYPE_RGB_8, TYPE_RGBA_8, TYPE_CMYK_8]: raise cmsError, "unsupported inMode type: %s" % inMode if not outMode in [TYPE_RGB_8, TYPE_RGBA_8, TYPE_CMYK_8]: raise cmsError, "unsupported outMode type: %s" % outMode w, h = inImage.size inImage.load() outImage = Image.new(outMode, (w, h)) _cms.transformBitmap(hTransform, inImage.im, outImage.im, w, h) return outImage