diff options
author | m.Rcu <> | 2012-01-24 22:40:06 +0100 |
---|---|---|
committer | Johns <johns98@gmx.net> | 2012-01-24 22:40:06 +0100 |
commit | 2dff69dc14ef8f59e8ae9e50dfa6b973d42f3369 (patch) | |
tree | af010f03e6a35d327b99462d6db892f8a207ec4d /softhddev.c | |
parent | 5668fa22d2d62385b6901f957d2d47d3385aef91 (diff) | |
download | vdr-plugin-softhddevice-2dff69dc14ef8f59e8ae9e50dfa6b973d42f3369.tar.gz vdr-plugin-softhddevice-2dff69dc14ef8f59e8ae9e50dfa6b973d42f3369.tar.bz2 |
Add support for grab jpeg image.
Diffstat (limited to 'softhddev.c')
-rw-r--r-- | softhddev.c | 59 |
1 files changed, 58 insertions, 1 deletions
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); } ////////////////////////////////////////////////////////////////////////////// |