Janilabo

Janilabo | TColorSettings.simba

Apr 20th, 2013
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pascal 19.80 KB | None | 0 0
  1. {==============================================================================]
  2.   Explanation: Constants for Simba's default CTS-related settings. Used in cs_CTS(Ex) functions.
  3. [==============================================================================}
  4. const
  5.   cs_DEFAULT_HUE_MODIFIER = 0.2;
  6.   cs_DEFAULT_SATURATION_MODIFIER = 0.2;
  7.   cs_DEFAULT_SENSITIVITY_MODIFIER = 1;
  8.   cs_DEFAULT_CTS = 1;
  9.  
  10. {==============================================================================]
  11.   Explanation: Used for easy storing/setting of Color (Tolerance) Speed settings.
  12. [==============================================================================}
  13. type
  14.   cs_TColorSettings = record
  15.     CTS: Integer;
  16.     modifier: record
  17.       hue, saturation, sensitivity: Extended;
  18.     end;
  19.   end;
  20.  
  21. {==============================================================================]
  22.   Explanation: Converts parameters to cs_TColorSettings type. Without Tolerance Speed 3 modifier!
  23. [==============================================================================}
  24. function cs_ToColorSettings(CTS: Integer; hueModifier, saturationModifier: Extended): cs_TColorSettings;
  25. begin
  26.   Result.CTS := CTS;
  27.   Result.modifier.hue := hueModifier;
  28.   Result.modifier.saturation := saturationModifier;
  29. end;
  30.  
  31. {==============================================================================]
  32.   Explanation: Converts parameters to cs_TColorSettings type. Contains field for Tolerance Speed 3 modifier aswell.
  33. [==============================================================================}
  34. function cs_ToColorSettings2(CTS: Integer; hueModifier, saturationModifier, sensitivityModifier: Extended): cs_TColorSettings;
  35. begin
  36.   Result.CTS := CTS;
  37.   Result.modifier.hue := hueModifier;
  38.   Result.modifier.saturation := saturationModifier;
  39.   Result.modifier.sensitivity := sensitivityModifier;
  40. end;
  41.  
  42. {==============================================================================]
  43.   Explanation: Returns current Color (Tolerance) Speed settings as TColorSettings.
  44. [==============================================================================}
  45. function cs_GetColorSettings: cs_TColorSettings;
  46. begin
  47.   Result.CTS := GetToleranceSpeed;
  48.   Result.modifier.sensitivity := GetToleranceSpeed3Modifier;
  49.   GetToleranceSpeed2Modifiers(Result.modifier.hue, Result.modifier.saturation);
  50. end;
  51.  
  52. {==============================================================================]
  53.   Explanation: Sets Color (Tolerance) Speed settings with settings.
  54. [==============================================================================}
  55. procedure cs_SetColorSettings(settings: cs_TColorSettings);
  56. begin
  57.   SetColorToleranceSpeed(settings.CTS);
  58.   SetToleranceSpeed2Modifiers(settings.modifier.hue, settings.modifier.saturation);
  59.   SetToleranceSpeed3Modifier(settings.modifier.sensitivity);
  60. end;
  61.  
  62. {==============================================================================]
  63.   function wrappers BELOW - they perform these steps:
  64.     1. Captures original (current) color settings in the begin to 'cs' variable
  65.     2. Sets custom color settings (by settings) to Simba
  66.     3. Performs the function [ex. FindColorTolerance()], just like it should - with custom settings!
  67.     4. Restores the original color settings from 'cs' variable to Simba
  68. [==============================================================================}
  69.  
  70. {==============================================================================]
  71.   Explanation: FindColorTolerance(), with parameter for custom color settings (settings)
  72. [==============================================================================}
  73. function cs_FindColorTolerance(var x, y: Integer; color, XS, YS, XE, YE, tol: Integer; settings: cs_TColorSettings): Boolean;
  74. var
  75.   cs: cs_TColorSettings;
  76. begin
  77.   cs := cs_GetColorSettings;
  78.   cs_SetColorSettings(settings);
  79.   Result := FindColorTolerance(x, y, color, XS, YS, XE, YE, tol);
  80.   cs_SetColorSettings(cs);
  81. end;
  82.  
  83. {==============================================================================]
  84.   Explanation: FindColorsTolerance(), with parameter for custom color settings (settings)
  85. [==============================================================================}
  86. function cs_FindColorsTolerance(var points: TPointArray; color, XS, YS, XE, YE, tol: Integer; settings: cs_TColorSettings): Boolean;
  87. var
  88.   cs: cs_TColorSettings;
  89. begin
  90.   cs := cs_GetColorSettings;
  91.   cs_SetColorSettings(settings);
  92.   Result := FindColorsTolerance(points, color, XS, YS, XE, YE, tol);
  93.   cs_SetColorSettings(cs);
  94. end;
  95.  
  96. {==============================================================================]
  97.   Explanation: FindColorSpiralTolerance(), with parameter for custom color settings (settings)
  98. [==============================================================================}
  99. function cs_FindColorSpiralTolerance(var x, y: Integer; color, XS, YS, XE, YE, tol: Integer; settings: cs_TColorSettings): Boolean;
  100. var
  101.   cs: cs_TColorSettings;
  102. begin
  103.   cs := cs_GetColorSettings;
  104.   cs_SetColorSettings(settings);
  105.   Result := FindColorSpiralTolerance(x, y, color, XS, YS, XE, YE, tol);
  106.   cs_SetColorSettings(cs);
  107. end;
  108.  
  109. {==============================================================================]
  110.   Explanation: FindColorsSpiralTolerance(), with parameter for custom color settings (settings)
  111. [==============================================================================}
  112. function cs_FindColorsSpiralTolerance(x, y: Integer; var points: TPointArray; color, XS, YS, XE, YE, tol: Integer; settings: cs_TColorSettings): Boolean;
  113. var
  114.   cs: cs_TColorSettings;
  115. begin
  116.   cs := cs_GetColorSettings;
  117.   cs_SetColorSettings(settings);
  118.   Result := FindColorsSpiralTolerance(x, y, points, color, XS, YS, XE, YE, tol);
  119.   cs_SetColorSettings(cs);
  120. end;
  121.  
  122. {==============================================================================]
  123.   Explanation: FindColoredAreaTolerance(), with parameter for custom color settings (settings)
  124. [==============================================================================}
  125. function cs_FindColoredAreaTolerance(var x, y: Integer; color, XS, YS, XE, YE, minArea, tol: Integer; settings: cs_TColorSettings): Boolean;
  126. var
  127.   cs: cs_TColorSettings;
  128. begin
  129.   cs := cs_GetColorSettings;
  130.   cs_SetColorSettings(settings);
  131.   Result := FindColoredAreaTolerance(x, y, color, XS, YS, XE, YE, minArea, tol);
  132.   cs_SetColorSettings(cs);
  133. end;
  134.  
  135. {==============================================================================]
  136.   Explanation: SimilarColors(), with parameter for custom color settings (settings)
  137. [==============================================================================}
  138. function cs_SimilarColors(col1, col2, tol: Integer; settings: cs_TColorSettings): Boolean;
  139. var
  140.   cs: cs_TColorSettings;
  141. begin
  142.   cs := cs_GetColorSettings;
  143.   cs_SetColorSettings(settings);
  144.   Result := SimilarColors(col1, col2, tol);
  145.   cs_SetColorSettings(cs);
  146. end;
  147.  
  148. {==============================================================================]
  149.   Explanation: CountColorTolerance(), with parameter for custom color settings (settings)
  150. [==============================================================================}
  151. function cs_CountColorTolerance(color, XS, YS, XE, YE, tol: Integer; settings: cs_TColorSettings): Integer;
  152. var
  153.   cs: cs_TColorSettings;
  154. begin
  155.   cs := cs_GetColorSettings;
  156.   cs_SetColorSettings(settings);
  157.   Result := CountColorTolerance(color, XS, YS, XE, YE, tol);
  158.   cs_SetColorSettings(cs);
  159. end;
  160.  
  161. {==============================================================================]
  162.   Explanation: FindBitmapToleranceIn(), with parameter for custom color settings (settings)
  163. [==============================================================================}
  164. function cs_FindBitmapToleranceIn(bitmap: Integer; var x, y: Integer; XS, YS, XE, YE, tol: Integer; settings: cs_TColorSettings): Boolean;
  165. var
  166.   cs: cs_TColorSettings;
  167. begin
  168.   cs := cs_GetColorSettings;
  169.   cs_SetColorSettings(settings);
  170.   Result := FindBitmapToleranceIn(bitmap, x, y, XS, YS, XE, YE, tol);
  171.   cs_SetColorSettings(cs);
  172. end;
  173.  
  174. {==============================================================================]
  175.   Explanation: FindBitmapSpiralTolerance(), with parameter for custom color settings (settings)
  176. [==============================================================================}
  177. function cs_FindBitmapSpiralTolerance(bitmap: Integer; var x, y: Integer; XS, YS, XE, YE, tol: Integer; settings: cs_TColorSettings): Boolean;
  178. var
  179.   cs: cs_TColorSettings;
  180. begin
  181.   cs := cs_GetColorSettings;
  182.   cs_SetColorSettings(settings);
  183.   Result := FindBitmapSpiralTolerance(bitmap, x, y, XS, YS, XE, YE, tol);
  184.   cs_SetColorSettings(cs);
  185. end;
  186.  
  187. {==============================================================================]
  188.   Explanation: FindBitmapsSpiralTolerance(), with parameter for custom color settings (settings)
  189. [==============================================================================}
  190. function cs_FindBitmapsSpiralTolerance(bitmap: Integer; x, y: Integer; var points: TPointArray; XS, YS, XE, YE, tol: Integer; settings: cs_TColorSettings): Boolean;
  191. var
  192.   cs: cs_TColorSettings;
  193. begin
  194.   cs := cs_GetColorSettings;
  195.   cs_SetColorSettings(settings);
  196.   Result := FindBitmapsSpiralTolerance(bitmap, x, y, points, XS, YS, XE, YE, tol);
  197.   cs_SetColorSettings(cs);
  198. end;
  199.  
  200. {==============================================================================]
  201.   Explanation: FindBitmapMaskTolerance(), with parameter for custom color settings (settings)
  202. [==============================================================================}
  203. function cs_FindBitmapMaskTolerance(mask: Integer; var x, y: Integer; XS, YS, XE, YE, tol, contourTol: Integer; settings: cs_TColorSettings): Boolean;
  204. var
  205.   cs: cs_TColorSettings;
  206. begin
  207.   cs := cs_GetColorSettings;
  208.   cs_SetColorSettings(settings);
  209.   Result := FindBitmapMaskTolerance(mask, x, y, XS, YS, XE, YE, tol, contourTol);
  210.   cs_SetColorSettings(cs);
  211. end;
  212.  
  213. {==============================================================================]
  214.   Explanation: FindDeformedBitmapToleranceIn(), with parameter for custom color settings (settings)
  215. [==============================================================================}
  216. function cs_FindDeformedBitmapToleranceIn(bitmap: Integer; var x, y: Integer; XS, YS, XE, YE, tol, range: Integer; allowPartialAccuracy: Boolean; var accuracy: Extended; settings: cs_TColorSettings): Boolean;
  217. var
  218.   cs: cs_TColorSettings;
  219. begin
  220.   cs := cs_GetColorSettings;
  221.   cs_SetColorSettings(settings);
  222.   Result := FindDeformedBitmapToleranceIn(bitmap, x, y, XS, YS, XE, YE, tol, range, allowPartialAccuracy, accuracy);
  223.   cs_SetColorSettings(cs);
  224. end;
  225.  
  226. {==============================================================================]
  227.   Explanation: GetTextAt(), with parameter for custom color settings (settings)
  228. [==============================================================================}
  229. function cs_GetTextAt(atX, atY, minvspacing, maxvspacing, hspacing, color, tol, len: Integer; font: string; settings: cs_TColorSettings): string;
  230. var
  231.   cs: cs_TColorSettings;
  232. begin
  233.   cs := cs_GetColorSettings;
  234.   cs_SetColorSettings(settings);
  235.   Result := GetTextAt(atX, atY, minvspacing, maxvspacing, hspacing, color, tol, len, font);
  236.   cs_SetColorSettings(cs);
  237. end;
  238.  
  239. {==============================================================================]
  240.   Explanation: GetTextAtEx(), with parameter for custom color settings (settings)
  241. [==============================================================================}
  242. function cs_GetTextAtEx(XS, YS, XE, YE, minvspacing, maxvspacing, hspacing, color, tol: Integer; font: string; settings: cs_TColorSettings): string;
  243. var
  244.   cs: cs_TColorSettings;
  245. begin
  246.   cs := cs_GetColorSettings;
  247.   cs_SetColorSettings(settings);
  248.   Result := GetTextAtEx(XS, YS, XE, YE, minvspacing, maxvspacing, hspacing, color, tol, font);
  249.   cs_SetColorSettings(cs);
  250. end;
  251.  
  252. {$IFNDEF Lape}
  253.   {==============================================================================]
  254.     Explanation: GetTextAtExWrap(), with parameter for custom color settings (settings)
  255.   [==============================================================================}
  256.   function cs_GetTextAtExWrap(XS, YS, XE, YE, minvspacing, maxvspacing, hspacing, color, tol: Integer; font: string; settings: cs_TColorSettings): string;
  257.   var
  258.     cs: cs_TColorSettings;
  259.   begin
  260.     cs := cs_GetColorSettings;
  261.     cs_SetColorSettings(settings);
  262.     Result := GetTextAtExWrap(XS, YS, XE, YE, minvspacing, maxvspacing, hspacing, color, tol, font);
  263.     cs_SetColorSettings(cs);
  264.   end;
  265. {$ENDIF}
  266.  
  267. {==============================================================================]
  268.   Explanation: FindMaskTolerance(), with parameter for custom color settings (settings)
  269. [==============================================================================}
  270. function cs_FindMaskTolerance(mask: TMask; var x, y: Integer; XS, YS, XE, YE, tol, contourTol: Integer; settings: cs_TColorSettings): Boolean;
  271. var
  272.   cs: cs_TColorSettings;
  273. begin
  274.   cs := cs_GetColorSettings;
  275.   cs_SetColorSettings(settings);
  276.   Result := FindMaskTolerance(mask, x, y, XS, YS, XE, YE, tol, contourTol);
  277.   cs_SetColorSettings(cs);
  278. end;
  279.  
  280. {==============================================================================]
  281.   Explanation: FindDTM(), with parameter for custom color settings (settings)
  282. [==============================================================================}
  283. function cs_FindDTM(DTM: Integer; var x, y: Integer; XS, YS, XE, YE: Integer; settings: cs_TColorSettings): Boolean;
  284. var
  285.   cs: cs_TColorSettings;
  286. begin
  287.   cs := cs_GetColorSettings;
  288.   cs_SetColorSettings(settings);
  289.   Result := FindDTM(DTM, x, y, XS, YS, XE, YE);
  290.   cs_SetColorSettings(cs);
  291. end;
  292.  
  293. {==============================================================================]
  294.   Explanation: FindDTM(), with parameter for custom color settings (settings)
  295. [==============================================================================}
  296. function cs_FindDTMs(DTM: Integer; var points: TPointArray; XS, YS, XE, YE: Integer; settings: cs_TColorSettings): Boolean;
  297. var
  298.   cs: cs_TColorSettings;
  299. begin
  300.   cs := cs_GetColorSettings;
  301.   cs_SetColorSettings(settings);
  302.   Result := FindDTMs(DTM, points, XS, YS, XE, YE);
  303.   cs_SetColorSettings(cs);
  304. end;
  305.  
  306. {==============================================================================]
  307.   Explanation: FindDTMRotatedSE(), with parameter for custom color settings (settings)
  308. [==============================================================================}
  309. function cs_FindDTMRotatedSE(DTM: Integer; var x, y: Integer; XS, YS, XE, YE: Integer; sAngle, eAngle, aStep: Extended; var aFound: Extended; settings: cs_TColorSettings): Boolean;
  310. var
  311.   cs: cs_TColorSettings;
  312. begin
  313.   cs := cs_GetColorSettings;
  314.   cs_SetColorSettings(settings);
  315.   Result := FindDTMRotatedSE(DTM, x, y, XS, YS, XE, YE, sAngle, eAngle, aStep, aFound);
  316.   cs_SetColorSettings(cs);
  317. end;
  318.  
  319. {==============================================================================]
  320.   Explanation: FindDTMRotatedAlternating(), with parameter for custom color settings (settings)
  321. [==============================================================================}
  322. function cs_FindDTMRotatedAlternating(DTM: Integer; var x, y: Integer; XS, YS, XE, YE: Integer; sAngle, eAngle, aStep: Extended; var aFound: Extended; settings: cs_TColorSettings): Boolean;
  323. var
  324.   cs: cs_TColorSettings;
  325. begin
  326.   cs := cs_GetColorSettings;
  327.   cs_SetColorSettings(settings);
  328.   Result := FindDTMRotatedAlternating(DTM, x, y, XS, YS, XE, YE, sAngle, eAngle, aStep, aFound);
  329.   cs_SetColorSettings(cs);
  330. end;
  331.  
  332. {==============================================================================]
  333.   Explanation: FindDTMsRotatedSE(), with parameter for custom color settings (settings)
  334. [==============================================================================}
  335. function cs_FindDTMsRotatedSE(DTM: Integer; var points: TPointArray; XS, YS, XE, YE: Integer; sAngle, eAngle, aStep: Extended; var aFound: T2DExtendedArray; settings: cs_TColorSettings): Boolean;
  336. var
  337.   cs: cs_TColorSettings;
  338. begin
  339.   cs := cs_GetColorSettings;
  340.   cs_SetColorSettings(settings);
  341.   Result := FindDTMsRotatedSE(DTM, points, XS, YS, XE, YE, sAngle, eAngle, aStep, aFound);
  342.   cs_SetColorSettings(cs);
  343. end;
  344.  
  345. {==============================================================================]
  346.   Explanation: FindDTMsRotatedAlternating(), with parameter for custom color settings (settings)
  347. [==============================================================================}
  348. function cs_FindDTMsRotatedAlternating(DTM: Integer; var points: TPointArray; XS, YS, XE, YE: Integer; sAngle, eAngle, aStep: Extended; var aFound: T2DExtendedArray; settings: cs_TColorSettings): Boolean;
  349. var
  350.   cs: cs_TColorSettings;
  351. begin
  352.   cs := cs_GetColorSettings;
  353.   cs_SetColorSettings(settings);
  354.   Result := FindDTMsRotatedAlternating(DTM, points, XS, YS, XE, YE, sAngle, eAngle, aStep, aFound);
  355.   cs_SetColorSettings(cs);
  356. end;
  357.  
  358. {==============================================================================]
  359.   Explanation: Returns cs_TColorSettings with CTS mode as x.
  360.                IF x is HIGHER than 3, then this function will set mode as the current one with GetColorToleranceSpeed.
  361.                ..and if its LOWER than 0 then this will return as Simba's DEFAULT CTS settings (note: this includes hue, saturation and sensitivity modifiers aswell). ;)
  362.   NOTE: If you set CTS as 2/3 with this function, this will set the CURRENT hue, saturation and sensitivity modifiers - with GetToleranceSpeed2Modifiers() & GetToleranceSpeed3Modifier.
  363. [==============================================================================}
  364. function cs_CTSEx(x: Integer): cs_TColorSettings;
  365. begin
  366.   case (x > -1) of
  367.     True:
  368.     begin
  369.       GetToleranceSpeed2Modifiers(Result.modifier.hue, Result.modifier.saturation);
  370.       Result.modifier.sensitivity := GetToleranceSpeed3Modifier;
  371.       case (x > 3) of
  372.         True: Result.CTS := GetToleranceSpeed;
  373.         False: Result.CTS := x;
  374.       end;
  375.     end;
  376.     False:
  377.     begin
  378.       Result.modifier.hue := cs_DEFAULT_HUE_MODIFIER;
  379.       Result.modifier.saturation := cs_DEFAULT_SATURATION_MODIFIER;
  380.       Result.modifier.sensitivity := cs_DEFAULT_SENSITIVITY_MODIFIER;
  381.       Result.CTS := cs_DEFAULT_CTS;
  382.     end;
  383.   end;
  384. end;
  385.  
  386. {==============================================================================]
  387.   Explanation: Returns cs_TColorSettings with Simba's DEFAULT CTS settings.
  388. [==============================================================================}
  389. function cs_CTS: cs_TColorSettings;
  390. begin
  391.   Result := cs_CTSEx(-1);
  392. end;
  393.  
  394. {==============================================================================]
  395.   Explanation: Returns cs_TColorSettings with CTS mode as 0.
  396. [==============================================================================}
  397. function cs_CTS0: cs_TColorSettings;
  398. begin
  399.   Result := cs_CTSEx(0);
  400. end;
  401.  
  402. {==============================================================================]
  403.   Explanation: Returns cs_TColorSettings with CTS mode as 1.
  404. [==============================================================================}
  405. function cs_CTS1: cs_TColorSettings;
  406. begin
  407.   Result := cs_CTSEx(1);
  408. end;
  409.  
  410. {==============================================================================]
  411.   Explanation: Returns cs_TColorSettings with CTS mode as 2.
  412.   NOTE: This will use the CURRENT hue and saturation modifiers - with GetToleranceSpeed2Modifiers().
  413. [==============================================================================}
  414. function cs_CTS2: cs_TColorSettings;
  415. begin
  416.   Result := cs_CTSEx(2);
  417. end;
  418.  
  419. {==============================================================================]
  420.   Explanation: Returns cs_TColorSettings with CTS mode as 3.
  421.   NOTE: This will use the CURRENT sensitivity modifier with GetToleranceSpeed3Modifier.
  422. [==============================================================================}
  423. function cs_CTS3: cs_TColorSettings;
  424. begin
  425.   Result := cs_CTSEx(3);
  426. end;
Advertisement
Add Comment
Please, Sign In to add comment