You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hello all, as I could not get closer to a solution after discussing for while in another issue here, I decided to start a new issue and describe what I want to do from the start.
I have an application written in C++, compiled in Visual Studio 2017, which I want to use to take any image from my file system (i.e. a jpeg) and put that image into a valid NITF which can be sent to any other partner (who uses the NITF standard) by my application. And then also take NITF files and extract the image inside and save it to a jpeg file.
I am using the NITRO Library Version 2.8 in my C++ project in order to read and write the data of NITF Files. Reading and writing the images from and to jpeg works fine, using the jpeglib library functions.
My first wish was to use a jpeg compression in the NITF, but as I understood from the discussion, NITRO does not support jpeg compression at the moment, so I would be happy to put the data uncompressed into the NITF, as long as it is a valid NITF.
The problem is that the result which my application produces seems not to be a valid NITF. I am using the XnView tool, and when opening my generated NITF it says "compressed images are not supported", althoug I had the intention to do no compression (image compression set to "NC", see code). The question is what goes wrong in my NITF production?
My code (most of the code is from the samples here on this website):
void populateFileHeader(nitf::Record &record, const std::string &title)
{
/* the file header is already created, so just grab it */
nitf::FileHeader header = record.getHeader();
int read_jpeg_file(const char *filename, unsigned char *&raw_image, int &width, int &height, int &num_components)
{
struct jpeg_decompress_struct cinfo;
struct jpeg_error_mgr jerr;
void addImageSegment(nitf::Record &record, int width, int height, int num_components, bool shouldCompress = false)
{
nitf::ImageSegment segment = record.newImageSegment();
nitf::ImageSubheader subheader = segment.getSubheader();
subheader.getImageId().set("DACAS IMG");
subheader.getImageDateAndTime().set(f2::Time::getCurrentDateTime("%Y%m%d%H%M%S", false));
if (shouldCompress)
{
subheader.getImageCompression().set("C3");
}
else
{
subheader.getImageCompression().set("NC");
}
const size_t NUM_BANDS = num_components;
std::vector<nitf::BandInfo> bands(NUM_BANDS, nitf::BandInfo());
for (size_t ii = 0; ii < bands.size(); ++ii)
{
bands[ii].init(RGB[ii], /* The band representation, Nth band */
" ", /* The band subcategory */
"N", /* The band filter condition */
" "); /* The band standard image filter code */
}
const std::string iRep = (num_components == 3) ? "RGB" : "MONO";
subheader.setPixelInformation("INT", /* Pixel value type */
8, /* Number of bits/pixel */
8, /* Actual number of bits/pixel */
"R", /* Pixel justification */
iRep, /* Image representation */
"VIS", /* Image category */
bands); /* Band information object list */
// The image mode P is part of an awful hack to workaround us not
// having a compression plugin for blocking mode P.
// If you run this test, it will throw an error. The error will reference
// a file in the j2k plugin. To make this test run, go to the file
// and disable the check for blocking mode B.
// To the best of my knowledge, nothing bad happens as a result.
subheader.setBlocking(height, /*!< The number of rows */
width, /*!< The number of columns */
height, /*!< The number of rows/block */
width, /*!< The number of columns/block */
"P"); /*!< Image mode */
}
void writeNITF(nitf::Record &record, const std::string &filename, unsigned char *buffer, int width, int height, int num_components)
{
const size_t NUM_BANDS = num_components;
nitf::IOHandle out(filename, NITF_ACCESS_WRITEONLY, NITF_CREATE);
nitf::Writer writer;
writer.prepare(out, record);
nitf::ImageWriter imageWriter = writer.newImageWriter(0);
nitf::ImageSource imageSource;
int pixelSkipValue = num_components - 1;
/* make one bandSource per band */
for (size_t ii = 0; ii < NUM_BANDS; ++ii)
{
nitf::BandSource bandSource = nitf::MemorySource(
buffer,
width * height,
ii,
1,
pixelSkipValue);
imageSource.addBand(bandSource);
}
imageWriter.setWriteCaching(1);
imageWriter.attachSource(imageSource);
writer.write();
This discussion was converted from issue #201 on December 08, 2020 19:34.
Heading
Bold
Italic
Quote
Code
Link
Numbered list
Unordered list
Task list
Attach files
Mention
Reference
Menu
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Hello all, as I could not get closer to a solution after discussing for while in another issue here, I decided to start a new issue and describe what I want to do from the start.
I have an application written in C++, compiled in Visual Studio 2017, which I want to use to take any image from my file system (i.e. a jpeg) and put that image into a valid NITF which can be sent to any other partner (who uses the NITF standard) by my application. And then also take NITF files and extract the image inside and save it to a jpeg file.
I am using the NITRO Library Version 2.8 in my C++ project in order to read and write the data of NITF Files. Reading and writing the images from and to jpeg works fine, using the jpeglib library functions.
My first wish was to use a jpeg compression in the NITF, but as I understood from the discussion, NITRO does not support jpeg compression at the moment, so I would be happy to put the data uncompressed into the NITF, as long as it is a valid NITF.
The problem is that the result which my application produces seems not to be a valid NITF. I am using the XnView tool, and when opening my generated NITF it says "compressed images are not supported", althoug I had the intention to do no compression (image compression set to "NC", see code). The question is what goes wrong in my NITF production?
My code (most of the code is from the samples here on this website):
void NitroWrapper::CreateNitfFromJpg(const std::string &jpg_path, const std::string &nitf_path)
{
nitf::Record record;
const char *nitfname = nitf_path.c_str();
const char *jpgname = jpg_path.c_str();
unsigned char *raw_image = NULL;
int width, height, num_components;
}
void populateFileHeader(nitf::Record &record, const std::string &title)
{
/* the file header is already created, so just grab it */
nitf::FileHeader header = record.getHeader();
}
int read_jpeg_file(const char *filename, unsigned char *&raw_image, int &width, int &height, int &num_components)
{
struct jpeg_decompress_struct cinfo;
struct jpeg_error_mgr jerr;
}
void addImageSegment(nitf::Record &record, int width, int height, int num_components, bool shouldCompress = false)
{
nitf::ImageSegment segment = record.newImageSegment();
nitf::ImageSubheader subheader = segment.getSubheader();
}
void writeNITF(nitf::Record &record, const std::string &filename, unsigned char *buffer, int width, int height, int num_components)
{
const size_t NUM_BANDS = num_components;
nitf::IOHandle out(filename, NITF_ACCESS_WRITEONLY, NITF_CREATE);
nitf::Writer writer;
writer.prepare(out, record);
}
Beta Was this translation helpful? Give feedback.
All reactions