diff --git a/configure.ac b/configure.ac index 04474bd9..df600e78 100644 --- a/configure.ac +++ b/configure.ac @@ -238,6 +238,16 @@ if test x$have_slang = xno; then AC_MSG_ERROR([*** SLANG development files not found!]) fi +dnl Check for GD +GD_LIBS="" +FREEJ_CHECK_LIB_HEADER([gd], [gdImageCreateTrueColor], [gd.h], + [have_gd=yes], [have_gd=no]) +if test x$have_gd = xyes; then + GD_LIBS="-lgd" + AC_DEFINE(WITH_GD,1,[define if compiling with GD to support screenshot taking]) + AC_SUBST([GD_LIBS]) +fi + dnl ============================================================== dnl Check for SDL dnl ============================================================== @@ -981,7 +991,8 @@ FREEJ_LIBS="-lpthread -lm -lrt $DL_LIBS \ \$(UNICAP_LIBS) \ \$(X11_LIBS) \ \$(CAIRO_LIBS) \ - \$(XIPH_LIBS)" + \$(XIPH_LIBS) \ + \$(GD_LIBS)" AC_SUBST(FREEJ_LIBS) dnl ########################################################################### @@ -1158,6 +1169,10 @@ fi VRB([ LIBS : $SDLIMAGE_LIBS]) VRB([ CFLAGS: $SDLIMAGE_CFLAGS]) +if test x$have_gd = xyes; then +INFO([= libGD (dynamic)]) +VRB([ LIBS : $GD_LIBS]) +fi dnl #### optional stuff INFO_N([= AAlib : ]) diff --git a/scripts/javascript/examples/screenshot.js b/scripts/javascript/examples/screenshot.js new file mode 100644 index 00000000..0a6fe303 --- /dev/null +++ b/scripts/javascript/examples/screenshot.js @@ -0,0 +1,6 @@ + + +include("test_rand.js"); + +rand_kbd.released_s = function() { scr.save_frame("rand_shot.png"); } + diff --git a/src/include/jsparser_data.h b/src/include/jsparser_data.h index 6f2bb9d7..a831d0f2 100644 --- a/src/include/jsparser_data.h +++ b/src/include/jsparser_data.h @@ -313,6 +313,7 @@ JS(screen_initialized); JS(screen_add_layer); JS(screen_rem_layer); JS(screen_list_layers); +JS(screen_save_frame); //////////////////////////////// diff --git a/src/include/screen.h b/src/include/screen.h index 91bb468f..d01788e7 100644 --- a/src/include/screen.h +++ b/src/include/screen.h @@ -117,6 +117,8 @@ class ViewPort : public Entry { Linklist encoders; ///< linked list of registered encoders + void save_frame(char *file); ///< save a screenshot of the current frame into file + void handle_resize(); virtual void set_magnification(int algo) { }; diff --git a/src/screen.cpp b/src/screen.cpp index 25259c35..461cffac 100644 --- a/src/screen.cpp +++ b/src/screen.cpp @@ -31,6 +31,10 @@ #include +#ifdef WITH_GD +#include +#endif + ViewPort::ViewPort() : Entry() { @@ -182,6 +186,28 @@ bool ViewPort::add_encoder(VideoEncoder *enc) { return true; } +#ifdef WITH_GD +void ViewPort::save_frame(char *file) { + FILE *fp; + gdImagePtr im; + int *src; + int x,y; + + im = gdImageCreateTrueColor(geo.w, geo.h); + src = (int*)coords(0,0); + for(y=0; y < geo.h; y++) { + for (x=0; x < geo.w; x++) { + gdImageSetPixel(im, x, y, src[x] & 0x00FFFFFF); + //im->tpixels[y][x] = src[x] & 0x00FFFFFF; + } + src += geo.w; + } + fp = fopen(file, "wb"); + gdImagePng(im,fp); + fclose(fp); +} +#endif + void ViewPort::blit_layers() { Layer *lay; diff --git a/src/screen_js.cpp b/src/screen_js.cpp index 379d64e6..c05f67dc 100644 --- a/src/screen_js.cpp +++ b/src/screen_js.cpp @@ -34,6 +34,7 @@ JSFunctionSpec screen_methods[] = { {"rem_layer", screen_rem_layer, 1}, {"list_layers", screen_list_layers, 0}, {"is_initialized", screen_initialized, 0}, + {"save_frame", screen_save_frame, 1}, {0} }; @@ -104,6 +105,23 @@ JS(screen_initialized) { return JS_TRUE; } +JS(screen_save_frame) { + func("%s",__PRETTY_FUNCTION__); + JS_CHECK_ARGC(1); + + ViewPort *screen = (ViewPort*)JS_GetPrivate(cx,obj); + if(!screen) { + JS_ERROR("Screen core data is NULL"); + return JS_FALSE; + } + + char *file = js_get_string(argv[0]); + + screen->save_frame(file); + + return JS_TRUE; +} + JS(screen_list_layers) { func("%s",__PRETTY_FUNCTION__); JSObject *arr;