iipsrv 1.1
iipsrv is an advanced high-performance feature-rich image server for web-based streamed viewing and zooming of ultra high-resolution images
JPEGCompressor.h
1/* JPEG class wrapper to ijg jpeg library
2
3 Copyright (C) 2000-2018 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#include "Compressor.h"
27
28
29// Fix missing snprintf in Windows
30#if _MSC_VER
31#define snprintf _snprintf
32#endif
33
34
35extern "C"{
36/* Undefine this to prevent compiler warning
37 */
38#undef HAVE_STDLIB_H
39#include <jpeglib.h>
40}
41
42
43
45
46
47typedef struct {
48 struct jpeg_destination_mgr pub;
50 size_t size;
51 JOCTET *buffer;
52 unsigned char* source;
53 unsigned int strip_height;
56
58
59
60
62
64
65 private:
66
68 unsigned int width, height, channels;
69
71 int Q;
72
74 unsigned char header[1024];
75
77 unsigned char *data;
78
80 unsigned int header_size;
81
83 struct jpeg_compress_struct cinfo;
84 struct jpeg_error_mgr jerr;
85 iip_destination_mgr dest_mgr;
86 iip_dest_ptr dest;
87
89 void writeICCProfile();
90
92 void writeXMPMetadata();
93
94
95 public:
96
98
99 JPEGCompressor( int quality ) { Q = quality; dest = NULL; };
100
101
103
104 inline void setQuality( int factor ) {
105 if( factor < 0 ) Q = 0;
106 else if( factor > 100 ) Q = 100;
107 else Q = factor;
108 };
109
110
112 inline int getQuality() { return Q; }
113
114
116
123 void InitCompression( const RawTile& rawtile, unsigned int strip_height );
124
126
130 unsigned int CompressStrip( unsigned char* s, unsigned char* o, unsigned int tile_height );
131
133
136 unsigned int Finish( unsigned char* output );
137
139
140 unsigned int Compress( RawTile& t );
141
143 inline unsigned int getHeaderSize() { return header_size; }
144
146 inline unsigned char* getHeader() { return header; }
147
149 inline const char* getMimeType(){ return "image/jpeg"; }
150
152 inline const char* getSuffix(){ return "jpg"; }
153
154};
155
156
157#endif
Base class for IIP output images.
Definition: Compressor.h:32
Wrapper class to the IJG JPEG library.
Definition: JPEGCompressor.h:63
JPEGCompressor(int quality)
Constructor.
Definition: JPEGCompressor.h:99
void InitCompression(const RawTile &rawtile, unsigned int strip_height)
Initialise strip based compression.
unsigned int Compress(RawTile &t)
Compress an entire buffer of image data at once in one command.
void setQuality(int factor)
Set the compression quality.
Definition: JPEGCompressor.h:104
unsigned int getHeaderSize()
Return the JPEG header size.
Definition: JPEGCompressor.h:143
unsigned int CompressStrip(unsigned char *s, unsigned char *o, unsigned int tile_height)
Compress a strip of image data.
const char * getSuffix()
Return the image filename suffix.
Definition: JPEGCompressor.h:152
const char * getMimeType()
Return the JPEG mime type.
Definition: JPEGCompressor.h:149
unsigned int Finish(unsigned char *output)
Finish the strip based compression and free memory.
int getQuality()
Get the current quality level.
Definition: JPEGCompressor.h:112
unsigned char * getHeader()
Return a pointer to the header itself.
Definition: JPEGCompressor.h:146
Class to represent a single image tile.
Definition: RawTile.h:45
Expanded data destination object for buffered output used by IJG JPEG library.
Definition: JPEGCompressor.h:47
JOCTET * buffer
Definition: JPEGCompressor.h:51
unsigned char * source
Definition: JPEGCompressor.h:52
size_t size
Definition: JPEGCompressor.h:50
unsigned int strip_height
Definition: JPEGCompressor.h:53