android 代码 lut,如何将颜色LUT应用于位图图像以获取android中的滤镜效果?

我正在研究一个LUT应用程序库,它可以简化在Android中使用LUT图像的过程.它使用下面的algorythm,但我希望将来增强它以优化内存使用.现在它还猜测了LUT的颜色轴:

https://github.com/dntks/easyLUT/wiki

你的LUT图像的红绿蓝颜色尺寸与我以前的颜色尺寸不同,所以我必须改变获取lutIndex的顺序(在getLutIndex()).

请检查我编辑的答案:

final static int X_DEPTH = 16;

final static int Y_DEPTH = 16; //One little square has 16x16 pixels in it

final static int ROW_DEPTH = 4;

final static int COLUMN_DEPTH = 4; // the image consists of 4x4 little squares

final static int COLOR_DISTORTION = 16; // 256*256*256 => 256 no distortion, 64*64*64 => 256 dividied by 4 = 64, 16x16x16 => 256 dividied by 16 = 16

private Bitmap applyLutToBitmap(Bitmap src, Bitmap lutBitmap) {

int lutWidth = lutBitmap.getWidth();

int lutColors[] = new int[lutWidth * lutBitmap.getHeight()];

lutBitmap.getPixels(lutColors, 0, lutWidth, 0, 0, lutWidth, lutBitmap.getHeight());

int mWidth = src.getWidth();

int mHeight = src.getHeight();

int[] pix = new int[mWidth * mHeight];

src.getPixels(pix, 0, mWidth, 0, 0, mWidth, mHeight);

int R, G, B;

for (int y = 0; y < mHeight; y++)

for (int x = 0; x < mWidth; x++) {

int index = y * mWidth + x;

int r = ((pix[index] >> 16) & 0xff) / COLOR_DISTORTION;

int g = ((pix[index] >> 8) & 0xff) / COLOR_DISTORTION;

int b = (pix[index] & 0xff) / COLOR_DISTORTION;

int lutIndex = getLutIndex(lutWidth, r, g, b);

R = ((lutColors[lutIndex] >> 16) & 0xff);

G = ((lutColors[lutIndex] >> 8) & 0xff);

B = ((lutColors[lutIndex]) & 0xff);

pix[index] = 0xff000000 | (R << 16) | (G << 8) | B;

}

Bitmap filteredBitmap = Bitmap.createBitmap(mWidth, mHeight, src.getConfig());

filteredBitmap.setPixels(pix, 0, mWidth, 0, 0, mWidth, mHeight);

return filteredBitmap;

}

//the magic happens here

private int getLutIndex(int lutWidth, int redDepth, int greenDepth, int blueDepth) {

int lutX = (greenDepth % ROW_DEPTH) * X_DEPTH + blueDepth;

int lutY = (greenDepth / COLUMN_DEPTH) * Y_DEPTH + redDepth;

return lutY * lutWidth + lutX;

}

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值