NSCalibrateBlackColorSpace 的未弃用替代品?

发布于 2024-08-28 08:20:08 字数 1464 浏览 7 评论 0原文

我正在实现自己的 NSBitmapImageRep (用于绘制 PBM 图像文件)。为了绘制它们,我使用 NSDrawBitmap() 并向其传递 NSCaliberatedBlackColorSpace (因为位为 1 表示黑色,0 表示白色)。

问题是,我收到以下警告:

warning: 'NSCalibratedBlackColorSpace' is deprecated

但是,我找不到一个好的替代品。 NSCaliberatedWhiteColorSpace 给了我一个倒置的图像,并且似乎没有办法让 NSDrawBitmap() 使用 CGColorSpaceRefNSColorSpace< /code> 我可以将其创建为与 NSCaliberatedBlackColorSpace 等效的自定义。

我找到了一种(hacky)方法来关闭警告(这样我仍然可以构建无警告的版本,直到有替代品可用),只需传递 @"NSCaliberatedBlackColorSpace" 而不是符号常量,但是我宁愿应用正确的修复。

有人有主意吗?


好的,我尝试了,

NSData*     pixelData = [[NSData alloc] initWithBytes: bytes +imgOffset length: [theData length] -imgOffset];
CGFloat     black[3] = { 0, 0, 0 };
CGFloat     white[3] = { 100, 100, 100 };
CGColorSpaceRef calibratedBlackCS = CGColorSpaceCreateCalibratedGray( white, black, 1.8 );
CGDataProviderRef provider = CGDataProviderCreateWithCFData( UKNSToCFData(pixelData) );
mImage = CGImageCreate( size.width, size.height, 1, 1, rowBytes, calibratedBlackCS, kCGImageAlphaNone,
                        provider, NULL, false, kCGRenderingIntentDefault );
CGColorSpaceRelease( calibratedBlackCS );

但它仍然是颠倒的。我也尝试过交换上面的黑色/白色,但没有改变任何东西。我是否误解了 CIE 三色值?大多数文档似乎假设您知道它是什么,或者愿意转换一段矩阵数学来弄清楚什么颜色是什么。或者什么。

我有点想避免一次接触所有数据并将其反转,但现在它似乎是最好的选择(/me 解压他的循环和异或运算符)。

I'm implementing my own NSBitmapImageRep (to draw PBM image files). To draw them, I'm using NSDrawBitmap() and passing it the NSCalibratedBlackColorSpace (as the bits are 1 for black, 0 for white).

Trouble is, I get the following warning:

warning: 'NSCalibratedBlackColorSpace' is deprecated

However, I couldn't find a good replacement for it. NSCalibratedWhiteColorSpace gives me an inverted image, and there seems to be no way to get NSDrawBitmap() to use a CGColorSpaceRef or NSColorSpace that I could create as a custom equivalent to NSCalibratedBlackColorSpace.

I've found a (hacky) way to shut up the warning (so I can still build warning-free until a replacement becomes available) by just passing @"NSCalibratedBlackColorSpace" instead of the symbolic constant, but I'd rather apply a correct fix.

Anybody have an idea?


OK, so I tried

NSData*     pixelData = [[NSData alloc] initWithBytes: bytes +imgOffset length: [theData length] -imgOffset];
CGFloat     black[3] = { 0, 0, 0 };
CGFloat     white[3] = { 100, 100, 100 };
CGColorSpaceRef calibratedBlackCS = CGColorSpaceCreateCalibratedGray( white, black, 1.8 );
CGDataProviderRef provider = CGDataProviderCreateWithCFData( UKNSToCFData(pixelData) );
mImage = CGImageCreate( size.width, size.height, 1, 1, rowBytes, calibratedBlackCS, kCGImageAlphaNone,
                        provider, NULL, false, kCGRenderingIntentDefault );
CGColorSpaceRelease( calibratedBlackCS );

but it's still inverted. I also tried swapping black/white above, didn't change a thing. Am I misinterpreting the CIE tristimulus color value thing? Most docs seem to assume you know what it is or are willing to transform a piece of matrix maths to figure out what color is what. Or something.

I'd kinda like to avoid having to touch all the data once and invert it, but right now it seems like the best choice (/me unpacks his loops and xor operators).

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

何处潇湘 2024-09-04 08:20:08

它似乎刚刚被删除,没有替换。解决方法可能只是反转所有位并使用 NSCalibrateWhiteColorSpace。

It seems to have just been removed with no replacement. The fix is probably to just invert all the bits and use NSCalibratedWhiteColorSpace.

宁愿没拥抱 2024-09-04 08:20:08

我会创建 经过校准的灰色 CGColorSpace,交换白点和黑点,然后 使用栅格数据和该颜色空间创建 CGImage。如果您想要位图图像代表,很容易 在 CGImage 周围创建其中之一

I'd create a calibrated gray CGColorSpace with the white and black points exchanged, then create a CGImage with the raster data and that color space. If you want a bitmap image rep, it's easy to create one of those around the CGImage.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文