Beispiel #1
0
static void
color_reverse(const GdkColor *a, GdkColor *b) {
    gdouble red;
    gdouble green;
    gdouble blue;
    gdouble h;
    gdouble s;
    gdouble v;

    red = (gdouble) a->red / 65535.0;
    green = (gdouble) a->green / 65535.0;
    blue = (gdouble) a->blue / 65535.0;

    gtk_rgb_to_hsv (red, green, blue, &h, &s, &v);

    /* pivot brightness around the center */
    v = 0.5 + (0.5 - v);
    if (v > 1.0)
        v = 1.0;
    else if (v < 0.0)
        v = 0.0;

    /* reduce saturation by 50% */
    s *= 0.5;

    gtk_hsv_to_rgb (h, s, v, &red, &green, &blue);

    b->red = red * 65535.0;
    b->green = green * 65535.0;
    b->blue = blue * 65535.0;
}
static void
color_reverse (const GdkColor *a,
               GdkColor       *b)
{
        gdouble red;
        gdouble green;
        gdouble blue;
        gdouble h;
        gdouble s;
        gdouble v;

        red = (gdouble) a->red / 65535.0;
        green = (gdouble) a->green / 65535.0;
        blue = (gdouble) a->blue / 65535.0;

        gtk_rgb_to_hsv (red, green, blue, &h, &s, &v);

        v = 0.5 + (0.5 - v);
        if (v > 1.0)
                v = 1.0;
        else if (v < 0.0)
                v = 0.0;

        gtk_hsv_to_rgb (h, s, v, &red, &green, &blue);

        b->red = red * 65535.0;
        b->green = green * 65535.0;
        b->blue = blue * 65535.0;
}
Beispiel #3
0
static void
color_reverse (GdkRGBA *a)
{
        gdouble red;
        gdouble green;
        gdouble blue;
        gdouble h;
        gdouble s;
        gdouble v;

        red = a->red;
        green = a->green;
        blue = a->blue;

        gtk_rgb_to_hsv (red, green, blue, &h, &s, &v);

        v = 0.5 + (0.5 - v);
        if (v > 1.0)
                v = 1.0;
        else if (v < 0.0)
                v = 0.0;

        gtk_hsv_to_rgb (h, s, v, &red, &green, &blue);

        a->red = red;
        a->green = green;
        a->blue = blue;
}
void on_colorselection_color_changed (GtkColorSelection *colorselection, gpointer user_data)
{
    char szhsv[64];
    gdouble r, g, b;
    gdouble h, s, v;
    gtk_color_selection_get_current_color (colorselection, &colorvalue);
    r = 1.0 * colorvalue.red / 65535;
    g = 1.0 * colorvalue.green / 65535;
    b = 1.0 * colorvalue.blue / 65535;
    gtk_rgb_to_hsv(r, g, b, &h, &s, &v);
    snprintf(szhsv, sizeof(szhsv), "OpenCV H: %hu S: %hu V: %hu",
             (uint16_t)nearbyint(h * 180.0),
             (uint16_t)nearbyint(s * 255.0),
             (uint16_t)nearbyint(v * 255.0));
    gtk_entry_set_text((GtkEntry *)mytext, szhsv);
}
int main(void) {
  gdouble h,s,v,r,g,b;
  uint16_t H,S,V,R,G,B;
  TColor RGB;
  TColor HSV;
  int Hi,Si,Vi,Ri,Gi,Bi;
  int T;
  int Errors = 0;
  int Error;
  int TotalError = 0;

#ifdef TEST_HSV2RGB
  // Test HSV2RGB
  for (Vi = 0; Vi <= 100; Vi++) {
    v = Vi*1.0/100.0;
    for (Si = 0; Si <= 100; Si++) {
      s = Si*1.0/100.0;
      for (Hi = 0; Hi < 360; Hi++) {
        h = Hi*1.0/360.0;
        gtk_hsv_to_rgb(h,s,v,&r,&g,&b);
        H = round(h*65535.0);
        S = round(s*65535.0);
        V = round(v*65535.0);
        R = round(r*65535.0);
        G = round(g*65535.0);
        B = round(b*65535.0);
        HSV.HSV.H = H;
        HSV.HSV.S = S;
        HSV.HSV.V = V;
        HSV2RGB(&HSV,&RGB);
        Error = abs((int)RGB.RGB.R-(int)R) + abs((int)RGB.RGB.G-(int)G) + abs((int)RGB.RGB.B-(int)B);
        if (Error > MAXDIFF) {
          printf("HSV2RGB %3d %3d %3d: %5d %5d %5d -> %5d %5d %5d",
              Hi,Si,Vi,
              H,S,V,
              RGB.RGB.R,RGB.RGB.G,RGB.RGB.B);
          printf(" (should be %5d %5d %5d, Error = %d)",R,G,B,Error);
          printf("\n");
          TotalError += Error;
          Errors++;
        }
      }
    }
  }
#endif // TEST_HSV2RGB

#ifdef TEST_RGB2HSV
  // Test RGB2HSV
  for (Bi = 0; Bi <= 100; Bi++) {
    b = Bi*1.0/100.0;
    for (Gi = 0; Gi <= 100; Gi++) {
      g = Gi*1.0/100.0;
      for (Ri = 0; Ri <= 100; Ri++) {
        r = Ri*1.0/100.0;
        gtk_rgb_to_hsv(r,g,b,&h,&s,&v);
        R = round(r*65535.0);
        G = round(g*65535.0);
        B = round(b*65535.0);
        H = round(h*65535.0);
        S = round(s*65535.0);
        V = round(v*65535.0);
        RGB.RGB.R = R;
        RGB.RGB.G = G;
        RGB.RGB.B = B;
        RGB2HSV(&RGB,&HSV);
        Error = abs((int)HSV.HSV.H-(int)H) + abs((int)HSV.HSV.S-(int)S) + abs((int)HSV.HSV.V-(int)V);
        if (Error > MAXDIFF) {
          printf("RGB2HSV %3d %3d %3d: %5d %5d %5d -> %5d %5d %5d",
              Ri,Gi,Bi,
              R,G,B,
              HSV.HSV.H,HSV.HSV.S,HSV.HSV.V);
          printf(" (should be %5d %5d %5d, Error = %d)",H,S,V,Error);
          printf("\n");
          TotalError += Error;
          Errors++;
        }
      }
    }
  }
#endif // TEST_RGB2HSV

#ifdef TEST_WHITE2RGB
  printf("<pre>\n");
  for (T = 1000; T <= 40000; T+=100) {
    White2RGB(T,&RGB);
    printf("<span style=\"background:#%02x%02x%02x\"> %5d K -> %5d %5d %5d - #%02x%02x%02x</span>\n",
        RGB.RGB.R >> 8,RGB.RGB.G >> 8,RGB.RGB.B >> 8,
        T,
        RGB.RGB.R,RGB.RGB.G,RGB.RGB.B,
        RGB.RGB.R >> 8,RGB.RGB.G >> 8,RGB.RGB.B >> 8);
  }
  printf("</pre>\n");
#endif

  printf("%d errors found, total deviation is %d.\n",Errors,TotalError);
  return (Errors == 0 ? 0 : 1);
}
Beispiel #6
0
static gboolean dt_iop_area_draw(GtkWidget *widget, cairo_t *cr, dt_iop_module_t *self)
{
  float flt_bg = darktable.bauhaus->bg_normal;
  if(gtk_widget_get_state(GTK_WIDGET(widget)) == GTK_STATE_SELECTED) flt_bg = darktable.bauhaus->bg_focus;
  float flt_dark = flt_bg / 1.5, flt_light = flt_bg * 1.5;

  uint32_t bg = ((255 << 24) | ((int)floor(flt_bg * 255 + 0.5) << 16) | ((int)floor(flt_bg * 255 + 0.5) << 8)
                 | (int)floor(flt_bg * 255 + 0.5));
  // bg = 0xffffffff;
  //   uint32_t dark = ((255 << 24) |
  //                  ((int)floor(flt_dark * 255 + 0.5) << 16) |
  //                  ((int)floor(flt_dark * 255 + 0.5) << 8) |
  //                  (int)floor(flt_dark * 255 + 0.5));
  uint32_t light = ((255 << 24) | ((int)floor(flt_light * 255 + 0.5) << 16)
                    | ((int)floor(flt_light * 255 + 0.5) << 8) | (int)floor(flt_light * 255 + 0.5));

  GtkAllocation allocation;
  gtk_widget_get_allocation(widget, &allocation);
  int width = allocation.width, height = allocation.height;
  if(width % 2 == 0) width--;
  if(height % 2 == 0) height--;
  double center_x = (float)width / 2.0, center_y = (float)height / 2.0;
  double diameter = MIN(width, height) - 4;
  double r_outside = diameter / 2.0, r_inside = r_outside * 0.87;
  double r_outside_2 = r_outside * r_outside, r_inside_2 = r_inside * r_inside;

  // clear the background
  cairo_set_source_rgb(cr, flt_bg, flt_bg, flt_bg);
  cairo_paint(cr);

  /* Create an image initialized with the ring colors */
  gint stride = cairo_format_stride_for_width(CAIRO_FORMAT_RGB24, width);
  guint32 *buf = (guint32 *)malloc(sizeof(guint32) * height * stride / 4);

  for(int y = 0; y < height; y++)
  {
    guint32 *p = buf + y * width;

    double dy = -(y + 0.5 - center_y);

    for(int x = 0; x < width; x++)
    {
      double dx = x + 0.5 - center_x;
      double dist = dx * dx + dy * dy;
      if(dist < r_inside_2 || dist > r_outside_2)
      {
        uint32_t col = bg;
        if((abs(dx) < 1 && abs(dy) < 3) || (abs(dx) < 3 && abs(dy) < 1)) col = light;
        *p++ = col;
        continue;
      }

      double angle = atan2(dy, dx) - M_PI_2;
      if(angle < 0.0) angle += 2.0 * M_PI;

      double hue = angle / (2.0 * M_PI);

      float rgb[3];
      hsl2rgb(rgb, hue, 1.0, 0.5);

      *p++ = (((int)floor(rgb[0] * 255 + 0.5) << 16) | ((int)floor(rgb[1] * 255 + 0.5) << 8)
              | (int)floor(rgb[2] * 255 + 0.5));
    }
  }

  cairo_surface_t *source
      = cairo_image_surface_create_for_data((unsigned char *)buf, CAIRO_FORMAT_RGB24, width, height, stride);

  cairo_set_source_surface(cr, source, 0.0, 0.0);
  cairo_paint(cr);
  free(buf);

  // draw border
  float line_width = 1;
  cairo_set_line_width(cr, line_width);

  cairo_set_source_rgb(cr, flt_bg, flt_bg, flt_bg);
  cairo_new_path(cr);
  cairo_arc(cr, center_x, center_y, r_outside, 0.0, 2.0 * M_PI);
  cairo_stroke(cr);
  cairo_arc(cr, center_x, center_y, r_inside, 0.0, 2.0 * M_PI);
  cairo_stroke(cr);

  cairo_set_source_rgb(cr, flt_dark, flt_dark, flt_dark);
  cairo_new_path(cr);
  cairo_arc(cr, center_x, center_y, r_outside, M_PI, 1.5 * M_PI);
  cairo_stroke(cr);
  cairo_arc(cr, center_x, center_y, r_inside, 0.0, 0.5 * M_PI);
  cairo_stroke(cr);

  cairo_set_source_rgb(cr, flt_light, flt_light, flt_light);
  cairo_new_path(cr);
  cairo_arc(cr, center_x, center_y, r_outside, 0.0, 0.5 * M_PI);
  cairo_stroke(cr);
  cairo_arc(cr, center_x, center_y, r_inside, M_PI, 1.5 * M_PI);
  cairo_stroke(cr);

  // draw selector
  double r = 255 / 255.0, g = 155 / 255.0, b = 40 / 255.0;
  double h, s, v;

  gtk_rgb_to_hsv(r, g, b, &h, &s, &v);

  cairo_save(cr);
  cairo_set_source_rgba(cr, 1.0, 1.0, 1.0, 0.7);

  cairo_translate(cr, center_x, center_y);
  cairo_rotate(cr, h * 2.0 * M_PI - M_PI_2);

  cairo_arc(cr, r_inside * v, 0.0, 3.0, 0, 2.0 * M_PI);
  cairo_stroke(cr);

  cairo_restore(cr);

  cairo_surface_destroy(source);

  return TRUE;
}