Skip to content

Commit 5177a1d

Browse files
committed
frame: Update format definitions
1 parent 4cb9fc0 commit 5177a1d

10 files changed

+50
-34
lines changed

include/libfreenect2/frame_listener.hpp

Lines changed: 12 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -47,20 +47,20 @@ class LIBFREENECT2_API Frame
4747
/** Available types of frames. */
4848
enum Type
4949
{
50-
Color = 1, ///< 1920x1080 32-bit BGRX.
50+
Color = 1, ///< 1920x1080
5151
Ir = 2, ///< 512x424 float. Range is [0.0, 65535.0].
5252
Depth = 4 ///< 512x424 float, unit: millimeter. Non-positive, NaN, and infinity are invalid or missing data.
5353
};
5454

55-
/** (Proposed for 0.2) Pixel format. */
55+
/** Pixel format. */
5656
enum Format
5757
{
58-
BGRX,
59-
RGBX,
60-
Gray,
61-
Float,
62-
// Note that if format is 'raw' then 'bytes_per_pixel' actually contains the number of bytes
63-
Raw
58+
Invalid = 0, ///< Invalid format.
59+
Raw = 1, ///< Raw bitstream. 'bytes_per_pixel' defines the number of bytes
60+
Float = 2, ///< A 4-byte float per pixel
61+
BGRX = 4, ///< 4 bytes of B, G, R, and unused per pixel
62+
RGBX = 5, ///< 4 bytes of R, G, B, and unused per pixel
63+
Gray = 6, ///< 1 byte of gray per pixel
6464
};
6565

6666
size_t width; ///< Length of a line (in pixels).
@@ -72,39 +72,17 @@ class LIBFREENECT2_API Frame
7272
float exposure; ///< From 0.5 (very bright) to ~60.0 (fully covered)
7373
float gain; ///< From 1.0 (bright) to 1.5 (covered)
7474
float gamma; ///< From 1.0 (bright) to 6.4 (covered)
75-
uint32_t status; ///< Reserved. To be defined in 0.2.
76-
Format format; ///< Reserved. To be defined in 0.2.
75+
uint32_t status; ///< zero if ok; non-zero for errors.
76+
Format format; ///< Byte format. Informative only, doesn't indicate errors.
7777

7878
/** Construct a new frame.
7979
* @param width Width in pixel
8080
* @param height Height in pixel
8181
* @param bytes_per_pixel Bytes per pixel
8282
* @param data_ Memory to store frame data. If `NULL`, new memory is allocated.
8383
*/
84-
Frame(size_t width, size_t height, size_t bytes_per_pixel, unsigned char *data_ = NULL) :
85-
width(width),
86-
height(height),
87-
bytes_per_pixel(bytes_per_pixel),
88-
data(data_),
89-
exposure(0.f),
90-
gain(0.f),
91-
gamma(0.f),
92-
rawdata(NULL)
93-
{
94-
if (data_)
95-
return;
96-
const size_t alignment = 64;
97-
size_t space = width * height * bytes_per_pixel + alignment;
98-
rawdata = new unsigned char[space];
99-
uintptr_t ptr = reinterpret_cast<uintptr_t>(rawdata);
100-
uintptr_t aligned = (ptr - 1u + alignment) & -alignment;
101-
data = reinterpret_cast<unsigned char *>(aligned);
102-
}
103-
104-
virtual ~Frame()
105-
{
106-
delete[] rawdata;
107-
}
84+
Frame(size_t width, size_t height, size_t bytes_per_pixel, unsigned char *data_ = NULL);
85+
virtual ~Frame();
10886

10987
protected:
11088
unsigned char* rawdata; ///< Unaligned start of #data.

src/cpu_depth_packet_processor.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,7 @@ class CpuDepthPacketProcessorImpl: public WithPerfLogging
301301
void newIrFrame()
302302
{
303303
ir_frame = new Frame(512, 424, 4);
304+
ir_frame->format = Frame::Float;
304305
//ir_frame = new Frame(512, 424, 12);
305306
}
306307

@@ -314,6 +315,7 @@ class CpuDepthPacketProcessorImpl: public WithPerfLogging
314315
void newDepthFrame()
315316
{
316317
depth_frame = new Frame(512, 424, 4);
318+
depth_frame->format = Frame::Float;
317319
}
318320

319321
int32_t decodePixelMeasurement(unsigned char* data, int sub, int x, int y)

src/cuda_depth_packet_processor.cu

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -867,11 +867,13 @@ public:
867867
void newIrFrame()
868868
{
869869
ir_frame = new CudaFrame(ir_allocator->allocate(IMAGE_SIZE*sizeof(float)));
870+
ir_frame->format = Frame::Float;
870871
}
871872

