Implementation suitable for JSR-234 phones which takes advantage of advanced camera - * capability.
- * - * @author Sean Owen - */ -final class AdvancedMultimediaManager implements MultimediaManager { - - private static final int NO_ZOOM = 100; - private static final int MAX_ZOOM = 200; - private static final long FOCUS_TIME_MS = 750L; - private static final String DESIRED_METERING = "center-weighted"; - private static final int DESIRED_FLASH = FlashControl.AUTO; - - public void setFocus(Controllable player) { - FocusControl focusControl = - (FocusControl) getControl(player, "javax.microedition.amms.control.camera.FocusControl"); - if (focusControl != null) { - try { - if (focusControl.isMacroSupported() && !focusControl.getMacro()) { - focusControl.setMacro(true); - } - if (focusControl.isAutoFocusSupported()) { - focusControl.setFocus(FocusControl.AUTO); - try { - Thread.sleep(FOCUS_TIME_MS); // let it focus... - } catch (InterruptedException ie) { - // continue - } - focusControl.setFocus(FocusControl.AUTO_LOCK); - } - } catch (MediaException me) { - // continue - } - } - } - - public void setZoom(Controllable player) { - ZoomControl zoomControl = (ZoomControl) getControl(player, "javax.microedition.amms.control.camera.ZoomControl"); - if (zoomControl != null) { - // We zoom in if possible to encourage the viewer to take a snapshot from a greater distance. - // This is a crude way of dealing with the fact that many phone cameras will not focus at a - // very close range. - int maxZoom = zoomControl.getMaxOpticalZoom(); - if (maxZoom > NO_ZOOM) { - zoomControl.setOpticalZoom(maxZoom > MAX_ZOOM ? MAX_ZOOM : maxZoom); - } else { - int maxDigitalZoom = zoomControl.getMaxDigitalZoom(); - if (maxDigitalZoom > NO_ZOOM) { - zoomControl.setDigitalZoom(maxDigitalZoom > MAX_ZOOM ? MAX_ZOOM : maxDigitalZoom); - } - } - } - } - - public void setExposure(Controllable player) { - ExposureControl exposureControl = - (ExposureControl) getControl(player, "javax.microedition.amms.control.camera.ExposureControl"); - if (exposureControl != null) { - - int[] supportedISOs = exposureControl.getSupportedISOs(); - if (supportedISOs != null && supportedISOs.length > 0) { - int maxISO = Integer.MIN_VALUE; - for (int i = 0; i < supportedISOs.length; i++) { - if (supportedISOs[i] > maxISO) { - maxISO = supportedISOs[i]; - } - } - try { - exposureControl.setISO(maxISO); - } catch (MediaException me) { - // continue - } - } - - String[] supportedMeterings = exposureControl.getSupportedLightMeterings(); - if (supportedMeterings != null) { - for (int i = 0; i < supportedMeterings.length; i++) { - if (DESIRED_METERING.equals(supportedMeterings[i])) { - exposureControl.setLightMetering(DESIRED_METERING); - break; - } - } - } - - } - } - - public void setFlash(Controllable player) { - FlashControl flashControl = - (FlashControl) getControl(player, "javax.microedition.amms.control.camera.FlashControl"); - if (flashControl != null) { - int[] supportedFlash = flashControl.getSupportedModes(); - if (supportedFlash != null && supportedFlash.length > 0) { - for (int i = 0; i < supportedFlash.length; i++) { - if (supportedFlash[i] == DESIRED_FLASH) { - try { - flashControl.setMode(DESIRED_FLASH); - } catch (IllegalArgumentException iae) { - // continue - } - break; - } - } - } - } - } - - private static Control getControl(Controllable player, String fullName) { - Control control = player.getControl(fullName); - if (control == null) { - String shortName = fullName.substring(fullName.lastIndexOf('.') + 1); - control = player.getControl(shortName); - } - return control; - } - -} \ No newline at end of file diff --git a/native/j2me/com/codename1/ext/codescan/BarCodeScanner.java b/native/j2me/com/codename1/ext/codescan/BarCodeScanner.java deleted file mode 100644 index 4a085c1..0000000 --- a/native/j2me/com/codename1/ext/codescan/BarCodeScanner.java +++ /dev/null @@ -1,181 +0,0 @@ -package com.codename1.ext.codescan; - -import com.codename1.media.Media; - -import javax.microedition.media.Player; -import javax.microedition.media.control.VideoControl; - -import com.google.zxing.Result; -import com.codename1.ui.Button; -import com.codename1.ui.Command; -import com.codename1.ui.Component; -import com.codename1.ui.Container; -import com.codename1.ui.Display; -import com.codename1.ui.Form; -import com.codename1.ui.events.ActionEvent; -import com.codename1.ui.layouts.BorderLayout; -import com.codename1.ui.layouts.FlowLayout; - -public class BarCodeScanner { - - private Media media; - private Player player; - private SnapshotThread snapshotThread; - private Form cameraForm; - private Form backForm; - private ScanResult callback; - int type; - public static final int BARCODE = 0; - public static final int QRCODE = 1; - - - public BarCodeScanner(Media media) { - this.media = media; - backForm = Display.getInstance().getCurrent(); - } - - private void startScan() { - player = (Player) media.getVideoComponent().getClientProperty("nativePlayer"); - - MultimediaManager multimediaManager = buildMultimediaManager(); - if (player != null) { - multimediaManager.setZoom(player); - multimediaManager.setExposure(player); - multimediaManager.setFlash(player); - } - media.play(); - snapshotThread = new SnapshotThread(this); - new Thread(snapshotThread).start(); - if (Display.getInstance().isEdt()) { - cameraForm.show(); - } else { - // Now show the dialog in EDT - Display.getInstance().callSerially(new Runnable() { - - public void run() { - cameraForm.show(); - } - }); - } - } - - - static MultimediaManager buildMultimediaManager() { - if (isAMMSPresent()) { - return new AdvancedMultimediaManager(); - } else { - return new DefaultMultimediaManager(); - } - } - - class HandleDecodedTextCall implements Runnable { - Result theResult; - public void run() { - callback.scanCompleted(theResult.getText(), theResult.getBarcodeFormat().getName(), theResult.getRawBytes()); - stop(); - media.cleanup(); - backForm.showBack(); - backForm = null; - cameraForm = null; - callback = null; - } - } - - public void handleDecodedText(final Result theResult) { - HandleDecodedTextCall h = new HandleDecodedTextCall(); - h.theResult = theResult; - Display.getInstance().callSerially(h); - } - - private void stop() { - media.pause(); - } - - private void startScaning(ScanResult callback) { - this.callback = callback; - try { - // Add the listener for scan and cancel - Container cmdContainer = new Container(new FlowLayout(Component.CENTER)); - Button scanButton = new Button(new Command("Scan") { - - public void actionPerformed(ActionEvent evt) { - cameraForm.repaint(); - if (snapshotThread != null) { - snapshotThread.continueRun(); - } - } - }); - Button cancelButton = new Button(new Command("Cancel") { - - public void actionPerformed(ActionEvent evt) { - if (snapshotThread != null) { - snapshotThread.stop(); - cancelScan(); - } - } - }); - cmdContainer.addComponent(scanButton); - cmdContainer.addComponent(cancelButton); - cameraForm = new Form(); - cameraForm.setScrollable(false); - cameraForm.setLayout(new BorderLayout()); - cameraForm.addComponent(BorderLayout.CENTER, media.getVideoComponent()); - cameraForm.addComponent(BorderLayout.SOUTH, cmdContainer); - } catch (Exception e) { -// throw new AppException("Image/video capture not supported on this phone", e).setCode(97); - e.printStackTrace(); - } - startScan(); - } - - class CancelScanCall implements Runnable { - public void run() { - stop(); - media.cleanup(); - backForm.showBack(); - callback.scanCanceled(); - backForm = null; - cameraForm = null; - callback = null; - } - } - - private void cancelScan() { - Display.getInstance().callSerially(new CancelScanCall()); - } - - private static boolean isAMMSPresent() { - try { - Class.forName("javax.microedition.amms.GlobalManager"); - return true; - } catch (ClassNotFoundException _ex) { - return false; - } - - } - - Player getPlayer() { - return player; - } - - VideoControl getVideoControl() { - return (VideoControl) media.getVideoComponent().getClientProperty("VideoControl"); - } - - void showError(String err) { - callback.scanError(-1, err); - } - - void startScaningQRcode(ScanResult callback) { - type = QRCODE; - startScaning(callback); - } - - void startScaningBarCode(ScanResult callback) { - type = BARCODE; - startScaning(callback); - } - - - -} diff --git a/native/j2me/com/codename1/ext/codescan/CN1ImageLuminanceSource.java b/native/j2me/com/codename1/ext/codescan/CN1ImageLuminanceSource.java deleted file mode 100644 index a75a862..0000000 --- a/native/j2me/com/codename1/ext/codescan/CN1ImageLuminanceSource.java +++ /dev/null @@ -1,164 +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.codename1.ext.codescan; - -import com.google.zxing.LuminanceSource; -import com.codename1.ui.Image; - -/** - * A LuminanceSource based on Java ME's LWUIT Library Image class. It does not - * support cropping or rotation. - * - * @author dswitkin@google.com (Daniel Switkin) - * @author Sean Owen - */ -public final class CN1ImageLuminanceSource extends LuminanceSource { - - private final Image image; - private int[] rgbData; - - public CN1ImageLuminanceSource(Image image) { - super(image.getWidth(), image.getHeight()); - this.image = image; - } - - // Instead of multiplying by 306, 601, 117, we multiply by 256, 512, 256, so that - // the multiplies can be implemented as shifts. - // - // Really, it's: - // - // return ((((pixel >> 16) & 0xFF) << 8) + - // (((pixel >> 8) & 0xFF) << 9) + - // (( pixel & 0xFF) << 8)) >> 10; - // - // That is, we're replacing the coefficients in the original with powers of two, - // which can be implemented as shifts, even though changing the coefficients slightly - // alters the conversion. The difference is not significant for our purposes. - 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]; - } - - /* - * if (rgbData == null || rgbData.length < width) { rgbData = new - * int[width]; } - */ - //image.getRGB(rgbData, 0, width, 0, y, width, 1); - // For LWUIT Image get the row as sub image without alpha processing, - // as we don't need alpha channel anyway - Image rowImg = image.subImage(0, y, width, 1, false); - rgbData = rowImg.getRGB(); - for (int x = 0; x < width; x++) { - row[x] = toLuminance(rgbData[x]); - } - return row; - } - - public byte[] getMatrix() { - int width = getWidth(); - int height = getHeight(); - int area = width * height; - byte[] matrix = new byte[area]; - - //int[] rgb = new int[area]; - //image.getRGB(rgb, 0, width, 0, 0, width, height); - int[] rgb = image.getRGBCached(); - for (int y = 0; y < height; y++) { - int offset = y * width; - for (int x = 0; x < width; x++) { - matrix[offset + x] = toLuminance(rgb[offset + x]); - } - } - return matrix; - } - - public boolean isRotateSupported() { - return true; - } - - public LuminanceSource rotateCounterClockwise() { - return new CCRotatedLWUITImageLuminanceSource(image); - } - - static byte toLuminance(int pixel) { - return (byte) ((((pixel & 0x00FF0000) >> 16) - + ((pixel & 0x0000FF00) >> 7) - + (pixel & 0x000000FF)) >> 2); - } - - /** - * A variant on {@link LWUITImageLuminanceSource} that acts as if the input - * is rotated 90 degrees counter-clockwise. - */ - private static final class CCRotatedLWUITImageLuminanceSource extends LuminanceSource { - - private final Image image; - private int[] rgbData; - - private CCRotatedLWUITImageLuminanceSource(Image image) { - super(image.getHeight(), image.getWidth()); - this.image = image; - } - - public byte[] getRow(int y, byte[] row) { - int height = getHeight(); - if (y < 0 || y >= height) { - throw new IllegalArgumentException("Requested row is outside the image: " + y); - } - int width = getWidth(); - if (row == null || row.length < width) { - row = new byte[width]; - } - - /* - * if (rgbData == null || rgbData.length < width) { rgbData = new - * int[width]; } - */ - //image.getRGB(rgbData, 0, height, height - 1 - y, 0, 1, width); - // For LWUIT Image get the row as sub image without alpha processing, - // as we don't need alpha channel anyway - Image rowImg = image.subImage(height - 1 - y, 0, 1, width, false); - rgbData = rowImg.getRGB(); - for (int x = 0; x < width; x++) { - row[x] = toLuminance(rgbData[x]); - } - return row; - } - - public byte[] getMatrix() { - int width = getWidth(); - int height = getHeight(); - int area = width * height; - byte[] matrix = new byte[area]; - - //int[] rgb = new int[area]; - //image.getRGB(rgb, 0, width, 0, 0, width, height); - int[] rgb = image.getRGBCached(); - // This flips x/y in the target to result in a rotated image - int offset = height * (width - 1); - for (int y = 0; y < height; y++) { - for (int x = 0; x < width; x++) { - matrix[offset - height * x + y] = toLuminance(rgb[y * width + x]); - } - } - return matrix; - } - } -} diff --git a/native/j2me/com/codename1/ext/codescan/CodeScannerImpl.java b/native/j2me/com/codename1/ext/codescan/CodeScannerImpl.java deleted file mode 100644 index 6edadaa..0000000 --- a/native/j2me/com/codename1/ext/codescan/CodeScannerImpl.java +++ /dev/null @@ -1,31 +0,0 @@ -/* - * To change this template, choose Tools | Templates - * and open the template in the editor. - */ -package com.codename1.ext.codescan; - - - -import com.codename1.media.Media; - -/** - * - * @author Chen - */ -public class CodeScannerImpl { - - private BarCodeScanner bs; - - public CodeScannerImpl(Media recorder) { - bs = new BarCodeScanner(recorder); - } - - public void scanQRCode(ScanResult callback) { - bs.startScaningQRcode(callback); - } - - public void scanBarCode(ScanResult callback) { - bs.startScaningBarCode(callback); - } - -} diff --git a/native/j2me/com/codename1/ext/codescan/DefaultMultimediaManager.java b/native/j2me/com/codename1/ext/codescan/DefaultMultimediaManager.java deleted file mode 100644 index 5438d7c..0000000 --- a/native/j2me/com/codename1/ext/codescan/DefaultMultimediaManager.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright 2007 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.codename1.ext.codescan; - -import javax.microedition.media.Controllable; - -/** - *Dummy implemenation which does nothing. This is suitable for non-JSR-234 phones.
- * - * @author Sean Owen - */ -final class DefaultMultimediaManager implements MultimediaManager { - - public void setFocus(Controllable player) { - } - - public void setZoom(Controllable player) { - } - - public void setExposure(Controllable player) { - } - - public void setFlash(Controllable player) { - } - -} \ No newline at end of file diff --git a/native/j2me/com/codename1/ext/codescan/MultimediaManager.java b/native/j2me/com/codename1/ext/codescan/MultimediaManager.java deleted file mode 100644 index e1c25b6..0000000 --- a/native/j2me/com/codename1/ext/codescan/MultimediaManager.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright 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.codename1.ext.codescan; - -import javax.microedition.media.Controllable; - -/** - *Implemented by {@link com.google.zxing.client.j2me.DefaultMultimediaManager} and - * {@link com.google.zxing.client.j2me.AdvancedMultimediaManager} in order to dynamically - * load support for JSR-234 APIs where possible.
- * - * @author Sean Owen - * @author Paul Hackenberger - */ -interface MultimediaManager { - - void setFocus(Controllable player); - - void setZoom(Controllable player); - - void setExposure(Controllable player); - - void setFlash(Controllable player); - -} \ No newline at end of file diff --git a/native/j2me/com/codename1/ext/codescan/NativeCodeScannerImpl.java b/native/j2me/com/codename1/ext/codescan/NativeCodeScannerImpl.java deleted file mode 100644 index bca8926..0000000 --- a/native/j2me/com/codename1/ext/codescan/NativeCodeScannerImpl.java +++ /dev/null @@ -1,44 +0,0 @@ -package com.codename1.ext.codescan; - -public class NativeCodeScannerImpl { - public void scanQRCode() { - new ScannerHider().getCodeScanner().scanQRCode(new ScanResult() { - - public void scanCompleted(String contents, String formatName, byte[] rawBytes) { - CodeScanner.scanCompletedCallback(contents, formatName, rawBytes); - } - - public void scanCanceled() { - CodeScanner.scanCanceledCallback(); - } - - public void scanError(int errorCode, String message) { - CodeScanner.scanErrorCallback(errorCode, message); - } - - }); - } - - public void scanBarCode() { - new ScannerHider().getCodeScanner().scanBarCode(new ScanResult() { - - public void scanCompleted(String contents, String formatName, byte[] rawBytes) { - CodeScanner.scanCompletedCallback(contents, formatName, rawBytes); - } - - public void scanCanceled() { - CodeScanner.scanCanceledCallback(); - } - - public void scanError(int errorCode, String message) { - CodeScanner.scanErrorCallback(errorCode, message); - } - - }); - } - - public boolean isSupported() { - return true; - } - -} diff --git a/native/j2me/com/codename1/ext/codescan/ScannerHider.java b/native/j2me/com/codename1/ext/codescan/ScannerHider.java deleted file mode 100644 index 6040f5e..0000000 --- a/native/j2me/com/codename1/ext/codescan/ScannerHider.java +++ /dev/null @@ -1,81 +0,0 @@ -/* - * Copyright (c) 2012, Codename One and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Codename One designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Codename One through http://www.codenameone.com/ if you - * need additional information or have any questions. - */ - -package com.codename1.ext.codescan; - -import com.codename1.io.CodeScannerUtil; -import com.codename1.impl.ImplementationFactory; -import com.codename1.impl.midp.GameCanvasImplementation; -import com.codename1.impl.midp.MMAPIPlayer; - -/** - * Class that effectively hides the code scanner API - * - * @author Shai Almog - */ -public class ScannerHider { - /** - * Returns the native implementation of the code scanner or null - * - * @return code scanner instance - */ - CodeScannerImpl getCodeScanner() { - try { - MMAPIPlayer player = null; - - String platform = System.getProperty("microedition.platform"); - /* - if (platform != null && platform.indexOf("Nokia") >= 0) { - try { - player = MMAPIPlayer.createPlayer("capture://image", null); - } catch (Throwable e) { - // Ignore all exceptions for image capture, continue with video capture... - } - } - if (player == null) { - try { - player = MMAPIPlayer.createPlayer("capture://video", null); - } catch (Exception e) { - // The Nokia 2630 throws this if image/video capture is not supported - throw new RuntimeException("Image/video capture not supported on this phone"); - } - } - */ - String uri = null; - if (platform != null && platform.indexOf("Nokia") >= 0) { - uri = "capture://image"; - } else { - uri = "capture://video"; - } - - //GameCanvasImplementation.MIDPVideoComponent video = new GameCanvasImplementation.MIDPVideoComponent(player, GameCanvasImplementationExt.getStaticCanvas()); - GameCanvasImplementation.MIDPVideoComponent video = (GameCanvasImplementation.MIDPVideoComponent)CodeScannerUtil.getImplementation().createMedia(uri, true, null); - video.setFocusable(false); - return new CodeScannerImpl(video); - } catch(Throwable t) { - return null; - } - } - - -} diff --git a/native/j2me/com/codename1/ext/codescan/SnapshotThread.java b/native/j2me/com/codename1/ext/codescan/SnapshotThread.java deleted file mode 100644 index f87278c..0000000 --- a/native/j2me/com/codename1/ext/codescan/SnapshotThread.java +++ /dev/null @@ -1,161 +0,0 @@ -/* - * Copyright 2007 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.codename1.ext.codescan; - -import com.google.zxing.*; -import com.google.zxing.common.HybridBinarizer; -import com.google.zxing.qrcode.QRCodeReader; -//import com.nvsoft.csk.util.Configuration; -import com.codename1.ui.Image; -import com.google.zxing.common.GlobalHistogramBinarizer; -import java.util.Hashtable; - -import javax.microedition.media.MediaException; -import javax.microedition.media.Player; -import javax.microedition.media.control.VideoControl; - -/** - * Thread which does the work of capturing a frame and decoding it. - * - * @author Sean Owen - */ -final class SnapshotThread implements Runnable { -// private static final Logger logger = LoggerFactory.getLogger(SnapshotThread.class); - - private final BarCodeScanner barCodeScanner; - private final Object waitLock; - private volatile boolean done; - private final MultimediaManager multimediaManager; - private String bestEncoding; - - SnapshotThread(BarCodeScanner barCodeScanner) { - this.barCodeScanner = barCodeScanner; - waitLock = new Object(); - done = false; - multimediaManager = BarCodeScanner.buildMultimediaManager(); - } - - void continueRun() { - synchronized (waitLock) { - waitLock.notifyAll(); - } - } - - private void waitForSignal() { - synchronized (waitLock) { - try { - waitLock.wait(); - } catch (InterruptedException ie) { - // continue - } - } - } - - void stop() { - done = true; - continueRun(); - } - - public void run() { - do { - waitForSignal(); - if (done) { - break; - } - BinaryBitmap bitmap = null; - try { - Player player = barCodeScanner.getPlayer(); - if (player == null) { - break; - } - multimediaManager.setFocus(player); - byte[] snapshot = takeSnapshot(); - if (snapshot == null) { - break; - } - Image capturedImage = Image.createImage(snapshot, 0, snapshot.length); - LuminanceSource source = new CN1ImageLuminanceSource(capturedImage); - bitmap = new BinaryBitmap(new HybridBinarizer(source)); - Result result = null; - if(barCodeScanner.type == BarCodeScanner.QRCODE){ - Reader reader = new QRCodeReader(); - result = reader.decode(bitmap); - }else{ - MultiFormatReader reader = new MultiFormatReader(); - result = reader.decodeBarcode(bitmap); - } - barCodeScanner.handleDecodedText(result); - - - } catch (ReaderException re) { - barCodeScanner.showError("Not found!"); - } catch (Exception e) { - barCodeScanner.showError(e.getMessage()); - } - } while (!done); - } - - private byte[] takeSnapshot() throws MediaException { - - String bestEncoding = guessBestEncoding(); - - VideoControl videoControl = barCodeScanner.getVideoControl(); - if (videoControl == null) { - throw new MediaException("Can't obtain video control"); - } - byte[] snapshot = null; - try { - snapshot = videoControl.getSnapshot("".equals(bestEncoding) ? null : bestEncoding); - } catch (MediaException me) { - } - if (snapshot == null) { - // Fall back on JPEG; seems that some cameras default to PNG even - // when PNG isn't supported! - snapshot = videoControl.getSnapshot("encoding=jpeg"); - if (snapshot == null) { - throw new MediaException("Can't obtain a snapshot"); - } - } - return snapshot; - } - - private synchronized String guessBestEncoding() throws MediaException { - if (bestEncoding == null) { - // Check this property, present on some Nokias? - String supportsVideoCapture = System.getProperty("supports.video.capture"); - if ("false".equals(supportsVideoCapture)) { - throw new MediaException("supports.video.capture is false"); - } - - bestEncoding = ""; - String videoSnapshotEncodings = System.getProperty("video.snapshot.encodings"); - if (videoSnapshotEncodings != null) { - // We know explicitly what the camera supports; see if PNG is among them since - // Image.createImage() should always support it - int pngEncodingStart = videoSnapshotEncodings.indexOf("encoding=png"); - if (pngEncodingStart >= 0) { - int space = videoSnapshotEncodings.indexOf(' ', pngEncodingStart); - bestEncoding = space >= 0 ? - videoSnapshotEncodings.substring(pngEncodingStart, space) : - videoSnapshotEncodings.substring(pngEncodingStart); - } - } - } - return bestEncoding; - } - -} diff --git a/native/j2me/com/codename1/io/CodeScannerUtil.java b/native/j2me/com/codename1/io/CodeScannerUtil.java deleted file mode 100644 index 4db7c6f..0000000 --- a/native/j2me/com/codename1/io/CodeScannerUtil.java +++ /dev/null @@ -1,16 +0,0 @@ -/* - * To change this license header, choose License Headers in Project Properties. - * To change this template file, choose Tools | Templates - * and open the template in the editor. - */ -package com.codename1.io; -import com.codename1.impl.midp.GameCanvasImplementation; -/** - * - * @author shannah - */ -public class CodeScannerUtil { - public static GameCanvasImplementation getImplementation() { - return (GameCanvasImplementation)Util.getImplementation(); - } -} diff --git a/native/j2me/org/littlemonkey/qrscanner/NativeScannerImpl.java b/native/j2me/org/littlemonkey/qrscanner/NativeScannerImpl.java deleted file mode 100644 index 192ebf3..0000000 --- a/native/j2me/org/littlemonkey/qrscanner/NativeScannerImpl.java +++ /dev/null @@ -1,14 +0,0 @@ -package org.littlemonkey.qrscanner; - -public class NativeScannerImpl { - public void scanQRCode() { - } - - public void scanBarCode() { - } - - public boolean isSupported() { - return false; - } - -} diff --git a/native/javase/org/littlemonkey/qrscanner/NativeScannerImpl.java b/native/javase/org/littlemonkey/qrscanner/NativeScannerImpl.java deleted file mode 100644 index 76adffc..0000000 --- a/native/javase/org/littlemonkey/qrscanner/NativeScannerImpl.java +++ /dev/null @@ -1,14 +0,0 @@ -package org.littlemonkey.qrscanner; - -public class NativeScannerImpl implements org.littlemonkey.qrscanner.NativeScanner{ - public void scanQRCode() { - } - - public void scanBarCode() { - } - - public boolean isSupported() { - return false; - } - -} diff --git a/native/rim/com/codename1/ext/codescan/BitmapLuminanceSource.java b/native/rim/com/codename1/ext/codescan/BitmapLuminanceSource.java deleted file mode 100644 index c81bfd7..0000000 --- a/native/rim/com/codename1/ext/codescan/BitmapLuminanceSource.java +++ /dev/null @@ -1,75 +0,0 @@ -/* - * To change this template, choose Tools | Templates - * and open the template in the editor. - */ -package com.codename1.ext.codescan; - -import com.google.zxing.LuminanceSource; -import net.rim.device.api.system.Bitmap; - -/** - * - * @author nirmal - */ -public class BitmapLuminanceSource extends LuminanceSource { - private final Bitmap _bitmap; - private byte[] _matrix; - - /** - * Construct luminance source for specified Bitmap - * @param bitmap - */ - public BitmapLuminanceSource(Bitmap bitmap) { - super(bitmap.getWidth(), bitmap.getHeight()); - int width = bitmap.getWidth(); - int height = bitmap.getHeight(); - _bitmap = bitmap; - - int area = width * height; - _matrix = new byte[area]; - int[] rgb = new int[area]; - - _bitmap.getARGB(rgb, 0, width, 0, 0, width, height); - - for (int y = 0; y < height; y++) { - int offset = y * width; - for (int x = 0; x < width; x++) { - int pixel = rgb[offset + x]; - int luminance = (306 * ((pixel >> 16) & 0xFF) + 601 - * ((pixel >> 8) & 0xFF) + 117 * (pixel & 0xFF)) >> 10; - _matrix[offset + x] = (byte) luminance; - } - } - - rgb = null; - - } - - /** - * Get the byte for specified row, starts from 0. - */ - 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 * width; - System.arraycopy(this._matrix, offset, row, 0, width); - - return row; - } - - /** - * Get the byte matrix in 1-dimensional array of byte - */ - public byte[] getMatrix() { - return _matrix; - } - -} diff --git a/native/rim/com/codename1/ext/codescan/CodeScannerImpl.java b/native/rim/com/codename1/ext/codescan/CodeScannerImpl.java deleted file mode 100644 index 6fd678d..0000000 --- a/native/rim/com/codename1/ext/codescan/CodeScannerImpl.java +++ /dev/null @@ -1,216 +0,0 @@ -/* - * To change this template, choose Tools | Templates - * and open the template in the editor. - */ -package com.codename1.ext.codescan; - - -import com.codename1.media.Media; -import com.codename1.ui.Form; -import com.google.zxing.*; -import com.google.zxing.common.HybridBinarizer; -import com.google.zxing.qrcode.QRCodeReader; -import java.util.Hashtable; -import java.util.Timer; -import java.util.TimerTask; -import javax.microedition.media.Manager; -import javax.microedition.media.MediaException; -import javax.microedition.media.Player; -import javax.microedition.media.control.VideoControl; -import net.rim.device.api.system.Application; -import net.rim.device.api.system.Bitmap; -import net.rim.device.api.system.Display; -import net.rim.device.api.ui.Field; -import net.rim.device.api.ui.UiApplication; -import net.rim.device.api.ui.container.MainScreen; - -/** - * - * @author Chen - */ -public class CodeScannerImpl { - - private MultimediaManager multimediaManager; - private ScanResult callback; - private boolean isQRScanning; - private VideoControl videoControl; - private Player player; - private Field viewFinder; - private ViewFinderScreen viewFinderScreen; - private BarcodeScanTask task; - private Timer timer; - private Result result; - - public CodeScannerImpl(MultimediaManager multimediaManager) { - // Setup barcode decoding hints, arg passed is not used at present - this.multimediaManager = multimediaManager; - } - - public void scanQRCode(ScanResult callback) { - this.callback = callback; - isQRScanning = true; - startScan(); - } - - public void scanBarCode(ScanResult callback) { - this.callback = callback; - isQRScanning = false; - startScan(); - } - - - public void cancelScan() { - stopScan(); - if (callback != null) { - callback.scanCanceled(); - //callback.onEvent(doneEvent); - callback = null; - } - } - - public void handleDecodedText(Result theResult) { - // And then stop the scan and go back to the LWUIT form, - // if there was no error. TODO: fix this properly later. - callback.scanCompleted(theResult.getText(), theResult.getBarcodeFormat().getName(), theResult.getRawBytes()); - stopScan(); - callback = null; - } - - /** - * Get the player instance - * - * @return player instance - */ - public Player getPlayer() { - return player; - } - - /** - * Get the video control - * - * @return video control instance - */ - public VideoControl getVideoControl() { - return videoControl; - } - - public void startScan() { - try { - System.gc(); - - player = Manager.createPlayer("capture://video"); - player.realize(); - multimediaManager.setZoom(player); - multimediaManager.setExposure(player); - multimediaManager.setFlash(player); - player.start(); - videoControl = (VideoControl) player.getControl("VideoControl"); - - viewFinder = (Field) videoControl.initDisplayMode( - VideoControl.USE_GUI_PRIMITIVE, - "net.rim.device.api.ui.Field"); - - if (videoControl != null) { - viewFinderScreen = new ViewFinderScreen(); - UiApplication.getUiApplication().invokeLater(new Runnable() { - - public void run() { - UiApplication.getUiApplication().pushScreen( - viewFinderScreen); - viewFinder.setFocus(); - - } - }); - videoControl.setVisible(true); - videoControl.setDisplayFullScreen(true); - task = new BarcodeScanTask(); - // create timer every 3 seconds, get a screenshot - timer = new Timer(); - timer.schedule(task, 0, 3000); // once every 3 seconds - } else { - throw new MediaException("Video Control is not initialized"); - } - } catch (Exception e) { - callback.scanError(-1, e.getMessage()); - } - } - - public void stopScan() { - if (timer != null) { - timer.cancel(); // stop the timer - } - // Destroy the videoControl and player - - if (videoControl != null) { - // TODO: This might not be needed, but have it just in case - videoControl.setVisible(false); - videoControl = null; - } - if (player != null) { - player.close(); - player = null; - } - if (viewFinderScreen != null) { - synchronized (Application.getEventLock()) { - // viewFinderScreen.close(); - UiApplication.getUiApplication().popScreen(viewFinderScreen); - } - viewFinderScreen = null; - } - System.gc(); - } - - final class BarcodeScanTask extends TimerTask { - - public void run() { - try { - - Bitmap bmpScreenshot = new Bitmap(Display.getWidth(), - Display.getHeight()); - multimediaManager.setFocus(player); - Display.screenshot(bmpScreenshot); - // creating luminance source - LuminanceSource source = new BitmapLuminanceSource( - bmpScreenshot); - BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer( - source)); - - if(isQRScanning){ - QRCodeReader reader = new QRCodeReader(); - result = reader.decodeQR(bitmap); - }else{ - MultiFormatReader reader = new MultiFormatReader(); - result = reader.decodeBarcode(bitmap); - } - handleDecodedText(result); - timer.cancel(); // stop the timer - } catch (Throwable e) { - callback.scanError(-1, e.getMessage()); - } - } - } - - public final class ViewFinderScreen extends MainScreen { - - public ViewFinderScreen() throws Exception { - super(MainScreen.DEFAULT_CLOSE); - add(viewFinder); - } - - protected boolean navigationClick(int arg0, int arg1) { - cancelScan(); - this.close(); - return true; - } - - public boolean onClose() { - try { - stopScan(); - return super.onClose(); - } catch (Exception e) { - return false; - } - } - } - -} diff --git a/native/rim/com/codename1/ext/codescan/MultimediaManager.java b/native/rim/com/codename1/ext/codescan/MultimediaManager.java deleted file mode 100644 index ebf3e7a..0000000 --- a/native/rim/com/codename1/ext/codescan/MultimediaManager.java +++ /dev/null @@ -1,46 +0,0 @@ -/* - * To change this template, choose Tools | Templates - * and open the template in the editor. - */ -package com.codename1.ext.codescan; - -/* - * Copyright 2007 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. - */ -import javax.microedition.media.Controllable; -import javax.microedition.media.MediaException; -import javax.microedition.media.Control; - -/** - *Implementation suitable for JSR-234 phones which takes advantage of advanced camera - * capability.
- * - * @author Sean Owen - */ -public class MultimediaManager { - - public void setFocus(Controllable player) { - } - - public void setZoom(Controllable player) { - } - - public void setExposure(Controllable player) { - } - - public void setFlash(Controllable player) { - } - -} \ No newline at end of file diff --git a/native/rim/com/codename1/ext/codescan/NativeCodeScannerImpl.java b/native/rim/com/codename1/ext/codescan/NativeCodeScannerImpl.java deleted file mode 100644 index ac3dcae..0000000 --- a/native/rim/com/codename1/ext/codescan/NativeCodeScannerImpl.java +++ /dev/null @@ -1,44 +0,0 @@ -package com.codename1.ext.codescan; - -public class NativeCodeScannerImpl { - public void scanQRCode() { - new CodeScannerImpl(new MultimediaManager()).scanQRCode(new ScanResult() { - - public void scanCompleted(String contents, String formatName, byte[] rawBytes) { - CodeScanner.scanCompletedCallback(contents, formatName, rawBytes); - } - - public void scanCanceled() { - CodeScanner.scanCanceledCallback(); - } - - public void scanError(int errorCode, String message) { - CodeScanner.scanErrorCallback(errorCode, message); - } - - }); - } - - public void scanBarCode() { - new CodeScannerImpl(new MultimediaManager()).scanBarCode(new ScanResult() { - - public void scanCompleted(String contents, String formatName, byte[] rawBytes) { - CodeScanner.scanCompletedCallback(contents, formatName, rawBytes); - } - - public void scanCanceled() { - CodeScanner.scanCanceledCallback(); - } - - public void scanError(int errorCode, String message) { - CodeScanner.scanErrorCallback(errorCode, message); - } - - }); - } - - public boolean isSupported() { - return true; - } - -} diff --git a/native/rim/org/littlemonkey/qrscanner/NativeScannerImpl.java b/native/rim/org/littlemonkey/qrscanner/NativeScannerImpl.java deleted file mode 100644 index 192ebf3..0000000 --- a/native/rim/org/littlemonkey/qrscanner/NativeScannerImpl.java +++ /dev/null @@ -1,14 +0,0 @@ -package org.littlemonkey.qrscanner; - -public class NativeScannerImpl { - public void scanQRCode() { - } - - public void scanBarCode() { - } - - public boolean isSupported() { - return false; - } - -} diff --git a/nbproject/build-impl.xml b/nbproject/build-impl.xml deleted file mode 100644 index 496b791..0000000 --- a/nbproject/build-impl.xml +++ /dev/null @@ -1,1400 +0,0 @@ - - -