Browse files

Initial commit

  • Loading branch information...
0 parents commit 4094151eb0a8eb71f24df9d204e04b89b1724ea1 @marcan marcan committed Nov 10, 2010
Showing with 887 additions and 0 deletions.
  1. +2 −0 .gitignore
  2. +13 −0 Makefile
  3. +6 −0 README.txt
  4. +265 −0 cameras.c
  5. +20 −0 cameras.h
  6. +26 −0 geninits.py
  7. +279 −0 inits.h
  8. +55 −0 inits.txt
  9. +221 −0 main.c
2 .gitignore
@@ -0,0 +1,2 @@
+testcam
+*.o
13 Makefile
@@ -0,0 +1,13 @@
+
+LDFLAGS += -lusb-1.0 -lGL -lGLU -lglut -pthread
+
+OBJECTS = cameras.o main.o
+
+testcam : $(OBJECTS)
+ gcc $(LDFLAGS) -o $@ $(OBJECTS)
+
+inits.h : inits.txt geninits.py
+ python geninits.py $< > $@
+
+clean:
+ rm -f testcam $(OBJECTS) inits.h
6 README.txt
@@ -0,0 +1,6 @@
+
+Horribly hacky first take at a Kinect Camera driver. Does RGB and Depth.
+
+main.c implements a simple OpenGL driver. Hopefully it should be mostly self-explanatory...
+You pretty much just open the USB device, call cams_init(dev, depthimg, rgbimg), and your
+depthimg and rgbimg callbacks get called as libusb processes events.
265 cameras.c
@@ -0,0 +1,265 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <libusb-1.0/libusb.h>
+#include "cameras.h"
+#include "inits.h"
+
+#define DEPTH_LEN 1760
+#define RGB_LEN 1920
+
+#define NUM_XFERS 512
+
+static struct libusb_transfer *depth_xfers[NUM_XFERS];
+static struct libusb_transfer *rgb_xfers[NUM_XFERS];
+
+static void *rgb_bufs[NUM_XFERS];
+static void *depth_bufs[NUM_XFERS];
+
+static depthcb depth_cb;
+static rgbcb rgb_cb;
+
+static libusb_device_handle *dev;
+
+struct frame_hdr {
+ uint8_t magic[2];
+ uint8_t pad;
+ uint8_t flag;
+ uint8_t unk1;
+ uint8_t seq;
+ uint8_t unk2;
+ uint8_t unk3;
+ uint32_t timestamp;
+};
+
+uint8_t depth_buf[2*422400];
+uint16_t depth_frame[640*480];
+int depth_pos = 0;
+
+uint8_t rgb_buf[2*307200];
+uint8_t rgb_frame[640*480*3];
+int rgb_pos = 0;
+
+static void depth_process(uint8_t *buf, size_t len)
+{
+ int i;
+ if (len == 0)
+ return;
+
+ struct frame_hdr *hdr = (void*)buf;
+ uint8_t *data = buf + sizeof(*hdr);
+ int datalen = len - sizeof(*hdr);
+
+ //printf("%02x %x\n", hdr->flag, depth_pos);
+ switch (hdr->flag) {
+ case 0x71:
+ depth_pos = 0;
+ case 0x72:
+ case 0x75:
+ memcpy(&depth_buf[depth_pos], data, datalen);
+ depth_pos += datalen;
+ break;
+ }
+
+ if (hdr->flag != 0x75)
+ return;
+
+ printf("GOT DEPTH FRAME, %d bytes\n", depth_pos);
+
+ int bitshift = 0;
+ for (i=0; i<(640*480); i++) {
+ int idx = (i*11)/8;
+ uint32_t word = (depth_buf[idx]<<16) | (depth_buf[idx+1]<<8) | depth_buf[idx+2];
+ depth_frame[i] = ((word >> (13-bitshift)) & 0x7ff) << 5;
+ bitshift = (bitshift + 11) % 8;
+ }
+
+ depth_cb(depth_frame, 640, 480);
+}
+
+static void rgb_process(uint8_t *buf, size_t len)
+{
+ int x,y,i;
+ if (len == 0)
+ return;
+
+ struct frame_hdr *hdr = (void*)buf;
+ uint8_t *data = buf + sizeof(*hdr);
+ int datalen = len - sizeof(*hdr);
+
+ //printf("%02x %x\n", hdr->flag, depth_pos);
+ switch (hdr->flag) {
+ case 0x81:
+ rgb_pos = 0;
+ case 0x82:
+ case 0x85:
+ memcpy(&rgb_buf[rgb_pos], data, datalen);
+ rgb_pos += datalen;
+ break;
+ }
+
+ if (hdr->flag != 0x85)
+ return;
+
+ printf("GOT RGB FRAME, %d bytes\n", rgb_pos);
+
+ // horrible bayer to RGB conversion, but does the job for now
+ for (y=0; y<480; y++) {
+ for (x=0; x<640; x++) {
+ i = y*640+x;
+ if (x&1) {
+ if (y&1) {
+ rgb_frame[3*i+1] = rgb_buf[i];
+ rgb_frame[3*i+4] = rgb_buf[i];
+ } else {
+ rgb_frame[3*i] = rgb_buf[i];
+ rgb_frame[3*i+3] = rgb_buf[i];
+ rgb_frame[3*(i-640)] = rgb_buf[i];
+ rgb_frame[3*(i-640)+3] = rgb_buf[i];
+ }
+ } else {
+ if (y&1) {
+ rgb_frame[3*i+2] = rgb_buf[i];
+ rgb_frame[3*i-1] = rgb_buf[i];
+ rgb_frame[3*(i+640)+2] = rgb_buf[i];
+ rgb_frame[3*(i+640)-1] = rgb_buf[i];
+ } else {
+ rgb_frame[3*i+1] = rgb_buf[i];
+ rgb_frame[3*i-2] = rgb_buf[i];
+ }
+ }
+ }
+ }
+
+ rgb_cb(rgb_frame, 640, 480);
+}
+
+/*static void rgb_process(uint8_t *buf, size_t len)
+{
+ int i;
+ if (len == 0)
+ return;
+
+ printf("RGB %ld %02x\n", len, buf[0]);
+
+ for (i=0; i<32; i++) {
+ printf("%02x ", buf[i]);
+ }
+ printf("\n");
+}*/
+
+static void depth_callback(struct libusb_transfer *xfer)
+{
+ if(xfer->status == LIBUSB_TRANSFER_COMPLETED) {
+ depth_process((void*)xfer->buffer, xfer->iso_packet_desc[0].actual_length);
+ libusb_set_iso_packet_lengths(xfer, DEPTH_LEN);
+ libusb_submit_transfer(xfer);
+ } else {
+ printf("Xfer error: %d\n", xfer->status);
+ }
+}
+
+static void rgb_callback(struct libusb_transfer *xfer)
+{
+ if(xfer->status == LIBUSB_TRANSFER_COMPLETED) {
+ rgb_process((void*)xfer->buffer, xfer->iso_packet_desc[0].actual_length);
+ libusb_set_iso_packet_lengths(xfer, RGB_LEN);
+ libusb_submit_transfer(xfer);
+ } else {
+ printf("Xfer error: %d\n", xfer->status);
+ }
+}
+
+struct cam_hdr {
+ uint8_t magic[2];
+ uint16_t len;
+ uint16_t cmd;
+ uint16_t tag;
+};
+
+void send_init(void)
+{
+ int i, j, ret;
+ uint8_t obuf[0x2000];
+ uint8_t ibuf[0x2000];
+ struct cam_hdr *chdr = (void*)obuf;
+ struct cam_hdr *rhdr = (void*)ibuf;
+
+ ret = libusb_control_transfer(dev, 0x80, 0x06, 0x3ee, 0, ibuf, 0x12, 0);
+ printf("First xfer: %d\n", ret);
+
+ chdr->magic[0] = 0x47;
+ chdr->magic[1] = 0x4d;
+
+ int count = sizeof(inits)/sizeof(inits[0]);
+ for (i=0; i<count; i++) {
+ const struct caminit *ip = &inits[i];
+ chdr->cmd = ip->command;
+ chdr->tag = ip->tag;
+ chdr->len = ip->cmdlen / 2;
+ memcpy(obuf+sizeof(*chdr), ip->cmddata, ip->cmdlen);
+ ret = libusb_control_transfer(dev, 0x40, 0, 0, 0, obuf, ip->cmdlen + sizeof(*chdr), 0);
+ printf("CTL CMD %04x %04x = %d\n", chdr->cmd, chdr->tag, ret);
+ do {
+ ret = libusb_control_transfer(dev, 0xc0, 0, 0, 0, ibuf, 0x200, 0);
+ } while (ret == 0);
+ printf("CTL RES = %d\n", ret);
+ if (rhdr->magic[0] != 0x52 || rhdr->magic[1] != 0x42) {
+ printf("Bad magic %02x %02x\n", rhdr->magic[0], rhdr->magic[1]);
+ continue;
+ }
+ if (rhdr->cmd != chdr->cmd) {
+ printf("Bad cmd %02x != %02x\n", rhdr->cmd, chdr->cmd);
+ continue;
+ }
+ if (rhdr->tag != chdr->tag) {
+ printf("Bad tag %04x != %04x\n", rhdr->tag, chdr->tag);
+ continue;
+ }
+ if (rhdr->len != (ret-sizeof(*rhdr))/2) {
+ printf("Bad len %04x != %04x\n", rhdr->len, (int)(ret-sizeof(*rhdr))/2);
+ continue;
+ }
+ if (rhdr->len != (ip->replylen/2) || memcmp(ibuf+sizeof(*rhdr), ip->replydata, ip->replylen)) {
+ printf("Expected: ");
+ for (j=0; j<ip->replylen; j++) {
+ printf("%02x ", ip->replydata[j]);
+ }
+ printf("\nGot: ");
+ for (j=0; j<(rhdr->len*2); j++) {
+ printf("%02x ", ibuf[j+sizeof(*rhdr)]);
+ }
+ printf("\n");
+ }
+ }
+}
+
+void cams_init(libusb_device_handle *d, depthcb dcb, rgbcb rcb)
+{
+ int i, ret;
+ dev = d;
+
+ depth_cb = dcb;
+ rgb_cb = rcb;
+
+ for (i=0; i<NUM_XFERS; i++) {
+ rgb_bufs[i] = malloc(RGB_LEN);
+ depth_bufs[i] = malloc(DEPTH_LEN);
+
+ rgb_xfers[i] = libusb_alloc_transfer(1);
+ depth_xfers[i] = libusb_alloc_transfer(1);
+
+ libusb_fill_iso_transfer(rgb_xfers[i], dev, 0x81, rgb_bufs[i], RGB_LEN, 1, rgb_callback, NULL, 0);
+ libusb_fill_iso_transfer(depth_xfers[i], dev, 0x82, depth_bufs[i], DEPTH_LEN, 1, depth_callback, NULL, 0);
+
+ libusb_set_iso_packet_lengths(rgb_xfers[i], RGB_LEN);
+ libusb_set_iso_packet_lengths(depth_xfers[i], DEPTH_LEN);
+
+ libusb_submit_transfer(rgb_xfers[i]);
+ libusb_submit_transfer(depth_xfers[i]);
+ }
+
+ send_init();
+
+}
+
20 cameras.h
@@ -0,0 +1,20 @@
+#ifndef CAMERAS_H
+#define CAMERAS_H
+
+#include <stdint.h>
+
+struct caminit {
+ uint16_t command;
+ uint16_t tag;
+ int cmdlen;
+ int replylen;
+ uint8_t cmddata[1024];
+ uint8_t replydata[1024];
+};
+
+typedef void (*depthcb)(uint16_t *buf, int width, int height);
+typedef void (*rgbcb)(uint8_t *buf, int width, int height);
+
+void cams_init(libusb_device_handle *d, depthcb depth_cb, rgbcb rgb_cb);
+
+#endif
26 geninits.py
@@ -0,0 +1,26 @@
+#!/usr/bin/python
+import struct
+
+print '#include "cameras.h"'
+print
+print "const struct caminit inits[] = {"
+for line in open("inits.txt"):
+ line = line.replace("\n","")
+ if line == "":
+ continue
+ cmd,tag,cdata,rdata = line.split(",")
+ cmd = int(cmd,16)
+ tag = int(tag,16)
+
+ cdata = cdata.decode('hex')
+ rdata = rdata.decode('hex')
+
+ hcdata = ", ".join(["0x%02x"%ord(x) for x in cdata])
+ hrdata = ", ".join(["0x%02x"%ord(x) for x in rdata])
+
+ print "\t{"
+ print "\t\t0x%02x, 0x%04x, %d, %d,"%(cmd, tag, len(cdata), len(rdata))
+ print "\t\t{%s},"%hcdata
+ print "\t\t{%s},"%hrdata
+ print "\t},"
+print "};"
279 inits.h
@@ -0,0 +1,279 @@
+#include "cameras.h"
+
+const struct caminit inits[] = {
+ {
+ 0x00, 0x1258, 0, 20,
+ {},
+ {0x00, 0x00, 0x01, 0x05, 0x04, 0x00, 0x20, 0x20, 0x20, 0x00, 0x0b, 0x01, 0x07, 0x00, 0x01, 0x01, 0x25, 0x20, 0x00, 0x00},
+ },
+ {
+ 0x05, 0x1259, 0, 4,
+ {},
+ {0x00, 0x00, 0x01, 0x00},
+ },
+ {
+ 0x94, 0x125a, 8, 4,
+ {0x25, 0x20, 0x01, 0x01, 0xff, 0xff, 0xff, 0xff},
+ {0x00, 0x00, 0x00, 0x00},
+ },
+ {
+ 0x13, 0x125b, 2, 486,
+ {0x00, 0x00},
+ {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x79, 0x56, 0x34, 0x12, 0x00, 0x20, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x41, 0xd8, 0x00, 0x80, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x07, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x02, 0x00, 0x07, 0x00, 0x04, 0x16, 0x01, 0x01, 0x00, 0x64, 0x00, 0x00, 0xa0, 0x00, 0x00, 0x00, 0x11, 0x75, 0x00, 0x80, 0x00, 0x00, 0x03, 0x00, 0x02, 0x00, 0x04, 0x16, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x4d, 0x00, 0x00, 0x00, 0xa4, 0xbd, 0x00, 0x80, 0x00, 0x00, 0x04, 0x00, 0x02, 0x00, 0x04, 0x16, 0x01, 0x01, 0x00, 0xf8, 0x00, 0x00, 0x47, 0x00, 0x00, 0x00, 0x6b, 0x53, 0x00, 0x80, 0x00, 0x00, 0x05, 0x00, 0x05, 0x00, 0x04, 0x16, 0x01, 0x01, 0x00, 0x02, 0x00, 0x00, 0x6d, 0x02, 0x00, 0x00, 0x76, 0xa6, 0x00, 0x80, 0x00, 0x00, 0x06, 0x00, 0x03, 0x00, 0x04, 0x16, 0x01, 0x01, 0x00, 0x80, 0x00, 0x00, 0xa3, 0x34, 0x00, 0x00, 0xcd, 0x34, 0x00, 0x80, 0x00, 0x00, 0x07, 0x00, 0x0c, 0x00, 0x25, 0x20, 0x01, 0x01, 0x00, 0x54, 0x07, 0x00, 0x6e, 0x00, 0x00, 0x00, 0x8f, 0x76, 0x00, 0x80, 0x00, 0x00, 0x08, 0x00, 0x0a, 0x00, 0x04, 0x16, 0x01, 0x01, 0x00, 0x66, 0x00, 0x00, 0xc8, 0x03, 0x00, 0x00, 0x72, 0xef, 0x00, 0x80, 0x00, 0x00, 0x09, 0x00, 0x0b, 0x00, 0x04, 0x16, 0x01, 0x01, 0x00, 0x6f, 0x00, 0x00, 0xb2, 0x00, 0x00, 0x00, 0xe5, 0xd0, 0x00, 0x80, 0x00, 0x00, 0x0a, 0x00, 0x0c, 0x00, 0x04, 0x16, 0x01, 0x01, 0x10, 0x0c, 0x00, 0x00, 0xc2, 0x01, 0x00, 0x00, 0x86, 0xbd, 0x00, 0x80, 0x00, 0x00, 0x0b, 0x00, 0x04, 0x00, 0x04, 0x16, 0x01, 0x01, 0x00, 0xf0, 0x00, 0x00, 0x30, 0x00, 0x00, 0x00, 0x2c, 0x48, 0x00, 0x80, 0x00, 0x00, 0x0c, 0x00, 0x06, 0x00, 0x04, 0x16, 0x01, 0x01, 0x00, 0x00, 0x01, 0x00, 0xa8, 0xf4, 0x00, 0x00, 0x4f, 0x9f, 0x00, 0x80, 0x00, 0x00, 0x0d, 0x00, 0x11, 0x00, 0x04, 0x16, 0x01, 0x01, 0x00, 0x60, 0x00, 0x00, 0x6d, 0x02, 0x00, 0x00, 0x34, 0x15, 0x00, 0x80, 0x00, 0x00, 0x0e, 0x00, 0x09, 0x00, 0x04, 0x16, 0x01, 0x01, 0x00, 0x63, 0x00, 0x00, 0x0e, 0x00, 0x00, 0x00, 0xf0, 0x2c, 0x00, 0x80, 0x00, 0x00, 0x0f, 0x00, 0x12, 0x00, 0x04, 0x16, 0x01, 0x01, 0x10, 0x06, 0x00, 0x00, 0x37, 0x03, 0x00, 0x00, 0x1a, 0xf5, 0x00, 0x80, 0x00, 0x00, 0x10, 0x00, 0x0e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x03, 0x00, 0x56, 0xa7, 0x00, 0x80, 0x00, 0x00, 0x11, 0x00, 0x14, 0x00, 0x04, 0x16, 0x01, 0x01, 0x50, 0x05, 0x00, 0x00, 0x16, 0x00, 0x00, 0x00, 0xdc, 0xe4, 0x00, 0x80, 0x00, 0x00, 0x12, 0x00, 0x15, 0x00, 0x04, 0x16, 0x01, 0x01, 0x80, 0x05, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0xa5, 0x0b, 0x00, 0x80, 0x00, 0x00, 0x13, 0x00, 0x16, 0x00, 0x04, 0x16, 0x01, 0x01, 0xb0, 0x05, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0xe5, 0x85, 0x00, 0x80, 0x00, 0x00, 0x14, 0x00, 0x17, 0x00, 0x04, 0x16, 0x01, 0x01, 0xe0, 0x05, 0x00, 0x00, 0x0c, 0x00, 0x00, 0x00, 0xfb, 0x96, 0x00, 0x80, 0x00, 0x00, 0x15, 0x00, 0x13, 0x00, 0x04, 0x16, 0x01, 0x01, 0x10, 0x0a, 0x00, 0x00, 0xc3, 0x00, 0x00, 0x00, 0xe0, 0x53, 0x00, 0x80, 0x00, 0x00},
+ },
+ {
+ 0x13, 0x125c, 2, 156,
+ {0x16, 0x00},
+ {0x00, 0x00, 0x16, 0x00, 0x09, 0x00, 0x25, 0x20, 0x01, 0x01, 0x00, 0x43, 0x07, 0x00, 0x0e, 0x00, 0x00, 0x00, 0xf0, 0x2c, 0x00, 0x80, 0x00, 0x00, 0x17, 0x00, 0x0b, 0x00, 0x25, 0x20, 0x01, 0x01, 0x00, 0x4f, 0x07, 0x00, 0x3c, 0x00, 0x00, 0x00, 0xcd, 0xb7, 0x00, 0x80, 0x00, 0x00, 0x18, 0x00, 0x07, 0x00, 0x25, 0x20, 0x01, 0x01, 0x00, 0x44, 0x07, 0x00, 0xa0, 0x00, 0x00, 0x00, 0x11, 0x75, 0x00, 0x80, 0x00, 0x00, 0x19, 0x00, 0x12, 0x00, 0x25, 0x20, 0x01, 0x01, 0x00, 0x50, 0x07, 0x00, 0xa7, 0x00, 0x00, 0x00, 0xae, 0xd6, 0x00, 0x80, 0x00, 0x00, 0x1a, 0x00, 0x0a, 0x00, 0x25, 0x20, 0x01, 0x01, 0x00, 0x46, 0x07, 0x00, 0xc8, 0x03, 0x00, 0x00, 0x72, 0xef, 0x00, 0x80, 0x00, 0x00, 0x1b, 0x00, 0x11, 0x00, 0x25, 0x20, 0x01, 0x01, 0x00, 0x40, 0x07, 0x00, 0x7e, 0x00, 0x00, 0x00, 0x82, 0xb6, 0x00, 0x80, 0x00, 0x00, 0x1c, 0x00, 0x06, 0x00, 0x25, 0x20, 0x01, 0x01, 0x00, 0x00, 0x06, 0x00, 0x98, 0xf7, 0x00, 0x00, 0x26, 0x1f, 0x00, 0x80, 0x00, 0x00},
+ },
+ {
+ 0x13, 0x125d, 2, 2,
+ {0x1d, 0x00},
+ {0x00, 0x00},
+ },
+ {
+ 0x01, 0x125e, 0, 4,
+ {},
+ {0x00, 0x00, 0x00, 0x00},
+ },
+ {
+ 0x06, 0x125f, 2, 2,
+ {0x03, 0x00},
+ {0x00, 0x00},
+ },
+ {
+ 0x01, 0x1260, 0, 4,
+ {},
+ {0x00, 0x00, 0x00, 0x00},
+ },
+ {
+ 0x04, 0x1261, 2, 230,
+ {0x17, 0x00},
+ {0x00, 0x00, 0x00, 0x00, 0xf0, 0x40, 0x33, 0x33, 0x13, 0x40, 0x00, 0x00, 0xf0, 0x42, 0xcf, 0x66, 0xd5, 0x3d, 0x13, 0x00, 0x04, 0x00, 0x04, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x2c, 0x01, 0x00, 0x00, 0x2c, 0x01, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xd0, 0x07, 0x00, 0x00, 0xc8, 0x00, 0x00, 0x00, 0xc8, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x32, 0x00, 0x00, 0x00, 0xf4, 0x01, 0x00, 0x00, 0x0a, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0xf4, 0x01, 0x00, 0x00, 0x70, 0x17, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xd0, 0x07, 0x00, 0x00, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x64, 0x00, 0x00, 0x00, 0x2c, 0x01, 0x00, 0x00, 0xed, 0x17, 0x00, 0x00, 0x5a, 0x00, 0x00, 0x00, 0x5a, 0x00, 0x00, 0x00, 0xc8, 0x00, 0x00, 0x00, 0xc8, 0x00, 0x00, 0x00, 0x14, 0x05, 0x00, 0x00, 0x23, 0x00, 0x00, 0x00, 0x64, 0x00, 0x00, 0x00, 0xa0, 0x86, 0x01, 0x00, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x5e, 0x04, 0x00, 0x00, 0xae, 0x02, 0x00, 0x00, 0x64, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x0a, 0x00, 0x00, 0x00, 0x32, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
+ },
+ {
+ 0x16, 0x1262, 10, 4,
+ {0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x1e, 0x00, 0x00, 0x00},
+ {0x00, 0x00, 0xc8, 0x00},
+ },
+ {
+ 0x16, 0x1263, 10, 14,
+ {0xc0, 0x00, 0x00, 0x00, 0x01, 0x00, 0x1e, 0x00, 0x00, 0x00},
+ {0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0xdb, 0xaf, 0x81, 0x3f, 0xde, 0x9f, 0xce, 0xc1},
+ },
+ {
+ 0x16, 0x1264, 10, 118,
+ {0x40, 0x00, 0x00, 0x00, 0x01, 0x00, 0x1e, 0x00, 0x00, 0x00},
+ {0x00, 0x00, 0x20, 0x0b, 0x1b, 0x72, 0x43, 0x07, 0x00, 0x00, 0x94, 0xff, 0xff, 0xff, 0x10, 0x00, 0x00, 0x00, 0x10, 0x02, 0x00, 0x00, 0xd3, 0x03, 0x00, 0x00, 0x37, 0x00, 0x00, 0x00, 0x99, 0x0a, 0x00, 0x00, 0x6f, 0x02, 0x00, 0x00, 0x1a, 0x00, 0x00, 0x00, 0x57, 0x1c, 0x00, 0x00, 0x4e, 0x27, 0x00, 0x00, 0xf1, 0xfe, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xaa, 0x00, 0x00, 0x00, 0x88, 0x00, 0x00, 0x00, 0x36, 0xfd, 0x1f, 0x00, 0xde, 0x03, 0x00, 0x00, 0xd5, 0x02, 0x00, 0x00, 0xc9, 0xfc, 0x1f, 0x00, 0xb3, 0xf5, 0xff, 0x07, 0xb4, 0xfd, 0xff, 0x07, 0x38, 0xfd, 0xff, 0x07, 0x5f, 0xfc, 0xff, 0x07, 0x00, 0x00, 0x00, 0x00, 0xb7, 0xfd, 0xff, 0x07, 0x00, 0x00, 0x00, 0x00, 0xe2, 0xf4, 0xff, 0x07},
+ },
+ {
+ 0x16, 0x1265, 10, 4,
+ {0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x1e, 0x00, 0xfb, 0x00},
+ {0x05, 0x00, 0x00, 0x00},
+ },
+ {
+ 0x04, 0x1266, 2, 322,
+ {0x00, 0x00},
+ {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x4b, 0x4c, 0x00, 0x01, 0x00, 0x00, 0x00, 0xff, 0xff, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x5d, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x48, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf0, 0x40, 0x33, 0x33, 0x13, 0x40, 0x00, 0x00, 0xf0, 0x42, 0xcf, 0x66, 0xd5, 0x3d, 0x13, 0x00, 0x04, 0x00, 0x04, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x2c, 0x01, 0x00, 0x00, 0x2c, 0x01, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xd0, 0x07, 0x00, 0x00, 0xc8, 0x00, 0x00, 0x00, 0xc8, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x32, 0x00, 0x00, 0x00, 0xf4, 0x01, 0x00, 0x00, 0x0a, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0xf4, 0x01, 0x00, 0x00, 0x70, 0x17, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xd0, 0x07, 0x00, 0x00, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x64, 0x00, 0x00, 0x00, 0x2c, 0x01, 0x00, 0x00, 0xed, 0x17, 0x00, 0x00, 0x5a, 0x00, 0x00, 0x00, 0x5a, 0x00, 0x00, 0x00, 0xc8, 0x00, 0x00, 0x00, 0xc8, 0x00, 0x00, 0x00, 0x14, 0x05, 0x00, 0x00, 0x23, 0x00, 0x00, 0x00, 0x64, 0x00, 0x00, 0x00, 0xa0, 0x86, 0x01, 0x00, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x5e, 0x04, 0x00, 0x00, 0xae, 0x02, 0x00, 0x00, 0x64, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x0a, 0x00, 0x00, 0x00, 0x32, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
+ },
+ {
+ 0x03, 0x1267, 4, 2,
+ {0x06, 0x00, 0x00, 0x00},
+ {0x00, 0x00},
+ },
+ {
+ 0x03, 0x1268, 4, 2,
+ {0x12, 0x00, 0x03, 0x00},
+ {0x00, 0x00},
+ },
+ {
+ 0x03, 0x1269, 4, 2,
+ {0x13, 0x00, 0x01, 0x00},
+ {0x00, 0x00},
+ },
+ {
+ 0x03, 0x126a, 4, 2,
+ {0x14, 0x00, 0x1e, 0x00},
+ {0x00, 0x00},
+ },
+ {
+ 0x03, 0x126b, 4, 2,
+ {0x06, 0x00, 0x02, 0x00},
+ {0x00, 0x00},
+ },
+ {
+ 0x91, 0x126c, 2, 2,
+ {0x01, 0x00},
+ {0x02, 0x00},
+ },
+ {
+ 0x8d, 0x126d, 0, 20,
+ {},
+ {0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x08, 0x9b, 0x00, 0x5a, 0x00, 0x58, 0x00, 0x84, 0x03, 0x00, 0x00},
+ },
+ {
+ 0x03, 0x126e, 4, 2,
+ {0x06, 0x00, 0x00, 0x00},
+ {0x00, 0x00},
+ },
+ {
+ 0x03, 0x126f, 4, 2,
+ {0x12, 0x00, 0x03, 0x00},
+ {0x00, 0x00},
+ },
+ {
+ 0x03, 0x1270, 4, 2,
+ {0x13, 0x00, 0x01, 0x00},
+ {0x00, 0x00},
+ },
+ {
+ 0x03, 0x1271, 4, 2,
+ {0x14, 0x00, 0x1e, 0x00},
+ {0x00, 0x00},
+ },
+ {
+ 0x03, 0x1272, 4, 2,
+ {0x16, 0x00, 0x01, 0x00},
+ {0x00, 0x00},
+ },
+ {
+ 0x03, 0x1273, 4, 2,
+ {0x18, 0x00, 0x00, 0x00},
+ {0x00, 0x00},
+ },
+ {
+ 0x03, 0x1274, 4, 2,
+ {0x02, 0x00, 0x00, 0x00},
+ {0x00, 0x00},
+ },
+ {
+ 0x03, 0x1275, 4, 2,
+ {0x05, 0x01, 0x00, 0x00},
+ {0x00, 0x00},
+ },
+ {
+ 0x03, 0x1276, 4, 2,
+ {0x24, 0x00, 0x01, 0x00},
+ {0x00, 0x00},
+ },
+ {
+ 0x03, 0x1277, 4, 2,
+ {0x2d, 0x00, 0x01, 0x00},
+ {0x00, 0x00},
+ },
+ {
+ 0x03, 0x1278, 4, 2,
+ {0x06, 0x00, 0x02, 0x00},
+ {0x00, 0x00},
+ },
+ {
+ 0x03, 0x1279, 4, 2,
+ {0x05, 0x00, 0x00, 0x00},
+ {0x00, 0x00},
+ },
+ {
+ 0x03, 0x127a, 4, 2,
+ {0x0c, 0x00, 0x01, 0x00},
+ {0x00, 0x00},
+ },
+ {
+ 0x03, 0x127b, 4, 2,
+ {0x0d, 0x00, 0x01, 0x00},
+ {0x00, 0x00},
+ },
+ {
+ 0x03, 0x127c, 4, 2,
+ {0x0e, 0x00, 0x1e, 0x00},
+ {0x00, 0x00},
+ },
+ {
+ 0x03, 0x127d, 4, 2,
+ {0x05, 0x00, 0x01, 0x00},
+ {0x00, 0x00},
+ },
+ {
+ 0x03, 0x127e, 4, 2,
+ {0x47, 0x00, 0x00, 0x00},
+ {0x00, 0x00},
+ },
+ {
+ 0x03, 0x127f, 4, 2,
+ {0x0c, 0x00, 0x00, 0x00},
+ {0x00, 0x00},
+ },
+ {
+ 0x03, 0x1280, 4, 2,
+ {0x05, 0x00, 0x00, 0x00},
+ {0x00, 0x00},
+ },
+ {
+ 0x03, 0x1281, 4, 2,
+ {0x0d, 0x00, 0x01, 0x00},
+ {0x00, 0x00},
+ },
+ {
+ 0x03, 0x1282, 4, 2,
+ {0x0e, 0x00, 0x1e, 0x00},
+ {0x00, 0x00},
+ },
+ {
+ 0x03, 0x1283, 4, 2,
+ {0x05, 0x00, 0x01, 0x00},
+ {0x00, 0x00},
+ },
+ {
+ 0x03, 0x1284, 4, 2,
+ {0x47, 0x00, 0x00, 0x00},
+ {0x00, 0x00},
+ },
+ {
+ 0x95, 0x1605, 6, 6,
+ {0x01, 0x00, 0x38, 0x82, 0x40, 0x04},
+ {0x00, 0x00, 0x38, 0xc2, 0x40, 0x04},
+ },
+ {
+ 0x95, 0x1606, 50, 50,
+ {0x0c, 0x00, 0x21, 0x80, 0x00, 0x80, 0x04, 0x80, 0x00, 0x05, 0x03, 0x80, 0x00, 0x04, 0x07, 0x80, 0x8e, 0x02, 0x08, 0x80, 0x5f, 0x00, 0x0b, 0x80, 0x46, 0x00, 0x39, 0x82, 0x16, 0x05, 0x57, 0x82, 0x64, 0x02, 0x58, 0x82, 0xe0, 0x02, 0x5c, 0x82, 0x10, 0x15, 0x5d, 0x82, 0x15, 0x1a, 0x3b, 0x82, 0xe6, 0x04},
+ {0x00, 0x00, 0x21, 0xc0, 0x00, 0x80, 0x04, 0xc0, 0x00, 0x05, 0x03, 0xc0, 0x00, 0x04, 0x07, 0xc0, 0x8e, 0x02, 0x08, 0xc0, 0x5f, 0x00, 0x0b, 0xc0, 0x46, 0x00, 0x39, 0xc2, 0x16, 0x05, 0x57, 0xc2, 0x64, 0x02, 0x58, 0xc2, 0xe0, 0x02, 0x5c, 0xc2, 0x10, 0x15, 0x5d, 0xc2, 0x15, 0x1a, 0x3b, 0xc2, 0xe6, 0x04},
+ },
+ {
+ 0x95, 0x1607, 50, 50,
+ {0x0c, 0x00, 0x02, 0x80, 0x68, 0x00, 0x01, 0x80, 0x1c, 0x00, 0x25, 0x81, 0x05, 0x00, 0x05, 0x81, 0x03, 0x00, 0x47, 0x81, 0x30, 0x10, 0x9d, 0x81, 0xae, 0x3c, 0x53, 0x81, 0x10, 0x20, 0x54, 0x81, 0x40, 0x60, 0x55, 0x81, 0x80, 0xa0, 0x56, 0x81, 0xc0, 0xd0, 0x57, 0x81, 0xe0, 0xf0, 0x58, 0x81, 0x00, 0xff},
+ {0x00, 0x00, 0x02, 0xc0, 0x68, 0x00, 0x01, 0xc0, 0x1c, 0x00, 0x25, 0xc1, 0x05, 0x00, 0x05, 0xc1, 0x03, 0x00, 0x47, 0xc1, 0x30, 0x10, 0x9d, 0xc1, 0xae, 0x3c, 0x53, 0xc1, 0x10, 0x20, 0x54, 0xc1, 0x40, 0x60, 0x55, 0xc1, 0x80, 0xa0, 0x56, 0xc1, 0xc0, 0xd0, 0x57, 0xc1, 0xe0, 0xf0, 0x58, 0xc1, 0x00, 0xff},
+ },
+ {
+ 0x95, 0x1608, 26, 26,
+ {0x06, 0x00, 0x06, 0x81, 0x82, 0x74, 0x2e, 0x82, 0x44, 0x10, 0x2f, 0x82, 0x00, 0x91, 0x26, 0x82, 0x0c, 0x73, 0x27, 0x82, 0x0c, 0x73, 0x37, 0x82, 0x80, 0x80},
+ {0x00, 0x00, 0x06, 0xc1, 0x82, 0x74, 0x2e, 0xc2, 0x44, 0x10, 0x2f, 0xc2, 0x00, 0x91, 0x26, 0xc2, 0x0c, 0x73, 0x27, 0xc2, 0x0c, 0x73, 0x37, 0xc2, 0x80, 0x80},
+ },
+ {
+ 0x22, 0x1285, 6, 2,
+ {0x5f, 0x00, 0x00, 0x00, 0x00, 0x00},
+ {0x00, 0x00},
+ },
+ {
+ 0x95, 0x1609, 2, 2,
+ {0x00, 0x00},
+ {0x00, 0x00},
+ },
+ {
+ 0x22, 0x1286, 6, 2,
+ {0x4a, 0x00, 0x01, 0x00, 0x00, 0x00},
+ {0x00, 0x00},
+ },
+ {
+ 0x95, 0x160a, 10, 10,
+ {0x02, 0x00, 0x08, 0x80, 0x5e, 0x00, 0x0b, 0x80, 0x88, 0x03},
+ {0x00, 0x00, 0x08, 0xc0, 0x5e, 0x00, 0x0b, 0xc0, 0x88, 0x03},
+ },
+ {
+ 0x95, 0x160b, 34, 34,
+ {0x08, 0x00, 0x47, 0x81, 0x00, 0x00, 0x53, 0x81, 0x04, 0x0e, 0x54, 0x81, 0x28, 0x4c, 0x55, 0x81, 0x77, 0x97, 0x56, 0x81, 0xb1, 0xc7, 0x57, 0x81, 0xdb, 0xee, 0x58, 0x81, 0x00, 0xff, 0x06, 0x81, 0x82, 0x60},
+ {0x00, 0x00, 0x47, 0xc1, 0x00, 0x00, 0x53, 0xc1, 0x04, 0x0e, 0x54, 0xc1, 0x28, 0x4c, 0x55, 0xc1, 0x77, 0x97, 0x56, 0xc1, 0xb1, 0xc7, 0x57, 0xc1, 0xdb, 0xee, 0x58, 0xc1, 0x00, 0xff, 0x06, 0xc1, 0x82, 0x60},
+ },
+ {
+ 0x95, 0x160c, 22, 22,
+ {0x05, 0x00, 0x2d, 0x00, 0x00, 0x00, 0x2b, 0x00, 0x00, 0x00, 0x2c, 0x00, 0x00, 0x00, 0x09, 0x00, 0x00, 0x00, 0x5b, 0x02, 0x00, 0x00},
+ {0x00, 0x00, 0x2d, 0x40, 0xc8, 0x01, 0x2b, 0x40, 0xba, 0x01, 0x2c, 0x40, 0xd2, 0x01, 0x09, 0x40, 0x64, 0x02, 0x5b, 0x42, 0x00, 0x80},
+ },
+};
55 inits.txt
@@ -0,0 +1,55 @@
+00,1258,,000001050400202020000b010700010125200000
+05,1259,,00000100
+94,125a,25200101ffffffff,00000000
+13,125b,0000,00000000000079563412002000000010000041d80080000001000100000000000080070000800000000000800000020007000416010100640000a00000001175008000000300020004160101000000004d000000a4bd00800000040002000416010100f80000470000006b53008000000500050004160101000200006d02000076a600800000060003000416010100800000a3340000cd340080000007000c0025200101005407006e0000008f760080000008000a000416010100660000c803000072ef0080000009000b0004160101006f0000b2000000e5d0008000000a000c0004160101100c0000c201000086bd008000000b0004000416010100f00000300000002c48008000000c0006000416010100000100a8f400004f9f008000000d00110004160101006000006d0200003415008000000e00090004160101006300000e000000f02c008000000f0012000416010110060000370300001af50080000010000e0000000000000003000000030056a70080000011001400041601015005000016000000dce40080000012001500041601018005000004000000a50b008000001300160004160101b005000010000000e585008000001400170004160101e00500000c000000fb96008000001500130004160101100a0000c3000000e05300800000
+13,125c,1600,00001600090025200101004307000e000000f02c0080000017000b0025200101004f07003c000000cdb700800000180007002520010100440700a0000000117500800000190012002520010100500700a7000000aed6008000001a000a002520010100460700c803000072ef008000001b00110025200101004007007e00000082b6008000001c000600252001010000060098f70000261f00800000
+13,125d,1d00,0000
+01,125e,,00000000
+06,125f,0300,0000
+01,1260,,00000000
+04,1261,1700,00000000f040333313400000f042cf66d53d13000400040000000500000005000000000000002c0100002c010000140000000000000001000000000000000100000000000000d0070000c8000000c80000000100000032000000f40100000a00000005000000f4010000701700000100000000000000d00700000f00000000000000640000002c010000ed1700005a0000005a000000c8000000c8000000140500002300000064000000a08601000500000000000000ffff000001000000010000005e040000ae020000640000000200000005000000010000000a0000003200000000000000
+16,1262,0000000001001e000000,0000c800
+16,1263,c000000001001e000000,000001000000dbaf813fde9fcec1
+16,1264,4000000001001e000000,0000200b1b724307000094ffffff1000000010020000d303000037000000990a00006f0200001a000000571c00004e270000f1fe01000000000000000000aa0000008800000036fd1f00de030000d5020000c9fc1f00b3f5ff07b4fdff0738fdff075ffcff0700000000b7fdff0700000000e2f4ff07
+16,1265,0100000001001e00fb00,05000000
+04,1266,0000,000000000000404b4c0001000000ffff0f0000000000050000000500000001000000060000000600000001000000000000000100000001000000010000005d000000000000000100000001000000010000004800000001000000010000000000f040333313400000f042cf66d53d13000400040000000500000005000000000000002c0100002c010000140000000000000001000000000000000100000000000000d0070000c8000000c80000000100000032000000f40100000a00000005000000f4010000701700000100000000000000d00700000f00000000000000640000002c010000ed1700005a0000005a000000c8000000c8000000140500002300000064000000a08601000500000000000000ffff000001000000010000005e040000ae020000640000000200000005000000010000000a0000003200000000000000
+03,1267,06000000,0000
+03,1268,12000300,0000
+03,1269,13000100,0000
+03,126a,14001e00,0000
+03,126b,06000200,0000
+91,126c,0100,0200
+8d,126d,,000001000000000800089b005a00580084030000
+03,126e,06000000,0000
+03,126f,12000300,0000
+03,1270,13000100,0000
+03,1271,14001e00,0000
+03,1272,16000100,0000
+03,1273,18000000,0000
+03,1274,02000000,0000
+03,1275,05010000,0000
+03,1276,24000100,0000
+03,1277,2d000100,0000
+03,1278,06000200,0000
+03,1279,05000000,0000
+03,127a,0c000100,0000
+03,127b,0d000100,0000
+03,127c,0e001e00,0000
+03,127d,05000100,0000
+03,127e,47000000,0000
+03,127f,0c000000,0000
+03,1280,05000000,0000
+03,1281,0d000100,0000
+03,1282,0e001e00,0000
+03,1283,05000100,0000
+03,1284,47000000,0000
+95,1605,010038824004,000038c24004
+95,1606,0c0021800080048000050380000407808e0208805f000b80460039821605578264025882e0025c8210155d82151a3b82e604,000021c0008004c0000503c0000407c08e0208c05f000bc0460039c2160557c2640258c2e0025cc210155dc2151a3bc2e604
+95,1607,0c000280680001801c002581050005810300478130109d81ae3c5381102054814060558180a05681c0d05781e0f0588100ff,000002c0680001c01c0025c1050005c1030047c130109dc1ae3c53c1102054c1406055c180a056c1c0d057c1e0f058c100ff
+95,1608,0600068182742e8244102f82009126820c7327820c7337828080,000006c182742ec244102fc2009126c20c7327c20c7337c28080
+22,1285,5f0000000000,0000
+95,1609,0000,0000
+22,1286,4a0001000000,0000
+95,160a,020008805e000b808803,000008c05e000bc08803
+95,160b,0800478100005381040e5481284c558177975681b1c75781dbee588100ff06818260,000047c1000053c1040e54c1284c55c1779756c1b1c757c1dbee58c100ff06c18260
+95,160c,05002d0000002b0000002c000000090000005b020000,00002d40c8012b40ba012c40d201094064025b420080
221 main.c
@@ -0,0 +1,221 @@
+#include <stdio.h>
+#include <string.h>
+#include <libusb-1.0/libusb.h>
+#include "cameras.h"
+
+#include <pthread.h>
+
+#include <GL/glut.h>
+#include <GL/gl.h>
+#include <GL/glu.h>
+
+pthread_t gl_thread;
+volatile int die = 0;
+
+int g_argc;
+char **g_argv;
+
+int window;
+
+pthread_mutex_t gl_backbuf_mutex = PTHREAD_MUTEX_INITIALIZER;
+
+uint8_t gl_depth_front[640*480*4];
+uint8_t gl_depth_back[640*480*4];
+
+uint8_t gl_rgb_front[640*480*4];
+uint8_t gl_rgb_back[640*480*4];
+
+int gl_depth_tex;
+int gl_rgb_tex;
+
+void DrawGLScene()
+{
+ pthread_mutex_lock(&gl_backbuf_mutex);
+ memcpy(gl_depth_front, gl_depth_back, sizeof(gl_depth_back));
+ memcpy(gl_rgb_front, gl_rgb_back, sizeof(gl_rgb_back));
+ pthread_mutex_unlock(&gl_backbuf_mutex);
+
+ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
+ glLoadIdentity();
+
+ glEnable(GL_TEXTURE_2D);
+
+ glBindTexture(GL_TEXTURE_2D, gl_depth_tex);
+ glTexImage2D(GL_TEXTURE_2D, 0, 3, 640, 480, 0, GL_RGB, GL_UNSIGNED_BYTE, gl_depth_front);
+
+ glBegin(GL_TRIANGLE_FAN);
+ glColor4f(255.0f, 255.0f, 255.0f, 255.0f);
+ glTexCoord2f(0, 0); glVertex3f(0,0,0);
+ glTexCoord2f(1, 0); glVertex3f(640,0,0);
+ glTexCoord2f(1, 1); glVertex3f(640,480,0);
+ glTexCoord2f(0, 1); glVertex3f(0,480,0);
+ glEnd();
+
+ glBindTexture(GL_TEXTURE_2D, gl_rgb_tex);
+ glTexImage2D(GL_TEXTURE_2D, 0, 3, 640, 480, 0, GL_RGB, GL_UNSIGNED_BYTE, gl_rgb_front);
+
+ glBegin(GL_TRIANGLE_FAN);
+ glColor4f(255.0f, 255.0f, 255.0f, 255.0f);
+ glTexCoord2f(0, 0); glVertex3f(640,0,0);
+ glTexCoord2f(1, 0); glVertex3f(1280,0,0);
+ glTexCoord2f(1, 1); glVertex3f(1280,480,0);
+ glTexCoord2f(0, 1); glVertex3f(640,480,0);
+ glEnd();
+
+ glutSwapBuffers();
+}
+
+void keyPressed(unsigned char key, int x, int y)
+{
+ if (key == 27) {
+ die = 1;
+ glutDestroyWindow(window);
+ pthread_exit(NULL);
+ }
+}
+
+void ReSizeGLScene(int Width, int Height)
+{
+ glViewport(0,0,Width,Height);
+ glMatrixMode(GL_PROJECTION);
+ glLoadIdentity();
+ glOrtho (0, 1280, 480, 0, -1.0f, 1.0f);
+ glMatrixMode(GL_MODELVIEW);
+}
+
+void InitGL(int Width, int Height)
+{
+ glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
+ glClearDepth(1.0);
+ glDepthFunc(GL_LESS);
+ glDisable(GL_DEPTH_TEST);
+ glEnable(GL_BLEND);
+ glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+ glShadeModel(GL_SMOOTH);
+ glGenTextures(1, &gl_depth_tex);
+ glBindTexture(GL_TEXTURE_2D, gl_depth_tex);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
+ glGenTextures(1, &gl_rgb_tex);
+ glBindTexture(GL_TEXTURE_2D, gl_rgb_tex);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
+ ReSizeGLScene(Width, Height);
+}
+
+void *gl_threadfunc(void *arg)
+{
+ printf("GL thread\n");
+
+ glutInit(&g_argc, g_argv);
+
+ glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GLUT_ALPHA | GLUT_DEPTH);
+ glutInitWindowSize(1280, 480);
+ glutInitWindowPosition(0, 0);
+
+ window = glutCreateWindow("LibFreenect");
+
+ glutDisplayFunc(&DrawGLScene);
+ glutIdleFunc(&DrawGLScene);
+ glutReshapeFunc(&ReSizeGLScene);
+ glutKeyboardFunc(&keyPressed);
+
+ InitGL(1280, 480);
+
+ glutMainLoop();
+
+ pthread_exit(NULL);
+ return NULL;
+}
+
+void depthimg(uint16_t *buf, int width, int height)
+{
+/* FILE *f = fopen("depth.bin", "w");
+ fwrite(depth_frame, 640*480, 2, f);
+ fclose(f);*/
+
+ int i;
+
+ pthread_mutex_lock(&gl_backbuf_mutex);
+ for (i=0; i<640*480; i++) {
+ int pval = (buf[i]*8)/256;
+ int lb = pval & 0xff;
+ switch (pval>>8) {
+ case 0:
+ gl_depth_back[3*i+0] = 255;
+ gl_depth_back[3*i+1] = lb;
+ gl_depth_back[3*i+2] = lb;
+ break;
+ case 1:
+ gl_depth_back[3*i+0] = 255;
+ gl_depth_back[3*i+1] = lb;
+ gl_depth_back[3*i+2] = 0;
+ break;
+ case 2:
+ gl_depth_back[3*i+0] = 255-lb;
+ gl_depth_back[3*i+1] = 255;
+ gl_depth_back[3*i+2] = 0;
+ break;
+ case 3:
+ gl_depth_back[3*i+0] = 0;
+ gl_depth_back[3*i+1] = 255;
+ gl_depth_back[3*i+2] = lb;
+ break;
+ case 4:
+ gl_depth_back[3*i+0] = 0;
+ gl_depth_back[3*i+1] = 255-lb;
+ gl_depth_back[3*i+2] = 255;
+ break;
+ case 5:
+ gl_depth_back[3*i+0] = 0;
+ gl_depth_back[3*i+1] = 0;
+ gl_depth_back[3*i+2] = 255-lb;
+ break;
+ default:
+ gl_depth_back[3*i+0] = 0;
+ gl_depth_back[3*i+1] = 0;
+ gl_depth_back[3*i+2] = 0;
+ break;
+ }
+ }
+ pthread_mutex_unlock(&gl_backbuf_mutex);
+}
+
+void rgbimg(uint8_t *buf, int width, int height)
+{
+ int i;
+
+ pthread_mutex_lock(&gl_backbuf_mutex);
+ memcpy(gl_rgb_back, buf, width*height*3);
+ pthread_mutex_unlock(&gl_backbuf_mutex);
+}
+
+
+int main(int argc, char **argv)
+{
+ int res;
+ libusb_device_handle *dev;
+ printf("Kinect camera test\n");
+
+ g_argc = argc;
+ g_argv = argv;
+
+ libusb_init(NULL);
+
+ dev = libusb_open_device_with_vid_pid(NULL, 0x45e, 0x2ae);
+ if (!dev) {
+ printf("Could not open device\n");
+ return 1;
+ }
+
+ res = pthread_create(&gl_thread, NULL, gl_threadfunc, NULL);
+ if (res) {
+ printf("pthread_create failed\n");
+ return 1;
+ }
+
+ cams_init(dev, depthimg, rgbimg);
+
+ while(!die && libusb_handle_events(NULL) == 0);
+ pthread_exit(NULL);
+}

0 comments on commit 4094151

Please sign in to comment.