Image.lua 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. class "Image"
  2. Image.IMAGE_RGB = 0
  3. Image.IMAGE_RGBA = 1
  4. Image.IMAGE_FP16 = 2
  5. function Image:Image(...)
  6. local arg = {...}
  7. for k,v in pairs(arg) do
  8. if type(v) == "table" then
  9. if v.__ptr ~= nil then
  10. arg[k] = v.__ptr
  11. end
  12. end
  13. end
  14. if self.__ptr == nil and arg[1] ~= "__skip_ptr__" then
  15. self.__ptr = Polycode.Image(unpack(arg))
  16. end
  17. end
  18. function Image:BlankImage(width, height, type)
  19. local retVal = Polycode.Image_BlankImage(self.__ptr, width, height, type)
  20. if retVal == nil then return nil end
  21. local __c = _G["Image"]("__skip_ptr__")
  22. __c.__ptr = retVal
  23. return __c
  24. end
  25. function Image:loadImage(fileName)
  26. local retVal = Polycode.Image_loadImage(self.__ptr, fileName)
  27. return retVal
  28. end
  29. function Image:saveImage(fileName)
  30. local retVal = Polycode.Image_saveImage(self.__ptr, fileName)
  31. return retVal
  32. end
  33. function Image:pasteImage(image, x, y, blendingMode, blendAmount, blendColor)
  34. local retVal = Polycode.Image_pasteImage(self.__ptr, image.__ptr, x, y, blendingMode, blendAmount, blendColor.__ptr)
  35. end
  36. function Image:createEmpty(width, height, fillColor)
  37. local retVal = Polycode.Image_createEmpty(self.__ptr, width, height, fillColor.__ptr)
  38. end
  39. function Image:fill(color)
  40. local retVal = Polycode.Image_fill(self.__ptr, color.__ptr)
  41. end
  42. function Image:setPixel(x, y, r, g, b, a)
  43. local retVal = Polycode.Image_setPixel(self.__ptr, x, y, r, g, b, a)
  44. end
  45. function Image:getPixel(x, y)
  46. local retVal = Polycode.Image_getPixel(self.__ptr, x, y)
  47. if retVal == nil then return nil end
  48. local __c = _G["Color"]("__skip_ptr__")
  49. __c.__ptr = retVal
  50. return __c
  51. end
  52. function Image:swap(v1, v2)
  53. local retVal = Polycode.Image_swap(self.__ptr, v1.__ptr, v2.__ptr)
  54. end
  55. function Image:drawLine(x0, y0, x1, y1, col)
  56. local retVal = Polycode.Image_drawLine(self.__ptr, x0, y0, x1, y1, col.__ptr)
  57. end
  58. function Image:moveBrushTo(x, y)
  59. local retVal = Polycode.Image_moveBrushTo(self.__ptr, x, y)
  60. end
  61. function Image:moveBrush(x, y)
  62. local retVal = Polycode.Image_moveBrush(self.__ptr, x, y)
  63. end
  64. function Image:drawLineTo(x, y, col)
  65. local retVal = Polycode.Image_drawLineTo(self.__ptr, x, y, col.__ptr)
  66. end
  67. function Image:fillRect(x, y, w, h, col)
  68. local retVal = Polycode.Image_fillRect(self.__ptr, x, y, w, h, col.__ptr)
  69. end
  70. function Image:perlinNoise(seed, alpha)
  71. local retVal = Polycode.Image_perlinNoise(self.__ptr, seed, alpha)
  72. end
  73. function Image:fastBlur(blurSize)
  74. local retVal = Polycode.Image_fastBlur(self.__ptr, blurSize)
  75. end
  76. function Image:fastBlurVert(blurSize)
  77. local retVal = Polycode.Image_fastBlurVert(self.__ptr, blurSize)
  78. end
  79. function Image:fastBlurHor(blurSize)
  80. local retVal = Polycode.Image_fastBlurHor(self.__ptr, blurSize)
  81. end
  82. function Image:getPixelsInRect(x, y, width, height)
  83. local retVal = Polycode.Image_getPixelsInRect(self.__ptr, x, y, width, height)
  84. if retVal == nil then return nil end
  85. local __c = _G["char"]("__skip_ptr__")
  86. __c.__ptr = retVal
  87. return __c
  88. end
  89. function Image:getImagePart(subRect)
  90. local retVal = Polycode.Image_getImagePart(self.__ptr, subRect.__ptr)
  91. if retVal == nil then return nil end
  92. local __c = _G["Image"]("__skip_ptr__")
  93. __c.__ptr = retVal
  94. return __c
  95. end
  96. function Image:getBrushX()
  97. local retVal = Polycode.Image_getBrushX(self.__ptr)
  98. return retVal
  99. end
  100. function Image:getBrushY()
  101. local retVal = Polycode.Image_getBrushY(self.__ptr)
  102. return retVal
  103. end
  104. function Image:isLoaded()
  105. local retVal = Polycode.Image_isLoaded(self.__ptr)
  106. return retVal
  107. end
  108. function Image:getType()
  109. local retVal = Polycode.Image_getType(self.__ptr)
  110. return retVal
  111. end
  112. function Image:getWidth()
  113. local retVal = Polycode.Image_getWidth(self.__ptr)
  114. return retVal
  115. end
  116. function Image:getHeight()
  117. local retVal = Polycode.Image_getHeight(self.__ptr)
  118. return retVal
  119. end
  120. function Image:getPixels()
  121. local retVal = Polycode.Image_getPixels(self.__ptr)
  122. if retVal == nil then return nil end
  123. local __c = _G["char"]("__skip_ptr__")
  124. __c.__ptr = retVal
  125. return __c
  126. end
  127. function Image:premultiplyAlpha()
  128. local retVal = Polycode.Image_premultiplyAlpha(self.__ptr)
  129. end
  130. function Image:savePNG(fileName)
  131. local retVal = Polycode.Image_savePNG(self.__ptr, fileName)
  132. return retVal
  133. end
  134. function Image:__delete()
  135. if self then Polycode.delete_Image(self.__ptr) end
  136. end