patterns.inc 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306
  1. /**--------------------------------------------------------------------------**\
  2. =================================
  3. y_bitmap - Generate bitmaps.
  4. =================================
  5. Description:
  6. Code to generate images on the server in the bitmap format. This is by far
  7. the simplest format to write to as it is just a huge array of colours (at
  8. least 24-bit bitmaps are, and we only do them).
  9. This file handles the patterns selectable in lines and fills.
  10. Legal:
  11. Version: MPL 1.1
  12. The contents of this file are subject to the Mozilla Public License Version
  13. 1.1 (the "License"); you may not use this file except in compliance with
  14. the License. You may obtain a copy of the License at
  15. http://www.mozilla.org/MPL/
  16. Software distributed under the License is distributed on an "AS IS" basis,
  17. WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  18. for the specific language governing rights and limitations under the
  19. License.
  20. The Original Code is the YSI utils include.
  21. The Initial Developer of the Original Code is Alex "Y_Less" Cole.
  22. Portions created by the Initial Developer are Copyright (C) 2011
  23. the Initial Developer. All Rights Reserved.
  24. Contributors:
  25. ZeeX, koolk, JoeBullet/Google63, g_aSlice/Slice
  26. Thanks:
  27. JoeBullet/Google63 - Handy arbitrary ASM jump code using SCTRL.
  28. ZeeX - Very productive conversations.
  29. koolk - IsPlayerinAreaEx code.
  30. TheAlpha - Danish translation.
  31. breadfish - German translation.
  32. Fireburn - Dutch translation.
  33. yom - French translation.
  34. 50p - Polish translation.
  35. Zamaroht - Spanish translation.
  36. Dracoblue, sintax, mabako, Xtreme, other coders - Producing other modes
  37. for me to strive to better.
  38. Pixels^ - Running XScripters where the idea was born.
  39. Matite - Pestering me to release it and using it.
  40. Very special thanks to:
  41. Thiadmer - PAWN, whose limits continue to amaze me!
  42. Kye/Kalcor - SA:MP.
  43. SA:MP Team past, present and future - SA:MP.
  44. Version:
  45. 0.1
  46. Changelog:
  47. 29/03/13:
  48. First version.
  49. Functions:
  50. Stock:
  51. -
  52. Inline:
  53. -
  54. Variables:
  55. Global:
  56. -
  57. \**--------------------------------------------------------------------------**/
  58. /*#define _PATTERN_FLAGS (0x01010000)
  59. #define _PATTERN_FADE_EDGE (0x01000000)
  60. #define _PATTERN_WIDTH (0xFE000000)
  61. #define _PATTERN_PADDING (0x00FE0000)
  62. #define _PATTERN_MASK (0x0000FFFF)
  63. // Pre-defined patterns.
  64. // ---------
  65. #define PATTERN_SOLID (0b1)
  66. // - - - - -
  67. #define PATTERN_DOTTED (0b10)
  68. // -- -- --
  69. #define PATTERN_DASHED (0b110)
  70. // - -- - --
  71. #define PATTERN_DOT_DASH (0b10110)
  72. // -- -- --
  73. #define PATTERN_WIDE_DASH (0b1100)
  74. // - - -- - - --
  75. #define PATTERN_DOT_DOT_DASH (0b1010110)
  76. // - -- --- --
  77. #define PATTERN_O_A_O_O_A_O_O_O_A_O_O_A (0b101101110110)*/
  78. /*stock const
  79. PATTERN_SOLID = "PATTERN_SOLID",
  80. PATTERN_DOTTED = "PATTERN_DOTTED",
  81. PATTERN_SOLID = "PATTERN_SOLID";*/
  82. /*#define PATTERN(%0) (_:_MK_PAT(0,%0@)&0xFFFF)
  83. #define _MK_PAT(%1,%0) _yPd:_yPD:_yPS:(%1,%0)
  84. // Dot.
  85. #define _yPd:%9(%1,.%0) _MK_PAT((%1)*2|1,%0)
  86. // Space.
  87. #define _yPD:%9(%1,-%0) _MK_PAT((%1)*2,%0)
  88. #define _yPS:%9(%1,) (%1)
  89. //#define _yPN:%9(%1,_%0) _MK_PAT((%1)*2%0)*/
  90. #define PATTERN_MASK_X (256)
  91. #define PATTERN_MASK_Y (256)
  92. stock
  93. // 8Kb
  94. YSI_gBitmapAlpha[PATTERN_MASK_Y][PATTERN_MASK_X char],
  95. YSI_gBitmapAlphaX = 1,
  96. YSI_gBitmapAlphaY = 1;
  97. //BitArray:YSI_gBitmapAlpha[PATTERN_MASK_Y]<PATTERN_MASK_X>;
  98. stock const
  99. YSI_gBitmapBlank[PATTERN_MASK_Y][PATTERN_MASK_X char];// = {Bit:0, ...};
  100. //BitArray:YSI_gBitmapBlank[PATTERN_MASK_Y]<PATTERN_MASK_X>;// = {Bit:0, ...};
  101. //stock Bitmap_ResetPattern()
  102. //{
  103. // YSI_gBitmapAlpha = YSI_gBitmapBlank;
  104. //}
  105. #define _Bitmap_ResetPattern() (YSI_gBitmapAlpha=YSI_gBitmapBlank)
  106. #define PATTERN(%0) (_:_PATTERN:(#%0))
  107. #define _PATTERN:(%0,%1) _PATTERN:(%0"\x2c;"#%1)
  108. stock _Bitmap_MakePattern(const pattern[], const posX, const posY, const offsetX, const offsetY)
  109. {
  110. static
  111. func[32] = "_BMP_PAT@";
  112. new
  113. pos = strfind(pattern, ",");
  114. func[9] = '\0',
  115. strcat(func, pattern);
  116. if (pos == -1)
  117. {
  118. if (funcidx(func) == -1) func = "_BMP_PAT@SOLID";
  119. CallLocalFunction(func, "iiiis", posX, posY, offsetX, offsetY, NULL);
  120. }
  121. else
  122. {
  123. func[pos + 9] = '\0';
  124. if (funcidx(func) == -1) func = "_BMP_PAT@SOLID";
  125. CallLocalFunction(func, "iiiis", posX, posY, offsetX, offsetY, pattern[pos]);
  126. }
  127. }
  128. stock _Bitmap_Param(const str[], const find[])
  129. {
  130. new
  131. pos = strfind(str, find, true),
  132. len = strlen(str),
  133. ch;
  134. if (0 < pos)
  135. {
  136. ch = str[pos - 1];
  137. if (ch == ' ' || ch == ',')
  138. {
  139. new
  140. p = pos;
  141. while (p != len)
  142. {
  143. ch = str[p];
  144. if (ch == '=')
  145. {
  146. return strval(str[++p]);
  147. }
  148. else if (ch == ',')
  149. {
  150. // There, but no value.
  151. return 0;
  152. }
  153. ++p;
  154. }
  155. return 0;
  156. }
  157. }
  158. return cellmin;
  159. }
  160. forward _BMP_PAT@SOLID(const posX, const posY, const offsetX, const offsetY, const flags[]);
  161. public _BMP_PAT@SOLID(const posX, const posY, const offsetX, const offsetY, const flags[])
  162. {
  163. #pragma unused posX, posY, offsetX, offsetY, flags
  164. YSI_gBitmapAlpha[0]{0} = 255,
  165. YSI_gBitmapAlphaX = 1,
  166. YSI_gBitmapAlphaY = 1;
  167. }
  168. forward _BMP_PAT@DIAGONAL(const posX, const posY, const offsetX, const offsetY, const flags[]);
  169. public _BMP_PAT@DIAGONAL(const posX, const posY, const offsetX, const offsetY, const flags[])
  170. {
  171. #pragma unused posX, posY, offsetX, offsetY, flags
  172. new
  173. // Alpha.
  174. stripe1 = _Bitmap_Param(flags, "stripe1"),
  175. stripe2 = _Bitmap_Param(flags, "stripe2"),
  176. left = _Bitmap_Param(flags, "right");
  177. if (stripe1 == cellmin) stripe1 = 8;
  178. if (stripe2 == cellmin) stripe2 = stripe1;
  179. // The stripes are the widths of the lines. Calculate the width of the
  180. // diagonal line horizontally.
  181. new
  182. Float:l1x = stripe1;
  183. l1x = floatsqroot(l1x * l1x / 2.0);
  184. new
  185. // The number of actual pixels across the first line.
  186. Float:l2w = stripe2,
  187. stripes = floatround((l1x + floatsqroot(l2w * l2w / 2.0)) * 2.0);
  188. // For 45 degrees there are only two types of partial pixels.
  189. stripe2 = floatround(l1x, floatround_floor);
  190. // Start pos.
  191. new
  192. pw = stripe2 / 2, // INTEGER division.
  193. mw = floatround(-l1x, floatround_floor),
  194. mp = mw - 1,
  195. pp = pw + 1;
  196. // Get the alpha parts.
  197. l2w = (l1x - stripe2),
  198. stripe2 = floatround(l2w * l2w / 2.0 * 255.0),
  199. l2w = 1.0 - l2w,
  200. stripe1 = floatround((1.0 - l2w * l2w / 2.0) * 255.0);
  201. // stripe2 is now the minor alpha, stripe1 is the major alpha.
  202. for (new y = 0; y != stripes; ++y)
  203. {
  204. for (new x = 0; x != stripes; ++x)
  205. {
  206. new
  207. xp = (x - mp) % stripes + mp;
  208. if (mw < xp < pw)
  209. YSI_gBitmapAlpha[y]{x} = 0xFF;
  210. else if (xp == mw || xp == pw)
  211. YSI_gBitmapAlpha[y]{x} = stripe1;
  212. else if (xp == mp || xp == pp)
  213. YSI_gBitmapAlpha[y]{x} = stripe2;
  214. else
  215. YSI_gBitmapAlpha[y]{x} = 0;
  216. }
  217. if (left)
  218. {
  219. ++pw,
  220. ++mw,
  221. ++mp,
  222. ++pp;
  223. }
  224. else
  225. {
  226. --pw,
  227. --mw,
  228. --mp,
  229. --pp;
  230. }
  231. }
  232. YSI_gBitmapAlphaX = stripes,
  233. YSI_gBitmapAlphaY = stripes;
  234. }
  235. forward _BMP_PAT@STRIPED(const posX, const posY, const offsetX, const offsetY, const flags[]);
  236. public _BMP_PAT@STRIPED(const posX, const posY, const offsetX, const offsetY, const flags[])
  237. {
  238. #pragma unused posX, posY, offsetX, offsetY, flags
  239. // Calculate the colour information.
  240. new
  241. // Alpha.
  242. stripe1 = _Bitmap_Param(flags, "stripe1"),
  243. stripe2 = _Bitmap_Param(flags, "stripe2"),
  244. stripes = _Bitmap_Param(flags, "horizontal");
  245. if (stripe1 == cellmin) stripe1 = 8;
  246. if (stripe2 == cellmin) stripe2 = stripe1;
  247. if (stripes)
  248. {
  249. stripes = stripe1 + stripe2,
  250. stripe2 = 0;
  251. while (stripe2 != stripe1)
  252. {
  253. YSI_gBitmapAlpha[0]{stripe2++} = 255;
  254. }
  255. while (stripe2 != stripes)
  256. {
  257. YSI_gBitmapAlpha[0]{stripe2++} = 0;
  258. }
  259. YSI_gBitmapAlphaX = stripes,
  260. YSI_gBitmapAlphaY = 1;
  261. }
  262. else
  263. {
  264. stripes = stripe1 + stripe2,
  265. stripe2 = 0;
  266. while (stripe2 != stripe1)
  267. {
  268. YSI_gBitmapAlpha[stripe2++]{0} = 255;
  269. }
  270. while (stripe2 != stripes)
  271. {
  272. YSI_gBitmapAlpha[stripe2++]{0} = 0;
  273. }
  274. YSI_gBitmapAlphaX = 1,
  275. YSI_gBitmapAlphaY = stripes;
  276. }
  277. }