简体   繁体   English

对png和bmp进行按位运算会得到不同的结果? (相同的32位ARGB表示形式)

[英]Bitwise operations on a png and bmp give different results? (Same 32 bit ARGB representation)

I'm trying to replicate some image filtering software on the Android platform. 我正在尝试在Android平台上复制一些图像过滤软件。 The desktop version works with bmps but crashes out on png files. 桌面版本可与bmp一起使用,但会在png文件上崩溃。

When I come to xOr two pictures (The 32 bit ints of each corresponding pixel) I get very different results for the two pieces of software. 当我用x或x拍摄两张图片时(每个对应像素的32位整数),我得到的两个软件结果截然不同。

I'm sure my code isn't wrong as it's such a simple task but here it is; 我确定我的代码没有错,因为它是一个非常简单的任务,但是在这里;

const int aMask = 0xFF000000;

int xOrPixels(int p1, int p2) {
    return (aMask | (p1 ^ p2) );
}

The definition for the JAI library used by the Java desktop software can be found here and states; Java桌面软件使用的JAI库的定义可以在此处找到并注明:

 The destination pixel values are defined by the pseudocode:

 dst[x][y][b] = srcs[0][x][y][b] ^ srcs[1][x][y][b];

Where the b is for band (ie R,G,B). 其中b是频段(即R,G,B)。

Any thoughts? 有什么想法吗? I have a similar problem with AND and OR. 我对AND和OR也有类似的问题。

Here is an image with the two source images xOr'd at the bottom on Android using a png. 这是在Android上使用png在底部显示两个源图像的图像。 The same file as a bitmap xOr'd gives me a bitmap filled with 0xFFFFFFFF (White), no pixels at all. 与位图相同的文件xOr'd给了我一个填充有0xFFFFFFFF(白色)的位图,根本没有像素。 I checked the binary values of the Android ap and it seems right to me.... 我检查了Android ap的二进制值,这对我来说似乎是正确的。

安卓系统

Gav 加夫

NB When i say (Same 32 bit ARGB representation) I mean that android allows you to decode a png file to this format. 注意:当我说(相同的32位ARGB表示形式)时,我的意思是android允许您将png文件解码为这种格式。 Whilst this might give room for some error (Is png lossless?) I get completely different colours on the output. 尽管这可能会为某些错误留出空间(png无损吗?),我在输出中得到的颜色完全不同。

The png could have the wrong gamma or color space, and it's getting converted on load, affecting the result. png可能具有错误的gamma或颜色空间,并且正在加载时进行转换,从而影响结果。 Some versions of Photoshop had a bug where they saved pngs with the wrong gamma. 某些版本的Photoshop存在一个错误,即使用错误的伽玛值保存png。

What are you doing prior to the code posted? 发布代码之前您在做什么?

PNG is a compressed format, using the deflate algorithm (See Section 5 of RFC2083 ), so if you're just doing binary reads, you're not looking at actual pixels. PNG是一种压缩格式,使用deflate算法(请参阅RFC2083的第5节),因此,如果您只是进行二进制读取,则不会查看实际像素。

I checked a couple of values from your screenshot. 我从您的屏幕截图中检查了几个值。

The input pixels: 输入像素:

  • Upper left corners, 0xc3cbce^0x293029 = 0xeafbe7 左上角0xc3cbce ^ 0x293029 = 0xeafbe7
  • Nape of the neck, 0xbdb221^0x424dd6 = 0xfffff7 颈项,0xbdb221 ^ 0x424dd6 = 0xfffff7

are very similar to the corresponding output pixels. 与相应的输出像素非常相似。

Looks to me like you are XORing two images that are closely related (inverted in each color channel), so, necessarily, the output is near 0xffffff. 在我看来,您正在对两个紧密相关的图像(在每个颜色通道中反转)进行异或运算,因此,输出必然接近0xffffff。

If you were to XOR two dissimilar images, perhaps you will get something more like what you expect. 如果您要对两个不同的图像进行XOR,也许您会得到更像您所期望的图像。

The question is, why do you want to XOR pixel values? 问题是,为什么要对像素值进行XOR?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM