summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorm.Rcu <>2012-01-24 22:40:06 +0100
committerJohns <johns98@gmx.net>2012-01-24 22:40:06 +0100
commit2dff69dc14ef8f59e8ae9e50dfa6b973d42f3369 (patch)
treeaf010f03e6a35d327b99462d6db892f8a207ec4d
parent5668fa22d2d62385b6901f957d2d47d3385aef91 (diff)
downloadvdr-plugin-softhddevice-2dff69dc14ef8f59e8ae9e50dfa6b973d42f3369.tar.gz
vdr-plugin-softhddevice-2dff69dc14ef8f59e8ae9e50dfa6b973d42f3369.tar.bz2
Add support for grab jpeg image.
-rw-r--r--ChangeLog7
-rw-r--r--Makefile5
-rw-r--r--softhddev.c59
-rw-r--r--video.c10
-rw-r--r--video.h2
5 files changed, 75 insertions, 8 deletions
diff --git a/ChangeLog b/ChangeLog
index 116beba..75178df 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,10 @@
+User m.Rcu
+Date: Tue Jan 24 22:38:30 CET 2012
+
+ Add support for grab jpeg image.
+
User johns
-Date:
+Date: Tue Jan 24 22:25:33 CET 2012
Fix bug: VaapiOsdExit doesn't deassociate osd surface.
Fix bug: First OSD can show random pixels.
diff --git a/Makefile b/Makefile
index 568b40f..2e577b3 100644
--- a/Makefile
+++ b/Makefile
@@ -23,6 +23,7 @@ CONFIG := #-DDEBUG
CONFIG += $(shell pkg-config --exists vdpau && echo "-DUSE_VDPAU")
CONFIG += $(shell pkg-config --exists libva && echo "-DUSE_VAAPI")
CONFIG += $(shell pkg-config --exists alsa && echo "-DUSE_ALSA")
+CONFIG += $(shell ls /usr/lib/libjpeg* >/dev/null 2>&1 && echo "-DUSE_JPEG")
CONFIG += -DUSE_OSS
### The C++ compiler and options:
@@ -89,7 +90,9 @@ LIBS += -lrt \
$(if $(findstring USE_VAAPI,$(CONFIG)), \
`pkg-config --libs libva-x11 libva-glx libva`) \
$(if $(findstring USE_ALSA,$(CONFIG)), \
- `pkg-config --libs alsa`)
+ `pkg-config --libs alsa`) \
+ $(if $(findstring USE_JPEG,$(CONFIG)), \
+ -ljpeg)
### The object files (add further files here):
diff --git a/softhddev.c b/softhddev.c
index 7a9272d..cbeaed1 100644
--- a/softhddev.c
+++ b/softhddev.c
@@ -39,6 +39,9 @@
#define __USE_GNU
#endif
#include <pthread.h>
+#ifdef USE_JPEG
+#include <jpeglib.h>
+#endif
#include "misc.h"
#include "softhddev.h"
@@ -813,6 +816,48 @@ int PlayVideo(const uint8_t * data, int size)
return size;
}
+#ifdef USE_JPEG
+
+uint8_t *CreateJpeg(uint8_t * image, int raw_size, int *size, int quality,
+ int width, int height)
+{
+ struct jpeg_compress_struct cinfo;
+ struct jpeg_error_mgr jerr;
+ JSAMPROW row_ptr[1];
+ int row_stride;
+ uint8_t *outbuf;
+ long unsigned int outsize;
+
+ outbuf = NULL;
+ outsize = 0;
+ cinfo.err = jpeg_std_error(&jerr);
+ jpeg_create_compress(&cinfo);
+ jpeg_mem_dest(&cinfo, &outbuf, &outsize);
+
+ cinfo.image_width = width;
+ cinfo.image_height = height;
+ cinfo.input_components = raw_size / height / width;
+ cinfo.in_color_space = JCS_RGB;
+
+ jpeg_set_defaults(&cinfo);
+ jpeg_set_quality(&cinfo, quality, TRUE);
+ jpeg_start_compress(&cinfo, TRUE);
+
+ row_stride = width * 3;
+ while (cinfo.next_scanline < cinfo.image_height) {
+ row_ptr[0] = &image[cinfo.next_scanline * row_stride];
+ jpeg_write_scanlines(&cinfo, row_ptr, 1);
+ }
+
+ jpeg_finish_compress(&cinfo);
+ jpeg_destroy_compress(&cinfo);
+ *size = outsize;
+
+ return outbuf;
+}
+
+#endif
+
/**
** Grabs the currently visible screen image.
**
@@ -825,14 +870,26 @@ int PlayVideo(const uint8_t * data, int size)
uint8_t *GrabImage(int *size, int jpeg, int quality, int width, int height)
{
if (jpeg) {
+#ifdef USE_JPEG
+ int raw_size;
+ uint8_t *image;
+ uint8_t *jpg_image;
+
+ raw_size = 0;
+ image = VideoGrab(&raw_size, &width, &height, 0);
+ jpg_image = CreateJpeg(image, raw_size, size, quality, width, height);
+ free(image);
+ return jpg_image;
+#else
(void)quality;
Error(_("softhddev: jpeg grabbing not supported\n"));
return NULL;
+#endif
}
if (width != -1 && height != -1) {
Warning(_("softhddev: scaling unsupported\n"));
}
- return VideoGrab(size, &width, &height);
+ return VideoGrab(size, &width, &height, 1);
}
//////////////////////////////////////////////////////////////////////////////
diff --git a/video.c b/video.c
index 5e1d84a..02628e0 100644
--- a/video.c
+++ b/video.c
@@ -7739,7 +7739,7 @@ int64_t VideoGetClock(void)
///
/// Grab full screen image.
///
-uint8_t *VideoGrab(int *size, int *width, int *height)
+uint8_t *VideoGrab(int *size, int *width, int *height, int write_header)
{
Debug(3, "video: grab\n");
@@ -7771,9 +7771,11 @@ uint8_t *VideoGrab(int *size, int *width, int *height)
if (scale_height <= 0) {
scale_height = *height;
}
-
- n = snprintf(buf, sizeof(buf), "P6\n%d\n%d\n255\n", scale_width,
- scale_height);
+ n = 0;
+ if (write_header) {
+ n = snprintf(buf, sizeof(buf), "P6\n%d\n%d\n255\n", scale_width,
+ scale_height);
+ }
rgb = malloc(scale_width * scale_height * 3 + n);
if (!rgb) {
Error(_("video: out of memory\n"));
diff --git a/video.h b/video.h
index c6c3bc6..443cf16 100644
--- a/video.h
+++ b/video.h
@@ -115,7 +115,7 @@ extern void VideoGetOsdSize(int *, int *);
extern int64_t VideoGetClock(void); ///< Get video clock.
/// Grab screen.
-extern uint8_t *VideoGrab(int *, int *, int *);
+extern uint8_t *VideoGrab(int *, int *, int *, int);
extern void VideoOsdInit(void); ///< Setup osd.
extern void VideoOsdExit(void); ///< Cleanup osd.