Image.lua 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  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)
  19. return retVal
  20. end
  21. function Image:loadPNG(fileName)
  22. local retVal = Polycore.Image_loadPNG(self.__ptr, fileName)
  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 Polycore.__ptr_lookup[retVal] ~= nil then
  37. return Polycore.__ptr_lookup[retVal]
  38. else
  39. Polycore.__ptr_lookup[retVal] = Color("__skip_ptr__")
  40. Polycore.__ptr_lookup[retVal].__ptr = retVal
  41. return Polycore.__ptr_lookup[retVal]
  42. end
  43. end
  44. function Image:swap(v1, v2)
  45. local retVal = Polycore.Image_swap(self.__ptr, v1.__ptr, v2.__ptr)
  46. end
  47. function Image:line(x0, y0, x1, y1, col)
  48. local retVal = Polycore.Image_line(self.__ptr, x0, y0, x1, y1, col.__ptr)
  49. end
  50. function Image:moveTo(x, y)
  51. local retVal = Polycore.Image_moveTo(self.__ptr, x, y)
  52. end
  53. function Image:move(x, y)
  54. local retVal = Polycore.Image_move(self.__ptr, x, y)
  55. end
  56. function Image:lineTo(x, y, col)
  57. local retVal = Polycore.Image_lineTo(self.__ptr, x, y, col.__ptr)
  58. end
  59. function Image:drawRect(x, y, w, h, col)
  60. local retVal = Polycore.Image_drawRect(self.__ptr, x, y, w, h, col.__ptr)
  61. end
  62. function Image:perlinNoise(seed, alpha)
  63. local retVal = Polycore.Image_perlinNoise(self.__ptr, seed, alpha)
  64. end
  65. function Image:fastBlur(blurSize)
  66. local retVal = Polycore.Image_fastBlur(self.__ptr, blurSize)
  67. end
  68. function Image:fastBlurVert(blurSize)
  69. local retVal = Polycore.Image_fastBlurVert(self.__ptr, blurSize)
  70. end
  71. function Image:fastBlurHor(blurSize)
  72. local retVal = Polycore.Image_fastBlurHor(self.__ptr, blurSize)
  73. end
  74. function Image:darken(amt, color, alpha)
  75. local retVal = Polycore.Image_darken(self.__ptr, amt, color, alpha)
  76. end
  77. function Image:lighten(amt, color, alpha)
  78. local retVal = Polycore.Image_lighten(self.__ptr, amt, color, alpha)
  79. end
  80. function Image:multiply(amt, color, alpha)
  81. local retVal = Polycore.Image_multiply(self.__ptr, amt, color, alpha)
  82. end
  83. function Image:getBrushX()
  84. local retVal = Polycore.Image_getBrushX(self.__ptr)
  85. return retVal
  86. end
  87. function Image:getBrushY()
  88. local retVal = Polycore.Image_getBrushY(self.__ptr)
  89. return retVal
  90. end
  91. function Image:isLoaded()
  92. local retVal = Polycore.Image_isLoaded(self.__ptr)
  93. return retVal
  94. end
  95. function Image:getType()
  96. local retVal = Polycore.Image_getType(self.__ptr)
  97. return retVal
  98. end
  99. function Image:writeBMP(fileName)
  100. local retVal = Polycore.Image_writeBMP(self.__ptr, fileName)
  101. end
  102. function Image:getWidth()
  103. local retVal = Polycore.Image_getWidth(self.__ptr)
  104. return retVal
  105. end
  106. function Image:getHeight()
  107. local retVal = Polycore.Image_getHeight(self.__ptr)
  108. return retVal
  109. end
  110. function Image:getPixels()
  111. local retVal = Polycore.Image_getPixels(self.__ptr)
  112. if Polycore.__ptr_lookup[retVal] ~= nil then
  113. return Polycore.__ptr_lookup[retVal]
  114. else
  115. Polycore.__ptr_lookup[retVal] = char("__skip_ptr__")
  116. Polycore.__ptr_lookup[retVal].__ptr = retVal
  117. return Polycore.__ptr_lookup[retVal]
  118. end
  119. end