gpt4 book ai didi

java - Android:视频的色度键性能

转载 作者:太空宇宙 更新时间:2023-11-04 14:35:19 24 4
gpt4 key购买 nike

我有一个video stream并喜欢对其应用色度键效果。我试过这个GPU library但它比我自己的代码更慢:

public class ChromaKey {
int[] pix;
Bitmap bm;
int picw, pich;
int index, cur_pix, red2, green2, blue2;

public Bitmap replaceIntervalColor(Bitmap bitmap,int red, int green, int blue)
{
if (bitmap != null)
{
picw = bitmap.getWidth();
pich = bitmap.getHeight();
if (pix == null)
{
pix = new int[picw * pich];
}
bitmap.getPixels(pix, 0, picw, 0, 0, picw, pich);

double distance;

for (int y = 0; y < pich; y++) {
for (int x = 0; x < picw ; x++) {
index = y * picw + x;
cur_pix = pix[index];
red2 = (int)((cur_pix & 0x00FF0000) >>> 16); // Color.red(cur_pix);
green2 = (int)((cur_pix & 0x0000FF00) >>> 8); //Color.green(cur_pix);
blue2 = (int)(cur_pix & 0x000000FF); //Color.blue(cur_pix);
// faster Math.sqrt
// Source: http://stackoverflow.com/a/13264441/956397
/* distance = Math.sqrt(
(red2 - red) * (red2 - red)
+ (green2 - green) * (green2 - green)
+ (blue2 - blue) * (blue2 - blue)
); */
distance = Double.longBitsToDouble(((Double.doubleToRawLongBits( (red2 - red) * (red2 - red)
+ (green2 - green) * (green2 - green)
+ (blue2 - blue) * (blue2 - blue) ) >> 32) + 1072632448 ) << 31);

if (distance < 190)
{
pix[index] = Color.TRANSPARENT;
}
}
}

if (bm == null)
{
bm = Bitmap.createBitmap(picw, pich, Bitmap.Config.ARGB_4444);
}
bm.setPixels(pix, 0, picw, 0, 0, picw, pich);
return bm;
}
return null;
}
}

如何提高此代码的性能?

我已经将所有对象创建移出以重用内存,但在高端平板电脑上它仍然很慢。

最佳答案

建议您将此操作移至 native 库(C/C++)。您可以将整个 Bitmap 对象传递给 native 库函数并修改 Bitmap 的内容,而无需来回复制像素。甚至可以应用汇编程序中的优化。

或更简单地尝试优化您的代码。

关于java - Android:视频的色度键性能,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25661036/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com