From fd9cef83e6da75079fa3f0148920752c4434fbd8 Mon Sep 17 00:00:00 2001 From: Pixel Date: Wed, 27 May 2009 11:44:52 -0700 Subject: Enabling full alpha blending support. --- src/plugin-luaosmesa.cc | 40 +++++++++++++++++++++++++++------------- 1 file changed, 27 insertions(+), 13 deletions(-) diff --git a/src/plugin-luaosmesa.cc b/src/plugin-luaosmesa.cc index daf0fd4..a594e0e 100644 --- a/src/plugin-luaosmesa.cc +++ b/src/plugin-luaosmesa.cc @@ -1,5 +1,3 @@ -#include - #include #include #include @@ -92,14 +90,19 @@ void flip_scene(scene_t * scene, const char * buffer, int width, int height, boo glFinish(); Magick::Image i(width, height, "BGRA", Magick::CharPixel, buffer); + i.matte(true); i.flip(); i.animationDelay(6); - i.opacity(0); + if (scene->scene.size() >= 1) + i.opacity(255); + if (scene->scene.size() == 1) + scene->scene.begin()->opacity(255); if (upscale) { - i.resize(Magick::Geometry(width / 2, height / 2)); +// i.resize(Magick::Geometry(width / 2, height / 2)); + i.sample(Magick::Geometry(width / 2, height / 2)); } - + scene->scene.push_back(i); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); } @@ -108,22 +111,30 @@ void * dump_scene_threaded(void * arg) { scene_t * scene = (scene_t *) arg; char fname[2049]; - writeImages(scene->scene.begin(), scene->scene.end(), scene->tmp_filename.to_charp()); + if (scene->scene.size() == 1) { + scene->scene.begin()->write(scene->tmp_filename.to_charp()); + } else { + writeImages(scene->scene.begin(), scene->scene.end(), scene->tmp_filename.to_charp()); + } unlink(scene->filename.to_charp()); rename(scene->tmp_filename.to_charp(), scene->filename.to_charp()); delete scene; pthread_exit(0); } -void dump_scene(scene_t * scene, const String & filename, Handle * out, const char * buffer, int width, int height, bool upscale) { +void dump_scene(scene_t * scene, const String & filename, Handle * out, const char * buffer, int width, int height, bool upscale, const String & format) { if (scene->scene.begin() == scene->scene.end()) flip_scene(scene, buffer, width, height, upscale); if (out) { Magick::Blob b; - scene->scene.begin()->magick("JPEG"); + scene->scene.begin()->magick(format.to_charp()); scene->scene.begin()->quality(95); - writeImages(scene->scene.begin(), scene->scene.end(), &b); + if (scene->scene.size() == 1) { + scene->scene.begin()->write(&b); + } else { + writeImages(scene->scene.begin(), scene->scene.end(), &b); + } out->write(b.data(), b.length()); delete scene; } else { @@ -160,7 +171,7 @@ enum plugin_osmesa_functions_t { struct lua_functypes_t plugin_osmesa_functions[] = { { PLUGIN_OSMESA_INITOSMESA, "InitOSMesa", 3, 4, { BLUA_USERDATA | BLUA_NIL, BLUA_NUMBER, BLUA_NUMBER, BLUA_BOOLEAN } }, { PLUGIN_OSMESA_FLIPSCENE, "FlipScene", 1, 1, { BLUA_USERDATA } }, - { PLUGIN_OSMESA_DUMPSCENE, "DumpScene", 2, 2, { BLUA_USERDATA, BLUA_STRING | BLUA_OBJECT } }, + { PLUGIN_OSMESA_DUMPSCENE, "DumpScene", 2, 3, { BLUA_USERDATA, BLUA_STRING | BLUA_OBJECT, BLUA_STRING } }, { PLUGIN_OSMESA_LOADTEX, "LoadTex", 1, 1, { BLUA_STRING } }, { -1, 0, 0, 0, 0 } }; @@ -219,10 +230,13 @@ int sLua_plugin_osmesa::plugin_osmesa_proceed_statics(Lua * L, int n, int caller case PLUGIN_OSMESA_DUMPSCENE: if (L->isstring(2)) { filename = L->tostring(2); - dump_scene((scene_t *) L->touserdata(1), filename, 0, (char *) buffer, width, height, upscale); + dump_scene((scene_t *) L->touserdata(1), filename, 0, (char *) buffer, width, height, upscale, ""); } else { - Handle * t = (Handle *) LuaObject::getme(L, 2); - dump_scene((scene_t *) L->touserdata(1), "", t, (char *) buffer, width, height, upscale); + Handle * t = lua_recast(L, 2); + String format = "JPEG"; + if (n == 3) + format = L->tostring(3); + dump_scene((scene_t *) L->touserdata(1), "", t, (char *) buffer, width, height, upscale, format); } break; case PLUGIN_OSMESA_LOADTEX: -- cgit v1.2.3