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 
26 #include <fvutils/compression/jpeg_compressor.h>
27 #include <fvutils/compression/jpeg_compressor_libjpeg.h>
28 #ifdef HAVE_MMAL
29 # include <fvutils/compression/jpeg_compressor_mmal.h>
30 #endif
31 
32 #include <core/exception.h>
33 
34 using namespace fawkes;
35 
36 namespace firevision {
37 #if 0 /* just to make Emacs auto-indent happy */
38 }
39 #endif
40 
41 /** @class JpegImageCompressor <fvutils/compression/jpeg_compressor.h>
42  * Jpeg image compressor.
43  * The compressor can choose from several actual implementations. The default
44  * is to use the system's version of libjpeg. On the Raspberry Pi the MMAL
45  * implementation (which uses VideoCore) is preferred.
46  * @author Tim Niemueller
47  */
48 
49 /** Constructor.
50  * @param quality JPEG quality in percent
51  * @param jcs Jpeg colorspace
52  */
53 JpegImageCompressor::JpegImageCompressor(unsigned int quality, JpegColorspace jcs)
54 {
55  impl_ = 0;
56 #ifdef HAVE_MMAL
57  if (jcs != JPEG_CS_RGB) {
58  throw Exception("JpegImageCompressor MMAL can only encode to RGB colorspace");
59  }
60  impl_ = new JpegImageCompressorMMAL(quality);
61 #else
62  #ifndef HAVE_LIBJPEG
63  throw Exception("No JPEG compressor implementation available.");
64  #else
65  impl_ = new JpegImageCompressorLibJpeg(quality, jcs);
66  #endif
67 #endif
68 }
69 
70 
71 /** Constructor.
72  * @param impl_type force usage of this implementation type
73  * @param quality JPEG quality in percent
74  * @param jcs Jpeg colorspace
75  */
76 JpegImageCompressor::JpegImageCompressor(JpegCompressorImplementation impl_type,
77  unsigned int quality, JpegColorspace jcs)
78 {
79  impl_ = 0;
80  if (impl_type == JPEG_CI_MMAL) {
81 #ifndef HAVE_MMAL
82  throw Exception("JpegImageCompressor MMAL not available at compile time");
83 #else
84  if (jcs != JPEG_CS_RGB) {
85  throw Exception("JpegImageCompressor MMAL can only encode to RGB colorspace");
86  }
87  impl_ = new JpegImageCompressorMMAL(quality);
88 #endif
89  } else if (impl_type == JPEG_CI_LIBJPEG) {
90 #ifndef HAVE_LIBJPEG
91  throw Exception("No JPEG compressor implementation available.");
92 #else
93  impl_ = new JpegImageCompressorLibJpeg(quality, jcs);
94 #endif
95  } else {
96  throw Exception("JpegImageCompressor: requested unknown implementation");
97  }
98 }
99 
100 /** Destructor. */
101 JpegImageCompressor::~JpegImageCompressor()
102 {
103  delete impl_;
104 }
105 
106 } // end namespace firevision
Fawkes library namespace.
JpegCompressorImplementation
JPEG color space.
Base class for exceptions in Fawkes.
Definition: exception.h:36