本文整理汇总了Java中android.support.v8.renderscript.RenderScript类的典型用法代码示例。如果您正苦于以下问题:Java RenderScript类的具体用法?Java RenderScript怎么用?Java RenderScript使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
RenderScript类属于android.support.v8.renderscript包,在下文中一共展示了RenderScript类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: initialize
import android.support.v8.renderscript.RenderScript; //导入依赖的package包/类
/**
* Initialize HeifReader module.
*
* @param context Context.
*/
public static void initialize(Context context) {
mRenderScript = RenderScript.create(context);
mCacheDir = context.getCacheDir();
// find best HEVC decoder
mDecoderName = null;
mDecoderSupportedSize = new Size(0, 0);
int numCodecs = MediaCodecList.getCodecCount();
for (int i = 0; i < numCodecs; i++) {
MediaCodecInfo codecInfo = MediaCodecList.getCodecInfoAt(i);
if (codecInfo.isEncoder()) {
continue;
}
for (String type : codecInfo.getSupportedTypes()) {
if (type.equalsIgnoreCase(MediaFormat.MIMETYPE_VIDEO_HEVC)) {
MediaCodecInfo.CodecCapabilities cap = codecInfo.getCapabilitiesForType(MediaFormat.MIMETYPE_VIDEO_HEVC);
MediaCodecInfo.VideoCapabilities vcap = cap.getVideoCapabilities();
Size supportedSize = new Size(vcap.getSupportedWidths().getUpper(), vcap.getSupportedHeights().getUpper());
Log.d(TAG, "HEVC decoder=\"" + codecInfo.getName() + "\""
+ " supported-size=" + supportedSize
+ " color-formats=" + Arrays.toString(cap.colorFormats)
);
if (mDecoderSupportedSize.getWidth() * mDecoderSupportedSize.getHeight() < supportedSize.getWidth() * supportedSize.getHeight()) {
mDecoderName = codecInfo.getName();
mDecoderSupportedSize = supportedSize;
}
}
}
}
if (mDecoderName == null) {
throw new RuntimeException("no HEVC decoding support");
}
Log.i(TAG, "HEVC decoder=\"" + mDecoderName + "\" supported-size=" + mDecoderSupportedSize);
}
示例2: createBlurredImageFromBitmap
import android.support.v8.renderscript.RenderScript; //导入依赖的package包/类
public static Drawable createBlurredImageFromBitmap(Bitmap bitmap, Context context, int inSampleSize) {
RenderScript rs = RenderScript.create(context);
final BitmapFactory.Options options = new BitmapFactory.Options();
options.inSampleSize = inSampleSize;
ByteArrayOutputStream stream = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, stream);
byte[] imageInByte = stream.toByteArray();
ByteArrayInputStream bis = new ByteArrayInputStream(imageInByte);
Bitmap blurTemplate = BitmapFactory.decodeStream(bis, null, options);
final android.support.v8.renderscript.Allocation input = android.support.v8.renderscript.Allocation.createFromBitmap(rs, blurTemplate);
final android.support.v8.renderscript.Allocation output = android.support.v8.renderscript.Allocation.createTyped(rs, input.getType());
final android.support.v8.renderscript.ScriptIntrinsicBlur script = android.support.v8.renderscript.ScriptIntrinsicBlur.create(rs, android.support.v8.renderscript.Element.U8_4(rs));
script.setRadius(8f);
script.setInput(input);
script.forEach(output);
output.copyTo(blurTemplate);
return new BitmapDrawable(context.getResources(), blurTemplate);
}
示例3: BatchNormalization
import android.support.v8.renderscript.RenderScript; //导入依赖的package包/类
public BatchNormalization(Context ctx, RenderScript rs, int size) {
super(ctx, rs);
this.size = size;
gamma = new float[size];
beta = new float[size];
avg_mean = new float[size];
avg_var = new float[size];
// Create RS Allocations.
gamma_alloc = Allocation.createSized(mRS, Element.F32(mRS), size);
beta_alloc = Allocation.createSized(mRS, Element.F32(mRS), size);
avg_mean_alloc = Allocation.createSized(mRS, Element.F32(mRS), size);
avg_var_alloc = Allocation.createSized(mRS, Element.F32(mRS), size);
// Initialize the BatchNormalization kernel;
rs_BN = new ScriptC_batchnormalization(mRS);
// Set the global variables for the RS kernel.
rs_BN.set_beta_alloc(beta_alloc);
rs_BN.set_gamma_alloc(gamma_alloc);
rs_BN.set_mean_alloc(avg_mean_alloc);
rs_BN.set_var_alloc(avg_var_alloc);
rs_BN.set_size(size);
}
示例4: blendProcess
import android.support.v8.renderscript.RenderScript; //导入依赖的package包/类
private static ImageProcess blendProcess(final Context context) {
return new ImageProcess() {
@Override
public Bitmap processImage(RenderScript rs, Bitmap bitmap, ImageFormat imageFormat) {
BitmapFactory.Options options = new BitmapFactory.Options();
options.inSampleSize = 4;
options.inDither = false;
options.inPurgeable = true;
Bitmap sampleEdgeBitmap = BitmapFactory.decodeResource(context.getResources(),
R.drawable.sample_edge, options);
if (imageFormat == ImageFormat.BITMAP) {
Blend.add(rs, bitmap, sampleEdgeBitmap);
return sampleEdgeBitmap;
} else {
Nv21Image nv21Image = Nv21Image.bitmapToNV21(rs, bitmap);
Nv21Image dstNv21Image = Nv21Image.bitmapToNV21(rs, sampleEdgeBitmap);
Blend.add(rs, nv21Image.nv21ByteArray, nv21Image.width, nv21Image.height,
dstNv21Image.nv21ByteArray);
return Nv21Image.nv21ToBitmap(rs, dstNv21Image.nv21ByteArray,
dstNv21Image.width, nv21Image.height);
}
}
};
}
示例5: yuvToRgb
import android.support.v8.renderscript.RenderScript; //导入依赖的package包/类
/**
* Converts a NV21 image to a Bitmap.
* @param nv21Image the NV21 image to convert.
*/
public static Bitmap yuvToRgb(RenderScript rs, Nv21Image nv21Image) {
long startTime = System.currentTimeMillis();
Type.Builder yuvTypeBuilder = new Type.Builder(rs, Element.U8(rs))
.setX(nv21Image.nv21ByteArray.length);
Type yuvType = yuvTypeBuilder.create();
Allocation yuvAllocation = Allocation.createTyped(rs, yuvType, Allocation.USAGE_SCRIPT);
yuvAllocation.copyFrom(nv21Image.nv21ByteArray);
Type.Builder rgbTypeBuilder = new Type.Builder(rs, Element.RGBA_8888(rs));
rgbTypeBuilder.setX(nv21Image.width);
rgbTypeBuilder.setY(nv21Image.height);
Allocation rgbAllocation = Allocation.createTyped(rs, rgbTypeBuilder.create());
ScriptIntrinsicYuvToRGB yuvToRgbScript = ScriptIntrinsicYuvToRGB.create(rs, Element.RGBA_8888(rs));
yuvToRgbScript.setInput(yuvAllocation);
yuvToRgbScript.forEach(rgbAllocation);
Bitmap bitmap = Bitmap.createBitmap(nv21Image.width, nv21Image.height, Bitmap.Config.ARGB_8888);
rgbAllocation.copyTo(bitmap);
Log.d("NV21", "Conversion to Bitmap: " + (System.currentTimeMillis() - startTime) + "ms");
return bitmap;
}
示例6: apply
import android.support.v8.renderscript.RenderScript; //导入依赖的package包/类
public static Bitmap apply(Context context, Bitmap sentBitmap, int radius) {
final Bitmap bitmap = sentBitmap.copy(sentBitmap.getConfig(), true);
final RenderScript rs = RenderScript.create(context);
final Allocation input = Allocation.createFromBitmap(rs, sentBitmap, Allocation.MipmapControl.MIPMAP_NONE, Allocation.USAGE_SCRIPT);
final Allocation output = Allocation.createTyped(rs, input.getType());
final ScriptIntrinsicBlur script = ScriptIntrinsicBlur.create(rs, Element.U8_4(rs));
script.setRadius(radius);
script.setInput(input);
script.forEach(output);
output.copyTo(bitmap);
sentBitmap.recycle();
rs.destroy();
input.destroy();
output.destroy();
script.destroy();
return bitmap;
}
示例7: render
import android.support.v8.renderscript.RenderScript; //导入依赖的package包/类
@WorkerThread
public Bitmap render(Bitmap source) {
Bitmap bitmap = source;
RenderScript rs = RenderScript.create(context);
if (getSize() > 0)
bitmap = scaleDown(bitmap);
Bitmap output = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Bitmap.Config.ARGB_8888);
Allocation inAlloc = Allocation.createFromBitmap(rs, bitmap, Allocation.MipmapControl.MIPMAP_NONE, Allocation.USAGE_GRAPHICS_TEXTURE);
Allocation outAlloc = Allocation.createFromBitmap(rs, output);
ScriptIntrinsicBlur script = ScriptIntrinsicBlur.create(rs, inAlloc.getElement()); // Element.U8_4(rs));
script.setRadius(getRadius());
script.setInput(inAlloc);
script.forEach(outAlloc);
outAlloc.copyTo(output);
rs.destroy();
return output;
}
示例8: resize
import android.support.v8.renderscript.RenderScript; //导入依赖的package包/类
/**
* Resizes a Bitmap image to a target width and height.
*/
public static Bitmap resize(RenderScript rs, Bitmap inputBitmap, int targetWidth,
int targetHeight) {
RSToolboxContext bitmapRSContext = RSToolboxContext.createFromBitmap(rs, inputBitmap);
Bitmap.Config config = inputBitmap.getConfig();
Bitmap outputBitmap = Bitmap.createBitmap(targetWidth, targetHeight, config);
Type outType = Type.createXY(bitmapRSContext.rs, bitmapRSContext.ain.getElement(), targetWidth,
targetHeight);
Allocation aout = Allocation.createTyped(bitmapRSContext.rs, outType);
ScriptIntrinsicResize resizeScript = ScriptIntrinsicResize.create(bitmapRSContext.rs);
resizeScript.setInput(bitmapRSContext.ain);
resizeScript.forEach_bicubic(aout);
aout.copyTo(outputBitmap);
return outputBitmap;
}
示例9: luminanceHistogram
import android.support.v8.renderscript.RenderScript; //导入依赖的package包/类
/**
* Computes a luminance histogram of a Bitmap.
* @return a 256-length int array of integer frequencies at luminance level.
*/
public static int[] luminanceHistogram(RenderScript rs, Bitmap inputBitmap) {
RSToolboxContext bitmapRSContext = RSToolboxContext.createFromBitmap(rs, inputBitmap);
Allocation aout = Allocation.createSized(bitmapRSContext.rs, Element.I32(bitmapRSContext.rs),
COLOR_DEPTH);
ScriptIntrinsicHistogram histogramScript = ScriptIntrinsicHistogram.create(
bitmapRSContext.rs, bitmapRSContext.ain.getElement());
histogramScript.setOutput(aout);
histogramScript.forEach(bitmapRSContext.ain);
int[] histogram = new int[COLOR_DEPTH];
aout.copyTo(histogram);
return histogram;
}
示例10: rgbaHistograms
import android.support.v8.renderscript.RenderScript; //导入依赖的package包/类
/**
* Computes a RGBA histogram of a Bitmap.
* @return a 1024-length int array of integer frequencies at each channel intensity in the
* following interleaved format [R0,G0,B0,A0,R1,G1,B1,A1...]
*/
public static int[] rgbaHistograms(RenderScript rs, Bitmap inputBitmap) {
RSToolboxContext bitmapRSContext = RSToolboxContext.createFromBitmap(rs, inputBitmap);
Allocation aout = Allocation.createSized(bitmapRSContext.rs, Element.I32_4(bitmapRSContext.rs),
COLOR_DEPTH);
ScriptIntrinsicHistogram histogramScript = ScriptIntrinsicHistogram.create(
bitmapRSContext.rs, bitmapRSContext.ain.getElement());
histogramScript.setOutput(aout);
histogramScript.forEach(bitmapRSContext.ain);
int[] histograms = new int[CHANNELS * COLOR_DEPTH];
aout.copyTo(histograms);
// RGBA interleaved: [R0,G0,B0,A0,R1,G1,B1,A1...
return histograms;
}
示例11: getExpectedHistogram
import android.support.v8.renderscript.RenderScript; //导入依赖的package包/类
@NonNull
private int[] getExpectedHistogram(RenderScript rs, Bitmap bmpFromNv21, Op op) {
Allocation ain = Allocation.createFromBitmap(rs, bmpFromNv21);
Allocation aout;
int[] histogram;
if (op == Op.LUMINANCE) {
aout = Allocation.createSized(rs, Element.I32(rs), Histogram.COLOR_DEPTH);
histogram = new int[Histogram.COLOR_DEPTH];
}
else {
aout = Allocation.createSized(rs, Element.I32_4(rs), Histogram.COLOR_DEPTH);
histogram = new int[Histogram.COLOR_DEPTH * Histogram.CHANNELS];
}
ScriptIntrinsicHistogram histogramScript = ScriptIntrinsicHistogram.create(
rs, ain.getElement());
histogramScript.setOutput(aout);
histogramScript.forEach(ain);
aout.copyTo(histogram);
return histogram;
}
示例12: doBlur
import android.support.v8.renderscript.RenderScript; //导入依赖的package包/类
/**
* blur a given bitmap
*
* @param sentBitmap bitmap to blur
* @param radius blur radius
* @param canReuseInBitmap true if bitmap must be reused without blur
* @param context used by RenderScript, can be null if RenderScript disabled
* @return blurred bitmap
*/
public static Bitmap doBlur(Bitmap sentBitmap, int radius, boolean canReuseInBitmap, Context context) {
Bitmap bitmap;
if (canReuseInBitmap) {
bitmap = sentBitmap;
} else {
bitmap = sentBitmap.copy(sentBitmap.getConfig(), true);
}
if (bitmap.getConfig() == Bitmap.Config.RGB_565) {
// RenderScript hates RGB_565 so we convert it to ARGB_8888
// (see http://stackoverflow.com/questions/21563299/
// defect-of-image-with-scriptintrinsicblur-from-support-library)
bitmap = convertRGB565toARGB888(bitmap);
}
try {
final RenderScript rs = RenderScript.create(context);
final Allocation input = Allocation.createFromBitmap(rs, bitmap, Allocation.MipmapControl.MIPMAP_NONE,
Allocation.USAGE_SCRIPT);
final Allocation output = Allocation.createTyped(rs, input.getType());
final ScriptIntrinsicBlur script = ScriptIntrinsicBlur.create(rs, Element.U8_4(rs));
script.setRadius(radius);
script.setInput(input);
script.forEach(output);
output.copyTo(bitmap);
return bitmap;
} catch (RSRuntimeException e) {
Log.e(TAG, "RenderScript known error : https://code.google.com/p/android/issues/detail?id=71347 "
+ "continue with the FastBlur approach.");
}
return null;
}
示例13: convertYuv420ToBitmap
import android.support.v8.renderscript.RenderScript; //导入依赖的package包/类
private static Bitmap convertYuv420ToBitmap(Image image) {
RenderScript rs = mRenderScript;
final int width = image.getWidth();
final int height = image.getHeight();
// prepare input Allocation for RenderScript
Type.Builder inType = new Type.Builder(rs, Element.U8(rs)).setX(width).setY(height).setYuvFormat(ImageFormat.YV12);
Allocation inAlloc = Allocation.createTyped(rs, inType.create(), Allocation.USAGE_SCRIPT);
byte[] rawBuffer = new byte[inAlloc.getBytesSize()];
int lumaSize = width * height;
int chromaSize = (width / 2) * (height / 2);
Image.Plane[] planes = image.getPlanes();
planes[0].getBuffer().get(rawBuffer, 0, lumaSize);
planes[1].getBuffer().get(rawBuffer, lumaSize, chromaSize);
planes[2].getBuffer().get(rawBuffer, lumaSize + chromaSize, chromaSize);
inAlloc.copyFromUnchecked(rawBuffer);
// prepare output Allocation for RenderScript
Bitmap bmp = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
Allocation outAlloc = Allocation.createFromBitmap(rs, bmp, Allocation.MipmapControl.MIPMAP_NONE, Allocation.USAGE_SCRIPT | Allocation.USAGE_SHARED);
// convert YUV to RGB colorspace
ScriptC_yuv2rgb converter = new ScriptC_yuv2rgb(rs);
converter.set_gYUV(inAlloc);
converter.forEach_convert(outAlloc);
outAlloc.copyTo(bmp);
return bmp;
}
示例14: doBlur
import android.support.v8.renderscript.RenderScript; //导入依赖的package包/类
/**
* blur a given bitmap
*
* @param sentBitmap bitmap to blur
* @param radius blur radius
* @param canReuseInBitmap true if bitmap must be reused without blur
* @param context used by RenderScript, can be null if RenderScript disabled
* @return blurred bitmap
*/
public static Bitmap doBlur(Bitmap sentBitmap, int radius, boolean canReuseInBitmap, Context context) {
Bitmap bitmap;
if (canReuseInBitmap) {
bitmap = sentBitmap;
} else {
bitmap = sentBitmap.copy(sentBitmap.getConfig(), true);
}
if (bitmap.getConfig() == Bitmap.Config.RGB_565) {
// RenderScript hates RGB_565 so we convert it to ARGB_8888
// (see http://stackoverflow.com/questions/21563299/
// defect-of-image-with-scriptintrinsicblur-from-support-library)
bitmap = convertRGB565toARGB888(bitmap);
}
try {
final RenderScript rs = RenderScript.create(context);
final Allocation input = Allocation.createFromBitmap(rs, bitmap, Allocation.MipmapControl.MIPMAP_NONE,
Allocation.USAGE_SCRIPT);
final Allocation output = Allocation.createTyped(rs, input.getType());
final ScriptIntrinsicBlur script = ScriptIntrinsicBlur.create(rs, Element.U8_4(rs));
script.setRadius(radius);
script.setInput(input);
script.forEach(output);
output.copyTo(bitmap);
return bitmap;
} catch (RSRuntimeException e) {
Log.e(TAG, "RenderScript known error : https://code.google.com/p/android/issues/detail?id=71347 "
+ "continue with the FastBlur approach.");
}
return null;
}
示例15: getBlurBitmap
import android.support.v8.renderscript.RenderScript; //导入依赖的package包/类
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
@WorkerThread
private Bitmap getBlurBitmap(Context context, Bitmap inBitmap, float radius) {
if (context == null || inBitmap == null) {
throw new IllegalArgumentException("have not called setParams() before call execute()");
}
int width = Math.round(inBitmap.getWidth() * SCALE);
int height = Math.round(inBitmap.getHeight() * SCALE);
Bitmap in = Bitmap.createScaledBitmap(inBitmap, width, height, false);
Bitmap out = Bitmap.createBitmap(in);
RenderScript rs = RenderScript.create(context);
ScriptIntrinsicBlur blurScript = ScriptIntrinsicBlur.create(rs, Element.U8_4(rs));
Allocation allocationIn = Allocation.createFromBitmap(rs, in);
Allocation allocationOut = Allocation.createFromBitmap(rs, out);
blurScript.setRadius(radius);
blurScript.setInput(allocationIn);
blurScript.forEach(allocationOut);
allocationOut.copyTo(out);
allocationIn.destroy();
allocationOut.destroy();
blurScript.destroy();
rs.destroy();
return out;
}