快速算法反转的ARGB颜色值ABGR? [英] Fast algorithm to invert an ARGB color value to ABGR?

查看:545
本文介绍了快速算法反转的ARGB颜色值ABGR?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用 IntBuffer 来处理位图的像素,但在缓冲区中的值应 AABBGGRR ,同时颜色常数 AARRGGBB 。我知道我可以使用 Col​​or.argb Col​​or.a ,...反转,但我认为这不是完美的。

我需要处理一个非常大的像素数,所以我需要一个能够在短时间内执行此操作符的算法。我认为这位前pression,但它不是正确的:

  0xFFFFFFFF的^ pSo​​urceColor
 

如果没有更好的,也许我会使用,而不是调用函数位的移位运算(执行 Col​​or.a ,...),以减少时间

编辑:

这是我目前的功能转换,但我认为有建议立即进行删除是一个更好的算法(较少运营商)来执行它:

 私人诠释getBufferedColor(最终诠释pSourceColor){
    返回
            ((pSourceColor>> 24)<< 24)| // Α
            ((pSourceColor>> 16)及为0xFF)| //红 - >蓝
            ((pSourceColor>→8)及为0xFF)其中;&其中; 8 | // 绿色
            ((pSourceColor)及为0xFF)其中;&其中; 16; //蓝 - >红
}
 

解决方案

由于A和G到位,你也许可以做的更好通过屏蔽掉B和R,然后将它们添加后退了几步。没有测试过,但应该是95%正确的:

 私有静态最终诠释EXCEPT_R_MASK = 0xFF00FFFF;
私有静态最终诠释ONLY_R_MASK =〜EXCEPT_R_MASK;
私有静态最终诠释EXCEPT_B_MASK = 0xFFFFFF00;
私有静态最终诠释ONLY_B_MASK =〜EXCEPT_B_MASK;

私人诠释getBufferedColor(最终诠释pSourceColor){
    INT R =(pSourceColor&安培; ONLY_R_MASK)>> 16;
    INT B = pSourceColor和放大器; ONLY_B_MASK;
    返回
      (pSourceColor&安培; EXCEPT_R_MASK&安培; EXCEPT_B_MASK)| (b将&所述; 16)| -  [R;
}
 

I'm using IntBuffer to manipulate pixels of a Bitmap, but the value in the buffer should be AABBGGRR, while the color constants are AARRGGBB. I know I can use Color.argb, Color.a, ... to invert, but I think it's not perfect.

I need to manipulate a very large number of pixels, so I need an algorithm that can perform this operator in short time. I think of this Bit Expression, but it's not correct:

0xFFFFFFFF ^ pSourceColor

If there's no better one, maybe I will use bit-shift operators (that performs Color.a, ...) instead of calling the functions to reduce the time.

EDIT:

This is my current function to convert, though I think there shoul be a better algorithm (less operators) to perform it:

private int getBufferedColor(final int pSourceColor) {
    return
            ((pSourceColor >> 24) << 24) |          // Alpha
            ((pSourceColor >> 16) & 0xFF) |         // Red  -> Blue
            ((pSourceColor >> 8) & 0xFF) << 8 |     // Green
            ((pSourceColor) & 0xFF) << 16;          // Blue -> Red
}

解决方案

Since A and G are in place, you can probably do a little better by masking off the B and R and then adding them back. Haven't tested it but ought to be 95% right:

private static final int EXCEPT_R_MASK = 0xFF00FFFF;
private static final int ONLY_R_MASK = ~EXCEPT_R_MASK;
private static final int EXCEPT_B_MASK = 0xFFFFFF00;
private static final int ONLY_B_MASK = ~EXCEPT_B_MASK;

private int getBufferedColor(final int pSourceColor) {
    int r = (pSourceColor & ONLY_R_MASK) >> 16;
    int b = pSourceColor & ONLY_B_MASK;
    return
      (pSourceColor & EXCEPT_R_MASK & EXCEPT_B_MASK) | (b << 16) | r;
}

这篇关于快速算法反转的ARGB颜色值ABGR?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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