Ir a la documentación de este archivo.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00025 package com.googlecode.leptonica.android;
00026
00032 public class Scale {
00033 static {
00034 System.loadLibrary("lept");
00035 }
00036
00037 public enum ScaleType {
00042 FILL,
00043
00049 FIT,
00050
00056 FIT_SHRINK,
00057 }
00058
00070 public static Pix scaleToSize(Pix pixs, int width, int height,
00071 ScaleType type) {
00072 if (pixs == null)
00073 throw new IllegalArgumentException("Source pix must be non-null");
00074
00075 int pixWidth = pixs.getWidth();
00076 int pixHeight = pixs.getHeight();
00077
00078 float scaleX = width / (float) pixWidth;
00079 float scaleY = height / (float) pixHeight;
00080
00081 switch (type) {
00082 case FILL:
00083
00084 break;
00085 case FIT:
00086 scaleX = Math.min(scaleX, scaleY);
00087 scaleY = scaleX;
00088 break;
00089 case FIT_SHRINK:
00090 scaleX = Math.min(1.0f, Math.min(scaleX, scaleY));
00091 scaleY = scaleX;
00092 break;
00093 }
00094
00095 return scale(pixs, scaleX, scaleY);
00096 }
00097
00108 public static Pix scale(Pix pixs, float scale) {
00109 return scale(pixs, scale, scale);
00110 }
00111
00124 public static Pix scale(Pix pixs, float scaleX, float scaleY) {
00125 if (pixs == null)
00126 throw new IllegalArgumentException("Source pix must be non-null");
00127 if (scaleX <= 0.0f)
00128 throw new IllegalArgumentException(
00129 "X scaling factor must be positive");
00130 if (scaleY <= 0.0f)
00131 throw new IllegalArgumentException(
00132 "Y scaling factor must be positive");
00133
00134 int nativePix = nativeScale(pixs.mNativePix, scaleX, scaleY);
00135
00136 if (nativePix == 0)
00137 throw new RuntimeException("Failed to natively scale pix");
00138
00139 return new Pix(nativePix);
00140 }
00141
00142
00143
00144
00145
00146 private static native int nativeScale(int nativePix, float scaleX,
00147 float scaleY);
00148 }