SHARE
TWEET

Untitled

a guest Jun 24th, 2016 167 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. --- gem.c.old   pá črn 24 14:13:21 2016
  2. +++ gem.c   pá črn 24 13:54:49 2016
  3. @@ -55,6 +55,17 @@
  4.  #include "magick/resize.h"
  5.  #include "magick/transform.h"
  6.  #include "magick/signature-private.h"
  7. +
  8. +/*
  9. + * constant to compare two float numbers.
  10. + *
  11. + * if (fabs(a-b) < EPSILON) { they are considered equal }
  12. + *
  13. + * please note that this EPSILON is suitable only for comparing small numbers
  14. + * in the range -10..10. For comparing bigger numbers we would need to use more
  15. + * elaborate solution.
  16. + */
  17. +#define EPSILON 0.00001
  18.  
  19.  /*
  20.  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  21. @@ -297,7 +308,7 @@
  22.    assert(red != (Quantum *) NULL);
  23.    assert(green != (Quantum *) NULL);
  24.    assert(blue != (Quantum *) NULL);
  25. -  if (saturation == 0.0)
  26. +  if (fabs(saturation) < EPSILON)
  27.      {
  28.        *red=ClampToQuantum(QuantumRange*brightness);
  29.        *green=(*red);
  30. @@ -472,22 +483,41 @@
  31.    /*
  32.      Convert HSL to RGB colorspace.
  33.    */
  34. +  //printf ("ConvertHSLToRGB hue=%f, sat=%f, light=%f ?????????????????\n", hue, saturation, lightness);
  35.    assert(red != (Quantum *) NULL);
  36.    assert(green != (Quantum *) NULL);
  37.    assert(blue != (Quantum *) NULL);
  38.    h=hue*360.0;
  39. -  if (lightness <= 0.5)
  40. +  //printf ("??? h=%f\n", h);
  41. +  if (lightness <= 0.5) {
  42. +    //printf ("?? if 1\n");
  43.      c=2.0*lightness*saturation;
  44. -  else
  45. +  }
  46. +  else {
  47. +    //printf ("?? if 2\n");
  48.      c=(2.0-2.0*lightness)*saturation;
  49. +  }
  50. +  //printf ("??? c=%f\n", c);
  51.    min=lightness-0.5*c;
  52. +  //printf ("??? min=%f\n", min);
  53. +  //printf ("??? h=%f\n", h);
  54. +  //printf ("??? h/360.0=%f\n", h/360.0);
  55. +  //printf ("??? floor(h/360.0)=%f\n", floor(h/360.0));
  56. +  //printf ("??? 360.0*floor(h/360)=%f\n", 360.0*floor(h/360.0));
  57. +  //printf ("??? h-360.0*floor(h/360)=%f\n", h-360.0*floor(h/360.0));
  58.    h-=360.0*floor(h/360.0);
  59. +  //printf ("??? h(1)=%f\n", h);
  60.    h/=60.0;
  61. +  //printf ("??? h(2)=%f\n", h);
  62. +  //printf ("??? h=%f\n", h);
  63.    x=c*(1.0-fabs(h-2.0*floor(h/2.0)-1.0));
  64. +  //printf ("??? x=%f\n", x);
  65. +  //printf ("??? floor(h)=%f\n", floor(h));
  66.    switch ((int) floor(h))
  67.    {
  68.      case 0:
  69.      {
  70. +      //printf ("??? switch 0\n");
  71.        r=min+c;
  72.        g=min+x;
  73.        b=min;
  74. @@ -495,6 +525,7 @@
  75.      }
  76.      case 1:
  77.      {
  78. +      //printf ("??? switch 1\n");
  79.        r=min+x;
  80.        g=min+c;
  81.        b=min;
  82. @@ -502,6 +533,7 @@
  83.      }
  84.      case 2:
  85.      {
  86. +      //printf ("??? switch 2\n");
  87.        r=min;
  88.        g=min+c;
  89.        b=min+x;
  90. @@ -509,6 +541,7 @@
  91.      }
  92.      case 3:
  93.      {
  94. +      //printf ("??? switch 3\n");
  95.        r=min;
  96.        g=min+x;
  97.        b=min+c;
  98. @@ -516,6 +549,7 @@
  99.      }
  100.      case 4:
  101.      {
  102. +      //printf ("??? switch 4\n");
  103.        r=min+x;
  104.        g=min;
  105.        b=min+c;
  106. @@ -523,6 +557,7 @@
  107.      }
  108.      case 5:
  109.      {
  110. +      //printf ("??? switch 5\n");
  111.        r=min+c;
  112.        g=min;
  113.        b=min+x;
  114. @@ -530,14 +565,18 @@
  115.      }
  116.      default:
  117.      {
  118. +      //printf ("??? switch default\n");
  119.        r=0.0;
  120.        g=0.0;
  121.        b=0.0;
  122.      }
  123.    }
  124. +  //printf ("RGB: r=%f, g=%f, b=%f\n", r, g, b);
  125. +  //printf ("RGB255: r=%f, g=%f, b=%f\n", r*255, g*255, b*255);
  126.    *red=ClampToQuantum(QuantumRange*r);
  127.    *green=ClampToQuantum(QuantumRange*g);
  128.    *blue=ClampToQuantum(QuantumRange*b);
  129. +  //printf ("RGB final: r=" QuantumFormat" g=" QuantumFormat " b=" QuantumFormat"\n", *red, *green, *blue);
  130.  }
  131.  
  132.  /*
  133. @@ -695,7 +734,7 @@
  134.    assert(green != (Quantum *) NULL);
  135.    assert(blue != (Quantum *) NULL);
  136.    v=1.0-blackness;
  137. -  if (hue == -1.0)
  138. +  if (fabs( hue - (-1.0)) < EPSILON)
  139.      {
  140.        *red=ClampToQuantum(QuantumRange*v);
  141.        *green=ClampToQuantum(QuantumRange*v);
  142. @@ -880,7 +919,7 @@
  143.    max=MagickMax(r,MagickMax(g,b));
  144.    c=max-(double) MagickMin(r,MagickMin(g,b));
  145.    h=0.0;
  146. -  if (c == 0.0)
  147. +  if (fabs(c) < EPSILON)
  148.      h=0.0;
  149.    else
  150.      if (red == (Quantum) max)
  151. @@ -947,7 +986,7 @@
  152.    max=MagickMax(r,MagickMax(g,b));
  153.    c=max-(double) MagickMin(r,MagickMin(g,b));
  154.    h=0.0;
  155. -  if (c == 0.0)
  156. +  if (fabs(c) < EPSILON)
  157.      h=0.0;
  158.    else
  159.      if (red == (Quantum) max)
  160. @@ -1020,17 +1059,17 @@
  161.    max=r > g ? r : g;
  162.    if (b > max)
  163.      max=b;
  164. -  if (max == 0.0)
  165. +  if (fabs(max) < EPSILON)
  166.      return;
  167.    delta=max-min;
  168.    *saturation=delta/max;
  169.    *brightness=QuantumScale*max;
  170. -  if (delta == 0.0)
  171. +  if (fabs(delta) < EPSILON)
  172.      return;
  173. -  if (r == max)
  174. +  if (fabs(r - max) < EPSILON)
  175.      *hue=(g-b)/delta;
  176.    else
  177. -    if (g == max)
  178. +    if (fabs(g - max) < EPSILON)
  179.        *hue=2.0+(b-r)/delta;
  180.      else
  181.        *hue=4.0+(r-g)/delta;
  182. @@ -1135,37 +1174,54 @@
  183.    /*
  184.      Convert RGB to HSL colorspace.
  185.    */
  186. +  //printf ("!!!! ConvertRGBToHSL red=" QuantumFormat ", green=" QuantumFormat ", blue=" QuantumFormat "\n", red, green, blue);
  187. +  //printf ("!!!! ConvertRGBToHSL255 red=%f, green=%f, blud=%f\n", (double)red/255, (double)green/255, (double)blue/255);
  188.    assert(hue != (double *) NULL);
  189.    assert(saturation != (double *) NULL);
  190.    assert(lightness != (double *) NULL);
  191.    max=MagickMax(QuantumScale*red,MagickMax(QuantumScale*green,
  192.      QuantumScale*blue));
  193. +  //printf ("!!! max: %f\n", max);
  194.    min=MagickMin(QuantumScale*red,MagickMin(QuantumScale*green,
  195.      QuantumScale*blue));
  196. +  //printf ("!!! min: %f\n", min);
  197.    c=max-min;
  198. +  //printf ("!!! c: %f\n", c);
  199.    *lightness=(max+min)/2.0;
  200. +  //printf ("!!! *lightness: %f\n", *lightness);
  201. +  //printf ("!!! QuantumScale*red: %f\n", QuantumScale*red);
  202. +  //printf ("!!! max - QuantumScale*red: %e\n", max-QuantumScale*red);
  203.    if (c <= 0.0)
  204.      {
  205. +      //printf ("if 1\n");
  206.        *hue=0.0;
  207.        *saturation=0.0;
  208.        return;
  209.      }
  210. -  if (max == (QuantumScale*red))
  211. +  if (fabs(max - QuantumScale*red) < EPSILON)
  212.      {
  213. +      //printf ("if 2\n");
  214.        *hue=(QuantumScale*green-QuantumScale*blue)/c;
  215.        if ((QuantumScale*green) < (QuantumScale*blue))
  216.          *hue+=6.0;
  217.      }
  218.    else
  219. -    if (max == (QuantumScale*green))
  220. +  {
  221. +      //printf ("if 3\n");
  222. +    if (fabs(max - QuantumScale*green) < EPSILON)
  223.        *hue=2.0+(QuantumScale*blue-QuantumScale*red)/c;
  224.      else
  225.        *hue=4.0+(QuantumScale*red-QuantumScale*green)/c;
  226. +  }
  227.    *hue*=60.0/360.0;
  228. -  if (*lightness <= 0.5)
  229. +  //printf ("!!! *hue: %f\n", *hue);
  230. +  if (*lightness <= 0.5) {
  231.      *saturation=c/(2.0*(*lightness));
  232. -  else
  233. +  }
  234. +  else {
  235.      *saturation=c/(2.0-2.0*(*lightness));
  236. +  }
  237. +  //printf ("!!! *saturation: %f\n", *saturation);
  238.  }
  239.  
  240.  /*
  241. @@ -1222,7 +1278,7 @@
  242.        *saturation=0.0;
  243.        return;
  244.      }
  245. -  if (max == (QuantumScale*red))
  246. +  if (fabs(max - QuantumScale*red) < EPSILON)
  247.      {
  248.        *hue=(QuantumScale*green-QuantumScale*blue)/c;
  249.        if ((QuantumScale*green) < (QuantumScale*blue))
  250. @@ -1229,7 +1285,7 @@
  251.          *hue+=6.0;
  252.      }
  253.    else
  254. -    if (max == (QuantumScale*green))
  255. +    if (fabs(max - QuantumScale*green) < EPSILON)
  256.        *hue=2.0+(QuantumScale*blue-QuantumScale*red)/c;
  257.      else
  258.        *hue=4.0+(QuantumScale*red-QuantumScale*green)/c;
  259. @@ -1290,13 +1346,13 @@
  260.    v=MagickMax(r,MagickMax(g,b));
  261.    *blackness=1.0-QuantumScale*v;
  262.    *whiteness=QuantumScale*w;
  263. -  if (v == w)
  264. +  if (fabs(v - w) < EPSILON)
  265.      {
  266.        *hue=(-1.0);
  267.        return;
  268.      }
  269. -  f=(r == w) ? g-b : ((g == w) ? b-r : r-g);
  270. -  p=(r == w) ? 3.0 : ((g == w) ? 5.0 : 1.0);
  271. +  f=(fabs(r - w) < EPSILON) ? g-b : ((fabs(g - w) < EPSILON) ? b-r : r-g);
  272. +  p=(fabs(r - w) < EPSILON) ? 3.0 : ((fabs(g - w) < EPSILON) ? 5.0 : 1.0);
  273.    *hue=(p-f/(v-1.0*w))/6.0;
  274.  }
  275.  
  276. @@ -1517,7 +1573,7 @@
  277.          gamma,
  278.          tau;
  279.  
  280. -      if (alpha == 0.0)
  281. +      if (fabs(alpha) < EPSILON)
  282.          alpha=1.0;
  283.        beta=GetPseudoRandomValue(random_info);
  284.        gamma=sqrt(-2.0*log(alpha));
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top