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

SIDD isn't required to have a LUT #683

Merged
merged 2 commits into from
Aug 8, 2023
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
2 changes: 1 addition & 1 deletion six/modules/c++/six.sicd/unittests/test_valid_sixsicd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,5 +149,5 @@ TEST_CASE(test_read_sicd130_xml)
TEST_MAIN(
TEST_CHECK(test_createFakeComplexData);
TEST_CHECK(test_read_sicd110_xml);
TEST_CHECK(test_read_sicd110_xml);
TEST_CHECK(test_read_sicd130_xml);
)
Binary file not shown.
19 changes: 19 additions & 0 deletions six/modules/c++/six.sidd/unittests/test_valid_sixsidd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@ static std::filesystem::path schema_relative_path()
return six_sidd_relative_path() / "conf" / "schema"; // .../conf/schema
}

static std::filesystem::path get_sample_nitf_path(const std::filesystem::path& filename)
{
static const auto modulePath = six_sidd_relative_path() / "tests" / "sample_nitf";
return sys::test::findGITModuleFile("six", modulePath, filename);
}
static std::filesystem::path get_sample_xml_path(const std::filesystem::path& filename)
{
static const auto modulePath = six_sidd_relative_path() / "tests" / "sample_xml";
Expand Down Expand Up @@ -116,6 +121,19 @@ TEST_CASE(test_createFakeDerivedData_validate)
test_createFakeDerivedData_(testName, true /*validate*/, six::sidd::Version::v300, six::sidd300::ISMVersion::v201609);
}

TEST_CASE(test_read_sidd200_no_LUT)
{
static const auto pathname = get_sample_nitf_path("2023-07-26-11-37-27_UMBRA-04_SIDD.nitf");

six::XMLControlRegistry& xml_registry = six::XMLControlFactory::getInstance();
xml_registry.addCreator(six::DataType::DERIVED,
new six::XMLControlCreatorT<six::sidd::DerivedXMLControl>());

six::NITFReadControl reader;
reader.setXMLControlRegistry(xml_registry);
reader.load(pathname.string());
}

static void test_assert_unmodeled_(const std::string& testName, const six::UnmodeledS& Unmodeled)
{
TEST_ASSERT_EQ(1.23, Unmodeled.Xrow);
Expand Down Expand Up @@ -180,6 +198,7 @@ TEST_CASE(test_read_sidd300_v13_xml)
TEST_MAIN(
TEST_CHECK(test_createFakeDerivedData);
TEST_CHECK(test_createFakeDerivedData_validate);
TEST_CHECK(test_read_sidd200_no_LUT);
TEST_CHECK(test_read_sidd200_xml);
TEST_CHECK(test_read_sidd300_xml);
TEST_CHECK(test_read_sidd300_v13_xml);
Expand Down
2 changes: 2 additions & 0 deletions six/modules/c++/six/include/six/NITFReadControl.h
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,8 @@ struct NITFReadControl : public ReadControl
return (iCat == "DED");
}

void setDisplayLUT(six::NITFImageInfo&, const nitf::ImageSubheader&); // LUT processing for SIDDs

// We need this for one of the load overloadings
// to prevent data from being deleted prematurely
// The issue occurs from the explicit destructor of
Expand Down
4 changes: 4 additions & 0 deletions six/modules/c++/six/include/six/ReadControl.h
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,10 @@ struct ReadControl
if (!mXMLRegistry)
mXMLRegistry = &XMLControlFactory::getInstance();
}
void setXMLControlRegistry(const XMLControlRegistry& xmlRegistry)
{
setXMLControlRegistry(&xmlRegistry);
}

protected:
std::shared_ptr<Container> mContainer;
Expand Down
37 changes: 31 additions & 6 deletions six/modules/c++/six/source/NITFReadControl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -455,16 +455,41 @@ void NITFReadControl::load_(std::shared_ptr<nitf::IOInterface> ioInterface, cons
}
}

// SIDD 2.0 needs to read LUT directly from NITF
const auto pData = currentInfo->getData();
if (pData->getDataType() == DataType::DERIVED && pData->getVersion() == "2.0.0")
setDisplayLUT(*currentInfo, subheader);

currentInfo->addSegment(si);
}
}
void NITFReadControl::setDisplayLUT(six::NITFImageInfo& currentInfo, const nitf::ImageSubheader& subheader)
{
// SIDD 2.0 needs to read LUT directly from NITF
const auto pData = currentInfo.getData();
if (pData->getDataType() != DataType::DERIVED)
{
// LUT processing only for SIDDs
return;
}

const auto version = pData->getVersion();
if (version == "1.0.0") // TODO: remove this hard-coded SIDD version check
{
// LUTs only with SIDD 2.0 and later
return;
}

// There's no requirement for SIDD 2.0 to have a LUT
const auto bandInfo0 = subheader.getBandInfo(0);
const int numLUTs = bandInfo0.getNumLUTs();
if (numLUTs > 0) // avoid getLookupTable() creating an empty nitf::LookupTable
{
const auto nitfLut = bandInfo0.getLookupTable();
if (nitfLut.getEntries() > 0)
{
const auto nitfLut = subheader.getBandInfo(0).getLookupTable();
currentInfo->getData_()->setDisplayLUT(std::make_unique<AmplitudeTable>(nitfLut));
currentInfo.getData_()->setDisplayLUT(std::make_unique<AmplitudeTable>(nitfLut));
}
currentInfo->addSegment(si);
}
}

void NITFReadControl::load(std::shared_ptr<nitf::IOInterface> ioInterface, const std::vector<std::string>* pSchemaPaths_)
{
const std::vector<std::string> schemaPaths;
Expand Down
Loading