00001 #include <ctype.h>
00002 #include "bchash.h"
00003 #include "picture.h"
00004 #include <string.h>
00005
00006
00007
00008
00009
00010 PictureItem::PictureItem()
00011 {
00012 name[0] = 0;
00013 min = 0;
00014 max = 0;
00015 default_ = 0;
00016 step = 0;
00017 type = 0;
00018 value = 0;
00019 device_id = 0;
00020 }
00021
00022
00023 PictureItem::~PictureItem()
00024 {
00025 }
00026
00027 void PictureItem::copy_from(PictureItem *src)
00028 {
00029 strcpy(this->name, src->name);
00030 this->device_id = src->device_id;
00031 this->min = src->min;
00032 this->max = src->max;
00033 this->default_ = src->default_;
00034 this->step = src->step;
00035 this->type = src->type;
00036 this->value = src->value;
00037 }
00038
00039 char* PictureItem::get_default_string(char *string)
00040 {
00041 sprintf(string, "VIDEO_%s_VALUE", name);
00042 for(int i = 0; i < strlen(string); i++)
00043 string[i] = toupper(string[i]);
00044 return string;
00045 }
00046
00047
00048
00049
00050
00051
00052
00053
00054 PictureConfig::PictureConfig(BC_Hash *defaults)
00055 {
00056 this->defaults = defaults;
00057 brightness = -1;
00058 hue = -1;
00059 color = -1;
00060 contrast = -1;
00061 whiteness = -1;
00062
00063 use_brightness = 0;
00064 use_contrast = 0;
00065 use_color = 0;
00066 use_hue = 0;
00067 use_whiteness = 0;
00068 }
00069
00070 PictureConfig::~PictureConfig()
00071 {
00072 controls.remove_all_objects();
00073 }
00074
00075 void PictureConfig::copy_settings(PictureConfig *picture)
00076 {
00077 this->brightness = picture->brightness;
00078 this->hue = picture->hue;
00079 this->color = picture->color;
00080 this->contrast = picture->contrast;
00081 this->whiteness = picture->whiteness;
00082
00083
00084 for(int i = 0; i < picture->controls.total; i++)
00085 {
00086 PictureItem *src_item = picture->controls.values[i];
00087 PictureItem *dst_item = 0;
00088 for(int j = 0; j < controls.total; j++)
00089 {
00090 if(controls.values[j]->device_id == src_item->device_id)
00091 {
00092 dst_item = controls.values[j];
00093 break;
00094 }
00095 }
00096 if(!dst_item)
00097 {
00098 dst_item = new PictureItem;
00099 controls.append(dst_item);
00100 }
00101 dst_item->copy_from(src_item);
00102 }
00103 }
00104
00105 void PictureConfig::copy_usage(PictureConfig *picture)
00106 {
00107 this->use_brightness = picture->use_brightness;
00108 this->use_contrast = picture->use_contrast;
00109 this->use_color = picture->use_color;
00110 this->use_hue = picture->use_hue;
00111 this->use_whiteness = picture->use_whiteness;
00112
00113
00114 for(int i = 0; i < picture->controls.total; i++)
00115 {
00116 PictureItem *src = picture->controls.values[i];
00117 int got_it = 0;
00118 for(int j = 0; j < controls.total; j++)
00119 {
00120 if(controls.values[j]->device_id == src->device_id)
00121 {
00122 got_it = 1;
00123 break;
00124 }
00125 }
00126 if(!got_it)
00127 {
00128 PictureItem *dst = new PictureItem;
00129 controls.append(dst);
00130 dst->copy_from(src);
00131 }
00132 }
00133 }
00134
00135 void PictureConfig::load_defaults()
00136 {
00137 if(!defaults)
00138 {
00139 printf("PictureConfig::load_defaults: no defaults pointer.\n");
00140 return;
00141 }
00142 brightness = defaults->get("VIDEO_BRIGHTNESS", 0);
00143 hue = defaults->get("VIDEO_HUE", 0);
00144 color = defaults->get("VIDEO_COLOR", 0);
00145 contrast = defaults->get("VIDEO_CONTRAST", 0);
00146 whiteness = defaults->get("VIDEO_WHITENESS", 0);
00147
00148
00149
00150 for(int i = 0; i < controls.total; i++)
00151 {
00152 PictureItem *item = controls.values[i];
00153 char string[BCTEXTLEN];
00154 item->get_default_string(string);
00155 item->value = defaults->get(string, item->value);
00156
00157 }
00158 }
00159
00160 void PictureConfig::save_defaults()
00161 {
00162 if(!defaults)
00163 {
00164 printf("PictureConfig::save_defaults: no defaults pointer.\n");
00165 return;
00166 }
00167 defaults->update("VIDEO_BRIGHTNESS", brightness);
00168 defaults->update("VIDEO_HUE", hue);
00169 defaults->update("VIDEO_COLOR", color);
00170 defaults->update("VIDEO_CONTRAST", contrast);
00171 defaults->update("VIDEO_WHITENESS", whiteness);
00172 for(int i = 0; i < controls.total; i++)
00173 {
00174 PictureItem *item = controls.values[i];
00175 char string[BCTEXTLEN];
00176 item->get_default_string(string);
00177 defaults->update(string, item->value);
00178
00179 }
00180 }
00181
00182 void PictureConfig::dump()
00183 {
00184 printf(" VIDEO_BRIGHTNESS=%d\n", brightness);
00185 printf(" VIDEO_HUE=%d\n", hue);
00186 printf(" VIDEO_COLOR=%d\n", color);
00187 printf(" VIDEO_CONTRAST=%d\n", contrast);
00188 printf(" VIDEO_WHITENESS=%d\n", whiteness);
00189 for(int i = 0; i < controls.total; i++)
00190 {
00191 PictureItem *item = controls.values[i];
00192 char string[BCTEXTLEN];
00193 item->get_default_string(string);
00194 printf(" %s=%d\n", string, item->value);
00195 }
00196 }
00197
00198 PictureItem* PictureConfig::new_item(const char *name)
00199 {
00200 for(int i = 0; i < controls.total; i++)
00201 {
00202 if(!strcmp(controls.values[i]->name, name)) return controls.values[i];
00203 }
00204 PictureItem *item = new PictureItem;
00205 strcpy(item->name, name);
00206 controls.append(item);
00207 return item;
00208 }
00209
00210 PictureItem* PictureConfig::get_item(const char *name, int id)
00211 {
00212 for(int i = 0; i < controls.total; i++)
00213 {
00214 if(!strcmp(controls.values[i]->name, name) &&
00215 controls.values[i]->device_id == id) return controls.values[i];
00216 }
00217 return 0;
00218 }
00219
00220 void PictureConfig::set_item(int device_id, int value)
00221 {
00222 for(int i = 0; i < controls.total; i++)
00223 {
00224 if(controls.values[i]->device_id == device_id)
00225 {
00226 controls.values[i]->value = value;
00227 return;
00228 }
00229 }
00230 }
00231
00232
00233
00234
00235
00236
00237
00238