coloritto.c 67.5 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
/*
 * Copyright (c) 2014 Øyvind Kolås <pippin@hodefoting.com>
 *
 * Permission to use, copy, modify, and/or distribute this software for any
 * purpose with or without fee is hereby granted, provided that the above
 * copyright notice and this permission notice appear in all copies.
 *
 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 */

#include <string.h>
#include <stdio.h>
#include <stdlib.h>
20
#include <libgen.h>
21
#include <math.h>
22
#ifdef HAVE_MRG
23
#include "mrg.h"
24
#include "mrg-string.h"
25
#endif
26
#include <babl/babl.h>
27
#include "luz.h"
28 29
#include "luz-xml.h"
#include "luz-string.h"
30
#include "luz-list.h"
31
#include "coloritto.h"
32

33

34 35 36 37
/* For coloritto structs that are multiple coloritto entries, the first
 * entry of the collectino is concsidered representative, thus the white
 * ramp is sorted from 100% and down.
 */
38

39
// XXX: eeek mrg doesn't permit forcing a width on a span
40

41
const char *css =
42
"a { color: yellow; text-decoration: none;  }\n"
Øyvind "pippin" Kolås's avatar
Øyvind "pippin" Kolås committed
43
"div.colorinfo { font-size: 1.0em; color: white; }\n"
44
"div.colorspaceinfo {  }\n"
Øyvind "pippin" Kolås's avatar
Øyvind "pippin" Kolås committed
45
"div.colorname { margin-bottom: 0.5em; margin-top: 1.0em; }\n"
46 47
"div.colorspacename { font-weight:bold; float:left; clear: left; width: 5em; height: 1.0em; }\n"
"div.colortriplet {  }\n"
48
"div.palitem { float:left;width:6em;height:6em; }\n"
Øyvind "pippin" Kolås's avatar
Øyvind "pippin" Kolås committed
49 50 51 52 53 54 55 56

"span.palitemlabel { color: white; }\n"
"span.bright { color: black; }\n"

"div.append { background-color:transparent; }\n"
"div.shell { background-color:transparent;color:white; }\n"
"div.prompt { color:#7aa; display: inline; }\n"
"div.commandline { color:white; display: inline; }\n"
57
"div.palettetoolbar {height: 3em;color:white}\n"
Øyvind "pippin" Kolås's avatar
Øyvind "pippin" Kolås committed
58
"div.palettetool {border: 2px solid green; }\n"
59
"";
60

61
static const char *todo =
62
"bake queuing of draw into post argv command phase\n"
63
"edit colors components\n"
64
"show selected color in relation to whatever is loaded in 3d view\n"
65
"edit spectra\n"
66
"measure spectra\n"
67 68 69 70 71 72 73
"export cxf\n"
"undo/redo\n"
"storing/visualising ramps as sub-items\n"
"commandline:\n"
" fading history\n"
" splitting newlines properly\n"
"viewport:\n"
74
" load an image\n"
75 76 77 78 79
" separate mode\n"
" separate+proof\n"
" additive models in luz\n"
;

80
const Babl *display_rgbf = NULL;
81
static int palette_no = 0;
82

83 84
#ifdef HAVE_MRG

85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
static void mrg_set_source_srgba (cairo_t *cr, float r, float g, float b, float a)
{
  float in_pix[4]={r,g,b,a};
  float conv_pix[4];
  babl_process (babl_fish (babl_format ("R'G'B' float"), display_rgbf),
                in_pix, conv_pix, 1);
  if (a == 1.0f)
    cairo_set_source_rgb (cr, conv_pix[0], conv_pix[1], conv_pix[2]);
  else
    cairo_set_source_rgba (cr, conv_pix[0], conv_pix[1], conv_pix[2], a);
}

static void mrg_set_source_srgb (cairo_t *cr, float r, float g, float b)
{
  mrg_set_source_srgba (cr, r, g, b, 1.0f);
}
101
#endif
102

103 104
#define MAX_KV 10

105
struct
106
_Coloritto {
107
  int   ref_count;
108
  int   kvs;
109 110
  char *keys[MAX_KV];
  char *values[MAX_KV];
111

112 113
  ColorittoDef set;
  ColorittoDef computed;
114 115 116 117 118 119 120 121 122

  /* first member is full, and first member on white is the spectrum
     propagated to 3d colors */
  Spectrum on_white;
  Spectrum on_black;
  Spectrum on_white_ramp[10];
  Spectrum on_black_ramp[10];
  /* have an enum of which ones are explicitly set */

123 124
  float scalar; /* last fallback - use for using colors as all values
                   internally */
125
  float lab[3];
126
  float display_rgb[3];
127 128 129 130
  float xyz[3];
  float xyY[3];
  float lch[3];
  float srgb[3];
131
  float cmyk[4];
132 133

  // CMYK
134

135

136 137 138
//  beware that copy by value works as long as the original
//  color is not freed - this caveat only applies to the key/value pairs
//  of the copies, not the rest of the struct.
139
   float delta_E;
140 141
};

142 143
struct
_ColorittoCollection {
144
  int   foo;
145
  int   kvs;
146 147
  char *keys[MAX_KV];
  char *values[MAX_KV];
148
  LuzList *list;
149 150
};

151
int use_ui = 0;
152 153
int test_precision = 0;
int use_repl = 0;
154

155 156 157


#ifdef HAVE_MRG
158 159
#define printf(foo...) \
   do{ MrgString *str = mrg_string_new_printf (foo);\
160
       if (use_ui) {\
161 162 163 164 165 166 167 168 169 170 171 172
       MrgString *line = mrg_string_new ("");\
       for (char *p= str->str; *p; p++) { \
         if (*p == '\n') { \
           mrg_list_prepend (&scrollback, strdup (line->str));\
           mrg_string_set (line, "");\
         } else { \
           mrg_string_append_byte (line, *p);\
         } \
       } \
       if (line->str[0]) \
         mrg_list_prepend (&scrollback, strdup (line->str));\
       mrg_string_free (line, 1);\
173 174 175 176
       }\
       else \
       { fprintf (stdout, "%s", str->str);\
       }\
177
       mrg_string_free (str, 1);\
178 179
   }while(0)

180 181
#endif

182 183 184 185
#ifndef MAX
#define MAX(a,b)  ((a)<(b)?(b):(a))
#endif

