~ubuntu-branches/ubuntu/jaunty/gimp/jaunty-security

« back to all changes in this revision

Viewing changes to libgimpcolor/gimpcolorspace.c

  • Committer: Bazaar Package Importer
  • Author(s): Daniel Holbach
  • Date: 2007-05-02 16:33:03 UTC
  • mfrom: (1.1.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20070502163303-bvzhjzbpw8qglc4y
Tags: 2.3.16-1ubuntu1
* Resynchronized with Debian, remaining Ubuntu changes:
  - debian/rules: i18n magic.
* debian/control.in:
  - Maintainer: Ubuntu Core Developers <ubuntu-devel@lists.ubuntu.com>
* debian/patches/02_help-message.patch,
  debian/patches/03_gimp.desktop.in.in.patch,
  debian/patches/10_dont_show_wizard.patch: updated.
* debian/patches/04_composite-signedness.patch,
  debian/patches/05_add-letter-spacing.patch: dropped, used upstream.

Show diffs side-by-side

added added

removed removed

Lines of Context:
52
52
 **/
53
53
void
54
54
gimp_rgb_to_hsv (const GimpRGB *rgb,
55
 
                 GimpHSV       *hsv)
 
55
                 GimpHSV       *hsv)
56
56
{
57
57
  gdouble max, min, delta;
58
58
 
72
72
      if (rgb->r == max)
73
73
        {
74
74
          hsv->h = (rgb->g - rgb->b) / delta;
75
 
          if (hsv->h < 0.0)
76
 
            hsv->h += 6.0;
 
75
          if (hsv->h < 0.0)
 
76
            hsv->h += 6.0;
77
77
        }
78
78
      else if (rgb->g == max)
79
79
        {
104
104
 **/
105
105
void
106
106
gimp_hsv_to_rgb (const GimpHSV *hsv,
107
 
                 GimpRGB       *rgb)
 
107
                 GimpRGB       *rgb)
108
108
{
109
109
  gint    i;
110
110
  gdouble f, w, q, t;
211
211
      delta = max - min;
212
212
 
213
213
      if (delta == 0.0)
214
 
        delta = 1.0;
 
214
        delta = 1.0;
215
215
 
216
216
      if (rgb->r == max)
217
217
        {
269
269
 **/
270
270
void
271
271
gimp_hsl_to_rgb (const GimpHSL *hsl,
272
 
                 GimpRGB       *rgb)
 
272
                 GimpRGB       *rgb)
273
273
{
274
274
  g_return_if_fail (hsl != NULL);
275
275
  g_return_if_fail (rgb != NULL);
416
416
 **/
417
417
void
418
418
gimp_rgb_to_hwb (const GimpRGB *rgb,
419
 
                 gdouble       *hue,
420
 
                 gdouble       *whiteness,
421
 
                 gdouble       *blackness)
 
419
                 gdouble       *hue,
 
420
                 gdouble       *whiteness,
 
421
                 gdouble       *blackness)
422
422
{
423
423
  /* RGB are each on [0, 1]. W and B are returned on [0, 1] and H is        */
424
424
  /* returned on [0, 6]. Exception: H is returned UNDEFINED if W ==  1 - B. */
460
460
 **/
461
461
void
462
462
gimp_hwb_to_rgb (gdouble  hue,
463
 
                 gdouble  whiteness,
464
 
                 gdouble  blackness,
465
 
                 GimpRGB *rgb)
 
463
                 gdouble  whiteness,
 
464
                 gdouble  blackness,
 
465
                 GimpRGB *rgb)
466
466
{
467
467
  /* H is given on [0, 6] or UNDEFINED. whiteness and
468
468
   * blackness are given on [0, 1].
487
487
      f = h - i;
488
488
 
489
489
      if (i & 1)
490
 
        f = 1.0 - f;  /* if i is odd */
 
490
        f = 1.0 - f;  /* if i is odd */
491
491
 
492
492
      n = w + f * (v - w);     /* linear interpolation between w and v */
493
493
 
530
530
 **/
531
531
void
532
532
gimp_rgb_to_hsv_int (gint *red,
533
 
                     gint *green,
534
 
                     gint *blue)
 
533
                     gint *green,
 
534
                     gint *blue)
535
535
{
536
536
  gdouble  r, g, b;
537
537
  gdouble  h, s, v;
565
565
  else
566
566
    {
567
567
      if (r == v)
568
 
        h = 60.0 * (g - b) / delta;
 
568
        h = 60.0 * (g - b) / delta;
569
569
      else if (g == v)
570
 
        h = 120 + 60.0 * (b - r) / delta;
 
570
        h = 120 + 60.0 * (b - r) / delta;
571
571
      else
572
 
        h = 240 + 60.0 * (r - g) / delta;
 
572
        h = 240 + 60.0 * (r - g) / delta;
573
573
 
574
574
      if (h < 0.0)
575
 
        h += 360.0;
 
575
        h += 360.0;
576
576
      if (h > 360.0)
577
 
        h -= 360.0;
 
577
        h -= 360.0;
578
578
    }
579
579
 
580
580
  *red   = ROUND (h);
596
596
 **/
597
597
void
598
598
gimp_hsv_to_rgb_int (gint *hue,
599
 
                     gint *saturation,
600
 
                     gint *value)
 
599
                     gint *saturation,
 
600
                     gint *value)
601
601
{
602
602
  gdouble h, s, v, h_temp;
603
603
  gdouble f, p, q, t;
628
628
      t = v * (1.0 - (s * (1.0 - f)));
629
629
 
630
630
      switch (i)
631
 
        {
632
 
        case 0:
633
 
          *hue        = ROUND (v * 255.0);
634
 
          *saturation = ROUND (t * 255.0);
635
 
          *value      = ROUND (p * 255.0);
636
 
          break;
637
 
 
638
 
        case 1:
639
 
          *hue        = ROUND (q * 255.0);
640
 
          *saturation = ROUND (v * 255.0);
641
 
          *value      = ROUND (p * 255.0);
642
 
          break;
643
 
 
644
 
        case 2:
645
 
          *hue        = ROUND (p * 255.0);
646
 
          *saturation = ROUND (v * 255.0);
647
 
          *value      = ROUND (t * 255.0);
648
 
          break;
649
 
 
650
 
        case 3:
651
 
          *hue        = ROUND (p * 255.0);
652
 
          *saturation = ROUND (q * 255.0);
653
 
          *value      = ROUND (v * 255.0);
654
 
          break;
655
 
 
656
 
        case 4:
657
 
          *hue        = ROUND (t * 255.0);
658
 
          *saturation = ROUND (p * 255.0);
659
 
          *value      = ROUND (v * 255.0);
660
 
          break;
661
 
 
662
 
        case 5:
663
 
          *hue        = ROUND (v * 255.0);
664
 
          *saturation = ROUND (p * 255.0);
665
 
          *value      = ROUND (q * 255.0);
666
 
          break;
667
 
        }
 
631
        {
 
632
        case 0:
 
633
          *hue        = ROUND (v * 255.0);
 
634
          *saturation = ROUND (t * 255.0);
 
635
          *value      = ROUND (p * 255.0);
 
636
          break;
 
637
 
 
638
        case 1:
 
639
          *hue        = ROUND (q * 255.0);
 
640
          *saturation = ROUND (v * 255.0);
 
641
          *value      = ROUND (p * 255.0);
 
642
          break;
 
643
 
 
644
        case 2:
 
645
          *hue        = ROUND (p * 255.0);
 
646
          *saturation = ROUND (v * 255.0);
 
647
          *value      = ROUND (t * 255.0);
 
648
          break;
 
649
 
 
650
        case 3:
 
651
          *hue        = ROUND (p * 255.0);
 
652
          *saturation = ROUND (q * 255.0);
 
653
          *value      = ROUND (v * 255.0);
 
654
          break;
 
655
 
 
656
        case 4:
 
657
          *hue        = ROUND (t * 255.0);
 
658
          *saturation = ROUND (p * 255.0);
 
659
          *value      = ROUND (v * 255.0);
 
660
          break;
 
661
 
 
662
        case 5:
 
663
          *hue        = ROUND (v * 255.0);
 
664
          *saturation = ROUND (p * 255.0);
 
665
          *value      = ROUND (q * 255.0);
 
666
          break;
 
667
        }
668
668
    }
669
669
}
670
670
 
683
683
 **/
684
684
void
685
685
gimp_rgb_to_hsl_int (gint *red,
686
 
                     gint *green,
687
 
                     gint *blue)
 
686
                     gint *green,
 
687
                     gint *blue)
