00001 /* 00002 * Copyright (C) 2010 ZXing authors 00003 * Copyright 2011 Robert Theis 00004 * Copyright 2012 Jaime Navarro Santapau 00005 * 00006 * Licensed under the Apache License, Version 2.0 (the "License"); 00007 * you may not use this file except in compliance with the License. 00008 * You may obtain a copy of the License at 00009 * 00010 * http://www.apache.org/licenses/LICENSE-2.0 00011 * 00012 * Unless required by applicable law or agreed to in writing, software 00013 * distributed under the License is distributed on an "AS IS" BASIS, 00014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00015 * See the License for the specific language governing permissions and 00016 * limitations under the License. 00017 */ 00018 00026 package edu.uoc.ocr.camera; 00027 00028 import android.graphics.Point; 00029 import android.hardware.Camera; 00030 import android.os.Handler; 00031 import android.os.Message; 00032 import android.util.Log; 00033 00039 final class PreviewCallback implements Camera.PreviewCallback { 00040 00041 private static final String TAG = PreviewCallback.class.getSimpleName(); 00042 00043 private final CameraConfigurationManager configManager; 00044 private Handler previewHandler; 00045 private int previewMessage; 00046 00047 PreviewCallback(CameraConfigurationManager configManager) { 00048 this.configManager = configManager; 00049 } 00050 00051 void setHandler(Handler previewHandler, int previewMessage) { 00052 this.previewHandler = previewHandler; 00053 this.previewMessage = previewMessage; 00054 } 00055 00056 // Since we're not calling setPreviewFormat(int), the data arrives here in 00057 // the YCbCr_420_SP 00058 // (NV21) format. 00059 @Override 00060 public void onPreviewFrame(byte[] data, Camera camera) { 00061 Point cameraResolution = configManager.getCameraResolution(); 00062 Handler thePreviewHandler = previewHandler; 00063 if (cameraResolution != null && thePreviewHandler != null) { 00064 Message message = thePreviewHandler.obtainMessage(previewMessage, 00065 cameraResolution.x, cameraResolution.y, data); 00066 message.sendToTarget(); 00067 previewHandler = null; 00068 } else { 00069 Log.d(TAG, 00070 "Got preview callback, but no handler or resolution available"); 00071 } 00072 } 00073 00074 }