186
static Luz *luz = NULL;
187 188

void
189
coloritto_set (Coloritto *color, ColorittoDef color_type,
190
                     const float *data)
191 192 193
{
  switch (color_type)
  {
194
    case COLORITTO_SET: break;
195 196 197 198
    case COLORITTO_SCALAR:
      color->scalar = data[0];
      color->set |= color_type;
      break;
199
    case COLORITTO_XYZ:
200 201 202
      color->xyz[0] = data[0];
      color->xyz[1] = data[1];
      color->xyz[2] = data[2];
203 204 205
      color->set |= color_type;
      break;
    case COLORITTO_xyY:
206 207 208
      color->xyY[0] = data[0];
      color->xyY[1] = data[1];
      color->xyY[2] = data[2];
209 210 211
      color->set |= color_type;
      break;
    case COLORITTO_LAB:
212 213 214
      color->lab[0] = data[0];
      color->lab[1] = data[1];
      color->lab[2] = data[2];
215 216 217
      color->set |= color_type;
      break;
    case COLORITTO_LCH:
218 219 220
      color->lch[0] = data[0];
      color->lch[1] = data[1];
      color->lch[2] = data[2];
221 222
      color->set |= color_type;
      break;
223 224 225 226
    case COLORITTO_DISPLAY_RGB:
      color->display_rgb[0] = data[0];
      color->display_rgb[1] = data[1];
      color->display_rgb[2] = data[2];
227 228 229
      color->set |= color_type;
      break;
    case COLORITTO_SRGB:
230 231 232
      color->srgb[0] = data[0];
      color->srgb[1] = data[1];
      color->srgb[2] = data[2];
233 234 235
      color->set |= color_type;
      break;
    case COLORITTO_SPECTRUM_ON_WHITE:
236 237 238
      color->on_white = *((Spectrum*)data);
      color->set |= color_type;
      break;
239
    case COLORITTO_SPECTRUM_ON_WHITE_AND_BLACK:
240 241 242 243
      color->on_black = *((Spectrum*)data);
      color->set |= color_type;
      break;
    case COLORITTO_SPECTRUM_ON_WHITE_RAMP:
244
    case COLORITTO_SPECTRUM_ON_WHITE_AND_BLACK_RAMP:
245
      /* NYI */
246 247
      break;
  }
248 249

  color->computed = 0; // drop all caches on all sets
250 251
}

252 253 254 255 256 257 258 259
int coloritto_is_set (Coloritto *color,
                      ColorittoDef color_type)
{
  if (color->set & color_type)
    return 1;
  return 0;
}

260
void coloritto_ensure (Coloritto *color, ColorittoDef color_type)
261 262 263 264 265 266 267 268 269 270 271 272 273 274
{
  int got_xyz = 0;
  /* ensure that the color definition exists, */
  if (color->set & color_type)
    return;
  if (color->computed & color_type)
    return;

  if ((color->set & COLORITTO_XYZ) ||
      (color->computed & COLORITTO_XYZ))
  {
    got_xyz = 1;
  }

275 276 277 278 279 280 281 282 283
  if ((!got_xyz && (color->set & COLORITTO_SPECTRUM_ON_WHITE) )||
      (!got_xyz && (color->set & COLORITTO_SPECTRUM_ON_WHITE_AND_BLACK)))
  {
    luz_reflectance_to_xyz (luz, &color->on_white, &color->xyz[0],
                                                   &color->xyz[1],
                                                   &color->xyz[2]);
    color->computed |= COLORITTO_XYZ;
    got_xyz = 1;
  }
284 285 286 287 288 289 290 291 292 293
  if (!got_xyz && (color->set & COLORITTO_LAB))
  {
    babl_process (babl_fish (babl_format ("CIE Lab float"),
                  babl_format ("CIE XYZ float")),
                  color->lab, color->xyz, 1);
    color->computed |= COLORITTO_XYZ;
    got_xyz = 1;
  }
  if (!got_xyz && (color->set & COLORITTO_LCH))
  {
294
    babl_process (babl_fish (babl_format ("CIE LCH(ab) float"),
295 296 297 298 299 300 301 302 303 304 305 306 307
                  babl_format ("CIE XYZ float")),
                  color->lch, color->xyz, 1);
    color->computed |= COLORITTO_XYZ;
    got_xyz = 1;
  }
  if (!got_xyz && (color->set & COLORITTO_SRGB))
  {
    babl_process (babl_fish (babl_format ("R'G'B' float"),
                  babl_format ("CIE XYZ float")),
                  color->srgb, color->xyz, 1);
    color->computed |= COLORITTO_XYZ;
    got_xyz = 1;
  }
308
  if (!got_xyz && (color->set & COLORITTO_DISPLAY_RGB))
309
  {
310 311 312
    babl_process (babl_fish (display_rgbf,
                  babl_format ("CIE XYZ float")),
                  color->display_rgb, color->xyz, 1);
313 314 315 316 317 318 319 320
    color->computed |= COLORITTO_XYZ;
    got_xyz = 1;
  }
  if (!got_xyz && (color->set & COLORITTO_SCALAR))
  {
    babl_process (babl_fish (babl_format ("CIE L float"),
                  babl_format ("CIE XYZ float")),
                  &color->scalar, color->xyz, 1);
321 322 323
    color->computed |= COLORITTO_XYZ;
    got_xyz = 1;
  }
324 325
  if (!got_xyz && (color->set & COLORITTO_xyY))
  {
326 327 328
    babl_process (babl_fish (babl_format ("CIE xyY float"),
                  babl_format ("CIE XYZ float")),
                  color->xyY, color->xyz, 1);
329 330 331
    color->computed |= COLORITTO_XYZ;
    got_xyz = 1;
  }
332 333 334

 switch (color_type)
  {
335 336 337
    case COLORITTO_XYZ:
    case COLORITTO_SET:
      return;
338
    case COLORITTO_xyY:
339 340 341
      babl_process (babl_fish (babl_format ("CIE XYZ float"),
                    babl_format ("CIE xyY float")),
                    color->xyz, color->xyY, 1);
342

343 344
      color->computed |= color_type;
      break;
345 346 347 348 349 350
    case COLORITTO_SCALAR:
      babl_process (babl_fish (babl_format ("CIE XYZ float"),
                    babl_format ("CIE L float")),
                    color->xyz, color->lab, 1);
      color->computed |= color_type;
      break;
351
    case COLORITTO_LAB:
352 353 354 355 356
      babl_process (babl_fish (babl_format ("CIE XYZ float"),
                    babl_format ("CIE Lab float")),
                    color->xyz, color->lab, 1);
      color->computed |= color_type;
      break;
357
    case COLORITTO_LCH:
358
      babl_process (babl_fish (babl_format ("CIE XYZ float"),
359
                    babl_format ("CIE LCH(ab) float")),
360 361 362
                    color->xyz, color->lch, 1);
      color->computed |= color_type;
      break;
363
    case COLORITTO_DISPLAY_RGB:
364
      babl_process (babl_fish (babl_format ("CIE XYZ float"),
365 366
                    display_rgbf),
                    color->xyz, color->display_rgb, 1);
367 368
      color->computed |= color_type;
      break;
369
    case COLORITTO_SRGB:
370 371 372 373 374 375 376
      babl_process (babl_fish (babl_format ("CIE XYZ float"),
                    babl_format ("R'G'B' float")),
                    color->xyz, color->srgb, 1);
      color->computed |= color_type;
      break;

    case COLORITTO_SPECTRUM_ON_WHITE:
377
      coloritto_ensure (color, COLORITTO_SRGB);
378
      color->on_white = luz_rgb_to_spectrum (luz, color->srgb[0], color->srgb[1], color->srgb[2]);
379 380 381
       /* should interpolate among known spectrums, the freie farbe set
          is probably a good one, that way we generate plausible spectrums
          for all values */
382
      color->computed |= color_type;
383
      break;
384 385 386 387 388 389 390 391
    case COLORITTO_SPECTRUM_ON_WHITE_RAMP:
    case COLORITTO_SPECTRUM_ON_WHITE_AND_BLACK:
    case COLORITTO_SPECTRUM_ON_WHITE_AND_BLACK_RAMP:
      break;
  }
}

void
392
coloritto_get (Coloritto *color, ColorittoDef color_type,
393
                     float *data)
394
{
395
  coloritto_ensure (color, color_type);
396 397
  switch (color_type)
  {
398
    case COLORITTO_SET: break;
399 400 401
    case COLORITTO_SCALAR:
      data[0] = color->scalar;
      break;
402
    case COLORITTO_XYZ:
403 404 405
      data[0] = color->xyz[0];
      data[1] = color->xyz[1];
      data[2] = color->xyz[2];
406 407
      break;
    case COLORITTO_xyY:
408 409 410
      data[0] = color->xyY[0];
      data[1] = color->xyY[1];
      data[2] = color->xyY[2];
411 412
      break;
    case COLORITTO_LAB:
413 414 415
      data[0] = color->lab[0];
      data[1] = color->lab[1];
      data[2] = color->lab[2];
416 417
      break;
    case COLORITTO_LCH:
418 419 420
      data[0] = color->lch[0];
      data[1] = color->lch[1];
      data[2] = color->lch[2];
421
      break;
422 423 424 425
    case COLORITTO_DISPLAY_RGB:
      data[0] = color->display_rgb[0];
      data[1] = color->display_rgb[1];
      data[2] = color->display_rgb[2];
426 427
      break;
    case COLORITTO_SRGB:
428 429 430
      data[0] = color->srgb[0];
      data[1] = color->srgb[1];
      data[2] = color->srgb[2];
431 432 433
      break;

    case COLORITTO_SPECTRUM_ON_WHITE:
434
      /* just read it out */
435 436 437
      for (int i = 0; i < LUZ_SPECTRUM_BANDS; i ++)
        data[i] = color->on_white.bands[i];
      break;
438 439 440 441 442 443 444 445 446
    case COLORITTO_SPECTRUM_ON_WHITE_RAMP:
    case COLORITTO_SPECTRUM_ON_WHITE_AND_BLACK:
    case COLORITTO_SPECTRUM_ON_WHITE_AND_BLACK_RAMP:
      break;
  }
}

typedef struct
ColorLemma {
447 448
  float sx;
  float sy;
449
  float d;
450 451
  float radius;

452
  Coloritto *color;
453

454 455 456 457
  /* keeps many/most key=vals from parsing, but spectrum is normalized
     to internal representation - which should be at 5nm or 10nm and as wide
     as or wider than perceptual to yield accurate tristimulus values out.
    */
458 459

} ColorLemma;
460

461
LuzList *items = NULL;  /* list of color lemmas existing at all   */
462

463 464
Coloritto      *current = NULL;
int pal_no = 0;
465
int pal_replace = 0;
466 467 468

static int projection_model = COLORITTO_xyY;

469
#ifdef HAVE_MRG
470 471
MrgList *scrollback = NULL; /* scrollback buffer of free() able strings
                               with latest prepended */
472
#endif
473

474 475
char    *commandline = NULL; /* commandline being edited */

476 477
#define SCALEX     200.0
#define SCALEY     200.0
478
#define SRGB_SCALE 1.5
479

480 481 482 483 484 485 486
#include "luz-config.inc"

static void init_luz (void)
{
  if (!luz) luz = luz_new (config_internal);
}

487
Coloritto *coloritto_new (void)
488
{
489
  init_luz ();
490
  return calloc (sizeof (Coloritto), 1);
491 492
}

493 494 495 496 497 498 499 500 501 502 503 504 505
Coloritto *coloritto_ref (Coloritto *color)
{
  color->ref_count++;
  return color;
}

void coloritto_unref (Coloritto *color)
{
  color->ref_count--;
  if (color->ref_count < 0)
    free (color);
}

506 507
void coloritto_destroy (Coloritto *coloritto)
{
508
  coloritto_unref (coloritto);
509 510
}

511 512
void coloritto_set_key (Coloritto *color, const char *key,
                        const char *value)
513 514 515 516 517 518 519 520 521
{
  int i;
  for (i = 0; i < color->kvs; i++)
    if (color->keys[i] && !strcmp (key, color->keys[i]))
    {
      free (color->values[i]);
      color->values[i] = strdup (value);
      return;
    }
522 523 524 525 526
  if (color->kvs >= MAX_KV)
  {
    fprintf (stderr, "key-value count overflow\n");
    return;
  }
527 528 529 530

  color->keys[color->kvs] = strdup (key);
  color->values[color->kvs] = strdup (value);
  color->kvs++;
531
  color->keys[color->kvs] = NULL;
532 533
}

