OSDN Git Service

初期インポート。
[nyartoolkit-and/nyartoolkit-android-0.9.git] / src / com / tomgibara / android / camera / GenuineCamera.java
diff --git a/src/com/tomgibara/android/camera/GenuineCamera.java b/src/com/tomgibara/android/camera/GenuineCamera.java
new file mode 100644 (file)
index 0000000..ecd67b0
--- /dev/null
@@ -0,0 +1,76 @@
+package com.tomgibara.android.camera;\r
+\r
+import android.graphics.Canvas;\r
+import android.hardware.CameraDevice;\r
+\r
+/**\r
+ * A CameraSource implementation that obtains its bitmaps directly from the\r
+ * device camera.\r
+ * \r
+ * @author Tom Gibara\r
+ *\r
+ */\r
+\r
+public class GenuineCamera implements CameraSource {\r
+\r
+       private final int width;\r
+       private final int height;\r
+       \r
+       private CameraDevice device = null;\r
+       \r
+       public GenuineCamera(int width, int height) {\r
+               this.width = width;\r
+               this.height = height;\r
+       }\r
+       \r
+       @Override\r
+       public int getWidth() {\r
+               return width;\r
+       }\r
+       \r
+       @Override\r
+       public int getHeight() {\r
+               return height;\r
+       }\r
+       \r
+       @Override\r
+       public boolean open() {\r
+               if (device != null) return true;\r
+               device = CameraDevice.open();\r
+               if (device == null) return false;\r
+               \r
+               //parameters for the device mostly as specified in sample app\r
+               CameraDevice.CaptureParams param = new CameraDevice.CaptureParams();\r
+               param.type = 1; // preview\r
+               param.srcWidth = 1280;\r
+               param.srcHeight = 960;\r
+               param.leftPixel = 0;\r
+               param.topPixel = 0;\r
+               param.outputWidth = width;\r
+               param.outputHeight = height;\r
+               param.dataFormat = 2; // RGB_565\r
+       \r
+               //attempt to configure the device here\r
+               if (!device.setCaptureParams(param)) {\r
+                       device.close();\r
+                       device = null;\r
+                       return false;\r
+               }\r
+               \r
+               return true;\r
+       }\r
+       \r
+       @Override\r
+       public void close() {\r
+               if (device == null) return;\r
+               device.close();\r
+               device = null;\r
+       }\r
+       \r
+       @Override\r
+       public boolean capture(Canvas canvas) {\r
+               if (device == null) return false;\r
+               return device.capture(canvas);\r
+       }\r
+\r
+}\r