style(uvc osx): CameraEngine code style fix.
This commit is contained in:
parent
55cd7cddd0
commit
cf79c71c1d
|
@ -12,27 +12,40 @@
|
|||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include <vector>
|
||||
#include "CameraEngine.h"
|
||||
|
||||
const char* dstr[] = { "default","dc1394","ps3eye","raspi","uvccam","","","","","","file","folder"};
|
||||
|
||||
const char* fstr[] = { "unknown", "mono8", "mono16", "rgb8", "rgb16", "mono16s", "rgb16s", "raw8", "raw16", "rgba", "yuyv", "uyvy", "yuv411", "yuv444", "yuv420p", "yuv410p", "yvyu", "yuv211", "", "", "jpeg", "mjpeg", "mpeg", "mpeg2", "mpeg4", "h263", "h264", "", "", "", "dvpal", "dvntsc" };
|
||||
const char* dstr[] = {"default", "dc1394", "ps3eye", "raspi",
|
||||
"uvccam", "", "", "", "", "", "file", "folder"};
|
||||
|
||||
const char* fstr[] = { "unknown", "mono8", "mono16", "rgb8",
|
||||
"rgb16", "mono16s", "rgb16s", "raw8", "raw16", "rgba",
|
||||
"yuyv", "uyvy", "yuv411", "yuv444", "yuv420p", "yuv410p",
|
||||
"yvyu", "yuv211", "", "", "jpeg", "mjpeg", "mpeg", "mpeg2",
|
||||
"mpeg4", "h263", "h264", "", "", "", "dvpal", "dvntsc" };
|
||||
|
||||
void CameraEngine::printInfo() {
|
||||
printf("camera: %s\n",cfg->name);
|
||||
printf("driver: %s\n",dstr[cfg->driver]);
|
||||
printf("codec: %s\n",fstr[cfg->cam_format]);
|
||||
if (cfg->frame_mode<0) {
|
||||
if (cfg->cam_fps==(int)cfg->cam_fps) printf("format: %dx%d, %dfps\n",cfg->frame_width,cfg->frame_height,(int)cfg->cam_fps);
|
||||
else printf("format: %dx%d, %.1ffps\n",cfg->frame_width,cfg->frame_height,cfg->cam_fps);
|
||||
printf("camera: %s\n", cfg->name);
|
||||
printf("driver: %s\n", dstr[cfg->driver]);
|
||||
printf("codec: %s\n", fstr[cfg->cam_format]);
|
||||
if (cfg->frame_mode < 0) {
|
||||
if (cfg->cam_fps == static_cast<int>(cfg->cam_fps)) {
|
||||
printf("format: %dx%d, %dfps\n", cfg->frame_width,
|
||||
cfg->frame_height, static_cast<int>(cfg->cam_fps));
|
||||
} else {
|
||||
printf("format: %dx%d, %.1ffps\n", cfg->frame_width,
|
||||
cfg->frame_height, cfg->cam_fps);
|
||||
}
|
||||
} else {
|
||||
printf("format7_%d: %dx%d\n", cfg->frame_mode,
|
||||
cfg->frame_width, cfg->frame_height);
|
||||
}
|
||||
else printf("format7_%d: %dx%d\n",cfg->frame_mode,cfg->frame_width,cfg->frame_height);
|
||||
}
|
||||
|
||||
void CameraEngine::setMinMaxConfig(CameraConfig *cam_cfg, std::vector<CameraConfig> cfg_list) {
|
||||
if ((cam_cfg->cam_width>0) && (cam_cfg->cam_height>0) && (cam_cfg->cam_fps>0)) return;
|
||||
void CameraEngine::setMinMaxConfig(CameraConfig *cam_cfg,
|
||||
std::vector<CameraConfig> cfg_list) {
|
||||
if ((cam_cfg->cam_width > 0) &&
|
||||
(cam_cfg->cam_height > 0) &&
|
||||
(cam_cfg->cam_fps > 0)) return;
|
||||
|
||||
int max_width = 0;
|
||||
int max_height = 0;
|
||||
|
@ -41,35 +54,58 @@ void CameraEngine::setMinMaxConfig(CameraConfig *cam_cfg, std::vector<CameraConf
|
|||
float max_fps = 0;
|
||||
float min_fps = INT_MAX;
|
||||
|
||||
for (unsigned int i=0;i<cfg_list.size();i++) {
|
||||
if (cfg_list[i].cam_format!=cam_cfg->cam_format) continue; // wrong format
|
||||
if (cfg_list[i].frame_mode!=cam_cfg->frame_mode) continue; // wrong format7
|
||||
for (unsigned int i = 0; i < cfg_list.size(); i++) {
|
||||
if (cfg_list[i].cam_format != cam_cfg->cam_format)
|
||||
continue; // wrong format
|
||||
if (cfg_list[i].frame_mode != cam_cfg->frame_mode)
|
||||
continue; // wrong format7
|
||||
|
||||
if (cfg_list[i].cam_width>max_width) max_width = cfg_list[i].cam_width;
|
||||
if (cfg_list[i].cam_width<min_width) min_width = cfg_list[i].cam_width;
|
||||
if (cfg_list[i].cam_width > max_width)
|
||||
max_width = cfg_list[i].cam_width;
|
||||
if (cfg_list[i].cam_width < min_width)
|
||||
min_width = cfg_list[i].cam_width;
|
||||
|
||||
if (cfg_list[i].cam_height>max_height) max_height = cfg_list[i].cam_height;
|
||||
if (cfg_list[i].cam_width<min_height) min_height = cfg_list[i].cam_height;
|
||||
if (cfg_list[i].cam_height > max_height)
|
||||
max_height = cfg_list[i].cam_height;
|
||||
if (cfg_list[i].cam_width < min_height)
|
||||
min_height = cfg_list[i].cam_height;
|
||||
}
|
||||
|
||||
if ((cam_cfg->cam_width==SETTING_MAX) || (cam_cfg->cam_width>max_width)) cam_cfg->cam_width = max_width;
|
||||
else if ((cam_cfg->cam_width==SETTING_MIN) || (cam_cfg->cam_width<min_width)) cam_cfg->cam_width = min_width;
|
||||
if ((cam_cfg->cam_height==SETTING_MAX) || (cam_cfg->cam_height>max_height)) cam_cfg->cam_height = max_height;
|
||||
else if ((cam_cfg->cam_height==SETTING_MIN) || (cam_cfg->cam_height<min_height)) cam_cfg->cam_height = min_height;
|
||||
if ((cam_cfg->cam_width == SETTING_MAX) ||
|
||||
(cam_cfg->cam_width > max_width)) {
|
||||
cam_cfg->cam_width = max_width;
|
||||
} else if ((cam_cfg->cam_width == SETTING_MIN) ||
|
||||
(cam_cfg->cam_width < min_width)) {
|
||||
cam_cfg->cam_width = min_width;
|
||||
}
|
||||
if ((cam_cfg->cam_height == SETTING_MAX) ||
|
||||
(cam_cfg->cam_height > max_height)) {
|
||||
cam_cfg->cam_height = max_height;
|
||||
} else if ((cam_cfg->cam_height == SETTING_MIN) ||
|
||||
(cam_cfg->cam_height < min_height)) {
|
||||
cam_cfg->cam_height = min_height;
|
||||
}
|
||||
if (cam_cfg->cam_fps > 0) return;
|
||||
|
||||
if (cam_cfg->cam_fps>0) return;
|
||||
for (unsigned int i = 0; i < cfg_list.size(); i++) {
|
||||
if (cfg_list[i].cam_format != cam_cfg->cam_format)
|
||||
continue; // wrong format
|
||||
if (cfg_list[i].frame_mode != cam_cfg->frame_mode)
|
||||
continue; // wrong format7
|
||||
if ((cfg_list[i].cam_width != cam_cfg->cam_width) ||
|
||||
(cfg_list[i].cam_height!= cam_cfg->cam_height))
|
||||
continue; // wrong size
|
||||
|
||||
for (unsigned int i=0;i<cfg_list.size();i++) {
|
||||
if (cfg_list[i].cam_format!=cam_cfg->cam_format) continue; // wrong format
|
||||
if (cfg_list[i].frame_mode!=cam_cfg->frame_mode) continue; // wrong format7
|
||||
if ((cfg_list[i].cam_width!=cam_cfg->cam_width) || (cfg_list[i].cam_height!=cam_cfg->cam_height)) continue; // wrong size
|
||||
|
||||
if (cfg_list[i].cam_fps>max_fps) max_fps = cfg_list[i].cam_fps;
|
||||
if (cfg_list[i].cam_fps<min_fps) min_fps = cfg_list[i].cam_fps;
|
||||
if (cfg_list[i].cam_fps > max_fps) max_fps = cfg_list[i].cam_fps;
|
||||
if (cfg_list[i].cam_fps < min_fps) min_fps = cfg_list[i].cam_fps;
|
||||
}
|
||||
|
||||
if ((cam_cfg->cam_fps==SETTING_MAX) || (cam_cfg->cam_fps>max_fps)) cam_cfg->cam_fps = max_fps;
|
||||
if ((cam_cfg->cam_fps==SETTING_MIN) || (cam_cfg->cam_fps<min_fps)) cam_cfg->cam_fps = min_fps;
|
||||
if ((cam_cfg->cam_fps == SETTING_MAX) ||
|
||||
(cam_cfg->cam_fps > max_fps))
|
||||
cam_cfg->cam_fps = max_fps;
|
||||
if ((cam_cfg->cam_fps == SETTING_MIN) ||
|
||||
(cam_cfg->cam_fps < min_fps))
|
||||
cam_cfg->cam_fps = min_fps;
|
||||
}
|
||||
|
||||
bool CameraEngine::showSettingsDialog(bool lock) {
|
||||
|
@ -77,46 +113,52 @@ bool CameraEngine::showSettingsDialog(bool lock) {
|
|||
}
|
||||
|
||||
void CameraEngine::control(unsigned char key) {
|
||||
if(!settingsDialog) return;
|
||||
if (!settingsDialog) return;
|
||||
|
||||
int step = 0;
|
||||
switch(key) {
|
||||
switch (key) {
|
||||
case VALUE_DECREASE:
|
||||
step = getCameraSettingStep(currentCameraSetting);
|
||||
if (step==1) step = (int)((float)ctrl_max/256.0f);
|
||||
if (step<1) step=1;
|
||||
if (step == 1) step = ctrl_max * 1.0f / 256.0f;
|
||||
if (step < 1) step = 1;
|
||||
ctrl_val -= step;
|
||||
if (ctrl_val<ctrl_min) ctrl_val=ctrl_min;
|
||||
setCameraSetting(currentCameraSetting,ctrl_val);
|
||||
if (ctrl_val <ctrl_min) ctrl_val = ctrl_min;
|
||||
setCameraSetting(currentCameraSetting, ctrl_val);
|
||||
break;
|
||||
case VALUE_INCREASE:
|
||||
step = getCameraSettingStep(currentCameraSetting);
|
||||
if (step==1) step = (int)((float)ctrl_max/256.0f);
|
||||
if (step<1) step=1;
|
||||
if (step == 1) step = ctrl_max * 1.0f / 256.0f;
|
||||
if (step < 1) step = 1;
|
||||
ctrl_val += step;
|
||||
if (ctrl_val>ctrl_max) ctrl_val=ctrl_max;
|
||||
setCameraSetting(currentCameraSetting,ctrl_val);
|
||||
if (ctrl_val > ctrl_max) ctrl_val = ctrl_max;
|
||||
setCameraSetting(currentCameraSetting, ctrl_val);
|
||||
break;
|
||||
case SETTING_PREVIOUS:
|
||||
currentCameraSetting--;
|
||||
if(currentCameraSetting<0) {
|
||||
if (cfg->color) currentCameraSetting=COLOR_BLUE;
|
||||
else currentCameraSetting=BACKLIGHT;
|
||||
if (currentCameraSetting < 0) {
|
||||
if (cfg->color) {
|
||||
currentCameraSetting = COLOR_BLUE;
|
||||
} else {
|
||||
currentCameraSetting = BACKLIGHT;
|
||||
}
|
||||
if ((!hasCameraSetting(currentCameraSetting)) || (getCameraSettingAuto(currentCameraSetting)))
|
||||
}
|
||||
if ((!hasCameraSetting(currentCameraSetting)) ||
|
||||
(getCameraSettingAuto(currentCameraSetting)))
|
||||
control(SETTING_PREVIOUS);
|
||||
break;
|
||||
case SETTING_NEXT:
|
||||
currentCameraSetting++;
|
||||
if ((cfg->color) && (currentCameraSetting>COLOR_BLUE)) currentCameraSetting=0;
|
||||
else if ((!cfg->color) && (currentCameraSetting>BACKLIGHT)) currentCameraSetting=0;
|
||||
if ((!hasCameraSetting(currentCameraSetting)) || (getCameraSettingAuto(currentCameraSetting)))
|
||||
if ((cfg->color) && (currentCameraSetting > COLOR_BLUE))
|
||||
currentCameraSetting = 0;
|
||||
else if ((!cfg->color) && (currentCameraSetting > BACKLIGHT))
|
||||
currentCameraSetting = 0;
|
||||
if ((!hasCameraSetting(currentCameraSetting)) ||
|
||||
(getCameraSettingAuto(currentCameraSetting)))
|
||||
control(SETTING_NEXT);
|
||||
break;
|
||||
case KEY_D:
|
||||
resetCameraSettings();
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
ctrl_val = getCameraSetting(currentCameraSetting);
|
||||
|
@ -124,9 +166,9 @@ void CameraEngine::control(unsigned char key) {
|
|||
ctrl_min = getMinCameraSetting(currentCameraSetting);
|
||||
}
|
||||
|
||||
void CameraEngine::uyvy2gray(int width, int height, unsigned char *src, unsigned char *dest) {
|
||||
|
||||
for (int i=height*width/2;i>0;i--) {
|
||||
void CameraEngine::uyvy2gray(int width, int height,
|
||||
unsigned char *src, unsigned char *dest) {
|
||||
for (int i = height*width/2; i > 0; i--) {
|
||||
src++;
|
||||
*dest++ = *src++;
|
||||
src++;
|
||||
|
@ -134,9 +176,10 @@ void CameraEngine::uyvy2gray(int width, int height, unsigned char *src, unsigned
|
|||
}
|
||||
}
|
||||
|
||||
void CameraEngine::crop_uyvy2gray(int cam_w, unsigned char *cam_buf, unsigned char *frm_buf) {
|
||||
void CameraEngine::crop_uyvy2gray(int cam_w,
|
||||
unsigned char *cam_buf, unsigned char *frm_buf) {
|
||||
|
||||
if(!cfg->frame) return;
|
||||
if (!cfg->frame) return;
|
||||
int x_off = cfg->frame_xoff;
|
||||
int y_off = cfg->frame_yoff;
|
||||
int frm_w = cfg->frame_width;
|
||||
|
@ -145,10 +188,9 @@ void CameraEngine::crop_uyvy2gray(int cam_w, unsigned char *cam_buf, unsigned ch
|
|||
cam_buf += 2*y_off*cam_w;
|
||||
int x_end = cam_w-(frm_w+x_off);
|
||||
|
||||
for (int i=frm_h;i>0;i--) {
|
||||
|
||||
for (int i = frm_h; i > 0; i--) {
|
||||
cam_buf += 2*x_off;
|
||||
for (int j=frm_w/2;j>0;j--) {
|
||||
for (int j = frm_w/2; j > 0; j--) {
|
||||
cam_buf++;
|
||||
*frm_buf++ = *cam_buf++;
|
||||
cam_buf++;
|
||||
|
@ -158,8 +200,9 @@ void CameraEngine::crop_uyvy2gray(int cam_w, unsigned char *cam_buf, unsigned ch
|
|||
}
|
||||
}
|
||||
|
||||
void CameraEngine::yuyv2gray(int width, int height, unsigned char *src, unsigned char *dest) {
|
||||
for (int i=height*width/2;i>0;i--) {
|
||||
void CameraEngine::yuyv2gray(int width, int height,
|
||||
unsigned char *src, unsigned char *dest) {
|
||||
for (int i = height*width/2; i > 0; i--) {
|
||||
*dest++ = *src++;
|
||||
src++;
|
||||
*dest++ = *src++;
|
||||
|
@ -167,9 +210,9 @@ void CameraEngine::yuyv2gray(int width, int height, unsigned char *src, unsigned
|
|||
}
|
||||
}
|
||||
|
||||
void CameraEngine::crop_yuyv2gray(int cam_w, unsigned char *cam_buf, unsigned char *frm_buf) {
|
||||
|
||||
if(!cfg->frame) return;
|
||||
void CameraEngine::crop_yuyv2gray(int cam_w,
|
||||
unsigned char *cam_buf, unsigned char *frm_buf) {
|
||||
if (!cfg->frame) return;
|
||||
int x_off = cfg->frame_xoff;
|
||||
int y_off = cfg->frame_yoff;
|
||||
int frm_w = cfg->frame_width;
|
||||
|
@ -178,10 +221,9 @@ void CameraEngine::crop_yuyv2gray(int cam_w, unsigned char *cam_buf, unsigned ch
|
|||
cam_buf += 2*y_off*cam_w;
|
||||
int x_end = cam_w-(frm_w+x_off);
|
||||
|
||||
for (int i=frm_h;i>0;i--) {
|
||||
|
||||
for (int i = frm_h; i > 0; i--) {
|
||||
cam_buf += 2*x_off;
|
||||
for (int j=frm_w/2;j>0;j--) {
|
||||
for (int j = frm_w/2; j > 0; j--) {
|
||||
*frm_buf++ = *cam_buf++;
|
||||
cam_buf++;
|
||||
*frm_buf++ = *cam_buf++;
|
||||
|
@ -191,9 +233,8 @@ void CameraEngine::crop_yuyv2gray(int cam_w, unsigned char *cam_buf, unsigned ch
|
|||
}
|
||||
}
|
||||
|
||||
//void yuv2rgb_conv(int Y1, int Y2, int U, int V, unsigned char *dest) {
|
||||
// void yuv2rgb_conv(int Y1, int Y2, int U, int V, unsigned char *dest) {
|
||||
void yuv2rgb_conv(int Y, int U, int V, unsigned char *dest) {
|
||||
|
||||
/*int R = (int)(Y + 1.370705f * V);
|
||||
int G = (int)(Y - 0.698001f * V - 0.337633f * U);
|
||||
int B = (int)(Y + 1.732446f * U);*/
|
||||
|
@ -213,106 +254,102 @@ void yuv2rgb_conv(int Y, int U, int V, unsigned char *dest) {
|
|||
*dest++ = B;
|
||||
}
|
||||
|
||||
void CameraEngine::uyvy2rgb(int width, int height, unsigned char *src, unsigned char *dest) {
|
||||
void CameraEngine::uyvy2rgb(int width, int height, unsigned char *src,
|
||||
unsigned char *dest) {
|
||||
int Y1, Y2, U, V;
|
||||
|
||||
int Y1,Y2,U,V;
|
||||
|
||||
for(int i=width*height/2;i>0;i--) {
|
||||
for (int i = width*height/2; i > 0; i--) {
|
||||
// U and V are +-0.5
|
||||
U = *src++ - 128;
|
||||
Y1 = *src++;
|
||||
V = *src++ - 128;
|
||||
Y2 = *src++;
|
||||
|
||||
yuv2rgb_conv(Y1,U,V,dest);
|
||||
yuv2rgb_conv(Y2,U,V,dest+=3);
|
||||
yuv2rgb_conv(Y1, U, V, dest);
|
||||
yuv2rgb_conv(Y2, U, V, dest+=3);
|
||||
dest+=3;
|
||||
}
|
||||
}
|
||||
|
||||
void CameraEngine::crop_uyvy2rgb(int cam_w, unsigned char *cam_buf, unsigned char *frm_buf) {
|
||||
|
||||
if(!cfg->frame) return;
|
||||
void CameraEngine::crop_uyvy2rgb(int cam_w, unsigned char *cam_buf,
|
||||
unsigned char *frm_buf) {
|
||||
if (!cfg->frame) return;
|
||||
int x_off = cfg->frame_xoff;
|
||||
int y_off = cfg->frame_yoff;
|
||||
int frm_w = cfg->frame_width;
|
||||
int frm_h = cfg->frame_height;
|
||||
|
||||
int Y1,Y2,U,V;
|
||||
int Y1, Y2, U, V;
|
||||
|
||||
cam_buf += 2*y_off*cam_w;
|
||||
int x_end = cam_w-(frm_w+x_off);
|
||||
|
||||
for (int i=frm_h;i>0;i--) {
|
||||
|
||||
for (int i = frm_h; i > 0; i--) {
|
||||
cam_buf += 2*x_off;
|
||||
for (int j=frm_w/2;j>0;j--) {
|
||||
for (int j=frm_w/2; j > 0; j--) {
|
||||
// U and V are +-0.5
|
||||
U = *cam_buf++ - 128;
|
||||
Y1 = *cam_buf++;
|
||||
V = *cam_buf++ - 128;
|
||||
Y2 = *cam_buf++;
|
||||
|
||||
yuv2rgb_conv(Y1,U,V,frm_buf);
|
||||
yuv2rgb_conv(Y2,U,V,frm_buf+=3);
|
||||
yuv2rgb_conv(Y1, U, V, frm_buf);
|
||||
yuv2rgb_conv(Y2, U, V, frm_buf+=3);
|
||||
frm_buf+=3;
|
||||
}
|
||||
cam_buf += 2*x_end;
|
||||
}
|
||||
}
|
||||
|
||||
void CameraEngine::yuyv2rgb(int width, int height, unsigned char *src, unsigned char *dest) {
|
||||
|
||||
int Y1,Y2,U,V;
|
||||
|
||||
for(int i=width*height/2;i>0;i--) {
|
||||
|
||||
void CameraEngine::yuyv2rgb(int width, int height, unsigned char *src,
|
||||
unsigned char *dest) {
|
||||
int Y1, Y2, U, V;
|
||||
for (int i = width*height/2; i > 0; i--) {
|
||||
Y1 = *src++;
|
||||
U = *src++ - 128;
|
||||
Y2 = *src++;
|
||||
V = *src++ - 128;
|
||||
|
||||
yuv2rgb_conv(Y1,U,V,dest);
|
||||
yuv2rgb_conv(Y2,U,V,dest+=3);
|
||||
yuv2rgb_conv(Y1, U, V, dest);
|
||||
yuv2rgb_conv(Y2, U, V, dest+=3);
|
||||
dest+=3;
|
||||
}
|
||||
}
|
||||
|
||||
void CameraEngine::crop_yuyv2rgb(int cam_w, unsigned char *cam_buf, unsigned char *frm_buf) {
|
||||
|
||||
if(!cfg->frame) return;
|
||||
void CameraEngine::crop_yuyv2rgb(int cam_w,
|
||||
unsigned char *cam_buf, unsigned char *frm_buf) {
|
||||
if (!cfg->frame) return;
|
||||
int x_off = cfg->frame_xoff;
|
||||
int y_off = cfg->frame_yoff;
|
||||
int frm_w = cfg->frame_width;
|
||||
int frm_h = cfg->frame_height;
|
||||
|
||||
int Y1,Y2,U,V;
|
||||
int Y1, Y2, U, V;
|
||||
|
||||
cam_buf += 2*y_off*cam_w;
|
||||
int x_end = cam_w-(frm_w+x_off);
|
||||
|
||||
for (int i=frm_h;i>0;i--) {
|
||||
|
||||
for (int i = frm_h; i > 0; i--) {
|
||||
cam_buf += 2*x_off;
|
||||
for (int j=frm_w/2;j>0;j--) {
|
||||
for (int j=frm_w/2; j > 0; j--) {
|
||||
// U and V are +-0.5
|
||||
Y1 = *cam_buf++;
|
||||
U = *cam_buf++ - 128;
|
||||
Y2 = *cam_buf++;
|
||||
V = *cam_buf++ - 128;
|
||||
|
||||
yuv2rgb_conv(Y1,U,V,frm_buf);
|
||||
yuv2rgb_conv(Y2,U,V,frm_buf+=3);
|
||||
yuv2rgb_conv(Y1, U, V, frm_buf);
|
||||
yuv2rgb_conv(Y2, U, V, frm_buf+=3);
|
||||
frm_buf+=3;
|
||||
}
|
||||
cam_buf += 2*x_end;
|
||||
}
|
||||
}
|
||||
|
||||
void CameraEngine::gray2rgb(int width, int height, unsigned char *src, unsigned char *dest) {
|
||||
|
||||
void CameraEngine::gray2rgb(int width, int height, unsigned char *src,
|
||||
unsigned char *dest) {
|
||||
int size = width*height;
|
||||
for (int i=size;i>0;i--) {
|
||||
for (int i=size; i > 0; i--) {
|
||||
unsigned char pixel = *src++;
|
||||
*dest++ = pixel;
|
||||
*dest++ = pixel;
|
||||
|
@ -320,9 +357,9 @@ void CameraEngine::gray2rgb(int width, int height, unsigned char *src, unsigned
|
|||
}
|
||||
}
|
||||
|
||||
void CameraEngine::crop_gray2rgb(int cam_w, unsigned char *cam_buf, unsigned char *frm_buf) {
|
||||
|
||||
if(!cfg->frame) return;
|
||||
void CameraEngine::crop_gray2rgb(int cam_w, unsigned char *cam_buf,
|
||||
unsigned char *frm_buf) {
|
||||
if (!cfg->frame) return;
|
||||
int x_off = cfg->frame_xoff;
|
||||
int y_off = cfg->frame_yoff;
|
||||
int frm_w = cfg->frame_width;
|
||||
|
@ -331,10 +368,9 @@ void CameraEngine::crop_gray2rgb(int cam_w, unsigned char *cam_buf, unsigned cha
|
|||
cam_buf += y_off*cam_w;
|
||||
int x_end = cam_w-(frm_w+x_off);
|
||||
|
||||
for (int i=frm_h;i>0;i--) {
|
||||
|
||||
for (int i = frm_h; i > 0; i--) {
|
||||
cam_buf += x_off;
|
||||
for (int j=frm_w;j>0;j--) {
|
||||
for (int j = frm_w; j > 0; j--) {
|
||||
unsigned char pixel = *cam_buf++;
|
||||
*frm_buf++ = pixel;
|
||||
*frm_buf++ = pixel;
|
||||
|
@ -344,13 +380,14 @@ void CameraEngine::crop_gray2rgb(int cam_w, unsigned char *cam_buf, unsigned cha
|
|||
}
|
||||
}
|
||||
|
||||
void CameraEngine::grayw2rgb(int width, int height, unsigned char *src, unsigned char *dest) {
|
||||
unsigned short src_pixel;
|
||||
void CameraEngine::grayw2rgb(int width, int height, unsigned char *src,
|
||||
unsigned char *dest) {
|
||||
unsigned short src_pixel; // NOLINT
|
||||
unsigned char dest_pixel;
|
||||
unsigned char pixel;
|
||||
|
||||
for(int i=width*height;i>0;i--) {
|
||||
pixel = *src++ ;
|
||||
for (int i = width*height; i > 0; i--) {
|
||||
pixel = *src++;
|
||||
src_pixel = pixel | (*src++ << 8);
|
||||
dest_pixel = (unsigned char)(src_pixel/4);
|
||||
*dest++ = dest_pixel;
|
||||
|
@ -359,25 +396,24 @@ void CameraEngine::grayw2rgb(int width, int height, unsigned char *src, unsigned
|
|||
}
|
||||
}
|
||||
|
||||
void CameraEngine::crop_grayw2rgb(int cam_w, unsigned char *src, unsigned char *dest) {
|
||||
|
||||
if(!cfg->frame) return;
|
||||
void CameraEngine::crop_grayw2rgb(int cam_w, unsigned char *src,
|
||||
unsigned char *dest) {
|
||||
if (!cfg->frame) return;
|
||||
int x_off = cfg->frame_xoff;
|
||||
int y_off = cfg->frame_yoff;
|
||||
int frm_w = cfg->frame_width;
|
||||
int frm_h = cfg->frame_height;
|
||||
|
||||
unsigned short src_pixel;
|
||||
unsigned short src_pixel; // NOLINT
|
||||
unsigned char dest_pixel;
|
||||
unsigned char pixel;
|
||||
|
||||
src += 2*y_off*cam_w;
|
||||
int x_end = cam_w-(frm_w+x_off);
|
||||
|
||||
for (int i=frm_h;i>0;i--) {
|
||||
|
||||
for (int i=frm_h; i > 0; i--) {
|
||||
src += 2*x_off;
|
||||
for (int j=frm_w;j>0;j--) {
|
||||
for (int j=frm_w; j > 0; j--) {
|
||||
pixel = *src++;
|
||||
src_pixel = pixel | (*src++ << 8);
|
||||
dest_pixel = (unsigned char)(src_pixel/4);
|
||||
|
@ -388,39 +424,37 @@ void CameraEngine::crop_grayw2rgb(int cam_w, unsigned char *src, unsigned char *
|
|||
}
|
||||
src += 2*x_end;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void CameraEngine::grayw2gray(int width, int height, unsigned char *src, unsigned char *dest) {
|
||||
|
||||
unsigned short value;
|
||||
void CameraEngine::grayw2gray(int width, int height, unsigned char *src,
|
||||
unsigned char *dest) {
|
||||
unsigned short value; // NOLINT
|
||||
unsigned char pixel;
|
||||
|
||||
for(int i=width*height;i>0;i--) {
|
||||
for (int i=width*height; i > 0; i--) {
|
||||
pixel = *src++;
|
||||
value = pixel | (*src++ << 8);
|
||||
*dest++ = (unsigned char)(value/4);
|
||||
}
|
||||
}
|
||||
|
||||
void CameraEngine::crop_grayw2gray(int cam_w, unsigned char *src, unsigned char *dest) {
|
||||
|
||||
if(!cfg->frame) return;
|
||||
void CameraEngine::crop_grayw2gray(int cam_w, unsigned char *src,
|
||||
unsigned char *dest) {
|
||||
if (!cfg->frame) return;
|
||||
int x_off = cfg->frame_xoff;
|
||||
int y_off = cfg->frame_yoff;
|
||||
int frm_w = cfg->frame_width;
|
||||
int frm_h = cfg->frame_height;
|
||||
|
||||
unsigned short src_pixel;
|
||||
unsigned short src_pixel; // NOLINT
|
||||
unsigned char pixel;
|
||||
|
||||
src += 2*y_off*cam_w;
|
||||
int x_end = cam_w-(frm_w+x_off);
|
||||
|
||||
for (int i=frm_h;i>0;i--) {
|
||||
|
||||
for (int i=frm_h; i > 0; i--) {
|
||||
src += 2*x_off;
|
||||
for (int j=frm_w;j>0;j--) {
|
||||
for (int j=frm_w; j > 0; j--) {
|
||||
pixel = *src++;
|
||||
src_pixel = pixel | (*src++ << 8);
|
||||
*dest++ = (unsigned char)(src_pixel/4);
|
||||
|
@ -429,9 +463,9 @@ void CameraEngine::crop_grayw2gray(int cam_w, unsigned char *src, unsigned char
|
|||
}
|
||||
}
|
||||
|
||||
void CameraEngine::crop(int cam_w, int cam_h, unsigned char *cam_buf, unsigned char *frm_buf, int b) {
|
||||
|
||||
if(!cfg->frame) return;
|
||||
void CameraEngine::crop(int cam_w, int cam_h, unsigned char *cam_buf,
|
||||
unsigned char *frm_buf, int b) {
|
||||
if (!cfg->frame) return;
|
||||
int x_off = cfg->frame_xoff;
|
||||
int y_off = cfg->frame_yoff;
|
||||
int frm_w = cfg->frame_width;
|
||||
|
@ -439,26 +473,26 @@ void CameraEngine::crop(int cam_w, int cam_h, unsigned char *cam_buf, unsigned c
|
|||
|
||||
cam_buf += b*(y_off*cam_w + x_off);
|
||||
|
||||
for (int i=frm_h;i>0;i--) {
|
||||
for (int i=frm_h; i > 0; i--) {
|
||||
memcpy(frm_buf, cam_buf, b*cam_w);
|
||||
|
||||
cam_buf += b*cam_w;
|
||||
frm_buf += b*frm_w;
|
||||
}
|
||||
}
|
||||
|
||||
void CameraEngine::flip(int width, int height, unsigned char *src, unsigned char *dest, int b) {
|
||||
}
|
||||
|
||||
void CameraEngine::flip(int width, int height, unsigned char *src,
|
||||
unsigned char *dest, int b) {
|
||||
int size = b*width*height;
|
||||
dest += size-1;
|
||||
for(int i=size;i>0;i--) {
|
||||
for (int i=size; i > 0; i--) {
|
||||
*dest-- = *src++;
|
||||
}
|
||||
}
|
||||
|
||||
void CameraEngine::flip_crop(int cam_w, int cam_h, unsigned char *cam_buf, unsigned char *frm_buf, int b) {
|
||||
|
||||
if(!cfg->frame) return;
|
||||
void CameraEngine::flip_crop(int cam_w, int cam_h, unsigned char *cam_buf,
|
||||
unsigned char *frm_buf, int b) {
|
||||
if (!cfg->frame) return;
|
||||
int x_off = cfg->frame_xoff;
|
||||
int y_off = cfg->frame_yoff;
|
||||
int frm_w = cfg->frame_width;
|
||||
|
@ -468,21 +502,20 @@ void CameraEngine::flip_crop(int cam_w, int cam_h, unsigned char *cam_buf, unsig
|
|||
frm_buf += b*frm_w*frm_h-1;
|
||||
int xend = (cam_w-(frm_w+x_off));
|
||||
|
||||
for (int i=frm_h;i>0;i--) {
|
||||
|
||||
for (int i=frm_h; i > 0; i--) {
|
||||
cam_buf += b*x_off;
|
||||
for (int j=b*frm_w;j>0;j--) {
|
||||
for (int j=b*frm_w; j > 0; j--) {
|
||||
*frm_buf-- = *cam_buf++;
|
||||
}
|
||||
cam_buf += b*xend;
|
||||
}
|
||||
}
|
||||
|
||||
void CameraEngine::rgb2gray(int width, int height, unsigned char *src, unsigned char *dest) {
|
||||
|
||||
int R,G,B;
|
||||
for (int i=width*height;i>0;i--) {
|
||||
void CameraEngine::rgb2gray(int width, int height, unsigned char *src,
|
||||
unsigned char *dest) {
|
||||
|
||||
int R, G, B;
|
||||
for (int i=width*height; i > 0; i--) {
|
||||
R = *src++;
|
||||
G = *src++;
|
||||
B = *src++;
|
||||
|
@ -490,23 +523,23 @@ void CameraEngine::rgb2gray(int width, int height, unsigned char *src, unsigned
|
|||
}
|
||||
}
|
||||
|
||||
void CameraEngine::flip_rgb2gray(int width, int height, unsigned char *src, unsigned char *dest) {
|
||||
void CameraEngine::flip_rgb2gray(int width, int height, unsigned char *src,
|
||||
unsigned char *dest) {
|
||||
|
||||
int size = width*height;
|
||||
dest += size-1;
|
||||
|
||||
int R,G,B;
|
||||
for (int i=size;i>0;i--) {
|
||||
|
||||
int R, G, B;
|
||||
for (int i = size; i > 0; i--) {
|
||||
R = *src++;
|
||||
G = *src++;
|
||||
B = *src++;
|
||||
*dest-- = HBT(R*77 + G*151 + B*28);
|
||||
}
|
||||
}
|
||||
void CameraEngine::crop_rgb2gray(int cam_w, unsigned char *cam_buf, unsigned char *frm_buf) {
|
||||
|
||||
if(!cfg->frame) return;
|
||||
void CameraEngine::crop_rgb2gray(int cam_w, unsigned char *cam_buf,
|
||||
unsigned char *frm_buf) {
|
||||
if (!cfg->frame) return;
|
||||
int x_off = cfg->frame_xoff;
|
||||
int y_off = cfg->frame_yoff;
|
||||
int frm_w = cfg->frame_width;
|
||||
|
@ -515,11 +548,10 @@ void CameraEngine::crop_rgb2gray(int cam_w, unsigned char *cam_buf, unsigned cha
|
|||
cam_buf += 3*y_off*cam_w;
|
||||
int x_end = cam_w-(frm_w+x_off);
|
||||
|
||||
int R,G,B;
|
||||
for (int i=frm_h;i>0;i--) {
|
||||
|
||||
int R, G, B;
|
||||
for (int i = frm_h; i > 0; i--) {
|
||||
cam_buf += 3*x_off;
|
||||
for (int j=frm_w;j>0;j--) {
|
||||
for (int j = frm_w; j > 0; j--) {
|
||||
R = *cam_buf++;
|
||||
G = *cam_buf++;
|
||||
B = *cam_buf++;
|
||||
|
@ -529,9 +561,9 @@ void CameraEngine::crop_rgb2gray(int cam_w, unsigned char *cam_buf, unsigned cha
|
|||
}
|
||||
}
|
||||
|
||||
void CameraEngine::flip_crop_rgb2gray(int cam_w, unsigned char *cam_buf, unsigned char *frm_buf) {
|
||||
|
||||
if(!cfg->frame) return;
|
||||
void CameraEngine::flip_crop_rgb2gray(int cam_w, unsigned char *cam_buf,
|
||||
unsigned char *frm_buf) {
|
||||
if (!cfg->frame) return;
|
||||
int x_off = cfg->frame_xoff;
|
||||
int y_off = cfg->frame_yoff;
|
||||
int frm_w = cfg->frame_width;
|
||||
|
@ -541,11 +573,10 @@ void CameraEngine::flip_crop_rgb2gray(int cam_w, unsigned char *cam_buf, unsigne
|
|||
int x_end = cam_w-(frm_w+x_off);
|
||||
frm_buf += frm_w*frm_h-1;
|
||||
|
||||
int R,G,B;
|
||||
for (int i=frm_h;i>0;i--) {
|
||||
|
||||
int R, G, B;
|
||||
for (int i = frm_h; i > 0; i--) {
|
||||
cam_buf += 3*x_off;
|
||||
for (int j=frm_w;j>0;j--) {
|
||||
for (int j = frm_w; j > 0; j--) {
|
||||
R = *cam_buf++;
|
||||
G = *cam_buf++;
|
||||
B = *cam_buf++;
|
||||
|
@ -556,26 +587,25 @@ void CameraEngine::flip_crop_rgb2gray(int cam_w, unsigned char *cam_buf, unsigne
|
|||
}
|
||||
|
||||
void CameraEngine::setupFrame() {
|
||||
|
||||
if(!cfg->frame) {
|
||||
if (!cfg->frame) {
|
||||
cfg->frame_width = cfg->cam_width;
|
||||
cfg->frame_height = cfg->cam_height;
|
||||
return;
|
||||
}
|
||||
|
||||
// size sanity check
|
||||
if (cfg->frame_width%2!=0) cfg->frame_width--;
|
||||
if (cfg->frame_height%2!=0) cfg->frame_height--;
|
||||
if (cfg->frame_width%2 != 0) cfg->frame_width--;
|
||||
if (cfg->frame_height%2 != 0) cfg->frame_height--;
|
||||
|
||||
if (cfg->frame_width<=0) cfg->frame_width = cfg->cam_width;
|
||||
if (cfg->frame_height<=0) cfg->frame_height = cfg->cam_height;
|
||||
if (cfg->frame_width <= 0) cfg->frame_width = cfg->cam_width;
|
||||
if (cfg->frame_height <= 0) cfg->frame_height = cfg->cam_height;
|
||||
|
||||
if (cfg->frame_width > cfg->cam_width) cfg->frame_width = cfg->cam_width;
|
||||
if (cfg->frame_height > cfg->cam_height) cfg->frame_height = cfg->cam_height;
|
||||
|
||||
// no cropping if same size
|
||||
if ((cfg->frame_width==cfg->cam_width) && (cfg->frame_height==cfg->cam_height)) {
|
||||
|
||||
if ((cfg->frame_width == cfg->cam_width) &&
|
||||
(cfg->frame_height == cfg->cam_height)) {
|
||||
cfg->frame_width = cfg->cam_width;
|
||||
cfg->frame_height = cfg->cam_height;
|
||||
cfg->frame = false;
|
||||
|
@ -584,22 +614,19 @@ void CameraEngine::setupFrame() {
|
|||
|
||||
// offset sanity check
|
||||
int xdiff = cfg->cam_width-cfg->frame_width;
|
||||
if (xdiff<0) cfg->frame_xoff = 0;
|
||||
if (xdiff < 0) cfg->frame_xoff = 0;
|
||||
else if (cfg->frame_xoff > xdiff) cfg->frame_xoff = xdiff;
|
||||
int ydiff = cfg->cam_height-cfg->frame_height;
|
||||
if (ydiff<0) cfg->frame_yoff = 0;
|
||||
if (ydiff < 0) cfg->frame_yoff = 0;
|
||||
else if (cfg->frame_yoff > ydiff) cfg->frame_yoff = ydiff;
|
||||
|
||||
}
|
||||
|
||||
void CameraEngine::applyCameraSetting(int mode, int value) {
|
||||
|
||||
if (!hasCameraSetting(mode)) return;
|
||||
|
||||
switch (value) {
|
||||
case SETTING_AUTO:
|
||||
if (hasCameraSettingAuto(mode)) {
|
||||
setCameraSettingAuto(mode,true);
|
||||
setCameraSettingAuto(mode, true);
|
||||
return;
|
||||
}
|
||||
case SETTING_OFF:
|
||||
|
@ -607,66 +634,61 @@ void CameraEngine::applyCameraSetting(int mode, int value) {
|
|||
setDefaultCameraSetting(mode);
|
||||
return;
|
||||
case SETTING_MIN:
|
||||
setCameraSettingAuto(mode,false);
|
||||
setCameraSetting(mode,getMinCameraSetting(mode)); return;
|
||||
setCameraSettingAuto(mode, false);
|
||||
setCameraSetting(mode, getMinCameraSetting(mode));
|
||||
return;
|
||||
case SETTING_MAX:
|
||||
setCameraSettingAuto(mode,false);
|
||||
setCameraSetting(mode,getMaxCameraSetting(mode)); return;
|
||||
setCameraSettingAuto(mode, false);
|
||||
setCameraSetting(mode, getMaxCameraSetting(mode));
|
||||
return;
|
||||
default: {
|
||||
int max = getMaxCameraSetting(mode);
|
||||
int min = getMinCameraSetting(mode);
|
||||
if (value<min) value = min;
|
||||
else if (value>max) value = max;
|
||||
setCameraSettingAuto(mode,false);
|
||||
setCameraSetting(mode,value);
|
||||
if (value < min) value = min;
|
||||
else if (value > max) value = max;
|
||||
setCameraSettingAuto(mode, false);
|
||||
setCameraSetting(mode, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CameraEngine::resetCameraSettings() {
|
||||
|
||||
for (int mode=MODE_MIN;mode<=MODE_MAX;mode++)
|
||||
for (int mode=MODE_MIN; mode <= MODE_MAX; mode++)
|
||||
setDefaultCameraSetting(mode);
|
||||
}
|
||||
|
||||
void CameraEngine::applyCameraSettings() {
|
||||
|
||||
resetCameraSettings();
|
||||
applyCameraSetting(BRIGHTNESS, cfg->brightness);
|
||||
applyCameraSetting(CONTRAST, cfg->contrast);
|
||||
applyCameraSetting(SHARPNESS, cfg->sharpness);
|
||||
applyCameraSetting(GAIN, cfg->gain);
|
||||
applyCameraSetting(EXPOSURE, cfg->exposure);
|
||||
applyCameraSetting(SHUTTER, cfg->shutter);
|
||||
applyCameraSetting(FOCUS, cfg->focus);
|
||||
applyCameraSetting(WHITE, cfg->white);
|
||||
applyCameraSetting(POWERLINE, cfg->powerline);
|
||||
applyCameraSetting(BACKLIGHT, cfg->backlight);
|
||||
applyCameraSetting(GAMMA, cfg->gamma);
|
||||
|
||||
applyCameraSetting(BRIGHTNESS,cfg->brightness);
|
||||
applyCameraSetting(CONTRAST,cfg->contrast);
|
||||
applyCameraSetting(SHARPNESS,cfg->sharpness);
|
||||
applyCameraSetting(GAIN,cfg->gain);
|
||||
applyCameraSetting(EXPOSURE,cfg->exposure);
|
||||
applyCameraSetting(SHUTTER,cfg->shutter);
|
||||
applyCameraSetting(FOCUS,cfg->focus);
|
||||
applyCameraSetting(WHITE,cfg->white);
|
||||
applyCameraSetting(POWERLINE,cfg->powerline);
|
||||
applyCameraSetting(BACKLIGHT,cfg->backlight);
|
||||
applyCameraSetting(GAMMA,cfg->gamma);
|
||||
|
||||
applyCameraSetting(SATURATION,cfg->saturation);
|
||||
applyCameraSetting(COLOR_HUE,cfg->hue);
|
||||
applyCameraSetting(COLOR_RED,cfg->red);
|
||||
applyCameraSetting(COLOR_GREEN,cfg->green);
|
||||
applyCameraSetting(COLOR_BLUE,cfg->blue);
|
||||
applyCameraSetting(SATURATION, cfg->saturation);
|
||||
applyCameraSetting(COLOR_HUE, cfg->hue);
|
||||
applyCameraSetting(COLOR_RED, cfg->red);
|
||||
applyCameraSetting(COLOR_GREEN, cfg->green);
|
||||
applyCameraSetting(COLOR_BLUE, cfg->blue);
|
||||
}
|
||||
|
||||
int CameraEngine::updateSetting(int mode) {
|
||||
|
||||
if (!hasCameraSetting(mode)) return SETTING_OFF;
|
||||
if (getCameraSettingAuto(mode)) return SETTING_AUTO;
|
||||
|
||||
int value = getCameraSetting(mode);
|
||||
if (value==getDefaultCameraSetting(mode)) value = SETTING_DEFAULT;
|
||||
else if (value==getMinCameraSetting(mode)) value = SETTING_MIN;
|
||||
else if (value==getMaxCameraSetting(mode)) value = SETTING_MAX;
|
||||
|
||||
if (value == getDefaultCameraSetting(mode)) value = SETTING_DEFAULT;
|
||||
else if (value == getMinCameraSetting(mode)) value = SETTING_MIN;
|
||||
else if (value == getMaxCameraSetting(mode)) value = SETTING_MAX;
|
||||
return value;
|
||||
}
|
||||
|
||||
void CameraEngine::updateSettings() {
|
||||
|
||||
cfg->brightness = updateSetting(BRIGHTNESS);
|
||||
cfg->contrast = updateSetting(CONTRAST);
|
||||
cfg->sharpness = updateSetting(SHARPNESS);
|
||||
|
@ -693,5 +715,4 @@ void CameraEngine::updateSettings() {
|
|||
cfg->green = SETTING_OFF;
|
||||
cfg->blue = SETTING_OFF;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -12,21 +12,27 @@
|
|||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#ifndef CAMERAENGINE_H
|
||||
#define CAMERAENGINE_H
|
||||
#ifndef SRC_MYNTEYE_UVC_MACOSX_CAMERAENGINE_H_
|
||||
#define SRC_MYNTEYE_UVC_MACOSX_CAMERAENGINE_H_
|
||||
|
||||
#include <limits.h>
|
||||
#include <math.h>
|
||||
#include <CoreFoundation/CFBundle.h>
|
||||
|
||||
#include <list>
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <algorithm>
|
||||
|
||||
#include <limits.h>
|
||||
#include <math.h>
|
||||
|
||||
#include <CoreFoundation/CFBundle.h>
|
||||
#include <vector>
|
||||
|
||||
#define SAT(c) \
|
||||
if (c & (~255)) { if (c < 0) c = 0; else c = 255; }
|
||||
if (c & (~255)) { \
|
||||
if (c < 0) { \
|
||||
c = 0; \
|
||||
} else { \
|
||||
c = 255; \
|
||||
} \
|
||||
}
|
||||
#define HBT(x) (unsigned char)((x)>>8)
|
||||
|
||||
#define KEY_A 4
|
||||
|
@ -117,12 +123,32 @@ extern const char* dstr[];
|
|||
#define SETTING_NEXT 81
|
||||
#define SETTING_PREVIOUS 82
|
||||
|
||||
enum CameraSetting { BRIGHTNESS, CONTRAST, SHARPNESS, AUTO_GAIN, GAIN, AUTO_EXPOSURE, EXPOSURE, SHUTTER, AUTO_FOCUS, FOCUS, AUTO_WHITE, WHITE, GAMMA, POWERLINE, BACKLIGHT, SATURATION, AUTO_HUE, COLOR_HUE, COLOR_RED, COLOR_GREEN, COLOR_BLUE };
|
||||
enum CameraSetting {
|
||||
BRIGHTNESS,
|
||||
CONTRAST,
|
||||
SHARPNESS,
|
||||
AUTO_GAIN,
|
||||
GAIN,
|
||||
AUTO_EXPOSURE,
|
||||
EXPOSURE,
|
||||
SHUTTER,
|
||||
AUTO_FOCUS,
|
||||
FOCUS,
|
||||
AUTO_WHITE,
|
||||
WHITE,
|
||||
GAMMA,
|
||||
POWERLINE,
|
||||
BACKLIGHT,
|
||||
SATURATION,
|
||||
AUTO_HUE,
|
||||
COLOR_HUE,
|
||||
COLOR_RED,
|
||||
COLOR_GREEN,
|
||||
COLOR_BLUE };
|
||||
#define MODE_MIN BRIGHTNESS
|
||||
#define MODE_MAX COLOR_BLUE
|
||||
|
||||
struct CameraConfig {
|
||||
|
||||
char path[256];
|
||||
|
||||
int driver;
|
||||
|
@ -166,37 +192,36 @@ struct CameraConfig {
|
|||
int red;
|
||||
int blue;
|
||||
int green;
|
||||
|
||||
bool force;
|
||||
|
||||
bool operator < (const CameraConfig& c) const {
|
||||
// if (device < c.device) return true;
|
||||
// if (cam_format < c.cam_format) return true;
|
||||
|
||||
//if (device < c.device) return true;
|
||||
//if (cam_format < c.cam_format) return true;
|
||||
|
||||
if (cam_width > c.cam_width || (cam_width == c.cam_width && cam_height < c.cam_height))
|
||||
if (cam_width > c.cam_width ||
|
||||
(cam_width == c.cam_width && cam_height < c.cam_height))
|
||||
return true;
|
||||
|
||||
if (cam_width == c.cam_width && cam_height == c.cam_height) {
|
||||
return (cam_fps > c.cam_fps);
|
||||
} else return false;
|
||||
|
||||
} else {return false;}
|
||||
}
|
||||
};
|
||||
|
||||
class CameraEngine
|
||||
{
|
||||
public:
|
||||
|
||||
CameraEngine(CameraConfig *cam_cfg) {
|
||||
class CameraEngine {
|
||||
public:
|
||||
explicit CameraEngine(CameraConfig *cam_cfg) {
|
||||
cfg = cam_cfg;
|
||||
settingsDialog=false;
|
||||
settingsDialog = false;
|
||||
|
||||
if (cfg->color) cfg->buf_format=FORMAT_RGB;
|
||||
else cfg->buf_format=FORMAT_GRAY;
|
||||
if (cfg->color) {
|
||||
cfg->buf_format = FORMAT_RGB;
|
||||
} else {
|
||||
cfg->buf_format = FORMAT_GRAY;
|
||||
}
|
||||
}
|
||||
|
||||
virtual ~CameraEngine() {};
|
||||
virtual ~CameraEngine() {}
|
||||
|
||||
virtual bool initCamera() = 0;
|
||||
virtual bool startCamera() = 0;
|
||||
|
@ -207,7 +232,8 @@ public:
|
|||
virtual bool stillRunning() = 0;
|
||||
|
||||
void printInfo();
|
||||
static void setMinMaxConfig(CameraConfig *cam_cfg, std::vector<CameraConfig> cfg_list);
|
||||
static void setMinMaxConfig(CameraConfig *cam_cfg,
|
||||
std::vector<CameraConfig> cfg_list);
|
||||
|
||||
virtual int getCameraSettingStep(int mode) = 0;
|
||||
virtual int getMinCameraSetting(int mode) = 0;
|
||||
|
@ -224,15 +250,14 @@ public:
|
|||
virtual bool showSettingsDialog(bool lock);
|
||||
virtual void control(unsigned char key);
|
||||
|
||||
int getId() { return cfg->device; }
|
||||
int getFps() { return (int)floor(cfg->cam_fps+0.5f); }
|
||||
int getWidth() { return cfg->frame_width; }
|
||||
int getHeight() { return cfg->frame_height; }
|
||||
int getFormat() { return cfg->buf_format; }
|
||||
char* getName() { return cfg->name; }
|
||||
|
||||
protected:
|
||||
inline int getId() { return cfg->device; }
|
||||
inline int getFps() { return static_cast<int>(floor(cfg->cam_fps+0.5f)); }
|
||||
inline int getWidth() { return cfg->frame_width; }
|
||||
inline int getHeight() { return cfg->frame_height; }
|
||||
inline int getFormat() { return cfg->buf_format; }
|
||||
inline char* getName() { return cfg->name; }
|
||||
|
||||
protected:
|
||||
CameraConfig *cfg;
|
||||
|
||||
unsigned char* frm_buffer;
|
||||
|
@ -244,18 +269,26 @@ protected:
|
|||
bool settingsDialog;
|
||||
int currentCameraSetting;
|
||||
|
||||
void crop(int width, int height, unsigned char *src, unsigned char *dest, int bytes);
|
||||
void flip(int width, int height, unsigned char *src, unsigned char *dest, int bytes);
|
||||
void flip_crop(int width, int height, unsigned char *src, unsigned char *dest, int bytes);
|
||||
void crop(int width, int height, unsigned char *src,
|
||||
unsigned char *dest, int bytes);
|
||||
void flip(int width, int height, unsigned char *src,
|
||||
unsigned char *dest, int bytes);
|
||||
void flip_crop(int width, int height, unsigned char *src,
|
||||
unsigned char *dest, int bytes);
|
||||
|
||||
void rgb2gray(int width, int height, unsigned char *src, unsigned char *dest);
|
||||
void rgb2gray(int width, int height, unsigned char *src,
|
||||
unsigned char *dest);
|
||||
void crop_rgb2gray(int width, unsigned char *src, unsigned char *dest);
|
||||
void flip_rgb2gray(int width, int height, unsigned char *src, unsigned char *dest);
|
||||
void flip_crop_rgb2gray(int width, unsigned char *src, unsigned char *dest);
|
||||
void flip_rgb2gray(int width, int height, unsigned char *src,
|
||||
unsigned char *dest);
|
||||
void flip_crop_rgb2gray(int width, unsigned char *src,
|
||||
unsigned char *dest);
|
||||
|
||||
void uyvy2gray(int width, int height, unsigned char *src, unsigned char *dest);
|
||||
void uyvy2gray(int width, int height, unsigned char *src,
|
||||
unsigned char *dest);
|
||||
void crop_uyvy2gray(int width, unsigned char *src, unsigned char *dest);
|
||||
void yuyv2gray(int width, int height, unsigned char *src, unsigned char *dest);
|
||||
void yuyv2gray(int width, int height, unsigned char *src,
|
||||
unsigned char *dest);
|
||||
void crop_yuyv2gray(int width, unsigned char *src, unsigned char *dest);
|
||||
void yuv2gray(int width, int height, unsigned char *src, unsigned char *dest);
|
||||
void crop_yuv2gray(int width, unsigned char *src, unsigned char *dest);
|
||||
|
@ -267,9 +300,11 @@ protected:
|
|||
void yuyv2rgb(int width, int height, unsigned char *src, unsigned char *dest);
|
||||
void crop_yuyv2rgb(int width, unsigned char *src, unsigned char *dest);
|
||||
|
||||
void grayw2rgb(int width, int height, unsigned char *src, unsigned char *dest);
|
||||
void grayw2rgb(int width, int height, unsigned char *src,
|
||||
unsigned char *dest);
|
||||
void crop_grayw2rgb(int width, unsigned char *src, unsigned char *dest);
|
||||
void grayw2gray(int width, int height, unsigned char *src, unsigned char *dest);
|
||||
void grayw2gray(int width, int height, unsigned char *src,
|
||||
unsigned char *dest);
|
||||
void crop_grayw2gray(int width, unsigned char *src, unsigned char *dest);
|
||||
|
||||
void resetCameraSettings();
|
||||
|
@ -303,4 +338,4 @@ protected:
|
|||
int ctrl_max;
|
||||
int ctrl_val;
|
||||
};
|
||||
#endif
|
||||
#endif // SRC_MYNTEYE_UVC_MACOSX_CAMERAENGINE_H_
|
||||
|
|
Loading…
Reference in New Issue
Block a user