534
const char *coloritto_get_key (Coloritto *color, const char *key)
535 536 537 538 539 540 541
{
  for (int i = 0; i < color->kvs; i++)
    if (color->keys[i] && !strcmp (key, color->keys[i]))
      return color->values[i];
  return NULL;
}

542
void coloritto_set_name (Coloritto *color, const char *name)
543
{
544
  coloritto_set_key (color, "name", name);
545 546 547
}


548
const char *coloritto_get_name (Coloritto *color)
549
{
550
  return coloritto_get_key (color, "name");
551 552
}

553
#include "argvs.h"
554
#ifdef HAVE_MRG
555
Mrg *mrg = NULL;
556
#endif
557

558 559
static Coloritto * add_item (
      ColorittoDef color_type,
560
      float *triplet,
561
      float radius,
562
      ColorittoCollection *cc)
563
{
564
  ColorLemma *item = calloc (sizeof (ColorLemma), 1);
565 566 567
  item->color = coloritto_new ();
  init_luz (); // we do it here and in the actual public allocation for colorittos
  coloritto_set (item->color, color_type, triplet);
568
  item->radius = radius;
569
  luz_list_prepend (&items, item);
570 571
  if (cc)
    coloritto_collection_set_no (cc, -1, item->color);
572
  return item->color;
573 574
}

575 576 577 578 579 580
int cmd_todo (COMMAND_ARGS) /* "todo", 0, "", "print coloritto todolist" */
{
  printf ("%s", todo);
  return 0;
}

581
int cmd_locus (COMMAND_ARGS) /* "locus", 0, "", "adds the spectral locus as 3d color elements" */
582 583 584 585 586
{
  float xyz[3];
  const Spectrum *xs = luz_get_spectrum (luz, "observer_x");
  const Spectrum *ys = luz_get_spectrum (luz, "observer_y");
  const Spectrum *zs = luz_get_spectrum (luz, "observer_z");
587 588

  for (float nm = 400; nm < 690; nm += 1)
589
  {
590
    char name[32];
591 592 593
    xyz[0] = luz_spectrum_interpolate_nm (xs, nm);
    xyz[1] = luz_spectrum_interpolate_nm (ys, nm);
    xyz[2] = luz_spectrum_interpolate_nm (zs, nm);
594
    Coloritto *color = add_item (COLORITTO_XYZ, &xyz[0], 0.005, 0);
595
    sprintf (name, "%.0fnm", nm);
596
    coloritto_set_name (color, name);
597
  }
598
#ifdef HAVE_MRG
599
  mrg_queue_draw (mrg, NULL);
600
#endif
601 602 603
  return 0;
}

604 605 606 607
int cmd_rgb_primaries (COMMAND_ARGS) /* "rgb_primaries", 0, "", "adds the rgb primaries" */
{
  {
    float rgb[3]={1,0,0};
608
    add_item (COLORITTO_DISPLAY_RGB, &rgb[0], 0.01, 0);
609 610 611
  }
  {
    float rgb[3]={0,1,0};
612
    add_item (COLORITTO_DISPLAY_RGB, &rgb[0], 0.01, 0);
613 614 615
  }
  {
    float rgb[3]={0,0,1};
616
    add_item (COLORITTO_DISPLAY_RGB, &rgb[0], 0.01, 0);
617 618 619 620 621 622 623 624 625
  }
  return 0;
}


int cmd_rgb_primaries2 (COMMAND_ARGS) /* "srgb_primaries", 0, "", "adds the srgb primaries" */
{
  {
    float rgb[3]={1,0,0};
626
    add_item (COLORITTO_SRGB, &rgb[0], 0.01, 0);
627 628 629
  }
  {
    float rgb[3]={0,1,0};
630
    add_item (COLORITTO_SRGB, &rgb[0], 0.01, 0);
631 632 633
  }
  {
    float rgb[3]={0,0,1};
634
    add_item (COLORITTO_SRGB, &rgb[0], 0.01, 0);
635 636 637 638
  }
  return 0;
}

639 640
static void add_items ()
{
641
  //float lab[3];
642

643
#if 0
644
  float rgb[3];
645 646 647 648
  for (rgb[0] = 0.0; rgb[0] <= 1.0; rgb[0] += 0.1)
  for (rgb[1] = 0.0; rgb[1] <= 1.0; rgb[1] += 0.1)
  for (rgb[2] = 0.0; rgb[2] <= 1.0; rgb[2] += 0.1)
  {
649
    add_item (COLORITTO_RGB, &rgb[0], 0.01);
650 651 652
  }
#endif

653
#if 0
654 655 656

  lab[1] = 0.0;
  lab[2] = 0.0;
657
  for (lab[0] = 50.0; lab[0] <= 100.0; lab[0] += 30.0)
658
  {
659
    add_item (COLORITTO_LAB, &lab[0], 0.01);
660 661 662
  }


663 664
  lab[1] = 0.0;
  lab[2] = 0.0;
665 666
  for (lab[0] = 0.0; lab[0] <= 50.0; lab[0] += 30.0)
  {
667
    add_item (COLORITTO_LAB, &lab[0], 0.01);
668 669
  }

670
 #if 0
671 672 673
  lab[0] = 100.0;
  for (lab[1] = -200.0; lab[1] <= 200.0; lab[1] += 30.0)
  for (lab[2] = -200.0; lab[2] <= 200.0; lab[2] += 30.0)
674
  {
675
    add_item (COLORITTO_LAB, &lab[0], 0.0025);
676
  }
677
#endif
678

679 680 681
#endif
}

682 683 684 685 686 687 688 689 690
static void *list_nth_data (LuzList *list, int nth)
{
  LuzList *l = luz_list_nth(list, nth);
  if (l)
   return l->data;
  return NULL;
}


691 692 693
int cmd_ax (COMMAND_ARGS) /* "rainbow", 0, "", "draw cie lch rainbow" */
{
  float lch[3] = {50, 95.0, 0.0};
694
  for (lch[2] = 0.0; lch[2] <= 360.0; lch[2] += .5)
695
    add_item (COLORITTO_LCH, &lch[0], 0.0025, 0);
696 697 698 699 700

  return 0;
}


