Main Page | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Class Members | File Members

picture.C

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

Generated on Sun Jan 8 13:38:58 2006 for Cinelerra-svn by  doxygen 1.4.4