/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. package com.googlecode.eyesfree.opticflow;
  17. import android.graphics.PixelFormat;
  18. import com.googlecode.leptonica.android.Convert;
  19. import com.googlecode.leptonica.android.Pix;
  20. import com.googlecode.leptonica.android.WriteFile;
  21. /**
  22. * Interface for an object that produces image frames on a request basis.
  23. *
  24. * @author alanv@google.com (Alan Viverette)
  25. */
  26. public interface FrameProducer {
  27. public int getFrameWidth();
  28. public int getFrameHeight();
  29. public void requestFrame(FrameReceiver listener);
  30. public interface FrameReceiver {
  31. public void onFrameReceived(Frame frame);
  32. }
  33. public static class Frame {
  34. public final byte[] data;
  35. public final int width;
  36. public final int height;
  37. public final int format;
  38. public final long timestamp;
  39. public Frame(Pix pix, long timestamp) {
  40. if (pix.getDepth() != 8) {
  41. Pix pix8 = Convert.convertTo8(pix);
  42. this.data = WriteFile.writeBytes8(pix);
  43. pix8.recycle();
  44. } else {
  45. this.data = WriteFile.writeBytes8(pix);
  46. }
  47. this.width = pix.getWidth();
  48. this.height = pix.getHeight();
  49. this.format = PixelFormat.L_8;
  50. this.timestamp = timestamp;
  51. }
  52. public Frame(byte[] data, int width, int height, int type, long timestamp) {
  53. this.data = data;
  54. this.width = width;
  55. this.height = height;
  56. this.format = type;
  57. this.timestamp = timestamp;
  58. }
  59. public void recycle() {
  60. // Does nothing in this implementation.
  61. }
  62. }
  63. }