zoukankan      html  css  js  c++  java
  • RenderScript多输入参数

    https://stackoverflow.com/questions/20783830/how-to-use-renderscript-with-multiple-input-allocations

    For the kernel with multiple inputs you would have to manually handle additional inputs.

    Let's say you want 2 inputs.

    example.rs:

    rs_allocation extra_alloc;
    
    uchar4 __attribute__((kernel)) kernel(uchar4 i1, uint32_t x, uint32_t y)
    {
        // Manually getting current element from the extra input
        uchar4 i2 = rsGetElementAt_uchar4(extra_alloc, x, y);
        // Now process i1 and i2 and generate out
        uchar4 out = ...;
        return out;
    }
    

    Java:

    Bitmap bitmapIn = ...;
    Bitmap bitmapInExtra = ...;
    Bitmap bitmapOut = Bitmap.createBitmap(bitmapIn.getWidth(),
                        bitmapIn.getHeight(), bitmapIn.getConfig());
    
    RenderScript rs = RenderScript.create(this);
    ScriptC_example script = new ScriptC_example(rs);
    
    Allocation inAllocation = Allocation.createFromBitmap(rs, bitmapIn);
    Allocation inAllocationExtra = Allocation.createFromBitmap(rs, bitmapInExtra);
    Allocation outAllocation = Allocation.createFromBitmap(rs, bitmapOut);
    
    // Execute this kernel on two inputs
    script.set_extra_alloc(inAllocationExtra);
    script.forEach_kernel(inAllocation, outAllocation);
    
    // Get the data back into bitmap
    outAllocation.copyTo(bitmapOut);


    //-----------------------------------------------------------------------------

    hen you only need a grayscale camera preview, you could use a very simple renderscript:

    # pragma version(1)
    # pragma rs java_package_name(com.example.name)
    # pragma rs_fp_relaxed
    
    rs_allocation gIn;   // Allocation filled with camera preview data (byte[])
    int previewwidth;    // camera preview width (int)
    
    // the parallel executed kernel
    void root(uchar4 *v_out, uint32_t x,uint32_t y){
       uchar c = rsGetElementAt_uchar(gIn,x+y*previewwidth); 
       *v_out = (uchar4){c,c,c,255};
    }
     
  • 相关阅读:
    mysql数据库引擎myisam与innodb
    Java观察者模式的理解
    线程安全的单例模式
    线程相关
    java 线程读写锁
    原子变量AtomicInteger
    接口文档管理,版本管理工具,阿里RAP的windows下部署
    谷歌浏览器报错:跨域问题处理( Access-Control-Allow-Origin)_ 用于本地测试的快捷解决方法
    mysql bin-log日志记录
    阿里RDS中插入emoji 表情插入失败的解决方案
  • 原文地址:https://www.cnblogs.com/jukan/p/7152081.html
Copyright © 2011-2022 走看看