我想從這個靜態變量中獲得一個常量變量。如何從C中的靜態變量聲明一個常量變量?
#define video_mode_count 12
static freenect_frame_mode supported_video_modes[video_mode_count] = {
// reserved, resolution, format, bytes, width, height, data_bits_per_pixel, padding_bits_per_pixel, framerate, is_valid
{MAKE_RESERVED(FREENECT_RESOLUTION_HIGH, FREENECT_VIDEO_RGB), FREENECT_RESOLUTION_HIGH, {FREENECT_VIDEO_RGB}, 1280*1024*3, 1280, 1024, 24, 0, 10, 1 },
{MAKE_RESERVED(FREENECT_RESOLUTION_MEDIUM, FREENECT_VIDEO_RGB), FREENECT_RESOLUTION_MEDIUM, {FREENECT_VIDEO_RGB}, 640*480*3, 640, 480, 24, 0, 30, 1 },
{MAKE_RESERVED(FREENECT_RESOLUTION_HIGH, FREENECT_VIDEO_BAYER), FREENECT_RESOLUTION_HIGH, {FREENECT_VIDEO_BAYER}, 1280*1024, 1280, 1024, 8, 0, 10, 1 },
{MAKE_RESERVED(FREENECT_RESOLUTION_MEDIUM, FREENECT_VIDEO_BAYER), FREENECT_RESOLUTION_MEDIUM, {FREENECT_VIDEO_BAYER}, 640*480, 640, 480, 8, 0, 30, 1 },
{MAKE_RESERVED(FREENECT_RESOLUTION_HIGH, FREENECT_VIDEO_IR_8BIT), FREENECT_RESOLUTION_HIGH, {FREENECT_VIDEO_IR_8BIT}, 1280*1024, 1280, 1024, 8, 0, 10, 1 },
{MAKE_RESERVED(FREENECT_RESOLUTION_MEDIUM, FREENECT_VIDEO_IR_8BIT), FREENECT_RESOLUTION_MEDIUM, {FREENECT_VIDEO_IR_8BIT}, 640*488, 640, 488, 8, 0, 30, 1 },
{MAKE_RESERVED(FREENECT_RESOLUTION_HIGH, FREENECT_VIDEO_IR_10BIT), FREENECT_RESOLUTION_HIGH, {FREENECT_VIDEO_IR_10BIT}, 1280*1024*2, 1280, 1024, 10, 6, 10, 1 },
{MAKE_RESERVED(FREENECT_RESOLUTION_MEDIUM, FREENECT_VIDEO_IR_10BIT), FREENECT_RESOLUTION_MEDIUM, {FREENECT_VIDEO_IR_10BIT}, 640*488*2, 640, 488, 10, 6, 30, 1 },
{MAKE_RESERVED(FREENECT_RESOLUTION_HIGH, FREENECT_VIDEO_IR_10BIT_PACKED), FREENECT_RESOLUTION_HIGH, {FREENECT_VIDEO_IR_10BIT_PACKED}, 1280*1024*10/8, 1280, 1024, 10, 0, 10, 1 },
{MAKE_RESERVED(FREENECT_RESOLUTION_MEDIUM, FREENECT_VIDEO_IR_10BIT_PACKED), FREENECT_RESOLUTION_MEDIUM, {FREENECT_VIDEO_IR_10BIT_PACKED}, 640*488*10/8, 640, 488, 10, 0, 30, 1 },
{MAKE_RESERVED(FREENECT_RESOLUTION_MEDIUM, FREENECT_VIDEO_YUV_RGB), FREENECT_RESOLUTION_MEDIUM, {FREENECT_VIDEO_YUV_RGB}, 640*480*3, 640, 480, 24, 0, 15, 1 },
{MAKE_RESERVED(FREENECT_RESOLUTION_MEDIUM, FREENECT_VIDEO_YUV_RAW), FREENECT_RESOLUTION_MEDIUM, {FREENECT_VIDEO_YUV_RAW}, 640*480*2, 640, 480, 16, 0, 15, 1 },};
現在我需要寫的東西
const FREENECT_VIDEO_RGB = [ An instance in the type of freenect_frame_mode ]
如何聲明該格式一個const變種?
原代碼來自:
https://github.com/OpenKinect/libfreenect/blob/master/src/cameras.c#L42
我需要傳遞一個const變種freenect_frame_mode成這樣了,看看它是否返回-1與否:
https://github.com/OpenKinect/libfreenect/blob/master/src/cameras.c#L1152
int freenect_set_video_mode(freenect_device* dev, const freenect_frame_mode mode)
{
freenect_context *ctx = dev->parent;
if (dev->video.running) {
FN_ERROR("Tried to set video mode while stream is active\n");
return -1;
}
// Verify that the mode passed in is actually in the supported mode list
int found = 0;
int i;
for(i = 0 ; i < video_mode_count; i++) {
if (supported_video_modes[i].reserved == mode.reserved) {
found = 1;
break;
}
}
if (!found) {
FN_ERROR("freenect_set_video_mode: freenect_frame_mode provided is invalid\n");
return -1;
}
freenect_resolution res = RESERVED_TO_RESOLUTION(mode.reserved);
freenect_video_format fmt = (freenect_video_format)RESERVED_TO_FORMAT(mode.reserved);
dev->video_format = fmt;
dev->video_resolution = res;
// Now that we've changed video format and resolution, we need to update
// registration tables.
freenect_fetch_reg_info(dev);
return 0;
}
我只是堅持使用現在的功能。
謝謝!
一個常量變量是definitelly不可變.... :)那麼'const靜態...'呢? –