| 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 |  | 
|---|
| 21 | // LOVE | 
|---|
| 22 | #include "wrap_Image.h" | 
|---|
| 23 |  | 
|---|
| 24 | namespace love | 
|---|
| 25 | { | 
|---|
| 26 | namespace graphics | 
|---|
| 27 | { | 
|---|
| 28 |  | 
|---|
| 29 | Image *luax_checkimage(lua_State *L, int idx) | 
|---|
| 30 | { | 
|---|
| 31 | return luax_checktype<Image>(L, idx); | 
|---|
| 32 | } | 
|---|
| 33 |  | 
|---|
| 34 | int w_Image_isFormatLinear(lua_State *L) | 
|---|
| 35 | { | 
|---|
| 36 | Image *i = luax_checkimage(L, 1); | 
|---|
| 37 | luax_pushboolean(L, i->isFormatLinear()); | 
|---|
| 38 | return 1; | 
|---|
| 39 | } | 
|---|
| 40 |  | 
|---|
| 41 | int w_Image_isCompressed(lua_State *L) | 
|---|
| 42 | { | 
|---|
| 43 | Image *i = luax_checkimage(L, 1); | 
|---|
| 44 | luax_pushboolean(L, i->isCompressed()); | 
|---|
| 45 | return 1; | 
|---|
| 46 | } | 
|---|
| 47 |  | 
|---|
| 48 | int w_Image_replacePixels(lua_State *L) | 
|---|
| 49 | { | 
|---|
| 50 | Image *i = luax_checkimage(L, 1); | 
|---|
| 51 | love::image::ImageData *id = luax_checktype<love::image::ImageData>(L, 2); | 
|---|
| 52 |  | 
|---|
| 53 | int slice = 0; | 
|---|
| 54 | int mipmap = 0; | 
|---|
| 55 | int x = 0; | 
|---|
| 56 | int y = 0; | 
|---|
| 57 | bool reloadmipmaps = i->getMipmapsType() == Image::MIPMAPS_GENERATED; | 
|---|
| 58 |  | 
|---|
| 59 | if (i->getTextureType() != TEXTURE_2D) | 
|---|
| 60 | slice = (int) luaL_checkinteger(L, 3) - 1; | 
|---|
| 61 |  | 
|---|
| 62 | mipmap = (int) luaL_optinteger(L, 4, 1) - 1; | 
|---|
| 63 |  | 
|---|
| 64 | if (!lua_isnoneornil(L, 5)) | 
|---|
| 65 | { | 
|---|
| 66 | x = (int) luaL_checkinteger(L, 5); | 
|---|
| 67 | y = (int) luaL_checkinteger(L, 6); | 
|---|
| 68 |  | 
|---|
| 69 | if (reloadmipmaps) | 
|---|
| 70 | reloadmipmaps = luax_optboolean(L, 7, reloadmipmaps); | 
|---|
| 71 | } | 
|---|
| 72 |  | 
|---|
| 73 | luax_catchexcept(L, [&](){ i->replacePixels(id, slice, mipmap, x, y, reloadmipmaps); }); | 
|---|
| 74 | return 0; | 
|---|
| 75 | } | 
|---|
| 76 |  | 
|---|
| 77 | static const luaL_Reg w_Image_functions[] = | 
|---|
| 78 | { | 
|---|
| 79 | { "isFormatLinear", w_Image_isFormatLinear }, | 
|---|
| 80 | { "isCompressed", w_Image_isCompressed }, | 
|---|
| 81 | { "replacePixels", w_Image_replacePixels }, | 
|---|
| 82 | { 0, 0 } | 
|---|
| 83 | }; | 
|---|
| 84 |  | 
|---|
| 85 | extern "C"int luaopen_image(lua_State *L) | 
|---|
| 86 | { | 
|---|
| 87 | return luax_register_type(L, &Image::type, w_Texture_functions, w_Image_functions, nullptr); | 
|---|
| 88 | } | 
|---|
| 89 |  | 
|---|
| 90 | } // graphics | 
|---|
| 91 | } // love | 
|---|
| 92 |  | 
|---|