Exemplo n.º 1
0
 private void checkMixFloat4Float4FloatFloat4() {
   Allocation inStart =
       createRandomAllocation(mRS, Element.DataType.FLOAT_32, 4, 0x64e44bb30a701d3dl, false);
   Allocation inStop =
       createRandomAllocation(mRS, Element.DataType.FLOAT_32, 4, 0xb4f372e0715beb33l, false);
   Allocation inAmount =
       createRandomAllocation(mRS, Element.DataType.FLOAT_32, 1, 0xf258b71221bfbc69l, false);
   try {
     Allocation out =
         Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 4), INPUTSIZE);
     script.set_gAllocInStop(inStop);
     script.set_gAllocInAmount(inAmount);
     script.forEach_testMixFloat4Float4FloatFloat4(inStart, out);
     verifyResultsMixFloat4Float4FloatFloat4(inStart, inStop, inAmount, out, false);
   } catch (Exception e) {
     throw new RSRuntimeException(
         "RenderScript. Can't invoke forEach_testMixFloat4Float4FloatFloat4: " + e.toString());
   }
   try {
     Allocation out =
         Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 4), INPUTSIZE);
     scriptRelaxed.set_gAllocInStop(inStop);
     scriptRelaxed.set_gAllocInAmount(inAmount);
     scriptRelaxed.forEach_testMixFloat4Float4FloatFloat4(inStart, out);
     verifyResultsMixFloat4Float4FloatFloat4(inStart, inStop, inAmount, out, true);
   } catch (Exception e) {
     throw new RSRuntimeException(
         "RenderScript. Can't invoke forEach_testMixFloat4Float4FloatFloat4: " + e.toString());
   }
 }
    public void exit() {
      mRun = false;

      synchronized (this) {
        notifyAll();
      }

      try {
        this.join();
      } catch (InterruptedException e) {
      }

      mInPixelsAllocation.destroy();
      mInPixelsAllocation2.destroy();
      if (mOutPixelsAllocation != mOutDisplayAllocation) {
        mOutPixelsAllocation.destroy();
      }
      mOutDisplayAllocation.destroy();
      mRS.destroy();

      mInPixelsAllocation = null;
      mInPixelsAllocation2 = null;
      mOutPixelsAllocation = null;
      mOutDisplayAllocation = null;
      mRS = null;
    }
Exemplo n.º 3
0
 private void checkMixFloat4Float4Float4Float4() {
   Allocation inStart =
       createRandomAllocation(mRS, Element.DataType.FLOAT_32, 4, 0xd818b19f433276a1l, false);
   Allocation inStop =
       createRandomAllocation(mRS, Element.DataType.FLOAT_32, 4, 0x7c186362f5a7e15fl, false);
   Allocation inAmount =
       createRandomAllocation(mRS, Element.DataType.FLOAT_32, 4, 0x4c25d5bfaa64c035l, false);
   try {
     Allocation out =
         Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 4), INPUTSIZE);
     script.set_gAllocInStop(inStop);
     script.set_gAllocInAmount(inAmount);
     script.forEach_testMixFloat4Float4Float4Float4(inStart, out);
     verifyResultsMixFloat4Float4Float4Float4(inStart, inStop, inAmount, out, false);
   } catch (Exception e) {
     throw new RSRuntimeException(
         "RenderScript. Can't invoke forEach_testMixFloat4Float4Float4Float4: " + e.toString());
   }
   try {
     Allocation out =
         Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 4), INPUTSIZE);
     scriptRelaxed.set_gAllocInStop(inStop);
     scriptRelaxed.set_gAllocInAmount(inAmount);
     scriptRelaxed.forEach_testMixFloat4Float4Float4Float4(inStart, out);
     verifyResultsMixFloat4Float4Float4Float4(inStart, inStop, inAmount, out, true);
   } catch (Exception e) {
     throw new RSRuntimeException(
         "RenderScript. Can't invoke forEach_testMixFloat4Float4Float4Float4: " + e.toString());
   }
 }
