gsl-shell.git - gsl-shell

index : gsl-shell.git
gsl-shell
summary refs log tree commit diff
path: root/agg-plot/bitmap-plot.cpp
diff options
context:
space:
mode:
authorfrancesco-ST <francesco.abbate@st.com>2010年11月29日 16:06:20 +0100
committerfrancesco-ST <francesco.abbate@st.com>2010年11月29日 16:06:20 +0100
commit6ad9ba6096db4d02ff8c09d5394f16de1d331bb6 (patch)
treef414a00a742260bcb6acae579538aa5e1181a1ba /agg-plot/bitmap-plot.cpp
parent21adabf6de2744550cd90b1012f81328f60a3e49 (diff)
downloadgsl-shell-6ad9ba6096db4d02ff8c09d5394f16de1d331bb6.tar.gz
plot save as bitmap file implementation
Diffstat (limited to 'agg-plot/bitmap-plot.cpp')
-rw-r--r--agg-plot/bitmap-plot.cpp 60
1 files changed, 60 insertions, 0 deletions
diff --git a/agg-plot/bitmap-plot.cpp b/agg-plot/bitmap-plot.cpp
new file mode 100644
index 00000000..faef9710
--- /dev/null
+++ b/agg-plot/bitmap-plot.cpp
@@ -0,0 +1,60 @@
+
+extern "C" {
+#include "lua.h"
+#include "lauxlib.h"
+}
+
+#include "bitmap-plot.h"
+#include "lua-cpp-utils.h"
+#include "lua-plot-cpp.h"
+#include "gs-types.h"
+#include "canvas.h"
+#include "colors.h"
+#include "agg-pixfmt-config.h"
+#include "platform_support_ext.h"
+
+int
+bitmap_save_image (lua_State *L)
+{
+ lua_plot *p = object_check<lua_plot>(L, 1, GS_PLOT);
+ const char *fn = luaL_checkstring (L, 2);
+ int w = luaL_optint (L, 3, 480), h = luaL_optint (L, 4, 480);
+
+ if (w <= 0 || w > 1024 * 8)
+ luaL_error (L, "width out of range");
+
+ if (h <= 0 || h > 1024 * 8)
+ luaL_error (L, "height out of range");
+
+ unsigned char * buffer = 0;
+ try
+ {
+ agg::rendering_buffer rbuf_tmp;
+ unsigned row_size = w * (gslshell::bpp / 8);
+ unsigned buf_size = h * row_size;
+ buffer = new unsigned char[buf_size];
+ rbuf_tmp.attach(buffer, w, h, gslshell::flip_y ? row_size : -row_size);
+
+ canvas can(rbuf_tmp, w, h, colors::white);
+ agg::trans_affine mtx(w, 0.0, 0.0, h, 0.0, 0.0);
+
+ agg::rect_base<int> r = rect_of_slot_matrix<int>(mtx);
+ can.clear_box(r);
+
+ p->draw(can, mtx);
+
+ if (! platform_support_ext::save_image_file (rbuf_tmp, fn))
+ {
+ delete [] buffer;
+ return luaL_error (L, "error saving image in filename %s", fn);
+ }
+ }
+ catch (std::bad_alloc&)
+ {
+ if (buffer == 0) delete [] buffer;
+ return luaL_error (L, "out of virtual memory");
+ }
+
+ delete [] buffer;
+ return 0;
+}
generated by cgit v1.2.3 (git 2.25.1) at 2025年09月12日 06:36:08 +0000

AltStyle によって変換されたページ (->オリジナル) /