How to use ScriptIntrinsic3DLUT with a .cube file?

Firstly, I am new to image processing in Android. I have a .cube file that was "Generated by Resolve", which is LUT_3D_SIZE 33. I am trying to use android.support.v8.renderscript.ScriptIntrinsic3DLUT to apply a lookup table for image processing. I assume I should use ScriptIntrinsic3DLUT and NOT android.support.v8.renderscript.ScriptIntrinsicLUT , right?

I'm having trouble finding the code for this, so this is what I put together. The problem I am facing is how to create a distribution based on my .cube file?

...
final RenderScript renderScript = RenderScript.create(getApplicationContext());
final ScriptIntrinsic3DLUT scriptIntrinsic3DLUT = ScriptIntrinsic3DLUT.create(renderScript, Element.U8_4(renderScript));

// How to create an Allocation from .cube file?
//final Allocation allocationLut = Allocation.createXXX();

scriptIntrinsic3DLUT.setLUT(allocationLut);

Bitmap bitmapIn = selectedImage;
Bitmap bitmapOut = selectedImage.copy(bitmapIn.getConfig(),true);

Allocation aIn = Allocation.createFromBitmap(renderScript, bitmapIn);
Allocation aOut = Allocation.createTyped(renderScript, aIn.getType());

aOut.copyTo(bitmapOut);
imageView.setImageBitmap(bitmapOut);
...

Any thoughts?

+4
2

3D LUT , , 3D LUT. 3D LUT , .cube( 3D LUT).

0

.cube

-, .cube.  OpenColorIO , ++. LUT, .cube,.lut .. , FileFormatIridasCube.cpp , .cube.

  LUT_3D_SIZE. . :

  • 17 ^ 3 , 33 ^ 3 65 ^ 3 .

, .cube float 3 * LUT_3D_SIZE ^ 3. , float. ScriptIntrinsic3DLUT Allocation. float.

.cube

, RGB 8- int, 8- . R 8-, G , B 8-. , 24- int .

.cube 3 . : !

. ( - .)

float 255.   :

int getRGBColorValue(float b, float g, float r) {
    int bcol = (int) (255 * clamp(b, 0.f, 1.f));
    int gcol = (int) (255 * clamp(g, 0.f, 1.f));
    int rcol = (int) (255 * clamp(r, 0.f, 1.f));
    return bcol | (gcol << 8) | (rcol << 16);
}

, , 3 . , , , LUT_3D_SIZE ^ 3. , .

ScriptIntrinsic3DLUT

RsLutDemo , ScriptIntrinsic3DLUT.

RenderScript mRs;
Bitmap mBitmap;
Bitmap mLutBitmap;
ScriptIntrinsic3DLUT mScriptlut;
Bitmap mOutputBitmap;
Allocation mAllocIn;
Allocation mAllocOut;
Allocation mAllocCube;
...
int redDim, greenDim, blueDim;
int[] lut;
if (mScriptlut == null) {
    mScriptlut = ScriptIntrinsic3DLUT.create(mRs, Element.U8_4(mRs));
}
if (mBitmap == null) {
    mBitmap = BitmapFactory.decodeResource(getResources(),
            R.drawable.bugs);

    mOutputBitmap = Bitmap.createBitmap(mBitmap.getWidth(), mBitmap.getHeight(), mBitmap.getConfig());

    mAllocIn = Allocation.createFromBitmap(mRs, mBitmap);
    mAllocOut = Allocation.createFromBitmap(mRs, mOutputBitmap);
}
...
// get the expected lut[] from .cube file.
...
Type.Builder tb = new Type.Builder(mRs, Element.U8_4(mRs));
tb.setX(redDim).setY(greenDim).setZ(blueDim);
Type t = tb.create();
mAllocCube = Allocation.createTyped(mRs, t);
mAllocCube.copyFromUnchecked(lut);

mScriptlut.setLUT(mAllocCube);
mScriptlut.forEach(mAllocIn, mAllocOut);

mAllocOut.copyTo(mOutputBitmap);

Demo

, . Github.
.

0

All Articles