wrap_CompressedImageData.cpp 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. /**
  2. * Copyright (c) 2006-2023 LOVE Development Team
  3. *
  4. * This software is provided 'as-is', without any express or implied
  5. * warranty. In no event will the authors be held liable for any damages
  6. * arising from the use of this software.
  7. *
  8. * Permission is granted to anyone to use this software for any purpose,
  9. * including commercial applications, and to alter it and redistribute it
  10. * freely, subject to the following restrictions:
  11. *
  12. * 1. The origin of this software must not be misrepresented; you must not
  13. * claim that you wrote the original software. If you use this software
  14. * in a product, an acknowledgment in the product documentation would be
  15. * appreciated but is not required.
  16. * 2. Altered source versions must be plainly marked as such, and must not be
  17. * misrepresented as being the original software.
  18. * 3. This notice may not be removed or altered from any source distribution.
  19. **/
  20. #include "wrap_CompressedImageData.h"
  21. #include "data/wrap_Data.h"
  22. namespace love
  23. {
  24. namespace image
  25. {
  26. CompressedImageData *luax_checkcompressedimagedata(lua_State *L, int idx)
  27. {
  28. return luax_checktype<CompressedImageData>(L, idx);
  29. }
  30. int w_CompressedImageData_clone(lua_State *L)
  31. {
  32. CompressedImageData *t = luax_checkcompressedimagedata(L, 1), *c = nullptr;
  33. luax_catchexcept(L, [&](){ c = t->clone(); });
  34. luax_pushtype(L, c);
  35. c->release();
  36. return 1;
  37. }
  38. int w_CompressedImageData_getWidth(lua_State *L)
  39. {
  40. CompressedImageData *t = luax_checkcompressedimagedata(L, 1);
  41. int miplevel = (int) luaL_optinteger(L, 2, 1);
  42. int width = 0;
  43. luax_catchexcept(L, [&](){ width = t->getWidth(miplevel - 1); });
  44. lua_pushinteger(L, width);
  45. return 1;
  46. }
  47. int w_CompressedImageData_getHeight(lua_State *L)
  48. {
  49. CompressedImageData *t = luax_checkcompressedimagedata(L, 1);
  50. int miplevel = (int) luaL_optinteger(L, 2, 1);
  51. int height = 0;
  52. luax_catchexcept(L, [&](){ height = t->getHeight(miplevel - 1); });
  53. lua_pushinteger(L, height);
  54. return 1;
  55. }
  56. int w_CompressedImageData_getDimensions(lua_State *L)
  57. {
  58. CompressedImageData *t = luax_checkcompressedimagedata(L, 1);
  59. int miplevel = (int) luaL_optinteger(L, 2, 1);
  60. int width = 0, height = 0;
  61. luax_catchexcept(L, [&]()
  62. {
  63. width = t->getWidth(miplevel - 1);
  64. height = t->getHeight(miplevel - 1);
  65. });
  66. lua_pushinteger(L, width);
  67. lua_pushinteger(L, height);
  68. return 2;
  69. }
  70. int w_CompressedImageData_getMipmapCount(lua_State *L)
  71. {
  72. CompressedImageData *t = luax_checkcompressedimagedata(L, 1);
  73. lua_pushinteger(L, t->getMipmapCount());
  74. return 1;
  75. }
  76. int w_CompressedImageData_getFormat(lua_State *L)
  77. {
  78. CompressedImageData *t = luax_checkcompressedimagedata(L, 1);
  79. PixelFormat format = t->getFormat();
  80. const char *str;
  81. if (getConstant(format, str))
  82. lua_pushstring(L, str);
  83. else
  84. lua_pushstring(L, "unknown");
  85. return 1;
  86. }
  87. static const luaL_Reg w_CompressedImageData_functions[] =
  88. {
  89. { "clone", w_CompressedImageData_clone },
  90. { "getWidth", w_CompressedImageData_getWidth },
  91. { "getHeight", w_CompressedImageData_getHeight },
  92. { "getDimensions", w_CompressedImageData_getDimensions },
  93. { "getMipmapCount", w_CompressedImageData_getMipmapCount },
  94. { "getFormat", w_CompressedImageData_getFormat },
  95. { 0, 0 },
  96. };
  97. extern "C" int luaopen_compressedimagedata(lua_State *L)
  98. {
  99. int ret = luax_register_type(L, &CompressedImageData::type, data::w_Data_functions, w_CompressedImageData_functions, nullptr);
  100. love::data::luax_rundatawrapper(L, CompressedImageData::type);
  101. return ret;
  102. }
  103. } // image
  104. } // love