Browse files

Switch entirely to using FrameModes internally

Signed-off-by: Robert Xiao <brx@cs.cmu.edu>
  • Loading branch information...
1 parent cfddec5 commit 1a0ea42bd02602f26a06ff6fcaaad5fe11811b74 @nneonneo nneonneo committed Nov 15, 2011
View
43 wrappers/java/src/main/java/org/openkinect/freenect/DepthFormat.java
@@ -24,33 +24,34 @@
*/
package org.openkinect.freenect;
+import java.util.HashMap;
+import java.util.Map;
public enum DepthFormat {
- D11BIT(0, Freenect.FREENECT_FRAME_W, Freenect.FREENECT_FRAME_H, Freenect.FREENECT_DEPTH_11BIT_SIZE),
- D10BIT(1, Freenect.FREENECT_FRAME_W, Freenect.FREENECT_FRAME_H, Freenect.FREENECT_DEPTH_10BIT_SIZE),
- D11BIT_PACKED(2, Freenect.FREENECT_FRAME_W, Freenect.FREENECT_FRAME_H, Freenect.FREENECT_DEPTH_11BIT_PACKED_SIZE),
- D10BIT_PACKED(3, Freenect.FREENECT_FRAME_W, Freenect.FREENECT_FRAME_H, Freenect.FREENECT_DEPTH_10BIT_PACKED_SIZE);
- private int value;
- private int frameSize;
- private int width;
- private int height;
+ D11BIT(0),
+ D10BIT(1),
+ D11BIT_PACKED(2),
+ D10BIT_PACKED(3),
+ REGISTERED(4),
+ MM(5);
- private DepthFormat(int value, int width, int height, int frameSize) {
+ private final int value;
+ private static final Map<Integer, DepthFormat> MAP = new HashMap<Integer, DepthFormat>(6);
+ static {
+ for(DepthFormat v : DepthFormat.values()) {
+ MAP.put(v.intValue(), v);
+ }
+ }
+
+ private DepthFormat(int value) {
this.value = value;
- this.width = width;
- this.height = height;
- this.frameSize = frameSize;
}
+
public int intValue() {
return value;
}
- public int getWidth() {
- return width;
- }
- public int getHeight() {
- return height;
- }
- public int getFrameSize() {
- return frameSize;
+
+ public static DepthFormat fromInt(int value) {
+ return MAP.get(value);
}
-}
+}
View
89 wrappers/java/src/main/java/org/openkinect/freenect/DepthFrameMode.java
@@ -1,89 +0,0 @@
-/**
- * This file is part of the OpenKinect Project. http://www.openkinect.org
- *
- * Copyright (c) 2010 individual OpenKinect contributors. See the CONTRIB file
- * for details.
- *
- * This code is licensed to you under the terms of the Apache License, version
- * 2.0, or, at your option, the terms of the GNU General Public License,
- * version 2.0. See the APACHE20 and GPL20 files for the text of the licenses,
- * or the following URLs:
- * http://www.apache.org/licenses/LICENSE-2.0
- * http://www.gnu.org/licenses/gpl-2.0.txt
- *
- * If you redistribute this file in source form, modified or unmodified,
- * you may:
- * 1) Leave this header intact and distribute it under the same terms,
- * accompanying it with the APACHE20 and GPL20 files, or
- * 2) Delete the Apache 2.0 clause and accompany it with the GPL20 file, or
- * 3) Delete the GPL v2.0 clause and accompany it with the APACHE20 file
- * In all cases you must keep the copyright notice intact and include a copy
- * of the CONTRIB file.
- * Binary distributions must follow the binary distribution requirements of
- * either License.
- */
-package org.openkinect.freenect;
-
-import com.sun.jna.Structure;
-
-
-/**
- * User: Erwan Daubert - erwan.daubert@gmail.com
- * Date: 12/08/11
- * Time: 13:46
- */
-public class DepthFrameMode extends Structure {
- public int reserved;
- public int resolution;
-// public DepthFormat format;
- public int bytes;
- public short width;
- public short height;
- public short dataBitsPerPixel;
- public short paddingBitsPerPixel;
- public short framerate;
- public short valid;
-
- public DepthFrameMode () {
- }
-
- public DepthFrameMode (int reserved, int resolution/*, DepthFormat format*/, int bytes, short width,
- short height,
- short dataBitsPerPixel, short paddingBitsPerPixel, short framerate, short valid) {
- this.reserved = reserved;
- this.resolution = resolution;
-// this.format = format;
- this.bytes = bytes;
- this.width = width;
- this.height = height;
- this.dataBitsPerPixel = dataBitsPerPixel;
- this.paddingBitsPerPixel = paddingBitsPerPixel;
- this.framerate = framerate;
- this.valid = valid;
- }
-
-
- public static class DepthFrameModeByReference extends DepthFrameMode implements Structure.ByReference {
-
- }
- public static class DepthFrameModeByValue extends DepthFrameMode implements Structure.ByValue {
-
- }
-}
-
-/*typedef struct {
- uint32_t reserved; *//**< unique ID used internally. The meaning of values may change without notice. Don't touch or depend on the contents of this field. We mean it. *//*
- freenect_resolution resolution; *//**< Resolution this freenect_frame_mode describes, should you want to find it again with freenect_find_*_frame_mode(). *//*
- union {
- int32_t dummy;
- freenect_video_format video_format;
- freenect_depth_format depth_format;
- }; *//**< The video or depth format that this freenect_frame_mode describes. The caller should know which of video_format or depth_format to use, since they called freenect_get_*_frame_mode() *//*
- int32_t bytes; *//**< Total buffer size in bytes to hold a single frame of data. Should be equivalent to width * height * (data_bits_per_pixel+padding_bits_per_pixel) / 8 *//*
- int16_t width; *//**< Width of the frame, in pixels *//*
- int16_t height; *//**< Height of the frame, in pixels *//*
- int8_t data_bits_per_pixel; *//**< Number of bits of information needed for each pixel *//*
- int8_t padding_bits_per_pixel; *//**< Number of bits of padding for alignment used for each pixel *//*
- int8_t framerate; *//**< Approximate expected frame rate, in Hz *//*
- int8_t is_valid; *//**< If 0, this freenect_frame_mode is invalid and does not describe a supported mode. Otherwise, the frame_mode is valid. *//*
-} freenect_frame_mode;*/
View
4 wrappers/java/src/main/java/org/openkinect/freenect/DepthHandler.java
@@ -27,5 +27,5 @@
import java.nio.ByteBuffer;
public interface DepthHandler {
- void onFrameReceived(DepthFormat format, ByteBuffer frame, int timestamp);
-}
+ void onFrameReceived(FrameMode mode, ByteBuffer frame, int timestamp);
+}
View
9 wrappers/java/src/main/java/org/openkinect/freenect/Device.java
@@ -31,15 +31,16 @@
double getTiltAngle();
int setTiltAngle(double angle);
TiltStatus getTiltStatus();
- void setResolution(Resolution res);
- //void setDepthFormat(DepthFrameMode mode);
void setDepthFormat(DepthFormat fmt);
- //void setVideoFormat(VideoFrameMode mode);
void setVideoFormat(VideoFormat fmt);
+ void setDepthFormat(DepthFormat fmt, Resolution res);
+ void setVideoFormat(VideoFormat fmt, Resolution res);
+ FrameMode getDepthMode();
+ FrameMode getVideoMode();
int startDepth(DepthHandler handler);
int startVideo(VideoHandler handler);
int stopDepth();
int stopVideo();
void close();
public abstract int getDeviceIndex();
-}
+}
View
34 ...n/java/org/openkinect/freenect/Flags.java → .../org/openkinect/freenect/DeviceFlags.java
@@ -24,28 +24,18 @@
*/
package org.openkinect.freenect;
-/**
- * User: Erwan Daubert - erwan.daubert@gmail.com
- * Date: 12/08/11
- * Time: 13:40
- */
-public enum Flags {
- FREENECT_DEVICE_MOTOR(0x01),
- FREENECT_DEVICE_CAMERA(0x02),
- FREENECT_DEVICE_AUDIO(0x04),;
+public enum DeviceFlags {
+ MOTOR(1),
+ CAMERA(2),
+ AUDIO(4);
- private int value;
+ private final int value;
- Flags (int value) {
- this.value = value;
- }
+ private DeviceFlags(int value) {
+ this.value = value;
+ }
- public int getValue () {
- return value;
- }
-}
-/*typedef enum {
- FREENECT_DEVICE_MOTOR = 0x01,
- FREENECT_DEVICE_CAMERA = 0x02,
- FREENECT_DEVICE_AUDIO = 0x04,
-} freenect_device_flags;*/
+ public int intValue() {
+ return value;
+ }
+}
View
77 wrappers/java/src/main/java/org/openkinect/freenect/FrameMode.java
@@ -0,0 +1,77 @@
+/**
+ * This file is part of the OpenKinect Project. http://www.openkinect.org
+ *
+ * Copyright (c) 2010 individual OpenKinect contributors. See the CONTRIB file
+ * for details.
+ *
+ * This code is licensed to you under the terms of the Apache License, version
+ * 2.0, or, at your option, the terms of the GNU General Public License,
+ * version 2.0. See the APACHE20 and GPL20 files for the text of the licenses,
+ * or the following URLs:
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.gnu.org/licenses/gpl-2.0.txt
+ *
+ * If you redistribute this file in source form, modified or unmodified,
+ * you may:
+ * 1) Leave this header intact and distribute it under the same terms,
+ * accompanying it with the APACHE20 and GPL20 files, or
+ * 2) Delete the Apache 2.0 clause and accompany it with the GPL20 file, or
+ * 3) Delete the GPL v2.0 clause and accompany it with the APACHE20 file
+ * In all cases you must keep the copyright notice intact and include a copy
+ * of the CONTRIB file.
+ * Binary distributions must follow the binary distribution requirements of
+ * either License.
+ */
+package org.openkinect.freenect;
+
+import com.sun.jna.Structure;
+
+public class FrameMode extends Structure {
+ /* All fields are public because Structure requires it.
+ However, fields should NOT be altered by external code. */
+ public int reserved;
+ public int resolution;
+ public int format;
+ public int bytes;
+ public short width, height;
+ public byte dataBitsPerPixel, paddingBitsPerPixel;
+ public byte framerate, valid;
+
+ public FrameMode() {
+ valid = 0;
+ }
+
+ public Resolution getResolution() {
+ return Resolution.fromInt(resolution);
+ }
+
+ public DepthFormat getDepthFormat() {
+ return DepthFormat.fromInt(format);
+ }
+
+ public VideoFormat getVideoFormat() {
+ return VideoFormat.fromInt(format);
+ }
+
+ public int getFrameSize() {
+ return bytes;
+ }
+
+ public short getWidth() {
+ return width;
+ }
+
+ public short getHeight() {
+ return height;
+ }
+
+ public int getFrameRate() {
+ return framerate;
+ }
+
+ public boolean isValid() {
+ return (valid != 0);
+ }
+
+ public static class ByValue extends FrameMode implements Structure.ByValue { }
+}
View
109 wrappers/java/src/main/java/org/openkinect/freenect/Freenect.java
@@ -34,7 +34,6 @@
public class Freenect implements Library {
static {
try {
- NativeLibrary.addSearchPath("freenect", "/home/edaubert/tmp/kinect/libfreenect/results/lib/");
NativeLibrary.addSearchPath("freenect", "/usr/local/lib");
NativeLibrary instance = NativeLibrary.getInstance("freenect");
System.err.println("Loaded " + instance.getName() + " from " + instance.getFile().getCanonicalPath());
@@ -44,24 +43,6 @@
}
}
- // constants from libfreenect.h
- static final int FREENECT_FRAME_W = 640;
- static final int FREENECT_FRAME_H = 480;
- static final int FREENECT_FRAME_PIX = (FREENECT_FRAME_H * FREENECT_FRAME_W);
- static final int FREENECT_IR_FRAME_W = 640;
- static final int FREENECT_IR_FRAME_H = 488;
- static final int FREENECT_IR_FRAME_PIX = (FREENECT_IR_FRAME_H * FREENECT_IR_FRAME_W);
- static final int FREENECT_VIDEO_RGB_SIZE = (FREENECT_FRAME_PIX * 3);
- static final int FREENECT_VIDEO_BAYER_SIZE = (FREENECT_FRAME_PIX);
- static final int FREENECT_VIDEO_YUV_SIZE = (FREENECT_FRAME_PIX * 2);
- static final int FREENECT_VIDEO_IR_8BIT_SIZE = (FREENECT_IR_FRAME_PIX);
- static final int FREENECT_VIDEO_IR_10BIT_SIZE = (FREENECT_IR_FRAME_PIX * 2);
- static final int FREENECT_VIDEO_IR_10BIT_PACKED_SIZE = 390400;
- static final int FREENECT_DEPTH_11BIT_SIZE = (FREENECT_FRAME_PIX * 2);
- static final int FREENECT_DEPTH_10BIT_SIZE = FREENECT_DEPTH_11BIT_SIZE;
- static final int FREENECT_DEPTH_11BIT_PACKED_SIZE = 422400;
- static final int FREENECT_DEPTH_10BIT_PACKED_SIZE = 384000;
-
protected Freenect () {
}
@@ -150,16 +131,18 @@ public void shutdown () {
}
protected static class NativeDevice extends PointerType implements Device {
- private Resolution resolution = Resolution.FREENECT_RESOLUTION_MEDIUM;
- private VideoFormat videoFormat;
+ private FrameMode videoMode;
private ByteBuffer videoBuffer;
- private DepthFormat depthFormat;
+ private VideoHandler videoHandler;
+
+ private FrameMode depthMode;
private ByteBuffer depthBuffer;
+ private DepthHandler depthHandler;
+
private final DoubleBuffer accelX = DoubleBuffer.allocate(1);
private final DoubleBuffer accelY = DoubleBuffer.allocate(1);
private final DoubleBuffer accelZ = DoubleBuffer.allocate(1);
- private VideoHandler videoHandler;
- private DepthHandler depthHandler;
+
private int index;
private TiltState rawTiltState;
@@ -170,14 +153,14 @@ public void shutdown () {
private final NativeVideoCallback videoCallback = new NativeVideoCallback() {
@Override
public void callback (Pointer dev, Pointer depth, int timestamp) {
- videoHandler.onFrameReceived(videoFormat, videoBuffer, timestamp);
+ videoHandler.onFrameReceived(videoMode, videoBuffer, timestamp);
}
};
private final NativeDepthCallback depthCallback = new NativeDepthCallback() {
@Override
public void callback (Pointer dev, Pointer depth, int timestamp) {
- depthHandler.onFrameReceived(depthFormat, depthBuffer, timestamp);
+ depthHandler.onFrameReceived(depthMode, depthBuffer, timestamp);
}
};
@@ -209,30 +192,45 @@ public void close () {
@Override
public void setDepthFormat (DepthFormat fmt) {
-// Native.setProtected(true);
- DepthFrameMode.DepthFrameModeByValue mode = freenect_find_depth_mode(resolution.getValue(), fmt.intValue());
- if (mode.valid != 0) {
- freenect_set_depth_mode(this, mode);
-
- //freenect_set_depth_format(this, fmt.intValue());
- depthBuffer = ByteBuffer.allocateDirect(fmt.getFrameSize());
- freenect_set_depth_buffer(this, depthBuffer);
- this.depthFormat = fmt;
- }
+ setDepthFormat(fmt, Resolution.MEDIUM);
}
@Override
public void setVideoFormat (VideoFormat fmt) {
-// Native.setProtected(true);
- VideoFrameMode.VideoFrameModeByValue mode = freenect_find_video_mode(resolution.getValue(), fmt.intValue());
- if (mode.valid != 0) {
+ setVideoFormat(fmt, Resolution.MEDIUM);
+ }
+
+ @Override
+ public void setDepthFormat (DepthFormat fmt, Resolution res) {
+ FrameMode.ByValue mode = freenect_find_depth_mode(res.intValue(), fmt.intValue());
+ if (mode.isValid()) {
+ freenect_set_depth_mode(this, mode);
+ depthBuffer = ByteBuffer.allocateDirect(mode.getFrameSize());
+ freenect_set_depth_buffer(this, depthBuffer);
+ this.depthMode = mode;
+ }
+ }
+
+ @Override
+ public void setVideoFormat (VideoFormat fmt, Resolution res) {
+ FrameMode.ByValue mode = freenect_find_video_mode(res.intValue(), fmt.intValue());
+ if (mode.isValid()) {
freenect_set_video_mode(this, mode);
- //freenect_set_video_format(this, fmt.intValue());
- videoBuffer = ByteBuffer.allocateDirect(fmt.getFrameSize());
+ videoBuffer = ByteBuffer.allocateDirect(mode.getFrameSize());
freenect_set_video_buffer(this, videoBuffer);
- this.videoFormat = fmt;
+ this.videoMode = mode;
}
- }
+ }
+
+ @Override
+ public FrameMode getDepthMode() {
+ return depthMode;
+ }
+
+ @Override
+ public FrameMode getVideoMode() {
+ return videoMode;
+ }
@Override
public int setLed (LedStatus status) {
@@ -267,11 +265,6 @@ public TiltStatus getTiltStatus () {
}
@Override
- public void setResolution (Resolution res) {
- this.resolution = res;
- }
-
- @Override
public double[] getAccel () {
return new double[]{accelX.get(0), accelY.get(0), accelZ.get(0)};
}
@@ -379,8 +372,6 @@ public TiltState () {
private static native void freenect_set_video_callback (NativeDevice dev, NativeVideoCallback cb);
- // private static native int freenect_set_depth_format(NativeDevice dev, int i);
-// private static native int freenect_set_video_format(NativeDevice dev, int i);
private static native int freenect_set_depth_buffer (NativeDevice dev, ByteBuffer buf);
private static native int freenect_set_video_buffer (NativeDevice dev, ByteBuffer buf);
@@ -412,22 +403,22 @@ private static native void freenect_get_mks_accel (TiltState tiltState, DoubleBu
private static native int freenect_get_video_mode_count ();
- private static native VideoFrameMode.VideoFrameModeByValue freenect_get_video_mode (int mode_num);
+ private static native FrameMode.ByValue freenect_get_video_mode (int mode_num);
- private static native VideoFrameMode.VideoFrameModeByValue freenect_get_current_video_mode (NativeDevice dev);
+ private static native FrameMode.ByValue freenect_get_current_video_mode (NativeDevice dev);
- private static native VideoFrameMode.VideoFrameModeByValue freenect_find_video_mode (int res, int fmt);
+ private static native FrameMode.ByValue freenect_find_video_mode (int res, int fmt);
- private static native int freenect_set_video_mode (NativeDevice dev, VideoFrameMode.VideoFrameModeByValue mode);
+ private static native int freenect_set_video_mode (NativeDevice dev, FrameMode.ByValue mode);
private static native int freenect_get_depth_mode_count ();
- private static native DepthFrameMode.DepthFrameModeByValue freenect_get_depth_mode (int mode_num);
+ private static native FrameMode.ByValue freenect_get_depth_mode (int mode_num);
- private static native DepthFrameMode.DepthFrameModeByValue freenect_get_current_depth_mode (NativeDevice dev);
+ private static native FrameMode.ByValue freenect_get_current_depth_mode (NativeDevice dev);
- private static native DepthFrameMode.DepthFrameModeByValue freenect_find_depth_mode (int res, int fmt);
+ private static native FrameMode.ByValue freenect_find_depth_mode (int res, int fmt);
- private static native int freenect_set_depth_mode (NativeDevice dev, DepthFrameMode.DepthFrameModeByValue mode);
+ private static native int freenect_set_depth_mode (NativeDevice dev, FrameMode.ByValue mode);
-}
+}
View
14 wrappers/java/src/main/java/org/openkinect/freenect/LedStatus.java
@@ -24,6 +24,9 @@
*/
package org.openkinect.freenect;
+import java.util.HashMap;
+import java.util.Map;
+
public enum LedStatus {
OFF(0),
GREEN(1),
@@ -32,7 +35,14 @@
BLINK_YELLOW(4),
BLINK_GREEN(5),
BLINK_RED_YELLOW(6);
+
private final int value;
+ private static final Map<Integer, LedStatus> MAP = new HashMap<Integer, LedStatus>(7);
+ static {
+ for(LedStatus v : LedStatus.values()) {
+ MAP.put(v.intValue(), v);
+ }
+ }
private LedStatus(int value) {
this.value = value;
@@ -41,4 +51,8 @@ private LedStatus(int value) {
public int intValue() {
return value;
}
+
+ public static LedStatus fromInt(int value) {
+ return MAP.get(value);
+ }
}
View
11 wrappers/java/src/main/java/org/openkinect/freenect/LogLevel.java
@@ -37,15 +37,14 @@
SPEW(6),
FLOOD(7);
+ private final int value;
private static final Map<Integer, LogLevel> MAP = new HashMap<Integer, LogLevel>(8);
static {
- for (LogLevel value : values()) {
- MAP.put(value.intValue(), value);
+ for(LogLevel v : LogLevel.values()) {
+ MAP.put(v.intValue(), v);
}
}
- private final int value;
-
private LogLevel(int value) {
this.value = value;
}
@@ -55,6 +54,6 @@ public int intValue() {
}
public static LogLevel fromInt(int value) {
- return MAP.get(value);
+ return MAP.get(value);
}
-}
+}
View
48 wrappers/java/src/main/java/org/openkinect/freenect/Resolution.java
@@ -22,33 +22,33 @@
* Binary distributions must follow the binary distribution requirements of
* either License.
*/
- package org.openkinect.freenect;
+package org.openkinect.freenect;
+
+import java.util.HashMap;
+import java.util.Map;
-/**
- * User: Erwan Daubert - erwan.daubert@gmail.com
- * Date: 12/08/11
- * Time: 13:48
- */
public enum Resolution {
- FREENECT_RESOLUTION_LOW (0),
- FREENECT_RESOLUTION_MEDIUM (1),
- FREENECT_RESOLUTION_HIGH (2),
- FREENECT_RESOLUTION_DUMMY (2147483647);
+ LOW(0),
+ MEDIUM(1),
+ HIGH(2);
- private int value;
+ private final int value;
+ private static final Map<Integer, Resolution> MAP = new HashMap<Integer, Resolution>(3);
+ static {
+ for(Resolution v : Resolution.values()) {
+ MAP.put(v.intValue(), v);
+ }
+ }
- Resolution (int value) {
- this.value = value;
- }
+ private Resolution(int value) {
+ this.value = value;
+ }
- public int getValue () {
- return value;
- }
-}
+ public int intValue() {
+ return value;
+ }
-/*typedef enum {
- FREENECT_RESOLUTION_LOW = 0, *//**< QVGA - 320x240 *//*
- FREENECT_RESOLUTION_MEDIUM = 1, *//**< VGA - 640x480 *//*
- FREENECT_RESOLUTION_HIGH = 2, *//**< SXGA - 1280x1024 *//*
- FREENECT_RESOLUTION_DUMMY = 2147483647, *//**< Dummy value to force enum to be 32 bits wide *//*
-} freenect_resolution;*/
+ public static Resolution fromInt(int value) {
+ return MAP.get(value);
+ }
+}
View
12 wrappers/java/src/main/java/org/openkinect/freenect/TiltStatus.java
@@ -31,13 +31,13 @@
STOPPED(0),
LIMIT(1),
MOVING(4);
- private final int value;
- static final Map<Integer, TiltStatus> MAP = new HashMap<Integer, TiltStatus>(3);
+ private final int value;
+ private static final Map<Integer, TiltStatus> MAP = new HashMap<Integer, TiltStatus>(3);
static {
- for (TiltStatus ts : TiltStatus.values()) {
- MAP.put(ts.intValue(), ts);
- }
+ for(TiltStatus v : TiltStatus.values()) {
+ MAP.put(v.intValue(), v);
+ }
}
private TiltStatus(int value) {
@@ -51,4 +51,4 @@ public int intValue() {
public static TiltStatus fromInt(int value) {
return MAP.get(value);
}
-}
+}
View
48 wrappers/java/src/main/java/org/openkinect/freenect/VideoFormat.java
@@ -24,41 +24,35 @@
*/
package org.openkinect.freenect;
+import java.util.HashMap;
+import java.util.Map;
public enum VideoFormat {
- RGB(0, Freenect.FREENECT_FRAME_W, Freenect.FREENECT_FRAME_H, Freenect.FREENECT_VIDEO_RGB_SIZE),
- BAYER(1, Freenect.FREENECT_FRAME_W, Freenect.FREENECT_FRAME_H, Freenect.FREENECT_VIDEO_BAYER_SIZE),
- IR_8BIT(2, Freenect.FREENECT_IR_FRAME_W, Freenect.FREENECT_IR_FRAME_H, Freenect.FREENECT_VIDEO_IR_8BIT_SIZE),
- IR_10BIT(3, Freenect.FREENECT_IR_FRAME_W, Freenect.FREENECT_IR_FRAME_H, Freenect.FREENECT_VIDEO_IR_10BIT_SIZE),
- IR_10BIT_PACKED(4, Freenect.FREENECT_IR_FRAME_W, Freenect.FREENECT_IR_FRAME_H, Freenect.FREENECT_VIDEO_IR_10BIT_PACKED_SIZE),
- YUV_RGB(5, Freenect.FREENECT_FRAME_W, Freenect.FREENECT_FRAME_H, Freenect.FREENECT_VIDEO_RGB_SIZE),
- YUV_RAW(6, Freenect.FREENECT_FRAME_W, Freenect.FREENECT_FRAME_H, Freenect.FREENECT_VIDEO_YUV_SIZE);
-
+ RGB(0),
+ BAYER(1),
+ IR_8BIT(2),
+ IR_10BIT(3),
+ IR_10BIT_PACKED(4),
+ YUV_RGB(5),
+ YUV_RAW(6);
+
private final int value;
- private final int frameSize;
- private final int width;
- private final int height;
+ private static final Map<Integer, VideoFormat> MAP = new HashMap<Integer, VideoFormat>(7);
+ static {
+ for(VideoFormat v : VideoFormat.values()) {
+ MAP.put(v.intValue(), v);
+ }
+ }
- private VideoFormat(int value, int width, int height, int frameSize) {
+ private VideoFormat(int value) {
this.value = value;
- this.width = width;
- this.height = height;
- this.frameSize = frameSize;
}
-
+
public int intValue() {
return value;
}
-
- public int getFrameSize() {
- return frameSize;
- }
-
- public int getWidth() {
- return width;
- }
-
- public int getHeight() {
- return height;
+
+ public static VideoFormat fromInt(int value) {
+ return MAP.get(value);
}
}
View
96 wrappers/java/src/main/java/org/openkinect/freenect/VideoFrameMode.java
@@ -1,96 +0,0 @@
-/**
- * This file is part of the OpenKinect Project. http://www.openkinect.org
- *
- * Copyright (c) 2010 individual OpenKinect contributors. See the CONTRIB file
- * for details.
- *
- * This code is licensed to you under the terms of the Apache License, version
- * 2.0, or, at your option, the terms of the GNU General Public License,
- * version 2.0. See the APACHE20 and GPL20 files for the text of the licenses,
- * or the following URLs:
- * http://www.apache.org/licenses/LICENSE-2.0
- * http://www.gnu.org/licenses/gpl-2.0.txt
- *
- * If you redistribute this file in source form, modified or unmodified,
- * you may:
- * 1) Leave this header intact and distribute it under the same terms,
- * accompanying it with the APACHE20 and GPL20 files, or
- * 2) Delete the Apache 2.0 clause and accompany it with the GPL20 file, or
- * 3) Delete the GPL v2.0 clause and accompany it with the APACHE20 file
- * In all cases you must keep the copyright notice intact and include a copy
- * of the CONTRIB file.
- * Binary distributions must follow the binary distribution requirements of
- * either License.
- */
-package org.openkinect.freenect;
-
-import com.sun.jna.Structure;
-
-
-/**
- * User: Erwan Daubert - erwan.daubert@gmail.com
- * Date: 12/08/11
- * Time: 13:46
- */
-public class VideoFrameMode extends Structure {
- public int reserved;
- public int resolution;
-// private UnionFormat format;
- public int bytes;
- public short width;
- public short height;
- public short dataBitsPerPixel;
- public short paddingBitsPerPixel;
- public short framerate;
- public short valid;
-
- /*private class UnionFormat extends Union {
- private int dummy;
- private VideoFormat video_format;
- private DepthFormat depth_format;
-
-
- }*/
-
- public VideoFrameMode () {
- }
-
- public VideoFrameMode (int reserved, int resolution/*, UnionFormat format*/, int bytes, short width, short height,
- short dataBitsPerPixel, short paddingBitsPerPixel, short framerate, short valid) {
- this.reserved = reserved;
- this.resolution = resolution;
-// this.format = format;
- this.bytes = bytes;
- this.width = width;
- this.height = height;
- this.dataBitsPerPixel = dataBitsPerPixel;
- this.paddingBitsPerPixel = paddingBitsPerPixel;
- this.framerate = framerate;
- this.valid = valid;
- }
-
-
- public static class VideoFrameModeByReference extends VideoFrameMode implements Structure.ByReference {
-
- }
- public static class VideoFrameModeByValue extends VideoFrameMode implements Structure.ByValue {
-
- }
-}
-
-/*typedef struct {
- uint32_t reserved; *//**< unique ID used internally. The meaning of values may change without notice. Don't touch or depend on the contents of this field. We mean it. *//*
- freenect_resolution resolution; *//**< Resolution this freenect_frame_mode describes, should you want to find it again with freenect_find_*_frame_mode(). *//*
- union {
- int32_t dummy;
- freenect_video_format video_format;
- freenect_depth_format depth_format;
- }; *//**< The video or depth format that this freenect_frame_mode describes. The caller should know which of video_format or depth_format to use, since they called freenect_get_*_frame_mode() *//*
- int32_t bytes; *//**< Total buffer size in bytes to hold a single frame of data. Should be equivalent to width * height * (data_bits_per_pixel+padding_bits_per_pixel) / 8 *//*
- int16_t width; *//**< Width of the frame, in pixels *//*
- int16_t height; *//**< Height of the frame, in pixels *//*
- int8_t data_bits_per_pixel; *//**< Number of bits of information needed for each pixel *//*
- int8_t padding_bits_per_pixel; *//**< Number of bits of padding for alignment used for each pixel *//*
- int8_t framerate; *//**< Approximate expected frame rate, in Hz *//*
- int8_t is_valid; *//**< If 0, this freenect_frame_mode is invalid and does not describe a supported mode. Otherwise, the frame_mode is valid. *//*
-} freenect_frame_mode;*/
View
2 wrappers/java/src/main/java/org/openkinect/freenect/VideoHandler.java
@@ -27,5 +27,5 @@
import java.nio.ByteBuffer;
public interface VideoHandler {
- void onFrameReceived(VideoFormat format, ByteBuffer frame, int timestamp);
+ void onFrameReceived(FrameMode mode, ByteBuffer frame, int timestamp);
}
View
10 wrappers/java/src/test/java/org/openkinect/freenect/FreenectTest.java
@@ -97,7 +97,7 @@ public void onMessage(Device dev, LogLevel level, String msg) {
});
dev.startVideo(new VideoHandler() {
@Override
- public void onFrameReceived(VideoFormat format, ByteBuffer frame, int timestamp) {
+ public void onFrameReceived(FrameMode mode, ByteBuffer frame, int timestamp) {
}
});
Thread.sleep(500);
@@ -117,13 +117,13 @@ public void testDepth() throws InterruptedException {
int frameCount = 0;
@Override
- public void onFrameReceived(DepthFormat format, ByteBuffer frame, int timestamp) {
+ public void onFrameReceived(FrameMode mode, ByteBuffer frame, int timestamp) {
frameCount++;
if (frameCount == 30) {
synchronized (lock) {
lock.notify();
System.out.format("Got %d depth frames in %4.2fs%n", frameCount,
- (((double) System.nanoTime() - start) / 1000000));
+ (((double) System.nanoTime() - start) / 1000000000));
}
}
}
@@ -143,13 +143,13 @@ public void testVideo() throws InterruptedException {
int frameCount = 0;
@Override
- public void onFrameReceived(VideoFormat format, ByteBuffer frame, int timestamp) {
+ public void onFrameReceived(FrameMode mode, ByteBuffer frame, int timestamp) {
frameCount++;
if (frameCount == 30) {
synchronized (lock) {
lock.notify();
System.out.format("Got %d video frames in %4.2fs%n", frameCount,
- (((double) System.nanoTime() - start) / 1000000));
+ (((double) System.nanoTime() - start) / 1000000000));
}
}
}

0 comments on commit 1a0ea42

Please sign in to comment.