Skip to content
Browse files

Update build files. Remove ZXing code.

  • Loading branch information...
1 parent 8489893 commit 173f0a6c07f2fa77d15ca4c67118523aedaec71f @jfinkhaeuser committed Jan 28, 2012
View
18 ant.properties
@@ -0,0 +1,18 @@
+# This file is used to override default values used by the Ant build system.
+#
+# This file must be checked in Version Control Systems, as it is
+# integral to the build system of your project.
+
+# This file is only used by the Ant script.
+
+# You can use this to override default values such as
+# 'source.dir' for the location of your java source folder and
+# 'out.dir' for the location of your output folder.
+
+# You can also use it define how the release builds are signed by declaring
+# the following properties:
+# 'key.store' for the location of your keystore and
+# 'key.alias' for the name of the key to use.
+# The password will be asked during the build when you use the 'release' target.
+
+application-package=de.unwesen.packrat
View
21 build.properties
@@ -1,21 +0,0 @@
-# This file is part of PackRat, an android program for managing media collections.
-# Copyright (C) 2009 Jens Finkhaeuser <unwesen@users.sourceforge.net>
-# All rights reserved.
-#
-# $Id$
-
-# This file is used to override default values used by the Ant build system.
-#
-# This file must be checked in Version Control Systems, as it is
-# integral to the build system of your project.
-
-# The name of your application package as defined in the manifest.
-# Used by the 'uninstall' rule.
-application-package=de.unwesen.packrat
-
-# The name of the source folder.
-#source-folder=src
-
-# The name of the output folder.
-#out-folder=bin
-
View
195 build.xml
@@ -1,160 +1,85 @@
<?xml version="1.0" encoding="UTF-8"?>
-<!--
- This file is part of PackRat, an android program for managing media collections.
- Copyright (C) 2009 Jens Finkhaeuser <unwesen@users.sourceforge.net>
- All rights reserved.
-
- $Id$
--->
<project name="PackRat" default="help">
<!-- The local.properties file is created and updated by the 'android' tool.
- It contains the path to the SDK. It should *NOT* be checked in in Version
- Control Systems. -->
+ It contains the path to the SDK. It should *NOT* be checked into
+ Version Control Systems. -->
<property file="local.properties" />
- <!-- The build.properties file can be created by you and is never touched
- by the 'android' tool. This is the place to change some of the default property values
- used by the Ant rules.
+ <!-- The ant.properties file can be created by you. It is only edited by the
+ 'android' tool to add properties to it.
+ This is the place to change some Ant specific build properties.
Here are some properties you may want to change/update:
- application.package
- the name of your application package as defined in the manifest. Used by the
- 'uninstall' rule.
source.dir
- the name of the source directory. Default is 'src'.
+ The name of the source directory. Default is 'src'.
out.dir
- the name of the output directory. Default is 'bin'.
+ The name of the output directory. Default is 'bin'.
- Properties related to the SDK location or the project target should be updated
- using the 'android' tool with the 'update' action.
+ For other overridable properties, look at the beginning of the rules
+ files in the SDK, at tools/ant/build.xml
- This file is an integral part of the build system for your application and
- should be checked in in Version Control Systems.
+ Properties related to the SDK location or the project target should
+ be updated using the 'android' tool with the 'update' action.
+
+ This file is an integral part of the build system for your
+ application and should be checked into Version Control Systems.
-->
- <property file="build.properties" />
-
- <!-- The default.properties file is created and updated by the 'android' tool, as well
- as ADT.
- This file is an integral part of the build system for your application and
- should be checked in in Version Control Systems. -->
- <property file="default.properties" />
-
- <!-- Custom Android task to deal with the project target, and import the proper rules.
- This requires ant 1.6.0 or above. -->
- <path id="android.antlibs">
- <pathelement path="${sdk.dir}/tools/lib/anttasks.jar" />
- <pathelement path="${sdk.dir}/tools/lib/sdklib.jar" />
- <pathelement path="${sdk.dir}/tools/lib/androidprefs.jar" />
- <pathelement path="${sdk.dir}/tools/lib/apkbuilder.jar" />
- <pathelement path="${sdk.dir}/tools/lib/jarutils.jar" />
- </path>
-
- <taskdef name="setup"
- classname="com.android.ant.SetupTask"
- classpathref="android.antlibs" />
-
- <!-- Execute the Android Setup task that will setup some properties specific to the target,
- and import the build rules files.
-
- The rules file is imported from
- <SDK>/platforms/<target_platform>/templates/android_rules.xml
-
- To customize some build steps for your project:
- - copy the content of the main node <project> from android_rules.xml
- - paste it in this build.xml below the <setup /> task.
- - disable the import by changing the setup task below to <setup import="false" />
-
- This will ensure that the properties are setup correctly but that your customized
- build steps are used.
- -->
- <setup />
-
- <!-- Root directory -->
- <property name="root.dir" value="${gen.absolute.dir}/.." />
- <property name="root.absolute.dir" location="${root.dir}" />
-
- <!-- Create the output directories if they don't exist yet. -->
- <target name="-real-dirs">
- <echo>Creating output directories if needed...</echo>
- <mkdir dir="${resource.absolute.dir}" />
- <mkdir dir="${jar.libs.absolute.dir}" />
- <mkdir dir="${gen.absolute.dir}" />
- <mkdir dir="${out.absolute.dir}" />
- <mkdir dir="${out.classes.absolute.dir}" />
- </target>
+ <property file="ant.properties" />
- <!-- unwesen lib target -->
- <property name="unwesenlib.absolute.dir" location="externals/unwesen" />
+ <!-- The project.properties file is created and updated by the 'android'
+ tool, as well as ADT.
- <target name="unwesenlib.check" depends="-real-dirs">
- <condition property="unwesenlib.exists">
- <and>
- <available file="${jar.libs.absolute.dir}/unwesen.jar" />
- </and>
- </condition>
- </target>
+ This contains project specific properties such as project target, and library
+ dependencies. Lower level build properties are stored in ant.properties
+ (or in .classpath for Eclipse projects).
- <target name="-unwesenlib" depends="-real-dirs, unwesenlib.check" unless="unwesenlib.exists">
- <echo>Building unwesen library...</echo>
- <ant
- antfile="build.xml"
- dir="${unwesenlib.absolute.dir}"
- target="build"
- inheritAll="false"
- >
- <property name="sdk.dir" value="${sdk.dir}" />
- </ant>
-
- <ant
- antfile="build.xml"
- dir="${unwesenlib.absolute.dir}"
- target="install"
- inheritAll="false"
- >
- <property name="sdk.dir" value="${sdk.dir}" />
- <property name="install.dir" value="${root.absolute.dir}" />
- </ant>
- </target>
+ This file is an integral part of the build system for your
+ application and should be checked into Version Control Systems. -->
+ <loadproperties srcFile="project.properties" />
- <!-- ZXing target -->
- <target name="zxing.check" depends="-real-dirs">
- <condition property="zxing.exists">
- <and>
- <available file="${jar.libs.absolute.dir}/core.jar" />
- </and>
- </condition>
- </target>
+ <!-- quick check on sdk.dir -->
+ <fail
+ message="sdk.dir is missing. Make sure to generate local.properties using 'android update project' or to inject it through an env var"
+ unless="sdk.dir"
+ />
- <target name="-zxing" depends="-real-dirs, zxing.check" unless="zxing.exists">
- <echo>Building ZXing library...</echo>
- <ant
- antfile="build.xml"
- dir="externals/zxing/core"
- target="build-no-debug"
- />
- <copy todir="${jar.libs.absolute.dir}" file="externals/zxing/core/core.jar"/>
- </target>
- <!-- GA target -->
- <target name="-analytics" depends="-real-dirs">
- <echo>Copying Google Analytics library...</echo>
- <copy todir="${jar.libs.absolute.dir}" file="externals/GoogleAnalyticsAndroid/libGoogleAnalytics.jar"/>
+<!-- extension targets. Uncomment the ones where you want to do custom work
+ in between standard targets -->
+<!--
+ <target name="-pre-build">
+ </target>
+ <target name="-pre-compile">
</target>
- <!-- Bootstrap target -->
- <target name="-bootstrap" depends="-zxing, -analytics, -unwesenlib" />
-
- <!-- Override "-dirs" target that is referenced from other targets. Just depends on
- bootstrap, to kickstart our own stuff here. -->
- <target name="-dirs" depends="-bootstrap" />
+ /* This is typically used for code obfuscation.
+ Compiled code location: ${out.classes.absolute.dir}
+ If this is not done in place, override ${out.dex.input.absolute.dir} */
+ <target name="-post-compile">
+ </target>
+-->
+ <!-- Import the actual build file.
+
+ To customize existing targets, there are two options:
+ - Customize only one target:
+ - copy/paste the target into this file, *before* the
+ <import> task.
+ - customize it to your needs.
+ - Customize the whole content of build.xml
+ - copy/paste the content of the rules files (minus the top node)
+ into this file, replacing the <import> task.
+ - customize to your needs.
+
+ ***********************
+ ****** IMPORTANT ******
+ ***********************
+ In all cases you must update the value of version-tag below to read 'custom' instead of an integer,
+ in order to avoid having your file be overridden by tools such as "android update project"
+ -->
+ <!-- version-tag: 1 -->
+ <import file="${sdk.dir}/tools/ant/build.xml" />
- <!-- Override "clean" target to also clean unwesen.jar -->
- <target name="clean" description="Removes output files created by other targets.">
- <delete dir="${out.absolute.dir}" verbose="${verbose}" />
- <delete dir="${gen.absolute.dir}" verbose="${verbose}" />
- <delete file="${jar.libs.absolute.dir}/unwesen.jar" verbose="${verbose}" />
- </target>
</project>
View
40 proguard.cfg
@@ -0,0 +1,40 @@
+-optimizationpasses 5
+-dontusemixedcaseclassnames
+-dontskipnonpubliclibraryclasses
+-dontpreverify
+-verbose
+-optimizations !code/simplification/arithmetic,!field/*,!class/merging/*
+
+-keep public class * extends android.app.Activity
+-keep public class * extends android.app.Application
+-keep public class * extends android.app.Service
+-keep public class * extends android.content.BroadcastReceiver
+-keep public class * extends android.content.ContentProvider
+-keep public class * extends android.app.backup.BackupAgentHelper
+-keep public class * extends android.preference.Preference
+-keep public class com.android.vending.licensing.ILicensingService
+
+-keepclasseswithmembernames class * {
+ native <methods>;
+}
+
+-keepclasseswithmembers class * {
+ public <init>(android.content.Context, android.util.AttributeSet);
+}
+
+-keepclasseswithmembers class * {
+ public <init>(android.content.Context, android.util.AttributeSet, int);
+}
+
+-keepclassmembers class * extends android.app.Activity {
+ public void *(android.view.View);
+}
+
+-keepclassmembers enum * {
+ public static **[] values();
+ public static ** valueOf(java.lang.String);
+}
+
+-keep class * implements android.os.Parcelable {
+ public static final android.os.Parcelable$Creator *;
+}
View
6 default.properties → project.properties
@@ -1,10 +1,10 @@
# This file is automatically generated by Android Tools.
# Do not modify this file -- YOUR CHANGES WILL BE ERASED!
-#
+#
# This file must be checked in Version Control Systems.
-#
+#
# To customize properties used by the Ant build system use,
-# "build.properties", and override values to adapt the script to your
+# "ant.properties", and override values to adapt the script to your
# project structure.
# Project target.
View
62 src/com/google/zxing/client/android/BaseLuminanceSource.java
@@ -1,62 +0,0 @@
-/*
- * Copyright 2009 ZXing authors
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.google.zxing.client.android;
-
-import com.google.zxing.LuminanceSource;
-
-import android.graphics.Bitmap;
-
-/**
- * An extension of LuminanceSource which adds some Android-specific methods.
- *
- * @author dswitkin@google.com (Daniel Switkin)
- */
-public abstract class BaseLuminanceSource extends LuminanceSource {
-
- BaseLuminanceSource(int width, int height) {
- super(width, height);
- }
-
- /**
- * Requests the width of the underlying platform's bitmap.
- *
- * @return The width in pixels.
- */
- public abstract int getDataWidth();
-
- /**
- * Requests the height of the underlying platform's bitmap.
- *
- * @return The height in pixels.
- */
- public abstract int getDataHeight();
-
- /**
- * Creates a greyscale Android Bitmap from the YUV data based on the crop rectangle.
- *
- * @return An 8888 bitmap.
- */
- public abstract Bitmap renderCroppedGreyscaleBitmap();
-
- /**
- * Creates a color Android Bitmap from the YUV data, ignoring the crop rectangle.
- *
- * @param halfSize If true, downsample to 50% in each dimension, otherwise not.
- * @return An 8888 bitmap.
- */
- public abstract Bitmap renderFullColorBitmap(boolean halfSize);
-}
View
343 src/com/google/zxing/client/android/CameraManager.java
@@ -1,343 +0,0 @@
-/*
- * Copyright (C) 2008 ZXing authors
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.google.zxing.client.android;
-
-import com.google.zxing.ResultPoint;
-
-import android.content.Context;
-import android.graphics.PixelFormat;
-import android.graphics.Point;
-import android.graphics.Rect;
-import android.hardware.Camera;
-import android.os.Build;
-import android.os.Handler;
-import android.os.Message;
-import android.util.Log;
-import android.view.Display;
-import android.view.SurfaceHolder;
-import android.view.WindowManager;
-
-import java.io.IOException;
-
-/**
- * This object wraps the Camera service object and expects to be the only one talking to it. The
- * implementation encapsulates the steps needed to take preview-sized images, which are used for
- * both preview and decoding.
- *
- * @author dswitkin@google.com (Daniel Switkin)
- */
-public class CameraManager {
- private static final String TAG = "CameraManager";
- private static final int MIN_FRAME_WIDTH = 240;
- private static final int MIN_FRAME_HEIGHT = 240;
- private static final int MAX_FRAME_WIDTH = 480;
- private static final int MAX_FRAME_HEIGHT = 360;
-
- private static CameraManager cameraManager;
- private Camera camera;
- private final Context context;
- private Point screenResolution;
- private Point cameraResolution;
- private Rect framingRect;
- private Handler previewHandler;
- private int previewMessage;
- private Handler autoFocusHandler;
- private int autoFocusMessage;
- private boolean initialized;
- private boolean previewing;
- private int previewFormat;
- private String previewFormatString;
- private boolean useOneShotPreviewCallback;
-
- /**
- * Preview frames are delivered here, which we pass on to the registered handler. Make sure to
- * clear the handler so it will only receive one message.
- */
- private final Camera.PreviewCallback previewCallback = new Camera.PreviewCallback() {
- public void onPreviewFrame(byte[] data, Camera camera) {
- if (!useOneShotPreviewCallback) {
- camera.setPreviewCallback(null);
- }
- if (previewHandler != null) {
- Message message = previewHandler.obtainMessage(previewMessage, cameraResolution.x,
- cameraResolution.y, data);
- message.sendToTarget();
- previewHandler = null;
- }
- }
- };
-
- /**
- * Autofocus callbacks arrive here, and are dispatched to the Handler which requested them.
- */
- private final Camera.AutoFocusCallback autoFocusCallback = new Camera.AutoFocusCallback() {
- public void onAutoFocus(boolean success, Camera camera) {
- if (autoFocusHandler != null) {
- Message message = autoFocusHandler.obtainMessage(autoFocusMessage, success);
- // Simulate continuous autofocus by sending a focus request every 1.5 seconds.
- autoFocusHandler.sendMessageDelayed(message, 1500L);
- autoFocusHandler = null;
- }
- }
- };
-
- /**
- * Initializes this static object with the Context of the calling Activity.
- *
- * @param context The Activity which wants to use the camera.
- */
- public static void init(Context context) {
- if (cameraManager == null) {
- cameraManager = new CameraManager(context);
- }
- }
-
- /**
- * Gets the CameraManager singleton instance.
- *
- * @return A reference to the CameraManager singleton.
- */
- public static CameraManager get() {
- return cameraManager;
- }
-
- private CameraManager(Context context) {
- this.context = context;
- camera = null;
- initialized = false;
- previewing = false;
-
- // Camera.setOneShotPreviewCallback() has a race condition in Cupcake, so we use the older
- // Camera.setPreviewCallback() on 1.5 and earlier. For Donut and later, we need to use
- // the more efficient one shot callback, as the older one can swamp the system and cause it
- // to run out of memory. We can't use SDK_INT because it was introduced in the Donut SDK.
- if (Integer.parseInt(Build.VERSION.SDK) <= Build.VERSION_CODES.CUPCAKE) {
- useOneShotPreviewCallback = false;
- } else {
- useOneShotPreviewCallback = true;
- }
- }
-
- /**
- * Opens the camera driver and initializes the hardware parameters.
- *
- * @param holder The surface object which the camera will draw preview frames into.
- * @throws IOException Indicates the camera driver failed to open.
- */
- public void openDriver(SurfaceHolder holder) throws IOException {
- if (camera == null) {
- camera = Camera.open();
- camera.setPreviewDisplay(holder);
-
- if (!initialized) {
- initialized = true;
- getScreenResolution();
- }
-
- setCameraParameters();
- }
- }
-
- /**
- * Closes the camera driver if still in use.
- */
- public void closeDriver() {
- if (camera != null) {
- camera.release();
- camera = null;
- }
- }
-
- /**
- * Asks the camera hardware to begin drawing preview frames to the screen.
- */
- public void startPreview() {
- if (camera != null && !previewing) {
- camera.startPreview();
- previewing = true;
- }
- }
-
- /**
- * Tells the camera to stop drawing preview frames.
- */
- public void stopPreview() {
- if (camera != null && previewing) {
- if (!useOneShotPreviewCallback) {
- camera.setPreviewCallback(null);
- }
- camera.stopPreview();
- previewHandler = null;
- autoFocusHandler = null;
- previewing = false;
- }
- }
-
- /**
- * A single preview frame will be returned to the handler supplied. The data will arrive as byte[]
- * in the message.obj field, with width and height encoded as message.arg1 and message.arg2,
- * respectively.
- *
- * @param handler The handler to send the message to.
- * @param message The what field of the message to be sent.
- */
- public void requestPreviewFrame(Handler handler, int message) {
- if (camera != null && previewing) {
- previewHandler = handler;
- previewMessage = message;
- if (useOneShotPreviewCallback) {
- camera.setOneShotPreviewCallback(previewCallback);
- } else {
- camera.setPreviewCallback(previewCallback);
- }
- }
- }
-
- /**
- * Asks the camera hardware to perform an autofocus.
- *
- * @param handler The Handler to notify when the autofocus completes.
- * @param message The message to deliver.
- */
- public void requestAutoFocus(Handler handler, int message) {
- if (camera != null && previewing) {
- autoFocusHandler = handler;
- autoFocusMessage = message;
- camera.autoFocus(autoFocusCallback);
- }
- }
-
- /**
- * Calculates the framing rect which the UI should draw to show the user where to place the
- * barcode. This target helps with alignment as well as forces the user to hold the device
- * far enough away to ensure the image will be in focus.
- *
- * @return The rectangle to draw on screen in window coordinates.
- */
- public Rect getFramingRect() {
- if (framingRect == null) {
- if (camera == null) {
- return null;
- }
- int width = cameraResolution.x * 3 / 4;
- if (width < MIN_FRAME_WIDTH) {
- width = MIN_FRAME_WIDTH;
- } else if (width > MAX_FRAME_WIDTH) {
- width = MAX_FRAME_WIDTH;
- }
- int height = cameraResolution.y * 3 / 4;
- if (height < MIN_FRAME_HEIGHT) {
- height = MIN_FRAME_HEIGHT;
- } else if (height > MAX_FRAME_HEIGHT) {
- height = MAX_FRAME_HEIGHT;
- }
- int leftOffset = (cameraResolution.x - width) / 2;
- int topOffset = (cameraResolution.y - height) / 2;
- framingRect = new Rect(leftOffset, topOffset, leftOffset + width, topOffset + height);
- Log.v(TAG, "Calculated framing rect: " + framingRect);
- }
- return framingRect;
- }
-
- /**
- * Converts the result points from still resolution coordinates to screen coordinates.
- *
- * @param points The points returned by the Reader subclass through Result.getResultPoints().
- * @return An array of Points scaled to the size of the framing rect and offset appropriately
- * so they can be drawn in screen coordinates.
- */
- public Point[] convertResultPoints(ResultPoint[] points) {
- Rect frame = getFramingRect();
- int count = points.length;
- Point[] output = new Point[count];
- for (int x = 0; x < count; x++) {
- output[x] = new Point();
- output[x].x = frame.left + (int) (points[x].getX() + 0.5f);
- output[x].y = frame.top + (int) (points[x].getY() + 0.5f);
- }
- return output;
- }
-
- /**
- * A factory method to build the appropriate LuminanceSource object based on the format
- * of the preview buffers, as described by Camera.Parameters.
- *
- * @param data A preview frame.
- * @param width The width of the image.
- * @param height The height of the image.
- * @return A BaseLuminanceSource subclass.
- */
- public BaseLuminanceSource buildLuminanceSource(byte[] data, int width, int height) {
- Rect rect = getFramingRect();
- switch (previewFormat) {
- case PixelFormat.YCbCr_420_SP:
- case PixelFormat.YCbCr_422_SP:
- return new PlanarYUVLuminanceSource(data, width, height, rect.left, rect.top,
- rect.width(), rect.height());
- default:
- // There's no PixelFormat constant for this buffer format yet.
- if (previewFormatString.equals("yuv422i-yuyv")) {
- return new InterleavedYUV422LuminanceSource(data, width, height, rect.left, rect.top,
- rect.width(), rect.height());
- }
- break;
- }
- return null;
- }
-
- /**
- * Sets the camera up to take preview images which are used for both preview and decoding.
- * We detect the preview format here so that buildLuminanceSource() can build an appropriate
- * LuminanceSource subclass. In the future we may want to force YUV420SP as it's the smallest,
- * and the planar Y can be used for barcode scanning without a copy in some cases.
- */
- private void setCameraParameters() {
- Camera.Parameters parameters = camera.getParameters();
- Camera.Size size = parameters.getPreviewSize();
- Log.v(TAG, "Default preview size: " + size.width + ", " + size.height);
- previewFormat = parameters.getPreviewFormat();
- previewFormatString = parameters.get("preview-format");
- Log.v(TAG, "Default preview format: " + previewFormat);
-
- // Ensure that the camera resolution is a multiple of 8, as the screen may not be.
- // TODO: A better solution would be to request the supported preview resolutions
- // and pick the best match, but this parameter is not standardized in Cupcake.
- cameraResolution = new Point();
- cameraResolution.x = (screenResolution.x >> 3) << 3;
- cameraResolution.y = (screenResolution.y >> 3) << 3;
- Log.v(TAG, "Setting preview size: " + cameraResolution.x + ", " + cameraResolution.y);
- parameters.setPreviewSize(cameraResolution.x, cameraResolution.y);
-
- // FIXME: This is a hack to turn the flash off on the Samsung Galaxy.
- parameters.set("flash-value", 2);
-
- // This is the standard setting to turn the flash off that all devices should honor.
- parameters.set("flash-mode", "off");
-
- camera.setParameters(parameters);
- }
-
- private Point getScreenResolution() {
- if (screenResolution == null) {
- WindowManager manager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
- Display display = manager.getDefaultDisplay();
- screenResolution = new Point(display.getWidth(), display.getHeight());
- }
- return screenResolution;
- }
-
-}
View
139 src/com/google/zxing/client/android/InterleavedYUV422LuminanceSource.java
@@ -1,139 +0,0 @@
-/*
- * Copyright 2009 ZXing authors
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.google.zxing.client.android;
-
-import com.google.zxing.LuminanceSource;
-
-import android.graphics.Bitmap;
-
-/**
- * This object extends LuminanceSource around an array of YUV data returned from the camera driver,
- * with the option to crop to a rectangle within the full data. This can be used to exclude
- * superfluous pixels around the perimeter and speed up decoding.
- *
- * It handles YUV 422 interleaved data, where each pixel consists of first a Y value, then
- * a color value, with U and V alternating at each pixel.
- *
- * @author dswitkin@google.com (Daniel Switkin)
- */
-public final class InterleavedYUV422LuminanceSource extends BaseLuminanceSource {
- private final byte[] yuvData;
- private final int dataWidth;
- private final int dataHeight;
- private final int left;
- private final int top;
-
- public InterleavedYUV422LuminanceSource(byte[] yuvData, int dataWidth, int dataHeight,
- int left, int top, int width, int height) {
- super(width, height);
-
- if (left + width > dataWidth || top + height > dataHeight) {
- throw new IllegalArgumentException("Crop rectangle does not fit within image data.");
- }
-
- this.yuvData = yuvData;
- this.dataWidth = dataWidth;
- this.dataHeight = dataHeight;
- this.left = left;
- this.top = top;
- }
-
- @Override
- public byte[] getRow(int y, byte[] row) {
- if (y < 0 || y >= getHeight()) {
- throw new IllegalArgumentException("Requested row is outside the image: " + y);
- }
- int width = getWidth();
- if (row == null || row.length < width) {
- row = new byte[width];
- }
- int offset = (y + top) * dataWidth * 2 + (left * 2);
- byte[] yuv = yuvData;
- for (int x = 0; x < width; x++) {
- row[x] = yuv[offset + (x << 1)];
- }
- return row;
- }
-
- @Override
- public byte[] getMatrix() {
- int width = getWidth();
- int height = getHeight();
- int area = width * height;
- byte[] matrix = new byte[area];
- int inputOffset = top * dataWidth * 2 + (left * 2);
- byte[] yuv = yuvData;
-
- for (int y = 0; y < height; y++) {
- int outputOffset = y * width;
- for (int x = 0; x < width; x++) {
- matrix[outputOffset + x] = yuv[inputOffset + (x << 1)];
- }
- inputOffset += (dataWidth * 2);
- }
- return matrix;
- }
-
- @Override
- public boolean isCropSupported() {
- return true;
- }
-
- @Override
- public LuminanceSource crop(int left, int top, int width, int height) {
- return new InterleavedYUV422LuminanceSource(yuvData, dataWidth, dataHeight, left, top,
- width, height);
- }
-
- @Override
- public int getDataWidth() {
- return dataWidth;
- }
-
- @Override
- public int getDataHeight() {
- return dataHeight;
- }
-
- @Override
- public Bitmap renderCroppedGreyscaleBitmap() {
- int width = getWidth();
- int height = getHeight();
- int[] pixels = new int[width * height];
- byte[] yuv = yuvData;
- int inputOffset = top * dataWidth * 2 + (left * 2);
-
- for (int y = 0; y < height; y++) {
- int outputOffset = y * width;
- for (int x = 0; x < width; x++) {
- int grey = yuv[inputOffset + (x << 1)] & 0xff;
- pixels[outputOffset + x] = (0xff000000) | (grey * 0x00010101);
- }
- inputOffset += (dataWidth * 2);
- }
-
- Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
- bitmap.setPixels(pixels, 0, width, 0, 0, width, height);
- return bitmap;
- }
-
- // Not currently needed.
- @Override
- public Bitmap renderFullColorBitmap(boolean halfSize) {
- return null;
- }
-}
View
147 src/com/google/zxing/client/android/PlanarYUVLuminanceSource.java
@@ -1,147 +0,0 @@
-/*
- * Copyright 2009 ZXing authors
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.google.zxing.client.android;
-
-import com.google.zxing.LuminanceSource;
-
-import android.graphics.Bitmap;
-
-/**
- * This object extends LuminanceSource around an array of YUV data returned from the camera driver,
- * with the option to crop to a rectangle within the full data. This can be used to exclude
- * superfluous pixels around the perimeter and speed up decoding.
- *
- * It works for any pixel format where the Y channel is planar and appears first, including
- * YCbCr_420_SP and YCbCr_422_SP. Any subsequent color data will be ignored.
- *
- * @author dswitkin@google.com (Daniel Switkin)
- */
-public final class PlanarYUVLuminanceSource extends BaseLuminanceSource {
- private final byte[] yuvData;
- private final int dataWidth;
- private final int dataHeight;
- private final int left;
- private final int top;
-
- public PlanarYUVLuminanceSource(byte[] yuvData, int dataWidth, int dataHeight, int left, int top,
- int width, int height) {
- super(width, height);
-
- if (left + width > dataWidth || top + height > dataHeight) {
- throw new IllegalArgumentException("Crop rectangle does not fit within image data.");
- }
-
- this.yuvData = yuvData;
- this.dataWidth = dataWidth;
- this.dataHeight = dataHeight;
- this.left = left;
- this.top = top;
- }
-
- @Override
- public byte[] getRow(int y, byte[] row) {
- if (y < 0 || y >= getHeight()) {
- throw new IllegalArgumentException("Requested row is outside the image: " + y);
- }
- int width = getWidth();
- if (row == null || row.length < width) {
- row = new byte[width];
- }
- int offset = (y + top) * dataWidth + left;
- System.arraycopy(yuvData, offset, row, 0, width);
- return row;
- }
-
- @Override
- public byte[] getMatrix() {
- int width = getWidth();
- int height = getHeight();
-
- // If the caller asks for the entire underlying image, save the copy and give them the
- // original data. The docs specifically warn that result.length must be ignored.
- if (width == dataWidth && height == dataHeight) {
- return yuvData;
- }
-
- int area = width * height;
- byte[] matrix = new byte[area];
- int inputOffset = top * dataWidth + left;
-
- // If the width matches the full width of the underlying data, perform a single copy.
- if (width == dataWidth) {
- System.arraycopy(yuvData, inputOffset, matrix, 0, area);
- return matrix;
- }
-
- // Otherwise copy one cropped row at a time.
- byte[] yuv = yuvData;
- for (int y = 0; y < height; y++) {
- int outputOffset = y * width;
- System.arraycopy(yuv, inputOffset, matrix, outputOffset, width);
- inputOffset += dataWidth;
- }
- return matrix;
- }
-
- @Override
- public boolean isCropSupported() {
- return true;
- }
-
- @Override
- public LuminanceSource crop(int left, int top, int width, int height) {
- return new PlanarYUVLuminanceSource(yuvData, dataWidth, dataHeight, left, top, width, height);
- }
-
- @Override
- public int getDataWidth() {
- return dataWidth;
- }
-
- @Override
- public int getDataHeight() {
- return dataHeight;
- }
-
- @Override
- public Bitmap renderCroppedGreyscaleBitmap() {
- int width = getWidth();
- int height = getHeight();
- int[] pixels = new int[width * height];
- byte[] yuv = yuvData;
- int inputOffset = top * dataWidth + left;
-
- for (int y = 0; y < height; y++) {
- int outputOffset = y * width;
- for (int x = 0; x < width; x++) {
- int grey = yuv[inputOffset + x] & 0xff;
- pixels[outputOffset + x] = (0xff000000) | (grey * 0x00010101);
- }
- inputOffset += dataWidth;
- }
-
- Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
- bitmap.setPixels(pixels, 0, width, 0, 0, width, height);
- return bitmap;
- }
-
- // Can't be implemented here, as the color representations vary.
- @Override
- public Bitmap renderFullColorBitmap(boolean halfSize) {
- return null;
- }
-}
View
124 src/com/google/zxing/client/android/ViewfinderView.java
@@ -1,124 +0,0 @@
-/**
- * This file is part of PackRat, an android program for managing media collections.
- * Copyright (C) 2009 Jens Finkhaeuser <unwesen@users.sourceforge.net>
- * All rights reserved.
- *
- * Parts of this file are based on ZXing (http://code.google.com/p/zxing/).
- * Copyright (C) 2008 ZXing authors
- *
- * $Id$
- **/
-
-package com.google.zxing.client.android;
-
-import android.content.Context;
-import android.content.res.Resources;
-import android.graphics.Bitmap;
-import android.graphics.Canvas;
-import android.graphics.Paint;
-import android.graphics.Rect;
-import android.util.AttributeSet;
-import android.view.View;
-
-// XXX Imports added over ZXing code.
-import de.unwesen.packrat.app.R;
-
-/**
- * This view is overlaid on top of the camera preview. It adds the viewfinder rectangle and partial
- * transparency outside it, as well as the laser scanner animation and result points.
- *
- * @author dswitkin@google.com (Daniel Switkin)
- */
-public final class ViewfinderView extends View {
- private static final int[] SCANNER_ALPHA = {0, 64, 128, 192, 255, 192, 128, 64};
- private static final long ANIMATION_DELAY = 100L;
-
- private final Paint paint;
- private final Rect box;
- private Bitmap resultBitmap;
- private final int maskColor;
- private final int resultColor;
- private final int frameColor;
- private final int laserColor;
- private int scannerAlpha;
-
- // This constructor is used when the class is built from an XML resource.
- public ViewfinderView(Context context, AttributeSet attrs) {
- super(context, attrs);
-
- // Initialize these once for performance rather than calling them every time in onDraw().
- paint = new Paint();
- box = new Rect();
- Resources resources = getResources();
- maskColor = resources.getColor(R.color.viewfinder_mask);
- resultColor = resources.getColor(R.color.result_view);
- frameColor = resources.getColor(R.color.viewfinder_frame);
- laserColor = resources.getColor(R.color.viewfinder_laser);
- scannerAlpha = 0;
- }
-
- @Override
- public void onDraw(Canvas canvas) {
- Rect frame = CameraManager.get().getFramingRect();
- if (frame == null) {
- return;
- }
- int width = canvas.getWidth();
- int height = canvas.getHeight();
-
- // Draw the exterior (i.e. outside the framing rect) darkened
- paint.setColor(resultBitmap != null ? resultColor : maskColor);
- box.set(0, 0, width, frame.top);
- canvas.drawRect(box, paint);
- box.set(0, frame.top, frame.left, frame.bottom + 1);
- canvas.drawRect(box, paint);
- box.set(frame.right + 1, frame.top, width, frame.bottom + 1);
- canvas.drawRect(box, paint);
- box.set(0, frame.bottom + 1, width, height);
- canvas.drawRect(box, paint);
-
- if (resultBitmap != null) {
- // Draw the opaque result bitmap over the scanning rectangle
- paint.setAlpha(255);
- canvas.drawBitmap(resultBitmap, frame.left, frame.top, paint);
- } else {
- // Draw a two pixel solid black border inside the framing rect
- paint.setColor(frameColor);
- box.set(frame.left, frame.top, frame.right + 1, frame.top + 2);
- canvas.drawRect(box, paint);
- box.set(frame.left, frame.top + 2, frame.left + 2, frame.bottom - 1);
- canvas.drawRect(box, paint);
- box.set(frame.right - 1, frame.top, frame.right + 1, frame.bottom - 1);
- canvas.drawRect(box, paint);
- box.set(frame.left, frame.bottom - 1, frame.right + 1, frame.bottom + 1);
- canvas.drawRect(box, paint);
-
- // Draw a red "laser scanner" line through the middle to show decoding is active
- paint.setColor(laserColor);
- paint.setAlpha(SCANNER_ALPHA[scannerAlpha]);
- scannerAlpha = (scannerAlpha + 1) % SCANNER_ALPHA.length;
- int middle = frame.height() / 2 + frame.top;
- box.set(frame.left + 2, middle - 1, frame.right - 1, middle + 2);
- canvas.drawRect(box, paint);
-
- // Request another update at the animation interval, but only repaint the laser line,
- // not the entire viewfinder mask.
- postInvalidateDelayed(ANIMATION_DELAY, box.left, box.top, box.right, box.bottom);
- }
- }
-
- public void drawViewfinder() {
- resultBitmap = null;
- invalidate();
- }
-
- /**
- * Draw a bitmap with the result points highlighted instead of the live scanning display.
- *
- * @param barcode An image of the decoded barcode.
- */
- public void drawResultBitmap(Bitmap barcode) {
- resultBitmap = barcode;
- invalidate();
- }
-}

0 comments on commit 173f0a6

Please sign in to comment.
Something went wrong with that request. Please try again.