-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Open
Description
目前补丁丁没有考虑ICC配置文件。所以cmyk色彩空间的jpg和jpx图像大多是偏色的(有些情况甚至没读ICC数据)。
我不清楚freeimage是否支持解析jpg和jpx的CMYK分量,如果不支持的话,可能需要Libjpeg和OpenJpegDotNet库来提取原始分量,然后才能用lcmsnet校正(你还得自己编译一个lcms.dll)。
这里有jpg cmyk样本了,我再提供一个jpx cmyk样本
下面是AI写的调用lcmsnet的代码,配合notBald的LibJPEGv9.net和OpenJpegDotNet已经测试通过。
Profile profile = null;
if (info.ICCProfile != null)
{
try
{
profile = Profile.Open(info.ICCProfile); //读取PDF里面的icc
}
catch { }
}
if (profile == null)
{
string iccfilename = "xxxx.USWebCoatedSWOP.icc";
Assembly assembly = Assembly.GetExecutingAssembly();
Stream stream = assembly.GetManifestResourceStream(iccfilename);
byte[] defaultICC = stream.ToByteArray();
profile = Profile.Open(defaultICC);
}
using var rgbprofile = Profile.Create_sRGB();
using (profile)
{
//创建transform,从cmyk转为bgra
//渲染意图:INTENT_PERCEPTUAL 保持视觉一致性(默认),适合照片类图像
//标志位: 无标志
using var transform = Transform.Create(profile, Cms.TYPE_CMYK_8, rgbprofile, Cms.TYPE_BGRA_8, Intent.Perceptual, CmsFlags.None);
byte[] rgbBytes = new byte[cmykBytes.Length];
transform.DoTransform(cmykBytes, rgbBytes, info.Width * info.Height);
// 写入Bitmap
bmp = new Bitmap(info.Width, info.Height, PixelFormat.Format32bppArgb);
var rect = new Rectangle(0, 0, info.Width, info.Height);
var bitmapData = bmp.LockBits(rect, ImageLockMode.WriteOnly, bmp.PixelFormat);
int srcStride = info.Width * 4;
int dstStride = Math.Abs(bitmapData.Stride);
Parallel.For(0, info.Height, y =>
{
IntPtr dst = bitmapData.Scan0 + y * dstStride;
int srcOffset = y * srcStride;
Marshal.Copy(rgbBytes, srcOffset, dst, srcStride);
});
bmp.UnlockBits(bitmapData);
}
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels