Guest User

Untitled

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