How to allocate the LUT to use on ScriptIntrinsic3DLUT?

旧城冷巷雨未停 提交于 2019-12-04 17:18:41

I found an example on the web here: https://android.googlesource.com/platform/frameworks/rs/+/master/java/tests/ImageProcessing/src/com/android/rs/image/ColorCube.java

This creates a 3D LUT that doesn't modify the actual color values. Good example though how it could work.

private ScriptIntrinsic3DLUT mIntrinsic;
private void initCube() {
        final int sx = 32;
        final int sy = 32;
        final int sz = 16;
        Type.Builder tb = new Type.Builder(mRS, Element.U8_4(mRS));
        tb.setX(sx);
        tb.setY(sy);
        tb.setZ(sz);
        Type t = tb.create();
        mCube = Allocation.createTyped(mRS, t);
        int dat[] = new int[sx * sy * sz];
        for (int z = 0; z < sz; z++) {
            for (int y = 0; y < sy; y++) {
                for (int x = 0; x < sx; x++ ) {
                    int v = 0xff000000;
                    v |= (0xff * x / (sx - 1));
                    v |= (0xff * y / (sy - 1)) << 8;
                    v |= (0xff * z / (sz - 1)) << 16;
                    dat[z*sy*sx + y*sx + x] = v;
                }
            }
        }
        mCube.copyFromUnchecked(dat);
    }

and then use it like so

mIntrinsic.setLUT(mCube);

If anyone can help with parsing a .cube file and fitting into this i would be very grateful.

You'll need to set the LUT before calling the forEach() method on the script. The LUT data is pixel format RGBA, Element.U8_4 and is in 3 dimensions. So you'll need to create an Allocation based on a data array which has enough space for 3 dimensions * 4 bytes per pixel.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!