001/** 002 * Copyright (c) 2011, The University of Southampton and the individual contributors. 003 * All rights reserved. 004 * 005 * Redistribution and use in source and binary forms, with or without modification, 006 * are permitted provided that the following conditions are met: 007 * 008 * * Redistributions of source code must retain the above copyright notice, 009 * this list of conditions and the following disclaimer. 010 * 011 * * Redistributions in binary form must reproduce the above copyright notice, 012 * this list of conditions and the following disclaimer in the documentation 013 * and/or other materials provided with the distribution. 014 * 015 * * Neither the name of the University of Southampton nor the names of its 016 * contributors may be used to endorse or promote products derived from this 017 * software without specific prior written permission. 018 * 019 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 020 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 021 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 022 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR 023 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 024 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 025 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 026 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 027 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 028 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 029 */ 030package org.openimaj.hardware.kinect.freenect; 031 032import java.nio.ByteBuffer; 033import java.util.Collections; 034import java.util.Iterator; 035 036import java.util.Collections; 037import java.util.Iterator; 038import org.bridj.BridJ; 039import org.bridj.CRuntime; 040import org.bridj.Callback; 041import org.bridj.FlagSet; 042import org.bridj.ValuedEnum; 043import org.bridj.Platform; 044import org.bridj.Pointer; 045import org.bridj.ann.Library; 046import org.bridj.ann.Runtime; 047/** 048 * Wrapper for library <b>freenect</b><br> 049 * This file was autogenerated by <a href="http://jnaerator.googlecode.com/">JNAerator</a>,<br> 050 * a tool written by <a href="http://ochafik.com/">Olivier Chafik</a> that <a href="http://code.google.com/p/jnaerator/wiki/CreditsAndLicense">uses a few opensource projects.</a>.<br> 051 * For help, please visit <a href="http://nativelibs4java.googlecode.com/">NativeLibs4Java</a> or <a href="http://bridj.googlecode.com/">BridJ</a> . 052 */ 053@Library("freenect-combined") 054@Runtime(CRuntime.class) 055@SuppressWarnings("all") 056public class libfreenectLibrary { 057 private static ByteBuffer videoBuffer; 058 private static ByteBuffer depthBuffer; 059 static { 060 Platform.addEmbeddedLibraryResourceRoot("org/openimaj/hardware/kinect/nativelib/"); 061 BridJ.register(); 062 } 063 public enum freenect_device_flags implements ValuedEnum<freenect_device_flags > { 064 FREENECT_DEVICE_MOTOR(0x01), 065 FREENECT_DEVICE_CAMERA(0x02), 066 FREENECT_DEVICE_AUDIO(0x04); 067 freenect_device_flags(long value) { 068 this.value = value; 069 } 070 public final long value; 071 public long value() { 072 return this.value; 073 } 074 public Iterator<freenect_device_flags > iterator() { 075 return Collections.singleton(this).iterator(); 076 } 077 public static ValuedEnum<freenect_device_flags > fromValue(int value) { 078 return FlagSet.fromValue(value, values()); 079 } 080 }; 081 public enum freenect_resolution implements ValuedEnum<freenect_resolution > { 082 FREENECT_RESOLUTION_LOW(0), 083 FREENECT_RESOLUTION_MEDIUM(1), 084 FREENECT_RESOLUTION_HIGH(2), 085 FREENECT_RESOLUTION_DUMMY(2147483647); 086 freenect_resolution(long value) { 087 this.value = value; 088 } 089 public final long value; 090 public long value() { 091 return this.value; 092 } 093 public Iterator<freenect_resolution > iterator() { 094 return Collections.singleton(this).iterator(); 095 } 096 public static ValuedEnum<freenect_resolution > fromValue(int value) { 097 return FlagSet.fromValue(value, values()); 098 } 099 }; 100 public enum freenect_video_format implements ValuedEnum<freenect_video_format > { 101 FREENECT_VIDEO_RGB(0), 102 FREENECT_VIDEO_BAYER(1), 103 FREENECT_VIDEO_IR_8BIT(2), 104 FREENECT_VIDEO_IR_10BIT(3), 105 FREENECT_VIDEO_IR_10BIT_PACKED(4), 106 FREENECT_VIDEO_YUV_RGB(5), 107 FREENECT_VIDEO_YUV_RAW(6), 108 FREENECT_VIDEO_DUMMY(2147483647); 109 freenect_video_format(long value) { 110 this.value = value; 111 } 112 public final long value; 113 public long value() { 114 return this.value; 115 } 116 public Iterator<freenect_video_format > iterator() { 117 return Collections.singleton(this).iterator(); 118 } 119 public static ValuedEnum<freenect_video_format > fromValue(int value) { 120 return FlagSet.fromValue(value, values()); 121 } 122 }; 123 public enum freenect_depth_format implements ValuedEnum<freenect_depth_format > { 124 FREENECT_DEPTH_11BIT(0), 125 FREENECT_DEPTH_10BIT(1), 126 FREENECT_DEPTH_11BIT_PACKED(2), 127 FREENECT_DEPTH_10BIT_PACKED(3), 128 FREENECT_DEPTH_REGISTERED(4), 129 FREENECT_DEPTH_MM(5), 130 FREENECT_DEPTH_DUMMY(2147483647); 131 freenect_depth_format(long value) { 132 this.value = value; 133 } 134 public final long value; 135 public long value() { 136 return this.value; 137 } 138 public Iterator<freenect_depth_format > iterator() { 139 return Collections.singleton(this).iterator(); 140 } 141 public static ValuedEnum<freenect_depth_format > fromValue(int value) { 142 return FlagSet.fromValue(value, values()); 143 } 144 }; 145 public enum freenect_led_options implements ValuedEnum<freenect_led_options > { 146 LED_OFF(0), 147 LED_GREEN(1), 148 LED_RED(2), 149 LED_YELLOW(3), 150 LED_BLINK_GREEN(4), 151 LED_BLINK_RED_YELLOW(6); 152 freenect_led_options(long value) { 153 this.value = value; 154 } 155 public final long value; 156 public long value() { 157 return this.value; 158 } 159 public Iterator<freenect_led_options > iterator() { 160 return Collections.singleton(this).iterator(); 161 } 162 public static ValuedEnum<freenect_led_options > fromValue(int value) { 163 return FlagSet.fromValue(value, values()); 164 } 165 }; 166 public enum freenect_tilt_status_code implements ValuedEnum<freenect_tilt_status_code > { 167 TILT_STATUS_STOPPED(0x00), 168 TILT_STATUS_LIMIT(0x01), 169 TILT_STATUS_MOVING(0x04); 170 freenect_tilt_status_code(long value) { 171 this.value = value; 172 } 173 public final long value; 174 public long value() { 175 return this.value; 176 } 177 public Iterator<freenect_tilt_status_code > iterator() { 178 return Collections.singleton(this).iterator(); 179 } 180 public static ValuedEnum<freenect_tilt_status_code > fromValue(int value) { 181 return FlagSet.fromValue(value, values()); 182 } 183 }; 184 public enum freenect_loglevel implements ValuedEnum<freenect_loglevel > { 185 FREENECT_LOG_FATAL(0), 186 FREENECT_LOG_ERROR(1), 187 FREENECT_LOG_WARNING(2), 188 FREENECT_LOG_NOTICE(3), 189 FREENECT_LOG_INFO(4), 190 FREENECT_LOG_DEBUG(5), 191 FREENECT_LOG_SPEW(6), 192 FREENECT_LOG_FLOOD(7); 193 freenect_loglevel(long value) { 194 this.value = value; 195 } 196 public final long value; 197 public long value() { 198 return this.value; 199 } 200 public Iterator<freenect_loglevel > iterator() { 201 return Collections.singleton(this).iterator(); 202 } 203 public static ValuedEnum<freenect_loglevel > fromValue(int value) { 204 return FlagSet.fromValue(value, values()); 205 } 206 }; 207 /// <i>native declaration : /usr/include/stdint.h</i> 208 public static final long INTMAX_MAX = (long)9223372036854775807L; 209 /// <i>native declaration : /usr/include/stdint.h</i> 210 public static final long INT_LEAST64_MIN = (long)(-9223372036854775807L - 1); 211 /// <i>native declaration : /usr/include/stdint.h</i> 212 public static final int INT32_MIN = (int)(-2147483647 - 1); 213 /// <i>native declaration : /usr/include/stdint.h</i> 214 public static final long INT_FAST64_MIN = (long)(-9223372036854775807L - 1); 215 /// <i>native declaration : /usr/include/stdint.h</i> 216 public static final int WINT_MIN = (int)(-2147483647 - 1); 217 /// <i>native declaration : /usr/include/stdint.h</i> 218 public static final int WINT_MAX = (int)2147483647; 219 /// <i>native declaration : /usr/include/stdint.h</i> 220 public static final int INT_FAST8_MAX = (int)127; 221 /// <i>native declaration : /usr/include/stdint.h</i> 222 public static final int INT16_MIN = (int)-32768; 223 /// <i>native declaration : /usr/include/stdint.h</i> 224 public static final int INT16_MAX = (int)32767; 225 /// <i>native declaration : /usr/include/stdint.h</i> 226 public static final int UINT_LEAST8_MAX = (int)255; 227 /// <i>native declaration : /usr/include/stdint.h</i> 228 public static final int WCHAR_MIN = (int)(0x7fffffff - 1); 229 /// <i>native declaration : /usr/include/stdint.h</i> 230 public static final int WCHAR_MAX = (int)0x7fffffff; 231 /// <i>native declaration : /usr/include/stdint.h</i> 232 public static final int INTPTR_MIN = (int)(-2147483647 - 1); 233 /// <i>native declaration : /usr/include/stdint.h</i> 234 public static final long INTMAX_MIN = (long)(-9223372036854775807L - 1); 235 /// <i>native declaration : /usr/include/stdint.h</i> 236 public static final int INTPTR_MAX = (int)2147483647; 237 /// <i>native declaration : /usr/include/stdint.h</i> 238 public static final long SIZE_MAX = (long)4294967295L; 239 /// <i>native declaration : /usr/include/stdint.h</i> 240 public static final int UINT_FAST8_MAX = (int)255; 241 /// <i>native declaration : /usr/include/stdint.h</i> 242 public static final int INT_FAST8_MIN = (int)-128; 243 /// <i>native declaration : /usr/include/stdint.h</i> 244 public static final long UINT_FAST32_MAX = (long)4294967295L; 245 public static final int FREENECT_COUNTS_PER_G = (int)819; 246 /// <i>native declaration : /usr/include/stdint.h</i> 247 public static final int INT_LEAST8_MAX = (int)127; 248 /// <i>native declaration : /usr/include/stdint.h</i> 249 public static final int UINT_FAST16_MAX = (int)65535; 250 /// <i>native declaration : /usr/include/stdint.h</i> 251 public static final int SIG_ATOMIC_MIN = (int)(-2147483647 - 1); 252 /// <i>native declaration : /usr/include/stdint.h</i> 253 public static final int __WORDSIZE = (int)32; 254 /// <i>native declaration : /usr/include/stdint.h</i> 255 public static final int UINT8_MAX = (int)255; 256 /// <i>native declaration : /usr/include/stdint.h</i> 257 public static final long UINTPTR_MAX = (long)4294967295L; 258 /// <i>native declaration : /usr/include/stdint.h</i> 259 public static final int INT32_MAX = (int)2147483647; 260 /// <i>native declaration : /usr/include/stdint.h</i> 261 public static final int SIG_ATOMIC_MAX = (int)2147483647; 262 /// <i>native declaration : /usr/include/stdint.h</i> 263 public static final int PTRDIFF_MIN = (int)(-2147483647 - 1); 264 /// <i>native declaration : /usr/include/stdint.h</i> 265 public static final int INT_FAST32_MIN = (int)(-2147483647 - 1); 266 /// <i>native declaration : /usr/include/stdint.h</i> 267 public static final int UINT_FAST64_MAX = (int)-1; 268 /// <i>native declaration : /usr/include/stdint.h</i> 269 public static final int INT_FAST16_MIN = (int)-32768; 270 /// <i>native declaration : /usr/include/stdint.h</i> 271 public static final int PTRDIFF_MAX = (int)2147483647; 272 /// <i>native declaration : /usr/include/stdint.h</i> 273 public static final long UINT32_MAX = (long)4294967295L; 274 /// <i>native declaration : /usr/include/stdint.h</i> 275 public static final int UINT16_MAX = (int)65535; 276 /// <i>native declaration : /usr/include/stdint.h</i> 277 public static final int INT_FAST32_MAX = (int)2147483647; 278 public static final int FREENECT_DEPTH_RAW_NO_VALUE = (int)2047; 279 /// <i>native declaration : /usr/include/stdint.h</i> 280 public static final int INT_LEAST16_MIN = (int)-32768; 281 /// <i>native declaration : /usr/include/stdint.h</i> 282 public static final int INT_LEAST8_MIN = (int)-128; 283 /// <i>native declaration : /usr/include/stdint.h</i> 284 public static final int UINTMAX_MAX = (int)-1; 285 /// <i>native declaration : /usr/include/stdint.h</i> 286 public static final int INT_FAST16_MAX = (int)32767; 287 /// <i>native declaration : /usr/include/stdint.h</i> 288 public static final int INT_LEAST16_MAX = (int)32767; 289 /// <i>native declaration : /usr/include/stdint.h</i> 290 public static final int INT8_MIN = (int)-128; 291 /// <i>native declaration : /usr/include/stdint.h</i> 292 public static final int UINT_LEAST16_MAX = (int)65535; 293 public static final int FREENECT_DEPTH_MM_MAX_VALUE = (int)10000; 294 /// <i>native declaration : /usr/include/stdint.h</i> 295 public static final long UINT_LEAST32_MAX = (long)4294967295L; 296 /// <i>native declaration : /usr/include/stdint.h</i> 297 public static final int UINT64_MAX = (int)-1; 298 /// <i>native declaration : /usr/include/stdint.h</i> 299 public static final int INT8_MAX = (int)127; 300 /// <i>native declaration : /usr/include/stdint.h</i> 301 public static final int INT_LEAST32_MIN = (int)(-2147483647 - 1); 302 /// <i>native declaration : /usr/include/stdint.h</i> 303 public static final int INT_LEAST32_MAX = (int)2147483647; 304 public static final int FREENECT_DEPTH_RAW_MAX_VALUE = (int)2048; 305 /// <i>native declaration : /usr/include/stdint.h</i> 306 public static final long INT64_MIN = (long)(-9223372036854775807L - 1); 307 /// <i>native declaration : /usr/include/stdint.h</i> 308 public static final long INT64_MAX = (long)9223372036854775807L; 309 /// <i>native declaration : /usr/include/stdint.h</i> 310 public static final long INT_FAST64_MAX = (long)9223372036854775807L; 311 /// <i>native declaration : /usr/include/stdint.h</i> 312 public static final long INT_LEAST64_MAX = (long)9223372036854775807L; 313 public static final int FREENECT_DEPTH_MM_NO_VALUE = (int)0; 314 /// <i>native declaration : /usr/include/stdint.h</i> 315 public static final int UINT_LEAST64_MAX = (int)-1; 316 /** 317 * Typedef for logging callback functions<br> 318 * <i>native declaration : /usr/include/stdint.h</i> 319 */ 320 public static abstract class freenect_log_cb extends Callback<freenect_log_cb > { 321 public abstract void apply(Pointer<libfreenectLibrary.freenect_context > dev, ValuedEnum<libfreenectLibrary.freenect_loglevel > level, Pointer<Byte > msg); 322 }; 323 /** 324 * Typedef for depth image received event callbacks<br> 325 * <i>native declaration : /usr/include/stdint.h</i> 326 */ 327 public static abstract class freenect_depth_cb extends Callback<freenect_depth_cb > { 328 public abstract void apply(Pointer<libfreenectLibrary.freenect_device > dev, Pointer<? > depth, int timestamp); 329 }; 330 /** 331 * Typedef for video image received event callbacks<br> 332 * <i>native declaration : /usr/include/stdint.h</i> 333 */ 334 public static abstract class freenect_video_cb extends Callback<freenect_video_cb > { 335 public abstract void apply(Pointer<libfreenectLibrary.freenect_device > dev, Pointer<? > video, int timestamp); 336 }; 337 public static native int freenect_init(Pointer<Pointer<libfreenectLibrary.freenect_context > > ctx, Pointer<? > usb_ctx); 338 public static native int freenect_shutdown(Pointer<libfreenectLibrary.freenect_context > ctx); 339 public static native void freenect_set_log_level(Pointer<libfreenectLibrary.freenect_context > ctx, ValuedEnum<libfreenectLibrary.freenect_loglevel > level); 340 public static native void freenect_set_log_callback(Pointer<libfreenectLibrary.freenect_context > ctx, Pointer<libfreenectLibrary.freenect_log_cb > cb); 341 public static native int freenect_process_events(Pointer<libfreenectLibrary.freenect_context > ctx); 342 public static native int freenect_process_events_timeout(Pointer<libfreenectLibrary.freenect_context > ctx, Pointer<libfreenectLibrary.timeval > timeout); 343 public static native int freenect_num_devices(Pointer<libfreenectLibrary.freenect_context > ctx); 344 public static native int freenect_list_device_attributes(Pointer<libfreenectLibrary.freenect_context > ctx, Pointer<Pointer<freenect_device_attributes > > attribute_list); 345 public static native void freenect_free_device_attributes(Pointer<freenect_device_attributes > attribute_list); 346 public static native int freenect_supported_subdevices(); 347 public static native void freenect_select_subdevices(Pointer<libfreenectLibrary.freenect_context > ctx, ValuedEnum<libfreenectLibrary.freenect_device_flags > subdevs); 348 public static native int freenect_open_device(Pointer<libfreenectLibrary.freenect_context > ctx, Pointer<Pointer<libfreenectLibrary.freenect_device > > dev, int index); 349 public static native int freenect_open_device_by_camera_serial(Pointer<libfreenectLibrary.freenect_context > ctx, Pointer<Pointer<libfreenectLibrary.freenect_device > > dev, Pointer<Byte > camera_serial); 350 public static native int freenect_close_device(Pointer<libfreenectLibrary.freenect_device > dev); 351 public static native void freenect_set_user(Pointer<libfreenectLibrary.freenect_device > dev, Pointer<? > user); 352 public static native Pointer<? > freenect_get_user(Pointer<libfreenectLibrary.freenect_device > dev); 353 public static native void freenect_set_depth_callback(Pointer<libfreenectLibrary.freenect_device > dev, Pointer<libfreenectLibrary.freenect_depth_cb > cb); 354 public static native void freenect_set_video_callback(Pointer<libfreenectLibrary.freenect_device > dev, Pointer<libfreenectLibrary.freenect_video_cb > cb); 355 public static native int freenect_set_depth_buffer(Pointer<libfreenectLibrary.freenect_device > dev, Pointer<? > buf); 356 public static native int freenect_set_video_buffer(Pointer<libfreenectLibrary.freenect_device > dev, Pointer<? > buf); 357 public static native int freenect_start_depth(Pointer<libfreenectLibrary.freenect_device > dev); 358 public static native int freenect_start_video(Pointer<libfreenectLibrary.freenect_device > dev); 359 public static native int freenect_stop_depth(Pointer<libfreenectLibrary.freenect_device > dev); 360 public static native int freenect_stop_video(Pointer<libfreenectLibrary.freenect_device > dev); 361 public static native int freenect_update_tilt_state(Pointer<libfreenectLibrary.freenect_device > dev); 362 public static native Pointer<freenect_raw_tilt_state > freenect_get_tilt_state(Pointer<libfreenectLibrary.freenect_device > dev); 363 public static native double freenect_get_tilt_degs(Pointer<freenect_raw_tilt_state > state); 364 public static native int freenect_set_tilt_degs(Pointer<libfreenectLibrary.freenect_device > dev, double angle); 365 public static native ValuedEnum<libfreenectLibrary.freenect_tilt_status_code > freenect_get_tilt_status(Pointer<freenect_raw_tilt_state > state); 366 public static native int freenect_set_led(Pointer<libfreenectLibrary.freenect_device > dev, ValuedEnum<libfreenectLibrary.freenect_led_options > option); 367 public static native void freenect_get_mks_accel(Pointer<freenect_raw_tilt_state > state, Pointer<Double > x, Pointer<Double > y, Pointer<Double > z); 368 public static native int freenect_get_video_mode_count(); 369 public static native freenect_frame_mode freenect_get_video_mode(int mode_num); 370 public static native freenect_frame_mode freenect_get_current_video_mode(Pointer<libfreenectLibrary.freenect_device > dev); 371 public static native freenect_frame_mode freenect_find_video_mode(ValuedEnum<libfreenectLibrary.freenect_resolution > res, ValuedEnum<libfreenectLibrary.freenect_video_format > fmt); 372 public static native int freenect_set_video_mode(Pointer<libfreenectLibrary.freenect_device > dev, freenect_frame_mode mode); 373 // PROXY ADDED IN OPENIMAJ 374 public static native int freenect_set_video_mode_proxy(Pointer<libfreenectLibrary.freenect_device > dev, ValuedEnum<libfreenectLibrary.freenect_resolution > res, ValuedEnum<libfreenectLibrary.freenect_video_format > fmt); 375 public static native int freenect_get_depth_mode_count(); 376 public static native freenect_frame_mode freenect_get_depth_mode(int mode_num); 377 public static native freenect_frame_mode freenect_get_current_depth_mode(Pointer<libfreenectLibrary.freenect_device > dev); 378 public static native freenect_frame_mode freenect_find_depth_mode(ValuedEnum<libfreenectLibrary.freenect_resolution > res, ValuedEnum<libfreenectLibrary.freenect_depth_format > fmt); 379 public static native int freenect_set_depth_mode(Pointer<libfreenectLibrary.freenect_device > dev, freenect_frame_mode mode); 380 // PROXY ADDED IN OPENIMAJ 381 public static native int freenect_set_depth_mode_proxy(Pointer<libfreenectLibrary.freenect_device > dev, ValuedEnum<libfreenectLibrary.freenect_resolution > res, ValuedEnum<libfreenectLibrary.freenect_depth_format > fmt); 382 // TWO UTILITIES ADDED IN OPENIMAJ 383 public static native int freenect_get_video_buffer_size(Pointer<libfreenectLibrary.freenect_device > dev); 384 public static native int freenect_get_depth_buffer_size(Pointer<libfreenectLibrary.freenect_device > dev); 385 /// Undefined type 386 public static interface freenect_device { 387 388 }; 389 /// Undefined type 390 public static interface timeval { 391 392 }; 393 /// Undefined type 394 public static interface freenect_context { 395 396 }; 397 398 //libfreenect-registration.h methods 399 public static native freenect_registration freenect_copy_registration(Pointer<libfreenectLibrary.freenect_device > dev); 400 public static native int freenect_destroy_registration(Pointer<freenect_registration > reg); 401 public static native void freenect_camera_to_world(Pointer<libfreenectLibrary.freenect_device > dev, int cx, int cy, int wz, Pointer<Double > wx, Pointer<Double > wy); 402}