diff options
Diffstat (limited to 'libxrdp/xrdp_jpeg_compress.c')
| -rw-r--r-- | libxrdp/xrdp_jpeg_compress.c | 139 |
1 files changed, 136 insertions, 3 deletions
diff --git a/libxrdp/xrdp_jpeg_compress.c b/libxrdp/xrdp_jpeg_compress.c index 82a816a0..a41bd1cf 100644 --- a/libxrdp/xrdp_jpeg_compress.c +++ b/libxrdp/xrdp_jpeg_compress.c @@ -20,7 +20,112 @@ #include "libxrdp.h" -#if defined(XRDP_JPEG) +#if defined(XRDP_TJPEG) + +/* turbo jpeg */ + +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <turbojpeg.h> + +/*****************************************************************************/ +int APP_CC +xrdp_jpeg_compress(void *handle, char *in_data, int width, int height, + struct stream *s, int bpp, int byte_limit, + int start_line, struct stream *temp_s, + int e, int quality) +{ + int error; + int i; + int j; + unsigned int pixel; + unsigned int *src32; + unsigned int *dst32; + unsigned long cdata_bytes; + unsigned char *src_buf; + unsigned char *dst_buf; + char *temp_buf; + tjhandle tj_han; + + if (bpp != 24) + { + g_writeln("xrdp_jpeg_compress: bpp wrong %d", bpp); + return height; + } + if (handle == 0) + { + g_writeln("xrdp_jpeg_compress: handle is nil"); + return height; + } + tj_han = (tjhandle) handle; + cdata_bytes = byte_limit; + src_buf = (unsigned char *) in_data; + dst_buf = (unsigned char *) (s->p); + temp_buf = 0; + if (e == 0) + { + src_buf = (unsigned char*)in_data; + } + else + { + temp_buf = (char *) g_malloc((width + e) * height * 4, 0); + dst32 = (unsigned int *) temp_buf; + src32 = (unsigned int *) in_data; + for (j = 0; j < height; j++) + { + for (i = 0; i < width; i++) + { + pixel = *src32; + src32++; + *dst32 = pixel; + dst32++; + } + for (i = 0; i < e; i++) + { + *dst32 = pixel; + dst32++; + } + } + src_buf = (unsigned char *) temp_buf; + } + dst_buf = (unsigned char*)(s->p); + error = tjCompress(tj_han, src_buf, width + e, (width + e) * 4, height, + TJPF_XBGR, dst_buf, &cdata_bytes, + TJSAMP_420, quality, 0); + s->p += cdata_bytes; + g_free(temp_buf); + return height; +} + +/*****************************************************************************/ +void *APP_CC +xrdp_jpeg_init(void) +{ + tjhandle tj_han; + + tj_han = tjInitCompress(); + return tj_han; +} + +/*****************************************************************************/ +int APP_CC +xrdp_jpeg_deinit(void *handle) +{ + tjhandle tj_han; + + if (handle == 0) + { + return 0; + } + tj_han = (tjhandle) handle; + tjDestroy(tj_han); + return 0; +} + +#elif defined(XRDP_JPEG) + +/* libjpeg */ #include <stdio.h> #include <stdlib.h> @@ -205,7 +310,7 @@ jpeg_compress(char *in_data, int width, int height, /*****************************************************************************/ int APP_CC -xrdp_jpeg_compress(char *in_data, int width, int height, +xrdp_jpeg_compress(void *handle, char *in_data, int width, int height, struct stream *s, int bpp, int byte_limit, int start_line, struct stream *temp_s, int e, int quality) @@ -215,11 +320,25 @@ xrdp_jpeg_compress(char *in_data, int width, int height, return height; } +/*****************************************************************************/ +void *APP_CC +xrdp_jpeg_init(void) +{ + return 0; +} + +/*****************************************************************************/ +int APP_CC +xrdp_jpeg_deinit(void *handle) +{ + return 0; +} + #else /*****************************************************************************/ int APP_CC -xrdp_jpeg_compress(char *in_data, int width, int height, +xrdp_jpeg_compress(void *handle, char *in_data, int width, int height, struct stream *s, int bpp, int byte_limit, int start_line, struct stream *temp_s, int e, int quality) @@ -227,4 +346,18 @@ xrdp_jpeg_compress(char *in_data, int width, int height, return height; } +/*****************************************************************************/ +void *APP_CC +xrdp_jpeg_init(void) +{ + return 0; +} + +/*****************************************************************************/ +int APP_CC +xrdp_jpeg_deinit(void *handle) +{ + return 0; +} + #endif |
