Add support for grab jpeg image.

This commit is contained in:
m.Rcu 2012-01-24 22:40:06 +01:00 committed by Johns
parent 5668fa22d2
commit 2dff69dc14
5 changed files with 75 additions and 8 deletions

View File

@ -1,5 +1,10 @@
User m.Rcu
Date: Tue Jan 24 22:38:30 CET 2012
Add support for grab jpeg image.
User johns User johns
Date: Date: Tue Jan 24 22:25:33 CET 2012
Fix bug: VaapiOsdExit doesn't deassociate osd surface. Fix bug: VaapiOsdExit doesn't deassociate osd surface.
Fix bug: First OSD can show random pixels. Fix bug: First OSD can show random pixels.

View File

@ -23,6 +23,7 @@ CONFIG := #-DDEBUG
CONFIG += $(shell pkg-config --exists vdpau && echo "-DUSE_VDPAU") CONFIG += $(shell pkg-config --exists vdpau && echo "-DUSE_VDPAU")
CONFIG += $(shell pkg-config --exists libva && echo "-DUSE_VAAPI") CONFIG += $(shell pkg-config --exists libva && echo "-DUSE_VAAPI")
CONFIG += $(shell pkg-config --exists alsa && echo "-DUSE_ALSA") 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 CONFIG += -DUSE_OSS
### The C++ compiler and options: ### The C++ compiler and options:
@ -89,7 +90,9 @@ LIBS += -lrt \
$(if $(findstring USE_VAAPI,$(CONFIG)), \ $(if $(findstring USE_VAAPI,$(CONFIG)), \
`pkg-config --libs libva-x11 libva-glx libva`) \ `pkg-config --libs libva-x11 libva-glx libva`) \
$(if $(findstring USE_ALSA,$(CONFIG)), \ $(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): ### The object files (add further files here):

View File

@ -39,6 +39,9 @@
#define __USE_GNU #define __USE_GNU
#endif #endif
#include <pthread.h> #include <pthread.h>
#ifdef USE_JPEG
#include <jpeglib.h>
#endif
#include "misc.h" #include "misc.h"
#include "softhddev.h" #include "softhddev.h"
@ -813,6 +816,48 @@ int PlayVideo(const uint8_t * data, int size)
return 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. ** 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) uint8_t *GrabImage(int *size, int jpeg, int quality, int width, int height)
{ {
if (jpeg) { 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; (void)quality;
Error(_("softhddev: jpeg grabbing not supported\n")); Error(_("softhddev: jpeg grabbing not supported\n"));
return NULL; return NULL;
#endif
} }
if (width != -1 && height != -1) { if (width != -1 && height != -1) {
Warning(_("softhddev: scaling unsupported\n")); Warning(_("softhddev: scaling unsupported\n"));
} }
return VideoGrab(size, &width, &height); return VideoGrab(size, &width, &height, 1);
} }
////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////

10
video.c
View File

@ -7739,7 +7739,7 @@ int64_t VideoGetClock(void)
/// ///
/// Grab full screen image. /// 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"); Debug(3, "video: grab\n");
@ -7771,9 +7771,11 @@ uint8_t *VideoGrab(int *size, int *width, int *height)
if (scale_height <= 0) { if (scale_height <= 0) {
scale_height = *height; scale_height = *height;
} }
n = 0;
n = snprintf(buf, sizeof(buf), "P6\n%d\n%d\n255\n", scale_width, if (write_header) {
scale_height); n = snprintf(buf, sizeof(buf), "P6\n%d\n%d\n255\n", scale_width,
scale_height);
}
rgb = malloc(scale_width * scale_height * 3 + n); rgb = malloc(scale_width * scale_height * 3 + n);
if (!rgb) { if (!rgb) {
Error(_("video: out of memory\n")); Error(_("video: out of memory\n"));

View File

@ -115,7 +115,7 @@ extern void VideoGetOsdSize(int *, int *);
extern int64_t VideoGetClock(void); ///< Get video clock. extern int64_t VideoGetClock(void); ///< Get video clock.
/// Grab screen. /// 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 VideoOsdInit(void); ///< Setup osd.
extern void VideoOsdExit(void); ///< Cleanup osd. extern void VideoOsdExit(void); ///< Cleanup osd.