00001 #include "bcdisplayinfo.h"
00002 #include "gammawindow.h"
00003 #include "language.h"
00004
00005
00006
00007
00008
00009 PLUGIN_THREAD_OBJECT(GammaMain, GammaThread, GammaWindow)
00010
00011
00012
00013
00014
00015
00016 GammaWindow::GammaWindow(GammaMain *client, int x, int y)
00017 : BC_Window(client->gui_string, x,
00018 y,
00019 400,
00020 350,
00021 400,
00022 350,
00023 0,
00024 0)
00025 {
00026 this->client = client;
00027 }
00028
00029 int GammaWindow::create_objects()
00030 {
00031 int x = 10, y = 10;
00032 add_subwindow(histogram = new BC_SubWindow(x,
00033 y,
00034 get_w() - x * 2,
00035 get_h() - 150,
00036 WHITE));
00037 y += histogram->get_h() + 10;
00038
00039 BC_Title *title;
00040 add_tool(title = new BC_Title(x, y, _("Maximum:")));
00041 x += title->get_w() + 10;
00042 add_tool(max_slider = new MaxSlider(client,
00043 this,
00044 x,
00045 y,
00046 190));
00047 x += max_slider->get_w() + 10;
00048 add_tool(max_text = new MaxText(client,
00049 this,
00050 x,
00051 y,
00052 100));
00053 y += max_text->get_h() + 10;
00054 x = 10;
00055 add_tool(automatic = new GammaAuto(client, x, y));
00056
00057 y += automatic->get_h() + 10;
00058 add_tool(title = new BC_Title(x, y, _("Gamma:")));
00059 x += title->get_w() + 10;
00060 add_tool(gamma_slider = new GammaSlider(client,
00061 this,
00062 x,
00063 y,
00064 190));
00065 x += gamma_slider->get_w() + 10;
00066 add_tool(gamma_text = new GammaText(client,
00067 this,
00068 x,
00069 y,
00070 100));
00071 y += gamma_text->get_h() + 10;
00072 x = 10;
00073
00074 add_tool(plot = new GammaPlot(client, x, y));
00075 y += plot->get_h() + 10;
00076
00077 add_tool(new GammaColorPicker(client, this, x, y));
00078
00079 show_window();
00080 flush();
00081 return 0;
00082 }
00083
00084 void GammaWindow::update()
00085 {
00086 max_slider->update(client->config.max);
00087 max_text->update(client->config.max);
00088 gamma_slider->update(client->config.gamma);
00089 gamma_text->update(client->config.gamma);
00090 automatic->update(client->config.automatic);
00091 plot->update(client->config.plot);
00092 update_histogram();
00093 }
00094
00095 void GammaWindow::update_histogram()
00096 {
00097 histogram->clear_box(0, 0, histogram->get_w(), histogram->get_h());
00098 if(client->engine)
00099 {
00100 int max = 0;
00101 histogram->set_color(MEGREY);
00102 for(int i = 0; i < histogram->get_w(); i++)
00103 {
00104 int x1 = (int64_t)i * HISTOGRAM_SIZE / histogram->get_w();
00105 int x2 = (int64_t)(i + 1) * HISTOGRAM_SIZE / histogram->get_w();
00106 if(x2 == x1) x2++;
00107 int accum = 0;
00108 for(int x = x1; x < x2; x++)
00109 {
00110 accum += client->engine->accum[x];
00111 }
00112 if(accum > max) max = accum;
00113 }
00114 for(int i = 0; i < histogram->get_w(); i++)
00115 {
00116 int x1 = (int64_t)i * HISTOGRAM_SIZE / histogram->get_w();
00117 int x2 = (int64_t)(i + 1) * HISTOGRAM_SIZE / histogram->get_w();
00118 if(x2 == x1) x2++;
00119 int accum = 0;
00120 for(int x = x1; x < x2; x++)
00121 {
00122 accum += client->engine->accum[x];
00123 }
00124
00125 int h = (int)(log(accum) / log(max) * histogram->get_h());
00126 histogram->draw_line(i,
00127 histogram->get_h(),
00128 i,
00129 histogram->get_h() - h);
00130 }
00131 }
00132
00133 histogram->set_color(GREEN);
00134 int y1 = histogram->get_h();
00135 float scale = 1.0 / client->config.max;
00136 float gamma = client->config.gamma - 1.0;
00137 float max = client->config.max;
00138 for(int i = 1; i < histogram->get_w(); i++)
00139 {
00140 float in = (float)i / histogram->get_w();
00141 float out = in * (scale * pow(in * 2 / max, gamma));
00142 int y2 = (int)(histogram->get_h() - out * histogram->get_h());
00143 histogram->draw_line(i - 1, y1, i, y2);
00144 y1 = y2;
00145 }
00146 histogram->flash();
00147 }
00148
00149 WINDOW_CLOSE_EVENT(GammaWindow)
00150
00151 MaxSlider::MaxSlider(GammaMain *client,
00152 GammaWindow *gui,
00153 int x,
00154 int y,
00155 int w)
00156 : BC_FSlider(x,
00157 y,
00158 0,
00159 w,
00160 w,
00161 0.0,
00162 1.0,
00163 client->config.max)
00164 {
00165 this->client = client;
00166 this->gui = gui;
00167 set_precision(0.01);
00168 }
00169
00170 int MaxSlider::handle_event()
00171 {
00172 client->config.max = get_value();
00173 gui->max_text->update(client->config.max);
00174 gui->update_histogram();
00175 client->send_configure_change();
00176 return 1;
00177 }
00178
00179 MaxText::MaxText(GammaMain *client,
00180 GammaWindow *gui,
00181 int x,
00182 int y,
00183 int w)
00184 : BC_TextBox(x, y, w, 1, client->config.max)
00185 {
00186 this->client = client;
00187 this->gui = gui;
00188 }
00189
00190 int MaxText::handle_event()
00191 {
00192 client->config.max = atof(get_text());
00193 gui->max_slider->update(client->config.max);
00194 client->send_configure_change();
00195 return 1;
00196 }
00197
00198 GammaSlider::GammaSlider(GammaMain *client,
00199 GammaWindow *gui,
00200 int x,
00201 int y,
00202 int w)
00203 : BC_FSlider(x,
00204 y,
00205 0,
00206 w,
00207 w,
00208 0.0,
00209 1.0,
00210 client->config.gamma)
00211 {
00212 this->client = client;
00213 this->gui = gui;
00214 set_precision(0.01);
00215 }
00216
00217 int GammaSlider::handle_event()
00218 {
00219 client->config.gamma = get_value();
00220 gui->gamma_text->update(client->config.gamma);
00221 gui->update_histogram();
00222 client->send_configure_change();
00223 return 1;
00224 }
00225
00226 GammaText::GammaText(GammaMain *client,
00227 GammaWindow *gui,
00228 int x,
00229 int y,
00230 int w)
00231 : BC_TextBox(x, y, w, 1, client->config.gamma)
00232 {
00233 this->client = client;
00234 this->gui = gui;
00235 }
00236
00237 int GammaText::handle_event()
00238 {
00239 client->config.gamma = atof(get_text());
00240 gui->gamma_slider->update(client->config.gamma);
00241 client->send_configure_change();
00242 return 1;
00243 }
00244
00245 GammaAuto::GammaAuto(GammaMain *client, int x, int y)
00246 : BC_CheckBox(x,
00247 y,
00248 client->config.automatic,
00249 _("Automatic"))
00250 {
00251 this->plugin = client;
00252 }
00253
00254 int GammaAuto::handle_event()
00255 {
00256 plugin->config.automatic = get_value();
00257 plugin->send_configure_change();
00258 return 1;
00259 }
00260
00261
00262 GammaPlot::GammaPlot(GammaMain *plugin, int x, int y)
00263 : BC_CheckBox(x, y, plugin->config.plot, _("Plot histogram"))
00264 {
00265 this->plugin = plugin;
00266 }
00267 int GammaPlot::handle_event()
00268 {
00269 plugin->config.plot = get_value();
00270 plugin->send_configure_change();
00271 return 1;
00272 }
00273
00274
00275 GammaColorPicker::GammaColorPicker(GammaMain *plugin,
00276 GammaWindow *gui,
00277 int x,
00278 int y)
00279 : BC_GenericButton(x, y, _("Use Color Picker"))
00280 {
00281 this->plugin = plugin;
00282 this->gui = gui;
00283 }
00284
00285 int GammaColorPicker::handle_event()
00286 {
00287
00288 float red = plugin->get_red();
00289 float green = plugin->get_green();
00290 float blue = plugin->get_blue();
00291
00292 plugin->config.max = MAX(red, green);
00293 plugin->config.max = MAX(plugin->config.max, blue);
00294 gui->max_text->update(plugin->config.max);
00295 gui->max_slider->update(plugin->config.max);
00296 plugin->send_configure_change();
00297 return 1;
00298 }
00299
00300