Exemplo n.º 4
0
 private void checkMixFloat2Float2Float2Float2() {
   Allocation inStart =
       createRandomAllocation(mRS, Element.DataType.FLOAT_32, 2, 0x45502e8f0a2d9ce9l, false);
   Allocation inStop =
       createRandomAllocation(mRS, Element.DataType.FLOAT_32, 2, 0xba2b8a035395e837l, false);
   Allocation inAmount =
       createRandomAllocation(mRS, Element.DataType.FLOAT_32, 2, 0xa477d20616942e4dl, false);
   try {
     Allocation out =
         Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 2), INPUTSIZE);
     script.set_gAllocInStop(inStop);
     script.set_gAllocInAmount(inAmount);
     script.forEach_testMixFloat2Float2Float2Float2(inStart, out);
     verifyResultsMixFloat2Float2Float2Float2(inStart, inStop, inAmount, out, false);
   } catch (Exception e) {
     throw new RSRuntimeException(
         "RenderScript. Can't invoke forEach_testMixFloat2Float2Float2Float2: " + e.toString());
   }
   try {
     Allocation out =
         Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 2), INPUTSIZE);
     scriptRelaxed.set_gAllocInStop(inStop);
     scriptRelaxed.set_gAllocInAmount(inAmount);
     scriptRelaxed.forEach_testMixFloat2Float2Float2Float2(inStart, out);
     verifyResultsMixFloat2Float2Float2Float2(inStart, inStop, inAmount, out, true);
   } catch (Exception e) {
     throw new RSRuntimeException(
         "RenderScript. Can't invoke forEach_testMixFloat2Float2Float2Float2: " + e.toString());
   }
 }
 public boolean prepareRenderscriptAllocations(Bitmap bitmap) {
   RenderScript RS = getRenderScriptContext();
   boolean needsUpdate = false;
   if (mOutPixelsAllocation == null
       || mInPixelsAllocation == null
       || bitmap.getWidth() != mWidth
       || bitmap.getHeight() != mHeight) {
     destroyPixelAllocations();
     Bitmap bitmapBuffer = bitmap;
     if (bitmap.getConfig() == null || bitmap.getConfig() != BITMAP_CONFIG) {
       bitmapBuffer = bitmap.copy(BITMAP_CONFIG, true);
     }
     mOutPixelsAllocation =
         Allocation.createFromBitmap(
             RS, bitmapBuffer, Allocation.MipmapControl.MIPMAP_NONE, Allocation.USAGE_SCRIPT);
     mInPixelsAllocation = Allocation.createTyped(RS, mOutPixelsAllocation.getType());
     needsUpdate = true;
   }
   if (RS != null) {
     mInPixelsAllocation.copyFrom(bitmap);
   }
   if (bitmap.getWidth() != mWidth || bitmap.getHeight() != mHeight) {
     mWidth = bitmap.getWidth();
     mHeight = bitmap.getHeight();
     needsUpdate = true;
   }
   if (DEBUG) {
     Log.v(LOGTAG, "prepareRenderscriptAllocations: " + needsUpdate + " in " + getName());
   }
   return needsUpdate;
 }
  public void test_AllocationPadded_copy1DRangeToUnchecked_Byte3() {
    Random random = new Random(0x172d8ab9);
    int width = random.nextInt(512);
    int arr_len = width * 3;

    byte[] inArray = new byte[arr_len];
    byte[] outArray = new byte[arr_len];
    random.nextBytes(inArray);

    Type.Builder typeBuilder = new Type.Builder(mRS, Element.I8_3(mRS));
    typeBuilder.setX(width);
    Allocation alloc = Allocation.createTyped(mRS, typeBuilder.create());
    alloc.setAutoPadding(true);
    int offset = random.nextInt(width);
    int count = width - offset;
    alloc.copy1DRangeFrom(offset, count, inArray);
    alloc.copy1DRangeToUnchecked(offset, count, outArray);

    boolean result = true;
    for (int i = 0; i < count * 3; i++) {
      if (inArray[i] != outArray[i]) {
        result = false;
        break;
      }
    }
    for (int i = count * 3; i < arr_len; i++) {
      if (outArray[i] != 0) {
        result = false;
        break;
      }
    }
    assertTrue(
        "test_copy1DRangeToUnchecked_Padded_Byte Failed, output array does not match input",
        result);
  }
  public void test_AllocationPadded_Byte3_3D() {
    Random random = new Random(0x172d8ab9);
    int w = random.nextInt(32);
    int h = random.nextInt(32);
    int d = random.nextInt(32);
    int arr_len = w * d * h * 3;

    byte[] inArray = new byte[arr_len];
    byte[] outArray = new byte[arr_len];
    random.nextBytes(inArray);

    Type.Builder typeBuilder = new Type.Builder(mRS, Element.I8_3(mRS));
    typeBuilder.setX(w).setY(h).setZ(d);
    Allocation alloc = Allocation.createTyped(mRS, typeBuilder.create());
    alloc.setAutoPadding(true);
    alloc.copyFrom(inArray);
    alloc.copyTo(outArray);

    boolean result = true;
    for (int i = 0; i < arr_len; i++) {
      if (inArray[i] != outArray[i]) {
        result = false;
        break;
      }
    }
    assertTrue(
        "test_AllocationCopyTo_3D_Padded_Byte Failed, output array does not match input", result);
  }
  public void test_AllocationPadded_copy2DRangeTo_Long3() {
    Random random = new Random(0x172d8ab9);
    int width = random.nextInt(128);
    int height = random.nextInt(128);
    int xoff = random.nextInt(width);
    int yoff = random.nextInt(height);
    int xcount = width - xoff;
    int ycount = height - yoff;
    int arr_len = xcount * ycount * 3;

    long[] inArray = new long[arr_len];
    long[] outArray = new long[arr_len];

    for (int i = 0; i < arr_len; i++) {
      inArray[i] = random.nextLong();
    }

    Type.Builder typeBuilder = new Type.Builder(mRS, Element.I64_3(mRS));
    typeBuilder.setX(width).setY(height);
    Allocation alloc = Allocation.createTyped(mRS, typeBuilder.create());
    alloc.setAutoPadding(true);
    alloc.copy2DRangeFrom(xoff, yoff, xcount, ycount, inArray);
    alloc.copy2DRangeTo(xoff, yoff, xcount, ycount, outArray);

    boolean result = true;
    for (int i = 0; i < arr_len; i++) {
      if (inArray[i] != outArray[i]) {
        result = false;
        break;
      }
    }
    assertTrue("test_copy2DRangeTo_Padded_Long Failed, output array does not match input", result);
  }
  public void test_AllocationPadded_Double3_2D() {
    Random random = new Random(0x172d8ab9);
    int width = random.nextInt(128);
    int height = random.nextInt(128);
    int arr_len = width * height * 3;

    double[] inArray = new double[arr_len];
    double[] outArray = new double[arr_len];

    for (int i = 0; i < arr_len; i++) {
      inArray[i] = (double) random.nextFloat();
    }

    Type.Builder typeBuilder = new Type.Builder(mRS, Element.F64_3(mRS));
    typeBuilder.setX(width).setY(height);
    Allocation alloc = Allocation.createTyped(mRS, typeBuilder.create());
    alloc.setAutoPadding(true);
    alloc.copyFrom(inArray);
    alloc.copyTo(outArray);

    boolean result = true;
    for (int i = 0; i < arr_len; i++) {
      if (inArray[i] != outArray[i]) {
        result = false;
        break;
      }
    }
    assertTrue(
        "test_AllocationCopyTo_2D_Padded_Double Failed, output array does not match input", result);
  }
  public void test_AllocationPadded_Long3_1D() {
    Random random = new Random(0x172d8ab9);
    int width = random.nextInt(512);
    int arr_len = width * 3;

    long[] inArray = new long[arr_len];
    long[] outArray = new long[arr_len];

    for (int i = 0; i < arr_len; i++) {
      inArray[i] = random.nextLong();
    }

    Type.Builder typeBuilder = new Type.Builder(mRS, Element.I64_3(mRS));
    typeBuilder.setX(width);
    Allocation alloc = Allocation.createTyped(mRS, typeBuilder.create());
    alloc.setAutoPadding(true);
    alloc.copyFrom(inArray);
    alloc.copyTo(outArray);

    boolean result = true;
    for (int i = 0; i < arr_len; i++) {
      if (inArray[i] != outArray[i]) {
        result = false;
        break;
      }
    }
    assertTrue(
        "test_AllocationCopyTo_1D_Padded_Long Failed, output array does not match input", result);
  }
