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