Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

WIP

  • Loading branch information...
commit e7ddb4f473eeeb830f0ed4de21565a099d050f93 1 parent 2c70737
@zmoratto authored
View
24 src/vw/FileIO/DiskImageResourceOpenJPEG.cc
@@ -77,10 +77,15 @@ static void openjpeg_error_handler( const char* msg, void *client_data ) {
VW_OUT( ErrorMessage, "fileio") << "DiskImageResourceOpenJPEG Error: " << msg << std::endl;
}
+vw::DiskImageResourceOpenJPEG::~DiskImageResourceOpenJPEG() {
+ if ( m_info )
+ delete m_info;
+}
+
void vw::DiskImageResourceOpenJPEG::open( std::string const& filename,
int subsample_factor ) {
- m_info.reset( new DiskImageResourceInfoOpenJPEG() );
+ if (!m_info) m_info = new DiskImageResourceInfoOpenJPEG();
OPJ_VDM << "Trying to open \"" << filename << "\"" << std::endl;
@@ -97,8 +102,8 @@ void vw::DiskImageResourceOpenJPEG::open( std::string const& filename,
OPJ_VDM << "Decode format: " << m_info->parameters.decod_format << std::endl;
- //m_info->l_codec = opj_create_decompress( OPJ_CODEC_JP2 );
- m_info->l_codec = opj_create_decompress( OPJ_CODEC_J2K );
+ m_info->l_codec = opj_create_decompress( OPJ_CODEC_JP2 );
+ //m_info->l_codec = opj_create_decompress( OPJ_CODEC_J2K );
VW_ASSERT( m_info->l_codec,
ArgumentErr() << "Failed to create codec.\n" );
@@ -167,10 +172,6 @@ void DiskImageResourceOpenJPEG::read( ImageBuffer const& dest, BBox2i const& bbo
Vector2i tile_size = block_read_size();
- opj_image_t* tile_image_data = NULL;
- VW_ASSERT( opj_read_header( m_info->l_codec, m_info->l_stream, &tile_image_data ),
- IOErr() << "Failed to reparse image header." );
-
if ( !(bbox.min().x() % tile_size.x()) &&
!(bbox.min().y() % tile_size.y()) ) {
// See if they are requesting on a tile boundary
@@ -179,7 +180,7 @@ void DiskImageResourceOpenJPEG::read( ImageBuffer const& dest, BBox2i const& bbo
if ( bbox.size() == tile_size ) {
// Call for decoding of a single tile!
OPJ_VDM << "Decoding tile at " << bbox << ": Which should be tile: " << index.x() + index.y() * m_info->codec_info->tw << std::endl;
- VW_ASSERT( opj_get_decoded_tile( m_info->l_codec, m_info->l_stream, tile_image_data,
+ VW_ASSERT( opj_get_decoded_tile( m_info->l_codec, m_info->l_stream, m_info->image,
index.x() + index.y() * m_info->codec_info->tw ),
IOErr() << "Failed to decoded tile index: " << index.x() + index.y() * m_info->codec_info->tw );
OPJ_VDM << "Finished!" << std::endl << std::flush;
@@ -189,13 +190,12 @@ void DiskImageResourceOpenJPEG::read( ImageBuffer const& dest, BBox2i const& bbo
src_buf.format = m_format;
src_buf.format.cols = bbox.width();
src_buf.format.rows = bbox.height();
- src_buf.data = tile_image_data->comps[0].data;
+ src_buf.data = m_info->image->comps[0].data;
src_buf.cstride = 4; // Always 4 bytes?
- src_buf.rstride = src_buf.cstride * tile_image_data->comps[0].w;
- src_buf.pstride = src_buf.rstride * tile_image_data->comps[0].h;
+ src_buf.rstride = src_buf.cstride * m_info->image->comps[0].w;
+ src_buf.pstride = src_buf.rstride * m_info->image->comps[0].h;
convert( dest, src_buf, m_rescale);
- opj_image_destroy( tile_image_data );
return;
}
}
View
8 src/vw/FileIO/DiskImageResourceOpenJPEG.h
@@ -33,17 +33,17 @@ namespace vw {
public:
DiskImageResourceOpenJPEG( std::string const& filename,
int subsample_factor = 1 ) :
- DiskImageResource( filename ) {
+ DiskImageResource( filename ), m_info(NULL) {
open( filename, subsample_factor );
}
DiskImageResourceOpenJPEG( std::string const& filename,
ImageFormat const& format ) :
- DiskImageResource( filename ) {
+ DiskImageResource( filename ), m_info(NULL) {
create( filename, format );
}
- virtual ~DiskImageResourceOpenJPEG() {}
+ virtual ~DiskImageResourceOpenJPEG();
/// Returns the type of disk image resource
static std::string type_static() { return "OpenJPEG"; }
@@ -76,7 +76,7 @@ namespace vw {
virtual Vector2i block_read_size() const;
private:
- boost::shared_ptr<DiskImageResourceInfoOpenJPEG> m_info;
+ DiskImageResourceInfoOpenJPEG* m_info;
};
}
View
12 src/vw/FileIO/tests/TestDiskImageResource.cxx
@@ -22,9 +22,12 @@
#include <vw/FileIO/DiskImageResource_internal.h>
#include <vw/Image/PixelTypes.h>
#include <vw/Image/ImageView.h>
+#include <vw/Image/ImageViewRef.h>
#include <vw/config.h>
#include <test/Helpers.h>
+#include <vw/FileIO/DiskImageResourceOpenJPEG.h>
+
using namespace vw;
using namespace vw::internal;
using namespace vw::test;
@@ -417,8 +420,13 @@ TEST( DiskImageResource, PNGComments ) {
}
TEST( DiskImageResource, OpenJPEG ) {
+ vw_settings().set_default_num_threads(8);
+
//DiskImageResourceOpenJPEG rsrc("/Users/zmoratto/Data/Earth/Pleiades_StereoTest/PRIMARY_TRISTEREO_BUNDLE/IMG_PHR1A_P_001/IMG_PHR1A_P_201202250026276_SEN_IPU_20120509_2001-006_R1C1.JP2");
//DiskImageView<PixelGray<uint16> > jp2("/Users/zmoratto/Data/Earth/Pleiades_StereoTest/PRIMARY_TRISTEREO_BUNDLE/IMG_PHR1A_P_001/IMG_PHR1A_P_201202250026276_SEN_IPU_20120509_2001-006_R1C1.JP2");
- DiskImageView<PixelGray<uint16> > jp2("/Users/zmoratto/testing/jp2_test/Cevennes1.j2k");
- write_image( "test_jp2.png", jp2 );
+ boost::shared_ptr<DiskImageResource> disk_rsrc( DiskImageResourceOpenJPEG::construct_open("/home/zmoratto/raid/asp_test_data/Earth/Alaska_Ikonos/WV01_20101215_102001001055C800_10200100118A8F00/WV01_10DEC151636563-P1BS-10200100118A8F00.jp2") );
+ DiskImageView<PixelGray<uint16> > jp2(disk_rsrc);
+ ImageView<PixelGray<uint16> > jp2_crop = crop(jp2, 0, 0, 4096, 1500);
+
+ write_image( "test_jp2.tif", jp2_crop, TerminalProgressCallback("","") );
}
Please sign in to comment.
Something went wrong with that request. Please try again.