Search in sources :

Example 51 with Allocation

use of android.renderscript.Allocation in project OpenCamera by ageback.

the class HDRProcessor method updateAvg.

@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
public void updateAvg(Allocation allocation, int width, int height, Bitmap bitmap_new, float avg_factor, int iso, boolean release_bitmap) throws HDRProcessorException {
    if (MyDebug.LOG) {
        Log.d(TAG, "processAvg");
        Log.d(TAG, "avg_factor: " + avg_factor);
    }
    if (width != bitmap_new.getWidth() || height != bitmap_new.getHeight()) {
        if (MyDebug.LOG) {
            Log.e(TAG, "bitmaps not of same resolution");
        }
        throw new HDRProcessorException(HDRProcessorException.UNEQUAL_SIZES);
    }
    long time_s = System.currentTimeMillis();
    // create allocations
    Allocation allocation_new = Allocation.createFromBitmap(rs, bitmap_new);
    if (MyDebug.LOG)
        Log.d(TAG, "### time after creating allocations from bitmaps: " + (System.currentTimeMillis() - time_s));
    processAvgCore(allocation, allocation, allocation_new, width, height, avg_factor, iso, false);
    if (release_bitmap) {
        if (MyDebug.LOG)
            Log.d(TAG, "release bitmap");
        bitmap_new.recycle();
    }
    if (MyDebug.LOG)
        Log.d(TAG, "### time for updateAvg: " + (System.currentTimeMillis() - time_s));
}
Also used : Allocation(android.renderscript.Allocation) RequiresApi(android.support.annotation.RequiresApi)

Example 52 with Allocation

use of android.renderscript.Allocation in project OpenCamera by ageback.

the class HDRProcessor method processSingleImage.

@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
private void processSingleImage(List<Bitmap> bitmaps, boolean release_bitmaps, Bitmap output_bitmap, float hdr_alpha, int n_tiles) {
    if (MyDebug.LOG)
        Log.d(TAG, "processSingleImage");
    long time_s = System.currentTimeMillis();
    int width = bitmaps.get(0).getWidth();
    int height = bitmaps.get(0).getHeight();
    initRenderscript();
    if (MyDebug.LOG)
        Log.d(TAG, "### time after creating renderscript: " + (System.currentTimeMillis() - time_s));
    // create allocation
    Allocation allocation = Allocation.createFromBitmap(rs, bitmaps.get(0));
    Allocation output_allocation;
    if (release_bitmaps) {
        output_allocation = allocation;
    } else {
        output_allocation = Allocation.createFromBitmap(rs, output_bitmap);
    }
    /*{
			// brighten?
			int [] histo = computeHistogram(allocation, false, false);
			HistogramInfo histogramInfo = getHistogramInfo(histo);
			int median_brightness = histogramInfo.median_brightness;
			int max_brightness = histogramInfo.max_brightness;
			if( MyDebug.LOG )
				Log.d(TAG, "### time after computeHistogram: " + (System.currentTimeMillis() - time_s));
			int median_target = getMedianTarget(median_brightness, 2);
			if( MyDebug.LOG ) {
				Log.d(TAG, "median brightness: " + median_brightness);
				Log.d(TAG, "median target: " + median_target);
				Log.d(TAG, "max brightness: " + max_brightness);
			}

			if( median_target > median_brightness && max_brightness < 255 ) {
				float gain = median_target / (float)median_brightness;
				if( MyDebug.LOG )
					Log.d(TAG, "gain " + gain);
				float max_possible_value = gain*max_brightness;
				if( MyDebug.LOG )
					Log.d(TAG, "max_possible_value: " + max_possible_value);
				if( max_possible_value > 255.0f ) {
					gain = 255.0f / max_brightness;
					if( MyDebug.LOG )
						Log.d(TAG, "limit gain to: " + gain);
				}
				ScriptC_avg_brighten script = new ScriptC_avg_brighten(rs);
				script.set_gain(gain);
				script.forEach_avg_brighten_gain(allocation, output_allocation);
				allocation = output_allocation; // output is now the input for subsequent operations
				if( MyDebug.LOG )
					Log.d(TAG, "### time after avg_brighten: " + (System.currentTimeMillis() - time_s));
			}
		}*/
    adjustHistogram(allocation, output_allocation, width, height, hdr_alpha, n_tiles, time_s);
    if (release_bitmaps) {
        allocation.copyTo(bitmaps.get(0));
        if (MyDebug.LOG)
            Log.d(TAG, "time after copying to bitmap: " + (System.currentTimeMillis() - time_s));
    } else {
        output_allocation.copyTo(output_bitmap);
        if (MyDebug.LOG)
            Log.d(TAG, "time after copying to bitmap: " + (System.currentTimeMillis() - time_s));
    }
    if (MyDebug.LOG)
        Log.d(TAG, "time for processSingleImage: " + (System.currentTimeMillis() - time_s));
}
Also used : Allocation(android.renderscript.Allocation) RequiresApi(android.support.annotation.RequiresApi)

