Image.lua 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  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. Polycore.__ptr_lookup[self.__ptr] = self
  15. end
  16. end
  17. function Image:loadImage(fileName)
  18. local retVal = Polycore.Image_loadImage(self.__ptr, fileName.__ptr)
  19. return retVal
  20. end
  21. function Image:loadPNG(fileName)
  22. local retVal = Polycore.Image_loadPNG(self.__ptr, fileName.__ptr)
  23. return retVal
  24. end
  25. function Image:createEmpty(width, height)
  26. local retVal = Polycore.Image_createEmpty(self.__ptr, width, height)
  27. end
  28. function Image:fill(r, g, b, a)
  29. local retVal = Polycore.Image_fill(self.__ptr, r, g, b, a)
  30. end
  31. function Image:setPixel(x, y, r, g, b, a)
  32. local retVal = Polycore.Image_setPixel(self.__ptr, x, y, r, g, b, a)
  33. end
  34. function Image:getPixel(x, y)
  35. local retVal = Polycore.Image_getPixel(self.__ptr, x, y)
  36. if retVal == nil then return nil end
  37. if Polycore.__ptr_lookup[retVal] ~= nil then
  38. return Polycore.__ptr_lookup[retVal]
  39. else
  40. Polycore.__ptr_lookup[retVal] = Color("__skip_ptr__")
  41. Polycore.__ptr_lookup[retVal].__ptr = retVal
  42. return Polycore.__ptr_lookup[retVal]
  43. end
  44. end
  45. function Image:swap(v1, v2)
  46. local retVal = Polycore.Image_swap(self.__ptr, v1.__ptr, v2.__ptr)
  47. end
  48. function Image:line(x0, y0, x1, y1, col)
  49. local retVal = Polycore.Image_line(self.__ptr, x0, y0, x1, y1, col.__ptr)
  50. end
  51. function Image:moveTo(x, y)
  52. local retVal = Polycore.Image_moveTo(self.__ptr, x, y)
  53. end
  54. function Image:move(x, y)
  55. local retVal = Polycore.Image_move(self.__ptr, x, y)
  56. end
  57. function Image:lineTo(x, y, col)
  58. local retVal = Polycore.Image_lineTo(self.__ptr, x, y, col.__ptr)
  59. end
  60. function Image:drawRect(x, y, w, h, col)
  61. local retVal = Polycore.Image_drawRect(self.__ptr, x, y, w, h, col.__ptr)
  62. end
  63. function Image:perlinNoise(seed, alpha)
  64. local retVal = Polycore.Image_perlinNoise(self.__ptr, seed, alpha)
  65. end
  66. function Image:fastBlur(blurSize)
  67. local retVal = Polycore.Image_fastBlur(self.__ptr, blurSize)
  68. end
  69. function Image:fastBlurVert(blurSize)
  70. local retVal = Polycore.Image_fastBlurVert(self.__ptr, blurSize)
  71. end
  72. function Image:fastBlurHor(blurSize)
  73. local retVal = Polycore.Image_fastBlurHor(self.__ptr, blurSize)
  74. end
  75. function Image:darken(amt, color, alpha)
  76. local retVal = Polycore.Image_darken(self.__ptr, amt, color, alpha)
  77. end
  78. function Image:lighten(amt, color, alpha)
  79. local retVal = Polycore.Image_lighten(self.__ptr, amt, color, alpha)
  80. end
  81. function Image:multiply(amt, color, alpha)
  82. local retVal = Polycore.Image_multiply(self.__ptr, amt, color, alpha)
  83. end
  84. function Image:getBrushX()
  85. local retVal = Polycore.Image_getBrushX(self.__ptr)
  86. return retVal
  87. end
  88. function Image:getBrushY()
  89. local retVal = Polycore.Image_getBrushY(self.__ptr)
  90. return retVal
  91. end
  92. function Image:isLoaded()
  93. local retVal = Polycore.Image_isLoaded(self.__ptr)
  94. return retVal
  95. end
  96. function Image:getType()
  97. local retVal = Polycore.Image_getType(self.__ptr)
  98. return retVal
  99. end
  100. function Image:writeBMP(fileName)
  101. local retVal = Polycore.Image_writeBMP(self.__ptr, fileName.__ptr)
  102. end
  103. function Image:getWidth()
  104. local retVal = Polycore.Image_getWidth(self.__ptr)
  105. return retVal
  106. end
  107. function Image:getHeight()
  108. local retVal = Polycore.Image_getHeight(self.__ptr)
  109. return retVal
  110. end
  111. function Image:getPixels()
  112. local retVal = Polycore.Image_getPixels(self.__ptr)
  113. if retVal == nil then return nil end
  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
  122. function Image:__delete()
  123. Polycore.__ptr_lookup[self.__ptr] = nil
  124. Polycore.delete_Image(self.__ptr)
  125. end