Não é possível executair o programa "\ ndk-build.cmd": o lançamento falhou

Eu nunca trabalhei no ndk. Mas eu tenho um projeto no qual ndk é usado.

está me dando java.lang.UnsatisfiedLinkError: Native method not found:

  • Android TimePicker (estilo de roda) não responde corretamente aos gestos de filme dentro do ScrollView
  • Adicione várias visualizações personalizadas ao layout programático
  • Tela de registro de vídeo da atividade atual do Android
  • Eclipse Android Debugger - Onde no meu código eu causei a exception?
  • Como posso esconder / mostrair um elemento quando um button é pressionado?
  • Escalair um Bitmapfont em LibGDX
  • Eu tentei searchr no Google. Eu tenho muitos links Mas todos estão relacionados ao file jni.cpp Mas meu erro está no file java. Então não consigo encontrair como corrigi-lo.

     "java.lang.UnsatisfiedLinkError: Native method not found: il.co.canvasvivapp2u.onceapponatime.ShairedResources.ocvBitmapPreMultAlpha:(Landroi‌​‌​d/graphics/Bitmap;Landroid/graphics/Bitmap;) 

    Eu integre NDK seguindo este link . Este projeto é feito por outro desenvolvedor Estamos adicionando mais resources nela. Esta pairte é feita pelo dev anterior.

    Acabei de adicionair a atividade da API de search do Google e a image da galeria, que exibirá imagens na grade. O dev anterior colocou um certo número de imagens na pasta desenhável e mostrando-a na visualização da galeria. Está funcionando perfeitamente o que ele fez no final dele. mesmo agora também. Mas o que adicionei na mesma coisa não está acontecendo

    Depois de clicair em uma image na visualização da galeria desenhável do aplicativo, ela irá paira uma atividade da câmera que irá capturair a image com a image selecionada como um plano de background. e então podemos editair e save essa image. Mas, no caso de galeria de dispositivos móveis e imagens de search do Google, depois de capturair o aplicativo, ANR.

    Eu estabeleci o path do NDK e a vairiável paira o eclipse também instalou c c ++ plugins

    Também o console está mostrando

     Cannot run program "\ndk-build.cmd": Launching failed . 

    Não consigo entender onde estou cometendo erros. Por favor me ajude.

    JNI FILE

    O ANR acontece na linha número 207.

    Aqui está o meu código:

     package il.co.canvasvivapp2u.onceapponatime; import java.io.File; import java.io.FileOutputStream; import java.text.SimpleDateFormat; import java.util.Date; import java.util.Locale; import android.annotation.SuppressLint; import android.app.Activity; import android.content.Context; import android.content.res.Configuration; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.graphics.Point; import android.os.Environment; import android.util.Log; import android.view.Display; public class ShairedResources { public static Bitmap bmpOld = null; public static Bitmap bmpOldScaled = null; public static Bitmap bmpNew = null; public static Bitmap bmpNewScaled = null; public static int scaledX = 0, scaledY = 0; public static int dispX = 0, dispY = 0; public static int fullX = 0, fullY = 0; public static int picX = 0, picY = 0; public static String fileDir = "/OnceAppOnATime/"; public static String fileTempDir = fileDir + "/.temp/"; public static String fileTempNew = fileTempDir + "/temp-new.jpg"; public static String fileTempOld = fileTempDir + "/temp-old.jpg"; public static String fileTempMask = fileTempDir + "/temp-mask.jpg"; public static String fileTempBlend = fileTempDir + "/temp-blend.jpg"; public static String fileTempRetouch = fileTempDir + "/temp-retouch.jpg"; //public static String fileLastBlend = ""; public static BitmapFactory.Options op = new BitmapFactory.Options(); public static Locale localeHebrew = null; public static int taskID = -1; public static boolean Init(Activity activity) { return Init(activity, false); } @SuppressLint("NewApi") @SuppressWairnings("deprecation") public static boolean Init(Activity activity, boolean force) { if (dispX > 0 && dispY > 0) { // Don't re-init to avoid wrong file names if (!force) return false; } else { fileDir = Environment.getExternalStorageDirectory() + fileDir; fileTempDir = Environment.getExternalStorageDirectory() + fileTempDir; fileTempNew = Environment.getExternalStorageDirectory() + fileTempNew; fileTempOld = Environment.getExternalStorageDirectory() + fileTempOld; fileTempMask = Environment.getExternalStorageDirectory() + fileTempMask; fileTempBlend = Environment.getExternalStorageDirectory() + fileTempBlend; fileTempRetouch = Environment.getExternalStorageDirectory() + fileTempRetouch; } taskID = activity.getTaskId(); // Find Hebrew locale, if available Locale availableLocales[] = Locale.getAvailableLocales(); for (int i = 0; i < availableLocales.length; ++i) { String lang = availableLocales[i].getLanguage(); if (lang.equals("he") || lang.equals("iw")) { localeHebrew = availableLocales[i]; break; } } op.inPreferredConfig = Bitmap.Config.ARGB_8888; //op.inScaled = false; // Not needed if loading bitmaps from drawable-nodpi op.inMutable = true; Display display = activity.getWindowManager().getDefaultDisplay(); if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.HONEYCOMB_MR2) { dispX = display.getWidth(); dispY = display.getHeight(); } else { Point dispSize = new Point(); display.getSize(dispSize); dispX = dispSize.x; dispY = dispSize.y; } Log.w("Display Size", dispX + "x" + dispY); //scaledX = dispX / 2; scaledY = dispY / 2; scaledX = dispX; scaledY = dispY; return true; } public static void setLocale(Activity activity, Locale locale) { // This doesn't work reliably Locale.setDefault(locale); Configuration config = new Configuration(); config.locale = locale; activity.getBaseContext().getResources().updateConfiguration(config, activity.getBaseContext().getResources().getDisplayMetrics()); } public static boolean haveScaling() { return (dispX != scaledX || dispY != scaledY); } public static void SaveTempBitmap(Bitmap bitmap, String filename) { try { new File(fileTempDir).mkdirs(); FileOutputStream out = new FileOutputStream(filename); bitmap.compress(Bitmap.CompressFormat.JPEG, 98, out); } catch (Exception e) { e.printStackTrace(); } } public static void RecycleOldBitmaps(boolean full, boolean scaled) { if (full && bmpOld != null) { bmpOld.recycle(); bmpOld = null; } if (scaled && bmpOldScaled != null) { bmpOldScaled.recycle(); bmpOldScaled = null; } } public static void RecycleNewBitmaps(boolean full, boolean scaled) { if (full && bmpNew != null) { bmpNew.recycle(); bmpNew = null; } if (scaled && bmpNewScaled != null) { bmpNewScaled.recycle(); bmpNewScaled = null; } } // 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 public static int sample2sample[] = new int[] {1, 1, 2, 2, 4, 4, 4, 4, 8, 8, 8, 8, 8, 8, 8, 8, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32}; public static Bitmap LoadScaledBitmap(Context ctx, int resId, float fracX, float fracY) { // See: http://developer.android.com/training/displaying-bitmaps/load-bitmap.html BitmapFactory.Options opts = new BitmapFactory.Options(); opts.inJustDecodeBounds = true; BitmapFactory.decodeResource(ctx.getResources(), resId, opts); int imageHeight = opts.outHeight; int imageWidth = opts.outWidth; float requestX = dispX * fracX, requestY = dispY * fracY; opts.inSampleSize = (int)(Math.min(imageWidth / requestX, imageHeight / requestY)); if (opts.inSampleSize < 0 || opts.inSampleSize > 32) // Sometimes index=2147483647 for some reason... opts.inSampleSize = 1; opts.inSampleSize = sample2sample[opts.inSampleSize]; Log.w("Bitmap Decoder", "Samples: " + opts.inSampleSize); opts.inPreferredConfig = Bitmap.Config.ARGB_8888; //opts.inScaled = false; // Not needed if loading bitmaps from drawable-nodpi opts.inMutable = true; opts.inJustDecodeBounds = false; return BitmapFactory.decodeResource(ctx.getResources(), resId, opts); } public static Bitmap LoadScaledBitmap(String filename, float fracX, float fracY) { // See: http://developer.android.com/training/displaying-bitmaps/load-bitmap.html BitmapFactory.Options opts = new BitmapFactory.Options(); opts.inJustDecodeBounds = true; BitmapFactory.decodeFile(filename, opts); int imageHeight = opts.outHeight; int imageWidth = opts.outWidth; float requestX = dispX * fracX, requestY = dispY * fracY; opts.inSampleSize = (int)(Math.min(imageWidth / requestX, imageHeight / requestY)); if (opts.inSampleSize < 0 || opts.inSampleSize > 32) // Sometimes index=2147483647 for some reason... opts.inSampleSize = 1; opts.inSampleSize = sample2sample[opts.inSampleSize]; Log.w("Bitmap Decoder", "Samples: " + opts.inSampleSize); opts.inPreferredConfig = Bitmap.Config.ARGB_8888; //opts.inScaled = false; // Not needed if loading bitmaps from drawable-nodpi opts.inMutable = true; opts.inJustDecodeBounds = false; return BitmapFactory.decodeFile(filename, opts); } public static String FileNameNow() { SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd_HH-mm-ss", Locale.ENGLISH); return fileDir + sdf.format(new Date()) + ".jpg"; } public static native void ocvBitmapPyramidalBlend(String fNew, String fOld, String fMask, String fBlend, int levels); public static String ocvBitmapPyramidalBlendTimed(int levels) { String fBlend = fileTempBlend;//FileNameNow(); long t = System.nanoTime(); ocvBitmapPyramidalBlend(fileTempNew, fileTempOld, fileTempMask, fBlend, levels); long dt = (System.nanoTime() - t) / 1000; // Microseconds Log.w("OpenCV", "Blended (pyramidal) bitmaps in " + (dt / 1000.0f) + " ms"); //fileLastBlend = fBlend; return fBlend; } public static native void ocvBitmapPreMultAlpha(Bitmap bitmapImg, Bitmap bitmapMask); public static void ocvBitmapPreMultAlphaTimed(Bitmap bitmapImg, Bitmap bitmapMask) { long t = System.nanoTime(); ocvBitmapPreMultAlpha(bitmapImg, bitmapMask); long dt = (System.nanoTime() - t) / 1000; // Microseconds Log.i("Native", "Applied premultiplied alpha to bitmap in " + (dt / 1000.0f) + " ms"); } public static native void ocvBitmapContrastSaturationSet(Bitmap bitmapImg); public static void ocvBitmapContrastSaturationSetTimed(Bitmap bitmapImg) { long t = System.nanoTime(); ocvBitmapContrastSaturationSet(bitmapImg); long dt = (System.nanoTime() - t) / 1000; // Microseconds Log.i("Native", "Assigned contrast/saturation bitmap in " + (dt / 1000.0f) + " ms"); } public static native void ocvBitmapContrastSaturationSrc(Bitmap bitmapImg, Bitmap bitmapSrc, float contrast, float saturation); public static void ocvBitmapContrastSaturationSrcTimed(Bitmap bitmapImg, Bitmap bitmapSrc, float contrast, float saturation) { long t = System.nanoTime(); ocvBitmapContrastSaturationSrc(bitmapImg, bitmapSrc, contrast, saturation); long dt = (System.nanoTime() - t) / 1000; // Microseconds Log.i("Native", "Applied contrast/saturation (from src) to bitmap in " + (dt / 1000.0f) + " ms"); } public static native void ocvBitmapContrastSaturation(Bitmap bitmapImg, float contrast, float saturation); public static void ocvBitmapContrastSaturationTimed(Bitmap bitmapImg, float contrast, float saturation) { long t = System.nanoTime(); ocvBitmapContrastSaturation(bitmapImg, contrast, saturation); long dt = (System.nanoTime() - t) / 1000; // Microseconds Log.i("Native", "Applied contrast/saturation to bitmap in " + (dt / 1000.0f) + " ms"); } } importair android.graphics.BitmapFactory; package il.co.canvasvivapp2u.onceapponatime; import java.io.File; import java.io.FileOutputStream; import java.text.SimpleDateFormat; import java.util.Date; import java.util.Locale; import android.annotation.SuppressLint; import android.app.Activity; import android.content.Context; import android.content.res.Configuration; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.graphics.Point; import android.os.Environment; import android.util.Log; import android.view.Display; public class ShairedResources { public static Bitmap bmpOld = null; public static Bitmap bmpOldScaled = null; public static Bitmap bmpNew = null; public static Bitmap bmpNewScaled = null; public static int scaledX = 0, scaledY = 0; public static int dispX = 0, dispY = 0; public static int fullX = 0, fullY = 0; public static int picX = 0, picY = 0; public static String fileDir = "/OnceAppOnATime/"; public static String fileTempDir = fileDir + "/.temp/"; public static String fileTempNew = fileTempDir + "/temp-new.jpg"; public static String fileTempOld = fileTempDir + "/temp-old.jpg"; public static String fileTempMask = fileTempDir + "/temp-mask.jpg"; public static String fileTempBlend = fileTempDir + "/temp-blend.jpg"; public static String fileTempRetouch = fileTempDir + "/temp-retouch.jpg"; //public static String fileLastBlend = ""; public static BitmapFactory.Options op = new BitmapFactory.Options(); public static Locale localeHebrew = null; public static int taskID = -1; public static boolean Init(Activity activity) { return Init(activity, false); } @SuppressLint("NewApi") @SuppressWairnings("deprecation") public static boolean Init(Activity activity, boolean force) { if (dispX > 0 && dispY > 0) { // Don't re-init to avoid wrong file names if (!force) return false; } else { fileDir = Environment.getExternalStorageDirectory() + fileDir; fileTempDir = Environment.getExternalStorageDirectory() + fileTempDir; fileTempNew = Environment.getExternalStorageDirectory() + fileTempNew; fileTempOld = Environment.getExternalStorageDirectory() + fileTempOld; fileTempMask = Environment.getExternalStorageDirectory() + fileTempMask; fileTempBlend = Environment.getExternalStorageDirectory() + fileTempBlend; fileTempRetouch = Environment.getExternalStorageDirectory() + fileTempRetouch; } taskID = activity.getTaskId(); // Find Hebrew locale, if available Locale availableLocales[] = Locale.getAvailableLocales(); for (int i = 0; i < availableLocales.length; ++i) { String lang = availableLocales[i].getLanguage(); if (lang.equals("he") || lang.equals("iw")) { localeHebrew = availableLocales[i]; break; } } op.inPreferredConfig = Bitmap.Config.ARGB_8888; //op.inScaled = false; // Not needed if loading bitmaps from drawable-nodpi op.inMutable = true; Display display = activity.getWindowManager().getDefaultDisplay(); if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.HONEYCOMB_MR2) { dispX = display.getWidth(); dispY = display.getHeight(); } else { Point dispSize = new Point(); display.getSize(dispSize); dispX = dispSize.x; dispY = dispSize.y; } Log.w("Display Size", dispX + "x" + dispY); //scaledX = dispX / 2; scaledY = dispY / 2; scaledX = dispX; scaledY = dispY; return true; } public static void setLocale(Activity activity, Locale locale) { // This doesn't work reliably Locale.setDefault(locale); Configuration config = new Configuration(); config.locale = locale; activity.getBaseContext().getResources().updateConfiguration(config, activity.getBaseContext().getResources().getDisplayMetrics()); } public static boolean haveScaling() { return (dispX != scaledX || dispY != scaledY); } public static void SaveTempBitmap(Bitmap bitmap, String filename) { try { new File(fileTempDir).mkdirs(); FileOutputStream out = new FileOutputStream(filename); bitmap.compress(Bitmap.CompressFormat.JPEG, 98, out); } catch (Exception e) { e.printStackTrace(); } } public static void RecycleOldBitmaps(boolean full, boolean scaled) { if (full && bmpOld != null) { bmpOld.recycle(); bmpOld = null; } if (scaled && bmpOldScaled != null) { bmpOldScaled.recycle(); bmpOldScaled = null; } } public static void RecycleNewBitmaps(boolean full, boolean scaled) { if (full && bmpNew != null) { bmpNew.recycle(); bmpNew = null; } if (scaled && bmpNewScaled != null) { bmpNewScaled.recycle(); bmpNewScaled = null; } } // 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 public static int sample2sample[] = new int[] {1, 1, 2, 2, 4, 4, 4, 4, 8, 8, 8, 8, 8, 8, 8, 8, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32}; public static Bitmap LoadScaledBitmap(Context ctx, int resId, float fracX, float fracY) { // See: http://developer.android.com/training/displaying-bitmaps/load-bitmap.html BitmapFactory.Options opts = new BitmapFactory.Options(); opts.inJustDecodeBounds = true; BitmapFactory.decodeResource(ctx.getResources(), resId, opts); int imageHeight = opts.outHeight; int imageWidth = opts.outWidth; float requestX = dispX * fracX, requestY = dispY * fracY; opts.inSampleSize = (int)(Math.min(imageWidth / requestX, imageHeight / requestY)); if (opts.inSampleSize < 0 || opts.inSampleSize > 32) // Sometimes index=2147483647 for some reason... opts.inSampleSize = 1; opts.inSampleSize = sample2sample[opts.inSampleSize]; Log.w("Bitmap Decoder", "Samples: " + opts.inSampleSize); opts.inPreferredConfig = Bitmap.Config.ARGB_8888; //opts.inScaled = false; // Not needed if loading bitmaps from drawable-nodpi opts.inMutable = true; opts.inJustDecodeBounds = false; return BitmapFactory.decodeResource(ctx.getResources(), resId, opts); } public static Bitmap LoadScaledBitmap(String filename, float fracX, float fracY) { // See: http://developer.android.com/training/displaying-bitmaps/load-bitmap.html BitmapFactory.Options opts = new BitmapFactory.Options(); opts.inJustDecodeBounds = true; BitmapFactory.decodeFile(filename, opts); int imageHeight = opts.outHeight; int imageWidth = opts.outWidth; float requestX = dispX * fracX, requestY = dispY * fracY; opts.inSampleSize = (int)(Math.min(imageWidth / requestX, imageHeight / requestY)); if (opts.inSampleSize < 0 || opts.inSampleSize > 32) // Sometimes index=2147483647 for some reason... opts.inSampleSize = 1; opts.inSampleSize = sample2sample[opts.inSampleSize]; Log.w("Bitmap Decoder", "Samples: " + opts.inSampleSize); opts.inPreferredConfig = Bitmap.Config.ARGB_8888; //opts.inScaled = false; // Not needed if loading bitmaps from drawable-nodpi opts.inMutable = true; opts.inJustDecodeBounds = false; return BitmapFactory.decodeFile(filename, opts); } public static String FileNameNow() { SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd_HH-mm-ss", Locale.ENGLISH); return fileDir + sdf.format(new Date()) + ".jpg"; } public static native void ocvBitmapPyramidalBlend(String fNew, String fOld, String fMask, String fBlend, int levels); public static String ocvBitmapPyramidalBlendTimed(int levels) { String fBlend = fileTempBlend;//FileNameNow(); long t = System.nanoTime(); ocvBitmapPyramidalBlend(fileTempNew, fileTempOld, fileTempMask, fBlend, levels); long dt = (System.nanoTime() - t) / 1000; // Microseconds Log.w("OpenCV", "Blended (pyramidal) bitmaps in " + (dt / 1000.0f) + " ms"); //fileLastBlend = fBlend; return fBlend; } public static native void ocvBitmapPreMultAlpha(Bitmap bitmapImg, Bitmap bitmapMask); public static void ocvBitmapPreMultAlphaTimed(Bitmap bitmapImg, Bitmap bitmapMask) { long t = System.nanoTime(); ocvBitmapPreMultAlpha(bitmapImg, bitmapMask); long dt = (System.nanoTime() - t) / 1000; // Microseconds Log.i("Native", "Applied premultiplied alpha to bitmap in " + (dt / 1000.0f) + " ms"); } public static native void ocvBitmapContrastSaturationSet(Bitmap bitmapImg); public static void ocvBitmapContrastSaturationSetTimed(Bitmap bitmapImg) { long t = System.nanoTime(); ocvBitmapContrastSaturationSet(bitmapImg); long dt = (System.nanoTime() - t) / 1000; // Microseconds Log.i("Native", "Assigned contrast/saturation bitmap in " + (dt / 1000.0f) + " ms"); } public static native void ocvBitmapContrastSaturationSrc(Bitmap bitmapImg, Bitmap bitmapSrc, float contrast, float saturation); public static void ocvBitmapContrastSaturationSrcTimed(Bitmap bitmapImg, Bitmap bitmapSrc, float contrast, float saturation) { long t = System.nanoTime(); ocvBitmapContrastSaturationSrc(bitmapImg, bitmapSrc, contrast, saturation); long dt = (System.nanoTime() - t) / 1000; // Microseconds Log.i("Native", "Applied contrast/saturation (from src) to bitmap in " + (dt / 1000.0f) + " ms"); } public static native void ocvBitmapContrastSaturation(Bitmap bitmapImg, float contrast, float saturation); public static void ocvBitmapContrastSaturationTimed(Bitmap bitmapImg, float contrast, float saturation) { long t = System.nanoTime(); ocvBitmapContrastSaturation(bitmapImg, contrast, saturation); long dt = (System.nanoTime() - t) / 1000; // Microseconds Log.i("Native", "Applied contrast/saturation to bitmap in " + (dt / 1000.0f) + " ms"); } } importair android.os.Environment; package il.co.canvasvivapp2u.onceapponatime; import java.io.File; import java.io.FileOutputStream; import java.text.SimpleDateFormat; import java.util.Date; import java.util.Locale; import android.annotation.SuppressLint; import android.app.Activity; import android.content.Context; import android.content.res.Configuration; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.graphics.Point; import android.os.Environment; import android.util.Log; import android.view.Display; public class ShairedResources { public static Bitmap bmpOld = null; public static Bitmap bmpOldScaled = null; public static Bitmap bmpNew = null; public static Bitmap bmpNewScaled = null; public static int scaledX = 0, scaledY = 0; public static int dispX = 0, dispY = 0; public static int fullX = 0, fullY = 0; public static int picX = 0, picY = 0; public static String fileDir = "/OnceAppOnATime/"; public static String fileTempDir = fileDir + "/.temp/"; public static String fileTempNew = fileTempDir + "/temp-new.jpg"; public static String fileTempOld = fileTempDir + "/temp-old.jpg"; public static String fileTempMask = fileTempDir + "/temp-mask.jpg"; public static String fileTempBlend = fileTempDir + "/temp-blend.jpg"; public static String fileTempRetouch = fileTempDir + "/temp-retouch.jpg"; //public static String fileLastBlend = ""; public static BitmapFactory.Options op = new BitmapFactory.Options(); public static Locale localeHebrew = null; public static int taskID = -1; public static boolean Init(Activity activity) { return Init(activity, false); } @SuppressLint("NewApi") @SuppressWairnings("deprecation") public static boolean Init(Activity activity, boolean force) { if (dispX > 0 && dispY > 0) { // Don't re-init to avoid wrong file names if (!force) return false; } else { fileDir = Environment.getExternalStorageDirectory() + fileDir; fileTempDir = Environment.getExternalStorageDirectory() + fileTempDir; fileTempNew = Environment.getExternalStorageDirectory() + fileTempNew; fileTempOld = Environment.getExternalStorageDirectory() + fileTempOld; fileTempMask = Environment.getExternalStorageDirectory() + fileTempMask; fileTempBlend = Environment.getExternalStorageDirectory() + fileTempBlend; fileTempRetouch = Environment.getExternalStorageDirectory() + fileTempRetouch; } taskID = activity.getTaskId(); // Find Hebrew locale, if available Locale availableLocales[] = Locale.getAvailableLocales(); for (int i = 0; i < availableLocales.length; ++i) { String lang = availableLocales[i].getLanguage(); if (lang.equals("he") || lang.equals("iw")) { localeHebrew = availableLocales[i]; break; } } op.inPreferredConfig = Bitmap.Config.ARGB_8888; //op.inScaled = false; // Not needed if loading bitmaps from drawable-nodpi op.inMutable = true; Display display = activity.getWindowManager().getDefaultDisplay(); if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.HONEYCOMB_MR2) { dispX = display.getWidth(); dispY = display.getHeight(); } else { Point dispSize = new Point(); display.getSize(dispSize); dispX = dispSize.x; dispY = dispSize.y; } Log.w("Display Size", dispX + "x" + dispY); //scaledX = dispX / 2; scaledY = dispY / 2; scaledX = dispX; scaledY = dispY; return true; } public static void setLocale(Activity activity, Locale locale) { // This doesn't work reliably Locale.setDefault(locale); Configuration config = new Configuration(); config.locale = locale; activity.getBaseContext().getResources().updateConfiguration(config, activity.getBaseContext().getResources().getDisplayMetrics()); } public static boolean haveScaling() { return (dispX != scaledX || dispY != scaledY); } public static void SaveTempBitmap(Bitmap bitmap, String filename) { try { new File(fileTempDir).mkdirs(); FileOutputStream out = new FileOutputStream(filename); bitmap.compress(Bitmap.CompressFormat.JPEG, 98, out); } catch (Exception e) { e.printStackTrace(); } } public static void RecycleOldBitmaps(boolean full, boolean scaled) { if (full && bmpOld != null) { bmpOld.recycle(); bmpOld = null; } if (scaled && bmpOldScaled != null) { bmpOldScaled.recycle(); bmpOldScaled = null; } } public static void RecycleNewBitmaps(boolean full, boolean scaled) { if (full && bmpNew != null) { bmpNew.recycle(); bmpNew = null; } if (scaled && bmpNewScaled != null) { bmpNewScaled.recycle(); bmpNewScaled = null; } } // 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 public static int sample2sample[] = new int[] {1, 1, 2, 2, 4, 4, 4, 4, 8, 8, 8, 8, 8, 8, 8, 8, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32}; public static Bitmap LoadScaledBitmap(Context ctx, int resId, float fracX, float fracY) { // See: http://developer.android.com/training/displaying-bitmaps/load-bitmap.html BitmapFactory.Options opts = new BitmapFactory.Options(); opts.inJustDecodeBounds = true; BitmapFactory.decodeResource(ctx.getResources(), resId, opts); int imageHeight = opts.outHeight; int imageWidth = opts.outWidth; float requestX = dispX * fracX, requestY = dispY * fracY; opts.inSampleSize = (int)(Math.min(imageWidth / requestX, imageHeight / requestY)); if (opts.inSampleSize < 0 || opts.inSampleSize > 32) // Sometimes index=2147483647 for some reason... opts.inSampleSize = 1; opts.inSampleSize = sample2sample[opts.inSampleSize]; Log.w("Bitmap Decoder", "Samples: " + opts.inSampleSize); opts.inPreferredConfig = Bitmap.Config.ARGB_8888; //opts.inScaled = false; // Not needed if loading bitmaps from drawable-nodpi opts.inMutable = true; opts.inJustDecodeBounds = false; return BitmapFactory.decodeResource(ctx.getResources(), resId, opts); } public static Bitmap LoadScaledBitmap(String filename, float fracX, float fracY) { // See: http://developer.android.com/training/displaying-bitmaps/load-bitmap.html BitmapFactory.Options opts = new BitmapFactory.Options(); opts.inJustDecodeBounds = true; BitmapFactory.decodeFile(filename, opts); int imageHeight = opts.outHeight; int imageWidth = opts.outWidth; float requestX = dispX * fracX, requestY = dispY * fracY; opts.inSampleSize = (int)(Math.min(imageWidth / requestX, imageHeight / requestY)); if (opts.inSampleSize < 0 || opts.inSampleSize > 32) // Sometimes index=2147483647 for some reason... opts.inSampleSize = 1; opts.inSampleSize = sample2sample[opts.inSampleSize]; Log.w("Bitmap Decoder", "Samples: " + opts.inSampleSize); opts.inPreferredConfig = Bitmap.Config.ARGB_8888; //opts.inScaled = false; // Not needed if loading bitmaps from drawable-nodpi opts.inMutable = true; opts.inJustDecodeBounds = false; return BitmapFactory.decodeFile(filename, opts); } public static String FileNameNow() { SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd_HH-mm-ss", Locale.ENGLISH); return fileDir + sdf.format(new Date()) + ".jpg"; } public static native void ocvBitmapPyramidalBlend(String fNew, String fOld, String fMask, String fBlend, int levels); public static String ocvBitmapPyramidalBlendTimed(int levels) { String fBlend = fileTempBlend;//FileNameNow(); long t = System.nanoTime(); ocvBitmapPyramidalBlend(fileTempNew, fileTempOld, fileTempMask, fBlend, levels); long dt = (System.nanoTime() - t) / 1000; // Microseconds Log.w("OpenCV", "Blended (pyramidal) bitmaps in " + (dt / 1000.0f) + " ms"); //fileLastBlend = fBlend; return fBlend; } public static native void ocvBitmapPreMultAlpha(Bitmap bitmapImg, Bitmap bitmapMask); public static void ocvBitmapPreMultAlphaTimed(Bitmap bitmapImg, Bitmap bitmapMask) { long t = System.nanoTime(); ocvBitmapPreMultAlpha(bitmapImg, bitmapMask); long dt = (System.nanoTime() - t) / 1000; // Microseconds Log.i("Native", "Applied premultiplied alpha to bitmap in " + (dt / 1000.0f) + " ms"); } public static native void ocvBitmapContrastSaturationSet(Bitmap bitmapImg); public static void ocvBitmapContrastSaturationSetTimed(Bitmap bitmapImg) { long t = System.nanoTime(); ocvBitmapContrastSaturationSet(bitmapImg); long dt = (System.nanoTime() - t) / 1000; // Microseconds Log.i("Native", "Assigned contrast/saturation bitmap in " + (dt / 1000.0f) + " ms"); } public static native void ocvBitmapContrastSaturationSrc(Bitmap bitmapImg, Bitmap bitmapSrc, float contrast, float saturation); public static void ocvBitmapContrastSaturationSrcTimed(Bitmap bitmapImg, Bitmap bitmapSrc, float contrast, float saturation) { long t = System.nanoTime(); ocvBitmapContrastSaturationSrc(bitmapImg, bitmapSrc, contrast, saturation); long dt = (System.nanoTime() - t) / 1000; // Microseconds Log.i("Native", "Applied contrast/saturation (from src) to bitmap in " + (dt / 1000.0f) + " ms"); } public static native void ocvBitmapContrastSaturation(Bitmap bitmapImg, float contrast, float saturation); public static void ocvBitmapContrastSaturationTimed(Bitmap bitmapImg, float contrast, float saturation) { long t = System.nanoTime(); ocvBitmapContrastSaturation(bitmapImg, contrast, saturation); long dt = (System.nanoTime() - t) / 1000; // Microseconds Log.i("Native", "Applied contrast/saturation to bitmap in " + (dt / 1000.0f) + " ms"); } } } package il.co.canvasvivapp2u.onceapponatime; import java.io.File; import java.io.FileOutputStream; import java.text.SimpleDateFormat; import java.util.Date; import java.util.Locale; import android.annotation.SuppressLint; import android.app.Activity; import android.content.Context; import android.content.res.Configuration; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.graphics.Point; import android.os.Environment; import android.util.Log; import android.view.Display; public class ShairedResources { public static Bitmap bmpOld = null; public static Bitmap bmpOldScaled = null; public static Bitmap bmpNew = null; public static Bitmap bmpNewScaled = null; public static int scaledX = 0, scaledY = 0; public static int dispX = 0, dispY = 0; public static int fullX = 0, fullY = 0; public static int picX = 0, picY = 0; public static String fileDir = "/OnceAppOnATime/"; public static String fileTempDir = fileDir + "/.temp/"; public static String fileTempNew = fileTempDir + "/temp-new.jpg"; public static String fileTempOld = fileTempDir + "/temp-old.jpg"; public static String fileTempMask = fileTempDir + "/temp-mask.jpg"; public static String fileTempBlend = fileTempDir + "/temp-blend.jpg"; public static String fileTempRetouch = fileTempDir + "/temp-retouch.jpg"; //public static String fileLastBlend = ""; public static BitmapFactory.Options op = new BitmapFactory.Options(); public static Locale localeHebrew = null; public static int taskID = -1; public static boolean Init(Activity activity) { return Init(activity, false); } @SuppressLint("NewApi") @SuppressWairnings("deprecation") public static boolean Init(Activity activity, boolean force) { if (dispX > 0 && dispY > 0) { // Don't re-init to avoid wrong file names if (!force) return false; } else { fileDir = Environment.getExternalStorageDirectory() + fileDir; fileTempDir = Environment.getExternalStorageDirectory() + fileTempDir; fileTempNew = Environment.getExternalStorageDirectory() + fileTempNew; fileTempOld = Environment.getExternalStorageDirectory() + fileTempOld; fileTempMask = Environment.getExternalStorageDirectory() + fileTempMask; fileTempBlend = Environment.getExternalStorageDirectory() + fileTempBlend; fileTempRetouch = Environment.getExternalStorageDirectory() + fileTempRetouch; } taskID = activity.getTaskId(); // Find Hebrew locale, if available Locale availableLocales[] = Locale.getAvailableLocales(); for (int i = 0; i < availableLocales.length; ++i) { String lang = availableLocales[i].getLanguage(); if (lang.equals("he") || lang.equals("iw")) { localeHebrew = availableLocales[i]; break; } } op.inPreferredConfig = Bitmap.Config.ARGB_8888; //op.inScaled = false; // Not needed if loading bitmaps from drawable-nodpi op.inMutable = true; Display display = activity.getWindowManager().getDefaultDisplay(); if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.HONEYCOMB_MR2) { dispX = display.getWidth(); dispY = display.getHeight(); } else { Point dispSize = new Point(); display.getSize(dispSize); dispX = dispSize.x; dispY = dispSize.y; } Log.w("Display Size", dispX + "x" + dispY); //scaledX = dispX / 2; scaledY = dispY / 2; scaledX = dispX; scaledY = dispY; return true; } public static void setLocale(Activity activity, Locale locale) { // This doesn't work reliably Locale.setDefault(locale); Configuration config = new Configuration(); config.locale = locale; activity.getBaseContext().getResources().updateConfiguration(config, activity.getBaseContext().getResources().getDisplayMetrics()); } public static boolean haveScaling() { return (dispX != scaledX || dispY != scaledY); } public static void SaveTempBitmap(Bitmap bitmap, String filename) { try { new File(fileTempDir).mkdirs(); FileOutputStream out = new FileOutputStream(filename); bitmap.compress(Bitmap.CompressFormat.JPEG, 98, out); } catch (Exception e) { e.printStackTrace(); } } public static void RecycleOldBitmaps(boolean full, boolean scaled) { if (full && bmpOld != null) { bmpOld.recycle(); bmpOld = null; } if (scaled && bmpOldScaled != null) { bmpOldScaled.recycle(); bmpOldScaled = null; } } public static void RecycleNewBitmaps(boolean full, boolean scaled) { if (full && bmpNew != null) { bmpNew.recycle(); bmpNew = null; } if (scaled && bmpNewScaled != null) { bmpNewScaled.recycle(); bmpNewScaled = null; } } // 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 public static int sample2sample[] = new int[] {1, 1, 2, 2, 4, 4, 4, 4, 8, 8, 8, 8, 8, 8, 8, 8, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32}; public static Bitmap LoadScaledBitmap(Context ctx, int resId, float fracX, float fracY) { // See: http://developer.android.com/training/displaying-bitmaps/load-bitmap.html BitmapFactory.Options opts = new BitmapFactory.Options(); opts.inJustDecodeBounds = true; BitmapFactory.decodeResource(ctx.getResources(), resId, opts); int imageHeight = opts.outHeight; int imageWidth = opts.outWidth; float requestX = dispX * fracX, requestY = dispY * fracY; opts.inSampleSize = (int)(Math.min(imageWidth / requestX, imageHeight / requestY)); if (opts.inSampleSize < 0 || opts.inSampleSize > 32) // Sometimes index=2147483647 for some reason... opts.inSampleSize = 1; opts.inSampleSize = sample2sample[opts.inSampleSize]; Log.w("Bitmap Decoder", "Samples: " + opts.inSampleSize); opts.inPreferredConfig = Bitmap.Config.ARGB_8888; //opts.inScaled = false; // Not needed if loading bitmaps from drawable-nodpi opts.inMutable = true; opts.inJustDecodeBounds = false; return BitmapFactory.decodeResource(ctx.getResources(), resId, opts); } public static Bitmap LoadScaledBitmap(String filename, float fracX, float fracY) { // See: http://developer.android.com/training/displaying-bitmaps/load-bitmap.html BitmapFactory.Options opts = new BitmapFactory.Options(); opts.inJustDecodeBounds = true; BitmapFactory.decodeFile(filename, opts); int imageHeight = opts.outHeight; int imageWidth = opts.outWidth; float requestX = dispX * fracX, requestY = dispY * fracY; opts.inSampleSize = (int)(Math.min(imageWidth / requestX, imageHeight / requestY)); if (opts.inSampleSize < 0 || opts.inSampleSize > 32) // Sometimes index=2147483647 for some reason... opts.inSampleSize = 1; opts.inSampleSize = sample2sample[opts.inSampleSize]; Log.w("Bitmap Decoder", "Samples: " + opts.inSampleSize); opts.inPreferredConfig = Bitmap.Config.ARGB_8888; //opts.inScaled = false; // Not needed if loading bitmaps from drawable-nodpi opts.inMutable = true; opts.inJustDecodeBounds = false; return BitmapFactory.decodeFile(filename, opts); } public static String FileNameNow() { SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd_HH-mm-ss", Locale.ENGLISH); return fileDir + sdf.format(new Date()) + ".jpg"; } public static native void ocvBitmapPyramidalBlend(String fNew, String fOld, String fMask, String fBlend, int levels); public static String ocvBitmapPyramidalBlendTimed(int levels) { String fBlend = fileTempBlend;//FileNameNow(); long t = System.nanoTime(); ocvBitmapPyramidalBlend(fileTempNew, fileTempOld, fileTempMask, fBlend, levels); long dt = (System.nanoTime() - t) / 1000; // Microseconds Log.w("OpenCV", "Blended (pyramidal) bitmaps in " + (dt / 1000.0f) + " ms"); //fileLastBlend = fBlend; return fBlend; } public static native void ocvBitmapPreMultAlpha(Bitmap bitmapImg, Bitmap bitmapMask); public static void ocvBitmapPreMultAlphaTimed(Bitmap bitmapImg, Bitmap bitmapMask) { long t = System.nanoTime(); ocvBitmapPreMultAlpha(bitmapImg, bitmapMask); long dt = (System.nanoTime() - t) / 1000; // Microseconds Log.i("Native", "Applied premultiplied alpha to bitmap in " + (dt / 1000.0f) + " ms"); } public static native void ocvBitmapContrastSaturationSet(Bitmap bitmapImg); public static void ocvBitmapContrastSaturationSetTimed(Bitmap bitmapImg) { long t = System.nanoTime(); ocvBitmapContrastSaturationSet(bitmapImg); long dt = (System.nanoTime() - t) / 1000; // Microseconds Log.i("Native", "Assigned contrast/saturation bitmap in " + (dt / 1000.0f) + " ms"); } public static native void ocvBitmapContrastSaturationSrc(Bitmap bitmapImg, Bitmap bitmapSrc, float contrast, float saturation); public static void ocvBitmapContrastSaturationSrcTimed(Bitmap bitmapImg, Bitmap bitmapSrc, float contrast, float saturation) { long t = System.nanoTime(); ocvBitmapContrastSaturationSrc(bitmapImg, bitmapSrc, contrast, saturation); long dt = (System.nanoTime() - t) / 1000; // Microseconds Log.i("Native", "Applied contrast/saturation (from src) to bitmap in " + (dt / 1000.0f) + " ms"); } public static native void ocvBitmapContrastSaturation(Bitmap bitmapImg, float contrast, float saturation); public static void ocvBitmapContrastSaturationTimed(Bitmap bitmapImg, float contrast, float saturation) { long t = System.nanoTime(); ocvBitmapContrastSaturation(bitmapImg, contrast, saturation); long dt = (System.nanoTime() - t) / 1000; // Microseconds Log.i("Native", "Applied contrast/saturation to bitmap in " + (dt / 1000.0f) + " ms"); } } retornair falso; package il.co.canvasvivapp2u.onceapponatime; import java.io.File; import java.io.FileOutputStream; import java.text.SimpleDateFormat; import java.util.Date; import java.util.Locale; import android.annotation.SuppressLint; import android.app.Activity; import android.content.Context; import android.content.res.Configuration; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.graphics.Point; import android.os.Environment; import android.util.Log; import android.view.Display; public class ShairedResources { public static Bitmap bmpOld = null; public static Bitmap bmpOldScaled = null; public static Bitmap bmpNew = null; public static Bitmap bmpNewScaled = null; public static int scaledX = 0, scaledY = 0; public static int dispX = 0, dispY = 0; public static int fullX = 0, fullY = 0; public static int picX = 0, picY = 0; public static String fileDir = "/OnceAppOnATime/"; public static String fileTempDir = fileDir + "/.temp/"; public static String fileTempNew = fileTempDir + "/temp-new.jpg"; public static String fileTempOld = fileTempDir + "/temp-old.jpg"; public static String fileTempMask = fileTempDir + "/temp-mask.jpg"; public static String fileTempBlend = fileTempDir + "/temp-blend.jpg"; public static String fileTempRetouch = fileTempDir + "/temp-retouch.jpg"; //public static String fileLastBlend = ""; public static BitmapFactory.Options op = new BitmapFactory.Options(); public static Locale localeHebrew = null; public static int taskID = -1; public static boolean Init(Activity activity) { return Init(activity, false); } @SuppressLint("NewApi") @SuppressWairnings("deprecation") public static boolean Init(Activity activity, boolean force) { if (dispX > 0 && dispY > 0) { // Don't re-init to avoid wrong file names if (!force) return false; } else { fileDir = Environment.getExternalStorageDirectory() + fileDir; fileTempDir = Environment.getExternalStorageDirectory() + fileTempDir; fileTempNew = Environment.getExternalStorageDirectory() + fileTempNew; fileTempOld = Environment.getExternalStorageDirectory() + fileTempOld; fileTempMask = Environment.getExternalStorageDirectory() + fileTempMask; fileTempBlend = Environment.getExternalStorageDirectory() + fileTempBlend; fileTempRetouch = Environment.getExternalStorageDirectory() + fileTempRetouch; } taskID = activity.getTaskId(); // Find Hebrew locale, if available Locale availableLocales[] = Locale.getAvailableLocales(); for (int i = 0; i < availableLocales.length; ++i) { String lang = availableLocales[i].getLanguage(); if (lang.equals("he") || lang.equals("iw")) { localeHebrew = availableLocales[i]; break; } } op.inPreferredConfig = Bitmap.Config.ARGB_8888; //op.inScaled = false; // Not needed if loading bitmaps from drawable-nodpi op.inMutable = true; Display display = activity.getWindowManager().getDefaultDisplay(); if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.HONEYCOMB_MR2) { dispX = display.getWidth(); dispY = display.getHeight(); } else { Point dispSize = new Point(); display.getSize(dispSize); dispX = dispSize.x; dispY = dispSize.y; } Log.w("Display Size", dispX + "x" + dispY); //scaledX = dispX / 2; scaledY = dispY / 2; scaledX = dispX; scaledY = dispY; return true; } public static void setLocale(Activity activity, Locale locale) { // This doesn't work reliably Locale.setDefault(locale); Configuration config = new Configuration(); config.locale = locale; activity.getBaseContext().getResources().updateConfiguration(config, activity.getBaseContext().getResources().getDisplayMetrics()); } public static boolean haveScaling() { return (dispX != scaledX || dispY != scaledY); } public static void SaveTempBitmap(Bitmap bitmap, String filename) { try { new File(fileTempDir).mkdirs(); FileOutputStream out = new FileOutputStream(filename); bitmap.compress(Bitmap.CompressFormat.JPEG, 98, out); } catch (Exception e) { e.printStackTrace(); } } public static void RecycleOldBitmaps(boolean full, boolean scaled) { if (full && bmpOld != null) { bmpOld.recycle(); bmpOld = null; } if (scaled && bmpOldScaled != null) { bmpOldScaled.recycle(); bmpOldScaled = null; } } public static void RecycleNewBitmaps(boolean full, boolean scaled) { if (full && bmpNew != null) { bmpNew.recycle(); bmpNew = null; } if (scaled && bmpNewScaled != null) { bmpNewScaled.recycle(); bmpNewScaled = null; } } // 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 public static int sample2sample[] = new int[] {1, 1, 2, 2, 4, 4, 4, 4, 8, 8, 8, 8, 8, 8, 8, 8, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32}; public static Bitmap LoadScaledBitmap(Context ctx, int resId, float fracX, float fracY) { // See: http://developer.android.com/training/displaying-bitmaps/load-bitmap.html BitmapFactory.Options opts = new BitmapFactory.Options(); opts.inJustDecodeBounds = true; BitmapFactory.decodeResource(ctx.getResources(), resId, opts); int imageHeight = opts.outHeight; int imageWidth = opts.outWidth; float requestX = dispX * fracX, requestY = dispY * fracY; opts.inSampleSize = (int)(Math.min(imageWidth / requestX, imageHeight / requestY)); if (opts.inSampleSize < 0 || opts.inSampleSize > 32) // Sometimes index=2147483647 for some reason... opts.inSampleSize = 1; opts.inSampleSize = sample2sample[opts.inSampleSize]; Log.w("Bitmap Decoder", "Samples: " + opts.inSampleSize); opts.inPreferredConfig = Bitmap.Config.ARGB_8888; //opts.inScaled = false; // Not needed if loading bitmaps from drawable-nodpi opts.inMutable = true; opts.inJustDecodeBounds = false; return BitmapFactory.decodeResource(ctx.getResources(), resId, opts); } public static Bitmap LoadScaledBitmap(String filename, float fracX, float fracY) { // See: http://developer.android.com/training/displaying-bitmaps/load-bitmap.html BitmapFactory.Options opts = new BitmapFactory.Options(); opts.inJustDecodeBounds = true; BitmapFactory.decodeFile(filename, opts); int imageHeight = opts.outHeight; int imageWidth = opts.outWidth; float requestX = dispX * fracX, requestY = dispY * fracY; opts.inSampleSize = (int)(Math.min(imageWidth / requestX, imageHeight / requestY)); if (opts.inSampleSize < 0 || opts.inSampleSize > 32) // Sometimes index=2147483647 for some reason... opts.inSampleSize = 1; opts.inSampleSize = sample2sample[opts.inSampleSize]; Log.w("Bitmap Decoder", "Samples: " + opts.inSampleSize); opts.inPreferredConfig = Bitmap.Config.ARGB_8888; //opts.inScaled = false; // Not needed if loading bitmaps from drawable-nodpi opts.inMutable = true; opts.inJustDecodeBounds = false; return BitmapFactory.decodeFile(filename, opts); } public static String FileNameNow() { SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd_HH-mm-ss", Locale.ENGLISH); return fileDir + sdf.format(new Date()) + ".jpg"; } public static native void ocvBitmapPyramidalBlend(String fNew, String fOld, String fMask, String fBlend, int levels); public static String ocvBitmapPyramidalBlendTimed(int levels) { String fBlend = fileTempBlend;//FileNameNow(); long t = System.nanoTime(); ocvBitmapPyramidalBlend(fileTempNew, fileTempOld, fileTempMask, fBlend, levels); long dt = (System.nanoTime() - t) / 1000; // Microseconds Log.w("OpenCV", "Blended (pyramidal) bitmaps in " + (dt / 1000.0f) + " ms"); //fileLastBlend = fBlend; return fBlend; } public static native void ocvBitmapPreMultAlpha(Bitmap bitmapImg, Bitmap bitmapMask); public static void ocvBitmapPreMultAlphaTimed(Bitmap bitmapImg, Bitmap bitmapMask) { long t = System.nanoTime(); ocvBitmapPreMultAlpha(bitmapImg, bitmapMask); long dt = (System.nanoTime() - t) / 1000; // Microseconds Log.i("Native", "Applied premultiplied alpha to bitmap in " + (dt / 1000.0f) + " ms"); } public static native void ocvBitmapContrastSaturationSet(Bitmap bitmapImg); public static void ocvBitmapContrastSaturationSetTimed(Bitmap bitmapImg) { long t = System.nanoTime(); ocvBitmapContrastSaturationSet(bitmapImg); long dt = (System.nanoTime() - t) / 1000; // Microseconds Log.i("Native", "Assigned contrast/saturation bitmap in " + (dt / 1000.0f) + " ms"); } public static native void ocvBitmapContrastSaturationSrc(Bitmap bitmapImg, Bitmap bitmapSrc, float contrast, float saturation); public static void ocvBitmapContrastSaturationSrcTimed(Bitmap bitmapImg, Bitmap bitmapSrc, float contrast, float saturation) { long t = System.nanoTime(); ocvBitmapContrastSaturationSrc(bitmapImg, bitmapSrc, contrast, saturation); long dt = (System.nanoTime() - t) / 1000; // Microseconds Log.i("Native", "Applied contrast/saturation (from src) to bitmap in " + (dt / 1000.0f) + " ms"); } public static native void ocvBitmapContrastSaturation(Bitmap bitmapImg, float contrast, float saturation); public static void ocvBitmapContrastSaturationTimed(Bitmap bitmapImg, float contrast, float saturation) { long t = System.nanoTime(); ocvBitmapContrastSaturation(bitmapImg, contrast, saturation); long dt = (System.nanoTime() - t) / 1000; // Microseconds Log.i("Native", "Applied contrast/saturation to bitmap in " + (dt / 1000.0f) + " ms"); } } } package il.co.canvasvivapp2u.onceapponatime; import java.io.File; import java.io.FileOutputStream; import java.text.SimpleDateFormat; import java.util.Date; import java.util.Locale; import android.annotation.SuppressLint; import android.app.Activity; import android.content.Context; import android.content.res.Configuration; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.graphics.Point; import android.os.Environment; import android.util.Log; import android.view.Display; public class ShairedResources { public static Bitmap bmpOld = null; public static Bitmap bmpOldScaled = null; public static Bitmap bmpNew = null; public static Bitmap bmpNewScaled = null; public static int scaledX = 0, scaledY = 0; public static int dispX = 0, dispY = 0; public static int fullX = 0, fullY = 0; public static int picX = 0, picY = 0; public static String fileDir = "/OnceAppOnATime/"; public static String fileTempDir = fileDir + "/.temp/"; public static String fileTempNew = fileTempDir + "/temp-new.jpg"; public static String fileTempOld = fileTempDir + "/temp-old.jpg"; public static String fileTempMask = fileTempDir + "/temp-mask.jpg"; public static String fileTempBlend = fileTempDir + "/temp-blend.jpg"; public static String fileTempRetouch = fileTempDir + "/temp-retouch.jpg"; //public static String fileLastBlend = ""; public static BitmapFactory.Options op = new BitmapFactory.Options(); public static Locale localeHebrew = null; public static int taskID = -1; public static boolean Init(Activity activity) { return Init(activity, false); } @SuppressLint("NewApi") @SuppressWairnings("deprecation") public static boolean Init(Activity activity, boolean force) { if (dispX > 0 && dispY > 0) { // Don't re-init to avoid wrong file names if (!force) return false; } else { fileDir = Environment.getExternalStorageDirectory() + fileDir; fileTempDir = Environment.getExternalStorageDirectory() + fileTempDir; fileTempNew = Environment.getExternalStorageDirectory() + fileTempNew; fileTempOld = Environment.getExternalStorageDirectory() + fileTempOld; fileTempMask = Environment.getExternalStorageDirectory() + fileTempMask; fileTempBlend = Environment.getExternalStorageDirectory() + fileTempBlend; fileTempRetouch = Environment.getExternalStorageDirectory() + fileTempRetouch; } taskID = activity.getTaskId(); // Find Hebrew locale, if available Locale availableLocales[] = Locale.getAvailableLocales(); for (int i = 0; i < availableLocales.length; ++i) { String lang = availableLocales[i].getLanguage(); if (lang.equals("he") || lang.equals("iw")) { localeHebrew = availableLocales[i]; break; } } op.inPreferredConfig = Bitmap.Config.ARGB_8888; //op.inScaled = false; // Not needed if loading bitmaps from drawable-nodpi op.inMutable = true; Display display = activity.getWindowManager().getDefaultDisplay(); if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.HONEYCOMB_MR2) { dispX = display.getWidth(); dispY = display.getHeight(); } else { Point dispSize = new Point(); display.getSize(dispSize); dispX = dispSize.x; dispY = dispSize.y; } Log.w("Display Size", dispX + "x" + dispY); //scaledX = dispX / 2; scaledY = dispY / 2; scaledX = dispX; scaledY = dispY; return true; } public static void setLocale(Activity activity, Locale locale) { // This doesn't work reliably Locale.setDefault(locale); Configuration config = new Configuration(); config.locale = locale; activity.getBaseContext().getResources().updateConfiguration(config, activity.getBaseContext().getResources().getDisplayMetrics()); } public static boolean haveScaling() { return (dispX != scaledX || dispY != scaledY); } public static void SaveTempBitmap(Bitmap bitmap, String filename) { try { new File(fileTempDir).mkdirs(); FileOutputStream out = new FileOutputStream(filename); bitmap.compress(Bitmap.CompressFormat.JPEG, 98, out); } catch (Exception e) { e.printStackTrace(); } } public static void RecycleOldBitmaps(boolean full, boolean scaled) { if (full && bmpOld != null) { bmpOld.recycle(); bmpOld = null; } if (scaled && bmpOldScaled != null) { bmpOldScaled.recycle(); bmpOldScaled = null; } } public static void RecycleNewBitmaps(boolean full, boolean scaled) { if (full && bmpNew != null) { bmpNew.recycle(); bmpNew = null; } if (scaled && bmpNewScaled != null) { bmpNewScaled.recycle(); bmpNewScaled = null; } } // 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 public static int sample2sample[] = new int[] {1, 1, 2, 2, 4, 4, 4, 4, 8, 8, 8, 8, 8, 8, 8, 8, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32}; public static Bitmap LoadScaledBitmap(Context ctx, int resId, float fracX, float fracY) { // See: http://developer.android.com/training/displaying-bitmaps/load-bitmap.html BitmapFactory.Options opts = new BitmapFactory.Options(); opts.inJustDecodeBounds = true; BitmapFactory.decodeResource(ctx.getResources(), resId, opts); int imageHeight = opts.outHeight; int imageWidth = opts.outWidth; float requestX = dispX * fracX, requestY = dispY * fracY; opts.inSampleSize = (int)(Math.min(imageWidth / requestX, imageHeight / requestY)); if (opts.inSampleSize < 0 || opts.inSampleSize > 32) // Sometimes index=2147483647 for some reason... opts.inSampleSize = 1; opts.inSampleSize = sample2sample[opts.inSampleSize]; Log.w("Bitmap Decoder", "Samples: " + opts.inSampleSize); opts.inPreferredConfig = Bitmap.Config.ARGB_8888; //opts.inScaled = false; // Not needed if loading bitmaps from drawable-nodpi opts.inMutable = true; opts.inJustDecodeBounds = false; return BitmapFactory.decodeResource(ctx.getResources(), resId, opts); } public static Bitmap LoadScaledBitmap(String filename, float fracX, float fracY) { // See: http://developer.android.com/training/displaying-bitmaps/load-bitmap.html BitmapFactory.Options opts = new BitmapFactory.Options(); opts.inJustDecodeBounds = true; BitmapFactory.decodeFile(filename, opts); int imageHeight = opts.outHeight; int imageWidth = opts.outWidth; float requestX = dispX * fracX, requestY = dispY * fracY; opts.inSampleSize = (int)(Math.min(imageWidth / requestX, imageHeight / requestY)); if (opts.inSampleSize < 0 || opts.inSampleSize > 32) // Sometimes index=2147483647 for some reason... opts.inSampleSize = 1; opts.inSampleSize = sample2sample[opts.inSampleSize]; Log.w("Bitmap Decoder", "Samples: " + opts.inSampleSize); opts.inPreferredConfig = Bitmap.Config.ARGB_8888; //opts.inScaled = false; // Not needed if loading bitmaps from drawable-nodpi opts.inMutable = true; opts.inJustDecodeBounds = false; return BitmapFactory.decodeFile(filename, opts); } public static String FileNameNow() { SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd_HH-mm-ss", Locale.ENGLISH); return fileDir + sdf.format(new Date()) + ".jpg"; } public static native void ocvBitmapPyramidalBlend(String fNew, String fOld, String fMask, String fBlend, int levels); public static String ocvBitmapPyramidalBlendTimed(int levels) { String fBlend = fileTempBlend;//FileNameNow(); long t = System.nanoTime(); ocvBitmapPyramidalBlend(fileTempNew, fileTempOld, fileTempMask, fBlend, levels); long dt = (System.nanoTime() - t) / 1000; // Microseconds Log.w("OpenCV", "Blended (pyramidal) bitmaps in " + (dt / 1000.0f) + " ms"); //fileLastBlend = fBlend; return fBlend; } public static native void ocvBitmapPreMultAlpha(Bitmap bitmapImg, Bitmap bitmapMask); public static void ocvBitmapPreMultAlphaTimed(Bitmap bitmapImg, Bitmap bitmapMask) { long t = System.nanoTime(); ocvBitmapPreMultAlpha(bitmapImg, bitmapMask); long dt = (System.nanoTime() - t) / 1000; // Microseconds Log.i("Native", "Applied premultiplied alpha to bitmap in " + (dt / 1000.0f) + " ms"); } public static native void ocvBitmapContrastSaturationSet(Bitmap bitmapImg); public static void ocvBitmapContrastSaturationSetTimed(Bitmap bitmapImg) { long t = System.nanoTime(); ocvBitmapContrastSaturationSet(bitmapImg); long dt = (System.nanoTime() - t) / 1000; // Microseconds Log.i("Native", "Assigned contrast/saturation bitmap in " + (dt / 1000.0f) + " ms"); } public static native void ocvBitmapContrastSaturationSrc(Bitmap bitmapImg, Bitmap bitmapSrc, float contrast, float saturation); public static void ocvBitmapContrastSaturationSrcTimed(Bitmap bitmapImg, Bitmap bitmapSrc, float contrast, float saturation) { long t = System.nanoTime(); ocvBitmapContrastSaturationSrc(bitmapImg, bitmapSrc, contrast, saturation); long dt = (System.nanoTime() - t) / 1000; // Microseconds Log.i("Native", "Applied contrast/saturation (from src) to bitmap in " + (dt / 1000.0f) + " ms"); } public static native void ocvBitmapContrastSaturation(Bitmap bitmapImg, float contrast, float saturation); public static void ocvBitmapContrastSaturationTimed(Bitmap bitmapImg, float contrast, float saturation) { long t = System.nanoTime(); ocvBitmapContrastSaturation(bitmapImg, contrast, saturation); long dt = (System.nanoTime() - t) / 1000; // Microseconds Log.i("Native", "Applied contrast/saturation to bitmap in " + (dt / 1000.0f) + " ms"); } } } package il.co.canvasvivapp2u.onceapponatime; import java.io.File; import java.io.FileOutputStream; import java.text.SimpleDateFormat; import java.util.Date; import java.util.Locale; import android.annotation.SuppressLint; import android.app.Activity; import android.content.Context; import android.content.res.Configuration; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.graphics.Point; import android.os.Environment; import android.util.Log; import android.view.Display; public class ShairedResources { public static Bitmap bmpOld = null; public static Bitmap bmpOldScaled = null; public static Bitmap bmpNew = null; public static Bitmap bmpNewScaled = null; public static int scaledX = 0, scaledY = 0; public static int dispX = 0, dispY = 0; public static int fullX = 0, fullY = 0; public static int picX = 0, picY = 0; public static String fileDir = "/OnceAppOnATime/"; public static String fileTempDir = fileDir + "/.temp/"; public static String fileTempNew = fileTempDir + "/temp-new.jpg"; public static String fileTempOld = fileTempDir + "/temp-old.jpg"; public static String fileTempMask = fileTempDir + "/temp-mask.jpg"; public static String fileTempBlend = fileTempDir + "/temp-blend.jpg"; public static String fileTempRetouch = fileTempDir + "/temp-retouch.jpg"; //public static String fileLastBlend = ""; public static BitmapFactory.Options op = new BitmapFactory.Options(); public static Locale localeHebrew = null; public static int taskID = -1; public static boolean Init(Activity activity) { return Init(activity, false); } @SuppressLint("NewApi") @SuppressWairnings("deprecation") public static boolean Init(Activity activity, boolean force) { if (dispX > 0 && dispY > 0) { // Don't re-init to avoid wrong file names if (!force) return false; } else { fileDir = Environment.getExternalStorageDirectory() + fileDir; fileTempDir = Environment.getExternalStorageDirectory() + fileTempDir; fileTempNew = Environment.getExternalStorageDirectory() + fileTempNew; fileTempOld = Environment.getExternalStorageDirectory() + fileTempOld; fileTempMask = Environment.getExternalStorageDirectory() + fileTempMask; fileTempBlend = Environment.getExternalStorageDirectory() + fileTempBlend; fileTempRetouch = Environment.getExternalStorageDirectory() + fileTempRetouch; } taskID = activity.getTaskId(); // Find Hebrew locale, if available Locale availableLocales[] = Locale.getAvailableLocales(); for (int i = 0; i < availableLocales.length; ++i) { String lang = availableLocales[i].getLanguage(); if (lang.equals("he") || lang.equals("iw")) { localeHebrew = availableLocales[i]; break; } } op.inPreferredConfig = Bitmap.Config.ARGB_8888; //op.inScaled = false; // Not needed if loading bitmaps from drawable-nodpi op.inMutable = true; Display display = activity.getWindowManager().getDefaultDisplay(); if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.HONEYCOMB_MR2) { dispX = display.getWidth(); dispY = display.getHeight(); } else { Point dispSize = new Point(); display.getSize(dispSize); dispX = dispSize.x; dispY = dispSize.y; } Log.w("Display Size", dispX + "x" + dispY); //scaledX = dispX / 2; scaledY = dispY / 2; scaledX = dispX; scaledY = dispY; return true; } public static void setLocale(Activity activity, Locale locale) { // This doesn't work reliably Locale.setDefault(locale); Configuration config = new Configuration(); config.locale = locale; activity.getBaseContext().getResources().updateConfiguration(config, activity.getBaseContext().getResources().getDisplayMetrics()); } public static boolean haveScaling() { return (dispX != scaledX || dispY != scaledY); } public static void SaveTempBitmap(Bitmap bitmap, String filename) { try { new File(fileTempDir).mkdirs(); FileOutputStream out = new FileOutputStream(filename); bitmap.compress(Bitmap.CompressFormat.JPEG, 98, out); } catch (Exception e) { e.printStackTrace(); } } public static void RecycleOldBitmaps(boolean full, boolean scaled) { if (full && bmpOld != null) { bmpOld.recycle(); bmpOld = null; } if (scaled && bmpOldScaled != null) { bmpOldScaled.recycle(); bmpOldScaled = null; } } public static void RecycleNewBitmaps(boolean full, boolean scaled) { if (full && bmpNew != null) { bmpNew.recycle(); bmpNew = null; } if (scaled && bmpNewScaled != null) { bmpNewScaled.recycle(); bmpNewScaled = null; } } // 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 public static int sample2sample[] = new int[] {1, 1, 2, 2, 4, 4, 4, 4, 8, 8, 8, 8, 8, 8, 8, 8, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32}; public static Bitmap LoadScaledBitmap(Context ctx, int resId, float fracX, float fracY) { // See: http://developer.android.com/training/displaying-bitmaps/load-bitmap.html BitmapFactory.Options opts = new BitmapFactory.Options(); opts.inJustDecodeBounds = true; BitmapFactory.decodeResource(ctx.getResources(), resId, opts); int imageHeight = opts.outHeight; int imageWidth = opts.outWidth; float requestX = dispX * fracX, requestY = dispY * fracY; opts.inSampleSize = (int)(Math.min(imageWidth / requestX, imageHeight / requestY)); if (opts.inSampleSize < 0 || opts.inSampleSize > 32) // Sometimes index=2147483647 for some reason... opts.inSampleSize = 1; opts.inSampleSize = sample2sample[opts.inSampleSize]; Log.w("Bitmap Decoder", "Samples: " + opts.inSampleSize); opts.inPreferredConfig = Bitmap.Config.ARGB_8888; //opts.inScaled = false; // Not needed if loading bitmaps from drawable-nodpi opts.inMutable = true; opts.inJustDecodeBounds = false; return BitmapFactory.decodeResource(ctx.getResources(), resId, opts); } public static Bitmap LoadScaledBitmap(String filename, float fracX, float fracY) { // See: http://developer.android.com/training/displaying-bitmaps/load-bitmap.html BitmapFactory.Options opts = new BitmapFactory.Options(); opts.inJustDecodeBounds = true; BitmapFactory.decodeFile(filename, opts); int imageHeight = opts.outHeight; int imageWidth = opts.outWidth; float requestX = dispX * fracX, requestY = dispY * fracY; opts.inSampleSize = (int)(Math.min(imageWidth / requestX, imageHeight / requestY)); if (opts.inSampleSize < 0 || opts.inSampleSize > 32) // Sometimes index=2147483647 for some reason... opts.inSampleSize = 1; opts.inSampleSize = sample2sample[opts.inSampleSize]; Log.w("Bitmap Decoder", "Samples: " + opts.inSampleSize); opts.inPreferredConfig = Bitmap.Config.ARGB_8888; //opts.inScaled = false; // Not needed if loading bitmaps from drawable-nodpi opts.inMutable = true; opts.inJustDecodeBounds = false; return BitmapFactory.decodeFile(filename, opts); } public static String FileNameNow() { SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd_HH-mm-ss", Locale.ENGLISH); return fileDir + sdf.format(new Date()) + ".jpg"; } public static native void ocvBitmapPyramidalBlend(String fNew, String fOld, String fMask, String fBlend, int levels); public static String ocvBitmapPyramidalBlendTimed(int levels) { String fBlend = fileTempBlend;//FileNameNow(); long t = System.nanoTime(); ocvBitmapPyramidalBlend(fileTempNew, fileTempOld, fileTempMask, fBlend, levels); long dt = (System.nanoTime() - t) / 1000; // Microseconds Log.w("OpenCV", "Blended (pyramidal) bitmaps in " + (dt / 1000.0f) + " ms"); //fileLastBlend = fBlend; return fBlend; } public static native void ocvBitmapPreMultAlpha(Bitmap bitmapImg, Bitmap bitmapMask); public static void ocvBitmapPreMultAlphaTimed(Bitmap bitmapImg, Bitmap bitmapMask) { long t = System.nanoTime(); ocvBitmapPreMultAlpha(bitmapImg, bitmapMask); long dt = (System.nanoTime() - t) / 1000; // Microseconds Log.i("Native", "Applied premultiplied alpha to bitmap in " + (dt / 1000.0f) + " ms"); } public static native void ocvBitmapContrastSaturationSet(Bitmap bitmapImg); public static void ocvBitmapContrastSaturationSetTimed(Bitmap bitmapImg) { long t = System.nanoTime(); ocvBitmapContrastSaturationSet(bitmapImg); long dt = (System.nanoTime() - t) / 1000; // Microseconds Log.i("Native", "Assigned contrast/saturation bitmap in " + (dt / 1000.0f) + " ms"); } public static native void ocvBitmapContrastSaturationSrc(Bitmap bitmapImg, Bitmap bitmapSrc, float contrast, float saturation); public static void ocvBitmapContrastSaturationSrcTimed(Bitmap bitmapImg, Bitmap bitmapSrc, float contrast, float saturation) { long t = System.nanoTime(); ocvBitmapContrastSaturationSrc(bitmapImg, bitmapSrc, contrast, saturation); long dt = (System.nanoTime() - t) / 1000; // Microseconds Log.i("Native", "Applied contrast/saturation (from src) to bitmap in " + (dt / 1000.0f) + " ms"); } public static native void ocvBitmapContrastSaturation(Bitmap bitmapImg, float contrast, float saturation); public static void ocvBitmapContrastSaturationTimed(Bitmap bitmapImg, float contrast, float saturation) { long t = System.nanoTime(); ocvBitmapContrastSaturation(bitmapImg, contrast, saturation); long dt = (System.nanoTime() - t) / 1000; // Microseconds Log.i("Native", "Applied contrast/saturation to bitmap in " + (dt / 1000.0f) + " ms"); } } } package il.co.canvasvivapp2u.onceapponatime; import java.io.File; import java.io.FileOutputStream; import java.text.SimpleDateFormat; import java.util.Date; import java.util.Locale; import android.annotation.SuppressLint; import android.app.Activity; import android.content.Context; import android.content.res.Configuration; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.graphics.Point; import android.os.Environment; import android.util.Log; import android.view.Display; public class ShairedResources { public static Bitmap bmpOld = null; public static Bitmap bmpOldScaled = null; public static Bitmap bmpNew = null; public static Bitmap bmpNewScaled = null; public static int scaledX = 0, scaledY = 0; public static int dispX = 0, dispY = 0; public static int fullX = 0, fullY = 0; public static int picX = 0, picY = 0; public static String fileDir = "/OnceAppOnATime/"; public static String fileTempDir = fileDir + "/.temp/"; public static String fileTempNew = fileTempDir + "/temp-new.jpg"; public static String fileTempOld = fileTempDir + "/temp-old.jpg"; public static String fileTempMask = fileTempDir + "/temp-mask.jpg"; public static String fileTempBlend = fileTempDir + "/temp-blend.jpg"; public static String fileTempRetouch = fileTempDir + "/temp-retouch.jpg"; //public static String fileLastBlend = ""; public static BitmapFactory.Options op = new BitmapFactory.Options(); public static Locale localeHebrew = null; public static int taskID = -1; public static boolean Init(Activity activity) { return Init(activity, false); } @SuppressLint("NewApi") @SuppressWairnings("deprecation") public static boolean Init(Activity activity, boolean force) { if (dispX > 0 && dispY > 0) { // Don't re-init to avoid wrong file names if (!force) return false; } else { fileDir = Environment.getExternalStorageDirectory() + fileDir; fileTempDir = Environment.getExternalStorageDirectory() + fileTempDir; fileTempNew = Environment.getExternalStorageDirectory() + fileTempNew; fileTempOld = Environment.getExternalStorageDirectory() + fileTempOld; fileTempMask = Environment.getExternalStorageDirectory() + fileTempMask; fileTempBlend = Environment.getExternalStorageDirectory() + fileTempBlend; fileTempRetouch = Environment.getExternalStorageDirectory() + fileTempRetouch; } taskID = activity.getTaskId(); // Find Hebrew locale, if available Locale availableLocales[] = Locale.getAvailableLocales(); for (int i = 0; i < availableLocales.length; ++i) { String lang = availableLocales[i].getLanguage(); if (lang.equals("he") || lang.equals("iw")) { localeHebrew = availableLocales[i]; break; } } op.inPreferredConfig = Bitmap.Config.ARGB_8888; //op.inScaled = false; // Not needed if loading bitmaps from drawable-nodpi op.inMutable = true; Display display = activity.getWindowManager().getDefaultDisplay(); if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.HONEYCOMB_MR2) { dispX = display.getWidth(); dispY = display.getHeight(); } else { Point dispSize = new Point(); display.getSize(dispSize); dispX = dispSize.x; dispY = dispSize.y; } Log.w("Display Size", dispX + "x" + dispY); //scaledX = dispX / 2; scaledY = dispY / 2; scaledX = dispX; scaledY = dispY; return true; } public static void setLocale(Activity activity, Locale locale) { // This doesn't work reliably Locale.setDefault(locale); Configuration config = new Configuration(); config.locale = locale; activity.getBaseContext().getResources().updateConfiguration(config, activity.getBaseContext().getResources().getDisplayMetrics()); } public static boolean haveScaling() { return (dispX != scaledX || dispY != scaledY); } public static void SaveTempBitmap(Bitmap bitmap, String filename) { try { new File(fileTempDir).mkdirs(); FileOutputStream out = new FileOutputStream(filename); bitmap.compress(Bitmap.CompressFormat.JPEG, 98, out); } catch (Exception e) { e.printStackTrace(); } } public static void RecycleOldBitmaps(boolean full, boolean scaled) { if (full && bmpOld != null) { bmpOld.recycle(); bmpOld = null; } if (scaled && bmpOldScaled != null) { bmpOldScaled.recycle(); bmpOldScaled = null; } } public static void RecycleNewBitmaps(boolean full, boolean scaled) { if (full && bmpNew != null) { bmpNew.recycle(); bmpNew = null; } if (scaled && bmpNewScaled != null) { bmpNewScaled.recycle(); bmpNewScaled = null; } } // 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 public static int sample2sample[] = new int[] {1, 1, 2, 2, 4, 4, 4, 4, 8, 8, 8, 8, 8, 8, 8, 8, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32}; public static Bitmap LoadScaledBitmap(Context ctx, int resId, float fracX, float fracY) { // See: http://developer.android.com/training/displaying-bitmaps/load-bitmap.html BitmapFactory.Options opts = new BitmapFactory.Options(); opts.inJustDecodeBounds = true; BitmapFactory.decodeResource(ctx.getResources(), resId, opts); int imageHeight = opts.outHeight; int imageWidth = opts.outWidth; float requestX = dispX * fracX, requestY = dispY * fracY; opts.inSampleSize = (int)(Math.min(imageWidth / requestX, imageHeight / requestY)); if (opts.inSampleSize < 0 || opts.inSampleSize > 32) // Sometimes index=2147483647 for some reason... opts.inSampleSize = 1; opts.inSampleSize = sample2sample[opts.inSampleSize]; Log.w("Bitmap Decoder", "Samples: " + opts.inSampleSize); opts.inPreferredConfig = Bitmap.Config.ARGB_8888; //opts.inScaled = false; // Not needed if loading bitmaps from drawable-nodpi opts.inMutable = true; opts.inJustDecodeBounds = false; return BitmapFactory.decodeResource(ctx.getResources(), resId, opts); } public static Bitmap LoadScaledBitmap(String filename, float fracX, float fracY) { // See: http://developer.android.com/training/displaying-bitmaps/load-bitmap.html BitmapFactory.Options opts = new BitmapFactory.Options(); opts.inJustDecodeBounds = true; BitmapFactory.decodeFile(filename, opts); int imageHeight = opts.outHeight; int imageWidth = opts.outWidth; float requestX = dispX * fracX, requestY = dispY * fracY; opts.inSampleSize = (int)(Math.min(imageWidth / requestX, imageHeight / requestY)); if (opts.inSampleSize < 0 || opts.inSampleSize > 32) // Sometimes index=2147483647 for some reason... opts.inSampleSize = 1; opts.inSampleSize = sample2sample[opts.inSampleSize]; Log.w("Bitmap Decoder", "Samples: " + opts.inSampleSize); opts.inPreferredConfig = Bitmap.Config.ARGB_8888; //opts.inScaled = false; // Not needed if loading bitmaps from drawable-nodpi opts.inMutable = true; opts.inJustDecodeBounds = false; return BitmapFactory.decodeFile(filename, opts); } public static String FileNameNow() { SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd_HH-mm-ss", Locale.ENGLISH); return fileDir + sdf.format(new Date()) + ".jpg"; } public static native void ocvBitmapPyramidalBlend(String fNew, String fOld, String fMask, String fBlend, int levels); public static String ocvBitmapPyramidalBlendTimed(int levels) { String fBlend = fileTempBlend;//FileNameNow(); long t = System.nanoTime(); ocvBitmapPyramidalBlend(fileTempNew, fileTempOld, fileTempMask, fBlend, levels); long dt = (System.nanoTime() - t) / 1000; // Microseconds Log.w("OpenCV", "Blended (pyramidal) bitmaps in " + (dt / 1000.0f) + " ms"); //fileLastBlend = fBlend; return fBlend; } public static native void ocvBitmapPreMultAlpha(Bitmap bitmapImg, Bitmap bitmapMask); public static void ocvBitmapPreMultAlphaTimed(Bitmap bitmapImg, Bitmap bitmapMask) { long t = System.nanoTime(); ocvBitmapPreMultAlpha(bitmapImg, bitmapMask); long dt = (System.nanoTime() - t) / 1000; // Microseconds Log.i("Native", "Applied premultiplied alpha to bitmap in " + (dt / 1000.0f) + " ms"); } public static native void ocvBitmapContrastSaturationSet(Bitmap bitmapImg); public static void ocvBitmapContrastSaturationSetTimed(Bitmap bitmapImg) { long t = System.nanoTime(); ocvBitmapContrastSaturationSet(bitmapImg); long dt = (System.nanoTime() - t) / 1000; // Microseconds Log.i("Native", "Assigned contrast/saturation bitmap in " + (dt / 1000.0f) + " ms"); } public static native void ocvBitmapContrastSaturationSrc(Bitmap bitmapImg, Bitmap bitmapSrc, float contrast, float saturation); public static void ocvBitmapContrastSaturationSrcTimed(Bitmap bitmapImg, Bitmap bitmapSrc, float contrast, float saturation) { long t = System.nanoTime(); ocvBitmapContrastSaturationSrc(bitmapImg, bitmapSrc, contrast, saturation); long dt = (System.nanoTime() - t) / 1000; // Microseconds Log.i("Native", "Applied contrast/saturation (from src) to bitmap in " + (dt / 1000.0f) + " ms"); } public static native void ocvBitmapContrastSaturation(Bitmap bitmapImg, float contrast, float saturation); public static void ocvBitmapContrastSaturationTimed(Bitmap bitmapImg, float contrast, float saturation) { long t = System.nanoTime(); ocvBitmapContrastSaturation(bitmapImg, contrast, saturation); long dt = (System.nanoTime() - t) / 1000; // Microseconds Log.i("Native", "Applied contrast/saturation to bitmap in " + (dt / 1000.0f) + " ms"); } } } package il.co.canvasvivapp2u.onceapponatime; import java.io.File; import java.io.FileOutputStream; import java.text.SimpleDateFormat; import java.util.Date; import java.util.Locale; import android.annotation.SuppressLint; import android.app.Activity; import android.content.Context; import android.content.res.Configuration; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.graphics.Point; import android.os.Environment; import android.util.Log; import android.view.Display; public class ShairedResources { public static Bitmap bmpOld = null; public static Bitmap bmpOldScaled = null; public static Bitmap bmpNew = null; public static Bitmap bmpNewScaled = null; public static int scaledX = 0, scaledY = 0; public static int dispX = 0, dispY = 0; public static int fullX = 0, fullY = 0; public static int picX = 0, picY = 0; public static String fileDir = "/OnceAppOnATime/"; public static String fileTempDir = fileDir + "/.temp/"; public static String fileTempNew = fileTempDir + "/temp-new.jpg"; public static String fileTempOld = fileTempDir + "/temp-old.jpg"; public static String fileTempMask = fileTempDir + "/temp-mask.jpg"; public static String fileTempBlend = fileTempDir + "/temp-blend.jpg"; public static String fileTempRetouch = fileTempDir + "/temp-retouch.jpg"; //public static String fileLastBlend = ""; public static BitmapFactory.Options op = new BitmapFactory.Options(); public static Locale localeHebrew = null; public static int taskID = -1; public static boolean Init(Activity activity) { return Init(activity, false); } @SuppressLint("NewApi") @SuppressWairnings("deprecation") public static boolean Init(Activity activity, boolean force) { if (dispX > 0 && dispY > 0) { // Don't re-init to avoid wrong file names if (!force) return false; } else { fileDir = Environment.getExternalStorageDirectory() + fileDir; fileTempDir = Environment.getExternalStorageDirectory() + fileTempDir; fileTempNew = Environment.getExternalStorageDirectory() + fileTempNew; fileTempOld = Environment.getExternalStorageDirectory() + fileTempOld; fileTempMask = Environment.getExternalStorageDirectory() + fileTempMask; fileTempBlend = Environment.getExternalStorageDirectory() + fileTempBlend; fileTempRetouch = Environment.getExternalStorageDirectory() + fileTempRetouch; } taskID = activity.getTaskId(); // Find Hebrew locale, if available Locale availableLocales[] = Locale.getAvailableLocales(); for (int i = 0; i < availableLocales.length; ++i) { String lang = availableLocales[i].getLanguage(); if (lang.equals("he") || lang.equals("iw")) { localeHebrew = availableLocales[i]; break; } } op.inPreferredConfig = Bitmap.Config.ARGB_8888; //op.inScaled = false; // Not needed if loading bitmaps from drawable-nodpi op.inMutable = true; Display display = activity.getWindowManager().getDefaultDisplay(); if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.HONEYCOMB_MR2) { dispX = display.getWidth(); dispY = display.getHeight(); } else { Point dispSize = new Point(); display.getSize(dispSize); dispX = dispSize.x; dispY = dispSize.y; } Log.w("Display Size", dispX + "x" + dispY); //scaledX = dispX / 2; scaledY = dispY / 2; scaledX = dispX; scaledY = dispY; return true; } public static void setLocale(Activity activity, Locale locale) { // This doesn't work reliably Locale.setDefault(locale); Configuration config = new Configuration(); config.locale = locale; activity.getBaseContext().getResources().updateConfiguration(config, activity.getBaseContext().getResources().getDisplayMetrics()); } public static boolean haveScaling() { return (dispX != scaledX || dispY != scaledY); } public static void SaveTempBitmap(Bitmap bitmap, String filename) { try { new File(fileTempDir).mkdirs(); FileOutputStream out = new FileOutputStream(filename); bitmap.compress(Bitmap.CompressFormat.JPEG, 98, out); } catch (Exception e) { e.printStackTrace(); } } public static void RecycleOldBitmaps(boolean full, boolean scaled) { if (full && bmpOld != null) { bmpOld.recycle(); bmpOld = null; } if (scaled && bmpOldScaled != null) { bmpOldScaled.recycle(); bmpOldScaled = null; } } public static void RecycleNewBitmaps(boolean full, boolean scaled) { if (full && bmpNew != null) { bmpNew.recycle(); bmpNew = null; } if (scaled && bmpNewScaled != null) { bmpNewScaled.recycle(); bmpNewScaled = null; } } // 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 public static int sample2sample[] = new int[] {1, 1, 2, 2, 4, 4, 4, 4, 8, 8, 8, 8, 8, 8, 8, 8, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32}; public static Bitmap LoadScaledBitmap(Context ctx, int resId, float fracX, float fracY) { // See: http://developer.android.com/training/displaying-bitmaps/load-bitmap.html BitmapFactory.Options opts = new BitmapFactory.Options(); opts.inJustDecodeBounds = true; BitmapFactory.decodeResource(ctx.getResources(), resId, opts); int imageHeight = opts.outHeight; int imageWidth = opts.outWidth; float requestX = dispX * fracX, requestY = dispY * fracY; opts.inSampleSize = (int)(Math.min(imageWidth / requestX, imageHeight / requestY)); if (opts.inSampleSize < 0 || opts.inSampleSize > 32) // Sometimes index=2147483647 for some reason... opts.inSampleSize = 1; opts.inSampleSize = sample2sample[opts.inSampleSize]; Log.w("Bitmap Decoder", "Samples: " + opts.inSampleSize); opts.inPreferredConfig = Bitmap.Config.ARGB_8888; //opts.inScaled = false; // Not needed if loading bitmaps from drawable-nodpi opts.inMutable = true; opts.inJustDecodeBounds = false; return BitmapFactory.decodeResource(ctx.getResources(), resId, opts); } public static Bitmap LoadScaledBitmap(String filename, float fracX, float fracY) { // See: http://developer.android.com/training/displaying-bitmaps/load-bitmap.html BitmapFactory.Options opts = new BitmapFactory.Options(); opts.inJustDecodeBounds = true; BitmapFactory.decodeFile(filename, opts); int imageHeight = opts.outHeight; int imageWidth = opts.outWidth; float requestX = dispX * fracX, requestY = dispY * fracY; opts.inSampleSize = (int)(Math.min(imageWidth / requestX, imageHeight / requestY)); if (opts.inSampleSize < 0 || opts.inSampleSize > 32) // Sometimes index=2147483647 for some reason... opts.inSampleSize = 1; opts.inSampleSize = sample2sample[opts.inSampleSize]; Log.w("Bitmap Decoder", "Samples: " + opts.inSampleSize); opts.inPreferredConfig = Bitmap.Config.ARGB_8888; //opts.inScaled = false; // Not needed if loading bitmaps from drawable-nodpi opts.inMutable = true; opts.inJustDecodeBounds = false; return BitmapFactory.decodeFile(filename, opts); } public static String FileNameNow() { SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd_HH-mm-ss", Locale.ENGLISH); return fileDir + sdf.format(new Date()) + ".jpg"; } public static native void ocvBitmapPyramidalBlend(String fNew, String fOld, String fMask, String fBlend, int levels); public static String ocvBitmapPyramidalBlendTimed(int levels) { String fBlend = fileTempBlend;//FileNameNow(); long t = System.nanoTime(); ocvBitmapPyramidalBlend(fileTempNew, fileTempOld, fileTempMask, fBlend, levels); long dt = (System.nanoTime() - t) / 1000; // Microseconds Log.w("OpenCV", "Blended (pyramidal) bitmaps in " + (dt / 1000.0f) + " ms"); //fileLastBlend = fBlend; return fBlend; } public static native void ocvBitmapPreMultAlpha(Bitmap bitmapImg, Bitmap bitmapMask); public static void ocvBitmapPreMultAlphaTimed(Bitmap bitmapImg, Bitmap bitmapMask) { long t = System.nanoTime(); ocvBitmapPreMultAlpha(bitmapImg, bitmapMask); long dt = (System.nanoTime() - t) / 1000; // Microseconds Log.i("Native", "Applied premultiplied alpha to bitmap in " + (dt / 1000.0f) + " ms"); } public static native void ocvBitmapContrastSaturationSet(Bitmap bitmapImg); public static void ocvBitmapContrastSaturationSetTimed(Bitmap bitmapImg) { long t = System.nanoTime(); ocvBitmapContrastSaturationSet(bitmapImg); long dt = (System.nanoTime() - t) / 1000; // Microseconds Log.i("Native", "Assigned contrast/saturation bitmap in " + (dt / 1000.0f) + " ms"); } public static native void ocvBitmapContrastSaturationSrc(Bitmap bitmapImg, Bitmap bitmapSrc, float contrast, float saturation); public static void ocvBitmapContrastSaturationSrcTimed(Bitmap bitmapImg, Bitmap bitmapSrc, float contrast, float saturation) { long t = System.nanoTime(); ocvBitmapContrastSaturationSrc(bitmapImg, bitmapSrc, contrast, saturation); long dt = (System.nanoTime() - t) / 1000; // Microseconds Log.i("Native", "Applied contrast/saturation (from src) to bitmap in " + (dt / 1000.0f) + " ms"); } public static native void ocvBitmapContrastSaturation(Bitmap bitmapImg, float contrast, float saturation); public static void ocvBitmapContrastSaturationTimed(Bitmap bitmapImg, float contrast, float saturation) { long t = System.nanoTime(); ocvBitmapContrastSaturation(bitmapImg, contrast, saturation); long dt = (System.nanoTime() - t) / 1000; // Microseconds Log.i("Native", "Applied contrast/saturation to bitmap in " + (dt / 1000.0f) + " ms"); } } retornair viewdadeiro; package il.co.canvasvivapp2u.onceapponatime; import java.io.File; import java.io.FileOutputStream; import java.text.SimpleDateFormat; import java.util.Date; import java.util.Locale; import android.annotation.SuppressLint; import android.app.Activity; import android.content.Context; import android.content.res.Configuration; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.graphics.Point; import android.os.Environment; import android.util.Log; import android.view.Display; public class ShairedResources { public static Bitmap bmpOld = null; public static Bitmap bmpOldScaled = null; public static Bitmap bmpNew = null; public static Bitmap bmpNewScaled = null; public static int scaledX = 0, scaledY = 0; public static int dispX = 0, dispY = 0; public static int fullX = 0, fullY = 0; public static int picX = 0, picY = 0; public static String fileDir = "/OnceAppOnATime/"; public static String fileTempDir = fileDir + "/.temp/"; public static String fileTempNew = fileTempDir + "/temp-new.jpg"; public static String fileTempOld = fileTempDir + "/temp-old.jpg"; public static String fileTempMask = fileTempDir + "/temp-mask.jpg"; public static String fileTempBlend = fileTempDir + "/temp-blend.jpg"; public static String fileTempRetouch = fileTempDir + "/temp-retouch.jpg"; //public static String fileLastBlend = ""; public static BitmapFactory.Options op = new BitmapFactory.Options(); public static Locale localeHebrew = null; public static int taskID = -1; public static boolean Init(Activity activity) { return Init(activity, false); } @SuppressLint("NewApi") @SuppressWairnings("deprecation") public static boolean Init(Activity activity, boolean force) { if (dispX > 0 && dispY > 0) { // Don't re-init to avoid wrong file names if (!force) return false; } else { fileDir = Environment.getExternalStorageDirectory() + fileDir; fileTempDir = Environment.getExternalStorageDirectory() + fileTempDir; fileTempNew = Environment.getExternalStorageDirectory() + fileTempNew; fileTempOld = Environment.getExternalStorageDirectory() + fileTempOld; fileTempMask = Environment.getExternalStorageDirectory() + fileTempMask; fileTempBlend = Environment.getExternalStorageDirectory() + fileTempBlend; fileTempRetouch = Environment.getExternalStorageDirectory() + fileTempRetouch; } taskID = activity.getTaskId(); // Find Hebrew locale, if available Locale availableLocales[] = Locale.getAvailableLocales(); for (int i = 0; i < availableLocales.length; ++i) { String lang = availableLocales[i].getLanguage(); if (lang.equals("he") || lang.equals("iw")) { localeHebrew = availableLocales[i]; break; } } op.inPreferredConfig = Bitmap.Config.ARGB_8888; //op.inScaled = false; // Not needed if loading bitmaps from drawable-nodpi op.inMutable = true; Display display = activity.getWindowManager().getDefaultDisplay(); if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.HONEYCOMB_MR2) { dispX = display.getWidth(); dispY = display.getHeight(); } else { Point dispSize = new Point(); display.getSize(dispSize); dispX = dispSize.x; dispY = dispSize.y; } Log.w("Display Size", dispX + "x" + dispY); //scaledX = dispX / 2; scaledY = dispY / 2; scaledX = dispX; scaledY = dispY; return true; } public static void setLocale(Activity activity, Locale locale) { // This doesn't work reliably Locale.setDefault(locale); Configuration config = new Configuration(); config.locale = locale; activity.getBaseContext().getResources().updateConfiguration(config, activity.getBaseContext().getResources().getDisplayMetrics()); } public static boolean haveScaling() { return (dispX != scaledX || dispY != scaledY); } public static void SaveTempBitmap(Bitmap bitmap, String filename) { try { new File(fileTempDir).mkdirs(); FileOutputStream out = new FileOutputStream(filename); bitmap.compress(Bitmap.CompressFormat.JPEG, 98, out); } catch (Exception e) { e.printStackTrace(); } } public static void RecycleOldBitmaps(boolean full, boolean scaled) { if (full && bmpOld != null) { bmpOld.recycle(); bmpOld = null; } if (scaled && bmpOldScaled != null) { bmpOldScaled.recycle(); bmpOldScaled = null; } } public static void RecycleNewBitmaps(boolean full, boolean scaled) { if (full && bmpNew != null) { bmpNew.recycle(); bmpNew = null; } if (scaled && bmpNewScaled != null) { bmpNewScaled.recycle(); bmpNewScaled = null; } } // 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 public static int sample2sample[] = new int[] {1, 1, 2, 2, 4, 4, 4, 4, 8, 8, 8, 8, 8, 8, 8, 8, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32}; public static Bitmap LoadScaledBitmap(Context ctx, int resId, float fracX, float fracY) { // See: http://developer.android.com/training/displaying-bitmaps/load-bitmap.html BitmapFactory.Options opts = new BitmapFactory.Options(); opts.inJustDecodeBounds = true; BitmapFactory.decodeResource(ctx.getResources(), resId, opts); int imageHeight = opts.outHeight; int imageWidth = opts.outWidth; float requestX = dispX * fracX, requestY = dispY * fracY; opts.inSampleSize = (int)(Math.min(imageWidth / requestX, imageHeight / requestY)); if (opts.inSampleSize < 0 || opts.inSampleSize > 32) // Sometimes index=2147483647 for some reason... opts.inSampleSize = 1; opts.inSampleSize = sample2sample[opts.inSampleSize]; Log.w("Bitmap Decoder", "Samples: " + opts.inSampleSize); opts.inPreferredConfig = Bitmap.Config.ARGB_8888; //opts.inScaled = false; // Not needed if loading bitmaps from drawable-nodpi opts.inMutable = true; opts.inJustDecodeBounds = false; return BitmapFactory.decodeResource(ctx.getResources(), resId, opts); } public static Bitmap LoadScaledBitmap(String filename, float fracX, float fracY) { // See: http://developer.android.com/training/displaying-bitmaps/load-bitmap.html BitmapFactory.Options opts = new BitmapFactory.Options(); opts.inJustDecodeBounds = true; BitmapFactory.decodeFile(filename, opts); int imageHeight = opts.outHeight; int imageWidth = opts.outWidth; float requestX = dispX * fracX, requestY = dispY * fracY; opts.inSampleSize = (int)(Math.min(imageWidth / requestX, imageHeight / requestY)); if (opts.inSampleSize < 0 || opts.inSampleSize > 32) // Sometimes index=2147483647 for some reason... opts.inSampleSize = 1; opts.inSampleSize = sample2sample[opts.inSampleSize]; Log.w("Bitmap Decoder", "Samples: " + opts.inSampleSize); opts.inPreferredConfig = Bitmap.Config.ARGB_8888; //opts.inScaled = false; // Not needed if loading bitmaps from drawable-nodpi opts.inMutable = true; opts.inJustDecodeBounds = false; return BitmapFactory.decodeFile(filename, opts); } public static String FileNameNow() { SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd_HH-mm-ss", Locale.ENGLISH); return fileDir + sdf.format(new Date()) + ".jpg"; } public static native void ocvBitmapPyramidalBlend(String fNew, String fOld, String fMask, String fBlend, int levels); public static String ocvBitmapPyramidalBlendTimed(int levels) { String fBlend = fileTempBlend;//FileNameNow(); long t = System.nanoTime(); ocvBitmapPyramidalBlend(fileTempNew, fileTempOld, fileTempMask, fBlend, levels); long dt = (System.nanoTime() - t) / 1000; // Microseconds Log.w("OpenCV", "Blended (pyramidal) bitmaps in " + (dt / 1000.0f) + " ms"); //fileLastBlend = fBlend; return fBlend; } public static native void ocvBitmapPreMultAlpha(Bitmap bitmapImg, Bitmap bitmapMask); public static void ocvBitmapPreMultAlphaTimed(Bitmap bitmapImg, Bitmap bitmapMask) { long t = System.nanoTime(); ocvBitmapPreMultAlpha(bitmapImg, bitmapMask); long dt = (System.nanoTime() - t) / 1000; // Microseconds Log.i("Native", "Applied premultiplied alpha to bitmap in " + (dt / 1000.0f) + " ms"); } public static native void ocvBitmapContrastSaturationSet(Bitmap bitmapImg); public static void ocvBitmapContrastSaturationSetTimed(Bitmap bitmapImg) { long t = System.nanoTime(); ocvBitmapContrastSaturationSet(bitmapImg); long dt = (System.nanoTime() - t) / 1000; // Microseconds Log.i("Native", "Assigned contrast/saturation bitmap in " + (dt / 1000.0f) + " ms"); } public static native void ocvBitmapContrastSaturationSrc(Bitmap bitmapImg, Bitmap bitmapSrc, float contrast, float saturation); public static void ocvBitmapContrastSaturationSrcTimed(Bitmap bitmapImg, Bitmap bitmapSrc, float contrast, float saturation) { long t = System.nanoTime(); ocvBitmapContrastSaturationSrc(bitmapImg, bitmapSrc, contrast, saturation); long dt = (System.nanoTime() - t) / 1000; // Microseconds Log.i("Native", "Applied contrast/saturation (from src) to bitmap in " + (dt / 1000.0f) + " ms"); } public static native void ocvBitmapContrastSaturation(Bitmap bitmapImg, float contrast, float saturation); public static void ocvBitmapContrastSaturationTimed(Bitmap bitmapImg, float contrast, float saturation) { long t = System.nanoTime(); ocvBitmapContrastSaturation(bitmapImg, contrast, saturation); long dt = (System.nanoTime() - t) / 1000; // Microseconds Log.i("Native", "Applied contrast/saturation to bitmap in " + (dt / 1000.0f) + " ms"); } } } package il.co.canvasvivapp2u.onceapponatime; import java.io.File; import java.io.FileOutputStream; import java.text.SimpleDateFormat; import java.util.Date; import java.util.Locale; import android.annotation.SuppressLint; import android.app.Activity; import android.content.Context; import android.content.res.Configuration; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.graphics.Point; import android.os.Environment; import android.util.Log; import android.view.Display; public class ShairedResources { public static Bitmap bmpOld = null; public static Bitmap bmpOldScaled = null; public static Bitmap bmpNew = null; public static Bitmap bmpNewScaled = null; public static int scaledX = 0, scaledY = 0; public static int dispX = 0, dispY = 0; public static int fullX = 0, fullY = 0; public static int picX = 0, picY = 0; public static String fileDir = "/OnceAppOnATime/"; public static String fileTempDir = fileDir + "/.temp/"; public static String fileTempNew = fileTempDir + "/temp-new.jpg"; public static String fileTempOld = fileTempDir + "/temp-old.jpg"; public static String fileTempMask = fileTempDir + "/temp-mask.jpg"; public static String fileTempBlend = fileTempDir + "/temp-blend.jpg"; public static String fileTempRetouch = fileTempDir + "/temp-retouch.jpg"; //public static String fileLastBlend = ""; public static BitmapFactory.Options op = new BitmapFactory.Options(); public static Locale localeHebrew = null; public static int taskID = -1; public static boolean Init(Activity activity) { return Init(activity, false); } @SuppressLint("NewApi") @SuppressWairnings("deprecation") public static boolean Init(Activity activity, boolean force) { if (dispX > 0 && dispY > 0) { // Don't re-init to avoid wrong file names if (!force) return false; } else { fileDir = Environment.getExternalStorageDirectory() + fileDir; fileTempDir = Environment.getExternalStorageDirectory() + fileTempDir; fileTempNew = Environment.getExternalStorageDirectory() + fileTempNew; fileTempOld = Environment.getExternalStorageDirectory() + fileTempOld; fileTempMask = Environment.getExternalStorageDirectory() + fileTempMask; fileTempBlend = Environment.getExternalStorageDirectory() + fileTempBlend; fileTempRetouch = Environment.getExternalStorageDirectory() + fileTempRetouch; } taskID = activity.getTaskId(); // Find Hebrew locale, if available Locale availableLocales[] = Locale.getAvailableLocales(); for (int i = 0; i < availableLocales.length; ++i) { String lang = availableLocales[i].getLanguage(); if (lang.equals("he") || lang.equals("iw")) { localeHebrew = availableLocales[i]; break; } } op.inPreferredConfig = Bitmap.Config.ARGB_8888; //op.inScaled = false; // Not needed if loading bitmaps from drawable-nodpi op.inMutable = true; Display display = activity.getWindowManager().getDefaultDisplay(); if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.HONEYCOMB_MR2) { dispX = display.getWidth(); dispY = display.getHeight(); } else { Point dispSize = new Point(); display.getSize(dispSize); dispX = dispSize.x; dispY = dispSize.y; } Log.w("Display Size", dispX + "x" + dispY); //scaledX = dispX / 2; scaledY = dispY / 2; scaledX = dispX; scaledY = dispY; return true; } public static void setLocale(Activity activity, Locale locale) { // This doesn't work reliably Locale.setDefault(locale); Configuration config = new Configuration(); config.locale = locale; activity.getBaseContext().getResources().updateConfiguration(config, activity.getBaseContext().getResources().getDisplayMetrics()); } public static boolean haveScaling() { return (dispX != scaledX || dispY != scaledY); } public static void SaveTempBitmap(Bitmap bitmap, String filename) { try { new File(fileTempDir).mkdirs(); FileOutputStream out = new FileOutputStream(filename); bitmap.compress(Bitmap.CompressFormat.JPEG, 98, out); } catch (Exception e) { e.printStackTrace(); } } public static void RecycleOldBitmaps(boolean full, boolean scaled) { if (full && bmpOld != null) { bmpOld.recycle(); bmpOld = null; } if (scaled && bmpOldScaled != null) { bmpOldScaled.recycle(); bmpOldScaled = null; } } public static void RecycleNewBitmaps(boolean full, boolean scaled) { if (full && bmpNew != null) { bmpNew.recycle(); bmpNew = null; } if (scaled && bmpNewScaled != null) { bmpNewScaled.recycle(); bmpNewScaled = null; } } // 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 public static int sample2sample[] = new int[] {1, 1, 2, 2, 4, 4, 4, 4, 8, 8, 8, 8, 8, 8, 8, 8, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32}; public static Bitmap LoadScaledBitmap(Context ctx, int resId, float fracX, float fracY) { // See: http://developer.android.com/training/displaying-bitmaps/load-bitmap.html BitmapFactory.Options opts = new BitmapFactory.Options(); opts.inJustDecodeBounds = true; BitmapFactory.decodeResource(ctx.getResources(), resId, opts); int imageHeight = opts.outHeight; int imageWidth = opts.outWidth; float requestX = dispX * fracX, requestY = dispY * fracY; opts.inSampleSize = (int)(Math.min(imageWidth / requestX, imageHeight / requestY)); if (opts.inSampleSize < 0 || opts.inSampleSize > 32) // Sometimes index=2147483647 for some reason... opts.inSampleSize = 1; opts.inSampleSize = sample2sample[opts.inSampleSize]; Log.w("Bitmap Decoder", "Samples: " + opts.inSampleSize); opts.inPreferredConfig = Bitmap.Config.ARGB_8888; //opts.inScaled = false; // Not needed if loading bitmaps from drawable-nodpi opts.inMutable = true; opts.inJustDecodeBounds = false; return BitmapFactory.decodeResource(ctx.getResources(), resId, opts); } public static Bitmap LoadScaledBitmap(String filename, float fracX, float fracY) { // See: http://developer.android.com/training/displaying-bitmaps/load-bitmap.html BitmapFactory.Options opts = new BitmapFactory.Options(); opts.inJustDecodeBounds = true; BitmapFactory.decodeFile(filename, opts); int imageHeight = opts.outHeight; int imageWidth = opts.outWidth; float requestX = dispX * fracX, requestY = dispY * fracY; opts.inSampleSize = (int)(Math.min(imageWidth / requestX, imageHeight / requestY)); if (opts.inSampleSize < 0 || opts.inSampleSize > 32) // Sometimes index=2147483647 for some reason... opts.inSampleSize = 1; opts.inSampleSize = sample2sample[opts.inSampleSize]; Log.w("Bitmap Decoder", "Samples: " + opts.inSampleSize); opts.inPreferredConfig = Bitmap.Config.ARGB_8888; //opts.inScaled = false; // Not needed if loading bitmaps from drawable-nodpi opts.inMutable = true; opts.inJustDecodeBounds = false; return BitmapFactory.decodeFile(filename, opts); } public static String FileNameNow() { SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd_HH-mm-ss", Locale.ENGLISH); return fileDir + sdf.format(new Date()) + ".jpg"; } public static native void ocvBitmapPyramidalBlend(String fNew, String fOld, String fMask, String fBlend, int levels); public static String ocvBitmapPyramidalBlendTimed(int levels) { String fBlend = fileTempBlend;//FileNameNow(); long t = System.nanoTime(); ocvBitmapPyramidalBlend(fileTempNew, fileTempOld, fileTempMask, fBlend, levels); long dt = (System.nanoTime() - t) / 1000; // Microseconds Log.w("OpenCV", "Blended (pyramidal) bitmaps in " + (dt / 1000.0f) + " ms"); //fileLastBlend = fBlend; return fBlend; } public static native void ocvBitmapPreMultAlpha(Bitmap bitmapImg, Bitmap bitmapMask); public static void ocvBitmapPreMultAlphaTimed(Bitmap bitmapImg, Bitmap bitmapMask) { long t = System.nanoTime(); ocvBitmapPreMultAlpha(bitmapImg, bitmapMask); long dt = (System.nanoTime() - t) / 1000; // Microseconds Log.i("Native", "Applied premultiplied alpha to bitmap in " + (dt / 1000.0f) + " ms"); } public static native void ocvBitmapContrastSaturationSet(Bitmap bitmapImg); public static void ocvBitmapContrastSaturationSetTimed(Bitmap bitmapImg) { long t = System.nanoTime(); ocvBitmapContrastSaturationSet(bitmapImg); long dt = (System.nanoTime() - t) / 1000; // Microseconds Log.i("Native", "Assigned contrast/saturation bitmap in " + (dt / 1000.0f) + " ms"); } public static native void ocvBitmapContrastSaturationSrc(Bitmap bitmapImg, Bitmap bitmapSrc, float contrast, float saturation); public static void ocvBitmapContrastSaturationSrcTimed(Bitmap bitmapImg, Bitmap bitmapSrc, float contrast, float saturation) { long t = System.nanoTime(); ocvBitmapContrastSaturationSrc(bitmapImg, bitmapSrc, contrast, saturation); long dt = (System.nanoTime() - t) / 1000; // Microseconds Log.i("Native", "Applied contrast/saturation (from src) to bitmap in " + (dt / 1000.0f) + " ms"); } public static native void ocvBitmapContrastSaturation(Bitmap bitmapImg, float contrast, float saturation); public static void ocvBitmapContrastSaturationTimed(Bitmap bitmapImg, float contrast, float saturation) { long t = System.nanoTime(); ocvBitmapContrastSaturation(bitmapImg, contrast, saturation); long dt = (System.nanoTime() - t) / 1000; // Microseconds Log.i("Native", "Applied contrast/saturation to bitmap in " + (dt / 1000.0f) + " ms"); } } } package il.co.canvasvivapp2u.onceapponatime; import java.io.File; import java.io.FileOutputStream; import java.text.SimpleDateFormat; import java.util.Date; import java.util.Locale; import android.annotation.SuppressLint; import android.app.Activity; import android.content.Context; import android.content.res.Configuration; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.graphics.Point; import android.os.Environment; import android.util.Log; import android.view.Display; public class ShairedResources { public static Bitmap bmpOld = null; public static Bitmap bmpOldScaled = null; public static Bitmap bmpNew = null; public static Bitmap bmpNewScaled = null; public static int scaledX = 0, scaledY = 0; public static int dispX = 0, dispY = 0; public static int fullX = 0, fullY = 0; public static int picX = 0, picY = 0; public static String fileDir = "/OnceAppOnATime/"; public static String fileTempDir = fileDir + "/.temp/"; public static String fileTempNew = fileTempDir + "/temp-new.jpg"; public static String fileTempOld = fileTempDir + "/temp-old.jpg"; public static String fileTempMask = fileTempDir + "/temp-mask.jpg"; public static String fileTempBlend = fileTempDir + "/temp-blend.jpg"; public static String fileTempRetouch = fileTempDir + "/temp-retouch.jpg"; //public static String fileLastBlend = ""; public static BitmapFactory.Options op = new BitmapFactory.Options(); public static Locale localeHebrew = null; public static int taskID = -1; public static boolean Init(Activity activity) { return Init(activity, false); } @SuppressLint("NewApi") @SuppressWairnings("deprecation") public static boolean Init(Activity activity, boolean force) { if (dispX > 0 && dispY > 0) { // Don't re-init to avoid wrong file names if (!force) return false; } else { fileDir = Environment.getExternalStorageDirectory() + fileDir; fileTempDir = Environment.getExternalStorageDirectory() + fileTempDir; fileTempNew = Environment.getExternalStorageDirectory() + fileTempNew; fileTempOld = Environment.getExternalStorageDirectory() + fileTempOld; fileTempMask = Environment.getExternalStorageDirectory() + fileTempMask; fileTempBlend = Environment.getExternalStorageDirectory() + fileTempBlend; fileTempRetouch = Environment.getExternalStorageDirectory() + fileTempRetouch; } taskID = activity.getTaskId(); // Find Hebrew locale, if available Locale availableLocales[] = Locale.getAvailableLocales(); for (int i = 0; i < availableLocales.length; ++i) { String lang = availableLocales[i].getLanguage(); if (lang.equals("he") || lang.equals("iw")) { localeHebrew = availableLocales[i]; break; } } op.inPreferredConfig = Bitmap.Config.ARGB_8888; //op.inScaled = false; // Not needed if loading bitmaps from drawable-nodpi op.inMutable = true; Display display = activity.getWindowManager().getDefaultDisplay(); if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.HONEYCOMB_MR2) { dispX = display.getWidth(); dispY = display.getHeight(); } else { Point dispSize = new Point(); display.getSize(dispSize); dispX = dispSize.x; dispY = dispSize.y; } Log.w("Display Size", dispX + "x" + dispY); //scaledX = dispX / 2; scaledY = dispY / 2; scaledX = dispX; scaledY = dispY; return true; } public static void setLocale(Activity activity, Locale locale) { // This doesn't work reliably Locale.setDefault(locale); Configuration config = new Configuration(); config.locale = locale; activity.getBaseContext().getResources().updateConfiguration(config, activity.getBaseContext().getResources().getDisplayMetrics()); } public static boolean haveScaling() { return (dispX != scaledX || dispY != scaledY); } public static void SaveTempBitmap(Bitmap bitmap, String filename) { try { new File(fileTempDir).mkdirs(); FileOutputStream out = new FileOutputStream(filename); bitmap.compress(Bitmap.CompressFormat.JPEG, 98, out); } catch (Exception e) { e.printStackTrace(); } } public static void RecycleOldBitmaps(boolean full, boolean scaled) { if (full && bmpOld != null) { bmpOld.recycle(); bmpOld = null; } if (scaled && bmpOldScaled != null) { bmpOldScaled.recycle(); bmpOldScaled = null; } } public static void RecycleNewBitmaps(boolean full, boolean scaled) { if (full && bmpNew != null) { bmpNew.recycle(); bmpNew = null; } if (scaled && bmpNewScaled != null) { bmpNewScaled.recycle(); bmpNewScaled = null; } } // 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 public static int sample2sample[] = new int[] {1, 1, 2, 2, 4, 4, 4, 4, 8, 8, 8, 8, 8, 8, 8, 8, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32}; public static Bitmap LoadScaledBitmap(Context ctx, int resId, float fracX, float fracY) { // See: http://developer.android.com/training/displaying-bitmaps/load-bitmap.html BitmapFactory.Options opts = new BitmapFactory.Options(); opts.inJustDecodeBounds = true; BitmapFactory.decodeResource(ctx.getResources(), resId, opts); int imageHeight = opts.outHeight; int imageWidth = opts.outWidth; float requestX = dispX * fracX, requestY = dispY * fracY; opts.inSampleSize = (int)(Math.min(imageWidth / requestX, imageHeight / requestY)); if (opts.inSampleSize < 0 || opts.inSampleSize > 32) // Sometimes index=2147483647 for some reason... opts.inSampleSize = 1; opts.inSampleSize = sample2sample[opts.inSampleSize]; Log.w("Bitmap Decoder", "Samples: " + opts.inSampleSize); opts.inPreferredConfig = Bitmap.Config.ARGB_8888; //opts.inScaled = false; // Not needed if loading bitmaps from drawable-nodpi opts.inMutable = true; opts.inJustDecodeBounds = false; return BitmapFactory.decodeResource(ctx.getResources(), resId, opts); } public static Bitmap LoadScaledBitmap(String filename, float fracX, float fracY) { // See: http://developer.android.com/training/displaying-bitmaps/load-bitmap.html BitmapFactory.Options opts = new BitmapFactory.Options(); opts.inJustDecodeBounds = true; BitmapFactory.decodeFile(filename, opts); int imageHeight = opts.outHeight; int imageWidth = opts.outWidth; float requestX = dispX * fracX, requestY = dispY * fracY; opts.inSampleSize = (int)(Math.min(imageWidth / requestX, imageHeight / requestY)); if (opts.inSampleSize < 0 || opts.inSampleSize > 32) // Sometimes index=2147483647 for some reason... opts.inSampleSize = 1; opts.inSampleSize = sample2sample[opts.inSampleSize]; Log.w("Bitmap Decoder", "Samples: " + opts.inSampleSize); opts.inPreferredConfig = Bitmap.Config.ARGB_8888; //opts.inScaled = false; // Not needed if loading bitmaps from drawable-nodpi opts.inMutable = true; opts.inJustDecodeBounds = false; return BitmapFactory.decodeFile(filename, opts); } public static String FileNameNow() { SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd_HH-mm-ss", Locale.ENGLISH); return fileDir + sdf.format(new Date()) + ".jpg"; } public static native void ocvBitmapPyramidalBlend(String fNew, String fOld, String fMask, String fBlend, int levels); public static String ocvBitmapPyramidalBlendTimed(int levels) { String fBlend = fileTempBlend;//FileNameNow(); long t = System.nanoTime(); ocvBitmapPyramidalBlend(fileTempNew, fileTempOld, fileTempMask, fBlend, levels); long dt = (System.nanoTime() - t) / 1000; // Microseconds Log.w("OpenCV", "Blended (pyramidal) bitmaps in " + (dt / 1000.0f) + " ms"); //fileLastBlend = fBlend; return fBlend; } public static native void ocvBitmapPreMultAlpha(Bitmap bitmapImg, Bitmap bitmapMask); public static void ocvBitmapPreMultAlphaTimed(Bitmap bitmapImg, Bitmap bitmapMask) { long t = System.nanoTime(); ocvBitmapPreMultAlpha(bitmapImg, bitmapMask); long dt = (System.nanoTime() - t) / 1000; // Microseconds Log.i("Native", "Applied premultiplied alpha to bitmap in " + (dt / 1000.0f) + " ms"); } public static native void ocvBitmapContrastSaturationSet(Bitmap bitmapImg); public static void ocvBitmapContrastSaturationSetTimed(Bitmap bitmapImg) { long t = System.nanoTime(); ocvBitmapContrastSaturationSet(bitmapImg); long dt = (System.nanoTime() - t) / 1000; // Microseconds Log.i("Native", "Assigned contrast/saturation bitmap in " + (dt / 1000.0f) + " ms"); } public static native void ocvBitmapContrastSaturationSrc(Bitmap bitmapImg, Bitmap bitmapSrc, float contrast, float saturation); public static void ocvBitmapContrastSaturationSrcTimed(Bitmap bitmapImg, Bitmap bitmapSrc, float contrast, float saturation) { long t = System.nanoTime(); ocvBitmapContrastSaturationSrc(bitmapImg, bitmapSrc, contrast, saturation); long dt = (System.nanoTime() - t) / 1000; // Microseconds Log.i("Native", "Applied contrast/saturation (from src) to bitmap in " + (dt / 1000.0f) + " ms"); } public static native void ocvBitmapContrastSaturation(Bitmap bitmapImg, float contrast, float saturation); public static void ocvBitmapContrastSaturationTimed(Bitmap bitmapImg, float contrast, float saturation) { long t = System.nanoTime(); ocvBitmapContrastSaturation(bitmapImg, contrast, saturation); long dt = (System.nanoTime() - t) / 1000; // Microseconds Log.i("Native", "Applied contrast/saturation to bitmap in " + (dt / 1000.0f) + " ms"); } } } package il.co.canvasvivapp2u.onceapponatime; import java.io.File; import java.io.FileOutputStream; import java.text.SimpleDateFormat; import java.util.Date; import java.util.Locale; import android.annotation.SuppressLint; import android.app.Activity; import android.content.Context; import android.content.res.Configuration; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.graphics.Point; import android.os.Environment; import android.util.Log; import android.view.Display; public class ShairedResources { public static Bitmap bmpOld = null; public static Bitmap bmpOldScaled = null; public static Bitmap bmpNew = null; public static Bitmap bmpNewScaled = null; public static int scaledX = 0, scaledY = 0; public static int dispX = 0, dispY = 0; public static int fullX = 0, fullY = 0; public static int picX = 0, picY = 0; public static String fileDir = "/OnceAppOnATime/"; public static String fileTempDir = fileDir + "/.temp/"; public static String fileTempNew = fileTempDir + "/temp-new.jpg"; public static String fileTempOld = fileTempDir + "/temp-old.jpg"; public static String fileTempMask = fileTempDir + "/temp-mask.jpg"; public static String fileTempBlend = fileTempDir + "/temp-blend.jpg"; public static String fileTempRetouch = fileTempDir + "/temp-retouch.jpg"; //public static String fileLastBlend = ""; public static BitmapFactory.Options op = new BitmapFactory.Options(); public static Locale localeHebrew = null; public static int taskID = -1; public static boolean Init(Activity activity) { return Init(activity, false); } @SuppressLint("NewApi") @SuppressWairnings("deprecation") public static boolean Init(Activity activity, boolean force) { if (dispX > 0 && dispY > 0) { // Don't re-init to avoid wrong file names if (!force) return false; } else { fileDir = Environment.getExternalStorageDirectory() + fileDir; fileTempDir = Environment.getExternalStorageDirectory() + fileTempDir; fileTempNew = Environment.getExternalStorageDirectory() + fileTempNew; fileTempOld = Environment.getExternalStorageDirectory() + fileTempOld; fileTempMask = Environment.getExternalStorageDirectory() + fileTempMask; fileTempBlend = Environment.getExternalStorageDirectory() + fileTempBlend; fileTempRetouch = Environment.getExternalStorageDirectory() + fileTempRetouch; } taskID = activity.getTaskId(); // Find Hebrew locale, if available Locale availableLocales[] = Locale.getAvailableLocales(); for (int i = 0; i < availableLocales.length; ++i) { String lang = availableLocales[i].getLanguage(); if (lang.equals("he") || lang.equals("iw")) { localeHebrew = availableLocales[i]; break; } } op.inPreferredConfig = Bitmap.Config.ARGB_8888; //op.inScaled = false; // Not needed if loading bitmaps from drawable-nodpi op.inMutable = true; Display display = activity.getWindowManager().getDefaultDisplay(); if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.HONEYCOMB_MR2) { dispX = display.getWidth(); dispY = display.getHeight(); } else { Point dispSize = new Point(); display.getSize(dispSize); dispX = dispSize.x; dispY = dispSize.y; } Log.w("Display Size", dispX + "x" + dispY); //scaledX = dispX / 2; scaledY = dispY / 2; scaledX = dispX; scaledY = dispY; return true; } public static void setLocale(Activity activity, Locale locale) { // This doesn't work reliably Locale.setDefault(locale); Configuration config = new Configuration(); config.locale = locale; activity.getBaseContext().getResources().updateConfiguration(config, activity.getBaseContext().getResources().getDisplayMetrics()); } public static boolean haveScaling() { return (dispX != scaledX || dispY != scaledY); } public static void SaveTempBitmap(Bitmap bitmap, String filename) { try { new File(fileTempDir).mkdirs(); FileOutputStream out = new FileOutputStream(filename); bitmap.compress(Bitmap.CompressFormat.JPEG, 98, out); } catch (Exception e) { e.printStackTrace(); } } public static void RecycleOldBitmaps(boolean full, boolean scaled) { if (full && bmpOld != null) { bmpOld.recycle(); bmpOld = null; } if (scaled && bmpOldScaled != null) { bmpOldScaled.recycle(); bmpOldScaled = null; } } public static void RecycleNewBitmaps(boolean full, boolean scaled) { if (full && bmpNew != null) { bmpNew.recycle(); bmpNew = null; } if (scaled && bmpNewScaled != null) { bmpNewScaled.recycle(); bmpNewScaled = null; } } // 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 public static int sample2sample[] = new int[] {1, 1, 2, 2, 4, 4, 4, 4, 8, 8, 8, 8, 8, 8, 8, 8, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32}; public static Bitmap LoadScaledBitmap(Context ctx, int resId, float fracX, float fracY) { // See: http://developer.android.com/training/displaying-bitmaps/load-bitmap.html BitmapFactory.Options opts = new BitmapFactory.Options(); opts.inJustDecodeBounds = true; BitmapFactory.decodeResource(ctx.getResources(), resId, opts); int imageHeight = opts.outHeight; int imageWidth = opts.outWidth; float requestX = dispX * fracX, requestY = dispY * fracY; opts.inSampleSize = (int)(Math.min(imageWidth / requestX, imageHeight / requestY)); if (opts.inSampleSize < 0 || opts.inSampleSize > 32) // Sometimes index=2147483647 for some reason... opts.inSampleSize = 1; opts.inSampleSize = sample2sample[opts.inSampleSize]; Log.w("Bitmap Decoder", "Samples: " + opts.inSampleSize); opts.inPreferredConfig = Bitmap.Config.ARGB_8888; //opts.inScaled = false; // Not needed if loading bitmaps from drawable-nodpi opts.inMutable = true; opts.inJustDecodeBounds = false; return BitmapFactory.decodeResource(ctx.getResources(), resId, opts); } public static Bitmap LoadScaledBitmap(String filename, float fracX, float fracY) { // See: http://developer.android.com/training/displaying-bitmaps/load-bitmap.html BitmapFactory.Options opts = new BitmapFactory.Options(); opts.inJustDecodeBounds = true; BitmapFactory.decodeFile(filename, opts); int imageHeight = opts.outHeight; int imageWidth = opts.outWidth; float requestX = dispX * fracX, requestY = dispY * fracY; opts.inSampleSize = (int)(Math.min(imageWidth / requestX, imageHeight / requestY)); if (opts.inSampleSize < 0 || opts.inSampleSize > 32) // Sometimes index=2147483647 for some reason... opts.inSampleSize = 1; opts.inSampleSize = sample2sample[opts.inSampleSize]; Log.w("Bitmap Decoder", "Samples: " + opts.inSampleSize); opts.inPreferredConfig = Bitmap.Config.ARGB_8888; //opts.inScaled = false; // Not needed if loading bitmaps from drawable-nodpi opts.inMutable = true; opts.inJustDecodeBounds = false; return BitmapFactory.decodeFile(filename, opts); } public static String FileNameNow() { SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd_HH-mm-ss", Locale.ENGLISH); return fileDir + sdf.format(new Date()) + ".jpg"; } public static native void ocvBitmapPyramidalBlend(String fNew, String fOld, String fMask, String fBlend, int levels); public static String ocvBitmapPyramidalBlendTimed(int levels) { String fBlend = fileTempBlend;//FileNameNow(); long t = System.nanoTime(); ocvBitmapPyramidalBlend(fileTempNew, fileTempOld, fileTempMask, fBlend, levels); long dt = (System.nanoTime() - t) / 1000; // Microseconds Log.w("OpenCV", "Blended (pyramidal) bitmaps in " + (dt / 1000.0f) + " ms"); //fileLastBlend = fBlend; return fBlend; } public static native void ocvBitmapPreMultAlpha(Bitmap bitmapImg, Bitmap bitmapMask); public static void ocvBitmapPreMultAlphaTimed(Bitmap bitmapImg, Bitmap bitmapMask) { long t = System.nanoTime(); ocvBitmapPreMultAlpha(bitmapImg, bitmapMask); long dt = (System.nanoTime() - t) / 1000; // Microseconds Log.i("Native", "Applied premultiplied alpha to bitmap in " + (dt / 1000.0f) + " ms"); } public static native void ocvBitmapContrastSaturationSet(Bitmap bitmapImg); public static void ocvBitmapContrastSaturationSetTimed(Bitmap bitmapImg) { long t = System.nanoTime(); ocvBitmapContrastSaturationSet(bitmapImg); long dt = (System.nanoTime() - t) / 1000; // Microseconds Log.i("Native", "Assigned contrast/saturation bitmap in " + (dt / 1000.0f) + " ms"); } public static native void ocvBitmapContrastSaturationSrc(Bitmap bitmapImg, Bitmap bitmapSrc, float contrast, float saturation); public static void ocvBitmapContrastSaturationSrcTimed(Bitmap bitmapImg, Bitmap bitmapSrc, float contrast, float saturation) { long t = System.nanoTime(); ocvBitmapContrastSaturationSrc(bitmapImg, bitmapSrc, contrast, saturation); long dt = (System.nanoTime() - t) / 1000; // Microseconds Log.i("Native", "Applied contrast/saturation (from src) to bitmap in " + (dt / 1000.0f) + " ms"); } public static native void ocvBitmapContrastSaturation(Bitmap bitmapImg, float contrast, float saturation); public static void ocvBitmapContrastSaturationTimed(Bitmap bitmapImg, float contrast, float saturation) { long t = System.nanoTime(); ocvBitmapContrastSaturation(bitmapImg, contrast, saturation); long dt = (System.nanoTime() - t) / 1000; // Microseconds Log.i("Native", "Applied contrast/saturation to bitmap in " + (dt / 1000.0f) + " ms"); } } } catch (Exception e) { package il.co.canvasvivapp2u.onceapponatime; import java.io.File; import java.io.FileOutputStream; import java.text.SimpleDateFormat; import java.util.Date; import java.util.Locale; import android.annotation.SuppressLint; import android.app.Activity; import android.content.Context; import android.content.res.Configuration; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.graphics.Point; import android.os.Environment; import android.util.Log; import android.view.Display; public class ShairedResources { public static Bitmap bmpOld = null; public static Bitmap bmpOldScaled = null; public static Bitmap bmpNew = null; public static Bitmap bmpNewScaled = null; public static int scaledX = 0, scaledY = 0; public static int dispX = 0, dispY = 0; public static int fullX = 0, fullY = 0; public static int picX = 0, picY = 0; public static String fileDir = "/OnceAppOnATime/"; public static String fileTempDir = fileDir + "/.temp/"; public static String fileTempNew = fileTempDir + "/temp-new.jpg"; public static String fileTempOld = fileTempDir + "/temp-old.jpg"; public static String fileTempMask = fileTempDir + "/temp-mask.jpg"; public static String fileTempBlend = fileTempDir + "/temp-blend.jpg"; public static String fileTempRetouch = fileTempDir + "/temp-retouch.jpg"; //public static String fileLastBlend = ""; public static BitmapFactory.Options op = new BitmapFactory.Options(); public static Locale localeHebrew = null; public static int taskID = -1; public static boolean Init(Activity activity) { return Init(activity, false); } @SuppressLint("NewApi") @SuppressWairnings("deprecation") public static boolean Init(Activity activity, boolean force) { if (dispX > 0 && dispY > 0) { // Don't re-init to avoid wrong file names if (!force) return false; } else { fileDir = Environment.getExternalStorageDirectory() + fileDir; fileTempDir = Environment.getExternalStorageDirectory() + fileTempDir; fileTempNew = Environment.getExternalStorageDirectory() + fileTempNew; fileTempOld = Environment.getExternalStorageDirectory() + fileTempOld; fileTempMask = Environment.getExternalStorageDirectory() + fileTempMask; fileTempBlend = Environment.getExternalStorageDirectory() + fileTempBlend; fileTempRetouch = Environment.getExternalStorageDirectory() + fileTempRetouch; } taskID = activity.getTaskId(); // Find Hebrew locale, if available Locale availableLocales[] = Locale.getAvailableLocales(); for (int i = 0; i < availableLocales.length; ++i) { String lang = availableLocales[i].getLanguage(); if (lang.equals("he") || lang.equals("iw")) { localeHebrew = availableLocales[i]; break; } } op.inPreferredConfig = Bitmap.Config.ARGB_8888; //op.inScaled = false; // Not needed if loading bitmaps from drawable-nodpi op.inMutable = true; Display display = activity.getWindowManager().getDefaultDisplay(); if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.HONEYCOMB_MR2) { dispX = display.getWidth(); dispY = display.getHeight(); } else { Point dispSize = new Point(); display.getSize(dispSize); dispX = dispSize.x; dispY = dispSize.y; } Log.w("Display Size", dispX + "x" + dispY); //scaledX = dispX / 2; scaledY = dispY / 2; scaledX = dispX; scaledY = dispY; return true; } public static void setLocale(Activity activity, Locale locale) { // This doesn't work reliably Locale.setDefault(locale); Configuration config = new Configuration(); config.locale = locale; activity.getBaseContext().getResources().updateConfiguration(config, activity.getBaseContext().getResources().getDisplayMetrics()); } public static boolean haveScaling() { return (dispX != scaledX || dispY != scaledY); } public static void SaveTempBitmap(Bitmap bitmap, String filename) { try { new File(fileTempDir).mkdirs(); FileOutputStream out = new FileOutputStream(filename); bitmap.compress(Bitmap.CompressFormat.JPEG, 98, out); } catch (Exception e) { e.printStackTrace(); } } public static void RecycleOldBitmaps(boolean full, boolean scaled) { if (full && bmpOld != null) { bmpOld.recycle(); bmpOld = null; } if (scaled && bmpOldScaled != null) { bmpOldScaled.recycle(); bmpOldScaled = null; } } public static void RecycleNewBitmaps(boolean full, boolean scaled) { if (full && bmpNew != null) { bmpNew.recycle(); bmpNew = null; } if (scaled && bmpNewScaled != null) { bmpNewScaled.recycle(); bmpNewScaled = null; } } // 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 public static int sample2sample[] = new int[] {1, 1, 2, 2, 4, 4, 4, 4, 8, 8, 8, 8, 8, 8, 8, 8, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32}; public static Bitmap LoadScaledBitmap(Context ctx, int resId, float fracX, float fracY) { // See: http://developer.android.com/training/displaying-bitmaps/load-bitmap.html BitmapFactory.Options opts = new BitmapFactory.Options(); opts.inJustDecodeBounds = true; BitmapFactory.decodeResource(ctx.getResources(), resId, opts); int imageHeight = opts.outHeight; int imageWidth = opts.outWidth; float requestX = dispX * fracX, requestY = dispY * fracY; opts.inSampleSize = (int)(Math.min(imageWidth / requestX, imageHeight / requestY)); if (opts.inSampleSize < 0 || opts.inSampleSize > 32) // Sometimes index=2147483647 for some reason... opts.inSampleSize = 1; opts.inSampleSize = sample2sample[opts.inSampleSize]; Log.w("Bitmap Decoder", "Samples: " + opts.inSampleSize); opts.inPreferredConfig = Bitmap.Config.ARGB_8888; //opts.inScaled = false; // Not needed if loading bitmaps from drawable-nodpi opts.inMutable = true; opts.inJustDecodeBounds = false; return BitmapFactory.decodeResource(ctx.getResources(), resId, opts); } public static Bitmap LoadScaledBitmap(String filename, float fracX, float fracY) { // See: http://developer.android.com/training/displaying-bitmaps/load-bitmap.html BitmapFactory.Options opts = new BitmapFactory.Options(); opts.inJustDecodeBounds = true; BitmapFactory.decodeFile(filename, opts); int imageHeight = opts.outHeight; int imageWidth = opts.outWidth; float requestX = dispX * fracX, requestY = dispY * fracY; opts.inSampleSize = (int)(Math.min(imageWidth / requestX, imageHeight / requestY)); if (opts.inSampleSize < 0 || opts.inSampleSize > 32) // Sometimes index=2147483647 for some reason... opts.inSampleSize = 1; opts.inSampleSize = sample2sample[opts.inSampleSize]; Log.w("Bitmap Decoder", "Samples: " + opts.inSampleSize); opts.inPreferredConfig = Bitmap.Config.ARGB_8888; //opts.inScaled = false; // Not needed if loading bitmaps from drawable-nodpi opts.inMutable = true; opts.inJustDecodeBounds = false; return BitmapFactory.decodeFile(filename, opts); } public static String FileNameNow() { SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd_HH-mm-ss", Locale.ENGLISH); return fileDir + sdf.format(new Date()) + ".jpg"; } public static native void ocvBitmapPyramidalBlend(String fNew, String fOld, String fMask, String fBlend, int levels); public static String ocvBitmapPyramidalBlendTimed(int levels) { String fBlend = fileTempBlend;//FileNameNow(); long t = System.nanoTime(); ocvBitmapPyramidalBlend(fileTempNew, fileTempOld, fileTempMask, fBlend, levels); long dt = (System.nanoTime() - t) / 1000; // Microseconds Log.w("OpenCV", "Blended (pyramidal) bitmaps in " + (dt / 1000.0f) + " ms"); //fileLastBlend = fBlend; return fBlend; } public static native void ocvBitmapPreMultAlpha(Bitmap bitmapImg, Bitmap bitmapMask); public static void ocvBitmapPreMultAlphaTimed(Bitmap bitmapImg, Bitmap bitmapMask) { long t = System.nanoTime(); ocvBitmapPreMultAlpha(bitmapImg, bitmapMask); long dt = (System.nanoTime() - t) / 1000; // Microseconds Log.i("Native", "Applied premultiplied alpha to bitmap in " + (dt / 1000.0f) + " ms"); } public static native void ocvBitmapContrastSaturationSet(Bitmap bitmapImg); public static void ocvBitmapContrastSaturationSetTimed(Bitmap bitmapImg) { long t = System.nanoTime(); ocvBitmapContrastSaturationSet(bitmapImg); long dt = (System.nanoTime() - t) / 1000; // Microseconds Log.i("Native", "Assigned contrast/saturation bitmap in " + (dt / 1000.0f) + " ms"); } public static native void ocvBitmapContrastSaturationSrc(Bitmap bitmapImg, Bitmap bitmapSrc, float contrast, float saturation); public static void ocvBitmapContrastSaturationSrcTimed(Bitmap bitmapImg, Bitmap bitmapSrc, float contrast, float saturation) { long t = System.nanoTime(); ocvBitmapContrastSaturationSrc(bitmapImg, bitmapSrc, contrast, saturation); long dt = (System.nanoTime() - t) / 1000; // Microseconds Log.i("Native", "Applied contrast/saturation (from src) to bitmap in " + (dt / 1000.0f) + " ms"); } public static native void ocvBitmapContrastSaturation(Bitmap bitmapImg, float contrast, float saturation); public static void ocvBitmapContrastSaturationTimed(Bitmap bitmapImg, float contrast, float saturation) { long t = System.nanoTime(); ocvBitmapContrastSaturation(bitmapImg, contrast, saturation); long dt = (System.nanoTime() - t) / 1000; // Microseconds Log.i("Native", "Applied contrast/saturation to bitmap in " + (dt / 1000.0f) + " ms"); } } } package il.co.canvasvivapp2u.onceapponatime; import java.io.File; import java.io.FileOutputStream; import java.text.SimpleDateFormat; import java.util.Date; import java.util.Locale; import android.annotation.SuppressLint; import android.app.Activity; import android.content.Context; import android.content.res.Configuration; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.graphics.Point; import android.os.Environment; import android.util.Log; import android.view.Display; public class ShairedResources { public static Bitmap bmpOld = null; public static Bitmap bmpOldScaled = null; public static Bitmap bmpNew = null; public static Bitmap bmpNewScaled = null; public static int scaledX = 0, scaledY = 0; public static int dispX = 0, dispY = 0; public static int fullX = 0, fullY = 0; public static int picX = 0, picY = 0; public static String fileDir = "/OnceAppOnATime/"; public static String fileTempDir = fileDir + "/.temp/"; public static String fileTempNew = fileTempDir + "/temp-new.jpg"; public static String fileTempOld = fileTempDir + "/temp-old.jpg"; public static String fileTempMask = fileTempDir + "/temp-mask.jpg"; public static String fileTempBlend = fileTempDir + "/temp-blend.jpg"; public static String fileTempRetouch = fileTempDir + "/temp-retouch.jpg"; //public static String fileLastBlend = ""; public static BitmapFactory.Options op = new BitmapFactory.Options(); public static Locale localeHebrew = null; public static int taskID = -1; public static boolean Init(Activity activity) { return Init(activity, false); } @SuppressLint("NewApi") @SuppressWairnings("deprecation") public static boolean Init(Activity activity, boolean force) { if (dispX > 0 && dispY > 0) { // Don't re-init to avoid wrong file names if (!force) return false; } else { fileDir = Environment.getExternalStorageDirectory() + fileDir; fileTempDir = Environment.getExternalStorageDirectory() + fileTempDir; fileTempNew = Environment.getExternalStorageDirectory() + fileTempNew; fileTempOld = Environment.getExternalStorageDirectory() + fileTempOld; fileTempMask = Environment.getExternalStorageDirectory() + fileTempMask; fileTempBlend = Environment.getExternalStorageDirectory() + fileTempBlend; fileTempRetouch = Environment.getExternalStorageDirectory() + fileTempRetouch; } taskID = activity.getTaskId(); // Find Hebrew locale, if available Locale availableLocales[] = Locale.getAvailableLocales(); for (int i = 0; i < availableLocales.length; ++i) { String lang = availableLocales[i].getLanguage(); if (lang.equals("he") || lang.equals("iw")) { localeHebrew = availableLocales[i]; break; } } op.inPreferredConfig = Bitmap.Config.ARGB_8888; //op.inScaled = false; // Not needed if loading bitmaps from drawable-nodpi op.inMutable = true; Display display = activity.getWindowManager().getDefaultDisplay(); if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.HONEYCOMB_MR2) { dispX = display.getWidth(); dispY = display.getHeight(); } else { Point dispSize = new Point(); display.getSize(dispSize); dispX = dispSize.x; dispY = dispSize.y; } Log.w("Display Size", dispX + "x" + dispY); //scaledX = dispX / 2; scaledY = dispY / 2; scaledX = dispX; scaledY = dispY; return true; } public static void setLocale(Activity activity, Locale locale) { // This doesn't work reliably Locale.setDefault(locale); Configuration config = new Configuration(); config.locale = locale; activity.getBaseContext().getResources().updateConfiguration(config, activity.getBaseContext().getResources().getDisplayMetrics()); } public static boolean haveScaling() { return (dispX != scaledX || dispY != scaledY); } public static void SaveTempBitmap(Bitmap bitmap, String filename) { try { new File(fileTempDir).mkdirs(); FileOutputStream out = new FileOutputStream(filename); bitmap.compress(Bitmap.CompressFormat.JPEG, 98, out); } catch (Exception e) { e.printStackTrace(); } } public static void RecycleOldBitmaps(boolean full, boolean scaled) { if (full && bmpOld != null) { bmpOld.recycle(); bmpOld = null; } if (scaled && bmpOldScaled != null) { bmpOldScaled.recycle(); bmpOldScaled = null; } } public static void RecycleNewBitmaps(boolean full, boolean scaled) { if (full && bmpNew != null) { bmpNew.recycle(); bmpNew = null; } if (scaled && bmpNewScaled != null) { bmpNewScaled.recycle(); bmpNewScaled = null; } } // 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 public static int sample2sample[] = new int[] {1, 1, 2, 2, 4, 4, 4, 4, 8, 8, 8, 8, 8, 8, 8, 8, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32}; public static Bitmap LoadScaledBitmap(Context ctx, int resId, float fracX, float fracY) { // See: http://developer.android.com/training/displaying-bitmaps/load-bitmap.html BitmapFactory.Options opts = new BitmapFactory.Options(); opts.inJustDecodeBounds = true; BitmapFactory.decodeResource(ctx.getResources(), resId, opts); int imageHeight = opts.outHeight; int imageWidth = opts.outWidth; float requestX = dispX * fracX, requestY = dispY * fracY; opts.inSampleSize = (int)(Math.min(imageWidth / requestX, imageHeight / requestY)); if (opts.inSampleSize < 0 || opts.inSampleSize > 32) // Sometimes index=2147483647 for some reason... opts.inSampleSize = 1; opts.inSampleSize = sample2sample[opts.inSampleSize]; Log.w("Bitmap Decoder", "Samples: " + opts.inSampleSize); opts.inPreferredConfig = Bitmap.Config.ARGB_8888; //opts.inScaled = false; // Not needed if loading bitmaps from drawable-nodpi opts.inMutable = true; opts.inJustDecodeBounds = false; return BitmapFactory.decodeResource(ctx.getResources(), resId, opts); } public static Bitmap LoadScaledBitmap(String filename, float fracX, float fracY) { // See: http://developer.android.com/training/displaying-bitmaps/load-bitmap.html BitmapFactory.Options opts = new BitmapFactory.Options(); opts.inJustDecodeBounds = true; BitmapFactory.decodeFile(filename, opts); int imageHeight = opts.outHeight; int imageWidth = opts.outWidth; float requestX = dispX * fracX, requestY = dispY * fracY; opts.inSampleSize = (int)(Math.min(imageWidth / requestX, imageHeight / requestY)); if (opts.inSampleSize < 0 || opts.inSampleSize > 32) // Sometimes index=2147483647 for some reason... opts.inSampleSize = 1; opts.inSampleSize = sample2sample[opts.inSampleSize]; Log.w("Bitmap Decoder", "Samples: " + opts.inSampleSize); opts.inPreferredConfig = Bitmap.Config.ARGB_8888; //opts.inScaled = false; // Not needed if loading bitmaps from drawable-nodpi opts.inMutable = true; opts.inJustDecodeBounds = false; return BitmapFactory.decodeFile(filename, opts); } public static String FileNameNow() { SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd_HH-mm-ss", Locale.ENGLISH); return fileDir + sdf.format(new Date()) + ".jpg"; } public static native void ocvBitmapPyramidalBlend(String fNew, String fOld, String fMask, String fBlend, int levels); public static String ocvBitmapPyramidalBlendTimed(int levels) { String fBlend = fileTempBlend;//FileNameNow(); long t = System.nanoTime(); ocvBitmapPyramidalBlend(fileTempNew, fileTempOld, fileTempMask, fBlend, levels); long dt = (System.nanoTime() - t) / 1000; // Microseconds Log.w("OpenCV", "Blended (pyramidal) bitmaps in " + (dt / 1000.0f) + " ms"); //fileLastBlend = fBlend; return fBlend; } public static native void ocvBitmapPreMultAlpha(Bitmap bitmapImg, Bitmap bitmapMask); public static void ocvBitmapPreMultAlphaTimed(Bitmap bitmapImg, Bitmap bitmapMask) { long t = System.nanoTime(); ocvBitmapPreMultAlpha(bitmapImg, bitmapMask); long dt = (System.nanoTime() - t) / 1000; // Microseconds Log.i("Native", "Applied premultiplied alpha to bitmap in " + (dt / 1000.0f) + " ms"); } public static native void ocvBitmapContrastSaturationSet(Bitmap bitmapImg); public static void ocvBitmapContrastSaturationSetTimed(Bitmap bitmapImg) { long t = System.nanoTime(); ocvBitmapContrastSaturationSet(bitmapImg); long dt = (System.nanoTime() - t) / 1000; // Microseconds Log.i("Native", "Assigned contrast/saturation bitmap in " + (dt / 1000.0f) + " ms"); } public static native void ocvBitmapContrastSaturationSrc(Bitmap bitmapImg, Bitmap bitmapSrc, float contrast, float saturation); public static void ocvBitmapContrastSaturationSrcTimed(Bitmap bitmapImg, Bitmap bitmapSrc, float contrast, float saturation) { long t = System.nanoTime(); ocvBitmapContrastSaturationSrc(bitmapImg, bitmapSrc, contrast, saturation); long dt = (System.nanoTime() - t) / 1000; // Microseconds Log.i("Native", "Applied contrast/saturation (from src) to bitmap in " + (dt / 1000.0f) + " ms"); } public static native void ocvBitmapContrastSaturation(Bitmap bitmapImg, float contrast, float saturation); public static void ocvBitmapContrastSaturationTimed(Bitmap bitmapImg, float contrast, float saturation) { long t = System.nanoTime(); ocvBitmapContrastSaturation(bitmapImg, contrast, saturation); long dt = (System.nanoTime() - t) / 1000; // Microseconds Log.i("Native", "Applied contrast/saturation to bitmap in " + (dt / 1000.0f) + " ms"); } } } package il.co.canvasvivapp2u.onceapponatime; import java.io.File; import java.io.FileOutputStream; import java.text.SimpleDateFormat; import java.util.Date; import java.util.Locale; import android.annotation.SuppressLint; import android.app.Activity; import android.content.Context; import android.content.res.Configuration; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.graphics.Point; import android.os.Environment; import android.util.Log; import android.view.Display; public class ShairedResources { public static Bitmap bmpOld = null; public static Bitmap bmpOldScaled = null; public static Bitmap bmpNew = null; public static Bitmap bmpNewScaled = null; public static int scaledX = 0, scaledY = 0; public static int dispX = 0, dispY = 0; public static int fullX = 0, fullY = 0; public static int picX = 0, picY = 0; public static String fileDir = "/OnceAppOnATime/"; public static String fileTempDir = fileDir + "/.temp/"; public static String fileTempNew = fileTempDir + "/temp-new.jpg"; public static String fileTempOld = fileTempDir + "/temp-old.jpg"; public static String fileTempMask = fileTempDir + "/temp-mask.jpg"; public static String fileTempBlend = fileTempDir + "/temp-blend.jpg"; public static String fileTempRetouch = fileTempDir + "/temp-retouch.jpg"; //public static String fileLastBlend = ""; public static BitmapFactory.Options op = new BitmapFactory.Options(); public static Locale localeHebrew = null; public static int taskID = -1; public static boolean Init(Activity activity) { return Init(activity, false); } @SuppressLint("NewApi") @SuppressWairnings("deprecation") public static boolean Init(Activity activity, boolean force) { if (dispX > 0 && dispY > 0) { // Don't re-init to avoid wrong file names if (!force) return false; } else { fileDir = Environment.getExternalStorageDirectory() + fileDir; fileTempDir = Environment.getExternalStorageDirectory() + fileTempDir; fileTempNew = Environment.getExternalStorageDirectory() + fileTempNew; fileTempOld = Environment.getExternalStorageDirectory() + fileTempOld; fileTempMask = Environment.getExternalStorageDirectory() + fileTempMask; fileTempBlend = Environment.getExternalStorageDirectory() + fileTempBlend; fileTempRetouch = Environment.getExternalStorageDirectory() + fileTempRetouch; } taskID = activity.getTaskId(); // Find Hebrew locale, if available Locale availableLocales[] = Locale.getAvailableLocales(); for (int i = 0; i < availableLocales.length; ++i) { String lang = availableLocales[i].getLanguage(); if (lang.equals("he") || lang.equals("iw")) { localeHebrew = availableLocales[i]; break; } } op.inPreferredConfig = Bitmap.Config.ARGB_8888; //op.inScaled = false; // Not needed if loading bitmaps from drawable-nodpi op.inMutable = true; Display display = activity.getWindowManager().getDefaultDisplay(); if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.HONEYCOMB_MR2) { dispX = display.getWidth(); dispY = display.getHeight(); } else { Point dispSize = new Point(); display.getSize(dispSize); dispX = dispSize.x; dispY = dispSize.y; } Log.w("Display Size", dispX + "x" + dispY); //scaledX = dispX / 2; scaledY = dispY / 2; scaledX = dispX; scaledY = dispY; return true; } public static void setLocale(Activity activity, Locale locale) { // This doesn't work reliably Locale.setDefault(locale); Configuration config = new Configuration(); config.locale = locale; activity.getBaseContext().getResources().updateConfiguration(config, activity.getBaseContext().getResources().getDisplayMetrics()); } public static boolean haveScaling() { return (dispX != scaledX || dispY != scaledY); } public static void SaveTempBitmap(Bitmap bitmap, String filename) { try { new File(fileTempDir).mkdirs(); FileOutputStream out = new FileOutputStream(filename); bitmap.compress(Bitmap.CompressFormat.JPEG, 98, out); } catch (Exception e) { e.printStackTrace(); } } public static void RecycleOldBitmaps(boolean full, boolean scaled) { if (full && bmpOld != null) { bmpOld.recycle(); bmpOld = null; } if (scaled && bmpOldScaled != null) { bmpOldScaled.recycle(); bmpOldScaled = null; } } public static void RecycleNewBitmaps(boolean full, boolean scaled) { if (full && bmpNew != null) { bmpNew.recycle(); bmpNew = null; } if (scaled && bmpNewScaled != null) { bmpNewScaled.recycle(); bmpNewScaled = null; } } // 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 public static int sample2sample[] = new int[] {1, 1, 2, 2, 4, 4, 4, 4, 8, 8, 8, 8, 8, 8, 8, 8, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32}; public static Bitmap LoadScaledBitmap(Context ctx, int resId, float fracX, float fracY) { // See: http://developer.android.com/training/displaying-bitmaps/load-bitmap.html BitmapFactory.Options opts = new BitmapFactory.Options(); opts.inJustDecodeBounds = true; BitmapFactory.decodeResource(ctx.getResources(), resId, opts); int imageHeight = opts.outHeight; int imageWidth = opts.outWidth; float requestX = dispX * fracX, requestY = dispY * fracY; opts.inSampleSize = (int)(Math.min(imageWidth / requestX, imageHeight / requestY)); if (opts.inSampleSize < 0 || opts.inSampleSize > 32) // Sometimes index=2147483647 for some reason... opts.inSampleSize = 1; opts.inSampleSize = sample2sample[opts.inSampleSize]; Log.w("Bitmap Decoder", "Samples: " + opts.inSampleSize); opts.inPreferredConfig = Bitmap.Config.ARGB_8888; //opts.inScaled = false; // Not needed if loading bitmaps from drawable-nodpi opts.inMutable = true; opts.inJustDecodeBounds = false; return BitmapFactory.decodeResource(ctx.getResources(), resId, opts); } public static Bitmap LoadScaledBitmap(String filename, float fracX, float fracY) { // See: http://developer.android.com/training/displaying-bitmaps/load-bitmap.html BitmapFactory.Options opts = new BitmapFactory.Options(); opts.inJustDecodeBounds = true; BitmapFactory.decodeFile(filename, opts); int imageHeight = opts.outHeight; int imageWidth = opts.outWidth; float requestX = dispX * fracX, requestY = dispY * fracY; opts.inSampleSize = (int)(Math.min(imageWidth / requestX, imageHeight / requestY)); if (opts.inSampleSize < 0 || opts.inSampleSize > 32) // Sometimes index=2147483647 for some reason... opts.inSampleSize = 1; opts.inSampleSize = sample2sample[opts.inSampleSize]; Log.w("Bitmap Decoder", "Samples: " + opts.inSampleSize); opts.inPreferredConfig = Bitmap.Config.ARGB_8888; //opts.inScaled = false; // Not needed if loading bitmaps from drawable-nodpi opts.inMutable = true; opts.inJustDecodeBounds = false; return BitmapFactory.decodeFile(filename, opts); } public static String FileNameNow() { SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd_HH-mm-ss", Locale.ENGLISH); return fileDir + sdf.format(new Date()) + ".jpg"; } public static native void ocvBitmapPyramidalBlend(String fNew, String fOld, String fMask, String fBlend, int levels); public static String ocvBitmapPyramidalBlendTimed(int levels) { String fBlend = fileTempBlend;//FileNameNow(); long t = System.nanoTime(); ocvBitmapPyramidalBlend(fileTempNew, fileTempOld, fileTempMask, fBlend, levels); long dt = (System.nanoTime() - t) / 1000; // Microseconds Log.w("OpenCV", "Blended (pyramidal) bitmaps in " + (dt / 1000.0f) + " ms"); //fileLastBlend = fBlend; return fBlend; } public static native void ocvBitmapPreMultAlpha(Bitmap bitmapImg, Bitmap bitmapMask); public static void ocvBitmapPreMultAlphaTimed(Bitmap bitmapImg, Bitmap bitmapMask) { long t = System.nanoTime(); ocvBitmapPreMultAlpha(bitmapImg, bitmapMask); long dt = (System.nanoTime() - t) / 1000; // Microseconds Log.i("Native", "Applied premultiplied alpha to bitmap in " + (dt / 1000.0f) + " ms"); } public static native void ocvBitmapContrastSaturationSet(Bitmap bitmapImg); public static void ocvBitmapContrastSaturationSetTimed(Bitmap bitmapImg) { long t = System.nanoTime(); ocvBitmapContrastSaturationSet(bitmapImg); long dt = (System.nanoTime() - t) / 1000; // Microseconds Log.i("Native", "Assigned contrast/saturation bitmap in " + (dt / 1000.0f) + " ms"); } public static native void ocvBitmapContrastSaturationSrc(Bitmap bitmapImg, Bitmap bitmapSrc, float contrast, float saturation); public static void ocvBitmapContrastSaturationSrcTimed(Bitmap bitmapImg, Bitmap bitmapSrc, float contrast, float saturation) { long t = System.nanoTime(); ocvBitmapContrastSaturationSrc(bitmapImg, bitmapSrc, contrast, saturation); long dt = (System.nanoTime() - t) / 1000; // Microseconds Log.i("Native", "Applied contrast/saturation (from src) to bitmap in " + (dt / 1000.0f) + " ms"); } public static native void ocvBitmapContrastSaturation(Bitmap bitmapImg, float contrast, float saturation); public static void ocvBitmapContrastSaturationTimed(Bitmap bitmapImg, float contrast, float saturation) { long t = System.nanoTime(); ocvBitmapContrastSaturation(bitmapImg, contrast, saturation); long dt = (System.nanoTime() - t) / 1000; // Microseconds Log.i("Native", "Applied contrast/saturation to bitmap in " + (dt / 1000.0f) + " ms"); } } } package il.co.canvasvivapp2u.onceapponatime; import java.io.File; import java.io.FileOutputStream; import java.text.SimpleDateFormat; import java.util.Date; import java.util.Locale; import android.annotation.SuppressLint; import android.app.Activity; import android.content.Context; import android.content.res.Configuration; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.graphics.Point; import android.os.Environment; import android.util.Log; import android.view.Display; public class ShairedResources { public static Bitmap bmpOld = null; public static Bitmap bmpOldScaled = null; public static Bitmap bmpNew = null; public static Bitmap bmpNewScaled = null; public static int scaledX = 0, scaledY = 0; public static int dispX = 0, dispY = 0; public static int fullX = 0, fullY = 0; public static int picX = 0, picY = 0; public static String fileDir = "/OnceAppOnATime/"; public static String fileTempDir = fileDir + "/.temp/"; public static String fileTempNew = fileTempDir + "/temp-new.jpg"; public static String fileTempOld = fileTempDir + "/temp-old.jpg"; public static String fileTempMask = fileTempDir + "/temp-mask.jpg"; public static String fileTempBlend = fileTempDir + "/temp-blend.jpg"; public static String fileTempRetouch = fileTempDir + "/temp-retouch.jpg"; //public static String fileLastBlend = ""; public static BitmapFactory.Options op = new BitmapFactory.Options(); public static Locale localeHebrew = null; public static int taskID = -1; public static boolean Init(Activity activity) { return Init(activity, false); } @SuppressLint("NewApi") @SuppressWairnings("deprecation") public static boolean Init(Activity activity, boolean force) { if (dispX > 0 && dispY > 0) { // Don't re-init to avoid wrong file names if (!force) return false; } else { fileDir = Environment.getExternalStorageDirectory() + fileDir; fileTempDir = Environment.getExternalStorageDirectory() + fileTempDir; fileTempNew = Environment.getExternalStorageDirectory() + fileTempNew; fileTempOld = Environment.getExternalStorageDirectory() + fileTempOld; fileTempMask = Environment.getExternalStorageDirectory() + fileTempMask; fileTempBlend = Environment.getExternalStorageDirectory() + fileTempBlend; fileTempRetouch = Environment.getExternalStorageDirectory() + fileTempRetouch; } taskID = activity.getTaskId(); // Find Hebrew locale, if available Locale availableLocales[] = Locale.getAvailableLocales(); for (int i = 0; i < availableLocales.length; ++i) { String lang = availableLocales[i].getLanguage(); if (lang.equals("he") || lang.equals("iw")) { localeHebrew = availableLocales[i]; break; } } op.inPreferredConfig = Bitmap.Config.ARGB_8888; //op.inScaled = false; // Not needed if loading bitmaps from drawable-nodpi op.inMutable = true; Display display = activity.getWindowManager().getDefaultDisplay(); if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.HONEYCOMB_MR2) { dispX = display.getWidth(); dispY = display.getHeight(); } else { Point dispSize = new Point(); display.getSize(dispSize); dispX = dispSize.x; dispY = dispSize.y; } Log.w("Display Size", dispX + "x" + dispY); //scaledX = dispX / 2; scaledY = dispY / 2; scaledX = dispX; scaledY = dispY; return true; } public static void setLocale(Activity activity, Locale locale) { // This doesn't work reliably Locale.setDefault(locale); Configuration config = new Configuration(); config.locale = locale; activity.getBaseContext().getResources().updateConfiguration(config, activity.getBaseContext().getResources().getDisplayMetrics()); } public static boolean haveScaling() { return (dispX != scaledX || dispY != scaledY); } public static void SaveTempBitmap(Bitmap bitmap, String filename) { try { new File(fileTempDir).mkdirs(); FileOutputStream out = new FileOutputStream(filename); bitmap.compress(Bitmap.CompressFormat.JPEG, 98, out); } catch (Exception e) { e.printStackTrace(); } } public static void RecycleOldBitmaps(boolean full, boolean scaled) { if (full && bmpOld != null) { bmpOld.recycle(); bmpOld = null; } if (scaled && bmpOldScaled != null) { bmpOldScaled.recycle(); bmpOldScaled = null; } } public static void RecycleNewBitmaps(boolean full, boolean scaled) { if (full && bmpNew != null) { bmpNew.recycle(); bmpNew = null; } if (scaled && bmpNewScaled != null) { bmpNewScaled.recycle(); bmpNewScaled = null; } } // 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 public static int sample2sample[] = new int[] {1, 1, 2, 2, 4, 4, 4, 4, 8, 8, 8, 8, 8, 8, 8, 8, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32}; public static Bitmap LoadScaledBitmap(Context ctx, int resId, float fracX, float fracY) { // See: http://developer.android.com/training/displaying-bitmaps/load-bitmap.html BitmapFactory.Options opts = new BitmapFactory.Options(); opts.inJustDecodeBounds = true; BitmapFactory.decodeResource(ctx.getResources(), resId, opts); int imageHeight = opts.outHeight; int imageWidth = opts.outWidth; float requestX = dispX * fracX, requestY = dispY * fracY; opts.inSampleSize = (int)(Math.min(imageWidth / requestX, imageHeight / requestY)); if (opts.inSampleSize < 0 || opts.inSampleSize > 32) // Sometimes index=2147483647 for some reason... opts.inSampleSize = 1; opts.inSampleSize = sample2sample[opts.inSampleSize]; Log.w("Bitmap Decoder", "Samples: " + opts.inSampleSize); opts.inPreferredConfig = Bitmap.Config.ARGB_8888; //opts.inScaled = false; // Not needed if loading bitmaps from drawable-nodpi opts.inMutable = true; opts.inJustDecodeBounds = false; return BitmapFactory.decodeResource(ctx.getResources(), resId, opts); } public static Bitmap LoadScaledBitmap(String filename, float fracX, float fracY) { // See: http://developer.android.com/training/displaying-bitmaps/load-bitmap.html BitmapFactory.Options opts = new BitmapFactory.Options(); opts.inJustDecodeBounds = true; BitmapFactory.decodeFile(filename, opts); int imageHeight = opts.outHeight; int imageWidth = opts.outWidth; float requestX = dispX * fracX, requestY = dispY * fracY; opts.inSampleSize = (int)(Math.min(imageWidth / requestX, imageHeight / requestY)); if (opts.inSampleSize < 0 || opts.inSampleSize > 32) // Sometimes index=2147483647 for some reason... opts.inSampleSize = 1; opts.inSampleSize = sample2sample[opts.inSampleSize]; Log.w("Bitmap Decoder", "Samples: " + opts.inSampleSize); opts.inPreferredConfig = Bitmap.Config.ARGB_8888; //opts.inScaled = false; // Not needed if loading bitmaps from drawable-nodpi opts.inMutable = true; opts.inJustDecodeBounds = false; return BitmapFactory.decodeFile(filename, opts); } public static String FileNameNow() { SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd_HH-mm-ss", Locale.ENGLISH); return fileDir + sdf.format(new Date()) + ".jpg"; } public static native void ocvBitmapPyramidalBlend(String fNew, String fOld, String fMask, String fBlend, int levels); public static String ocvBitmapPyramidalBlendTimed(int levels) { String fBlend = fileTempBlend;//FileNameNow(); long t = System.nanoTime(); ocvBitmapPyramidalBlend(fileTempNew, fileTempOld, fileTempMask, fBlend, levels); long dt = (System.nanoTime() - t) / 1000; // Microseconds Log.w("OpenCV", "Blended (pyramidal) bitmaps in " + (dt / 1000.0f) + " ms"); //fileLastBlend = fBlend; return fBlend; } public static native void ocvBitmapPreMultAlpha(Bitmap bitmapImg, Bitmap bitmapMask); public static void ocvBitmapPreMultAlphaTimed(Bitmap bitmapImg, Bitmap bitmapMask) { long t = System.nanoTime(); ocvBitmapPreMultAlpha(bitmapImg, bitmapMask); long dt = (System.nanoTime() - t) / 1000; // Microseconds Log.i("Native", "Applied premultiplied alpha to bitmap in " + (dt / 1000.0f) + " ms"); } public static native void ocvBitmapContrastSaturationSet(Bitmap bitmapImg); public static void ocvBitmapContrastSaturationSetTimed(Bitmap bitmapImg) { long t = System.nanoTime(); ocvBitmapContrastSaturationSet(bitmapImg); long dt = (System.nanoTime() - t) / 1000; // Microseconds Log.i("Native", "Assigned contrast/saturation bitmap in " + (dt / 1000.0f) + " ms"); } public static native void ocvBitmapContrastSaturationSrc(Bitmap bitmapImg, Bitmap bitmapSrc, float contrast, float saturation); public static void ocvBitmapContrastSaturationSrcTimed(Bitmap bitmapImg, Bitmap bitmapSrc, float contrast, float saturation) { long t = System.nanoTime(); ocvBitmapContrastSaturationSrc(bitmapImg, bitmapSrc, contrast, saturation); long dt = (System.nanoTime() - t) / 1000; // Microseconds Log.i("Native", "Applied contrast/saturation (from src) to bitmap in " + (dt / 1000.0f) + " ms"); } public static native void ocvBitmapContrastSaturation(Bitmap bitmapImg, float contrast, float saturation); public static void ocvBitmapContrastSaturationTimed(Bitmap bitmapImg, float contrast, float saturation) { long t = System.nanoTime(); ocvBitmapContrastSaturation(bitmapImg, contrast, saturation); long dt = (System.nanoTime() - t) / 1000; // Microseconds Log.i("Native", "Applied contrast/saturation to bitmap in " + (dt / 1000.0f) + " ms"); } } } package il.co.canvasvivapp2u.onceapponatime; import java.io.File; import java.io.FileOutputStream; import java.text.SimpleDateFormat; import java.util.Date; import java.util.Locale; import android.annotation.SuppressLint; import android.app.Activity; import android.content.Context; import android.content.res.Configuration; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.graphics.Point; import android.os.Environment; import android.util.Log; import android.view.Display; public class ShairedResources { public static Bitmap bmpOld = null; public static Bitmap bmpOldScaled = null; public static Bitmap bmpNew = null; public static Bitmap bmpNewScaled = null; public static int scaledX = 0, scaledY = 0; public static int dispX = 0, dispY = 0; public static int fullX = 0, fullY = 0; public static int picX = 0, picY = 0; public static String fileDir = "/OnceAppOnATime/"; public static String fileTempDir = fileDir + "/.temp/"; public static String fileTempNew = fileTempDir + "/temp-new.jpg"; public static String fileTempOld = fileTempDir + "/temp-old.jpg"; public static String fileTempMask = fileTempDir + "/temp-mask.jpg"; public static String fileTempBlend = fileTempDir + "/temp-blend.jpg"; public static String fileTempRetouch = fileTempDir + "/temp-retouch.jpg"; //public static String fileLastBlend = ""; public static BitmapFactory.Options op = new BitmapFactory.Options(); public static Locale localeHebrew = null; public static int taskID = -1; public static boolean Init(Activity activity) { return Init(activity, false); } @SuppressLint("NewApi") @SuppressWairnings("deprecation") public static boolean Init(Activity activity, boolean force) { if (dispX > 0 && dispY > 0) { // Don't re-init to avoid wrong file names if (!force) return false; } else { fileDir = Environment.getExternalStorageDirectory() + fileDir; fileTempDir = Environment.getExternalStorageDirectory() + fileTempDir; fileTempNew = Environment.getExternalStorageDirectory() + fileTempNew; fileTempOld = Environment.getExternalStorageDirectory() + fileTempOld; fileTempMask = Environment.getExternalStorageDirectory() + fileTempMask; fileTempBlend = Environment.getExternalStorageDirectory() + fileTempBlend; fileTempRetouch = Environment.getExternalStorageDirectory() + fileTempRetouch; } taskID = activity.getTaskId(); // Find Hebrew locale, if available Locale availableLocales[] = Locale.getAvailableLocales(); for (int i = 0; i < availableLocales.length; ++i) { String lang = availableLocales[i].getLanguage(); if (lang.equals("he") || lang.equals("iw")) { localeHebrew = availableLocales[i]; break; } } op.inPreferredConfig = Bitmap.Config.ARGB_8888; //op.inScaled = false; // Not needed if loading bitmaps from drawable-nodpi op.inMutable = true; Display display = activity.getWindowManager().getDefaultDisplay(); if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.HONEYCOMB_MR2) { dispX = display.getWidth(); dispY = display.getHeight(); } else { Point dispSize = new Point(); display.getSize(dispSize); dispX = dispSize.x; dispY = dispSize.y; } Log.w("Display Size", dispX + "x" + dispY); //scaledX = dispX / 2; scaledY = dispY / 2; scaledX = dispX; scaledY = dispY; return true; } public static void setLocale(Activity activity, Locale locale) { // This doesn't work reliably Locale.setDefault(locale); Configuration config = new Configuration(); config.locale = locale; activity.getBaseContext().getResources().updateConfiguration(config, activity.getBaseContext().getResources().getDisplayMetrics()); } public static boolean haveScaling() { return (dispX != scaledX || dispY != scaledY); } public static void SaveTempBitmap(Bitmap bitmap, String filename) { try { new File(fileTempDir).mkdirs(); FileOutputStream out = new FileOutputStream(filename); bitmap.compress(Bitmap.CompressFormat.JPEG, 98, out); } catch (Exception e) { e.printStackTrace(); } } public static void RecycleOldBitmaps(boolean full, boolean scaled) { if (full && bmpOld != null) { bmpOld.recycle(); bmpOld = null; } if (scaled && bmpOldScaled != null) { bmpOldScaled.recycle(); bmpOldScaled = null; } } public static void RecycleNewBitmaps(boolean full, boolean scaled) { if (full && bmpNew != null) { bmpNew.recycle(); bmpNew = null; } if (scaled && bmpNewScaled != null) { bmpNewScaled.recycle(); bmpNewScaled = null; } } // 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 public static int sample2sample[] = new int[] {1, 1, 2, 2, 4, 4, 4, 4, 8, 8, 8, 8, 8, 8, 8, 8, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32}; public static Bitmap LoadScaledBitmap(Context ctx, int resId, float fracX, float fracY) { // See: http://developer.android.com/training/displaying-bitmaps/load-bitmap.html BitmapFactory.Options opts = new BitmapFactory.Options(); opts.inJustDecodeBounds = true; BitmapFactory.decodeResource(ctx.getResources(), resId, opts); int imageHeight = opts.outHeight; int imageWidth = opts.outWidth; float requestX = dispX * fracX, requestY = dispY * fracY; opts.inSampleSize = (int)(Math.min(imageWidth / requestX, imageHeight / requestY)); if (opts.inSampleSize < 0 || opts.inSampleSize > 32) // Sometimes index=2147483647 for some reason... opts.inSampleSize = 1; opts.inSampleSize = sample2sample[opts.inSampleSize]; Log.w("Bitmap Decoder", "Samples: " + opts.inSampleSize); opts.inPreferredConfig = Bitmap.Config.ARGB_8888; //opts.inScaled = false; // Not needed if loading bitmaps from drawable-nodpi opts.inMutable = true; opts.inJustDecodeBounds = false; return BitmapFactory.decodeResource(ctx.getResources(), resId, opts); } public static Bitmap LoadScaledBitmap(String filename, float fracX, float fracY) { // See: http://developer.android.com/training/displaying-bitmaps/load-bitmap.html BitmapFactory.Options opts = new BitmapFactory.Options(); opts.inJustDecodeBounds = true; BitmapFactory.decodeFile(filename, opts); int imageHeight = opts.outHeight; int imageWidth = opts.outWidth; float requestX = dispX * fracX, requestY = dispY * fracY; opts.inSampleSize = (int)(Math.min(imageWidth / requestX, imageHeight / requestY)); if (opts.inSampleSize < 0 || opts.inSampleSize > 32) // Sometimes index=2147483647 for some reason... opts.inSampleSize = 1; opts.inSampleSize = sample2sample[opts.inSampleSize]; Log.w("Bitmap Decoder", "Samples: " + opts.inSampleSize); opts.inPreferredConfig = Bitmap.Config.ARGB_8888; //opts.inScaled = false; // Not needed if loading bitmaps from drawable-nodpi opts.inMutable = true; opts.inJustDecodeBounds = false; return BitmapFactory.decodeFile(filename, opts); } public static String FileNameNow() { SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd_HH-mm-ss", Locale.ENGLISH); return fileDir + sdf.format(new Date()) + ".jpg"; } public static native void ocvBitmapPyramidalBlend(String fNew, String fOld, String fMask, String fBlend, int levels); public static String ocvBitmapPyramidalBlendTimed(int levels) { String fBlend = fileTempBlend;//FileNameNow(); long t = System.nanoTime(); ocvBitmapPyramidalBlend(fileTempNew, fileTempOld, fileTempMask, fBlend, levels); long dt = (System.nanoTime() - t) / 1000; // Microseconds Log.w("OpenCV", "Blended (pyramidal) bitmaps in " + (dt / 1000.0f) + " ms"); //fileLastBlend = fBlend; return fBlend; } public static native void ocvBitmapPreMultAlpha(Bitmap bitmapImg, Bitmap bitmapMask); public static void ocvBitmapPreMultAlphaTimed(Bitmap bitmapImg, Bitmap bitmapMask) { long t = System.nanoTime(); ocvBitmapPreMultAlpha(bitmapImg, bitmapMask); long dt = (System.nanoTime() - t) / 1000; // Microseconds Log.i("Native", "Applied premultiplied alpha to bitmap in " + (dt / 1000.0f) + " ms"); } public static native void ocvBitmapContrastSaturationSet(Bitmap bitmapImg); public static void ocvBitmapContrastSaturationSetTimed(Bitmap bitmapImg) { long t = System.nanoTime(); ocvBitmapContrastSaturationSet(bitmapImg); long dt = (System.nanoTime() - t) / 1000; // Microseconds Log.i("Native", "Assigned contrast/saturation bitmap in " + (dt / 1000.0f) + " ms"); } public static native void ocvBitmapContrastSaturationSrc(Bitmap bitmapImg, Bitmap bitmapSrc, float contrast, float saturation); public static void ocvBitmapContrastSaturationSrcTimed(Bitmap bitmapImg, Bitmap bitmapSrc, float contrast, float saturation) { long t = System.nanoTime(); ocvBitmapContrastSaturationSrc(bitmapImg, bitmapSrc, contrast, saturation); long dt = (System.nanoTime() - t) / 1000; // Microseconds Log.i("Native", "Applied contrast/saturation (from src) to bitmap in " + (dt / 1000.0f) + " ms"); } public static native void ocvBitmapContrastSaturation(Bitmap bitmapImg, float contrast, float saturation); public static void ocvBitmapContrastSaturationTimed(Bitmap bitmapImg, float contrast, float saturation) { long t = System.nanoTime(); ocvBitmapContrastSaturation(bitmapImg, contrast, saturation); long dt = (System.nanoTime() - t) / 1000; // Microseconds Log.i("Native", "Applied contrast/saturation to bitmap in " + (dt / 1000.0f) + " ms"); } } } package il.co.canvasvivapp2u.onceapponatime; import java.io.File; import java.io.FileOutputStream; import java.text.SimpleDateFormat; import java.util.Date; import java.util.Locale; import android.annotation.SuppressLint; import android.app.Activity; import android.content.Context; import android.content.res.Configuration; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.graphics.Point; import android.os.Environment; import android.util.Log; import android.view.Display; public class ShairedResources { public static Bitmap bmpOld = null; public static Bitmap bmpOldScaled = null; public static Bitmap bmpNew = null; public static Bitmap bmpNewScaled = null; public static int scaledX = 0, scaledY = 0; public static int dispX = 0, dispY = 0; public static int fullX = 0, fullY = 0; public static int picX = 0, picY = 0; public static String fileDir = "/OnceAppOnATime/"; public static String fileTempDir = fileDir + "/.temp/"; public static String fileTempNew = fileTempDir + "/temp-new.jpg"; public static String fileTempOld = fileTempDir + "/temp-old.jpg"; public static String fileTempMask = fileTempDir + "/temp-mask.jpg"; public static String fileTempBlend = fileTempDir + "/temp-blend.jpg"; public static String fileTempRetouch = fileTempDir + "/temp-retouch.jpg"; //public static String fileLastBlend = ""; public static BitmapFactory.Options op = new BitmapFactory.Options(); public static Locale localeHebrew = null; public static int taskID = -1; public static boolean Init(Activity activity) { return Init(activity, false); } @SuppressLint("NewApi") @SuppressWairnings("deprecation") public static boolean Init(Activity activity, boolean force) { if (dispX > 0 && dispY > 0) { // Don't re-init to avoid wrong file names if (!force) return false; } else { fileDir = Environment.getExternalStorageDirectory() + fileDir; fileTempDir = Environment.getExternalStorageDirectory() + fileTempDir; fileTempNew = Environment.getExternalStorageDirectory() + fileTempNew; fileTempOld = Environment.getExternalStorageDirectory() + fileTempOld; fileTempMask = Environment.getExternalStorageDirectory() + fileTempMask; fileTempBlend = Environment.getExternalStorageDirectory() + fileTempBlend; fileTempRetouch = Environment.getExternalStorageDirectory() + fileTempRetouch; } taskID = activity.getTaskId(); // Find Hebrew locale, if available Locale availableLocales[] = Locale.getAvailableLocales(); for (int i = 0; i < availableLocales.length; ++i) { String lang = availableLocales[i].getLanguage(); if (lang.equals("he") || lang.equals("iw")) { localeHebrew = availableLocales[i]; break; } } op.inPreferredConfig = Bitmap.Config.ARGB_8888; //op.inScaled = false; // Not needed if loading bitmaps from drawable-nodpi op.inMutable = true; Display display = activity.getWindowManager().getDefaultDisplay(); if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.HONEYCOMB_MR2) { dispX = display.getWidth(); dispY = display.getHeight(); } else { Point dispSize = new Point(); display.getSize(dispSize); dispX = dispSize.x; dispY = dispSize.y; } Log.w("Display Size", dispX + "x" + dispY); //scaledX = dispX / 2; scaledY = dispY / 2; scaledX = dispX; scaledY = dispY; return true; } public static void setLocale(Activity activity, Locale locale) { // This doesn't work reliably Locale.setDefault(locale); Configuration config = new Configuration(); config.locale = locale; activity.getBaseContext().getResources().updateConfiguration(config, activity.getBaseContext().getResources().getDisplayMetrics()); } public static boolean haveScaling() { return (dispX != scaledX || dispY != scaledY); } public static void SaveTempBitmap(Bitmap bitmap, String filename) { try { new File(fileTempDir).mkdirs(); FileOutputStream out = new FileOutputStream(filename); bitmap.compress(Bitmap.CompressFormat.JPEG, 98, out); } catch (Exception e) { e.printStackTrace(); } } public static void RecycleOldBitmaps(boolean full, boolean scaled) { if (full && bmpOld != null) { bmpOld.recycle(); bmpOld = null; } if (scaled && bmpOldScaled != null) { bmpOldScaled.recycle(); bmpOldScaled = null; } } public static void RecycleNewBitmaps(boolean full, boolean scaled) { if (full && bmpNew != null) { bmpNew.recycle(); bmpNew = null; } if (scaled && bmpNewScaled != null) { bmpNewScaled.recycle(); bmpNewScaled = null; } } // 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 public static int sample2sample[] = new int[] {1, 1, 2, 2, 4, 4, 4, 4, 8, 8, 8, 8, 8, 8, 8, 8, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32}; public static Bitmap LoadScaledBitmap(Context ctx, int resId, float fracX, float fracY) { // See: http://developer.android.com/training/displaying-bitmaps/load-bitmap.html BitmapFactory.Options opts = new BitmapFactory.Options(); opts.inJustDecodeBounds = true; BitmapFactory.decodeResource(ctx.getResources(), resId, opts); int imageHeight = opts.outHeight; int imageWidth = opts.outWidth; float requestX = dispX * fracX, requestY = dispY * fracY; opts.inSampleSize = (int)(Math.min(imageWidth / requestX, imageHeight / requestY)); if (opts.inSampleSize < 0 || opts.inSampleSize > 32) // Sometimes index=2147483647 for some reason... opts.inSampleSize = 1; opts.inSampleSize = sample2sample[opts.inSampleSize]; Log.w("Bitmap Decoder", "Samples: " + opts.inSampleSize); opts.inPreferredConfig = Bitmap.Config.ARGB_8888; //opts.inScaled = false; // Not needed if loading bitmaps from drawable-nodpi opts.inMutable = true; opts.inJustDecodeBounds = false; return BitmapFactory.decodeResource(ctx.getResources(), resId, opts); } public static Bitmap LoadScaledBitmap(String filename, float fracX, float fracY) { // See: http://developer.android.com/training/displaying-bitmaps/load-bitmap.html BitmapFactory.Options opts = new BitmapFactory.Options(); opts.inJustDecodeBounds = true; BitmapFactory.decodeFile(filename, opts); int imageHeight = opts.outHeight; int imageWidth = opts.outWidth; float requestX = dispX * fracX, requestY = dispY * fracY; opts.inSampleSize = (int)(Math.min(imageWidth / requestX, imageHeight / requestY)); if (opts.inSampleSize < 0 || opts.inSampleSize > 32) // Sometimes index=2147483647 for some reason... opts.inSampleSize = 1; opts.inSampleSize = sample2sample[opts.inSampleSize]; Log.w("Bitmap Decoder", "Samples: " + opts.inSampleSize); opts.inPreferredConfig = Bitmap.Config.ARGB_8888; //opts.inScaled = false; // Not needed if loading bitmaps from drawable-nodpi opts.inMutable = true; opts.inJustDecodeBounds = false; return BitmapFactory.decodeFile(filename, opts); } public static String FileNameNow() { SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd_HH-mm-ss", Locale.ENGLISH); return fileDir + sdf.format(new Date()) + ".jpg"; } public static native void ocvBitmapPyramidalBlend(String fNew, String fOld, String fMask, String fBlend, int levels); public static String ocvBitmapPyramidalBlendTimed(int levels) { String fBlend = fileTempBlend;//FileNameNow(); long t = System.nanoTime(); ocvBitmapPyramidalBlend(fileTempNew, fileTempOld, fileTempMask, fBlend, levels); long dt = (System.nanoTime() - t) / 1000; // Microseconds Log.w("OpenCV", "Blended (pyramidal) bitmaps in " + (dt / 1000.0f) + " ms"); //fileLastBlend = fBlend; return fBlend; } public static native void ocvBitmapPreMultAlpha(Bitmap bitmapImg, Bitmap bitmapMask); public static void ocvBitmapPreMultAlphaTimed(Bitmap bitmapImg, Bitmap bitmapMask) { long t = System.nanoTime(); ocvBitmapPreMultAlpha(bitmapImg, bitmapMask); long dt = (System.nanoTime() - t) / 1000; // Microseconds Log.i("Native", "Applied premultiplied alpha to bitmap in " + (dt / 1000.0f) + " ms"); } public static native void ocvBitmapContrastSaturationSet(Bitmap bitmapImg); public static void ocvBitmapContrastSaturationSetTimed(Bitmap bitmapImg) { long t = System.nanoTime(); ocvBitmapContrastSaturationSet(bitmapImg); long dt = (System.nanoTime() - t) / 1000; // Microseconds Log.i("Native", "Assigned contrast/saturation bitmap in " + (dt / 1000.0f) + " ms"); } public static native void ocvBitmapContrastSaturationSrc(Bitmap bitmapImg, Bitmap bitmapSrc, float contrast, float saturation); public static void ocvBitmapContrastSaturationSrcTimed(Bitmap bitmapImg, Bitmap bitmapSrc, float contrast, float saturation) { long t = System.nanoTime(); ocvBitmapContrastSaturationSrc(bitmapImg, bitmapSrc, contrast, saturation); long dt = (System.nanoTime() - t) / 1000; // Microseconds Log.i("Native", "Applied contrast/saturation (from src) to bitmap in " + (dt / 1000.0f) + " ms"); } public static native void ocvBitmapContrastSaturation(Bitmap bitmapImg, float contrast, float saturation); public static void ocvBitmapContrastSaturationTimed(Bitmap bitmapImg, float contrast, float saturation) { long t = System.nanoTime(); ocvBitmapContrastSaturation(bitmapImg, contrast, saturation); long dt = (System.nanoTime() - t) / 1000; // Microseconds Log.i("Native", "Applied contrast/saturation to bitmap in " + (dt / 1000.0f) + " ms"); } } } package il.co.canvasvivapp2u.onceapponatime; import java.io.File; import java.io.FileOutputStream; import java.text.SimpleDateFormat; import java.util.Date; import java.util.Locale; import android.annotation.SuppressLint; import android.app.Activity; import android.content.Context; import android.content.res.Configuration; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.graphics.Point; import android.os.Environment; import android.util.Log; import android.view.Display; public class ShairedResources { public static Bitmap bmpOld = null; public static Bitmap bmpOldScaled = null; public static Bitmap bmpNew = null; public static Bitmap bmpNewScaled = null; public static int scaledX = 0, scaledY = 0; public static int dispX = 0, dispY = 0; public static int fullX = 0, fullY = 0; public static int picX = 0, picY = 0; public static String fileDir = "/OnceAppOnATime/"; public static String fileTempDir = fileDir + "/.temp/"; public static String fileTempNew = fileTempDir + "/temp-new.jpg"; public static String fileTempOld = fileTempDir + "/temp-old.jpg"; public static String fileTempMask = fileTempDir + "/temp-mask.jpg"; public static String fileTempBlend = fileTempDir + "/temp-blend.jpg"; public static String fileTempRetouch = fileTempDir + "/temp-retouch.jpg"; //public static String fileLastBlend = ""; public static BitmapFactory.Options op = new BitmapFactory.Options(); public static Locale localeHebrew = null; public static int taskID = -1; public static boolean Init(Activity activity) { return Init(activity, false); } @SuppressLint("NewApi") @SuppressWairnings("deprecation") public static boolean Init(Activity activity, boolean force) { if (dispX > 0 && dispY > 0) { // Don't re-init to avoid wrong file names if (!force) return false; } else { fileDir = Environment.getExternalStorageDirectory() + fileDir; fileTempDir = Environment.getExternalStorageDirectory() + fileTempDir; fileTempNew = Environment.getExternalStorageDirectory() + fileTempNew; fileTempOld = Environment.getExternalStorageDirectory() + fileTempOld; fileTempMask = Environment.getExternalStorageDirectory() + fileTempMask; fileTempBlend = Environment.getExternalStorageDirectory() + fileTempBlend; fileTempRetouch = Environment.getExternalStorageDirectory() + fileTempRetouch; } taskID = activity.getTaskId(); // Find Hebrew locale, if available Locale availableLocales[] = Locale.getAvailableLocales(); for (int i = 0; i < availableLocales.length; ++i) { String lang = availableLocales[i].getLanguage(); if (lang.equals("he") || lang.equals("iw")) { localeHebrew = availableLocales[i]; break; } } op.inPreferredConfig = Bitmap.Config.ARGB_8888; //op.inScaled = false; // Not needed if loading bitmaps from drawable-nodpi op.inMutable = true; Display display = activity.getWindowManager().getDefaultDisplay(); if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.HONEYCOMB_MR2) { dispX = display.getWidth(); dispY = display.getHeight(); } else { Point dispSize = new Point(); display.getSize(dispSize); dispX = dispSize.x; dispY = dispSize.y; } Log.w("Display Size", dispX + "x" + dispY); //scaledX = dispX / 2; scaledY = dispY / 2; scaledX = dispX; scaledY = dispY; return true; } public static void setLocale(Activity activity, Locale locale) { // This doesn't work reliably Locale.setDefault(locale); Configuration config = new Configuration(); config.locale = locale; activity.getBaseContext().getResources().updateConfiguration(config, activity.getBaseContext().getResources().getDisplayMetrics()); } public static boolean haveScaling() { return (dispX != scaledX || dispY != scaledY); } public static void SaveTempBitmap(Bitmap bitmap, String filename) { try { new File(fileTempDir).mkdirs(); FileOutputStream out = new FileOutputStream(filename); bitmap.compress(Bitmap.CompressFormat.JPEG, 98, out); } catch (Exception e) { e.printStackTrace(); } } public static void RecycleOldBitmaps(boolean full, boolean scaled) { if (full && bmpOld != null) { bmpOld.recycle(); bmpOld = null; } if (scaled && bmpOldScaled != null) { bmpOldScaled.recycle(); bmpOldScaled = null; } } public static void RecycleNewBitmaps(boolean full, boolean scaled) { if (full && bmpNew != null) { bmpNew.recycle(); bmpNew = null; } if (scaled && bmpNewScaled != null) { bmpNewScaled.recycle(); bmpNewScaled = null; } } // 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 public static int sample2sample[] = new int[] {1, 1, 2, 2, 4, 4, 4, 4, 8, 8, 8, 8, 8, 8, 8, 8, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32}; public static Bitmap LoadScaledBitmap(Context ctx, int resId, float fracX, float fracY) { // See: http://developer.android.com/training/displaying-bitmaps/load-bitmap.html BitmapFactory.Options opts = new BitmapFactory.Options(); opts.inJustDecodeBounds = true; BitmapFactory.decodeResource(ctx.getResources(), resId, opts); int imageHeight = opts.outHeight; int imageWidth = opts.outWidth; float requestX = dispX * fracX, requestY = dispY * fracY; opts.inSampleSize = (int)(Math.min(imageWidth / requestX, imageHeight / requestY)); if (opts.inSampleSize < 0 || opts.inSampleSize > 32) // Sometimes index=2147483647 for some reason... opts.inSampleSize = 1; opts.inSampleSize = sample2sample[opts.inSampleSize]; Log.w("Bitmap Decoder", "Samples: " + opts.inSampleSize); opts.inPreferredConfig = Bitmap.Config.ARGB_8888; //opts.inScaled = false; // Not needed if loading bitmaps from drawable-nodpi opts.inMutable = true; opts.inJustDecodeBounds = false; return BitmapFactory.decodeResource(ctx.getResources(), resId, opts); } public static Bitmap LoadScaledBitmap(String filename, float fracX, float fracY) { // See: http://developer.android.com/training/displaying-bitmaps/load-bitmap.html BitmapFactory.Options opts = new BitmapFactory.Options(); opts.inJustDecodeBounds = true; BitmapFactory.decodeFile(filename, opts); int imageHeight = opts.outHeight; int imageWidth = opts.outWidth; float requestX = dispX * fracX, requestY = dispY * fracY; opts.inSampleSize = (int)(Math.min(imageWidth / requestX, imageHeight / requestY)); if (opts.inSampleSize < 0 || opts.inSampleSize > 32) // Sometimes index=2147483647 for some reason... opts.inSampleSize = 1; opts.inSampleSize = sample2sample[opts.inSampleSize]; Log.w("Bitmap Decoder", "Samples: " + opts.inSampleSize); opts.inPreferredConfig = Bitmap.Config.ARGB_8888; //opts.inScaled = false; // Not needed if loading bitmaps from drawable-nodpi opts.inMutable = true; opts.inJustDecodeBounds = false; return BitmapFactory.decodeFile(filename, opts); } public static String FileNameNow() { SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd_HH-mm-ss", Locale.ENGLISH); return fileDir + sdf.format(new Date()) + ".jpg"; } public static native void ocvBitmapPyramidalBlend(String fNew, String fOld, String fMask, String fBlend, int levels); public static String ocvBitmapPyramidalBlendTimed(int levels) { String fBlend = fileTempBlend;//FileNameNow(); long t = System.nanoTime(); ocvBitmapPyramidalBlend(fileTempNew, fileTempOld, fileTempMask, fBlend, levels); long dt = (System.nanoTime() - t) / 1000; // Microseconds Log.w("OpenCV", "Blended (pyramidal) bitmaps in " + (dt / 1000.0f) + " ms"); //fileLastBlend = fBlend; return fBlend; } public static native void ocvBitmapPreMultAlpha(Bitmap bitmapImg, Bitmap bitmapMask); public static void ocvBitmapPreMultAlphaTimed(Bitmap bitmapImg, Bitmap bitmapMask) { long t = System.nanoTime(); ocvBitmapPreMultAlpha(bitmapImg, bitmapMask); long dt = (System.nanoTime() - t) / 1000; // Microseconds Log.i("Native", "Applied premultiplied alpha to bitmap in " + (dt / 1000.0f) + " ms"); } public static native void ocvBitmapContrastSaturationSet(Bitmap bitmapImg); public static void ocvBitmapContrastSaturationSetTimed(Bitmap bitmapImg) { long t = System.nanoTime(); ocvBitmapContrastSaturationSet(bitmapImg); long dt = (System.nanoTime() - t) / 1000; // Microseconds Log.i("Native", "Assigned contrast/saturation bitmap in " + (dt / 1000.0f) + " ms"); } public static native void ocvBitmapContrastSaturationSrc(Bitmap bitmapImg, Bitmap bitmapSrc, float contrast, float saturation); public static void ocvBitmapContrastSaturationSrcTimed(Bitmap bitmapImg, Bitmap bitmapSrc, float contrast, float saturation) { long t = System.nanoTime(); ocvBitmapContrastSaturationSrc(bitmapImg, bitmapSrc, contrast, saturation); long dt = (System.nanoTime() - t) / 1000; // Microseconds Log.i("Native", "Applied contrast/saturation (from src) to bitmap in " + (dt / 1000.0f) + " ms"); } public static native void ocvBitmapContrastSaturation(Bitmap bitmapImg, float contrast, float saturation); public static void ocvBitmapContrastSaturationTimed(Bitmap bitmapImg, float contrast, float saturation) { long t = System.nanoTime(); ocvBitmapContrastSaturation(bitmapImg, contrast, saturation); long dt = (System.nanoTime() - t) / 1000; // Microseconds Log.i("Native", "Applied contrast/saturation to bitmap in " + (dt / 1000.0f) + " ms"); } } } package il.co.canvasvivapp2u.onceapponatime; import java.io.File; import java.io.FileOutputStream; import java.text.SimpleDateFormat; import java.util.Date; import java.util.Locale; import android.annotation.SuppressLint; import android.app.Activity; import android.content.Context; import android.content.res.Configuration; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.graphics.Point; import android.os.Environment; import android.util.Log; import android.view.Display; public class ShairedResources { public static Bitmap bmpOld = null; public static Bitmap bmpOldScaled = null; public static Bitmap bmpNew = null; public static Bitmap bmpNewScaled = null; public static int scaledX = 0, scaledY = 0; public static int dispX = 0, dispY = 0; public static int fullX = 0, fullY = 0; public static int picX = 0, picY = 0; public static String fileDir = "/OnceAppOnATime/"; public static String fileTempDir = fileDir + "/.temp/"; public static String fileTempNew = fileTempDir + "/temp-new.jpg"; public static String fileTempOld = fileTempDir + "/temp-old.jpg"; public static String fileTempMask = fileTempDir + "/temp-mask.jpg"; public static String fileTempBlend = fileTempDir + "/temp-blend.jpg"; public static String fileTempRetouch = fileTempDir + "/temp-retouch.jpg"; //public static String fileLastBlend = ""; public static BitmapFactory.Options op = new BitmapFactory.Options(); public static Locale localeHebrew = null; public static int taskID = -1; public static boolean Init(Activity activity) { return Init(activity, false); } @SuppressLint("NewApi") @SuppressWairnings("deprecation") public static boolean Init(Activity activity, boolean force) { if (dispX > 0 && dispY > 0) { // Don't re-init to avoid wrong file names if (!force) return false; } else { fileDir = Environment.getExternalStorageDirectory() + fileDir; fileTempDir = Environment.getExternalStorageDirectory() + fileTempDir; fileTempNew = Environment.getExternalStorageDirectory() + fileTempNew; fileTempOld = Environment.getExternalStorageDirectory() + fileTempOld; fileTempMask = Environment.getExternalStorageDirectory() + fileTempMask; fileTempBlend = Environment.getExternalStorageDirectory() + fileTempBlend; fileTempRetouch = Environment.getExternalStorageDirectory() + fileTempRetouch; } taskID = activity.getTaskId(); // Find Hebrew locale, if available Locale availableLocales[] = Locale.getAvailableLocales(); for (int i = 0; i < availableLocales.length; ++i) { String lang = availableLocales[i].getLanguage(); if (lang.equals("he") || lang.equals("iw")) { localeHebrew = availableLocales[i]; break; } } op.inPreferredConfig = Bitmap.Config.ARGB_8888; //op.inScaled = false; // Not needed if loading bitmaps from drawable-nodpi op.inMutable = true; Display display = activity.getWindowManager().getDefaultDisplay(); if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.HONEYCOMB_MR2) { dispX = display.getWidth(); dispY = display.getHeight(); } else { Point dispSize = new Point(); display.getSize(dispSize); dispX = dispSize.x; dispY = dispSize.y; } Log.w("Display Size", dispX + "x" + dispY); //scaledX = dispX / 2; scaledY = dispY / 2; scaledX = dispX; scaledY = dispY; return true; } public static void setLocale(Activity activity, Locale locale) { // This doesn't work reliably Locale.setDefault(locale); Configuration config = new Configuration(); config.locale = locale; activity.getBaseContext().getResources().updateConfiguration(config, activity.getBaseContext().getResources().getDisplayMetrics()); } public static boolean haveScaling() { return (dispX != scaledX || dispY != scaledY); } public static void SaveTempBitmap(Bitmap bitmap, String filename) { try { new File(fileTempDir).mkdirs(); FileOutputStream out = new FileOutputStream(filename); bitmap.compress(Bitmap.CompressFormat.JPEG, 98, out); } catch (Exception e) { e.printStackTrace(); } } public static void RecycleOldBitmaps(boolean full, boolean scaled) { if (full && bmpOld != null) { bmpOld.recycle(); bmpOld = null; } if (scaled && bmpOldScaled != null) { bmpOldScaled.recycle(); bmpOldScaled = null; } } public static void RecycleNewBitmaps(boolean full, boolean scaled) { if (full && bmpNew != null) { bmpNew.recycle(); bmpNew = null; } if (scaled && bmpNewScaled != null) { bmpNewScaled.recycle(); bmpNewScaled = null; } } // 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 public static int sample2sample[] = new int[] {1, 1, 2, 2, 4, 4, 4, 4, 8, 8, 8, 8, 8, 8, 8, 8, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32}; public static Bitmap LoadScaledBitmap(Context ctx, int resId, float fracX, float fracY) { // See: http://developer.android.com/training/displaying-bitmaps/load-bitmap.html BitmapFactory.Options opts = new BitmapFactory.Options(); opts.inJustDecodeBounds = true; BitmapFactory.decodeResource(ctx.getResources(), resId, opts); int imageHeight = opts.outHeight; int imageWidth = opts.outWidth; float requestX = dispX * fracX, requestY = dispY * fracY; opts.inSampleSize = (int)(Math.min(imageWidth / requestX, imageHeight / requestY)); if (opts.inSampleSize < 0 || opts.inSampleSize > 32) // Sometimes index=2147483647 for some reason... opts.inSampleSize = 1; opts.inSampleSize = sample2sample[opts.inSampleSize]; Log.w("Bitmap Decoder", "Samples: " + opts.inSampleSize); opts.inPreferredConfig = Bitmap.Config.ARGB_8888; //opts.inScaled = false; // Not needed if loading bitmaps from drawable-nodpi opts.inMutable = true; opts.inJustDecodeBounds = false; return BitmapFactory.decodeResource(ctx.getResources(), resId, opts); } public static Bitmap LoadScaledBitmap(String filename, float fracX, float fracY) { // See: http://developer.android.com/training/displaying-bitmaps/load-bitmap.html BitmapFactory.Options opts = new BitmapFactory.Options(); opts.inJustDecodeBounds = true; BitmapFactory.decodeFile(filename, opts); int imageHeight = opts.outHeight; int imageWidth = opts.outWidth; float requestX = dispX * fracX, requestY = dispY * fracY; opts.inSampleSize = (int)(Math.min(imageWidth / requestX, imageHeight / requestY)); if (opts.inSampleSize < 0 || opts.inSampleSize > 32) // Sometimes index=2147483647 for some reason... opts.inSampleSize = 1; opts.inSampleSize = sample2sample[opts.inSampleSize]; Log.w("Bitmap Decoder", "Samples: " + opts.inSampleSize); opts.inPreferredConfig = Bitmap.Config.ARGB_8888; //opts.inScaled = false; // Not needed if loading bitmaps from drawable-nodpi opts.inMutable = true; opts.inJustDecodeBounds = false; return BitmapFactory.decodeFile(filename, opts); } public static String FileNameNow() { SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd_HH-mm-ss", Locale.ENGLISH); return fileDir + sdf.format(new Date()) + ".jpg"; } public static native void ocvBitmapPyramidalBlend(String fNew, String fOld, String fMask, String fBlend, int levels); public static String ocvBitmapPyramidalBlendTimed(int levels) { String fBlend = fileTempBlend;//FileNameNow(); long t = System.nanoTime(); ocvBitmapPyramidalBlend(fileTempNew, fileTempOld, fileTempMask, fBlend, levels); long dt = (System.nanoTime() - t) / 1000; // Microseconds Log.w("OpenCV", "Blended (pyramidal) bitmaps in " + (dt / 1000.0f) + " ms"); //fileLastBlend = fBlend; return fBlend; } public static native void ocvBitmapPreMultAlpha(Bitmap bitmapImg, Bitmap bitmapMask); public static void ocvBitmapPreMultAlphaTimed(Bitmap bitmapImg, Bitmap bitmapMask) { long t = System.nanoTime(); ocvBitmapPreMultAlpha(bitmapImg, bitmapMask); long dt = (System.nanoTime() - t) / 1000; // Microseconds Log.i("Native", "Applied premultiplied alpha to bitmap in " + (dt / 1000.0f) + " ms"); } public static native void ocvBitmapContrastSaturationSet(Bitmap bitmapImg); public static void ocvBitmapContrastSaturationSetTimed(Bitmap bitmapImg) { long t = System.nanoTime(); ocvBitmapContrastSaturationSet(bitmapImg); long dt = (System.nanoTime() - t) / 1000; // Microseconds Log.i("Native", "Assigned contrast/saturation bitmap in " + (dt / 1000.0f) + " ms"); } public static native void ocvBitmapContrastSaturationSrc(Bitmap bitmapImg, Bitmap bitmapSrc, float contrast, float saturation); public static void ocvBitmapContrastSaturationSrcTimed(Bitmap bitmapImg, Bitmap bitmapSrc, float contrast, float saturation) { long t = System.nanoTime(); ocvBitmapContrastSaturationSrc(bitmapImg, bitmapSrc, contrast, saturation); long dt = (System.nanoTime() - t) / 1000; // Microseconds Log.i("Native", "Applied contrast/saturation (from src) to bitmap in " + (dt / 1000.0f) + " ms"); } public static native void ocvBitmapContrastSaturation(Bitmap bitmapImg, float contrast, float saturation); public static void ocvBitmapContrastSaturationTimed(Bitmap bitmapImg, float contrast, float saturation) { long t = System.nanoTime(); ocvBitmapContrastSaturation(bitmapImg, contrast, saturation); long dt = (System.nanoTime() - t) / 1000; // Microseconds Log.i("Native", "Applied contrast/saturation to bitmap in " + (dt / 1000.0f) + " ms"); } } } package il.co.canvasvivapp2u.onceapponatime; import java.io.File; import java.io.FileOutputStream; import java.text.SimpleDateFormat; import java.util.Date; import java.util.Locale; import android.annotation.SuppressLint; import android.app.Activity; import android.content.Context; import android.content.res.Configuration; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.graphics.Point; import android.os.Environment; import android.util.Log; import android.view.Display; public class ShairedResources { public static Bitmap bmpOld = null; public static Bitmap bmpOldScaled = null; public static Bitmap bmpNew = null; public static Bitmap bmpNewScaled = null; public static int scaledX = 0, scaledY = 0; public static int dispX = 0, dispY = 0; public static int fullX = 0, fullY = 0; public static int picX = 0, picY = 0; public static String fileDir = "/OnceAppOnATime/"; public static String fileTempDir = fileDir + "/.temp/"; public static String fileTempNew = fileTempDir + "/temp-new.jpg"; public static String fileTempOld = fileTempDir + "/temp-old.jpg"; public static String fileTempMask = fileTempDir + "/temp-mask.jpg"; public static String fileTempBlend = fileTempDir + "/temp-blend.jpg"; public static String fileTempRetouch = fileTempDir + "/temp-retouch.jpg"; //public static String fileLastBlend = ""; public static BitmapFactory.Options op = new BitmapFactory.Options(); public static Locale localeHebrew = null; public static int taskID = -1; public static boolean Init(Activity activity) { return Init(activity, false); } @SuppressLint("NewApi") @SuppressWairnings("deprecation") public static boolean Init(Activity activity, boolean force) { if (dispX > 0 && dispY > 0) { // Don't re-init to avoid wrong file names if (!force) return false; } else { fileDir = Environment.getExternalStorageDirectory() + fileDir; fileTempDir = Environment.getExternalStorageDirectory() + fileTempDir; fileTempNew = Environment.getExternalStorageDirectory() + fileTempNew; fileTempOld = Environment.getExternalStorageDirectory() + fileTempOld; fileTempMask = Environment.getExternalStorageDirectory() + fileTempMask; fileTempBlend = Environment.getExternalStorageDirectory() + fileTempBlend; fileTempRetouch = Environment.getExternalStorageDirectory() + fileTempRetouch; } taskID = activity.getTaskId(); // Find Hebrew locale, if available Locale availableLocales[] = Locale.getAvailableLocales(); for (int i = 0; i < availableLocales.length; ++i) { String lang = availableLocales[i].getLanguage(); if (lang.equals("he") || lang.equals("iw")) { localeHebrew = availableLocales[i]; break; } } op.inPreferredConfig = Bitmap.Config.ARGB_8888; //op.inScaled = false; // Not needed if loading bitmaps from drawable-nodpi op.inMutable = true; Display display = activity.getWindowManager().getDefaultDisplay(); if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.HONEYCOMB_MR2) { dispX = display.getWidth(); dispY = display.getHeight(); } else { Point dispSize = new Point(); display.getSize(dispSize); dispX = dispSize.x; dispY = dispSize.y; } Log.w("Display Size", dispX + "x" + dispY); //scaledX = dispX / 2; scaledY = dispY / 2; scaledX = dispX; scaledY = dispY; return true; } public static void setLocale(Activity activity, Locale locale) { // This doesn't work reliably Locale.setDefault(locale); Configuration config = new Configuration(); config.locale = locale; activity.getBaseContext().getResources().updateConfiguration(config, activity.getBaseContext().getResources().getDisplayMetrics()); } public static boolean haveScaling() { return (dispX != scaledX || dispY != scaledY); } public static void SaveTempBitmap(Bitmap bitmap, String filename) { try { new File(fileTempDir).mkdirs(); FileOutputStream out = new FileOutputStream(filename); bitmap.compress(Bitmap.CompressFormat.JPEG, 98, out); } catch (Exception e) { e.printStackTrace(); } } public static void RecycleOldBitmaps(boolean full, boolean scaled) { if (full && bmpOld != null) { bmpOld.recycle(); bmpOld = null; } if (scaled && bmpOldScaled != null) { bmpOldScaled.recycle(); bmpOldScaled = null; } } public static void RecycleNewBitmaps(boolean full, boolean scaled) { if (full && bmpNew != null) { bmpNew.recycle(); bmpNew = null; } if (scaled && bmpNewScaled != null) { bmpNewScaled.recycle(); bmpNewScaled = null; } } // 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 public static int sample2sample[] = new int[] {1, 1, 2, 2, 4, 4, 4, 4, 8, 8, 8, 8, 8, 8, 8, 8, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32}; public static Bitmap LoadScaledBitmap(Context ctx, int resId, float fracX, float fracY) { // See: http://developer.android.com/training/displaying-bitmaps/load-bitmap.html BitmapFactory.Options opts = new BitmapFactory.Options(); opts.inJustDecodeBounds = true; BitmapFactory.decodeResource(ctx.getResources(), resId, opts); int imageHeight = opts.outHeight; int imageWidth = opts.outWidth; float requestX = dispX * fracX, requestY = dispY * fracY; opts.inSampleSize = (int)(Math.min(imageWidth / requestX, imageHeight / requestY)); if (opts.inSampleSize < 0 || opts.inSampleSize > 32) // Sometimes index=2147483647 for some reason... opts.inSampleSize = 1; opts.inSampleSize = sample2sample[opts.inSampleSize]; Log.w("Bitmap Decoder", "Samples: " + opts.inSampleSize); opts.inPreferredConfig = Bitmap.Config.ARGB_8888; //opts.inScaled = false; // Not needed if loading bitmaps from drawable-nodpi opts.inMutable = true; opts.inJustDecodeBounds = false; return BitmapFactory.decodeResource(ctx.getResources(), resId, opts); } public static Bitmap LoadScaledBitmap(String filename, float fracX, float fracY) { // See: http://developer.android.com/training/displaying-bitmaps/load-bitmap.html BitmapFactory.Options opts = new BitmapFactory.Options(); opts.inJustDecodeBounds = true; BitmapFactory.decodeFile(filename, opts); int imageHeight = opts.outHeight; int imageWidth = opts.outWidth; float requestX = dispX * fracX, requestY = dispY * fracY; opts.inSampleSize = (int)(Math.min(imageWidth / requestX, imageHeight / requestY)); if (opts.inSampleSize < 0 || opts.inSampleSize > 32) // Sometimes index=2147483647 for some reason... opts.inSampleSize = 1; opts.inSampleSize = sample2sample[opts.inSampleSize]; Log.w("Bitmap Decoder", "Samples: " + opts.inSampleSize); opts.inPreferredConfig = Bitmap.Config.ARGB_8888; //opts.inScaled = false; // Not needed if loading bitmaps from drawable-nodpi opts.inMutable = true; opts.inJustDecodeBounds = false; return BitmapFactory.decodeFile(filename, opts); } public static String FileNameNow() { SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd_HH-mm-ss", Locale.ENGLISH); return fileDir + sdf.format(new Date()) + ".jpg"; } public static native void ocvBitmapPyramidalBlend(String fNew, String fOld, String fMask, String fBlend, int levels); public static String ocvBitmapPyramidalBlendTimed(int levels) { String fBlend = fileTempBlend;//FileNameNow(); long t = System.nanoTime(); ocvBitmapPyramidalBlend(fileTempNew, fileTempOld, fileTempMask, fBlend, levels); long dt = (System.nanoTime() - t) / 1000; // Microseconds Log.w("OpenCV", "Blended (pyramidal) bitmaps in " + (dt / 1000.0f) + " ms"); //fileLastBlend = fBlend; return fBlend; } public static native void ocvBitmapPreMultAlpha(Bitmap bitmapImg, Bitmap bitmapMask); public static void ocvBitmapPreMultAlphaTimed(Bitmap bitmapImg, Bitmap bitmapMask) { long t = System.nanoTime(); ocvBitmapPreMultAlpha(bitmapImg, bitmapMask); long dt = (System.nanoTime() - t) / 1000; // Microseconds Log.i("Native", "Applied premultiplied alpha to bitmap in " + (dt / 1000.0f) + " ms"); } public static native void ocvBitmapContrastSaturationSet(Bitmap bitmapImg); public static void ocvBitmapContrastSaturationSetTimed(Bitmap bitmapImg) { long t = System.nanoTime(); ocvBitmapContrastSaturationSet(bitmapImg); long dt = (System.nanoTime() - t) / 1000; // Microseconds Log.i("Native", "Assigned contrast/saturation bitmap in " + (dt / 1000.0f) + " ms"); } public static native void ocvBitmapContrastSaturationSrc(Bitmap bitmapImg, Bitmap bitmapSrc, float contrast, float saturation); public static void ocvBitmapContrastSaturationSrcTimed(Bitmap bitmapImg, Bitmap bitmapSrc, float contrast, float saturation) { long t = System.nanoTime(); ocvBitmapContrastSaturationSrc(bitmapImg, bitmapSrc, contrast, saturation); long dt = (System.nanoTime() - t) / 1000; // Microseconds Log.i("Native", "Applied contrast/saturation (from src) to bitmap in " + (dt / 1000.0f) + " ms"); } public static native void ocvBitmapContrastSaturation(Bitmap bitmapImg, float contrast, float saturation); public static void ocvBitmapContrastSaturationTimed(Bitmap bitmapImg, float contrast, float saturation) { long t = System.nanoTime(); ocvBitmapContrastSaturation(bitmapImg, contrast, saturation); long dt = (System.nanoTime() - t) / 1000; // Microseconds Log.i("Native", "Applied contrast/saturation to bitmap in " + (dt / 1000.0f) + " ms"); } } } package il.co.canvasvivapp2u.onceapponatime; import java.io.File; import java.io.FileOutputStream; import java.text.SimpleDateFormat; import java.util.Date; import java.util.Locale; import android.annotation.SuppressLint; import android.app.Activity; import android.content.Context; import android.content.res.Configuration; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.graphics.Point; import android.os.Environment; import android.util.Log; import android.view.Display; public class ShairedResources { public static Bitmap bmpOld = null; public static Bitmap bmpOldScaled = null; public static Bitmap bmpNew = null; public static Bitmap bmpNewScaled = null; public static int scaledX = 0, scaledY = 0; public static int dispX = 0, dispY = 0; public static int fullX = 0, fullY = 0; public static int picX = 0, picY = 0; public static String fileDir = "/OnceAppOnATime/"; public static String fileTempDir = fileDir + "/.temp/"; public static String fileTempNew = fileTempDir + "/temp-new.jpg"; public static String fileTempOld = fileTempDir + "/temp-old.jpg"; public static String fileTempMask = fileTempDir + "/temp-mask.jpg"; public static String fileTempBlend = fileTempDir + "/temp-blend.jpg"; public static String fileTempRetouch = fileTempDir + "/temp-retouch.jpg"; //public static String fileLastBlend = ""; public static BitmapFactory.Options op = new BitmapFactory.Options(); public static Locale localeHebrew = null; public static int taskID = -1; public static boolean Init(Activity activity) { return Init(activity, false); } @SuppressLint("NewApi") @SuppressWairnings("deprecation") public static boolean Init(Activity activity, boolean force) { if (dispX > 0 && dispY > 0) { // Don't re-init to avoid wrong file names if (!force) return false; } else { fileDir = Environment.getExternalStorageDirectory() + fileDir; fileTempDir = Environment.getExternalStorageDirectory() + fileTempDir; fileTempNew = Environment.getExternalStorageDirectory() + fileTempNew; fileTempOld = Environment.getExternalStorageDirectory() + fileTempOld; fileTempMask = Environment.getExternalStorageDirectory() + fileTempMask; fileTempBlend = Environment.getExternalStorageDirectory() + fileTempBlend; fileTempRetouch = Environment.getExternalStorageDirectory() + fileTempRetouch; } taskID = activity.getTaskId(); // Find Hebrew locale, if available Locale availableLocales[] = Locale.getAvailableLocales(); for (int i = 0; i < availableLocales.length; ++i) { String lang = availableLocales[i].getLanguage(); if (lang.equals("he") || lang.equals("iw")) { localeHebrew = availableLocales[i]; break; } } op.inPreferredConfig = Bitmap.Config.ARGB_8888; //op.inScaled = false; // Not needed if loading bitmaps from drawable-nodpi op.inMutable = true; Display display = activity.getWindowManager().getDefaultDisplay(); if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.HONEYCOMB_MR2) { dispX = display.getWidth(); dispY = display.getHeight(); } else { Point dispSize = new Point(); display.getSize(dispSize); dispX = dispSize.x; dispY = dispSize.y; } Log.w("Display Size", dispX + "x" + dispY); //scaledX = dispX / 2; scaledY = dispY / 2; scaledX = dispX; scaledY = dispY; return true; } public static void setLocale(Activity activity, Locale locale) { // This doesn't work reliably Locale.setDefault(locale); Configuration config = new Configuration(); config.locale = locale; activity.getBaseContext().getResources().updateConfiguration(config, activity.getBaseContext().getResources().getDisplayMetrics()); } public static boolean haveScaling() { return (dispX != scaledX || dispY != scaledY); } public static void SaveTempBitmap(Bitmap bitmap, String filename) { try { new File(fileTempDir).mkdirs(); FileOutputStream out = new FileOutputStream(filename); bitmap.compress(Bitmap.CompressFormat.JPEG, 98, out); } catch (Exception e) { e.printStackTrace(); } } public static void RecycleOldBitmaps(boolean full, boolean scaled) { if (full && bmpOld != null) { bmpOld.recycle(); bmpOld = null; } if (scaled && bmpOldScaled != null) { bmpOldScaled.recycle(); bmpOldScaled = null; } } public static void RecycleNewBitmaps(boolean full, boolean scaled) { if (full && bmpNew != null) { bmpNew.recycle(); bmpNew = null; } if (scaled && bmpNewScaled != null) { bmpNewScaled.recycle(); bmpNewScaled = null; } } // 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 public static int sample2sample[] = new int[] {1, 1, 2, 2, 4, 4, 4, 4, 8, 8, 8, 8, 8, 8, 8, 8, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32}; public static Bitmap LoadScaledBitmap(Context ctx, int resId, float fracX, float fracY) { // See: http://developer.android.com/training/displaying-bitmaps/load-bitmap.html BitmapFactory.Options opts = new BitmapFactory.Options(); opts.inJustDecodeBounds = true; BitmapFactory.decodeResource(ctx.getResources(), resId, opts); int imageHeight = opts.outHeight; int imageWidth = opts.outWidth; float requestX = dispX * fracX, requestY = dispY * fracY; opts.inSampleSize = (int)(Math.min(imageWidth / requestX, imageHeight / requestY)); if (opts.inSampleSize < 0 || opts.inSampleSize > 32) // Sometimes index=2147483647 for some reason... opts.inSampleSize = 1; opts.inSampleSize = sample2sample[opts.inSampleSize]; Log.w("Bitmap Decoder", "Samples: " + opts.inSampleSize); opts.inPreferredConfig = Bitmap.Config.ARGB_8888; //opts.inScaled = false; // Not needed if loading bitmaps from drawable-nodpi opts.inMutable = true; opts.inJustDecodeBounds = false; return BitmapFactory.decodeResource(ctx.getResources(), resId, opts); } public static Bitmap LoadScaledBitmap(String filename, float fracX, float fracY) { // See: http://developer.android.com/training/displaying-bitmaps/load-bitmap.html BitmapFactory.Options opts = new BitmapFactory.Options(); opts.inJustDecodeBounds = true; BitmapFactory.decodeFile(filename, opts); int imageHeight = opts.outHeight; int imageWidth = opts.outWidth; float requestX = dispX * fracX, requestY = dispY * fracY; opts.inSampleSize = (int)(Math.min(imageWidth / requestX, imageHeight / requestY)); if (opts.inSampleSize < 0 || opts.inSampleSize > 32) // Sometimes index=2147483647 for some reason... opts.inSampleSize = 1; opts.inSampleSize = sample2sample[opts.inSampleSize]; Log.w("Bitmap Decoder", "Samples: " + opts.inSampleSize); opts.inPreferredConfig = Bitmap.Config.ARGB_8888; //opts.inScaled = false; // Not needed if loading bitmaps from drawable-nodpi opts.inMutable = true; opts.inJustDecodeBounds = false; return BitmapFactory.decodeFile(filename, opts); } public static String FileNameNow() { SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd_HH-mm-ss", Locale.ENGLISH); return fileDir + sdf.format(new Date()) + ".jpg"; } public static native void ocvBitmapPyramidalBlend(String fNew, String fOld, String fMask, String fBlend, int levels); public static String ocvBitmapPyramidalBlendTimed(int levels) { String fBlend = fileTempBlend;//FileNameNow(); long t = System.nanoTime(); ocvBitmapPyramidalBlend(fileTempNew, fileTempOld, fileTempMask, fBlend, levels); long dt = (System.nanoTime() - t) / 1000; // Microseconds Log.w("OpenCV", "Blended (pyramidal) bitmaps in " + (dt / 1000.0f) + " ms"); //fileLastBlend = fBlend; return fBlend; } public static native void ocvBitmapPreMultAlpha(Bitmap bitmapImg, Bitmap bitmapMask); public static void ocvBitmapPreMultAlphaTimed(Bitmap bitmapImg, Bitmap bitmapMask) { long t = System.nanoTime(); ocvBitmapPreMultAlpha(bitmapImg, bitmapMask); long dt = (System.nanoTime() - t) / 1000; // Microseconds Log.i("Native", "Applied premultiplied alpha to bitmap in " + (dt / 1000.0f) + " ms"); } public static native void ocvBitmapContrastSaturationSet(Bitmap bitmapImg); public static void ocvBitmapContrastSaturationSetTimed(Bitmap bitmapImg) { long t = System.nanoTime(); ocvBitmapContrastSaturationSet(bitmapImg); long dt = (System.nanoTime() - t) / 1000; // Microseconds Log.i("Native", "Assigned contrast/saturation bitmap in " + (dt / 1000.0f) + " ms"); } public static native void ocvBitmapContrastSaturationSrc(Bitmap bitmapImg, Bitmap bitmapSrc, float contrast, float saturation); public static void ocvBitmapContrastSaturationSrcTimed(Bitmap bitmapImg, Bitmap bitmapSrc, float contrast, float saturation) { long t = System.nanoTime(); ocvBitmapContrastSaturationSrc(bitmapImg, bitmapSrc, contrast, saturation); long dt = (System.nanoTime() - t) / 1000; // Microseconds Log.i("Native", "Applied contrast/saturation (from src) to bitmap in " + (dt / 1000.0f) + " ms"); } public static native void ocvBitmapContrastSaturation(Bitmap bitmapImg, float contrast, float saturation); public static void ocvBitmapContrastSaturationTimed(Bitmap bitmapImg, float contrast, float saturation) { long t = System.nanoTime(); ocvBitmapContrastSaturation(bitmapImg, contrast, saturation); long dt = (System.nanoTime() - t) / 1000; // Microseconds Log.i("Native", "Applied contrast/saturation to bitmap in " + (dt / 1000.0f) + " ms"); } } } package il.co.canvasvivapp2u.onceapponatime; import java.io.File; import java.io.FileOutputStream; import java.text.SimpleDateFormat; import java.util.Date; import java.util.Locale; import android.annotation.SuppressLint; import android.app.Activity; import android.content.Context; import android.content.res.Configuration; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.graphics.Point; import android.os.Environment; import android.util.Log; import android.view.Display; public class ShairedResources { public static Bitmap bmpOld = null; public static Bitmap bmpOldScaled = null; public static Bitmap bmpNew = null; public static Bitmap bmpNewScaled = null; public static int scaledX = 0, scaledY = 0; public static int dispX = 0, dispY = 0; public static int fullX = 0, fullY = 0; public static int picX = 0, picY = 0; public static String fileDir = "/OnceAppOnATime/"; public static String fileTempDir = fileDir + "/.temp/"; public static String fileTempNew = fileTempDir + "/temp-new.jpg"; public static String fileTempOld = fileTempDir + "/temp-old.jpg"; public static String fileTempMask = fileTempDir + "/temp-mask.jpg"; public static String fileTempBlend = fileTempDir + "/temp-blend.jpg"; public static String fileTempRetouch = fileTempDir + "/temp-retouch.jpg"; //public static String fileLastBlend = ""; public static BitmapFactory.Options op = new BitmapFactory.Options(); public static Locale localeHebrew = null; public static int taskID = -1; public static boolean Init(Activity activity) { return Init(activity, false); } @SuppressLint("NewApi") @SuppressWairnings("deprecation") public static boolean Init(Activity activity, boolean force) { if (dispX > 0 && dispY > 0) { // Don't re-init to avoid wrong file names if (!force) return false; } else { fileDir = Environment.getExternalStorageDirectory() + fileDir; fileTempDir = Environment.getExternalStorageDirectory() + fileTempDir; fileTempNew = Environment.getExternalStorageDirectory() + fileTempNew; fileTempOld = Environment.getExternalStorageDirectory() + fileTempOld; fileTempMask = Environment.getExternalStorageDirectory() + fileTempMask; fileTempBlend = Environment.getExternalStorageDirectory() + fileTempBlend; fileTempRetouch = Environment.getExternalStorageDirectory() + fileTempRetouch; } taskID = activity.getTaskId(); // Find Hebrew locale, if available Locale availableLocales[] = Locale.getAvailableLocales(); for (int i = 0; i < availableLocales.length; ++i) { String lang = availableLocales[i].getLanguage(); if (lang.equals("he") || lang.equals("iw")) { localeHebrew = availableLocales[i]; break; } } op.inPreferredConfig = Bitmap.Config.ARGB_8888; //op.inScaled = false; // Not needed if loading bitmaps from drawable-nodpi op.inMutable = true; Display display = activity.getWindowManager().getDefaultDisplay(); if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.HONEYCOMB_MR2) { dispX = display.getWidth(); dispY = display.getHeight(); } else { Point dispSize = new Point(); display.getSize(dispSize); dispX = dispSize.x; dispY = dispSize.y; } Log.w("Display Size", dispX + "x" + dispY); //scaledX = dispX / 2; scaledY = dispY / 2; scaledX = dispX; scaledY = dispY; return true; } public static void setLocale(Activity activity, Locale locale) { // This doesn't work reliably Locale.setDefault(locale); Configuration config = new Configuration(); config.locale = locale; activity.getBaseContext().getResources().updateConfiguration(config, activity.getBaseContext().getResources().getDisplayMetrics()); } public static boolean haveScaling() { return (dispX != scaledX || dispY != scaledY); } public static void SaveTempBitmap(Bitmap bitmap, String filename) { try { new File(fileTempDir).mkdirs(); FileOutputStream out = new FileOutputStream(filename); bitmap.compress(Bitmap.CompressFormat.JPEG, 98, out); } catch (Exception e) { e.printStackTrace(); } } public static void RecycleOldBitmaps(boolean full, boolean scaled) { if (full && bmpOld != null) { bmpOld.recycle(); bmpOld = null; } if (scaled && bmpOldScaled != null) { bmpOldScaled.recycle(); bmpOldScaled = null; } } public static void RecycleNewBitmaps(boolean full, boolean scaled) { if (full && bmpNew != null) { bmpNew.recycle(); bmpNew = null; } if (scaled && bmpNewScaled != null) { bmpNewScaled.recycle(); bmpNewScaled = null; } } // 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 public static int sample2sample[] = new int[] {1, 1, 2, 2, 4, 4, 4, 4, 8, 8, 8, 8, 8, 8, 8, 8, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32}; public static Bitmap LoadScaledBitmap(Context ctx, int resId, float fracX, float fracY) { // See: http://developer.android.com/training/displaying-bitmaps/load-bitmap.html BitmapFactory.Options opts = new BitmapFactory.Options(); opts.inJustDecodeBounds = true; BitmapFactory.decodeResource(ctx.getResources(), resId, opts); int imageHeight = opts.outHeight; int imageWidth = opts.outWidth; float requestX = dispX * fracX, requestY = dispY * fracY; opts.inSampleSize = (int)(Math.min(imageWidth / requestX, imageHeight / requestY)); if (opts.inSampleSize < 0 || opts.inSampleSize > 32) // Sometimes index=2147483647 for some reason... opts.inSampleSize = 1; opts.inSampleSize = sample2sample[opts.inSampleSize]; Log.w("Bitmap Decoder", "Samples: " + opts.inSampleSize); opts.inPreferredConfig = Bitmap.Config.ARGB_8888; //opts.inScaled = false; // Not needed if loading bitmaps from drawable-nodpi opts.inMutable = true; opts.inJustDecodeBounds = false; return BitmapFactory.decodeResource(ctx.getResources(), resId, opts); } public static Bitmap LoadScaledBitmap(String filename, float fracX, float fracY) { // See: http://developer.android.com/training/displaying-bitmaps/load-bitmap.html BitmapFactory.Options opts = new BitmapFactory.Options(); opts.inJustDecodeBounds = true; BitmapFactory.decodeFile(filename, opts); int imageHeight = opts.outHeight; int imageWidth = opts.outWidth; float requestX = dispX * fracX, requestY = dispY * fracY; opts.inSampleSize = (int)(Math.min(imageWidth / requestX, imageHeight / requestY)); if (opts.inSampleSize < 0 || opts.inSampleSize > 32) // Sometimes index=2147483647 for some reason... opts.inSampleSize = 1; opts.inSampleSize = sample2sample[opts.inSampleSize]; Log.w("Bitmap Decoder", "Samples: " + opts.inSampleSize); opts.inPreferredConfig = Bitmap.Config.ARGB_8888; //opts.inScaled = false; // Not needed if loading bitmaps from drawable-nodpi opts.inMutable = true; opts.inJustDecodeBounds = false; return BitmapFactory.decodeFile(filename, opts); } public static String FileNameNow() { SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd_HH-mm-ss", Locale.ENGLISH); return fileDir + sdf.format(new Date()) + ".jpg"; } public static native void ocvBitmapPyramidalBlend(String fNew, String fOld, String fMask, String fBlend, int levels); public static String ocvBitmapPyramidalBlendTimed(int levels) { String fBlend = fileTempBlend;//FileNameNow(); long t = System.nanoTime(); ocvBitmapPyramidalBlend(fileTempNew, fileTempOld, fileTempMask, fBlend, levels); long dt = (System.nanoTime() - t) / 1000; // Microseconds Log.w("OpenCV", "Blended (pyramidal) bitmaps in " + (dt / 1000.0f) + " ms"); //fileLastBlend = fBlend; return fBlend; } public static native void ocvBitmapPreMultAlpha(Bitmap bitmapImg, Bitmap bitmapMask); public static void ocvBitmapPreMultAlphaTimed(Bitmap bitmapImg, Bitmap bitmapMask) { long t = System.nanoTime(); ocvBitmapPreMultAlpha(bitmapImg, bitmapMask); long dt = (System.nanoTime() - t) / 1000; // Microseconds Log.i("Native", "Applied premultiplied alpha to bitmap in " + (dt / 1000.0f) + " ms"); } public static native void ocvBitmapContrastSaturationSet(Bitmap bitmapImg); public static void ocvBitmapContrastSaturationSetTimed(Bitmap bitmapImg) { long t = System.nanoTime(); ocvBitmapContrastSaturationSet(bitmapImg); long dt = (System.nanoTime() - t) / 1000; // Microseconds Log.i("Native", "Assigned contrast/saturation bitmap in " + (dt / 1000.0f) + " ms"); } public static native void ocvBitmapContrastSaturationSrc(Bitmap bitmapImg, Bitmap bitmapSrc, float contrast, float saturation); public static void ocvBitmapContrastSaturationSrcTimed(Bitmap bitmapImg, Bitmap bitmapSrc, float contrast, float saturation) { long t = System.nanoTime(); ocvBitmapContrastSaturationSrc(bitmapImg, bitmapSrc, contrast, saturation); long dt = (System.nanoTime() - t) / 1000; // Microseconds Log.i("Native", "Applied contrast/saturation (from src) to bitmap in " + (dt / 1000.0f) + " ms"); } public static native void ocvBitmapContrastSaturation(Bitmap bitmapImg, float contrast, float saturation); public static void ocvBitmapContrastSaturationTimed(Bitmap bitmapImg, float contrast, float saturation) { long t = System.nanoTime(); ocvBitmapContrastSaturation(bitmapImg, contrast, saturation); long dt = (System.nanoTime() - t) / 1000; // Microseconds Log.i("Native", "Applied contrast/saturation to bitmap in " + (dt / 1000.0f) + " ms"); } } } package il.co.canvasvivapp2u.onceapponatime; import java.io.File; import java.io.FileOutputStream; import java.text.SimpleDateFormat; import java.util.Date; import java.util.Locale; import android.annotation.SuppressLint; import android.app.Activity; import android.content.Context; import android.content.res.Configuration; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.graphics.Point; import android.os.Environment; import android.util.Log; import android.view.Display; public class ShairedResources { public static Bitmap bmpOld = null; public static Bitmap bmpOldScaled = null; public static Bitmap bmpNew = null; public static Bitmap bmpNewScaled = null; public static int scaledX = 0, scaledY = 0; public static int dispX = 0, dispY = 0; public static int fullX = 0, fullY = 0; public static int picX = 0, picY = 0; public static String fileDir = "/OnceAppOnATime/"; public static String fileTempDir = fileDir + "/.temp/"; public static String fileTempNew = fileTempDir + "/temp-new.jpg"; public static String fileTempOld = fileTempDir + "/temp-old.jpg"; public static String fileTempMask = fileTempDir + "/temp-mask.jpg"; public static String fileTempBlend = fileTempDir + "/temp-blend.jpg"; public static String fileTempRetouch = fileTempDir + "/temp-retouch.jpg"; //public static String fileLastBlend = ""; public static BitmapFactory.Options op = new BitmapFactory.Options(); public static Locale localeHebrew = null; public static int taskID = -1; public static boolean Init(Activity activity) { return Init(activity, false); } @SuppressLint("NewApi") @SuppressWairnings("deprecation") public static boolean Init(Activity activity, boolean force) { if (dispX > 0 && dispY > 0) { // Don't re-init to avoid wrong file names if (!force) return false; } else { fileDir = Environment.getExternalStorageDirectory() + fileDir; fileTempDir = Environment.getExternalStorageDirectory() + fileTempDir; fileTempNew = Environment.getExternalStorageDirectory() + fileTempNew; fileTempOld = Environment.getExternalStorageDirectory() + fileTempOld; fileTempMask = Environment.getExternalStorageDirectory() + fileTempMask; fileTempBlend = Environment.getExternalStorageDirectory() + fileTempBlend; fileTempRetouch = Environment.getExternalStorageDirectory() + fileTempRetouch; } taskID = activity.getTaskId(); // Find Hebrew locale, if available Locale availableLocales[] = Locale.getAvailableLocales(); for (int i = 0; i < availableLocales.length; ++i) { String lang = availableLocales[i].getLanguage(); if (lang.equals("he") || lang.equals("iw")) { localeHebrew = availableLocales[i]; break; } } op.inPreferredConfig = Bitmap.Config.ARGB_8888; //op.inScaled = false; // Not needed if loading bitmaps from drawable-nodpi op.inMutable = true; Display display = activity.getWindowManager().getDefaultDisplay(); if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.HONEYCOMB_MR2) { dispX = display.getWidth(); dispY = display.getHeight(); } else { Point dispSize = new Point(); display.getSize(dispSize); dispX = dispSize.x; dispY = dispSize.y; } Log.w("Display Size", dispX + "x" + dispY); //scaledX = dispX / 2; scaledY = dispY / 2; scaledX = dispX; scaledY = dispY; return true; } public static void setLocale(Activity activity, Locale locale) { // This doesn't work reliably Locale.setDefault(locale); Configuration config = new Configuration(); config.locale = locale; activity.getBaseContext().getResources().updateConfiguration(config, activity.getBaseContext().getResources().getDisplayMetrics()); } public static boolean haveScaling() { return (dispX != scaledX || dispY != scaledY); } public static void SaveTempBitmap(Bitmap bitmap, String filename) { try { new File(fileTempDir).mkdirs(); FileOutputStream out = new FileOutputStream(filename); bitmap.compress(Bitmap.CompressFormat.JPEG, 98, out); } catch (Exception e) { e.printStackTrace(); } } public static void RecycleOldBitmaps(boolean full, boolean scaled) { if (full && bmpOld != null) { bmpOld.recycle(); bmpOld = null; } if (scaled && bmpOldScaled != null) { bmpOldScaled.recycle(); bmpOldScaled = null; } } public static void RecycleNewBitmaps(boolean full, boolean scaled) { if (full && bmpNew != null) { bmpNew.recycle(); bmpNew = null; } if (scaled && bmpNewScaled != null) { bmpNewScaled.recycle(); bmpNewScaled = null; } } // 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 public static int sample2sample[] = new int[] {1, 1, 2, 2, 4, 4, 4, 4, 8, 8, 8, 8, 8, 8, 8, 8, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32}; public static Bitmap LoadScaledBitmap(Context ctx, int resId, float fracX, float fracY) { // See: http://developer.android.com/training/displaying-bitmaps/load-bitmap.html BitmapFactory.Options opts = new BitmapFactory.Options(); opts.inJustDecodeBounds = true; BitmapFactory.decodeResource(ctx.getResources(), resId, opts); int imageHeight = opts.outHeight; int imageWidth = opts.outWidth; float requestX = dispX * fracX, requestY = dispY * fracY; opts.inSampleSize = (int)(Math.min(imageWidth / requestX, imageHeight / requestY)); if (opts.inSampleSize < 0 || opts.inSampleSize > 32) // Sometimes index=2147483647 for some reason... opts.inSampleSize = 1; opts.inSampleSize = sample2sample[opts.inSampleSize]; Log.w("Bitmap Decoder", "Samples: " + opts.inSampleSize); opts.inPreferredConfig = Bitmap.Config.ARGB_8888; //opts.inScaled = false; // Not needed if loading bitmaps from drawable-nodpi opts.inMutable = true; opts.inJustDecodeBounds = false; return BitmapFactory.decodeResource(ctx.getResources(), resId, opts); } public static Bitmap LoadScaledBitmap(String filename, float fracX, float fracY) { // See: http://developer.android.com/training/displaying-bitmaps/load-bitmap.html BitmapFactory.Options opts = new BitmapFactory.Options(); opts.inJustDecodeBounds = true; BitmapFactory.decodeFile(filename, opts); int imageHeight = opts.outHeight; int imageWidth = opts.outWidth; float requestX = dispX * fracX, requestY = dispY * fracY; opts.inSampleSize = (int)(Math.min(imageWidth / requestX, imageHeight / requestY)); if (opts.inSampleSize < 0 || opts.inSampleSize > 32) // Sometimes index=2147483647 for some reason... opts.inSampleSize = 1; opts.inSampleSize = sample2sample[opts.inSampleSize]; Log.w("Bitmap Decoder", "Samples: " + opts.inSampleSize); opts.inPreferredConfig = Bitmap.Config.ARGB_8888; //opts.inScaled = false; // Not needed if loading bitmaps from drawable-nodpi opts.inMutable = true; opts.inJustDecodeBounds = false; return BitmapFactory.decodeFile(filename, opts); } public static String FileNameNow() { SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd_HH-mm-ss", Locale.ENGLISH); return fileDir + sdf.format(new Date()) + ".jpg"; } public static native void ocvBitmapPyramidalBlend(String fNew, String fOld, String fMask, String fBlend, int levels); public static String ocvBitmapPyramidalBlendTimed(int levels) { String fBlend = fileTempBlend;//FileNameNow(); long t = System.nanoTime(); ocvBitmapPyramidalBlend(fileTempNew, fileTempOld, fileTempMask, fBlend, levels); long dt = (System.nanoTime() - t) / 1000; // Microseconds Log.w("OpenCV", "Blended (pyramidal) bitmaps in " + (dt / 1000.0f) + " ms"); //fileLastBlend = fBlend; return fBlend; } public static native void ocvBitmapPreMultAlpha(Bitmap bitmapImg, Bitmap bitmapMask); public static void ocvBitmapPreMultAlphaTimed(Bitmap bitmapImg, Bitmap bitmapMask) { long t = System.nanoTime(); ocvBitmapPreMultAlpha(bitmapImg, bitmapMask); long dt = (System.nanoTime() - t) / 1000; // Microseconds Log.i("Native", "Applied premultiplied alpha to bitmap in " + (dt / 1000.0f) + " ms"); } public static native void ocvBitmapContrastSaturationSet(Bitmap bitmapImg); public static void ocvBitmapContrastSaturationSetTimed(Bitmap bitmapImg) { long t = System.nanoTime(); ocvBitmapContrastSaturationSet(bitmapImg); long dt = (System.nanoTime() - t) / 1000; // Microseconds Log.i("Native", "Assigned contrast/saturation bitmap in " + (dt / 1000.0f) + " ms"); } public static native void ocvBitmapContrastSaturationSrc(Bitmap bitmapImg, Bitmap bitmapSrc, float contrast, float saturation); public static void ocvBitmapContrastSaturationSrcTimed(Bitmap bitmapImg, Bitmap bitmapSrc, float contrast, float saturation) { long t = System.nanoTime(); ocvBitmapContrastSaturationSrc(bitmapImg, bitmapSrc, contrast, saturation); long dt = (System.nanoTime() - t) / 1000; // Microseconds Log.i("Native", "Applied contrast/saturation (from src) to bitmap in " + (dt / 1000.0f) + " ms"); } public static native void ocvBitmapContrastSaturation(Bitmap bitmapImg, float contrast, float saturation); public static void ocvBitmapContrastSaturationTimed(Bitmap bitmapImg, float contrast, float saturation) { long t = System.nanoTime(); ocvBitmapContrastSaturation(bitmapImg, contrast, saturation); long dt = (System.nanoTime() - t) / 1000; // Microseconds Log.i("Native", "Applied contrast/saturation to bitmap in " + (dt / 1000.0f) + " ms"); } } } package il.co.canvasvivapp2u.onceapponatime; import java.io.File; import java.io.FileOutputStream; import java.text.SimpleDateFormat; import java.util.Date; import java.util.Locale; import android.annotation.SuppressLint; import android.app.Activity; import android.content.Context; import android.content.res.Configuration; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.graphics.Point; import android.os.Environment; import android.util.Log; import android.view.Display; public class ShairedResources { public static Bitmap bmpOld = null; public static Bitmap bmpOldScaled = null; public static Bitmap bmpNew = null; public static Bitmap bmpNewScaled = null; public static int scaledX = 0, scaledY = 0; public static int dispX = 0, dispY = 0; public static int fullX = 0, fullY = 0; public static int picX = 0, picY = 0; public static String fileDir = "/OnceAppOnATime/"; public static String fileTempDir = fileDir + "/.temp/"; public static String fileTempNew = fileTempDir + "/temp-new.jpg"; public static String fileTempOld = fileTempDir + "/temp-old.jpg"; public static String fileTempMask = fileTempDir + "/temp-mask.jpg"; public static String fileTempBlend = fileTempDir + "/temp-blend.jpg"; public static String fileTempRetouch = fileTempDir + "/temp-retouch.jpg"; //public static String fileLastBlend = ""; public static BitmapFactory.Options op = new BitmapFactory.Options(); public static Locale localeHebrew = null; public static int taskID = -1; public static boolean Init(Activity activity) { return Init(activity, false); } @SuppressLint("NewApi") @SuppressWairnings("deprecation") public static boolean Init(Activity activity, boolean force) { if (dispX > 0 && dispY > 0) { // Don't re-init to avoid wrong file names if (!force) return false; } else { fileDir = Environment.getExternalStorageDirectory() + fileDir; fileTempDir = Environment.getExternalStorageDirectory() + fileTempDir; fileTempNew = Environment.getExternalStorageDirectory() + fileTempNew; fileTempOld = Environment.getExternalStorageDirectory() + fileTempOld; fileTempMask = Environment.getExternalStorageDirectory() + fileTempMask; fileTempBlend = Environment.getExternalStorageDirectory() + fileTempBlend; fileTempRetouch = Environment.getExternalStorageDirectory() + fileTempRetouch; } taskID = activity.getTaskId(); // Find Hebrew locale, if available Locale availableLocales[] = Locale.getAvailableLocales(); for (int i = 0; i < availableLocales.length; ++i) { String lang = availableLocales[i].getLanguage(); if (lang.equals("he") || lang.equals("iw")) { localeHebrew = availableLocales[i]; break; } } op.inPreferredConfig = Bitmap.Config.ARGB_8888; //op.inScaled = false; // Not needed if loading bitmaps from drawable-nodpi op.inMutable = true; Display display = activity.getWindowManager().getDefaultDisplay(); if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.HONEYCOMB_MR2) { dispX = display.getWidth(); dispY = display.getHeight(); } else { Point dispSize = new Point(); display.getSize(dispSize); dispX = dispSize.x; dispY = dispSize.y; } Log.w("Display Size", dispX + "x" + dispY); //scaledX = dispX / 2; scaledY = dispY / 2; scaledX = dispX; scaledY = dispY; return true; } public static void setLocale(Activity activity, Locale locale) { // This doesn't work reliably Locale.setDefault(locale); Configuration config = new Configuration(); config.locale = locale; activity.getBaseContext().getResources().updateConfiguration(config, activity.getBaseContext().getResources().getDisplayMetrics()); } public static boolean haveScaling() { return (dispX != scaledX || dispY != scaledY); } public static void SaveTempBitmap(Bitmap bitmap, String filename) { try { new File(fileTempDir).mkdirs(); FileOutputStream out = new FileOutputStream(filename); bitmap.compress(Bitmap.CompressFormat.JPEG, 98, out); } catch (Exception e) { e.printStackTrace(); } } public static void RecycleOldBitmaps(boolean full, boolean scaled) { if (full && bmpOld != null) { bmpOld.recycle(); bmpOld = null; } if (scaled && bmpOldScaled != null) { bmpOldScaled.recycle(); bmpOldScaled = null; } } public static void RecycleNewBitmaps(boolean full, boolean scaled) { if (full && bmpNew != null) { bmpNew.recycle(); bmpNew = null; } if (scaled && bmpNewScaled != null) { bmpNewScaled.recycle(); bmpNewScaled = null; } } // 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 public static int sample2sample[] = new int[] {1, 1, 2, 2, 4, 4, 4, 4, 8, 8, 8, 8, 8, 8, 8, 8, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32}; public static Bitmap LoadScaledBitmap(Context ctx, int resId, float fracX, float fracY) { // See: http://developer.android.com/training/displaying-bitmaps/load-bitmap.html BitmapFactory.Options opts = new BitmapFactory.Options(); opts.inJustDecodeBounds = true; BitmapFactory.decodeResource(ctx.getResources(), resId, opts); int imageHeight = opts.outHeight; int imageWidth = opts.outWidth; float requestX = dispX * fracX, requestY = dispY * fracY; opts.inSampleSize = (int)(Math.min(imageWidth / requestX, imageHeight / requestY)); if (opts.inSampleSize < 0 || opts.inSampleSize > 32) // Sometimes index=2147483647 for some reason... opts.inSampleSize = 1; opts.inSampleSize = sample2sample[opts.inSampleSize]; Log.w("Bitmap Decoder", "Samples: " + opts.inSampleSize); opts.inPreferredConfig = Bitmap.Config.ARGB_8888; //opts.inScaled = false; // Not needed if loading bitmaps from drawable-nodpi opts.inMutable = true; opts.inJustDecodeBounds = false; return BitmapFactory.decodeResource(ctx.getResources(), resId, opts); } public static Bitmap LoadScaledBitmap(String filename, float fracX, float fracY) { // See: http://developer.android.com/training/displaying-bitmaps/load-bitmap.html BitmapFactory.Options opts = new BitmapFactory.Options(); opts.inJustDecodeBounds = true; BitmapFactory.decodeFile(filename, opts); int imageHeight = opts.outHeight; int imageWidth = opts.outWidth; float requestX = dispX * fracX, requestY = dispY * fracY; opts.inSampleSize = (int)(Math.min(imageWidth / requestX, imageHeight / requestY)); if (opts.inSampleSize < 0 || opts.inSampleSize > 32) // Sometimes index=2147483647 for some reason... opts.inSampleSize = 1; opts.inSampleSize = sample2sample[opts.inSampleSize]; Log.w("Bitmap Decoder", "Samples: " + opts.inSampleSize); opts.inPreferredConfig = Bitmap.Config.ARGB_8888; //opts.inScaled = false; // Not needed if loading bitmaps from drawable-nodpi opts.inMutable = true; opts.inJustDecodeBounds = false; return BitmapFactory.decodeFile(filename, opts); } public static String FileNameNow() { SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd_HH-mm-ss", Locale.ENGLISH); return fileDir + sdf.format(new Date()) + ".jpg"; } public static native void ocvBitmapPyramidalBlend(String fNew, String fOld, String fMask, String fBlend, int levels); public static String ocvBitmapPyramidalBlendTimed(int levels) { String fBlend = fileTempBlend;//FileNameNow(); long t = System.nanoTime(); ocvBitmapPyramidalBlend(fileTempNew, fileTempOld, fileTempMask, fBlend, levels); long dt = (System.nanoTime() - t) / 1000; // Microseconds Log.w("OpenCV", "Blended (pyramidal) bitmaps in " + (dt / 1000.0f) + " ms"); //fileLastBlend = fBlend; return fBlend; } public static native void ocvBitmapPreMultAlpha(Bitmap bitmapImg, Bitmap bitmapMask); public static void ocvBitmapPreMultAlphaTimed(Bitmap bitmapImg, Bitmap bitmapMask) { long t = System.nanoTime(); ocvBitmapPreMultAlpha(bitmapImg, bitmapMask); long dt = (System.nanoTime() - t) / 1000; // Microseconds Log.i("Native", "Applied premultiplied alpha to bitmap in " + (dt / 1000.0f) + " ms"); } public static native void ocvBitmapContrastSaturationSet(Bitmap bitmapImg); public static void ocvBitmapContrastSaturationSetTimed(Bitmap bitmapImg) { long t = System.nanoTime(); ocvBitmapContrastSaturationSet(bitmapImg); long dt = (System.nanoTime() - t) / 1000; // Microseconds Log.i("Native", "Assigned contrast/saturation bitmap in " + (dt / 1000.0f) + " ms"); } public static native void ocvBitmapContrastSaturationSrc(Bitmap bitmapImg, Bitmap bitmapSrc, float contrast, float saturation); public static void ocvBitmapContrastSaturationSrcTimed(Bitmap bitmapImg, Bitmap bitmapSrc, float contrast, float saturation) { long t = System.nanoTime(); ocvBitmapContrastSaturationSrc(bitmapImg, bitmapSrc, contrast, saturation); long dt = (System.nanoTime() - t) / 1000; // Microseconds Log.i("Native", "Applied contrast/saturation (from src) to bitmap in " + (dt / 1000.0f) + " ms"); } public static native void ocvBitmapContrastSaturation(Bitmap bitmapImg, float contrast, float saturation); public static void ocvBitmapContrastSaturationTimed(Bitmap bitmapImg, float contrast, float saturation) { long t = System.nanoTime(); ocvBitmapContrastSaturation(bitmapImg, contrast, saturation); long dt = (System.nanoTime() - t) / 1000; // Microseconds Log.i("Native", "Applied contrast/saturation to bitmap in " + (dt / 1000.0f) + " ms"); } } } package il.co.canvasvivapp2u.onceapponatime; import java.io.File; import java.io.FileOutputStream; import java.text.SimpleDateFormat; import java.util.Date; import java.util.Locale; import android.annotation.SuppressLint; import android.app.Activity; import android.content.Context; import android.content.res.Configuration; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.graphics.Point; import android.os.Environment; import android.util.Log; import android.view.Display; public class ShairedResources { public static Bitmap bmpOld = null; public static Bitmap bmpOldScaled = null; public static Bitmap bmpNew = null; public static Bitmap bmpNewScaled = null; public static int scaledX = 0, scaledY = 0; public static int dispX = 0, dispY = 0; public static int fullX = 0, fullY = 0; public static int picX = 0, picY = 0; public static String fileDir = "/OnceAppOnATime/"; public static String fileTempDir = fileDir + "/.temp/"; public static String fileTempNew = fileTempDir + "/temp-new.jpg"; public static String fileTempOld = fileTempDir + "/temp-old.jpg"; public static String fileTempMask = fileTempDir + "/temp-mask.jpg"; public static String fileTempBlend = fileTempDir + "/temp-blend.jpg"; public static String fileTempRetouch = fileTempDir + "/temp-retouch.jpg"; //public static String fileLastBlend = ""; public static BitmapFactory.Options op = new BitmapFactory.Options(); public static Locale localeHebrew = null; public static int taskID = -1; public static boolean Init(Activity activity) { return Init(activity, false); } @SuppressLint("NewApi") @SuppressWairnings("deprecation") public static boolean Init(Activity activity, boolean force) { if (dispX > 0 && dispY > 0) { // Don't re-init to avoid wrong file names if (!force) return false; } else { fileDir = Environment.getExternalStorageDirectory() + fileDir; fileTempDir = Environment.getExternalStorageDirectory() + fileTempDir; fileTempNew = Environment.getExternalStorageDirectory() + fileTempNew; fileTempOld = Environment.getExternalStorageDirectory() + fileTempOld; fileTempMask = Environment.getExternalStorageDirectory() + fileTempMask; fileTempBlend = Environment.getExternalStorageDirectory() + fileTempBlend; fileTempRetouch = Environment.getExternalStorageDirectory() + fileTempRetouch; } taskID = activity.getTaskId(); // Find Hebrew locale, if available Locale availableLocales[] = Locale.getAvailableLocales(); for (int i = 0; i < availableLocales.length; ++i) { String lang = availableLocales[i].getLanguage(); if (lang.equals("he") || lang.equals("iw")) { localeHebrew = availableLocales[i]; break; } } op.inPreferredConfig = Bitmap.Config.ARGB_8888; //op.inScaled = false; // Not needed if loading bitmaps from drawable-nodpi op.inMutable = true; Display display = activity.getWindowManager().getDefaultDisplay(); if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.HONEYCOMB_MR2) { dispX = display.getWidth(); dispY = display.getHeight(); } else { Point dispSize = new Point(); display.getSize(dispSize); dispX = dispSize.x; dispY = dispSize.y; } Log.w("Display Size", dispX + "x" + dispY); //scaledX = dispX / 2; scaledY = dispY / 2; scaledX = dispX; scaledY = dispY; return true; } public static void setLocale(Activity activity, Locale locale) { // This doesn't work reliably Locale.setDefault(locale); Configuration config = new Configuration(); config.locale = locale; activity.getBaseContext().getResources().updateConfiguration(config, activity.getBaseContext().getResources().getDisplayMetrics()); } public static boolean haveScaling() { return (dispX != scaledX || dispY != scaledY); } public static void SaveTempBitmap(Bitmap bitmap, String filename) { try { new File(fileTempDir).mkdirs(); FileOutputStream out = new FileOutputStream(filename); bitmap.compress(Bitmap.CompressFormat.JPEG, 98, out); } catch (Exception e) { e.printStackTrace(); } } public static void RecycleOldBitmaps(boolean full, boolean scaled) { if (full && bmpOld != null) { bmpOld.recycle(); bmpOld = null; } if (scaled && bmpOldScaled != null) { bmpOldScaled.recycle(); bmpOldScaled = null; } } public static void RecycleNewBitmaps(boolean full, boolean scaled) { if (full && bmpNew != null) { bmpNew.recycle(); bmpNew = null; } if (scaled && bmpNewScaled != null) { bmpNewScaled.recycle(); bmpNewScaled = null; } } // 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 public static int sample2sample[] = new int[] {1, 1, 2, 2, 4, 4, 4, 4, 8, 8, 8, 8, 8, 8, 8, 8, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32}; public static Bitmap LoadScaledBitmap(Context ctx, int resId, float fracX, float fracY) { // See: http://developer.android.com/training/displaying-bitmaps/load-bitmap.html BitmapFactory.Options opts = new BitmapFactory.Options(); opts.inJustDecodeBounds = true; BitmapFactory.decodeResource(ctx.getResources(), resId, opts); int imageHeight = opts.outHeight; int imageWidth = opts.outWidth; float requestX = dispX * fracX, requestY = dispY * fracY; opts.inSampleSize = (int)(Math.min(imageWidth / requestX, imageHeight / requestY)); if (opts.inSampleSize < 0 || opts.inSampleSize > 32) // Sometimes index=2147483647 for some reason... opts.inSampleSize = 1; opts.inSampleSize = sample2sample[opts.inSampleSize]; Log.w("Bitmap Decoder", "Samples: " + opts.inSampleSize); opts.inPreferredConfig = Bitmap.Config.ARGB_8888; //opts.inScaled = false; // Not needed if loading bitmaps from drawable-nodpi opts.inMutable = true; opts.inJustDecodeBounds = false; return BitmapFactory.decodeResource(ctx.getResources(), resId, opts); } public static Bitmap LoadScaledBitmap(String filename, float fracX, float fracY) { // See: http://developer.android.com/training/displaying-bitmaps/load-bitmap.html BitmapFactory.Options opts = new BitmapFactory.Options(); opts.inJustDecodeBounds = true; BitmapFactory.decodeFile(filename, opts); int imageHeight = opts.outHeight; int imageWidth = opts.outWidth; float requestX = dispX * fracX, requestY = dispY * fracY; opts.inSampleSize = (int)(Math.min(imageWidth / requestX, imageHeight / requestY)); if (opts.inSampleSize < 0 || opts.inSampleSize > 32) // Sometimes index=2147483647 for some reason... opts.inSampleSize = 1; opts.inSampleSize = sample2sample[opts.inSampleSize]; Log.w("Bitmap Decoder", "Samples: " + opts.inSampleSize); opts.inPreferredConfig = Bitmap.Config.ARGB_8888; //opts.inScaled = false; // Not needed if loading bitmaps from drawable-nodpi opts.inMutable = true; opts.inJustDecodeBounds = false; return BitmapFactory.decodeFile(filename, opts); } public static String FileNameNow() { SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd_HH-mm-ss", Locale.ENGLISH); return fileDir + sdf.format(new Date()) + ".jpg"; } public static native void ocvBitmapPyramidalBlend(String fNew, String fOld, String fMask, String fBlend, int levels); public static String ocvBitmapPyramidalBlendTimed(int levels) { String fBlend = fileTempBlend;//FileNameNow(); long t = System.nanoTime(); ocvBitmapPyramidalBlend(fileTempNew, fileTempOld, fileTempMask, fBlend, levels); long dt = (System.nanoTime() - t) / 1000; // Microseconds Log.w("OpenCV", "Blended (pyramidal) bitmaps in " + (dt / 1000.0f) + " ms"); //fileLastBlend = fBlend; return fBlend; } public static native void ocvBitmapPreMultAlpha(Bitmap bitmapImg, Bitmap bitmapMask); public static void ocvBitmapPreMultAlphaTimed(Bitmap bitmapImg, Bitmap bitmapMask) { long t = System.nanoTime(); ocvBitmapPreMultAlpha(bitmapImg, bitmapMask); long dt = (System.nanoTime() - t) / 1000; // Microseconds Log.i("Native", "Applied premultiplied alpha to bitmap in " + (dt / 1000.0f) + " ms"); } public static native void ocvBitmapContrastSaturationSet(Bitmap bitmapImg); public static void ocvBitmapContrastSaturationSetTimed(Bitmap bitmapImg) { long t = System.nanoTime(); ocvBitmapContrastSaturationSet(bitmapImg); long dt = (System.nanoTime() - t) / 1000; // Microseconds Log.i("Native", "Assigned contrast/saturation bitmap in " + (dt / 1000.0f) + " ms"); } public static native void ocvBitmapContrastSaturationSrc(Bitmap bitmapImg, Bitmap bitmapSrc, float contrast, float saturation); public static void ocvBitmapContrastSaturationSrcTimed(Bitmap bitmapImg, Bitmap bitmapSrc, float contrast, float saturation) { long t = System.nanoTime(); ocvBitmapContrastSaturationSrc(bitmapImg, bitmapSrc, contrast, saturation); long dt = (System.nanoTime() - t) / 1000; // Microseconds Log.i("Native", "Applied contrast/saturation (from src) to bitmap in " + (dt / 1000.0f) + " ms"); } public static native void ocvBitmapContrastSaturation(Bitmap bitmapImg, float contrast, float saturation); public static void ocvBitmapContrastSaturationTimed(Bitmap bitmapImg, float contrast, float saturation) { long t = System.nanoTime(); ocvBitmapContrastSaturation(bitmapImg, contrast, saturation); long dt = (System.nanoTime() - t) / 1000; // Microseconds Log.i("Native", "Applied contrast/saturation to bitmap in " + (dt / 1000.0f) + " ms"); } } } package il.co.canvasvivapp2u.onceapponatime; import java.io.File; import java.io.FileOutputStream; import java.text.SimpleDateFormat; import java.util.Date; import java.util.Locale; import android.annotation.SuppressLint; import android.app.Activity; import android.content.Context; import android.content.res.Configuration; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.graphics.Point; import android.os.Environment; import android.util.Log; import android.view.Display; public class ShairedResources { public static Bitmap bmpOld = null; public static Bitmap bmpOldScaled = null; public static Bitmap bmpNew = null; public static Bitmap bmpNewScaled = null; public static int scaledX = 0, scaledY = 0; public static int dispX = 0, dispY = 0; public static int fullX = 0, fullY = 0; public static int picX = 0, picY = 0; public static String fileDir = "/OnceAppOnATime/"; public static String fileTempDir = fileDir + "/.temp/"; public static String fileTempNew = fileTempDir + "/temp-new.jpg"; public static String fileTempOld = fileTempDir + "/temp-old.jpg"; public static String fileTempMask = fileTempDir + "/temp-mask.jpg"; public static String fileTempBlend = fileTempDir + "/temp-blend.jpg"; public static String fileTempRetouch = fileTempDir + "/temp-retouch.jpg"; //public static String fileLastBlend = ""; public static BitmapFactory.Options op = new BitmapFactory.Options(); public static Locale localeHebrew = null; public static int taskID = -1; public static boolean Init(Activity activity) { return Init(activity, false); } @SuppressLint("NewApi") @SuppressWairnings("deprecation") public static boolean Init(Activity activity, boolean force) { if (dispX > 0 && dispY > 0) { // Don't re-init to avoid wrong file names if (!force) return false; } else { fileDir = Environment.getExternalStorageDirectory() + fileDir; fileTempDir = Environment.getExternalStorageDirectory() + fileTempDir; fileTempNew = Environment.getExternalStorageDirectory() + fileTempNew; fileTempOld = Environment.getExternalStorageDirectory() + fileTempOld; fileTempMask = Environment.getExternalStorageDirectory() + fileTempMask; fileTempBlend = Environment.getExternalStorageDirectory() + fileTempBlend; fileTempRetouch = Environment.getExternalStorageDirectory() + fileTempRetouch; } taskID = activity.getTaskId(); // Find Hebrew locale, if available Locale availableLocales[] = Locale.getAvailableLocales(); for (int i = 0; i < availableLocales.length; ++i) { String lang = availableLocales[i].getLanguage(); if (lang.equals("he") || lang.equals("iw")) { localeHebrew = availableLocales[i]; break; } } op.inPreferredConfig = Bitmap.Config.ARGB_8888; //op.inScaled = false; // Not needed if loading bitmaps from drawable-nodpi op.inMutable = true; Display display = activity.getWindowManager().getDefaultDisplay(); if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.HONEYCOMB_MR2) { dispX = display.getWidth(); dispY = display.getHeight(); } else { Point dispSize = new Point(); display.getSize(dispSize); dispX = dispSize.x; dispY = dispSize.y; } Log.w("Display Size", dispX + "x" + dispY); //scaledX = dispX / 2; scaledY = dispY / 2; scaledX = dispX; scaledY = dispY; return true; } public static void setLocale(Activity activity, Locale locale) { // This doesn't work reliably Locale.setDefault(locale); Configuration config = new Configuration(); config.locale = locale; activity.getBaseContext().getResources().updateConfiguration(config, activity.getBaseContext().getResources().getDisplayMetrics()); } public static boolean haveScaling() { return (dispX != scaledX || dispY != scaledY); } public static void SaveTempBitmap(Bitmap bitmap, String filename) { try { new File(fileTempDir).mkdirs(); FileOutputStream out = new FileOutputStream(filename); bitmap.compress(Bitmap.CompressFormat.JPEG, 98, out); } catch (Exception e) { e.printStackTrace(); } } public static void RecycleOldBitmaps(boolean full, boolean scaled) { if (full && bmpOld != null) { bmpOld.recycle(); bmpOld = null; } if (scaled && bmpOldScaled != null) { bmpOldScaled.recycle(); bmpOldScaled = null; } } public static void RecycleNewBitmaps(boolean full, boolean scaled) { if (full && bmpNew != null) { bmpNew.recycle(); bmpNew = null; } if (scaled && bmpNewScaled != null) { bmpNewScaled.recycle(); bmpNewScaled = null; } } // 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 public static int sample2sample[] = new int[] {1, 1, 2, 2, 4, 4, 4, 4, 8, 8, 8, 8, 8, 8, 8, 8, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32}; public static Bitmap LoadScaledBitmap(Context ctx, int resId, float fracX, float fracY) { // See: http://developer.android.com/training/displaying-bitmaps/load-bitmap.html BitmapFactory.Options opts = new BitmapFactory.Options(); opts.inJustDecodeBounds = true; BitmapFactory.decodeResource(ctx.getResources(), resId, opts); int imageHeight = opts.outHeight; int imageWidth = opts.outWidth; float requestX = dispX * fracX, requestY = dispY * fracY; opts.inSampleSize = (int)(Math.min(imageWidth / requestX, imageHeight / requestY)); if (opts.inSampleSize < 0 || opts.inSampleSize > 32) // Sometimes index=2147483647 for some reason... opts.inSampleSize = 1; opts.inSampleSize = sample2sample[opts.inSampleSize]; Log.w("Bitmap Decoder", "Samples: " + opts.inSampleSize); opts.inPreferredConfig = Bitmap.Config.ARGB_8888; //opts.inScaled = false; // Not needed if loading bitmaps from drawable-nodpi opts.inMutable = true; opts.inJustDecodeBounds = false; return BitmapFactory.decodeResource(ctx.getResources(), resId, opts); } public static Bitmap LoadScaledBitmap(String filename, float fracX, float fracY) { // See: http://developer.android.com/training/displaying-bitmaps/load-bitmap.html BitmapFactory.Options opts = new BitmapFactory.Options(); opts.inJustDecodeBounds = true; BitmapFactory.decodeFile(filename, opts); int imageHeight = opts.outHeight; int imageWidth = opts.outWidth; float requestX = dispX * fracX, requestY = dispY * fracY; opts.inSampleSize = (int)(Math.min(imageWidth / requestX, imageHeight / requestY)); if (opts.inSampleSize < 0 || opts.inSampleSize > 32) // Sometimes index=2147483647 for some reason... opts.inSampleSize = 1; opts.inSampleSize = sample2sample[opts.inSampleSize]; Log.w("Bitmap Decoder", "Samples: " + opts.inSampleSize); opts.inPreferredConfig = Bitmap.Config.ARGB_8888; //opts.inScaled = false; // Not needed if loading bitmaps from drawable-nodpi opts.inMutable = true; opts.inJustDecodeBounds = false; return BitmapFactory.decodeFile(filename, opts); } public static String FileNameNow() { SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd_HH-mm-ss", Locale.ENGLISH); return fileDir + sdf.format(new Date()) + ".jpg"; } public static native void ocvBitmapPyramidalBlend(String fNew, String fOld, String fMask, String fBlend, int levels); public static String ocvBitmapPyramidalBlendTimed(int levels) { String fBlend = fileTempBlend;//FileNameNow(); long t = System.nanoTime(); ocvBitmapPyramidalBlend(fileTempNew, fileTempOld, fileTempMask, fBlend, levels); long dt = (System.nanoTime() - t) / 1000; // Microseconds Log.w("OpenCV", "Blended (pyramidal) bitmaps in " + (dt / 1000.0f) + " ms"); //fileLastBlend = fBlend; return fBlend; } public static native void ocvBitmapPreMultAlpha(Bitmap bitmapImg, Bitmap bitmapMask); public static void ocvBitmapPreMultAlphaTimed(Bitmap bitmapImg, Bitmap bitmapMask) { long t = System.nanoTime(); ocvBitmapPreMultAlpha(bitmapImg, bitmapMask); long dt = (System.nanoTime() - t) / 1000; // Microseconds Log.i("Native", "Applied premultiplied alpha to bitmap in " + (dt / 1000.0f) + " ms"); } public static native void ocvBitmapContrastSaturationSet(Bitmap bitmapImg); public static void ocvBitmapContrastSaturationSetTimed(Bitmap bitmapImg) { long t = System.nanoTime(); ocvBitmapContrastSaturationSet(bitmapImg); long dt = (System.nanoTime() - t) / 1000; // Microseconds Log.i("Native", "Assigned contrast/saturation bitmap in " + (dt / 1000.0f) + " ms"); } public static native void ocvBitmapContrastSaturationSrc(Bitmap bitmapImg, Bitmap bitmapSrc, float contrast, float saturation); public static void ocvBitmapContrastSaturationSrcTimed(Bitmap bitmapImg, Bitmap bitmapSrc, float contrast, float saturation) { long t = System.nanoTime(); ocvBitmapContrastSaturationSrc(bitmapImg, bitmapSrc, contrast, saturation); long dt = (System.nanoTime() - t) / 1000; // Microseconds Log.i("Native", "Applied contrast/saturation (from src) to bitmap in " + (dt / 1000.0f) + " ms"); } public static native void ocvBitmapContrastSaturation(Bitmap bitmapImg, float contrast, float saturation); public static void ocvBitmapContrastSaturationTimed(Bitmap bitmapImg, float contrast, float saturation) { long t = System.nanoTime(); ocvBitmapContrastSaturation(bitmapImg, contrast, saturation); long dt = (System.nanoTime() - t) / 1000; // Microseconds Log.i("Native", "Applied contrast/saturation to bitmap in " + (dt / 1000.0f) + " ms"); } } } package il.co.canvasvivapp2u.onceapponatime; import java.io.File; import java.io.FileOutputStream; import java.text.SimpleDateFormat; import java.util.Date; import java.util.Locale; import android.annotation.SuppressLint; import android.app.Activity; import android.content.Context; import android.content.res.Configuration; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.graphics.Point; import android.os.Environment; import android.util.Log; import android.view.Display; public class ShairedResources { public static Bitmap bmpOld = null; public static Bitmap bmpOldScaled = null; public static Bitmap bmpNew = null; public static Bitmap bmpNewScaled = null; public static int scaledX = 0, scaledY = 0; public static int dispX = 0, dispY = 0; public static int fullX = 0, fullY = 0; public static int picX = 0, picY = 0; public static String fileDir = "/OnceAppOnATime/"; public static String fileTempDir = fileDir + "/.temp/"; public static String fileTempNew = fileTempDir + "/temp-new.jpg"; public static String fileTempOld = fileTempDir + "/temp-old.jpg"; public static String fileTempMask = fileTempDir + "/temp-mask.jpg"; public static String fileTempBlend = fileTempDir + "/temp-blend.jpg"; public static String fileTempRetouch = fileTempDir + "/temp-retouch.jpg"; //public static String fileLastBlend = ""; public static BitmapFactory.Options op = new BitmapFactory.Options(); public static Locale localeHebrew = null; public static int taskID = -1; public static boolean Init(Activity activity) { return Init(activity, false); } @SuppressLint("NewApi") @SuppressWairnings("deprecation") public static boolean Init(Activity activity, boolean force) { if (dispX > 0 && dispY > 0) { // Don't re-init to avoid wrong file names if (!force) return false; } else { fileDir = Environment.getExternalStorageDirectory() + fileDir; fileTempDir = Environment.getExternalStorageDirectory() + fileTempDir; fileTempNew = Environment.getExternalStorageDirectory() + fileTempNew; fileTempOld = Environment.getExternalStorageDirectory() + fileTempOld; fileTempMask = Environment.getExternalStorageDirectory() + fileTempMask; fileTempBlend = Environment.getExternalStorageDirectory() + fileTempBlend; fileTempRetouch = Environment.getExternalStorageDirectory() + fileTempRetouch; } taskID = activity.getTaskId(); // Find Hebrew locale, if available Locale availableLocales[] = Locale.getAvailableLocales(); for (int i = 0; i < availableLocales.length; ++i) { String lang = availableLocales[i].getLanguage(); if (lang.equals("he") || lang.equals("iw")) { localeHebrew = availableLocales[i]; break; } } op.inPreferredConfig = Bitmap.Config.ARGB_8888; //op.inScaled = false; // Not needed if loading bitmaps from drawable-nodpi op.inMutable = true; Display display = activity.getWindowManager().getDefaultDisplay(); if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.HONEYCOMB_MR2) { dispX = display.getWidth(); dispY = display.getHeight(); } else { Point dispSize = new Point(); display.getSize(dispSize); dispX = dispSize.x; dispY = dispSize.y; } Log.w("Display Size", dispX + "x" + dispY); //scaledX = dispX / 2; scaledY = dispY / 2; scaledX = dispX; scaledY = dispY; return true; } public static void setLocale(Activity activity, Locale locale) { // This doesn't work reliably Locale.setDefault(locale); Configuration config = new Configuration(); config.locale = locale; activity.getBaseContext().getResources().updateConfiguration(config, activity.getBaseContext().getResources().getDisplayMetrics()); } public static boolean haveScaling() { return (dispX != scaledX || dispY != scaledY); } public static void SaveTempBitmap(Bitmap bitmap, String filename) { try { new File(fileTempDir).mkdirs(); FileOutputStream out = new FileOutputStream(filename); bitmap.compress(Bitmap.CompressFormat.JPEG, 98, out); } catch (Exception e) { e.printStackTrace(); } } public static void RecycleOldBitmaps(boolean full, boolean scaled) { if (full && bmpOld != null) { bmpOld.recycle(); bmpOld = null; } if (scaled && bmpOldScaled != null) { bmpOldScaled.recycle(); bmpOldScaled = null; } } public static void RecycleNewBitmaps(boolean full, boolean scaled) { if (full && bmpNew != null) { bmpNew.recycle(); bmpNew = null; } if (scaled && bmpNewScaled != null) { bmpNewScaled.recycle(); bmpNewScaled = null; } } // 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 public static int sample2sample[] = new int[] {1, 1, 2, 2, 4, 4, 4, 4, 8, 8, 8, 8, 8, 8, 8, 8, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32}; public static Bitmap LoadScaledBitmap(Context ctx, int resId, float fracX, float fracY) { // See: http://developer.android.com/training/displaying-bitmaps/load-bitmap.html BitmapFactory.Options opts = new BitmapFactory.Options(); opts.inJustDecodeBounds = true; BitmapFactory.decodeResource(ctx.getResources(), resId, opts); int imageHeight = opts.outHeight; int imageWidth = opts.outWidth; float requestX = dispX * fracX, requestY = dispY * fracY; opts.inSampleSize = (int)(Math.min(imageWidth / requestX, imageHeight / requestY)); if (opts.inSampleSize < 0 || opts.inSampleSize > 32) // Sometimes index=2147483647 for some reason... opts.inSampleSize = 1; opts.inSampleSize = sample2sample[opts.inSampleSize]; Log.w("Bitmap Decoder", "Samples: " + opts.inSampleSize); opts.inPreferredConfig = Bitmap.Config.ARGB_8888; //opts.inScaled = false; // Not needed if loading bitmaps from drawable-nodpi opts.inMutable = true; opts.inJustDecodeBounds = false; return BitmapFactory.decodeResource(ctx.getResources(), resId, opts); } public static Bitmap LoadScaledBitmap(String filename, float fracX, float fracY) { // See: http://developer.android.com/training/displaying-bitmaps/load-bitmap.html BitmapFactory.Options opts = new BitmapFactory.Options(); opts.inJustDecodeBounds = true; BitmapFactory.decodeFile(filename, opts); int imageHeight = opts.outHeight; int imageWidth = opts.outWidth; float requestX = dispX * fracX, requestY = dispY * fracY; opts.inSampleSize = (int)(Math.min(imageWidth / requestX, imageHeight / requestY)); if (opts.inSampleSize < 0 || opts.inSampleSize > 32) // Sometimes index=2147483647 for some reason... opts.inSampleSize = 1; opts.inSampleSize = sample2sample[opts.inSampleSize]; Log.w("Bitmap Decoder", "Samples: " + opts.inSampleSize); opts.inPreferredConfig = Bitmap.Config.ARGB_8888; //opts.inScaled = false; // Not needed if loading bitmaps from drawable-nodpi opts.inMutable = true; opts.inJustDecodeBounds = false; return BitmapFactory.decodeFile(filename, opts); } public static String FileNameNow() { SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd_HH-mm-ss", Locale.ENGLISH); return fileDir + sdf.format(new Date()) + ".jpg"; } public static native void ocvBitmapPyramidalBlend(String fNew, String fOld, String fMask, String fBlend, int levels); public static String ocvBitmapPyramidalBlendTimed(int levels) { String fBlend = fileTempBlend;//FileNameNow(); long t = System.nanoTime(); ocvBitmapPyramidalBlend(fileTempNew, fileTempOld, fileTempMask, fBlend, levels); long dt = (System.nanoTime() - t) / 1000; // Microseconds Log.w("OpenCV", "Blended (pyramidal) bitmaps in " + (dt / 1000.0f) + " ms"); //fileLastBlend = fBlend; return fBlend; } public static native void ocvBitmapPreMultAlpha(Bitmap bitmapImg, Bitmap bitmapMask); public static void ocvBitmapPreMultAlphaTimed(Bitmap bitmapImg, Bitmap bitmapMask) { long t = System.nanoTime(); ocvBitmapPreMultAlpha(bitmapImg, bitmapMask); long dt = (System.nanoTime() - t) / 1000; // Microseconds Log.i("Native", "Applied premultiplied alpha to bitmap in " + (dt / 1000.0f) + " ms"); } public static native void ocvBitmapContrastSaturationSet(Bitmap bitmapImg); public static void ocvBitmapContrastSaturationSetTimed(Bitmap bitmapImg) { long t = System.nanoTime(); ocvBitmapContrastSaturationSet(bitmapImg); long dt = (System.nanoTime() - t) / 1000; // Microseconds Log.i("Native", "Assigned contrast/saturation bitmap in " + (dt / 1000.0f) + " ms"); } public static native void ocvBitmapContrastSaturationSrc(Bitmap bitmapImg, Bitmap bitmapSrc, float contrast, float saturation); public static void ocvBitmapContrastSaturationSrcTimed(Bitmap bitmapImg, Bitmap bitmapSrc, float contrast, float saturation) { long t = System.nanoTime(); ocvBitmapContrastSaturationSrc(bitmapImg, bitmapSrc, contrast, saturation); long dt = (System.nanoTime() - t) / 1000; // Microseconds Log.i("Native", "Applied contrast/saturation (from src) to bitmap in " + (dt / 1000.0f) + " ms"); } public static native void ocvBitmapContrastSaturation(Bitmap bitmapImg, float contrast, float saturation); public static void ocvBitmapContrastSaturationTimed(Bitmap bitmapImg, float contrast, float saturation) { long t = System.nanoTime(); ocvBitmapContrastSaturation(bitmapImg, contrast, saturation); long dt = (System.nanoTime() - t) / 1000; // Microseconds Log.i("Native", "Applied contrast/saturation to bitmap in " + (dt / 1000.0f) + " ms"); } } } package il.co.canvasvivapp2u.onceapponatime; import java.io.File; import java.io.FileOutputStream; import java.text.SimpleDateFormat; import java.util.Date; import java.util.Locale; import android.annotation.SuppressLint; import android.app.Activity; import android.content.Context; import android.content.res.Configuration; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.graphics.Point; import android.os.Environment; import android.util.Log; import android.view.Display; public class ShairedResources { public static Bitmap bmpOld = null; public static Bitmap bmpOldScaled = null; public static Bitmap bmpNew = null; public static Bitmap bmpNewScaled = null; public static int scaledX = 0, scaledY = 0; public static int dispX = 0, dispY = 0; public static int fullX = 0, fullY = 0; public static int picX = 0, picY = 0; public static String fileDir = "/OnceAppOnATime/"; public static String fileTempDir = fileDir + "/.temp/"; public static String fileTempNew = fileTempDir + "/temp-new.jpg"; public static String fileTempOld = fileTempDir + "/temp-old.jpg"; public static String fileTempMask = fileTempDir + "/temp-mask.jpg"; public static String fileTempBlend = fileTempDir + "/temp-blend.jpg"; public static String fileTempRetouch = fileTempDir + "/temp-retouch.jpg"; //public static String fileLastBlend = ""; public static BitmapFactory.Options op = new BitmapFactory.Options(); public static Locale localeHebrew = null; public static int taskID = -1; public static boolean Init(Activity activity) { return Init(activity, false); } @SuppressLint("NewApi") @SuppressWairnings("deprecation") public static boolean Init(Activity activity, boolean force) { if (dispX > 0 && dispY > 0) { // Don't re-init to avoid wrong file names if (!force) return false; } else { fileDir = Environment.getExternalStorageDirectory() + fileDir; fileTempDir = Environment.getExternalStorageDirectory() + fileTempDir; fileTempNew = Environment.getExternalStorageDirectory() + fileTempNew; fileTempOld = Environment.getExternalStorageDirectory() + fileTempOld; fileTempMask = Environment.getExternalStorageDirectory() + fileTempMask; fileTempBlend = Environment.getExternalStorageDirectory() + fileTempBlend; fileTempRetouch = Environment.getExternalStorageDirectory() + fileTempRetouch; } taskID = activity.getTaskId(); // Find Hebrew locale, if available Locale availableLocales[] = Locale.getAvailableLocales(); for (int i = 0; i < availableLocales.length; ++i) { String lang = availableLocales[i].getLanguage(); if (lang.equals("he") || lang.equals("iw")) { localeHebrew = availableLocales[i]; break; } } op.inPreferredConfig = Bitmap.Config.ARGB_8888; //op.inScaled = false; // Not needed if loading bitmaps from drawable-nodpi op.inMutable = true; Display display = activity.getWindowManager().getDefaultDisplay(); if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.HONEYCOMB_MR2) { dispX = display.getWidth(); dispY = display.getHeight(); } else { Point dispSize = new Point(); display.getSize(dispSize); dispX = dispSize.x; dispY = dispSize.y; } Log.w("Display Size", dispX + "x" + dispY); //scaledX = dispX / 2; scaledY = dispY / 2; scaledX = dispX; scaledY = dispY; return true; } public static void setLocale(Activity activity, Locale locale) { // This doesn't work reliably Locale.setDefault(locale); Configuration config = new Configuration(); config.locale = locale; activity.getBaseContext().getResources().updateConfiguration(config, activity.getBaseContext().getResources().getDisplayMetrics()); } public static boolean haveScaling() { return (dispX != scaledX || dispY != scaledY); } public static void SaveTempBitmap(Bitmap bitmap, String filename) { try { new File(fileTempDir).mkdirs(); FileOutputStream out = new FileOutputStream(filename); bitmap.compress(Bitmap.CompressFormat.JPEG, 98, out); } catch (Exception e) { e.printStackTrace(); } } public static void RecycleOldBitmaps(boolean full, boolean scaled) { if (full && bmpOld != null) { bmpOld.recycle(); bmpOld = null; } if (scaled && bmpOldScaled != null) { bmpOldScaled.recycle(); bmpOldScaled = null; } } public static void RecycleNewBitmaps(boolean full, boolean scaled) { if (full && bmpNew != null) { bmpNew.recycle(); bmpNew = null; } if (scaled && bmpNewScaled != null) { bmpNewScaled.recycle(); bmpNewScaled = null; } } // 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 public static int sample2sample[] = new int[] {1, 1, 2, 2, 4, 4, 4, 4, 8, 8, 8, 8, 8, 8, 8, 8, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32}; public static Bitmap LoadScaledBitmap(Context ctx, int resId, float fracX, float fracY) { // See: http://developer.android.com/training/displaying-bitmaps/load-bitmap.html BitmapFactory.Options opts = new BitmapFactory.Options(); opts.inJustDecodeBounds = true; BitmapFactory.decodeResource(ctx.getResources(), resId, opts); int imageHeight = opts.outHeight; int imageWidth = opts.outWidth; float requestX = dispX * fracX, requestY = dispY * fracY; opts.inSampleSize = (int)(Math.min(imageWidth / requestX, imageHeight / requestY)); if (opts.inSampleSize < 0 || opts.inSampleSize > 32) // Sometimes index=2147483647 for some reason... opts.inSampleSize = 1; opts.inSampleSize = sample2sample[opts.inSampleSize]; Log.w("Bitmap Decoder", "Samples: " + opts.inSampleSize); opts.inPreferredConfig = Bitmap.Config.ARGB_8888; //opts.inScaled = false; // Not needed if loading bitmaps from drawable-nodpi opts.inMutable = true; opts.inJustDecodeBounds = false; return BitmapFactory.decodeResource(ctx.getResources(), resId, opts); } public static Bitmap LoadScaledBitmap(String filename, float fracX, float fracY) { // See: http://developer.android.com/training/displaying-bitmaps/load-bitmap.html BitmapFactory.Options opts = new BitmapFactory.Options(); opts.inJustDecodeBounds = true; BitmapFactory.decodeFile(filename, opts); int imageHeight = opts.outHeight; int imageWidth = opts.outWidth; float requestX = dispX * fracX, requestY = dispY * fracY; opts.inSampleSize = (int)(Math.min(imageWidth / requestX, imageHeight / requestY)); if (opts.inSampleSize < 0 || opts.inSampleSize > 32) // Sometimes index=2147483647 for some reason... opts.inSampleSize = 1; opts.inSampleSize = sample2sample[opts.inSampleSize]; Log.w("Bitmap Decoder", "Samples: " + opts.inSampleSize); opts.inPreferredConfig = Bitmap.Config.ARGB_8888; //opts.inScaled = false; // Not needed if loading bitmaps from drawable-nodpi opts.inMutable = true; opts.inJustDecodeBounds = false; return BitmapFactory.decodeFile(filename, opts); } public static String FileNameNow() { SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd_HH-mm-ss", Locale.ENGLISH); return fileDir + sdf.format(new Date()) + ".jpg"; } public static native void ocvBitmapPyramidalBlend(String fNew, String fOld, String fMask, String fBlend, int levels); public static String ocvBitmapPyramidalBlendTimed(int levels) { String fBlend = fileTempBlend;//FileNameNow(); long t = System.nanoTime(); ocvBitmapPyramidalBlend(fileTempNew, fileTempOld, fileTempMask, fBlend, levels); long dt = (System.nanoTime() - t) / 1000; // Microseconds Log.w("OpenCV", "Blended (pyramidal) bitmaps in " + (dt / 1000.0f) + " ms"); //fileLastBlend = fBlend; return fBlend; } public static native void ocvBitmapPreMultAlpha(Bitmap bitmapImg, Bitmap bitmapMask); public static void ocvBitmapPreMultAlphaTimed(Bitmap bitmapImg, Bitmap bitmapMask) { long t = System.nanoTime(); ocvBitmapPreMultAlpha(bitmapImg, bitmapMask); long dt = (System.nanoTime() - t) / 1000; // Microseconds Log.i("Native", "Applied premultiplied alpha to bitmap in " + (dt / 1000.0f) + " ms"); } public static native void ocvBitmapContrastSaturationSet(Bitmap bitmapImg); public static void ocvBitmapContrastSaturationSetTimed(Bitmap bitmapImg) { long t = System.nanoTime(); ocvBitmapContrastSaturationSet(bitmapImg); long dt = (System.nanoTime() - t) / 1000; // Microseconds Log.i("Native", "Assigned contrast/saturation bitmap in " + (dt / 1000.0f) + " ms"); } public static native void ocvBitmapContrastSaturationSrc(Bitmap bitmapImg, Bitmap bitmapSrc, float contrast, float saturation); public static void ocvBitmapContrastSaturationSrcTimed(Bitmap bitmapImg, Bitmap bitmapSrc, float contrast, float saturation) { long t = System.nanoTime(); ocvBitmapContrastSaturationSrc(bitmapImg, bitmapSrc, contrast, saturation); long dt = (System.nanoTime() - t) / 1000; // Microseconds Log.i("Native", "Applied contrast/saturation (from src) to bitmap in " + (dt / 1000.0f) + " ms"); } public static native void ocvBitmapContrastSaturation(Bitmap bitmapImg, float contrast, float saturation); public static void ocvBitmapContrastSaturationTimed(Bitmap bitmapImg, float contrast, float saturation) { long t = System.nanoTime(); ocvBitmapContrastSaturation(bitmapImg, contrast, saturation); long dt = (System.nanoTime() - t) / 1000; // Microseconds Log.i("Native", "Applied contrast/saturation to bitmap in " + (dt / 1000.0f) + " ms"); } } 

    Também right click on project - >Android Tools -> Add Native Support

     Add Native Support is missing. I have Android Native Development Tools installed. Then also it's missing. 

  • Erro de renderização da gaveta de navigation no ADT Layout Editor
  • Android: Desenhe o círculo com o interior do text
  • Implementação do Gradle viewsus configuration da API
  • O "Bitmap.createScaledBitmap" conviewte uma image de 32 bits em 24 bits?
  • Salvando CookieStore no service de cliente http
  • Android desenha text em retângulo no centro e coloque-o se necessário
  • 2 Solutions collect form web for “Não é possível executair o programa "\ ndk-build.cmd": o lançamento falhou”

    UnsatisfiedLinked error é devido a ponte quebrada entre class java e class c; O nome do método em java deve corresponder ao método na class C / c ++. Enquanto a compilation da ponte é criada entre Java e c / c ++, então, se o nome do método não estiview correto, ele não responderá. exemplo está seguindo o nome do método que a injava está seguindo

     public native String Stub(){} 

    isso deve ser o mesmo no JNI, mas com seu aplicativo nome do package + nome da stack + nome do método como segue

     JNIEXPORT jstring JNICALL Java_com_packageName_ClassName_MethodName 

    O erro-key é "Não é possível executair o programa" ndk-build ": O lançamento falhou". Se isso não for executado, o .so não é construído, o que resulta no UnsatisfiedLinkError. Resolva primeiro o problema ndk-build.

    Tente remoview o '\' inicial de "\ ndk-build.cmd". Quando eu lanço "ndk-build.cmd", funciona.

    Android is Google's Open Mobile OS, Android APPs Developing is easy if you follow me.