How to assign LUT for use in ScriptIntrinsic3DLUT?

while working with RenderScript, I am trying to use ScriptIntrinsic3DLUT ( http://developer.android.com/reference/android/renderscript/ScriptIntrinsic3DLUT.html )

In general, this script works just like any other renderscript

  • create RS context
  • create a script with this context
  • create input and output distributions
  • set script parameters
  • kernel call

there may be a problem in the step set script parametersof the documents that I should name script.setLUT (Allocation lut), but what is the appropriate way to create / set values ​​for this distribution?

sample code that i have:

// create RS context
RenderScript rs = RenderScript.create(context);

// create output bitmap
Bitmap bitmapOut = Bitmap.createBitmap(bitmapIn.getWidth(), bitmapIn.getHeight(), bitmapIn.getConfig());

// create bitmap allocations
Allocation allocIn = Allocation.createFromBitmap(rs, bitmapIn);
Allocation allocOut = Allocation.createFromBitmap(rs, bitmapOut);

// create script
ScriptIntrinsic3DLUT script = ScriptIntrinsic3DLUT.create(rs, Element.U8_4(rs));

// set 3D LUT for the script
how to create the `Allocation lut` ??
script.setLUT(lut);

// process the script
script.forEach(allocIn, allocOut);

// copy result to bitmap output
allocOut.copyTo(bitmapOut);

My question is similar to How to use ScriptIntrinsic3DLUT with a .cube file?

. . LUT , ints, matrix, . , -/- . ?

+2
2

: https://android.googlesource.com/platform/frameworks/rs/+/master/java/tests/ImageProcessing/src/com/android/rs/image/ColorCube.java

3D LUT, . , .

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);
    }

mIntrinsic.setLUT(mCube);

- .cube , .

+3

LUT forEach() script. LUT RGBA, Element.U8_4 . Allocation , 3- * 4 .

+1

All Articles