PageRenderTime 30ms CodeModel.GetById 14ms app.highlight 11ms RepoModel.GetById 1ms app.codeStats 0ms

/ocr/ocrservice/src/com/googlecode/eyesfree/opticflow/FrameProducer.java

http://eyes-free.googlecode.com/
Java | 79 lines | 42 code | 16 blank | 21 comment | 3 complexity | bbe235155063853635c2dae2e788b547 MD5 | raw file
 1/*
 2 * Copyright (C) 2011 Google Inc.
 3 *
 4 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 5 * use this file except in compliance with the License. You may obtain a copy of
 6 * the License at
 7 *
 8 * http://www.apache.org/licenses/LICENSE-2.0
 9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 * License for the specific language governing permissions and limitations under
14 * the License.
15 */
16
17package com.googlecode.eyesfree.opticflow;
18
19import android.graphics.PixelFormat;
20
21import com.googlecode.leptonica.android.Convert;
22import com.googlecode.leptonica.android.Pix;
23import com.googlecode.leptonica.android.WriteFile;
24
25/**
26 * Interface for an object that produces image frames on a request basis.
27 *
28 * @author alanv@google.com (Alan Viverette)
29 */
30public interface FrameProducer {
31    public int getFrameWidth();
32
33    public int getFrameHeight();
34
35    public void requestFrame(FrameReceiver listener);
36
37    public interface FrameReceiver {
38        public void onFrameReceived(Frame frame);
39    }
40
41    public static class Frame {
42        public final byte[] data;
43
44        public final int width;
45
46        public final int height;
47
48        public final int format;
49
50        public final long timestamp;
51
52        public Frame(Pix pix, long timestamp) {
53            if (pix.getDepth() != 8) {
54                Pix pix8 = Convert.convertTo8(pix);
55                this.data = WriteFile.writeBytes8(pix);
56                pix8.recycle();
57            } else {
58                this.data = WriteFile.writeBytes8(pix);
59            }
60
61            this.width = pix.getWidth();
62            this.height = pix.getHeight();
63            this.format = PixelFormat.L_8;
64            this.timestamp = timestamp;
65        }
66
67        public Frame(byte[] data, int width, int height, int type, long timestamp) {
68            this.data = data;
69            this.width = width;
70            this.height = height;
71            this.format = type;
72            this.timestamp = timestamp;
73        }
74
75        public void recycle() {
76            // Does nothing in this implementation.
77        }
78    }
79}