void CameraEngine::applyCameraSetting(int mode, int value) { switch (value) { case SETTING_DEFAULT: break; case SETTING_AUTO: setCameraSettingAuto(mode,true); break; case SETTING_MIN: setCameraSetting(mode,getMinCameraSetting(mode)); break; case SETTING_MAX: setCameraSetting(mode,getMaxCameraSetting(mode)); break; default: { int max = getMaxCameraSetting(mode); int min = getMinCameraSetting(mode); if (value<min) value = min; else if (value>max) value = max; setCameraSetting(mode,value); } } }
void CameraEngine::drawGUI(SDL_Surface *display) { if(!settingsDialog) return; unsigned char* disp = (unsigned char*)(display->pixels); int settingValue = getCameraSetting(currentCameraSetting); int maxValue = getMaxCameraSetting(currentCameraSetting); int minValue = getMinCameraSetting(currentCameraSetting); int valueRange = maxValue - minValue; const char *settingText = NULL; switch (currentCameraSetting) { case BRIGHTNESS: settingText = "Brightness"; break; case GAIN: settingText = "Gain"; break; case SHUTTER: settingText = "Shutter"; break; case EXPOSURE: settingText = "Exposure"; break; case SHARPNESS: settingText = "Sharpness"; break; case FOCUS: settingText = "Focus"; break; case GAMMA: settingText = "Gamma"; break; } int x_offset=width/2-128; int y_offset=height-100; char displayText[256]; sprintf(displayText,"%s %d",settingText,settingValue); FontTool::drawText(x_offset+128-(FontTool::getTextWidth(displayText)/2),y_offset-FontTool::getFontHeight(),displayText,display); // draw the border for (int i=x_offset;i<(x_offset+256);i++) { int pixel=(width*y_offset+i)*3+1; disp[pixel]=255; pixel=(width*(y_offset+25)+i)*3+1; disp[pixel]=255; } for (int i=y_offset;i<(y_offset+25);i++) { int pixel=(width*i+x_offset)*3+1; disp[pixel]=255; pixel=(width*i+x_offset+256)*3+1; disp[pixel]=255; } // draw the bar int xpos = (int)(254*(((float)settingValue-(float)minValue)/(float)valueRange)); for (int i=x_offset+2;i<=(x_offset+xpos);i++) { for (int j=y_offset+2;j<=(y_offset+23);j++) { int pixel=(width*j+i)*3+1; disp[pixel]=255; } } }
void CameraEngine::control(int key) { if(!settingsDialog) return; int value,min,max,step = 0; switch(key) { case SDLK_LEFT: value = getCameraSetting(currentCameraSetting); min = getMinCameraSetting(currentCameraSetting); max = getMaxCameraSetting(currentCameraSetting); step = getCameraSettingStep(currentCameraSetting); if (step==1) step = (int)((float)max/256.0f); if (step<1) step=1; value -= step; if (value<min) value=min; setCameraSetting(currentCameraSetting,value); break; case SDLK_RIGHT: value = getCameraSetting(currentCameraSetting); min = getMinCameraSetting(currentCameraSetting); max = getMaxCameraSetting(currentCameraSetting); step = getCameraSettingStep(currentCameraSetting); if (step==1) step = (int)((float)max/256.0f); if (step<1) step=1; value += step; if (value>max) value=max; setCameraSetting(currentCameraSetting,value); break; case SDLK_UP: currentCameraSetting--; if(currentCameraSetting<0) currentCameraSetting=GAMMA; break; case SDLK_DOWN: currentCameraSetting++; if(currentCameraSetting>GAMMA) currentCameraSetting=0; break; } }
void CameraEngine::updateSettings() { int brightness = getCameraSetting(BRIGHTNESS); if (brightness==getMinCameraSetting(BRIGHTNESS)) config.brightness=SETTING_MIN; if (brightness==getMaxCameraSetting(BRIGHTNESS)) config.brightness=SETTING_MAX; if (brightness==getDefaultCameraSetting(BRIGHTNESS)) config.brightness=SETTING_DEFAULT; //printf("brightness %d\n",brightness); int contrast = getCameraSetting(CONTRAST); if (contrast==getMinCameraSetting(CONTRAST)) config.contrast=SETTING_MIN; if (contrast==getMaxCameraSetting(CONTRAST)) config.contrast=SETTING_MAX; if (contrast==getDefaultCameraSetting(CONTRAST)) config.contrast=SETTING_DEFAULT; //printf("contrast %d\n",contrast); int gain = getCameraSetting(GAIN); if (gain==getMinCameraSetting(GAIN)) config.gain=SETTING_MIN; if (gain==getMaxCameraSetting(GAIN)) config.gain=SETTING_MAX; if (gain==getDefaultCameraSetting(GAIN)) config.gain=SETTING_DEFAULT; //printf("gain %d\n",gain); int exposure = getCameraSetting(EXPOSURE); if (exposure==getMinCameraSetting(EXPOSURE)) config.exposure=SETTING_MIN; if (exposure==getMaxCameraSetting(EXPOSURE)) config.exposure=SETTING_MAX; if (getCameraSettingAuto(EXPOSURE)==true) config.exposure=SETTING_AUTO; if (exposure==getDefaultCameraSetting(EXPOSURE)) config.exposure=SETTING_DEFAULT; //printf("exposure %d\n",exposure); int sharpness = getCameraSetting(SHARPNESS); if (sharpness==getMinCameraSetting(SHARPNESS)) config.sharpness=SETTING_MIN; if (sharpness==getMaxCameraSetting(SHARPNESS)) config.sharpness=SETTING_MAX; if (sharpness==getDefaultCameraSetting(SHARPNESS)) config.sharpness=SETTING_DEFAULT; //printf("sharpness %d\n",sharpness); int focus = getCameraSetting(FOCUS); if (focus==getMinCameraSetting(FOCUS)) config.focus=SETTING_MIN; if (focus==getMaxCameraSetting(FOCUS)) config.focus=SETTING_MAX; if (focus==getDefaultCameraSetting(FOCUS)) config.focus=SETTING_DEFAULT; //printf("focus %d\n",focus); int gamma = getCameraSetting(GAMMA); if (gamma==getMinCameraSetting(GAMMA)) config.gamma=SETTING_MIN; if (gamma==getMaxCameraSetting(GAMMA)) config.gamma=SETTING_MAX; if (gamma==getDefaultCameraSetting(GAMMA)) config.gamma=SETTING_DEFAULT; if (getCameraSettingAuto(GAMMA)==true) config.gamma=SETTING_AUTO; //printf("gamma %d\n",gamma); }