X-Git-Url: http://git.cinelerra-gg.org/git/?a=blobdiff_plain;f=cinelerra-5.1%2Fcinelerra%2Fcolorpicker.C;h=1b40fcf0c38f8d00bca6f4b35972422918d71c3c;hb=803cf48f8f7ee246eb5473e55fc2125e8b398250;hp=969e8c98ce6d870f643e32d1d5d0e4dacbd905fc;hpb=72a6abf751403bd91464e77ff2cece01c9756a6b;p=goodguy%2Fhistory.git diff --git a/cinelerra-5.1/cinelerra/colorpicker.C b/cinelerra-5.1/cinelerra/colorpicker.C index 969e8c98..1b40fcf0 100644 --- a/cinelerra-5.1/cinelerra/colorpicker.C +++ b/cinelerra-5.1/cinelerra/colorpicker.C @@ -21,13 +21,15 @@ #include "bcbutton.h" #include "bccapture.h" +#include "bccolors.h" #include "bcdisplayinfo.h" #include "colorpicker.h" #include "condition.h" +#include "keys.h" #include "language.h" #include "mutex.h" #include "mwindow.h" -#include "cicolors.h" +#include "bccolors.h" #include "vframe.h" #include @@ -35,7 +37,7 @@ #define PALETTE_DATA "palette.dat" -ColorThread::ColorThread(int do_alpha, const char *title) +ColorPicker::ColorPicker(int do_alpha, const char *title) : BC_DialogThread() { this->title = title; @@ -45,17 +47,17 @@ ColorThread::ColorThread(int do_alpha, const char *title) this->alpha = 255; } -ColorThread::~ColorThread() +ColorPicker::~ColorPicker() { close_window(); } -void ColorThread::start_window(int output, int alpha, int do_okcancel) +void ColorPicker::start_window(int output, int alpha, int do_okcancel) { if( running() ) { ColorWindow *gui = (ColorWindow *)get_gui(); if( gui ) { - gui->lock_window("ColorThread::start_window"); + gui->lock_window("ColorPicker::start_window"); gui->raise_window(1); gui->unlock_window(); } @@ -67,7 +69,7 @@ void ColorThread::start_window(int output, int alpha, int do_okcancel) start(); } -BC_Window* ColorThread::new_gui() +BC_Window* ColorPicker::new_gui() { char window_title[BCTEXTLEN]; strcpy(window_title, _(PROGRAM_NAME ": ")); @@ -88,7 +90,7 @@ BC_Window* ColorThread::new_gui() return gui; } -void ColorThread::update_gui(int output, int alpha) +void ColorPicker::update_gui(int output, int alpha) { ColorWindow *gui = (ColorWindow *)get_gui(); if( !gui ) return; @@ -100,14 +102,14 @@ void ColorThread::update_gui(int output, int alpha) gui->unlock_window(); } -int ColorThread::handle_new_color(int output, int alpha) +int ColorPicker::handle_new_color(int output, int alpha) { - printf("ColorThread::handle_new_color undefined.\n"); + printf("ColorPicker::handle_new_color undefined.\n"); return 0; } -ColorWindow::ColorWindow(ColorThread *thread, int x, int y, int w, int h, const char *title) +ColorWindow::ColorWindow(ColorPicker *thread, int x, int y, int w, int h, const char *title) : BC_Window(title, x, y, w, h, w, h, 0, 0, 1) { this->thread = thread; @@ -134,6 +136,10 @@ ColorWindow::~ColorWindow() delete yuv_y; delete yuv_u; delete yuv_v; delete aph_a; + if( button_grabbed ) { + ungrab_buttons(); + ungrab_cursor(); + } update_history(rgb888()); save_history(); } @@ -166,17 +172,17 @@ void ColorWindow::create_objects() add_tool(history = new PaletteHistory(this, 10, y)); x += 240; - add_tool(new BC_Title(x, y =y0, _("H:"), SMALLFONT)); - add_tool(new BC_Title(x, y+=25, _("S:"), SMALLFONT)); - add_tool(new BC_Title(x, y+=25, _("V:"), SMALLFONT)); - add_tool(new BC_Title(x, y+=40, _("R:"), SMALLFONT)); - add_tool(new BC_Title(x, y+=25, _("G:"), SMALLFONT)); - add_tool(new BC_Title(x, y+=25, _("B:"), SMALLFONT)); - add_tool(new BC_Title(x, y+=40, _("Y:"), SMALLFONT)); - add_tool(new BC_Title(x, y+=25, _("U:"), SMALLFONT)); - add_tool(new BC_Title(x, y+=25, _("V:"), SMALLFONT)); + add_tool(new BC_Title(x, y =y0, C_("H:"), SMALLFONT)); + add_tool(new BC_Title(x, y+=25, C_("S:"), SMALLFONT)); + add_tool(new BC_Title(x, y+=25, D_("colorpicker_value#V:"), SMALLFONT)); + add_tool(new BC_Title(x, y+=40, C_("R:"), SMALLFONT)); + add_tool(new BC_Title(x, y+=25, C_("G:"), SMALLFONT)); + add_tool(new BC_Title(x, y+=25, C_("B:"), SMALLFONT)); + add_tool(new BC_Title(x, y+=40, C_("Y:"), SMALLFONT)); + add_tool(new BC_Title(x, y+=25, C_("U:"), SMALLFONT)); + add_tool(new BC_Title(x, y+=25, D_("colorpicker_Cr#V:"), SMALLFONT)); if( thread->do_alpha ) - add_tool(new BC_Title(x, y+=40, _("A:"), SMALLFONT)); + add_tool(new BC_Title(x, y+=40, C_("A:"), SMALLFONT)); x += 24; add_tool(hue = new PaletteHue(this, x, y= y0)); add_tool(sat = new PaletteSat(this, x, y+=25)); @@ -206,9 +212,9 @@ void ColorWindow::create_objects() yuv_y = new PaletteYUV(this, x,y+=40, yuv.y, 0, 1); yuv_y->create_objects(); yuv_y->set_tooltip(_("Luminance")); yuv_u = new PaletteYUV(this, x,y+=25, yuv.u, 0, 1); - yuv_u->create_objects(); yuv_u->set_tooltip(_("Compliment Red")); + yuv_u->create_objects(); yuv_u->set_tooltip(_("Blue Luminance Difference")); yuv_v = new PaletteYUV(this, x,y+=25, yuv.v, 0, 1); - yuv_v->create_objects(); yuv_v->set_tooltip(_("Compliment Blue")); + yuv_v->create_objects(); yuv_v->set_tooltip(_("Red Luminance Difference")); if( thread->do_alpha ) { aph_a = new PaletteAPH(this, x,y+=40, aph, 0, 1); aph_a->create_objects(); aph_a->set_tooltip(_("Alpha")); @@ -304,35 +310,61 @@ int ColorWindow::handle_event() return 1; } +void ColorWindow::get_screen_sample() +{ + int cx, cy; + get_abs_cursor(cx, cy); + BC_Capture capture_bitmap(1, 1, 0); + VFrame vframe(1,1,BC_RGB888); + capture_bitmap.capture_frame(&vframe, cx,cy); + unsigned char *data = vframe.get_data(); + rgb.r = data[0]/255.; rgb.g = data[1]/255.; rgb.b = data[2]/255.; + update_rgb(); +} + +int ColorWindow::cursor_motion_event() +{ + if( button_grabbed && get_button_down() ) { + get_screen_sample(); + return 1; + } + return 0; +} + int ColorWindow::button_press_event() { if( button_grabbed ) { - grab_cursor(); + get_screen_sample(); + return 1; } return 0; } + int ColorWindow::button_release_event() { if( button_grabbed ) { - grab_btn->disable(); - grab_btn->enable(); ungrab_buttons(); ungrab_cursor(); + grab_btn->enable(); button_grabbed = 0; - int cx, cy; - get_abs_cursor_xy(cx, cy); -//printf("grabbed button %d,%d\n",cx,cy); - BC_Capture capture_bitmap(1, 1, 0); - VFrame vframe(1,1,BC_RGB888); - capture_bitmap.capture_frame(&vframe, cx,cy); - unsigned char *data = vframe.get_data(); - rgb.r = data[0]/255.; rgb.g = data[1]/255.; rgb.b = data[2]/255.; - update_rgb(); - update_display(); update_history(); return handle_event(); } - return 0; + return 1; +} + +void ColorWindow::update_rgb_hex(const char *hex) +{ + int color; + if( sscanf(hex,"%x",&color) == 1 ) { + float r = ((color>>16) & 0xff) / 255.; + float g = ((color>>8) & 0xff) / 255.; + float b = ((color>>0) & 0xff) / 255.; + rgb.r = r; rgb.g = g; rgb.b = b; + update_rgb(); + update_history(); + handle_event(); + } } @@ -372,8 +404,8 @@ int PaletteWheel::cursor_motion_event() distance = (int)sqrt(x1 * x1 + y1 * y1); float s = (float)distance / (get_w() / 2); bclamp(s, 0, 1); window->hsv.s = s; + window->hsv.v = 1; window->update_hsv(); - window->update_display(); window->handle_event(); return 1; } @@ -546,7 +578,7 @@ PaletteWheelValue::~PaletteWheelValue() void PaletteWheelValue::create_objects() { - frame = new VFrame(0, -1, get_w(), get_h(), BC_RGB888, -1); + frame = new VFrame(get_w(), get_h(), BC_RGB888); draw(window->hsv.h, window->hsv.s, window->hsv.v); flash(); } @@ -572,7 +604,6 @@ int PaletteWheelValue::cursor_motion_event() float v = 1.0 - (float)(get_cursor_y() - 2) / (get_h() - 4); bclamp(v, 0, 1); window->hsv.v = v; window->update_hsv(); - window->update_display(); window->handle_event(); return 1; } @@ -602,9 +633,9 @@ int PaletteWheelValue::draw(float hue, float saturation, float value) g = (int)(g_f * 255); b = (int)(b_f * 255); for( j = 0; j < get_w(); j++ ) { - row[j * 3] = r; - row[j * 3 + 1] = g; - row[j * 3 + 2] = b; + row[j * 3] = r; + row[j * 3 + 1] = g; + row[j * 3 + 2] = b; } } @@ -831,7 +862,7 @@ int PaletteCb::handle_event() void ColorWindow::update_rgb(float r, float g, float b) { { float y, u, v; - YUV::rgb_to_yuv_f(r, g, b, y, u, v); + YUV::yuv.rgb_to_yuv_f(r, g, b, y, u, v); u += 0.5; v += 0.5; bclamp(y, 0, 1); yuv.y = y; bclamp(u, 0, 1); yuv.u = u; @@ -847,7 +878,7 @@ void ColorWindow::update_yuv(float y, float u, float v) { u -= 0.5; v -= 0.5; { float r, g, b; - YUV::yuv_to_rgb_f(r, g, b, y, u, v); + YUV::yuv.yuv_to_rgb_f(r, g, b, y, u, v); bclamp(r, 0, 1); rgb.r = r; bclamp(g, 0, 1); rgb.g = g; bclamp(b, 0, 1); rgb.b = b; @@ -866,7 +897,7 @@ void ColorWindow::update_hsv(float h, float s, float v) bclamp(g, 0, 1); rgb.g = g; bclamp(b, 0, 1); rgb.b = b; float y, u, v; - YUV::rgb_to_yuv_f(r, g, b, y, u, v); + YUV::yuv.rgb_to_yuv_f(r, g, b, y, u, v); u += 0.5; v += 0.5; bclamp(y, 0, 1); yuv.y = y; bclamp(u, 0, 1); yuv.u = u; @@ -880,7 +911,7 @@ void ColorWindow::load_history() FILE *fp = fopen(history_path,"r"); int i=0; if( fp ) { - while( i < PALLETTE_HISTORY_SIZE ) { + while( i < PALLETTE_HISTORY_SIZE ) { char line[BCSTRLEN]; if( !fgets(line,sizeof(line)-1,fp) ) break; line[sizeof(line)-1] = 0; @@ -956,7 +987,6 @@ int PaletteHSV::handle_event() { update_output(); window->update_hsv(); - window->update_display(); window->handle_event(); return 1; } @@ -965,7 +995,6 @@ int PaletteRGB::handle_event() { update_output(); window->update_rgb(); - window->update_display(); window->handle_event(); return 1; } @@ -974,7 +1003,6 @@ int PaletteYUV::handle_event() { update_output(); window->update_yuv(); - window->update_display(); window->handle_event(); return 1; } @@ -999,17 +1027,7 @@ PaletteHexButton::~PaletteHexButton() int PaletteHexButton::handle_event() { const char *hex = window->hex_box->get_text(); - int color; - if( sscanf(hex,"%x",&color) == 1 ) { - float r = ((color>>16) & 0xff) / 255.; - float g = ((color>>8) & 0xff) / 255.; - float b = ((color>>0) & 0xff) / 255.; - window->rgb.r = r; window->rgb.g = g; window->rgb.b = b; - window->update_rgb(); - window->update_display(); - window->update_history(); - window->handle_event(); - } + window->update_rgb_hex(hex); return 1; } @@ -1027,8 +1045,11 @@ void PaletteHex::update() BC_TextBox::update(hex); } -int PaletteHex::handle_event() +int PaletteHex::keypress_event() { + if( get_keypress() != RETURN ) + return BC_TextBox::keypress_event(); + window->update_rgb_hex(get_text()); return 1; } @@ -1047,12 +1068,13 @@ PaletteGrabButton::PaletteGrabButton(ColorWindow *window, int x, int y) } PaletteGrabButton::~PaletteGrabButton() { - for( int i=0; i<3; ++i ) - delete vframes[i]; + for( int i=0; i<3; ++i ) + delete vframes[i]; } int PaletteGrabButton::handle_event() { if( window->grab_buttons() ) { + grab_cursor(); window->button_grabbed = 1; button_press_event(); // redraw face HI } @@ -1112,20 +1134,13 @@ int PaletteHistory::cursor_motion_event() if( window->rgb.r != r || window->rgb.g != g || window->rgb.b != b ) { window->rgb.r = r; window->rgb.g = g; window->rgb.b = b; window->update_rgb(); - window->update_display(); } return 1; } -int PaletteHistory::cursor_enter_event() -{ - set_tooltip_done(0); - return 0; -} int PaletteHistory::cursor_leave_event() { hide_tooltip(); - set_tooltip_done(0); return 0; } int PaletteHistory::repeat_event(int64_t duration) @@ -1135,7 +1150,6 @@ int PaletteHistory::repeat_event(int64_t duration) if( duration == get_resources()->tooltip_delay && get_tooltip() && *get_tooltip() && cursor_above() ) { show_tooltip(); - set_tooltip_done(1); result = 1; } return result;