From 9387a8eecefce08102b254a8cc1f9f068f9d4f02 Mon Sep 17 00:00:00 2001 From: Marten Richter Date: Sun, 5 Oct 2014 12:43:06 +0200 Subject: [PATCH] Screenshot support for vector based osd on raspberry pi --- command.cc | 5 +++++ main.cc | 1 + osdopenvg.cc | 35 +++++++++++++++++++++++++++++++++++ osdopenvg.h | 2 ++ osdvector.cc | 25 ++++++++++++++++++++++++- osdvector.h | 2 ++ 6 files changed, 69 insertions(+), 1 deletion(-) diff --git a/command.cc b/command.cc index f9f8946..4c41ce1 100644 --- a/command.cc +++ b/command.cc @@ -417,7 +417,12 @@ void Command::processMessage(Message* m) } case Message::SCREENSHOT: { +#ifdef VOMP_PLATTFORM_MVP Osd::getInstance()->screenShot("/out.jpg"); +#else + logger->log("Osd", Log::NOTICE, "Screenshot Message arrived"); + Osd::getInstance()->screenShot("out.jpg"); +#endif break; } case Message::CONNECTION_LOST: diff --git a/main.cc b/main.cc index 360eea6..b8d193a 100644 --- a/main.cc +++ b/main.cc @@ -429,6 +429,7 @@ void sighandler(int signalReceived) } case SIGUSR1: { + logger->log("Core", Log::NOTICE, "USR1 signal, screenshot..."); command->sig1(); break; } diff --git a/osdopenvg.cc b/osdopenvg.cc index 86d2dc4..ca67d8d 100644 --- a/osdopenvg.cc +++ b/osdopenvg.cc @@ -328,6 +328,41 @@ void OsdOpenVG::getScreenSize(int &width, int &height) height=BACKBUFFER_HEIGHT; } +void OsdOpenVG::getRealScreenSize(int &width, int &height) +{ + width=display_width; + height=display_height; +} + +bool OsdOpenVG::screenShot(void *buffer, int width, int height, bool osd /*include osd*/) +{ + if (!initted) return false; + if (!buffer) return false; + + DISPMANX_RESOURCE_HANDLE_T res; + DISPMANX_DISPLAY_HANDLE_T display; + + uint32_t image_ptr; + VC_RECT_T rect; + res=vc_dispmanx_resource_create(VC_IMAGE_RGBA32,width,height,&image_ptr); + display=vc_dispmanx_display_open(0); + if (!osd ) { + vc_dispmanx_snapshot(display, res, + (DISPMANX_TRANSFORM_T)(DISPMANX_SNAPSHOT_NO_RGB|DISPMANX_SNAPSHOT_FILL/*|DISPMANX_SNAPSHOT_PACK*/)); + } + else + { + vc_dispmanx_snapshot(display, res, + (DISPMANX_TRANSFORM_T)(DISPMANX_SNAPSHOT_FILL)); + } + vc_dispmanx_rect_set(&rect,0,0,width,height); + vc_dispmanx_resource_read_data(res, &rect, buffer, width*4); + vc_dispmanx_resource_delete(res); + vc_dispmanx_display_close(display); + return true; + +} + void OsdOpenVG::initPaths() { diff --git a/osdopenvg.h b/osdopenvg.h index 49fdfe6..cd21c3d 100644 --- a/osdopenvg.h +++ b/osdopenvg.h @@ -86,6 +86,7 @@ class OsdOpenVG : public OsdVector, public Thread_TYPE, public EGLPictureCreator int shutdown(); int stopUpdate(); + bool screenShot(void *buffer, int width, int height, bool osd /*include osd*/); @@ -125,6 +126,7 @@ protected: long long lastrendertime; void InternalRendering(); void getScreenSize(int &width, int &height); + void getRealScreenSize(int &width, int &height); diff --git a/osdvector.cc b/osdvector.cc index da4212c..01f4d9a 100644 --- a/osdvector.cc +++ b/osdvector.cc @@ -122,7 +122,30 @@ int OsdVector::getFD() void OsdVector::screenShot(const char* fileName) { - //Do nothing, + //Do nothing, if no libmagick is there +#ifdef PICTURE_DECODER_MAGICK + int width,height; + getRealScreenSize(width,height); + size_t length=width*height*4; + void *mem=malloc(length); + + try { + Blob myblob; + if (!screenShot(mem,width,height,true)) { + Log::getInstance()->log("OsdVector", Log::DEBUG, "Screenshot failed!"); + free(mem); + return; + } + myblob.updateNoCopy(mem,length,Blob::MallocAllocator); + Image image(myblob,Geometry(width,height),8,"RGBA"); + image.write(fileName); + }catch( Exception &error_ ) + { + Log::getInstance()->log("MagickEncoder", Log::DEBUG, "Libmagick: %s",error_.what()); + + } + +#endif } Surface * OsdVector::createNewSurface() diff --git a/osdvector.h b/osdvector.h index b8d3f21..a3e193c 100644 --- a/osdvector.h +++ b/osdvector.h @@ -212,6 +212,7 @@ class OsdVector : public Osd int getFD(); void screenShot(const char* fileName); + virtual bool screenShot(void *buffer, int width, int height, bool osd /*include osd*/)=0; Surface * createNewSurface(); void BeginPainting(); @@ -241,6 +242,7 @@ class OsdVector : public Osd unsigned int getStyleRef(const DrawStyle &c); virtual void removeStyleRef(unsigned int ref); virtual void getScreenSize(int &width, int &height)=0; + virtual void getRealScreenSize(int &width, int &height)=0; // should be only called from command thread void informPicture(LoadIndex index, ImageIndex i_index); -- 2.39.2