summaryrefslogtreecommitdiff
path: root/client
diff options
context:
space:
mode:
authorYonit Halperin <yhalperi@redhat.com>2010-06-09 11:40:25 +0200
committerAlexander Larsson <alexl@redhat.com>2010-06-09 11:40:25 +0200
commit263646a1f7e705766f7d46017679812d4b1406b8 (patch)
treebd8056f34c7413e5fb2f66959db085cd6efecdb4 /client
parentea74fc64543ef486085a82aec0c67a3b265ba3ac (diff)
JPEG support: introducing jpeg encoding for spice bitmaps
Diffstat (limited to 'client')
-rw-r--r--client/Makefile.am2
-rw-r--r--client/canvas.cpp1
-rw-r--r--client/canvas.h4
-rw-r--r--client/jpeg_decoder.cpp147
-rw-r--r--client/jpeg_decoder.h91
-rw-r--r--client/red_gdi_canvas.cpp3
-rw-r--r--client/red_gl_canvas.cpp3
-rw-r--r--client/red_sw_canvas.cpp6
-rw-r--r--client/screen.cpp2
-rw-r--r--client/windows/redc.vcproj8
-rw-r--r--client/x11/Makefile.am2
11 files changed, 264 insertions, 5 deletions
diff --git a/client/Makefile.am b/client/Makefile.am
index e1c31fd..55bc0f8 100644
--- a/client/Makefile.am
+++ b/client/Makefile.am
@@ -43,6 +43,8 @@ RED_COMMON_SRCS = \
inputs_channel.cpp \
inputs_channel.h \
inputs_handler.h \
+ jpeg_decoder.cpp \
+ jpeg_decoder.h \
lz.cpp \
monitor.cpp \
monitor.h \
diff --git a/client/canvas.cpp b/client/canvas.cpp
index 419bfc9..0a4d8e5 100644
--- a/client/canvas.cpp
+++ b/client/canvas.cpp
@@ -88,6 +88,7 @@ void Canvas::localalize_image(SPICE_ADDRESS* in_bitmap)
case SPICE_IMAGE_TYPE_LZ_RGB:
case SPICE_IMAGE_TYPE_GLZ_RGB:
case SPICE_IMAGE_TYPE_QUIC:
+ case SPICE_IMAGE_TYPE_JPEG:
break;
case SPICE_IMAGE_TYPE_FROM_CACHE:
break;
diff --git a/client/canvas.h b/client/canvas.h
index 135783b..8d64ca3 100644
--- a/client/canvas.h
+++ b/client/canvas.h
@@ -29,6 +29,7 @@
#include "canvas_utils.h"
#include "glz_decoded_image.h"
#include "glz_decoder.h"
+#include "jpeg_decoder.h"
enum CanvasType {
CANVAS_TYPE_INVALID,
@@ -423,6 +424,7 @@ protected:
CSurfaces& csurfaces() { return _csurfaces; }
GlzDecoder& glz_decoder() {return _glz_decoder;}
+ JpegDecoder& jpeg_decoder() { return _jpeg_decoder;}
private:
void access_test(void* ptr, size_t size);
@@ -445,6 +447,8 @@ private:
GlzDecoderCanvasDebug _glz_debug;
GlzDecoder _glz_decoder;
+ JpegDecoder _jpeg_decoder;
+
CSurfaces& _csurfaces;
unsigned long _base;
diff --git a/client/jpeg_decoder.cpp b/client/jpeg_decoder.cpp
new file mode 100644
index 0000000..a7824a9
--- /dev/null
+++ b/client/jpeg_decoder.cpp
@@ -0,0 +1,147 @@
+/*
+ Copyright (C) 2009 Red Hat, Inc.
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with this library; if not, see <http://www.gnu.org/licenses/>.
+*/
+
+#include "common.h"
+#include "jpeg_decoder.h"
+#include "debug.h"
+#include "utils.h"
+
+static void op_begin_decode(SpiceJpegDecoder *decoder,
+ uint8_t* data,
+ int data_size,
+ int* out_width,
+ int* out_height)
+{
+ JpegDecoder* _decoder = static_cast<JpegDecoder*>(decoder);
+ _decoder->begin_decode(data, data_size, *out_width, *out_height);
+}
+
+static void op_decode(SpiceJpegDecoder *decoder,
+ uint8_t* dest,
+ int stride,
+ int format)
+{
+ JpegDecoder* _decoder = static_cast<JpegDecoder*>(decoder);
+ _decoder->decode(dest, stride, format);
+}
+
+extern "C" {
+
+ void jpeg_decoder_init_source(j_decompress_ptr cinfo)
+ {
+ }
+
+ static boolean jpeg_decoder_fill_input_buffer(j_decompress_ptr cinfo)
+ {
+ PANIC("no more data for jpeg");
+ return FALSE;
+ }
+
+ static void jpeg_decoder_skip_input_data(j_decompress_ptr cinfo, long num_bytes)
+ {
+ ASSERT(num_bytes < (long)cinfo->src->bytes_in_buffer);
+ cinfo->src->next_input_byte += num_bytes;
+ cinfo->src->bytes_in_buffer -= num_bytes;
+ }
+
+ static void jpeg_decoder_term_source (j_decompress_ptr cinfo)
+ {
+ return;
+ }
+}
+
+
+JpegDecoder::JpegDecoder()
+ : _data (NULL)
+ , _data_size (0)
+{
+ _cinfo.err = jpeg_std_error(&_jerr);
+ jpeg_create_decompress(&_cinfo);
+
+ _cinfo.src = &_jsrc;
+ _cinfo.src->init_source = jpeg_decoder_init_source;
+ _cinfo.src->fill_input_buffer = jpeg_decoder_fill_input_buffer;
+ _cinfo.src->skip_input_data = jpeg_decoder_skip_input_data;
+ _cinfo.src->resync_to_restart = jpeg_resync_to_restart;
+ _cinfo.src->term_source = jpeg_decoder_term_source;
+
+ static SpiceJpegDecoderOps decoder_ops = {
+ op_begin_decode,
+ op_decode,
+ };
+
+ ops = &decoder_ops;
+}
+
+JpegDecoder::~JpegDecoder()
+{
+ jpeg_destroy_decompress(&_cinfo);
+}
+
+void JpegDecoder::begin_decode(uint8_t* data, int data_size, int& out_width, int& out_height)
+{
+ ASSERT(data);
+ ASSERT(data_size);
+
+ if (_data) {
+ jpeg_abort_decompress(&_cinfo);
+ }
+
+ _data = data;
+ _data_size = data_size;
+
+ _cinfo.src->next_input_byte = _data;
+ _cinfo.src->bytes_in_buffer = _data_size;
+
+ jpeg_read_header(&_cinfo, TRUE);
+
+ _cinfo.out_color_space = JCS_RGB;
+ _width = _cinfo.image_width;
+ _height = _cinfo.image_height;
+
+ out_width = _width;
+ out_height = _height;
+}
+
+void JpegDecoder::decode(uint8_t *dest, int stride, int format)
+{
+ uint8_t* scan_line = new uint8_t[_width*3];
+ RGBConverter* rgb_converter;
+
+ switch (format) {
+ case SPICE_BITMAP_FMT_24BIT:
+ rgb_converter = &_rgb2bgr;
+ break;
+ case SPICE_BITMAP_FMT_32BIT:
+ rgb_converter = &_rgb2bgrx;
+ break;
+ default:
+ THROW("bad bitmap format, %d", format);
+ }
+
+ jpeg_start_decompress(&_cinfo);
+
+ for (int row = 0; row < _height; row++) {
+ jpeg_read_scanlines(&_cinfo, &scan_line, 1);
+ rgb_converter->convert(scan_line, dest, _width);
+ dest += stride;
+ }
+
+ delete [] scan_line;
+
+ jpeg_finish_decompress(&_cinfo);
+}
diff --git a/client/jpeg_decoder.h b/client/jpeg_decoder.h
new file mode 100644
index 0000000..5c38cfa
--- /dev/null
+++ b/client/jpeg_decoder.h
@@ -0,0 +1,91 @@
+/* -*- Mode: C; c-basic-offset: 4; indent-tabs-mode: nil -*- */
+/*
+ Copyright (C) 2010 Red Hat, Inc.
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with this library; if not, see <http://www.gnu.org/licenses/>.
+*/
+
+#ifndef _H_JPEG_DECODER
+#define _H_JPEG_DECODER
+
+#include "common.h"
+#include "canvas_base.h"
+
+#ifdef WIN32
+/* We need some hacks to avoid warnings from the jpeg headers */
+#define XMD_H
+#undef FAR
+#endif
+
+extern "C" {
+#include <jpeglib.h>
+}
+
+class RGBConverter {
+public:
+ virtual ~RGBConverter() {}
+ virtual void convert(uint8_t* src, uint8_t* dest, int width) = 0;
+};
+
+class RGBToBGRConverter : public RGBConverter {
+public:
+ void convert(uint8_t* src, uint8_t* dest, int width)
+ {
+ for (int x = 0; x < width; x++) {
+ *dest++ = src[2];
+ *dest++ = src[1];
+ *dest++ = src[0];
+ src += 3;
+ }
+ }
+};
+
+class RGBToBGRXConverter : public RGBConverter {
+public:
+ void convert(uint8_t* src, uint8_t* dest, int width)
+ {
+ for (int x = 0; x < width; x++) {
+ *dest++ = src[2];
+ *dest++ = src[1];
+ *dest++ = src[0];
+ *dest++ = 0;
+ src += 3;
+ }
+ }
+};
+
+class JpegDecoder : public SpiceJpegDecoder {
+public:
+ JpegDecoder();
+ ~JpegDecoder();
+
+ void begin_decode(uint8_t* data, int data_size, int& out_width, int& out_height);
+ /* format is SPICE_BITMAP_FMT_<X> for the dest; currently, only
+ x=32BIT and x=24BIT are supported */
+ void decode(uint8_t* dest, int stride, int format);
+
+private:
+ struct jpeg_decompress_struct _cinfo;
+ struct jpeg_error_mgr _jerr;
+ struct jpeg_source_mgr _jsrc;
+
+ uint8_t* _data;
+ int _data_size;
+ int _width;
+ int _height;
+
+ RGBToBGRConverter _rgb2bgr;
+ RGBToBGRXConverter _rgb2bgrx;
+};
+#endif \ No newline at end of file
diff --git a/client/red_gdi_canvas.cpp b/client/red_gdi_canvas.cpp
index 391883b..453023e 100644
--- a/client/red_gdi_canvas.cpp
+++ b/client/red_gdi_canvas.cpp
@@ -37,7 +37,8 @@ GDICanvas::GDICanvas(int width, int height, uint32_t format,
format, &pixmap_cache.base,
&palette_cache.base,
&csurfaces.base,
- &glz_decoder()))) {
+ &glz_decoder(),
+ &jpeg_decoder()))) {
THROW("create canvas failed");
}
}
diff --git a/client/red_gl_canvas.cpp b/client/red_gl_canvas.cpp
index 13e4723..1a219cd 100644
--- a/client/red_gl_canvas.cpp
+++ b/client/red_gl_canvas.cpp
@@ -40,7 +40,8 @@ GCanvas::GCanvas(int width, int height, uint32_t format, RedWindow *win,
&pixmap_cache.base,
&palette_cache.base,
&csurfaces.base,
- &glz_decoder()))) {
+ &glz_decoder(),
+ &jpeg_decoder()))) {
THROW("create canvas failed");
}
}
diff --git a/client/red_sw_canvas.cpp b/client/red_sw_canvas.cpp
index 05da430..7a8daf4 100644
--- a/client/red_sw_canvas.cpp
+++ b/client/red_sw_canvas.cpp
@@ -42,13 +42,15 @@ SCanvas::SCanvas(bool onscreen,
&pixmap_cache.base,
&palette_cache.base,
&csurfaces.base,
- &glz_decoder());
+ &glz_decoder(),
+ &jpeg_decoder());
} else {
_canvas = canvas_create(width, height, format,
&pixmap_cache.base,
&palette_cache.base,
&csurfaces.base,
- &glz_decoder());
+ &glz_decoder(),
+ &jpeg_decoder());
}
if (_canvas == NULL) {
THROW("create canvas failed");
diff --git a/client/screen.cpp b/client/screen.cpp
index 1567978..bc87646 100644
--- a/client/screen.cpp
+++ b/client/screen.cpp
@@ -692,7 +692,7 @@ void RedScreen::on_mouse_button_release(SpiceMouseButton button, unsigned int bu
void RedScreen::on_pointer_leave()
{
- ASSERT(!_mouse_captured);
+// ASSERT(!_mouse_captured);
if (_pointer_layer) {
_pointer_layer->on_pointer_leave();
diff --git a/client/windows/redc.vcproj b/client/windows/redc.vcproj
index d2540ce..c0ba905 100644
--- a/client/windows/redc.vcproj
+++ b/client/windows/redc.vcproj
@@ -252,6 +252,10 @@
>
</File>
<File
+ RelativePath="..\jpeg_decoder.cpp"
+ >
+ </File>
+ <File
RelativePath="..\lines.cpp"
>
</File>
@@ -524,6 +528,10 @@
>
</File>
<File
+ RelativePath="..\jpeg_decoder.h"
+ >
+ </File>
+ <File
RelativePath="..\menu.h"
>
</File>
diff --git a/client/x11/Makefile.am b/client/x11/Makefile.am
index 904fb42..26140f4 100644
--- a/client/x11/Makefile.am
+++ b/client/x11/Makefile.am
@@ -69,6 +69,8 @@ RED_COMMON_SRCS = \
$(CLIENT_DIR)/inputs_channel.cpp \
$(CLIENT_DIR)/inputs_channel.h \
$(CLIENT_DIR)/inputs_handler.h \
+ $(CLIENT_DIR)/jpeg_decoder.cpp \
+ $(CLIENT_DIR)/jpeg_decoder.h \
$(CLIENT_DIR)/lz.cpp \
$(CLIENT_DIR)/lines.cpp \
$(CLIENT_DIR)/monitor.cpp \