Exemplo n.º 11
0
 private void checkMixFloat3Float3Float3Float3() {
   Allocation inStart =
       createRandomAllocation(mRS, Element.DataType.FLOAT_32, 3, 0xeb4701726b009c5l, false);
   Allocation inStop =
       createRandomAllocation(mRS, Element.DataType.FLOAT_32, 3, 0x9b21f6b3249ee4cbl, false);
   Allocation inAmount =
       createRandomAllocation(mRS, Element.DataType.FLOAT_32, 3, 0x784ed3e2e07c7741l, false);
   try {
     Allocation out =
         Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 3), INPUTSIZE);
     script.set_gAllocInStop(inStop);
     script.set_gAllocInAmount(inAmount);
     script.forEach_testMixFloat3Float3Float3Float3(inStart, out);
     verifyResultsMixFloat3Float3Float3Float3(inStart, inStop, inAmount, out, false);
   } catch (Exception e) {
     throw new RSRuntimeException(
         "RenderScript. Can't invoke forEach_testMixFloat3Float3Float3Float3: " + e.toString());
   }
   try {
     Allocation out =
         Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 3), INPUTSIZE);
     scriptRelaxed.set_gAllocInStop(inStop);
     scriptRelaxed.set_gAllocInAmount(inAmount);
     scriptRelaxed.forEach_testMixFloat3Float3Float3Float3(inStart, out);
     verifyResultsMixFloat3Float3Float3Float3(inStart, inStop, inAmount, out, true);
   } catch (Exception e) {
     throw new RSRuntimeException(
         "RenderScript. Can't invoke forEach_testMixFloat3Float3Float3Float3: " + e.toString());
   }
 }
