Skip to content

Commit 1a0ea42

Browse files
committed
Switch entirely to using FrameModes internally
Signed-off-by: Robert Xiao <[email protected]>
1 parent cfddec5 commit 1a0ea42

File tree

15 files changed

+244
-362
lines changed

15 files changed

+244
-362
lines changed

wrappers/java/src/main/java/org/openkinect/freenect/DepthFormat.java

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -24,33 +24,34 @@
2424
*/
2525
package org.openkinect.freenect;
2626

27+
import java.util.HashMap;
28+
import java.util.Map;
2729

2830
public enum DepthFormat {
29-
D11BIT(0, Freenect.FREENECT_FRAME_W, Freenect.FREENECT_FRAME_H, Freenect.FREENECT_DEPTH_11BIT_SIZE),
30-
D10BIT(1, Freenect.FREENECT_FRAME_W, Freenect.FREENECT_FRAME_H, Freenect.FREENECT_DEPTH_10BIT_SIZE),
31-
D11BIT_PACKED(2, Freenect.FREENECT_FRAME_W, Freenect.FREENECT_FRAME_H, Freenect.FREENECT_DEPTH_11BIT_PACKED_SIZE),
32-
D10BIT_PACKED(3, Freenect.FREENECT_FRAME_W, Freenect.FREENECT_FRAME_H, Freenect.FREENECT_DEPTH_10BIT_PACKED_SIZE);
33-
private int value;
34-
private int frameSize;
35-
private int width;
36-
private int height;
31+
D11BIT(0),
32+
D10BIT(1),
33+
D11BIT_PACKED(2),
34+
D10BIT_PACKED(3),
35+
REGISTERED(4),
36+
MM(5);
3737

38-
private DepthFormat(int value, int width, int height, int frameSize) {
38+
private final int value;
39+
private static final Map<Integer, DepthFormat> MAP = new HashMap<Integer, DepthFormat>(6);
40+
static {
41+
for(DepthFormat v : DepthFormat.values()) {
42+
MAP.put(v.intValue(), v);
43+
}
44+
}
45+
46+
private DepthFormat(int value) {
3947
this.value = value;
40-
this.width = width;
41-
this.height = height;
42-
this.frameSize = frameSize;
4348
}
49+
4450
public int intValue() {
4551
return value;
4652
}
47-
public int getWidth() {
48-
return width;
49-
}
50-
public int getHeight() {
51-
return height;
52-
}
53-
public int getFrameSize() {
54-
return frameSize;
53+
54+
public static DepthFormat fromInt(int value) {
55+
return MAP.get(value);
5556
}
56-
}
57+
}

wrappers/java/src/main/java/org/openkinect/freenect/DepthFrameMode.java

Lines changed: 0 additions & 89 deletions
This file was deleted.

wrappers/java/src/main/java/org/openkinect/freenect/DepthHandler.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,5 +27,5 @@
2727
import java.nio.ByteBuffer;
2828

2929
public interface DepthHandler {
30-
void onFrameReceived(DepthFormat format, ByteBuffer frame, int timestamp);
31-
}
30+
void onFrameReceived(FrameMode mode, ByteBuffer frame, int timestamp);
31+
}

wrappers/java/src/main/java/org/openkinect/freenect/Device.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,16 @@ public interface Device {
3131
double getTiltAngle();
3232
int setTiltAngle(double angle);
3333
TiltStatus getTiltStatus();
34-
void setResolution(Resolution res);
35-
//void setDepthFormat(DepthFrameMode mode);
3634
void setDepthFormat(DepthFormat fmt);
37-
//void setVideoFormat(VideoFrameMode mode);
3835
void setVideoFormat(VideoFormat fmt);
36+
void setDepthFormat(DepthFormat fmt, Resolution res);
37+
void setVideoFormat(VideoFormat fmt, Resolution res);
38+
FrameMode getDepthMode();
39+
FrameMode getVideoMode();
3940
int startDepth(DepthHandler handler);
4041
int startVideo(VideoHandler handler);
4142
int stopDepth();
4243
int stopVideo();
4344
void close();
4445
public abstract int getDeviceIndex();
45-
}
46+
}

