<commit_before>﻿using System;
using Android.Graphics;
using Android.Content;
using Android.Runtime;

namespace FFImageLoading.Transformations
{
	[Preserve(AllMembers = true)]
	public class BlurredTransformation: TransformationBase
	{
		private Context _context;

		public BlurredTransformation()
		{
			Radius = 20d;
			_context = Android.App.Application.Context;
		}

		public BlurredTransformation(double radius)
		{
			Radius = radius;
			_context = Android.App.Application.Context;
		}

		public double Radius { get; set; }

		public override string Key
		{
			get { return string.Format("BlurredTransformation,radius={0}", Radius); }
		}

		protected override Bitmap Transform(Bitmap source)
		{
			return ToBlurred(source, _context, (float)Radius);
		}

		public static Bitmap ToBlurred(Bitmap source, Context context, float radius)
		{
			if ((int)Android.OS.Build.VERSION.SdkInt >= 17)
			{
				Bitmap bitmap = Bitmap.CreateBitmap(source.Width, source.Height, Bitmap.Config.Argb8888);

				using (Canvas canvas = new Canvas(bitmap))
				{
					canvas.DrawBitmap(source, 0, 0, null);
					using (Android.Renderscripts.RenderScript rs = Android.Renderscripts.RenderScript.Create(context))
					{
						using (Android.Renderscripts.Allocation overlayAlloc = Android.Renderscripts.Allocation.CreateFromBitmap(rs, bitmap))
						{
							using (Android.Renderscripts.ScriptIntrinsicBlur blur = Android.Renderscripts.ScriptIntrinsicBlur.Create(rs, overlayAlloc.Element))
							{
								blur.SetInput(overlayAlloc);
								blur.SetRadius(radius);	
								blur.ForEach(overlayAlloc);
								overlayAlloc.CopyTo(bitmap);

								rs.Destroy();
								return bitmap;
							}
						}
					}
				}<commit_msg>#463 Android BlurredTransformation fixes<commit_after>﻿using System;
using Android.Graphics;
using Android.Content;
using Android.Runtime;

namespace FFImageLoading.Transformations
{
	[Preserve(AllMembers = true)]
	public class BlurredTransformation: TransformationBase
	{
		private Context _context;

		public BlurredTransformation()
		{
			Radius = 20d;
			_context = new ContextWrapper(Android.App.Application.Context);
		}

		public BlurredTransformation(double radius)
		{
			Radius = radius;
			_context = new ContextWrapper(Android.App.Application.Context);
		}

		double _radius;
		public double Radius
		{
			get
			{
				return _radius;
			}

			set
			{
				_radius = Math.Min(25, Math.Max(value, 0));
			}
		}

		public static bool LegacyMode { get; set; } = false;

		public override string Key
		{
			get { return string.Format("BlurredTransformation,radius={0}", Radius); }
		}

		protected override Bitmap Transform(Bitmap source)
		{
			return ToBlurred(source, _context, (float)Radius);
		}

		public static Bitmap ToBlurred(Bitmap source, Context context, float radius)
		{
			if (!LegacyMode && (int)Android.OS.Build.VERSION.SdkInt >= 17)
			{
				Bitmap bitmap = Bitmap.CreateBitmap(source.Width, source.Height, Bitmap.Config.Argb8888);

				using (Canvas canvas = new Canvas(bitmap))
				{
					canvas.DrawBitmap(source, 0, 0, null);
					using (Android.Renderscripts.RenderScript rs = Android.Renderscripts.RenderScript.Create(context))
					{
						using (Android.Renderscripts.Allocation overlayAlloc = Android.Renderscripts.Allocation.CreateFromBitmap(rs, bitmap))
						{
							using (Android.Renderscripts.ScriptIntrinsicBlur blur = Android.Renderscripts.ScriptIntrinsicBlur.Create(rs, overlayAlloc.Element))
							{
								blur.SetInput(overlayAlloc);
								blur.SetRadius(radius);	
								blur.ForEach(overlayAlloc);
								overlayAlloc.CopyTo(bitmap);

								rs.Destroy();
								return bitmap;
							}
						}
					}
				}
{'fraction_non_alphanumeric': 0.10225727495240686, 'fraction_numerical': 0.007614903453902638, 'mean_word_length': 3.557620817843866, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2144087', 'n_tokens_mistral': 1457, 'n_tokens_neox': 1090, 'n_words': 223}