42 static ossimTrace traceDebug(
"ossimOpjCompressor:debug");
47 static OPJ_SIZE_T ossim_opj_ostream_write(
void * p_buffer,
48 OPJ_SIZE_T p_nb_bytes,
55 std::streamsize bytesToRead = (std::streamsize)p_nb_bytes;
56 str->write( (
char*) p_buffer, bytesToRead );
63 static OPJ_OFF_T ossim_opj_ostream_skip(OPJ_OFF_T p_nb_bytes,
void * p_user_data)
69 str->seekp( p_nb_bytes, std::ios_base::cur );
76 static OPJ_BOOL ossim_opj_ostream_seek(OPJ_OFF_T p_nb_bytes,
void * p_user_data)
82 str->seekp( p_nb_bytes, std::ios_base::beg );
87 static void ossim_opj_free_user_ostream_data(
void * p_user_data )
97 static const ossimString COMPRESSION_QUALITY[] = {
"unknown",
99 "numerically_lossless",
136 static const char MODULE[] =
"ossimOpjCompressor::create";
146 <<
"\nscalar: " << scalar
147 <<
"\nbands: " << bands
148 <<
"\nimageRect: " << imageRect
149 <<
"\ntileSize: " << tileSize
159 std::string errMsg = MODULE;
160 errMsg +=
" ERROR: Null stream passed to method!";
166 std::string errMsg = MODULE;
167 errMsg +=
" ERROR: Stream state has error!";
176 std::string errMsg = MODULE;
177 errMsg +=
" ERROR: Reversible processing not possible with 32 bit data!";
188 std::string errMsg = MODULE;
189 errMsg +=
" ERROR: OPJ stream creation failed!";
200 std::string errMsg = MODULE;
201 errMsg +=
" ERROR: coding parameters creation failed!";
208 std::string errMsg = MODULE;
209 errMsg +=
" ERROR: code creation failed!";
220 if ( (bands != 1) && (bands != 3) )
226 <<
"Alpha channel being unset! Can only be used with " 227 <<
"one or three band data.\n" 228 <<
"Source image bands: " << bands <<
"\n";
237 std::string errMsg = MODULE;
238 errMsg +=
" ERROR: Unsupported input image type!";
244 std::string errMsg = MODULE;
245 errMsg +=
" ERROR: opj_setup_encoder failed!";
256 << MODULE <<
" exiting...\n";
268 std::string errMsg =
"ossimOpjCompressor::openJp2Codestream ERROR: opj_start_compress failed!";
296 <<
"ossimOpjCompressor::writeTile ERROR on tile index: " 297 << tileIndex << std::endl;
303 <<
"ossimOpjCompressor::writeTile ERROR null tile passed in!" << endl;
407 std::vector<ossimString>::const_iterator i = options.begin();
408 while ( i != options.end() )
417 bool consumed =
false;
419 if ( property.
valid() )
426 <<
"ossimOpjCompressor::setProperty DEBUG:" 428 <<
" values: " <<
property->valueToString() << std::endl;
436 else if ( (key == LEVELS_KW) || (key ==
"Clevels") )
438 m_levels =
property->valueToString().toInt32();
441 else if( (key == REVERSIBLE_KW) || (key ==
"Creversible") )
446 else if (key == ADD_ALPHA_CHANNEL_KW)
448 m_alpha =
property->valueToString().toBool();
451 else if ( key == THREADS_KW)
453 m_threads =
property->valueToString().toInt32();
456 else if ( (key ==
"Clayers") ||
457 (key ==
"Cprecincts") )
464 option +=
property->valueToString();
494 vector<ossimString> constraintList;
507 else if (name == LEVELS_KW)
511 else if (name == REVERSIBLE_KW)
515 else if (name == ADD_ALPHA_CHANNEL_KW)
519 else if (name == THREADS_KW)
528 std::vector<ossimString>& propertyNames)
const 531 propertyNames.push_back(LEVELS_KW);
532 propertyNames.push_back(REVERSIBLE_KW);
533 propertyNames.push_back(THREADS_KW);
537 const char* prefix)
const 555 ADD_ALPHA_CHANNEL_KW,
582 const char* value = 0;
590 value = kwl.
find(prefix, LEVELS_KW);
596 value = kwl.
find(prefix, REVERSIBLE_KW);
602 value = kwl.
find(prefix, ADD_ALPHA_CHANNEL_KW);
608 value = kwl.
find(prefix, THREADS_KW);
619 searchKey +=
"option";
626 const char* lookup = kwl.
find(key.
c_str());
647 if ( stream && geom )
659 std::vector<ossim_uint8> buf;
674 0x75, 0x75, 0x69, 0x64
688 stream->write( (
char*)&lbox, 4 );
690 stream->write((
const char*)UUID, 4);
693 stream->write((
const char*)&buf.front(), (std::streamsize)buf.size());
714 if ( stream && geom )
722 0x61, 0x73, 0x6F, 0x63
727 0x6C, 0x62, 0x6C, 0x20
732 0x78, 0x6D, 0x6C, 0x20
737 if ( gml->
write( xmlStr ) )
742 ossim_uint32 boxSize = xmlDataSize + 17 + 8 + 8 + 8 + 8 + 8 + 8;
746 endian.
swap( boxSize );
748 stream->write((
char*)&boxSize, 4);
749 stream->write((
const char*)ASOC_BOX_ID, 4);
756 endian.
swap( boxSize );
758 stream->write((
char*)&boxSize, 4);
759 stream->write((
const char*)LBL_BOX_ID, 4);
760 stream->write(
"gml.data", 8);
763 boxSize = xmlDataSize + 17 + 8 + 8 + 8;
767 endian.
swap( boxSize );
769 stream->write((
char*)&boxSize, 4);
770 stream->write((
const char*)ASOC_BOX_ID, 4);
777 endian.
swap( boxSize );
779 stream->write((
char*)&boxSize, 4);
780 stream->write((
const char*)LBL_BOX_ID, 4);
781 stream->write(
"gml.root-instance", 17);
784 boxSize = xmlDataSize + 8;
788 endian.
swap( boxSize );
790 stream->write((
char*)&boxSize, 4);
791 stream->write((
const char*)XML_BOX_ID, 4);
792 stream->write(xmlStr.str().data(), xmlDataSize);
813 static const char MODULE[] =
"ossimOpjCompressor::initOpjCodingParams";
827 opj_set_default_encoder_parameters(
m_params );
903 m_params->tcp_rates[0] = std::ceil( TP * 0.03125 * 0.125 );
904 m_params->tcp_rates[1] = std::ceil( TP * 0.0625 * 0.125 );
905 m_params->tcp_rates[2] = std::ceil( TP * 0.125 * 0.125 );
906 m_params->tcp_rates[3] = std::ceil( TP * 0.25 * 0.125 );
907 m_params->tcp_rates[4] = std::ceil( TP * 0.5 * 0.125 );
908 m_params->tcp_rates[5] = std::ceil( TP * 0.6 * 0.125 );
909 m_params->tcp_rates[6] = std::ceil( TP * 0.7 * 0.125 );
910 m_params->tcp_rates[7] = std::ceil( TP * 0.8 * 0.125 );
911 m_params->tcp_rates[8] = std::ceil( TP * 0.9 * 0.125 );
912 m_params->tcp_rates[9] = std::ceil( TP * 1.0 * 0.125 );
913 m_params->tcp_rates[10] = std::ceil( TP * 1.1 * 0.125 );
914 m_params->tcp_rates[11] = std::ceil( TP * 1.2 * 0.125 );
915 m_params->tcp_rates[12] = std::ceil( TP * 1.3 * 0.125 );
916 m_params->tcp_rates[13] = std::ceil( TP * 1.5 * 0.125 );
917 m_params->tcp_rates[14] = std::ceil( TP * 1.7 * 0.125 );
918 m_params->tcp_rates[15] = std::ceil( TP * 2.0 * 0.125 );
919 m_params->tcp_rates[16] = std::ceil( TP * 2.3 * 0.125 );
920 m_params->tcp_rates[17] = std::ceil( TP * 2.8 * 0.125 );
921 m_params->tcp_rates[18] = std::ceil( TP * 3.5 * 0.125 );
928 m_params->tcp_rates[19] = std::ceil( TP * 4.0 * 0.125 );
941 m_params->tcp_rates[0] = std::ceil( TP * 0.03125 * 0.125 );
942 m_params->tcp_rates[1] = std::ceil( TP * 0.0625 * 0.125 );
943 m_params->tcp_rates[2] = std::ceil( TP * 0.125 * 0.125 );
944 m_params->tcp_rates[3] = std::ceil( TP * 0.25 * 0.125 );
945 m_params->tcp_rates[4] = std::ceil( TP * 0.5 * 0.125 );
946 m_params->tcp_rates[5] = std::ceil( TP * 0.6 * 0.125 );
947 m_params->tcp_rates[6] = std::ceil( TP * 0.7 * 0.125 );
948 m_params->tcp_rates[7] = std::ceil( TP * 0.8 * 0.125 );
949 m_params->tcp_rates[8] = std::ceil( TP * 0.9 * 0.125 );
950 m_params->tcp_rates[9] = std::ceil( TP * 1.0 * 0.125 );
951 m_params->tcp_rates[10] = std::ceil( TP * 1.1 * 0.125 );
952 m_params->tcp_rates[11] = std::ceil( TP * 1.2 * 0.125 );
953 m_params->tcp_rates[12] = std::ceil( TP * 1.3 * 0.125 );
954 m_params->tcp_rates[13] = std::ceil( TP * 1.5 * 0.125 );
955 m_params->tcp_rates[14] = std::ceil( TP * 1.7 * 0.125 );
956 m_params->tcp_rates[15] = std::ceil( TP * 2.0 * 0.125 );
957 m_params->tcp_rates[16] = std::ceil( TP * 2.3 * 0.125 );
958 m_params->tcp_rates[17] = std::ceil( TP * 2.8 * 0.125 );
959 m_params->tcp_rates[18] = std::ceil( TP * 3.5 * 0.125 );
969 m_params->tcp_rates[0] = std::ceil( TP * 0.03125 * 0.125 );
970 m_params->tcp_rates[1] = std::ceil( TP * 0.0625 * 0.125 );
971 m_params->tcp_rates[2] = std::ceil( TP * 0.125 * 0.125 );
972 m_params->tcp_rates[3] = std::ceil( TP * 0.25 * 0.125 );
973 m_params->tcp_rates[4] = std::ceil( TP * 0.5 * 0.125 );
974 m_params->tcp_rates[5] = std::ceil( TP * 0.6 * 0.125 );
975 m_params->tcp_rates[6] = std::ceil( TP * 0.7 * 0.125 );
976 m_params->tcp_rates[7] = std::ceil( TP * 0.8 * 0.125 );
977 m_params->tcp_rates[8] = std::ceil( TP * 0.9 * 0.125 );
978 m_params->tcp_rates[9] = std::ceil( TP * 1.0 * 0.125 );
990 <<
"unspecified quality type\n";
1008 <<
"\nm_levels: " <<
m_levels <<
"\n";
1050 else if (type ==
"lossy")
1059 <<
"ossimOpjCompressor::setQualityTypeString DEBUG" 1060 <<
"\nUnhandled quality type: " << type
1116 m_params->prog_order = progressionOrder;
1134 opj_codec_t* codec = 0;
1137 codec = opj_create_compress(OPJ_CODEC_JP2);
1141 codec = opj_create_compress(OPJ_CODEC_J2K);
1157 opj_stream_t* stream = 0;
1167 stream = opj_stream_create(1048576, OPJ_FALSE);
1173 opj_stream_set_user_data(stream, os, ossim_opj_free_user_ostream_data);
1178 opj_stream_set_write_function(stream, ossim_opj_ostream_write);
1179 opj_stream_set_skip_function(stream, ossim_opj_ostream_skip);
1180 opj_stream_set_seek_function(stream, ossim_opj_ostream_seek);
1191 opj_image_t* image = 0;
1194 opj_image_cmptparm_t* imageParams =
new opj_image_cmptparm_t[bands];
1195 opj_image_cmptparm_t* imageParam = imageParams;
1200 imageParam->h = imageRect.
height();
1201 imageParam->w = imageRect.
width();
1210 OPJ_COLOR_SPACE clrspc;
1213 clrspc = OPJ_CLRSPC_SRGB;
1218 clrspc = OPJ_CLRSPC_GRAY;
1221 if ( clrspc != OPJ_CLRSPC_UNKNOWN )
1223 image = opj_image_tile_create( bands, imageParams, clrspc );
1228 image->x1 = imageRect.
width();
1229 image->y1 = imageRect.
height();
1230 image->color_space = clrspc;
1234 delete [] imageParams;
1240 <<
"ossimOpjCompressor::createOpjImage DEBUG:\n";
1248 <<
"ossimOpjCompressor::createOpjImage DEBUG image not created!" ~ossimOpjCompressor()
destructor
virtual void valueToString(ossimString &valueResult) const =0
bool setProperty(ossimRefPtr< ossimProperty > property)
Will set the property whose name matches the argument "property->getName()".
OSSIM_DLL ossim_uint32 computeLevels(const ossimIrect &rect)
Computes the number of decimation levels to get to the overview stop dimension.
void finish()
Finish method.
ossim_uint32 numberOf(const char *str) const
bool writeGeotiffBox(std::ostream *stream, const ossimImageGeometry *geom, const ossimIrect &rect, const ossimFilename &tmpFile, ossimPixelType pixelType)
Writes the geotiff box to the jp2.
std::basic_ostringstream< char > ostringstream
Class for char output memory streams.
ossimOpjCompressionQuality m_qualityType
void create(std::ostream *os, ossimScalarType scalar, ossim_uint32 bands, const ossimIrect &imageRect, const ossimIpt &tileSize, bool jp2)
Create method.
virtual const ossim_uint8 * getUcharBuf() const
Represents serializable keyword/value map.
void setProgressionOrder(OPJ_PROG_ORDER progressionOrder)
Sets progression order.
void setAlphaChannelFlag(bool flag)
Set the writer to add an alpha channel to the output png image.
const char * find(const char *key) const
ossimOpjCompressor()
default constructor
bool saveState(ossimKeywordlist &kwl, const char *prefix=0) const
saves the state of the object.
ossim_uint32 height() const
ossim_int32 m_threads
Number of threads.
ossimRefPtr< ossimProperty > getProperty(const ossimString &name) const
static ossimString toString(bool aValue)
Numeric to string methods.
opj_stream_t * createOpjStream(std::ostream *os) const
virtual ossimDataObjectStatus getDataObjectStatus() const
OSSIM_DLL ossimByteOrder byteOrder()
OSSIM_DLL ossim_uint32 getActualBitsPerPixel(ossimScalarType scalarType)
Get actual bits per pixel for a given scalar type.
void setOptions(const std::vector< ossimString > &options)
Sets the options array.
void setQualityType(ossimOpjCompressionQuality type)
Sets the quality type.
ossimOpjCompressionQuality getQualityType() const
void initOpjCodingParams(bool jp2, const ossimIpt &tileSize, const ossimIrect &imageRect)
ossimOpjCompressionQuality
void setThreads(ossim_int32 threads)
Sets the number of threads.
int getNumberOfLayers() const
bool m_reversible
Lossless or lossy.
bool write(std::ostream &os)
Write xml doc to stream.
ossimIrect m_imageRect
Image rectangle.
ossim_int32 toInt32() const
void push_back(char c)
Equivalent to insert(end(), c).
void add(const char *prefix, const ossimKeywordlist &kwl, bool overwrite=true)
void opj_warning_callback(const char *msg, void *)
Callback method for warnings.
OSSIM_DLL bool isSigned(ossimScalarType scalarType)
void initLevels(const ossimIrect &imageRect)
Set levels, class attribute m_levels and m_parameters->numresolution.
static bool writeJp2GeotiffBox(const ossimFilename &tmpFile, const ossimIrect &rect, const ossimProjection *proj, std::vector< ossim_uint8 > &buf, ossimPixelType pixelType)
Writes a geotiff box to a buffer.
bool toBool() const
String to numeric methods.
std::ostream & print(std::ostream &out, kdu_core::kdu_codestream &cs)
Convenience print method for kdu_codestream.
unsigned int ossim_uint32
void opj_info_callback(const char *msg, void *)
Callback method for info.
virtual ossimIrect getImageRectangle() const
opj_image_t * createOpjImage(ossimScalarType scalar, ossim_uint32 bands, const ossimIrect &imageRect) const
static ossimString downcase(const ossimString &aString)
void setReversibleFlag(bool reversible)
Sets the m_reversible flag.
bool initialize(const ossimImageGeometry *geom, const ossimIrect &rect)
Initializes gml block from geometry file.
ossim_uint32 width() const
Container class that holds both 2D transform and 3D projection information for an image Only one inst...
OSSIM_DLL ossim_uint32 getBitsPerPixel(ossimScalarType scalarType)
Get bits per pixel for a given scalar type.
void setLevels(ossim_int32 levels)
Sets the number of levels.
std::vector< ossimString > m_options
Container for Opj options.
const ossimProjection * getProjection() const
Access methods for projection (may be NULL pointer).
ossim_int32 getThreads() const
ossim_int32 getLevels() const
bool getReversibleFlag() const
void setQualityTypeString(const ossimString &s)
bool m_alpha
If true write alpha channel.
ossimString getQualityTypeString() const
static const char * COMPRESSION_QUALITY_KW
ossim_uint32 area() const
const char * c_str() const
Returns a pointer to a null-terminated array of characters representing the string's contents...
ossim_int32 m_levels
Reduced resolution levels.
virtual ossim_uint32 getDataSizeInBytes() const
void opj_error_callback(const char *msg, void *)
Callback method for errors.
opj_cparameters_t * m_params
opj_codec_t * createOpjCodec(bool jp2) const
bool writeGmlBox(std::ostream *stream, const ossimImageGeometry *geom, const ossimIrect &rect)
Writes the gml box to the jp2.
bool getAlphaChannelFlag() const
Retrieve the writer's setting for whether or not to add an alpha channel to the output png image...
void openJp2Codestream()
Calls "open_codestream" on the m_jp2Target.
unsigned char ossim_uint8
void setTlmTileCount(ossim_uint32 tilesToWrite)
bool writeTile(ossimImageData *srcTile, ossim_uint32 tileIndex)
Write tile method.
OSSIMDLLEXPORT std::ostream & ossimNotify(ossimNotifyLevel level=ossimNotifyLevel_WARN)
std::basic_ostream< char > ostream
Base class for char output streams.
bool loadState(const ossimKeywordlist &kwl, const char *prefix=0)
Method to the load (recreate) the state of an object from a keyword list.
void setCodeBlockSize(ossim_int32 xSize, ossim_int32 ySize)
Set code block size.
void getPropertyNames(std::vector< ossimString > &propertyNames) const
Pushes this's names onto the list of property names.