summaryrefslogtreecommitdiffstats
path: root/client/mjpeg_decoder.h
diff options
context:
space:
mode:
authorAlexander Larsson <alexl@redhat.com>2010-04-07 10:42:57 +0200
committerAlexander Larsson <alexl@redhat.com>2010-04-08 11:30:18 +0200
commit5059c304be3aeae6bf8c8b201f844afa77cf1323 (patch)
treead1ca8cb21f5f2f06aae6145347e8e1da86770cd /client/mjpeg_decoder.h
parented568302ad62db7eb8cc52961484c227a401f14e (diff)
downloadspice-5059c304be3aeae6bf8c8b201f844afa77cf1323.tar.gz
spice-5059c304be3aeae6bf8c8b201f844afa77cf1323.tar.xz
spice-5059c304be3aeae6bf8c8b201f844afa77cf1323.zip
Use libjpeg to decode mjpegs, not ffmpeg
This is pretty straightforward, although there are two weird issues. The current encoder has two bugs in the yuv conversion. First of all it switches red and blue, due to something of an endianness issue. We keep this behavior by switching red and blue. Maybe we want to change this in the new protocol version since switching this may cause jpeg compression to be worse. Secondly, the old coder/decoder did rgb to/from yuv420 wrongly for jpeg, not using the "full scale" version of Y that is used in jpeg, but the other one where y goes from 16 to 235. (See jpeg/jfif reference on http://en.wikipedia.org/wiki/YCbCr for details.) The new decoder uses the full range in order to get better quality, which means old encoders will show slightly darker images. This completely removes all ffmpeg usage in the client
Diffstat (limited to 'client/mjpeg_decoder.h')
-rw-r--r--client/mjpeg_decoder.h72
1 files changed, 72 insertions, 0 deletions
diff --git a/client/mjpeg_decoder.h b/client/mjpeg_decoder.h
new file mode 100644
index 00000000..f5176758
--- /dev/null
+++ b/client/mjpeg_decoder.h
@@ -0,0 +1,72 @@
+/* -*- Mode: C; c-basic-offset: 4; indent-tabs-mode: nil -*- */
+/*
+ Copyright (C) 2010 Red Hat, Inc.
+
+ This program is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License as
+ published by the Free Software Foundation; either version 2 of
+ the License, or (at your option) any later version.
+
+ This program 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 General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#ifndef _H_MJPEG_DECODER
+#define _H_MJPEG_DECODER
+
+#include "common.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>
+}
+
+extern "C" {
+ void mjpeg_skip_input_data(j_decompress_ptr cinfo, long num_bytes);
+}
+
+class MJpegDecoder {
+public:
+ MJpegDecoder(int width, int height, int stride,
+ uint8_t *frame);
+ ~MJpegDecoder();
+
+ bool decode_data(uint8_t *data, size_t length);
+
+private:
+
+ friend void mjpeg_skip_input_data(j_decompress_ptr cinfo, long num_bytes);
+
+ void convert_scanline(void);
+
+ struct jpeg_decompress_struct _cinfo;
+ struct jpeg_error_mgr _jerr;
+ struct jpeg_source_mgr _jsrc;
+
+ uint8_t *_data;
+ size_t _data_size;
+ size_t _data_start;
+ size_t _data_end;
+ size_t _extra_skip;
+
+ int _width;
+ int _height;
+ int _stride;
+ uint8_t *_frame;
+
+ int _y;
+ uint8_t *_scanline;
+
+ int _state;
+};
+
+#endif