From 7e42d823081f22d16fa26eab8771e4f78b09fb99 Mon Sep 17 00:00:00 2001 From: Alex Szpakowski Date: Wed, 27 May 2015 21:21:47 -0300 Subject: [PATCH] Added an optional third argument to the width/height variant of love.image.newImageData. The new argument is a string containing raw byte pixel data to copy to the new ImageData (e.g. the result of a previous ImageData:getString with an ImageData of the same width and height..) --- src/modules/graphics/opengl/Graphics.h | 2 +- src/modules/image/wrap_Image.cpp | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/modules/graphics/opengl/Graphics.h b/src/modules/graphics/opengl/Graphics.h index 5279e7f26..236148aab 100644 --- a/src/modules/graphics/opengl/Graphics.h +++ b/src/modules/graphics/opengl/Graphics.h @@ -391,7 +391,7 @@ public: void circle(DrawMode mode, float x, float y, float radius, int points = 10); /** - * Draws an eclipse using the specified arguments. + * Draws an ellipse using the specified arguments. * @param mode The mode of drawing (line/filled). * @param x X-coordinate of center * @param y Y-coordinate of center diff --git a/src/modules/image/wrap_Image.cpp b/src/modules/image/wrap_Image.cpp index 34c360ee9..93be52c43 100644 --- a/src/modules/image/wrap_Image.cpp +++ b/src/modules/image/wrap_Image.cpp @@ -44,9 +44,26 @@ int w_newImageData(lua_State *L) if (w <= 0 || h <= 0) return luaL_error(L, "Invalid image size."); + size_t numbytes = 0; + const char *bytes = nullptr; + + if (!lua_isnoneornil(L, 3)) + bytes = luaL_checklstring(L, 3, &numbytes); + ImageData *t = nullptr; luax_catchexcept(L, [&](){ t = instance()->newImageData(w, h); }); + if (bytes) + { + if (numbytes != t->getSize()) + { + t->release(); + return luaL_error(L, "The size of the raw byte string must match the ImageData's actual size in bytes."); + } + + memcpy(t->getData(), bytes, t->getSize()); + } + luax_pushtype(L, IMAGE_IMAGE_DATA_ID, t); t->release(); return 1;