Skip to content

Commit

Permalink
Switch entirely to using FrameModes internally
Browse files Browse the repository at this point in the history
Signed-off-by: Robert Xiao <[email protected]>
  • Loading branch information
nneonneo committed Nov 15, 2011
1 parent cfddec5 commit 1a0ea42
Show file tree
Hide file tree
Showing 15 changed files with 244 additions and 362 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,16 @@ public interface Device {
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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,28 +24,18 @@
*/
package org.openkinect.freenect;

/**
* User: Erwan Daubert - [email protected]
* 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;
}
}
77 changes: 77 additions & 0 deletions wrappers/java/src/main/java/org/openkinect/freenect/FrameMode.java
Original file line number Diff line number Diff line change
@@ -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 { }
}
Loading

0 comments on commit 1a0ea42

Please sign in to comment.