Mercurial > love-experiments
annotate src/modules/image/wrap_Image.cpp @ 1448:108ee2e81f65 default tip
Fix a case typo, imageData.h -> ImageData.h
| author | Radomir Dopieralski <sheep-devel@sheep.art.pl> |
|---|---|
| date | Sat, 18 Jan 2014 13:57:44 +0100 |
| parents | 5b9ebe6a9a7e |
| children |
| rev | line source |
|---|---|
| 1096 | 1 /** |
|
1282
b7f097053d74
Updated copyright text for the new year
Alex Szpakowski <slime73@gmail.com>
parents:
1096
diff
changeset
|
2 * Copyright (c) 2006-2013 LOVE Development Team |
| 1096 | 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 #include "wrap_Image.h" | |
| 22 | |
| 23 #include "common/Data.h" | |
| 24 #include "common/StringMap.h" | |
| 25 | |
|
1422
377f9dad7a2d
Replaced the devil love.image module with love.image.magpie, which can decide which image library to use in a similar manner to love.sound.lullaby. Some rough edges still exist.
Alex Szpakowski <slime73@gmail.com>
parents:
1420
diff
changeset
|
26 #include "magpie/Image.h" |
| 1096 | 27 |
| 28 namespace love | |
| 29 { | |
| 30 namespace image | |
| 31 { | |
| 32 | |
| 33 static Image *instance = 0; | |
| 34 | |
| 35 int w_newImageData(lua_State *L) | |
| 36 { | |
| 37 // Case 1: Integers. | |
| 38 if (lua_isnumber(L, 1)) | |
| 39 { | |
| 40 int w = luaL_checkint(L, 1); | |
| 41 int h = luaL_checkint(L, 2); | |
| 42 if (w <= 0 || h <= 0) | |
| 43 return luaL_error(L, "Invalid image size."); | |
| 44 | |
| 45 ImageData *t = 0; | |
| 46 try | |
| 47 { | |
| 48 t = instance->newImageData(w, h); | |
| 49 } | |
| 50 catch(love::Exception &e) | |
| 51 { | |
| 52 return luaL_error(L, "%s", e.what()); | |
| 53 } | |
| 54 luax_newtype(L, "ImageData", IMAGE_IMAGE_DATA_T, (void *)t); | |
| 55 return 1; | |
| 56 } | |
| 57 | |
|
1422
377f9dad7a2d
Replaced the devil love.image module with love.image.magpie, which can decide which image library to use in a similar manner to love.sound.lullaby. Some rough edges still exist.
Alex Szpakowski <slime73@gmail.com>
parents:
1420
diff
changeset
|
58 // Case 2: File(Data). |
| 1096 | 59 |
|
1422
377f9dad7a2d
Replaced the devil love.image module with love.image.magpie, which can decide which image library to use in a similar manner to love.sound.lullaby. Some rough edges still exist.
Alex Szpakowski <slime73@gmail.com>
parents:
1420
diff
changeset
|
60 // Convert to FileData, if necessary. |
|
377f9dad7a2d
Replaced the devil love.image module with love.image.magpie, which can decide which image library to use in a similar manner to love.sound.lullaby. Some rough edges still exist.
Alex Szpakowski <slime73@gmail.com>
parents:
1420
diff
changeset
|
61 if (lua_isstring(L, 1) || luax_istype(L, 1, FILESYSTEM_FILE_T)) |
|
377f9dad7a2d
Replaced the devil love.image module with love.image.magpie, which can decide which image library to use in a similar manner to love.sound.lullaby. Some rough edges still exist.
Alex Szpakowski <slime73@gmail.com>
parents:
1420
diff
changeset
|
62 luax_convobj(L, 1, "filesystem", "newFileData"); |
| 1096 | 63 |
|
1422
377f9dad7a2d
Replaced the devil love.image module with love.image.magpie, which can decide which image library to use in a similar manner to love.sound.lullaby. Some rough edges still exist.
Alex Szpakowski <slime73@gmail.com>
parents:
1420
diff
changeset
|
64 love::filesystem::FileData *data = luax_checktype<love::filesystem::FileData>(L, 1, "FileData", FILESYSTEM_FILE_DATA_T); |
| 1096 | 65 |
| 66 ImageData *t = 0; | |
| 67 try | |
| 68 { | |
|
1422
377f9dad7a2d
Replaced the devil love.image module with love.image.magpie, which can decide which image library to use in a similar manner to love.sound.lullaby. Some rough edges still exist.
Alex Szpakowski <slime73@gmail.com>
parents:
1420
diff
changeset
|
69 t = instance->newImageData(data); |
|
377f9dad7a2d
Replaced the devil love.image module with love.image.magpie, which can decide which image library to use in a similar manner to love.sound.lullaby. Some rough edges still exist.
Alex Szpakowski <slime73@gmail.com>
parents:
1420
diff
changeset
|
70 } |
|
377f9dad7a2d
Replaced the devil love.image module with love.image.magpie, which can decide which image library to use in a similar manner to love.sound.lullaby. Some rough edges still exist.
Alex Szpakowski <slime73@gmail.com>
parents:
1420
diff
changeset
|
71 catch (love::Exception &e) |
|
377f9dad7a2d
Replaced the devil love.image module with love.image.magpie, which can decide which image library to use in a similar manner to love.sound.lullaby. Some rough edges still exist.
Alex Szpakowski <slime73@gmail.com>
parents:
1420
diff
changeset
|
72 { |
|
377f9dad7a2d
Replaced the devil love.image module with love.image.magpie, which can decide which image library to use in a similar manner to love.sound.lullaby. Some rough edges still exist.
Alex Szpakowski <slime73@gmail.com>
parents:
1420
diff
changeset
|
73 return luaL_error(L, "%s", e.what()); |
|
377f9dad7a2d
Replaced the devil love.image module with love.image.magpie, which can decide which image library to use in a similar manner to love.sound.lullaby. Some rough edges still exist.
Alex Szpakowski <slime73@gmail.com>
parents:
1420
diff
changeset
|
74 } |
|
377f9dad7a2d
Replaced the devil love.image module with love.image.magpie, which can decide which image library to use in a similar manner to love.sound.lullaby. Some rough edges still exist.
Alex Szpakowski <slime73@gmail.com>
parents:
1420
diff
changeset
|
75 |
|
377f9dad7a2d
Replaced the devil love.image module with love.image.magpie, which can decide which image library to use in a similar manner to love.sound.lullaby. Some rough edges still exist.
Alex Szpakowski <slime73@gmail.com>
parents:
1420
diff
changeset
|
76 luax_newtype(L, "ImageData", IMAGE_IMAGE_DATA_T, (void *) t); |
|
377f9dad7a2d
Replaced the devil love.image module with love.image.magpie, which can decide which image library to use in a similar manner to love.sound.lullaby. Some rough edges still exist.
Alex Szpakowski <slime73@gmail.com>
parents:
1420
diff
changeset
|
77 |
|
377f9dad7a2d
Replaced the devil love.image module with love.image.magpie, which can decide which image library to use in a similar manner to love.sound.lullaby. Some rough edges still exist.
Alex Szpakowski <slime73@gmail.com>
parents:
1420
diff
changeset
|
78 return 1; |
|
377f9dad7a2d
Replaced the devil love.image module with love.image.magpie, which can decide which image library to use in a similar manner to love.sound.lullaby. Some rough edges still exist.
Alex Szpakowski <slime73@gmail.com>
parents:
1420
diff
changeset
|
79 } |
|
377f9dad7a2d
Replaced the devil love.image module with love.image.magpie, which can decide which image library to use in a similar manner to love.sound.lullaby. Some rough edges still exist.
Alex Szpakowski <slime73@gmail.com>
parents:
1420
diff
changeset
|
80 |
|
377f9dad7a2d
Replaced the devil love.image module with love.image.magpie, which can decide which image library to use in a similar manner to love.sound.lullaby. Some rough edges still exist.
Alex Szpakowski <slime73@gmail.com>
parents:
1420
diff
changeset
|
81 int w_newCompressedData(lua_State *L) |
|
377f9dad7a2d
Replaced the devil love.image module with love.image.magpie, which can decide which image library to use in a similar manner to love.sound.lullaby. Some rough edges still exist.
Alex Szpakowski <slime73@gmail.com>
parents:
1420
diff
changeset
|
82 { |
|
377f9dad7a2d
Replaced the devil love.image module with love.image.magpie, which can decide which image library to use in a similar manner to love.sound.lullaby. Some rough edges still exist.
Alex Szpakowski <slime73@gmail.com>
parents:
1420
diff
changeset
|
83 // Convert to FileData, if necessary. |
|
377f9dad7a2d
Replaced the devil love.image module with love.image.magpie, which can decide which image library to use in a similar manner to love.sound.lullaby. Some rough edges still exist.
Alex Szpakowski <slime73@gmail.com>
parents:
1420
diff
changeset
|
84 if (lua_isstring(L, 1) || luax_istype(L, 1, FILESYSTEM_FILE_T)) |
|
377f9dad7a2d
Replaced the devil love.image module with love.image.magpie, which can decide which image library to use in a similar manner to love.sound.lullaby. Some rough edges still exist.
Alex Szpakowski <slime73@gmail.com>
parents:
1420
diff
changeset
|
85 luax_convobj(L, 1, "filesystem", "newFileData"); |
|
377f9dad7a2d
Replaced the devil love.image module with love.image.magpie, which can decide which image library to use in a similar manner to love.sound.lullaby. Some rough edges still exist.
Alex Szpakowski <slime73@gmail.com>
parents:
1420
diff
changeset
|
86 |
|
377f9dad7a2d
Replaced the devil love.image module with love.image.magpie, which can decide which image library to use in a similar manner to love.sound.lullaby. Some rough edges still exist.
Alex Szpakowski <slime73@gmail.com>
parents:
1420
diff
changeset
|
87 love::filesystem::FileData *data = luax_checktype<love::filesystem::FileData>(L, 1, "FileData", FILESYSTEM_FILE_DATA_T); |
|
377f9dad7a2d
Replaced the devil love.image module with love.image.magpie, which can decide which image library to use in a similar manner to love.sound.lullaby. Some rough edges still exist.
Alex Szpakowski <slime73@gmail.com>
parents:
1420
diff
changeset
|
88 |
|
377f9dad7a2d
Replaced the devil love.image module with love.image.magpie, which can decide which image library to use in a similar manner to love.sound.lullaby. Some rough edges still exist.
Alex Szpakowski <slime73@gmail.com>
parents:
1420
diff
changeset
|
89 CompressedData *t = 0; |
|
377f9dad7a2d
Replaced the devil love.image module with love.image.magpie, which can decide which image library to use in a similar manner to love.sound.lullaby. Some rough edges still exist.
Alex Szpakowski <slime73@gmail.com>
parents:
1420
diff
changeset
|
90 try |
|
377f9dad7a2d
Replaced the devil love.image module with love.image.magpie, which can decide which image library to use in a similar manner to love.sound.lullaby. Some rough edges still exist.
Alex Szpakowski <slime73@gmail.com>
parents:
1420
diff
changeset
|
91 { |
|
377f9dad7a2d
Replaced the devil love.image module with love.image.magpie, which can decide which image library to use in a similar manner to love.sound.lullaby. Some rough edges still exist.
Alex Szpakowski <slime73@gmail.com>
parents:
1420
diff
changeset
|
92 t = instance->newCompressedData(data); |
| 1096 | 93 } |
| 94 catch(love::Exception &e) | |
| 95 { | |
| 96 return luaL_error(L, "%s", e.what()); | |
| 97 } | |
| 98 | |
|
1420
2a5ef265e040
Added support for DXT1/3/5 and BC5/7 compressed textures via love.image.CompressedData. Some internals are still iffy.
Alex Szpakowski <slime73@gmail.com>
parents:
1282
diff
changeset
|
99 luax_newtype(L, "CompressedData", IMAGE_COMPRESSED_DATA_T, (void *) t); |
|
2a5ef265e040
Added support for DXT1/3/5 and BC5/7 compressed textures via love.image.CompressedData. Some internals are still iffy.
Alex Szpakowski <slime73@gmail.com>
parents:
1282
diff
changeset
|
100 |
|
2a5ef265e040
Added support for DXT1/3/5 and BC5/7 compressed textures via love.image.CompressedData. Some internals are still iffy.
Alex Szpakowski <slime73@gmail.com>
parents:
1282
diff
changeset
|
101 return 1; |
|
2a5ef265e040
Added support for DXT1/3/5 and BC5/7 compressed textures via love.image.CompressedData. Some internals are still iffy.
Alex Szpakowski <slime73@gmail.com>
parents:
1282
diff
changeset
|
102 } |
|
2a5ef265e040
Added support for DXT1/3/5 and BC5/7 compressed textures via love.image.CompressedData. Some internals are still iffy.
Alex Szpakowski <slime73@gmail.com>
parents:
1282
diff
changeset
|
103 |
|
2a5ef265e040
Added support for DXT1/3/5 and BC5/7 compressed textures via love.image.CompressedData. Some internals are still iffy.
Alex Szpakowski <slime73@gmail.com>
parents:
1282
diff
changeset
|
104 int w_isCompressed(lua_State *L) |
|
2a5ef265e040
Added support for DXT1/3/5 and BC5/7 compressed textures via love.image.CompressedData. Some internals are still iffy.
Alex Szpakowski <slime73@gmail.com>
parents:
1282
diff
changeset
|
105 { |
|
1422
377f9dad7a2d
Replaced the devil love.image module with love.image.magpie, which can decide which image library to use in a similar manner to love.sound.lullaby. Some rough edges still exist.
Alex Szpakowski <slime73@gmail.com>
parents:
1420
diff
changeset
|
106 // Convert to FileData, if necessary. |
|
377f9dad7a2d
Replaced the devil love.image module with love.image.magpie, which can decide which image library to use in a similar manner to love.sound.lullaby. Some rough edges still exist.
Alex Szpakowski <slime73@gmail.com>
parents:
1420
diff
changeset
|
107 if (lua_isstring(L, 1) || luax_istype(L, 1, FILESYSTEM_FILE_T)) |
|
377f9dad7a2d
Replaced the devil love.image module with love.image.magpie, which can decide which image library to use in a similar manner to love.sound.lullaby. Some rough edges still exist.
Alex Szpakowski <slime73@gmail.com>
parents:
1420
diff
changeset
|
108 luax_convobj(L, 1, "filesystem", "newFileData"); |
|
1420
2a5ef265e040
Added support for DXT1/3/5 and BC5/7 compressed textures via love.image.CompressedData. Some internals are still iffy.
Alex Szpakowski <slime73@gmail.com>
parents:
1282
diff
changeset
|
109 |
|
1422
377f9dad7a2d
Replaced the devil love.image module with love.image.magpie, which can decide which image library to use in a similar manner to love.sound.lullaby. Some rough edges still exist.
Alex Szpakowski <slime73@gmail.com>
parents:
1420
diff
changeset
|
110 love::filesystem::FileData *data = luax_checktype<love::filesystem::FileData>(L, 1, "FileData", FILESYSTEM_FILE_DATA_T); |
|
1420
2a5ef265e040
Added support for DXT1/3/5 and BC5/7 compressed textures via love.image.CompressedData. Some internals are still iffy.
Alex Szpakowski <slime73@gmail.com>
parents:
1282
diff
changeset
|
111 |
|
1422
377f9dad7a2d
Replaced the devil love.image module with love.image.magpie, which can decide which image library to use in a similar manner to love.sound.lullaby. Some rough edges still exist.
Alex Szpakowski <slime73@gmail.com>
parents:
1420
diff
changeset
|
112 bool compressed = false; |
|
1420
2a5ef265e040
Added support for DXT1/3/5 and BC5/7 compressed textures via love.image.CompressedData. Some internals are still iffy.
Alex Szpakowski <slime73@gmail.com>
parents:
1282
diff
changeset
|
113 try |
|
2a5ef265e040
Added support for DXT1/3/5 and BC5/7 compressed textures via love.image.CompressedData. Some internals are still iffy.
Alex Szpakowski <slime73@gmail.com>
parents:
1282
diff
changeset
|
114 { |
|
1422
377f9dad7a2d
Replaced the devil love.image module with love.image.magpie, which can decide which image library to use in a similar manner to love.sound.lullaby. Some rough edges still exist.
Alex Szpakowski <slime73@gmail.com>
parents:
1420
diff
changeset
|
115 compressed = instance->isCompressed(data); |
|
1420
2a5ef265e040
Added support for DXT1/3/5 and BC5/7 compressed textures via love.image.CompressedData. Some internals are still iffy.
Alex Szpakowski <slime73@gmail.com>
parents:
1282
diff
changeset
|
116 } |
|
2a5ef265e040
Added support for DXT1/3/5 and BC5/7 compressed textures via love.image.CompressedData. Some internals are still iffy.
Alex Szpakowski <slime73@gmail.com>
parents:
1282
diff
changeset
|
117 catch (love::Exception &e) |
|
2a5ef265e040
Added support for DXT1/3/5 and BC5/7 compressed textures via love.image.CompressedData. Some internals are still iffy.
Alex Szpakowski <slime73@gmail.com>
parents:
1282
diff
changeset
|
118 { |
|
2a5ef265e040
Added support for DXT1/3/5 and BC5/7 compressed textures via love.image.CompressedData. Some internals are still iffy.
Alex Szpakowski <slime73@gmail.com>
parents:
1282
diff
changeset
|
119 return luaL_error(L, "%s", e.what()); |
|
2a5ef265e040
Added support for DXT1/3/5 and BC5/7 compressed textures via love.image.CompressedData. Some internals are still iffy.
Alex Szpakowski <slime73@gmail.com>
parents:
1282
diff
changeset
|
120 } |
|
1423
5b9ebe6a9a7e
Cosmetic code improvements
Alex Szpakowski <slime73@gmail.com>
parents:
1422
diff
changeset
|
121 luax_pushboolean(L, compressed); |
|
1420
2a5ef265e040
Added support for DXT1/3/5 and BC5/7 compressed textures via love.image.CompressedData. Some internals are still iffy.
Alex Szpakowski <slime73@gmail.com>
parents:
1282
diff
changeset
|
122 return 1; |
|
2a5ef265e040
Added support for DXT1/3/5 and BC5/7 compressed textures via love.image.CompressedData. Some internals are still iffy.
Alex Szpakowski <slime73@gmail.com>
parents:
1282
diff
changeset
|
123 } |
|
2a5ef265e040
Added support for DXT1/3/5 and BC5/7 compressed textures via love.image.CompressedData. Some internals are still iffy.
Alex Szpakowski <slime73@gmail.com>
parents:
1282
diff
changeset
|
124 |
| 1096 | 125 // List of functions to wrap. |
| 126 static const luaL_Reg functions[] = | |
| 127 { | |
| 128 { "newImageData", w_newImageData }, | |
|
1420
2a5ef265e040
Added support for DXT1/3/5 and BC5/7 compressed textures via love.image.CompressedData. Some internals are still iffy.
Alex Szpakowski <slime73@gmail.com>
parents:
1282
diff
changeset
|
129 { "newCompressedData", w_newCompressedData }, |
|
2a5ef265e040
Added support for DXT1/3/5 and BC5/7 compressed textures via love.image.CompressedData. Some internals are still iffy.
Alex Szpakowski <slime73@gmail.com>
parents:
1282
diff
changeset
|
130 { "isCompressed", w_isCompressed }, |
| 1096 | 131 { 0, 0 } |
| 132 }; | |
| 133 | |
| 134 static const lua_CFunction types[] = | |
| 135 { | |
| 136 luaopen_imagedata, | |
|
1420
2a5ef265e040
Added support for DXT1/3/5 and BC5/7 compressed textures via love.image.CompressedData. Some internals are still iffy.
Alex Szpakowski <slime73@gmail.com>
parents:
1282
diff
changeset
|
137 luaopen_compresseddata, |
| 1096 | 138 0 |
| 139 }; | |
| 140 | |
| 141 extern "C" int luaopen_love_image(lua_State *L) | |
| 142 { | |
| 143 if (instance == 0) | |
| 144 { | |
| 145 try | |
| 146 { | |
|
1422
377f9dad7a2d
Replaced the devil love.image module with love.image.magpie, which can decide which image library to use in a similar manner to love.sound.lullaby. Some rough edges still exist.
Alex Szpakowski <slime73@gmail.com>
parents:
1420
diff
changeset
|
147 instance = new love::image::magpie::Image(); |
| 1096 | 148 } |
| 149 catch(Exception &e) | |
| 150 { | |
| 151 return luaL_error(L, "%s", e.what()); | |
| 152 } | |
| 153 } | |
| 154 else | |
| 155 instance->retain(); | |
| 156 | |
| 157 WrappedModule w; | |
| 158 w.module = instance; | |
| 159 w.name = "image"; | |
| 160 w.flags = MODULE_IMAGE_T; | |
| 161 w.functions = functions; | |
| 162 w.types = types; | |
| 163 | |
| 164 return luax_register_module(L, w); | |
| 165 } | |
| 166 | |
| 167 } // image | |
| 168 } // love |
