From: Good Guy Date: Tue, 28 Feb 2017 02:41:58 +0000 (-0700) Subject: colorpick rework, color popup for titler, color convert fixes X-Git-Url: https://cinelerra-gg.org/git/?a=commitdiff_plain;h=624f99bd6dccb2af28fdbef8fbb3ae41c19fcbd2;p=goodguy%2Fhistory.git colorpick rework, color popup for titler, color convert fixes --- diff --git a/cinelerra-5.1/cinelerra/cicolors.C b/cinelerra-5.1/cinelerra/cicolors.C index 8b99fb5c..2dba6f87 100644 --- a/cinelerra-5.1/cinelerra/cicolors.C +++ b/cinelerra-5.1/cinelerra/cicolors.C @@ -47,8 +47,8 @@ int HSV::rgb_to_hsv(float r, float g, float b, float &h, float &s, float &v) 4 + (r - g) / delta; // between magenta & cyan if( (h*=60) < 0 ) h += 360; // degrees } - else { // r = g = b = 0 - h = -1; s = 0; v = 0; // s = 0, v is undefined + else { // r = g = b + h = 0; s = 0; v = max; } return 0; diff --git a/cinelerra-5.1/cinelerra/colorpicker.C b/cinelerra-5.1/cinelerra/colorpicker.C index 53536940..dce319e9 100644 --- a/cinelerra-5.1/cinelerra/colorpicker.C +++ b/cinelerra-5.1/cinelerra/colorpicker.C @@ -38,6 +38,8 @@ ColorThread::ColorThread(int do_alpha, const char *title) this->title = title; this->do_alpha = do_alpha; this->do_okcancel = 0; + this->output = BLACK; + this->alpha = 255; } ColorThread::~ColorThread() @@ -70,9 +72,11 @@ BC_Window* ColorThread::new_gui() BC_DisplayInfo display_info; int x = display_info.get_abs_cursor_x() + 25; int y = display_info.get_abs_cursor_y() - 100; - int w = 410, h = 320; + int w = 540, h = 290; + if( do_alpha ) + h += 40 + PalletteAPH::calculate_h(); if( do_okcancel ) - h += 10 + MAX(BC_OKButton::calculate_h(),BC_CancelButton::calculate_h()); + h += bmax(BC_OKButton::calculate_h(),BC_CancelButton::calculate_h()); int root_w = display_info.get_root_w(), root_h = display_info.get_root_h(); if( x+w > root_w ) x = root_w - w; if( y+h > root_h ) y = root_h - h; @@ -106,6 +110,26 @@ ColorWindow::ColorWindow(ColorThread *thread, int x, int y, int w, int h, const : BC_Window(title, x, y, w, h, w, h, 0, 0, 1) { this->thread = thread; + wheel = 0; + wheel_value = 0; + output = 0; + + hue = 0; sat = 0; val = 0; + red = 0; grn = 0; blu = 0; + lum = 0; c_r = 0; c_b = 0; + alpha = 0; + + hsv_h = 0; hsv_s = 0; hsv_v = 0; + rgb_r = 0; rgb_g = 0; rgb_b = 0; + yuv_y = 0; yuv_u = 0; yuv_v = 0; + aph_a = 0; +} +ColorWindow::~ColorWindow() +{ + delete hsv_h; delete hsv_s; delete hsv_v; + delete rgb_r; delete rgb_g; delete rgb_b; + delete yuv_y; delete yuv_u; delete yuv_v; + delete aph_a; } void ColorWindow::create_objects() @@ -123,29 +147,51 @@ void ColorWindow::create_objects() x = x0; y += 180; add_tool(output = new PaletteOutput(this, x, y)); output->create_objects(); + y += output->get_h() + 20; x += 240; - y = y0; add_tool(new BC_Title(x, y, _("Hue"), SMALLFONT)); - y += 15; add_tool(hue = new PaletteHue(this, x, y)); - y += 30; add_tool(new BC_Title(x, y, _("Saturation"), SMALLFONT)); - y += 15; add_tool(saturation = new PaletteSaturation(this, x, y)); - y += 30; add_tool(new BC_Title(x, y, _("Value"), SMALLFONT)); - y += 15; add_tool(value = new PaletteValue(this, x, y)); - y += 30; add_tool(new BC_Title(x, y, _("Red"), SMALLFONT)); - y += 15; add_tool(red = new PaletteRed(this, x, y)); - y += 30; add_tool(new BC_Title(x, y, _("Green"), SMALLFONT)); - y += 15; add_tool(green = new PaletteGreen(this, x, y)); - y += 30; add_tool(new BC_Title(x, y, _("Blue"), SMALLFONT)); - y += 15; add_tool(blue = new PaletteBlue(this, x, y)); - - if(thread->do_alpha) { - y += 30; add_tool(new BC_Title(x, y, _("Alpha"), SMALLFONT)); - y += 15; add_tool(alpha = new PaletteAlpha(this, x, y)); + 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)); + if( thread->do_alpha ) + add_tool(new BC_Title(x, y+=40, _("A:"), SMALLFONT)); + x += 24; + add_tool(hue = new PaletteHue(this, x, y= y0)); + add_tool(sat = new PaletteSat(this, x, y+=25)); + add_tool(val = new PaletteVal(this, x, y+=25)); + add_tool(red = new PaletteRed(this, x, y+=40)); + add_tool(grn = new PaletteGrn(this, x, y+=25)); + add_tool(blu = new PaletteBlu(this, x, y+=25)); + add_tool(lum = new PaletteLum(this, x, y+=40)); + add_tool(c_r = new PaletteCr (this, x, y+=25)); + add_tool(c_b = new PaletteCb (this, x, y+=25)); + if( thread->do_alpha ) + add_tool(alpha = new PaletteAlpha(this, x, y+=40)); + + x += hue->get_w() + 10; + hsv_h = new PalletteHSV(this, x,y= y0, hsv.h, 0, 360); hsv_h->create_objects(); + hsv_s = new PalletteHSV(this, x,y+=25, hsv.s, 0, 1); hsv_s->create_objects(); + hsv_v = new PalletteHSV(this, x,y+=25, hsv.v, 0, 1); hsv_v->create_objects(); + rgb_r = new PalletteRGB(this, x,y+=40, rgb.r, 0, 1); rgb_r->create_objects(); + rgb_g = new PalletteRGB(this, x,y+=25, rgb.g, 0, 1); rgb_g->create_objects(); + rgb_b = new PalletteRGB(this, x,y+=25, rgb.b, 0, 1); rgb_b->create_objects(); + yuv_y = new PalletteYUV(this, x,y+=40, yuv.y, 0, 1); yuv_y->create_objects(); + yuv_u = new PalletteYUV(this, x,y+=25, yuv.u, 0, 1); yuv_u->create_objects(); + yuv_v = new PalletteYUV(this, x,y+=25, yuv.v, 0, 1); yuv_v->create_objects(); + if( thread->do_alpha ) { + aph_a = new PalletteAPH(this, x,y+=40, aph, 0, 1); aph_a->create_objects(); } if( thread->do_okcancel ) { add_tool(new BC_OKButton(this)); add_tool(new BC_CancelButton(this)); } + update_display(); show_window(1); unlock_window(); @@ -154,11 +200,12 @@ void ColorWindow::create_objects() void ColorWindow::change_values() { - r = (float)((thread->output & 0xff0000) >> 16) / 255; - g = (float)((thread->output & 0xff00) >> 8) / 255; - b = (float)((thread->output & 0xff)) / 255; - HSV::rgb_to_hsv(r, g, b, h, s, v); - a = (float)thread->alpha / 255; + float r = ((thread->output & 0xff0000) >> 16) / 255.; + float g = ((thread->output & 0xff00) >> 8) / 255.; + float b = ((thread->output & 0xff)) / 255.; + rgb.r = r; rgb.g = g; rgb.b = b; + aph = (float)thread->alpha / 255; + update_rgb(rgb.r, rgb.g, rgb.b); } @@ -171,55 +218,62 @@ int ColorWindow::close_event() void ColorWindow::update_rgb() { - float r = red->get_value(); - float g = green->get_value(); - float b = blue->get_value(); - HSV::rgb_to_hsv(r, g, b, h, s, v); + update_rgb(rgb.r, rgb.g, rgb.b); + update_display(); +} +void ColorWindow::update_hsv() +{ + update_hsv(hsv.h, hsv.s, hsv.v); + update_display(); +} +void ColorWindow::update_yuv() +{ + update_yuv(yuv.y, yuv.u, yuv.v); update_display(); } void ColorWindow::update_display() { - float r, g, b; - if(h < 0) h = 0; - if(h > 360) h = 360; - if(s < 0) s = 0; - if(s > 1) s = 1; - if(v < 0) v = 0; - if(v > 1) v = 1; - if(a < 0) a = 0; - if(a > 1) a = 1; - - wheel->draw(wheel->oldhue, - wheel->oldsaturation); - wheel->oldhue = h; - wheel->oldsaturation = s; - wheel->draw(h, s); + wheel->draw(wheel->oldhue, wheel->oldsaturation); + wheel->oldhue = hsv.h; + wheel->oldsaturation = hsv.s; + wheel->draw(hsv.h, hsv.s); wheel->flash(); - wheel_value->draw(h, s, v); + wheel_value->draw(hsv.h, hsv.s, hsv.v); wheel_value->flash(); output->draw(); output->flash(); - hue->update((int)h); - saturation->update(s); - value->update(v); - - HSV::hsv_to_rgb(r, g, b, h, s, v); - red->update(r); - green->update(g); - blue->update(b); - if(thread->do_alpha) - { - alpha->update(a); - } + + hue->update((int)hsv.h); + sat->update(hsv.s); + val->update(hsv.v); + + red->update(rgb.r); + grn->update(rgb.g); + blu->update(rgb.b); + + lum->update(yuv.y); + c_r->update(yuv.u); + c_b->update(yuv.v); + + hsv_h->update(hsv.h); + hsv_s->update(hsv.s); + hsv_v->update(hsv.v); + rgb_r->update(rgb.r); + rgb_g->update(rgb.g); + rgb_b->update(rgb.b); + yuv_y->update(yuv.y); + yuv_u->update(yuv.u); + yuv_v->update(yuv.v); + if( thread->do_alpha ) + aph_a->update(aph); } int ColorWindow::handle_event() { - float r, g, b; - HSV::hsv_to_rgb(r, g, b, h, s, v); - int result = (((int)(r * 255)) << 16) | (((int)(g * 255)) << 8) | ((int)(b * 255)); - thread->handle_new_color(result, (int)(a * 255)); + int r = 255*rgb.r + 0.5, g = 255*rgb.g + 0.5, b = 255*rgb.b + 0.5; + int result = (r << 16) | (g << 8) | (b << 0); + thread->handle_new_color(result, (int)(255*aph + 0.5)); return 1; } @@ -255,7 +309,7 @@ int PaletteWheel::cursor_motion_event() int x1, y1, distance; if(button_down && is_event_win()) { - window->h = get_angle(get_w() / 2, + window->hsv.h = get_angle(get_w() / 2, get_h() / 2, get_cursor_x(), get_cursor_y()); @@ -263,7 +317,8 @@ int PaletteWheel::cursor_motion_event() y1 = get_h() / 2 - get_cursor_y(); distance = (int)sqrt(x1 * x1 + y1 * y1); if(distance > get_w() / 2) distance = get_w() / 2; - window->s = (float)distance / (get_w() / 2); + window->hsv.s = (float)distance / (get_w() / 2); + window->update_hsv(); window->update_display(); window->handle_event(); return 1; @@ -365,8 +420,8 @@ void PaletteWheel::create_objects() 0); //printf("PaletteWheel::create_objects 1\n"); - oldhue = window->h; - oldsaturation = window->s; + oldhue = window->hsv.h; + oldsaturation = window->hsv.s; //printf("PaletteWheel::create_objects 1\n"); draw(oldhue, oldsaturation); //printf("PaletteWheel::create_objects 1\n"); @@ -463,7 +518,7 @@ PaletteWheelValue::~PaletteWheelValue() void PaletteWheelValue::create_objects() { frame = new VFrame(0, -1, get_w(), get_h(), BC_RGB888, -1); - draw(window->h, window->s, window->v); + draw(window->hsv.h, window->hsv.s, window->hsv.v); flash(); } @@ -487,7 +542,8 @@ int PaletteWheelValue::cursor_motion_event() if(button_down && is_event_win()) { //printf("PaletteWheelValue::cursor_motion 1\n"); - window->v = 1.0 - (float)(get_cursor_y() - 2) / (get_h() - 4); + window->hsv.v = 1.0 - (float)(get_cursor_y() - 2) / (get_h() - 4); + window->update_hsv(); window->update_display(); window->handle_event(); return 1; @@ -561,17 +617,17 @@ int PaletteOutput::handle_event() int PaletteOutput::draw() { - float r_f, g_f, b_f; - - HSV::hsv_to_rgb(r_f, g_f, b_f, window->h, window->s, window->v); - set_color(((int)(r_f * 255) << 16) | ((int)(g_f * 255) << 8) | ((int)(b_f * 255))); + int r = 255*window->rgb.r + 0.5f; + int g = 255*window->rgb.g + 0.5f; + int b = 255*window->rgb.b + 0.5f; + set_color((r << 16) | (g << 8) | (b << 0)); draw_box(2, 2, get_w() - 4, get_h() - 4); draw_3d_border(0, 0, get_w(), get_h(), 1); return 0; } PaletteHue::PaletteHue(ColorWindow *window, int x, int y) - : BC_ISlider(x, y, 0, 150, 200, 0, 359, (int)(window->h), 0) + : BC_ISlider(x, y, 0, 150, 200, 0, 359, (int)(window->hsv.h), 0) { this->window = window; } @@ -581,54 +637,52 @@ PaletteHue::~PaletteHue() int PaletteHue::handle_event() { - window->h = get_value(); - window->update_display(); + window->hsv.h = get_value(); + window->update_hsv(); window->handle_event(); return 1; } -PaletteSaturation::PaletteSaturation(ColorWindow *window, int x, int y) - : BC_FSlider(x, y, 0, 150, 200, 0, 1.0, window->s, 0) +PaletteSat::PaletteSat(ColorWindow *window, int x, int y) + : BC_FSlider(x, y, 0, 150, 200, 0, 1.0, window->hsv.s, 0) { this->window = window; set_precision(0.01); } -PaletteSaturation::~PaletteSaturation() +PaletteSat::~PaletteSat() { } -int PaletteSaturation::handle_event() +int PaletteSat::handle_event() { -//printf("PaletteSaturation::handle_event 1 %f\n", get_value()); - window->s = get_value(); - window->update_display(); -//printf("PaletteSaturation::handle_event 2 %f\n", get_value()); + window->hsv.s = get_value(); + window->update_hsv(); window->handle_event(); return 1; } -PaletteValue::PaletteValue(ColorWindow *window, int x, int y) - : BC_FSlider(x, y, 0, 150, 200, 0, 1.0, window->v, 0) +PaletteVal::PaletteVal(ColorWindow *window, int x, int y) + : BC_FSlider(x, y, 0, 150, 200, 0, 1.0, window->hsv.v, 0) { this->window = window; set_precision(0.01); } -PaletteValue::~PaletteValue() +PaletteVal::~PaletteVal() { } -int PaletteValue::handle_event() +int PaletteVal::handle_event() { - window->v = get_value(); - window->update_display(); + window->hsv.v = get_value(); + window->update_hsv(); window->handle_event(); return 1; } PaletteRed::PaletteRed(ColorWindow *window, int x, int y) - : BC_FSlider(x, y, 0, 150, 200, 0, 1, window->r, 0) + : BC_FSlider(x, y, 0, 150, 200, 0, 1, window->rgb.r, 0) { this->window = window; set_precision(0.01); @@ -639,47 +693,50 @@ PaletteRed::~PaletteRed() int PaletteRed::handle_event() { + window->rgb.r = get_value(); window->update_rgb(); window->handle_event(); return 1; } -PaletteGreen::PaletteGreen(ColorWindow *window, int x, int y) - : BC_FSlider(x, y, 0, 150, 200, 0, 1, window->g, 0) +PaletteGrn::PaletteGrn(ColorWindow *window, int x, int y) + : BC_FSlider(x, y, 0, 150, 200, 0, 1, window->rgb.g, 0) { this->window = window; set_precision(0.01); } -PaletteGreen::~PaletteGreen() +PaletteGrn::~PaletteGrn() { } -int PaletteGreen::handle_event() +int PaletteGrn::handle_event() { + window->rgb.g = get_value(); window->update_rgb(); window->handle_event(); return 1; } -PaletteBlue::PaletteBlue(ColorWindow *window, int x, int y) - : BC_FSlider(x, y, 0, 150, 200, 0, 1, window->b, 0) +PaletteBlu::PaletteBlu(ColorWindow *window, int x, int y) + : BC_FSlider(x, y, 0, 150, 200, 0, 1, window->rgb.b, 0) { this->window = window; set_precision(0.01); } -PaletteBlue::~PaletteBlue() +PaletteBlu::~PaletteBlu() { } -int PaletteBlue::handle_event() +int PaletteBlu::handle_event() { + window->rgb.b = get_value(); window->update_rgb(); window->handle_event(); return 1; } PaletteAlpha::PaletteAlpha(ColorWindow *window, int x, int y) - : BC_FSlider(x, y, 0, 150, 200, 0, 1, window->a, 0) + : BC_FSlider(x, y, 0, 150, 200, 0, 1, window->aph, 0) { this->window = window; set_precision(0.01); @@ -690,9 +747,156 @@ PaletteAlpha::~PaletteAlpha() int PaletteAlpha::handle_event() { - window->a = get_value(); + window->aph = get_value(); window->handle_event(); return 1; } +PaletteLum::PaletteLum(ColorWindow *window, int x, int y) + : BC_FSlider(x, y, 0, 150, 200, 0, 1, window->yuv.y, 0) +{ + this->window = window; + set_precision(0.01); +} +PaletteLum::~PaletteLum() +{ +} + +int PaletteLum::handle_event() +{ + window->yuv.y = get_value(); + window->update_yuv(); + window->handle_event(); + return 1; +} + +PaletteCr::PaletteCr(ColorWindow *window, int x, int y) + : BC_FSlider(x, y, 0, 150, 200, 0, 1, window->yuv.u, 0) +{ + this->window = window; + set_precision(0.01); +} +PaletteCr::~PaletteCr() +{ +} + +int PaletteCr::handle_event() +{ + window->yuv.u = get_value(); + window->update_yuv(); + window->handle_event(); + return 1; +} + +PaletteCb::PaletteCb(ColorWindow *window, int x, int y) + : BC_FSlider(x, y, 0, 150, 200, 0, 1, window->yuv.v, 0) +{ + this->window = window; + set_precision(0.01); +} +PaletteCb::~PaletteCb() +{ +} + +int PaletteCb::handle_event() +{ + window->yuv.v = get_value(); + window->update_yuv(); + window->handle_event(); + return 1; +} + +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); + u += 0.5f; v += 0.5f; + bclamp(y, 0, 1); yuv.y = y; + bclamp(u, 0, 1); yuv.u = u; + bclamp(v, 0, 1); yuv.v = v; } + { float h, s, v; + HSV::rgb_to_hsv(r,g,b, h,s,v); + bclamp(h, 0, 360); hsv.h = h; + bclamp(s, 0, 1); hsv.s = s; + bclamp(v, 0, 1); hsv.v = v; } +} + +void ColorWindow::update_yuv(float y, float u, float v) +{ + u -= 0.5f; v -= 0.5f; + { float r, g, b; + 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; + float h, s, v; + HSV::rgb_to_hsv(r,g,b, h, s, v); + bclamp(h, 0, 360); hsv.h = h; + bclamp(s, 0, 1); hsv.s = s; + bclamp(v, 0, 1); hsv.v = v; } +} + +void ColorWindow::update_hsv(float h, float s, float v) +{ + { float r, g, b; + HSV::hsv_to_rgb(r,g,b, h,s,v); + bclamp(r, 0, 1); rgb.r = r; + 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); + u += 0.5f; v += 0.5f; + bclamp(y, 0, 1); yuv.y = y; + bclamp(u, 0, 1); yuv.u = u; + bclamp(v, 0, 1); yuv.v = v; } +} + +PalletteNum::PalletteNum(ColorWindow *window, int x, int y, + float &output, float min, float max) + : BC_TumbleTextBox(window, output, min, max, x, y, 64) +{ + this->window = window; + this->output = &output; + set_increment(0.01); +} + +PalletteNum::~PalletteNum() +{ +} + + +int PalletteHSV::handle_event() +{ + update_output(); + window->update_hsv(); + window->update_display(); + window->handle_event(); + return 1; +} + +int PalletteRGB::handle_event() +{ + update_output(); + window->update_rgb(); + window->update_display(); + window->handle_event(); + return 1; +} + +int PalletteYUV::handle_event() +{ + update_output(); + window->update_yuv(); + window->update_display(); + window->handle_event(); + return 1; +} + +int PalletteAPH::handle_event() +{ + update_output(); + window->update_display(); + window->handle_event(); + return 1; +} diff --git a/cinelerra-5.1/cinelerra/colorpicker.h b/cinelerra-5.1/cinelerra/colorpicker.h index 2d69a92d..383bd877 100644 --- a/cinelerra-5.1/cinelerra/colorpicker.h +++ b/cinelerra-5.1/cinelerra/colorpicker.h @@ -23,6 +23,7 @@ #define COLORPICKER_H #include "bcdialog.h" +#include "clip.h" #include "condition.inc" #include "guicast.h" #include "mutex.inc" @@ -34,12 +35,19 @@ class PaletteWheel; class PaletteWheelValue; class PaletteOutput; class PaletteHue; -class PaletteSaturation; -class PaletteValue; +class PaletteSat; +class PaletteVal; class PaletteRed; -class PaletteGreen; -class PaletteBlue; +class PaletteGrn; +class PaletteBlu; +class PaletteLum; +class PaletteCr; +class PaletteCb; class PaletteAlpha; +class PalletteHSV; +class PalletteRGB; +class PalletteYUV; +class PalletteAPH; class ColorThread : public BC_DialogThread { @@ -61,28 +69,47 @@ class ColorWindow : public BC_Window { public: ColorWindow(ColorThread *thread, int x, int y, int w, int h, const char *title); + ~ColorWindow(); void create_objects(); void change_values(); int close_event(); void update_display(); void update_rgb(); + void update_hsv(); + void update_yuv(); int handle_event(); + struct { float r, g, b; } rgb; + struct { float y, u, v; } yuv; + struct { float h, s, v; } hsv; + float aph; + void update_rgb(float r, float g, float b); + void update_hsv(float h, float s, float v); + void update_yuv(float y, float u, float v); + ColorThread *thread; PaletteWheel *wheel; PaletteWheelValue *wheel_value; PaletteOutput *output; PaletteHue *hue; - PaletteSaturation *saturation; - PaletteValue *value; + PaletteSat *sat; + PaletteVal *val; PaletteRed *red; - PaletteGreen *green; - PaletteBlue *blue; + PaletteGrn *grn; + PaletteBlu *blu; + PaletteLum *lum; + PaletteCr *c_r; + PaletteCb *c_b; PaletteAlpha *alpha; + + PalletteHSV *hsv_h, *hsv_s, *hsv_v; + PalletteRGB *rgb_r, *rgb_g, *rgb_b; + PalletteYUV *yuv_y, *yuv_u, *yuv_v; + PalletteAPH *aph_a; + VFrame *value_bitmap; - float h, s, v, r, g, b, a; }; @@ -141,20 +168,20 @@ public: ColorWindow *window; }; -class PaletteSaturation : public BC_FSlider +class PaletteSat : public BC_FSlider { public: - PaletteSaturation(ColorWindow *window, int x, int y); - ~PaletteSaturation(); + PaletteSat(ColorWindow *window, int x, int y); + ~PaletteSat(); int handle_event(); ColorWindow *window; }; -class PaletteValue : public BC_FSlider +class PaletteVal : public BC_FSlider { public: - PaletteValue(ColorWindow *window, int x, int y); - ~PaletteValue(); + PaletteVal(ColorWindow *window, int x, int y); + ~PaletteVal(); int handle_event(); ColorWindow *window; }; @@ -168,20 +195,20 @@ public: ColorWindow *window; }; -class PaletteGreen : public BC_FSlider +class PaletteGrn : public BC_FSlider { public: - PaletteGreen(ColorWindow *window, int x, int y); - ~PaletteGreen(); + PaletteGrn(ColorWindow *window, int x, int y); + ~PaletteGrn(); int handle_event(); ColorWindow *window; }; -class PaletteBlue : public BC_FSlider +class PaletteBlu : public BC_FSlider { public: - PaletteBlue(ColorWindow *window, int x, int y); - ~PaletteBlue(); + PaletteBlu(ColorWindow *window, int x, int y); + ~PaletteBlu(); int handle_event(); ColorWindow *window; }; @@ -195,4 +222,80 @@ public: ColorWindow *window; }; +class PaletteLum : public BC_FSlider +{ +public: + PaletteLum(ColorWindow *window, int x, int y); + ~PaletteLum(); + int handle_event(); + ColorWindow *window; +}; + +class PaletteCr : public BC_FSlider +{ +public: + PaletteCr(ColorWindow *window, int x, int y); + ~PaletteCr(); + int handle_event(); + ColorWindow *window; +}; + +class PaletteCb : public BC_FSlider +{ +public: + PaletteCb(ColorWindow *window, int x, int y); + ~PaletteCb(); + int handle_event(); + ColorWindow *window; +}; + +class PalletteNum : public BC_TumbleTextBox +{ +public: + ColorWindow *window; + float *output; + + PalletteNum(ColorWindow *window, int x, int y, + float &output, float min, float max); + ~PalletteNum(); + void update_output() { *output = atof(get_text()); } + static int calculate_h() { return BC_Tumbler::calculate_h(); } +}; + +class PalletteRGB : public PalletteNum +{ +public: + PalletteRGB(ColorWindow *window, int x, int y, + float &output, float min, float max) + : PalletteNum(window, x, y, output, min, max) {} + int handle_event(); +}; + +class PalletteYUV : public PalletteNum +{ +public: + PalletteYUV(ColorWindow *window, int x, int y, + float &output, float min, float max) + : PalletteNum(window, x, y, output, min, max) {} + int handle_event(); +}; + +class PalletteHSV : public PalletteNum +{ +public: + PalletteHSV(ColorWindow *window, int x, int y, + float &output, float min, float max) + : PalletteNum(window, x, y, output, min, max) {} + int handle_event(); +}; + +class PalletteAPH : public PalletteNum +{ +public: + PalletteAPH(ColorWindow *window, int x, int y, + float &output, float min, float max) + : PalletteNum(window, x, y, output, min, max) {} + int handle_event(); +}; + #endif diff --git a/cinelerra-5.1/guicast/bcwindowbase.C b/cinelerra-5.1/guicast/bcwindowbase.C index 791aa0c8..d7761f95 100644 --- a/cinelerra-5.1/guicast/bcwindowbase.C +++ b/cinelerra-5.1/guicast/bcwindowbase.C @@ -3543,13 +3543,21 @@ int BC_WindowBase::deactivate() { if(window_type == MAIN_WINDOW) { - if(top_level->active_menubar) top_level->active_menubar->deactivate(); - if(top_level->active_popup_menu) top_level->active_popup_menu->deactivate(); - if(top_level->active_subwindow) top_level->active_subwindow->deactivate(); + if( top_level->active_menubar ) { + top_level->active_menubar->deactivate(); + top_level->active_menubar = 0; + } + if( top_level->active_popup_menu ) { + top_level->active_popup_menu->deactivate(); + top_level->active_popup_menu = 0; + } + if( top_level->active_subwindow ) { + top_level->active_subwindow->deactivate(); + top_level->active_subwindow = 0; + } + if( top_level->motion_events && top_level->last_motion_win == this->win ) + top_level->motion_events = 0; - top_level->active_menubar = 0; - top_level->active_popup_menu = 0; - top_level->active_subwindow = 0; } return 0; } diff --git a/cinelerra-5.1/guicast/clip.h b/cinelerra-5.1/guicast/clip.h index 4246f2ec..00337442 100644 --- a/cinelerra-5.1/guicast/clip.h +++ b/cinelerra-5.1/guicast/clip.h @@ -43,38 +43,59 @@ #define TO_RAD(x) ((x) * 2 * M_PI / 360) #define TO_DEG(x) ((x) * 360 / 2 / M_PI) +static inline int bmin(int a, int b) { return a < b ? a : b; } +static inline float bmin(float a, float b) { return a < b ? a : b; } +static inline double bmin(double a, double b) { return a < b ? a : b; } +static inline int bmax(int a, int b) { return a > b ? a : b; } +static inline float bmax(float a, float b) { return a > b ? a : b; } +static inline double bmax(double a, double b) { return a > b ? a : b; } + static inline int bclip(int &iv, int imn, int imx) { - return iv < imn ? imn : iv > imx ? imx : iv; + return iv < imn ? imn : iv > imx ? imx : iv; } static inline float bclip(float &fv, float fmn, float fmx) { - return fv < fmn ? fmn : fv > fmx ? fmx : fv; + return fv < fmn ? fmn : fv > fmx ? fmx : fv; } static inline double bclip(double &dv, double dmn, double dmx) { - return dv < dmn ? dmn : dv > dmx ? dmx : dv; + return dv < dmn ? dmn : dv > dmx ? dmx : dv; } static inline void bclamp(int &iv, int imn, int imx) { - if( iv < imn ) iv = imn; else if( iv > imx ) iv = imx; + if( iv < imn ) iv = imn; else if( iv > imx ) iv = imx; } static inline void bclamp(float &fv, float fmn, float fmx) { - if( fv < fmn ) fv = fmn; else if( fv > fmx ) fv = fmx; + if( fv < fmn ) fv = fmn; else if( fv > fmx ) fv = fmx; } static inline void bclamp(double &dv, double dmn, double dmx) { - if( dv < dmn ) dv = dmn; else if( dv > dmx ) dv = dmx; + if( dv < dmn ) dv = dmn; else if( dv > dmx ) dv = dmx; +} +static inline void bc_rgb2yuv(float r, float g, float b, float &y, float &u, float &v) +{ //bt601, jpeg, unclipped + y = 0.29900*r + 0.58700*g + 0.11400*b; + u = -0.16874*r - 0.33126*g + 0.50000*b + 0.5; + v = 0.50000*r - 0.41869*g - 0.08131*b + 0.5; } static inline void bc_rgb2yuv(int r, int g, int b, int &y, int &u, int &v, int max=255) +{ // clipped + float mx = max, fr = r/mx, fg = g/mx, fb = b/mx, fy, fu, fv; + bc_rgb2yuv(fr,fg,fb, fy,fu,fv); + y = (int)(fy * mx + 0.5); bclamp(y,0,max); + u = (int)(fu * mx + 0.5); bclamp(u,0,max); + v = (int)(fv * mx + 0.5); bclamp(v,0,max); +} +static inline void bc_yuv2rgb(float y, float u, float v, float &r, float &g, float &b) { //bt601, jpeg, unclipped - double mx = max, rr = r/mx, gg = g/mx, bb = b/mx; - y = (int)(( 0.29900*rr + 0.58700*gg + 0.11400*bb) * mx + 0.5); - u = (int)((-0.16874*rr - 0.33126*gg + 0.50000*bb + 0.5) * mx + 0.5); - v = (int)(( 0.50000*rr - 0.41869*gg - 0.08131*bb + 0.5) * mx + 0.5); + r = y + 1.40200*v; + g = y - 0.34414*u - 0.71414*v; + b = y + 1.77200*u; } static inline void bc_yuv2rgb(int y, int u, int v, int &r, int &g, int &b, int max=255) -{ +{ // clipped int ofs = (max + 1) / 2; - double mx = max, yy = y/mx, uu = (u-ofs)/mx, vv = (v-ofs)/mx; - r = (int)((yy + 1.40200*vv) * mx + 0.5); - g = (int)((yy - 0.34414*uu - 0.71414*vv) * mx + 0.5); - b = (int)((yy + 1.77200*uu) * mx + 0.5); + float mx = max, fy = y/mx, fu = (u-ofs)/mx, fv = (v-ofs)/mx, fr, fg, fb; + bc_yuv2rgb(fy,fu,fv, fr,fg,fb); + r = (int)(fr * mx + 0.5); bclamp(r,0,max); + g = (int)(fg * mx + 0.5); bclamp(g,0,max); + b = (int)(fb * mx + 0.5); bclamp(b,0,max); } #endif diff --git a/cinelerra-5.1/guicast/vframe.C b/cinelerra-5.1/guicast/vframe.C index 0ae65a66..aadd6a72 100644 --- a/cinelerra-5.1/guicast/vframe.C +++ b/cinelerra-5.1/guicast/vframe.C @@ -1298,9 +1298,6 @@ void VFrame::set_pixel_color(int rgb) int ig = 0xff & (pixel_rgb >> 8); int ib = 0xff & (pixel_rgb >> 0); bc_rgb2yuv(ir,ig,ib, ir,ig,ib); - bclamp(ir,0,255); - bclamp(ig,0,255); - bclamp(ib,0,255); pixel_yuv = (ir<<16) | (ig<<8) | (ib<<0); } diff --git a/cinelerra-5.1/plugins/titler/titler.C b/cinelerra-5.1/plugins/titler/titler.C index e2642af3..ba9a5fce 100644 --- a/cinelerra-5.1/plugins/titler/titler.C +++ b/cinelerra-5.1/plugins/titler/titler.C @@ -523,10 +523,7 @@ TitleUnit::TitleUnit(TitleMain *plugin, TitleEngine *server) static void get_mask_colors(int rgb, int color_model, int &rr, int &gg, int &bb) { int r = 0xff & (rgb>>16), g = 0xff & (rgb>>8), b = 0xff & (rgb>>0); - if( BC_CModels::is_yuv(color_model) ) { - bc_rgb2yuv(r,g,b, r,g,b); - bclamp(r,0,255); bclamp(g,0,255); bclamp(b,0,255); - } + if( BC_CModels::is_yuv(color_model) ) bc_rgb2yuv(r,g,b, r,g,b); rr = r; gg = g; bb = b; } diff --git a/cinelerra-5.1/plugins/titler/titlerwindow.C b/cinelerra-5.1/plugins/titler/titlerwindow.C index 2c92d8f3..394d82de 100644 --- a/cinelerra-5.1/plugins/titler/titlerwindow.C +++ b/cinelerra-5.1/plugins/titler/titlerwindow.C @@ -382,6 +382,7 @@ void TitleWindow::create_objects() add_tool(cur_popup = new TitleCurPopup(client, this)); cur_popup->create_objects(); add_tool(fonts_popup = new TitleFontsPopup(client, this)); + color_popup = new TitleColorPopup(client, this); show_window(1); update(); @@ -1221,7 +1222,7 @@ int TitleBottom::handle_event() TitleColorThread::TitleColorThread(TitleMain *client, TitleWindow *window, int is_outline) - : ColorThread(1) + : ColorThread(1, _("Text Color")) { this->client = client; this->window = window; @@ -1329,6 +1330,7 @@ void TitleCurPopup::create_objects() add_item(cur_item = new TitleCurItem(this, _("color"))); cur_item->add_submenu(sub_menu = new TitleCurSubMenu(cur_item)); sub_menu->add_submenuitem(new TitleCurSubMenuItem(sub_menu,_("color #"))); + sub_menu->add_submenuitem(new TitleCurSubMenuItem(sub_menu,_("color "))); sub_menu->add_submenuitem(new TitleCurSubMenuItem(sub_menu,_("/color"))); add_item(cur_item = new TitleCurItem(this, _("alpha"))); cur_item->add_submenu(sub_menu = new TitleCurSubMenu(cur_item)); @@ -1340,6 +1342,7 @@ void TitleCurPopup::create_objects() add_item(cur_item = new TitleCurItem(this, _("font"))); cur_item->add_submenu(sub_menu = new TitleCurSubMenu(cur_item)); sub_menu->add_submenuitem(new TitleCurSubMenuItem(sub_menu,_("font name"))); + sub_menu->add_submenuitem(new TitleCurSubMenuItem(sub_menu,_("font "))); sub_menu->add_submenuitem(new TitleCurSubMenuItem(sub_menu,_("/font"))); add_item(cur_item = new TitleCurItem(this, _("size"))); cur_item->add_submenu(sub_menu = new TitleCurSubMenu(cur_item)); @@ -1424,13 +1427,14 @@ int TitleCurSubMenuItem::handle_event() TitleCurPopup *popup = submenu->cur_item->popup; TitleWindow *window = popup->window; const char *item_text = get_text(); - if( !strcmp(item_text, _("font")) ) { - int w = 300, h = 200; - int x = window->get_abs_cursor_x(0) - w + 10; - int y = window->get_abs_cursor_y(0) - 20; - if( x < 2 ) x = 2; - if( y < 2 ) y = 2; - window->fonts_popup->activate(x, y, w,h); + if( !strcmp(item_text, _("font name")) ) { + int px, py; + window->get_pop_cursor_xy(px ,py); + window->fonts_popup->activate(px, py, 300,200); + return 1; + } + if( !strcmp(item_text, _("color #")) ) { + window->color_popup->activate(); return 1; } char txt[BCSTRLEN]; @@ -1458,10 +1462,34 @@ int TitleFontsPopup::handle_event() BC_ListBoxItem *item = get_selection(0, 0); if( !item ) return 1; const char *item_text = item->get_text(); - char txt[BCTEXTLEN]; - sprintf(txt, "",item_text); - int adv = strlen(txt); - int ret = window->insert_ibeam(txt, adv); - return ret; + char txt[BCTEXTLEN]; sprintf(txt, "",item_text); + return window->insert_ibeam(txt, strlen(txt)); +} + +TitleColorPopup::TitleColorPopup(TitleMain *client, TitleWindow *window) + : ColorThread(0, _("Text Color")) +{ + this->client = client; + this->window = window; + this->color_value = client->config.color; +} +TitleColorPopup::~TitleColorPopup() +{ +} +int TitleColorPopup::handle_new_color(int output, int alpha) +{ + color_value = output; + return 1; +} +int TitleColorPopup::activate() +{ + start_window(client->config.color, 255, 1); + return 1; +} +void TitleColorPopup::handle_done_event(int result) +{ + if( result ) return; + char txt[BCSTRLEN]; sprintf(txt, "",color_value); + window->insert_ibeam(txt, strlen(txt)); } diff --git a/cinelerra-5.1/plugins/titler/titlerwindow.h b/cinelerra-5.1/plugins/titler/titlerwindow.h index 79ab76f2..7e73324f 100644 --- a/cinelerra-5.1/plugins/titler/titlerwindow.h +++ b/cinelerra-5.1/plugins/titler/titlerwindow.h @@ -77,6 +77,7 @@ class TitleCurItem; class TitleCurSubMenu; class TitleCurSubMenuItem; class TitleFontsPopup; +class TitleColorPopup; class TitleWindow : public PluginClientWindow { @@ -119,6 +120,7 @@ public: TitleDrag *drag; TitleCurPopup *cur_popup; TitleFontsPopup *fonts_popup; + TitleColorPopup *color_popup; int color_x, color_y; int outline_color_x, outline_color_y; @@ -550,4 +552,18 @@ public: TitleWindow *window; }; +class TitleColorPopup : public ColorThread +{ +public: + TitleColorPopup(TitleMain *client, TitleWindow *window); + ~TitleColorPopup(); + int handle_new_color(int output, int alpha); + void handle_done_event(int result); + int activate(); + + TitleMain *client; + TitleWindow *window; + int color_value; +}; + #endif