688
688
{
689
689
  gint    r, g, b;
690
690
  gdouble h, s, l;
718
718
      delta = (max - min);
719
719
 
720
720
      if (l < 128)
721
 
        s = 255 * (gdouble) delta / (gdouble) (max + min);
 
721
        s = 255 * (gdouble) delta / (gdouble) (max + min);
722
722
      else
723
 
        s = 255 * (gdouble) delta / (gdouble) (511 - max - min);
 
723
        s = 255 * (gdouble) delta / (gdouble) (511 - max - min);
724
724
 
725
725
      if (r == max)
726
 
        h = (g - b) / (gdouble) delta;
 
726
        h = (g - b) / (gdouble) delta;
727
727
      else if (g == max)
728
 
        h = 2 + (b - r) / (gdouble) delta;
 
728
        h = 2 + (b - r) / (gdouble) delta;
729
729
      else
730
 
        h = 4 + (r - g) / (gdouble) delta;
 
730
        h = 4 + (r - g) / (gdouble) delta;
731
731
 
732
732
      h = h * 42.5;
733
733
 
734
734
      if (h < 0)
735
 
        h += 255;
 
735
        h += 255;
736
736
      else if (h > 255)
737
 
        h -= 255;
 
737
        h -= 255;
738
738
    }
739
739
 
