iipsrv  0.9.9
JPEGCompressor.h
1 /* JPEG class wrapper to ijg jpeg library
2 
3  Copyright (C) 2000-2003 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 2 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
17  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 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 
63  private:
64 
66  unsigned int width, height, channels;
67 
69  int Q;
70 
72  unsigned char header[1024];
73 
75  unsigned char *data;
76 
78  unsigned int header_size;
79 
81  struct jpeg_compress_struct cinfo;
82  struct jpeg_error_mgr jerr;
83  iip_destination_mgr dest_mgr;
84  iip_dest_ptr dest;
85 
86 
87  public:
88 
90 
91  JPEGCompressor( int quality ) { Q = quality; };
92 
93 
95 
96  void setQuality( int factor ) {
97  if( factor < 0 ) Q = 0;
98  else if( factor > 100 ) Q = 100;
99  else Q = factor;
100  };
101 
102 
104  int getQuality() { return Q; }
105 
106 
108 
114  void InitCompression( RawTile& rawtile, unsigned int strip_height ) throw (std::string);
115 
117 
120  unsigned int CompressStrip( unsigned char* s, unsigned int tile_height ) throw (std::string);
121 
123  unsigned int Finish() throw (std::string);
124 
125 
127 
128  int Compress( RawTile& t ) throw (std::string);
129 
130 
132  unsigned int getHeaderSize() { return header_size; }
133 
135  inline unsigned char* getHeader() { return header; }
136 
137 
138 };
139 
140 
141 #endif
int Compress(RawTile &t)
Compress an entire buffer of image data at once in one command.
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
void InitCompression(RawTile &rawtile, unsigned int strip_height)
Initialise strip based compression.
unsigned int CompressStrip(unsigned char *s, unsigned int tile_height)
Compress a strip of image data.
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:96
unsigned int Finish()
Finish the strip based compression and free memory.
JPEGCompressor(int quality)
Constructor.
Definition: JPEGCompressor.h:91
size_t size
Definition: JPEGCompressor.h:47
unsigned int getHeaderSize()
Return the JPEG header size.
Definition: JPEGCompressor.h:132
unsigned char * getHeader()
Return a pointer to the header itself.
Definition: JPEGCompressor.h:135
Class to represent a single image tile.
Definition: RawTile.h:43
int getQuality()
Get the current quality level.
Definition: JPEGCompressor.h:104
JOCTET * buffer
Definition: JPEGCompressor.h:48