Image.lua 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. class "Image"
  2. IMAGE_RGB = 0
  3. IMAGE_RGBA = 1
  4. function Image:Image(...)
  5. for k,v in pairs(arg) do
  6. if type(v) == "table" then
  7. if v.__ptr ~= nil then
  8. arg[k] = v.__ptr
  9. end
  10. end
  11. end
  12. if self.__ptr == nil and arg[1] ~= "__skip_ptr__" then
  13. self.__ptr = Polycore.Image(unpack(arg))
  14. end
  15. end
  16. function Image:loadImage(fileName)
  17. local retVal = Polycore.Image_loadImage(self.__ptr, fileName)
  18. return retVal
  19. end
  20. function Image:loadPNG(fileName)
  21. local retVal = Polycore.Image_loadPNG(self.__ptr, fileName)
  22. return retVal
  23. end
  24. function Image:createEmpty(width, height)
  25. local retVal = Polycore.Image_createEmpty(self.__ptr, width, height)
  26. end
  27. function Image:fill(r, g, b, a)
  28. local retVal = Polycore.Image_fill(self.__ptr, r, g, b, a)
  29. end
  30. function Image:setPixel(x, y, r, g, b, a)
  31. local retVal = Polycore.Image_setPixel(self.__ptr, x, y, r, g, b, a)
  32. end
  33. function Image:getPixel(x, y)
  34. local retVal = Polycore.Image_getPixel(self.__ptr, x, y)
  35. if Polycore.__ptr_lookup[retVal] ~= nil then
  36. return Polycore.__ptr_lookup[retVal]
  37. else
  38. Polycore.__ptr_lookup[retVal] = Color("__skip_ptr__")
  39. Polycore.__ptr_lookup[retVal].__ptr = retVal
  40. return Polycore.__ptr_lookup[retVal]
  41. end
  42. end
  43. function Image:setAAPixel(x, y, col)
  44. local retVal = Polycore.Image_setAAPixel(self.__ptr, x, y, col.__ptr)
  45. end
  46. function Image:swap(v1, v2)
  47. local retVal = Polycore.Image_swap(self.__ptr, v1.__ptr, v2.__ptr)
  48. end
  49. function Image:line(x0, y0, x1, y1, col)
  50. local retVal = Polycore.Image_line(self.__ptr, x0, y0, x1, y1, col.__ptr)
  51. end
  52. function Image:moveTo(x, y)
  53. local retVal = Polycore.Image_moveTo(self.__ptr, x, y)
  54. end
  55. function Image:move(x, y)
  56. local retVal = Polycore.Image_move(self.__ptr, x, y)
  57. end
  58. function Image:lineTo(x, y, col)
  59. local retVal = Polycore.Image_lineTo(self.__ptr, x, y, col.__ptr)
  60. end
  61. function Image:drawRect(x, y, w, h, col)
  62. local retVal = Polycore.Image_drawRect(self.__ptr, x, y, w, h, col.__ptr)
  63. end
  64. function Image:perlinNoise(seed, alpha)
  65. local retVal = Polycore.Image_perlinNoise(self.__ptr, seed, alpha)
  66. end
  67. function Image:fastBlur(blurSize)
  68. local retVal = Polycore.Image_fastBlur(self.__ptr, blurSize)
  69. end
  70. function Image:fastBlurVert(blurSize)
  71. local retVal = Polycore.Image_fastBlurVert(self.__ptr, blurSize)
  72. end
  73. function Image:fastBlurHor(blurSize)
  74. local retVal = Polycore.Image_fastBlurHor(self.__ptr, blurSize)
  75. end
  76. function Image:darken(amt, color, alpha)
  77. local retVal = Polycore.Image_darken(self.__ptr, amt, color, alpha)
  78. end
  79. function Image:lighten(amt, color, alpha)
  80. local retVal = Polycore.Image_lighten(self.__ptr, amt, color, alpha)
  81. end
  82. function Image:multiply(amt, color, alpha)
  83. local retVal = Polycore.Image_multiply(self.__ptr, amt, color, alpha)
  84. end
  85. function Image:getBrushX()
  86. local retVal = Polycore.Image_getBrushX(self.__ptr)
  87. return retVal
  88. end
  89. function Image:getBrushY()
  90. local retVal = Polycore.Image_getBrushY(self.__ptr)
  91. return retVal
  92. end
  93. function Image:isLoaded()
  94. local retVal = Polycore.Image_isLoaded(self.__ptr)
  95. return retVal
  96. end
  97. function Image:getType()
  98. local retVal = Polycore.Image_getType(self.__ptr)
  99. return retVal
  100. end
  101. function Image:writeBMP(fileName)
  102. local retVal = Polycore.Image_writeBMP(self.__ptr, fileName)
  103. end
  104. function Image:getWidth()
  105. local retVal = Polycore.Image_getWidth(self.__ptr)
  106. return retVal
  107. end
  108. function Image:getHeight()
  109. local retVal = Polycore.Image_getHeight(self.__ptr)
  110. return retVal
  111. end
  112. function Image:getPixels()
  113. local retVal = Polycore.Image_getPixels(self.__ptr)
  114. if Polycore.__ptr_lookup[retVal] ~= nil then
  115. return Polycore.__ptr_lookup[retVal]
  116. else
  117. Polycore.__ptr_lookup[retVal] = char("__skip_ptr__")
  118. Polycore.__ptr_lookup[retVal].__ptr = retVal
  119. return Polycore.__ptr_lookup[retVal]
  120. end
  121. end