740
740
  *red   = ROUND (h);
755
755
 **/
756
756
gint
757
757
gimp_rgb_to_l_int (gint red,
758
 
                   gint green,
759
 
                   gint blue)
 
758
                   gint green,
 
759
                   gint blue)
760
760
{
761
761
  gint min, max;
762
762
 
776
776
 
777
777
static gint
778
778
gimp_hsl_value_int (gdouble n1,
779
 
                    gdouble n2,
780
 
                    gdouble hue)
 
779
                    gdouble n2,
 
780
                    gdouble hue)
781
781
{
782
782
  gdouble value;
783
783
 
812
812
 **/
813
813
void
814
814
gimp_hsl_to_rgb_int (gint *hue,
815
 
                     gint *saturation,
816
 
                     gint *lightness)
 
815
                     gint *saturation,
 
816
                     gint *lightness)
817
817
{
818
818
  gdouble h, s, l;
819
819
 
833
833
      gdouble m1, m2;
834
834
 
835
835
      if (l < 128)
836
 
        m2 = (l * (255 + s)) / 65025.0;
 
836
        m2 = (l * (255 + s)) / 65025.0;
837
837
      else
838
 
        m2 = (l + s - (l * s) / 255.0) / 255.0;
 
838
        m2 = (l + s - (l * s) / 255.0) / 255.0;
839
839
 
840
840
      m1 = (l / 127.5) - m2;
841
841
 
938
938
 * @saturation: Pointer to saturation channel (0..1)
939
939
 * @value:      Pointer to value channel (0..1)
940
940
 **/
941
 
 
942
941
void
943
 
gimp_rgb_to_hsv4 (guchar  *rgb,
944
 
                  gdouble *hue,
945
 
                  gdouble *saturation,
946
 
                  gdouble *value)
 
942
gimp_rgb_to_hsv4 (const guchar *rgb,
 
943
                  gdouble      *hue,
 
944
                  gdouble      *saturation,
 
945
                  gdouble      *value)
947
946
{
948
947
  gdouble red, green, blue;
949
948
  gdouble h, s, v;
981
980
      delta = max - min;
982
981
 
983
982
      if (delta == 0.0)
984
 
        delta = 1.0;
 
983
        delta = 1.0;
985
984
 
986
985
      if (red == max)
987
 
        h = (green - blue) / delta;
 
986
        h = (green - blue) / delta;
988
987
      else if (green == max)
989
 
        h = 2 + (blue - red) / delta;
 
988
        h = 2 + (blue - red) / delta;
990
989
      else if (blue == max)
991
 
        h = 4 + (red - green) / delta;
 
990
        h = 4 + (red - green) / delta;
992
991
 
993
992
      h /= 6.0;
994
993
 
995
994
      if (h < 0.0)
996
 
        h += 1.0;
 
995
        h += 1.0;
997
996
      else if (h > 1.0)
998
 
        h -= 1.0;
 
997
        h -= 1.0;
999
998
    }
1000
999
 
1001
1000
  *hue        = h;
1011
1010
 * @saturation: Saturation channel (0..1)
1012
1011
 * @value:      Value channel (0..1)
1013
1012
 **/
1014
 
 
1015
1013
void
1016
1014
gimp_hsv_to_rgb4 (guchar  *rgb,
1017
 
                  gdouble  hue,
1018
 
                  gdouble  saturation,
1019
 
                  gdouble  value)
 
1015
                  gdouble  hue,
 
1016
                  gdouble  saturation,
 
1017
                  gdouble  value)
