Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --- gem.c.old pá Ärn 24 14:13:21 2016
- +++ gem.c pá Ärn 24 13:54:49 2016
- @@ -55,6 +55,17 @@
- #include "magick/resize.h"
- #include "magick/transform.h"
- #include "magick/signature-private.h"
- +
- +/*
- + * constant to compare two float numbers.
- + *
- + * if (fabs(a-b) < EPSILON) { they are considered equal }
- + *
- + * please note that this EPSILON is suitable only for comparing small numbers
- + * in the range -10..10. For comparing bigger numbers we would need to use more
- + * elaborate solution.
- + */
- +#define EPSILON 0.00001
- /*
- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- @@ -297,7 +308,7 @@
- assert(red != (Quantum *) NULL);
- assert(green != (Quantum *) NULL);
- assert(blue != (Quantum *) NULL);
- - if (saturation == 0.0)
- + if (fabs(saturation) < EPSILON)
- {
- *red=ClampToQuantum(QuantumRange*brightness);
- *green=(*red);
- @@ -472,22 +483,41 @@
- /*
- Convert HSL to RGB colorspace.
- */
- + //printf ("ConvertHSLToRGB hue=%f, sat=%f, light=%f ?????????????????\n", hue, saturation, lightness);
- assert(red != (Quantum *) NULL);
- assert(green != (Quantum *) NULL);
- assert(blue != (Quantum *) NULL);
- h=hue*360.0;
- - if (lightness <= 0.5)
- + //printf ("??? h=%f\n", h);
- + if (lightness <= 0.5) {
- + //printf ("?? if 1\n");
- c=2.0*lightness*saturation;
- - else
- + }
- + else {
- + //printf ("?? if 2\n");
- c=(2.0-2.0*lightness)*saturation;
- + }
- + //printf ("??? c=%f\n", c);
- min=lightness-0.5*c;
- + //printf ("??? min=%f\n", min);
- + //printf ("??? h=%f\n", h);
- + //printf ("??? h/360.0=%f\n", h/360.0);
- + //printf ("??? floor(h/360.0)=%f\n", floor(h/360.0));
- + //printf ("??? 360.0*floor(h/360)=%f\n", 360.0*floor(h/360.0));
- + //printf ("??? h-360.0*floor(h/360)=%f\n", h-360.0*floor(h/360.0));
- h-=360.0*floor(h/360.0);
- + //printf ("??? h(1)=%f\n", h);
- h/=60.0;
- + //printf ("??? h(2)=%f\n", h);
- + //printf ("??? h=%f\n", h);
- x=c*(1.0-fabs(h-2.0*floor(h/2.0)-1.0));
- + //printf ("??? x=%f\n", x);
- + //printf ("??? floor(h)=%f\n", floor(h));
- switch ((int) floor(h))
- {
- case 0:
- {
- + //printf ("??? switch 0\n");
- r=min+c;
- g=min+x;
- b=min;
- @@ -495,6 +525,7 @@
- }
- case 1:
- {
- + //printf ("??? switch 1\n");
- r=min+x;
- g=min+c;
- b=min;
- @@ -502,6 +533,7 @@
- }
- case 2:
- {
- + //printf ("??? switch 2\n");
- r=min;
- g=min+c;
- b=min+x;
- @@ -509,6 +541,7 @@
- }
- case 3:
- {
- + //printf ("??? switch 3\n");
- r=min;
- g=min+x;
- b=min+c;
- @@ -516,6 +549,7 @@
- }
- case 4:
- {
- + //printf ("??? switch 4\n");
- r=min+x;
- g=min;
- b=min+c;
- @@ -523,6 +557,7 @@
- }
- case 5:
- {
- + //printf ("??? switch 5\n");
- r=min+c;
- g=min;
- b=min+x;
- @@ -530,14 +565,18 @@
- }
- default:
- {
- + //printf ("??? switch default\n");
- r=0.0;
- g=0.0;
- b=0.0;
- }
- }
- + //printf ("RGB: r=%f, g=%f, b=%f\n", r, g, b);
- + //printf ("RGB255: r=%f, g=%f, b=%f\n", r*255, g*255, b*255);
- *red=ClampToQuantum(QuantumRange*r);
- *green=ClampToQuantum(QuantumRange*g);
- *blue=ClampToQuantum(QuantumRange*b);
- + //printf ("RGB final: r=" QuantumFormat" g=" QuantumFormat " b=" QuantumFormat"\n", *red, *green, *blue);
- }
- /*
- @@ -695,7 +734,7 @@
- assert(green != (Quantum *) NULL);
- assert(blue != (Quantum *) NULL);
- v=1.0-blackness;
- - if (hue == -1.0)
- + if (fabs( hue - (-1.0)) < EPSILON)
- {
- *red=ClampToQuantum(QuantumRange*v);
- *green=ClampToQuantum(QuantumRange*v);
- @@ -880,7 +919,7 @@
- max=MagickMax(r,MagickMax(g,b));
- c=max-(double) MagickMin(r,MagickMin(g,b));
- h=0.0;
- - if (c == 0.0)
- + if (fabs(c) < EPSILON)
- h=0.0;
- else
- if (red == (Quantum) max)
- @@ -947,7 +986,7 @@
- max=MagickMax(r,MagickMax(g,b));
- c=max-(double) MagickMin(r,MagickMin(g,b));
- h=0.0;
- - if (c == 0.0)
- + if (fabs(c) < EPSILON)
- h=0.0;
- else
- if (red == (Quantum) max)
- @@ -1020,17 +1059,17 @@
- max=r > g ? r : g;
- if (b > max)
- max=b;
- - if (max == 0.0)
- + if (fabs(max) < EPSILON)
- return;
- delta=max-min;
- *saturation=delta/max;
- *brightness=QuantumScale*max;
- - if (delta == 0.0)
- + if (fabs(delta) < EPSILON)
- return;
- - if (r == max)
- + if (fabs(r - max) < EPSILON)
- *hue=(g-b)/delta;
- else
- - if (g == max)
- + if (fabs(g - max) < EPSILON)
- *hue=2.0+(b-r)/delta;
- else
- *hue=4.0+(r-g)/delta;
- @@ -1135,37 +1174,54 @@
- /*
- Convert RGB to HSL colorspace.
- */
- + //printf ("!!!! ConvertRGBToHSL red=" QuantumFormat ", green=" QuantumFormat ", blue=" QuantumFormat "\n", red, green, blue);
- + //printf ("!!!! ConvertRGBToHSL255 red=%f, green=%f, blud=%f\n", (double)red/255, (double)green/255, (double)blue/255);
- assert(hue != (double *) NULL);
- assert(saturation != (double *) NULL);
- assert(lightness != (double *) NULL);
- max=MagickMax(QuantumScale*red,MagickMax(QuantumScale*green,
- QuantumScale*blue));
- + //printf ("!!! max: %f\n", max);
- min=MagickMin(QuantumScale*red,MagickMin(QuantumScale*green,
- QuantumScale*blue));
- + //printf ("!!! min: %f\n", min);
- c=max-min;
- + //printf ("!!! c: %f\n", c);
- *lightness=(max+min)/2.0;
- + //printf ("!!! *lightness: %f\n", *lightness);
- + //printf ("!!! QuantumScale*red: %f\n", QuantumScale*red);
- + //printf ("!!! max - QuantumScale*red: %e\n", max-QuantumScale*red);
- if (c <= 0.0)
- {
- + //printf ("if 1\n");
- *hue=0.0;
- *saturation=0.0;
- return;
- }
- - if (max == (QuantumScale*red))
- + if (fabs(max - QuantumScale*red) < EPSILON)
- {
- + //printf ("if 2\n");
- *hue=(QuantumScale*green-QuantumScale*blue)/c;
- if ((QuantumScale*green) < (QuantumScale*blue))
- *hue+=6.0;
- }
- else
- - if (max == (QuantumScale*green))
- + {
- + //printf ("if 3\n");
- + if (fabs(max - QuantumScale*green) < EPSILON)
- *hue=2.0+(QuantumScale*blue-QuantumScale*red)/c;
- else
- *hue=4.0+(QuantumScale*red-QuantumScale*green)/c;
- + }
- *hue*=60.0/360.0;
- - if (*lightness <= 0.5)
- + //printf ("!!! *hue: %f\n", *hue);
- + if (*lightness <= 0.5) {
- *saturation=c/(2.0*(*lightness));
- - else
- + }
- + else {
- *saturation=c/(2.0-2.0*(*lightness));
- + }
- + //printf ("!!! *saturation: %f\n", *saturation);
- }
- /*
- @@ -1222,7 +1278,7 @@
- *saturation=0.0;
- return;
- }
- - if (max == (QuantumScale*red))
- + if (fabs(max - QuantumScale*red) < EPSILON)
- {
- *hue=(QuantumScale*green-QuantumScale*blue)/c;
- if ((QuantumScale*green) < (QuantumScale*blue))
- @@ -1229,7 +1285,7 @@
- *hue+=6.0;
- }
- else
- - if (max == (QuantumScale*green))
- + if (fabs(max - QuantumScale*green) < EPSILON)
- *hue=2.0+(QuantumScale*blue-QuantumScale*red)/c;
- else
- *hue=4.0+(QuantumScale*red-QuantumScale*green)/c;
- @@ -1290,13 +1346,13 @@
- v=MagickMax(r,MagickMax(g,b));
- *blackness=1.0-QuantumScale*v;
- *whiteness=QuantumScale*w;
- - if (v == w)
- + if (fabs(v - w) < EPSILON)
- {
- *hue=(-1.0);
- return;
- }
- - f=(r == w) ? g-b : ((g == w) ? b-r : r-g);
- - p=(r == w) ? 3.0 : ((g == w) ? 5.0 : 1.0);
- + f=(fabs(r - w) < EPSILON) ? g-b : ((fabs(g - w) < EPSILON) ? b-r : r-g);
- + p=(fabs(r - w) < EPSILON) ? 3.0 : ((fabs(g - w) < EPSILON) ? 5.0 : 1.0);
- *hue=(p-f/(v-1.0*w))/6.0;
- }
- @@ -1517,7 +1573,7 @@
- gamma,
- tau;
- - if (alpha == 0.0)
- + if (fabs(alpha) < EPSILON)
- alpha=1.0;
- beta=GetPseudoRandomValue(random_info);
- gamma=sqrt(-2.0*log(alpha));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement