JPEGCompressor.h
/* JPEG class wrapper to ijg jpeg library
Copyright (C) 2000-2018 Ruven Pillay.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#ifndef _JPEGCOMPRESSOR_H
#define _JPEGCOMPRESSOR_H
#include "Compressor.h"
// Fix missing snprintf in Windows
#if _MSC_VER
#define snprintf _snprintf
#endif
extern "C"{
/* Undefine this to prevent compiler warning
*/
#undef HAVE_STDLIB_H
#include <jpeglib.h>
}
typedef struct {
struct jpeg_destination_mgr pub;
size_t size;
JOCTET *buffer;
unsigned char* source;
unsigned int strip_height;
} iip_destination_mgr;
typedef iip_destination_mgr * iip_dest_ptr;
class JPEGCompressor: public Compressor{
private:
unsigned int width, height, channels;
int Q;
unsigned char header[1024];
unsigned char *data;
unsigned int header_size;
struct jpeg_compress_struct cinfo;
struct jpeg_error_mgr jerr;
iip_destination_mgr dest_mgr;
iip_dest_ptr dest;
void writeICCProfile();
void writeXMPMetadata();
public:
JPEGCompressor( int quality ) { Q = quality; dest = NULL; };
inline void setQuality( int factor ) {
if( factor < 0 ) Q = 0;
else if( factor > 100 ) Q = 100;
else Q = factor;
};
inline int getQuality() { return Q; }
void InitCompression( const RawTile& rawtile, unsigned int strip_height );
unsigned int CompressStrip( unsigned char* s, unsigned char* o, unsigned int tile_height );
unsigned int Finish( unsigned char* output );
unsigned int Compress( RawTile& t );
inline unsigned int getHeaderSize() { return header_size; }
inline unsigned char* getHeader() { return header; }
inline const char* getMimeType(){ return "image/jpeg"; }
inline const char* getSuffix(){ return "jpg"; }
};
#endif
Compressor
Base class for IIP output images.
Definition Compressor.h:32
Compressor::writeICCProfile
virtual void writeICCProfile()
Write ICC profile.
Definition Compressor.h:46
Compressor::writeXMPMetadata
virtual void writeXMPMetadata()
Write XMP metadata.
Definition Compressor.h:49
JPEGCompressor::JPEGCompressor
JPEGCompressor(int quality)
Constructor.
Definition JPEGCompressor.h:99
JPEGCompressor::InitCompression
void InitCompression(const RawTile &rawtile, unsigned int strip_height)
Initialise strip based compression.
JPEGCompressor::Compress
unsigned int Compress(RawTile &t)
Compress an entire buffer of image data at once in one command.
JPEGCompressor::setQuality
void setQuality(int factor)
Set the compression quality.
Definition JPEGCompressor.h:104
JPEGCompressor::getHeaderSize
unsigned int getHeaderSize()
Return the JPEG header size.
Definition JPEGCompressor.h:143
JPEGCompressor::CompressStrip
unsigned int CompressStrip(unsigned char *s, unsigned char *o, unsigned int tile_height)
Compress a strip of image data.
JPEGCompressor::getSuffix
const char * getSuffix()
Return the image filename suffix.
Definition JPEGCompressor.h:152
JPEGCompressor::getMimeType
const char * getMimeType()
Return the JPEG mime type.
Definition JPEGCompressor.h:149
JPEGCompressor::Finish
unsigned int Finish(unsigned char *output)
Finish the strip based compression and free memory.
JPEGCompressor::getQuality
int getQuality()
Get the current quality level.
Definition JPEGCompressor.h:112
JPEGCompressor::getHeader
unsigned char * getHeader()
Return a pointer to the header itself.
Definition JPEGCompressor.h:146
RawTile
Class to represent a single image tile.
Definition RawTile.h:45
iip_destination_mgr
Expanded data destination object for buffered output used by IJG JPEG library.
Definition JPEGCompressor.h:47
iip_destination_mgr::buffer
JOCTET * buffer
Definition JPEGCompressor.h:51
iip_destination_mgr::source
unsigned char * source
Definition JPEGCompressor.h:52
iip_destination_mgr::size
size_t size
Definition JPEGCompressor.h:50
iip_destination_mgr::strip_height
unsigned int strip_height
Definition JPEGCompressor.h:53
iip_destination_mgr::pub
struct jpeg_destination_mgr pub
Definition JPEGCompressor.h:48