iipsrv  1.0
JPEGCompressor.h
1 /* JPEG class wrapper to ijg jpeg library
2 
3  Copyright (C) 2000-2012 Ruven Pillay.
4 
5  This program is free software; you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation; either version 3 of the License, or
8  (at your option) any later version.
9 
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License
16  along with this program; if not, write to the Free Software Foundation,
17  Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
18 */
19 
20 
21 
22 #ifndef _JPEGCOMPRESSOR_H
23 #define _JPEGCOMPRESSOR_H
24 
25 
26 
27 #include <cstdio>
28 #include <string>
29 #include "RawTile.h"
30 
31 
32 extern "C"{
33 /* Undefine this to prevent compiler warning
34  */
35 #undef HAVE_STDLIB_H
36 #include <jpeglib.h>
37 }
38 
39 
40 
42 
43 
44 typedef struct {
45  struct jpeg_destination_mgr pub;
47  size_t size;
48  JOCTET *buffer;
49  unsigned char* source;
50  unsigned int strip_height;
53 
55 
56 
57 
59 
61 
62  private:
63 
65  unsigned int width, height, channels;
66 
68  int Q;
69 
71  unsigned char header[1024];
72 
74  unsigned char *data;
75 
77  unsigned int header_size;
78 
80  struct jpeg_compress_struct cinfo;
81  struct jpeg_error_mgr jerr;
82  iip_destination_mgr dest_mgr;
83  iip_dest_ptr dest;
84 
85 
86  public:
87 
89 
90  JPEGCompressor( int quality ) { Q = quality; dest = NULL; };
91 
92 
94 
95  void setQuality( int factor ) {
96  if( factor < 0 ) Q = 0;
97  else if( factor > 100 ) Q = 100;
98  else Q = factor;
99  };
100 
101 
103  int getQuality() { return Q; }
104 
105 
107 
114  void InitCompression( const RawTile& rawtile, unsigned int strip_height ) throw (std::string);
115 
117 
121  unsigned int CompressStrip( unsigned char* s, unsigned char* o, unsigned int tile_height ) throw (std::string);
122 
124 
127  unsigned int Finish( unsigned char* output ) throw (std::string);
128 
129 
131 
132  int Compress( RawTile& t ) throw (std::string);
133 
134 
136 
137  void addMetadata( const std::string& m );
138 
139 
141  unsigned int getHeaderSize() { return header_size; }
142 
144  inline unsigned char* getHeader() { return header; }
145 
146 
147 };
148 
149 
150 #endif
int Compress(RawTile &t)
Compress an entire buffer of image data at once in one command.
unsigned int CompressStrip(unsigned char *s, unsigned char *o, unsigned int tile_height)
Compress a strip of image data.
Wrapper class to the IJG JPEG library.
Definition: JPEGCompressor.h:60
Expanded data destination object for buffered output used by IJG JPEG library.
Definition: JPEGCompressor.h:44
unsigned int Finish(unsigned char *output)
Finish the strip based compression and free memory.
unsigned int strip_height
Definition: JPEGCompressor.h:50
unsigned char * source
Definition: JPEGCompressor.h:49
void setQuality(int factor)
Set the compression quality.
Definition: JPEGCompressor.h:95
JPEGCompressor(int quality)
Constructor.
Definition: JPEGCompressor.h:90
size_t size
Definition: JPEGCompressor.h:47
void addMetadata(const std::string &m)
Add metadata to the JPEG header.
unsigned int getHeaderSize()
Return the JPEG header size.
Definition: JPEGCompressor.h:141
void InitCompression(const RawTile &rawtile, unsigned int strip_height)
Initialise strip based compression.
unsigned char * getHeader()
Return a pointer to the header itself.
Definition: JPEGCompressor.h:144
Class to represent a single image tile.
Definition: RawTile.h:45
int getQuality()
Get the current quality level.
Definition: JPEGCompressor.h:103
JOCTET * buffer
Definition: JPEGCompressor.h:48