Exemplo n.º 12
0
  protected void createWalk(int vsize) {
    // We do a random copy order to attempt to get multiple threads
    // reading and writing the same cache line
    // We could do this as a simple walk but that would likely miss
    // some caching issues.
    final int tw = gCount / vsize;
    int tmp[] = new int[tw];
    boolean b[] = new boolean[tw];
    int toCopy = tw;
    int i = 0;

    while (toCopy > 0) {
      int x = random.nextInt(tw);

      while ((x < tw) && b[x]) {
        x++;
        if (x >= tw) {
          x = 0;
        }
      }

      b[x] = true;
      toCopy--;

      // android.util.Log.v("rs", "walk  " + i + ", " + x);
      tmp[i++] = x;
    }

    walkAlloc = Allocation.createSized(mRS, Element.I32(mRS), tw);
    walkAlloc.copy1DRangeFrom(0, tw, tmp);
  }
Exemplo n.º 13
0
  /**
   * 高斯模糊
   *
   * @param bitmap
   * @return
   */
  @SuppressLint("NewApi")
  public static Bitmap blurBitmap(Bitmap bitmap) {

    // Let's create an empty bitmap with the same size of the bitmap we want
    // to blur
    Bitmap outBitmap = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Config.ARGB_8888);

    // Instantiate a new Renderscript
    RenderScript rs = RenderScript.create(MyApplication.getAppContext());

    // Create an Intrinsic Blur Script using the Renderscript U8_4(rs)
    ScriptIntrinsicBlur blurScript = ScriptIntrinsicBlur.create(rs, Element.U8_4(rs));

    // Create the Allocations (in/out) with the Renderscript and the in/out
    // bitmaps
    Allocation allIn = Allocation.createFromBitmap(rs, bitmap);
    Allocation allOut = Allocation.createFromBitmap(rs, outBitmap);

    // Set the radius of the blur
    blurScript.setRadius(25.f);

    // Perform the Renderscript
    blurScript.setInput(allIn);
    blurScript.forEach(allOut);

    // Copy the final bitmap created by the out Allocation to the outBitmap
    allOut.copyTo(outBitmap);

    // recycle the original bitmap
    // bitmap.recycle();

    // After finishing everything, we destroy the Renderscript.
    rs.destroy();
    return outBitmap;
  }
