static void plot_data_fft(SFSUI* ui) { cairo_t* cr; cr = cairo_create (ui->sf_dat); rounded_rectangle (cr, SS_BORDER, SS_BORDER, SS_SIZE, SS_SIZE, SS_BORDER); cairo_clip_preserve (cr); const float persistence = robtk_dial_get_value(ui->screen); float transp; cairo_set_operator (cr, CAIRO_OPERATOR_OVER); if (persistence > 0) { cairo_set_source_rgba(cr, 0, 0, 0, .25 - .0025 * persistence); transp = 0.05; } else { cairo_set_source_rgba(cr, 0, 0, 0, 1.0); transp = .5; } cairo_fill(cr); cairo_set_line_cap(cr, CAIRO_LINE_CAP_ROUND); cairo_set_line_width (cr, 1.0); const float xmid = rintf(SS_BORDER + SS_SIZE *.5) + .5; const float dnum = SS_SIZE / ui->log_base; const float denom = ui->log_rate / (float)ui->fft_bins; cairo_set_operator (cr, CAIRO_OPERATOR_OVER); for (uint32_t i = 1; i < ui->fft_bins-1 ; ++i) { if (ui->level[i] < 0) continue; const float level = MAKEUP_GAIN + fftx_power_to_dB(ui->level[i]); if (level < -80) continue; const float y = rintf(SS_BORDER + SS_SIZE - dnum * fast_log10(1.0 + i * denom)) + .5; const float y1 = rintf(SS_BORDER + SS_SIZE - dnum * fast_log10(1.0 + (i+1) * denom)) + .5; const float pk = level > 0.0 ? 1.0 : (80 + level) / 80.0; const float a_lr = ui->lr[i]; float clr[3]; hsl2rgb(clr, .70 - .72 * pk, .9, .3 + pk * .4); cairo_set_source_rgba(cr, clr[0], clr[1], clr[2], transp + pk * .2); cairo_set_line_width (cr, MAX(1.0, (y - y1))); cairo_move_to(cr, xmid, y); cairo_line_to(cr, SS_BORDER + SS_SIZE * a_lr, y); cairo_stroke(cr); } cairo_destroy (cr); }
void gui_update(struct dt_iop_module_t *self) { dt_iop_module_t *module = (dt_iop_module_t *)self; dt_iop_splittoning_gui_data_t *g = (dt_iop_splittoning_gui_data_t *)self->gui_data; dt_iop_splittoning_params_t *p = (dt_iop_splittoning_params_t *)module->params; dtgtk_gradient_slider_set_value(g->gslider1,p->shadow_hue); dtgtk_gradient_slider_set_value(g->gslider3,p->highlight_hue); dtgtk_gradient_slider_set_value(g->gslider4,p->highlight_saturation); dtgtk_gradient_slider_set_value(g->gslider2,p->shadow_saturation); dt_bauhaus_slider_set(g->scale1, p->balance*100.0); dt_bauhaus_slider_set(g->scale2, p->compress); float color[3]; hsl2rgb(color,p->shadow_hue,p->shadow_saturation,0.5); GdkColor c; c.red=color[0]*65535.0; c.green=color[1]*65535.0; c.blue=color[2]*65535.0; gtk_widget_modify_fg(GTK_WIDGET(g->colorpick1),GTK_STATE_NORMAL,&c); hsl2rgb(color,p->highlight_hue,p->highlight_saturation,0.5); c.red=color[0]*65535.0; c.green=color[1]*65535.0; c.blue=color[2]*65535.0; gtk_widget_modify_fg(GTK_WIDGET(g->colorpick2),GTK_STATE_NORMAL,&c); }
mat3f dcolor(const vec3f &rgb, const vec3f &) { vec3f hsl = rgb2hsl(rgb); vec3f RGB; mat3f m; RGB = hsl2rgb(hsl + vec3f(0.01f, 0, 0)); m.setColumn(0, (RGB - rgb) / 0.01f * amp.x); RGB = hsl2rgb(hsl + vec3f(0, 0.01f, 0)); m.setColumn(1, (RGB - rgb) / 0.01f * amp.y); RGB = hsl2rgb(hsl + vec3f(0, 0, 0.01f)); m.setColumn(2, (RGB - rgb) / 0.01f * amp.z); return m; }
static inline void update_balance_slider_colors(GtkWidget *slider, float hue1, float hue2) { float rgb[3]; if(hue1 != -1) { hsl2rgb(rgb, hue1, 1.0, 0.5); dt_bauhaus_slider_set_stop(slider, 0.0, rgb[0], rgb[1], rgb[2]); } if(hue2 != -1) { hsl2rgb(rgb, hue2, 1.0, 0.5); dt_bauhaus_slider_set_stop(slider, 1.0, rgb[0], rgb[1], rgb[2]); } }
static inline void update_colorpicker_color(GtkWidget *colorpicker, float hue, float sat) { float rgb[3]; hsl2rgb(rgb, hue, sat, 0.5); GdkRGBA color = (GdkRGBA){.red = rgb[0], .green = rgb[1], .blue = rgb[2], .alpha = 1.0 }; gtk_color_chooser_set_rgba(GTK_COLOR_CHOOSER(colorpicker), &color); } static inline void update_saturation_slider_end_color(GtkWidget *slider, float hue) { float rgb[3]; hsl2rgb(rgb, hue, 1.0, 0.5); dt_bauhaus_slider_set_stop(slider, 1.0, rgb[0], rgb[1], rgb[2]); }
static void colorpick_callback (GtkDarktableButton *button, gpointer user_data) { dt_iop_module_t *self = (dt_iop_module_t *)user_data; dt_iop_splittoning_gui_data_t *g = (dt_iop_splittoning_gui_data_t *)self->gui_data; if(self->dt->gui->reset) return; dt_iop_splittoning_params_t *p = (dt_iop_splittoning_params_t *)self->params; GtkColorSelectionDialog *csd = GTK_COLOR_SELECTION_DIALOG(gtk_color_selection_dialog_new(_("select tone color"))); gtk_window_set_transient_for(GTK_WINDOW(csd), GTK_WINDOW(dt_ui_main_window(darktable.gui->ui))); GtkWidget *okButton, *cancelButton = 0; g_object_get(G_OBJECT(csd), "ok-button", &okButton, NULL); g_object_get(G_OBJECT(csd), "cancel-button", &cancelButton, NULL); g_signal_connect (G_OBJECT (okButton), "clicked", G_CALLBACK (colorpick_button_callback), csd); g_signal_connect (G_OBJECT (cancelButton), "clicked", G_CALLBACK (colorpick_button_callback), csd); GtkColorSelection *cs = GTK_COLOR_SELECTION(gtk_color_selection_dialog_get_color_selection(csd)); GdkColor c; float color[3],h,s,l; h=(button==g->colorpick1)?p->shadow_hue:p->highlight_hue; s=(button==g->colorpick1)?p->shadow_saturation:p->highlight_saturation; l=0.5; hsl2rgb(color,h,s,l); c.red= 65535 * color[0]; c.green= 65535 * color[1]; c.blue= 65535 * color[2]; gtk_color_selection_set_current_color(cs,&c); if(gtk_dialog_run(GTK_DIALOG(csd))==GTK_RESPONSE_ACCEPT) { gtk_color_selection_get_current_color(cs,&c); color[0]=c.red/65535.0; color[1]=c.green/65535.0; color[2]=c.blue/65535.0; rgb2hsl(color,&h,&s,&l); l=0.5; hsl2rgb(color,h,s,l); dt_bauhaus_slider_set( (button==g->colorpick1)? g->gslider1: g->gslider3 ,h ); dt_bauhaus_slider_set( (button==g->colorpick1)? g->gslider2: g->gslider4 ,s ); } gtk_widget_destroy(GTK_WIDGET(csd)); dt_dev_add_history_item(darktable.develop, self, TRUE); }
void CParticle::Init() { m_width = rsRandf(0.8f) + 0.2f; m_step = 0.0f; m_spinAngle = rsRandf(360); hsl2rgb(m_cy->m_hsl[0], m_cy->m_hsl[1],m_cy->m_hsl[2], m_r, m_g, m_b); }
static void saturation_callback(GtkDarktableGradientSlider *slider, gpointer user_data) { dt_iop_module_t *self = (dt_iop_module_t *)user_data; dt_iop_colorize_params_t *p = (dt_iop_colorize_params_t *)self->params; dt_iop_colorize_gui_data_t *g = (dt_iop_colorize_gui_data_t *)self->gui_data; float color[3]; GtkWidget *preview; // hue = dtgtk_gradient_slider_get_value(g->gslider1); p->saturation = dtgtk_gradient_slider_get_value(slider); preview = GTK_WIDGET(g->colorpick1); /* convert to rgb */ hsl2rgb(color,p->hue,p->saturation,0.5); GdkColor c; c.red=color[0]*65535.0; c.green=color[1]*65535.0; c.blue=color[2]*65535.0; /* update preview color */ gtk_widget_modify_fg(preview,GTK_STATE_NORMAL,&c); if (self->dt->gui->reset) return; if (dtgtk_gradient_slider_is_dragging(slider)==FALSE) dt_dev_add_history_item(darktable.develop, self, TRUE); }
/** draw a data-point * * @param pk level-peak, normalized 0..1 according to cutoff range + gain * @param dx,dy X,Y cartesian position * @param ccc circle radius (optional, show spread if >0) * @param dist, phase angular vector corresponding to X,Y (optional spread) */ static inline void draw_point(MF2UI* ui, cairo_t *cr, const float pk, const float dx, const float dy, const float ccc, const float dist, float phase) { float clr[3]; hsl2rgb(clr, .68 - .72 * pk, .9, .2 + pk * .4); cairo_set_line_width (cr, PH_POINT); cairo_set_source_rgba(cr, clr[0], clr[1], clr[2], 0.3 + pk * .7); cairo_new_path (cr); cairo_move_to(cr, dx, dy); cairo_close_path(cr); if (ccc == 0) { cairo_stroke_preserve(cr); cairo_set_source_rgba(cr, clr[0], clr[1], clr[2], .1); cairo_set_line_width (cr, 2.f * PH_POINT + 1); } cairo_stroke(cr); if (ccc > 0 && dist > 0) { const float dev = .01256 * ccc / dist; // .004 * M_PI * ccc / dist cairo_set_line_width(cr, PH_POINT); cairo_set_source_rgba(cr, clr[0], clr[1], clr[2], .1); float pp = phase - .5 * M_PI; cairo_arc (cr, ccc, ccc, dist, (pp-dev), (pp+dev)); cairo_stroke(cr); } }
static void colorpick_callback (GtkDarktableButton *button, gpointer user_data) { dt_iop_module_t *self = (dt_iop_module_t *)user_data; dt_iop_colorize_gui_data_t *g = (dt_iop_colorize_gui_data_t *)self->gui_data; if(self->dt->gui->reset) return; dt_iop_colorize_params_t *p = (dt_iop_colorize_params_t *)self->params; GtkColorSelectionDialog *csd = GTK_COLOR_SELECTION_DIALOG(gtk_color_selection_dialog_new(_("select tone color"))); g_signal_connect (G_OBJECT (csd->ok_button), "clicked", G_CALLBACK (colorpick_button_callback), csd); g_signal_connect (G_OBJECT (csd->cancel_button), "clicked", G_CALLBACK (colorpick_button_callback), csd); GtkColorSelection *cs = GTK_COLOR_SELECTION(gtk_color_selection_dialog_get_color_selection(csd)); GdkColor c; float color[3],h,s,l; h = p->hue; s = p->saturation; l=0.5; hsl2rgb(color,h,s,l); c.red= 65535 * color[0]; c.green= 65535 * color[1]; c.blue= 65535 * color[2]; gtk_color_selection_set_current_color(cs,&c); if(gtk_dialog_run(GTK_DIALOG(csd))==GTK_RESPONSE_ACCEPT) { gtk_color_selection_get_current_color(cs,&c); color[0]=c.red/65535.0; color[1]=c.green/65535.0; color[2]=c.blue/65535.0; rgb2hsl(color,&h,&s,&l); l=0.5; hsl2rgb(color,h,s,l); dtgtk_gradient_slider_set_value(g->gslider1, h); dtgtk_gradient_slider_set_value(g->gslider2, s); } gtk_widget_destroy(GTK_WIDGET(csd)); dt_dev_add_history_item(darktable.develop, self, TRUE); }
void rgb_from_hue(float percentage,float start_hue,float end_hue,struct razer_rgb *color) { struct razer_hsl hsl; hsl.h=percentage*(end_hue-start_hue)+start_hue; hsl.l=0.5f; hsl.s=1.0f; hsl2rgb(&hsl,color); }
void rgbTween (float r1, float g1, float b1, float r2, float g2, float b2, float tween, int direction, float &outr, float &outg, float &outb) { float h1, s1, l1, h2, s2, l2, outh, outs, outl; rgb2hsl (r1, g1, b1, h1, s1, l1); rgb2hsl (r2, g2, b2, h2, s2, l2); hslTween (h1, s1, l1, h2, s2, l2, tween, direction, outh, outs, outl); hsl2rgb (outh, outs, outl, outr, outg, outb); }
static inline void update_saturation_slider_end_color( GtkWidget* slider, float hue) { float rgb[3]; hsl2rgb(rgb, hue, 1.0, 0.5); dt_bauhaus_slider_set_stop(slider, 1.0, rgb[0], rgb[1], rgb[2]); }
result_t gd_base::hsl(double hue, double saturation, double lightness, int32_t &retVal) { if (hue < 0 || hue > 360 || saturation < 0 || saturation > 1 || lightness < 0 || lightness > 1) return CHECK_ERROR(CALL_E_INVALIDARG); retVal = hsl2rgb(hue, saturation, lightness); return 0; }
result_t gd_base::hsla(double hue, double saturation, double lightness, double alpha, int32_t &retVal) { if (hue < 0 || hue > 360 || saturation < 0 || saturation > 1 || lightness < 0 || lightness > 1 || alpha < 0 || alpha > 1) return CHECK_ERROR(CALL_E_INVALIDARG); retVal = (doubleToInt(alpha * 127) << 24) | hsl2rgb(hue, saturation, lightness); return 0; }
void rgbTween(double r1, double g1, double b1, double r2, double g2, double b2, double tween, int direction, double &outr, double &outg, double &outb){ double h1, s1, l1, h2, s2, l2, outh, outs, outl; rgb2hsl(r1, g1, b1, h1, s1, l1); rgb2hsl(r2, g2, b2, h2, s2, l2); hslTween(h1, s1, l1, h2, s2, l2, tween, direction, outh, outs, outl); hsl2rgb(outh, outs, outl, outr, outg, outb); }
static inline void update_colorpicker_fg( GtkWidget* colorpicker, float hue, float sat) { float rgb[3]; GdkColor c; hsl2rgb(rgb, hue, sat, 0.5); c.red = rgb[0]*65535.0; c.green = rgb[1]*65535.0; c.blue = rgb[2]*65535.0; gtk_widget_modify_fg(colorpicker,GTK_STATE_NORMAL,&c); }
bool hslv2rgb(FILE* fp) { char type[4]; uint h, s, lv; if(fscanf(fp, "%[^(](%d,%d,%d)", type, &h, &s, &lv) != 4) { return false; } if(strcmp(type, "HSV") == 0) { hsv2rgb(h, s/100.0f, lv/100.0f); return true; } if(strcmp(type, "HSL") == 0) { hsl2rgb(h, s/100.0f, lv/100.0f); return true; } return false; }
void process(struct dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *piece, void *ivoid, void *ovoid, const dt_iop_roi_t *roi_in, const dt_iop_roi_t *roi_out) { dt_iop_splittoning_data_t *data = (dt_iop_splittoning_data_t *)piece->data; float *in; float *out; const int ch = piece->colors; const float compress = (data->compress / 110.0) / 2.0; // Dont allow 100% compression.. #ifdef _OPENMP #pragma omp parallel for default(none) shared(ivoid, ovoid, roi_out, data) private(in, out) schedule(static) #endif for(int k = 0; k < roi_out->height; k++) { in = ((float *)ivoid) + (size_t)ch * k * roi_out->width; out = ((float *)ovoid) + (size_t)ch * k * roi_out->width; for(int j = 0; j < roi_out->width; j++, in += ch, out += ch) { double ra, la; float mixrgb[3]; float h, s, l; rgb2hsl(in, &h, &s, &l); if(l < data->balance - compress || l > data->balance + compress) { h = l < data->balance ? data->shadow_hue : data->highlight_hue; s = l < data->balance ? data->shadow_saturation : data->highlight_saturation; ra = l < data->balance ? CLIP((fabs(-data->balance + compress + l) * 2.0)) : CLIP((fabs(-data->balance - compress + l) * 2.0)); la = (1.0 - ra); hsl2rgb(mixrgb, h, s, l); out[0] = CLIP(in[0] * la + mixrgb[0] * ra); out[1] = CLIP(in[1] * la + mixrgb[1] * ra); out[2] = CLIP(in[2] * la + mixrgb[2] * ra); } else { out[0] = in[0]; out[1] = in[1]; out[2] = in[2]; } out[3] = in[3]; } } }
int process_cl (struct dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *piece, cl_mem dev_in, cl_mem dev_out, const dt_iop_roi_t *roi_in, const dt_iop_roi_t *roi_out) { dt_iop_colorize_data_t *data = (dt_iop_colorize_data_t *)piece->data; dt_iop_colorize_global_data_t *gd = (dt_iop_colorize_global_data_t *)self->data; cl_int err = -999; const int devid = piece->pipe->devid; const int width = roi_in->width; const int height = roi_in->height; /* create Lab */ float rgb[3]={0}, XYZ[3]={0}, Lab[3]={0}; hsl2rgb(rgb,data->hue, data->saturation, data->lightness/100.0); XYZ[0] = (rgb[0] * 0.5767309) + (rgb[1] * 0.1855540) + (rgb[2] * 0.1881852); XYZ[1] = (rgb[0] * 0.2973769) + (rgb[1] * 0.6273491) + (rgb[2] * 0.0752741); XYZ[2] = (rgb[0] * 0.0270343) + (rgb[1] * 0.0706872) + (rgb[2] * 0.9911085); dt_XYZ_to_Lab(XYZ,Lab); /* a/b components */ const float L = Lab[0]; const float a = Lab[1]; const float b = Lab[2]; const float mix = data->source_lightness_mix/100.0f; size_t sizes[] = { ROUNDUPWD(width), ROUNDUPHT(height), 1}; dt_opencl_set_kernel_arg(devid, gd->kernel_colorize, 0, sizeof(cl_mem), (void *)&dev_in); dt_opencl_set_kernel_arg(devid, gd->kernel_colorize, 1, sizeof(cl_mem), (void *)&dev_out); dt_opencl_set_kernel_arg(devid, gd->kernel_colorize, 2, sizeof(int), (void *)&width); dt_opencl_set_kernel_arg(devid, gd->kernel_colorize, 3, sizeof(int), (void *)&height); dt_opencl_set_kernel_arg(devid, gd->kernel_colorize, 4, sizeof(float), (void *)&mix); dt_opencl_set_kernel_arg(devid, gd->kernel_colorize, 5, sizeof(float), (void *)&L); dt_opencl_set_kernel_arg(devid, gd->kernel_colorize, 6, sizeof(float), (void *)&a); dt_opencl_set_kernel_arg(devid, gd->kernel_colorize, 7, sizeof(float), (void *)&b); err = dt_opencl_enqueue_kernel_2d(devid, gd->kernel_colorize, sizes); if(err != CL_SUCCESS) goto error; return TRUE; error: dt_print(DT_DEBUG_OPENCL, "[opencl_colorize] couldn't enqueue kernel! %d\n", err); return FALSE; }
void TuneColorDialog::updateImage(int hue,int sat,int gam) { QImage coloredImg(m_image->width(),m_image->height(),QImage::Format_RGB32); uint *srcPixel = (uint *)m_image->scanLine(0); uint *dstPixel = (uint *)coloredImg.scanLine(0); uint nrPixels = coloredImg.width()*coloredImg.height(); for (uint i=0;i<nrPixels;i++,srcPixel++,dstPixel++) { QColor c = QColor::fromRgb(*srcPixel); double r,g,b; hsl2rgb(hue/359.0, sat/255.0, pow(c.green()/255.0,gam/100.0),&r,&g,&b); *dstPixel = qRgb((int)(r*255.0),(int)(g*255.0),(int)(b*255.0)); } m_imageLab->setPixmap(QPixmap::fromImage(coloredImg)); m_hue = hue; m_sat = sat; m_gam = gam; }
void process (struct dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *piece, void *ivoid, void *ovoid, const dt_iop_roi_t *roi_in, const dt_iop_roi_t *roi_out) { float *in, *out; dt_iop_colorize_data_t *d = (dt_iop_colorize_data_t *)piece->data; const int ch = piece->colors; /* create Lab */ float rgb[3]={0}, XYZ[3]={0}, Lab[3]={0}; hsl2rgb(rgb,d->hue, d->saturation, d->lightness/100.0); XYZ[0] = (rgb[0] * 0.5767309) + (rgb[1] * 0.1855540) + (rgb[2] * 0.1881852); XYZ[1] = (rgb[0] * 0.2973769) + (rgb[1] * 0.6273491) + (rgb[2] * 0.0752741); XYZ[2] = (rgb[0] * 0.0270343) + (rgb[1] * 0.0706872) + (rgb[2] * 0.9911085); dt_XYZ_to_Lab(XYZ,Lab); /* a/b components */ const float L = Lab[0]; const float a = Lab[1]; const float b = Lab[2]; const float mix = d->source_lightness_mix/100.0; #ifdef _OPENMP #pragma omp parallel for default(none) shared(ivoid,ovoid,roi_out) private(in,out) schedule(static) #endif for(int k=0; k<roi_out->height; k++) { float lmix=(mix*100.0)/2.0; int stride = ch*roi_out->width; in = (float *)ivoid+(k*stride); out = (float *)ovoid+(k*stride); for(int l=0; l < stride; l+=ch) { out[l+0] = L-lmix + in[l+0]*mix; out[l+1] = a; out[l+2] = b; out[l+3] = in[l+3]; } } }
static void hue_callback(GtkDarktableGradientSlider *slider, gpointer user_data) { dt_iop_module_t *self = (dt_iop_module_t *)user_data; dt_iop_splittoning_params_t *p = (dt_iop_splittoning_params_t *)self->params; dt_iop_splittoning_gui_data_t *g = (dt_iop_splittoning_gui_data_t *)self->gui_data; double hue=0; double saturation=0; float color[3]; GtkWidget *preview; GtkDarktableGradientSlider *sslider=NULL; if( slider == g->gslider1 ) { // Shadows p->shadow_hue=hue=dtgtk_gradient_slider_get_value(slider); saturation=p->shadow_saturation; preview=GTK_WIDGET(g->colorpick1); sslider=g->gslider2; } else { p->highlight_hue=hue=dtgtk_gradient_slider_get_value(slider); saturation=p->highlight_saturation; preview=GTK_WIDGET(g->colorpick2); sslider=g->gslider4; } hsl2rgb(color,hue,saturation,0.5); GdkColor c; c.red=color[0]*65535.0; c.green=color[1]*65535.0; c.blue=color[2]*65535.0; dtgtk_gradient_slider_set_stop(sslider,1.0,c); // Update saturation end color gtk_widget_modify_fg(preview,GTK_STATE_NORMAL,&c); // update color preview if(self->dt->gui->reset) return; gtk_widget_draw(GTK_WIDGET(sslider),NULL); dt_dev_add_history_item(darktable.develop, self, TRUE); }
void commit_params(struct dt_iop_module_t *self, dt_iop_params_t *p1, dt_dev_pixelpipe_t *pipe, dt_dev_pixelpipe_iop_t *piece) { dt_iop_graduatednd_params_t *p = (dt_iop_graduatednd_params_t *)p1; dt_iop_graduatednd_data_t *d = (dt_iop_graduatednd_data_t *)piece->data; d->density = p->density; d->compression = p->compression; d->rotation = p->rotation; d->offset = p->offset; hsl2rgb(d->color, p->hue, p->saturation, 0.5); d->color[3] = 0.0f; if(d->density < 0) for(int l = 0; l < 4; l++) d->color[l] = 1.0 - d->color[l]; for(int l = 0; l < 4; l++) d->color1[l] = 1.0 - d->color[l]; }
void gui_update(struct dt_iop_module_t *self) { dt_iop_module_t *module = (dt_iop_module_t *)self; dt_iop_colorize_gui_data_t *g = (dt_iop_colorize_gui_data_t *)self->gui_data; dt_iop_colorize_params_t *p = (dt_iop_colorize_params_t *)module->params; dtgtk_gradient_slider_set_value(g->gslider1,p->hue); dtgtk_gradient_slider_set_value(g->gslider2,p->saturation); dtgtk_slider_set_value(g->scale1, p->lightness); dtgtk_slider_set_value(g->scale2, p->source_lightness_mix); float color[3]; hsl2rgb(color,p->hue,p->saturation,0.5); GdkColor c; c.red=color[0]*65535.0; c.green=color[1]*65535.0; c.blue=color[2]*65535.0; gtk_widget_modify_fg(GTK_WIDGET(g->colorpick1),GTK_STATE_NORMAL,&c); }
// BANG - calculate and output void cs_bang(t_cs *x) { if(x->attr_mode == ps_rgb2hsl) rgb2hsl(x, x->val1, x->val2, x->val3); // first for speed else if(x->attr_mode == ps_hsl2rgb) hsl2rgb(x, x->val1, x->val2, x->val3); else if(x->attr_mode == ps_no_transform) no_transform(x); else if(x->attr_mode == ps_rgb2cmy) rgb2cmy(x, x->val1, x->val2, x->val3); else if(x->attr_mode == ps_cmy2rgb) cmy2rgb(x, x->val1, x->val2, x->val3); else if(x->attr_mode == ps_rgb2hsv) rgb2hsv(x, x->val1, x->val2, x->val3); else if(x->attr_mode == ps_hsv2rgb) hsv2rgb(x, x->val1, x->val2, x->val3); else if(x->attr_mode == ps_rgb2xyz) rgb2xyz(x, x->val1, x->val2, x->val3); else if(x->attr_mode == ps_xyz2rgb) xyz2rgb(x, x->val1, x->val2, x->val3); else if(x->attr_mode == ps_rgb2uvw) rgb2uvw(x, x->val1, x->val2, x->val3); else if(x->attr_mode == ps_uvw2rgb) uvw2rgb(x, x->val1, x->val2, x->val3); else if(x->attr_mode == ps_rgb2retinalcone) rgb2cone(x, x->val1, x->val2, x->val3); else if(x->attr_mode == ps_retinalcone2rgb) cone2rgb(x, x->val1, x->val2, x->val3); else if(x->attr_mode == ps_rgb2lab) rgb2lab(x, x->val1, x->val2, x->val3); else if(x->attr_mode == ps_lab2rgb) lab2rgb(x, x->val1, x->val2, x->val3); else if(x->attr_mode == ps_rgb2yiq) rgb2yiq(x, x->val1, x->val2, x->val3); else if(x->attr_mode == ps_yiq2rgb) yiq2rgb(x, x->val1, x->val2, x->val3); else if(x->attr_mode == ps_rgb2hls) rgb2hls(x, x->val1, x->val2, x->val3); else if(x->attr_mode == ps_hls2rgb) hls2rgb(x, x->val1, x->val2, x->val3); else if(x->attr_mode == ps_rgb2rgbcie) rgb2rgbcie(x, x->val1, x->val2, x->val3); else if(x->attr_mode == ps_rgbcie2rgb) rgbcie2rgb(x, x->val1, x->val2, x->val3); else if(x->attr_mode == ps_rgb2rgbsmpte) rgb2rgbsmpte(x, x->val1, x->val2, x->val3); else if(x->attr_mode == ps_rgbsmpte2rgb) rgbsmpte2rgb(x, x->val1, x->val2, x->val3); if(x->attr_outputtype == ps_packed){ Atom temp_list[3]; atom_setlong(temp_list+0, x->calc1); atom_setlong(temp_list+1, x->calc2); atom_setlong(temp_list+2, x->calc3); outlet_list(x->out1, 0L, 3, temp_list); // output the result } else{ outlet_int(x->out3, x->calc3); // output the result outlet_int(x->out2, x->calc2); // output the result outlet_int(x->out1, x->calc1); // output the result } }
static void hue_callback(GtkWidget *slider, gpointer user_data) { dt_iop_module_t *self = (dt_iop_module_t *)user_data; dt_iop_graduatednd_params_t *p = (dt_iop_graduatednd_params_t *)self->params; dt_iop_graduatednd_gui_data_t *g = (dt_iop_graduatednd_gui_data_t *)self->gui_data; const float hue = dt_bauhaus_slider_get(g->gslider1); //fprintf(stderr," hue: %f, saturation: %f\n",hue,dtgtk_gradient_slider_get_value(g->gslider2)); float saturation = 1.0f; float color[3]; hsl2rgb(color, hue, saturation, 0.5f); dt_bauhaus_slider_set_stop(g->gslider2, 1.0f, color[0], color[1], color[2]); // Update saturation end color if(self->dt->gui->reset) return; gtk_widget_draw(GTK_WIDGET(g->gslider2),NULL); p->hue = hue; dt_dev_add_history_item(darktable.develop, self, TRUE); }
void setupSH() { struct Vertex* vtx = vertices; struct Vertex* currvtx = vtx; float du = (GU_PI*2) / GRID_WIDTH; float dh = 1.0f / GRID_WIDTH; unsigned int i,j; for (i = 0; i < GRID_WIDTH; ++i) { float u = i * du; for (j = 0; j < GRID_HEIGHT; ++j) { currvtx->color = hsl2rgb(i * dh, 1.0f, 0.5f); currvtx++; } } }
void print_ChangeColor( void ) { print_ColorH += 320; print_ColorH %= 768; uint8_t rgb_ar[3]; hsl2rgb( print_ColorH, print_ColorS, print_ColorL, rgb_ar ); print_CharacterRedVal = rgb_ar[0]; print_CharacterGreenVal = rgb_ar[1]; print_CharacterBlueVal = rgb_ar[2]; /* print_CharacterBlueVal += 80; print_CharacterBlueVal %= 255; print_CharacterGreenVal += 80; print_CharacterGreenVal %= 255; print_CharacterRedVal += 80; print_CharacterRedVal %= 255; */ }
// This is the actual task that is run static portTASK_FUNCTION( vLCDUpdateTask, pvParameters ) { #if LCD_EXAMPLE_OP==0 unsigned short screenColor = 0; unsigned short tscr; unsigned char curLine; unsigned timerCount = 0; int xoffset = 0, yoffset = 0; unsigned int xmin=0, xmax=0, ymin=0, ymax=0; unsigned int x, y; int i, j; float hue=0, sat=0.2, light=0.2; #elif LCD_EXAMPLE_OP==1 unsigned char picIndex = 0; #else Bad definition #endif vtLCDMsg msgBuffer; vtLCDStruct *lcdPtr = (vtLCDStruct *) pvParameters; #ifdef INSPECT_STACK // This is meant as an example that you can re-use in your own tasks // Inspect to the stack remaining to see how much room is remaining // 1. I'll check it here before anything really gets started // 2. I'll check during the run to see if it drops below 10% // 3. You could use break points or logging to check on this, but // you really don't want to print it out because printf() can // result in significant stack usage. // 4. Note that this checking is not perfect -- in fact, it will not // be able to tell how much the stack grows on a printf() call and // that growth can be *large* if version 1 of printf() is used. unsigned portBASE_TYPE InitialStackLeft = uxTaskGetStackHighWaterMark(NULL); unsigned portBASE_TYPE CurrentStackLeft; float remainingStack = InitialStackLeft; remainingStack /= lcdSTACK_SIZE; if (remainingStack < 0.10) { // If the stack is really low, stop everything because we don't want it to run out // The 0.10 is just leaving a cushion, in theory, you could use exactly all of it VT_HANDLE_FATAL_ERROR(0); } #endif /* Initialize the LCD and set the initial colors */ GLCD_Init(); tscr = Red; // may be reset in the LCDMsgTypeTimer code below screenColor = White; // may be reset in the LCDMsgTypeTimer code below GLCD_SetTextColor(tscr); GLCD_SetBackColor(screenColor); GLCD_Clear(screenColor); // Added by Matthew Ibarra 2/2/2013 int xPos = 0; // Note that srand() & rand() require the use of malloc() and should not be used unless you are using // MALLOC_VERSION==1 #if MALLOC_VERSION==1 srand((unsigned) 55); // initialize the random number generator to the same seed for repeatability #endif curLine = 5; // This task should never exit for(;;) { #ifdef INSPECT_STACK CurrentStackLeft = uxTaskGetStackHighWaterMark(NULL); float remainingStack = CurrentStackLeft; remainingStack /= lcdSTACK_SIZE; if (remainingStack < 0.10) { // If the stack is really low, stop everything because we don't want it to run out VT_HANDLE_FATAL_ERROR(0); } #endif #if LCD_EXAMPLE_OP==0 // Wait for a message if (xQueueReceive(lcdPtr->inQ,(void *) &msgBuffer,portMAX_DELAY) != pdTRUE) { VT_HANDLE_FATAL_ERROR(0); } #if EXAMPLE_COLOR_CHANGE==1 //Log that we are processing a message -- more explanation of logging is given later on vtITMu8(vtITMPortLCDMsg,getMsgType(&msgBuffer)); vtITMu8(vtITMPortLCDMsg,getMsgLength(&msgBuffer)); // Take a different action depending on the type of the message that we received switch(getMsgType(&msgBuffer)) { case LCDMsgTypePrint: { // This will result in the text printing in the last five lines of the screen char lineBuffer[lcdCHAR_IN_LINE+1]; copyMsgString(lineBuffer,&msgBuffer,lcdCHAR_IN_LINE); // clear the line GLCD_ClearLn(curLine,1); // show the text GLCD_DisplayString(curLine,0,1,(unsigned char *)lineBuffer); curLine++; if (curLine == lcdNUM_LINES) { curLine = 5; } break; } case LCDMsgTypeTimer: { // Note: if I cared how long the timer update was I would call my routine // unpackTimerMsg() which would unpack the message and get that value // Each timer update will cause a circle to be drawn on the top half of the screen // as explained below if (timerCount == 0) { /* ************************************************** */ // Find a new color for the screen by randomly (within limits) selecting HSL values // This can be ignored unless you care about the color map #if MALLOC_VERSION==1 hue = rand() % 360; sat = (rand() % 1024) / 1023.0; sat = sat * 0.5; sat += 0.5; light = (rand() % 1024) / 1023.0; light = light * 0.8; light += 0.10; #else hue = (hue + 1); if (hue >= 360) hue = 0; sat+=0.01; if (sat > 1.0) sat = 0.20; light+=0.03; if (light > 1.0) light = 0.20; #endif screenColor = hsl2rgb(hue,sat,light); // Now choose a complementary value for the text color hue += 180; if (hue >= 360) hue -= 360; tscr = hsl2rgb(hue,sat,light); GLCD_SetTextColor(tscr); GLCD_SetBackColor(screenColor); // End of playing around with figuring out a random color /* ************************************************** */ // clear the top half of the screen GLCD_ClearWindow(0,0,320,120,screenColor); // Now we are going to draw a circle in the upper left corner of the screen int count = 200; float radius; float inc, val, offset = MAX_RADIUS; unsigned short circleColor; inc = 2*M_PI/count; xmax = 0; ymax = 0; xmin = 50000; ymin = 50000; val = 0.0; for (i=0;i<count;i++) { // Make the circle a little thicker // by actually drawing three circles w/ different radii float cv = cos(val), sv=sin(val); circleColor = (val*0xFFFF)/(2*M_PI); GLCD_SetTextColor(circleColor); for (radius=MAX_RADIUS-2.0;radius<=MAX_RADIUS;radius+=1.0) { x = round(cv*radius+offset); y = round(sv*radius+offset); if (x > xmax) xmax = x; if (y > ymax) ymax = y; if (x < xmin) xmin = x; if (y < ymin) ymin = y; GLCD_PutPixel(x,y); } val += inc; } // Now we are going to read the upper left square of the LCD's // memory (see its data sheet for details on that) and save // that into a buffer for fast re-drawing later if (((xmax+1-xmin)*(ymax+1-ymin)) > BUF_LEN) { // Make sure we have room for the data VT_HANDLE_FATAL_ERROR(0); } unsigned short int *tbuffer = buffer; unsigned int width = (xmax+1-xmin); for (j=ymin;j<=ymax;j++) { GLCD_GetPixelRow (xmin,j,width,tbuffer); tbuffer += width; } // end of reading in the buffer xoffset = xmin; yoffset = ymin; } else { // We are going to write out the data read into the buffer // back onto the screen at a new location // This is *very* fast // First, clear out where we were GLCD_ClearWindow(xoffset,yoffset,xmax+1-xmin,ymax+1-ymin,screenColor); // Pick the new location #if MALLOC_VERSION==1 xoffset = rand() % (320-(xmax+1-xmin)); yoffset = rand() % (120-(ymax+1-ymin)); #else xoffset = (xoffset + 10) % (320-(xmax+1-xmin)); yoffset = (yoffset + 10) % (120-(ymax+1-ymin)); #endif // Draw the bitmap GLCD_Bitmap(xoffset,yoffset,xmax+1-xmin,ymax-1-ymin,(unsigned char *)buffer); } timerCount++; if (timerCount >= 40) { // every so often, we reset timer count and start again // This isn't for any important reason, it is just to for this example code to do "stuff" timerCount = 0; } break; } default: { // In this configuration, we are only expecting to receive timer messages VT_HANDLE_FATAL_ERROR(getMsgType(&msgBuffer)); break; } } // end of switch() #endif #if MILESTONE_1==1 // Added by Matthew Ibarra 2/2/2013 if(timerCount==0) { GLCD_Clear(screenColor); // Draw the vertical gridlines onto the LCD int i; for(i = 320/6; i < 315; i = i + 320/6) { GLCD_ClearWindow(i, 0, 1, 240, Red); } // Draw the vertical gridlines onto the LCD for(i = 240/4; i < 235; i = i + 240/4) { GLCD_ClearWindow(0, i, 320, 1, Red); } //Output Scale on LCD GLCD_DisplayString(29, 0, 0, (unsigned char*) "V/div=2.5 s/div=3"); timerCount++; } int adcValue; getMsgValue(&adcValue, &msgBuffer); int displayValue; displayValue = 120 - (adcValue * 120)/(0x100); GLCD_ClearWindow(xPos, displayValue, 2, 2, Black); xPos += 2; if(xPos > 320) { timerCount = 0; xPos = 0; } #endif // Here is a way to do debugging output via the built-in hardware -- it requires the ULINK cable and the // debugger in the Keil tools to be connected. You can view PORT0 output in the "Debug(printf) Viewer" // under "View->Serial Windows". You have to enable "Trace" and "Port0" in the Debug setup options. This // should not be used if you are using Port0 for printf() // There are 31 other ports and their output (and port 0's) can be seen in the "View->Trace->Records" // windows. You have to enable the prots in the Debug setup options. Note that unlike ITM_SendChar() // this "raw" port write is not blocking. That means it can overrun the capability of the system to record // the trace events if you go too quickly; that won't hurt anything or change the program execution and // you can tell if it happens because the "View->Trace->Records" window will show there was an overrun. //vtITMu16(vtITMPortLCD,screenColor); #elif LCD_EXAMPLE_OP==1 // In this alternate version, we just keep redrawing a series of bitmaps as // we receive timer messages // Wait for a message if (xQueueReceive(lcdPtr->inQ,(void *) &msgBuffer,portMAX_DELAY) != pdTRUE) { VT_HANDLE_FATAL_ERROR(0); } if (getMsgType(&msgBuffer) != LCDMsgTypeTimer) { // In this configuration, we are only expecting to receive timer messages VT_HANDLE_FATAL_ERROR(getMsgType(&msgBuffer)); } /* go through a bitmap that is really a series of bitmaps */ picIndex = (picIndex + 1) % 9; GLCD_Bmp(99,99,120,45,(unsigned char *) &ARM_Ani_16bpp[picIndex*(120*45*2)]); #else Bad setting #endif } }