KakaduImage.h
// Kakadu JPEG2000 Image class Interface
/* IIP Kakadu JPEG2000 Class
Development supported by Moravian Library in Brno (Moravska zemska
knihovna v Brne, http://www.mzk.cz/) R&D grant MK00009494301 & Old
Maps Online (http://www.oldmapsonline.org/) from the Ministry of
Culture of the Czech Republic.
Copyright (C) 2009-2017 IIPImage.
Author: 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 _KAKADUIMAGE_H
#define _KAKADUIMAGE_H
#include "IIPImage.h"
#include "Logger.h"
#include <jpx.h>
#include <jp2.h>
#include <kdu_stripe_decompressor.h>
#include <fstream>
#define TILESIZE 256
// Kakadu 7.5 uses namespaces
#if KDU_MAJOR_VERSION > 7 || (KDU_MAJOR_VERSION == 7 && KDU_MINOR_VERSION >= 5)
using namespace kdu_supp; // Also includes the `kdu_core' namespace
#endif
extern Logger logfile;
class kdu_stream_message : public kdu_message {
private: // Data
std::ostream *stream;
std::string message;
public: // Member classes
kdu_stream_message(std::ostream *stream)
{ this->stream = stream; }
void put_text(const char *string)
{ logfile << string; }
void flush(bool end_of_message=false){
logfile << message;
if( end_of_message ) throw 1;
}
};
//static kdu_stream_message cout_message(&std::cout);
//static kdu_stream_message cerr_message(&std::cerr);
static kdu_stream_message cout_message(&logfile);
static kdu_stream_message cerr_message(&logfile);
static kdu_message_formatter pretty_cout(&cout_message);
static kdu_message_formatter pretty_cerr(&cerr_message);
class KakaduImage : public IIPImage {
private:
kdu_codestream codestream;
kdu_compressed_source *input;
jpx_source jpx_input;
jp2_family_src src;
jpx_codestream_source jpx_stream;
kdu_stripe_decompressor decompressor;
kdu_dims comp_dims;
void process( unsigned int r, int l, int x, int y, unsigned int w, unsigned int h, void* d );
void delete_buffer( void* b );
public:
KakaduImage(): IIPImage(){
tile_width = TILESIZE; tile_height = TILESIZE; input = NULL;
};
KakaduImage( const std::string& path ): IIPImage( path ){
tile_width = TILESIZE; tile_height = TILESIZE; input = NULL;
};
KakaduImage( const KakaduImage& image ): IIPImage( image ) {};
KakaduImage( const IIPImage& image ): IIPImage( image ){
tile_width = TILESIZE; tile_height = TILESIZE; input = NULL;
};
KakaduImage& operator = ( KakaduImage image ) {
if( this != &image ){
closeImage();
IIPImage::operator=(image);
}
return *this;
}
~KakaduImage() { closeImage(); };
void openImage();
void loadImageInfo( int x, int y );
void closeImage();
bool regionDecoding(){ return true; };
RawTile getTile( int x, int y, unsigned int r, int l, unsigned int t );
RawTile getRegion( int ha, int va, unsigned int r, int l, int x, int y, unsigned int w, unsigned int h );
enum KDU_READMODE { KDU_FAST,
KDU_FUSSY,
KDU_RESILIENT
};
KDU_READMODE kdu_readmode;
};
#endif
IIPImage::IIPImage
IIPImage()
Default Constructor.
Definition IIPImage.h:157
IIPImage::operator=
IIPImage & operator=(IIPImage image)
Assignment operator.
Definition IIPImage.h:375
IIPImage::tile_width
unsigned int tile_width
The base tile pixel dimensions.
Definition IIPImage.h:115
KakaduImage::kdu_readmode
KDU_READMODE kdu_readmode
Read-mode.
Definition KakaduImage.h:214
KakaduImage::KakaduImage
KakaduImage()
Constructor.
Definition KakaduImage.h:130
KakaduImage::regionDecoding
bool regionDecoding()
Return whether this image type directly handles region decoding.
Definition KakaduImage.h:182
KakaduImage::KakaduImage
KakaduImage(const std::string &path)
Constructor.
Definition KakaduImage.h:137
KakaduImage::openImage
void openImage()
Overloaded function for opening a TIFF image.
KakaduImage::loadImageInfo
void loadImageInfo(int x, int y)
Overloaded function for loading TIFF image information.
KakaduImage::~KakaduImage
~KakaduImage()
Destructor.
Definition KakaduImage.h:166
KakaduImage::getTile
RawTile getTile(int x, int y, unsigned int r, int l, unsigned int t)
Overloaded function for getting a particular tile.
KakaduImage::closeImage
void closeImage()
Overloaded function for closing a JPEG2000 image.
KakaduImage::KDU_READMODE
KDU_READMODE
Read-mode types.
Definition KakaduImage.h:208
KakaduImage::KDU_FUSSY
@ KDU_FUSSY
Fussy mode.
Definition KakaduImage.h:209
KakaduImage::KDU_RESILIENT
@ KDU_RESILIENT
Reslient mode for damaged JP2 streams.
Definition KakaduImage.h:210
KakaduImage::KDU_FAST
@ KDU_FAST
Default fast mode.
Definition KakaduImage.h:208
KakaduImage::KakaduImage
KakaduImage(const KakaduImage &image)
Copy Constructor.
Definition KakaduImage.h:144
KakaduImage::KakaduImage
KakaduImage(const IIPImage &image)
Constructor from IIPImage object.
Definition KakaduImage.h:149
KakaduImage::operator=
KakaduImage & operator=(KakaduImage image)
Assignment Operator.
Definition KakaduImage.h:156
KakaduImage::getRegion
RawTile getRegion(int ha, int va, unsigned int r, int l, int x, int y, unsigned int w, unsigned int h)
Overloaded function for returning a region for a given angle and resolution.
Logger
Logger class - handles ofstreams and syslog.
Definition Logger.h:79
RawTile
Class to represent a single image tile.
Definition RawTile.h:45
kdu_stream_message
Wrapper class to handle error messages from Kakadu.
Definition KakaduImage.h:54