Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow sidd blocking #1

Merged
merged 3 commits into from
Jul 19, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions modules/c++/six/include/six/NITFWriteControl.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,13 @@ class NITFWriteControl : public WriteControl
static const char OPT_MAX_ILOC_ROWS[];
static const char OPT_J2K_COMPRESSION[];

//! These determine the NITF blocking
// They only pertain to SIDD
// SICDs are never blocked, so setting this for a SICD will
// result in an error
static const char OPT_NUM_ROWS_PER_BLOCK[];
static const char OPT_NUM_COLS_PER_BLOCK[];

//! Buffered IO
enum
{
Expand Down Expand Up @@ -274,6 +281,17 @@ class NITFWriteControl : public WriteControl
*/
void addDataAndWrite(const std::vector<std::string>& schemaPaths);

/*!
* This function sets the NITF blocking. By default, the product
* will be unblocked, but for SIDDs the user can override this via
* the options. To be pedantic, the SIDD spec defines the NITF
* header such that blocking is not allowed, but this is a typo and
* will cause problems with some ELTs for images > 1 GB.
*/
void setBlocking(const std::string& imode,
const types::RowCol<size_t>& segmentDims,
nitf::ImageSubheader& subheader);

/*!
* This function sets the image security fields in the
* given image subheader using the parameters in the
Expand Down
20 changes: 8 additions & 12 deletions modules/c++/six/include/six/Options.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,48 +43,44 @@ namespace six
*/
class Options
{
std::map<std::string, Parameter> mParameters;

public:
typedef std::map<std::string, Parameter> ParameterMap;
typedef std::map<std::string, Parameter>::const_iterator ParameterIter;

Options()
{
}
virtual ~Options()
{
}
virtual ~Options();

/*!
* Get back the parameter with option key specified in argument
*
*/
virtual Parameter getParameter(std::string option) const;
virtual Parameter getParameter(const std::string& option) const;

/*!
* Get back the parameter with option key specified in argument.
* If we fail to find that option, supplement it with defaultValue
* that is passed in
*/
virtual Parameter
getParameter(std::string option, Parameter defaultValue) const;
getParameter(const std::string& option, Parameter defaultValue) const;

/*!
* Set a parameter with key given in option parameter
*/
virtual void setParameter(std::string option, Parameter value);
virtual void setParameter(const std::string& option, Parameter value);

/*!
* Is there a parameter of name given in argument
*/
virtual bool hasParameter(std::string option) const;
virtual bool hasParameter(const std::string& option) const;

//! Allows us to iterate a parameter list
ParameterIter begin() const { return mParameters.begin(); }

//! Allows us to compare an iterator against end
ParameterIter end() const { return mParameters.end(); }

private:
std::map<std::string, Parameter> mParameters;
};
}

Expand Down
61 changes: 55 additions & 6 deletions modules/c++/six/source/NITFWriteControl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ using namespace six;
const char NITFWriteControl::OPT_MAX_PRODUCT_SIZE[] = "MaxProductSize";
const char NITFWriteControl::OPT_MAX_ILOC_ROWS[] = "MaxILOCRows";
const char NITFWriteControl::OPT_J2K_COMPRESSION[] = "J2KCompression";
const char NITFWriteControl::OPT_NUM_ROWS_PER_BLOCK[] = "NumRowsPerBlock";
const char NITFWriteControl::OPT_NUM_COLS_PER_BLOCK[] = "NumColsPerBlock";

namespace
{
Expand Down Expand Up @@ -148,7 +150,7 @@ void NITFWriteControl::initialize(Container* container)
{
NITFImageInfo* info = mInfos[ii];

std::vector < NITFSegmentInfo > imageSegments
const std::vector <NITFSegmentInfo> imageSegments
= info->getImageSegments();

size_t numIS = imageSegments.size();
Expand Down Expand Up @@ -229,11 +231,10 @@ void NITFWriteControl::initialize(Container* container)
subheader.setPixelInformation(pvtype, nbpp, nbpp, "R", irep, "SAR",
bandInfo);

subheader.setBlocking(segmentInfo.numRows,
numCols,
segmentInfo.numRows > 8192 ? 0
: segmentInfo.numRows,
numCols > 8192 ? 0 : numCols, imode);
setBlocking(imode,
types::RowCol<size_t>(segmentInfo.numRows, numCols),
subheader);

subheader.getImageSyncCode().set(0);
if (jj == 0)
{
Expand Down Expand Up @@ -288,6 +289,54 @@ void NITFWriteControl::initialize(Container* container)
updateFileHeaderSecurity();
}

void NITFWriteControl::setBlocking(const std::string& imode,
const types::RowCol<size_t>& segmentDims,
nitf::ImageSubheader& subheader)
{
const bool isSICD = (mContainer->getDataType() == DataType::COMPLEX);

nitf::Uint32 numRowsPerBlock;
if (mOptions.hasParameter(OPT_NUM_ROWS_PER_BLOCK))
{
if (isSICD)
{
throw except::Exception(Ctxt("SICDs do not support blocking"));
}

numRowsPerBlock = static_cast<sys::Uint32_T>(
mOptions.getParameter(OPT_NUM_ROWS_PER_BLOCK));
}
else
{
// Unblocked (per 2500C, if > 8192, should be set to 0)
numRowsPerBlock = (segmentDims.row > 8192) ?
0 : segmentDims.row;
}

nitf::Uint32 numColsPerBlock;
if (mOptions.hasParameter(OPT_NUM_COLS_PER_BLOCK))
{
if (isSICD)
{
throw except::Exception(Ctxt("SICDs do not support blocking"));
}

numColsPerBlock = static_cast<sys::Uint32_T>(
mOptions.getParameter(OPT_NUM_COLS_PER_BLOCK));
}
else
{
// Unblocked (per 2500C, if > 8192, should be set to 0)
numColsPerBlock = (segmentDims.col > 8192) ? 0 : segmentDims.col;
}

subheader.setBlocking(segmentDims.row,
segmentDims.col,
numRowsPerBlock,
numColsPerBlock,
imode);
}

void NITFWriteControl::setImageSecurity(const six::Classification& c,
nitf::ImageSubheader& subheader)
{
Expand Down
22 changes: 13 additions & 9 deletions modules/c++/six/source/Options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,36 +21,40 @@
*/
#include "six/Options.h"

using namespace six;
namespace six
{
Options::~Options()
{
}

Parameter Options::getParameter(std::string option) const
Parameter Options::getParameter(const std::string& option) const
{
ParameterIter p = mParameters.find(option);
const ParameterIter p = mParameters.find(option);
if (p == mParameters.end())
{
throw except::Exception(Ctxt("No such option exists"));
}
return p->second;
}

Parameter Options::getParameter(std::string option, Parameter defaultValue) const
Parameter Options::getParameter(const std::string& option, Parameter defaultValue) const
{
ParameterIter p = mParameters.find(option);
const ParameterIter p = mParameters.find(option);
if (p == mParameters.end())
{
return defaultValue;
}
return p->second;
}

void Options::setParameter(std::string option, Parameter value)
void Options::setParameter(const std::string& option, Parameter value)
{
mParameters[option] = value;
}

bool Options::hasParameter(std::string option) const
bool Options::hasParameter(const std::string& option) const
{
ParameterIter p = mParameters.find(option);
const ParameterIter p = mParameters.find(option);
return (p != mParameters.end());
}

}