Beispiel #1
0
        /// <summary>
        /// Transforms the pixels of a FreeImageBitmap using a standard color profile
        /// for the bitmap's color space and the current color profile.
        /// </summary>
        /// <param name="freeImageBitmap">FreeImageBitmap whose pixels to convert.</param>
        /// <remarks>
        /// Since Excel does not support color management at all, conversions are done
        /// using standard color profiles that LittleCMS provides.
        /// </remarks>
        public void TransformFromStandardProfile(FreeImageAPI.FreeImageBitmap freeImageBitmap)
        {
            cmsHProfile standardProfile = CreateStandardProfile(freeImageBitmap);

            if (standardProfile == cmsHProfile.Zero)
            {
                throw new InvalidOperationException(
                          "Unable to create standard profile for " + freeImageBitmap.ColorType.ToString());
            }

            cmsHProfile targetProfile = cmsOpenProfileFromFile(GetPathFromName(), "r");

            if (targetProfile == cmsHProfile.Zero)
            {
                throw new InvalidOperationException(
                          "Unable to open desired color profile: " + Name);
            }

            // Create transform with perceptual intent (0) and no special options (0)
            cmsHTransform t = cmsCreateTransform(
                standardProfile, Lcms.Formatters.TYPE_BGRA_8,
                targetProfile, GetLcmsPixelFormat(ColorSpace),
                0, 0);

            if (t == cmsHTransform.Zero)
            {
                throw new InvalidOperationException("Unable to create CMS transform.");
            }
            UInt32 numPixels = (UInt32)freeImageBitmap.Size.Width * (UInt32)freeImageBitmap.Size.Height;

            cmsDoTransform(t, freeImageBitmap.Bits, freeImageBitmap.Bits, numPixels);
            freeImageBitmap.CreateICCProfile(GetIccBytes());

            cmsDeleteTransform(t);
            cmsCloseProfile(standardProfile);
            cmsCloseProfile(targetProfile);
        }
Beispiel #2
0
 private static extern void cmsDoTransform(
     cmsHTransform hTransform,
     IntPtr InputBuffer,
     IntPtr OutputBuffer,
     cmsUInt32Number Size);
Beispiel #3
0
 private static extern void cmsDeleteTransform(cmsHTransform hTransform);