r668: Configure.in and autogen.sh cleanup based on ideas by giskard.
[cinelerra_cv.git] / cinelerra / picture.C
blob4f654549b5f66cee699b68d9119fb9180e96f340
1 #include <ctype.h>
2 #include "defaults.h"
3 #include "mwindow.h"
4 #include "picture.h"
5 #include <string.h>
11 PictureItem::PictureItem()
13         name[0] = 0;
14         min = 0;
15         max = 0;
16         default_ = 0;
17         step = 0;
18         type = 0;
19         value = 0;
20         device_id = 0;
24 PictureItem::~PictureItem()
28 void PictureItem::copy_from(PictureItem *src)
30         strcpy(this->name, src->name);
31         this->device_id = src->device_id;
32         this->min = src->min;
33         this->max = src->max;
34         this->default_ = src->default_;
35         this->step = src->step;
36         this->type = src->type;
37         this->value = src->value;
40 char* PictureItem::get_default_string(char *string)
42         sprintf(string, "VIDEO_%s_VALUE", name);
43         for(int i = 0; i < strlen(string); i++)
44                 string[i] = toupper(string[i]);
45         return string;
55 PictureConfig::PictureConfig(MWindow *mwindow)
57         this->mwindow = mwindow;
58         brightness = -1;
59         hue = -1;
60         color = -1;
61         contrast = -1;
62         whiteness = -1;
64         use_brightness = 0;
65         use_contrast = 0;
66         use_color = 0;
67         use_hue = 0;
68         use_whiteness = 0;
71 PictureConfig::~PictureConfig()
73         controls.remove_all_objects();
76 void PictureConfig::copy_settings(PictureConfig *picture)
78         this->brightness = picture->brightness;
79         this->hue = picture->hue;
80         this->color = picture->color;
81         this->contrast = picture->contrast;
82         this->whiteness = picture->whiteness;
85         for(int i = 0; i < picture->controls.total; i++)
86         {
87                 PictureItem *src_item = picture->controls.values[i];
88                 PictureItem *dst_item = 0;
89                 for(int j = 0; j < controls.total; j++)
90                 {
91                         if(controls.values[j]->device_id == src_item->device_id)
92                         {
93                                 dst_item = controls.values[j];
94                                 break;
95                         }
96                 }
97                 if(!dst_item)
98                 {
99                         dst_item = new PictureItem;
100                         controls.append(dst_item);
101                 }
102                 dst_item->copy_from(src_item);
103         }
106 void PictureConfig::copy_usage(PictureConfig *picture)
108         this->use_brightness = picture->use_brightness;
109         this->use_contrast = picture->use_contrast;
110         this->use_color = picture->use_color;
111         this->use_hue = picture->use_hue;
112         this->use_whiteness = picture->use_whiteness;
114 // Add the controls if they don't exists but don't replace existing values.
115         for(int i = 0; i < picture->controls.total; i++)
116         {
117                 PictureItem *src = picture->controls.values[i];
118                 int got_it = 0;
119                 for(int j = 0; j < controls.total; j++)
120                 {
121                         if(controls.values[j]->device_id == src->device_id)
122                         {
123                                 got_it = 1;
124                                 break;
125                         }
126                 }
127                 if(!got_it)
128                 {
129                         PictureItem *dst = new PictureItem;
130                         controls.append(dst);
131                         dst->copy_from(src);
132                 }
133         }
136 void PictureConfig::load_defaults()
138         if(!mwindow)
139         {
140                 printf("PictureConfig::load_defaults: mwindow not set.\n");
141                 return;
142         }
143         brightness = mwindow->defaults->get("VIDEO_BRIGHTNESS", 0);
144         hue = mwindow->defaults->get("VIDEO_HUE", 0);
145         color = mwindow->defaults->get("VIDEO_COLOR", 0);
146         contrast = mwindow->defaults->get("VIDEO_CONTRAST", 0);
147         whiteness = mwindow->defaults->get("VIDEO_WHITENESS", 0);
149 // The device must be probed first to keep unsupported controls from getting 
150 // displayed.
151         for(int i = 0; i < controls.total; i++)
152         {
153                 PictureItem *item = controls.values[i];
154                 char string[BCTEXTLEN];
155                 item->get_default_string(string);
156                 item->value = mwindow->defaults->get(string, item->value);
157 //printf("PictureConfig::load_defaults %s %d %d\n", item->name, item->device_id, item->value);
158         }
161 void PictureConfig::save_defaults()
163         if(!mwindow)
164         {
165                 printf("PictureConfig::save_defaults: mwindow not set.\n");
166                 return;
167         }
168         mwindow->defaults->update("VIDEO_BRIGHTNESS", brightness);
169         mwindow->defaults->update("VIDEO_HUE", hue);
170         mwindow->defaults->update("VIDEO_COLOR", color);
171         mwindow->defaults->update("VIDEO_CONTRAST", contrast);
172         mwindow->defaults->update("VIDEO_WHITENESS", whiteness);
173         for(int i = 0; i < controls.total; i++)
174         {
175                 PictureItem *item = controls.values[i];
176                 char string[BCTEXTLEN];
177                 item->get_default_string(string);
178                 mwindow->defaults->update(string, item->value);
179 //printf("PictureConfig::save_defaults %s %d %d\n", string, item->device_id, item->value);
180         }
183 PictureItem* PictureConfig::new_item(const char *name)
185         for(int i = 0; i < controls.total; i++)
186         {
187                 if(!strcmp(controls.values[i]->name, name)) return controls.values[i];
188         }
189         PictureItem *item = new PictureItem;
190         strcpy(item->name, name);
191         controls.append(item);
192         return item;
195 PictureItem* PictureConfig::get_item(const char *name, int id)
197         for(int i = 0; i < controls.total; i++)
198         {
199                 if(!strcmp(controls.values[i]->name, name) &&
200                         controls.values[i]->device_id == id) return controls.values[i];
201         }
202         return 0;
205 void PictureConfig::set_item(int device_id, int value)
207         for(int i = 0; i < controls.total; i++)
208         {
209                 if(controls.values[i]->device_id == device_id)
210                 {
211                         controls.values[i]->value = value;
212                         return;
213                 }
214         }