iipsrv 1.2
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 libjpeg library
2
3 Copyright (C) 2000-2023 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
45typedef struct {
46
47 struct jpeg_destination_mgr pub;
48
49 unsigned char* source;
50 size_t source_size;
51 size_t written;
52 unsigned int strip_height;
53
56
57
58
61
62 private:
63
65 unsigned int width, height, channels;
66
68 unsigned char *data;
69
71 struct jpeg_compress_struct cinfo;
72 struct jpeg_error_mgr jerr;
73 iip_destination_mgr dest_mgr;
74 iip_dest_ptr dest;
75
77 void writeICCProfile();
78
80 void writeXMPMetadata();
81
82
83 public:
84
86
87 JPEGCompressor( int quality ) : Compressor(quality), dest(NULL) {};
88
89
91
92 inline void setQuality( int factor ) {
93 if( factor < 0 ) Q = 0;
94 else if( factor > 100 ) Q = 100;
95 else Q = factor;
96 };
97
98
100 inline int getQuality() const { return Q; }
101
102
104
111 void InitCompression( const RawTile& rawtile, unsigned int strip_height );
112
114
118 unsigned int CompressStrip( unsigned char* s, unsigned char* o, unsigned int tile_height );
119
121
124 unsigned int Finish( unsigned char* output );
125
127
128 unsigned int Compress( RawTile& t );
129
131 inline unsigned int getHeaderSize() const { return header_size; }
132
134 inline unsigned char* getHeader() { return header; }
135
137 inline const char* getMimeType() const { return "image/jpeg"; }
138
140 inline const char* getSuffix() const { return "jpg"; }
141
143 inline CompressionType getCompressionType() const { return JPEG; };
144
145};
146
147
148#endif
Base class for IIP output images.
Definition: Compressor.h:32
unsigned int header_size
Size of the header data.
Definition: Compressor.h:43
int Q
Quality or compression level for all image types.
Definition: Compressor.h:37
unsigned char * header
Pointer to the header data for the output image.
Definition: Compressor.h:40
Wrapper class to the IJG JPEG library.
Definition: JPEGCompressor.h:60
JPEGCompressor(int quality)
Constructor.
Definition: JPEGCompressor.h:87
unsigned int getHeaderSize() const
Return the JPEG header size.
Definition: JPEGCompressor.h:131
void InitCompression(const RawTile &rawtile, unsigned int strip_height)
Initialise strip based compression.
CompressionType getCompressionType() const
Get compression type.
Definition: JPEGCompressor.h:143
const char * getMimeType() const
Return the JPEG mime type.
Definition: JPEGCompressor.h:137
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:92
unsigned int CompressStrip(unsigned char *s, unsigned char *o, unsigned int tile_height)
Compress a strip of image data.
int getQuality() const
Get the current quality level.
Definition: JPEGCompressor.h:100
unsigned int Finish(unsigned char *output)
Finish the strip based compression and free memory.
unsigned char * getHeader()
Return a pointer to the header itself.
Definition: JPEGCompressor.h:134
const char * getSuffix() const
Return the image filename suffix.
Definition: JPEGCompressor.h:140
Class to represent a single image tile.
Definition: RawTile.h:47
Expanded data destination object for buffered output used by IJG JPEG library.
Definition: JPEGCompressor.h:45
size_t source_size
size of output buffer
Definition: JPEGCompressor.h:50
unsigned char * source
output data buffer pointer
Definition: JPEGCompressor.h:49
size_t written
number of bytes written to buffer
Definition: JPEGCompressor.h:51
unsigned int strip_height
used for stream-based encoding
Definition: JPEGCompressor.h:52