Exemplo n.º 14
0
 private void checkMixFloatFloatFloatFloat() {
   Allocation inStart =
       createRandomAllocation(mRS, Element.DataType.FLOAT_32, 1, 0x9f4beff6471d6db1l, false);
   Allocation inStop =
       createRandomAllocation(mRS, Element.DataType.FLOAT_32, 1, 0x6ede0b88b4422e8fl, false);
   Allocation inAmount =
       createRandomAllocation(mRS, Element.DataType.FLOAT_32, 1, 0xc1c14e5d52dc3fe5l, false);
   try {
     Allocation out =
         Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 1), INPUTSIZE);
     script.set_gAllocInStop(inStop);
     script.set_gAllocInAmount(inAmount);
     script.forEach_testMixFloatFloatFloatFloat(inStart, out);
     verifyResultsMixFloatFloatFloatFloat(inStart, inStop, inAmount, out, false);
   } catch (Exception e) {
     throw new RSRuntimeException(
         "RenderScript. Can't invoke forEach_testMixFloatFloatFloatFloat: " + e.toString());
   }
   try {
     Allocation out =
         Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 1), INPUTSIZE);
     scriptRelaxed.set_gAllocInStop(inStop);
     scriptRelaxed.set_gAllocInAmount(inAmount);
     scriptRelaxed.forEach_testMixFloatFloatFloatFloat(inStart, out);
     verifyResultsMixFloatFloatFloatFloat(inStart, inStop, inAmount, out, true);
   } catch (Exception e) {
     throw new RSRuntimeException(
         "RenderScript. Can't invoke forEach_testMixFloatFloatFloatFloat: " + e.toString());
   }
 }
Exemplo n.º 15
0
 private void checkMixFloat2Float2FloatFloat2() {
   Allocation inStart =
       createRandomAllocation(mRS, Element.DataType.FLOAT_32, 2, 0xf811b2d52bd1d7c3l, false);
   Allocation inStop =
       createRandomAllocation(mRS, Element.DataType.FLOAT_32, 2, 0x17a127e13c8dd1c5l, false);
   Allocation inAmount =
       createRandomAllocation(mRS, Element.DataType.FLOAT_32, 1, 0xaaf909cdbd2a10ebl, false);
   try {
     Allocation out =
         Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 2), INPUTSIZE);
     script.set_gAllocInStop(inStop);
     script.set_gAllocInAmount(inAmount);
     script.forEach_testMixFloat2Float2FloatFloat2(inStart, out);
     verifyResultsMixFloat2Float2FloatFloat2(inStart, inStop, inAmount, out, false);
   } catch (Exception e) {
     throw new RSRuntimeException(
         "RenderScript. Can't invoke forEach_testMixFloat2Float2FloatFloat2: " + e.toString());
   }
   try {
     Allocation out =
         Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 2), INPUTSIZE);
     scriptRelaxed.set_gAllocInStop(inStop);
     scriptRelaxed.set_gAllocInAmount(inAmount);
     scriptRelaxed.forEach_testMixFloat2Float2FloatFloat2(inStart, out);
     verifyResultsMixFloat2Float2FloatFloat2(inStart, inStop, inAmount, out, true);
   } catch (Exception e) {
     throw new RSRuntimeException(
         "RenderScript. Can't invoke forEach_testMixFloat2Float2FloatFloat2: " + e.toString());
   }
 }
