如何分配上ScriptIntrinsic3DLUT使用LUT? [英] How to allocate the LUT to use on ScriptIntrinsic3DLUT?

查看:448
本文介绍了如何分配上ScriptIntrinsic3DLUT使用LUT?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

与RenderScript工作,我试图用ScriptIntrinsic3DLUT(的http://developer.android.com/reference/android/renderscript/ScriptIntrinsic3DLUT.html)

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

在一般这种以股代息的作品就像任何其他renderscript

In general this scrip works just like any other renderscript


  • 创建RS背景

  • 此环境中创建的脚本

  • 创建输入和输出的分配

  • 设置脚本参数

  • 调用内核

可问题是,在设置脚本参数一步,从我应该调用文档 script.setLUT(分配LUT),但什么是发电的适当方式/此分配设定值?

may problem is on the set script parameters step, from the docs I should call script.setLUT (Allocation lut), but what is the appropriate way of generating/setting values for this allocation?

在code我的样品是:

sample of the code I have is:

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

我的问题是类似<一个href=\"http://stackoverflow.com/questions/25686572/how-to-use-scriptintrinsic3dlut-with-a-cube-file\">How使用ScriptIntrinsic3DLUT与.cube等文件?

,但它是不一样的。我不关心的多维数据集文件。我可以创建一个从字节,整型,矩阵,无论阵列的LUT。我只是想知道如何对/在哪里,放置分配里面的字节。什么是这个分配适当的格式?

but it is not the same. I do not care about the cube file. I can create the LUT from array of bytes, ints, matrix, whatever. I just want to know how-to/where-to place those bytes inside the allocation. What's the appropriate formatting for this allocation?

推荐答案

我在网上找到了一个例子在这里:
<一href=\"https://android.googlesource.com/platform/frameworks/rs/+/master/java/tests/ImageProcessing/src/com/android/rs/image/ColorCube.java\" rel=\"nofollow\">https://android.googlesource.com/platform/frameworks/rs/+/master/java/tests/ImageProcessing/src/com/android/rs/image/ColorCube.java

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

这将创建一个3D LUT,不修改实际色彩值。很好的例子,虽然它如何能工作。

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

如果任何人都可以解析为.cube 文件,并装配到这方面的帮助,我将非常感激。

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

这篇关于如何分配上ScriptIntrinsic3DLUT使用LUT?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