Example 53 with Allocation

use of android.renderscript.Allocation in project android_packages_apps_Dialer by LineageOS.

the class VideoCallFragment method blur.

private static void blur(Context context, Bitmap image, float blurRadius) {
    RenderScript renderScript = RenderScript.create(context);
    ScriptIntrinsicBlur blurScript = ScriptIntrinsicBlur.create(renderScript, Element.U8_4(renderScript));
    Allocation allocationIn = Allocation.createFromBitmap(renderScript, image);
    Allocation allocationOut = Allocation.createFromBitmap(renderScript, image);
    blurScript.setRadius(blurRadius);
    blurScript.setInput(allocationIn);
    blurScript.forEach(allocationOut);
    allocationOut.copyTo(image);
    blurScript.destroy();
    allocationIn.destroy();
    allocationOut.destroy();
}
Also used : RenderScript(android.renderscript.RenderScript) ScriptIntrinsicBlur(android.renderscript.ScriptIntrinsicBlur) Allocation(android.renderscript.Allocation)

Example 54 with Allocation

use of android.renderscript.Allocation in project Habba18 by chiragsastry1996.

the class BlurBuilder method blur.

public static Bitmap blur(Context ctx, Bitmap image) {
    int width = Math.round(image.getWidth() * BITMAP_SCALE);
    int height = Math.round(image.getHeight() * BITMAP_SCALE);
    Bitmap inputBitmap = Bitmap.createScaledBitmap(image, width, height, false);
    Bitmap outputBitmap = Bitmap.createBitmap(inputBitmap);
    RenderScript rs = RenderScript.create(ctx);
    ScriptIntrinsicBlur theIntrinsic = ScriptIntrinsicBlur.create(rs, Element.U8_4(rs));
    Allocation tmpIn = Allocation.createFromBitmap(rs, inputBitmap);
    Allocation tmpOut = Allocation.createFromBitmap(rs, outputBitmap);
    theIntrinsic.setRadius(BLUR_RADIUS);
    theIntrinsic.setInput(tmpIn);
    theIntrinsic.forEach(tmpOut);
    tmpOut.copyTo(outputBitmap);
    return outputBitmap;
}
Also used : Bitmap(android.graphics.Bitmap) RenderScript(android.renderscript.RenderScript) ScriptIntrinsicBlur(android.renderscript.ScriptIntrinsicBlur) Allocation(android.renderscript.Allocation)

Example 55 with Allocation

use of android.renderscript.Allocation in project AgileDev by LZ9.

the class RSBlur method blur.

@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR2)
public static Bitmap blur(Context context, Bitmap bitmap, int radius) throws RSRuntimeException {
    RenderScript rs = null;
    Allocation input = null;
    Allocation output = null;
    ScriptIntrinsicBlur blur = null;
    try {
        rs = RenderScript.create(context);
        rs.setMessageHandler(new RenderScript.RSMessageHandler());
        input = Allocation.createFromBitmap(rs, bitmap, Allocation.MipmapControl.MIPMAP_NONE, Allocation.USAGE_SCRIPT);
        output = Allocation.createTyped(rs, input.getType());
        blur = ScriptIntrinsicBlur.create(rs, Element.U8_4(rs));
        blur.setInput(input);
        blur.setRadius(radius);
        blur.forEach(output);
        output.copyTo(bitmap);
    } finally {
        if (rs != null) {
            rs.destroy();
        }
        if (input != null) {
            input.destroy();
        }
        if (output != null) {
            output.destroy();
        }
        if (blur != null) {
            blur.destroy();
        }
    }
    return bitmap;
}
Also used : RenderScript(android.renderscript.RenderScript) Allocation(android.renderscript.Allocation) ScriptIntrinsicBlur(android.renderscript.ScriptIntrinsicBlur) TargetApi(android.annotation.TargetApi)

Aggregations

Allocation (android.renderscript.Allocation)71 Bitmap (android.graphics.Bitmap)42 RenderScript (android.renderscript.RenderScript)42 ScriptIntrinsicBlur (android.renderscript.ScriptIntrinsicBlur)41 SuppressLint (android.annotation.SuppressLint)14 RequiresApi (android.support.annotation.RequiresApi)14 TargetApi (android.annotation.TargetApi)10 Type (android.renderscript.Type)6 SdkConstantType (android.annotation.SdkConstant.SdkConstantType)5 Paint (android.graphics.Paint)4 BitmapDrawable (android.graphics.drawable.BitmapDrawable)4 BitmapFactory (android.graphics.BitmapFactory)3 ByteArrayInputStream (java.io.ByteArrayInputStream)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 Canvas (android.graphics.Canvas)2 Point (android.graphics.Point)2 Element (android.renderscript.Element)2 Script (android.renderscript.Script)2 RequiresApi (androidx.annotation.RequiresApi)2 ArrayList (java.util.ArrayList)2