impl.inc 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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 misc functions.
  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 Bitmap:%0<>
  59. /*enum E_BITMAP
  60. {
  61. Alloc:E_BITMAP_MEMORY,
  62. E_BITMAP_SIZE,
  63. E_BITMAP_X,
  64. E_BITMAP_Y
  65. }*/
  66. #define Bitmap_Size(%0) (YSI_gMallocMemory[_:(%0) - 3])
  67. #define Bitmap_Width(%0) (YSI_gMallocMemory[_:(%0) - 2])
  68. #define Bitmap_Height(%0) (YSI_gMallocMemory[_:(%0) - 1])
  69. //#define Bitmap_Height(%0) (YSI_gMallocMemory[_:(%0) - 1])
  70. #define Bitmap_IndexInt(%9,%0,%1,%2) (_:(%9) + (_:(%2) * _:(%1)) + _:(%0))
  71. #define Bitmap_IndexCtx(%9,%0,%2) (_:(%9) + (_:(%2) * _:Bitmap_Width(%9)) + _:(%0))
  72. #define Bitmap_ReadInt(%9,%0,%1,%2) (YSI_gMallocMemory[_:(%9) + (_:(%2) * _:(%1)) + _:(%0)])
  73. #define Bitmap_WriteInt(%9,%0,%1,%2,%3) (YSI_gMallocMemory[_:(%9) + (_:(%2) * _:(%1)) + _:(%0)] = (%3))
  74. #define Bitmap_ReadCtx(%9,%0,%2) (YSI_gMallocMemory[_:(%9) + (_:(%2) * _:Bitmap_Width(%9)) + _:(%0)])
  75. #define Bitmap_WriteCtx(%9,%0,%2,%3) (YSI_gMallocMemory[_:(%9) + (_:(%2) * _:Bitmap_Width(%9)) + _:(%0)] = (%3))
  76. stock Bitmap:Bitmap_Create(xSize, ySize, bgColour = 0xFFFFFFFF)
  77. {
  78. new
  79. s = xSize * ySize,
  80. Alloc:d = malloc(s + 3);
  81. if (!d) //(ctx[E_BITMAP_MEMORY] = d))
  82. {
  83. P:E("Could not allocate bitmap buffer");
  84. return Bitmap:0;
  85. }
  86. //ctx[E_BITMAP_SIZE] = s;
  87. //ctx[E_BITMAP_X] = x;
  88. //ctx[E_BITMAP_Y] = y;
  89. // Raw malloc access. Set the background colour.
  90. memset(YSI_gMallocMemory[_:d + 3], s, bgColour | 0xFF);
  91. /*for (new y = 0; y != ySize; ++y)
  92. {
  93. for (new x = 0; x != xSize; ++x)
  94. {
  95. printf("(%02d, %02d) = %08x", x, y, YSI_gMallocMemory[
  96. }
  97. }*/
  98. mset(d, 0, s);
  99. mset(d, 1, xSize);
  100. mset(d, 2, ySize);
  101. // Hide the header data.
  102. return Bitmap:(_:d + 3);
  103. }
  104. stock Bitmap_Destroy(Bitmap:ctx)
  105. {
  106. if (ctx) free(Alloc:(_:ctx - 3));
  107. }