701
int cmd_lab (COMMAND_ARGS) /* "lab", 0, "", "switch to CIE Lab space in 3d view" */
702 703
{
  projection_model = COLORITTO_LAB;
704
#ifdef HAVE_MRG
705
  mrg_queue_draw (mrg, NULL);
706
#endif
707 708 709
  return 0;
}

710
int cmd_xyY (COMMAND_ARGS) /* "xyY", 0, "", "switch to xyY space in 3d view" */
711 712
{
  projection_model = COLORITTO_xyY;
713
#ifdef HAVE_MRG
714
  mrg_queue_draw (mrg, NULL);
715
#endif
716 717 718
  return 0;
}

719
int cmd_xyz (COMMAND_ARGS) /* "xyz", 0, "", "switch to CIE XYZ color space in 3d view" */
720 721
{
  projection_model = COLORITTO_XYZ;
722
#ifdef HAVE_MRG
723
  mrg_queue_draw (mrg, NULL);
724
#endif
725 726 727
  return 0;
}

728
int cmd_rgb (COMMAND_ARGS) /* "rgb", 0, "", "switch to sRGB view in 3d space" */
729 730
{
  projection_model = COLORITTO_SRGB;
731
#ifdef HAVE_MRG
732
  mrg_queue_draw (mrg, NULL);
733
#endif
734 735 736
  return 0;
}

737 738
#ifdef HAVE_MRG