872873
void newDepthFrame()
873874
{
874875
depth_frame = new CudaFrame(depth_allocator->allocate(IMAGE_SIZE*sizeof(float)));
876+
depth_frame->format = Frame::Float;
875877
}
876878

877879
void fill_trig_table(const protocol::P0TablesResponse *p0table)

src/frame_listener_impl.cpp

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,33 @@
3232
namespace libfreenect2
3333
{
3434

35+
Frame::Frame(size_t width, size_t height, size_t bytes_per_pixel, unsigned char *data_) :
36+
width(width),
37+
height(height),
38+
bytes_per_pixel(bytes_per_pixel),
39+
data(data_),
40+
exposure(0.f),
41+
gain(0.f),
42+
gamma(0.f),
43+
status(0),
44+
format(Frame::Invalid),
45+
rawdata(NULL)
46+
{
47+
if (data_)
48+
return;
49+
const size_t alignment = 64;
50+
size_t space = width * height * bytes_per_pixel + alignment;
51+
rawdata = new unsigned char[space];
52+
uintptr_t ptr = reinterpret_cast<uintptr_t>(rawdata);
53+
uintptr_t aligned = (ptr - 1u + alignment) & -alignment;
54+
data = reinterpret_cast<unsigned char *>(aligned);
55+
}
56+
57+
Frame::~Frame()
58+
{
59+
delete[] rawdata;
60+
}
61+
3562
FrameListener::~FrameListener() {}
3663

3764
/** Implementation class for synchronizing different types of frames. */

src/opencl_depth_packet_processor.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -643,11 +643,13 @@ class OpenCLDepthPacketProcessorImpl: public WithPerfLogging
643643
void newIrFrame()
644644
{
645645
ir_frame = new OpenCLFrame(static_cast<OpenCLBuffer *>(ir_buffer_allocator->allocate(IMAGE_SIZE * sizeof(cl_float))));
646+
ir_frame->format = Frame::Float;
646647
}
647648

648649
void newDepthFrame()
649650
{
650651
depth_frame = new OpenCLFrame(static_cast<OpenCLBuffer *>(depth_buffer_allocator->allocate(IMAGE_SIZE * sizeof(cl_float))));
652+
depth_frame->format = Frame::Float;
651653
}
652654

653655
bool fill_trig_table(const libfreenect2::protocol::P0TablesResponse *p0table)

src/opengl_depth_packet_processor.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -385,6 +385,7 @@ struct Texture : public WithOpenGLBindings
385385
Frame *downloadToNewFrame()
386386
{
387387
Frame *f = new Frame(width, height, bytes_per_pixel);
388+
f->format = Frame::Float;
388389
downloadToBuffer(f->data);
389390
flipYBuffer(f->data);
390391

src/tegra_jpeg_rgb_packet_processor.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,7 @@ class TegraJpegRgbPacketProcessorImpl: public WithPerfLogging
194194
void newFrame()
195195
{
196196
frame = new TegraFrame(WIDTH, HEIGHT, BPP, static_cast<TegraImage *>(image_allocator->allocate(0)));
197+
frame->format = Format:RGBX;
197198
}
198199

199200
static inline TegraJpegRgbPacketProcessorImpl *owner(j_decompress_ptr dinfo)

src/turbo_jpeg_rgb_packet_processor.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ class TurboJpegRgbPacketProcessorImpl: public WithPerfLogging
6969
void newFrame()
7070
{
7171
frame = new Frame(1920, 1080, tjPixelSize[TJPF_BGRX]);
72+
frame->format = Frame::BGRX;
7273
}
7374
};
7475

src/vaapi_rgb_packet_processor.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,7 @@ class VaapiRgbPacketProcessorImpl: public WithPerfLogging
247247
void newFrame()
248248
{
249249
frame = new VaapiFrame(static_cast<VaapiImage *>(image_allocator->allocate(0)));
250+
frame->format = Frame::BGRX;
250251
}
251252

252253
bool initializeVaapi()

src/vt_rgb_packet_processor.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ void VTRgbPacketProcessor::process(const RgbPacket &packet)
156156
VTDecompressionSessionDecodeFrame(impl_->decoder, sampleBuffer, 0, &pixelBuffer, NULL);
157157

158158
Frame *frame = new VTFrame(1920, 1080, 4, pixelBuffer);
159+
frame->format = Frame::BGRX;
159160

160161
frame->timestamp = packet.timestamp;
161162
frame->sequence = packet.sequence;

0 commit comments

Comments
 (0)