1020
1018
{
1021
1019
  gdouble h, s, v;
1022
1020
  gdouble f, p, q, t;
1034
1032
      v = value;
1035
1033
 
1036
1034
      if (h == 6.0)
1037
 
        h = 0.0;
 
1035
        h = 0.0;
1038
1036
 
1039
1037
      f = h - (gint) h;
1040
1038
      p = v * (1.0 - s);
1042
1040
      t = v * (1.0 - s * (1.0 - f));
1043
1041
 
1044
1042
      switch ((int) h)
1045
 
        {
1046
 
        case 0:
1047
 
          hue        = v;
1048
 
          saturation = t;
1049
 
          value      = p;
1050
 
          break;
1051
 
 
1052
 
        case 1:
1053
 
          hue        = q;
1054
 
          saturation = v;
1055
 
          value      = p;
1056
 
          break;
1057
 
 
1058
 
        case 2:
1059
 
          hue        = p;
1060
 
          saturation = v;
1061
 
          value      = t;
1062
 
          break;
1063
 
 
1064
 
        case 3:
1065
 
          hue        = p;
1066
 
          saturation = q;
1067
 
          value      = v;
1068
 
          break;
1069
 
 
1070
 
        case 4:
1071
 
          hue        = t;
1072
 
          saturation = p;
1073
 
          value      = v;
1074
 
          break;
1075
 
 
1076
 
        case 5:
1077
 
          hue        = v;
1078
 
          saturation = p;
1079
 
          value      = q;
1080
 
          break;
1081
 
        }
 
1043
        {
 
1044
        case 0:
 
1045
          hue        = v;
 
1046
          saturation = t;
 
1047
          value      = p;
 
1048
          break;
 
1049
 
 
1050
        case 1:
 
1051
          hue        = q;
 
1052
          saturation = v;
 
1053
          value      = p;
 
1054
          break;
 
1055
 
 
1056
        case 2:
 
1057
          hue        = p;
 
1058
          saturation = v;
 
1059
          value      = t;
 
1060
          break;
 
1061
 
 
1062
        case 3:
 
1063
          hue        = p;
 
1064
          saturation = q;
 
1065
          value      = v;
 
1066
          break;
 
1067
 
 
1068
        case 4:
 
1069
          hue        = t;
 
1070
          saturation = p;
 
1071
          value      = v;
 
1072
          break;
 
1073
 
 
1074
        case 5:
 
1075
          hue        = v;
 
1076
          saturation = p;
 
1077
          value      = q;
 
1078
          break;
 
1079
        }
1082
1080
    }
1083
1081
 
1084
1082
  rgb[0] = ROUND (hue        * 255.0);