Exemplo n.º 16
0
 private void checkMixFloat3Float3FloatFloat3() {
   Allocation inStart =
       createRandomAllocation(mRS, Element.DataType.FLOAT_32, 3, 0xae7aff441b20fa80l, false);
   Allocation inStop =
       createRandomAllocation(mRS, Element.DataType.FLOAT_32, 3, 0xe64a4d60d6f4de7cl, false);
   Allocation inAmount =
       createRandomAllocation(mRS, Element.DataType.FLOAT_32, 1, 0x4ea8e06fef74e6aal, false);
   try {
     Allocation out =
         Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 3), INPUTSIZE);
     script.set_gAllocInStop(inStop);
     script.set_gAllocInAmount(inAmount);
     script.forEach_testMixFloat3Float3FloatFloat3(inStart, out);
     verifyResultsMixFloat3Float3FloatFloat3(inStart, inStop, inAmount, out, false);
   } catch (Exception e) {
     throw new RSRuntimeException(
         "RenderScript. Can't invoke forEach_testMixFloat3Float3FloatFloat3: " + e.toString());
   }
   try {
     Allocation out =
         Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 3), INPUTSIZE);
     scriptRelaxed.set_gAllocInStop(inStop);
     scriptRelaxed.set_gAllocInAmount(inAmount);
     scriptRelaxed.forEach_testMixFloat3Float3FloatFloat3(inStart, out);
     verifyResultsMixFloat3Float3FloatFloat3(inStart, inStop, inAmount, out, true);
   } catch (Exception e) {
     throw new RSRuntimeException(
         "RenderScript. Can't invoke forEach_testMixFloat3Float3FloatFloat3: " + e.toString());
   }
 }
Exemplo n.º 17
0
 private byte[] randomByteArray(int len) {
   byte t[] = new byte[len];
   random.nextBytes(t);
   in1DAlloc.copyFrom(t);
   in2DAlloc.copyFrom(t);
   in3DAlloc.copyFrom(t);
   return t;
 }
Exemplo n.º 18
0
  public byte[] decodeBMPToYUV422(Bitmap bmp) {
    int width = bmp.getWidth();
    int height = bmp.getHeight();

    boolean needUpdateAllocation = false;
    if (mOriginHeight2 != height || mOriginWidth2 != width) {
      mOriginWidth2 = width;
      mOriginHeight2 = height;
      needUpdateAllocation = true;
    }
    Type.Builder tbIn = new Type.Builder(mRS, Element.RGBA_8888(mRS));
    tbIn.setX(width).setY(height);
    //		tbIn.setX(nv21.length);
    Type.Builder tbOut = new Type.Builder(mRS, Element.U8(mRS));
    tbOut.setX(width * height + width * height / 2);

    //		if(mInAlloc2==null){
    //			mInAlloc2=Allocation.createTyped(mRS, tbIn.create(),Allocation.USAGE_SCRIPT);
    //		}
    if (mOutAlloc2 == null || needUpdateAllocation) {
      mOutAlloc2 = Allocation.createTyped(mRS, tbOut.create(), Allocation.USAGE_SCRIPT);
    }
    mInAlloc2 = Allocation.createFromBitmap(mRS, bmp);

    mScript.bind_bmpInput(mInAlloc2);
    mScript.bind_yuvOutput(mOutAlloc2);
    //
    //		mScript.bind_input(mInAlloc2);
    //		mScript.bind_output(mOutAlloc2);
    mScript.set_mImageWidth(width);
    mScript.set_mImageHeight(height);

    int[] indexBuffer = new int[height];
    for (int i = 0; i < indexBuffer.length; i++) {
      indexBuffer[i] = i;
    }

    Type.Builder tbIndex = new Type.Builder(mRS, Element.I32(mRS));
    tbIndex.setX(indexBuffer.length);
    if (mIndexAlloc2 == null || needUpdateAllocation) {
      mIndexAlloc2 = Allocation.createTyped(mRS, tbIndex.create());
      mOriginHeight2 = height;
    }
    mIndexAlloc2.copyFrom(indexBuffer);

    mScript.forEach_process_jpg2yuv(mIndexAlloc2);

    if (mOutput2 == null || needUpdateAllocation) {
      mOutputLength2 = width * height + width * height / 2;
      mOutput2 = new byte[mOutputLength2];
    }

    mOutAlloc2.copyTo(mOutput2);

    return mOutput2;
  }
Exemplo n.º 19
0
 private int[] randomIntArray(int len) {
   int t[] = new int[len];
   for (int i = 0; i < t.length; i++) {
     t[i] = random.nextInt();
   }
   in1DAlloc.copyFrom(t);
   in2DAlloc.copyFrom(t);
   in3DAlloc.copyFrom(t);
   return t;
 }
