r1009: Move the dependencies to newer package names
[cinelerra_cv/mob.git] / cinelerra / picture.C
blob7a0afae806c109aa55dadfb8108c6721438d9c0e
1 #include <ctype.h>
2 #include "bchash.h"
3 #include "picture.h"
4 #include <string.h>
10 PictureItem::PictureItem()
12         name[0] = 0;
13         min = 0;
14         max = 0;
15         default_ = 0;
16         step = 0;
17         type = 0;
18         value = 0;
19         device_id = 0;
23 PictureItem::~PictureItem()
27 void PictureItem::copy_from(PictureItem *src)
29         strcpy(this->name, src->name);
30         this->device_id = src->device_id;
31         this->min = src->min;
32         this->max = src->max;
33         this->default_ = src->default_;
34         this->step = src->step;
35         this->type = src->type;
36         this->value = src->value;
39 char* PictureItem::get_default_string(char *string)
41         sprintf(string, "VIDEO_%s_VALUE", name);
42         for(int i = 0; i < strlen(string); i++)
43                 string[i] = toupper(string[i]);
44         return string;
54 PictureConfig::PictureConfig(BC_Hash *defaults)
56         this->defaults = defaults;
57         brightness = -1;
58         hue = -1;
59         color = -1;
60         contrast = -1;
61         whiteness = -1;
63         use_brightness = 0;
64         use_contrast = 0;
65         use_color = 0;
66         use_hue = 0;
67         use_whiteness = 0;
70 PictureConfig::~PictureConfig()
72         controls.remove_all_objects();
75 void PictureConfig::copy_settings(PictureConfig *picture)
77         this->brightness = picture->brightness;
78         this->hue = picture->hue;
79         this->color = picture->color;
80         this->contrast = picture->contrast;
81         this->whiteness = picture->whiteness;
84         for(int i = 0; i < picture->controls.total; i++)
85         {
86                 PictureItem *src_item = picture->controls.values[i];
87                 PictureItem *dst_item = 0;
88                 for(int j = 0; j < controls.total; j++)
89                 {
90                         if(controls.values[j]->device_id == src_item->device_id)
91                         {
92                                 dst_item = controls.values[j];
93                                 break;
94                         }
95                 }
96                 if(!dst_item)
97                 {
98                         dst_item = new PictureItem;
99                         controls.append(dst_item);
100                 }
101                 dst_item->copy_from(src_item);
102         }
105 void PictureConfig::copy_usage(PictureConfig *picture)
107         this->use_brightness = picture->use_brightness;
108         this->use_contrast = picture->use_contrast;
109         this->use_color = picture->use_color;
110         this->use_hue = picture->use_hue;
111         this->use_whiteness = picture->use_whiteness;
113 // Add the controls if they don't exists but don't replace existing values.
114         for(int i = 0; i < picture->controls.total; i++)
115         {
116                 PictureItem *src = picture->controls.values[i];
117                 int got_it = 0;
118                 for(int j = 0; j < controls.total; j++)
119                 {
120                         if(controls.values[j]->device_id == src->device_id)
121                         {
122                                 got_it = 1;
123                                 break;
124                         }
125                 }
126                 if(!got_it)
127                 {
128                         PictureItem *dst = new PictureItem;
129                         controls.append(dst);
130                         dst->copy_from(src);
131                 }
132         }
135 void PictureConfig::load_defaults()
137         if(!defaults)
138         {
139                 printf("PictureConfig::load_defaults: no defaults pointer.\n");
140                 return;
141         }
142         brightness = defaults->get("VIDEO_BRIGHTNESS", 0);
143         hue = defaults->get("VIDEO_HUE", 0);
144         color = defaults->get("VIDEO_COLOR", 0);
145         contrast = defaults->get("VIDEO_CONTRAST", 0);
146         whiteness = defaults->get("VIDEO_WHITENESS", 0);
148 // The device must be probed first to keep unsupported controls from getting 
149 // displayed.
150         for(int i = 0; i < controls.total; i++)
151         {
152                 PictureItem *item = controls.values[i];
153                 char string[BCTEXTLEN];
154                 item->get_default_string(string);
155                 item->value = defaults->get(string, item->value);
156 //printf("PictureConfig::load_defaults %s %d %d\n", item->name, item->device_id, item->value);
157         }
160 void PictureConfig::save_defaults()
162         if(!defaults)
163         {
164                 printf("PictureConfig::save_defaults: no defaults pointer.\n");
165                 return;
166         }
167         defaults->update("VIDEO_BRIGHTNESS", brightness);
168         defaults->update("VIDEO_HUE", hue);
169         defaults->update("VIDEO_COLOR", color);
170         defaults->update("VIDEO_CONTRAST", contrast);
171         defaults->update("VIDEO_WHITENESS", whiteness);
172         for(int i = 0; i < controls.total; i++)
173         {
174                 PictureItem *item = controls.values[i];
175                 char string[BCTEXTLEN];
176                 item->get_default_string(string);
177                 defaults->update(string, item->value);
178 //printf("PictureConfig::save_defaults %s %d %d\n", string, item->device_id, item->value);
179         }
182 void PictureConfig::dump()
184         printf("    VIDEO_BRIGHTNESS=%d\n", brightness);
185         printf("    VIDEO_HUE=%d\n", hue);
186         printf("    VIDEO_COLOR=%d\n", color);
187         printf("    VIDEO_CONTRAST=%d\n", contrast);
188         printf("    VIDEO_WHITENESS=%d\n", whiteness);
189         for(int i = 0; i < controls.total; i++)
190         {
191                 PictureItem *item = controls.values[i];
192                 char string[BCTEXTLEN];
193                 item->get_default_string(string);
194                 printf("    %s=%d\n", string, item->value);
195         }
198 PictureItem* PictureConfig::new_item(const char *name)
200         for(int i = 0; i < controls.total; i++)
201         {
202                 if(!strcmp(controls.values[i]->name, name)) return controls.values[i];
203         }
204         PictureItem *item = new PictureItem;
205         strcpy(item->name, name);
206         controls.append(item);
207         return item;
210 PictureItem* PictureConfig::get_item(const char *name, int id)
212         for(int i = 0; i < controls.total; i++)
213         {
214                 if(!strcmp(controls.values[i]->name, name) &&
215                         controls.values[i]->device_id == id) return controls.values[i];
216         }
217         return 0;
220 void PictureConfig::set_item(int device_id, int value)
222         for(int i = 0; i < controls.total; i++)
223         {
224                 if(controls.values[i]->device_id == device_id)
225                 {
226                         controls.values[i]->value = value;
227                         return;
228                 }
229         }