Fawkes API Fawkes Development Version
jpeg_compressor.cpp
1
2/***************************************************************************
3 * jpeg_compressor.cpp - JPEG image compressor
4 *
5 * Created: Sat Aug 12 13:42:39 2006 (in LFI of Central Medical Library
6 * of Germany, Cologne)
7 * Copyright 2005-2011 Tim Niemueller [www.niemueller.de]
8 *
9 ****************************************************************************/
10
11/* This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version. A runtime exception applies to
15 * this software (see LICENSE.GPL_WRE file mentioned below for details).
16 *
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU Library General Public License for more details.
21 *
22 * Read the full text in the LICENSE.GPL_WRE file in the doc directory.
23 */
24
25#include <fvutils/compression/jpeg_compressor.h>
26#include <fvutils/compression/jpeg_compressor_libjpeg.h>
27#ifdef HAVE_MMAL
28# include <fvutils/compression/jpeg_compressor_mmal.h>
29#endif
30
31#include <core/exception.h>
32
33using namespace fawkes;
34
35namespace firevision {
36
37/** @class JpegImageCompressor <fvutils/compression/jpeg_compressor.h>
38 * Jpeg image compressor.
39 * The compressor can choose from several actual implementations. The default
40 * is to use the system's version of libjpeg. On the Raspberry Pi the MMAL
41 * implementation (which uses VideoCore) is preferred.
42 * @author Tim Niemueller
43 */
44
45/** Constructor.
46 * @param quality JPEG quality in percent
47 * @param jcs Jpeg colorspace
48 */
50{
51 impl_ = 0;
52#ifdef HAVE_MMAL
53 if (jcs != JPEG_CS_RGB) {
54 throw Exception("JpegImageCompressor MMAL can only encode to RGB colorspace");
55 }
56 impl_ = new JpegImageCompressorMMAL(quality);
57#else
58# ifndef HAVE_LIBJPEG
59 throw Exception("No JPEG compressor implementation available.");
60# else
61 impl_ = new JpegImageCompressorLibJpeg(quality, jcs);
62# endif
63#endif
64}
65
66/** Constructor.
67 * @param impl_type force usage of this implementation type
68 * @param quality JPEG quality in percent
69 * @param jcs Jpeg colorspace
70 */
72 unsigned int quality,
74{
75 impl_ = 0;
76 if (impl_type == JPEG_CI_MMAL) {
77#ifndef HAVE_MMAL
78 throw Exception("JpegImageCompressor MMAL not available at compile time");
79#else
80 if (jcs != JPEG_CS_RGB) {
81 throw Exception("JpegImageCompressor MMAL can only encode to RGB colorspace");
82 }
83 impl_ = new JpegImageCompressorMMAL(quality);
84#endif
85 } else if (impl_type == JPEG_CI_LIBJPEG) {
86#ifndef HAVE_LIBJPEG
87 throw Exception("No JPEG compressor implementation available.");
88#else
89 impl_ = new JpegImageCompressorLibJpeg(quality, jcs);
90#endif
91 } else {
92 throw Exception("JpegImageCompressor: requested unknown implementation");
93 }
94}
95
96/** Destructor. */
98{
99 delete impl_;
100}
101
102} // end namespace firevision
Base class for exceptions in Fawkes.
Definition: exception.h:36
JpegCompressorImplementation
JPEG color space.
@ JPEG_CI_LIBJPEG
Force usage of libjpeg for compression.
@ JPEG_CI_MMAL
Force usage of MMAL for compression.
JpegImageCompressor(unsigned int quality=80, JpegColorspace jcs=JPEG_CS_RGB)
Constructor.
virtual ~JpegImageCompressor()
Destructor.
Fawkes library namespace.