Exemplo n.º 20
0
 private short[] randomShortArray(int len) {
   short t[] = new short[len];
   for (int i = 0; i < t.length; i++) {
     t[i] = (short) (random.nextInt() & 0xffff);
   }
   in1DAlloc.copyFrom(t);
   in2DAlloc.copyFrom(t);
   in3DAlloc.copyFrom(t);
   return t;
 }
Exemplo n.º 21
0
 private long[] randomLongArray(int len) {
   long t[] = new long[len];
   for (int i = 0; i < t.length; i++) {
     t[i] = random.nextLong();
   }
   in1DAlloc.copyFrom(t);
   in2DAlloc.copyFrom(t);
   in3DAlloc.copyFrom(t);
   return t;
 }
Exemplo n.º 22
0
 private float[] randomFloatArray(int len) {
   float t[] = new float[len];
   for (int i = 0; i < t.length; i++) {
     t[i] = random.nextFloat();
   }
   in1DAlloc.copyFrom(t);
   in2DAlloc.copyFrom(t);
   in3DAlloc.copyFrom(t);
   return t;
 }
Exemplo n.º 23
0
 private double[] randomDoubleArray(int len) {
   double t[] = new double[len];
   for (int i = 0; i < t.length; i++) {
     t[i] = random.nextDouble();
   }
   in1DAlloc.copyFrom(t);
   in2DAlloc.copyFrom(t);
   in3DAlloc.copyFrom(t);
   return t;
 }
Exemplo n.º 24
0
 private void verifyResultsNativeAcospiFloatFloat(
     Allocation inV, Allocation out, boolean relaxed) {
   float[] arrayInV = new float[INPUTSIZE * 1];
   Arrays.fill(arrayInV, (float) 42);
   inV.copyTo(arrayInV);
   float[] arrayOut = new float[INPUTSIZE * 1];
   Arrays.fill(arrayOut, (float) 42);
   out.copyTo(arrayOut);
   StringBuilder message = new StringBuilder();
   boolean errorFound = false;
   for (int i = 0; i < INPUTSIZE; i++) {
     for (int j = 0; j < 1; j++) {
       // Extract the inputs.
       ArgumentsFloatFloat args = new ArgumentsFloatFloat();
       args.inV = arrayInV[i];
       // Figure out what the outputs should have been.
       Target target = new Target(relaxed);
       CoreMathVerifier.computeNativeAcospi(args, target);
       // Validate the outputs.
       boolean valid = true;
       if (!args.out.couldBe(arrayOut[i * 1 + j], 0.0005)) {
         valid = false;
       }
       if (!valid) {
         if (!errorFound) {
           errorFound = true;
           message.append("Input inV: ");
           appendVariableToMessage(message, args.inV);
           message.append("\n");
           message.append("Expected output out: ");
           appendVariableToMessage(message, args.out);
           message.append("\n");
           message.append("Actual   output out: ");
           appendVariableToMessage(message, arrayOut[i * 1 + j]);
           if (!args.out.couldBe(arrayOut[i * 1 + j], 0.0005)) {
             message.append(" FAIL");
           }
           message.append("\n");
           message.append("Errors at");
         }
         message.append(" [");
         message.append(Integer.toString(i));
         message.append(", ");
         message.append(Integer.toString(j));
         message.append("]");
       }
     }
   }
   assertFalse(
       "Incorrect output for checkNativeAcospiFloatFloat"
           + (relaxed ? "_relaxed" : "")
           + ":\n"
           + message.toString(),
       errorFound);
 }
Exemplo n.º 25
0
 /*
 本程序中大概耗时为20-30毫秒
  */
 private Bitmap blurBitmap(Bitmap bitmap, int radius) {
   RenderScript rs = RenderScript.create(this);
   Allocation overlayAlloc = Allocation.createFromBitmap(rs, bitmap);
   ScriptIntrinsicBlur blur = ScriptIntrinsicBlur.create(rs, overlayAlloc.getElement());
   blur.setInput(overlayAlloc);
   blur.setRadius(radius);
   blur.forEach(overlayAlloc);
   overlayAlloc.copyTo(bitmap);
   rs.destroy();
   return bitmap;
 }
