Image.lua 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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:loadImage(fileName)
  19. local retVal = Polycode.Image_loadImage(self.__ptr, fileName)
  20. return retVal
  21. end
  22. function Image:saveImage(fileName)
  23. local retVal = Polycode.Image_saveImage(self.__ptr, fileName)
  24. return retVal
  25. end
  26. function Image:createEmpty(width, height, fillColor)
  27. local retVal = Polycode.Image_createEmpty(self.__ptr, width, height, fillColor.__ptr)
  28. end
  29. function Image:fill(color)
  30. local retVal = Polycode.Image_fill(self.__ptr, color.__ptr)
  31. end
  32. function Image:setPixel(x, y, r, g, b, a)
  33. local retVal = Polycode.Image_setPixel(self.__ptr, x, y, r, g, b, a)
  34. end
  35. function Image:getPixel(x, y)
  36. local retVal = Polycode.Image_getPixel(self.__ptr, x, y)
  37. if retVal == nil then return nil end
  38. local __c = _G["Color"]("__skip_ptr__")
  39. __c.__ptr = retVal
  40. return __c
  41. end
  42. function Image:drawLine(x0, y0, x1, y1, col)
  43. local retVal = Polycode.Image_drawLine(self.__ptr, x0, y0, x1, y1, col.__ptr)
  44. end
  45. function Image:moveBrushTo(x, y)
  46. local retVal = Polycode.Image_moveBrushTo(self.__ptr, x, y)
  47. end
  48. function Image:moveBrush(x, y)
  49. local retVal = Polycode.Image_moveBrush(self.__ptr, x, y)
  50. end
  51. function Image:drawLineTo(x, y, col)
  52. local retVal = Polycode.Image_drawLineTo(self.__ptr, x, y, col.__ptr)
  53. end
  54. function Image:fillRect(x, y, w, h, col)
  55. local retVal = Polycode.Image_fillRect(self.__ptr, x, y, w, h, col.__ptr)
  56. end
  57. function Image:perlinNoise(seed, alpha)
  58. local retVal = Polycode.Image_perlinNoise(self.__ptr, seed, alpha)
  59. end
  60. function Image:fastBlur(blurSize)
  61. local retVal = Polycode.Image_fastBlur(self.__ptr, blurSize)
  62. end
  63. function Image:fastBlurVert(blurSize)
  64. local retVal = Polycode.Image_fastBlurVert(self.__ptr, blurSize)
  65. end
  66. function Image:fastBlurHor(blurSize)
  67. local retVal = Polycode.Image_fastBlurHor(self.__ptr, blurSize)
  68. end
  69. function Image:getBrushX()
  70. local retVal = Polycode.Image_getBrushX(self.__ptr)
  71. return retVal
  72. end
  73. function Image:getBrushY()
  74. local retVal = Polycode.Image_getBrushY(self.__ptr)
  75. return retVal
  76. end
  77. function Image:isLoaded()
  78. local retVal = Polycode.Image_isLoaded(self.__ptr)
  79. return retVal
  80. end
  81. function Image:getType()
  82. local retVal = Polycode.Image_getType(self.__ptr)
  83. return retVal
  84. end
  85. function Image:getWidth()
  86. local retVal = Polycode.Image_getWidth(self.__ptr)
  87. return retVal
  88. end
  89. function Image:getHeight()
  90. local retVal = Polycode.Image_getHeight(self.__ptr)
  91. return retVal
  92. end
  93. function Image:premultiplyAlpha()
  94. local retVal = Polycode.Image_premultiplyAlpha(self.__ptr)
  95. end
  96. function Image:savePNG(fileName)
  97. local retVal = Polycode.Image_savePNG(self.__ptr, fileName)
  98. return retVal
  99. end
  100. function Image:__delete()
  101. if self then Polycode.delete_Image(self.__ptr) end
  102. end