iipsrv 1.3
iipsrv is an advanced high-performance feature-rich image server for web-based streamed viewing and zooming of ultra high-resolution images
Compressor.h
1/* Generic compressor class - extended by JPEG and PNG Compressor classes
2
3 Copyright (C) 2017-2025 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#ifndef _COMPRESSOR_H
22#define _COMPRESSOR_H
23
24
25
26#include "RawTile.h"
27#include <map>
28
29
32
33 protected:
34
36 int Q;
37
40
42 unsigned char *header;
43
45 unsigned int header_size;
46
49
51 float dpi_x;
52
54 float dpi_y;
55
57 std::map <const std::string, const std::string> metadata;
58
60 std::string icc;
61
64
66 std::string xmp;
67
70
72 std::string exif;
73
76
78 virtual void writeMetadata() {};
79
81 virtual void writeResolution() {};
82
84 virtual void writeICCProfile() {};
85
87 virtual void writeXMPMetadata() {};
88
90 virtual void writeExifMetadata() {};
91
92
93 public:
94
96
97 Compressor( int compressionLevel ) :
98 Q( compressionLevel ),
99 default_quality( true ),
100 header( NULL ),
101 header_size( 0 ),
102 dpi_units( 0 ),
103 dpi_x( 0 ),
104 dpi_y( 0 ),
105 embedICC( false ),
106 embedXMP( false ),
107 embedEXIF( false ) {};
108
109
110 virtual ~Compressor() {};
111
112
114
115 unsigned int getHeaderSize() const { return header_size; };
116
117
119
120 unsigned char* getHeader() { return header; };
121
122
124 inline int getQuality() const { return Q; }
125
126
128 inline bool defaultQuality() const { return default_quality; }
129
130
132 inline void setResolution( float x, float y, int units ){ dpi_x = x; dpi_y = y; dpi_units = units; };
133
134
136
137 inline void embedICCProfile( const bool embed ){ this->embedICC = embed; }
138
139
141
142 inline void embedXMPMetadata( const bool embed ){ this->embedXMP = embed; }
143
145
146 inline void embedExifMetadata( const bool embed ){ this->embedEXIF = embed; }
147
149
150 inline void setMetadata( const std::map <const std::string, const std::string>& metadata )
151 {
152 this->metadata = std::map <const std::string, const std::string>( metadata );
153
154 // Extract ICC profile if it exists and remove from list
155 std::map<const std::string, const std::string> :: const_iterator it;
156 it = this->metadata.find("icc");
157 if( it != this->metadata.end() ){
158 icc = it->second;
159 this->metadata.erase( it );
160 }
161
162 // Extract XMP chunk if it exists and remove from list
163 it = this->metadata.find("xmp");
164 if( it != this->metadata.end() ){
165 xmp = it->second;
166 this->metadata.erase( it );
167 }
168
169 // Extract EXIF chunk if it exists and remove from list
170 it = this->metadata.find("exif");
171 if( it != this->metadata.end() ){
172 exif = it->second;
173 this->metadata.erase( it );
174 }
175
176 };
177
178
180
181 virtual void setQuality( int quality ) {};
182
183
185
191 virtual void InitCompression( const RawTile& rawtile, unsigned int strip_height ) {};
192
193
195
200 virtual unsigned int CompressStrip( unsigned char* s, unsigned char* o, unsigned int tile_height ) { return 0; };
201
202
204
207 virtual unsigned int Finish( unsigned char* output ) { return 0; };
208
209
211
214 virtual unsigned int Compress( RawTile& t ) { return 0; };
215
216
218
219 virtual const char* getMimeType() const { return "image/example"; };
220
221
223
224 virtual const char* getSuffix() const { return "img"; };
225
226
228
229 virtual ImageEncoding getImageEncoding() const { return ImageEncoding::RAW; };
230
231
233
234 virtual void injectMetadata( RawTile& t ) {};
235
236};
237
238#endif
Base class for IIP output images.
Definition Compressor.h:31
virtual void writeResolution()
Write DPI.
Definition Compressor.h:81
virtual const char * getSuffix() const
Get file suffix.
Definition Compressor.h:224
int dpi_units
Physical resolution units: 0 for unknown, 1 for dots/inch or 2 for dots/cm.
Definition Compressor.h:48
virtual unsigned int CompressStrip(unsigned char *s, unsigned char *o, unsigned int tile_height)
Compress a strip of image data.
Definition Compressor.h:200
Compressor(int compressionLevel)
Constructor.
Definition Compressor.h:97
bool defaultQuality() const
Check whether we are using the default or whether user has requested a specific quality level.
Definition Compressor.h:128
std::string exif
EXIF metadata.
Definition Compressor.h:72
std::string xmp
XMP metadata.
Definition Compressor.h:66
bool embedICC
Whether ICC profile should be embedded.
Definition Compressor.h:63
bool default_quality
Whether compression level is default or has been set manually.
Definition Compressor.h:39
virtual void injectMetadata(RawTile &t)
Inject metadata into raw bitstream.
Definition Compressor.h:234
int getQuality() const
Get the current quality level.
Definition Compressor.h:124
virtual void writeICCProfile()
Write ICC profile.
Definition Compressor.h:84
virtual void writeMetadata()
Write metadata.
Definition Compressor.h:78
virtual void writeXMPMetadata()
Write XMP metadata.
Definition Compressor.h:87
unsigned int header_size
Size of the header data.
Definition Compressor.h:45
unsigned int getHeaderSize() const
Return the image header size.
Definition Compressor.h:115
std::string icc
ICC Profile.
Definition Compressor.h:60
int Q
Quality or compression level for all image types.
Definition Compressor.h:36
virtual unsigned int Finish(unsigned char *output)
Finish the strip based compression and free memory.
Definition Compressor.h:207
virtual void writeExifMetadata()
Write EXIF metadata.
Definition Compressor.h:90
void setMetadata(const std::map< const std::string, const std::string > &metadata)
Set general metadata.
Definition Compressor.h:150
unsigned char * header
Pointer to the header data for the output image.
Definition Compressor.h:42
bool embedEXIF
Whether EXIF metadata should be embedded.
Definition Compressor.h:75
std::map< const std::string, const std::string > metadata
Metadata.
Definition Compressor.h:57
float dpi_y
Physical resolution (pixels per phyisical unit) in Y direction.
Definition Compressor.h:54
virtual void setQuality(int quality)
Set quality level.
Definition Compressor.h:181
bool embedXMP
Whether XMP metadata should be embedded.
Definition Compressor.h:69
virtual void InitCompression(const RawTile &rawtile, unsigned int strip_height)
Initialise strip based compression.
Definition Compressor.h:191
float dpi_x
Physical resolution (pixels per physical unit) for X direction.
Definition Compressor.h:51
void embedXMPMetadata(const bool embed)
Embed XMP metadata.
Definition Compressor.h:142
void setResolution(float x, float y, int units)
Set the physical output resolution.
Definition Compressor.h:132
void embedICCProfile(const bool embed)
Embed ICC profile.
Definition Compressor.h:137
virtual ImageEncoding getImageEncoding() const
Get compression type.
Definition Compressor.h:229
virtual unsigned int Compress(RawTile &t)
Compress an entire buffer of image data at once in one command.
Definition Compressor.h:214
unsigned char * getHeader()
Return a pointer to the image header itself.
Definition Compressor.h:120
virtual const char * getMimeType() const
Get mime type.
Definition Compressor.h:219
void embedExifMetadata(const bool embed)
Embed EXIF metadata.
Definition Compressor.h:146
Class to represent a single image tile.
Definition RawTile.h:45