Exemplo n.º 26
0
 public void convert(byte[] mYUVData, int imageWidth, int imageHeight, Allocation mOutAllocation) {
   set_imageHeight(imageHeight);
   set_imageWidth(imageWidth);
   try {
     yuvAllocation.copyFrom(mYUVData);
   } catch (Throwable t) {
     yuvAllocation = Allocation.createSized(mRS, Element.I8(mRS), mYUVData.length);
     yuvAllocation.copyFrom(mYUVData);
   }
   set_yuvData(yuvAllocation);
   invoke_convert(this, mOutAllocation, mOutAllocation);
 }
Exemplo n.º 27
0
  private void initializeGlobals(RenderScript RS, ScriptC_kernel s) {
    Type.Builder typeBuilder = new Type.Builder(RS, Element.I32(RS));
    int X = 5;
    s.set_dimX(X);
    typeBuilder.setX(X);
    A = Allocation.createTyped(RS, typeBuilder.create());
    s.bind_ain(A);
    B = Allocation.createTyped(RS, typeBuilder.create());
    s.bind_aout(B);

    return;
  }
Exemplo n.º 28
0
 private void verify(double[] a1, double[] a2, Allocation alloc, String s, int vsize) {
   alloc.copyTo(a2);
   for (int i = 0; i < gWidth; i++) {
     if (a1[i] != a2[i]) {
       if ((vsize == 3) && ((i % 4) == 3)) {
         continue;
       }
       throw new RSRuntimeException(s + a1[i] + ", " + a2[i] + ", at " + i);
     }
     a2[i] = 0;
   }
   alloc.copyFrom(a2);
 }
 // Allow the filter to complete without blocking the UI
 // thread.  When the message arrives that the op is complete
 // we will either mark completion or start a new filter if
 // more work is ready.  Either way, display the result.
 @Override
 public void handleMessage(Message msg) {
   synchronized (this) {
     if (mRS == null || mOutPixelsAllocation == null) {
       return;
     }
     if (mOutDisplayAllocation != mOutPixelsAllocation) {
       mOutDisplayAllocation.copyFrom(mOutPixelsAllocation);
     }
     mOutDisplayAllocation.ioSend();
     mDisplayView.invalidate();
     // mTest.runTestSendMessage();
   }
 }
Exemplo n.º 30
0
 private void verifyResultsExpm1FloatFloat(Allocation in, Allocation out, boolean relaxed) {
   float[] arrayIn = new float[INPUTSIZE * 1];
   in.copyTo(arrayIn);
   float[] arrayOut = new float[INPUTSIZE * 1];
   out.copyTo(arrayOut);
   for (int i = 0; i < INPUTSIZE; i++) {
     for (int j = 0; j < 1; j++) {
       // Extract the inputs.
       ArgumentsFloatFloat args = new ArgumentsFloatFloat();
       args.in = arrayIn[i];
       // Figure out what the outputs should have been.
       Target target = new Target(relaxed);
       CoreMathVerifier.computeExpm1(args, target);
       // Validate the outputs.
       boolean valid = true;
       if (!args.out.couldBe(arrayOut[i * 1 + j])) {
         valid = false;
       }
       if (!valid) {
         StringBuilder message = new StringBuilder();
         message.append("Input in: ");
         message.append(
             String.format(
                 "%14.8g {%8x} %15a", args.in, Float.floatToRawIntBits(args.in), args.in));
         message.append("\n");
         message.append("Expected output out: ");
         message.append(args.out.toString());
         message.append("\n");
         message.append("Actual   output out: ");
         message.append(
             String.format(
                 "%14.8g {%8x} %15a",
                 arrayOut[i * 1 + j],
                 Float.floatToRawIntBits(arrayOut[i * 1 + j]),
                 arrayOut[i * 1 + j]));
         if (!args.out.couldBe(arrayOut[i * 1 + j])) {
           message.append(" FAIL");
         }
         message.append("\n");
         assertTrue(
             "Incorrect output for checkExpm1FloatFloat"
                 + (relaxed ? "_relaxed" : "")
                 + ":\n"
                 + message.toString(),
             valid);
       }
     }
   }
 }