00001 #include "bcdisplayinfo.h"
00002 #include "colorbalancewindow.h"
00003 #include "language.h"
00004
00005
00006
00007
00008
00009 PLUGIN_THREAD_OBJECT(ColorBalanceMain, ColorBalanceThread, ColorBalanceWindow)
00010
00011
00012
00013
00014
00015
00016 ColorBalanceWindow::ColorBalanceWindow(ColorBalanceMain *client, int x, int y)
00017 : BC_Window(client->gui_string, x,
00018 y,
00019 330,
00020 250,
00021 330,
00022 250,
00023 0,
00024 0)
00025 {
00026 this->client = client;
00027 }
00028
00029 ColorBalanceWindow::~ColorBalanceWindow()
00030 {
00031 }
00032
00033 int ColorBalanceWindow::create_objects()
00034 {
00035 int x = 10, y = 10;
00036 add_tool(new BC_Title(x, y, _("Color Balance")));
00037 y += 25;
00038 add_tool(new BC_Title(x, y, _("Cyan")));
00039 add_tool(cyan = new ColorBalanceSlider(client, &(client->config.cyan), x + 70, y));
00040 add_tool(new BC_Title(x + 270, y, _("Red")));
00041 y += 25;
00042 add_tool(new BC_Title(x, y, _("Magenta")));
00043 add_tool(magenta = new ColorBalanceSlider(client, &(client->config.magenta), x + 70, y));
00044 add_tool(new BC_Title(x + 270, y, _("Green")));
00045 y += 25;
00046 add_tool(new BC_Title(x, y, _("Yellow")));
00047 add_tool(yellow = new ColorBalanceSlider(client, &(client->config.yellow), x + 70, y));
00048 add_tool(new BC_Title(x + 270, y, _("Blue")));
00049 y += 25;
00050 add_tool(preserve = new ColorBalancePreserve(client, x + 70, y));
00051 y += preserve->get_h() + 10;
00052 add_tool(lock_params = new ColorBalanceLock(client, x + 70, y));
00053 y += lock_params->get_h() + 10;
00054 add_tool(new ColorBalanceWhite(client, this, x, y));
00055 y += lock_params->get_h() + 10;
00056 add_tool(new ColorBalanceReset(client, this, x, y));
00057
00058 show_window();
00059 flush();
00060 return 0;
00061 }
00062
00063 void ColorBalanceWindow::update()
00064 {
00065 cyan->update((int64_t)client->config.cyan);
00066 magenta->update((int64_t)client->config.magenta);
00067 yellow->update((int64_t)client->config.yellow);
00068 }
00069
00070 WINDOW_CLOSE_EVENT(ColorBalanceWindow)
00071
00072 ColorBalanceSlider::ColorBalanceSlider(ColorBalanceMain *client,
00073 float *output, int x, int y)
00074 : BC_ISlider(x,
00075 y,
00076 0,
00077 200,
00078 200,
00079 -1000,
00080 1000,
00081 (int)*output)
00082 {
00083 this->client = client;
00084 this->output = output;
00085 old_value = *output;
00086 }
00087
00088 ColorBalanceSlider::~ColorBalanceSlider()
00089 {
00090 }
00091
00092 int ColorBalanceSlider::handle_event()
00093 {
00094 float difference = get_value() - *output;
00095 *output = get_value();
00096 client->synchronize_params(this, difference);
00097 client->send_configure_change();
00098 return 1;
00099 }
00100
00101 char* ColorBalanceSlider::get_caption()
00102 {
00103 float fraction = client->calculate_transfer(*output);
00104 sprintf(string, "%0.4f", fraction);
00105 return string;
00106 }
00107
00108
00109
00110
00111 ColorBalancePreserve::ColorBalancePreserve(ColorBalanceMain *client, int x, int y)
00112 : BC_CheckBox(x,
00113 y,
00114 client->config.preserve,
00115 _("Preserve luminosity"))
00116 {
00117 this->client = client;
00118 }
00119 ColorBalancePreserve::~ColorBalancePreserve()
00120 {
00121 }
00122
00123 int ColorBalancePreserve::handle_event()
00124 {
00125 client->config.preserve = get_value();
00126 client->send_configure_change();
00127 return 1;
00128 }
00129
00130 ColorBalanceLock::ColorBalanceLock(ColorBalanceMain *client, int x, int y)
00131 : BC_CheckBox(x,
00132 y,
00133 client->config.lock_params,
00134 _("Lock parameters"))
00135 {
00136 this->client = client;
00137 }
00138 ColorBalanceLock::~ColorBalanceLock()
00139 {
00140 }
00141
00142 int ColorBalanceLock::handle_event()
00143 {
00144 client->config.lock_params = get_value();
00145 client->send_configure_change();
00146 return 1;
00147 }
00148
00149
00150 ColorBalanceWhite::ColorBalanceWhite(ColorBalanceMain *plugin,
00151 ColorBalanceWindow *gui,
00152 int x,
00153 int y)
00154 : BC_GenericButton(x, y, _("White balance"))
00155 {
00156 this->plugin = plugin;
00157 this->gui = gui;
00158 }
00159
00160 int ColorBalanceWhite::handle_event()
00161 {
00162
00163 float red = plugin->get_red();
00164 float green = plugin->get_green();
00165 float blue = plugin->get_blue();
00166
00167
00168
00169
00170
00171
00172
00173
00174 float min = MIN(red, green);
00175 min = MIN(min, blue);
00176
00177 float r_factor = min / red;
00178 float g_factor = min / green;
00179 float b_factor = min / blue;
00180
00181
00182 r_factor = green / red;
00183 g_factor = 1.0;
00184 b_factor = green / blue;
00185
00186 plugin->config.cyan = plugin->calculate_slider(r_factor);
00187 plugin->config.magenta = plugin->calculate_slider(g_factor);
00188 plugin->config.yellow = plugin->calculate_slider(b_factor);
00189 gui->update();
00190
00191 plugin->send_configure_change();
00192 return 1;
00193 }
00194
00195
00196 ColorBalanceReset::ColorBalanceReset(ColorBalanceMain *plugin,
00197 ColorBalanceWindow *gui,
00198 int x,
00199 int y)
00200 : BC_GenericButton(x, y, _("Reset"))
00201 {
00202 this->plugin = plugin;
00203 this->gui = gui;
00204 }
00205
00206 int ColorBalanceReset::handle_event()
00207 {
00208 plugin->config.cyan = 0;
00209 plugin->config.magenta = 0;
00210 plugin->config.yellow = 0;
00211 gui->update();
00212 plugin->send_configure_change();
00213 return 1;
00214 }
00215
00216