don't use a global for turbo jpeg

ulab-next
Jay Sorg 11 years ago
parent 1d09427c57
commit 2c021f5fab

@ -211,6 +211,7 @@ struct xrdp_orders
int order_count; int order_count;
int order_level; /* inc for every call to xrdp_orders_init */ int order_level; /* inc for every call to xrdp_orders_init */
struct xrdp_orders_state orders_state; struct xrdp_orders_state orders_state;
void* jpeg_han;
}; };
#define PROTO_RDP_40 1 #define PROTO_RDP_40 1
@ -431,10 +432,14 @@ xrdp_bitmap_compress(char* in_data, int width, int height,
int start_line, struct stream* temp_s, int start_line, struct stream* temp_s,
int e); int e);
int APP_CC 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, struct stream* s, int bpp, int byte_limit,
int start_line, struct stream* temp_s, int start_line, struct stream* temp_s,
int e, int quality); int e, int quality);
void *APP_CC
xrdp_jpeg_init(void);
int APP_CC
xrdp_jpeg_deinit(void *handle);
/* xrdp_channel.c */ /* xrdp_channel.c */
struct xrdp_channel* APP_CC struct xrdp_channel* APP_CC

@ -29,11 +29,9 @@
#include <string.h> #include <string.h>
#include <turbojpeg.h> #include <turbojpeg.h>
static tjhandle g_tj_han = 0; /* turbojpeg handle */
/*****************************************************************************/ /*****************************************************************************/
int APP_CC 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, struct stream *s, int bpp, int byte_limit,
int start_line, struct stream *temp_s, int start_line, struct stream *temp_s,
int e, int quality) int e, int quality)
@ -48,16 +46,19 @@ xrdp_jpeg_compress(char *in_data, int width, int height,
unsigned char *src_buf; unsigned char *src_buf;
unsigned char *dst_buf; unsigned char *dst_buf;
char *temp_buf; char *temp_buf;
tjhandle tj_han;
if (bpp != 24) if (bpp != 24)
{ {
g_writeln("bpp wrong %d", bpp); g_writeln("xrdp_jpeg_compress: bpp wrong %d", bpp);
return height; return height;
} }
if (g_tj_han == 0) if (handle == 0)
{ {
g_tj_han = tjInitCompress(); g_writeln("xrdp_jpeg_compress: handle is nil");
return height;
} }
tj_han = (tjhandle) handle;
cdata_bytes = byte_limit; cdata_bytes = byte_limit;
src_buf = (unsigned char *) in_data; src_buf = (unsigned char *) in_data;
dst_buf = (unsigned char *) (s->p); dst_buf = (unsigned char *) (s->p);
@ -89,15 +90,39 @@ xrdp_jpeg_compress(char *in_data, int width, int height,
src_buf = (unsigned char *) temp_buf; src_buf = (unsigned char *) temp_buf;
} }
dst_buf = (unsigned char*)(s->p); dst_buf = (unsigned char*)(s->p);
error = tjCompress(g_tj_han, src_buf, width + e, (width + e) * 4, height, error = tjCompress(tj_han, src_buf, width + e, (width + e) * 4, height,
TJPF_XBGR, dst_buf, &cdata_bytes, TJPF_XBGR, dst_buf, &cdata_bytes,
TJSAMP_420, quality, 0); TJSAMP_420, quality, 0);
//g_writeln("error %d %d %d %d", error, width, e, height);
s->p += cdata_bytes; s->p += cdata_bytes;
g_free(temp_buf); g_free(temp_buf);
return height; 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) #elif defined(XRDP_JPEG)
/* libjpeg */ /* libjpeg */
@ -285,7 +310,7 @@ jpeg_compress(char *in_data, int width, int height,
/*****************************************************************************/ /*****************************************************************************/
int APP_CC 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, struct stream *s, int bpp, int byte_limit,
int start_line, struct stream *temp_s, int start_line, struct stream *temp_s,
int e, int quality) int e, int quality)
@ -295,11 +320,25 @@ xrdp_jpeg_compress(char *in_data, int width, int height,
return height; return height;
} }
/*****************************************************************************/
void *APP_CC
xrdp_jpeg_init(void)
{
return 0;
}
/*****************************************************************************/
int APP_CC
xrdp_jpeg_deinit(void *handle)
{
return 0;
}
#else #else
/*****************************************************************************/ /*****************************************************************************/
int APP_CC 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, struct stream *s, int bpp, int byte_limit,
int start_line, struct stream *temp_s, int start_line, struct stream *temp_s,
int e, int quality) int e, int quality)
@ -307,4 +346,18 @@ xrdp_jpeg_compress(char *in_data, int width, int height,
return height; return height;
} }
/*****************************************************************************/
void *APP_CC
xrdp_jpeg_init(void)
{
return 0;
}
/*****************************************************************************/
int APP_CC
xrdp_jpeg_deinit(void *handle)
{
return 0;
}
#endif #endif

@ -47,6 +47,7 @@ xrdp_orders_create(struct xrdp_session *session, struct xrdp_rdp *rdp_layer)
init_stream(self->out_s, 16384); init_stream(self->out_s, 16384);
self->orders_state.clip_right = 1; /* silly rdp right clip */ self->orders_state.clip_right = 1; /* silly rdp right clip */
self->orders_state.clip_bottom = 1; /* silly rdp bottom clip */ self->orders_state.clip_bottom = 1; /* silly rdp bottom clip */
self->jpeg_han = xrdp_jpeg_init();
return self; return self;
} }
@ -59,6 +60,7 @@ xrdp_orders_delete(struct xrdp_orders *self)
return; return;
} }
xrdp_jpeg_deinit(self->jpeg_han);
free_stream(self->out_s); free_stream(self->out_s);
g_free(self->orders_state.text_data); g_free(self->orders_state.text_data);
g_free(self); g_free(self);
@ -2394,7 +2396,7 @@ xrdp_orders_send_bitmap3(struct xrdp_orders *self,
make_stream(temp_s); make_stream(temp_s);
init_stream(temp_s, 16384); init_stream(temp_s, 16384);
quality = ci->jpeg_prop[0]; quality = ci->jpeg_prop[0];
xrdp_jpeg_compress(data, width, height, xr_s, bpp, 16384, xrdp_jpeg_compress(self->jpeg_han, data, width, height, xr_s, bpp, 16384,
height - 1, temp_s, e, quality); height - 1, temp_s, e, quality);
s_mark_end(xr_s); s_mark_end(xr_s);
bufsize = (int)(xr_s->end - xr_s->data); bufsize = (int)(xr_s->end - xr_s->data);

Loading…
Cancel
Save