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_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_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);
  }
  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);
  }
Пример #6
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;
  }
Пример #7
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;
  }
Пример #8
0
  public byte[] decodeNV21ToRGB888(byte[] nv21, int width, int height, int degree) {

    Type.Builder tbIn = new Type.Builder(mRS, Element.U8(mRS));
    tbIn.setX(nv21.length);
    Type.Builder tbOut = new Type.Builder(mRS, Element.U8(mRS));
    tbOut.setX(width * height * 4);

    if (mInAlloc == null) {
      mInAlloc = Allocation.createTyped(mRS, tbIn.create());
    }
    if (mOutAlloc == null) {
      mOutAlloc = Allocation.createTyped(mRS, tbOut.create());
    }
    mInAlloc.copyFrom(nv21);

    mScript.bind_input(mInAlloc);
    mScript.bind_output(mOutAlloc);
    mScript.set_rotateDegree(degree);
    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 (mIndexAlloc == null) {
      mIndexAlloc = Allocation.createTyped(mRS, tbIndex.create());
    }
    mIndexAlloc.copyFrom(indexBuffer);

    mScript.forEach_process(mIndexAlloc);

    if (mOutput == null || mOutputLength == -1) {
      mOutputLength = width * height * 4;
      mOutput = new byte[mOutputLength];
    }

    mOutAlloc.copyTo(mOutput);

    return mOutput;
  }
Пример #9
0
  public void testScript() {
    Script S = new ScriptC_primitives(mRS);

    S.setTimeZone("America/New_York");

    S.setVar(4, 9.0f); // floatTest
    S.setVar(5, 9.0); // doubleTest
    S.setVar(6, 7); // charTest
    S.setVar(7, 300); // shortTest
    S.setVar(8, 20000); // intTest
    S.setVar(9, 20000000000l); // longTest
    S.setVar(11, true); // boolTest

    FieldPacker fp = new FieldPacker(4);
    fp.addI32(3);
    S.setVar(12, fp); // structTest

    Type.Builder tb = new Type.Builder(mRS, Element.I32(mRS));
    Allocation a = Allocation.createTyped(mRS, tb.create());
    S.setVar(13, a); // allocationTest

    S.bindAllocation(a, 14); // intPtrTest
  }