如何做到位图的对比iOS中? [英] How to do comparisons of bitmaps in iOS?

查看:74
本文介绍了如何做到位图的对比iOS中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有三个CGLayers谁的,我想比较数据。

I have three CGLayers who's data I'd like to compare.

void *a = CGBitmapContextGetData(CGLayerGetContext(layerA));
void *b = CGBitmapContextGetData(CGLayerGetContext(layerB));
void *c = CGBitmapContextGetData(CGLayerGetContext(layerC));

我希望得到这样的结果((A或B)和C)其中只有位是在层1.或layerB,并在layerC的结果告终。这些层 kCGImageAlphaOnly 所以他们只有8位深,而我只卷入其中1.0阿尔法。我也不需要知道的重叠所在,我只需要知道有没有的任何的结果中的位上。

I'd like to get a result like ((a OR b) AND c) where only bits that are on in layerA or layerB and also on in layerC end up in the result. These layers are kCGImageAlphaOnly so they are only 8 bits "deep", and I've only drawn into them with 1.0 alpha. I also don't need to know where the overlap lies, I just need to know whether there are any bits on in the result.

今天我真的错过的QuickDraw,它有大量的非常快速的面向比特的操作。如何实现这样的事情有什么想法?

I'm really missing QuickDraw today, it had plenty of bit-oriented operations that were very speedy. Any thoughts on how to accomplish something like this?

推荐答案

下面是一个天真的实现,假设所有三个大小相同:

Here's a naive implementation, assuming all three are the same size:

unsigned char *a = CGBitmapContextGetData(CGLayerGetContext(layerA));
unsigned char *b = CGBitmapContextGetData(CGLayerGetContext(layerB));
CGContextRef context = CGLayerGetContext(layerC);
unsigned char *c = CGBitmapContextGetData(context);
size_t bytesPerRow = CGBitmapContextGetBytesPerRow(context);
size_t height = CGBitmapContextGetHeight(context);
size_t len = bytesPerRow * height;
BOOL bitsFound = NO;
for (int i = 0; i < len; i++) {
    if ((a[i] | b[i]) & c[i]) { bitsFound = YES; break; }
}

既然你渴望的QuickDraw的,我想你可能已经编写了你自己,你知道,这将可能是缓慢的。

Since you're hankering for QuickDraw, I assume you could have written that yourself, and you know that will probably be slow.

如果你能保证位图的大小,你可以使用 INT 而不是字符,并在四个字节操作一时间。

If you can guarantee the bitmap sizes, you could use int instead of char and operate on four bytes at a time.

对于较严重的优化,你应该检查出加速的框架。

For more serious optimization, you should check out the Accelerate framework.

这篇关于如何做到位图的对比iOS中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