739 740 741 742 743 744 745 746 747 748 749 750
#define ARGV_BOOL(name) \
  if (argv[1]) \
  {            \
    name = atoi(argv[1]); \
    if (!strcmp (argv[1], "on")) name = 1; \
  } \
  else \
   name = !name; \
  printf (#name " is %s", name?"on":"off"); \
  mrg_queue_draw (mrg, NULL); \
  return 0

751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766
#else

#define ARGV_BOOL(name) \
  if (argv[1]) \
  {            \
    name = atoi(argv[1]); \
    if (!strcmp (argv[1], "on")) name = 1; \
  } \
  else \
   name = !name; \
  printf (#name " is %s", name?"on":"off"); \
  return 0

#endif


767
static float rotation_angle = 0.0;
768 769 770 771
static int ortho = 1;
static int spin = 0;
static int axes = 1;
static int crosshair = 1;
772

773
int cmd_crosshair (COMMAND_ARGS) /* "crosshair", 0, "[on|off]", "toggle crosshair or set expiclit mode" */
774
{
775 776

  ARGV_BOOL(crosshair);
777
}
778

779
int cmd_ortho (COMMAND_ARGS) /* "ortho", 0, "[on|off]", "toggle orthographic or perspective rendering" */
780
{
781
  ARGV_BOOL(ortho);
782 783
}

784
int cmd_axes (COMMAND_ARGS) /* "axes", 0, "[on|off]", "toggle drawing of axis lines in 3d view" */
785
{
786
  ARGV_BOOL(axes);
787 788
}

789
int cmd_spin (COMMAND_ARGS) /* "spin", 0, "[on|off]", "toggle automatic spinning of 3d view" */
790
{
791
  ARGV_BOOL(spin);
792
}
793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811

LuzList *palettes = NULL;


static void update_current (void)
{
  ColorittoCollection *cc = list_nth_data (palettes, palette_no);
  LuzList *palette = cc->list;
  int no = 0;
  for (LuzList *l = palette; l; l = l->next, no ++)
  {
    if (no == pal_no)
    {
      current = l->data;
      return;
    }
  }
}

812

813 814 815 816 817
int cmd_pno (COMMAND_ARGS) /* "pno", 0, "[no]", "sets the current palette no" */
{
  if (argv[1])
  {
    palette_no = atoi(argv[1]);
818 819
    if (palette_no < 0)
     palette_no = 0;
820 821
    if (palette_no > luz_list_length (palettes) - 1)
     palette_no = luz_list_length (palettes) - 1;
822 823 824
  }
  else
    palette_no = 0;
825
#ifdef HAVE_MRG
826
  mrg_queue_draw (mrg, NULL);
827
#endif
828 829 830
  return 0;
}

831
int cmd_rotate (COMMAND_ARGS) /* "rotate", 0, "[degrees]", "sets the degrees of rotation around y axis in 3d view, with no arguments reset to 0" */
832 833 834
{
  if (argv[1])
  {
835
    rotation_angle = strtod(argv[1], NULL);
836
  }
837 838
  else
    rotation_angle = 0.0;
839
  spin = 0;
840
#ifdef HAVE_MRG
841
  mrg_queue_draw (mrg, NULL);
842
#endif
843 844 845
  return 0;
}

846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898
static float cos_rotation;
static float sin_rotation;

void xyz_to_xy (float x, float y, float z,
                float *sx, float *sy, float *d)
{
   {
     float u,v,w;

     u = x * cos_rotation - z * sin_rotation;
     v = y;
     w = x * sin_rotation + z * cos_rotation;

     x=u; y = v; z = w;

   }

   if (ortho)
   {
     if (d)   *d = z;
     if (sx) *sx = x + 0.5;
     if (sy) *sy = y + 0.5;
   }
   else
   {
     float eyed = 1.0;
     float dist = 1.0;

/*
                     ,`
              /    ,` |
             /|  ,`   |
            / |,`     | y
           / ,`sy     |
      eye /,`_|_______|
          \eyed+dist+z
           \  |
            \ |
             \|
              \

    sy / eyed  =  y / ( eyed + dist + z );

    sy =  y * eyed / ( eyed + dist + z ) + 0.5;
*/

     if (d) *d = dist + z;
     if (sx) *sx =  x * eyed / ( eyed + dist + z ) + 0.5;
     if (sy) *sy =  y * eyed / ( eyed + dist + z ) + 0.5;

   }
}

899 900 901 902 903 904 905 906 907 908 909 910
static int compare_delta_e (const void *a, const void *b, void *userdata)
{
  const Coloritto *la = a;
  const Coloritto *lb = b;

  if (la->delta_E < lb->delta_E)
    return -1;
  else if (la->delta_E > lb->delta_E)
    return 1;
  return 0;
}

911
#ifdef HAVE_MRG
912 913 914 915 916 917 918
static int compare_depths (const void *a, const void *b, void *userdata)
{
  const ColorLemma *la = a;
  const ColorLemma *lb = b;
  return (la->d - lb->d) * 100;
}

919 920 921
static void update_projection ()
{
  /* here 3d projection and rotation can be incorporated */
922
  if (spin)
923 924 925 926 927 928
  {
    rotation_angle += 0.02;
    mrg_queue_draw (mrg, NULL);
  }
  cos_rotation = cos (rotation_angle);
  sin_rotation = sin (rotation_angle);
929

930
  for (LuzList *l = items; l; l = l->next)
931
  {
932
    ColorLemma *item = l->data;
933 934
    coloritto_ensure (item->color, COLORITTO_SRGB);
    coloritto_ensure (item->color, COLORITTO_DISPLAY_RGB);
935 936 937
    float x, y, z;
    x = y = z = 0.0f;

938
    coloritto_ensure (item->color, projection_model);
939

940 941 942
    switch (projection_model)
    {
      case COLORITTO_xyY:
943 944 945
        x = item->color->xyY[0] - 0.5;
        y = 1.0-item->color->xyY[1] - 0.5;
        z = item->color->xyY[2] - 0.5;
946 947
        break;
      case COLORITTO_LAB:
948 949 950
        x = (item->color->lab[1])/SCALEX;
        y = item->color->lab[2]/SCALEX;
        z = (item->color->lab[0]-50)/SCALEY;
951 952
        break;
      case COLORITTO_SRGB:
953 954 955
        x = (item->color->srgb[0]-0.5) / SRGB_SCALE ;
        y = -(item->color->srgb[1]-0.5) / SRGB_SCALE ;
        z = (item->color->srgb[2]-0.5) / SRGB_SCALE ;
956

957 958 959
        break;

      case COLORITTO_XYZ:
960 961 962
        x = (item->color->xyz[0] - 0.5) / SRGB_SCALE;
        y = -(item->color->xyz[1] - 0.5) / SRGB_SCALE;
        z = (item->color->xyz[2] - 0.5) / SRGB_SCALE;
963 964
        break;
    }
965

966
    xyz_to_xy (x, y, z, &item->sx, &item->sy, &item->d);
967
  }
968
  luz_list_sort (&items, compare_depths, NULL);
969 970
}

971 972 973 974 975
static void do_cmd (MrgEvent *event, void *data1, void *data2) {
  argvs_eval (data1);
  mrg_event_stop_propagate (event);
  mrg_queue_draw (event->mrg, NULL);
}
976 977

static void select_item_cb (MrgEvent *event, void *data1, void *data2) {
978
  ColorittoCollection *cc = list_nth_data (palettes, palette_no);
979
  LuzList *palette = cc->list;
980

981
  current = data1;
982
  if (pal_replace)
983
  {
984
    int no  = 0;
985

986
    for (LuzList *l = palette; l; l = l->next, no ++)
987 988 989 990 991 992 993
    {
      if (no == pal_no)
      {
        l->data = current;
        break;
      }
    }
994 995 996 997
  }
  mrg_event_stop_propagate (event);
}

998
static void clicked_palette (MrgEvent *event, void *data1, void *data2) {
999
  ColorittoCollection *cc = list_nth_data (palettes, palette_no);
1000
  LuzList *palette = cc->list;
1001 1002 1003 1004 1005 1006 1007
  if (pal_no == (size_t) data2)
    {
      pal_replace = !pal_replace;
      mrg_event_stop_propagate (event);
      mrg_queue_draw (event->mrg, NULL);
      return;
    }
1008
  pal_no = (size_t) data2;   /* set the index# to activate */
1009 1010 1011
  pal_replace = 0;


1012
  if (luz_list_length (palette) <= pal_no)
1013 1014 1015 1016 1017 1018 1019 1020 1021 1022
    {
      if (!items)
        return;
#if 0
      /* should invent a new blank color starting from black instead */
      ColorLemma *lemma = items->data;
      Coloritto  *color = &lemma->color;
#else
      Coloritto  *color = coloritto_new ();
#endif
1023
      luz_list_append (&palette, color);
1024 1025
    }

1026
  update_current ();
1027 1028 1029 1030
  mrg_event_stop_propagate (event);
  mrg_queue_draw (event->mrg, NULL);
}

1031
static void evaluate_commandline (MrgEvent *event, void *data1, void *data2) {
1032 1033 1034
  argvs_eval (commandline);
  free (commandline);
  commandline = strdup ("");
1035
  mrg_set_cursor_pos (mrg, 0);
1036 1037 1038 1039
  mrg_event_stop_propagate (event);
  mrg_queue_draw (event->mrg, NULL);
}

1040 1041 1042 1043 1044
static void drag_void (MrgEvent *event, void *data1, void *data2)
{
  rotation_angle += event->delta_x / mrg_height (event->mrg) * 3.1415 * 2;
}

1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057
void select_none (void)
{
}

void make_collection_selection (void)
{
}

void save_selection (void)
{

}

1058 1059 1060 1061
//#define MAYBE_CENTER(x)  ( (x) * h + (w - h) / 2)
#define MAYBE_CENTER(x)  ((x) * h)


Øyvind "pippin" Kolås's avatar
Øyvind "pippin" Kolås committed
1062
static void ui_axes (Mrg *mrg, void *data)
1063 1064
{
  cairo_t *cr = mrg_cr (mrg);
Øyvind "pippin" Kolås's avatar
Øyvind "pippin" Kolås committed
1065
  float h = mrg_height (mrg);
1066 1067 1068 1069 1070 1071 1072 1073 1074 1075
  const Spectrum *xs = luz_get_spectrum (luz, "observer_x");
  const Spectrum *ys = luz_get_spectrum (luz, "observer_y");
  const Spectrum *zs = luz_get_spectrum (luz, "observer_z");

  switch (projection_model)
  {
    case COLORITTO_xyY:
      {
        float sx, sy;
#define C(x,y,z) \
1076
        xyz_to_xy ((x-0.5),1.0-y-0.5,(z-0.5), &sx, &sy, NULL); sx = MAYBE_CENTER(sx); sy *= h;
1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101

        cairo_new_path (cr);
        for (float nm = 400; nm < 690; nm += 2)
        {
           float xyz[3];
           xyz[0] = luz_spectrum_interpolate_nm (xs, nm);
           xyz[1] = luz_spectrum_interpolate_nm (ys, nm);
           xyz[2] = luz_spectrum_interpolate_nm (zs, nm);
           float sum = xyz[0] + xyz[1] + xyz[2];

           C(xyz[0]/sum,xyz[1]/sum,xyz[1]); cairo_line_to (cr, sx, sy);
        }
        cairo_close_path (cr);

        cairo_set_source_rgb (cr, 1,1,1);
        cairo_set_line_width (cr, 1);
        cairo_stroke (cr);
      }
      break;
#undef C

    case COLORITTO_XYZ:
      {
        float sx, sy;
#define C(x,y,z) \
1102
        xyz_to_xy ((x-0.5)/SRGB_SCALE,-(y-0.5)/SRGB_SCALE,(z-0.5)/SRGB_SCALE, &sx, &sy, NULL); sx = MAYBE_CENTER(sx); sy *= h;
1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150

        C(0,0,0); cairo_move_to (cr, sx, sy);
        C(1,0,0); cairo_line_to (cr, sx, sy);
        C(0,0,0); cairo_move_to (cr, sx, sy);
        C(0,1,0); cairo_line_to (cr, sx, sy);
        C(0,0,0); cairo_move_to (cr, sx, sy);
        C(0,0,1); cairo_line_to (cr, sx, sy);
        C(0,0,0); cairo_move_to (cr, sx, sy);
        C(1,1,1); cairo_line_to (cr, sx, sy);

        cairo_set_source_rgb (cr, 1,1,1);
        cairo_set_line_width (cr, 1);
        cairo_stroke (cr);
      }
      break;
    case COLORITTO_SRGB:
     {
        float sx, sy;
        cairo_set_line_width (cr, 1);

        C(0,0,0); cairo_move_to (cr, sx, sy);
        C(1,0,0); cairo_line_to (cr, sx, sy);
        cairo_set_source_rgb (cr, 1,0,0);
        cairo_stroke (cr);

        C(0,0,0); cairo_move_to (cr, sx, sy);
        C(0,1,0); cairo_line_to (cr, sx, sy);
        cairo_set_source_rgb (cr, 0,1,0);
        cairo_stroke (cr);

        C(0,0,0); cairo_move_to (cr, sx, sy);
        C(0,0,1); cairo_line_to (cr, sx, sy);
        cairo_set_source_rgb (cr, 0,0,1);
        cairo_stroke (cr);


        C(0,0,0); cairo_move_to (cr, sx, sy);
        C(1,1,1); cairo_line_to (cr, sx, sy);
        cairo_set_source_rgb (cr, 1,1,1);
        cairo_stroke (cr);

      }
      break;
#undef C
    case COLORITTO_LAB:
      {
        float sx, sy;
#define C(x,y,z) \
1151
        xyz_to_xy ((y)/SCALEX,z/SCALEX,(x-50)/SCALEY, &sx, &sy, NULL); sx = MAYBE_CENTER(sx); sy *= h;
1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163

        cairo_set_line_width (cr, 1);
        C(0,0,0); cairo_move_to (cr, sx, sy);
        C(100,0,0); cairo_line_to (cr, sx, sy);

        cairo_set_source_rgb (cr, 1,1,1);
        cairo_stroke (cr);
      }

      break;
  }
}
1164

1165 1166 1167 1168
// performance hack, cache sx and sy of current
static float current_sx;
static float current_sy;

Øyvind "pippin" Kolås's avatar
Øyvind "pippin" Kolås committed
1169
static void ui_items (Mrg *mrg, void *data)
1170
{
Øyvind "pippin" Kolås's avatar
Øyvind "pippin" Kolås committed
1171 1172
  float w = mrg_width (mrg);
  float h = mrg_height (mrg);
1173
  cairo_t *cr = mrg_cr (mrg);
1174
  cairo_set_antialias (cr, CAIRO_ANTIALIAS_FAST);
1175
  int length = luz_list_length (items);
1176 1177 1178 1179 1180

  cairo_new_path (cr);
  cairo_rectangle (cr, 0, 0, w, h);
  mrg_listen (mrg, MRG_DRAG, drag_void, NULL, NULL);
  cairo_new_path (cr);
1181
  //fprintf (stdout, "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n");
1182

1183
  for (LuzList *l = items; l; l = l->next)
1184
  {
1185
    ColorLemma *lemma = l->data;
1186
    Coloritto  *color = lemma->color;
1187 1188
    float rad_scale = 1.0;

1189 1190
    if (lemma->d < 0.0 && !ortho) continue;

1191 1192 1193 1194
    if (current == color){
       current_sx = lemma->sx;
       current_sy = lemma->sy;
    }
1195

1196
    cairo_arc (cr, MAYBE_CENTER (lemma->sx), lemma->sy * h,
1197
      lemma->radius * h * rad_scale, 0.0, M_PI * 2);
1198 1199

    if (length > 100)
1200
      cairo_set_source_rgba (cr, color->display_rgb[0], color->display_rgb[1], color->display_rgb[2], 0.65);
1201
    else
1202
      cairo_set_source_rgb (cr, color->display_rgb[0], color->display_rgb[1], color->display_rgb[2]);
1203 1204 1205

    mrg_listen (mrg, MRG_PRESS, select_item_cb, color, NULL);

1206
    cairo_fill (cr);
1207 1208 1209 1210 1211 1212 1213 1214 1215 1216


    if(0){
      const char *name = coloritto_get_name (color);
      char *tmp = strdup (name);
      int H = atoi (tmp+1);
      int L = atoi (tmp+6);
      int C = atoi (tmp+10);

      float triplet[3];
1217
      coloritto_get (color, COLORITTO_LCH, triplet);
1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228
      if (fabs (H-triplet[2] + fabs (L-triplet[0] + fabs (C - triplet[1])) > 7.5))
      {

      if(1)fprintf (stdout, "\n%s\nH%.2f L%.2f C%.2f - %i %i %i\n\n",
          coloritto_get_name (color),
          triplet[2], triplet[0], triplet[1], H, L, C);
      if(0)fprintf (stdout, "\n%s\nH%03.0f_L%02.0f_C%03.0f\n\n",
          coloritto_get_name (color),
          round(triplet[2]), round(triplet[0]), round(triplet[1]));
      }
    }
1229 1230 1231
  }
}

Øyvind "pippin" Kolås's avatar
Øyvind "pippin" Kolås committed
1232
void ui_color_info (Mrg *mrg, void *data, Coloritto *color)
1233 1234 1235
{
  MrgString *str = mrg_string_new ("");
  float em = mrg_em (mrg);
1236
  mrg_start (mrg, "div.colorinfo", NULL);
Øyvind "pippin" Kolås's avatar
Øyvind "pippin" Kolås committed
1237 1238
  //mrg_set_edge_left (mrg, mrg_width (mrg) - 6.4 * em * 6);
  mrg_set_edge_left (mrg, 0);
Øyvind "pippin" Kolås's avatar
Øyvind "pippin" Kolås committed
1239
  mrg_set_xy (mrg, 0, mrg_height (mrg) * 0.5);
1240

1241
  mrg_string_append_printf (str, "<div class='colorname'>%s</div>", coloritto_get_name (current));
1242 1243
    {
      float triplet[3];
1244
      coloritto_get (current, COLORITTO_LAB, triplet);
1245
      mrg_string_append_printf (str, "<div class='colorspaceinfo'><div class='colorspacename'>CIE Lab</div> <div class='colortriplet'>%.5f %.5f %.5f</div> %s</div>\n",
1246 1247 1248 1249 1250
          triplet[0], triplet[1], triplet[2], coloritto_is_set (current, COLORITTO_LAB)?"*":"");
    }

    {
      float triplet[3];
1251
      coloritto_get (current, COLORITTO_LCH, triplet);
1252
      mrg_string_append_printf (str, "<div class='colorspaceinfo'><div class='colorspacename'>CIE LCH</div> <div class='colortriplet'>%.5f %.5f %.5f</div> %s</div>\n",
1253 1254 1255 1256 1257
          triplet[0], triplet[1], triplet[2], coloritto_is_set (current, COLORITTO_LCH)?"*":"");
    }

    {
      float triplet[3];
1258
      coloritto_get (current, COLORITTO_XYZ, triplet);
1259
      mrg_string_append_printf (str, "<div class='colorspaceinfo'><div class='colorspacename'>CIE XYZ</div><div class='colortriplet'>%.5f %.5f %.5f</div> %s</div>\n",
1260 1261 1262 1263 1264
          triplet[0], triplet[1], triplet[2], coloritto_is_set (current, COLORITTO_XYZ)?"*":"");
    }

    {
      float triplet[3];
1265
      coloritto_get (current, COLORITTO_xyY, triplet);
1266
      mrg_string_append_printf (str, "<div class='colorspaceinfo'><div class='colorspacename'>CIE xyY</div><div class='colortriplet'>%.5f %.5f %.5f</div> %s</div>\n",
1267 1268 1269 1270 1271
          triplet[0], triplet[1], triplet[2], coloritto_is_set (current, COLORITTO_xyY)?"*":"");
    }

    {
      float triplet[3];
1272
      coloritto_get (current, COLORITTO_SRGB, triplet);
1273
      mrg_string_append_printf (str, "<div class='colorspaceinfo'><div class='colorspacename'>sRGB</div><div class='colortriplet'>%.4f %.4f %.4f</div> %s</div>\n",
1274 1275 1276
          triplet[0] * 255, triplet[1] * 255, triplet[2] * 255, coloritto_is_set (current, COLORITTO_SRGB)?"*":"");
    }

1277 1278
    {
      float triplet[3];
1279
      coloritto_get (current, COLORITTO_DISPLAY_RGB, triplet);
1280 1281 1282 1283
      mrg_string_append_printf (str, "<div class='colorspaceinfo'><div class='colorspacename'>dRGB</div><div class='colortriplet'>%.4f %.4f %.4f</div> %s</div>\n",
          triplet[0] * 255, triplet[1] * 255, triplet[2] * 255, coloritto_is_set (current, COLORITTO_DISPLAY_RGB)?"*":"");
    }

1284 1285 1286 1287 1288 1289 1290
  mrg_print_xml (mrg, str->str);
  mrg_string_free (str, 1);

   {
      float x0, y0, x1, y1;
      cairo_t *cr = mrg_cr (mrg);

1291
      Spectrum spec;
Øyvind "pippin" Kolås's avatar
Øyvind "pippin" Kolås committed
1292 1293
      x0 = 0;
      x1 = 6 * 6.6 * em;
Øyvind "pippin" Kolås's avatar
Øyvind "pippin" Kolås committed
1294 1295
      y1 = mrg_height (mrg);
      y0 = mrg_height (mrg) * 0.75;
1296 1297

      cairo_new_path (cr);
1298
      coloritto_get (current, COLORITTO_SPECTRUM_ON_WHITE, (float*)&spec);
1299 1300 1301 1302 1303 1304 1305 1306 1307 1308
      for (int i = 0; i < LUZ_SPECTRUM_BANDS; i++)
      {
        cairo_line_to (cr, x0 + (i * 1.0f / LUZ_SPECTRUM_BANDS) * (x1-x0),
                           y1 - spec.bands[i] * (y1-y0));
      }
      if (coloritto_is_set (current, COLORITTO_SPECTRUM_ON_WHITE))
        cairo_set_source_rgb (cr, 1, 1, 1);
      else
        cairo_set_source_rgba (cr, 1, 1, 1, 0.5);
      cairo_stroke (cr);
1309

1310
   }
1311

1312
  mrg_end (mrg);
Øyvind "pippin" Kolås's avatar
Øyvind "pippin" Kolås committed
1313
}
1314

Øyvind "pippin" Kolås's avatar
Øyvind "pippin" Kolås committed
1315 1316 1317
static void link_argvs_eval (MrgEvent *event, void *href, void *link_data) {
  argvs_eval (href);
  //fprintf (stderr, "%s\n", href);
1318 1319
}

Øyvind "pippin" Kolås's avatar
Øyvind "pippin" Kolås committed
1320
int ui_palette (Mrg *mrg, void *data)
1321
{
1322
  ColorittoCollection *cc = list_nth_data (palettes, palette_no);
1323
  LuzList *palette = cc->list;
Øyvind "pippin" Kolås's avatar
Øyvind "pippin" Kolås committed
1324 1325
  cairo_t *cr = mrg_cr (mrg);
  MrgString *str = mrg_string_new ("");
1326
  LuzList *l;
Øyvind "pippin" Kolås's avatar
Øyvind "pippin" Kolås committed
1327 1328 1329 1330 1331 1332