wrappers/java/src/main/java/org/openkinect/freenect/Flags.java renamed to wrappers/java/src/main/java/org/openkinect/freenect/DeviceFlags.java

Lines changed: 12 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -24,28 +24,18 @@
2424
*/
2525
package org.openkinect.freenect;
2626

27-
/**
28-
* User: Erwan Daubert - [email protected]
29-
* Date: 12/08/11
30-
* Time: 13:40
31-
*/
32-
public enum Flags {
33-
FREENECT_DEVICE_MOTOR(0x01),
34-
FREENECT_DEVICE_CAMERA(0x02),
35-
FREENECT_DEVICE_AUDIO(0x04),;
27+
public enum DeviceFlags {
28+
MOTOR(1),
29+
CAMERA(2),
30+
AUDIO(4);
3631

37-
private int value;
32+
private final int value;
3833

39-
Flags (int value) {
40-
this.value = value;
41-
}
34+
private DeviceFlags(int value) {
35+
this.value = value;
36+
}
4237

43-
public int getValue () {
44-
return value;
45-
}
46-
}
47-
/*typedef enum {
48-
FREENECT_DEVICE_MOTOR = 0x01,
49-
FREENECT_DEVICE_CAMERA = 0x02,
50-
FREENECT_DEVICE_AUDIO = 0x04,
51-
} freenect_device_flags;*/
38+
public int intValue() {
39+
return value;
40+
}
41+
}
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
/**
2+
* This file is part of the OpenKinect Project. http://www.openkinect.org
3+
*
4+
* Copyright (c) 2010 individual OpenKinect contributors. See the CONTRIB file
5+
* for details.
6+
*
7+
* This code is licensed to you under the terms of the Apache License, version
8+
* 2.0, or, at your option, the terms of the GNU General Public License,
9+
* version 2.0. See the APACHE20 and GPL20 files for the text of the licenses,
10+
* or the following URLs:
11+
* http://www.apache.org/licenses/LICENSE-2.0
12+
* http://www.gnu.org/licenses/gpl-2.0.txt
13+
*
14+
* If you redistribute this file in source form, modified or unmodified,
15+
* you may:
16+
* 1) Leave this header intact and distribute it under the same terms,
17+
* accompanying it with the APACHE20 and GPL20 files, or
18+
* 2) Delete the Apache 2.0 clause and accompany it with the GPL20 file, or
19+
* 3) Delete the GPL v2.0 clause and accompany it with the APACHE20 file
20+
* In all cases you must keep the copyright notice intact and include a copy
21+
* of the CONTRIB file.
22+
* Binary distributions must follow the binary distribution requirements of
23+
* either License.
24+
*/
25+
package org.openkinect.freenect;
26+
27+
import com.sun.jna.Structure;
28+
29+
public class FrameMode extends Structure {
30+
/* All fields are public because Structure requires it.
31+
However, fields should NOT be altered by external code. */
32+
public int reserved;
33+
public int resolution;
34+
public int format;
35+
public int bytes;
36+
public short width, height;
37+
public byte dataBitsPerPixel, paddingBitsPerPixel;
38+
public byte framerate, valid;
39+
40+
public FrameMode() {
41+
valid = 0;
42+
}
43+
44+
public Resolution getResolution() {
45+
return Resolution.fromInt(resolution);
46+
}
47+
48+
public DepthFormat getDepthFormat() {
49+
return DepthFormat.fromInt(format);
50+
}
51+
52+
public VideoFormat getVideoFormat() {
53+
return VideoFormat.fromInt(format);
54+
}
55+
56+
public int getFrameSize() {
57+
return bytes;
58+
}
59+
60+
public short getWidth() {
61+
return width;
62+
}
63+
64+
public short getHeight() {
65+
return height;
66+
}
67+
68+
public int getFrameRate() {
69+
return framerate;
70+
}
71+
72+
public boolean isValid() {
73+
return (valid != 0);
74+
}
75+
76+
public static class ByValue extends FrameMode implements Structure.ByValue { }
77+
}

0 commit comments

Comments
 (0)