-
Notifications
You must be signed in to change notification settings - Fork 39
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
Convenience overload to make it easy to read entire image #157
Changes from 6 commits
61536d5
f0cfc29
3a3bbc8
40f0db8
c9d646a
9e6951e
0100db0
a421ce7
8556f0f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -102,33 +102,25 @@ void write(const sys::Int16_T* data) | |
writer.save(reinterpret_cast<const six::UByte*>(data), OUTPUT_NAME); | ||
} | ||
|
||
void read(const std::string& filename, sys::Int16_T* data) | ||
void read(const std::string& filename, mem::ScopedArray<sys::Int16_T>& data) | ||
{ | ||
six::sidd::GeoTIFFReadControl reader; | ||
six::NITFReadControl reader; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does this test program really get run? This can't be right... it should still be a |
||
reader.load(filename); | ||
mem::SharedPtr<const six::Container> container = reader.getContainer(); | ||
const six::Data* const inData = container->getData(0); | ||
|
||
const size_t numRows = inData->getNumRows(); | ||
const size_t numCols = inData->getNumCols(); | ||
six::Region region; | ||
region.setStartRow(0); | ||
region.setStartCol(0); | ||
region.setNumRows(numRows); | ||
region.setNumCols(numCols); | ||
region.setBuffer(reinterpret_cast<six::UByte*>(data)); | ||
reader.interleaved(region, 0); | ||
reader.interleaved(region, 0, data); | ||
} | ||
|
||
bool run() | ||
{ | ||
mem::ScopedArray<sys::Int16_T> imageData(new sys::Int16_T[DATA_LENGTH]); | ||
generateData(imageData.get()); | ||
|
||
mem::ScopedArray<sys::Int16_T> testData(new sys::Int16_T[DATA_LENGTH]); | ||
//mem::ScopedArray<sys::Int16_T> testData(new sys::Int16_T[DATA_LENGTH]); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Don't need this line anymore |
||
|
||
write(imageData.get()); | ||
read(OUTPUT_NAME, testData.get()); | ||
|
||
mem::ScopedArray<sys::Int16_T> testData; | ||
read(OUTPUT_NAME, testData); | ||
|
||
if (memcmp(testData.get(), imageData.get(), DATA_SIZE_IN_BYTES) == 0) | ||
{ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,6 +27,7 @@ | |
#include "six/Container.h" | ||
#include "six/Options.h" | ||
#include "six/XMLControlFactory.h" | ||
#include <mem/ScopedArray.h> | ||
#include <import/logging.h> | ||
|
||
namespace six | ||
|
@@ -108,11 +109,42 @@ class ReadControl | |
* This function reads in the image area specified by the region. | ||
* If you want us to use a work buffer, you can set it through region. | ||
* | ||
* To simply read the entire image, pass a default-constructed | ||
* Region as the first parameter | ||
* | ||
* Once read, the image buffer is set in both the region pointer, | ||
* and in the return value, for convenience | ||
* | ||
* For safety, prefer the overload below. | ||
*/ | ||
virtual UByte* interleaved(Region& region, size_t imageNumber) = 0; | ||
|
||
/*! | ||
* This function reads in the image area specified by the region. | ||
* If you want us to use a work buffer, you can set it through region. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since |
||
* | ||
* To simply read the entire image, pass a default-constructed | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also add a comment somewhere in here that there's no casting that happens... for example, if it's an integer SICD on disk and you pass in a |
||
* Region as the first parameter. | ||
* | ||
* Once read, the image buffer is set in the passed buffer, and | ||
* also the region pointer and the return value for convenience. | ||
* | ||
* \param region Region stores row and cols to be read | ||
* \param imageNumber Index of the image to read | ||
* \param buffer Scoped array that holds the memory for the read-in image. | ||
* This will be allocated by this function. | ||
* | ||
* \return Buffer of image data. This is simply equal to buffer.get() and | ||
* is provided as a convenience. | ||
*/ | ||
template<typename T> | ||
T* interleaved(Region& region, size_t imageNumber, | ||
mem::ScopedArray<T>& buffer) | ||
{ | ||
buffer.reset(reinterpret_cast<T*>(interleaved(region, imageNumber))); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So... if they pass in a region with a non-NULL buffer, they will probably think they still own the memory and double delete it. I wish the region held a smart pointer but it doesn't right now. Any thoughs? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I like this templated - might as well make the return type T* for convenience too There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am not overfond of the I'm trying to think through passing a Region that already has a buffer. I would hope that the smart pointer parameter and the documentation would make it clear that that's what owns the memory at the end. Presumably the caller would already have it stored as a ScopedArray and not just a smart pointer, so that's what they'd end up passing as the third argument, and nothing would change. Or if we change Region to hold a smart pointer, we don't even need the new overload, and there's one less pointer to the same data getting passed around. |
||
return buffer.get(); | ||
} | ||
|
||
/*! | ||
* Get the file type. For SICD, this will only include "NITF", but | ||
* for SIDD, there will be subclassing for "NITF" and "GeoTIFF" | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm still a little hung up on that we're not re-using the memory now... to me, just adding one more line (the
region.setBuffer()
line from before) and passing in a raw pointer here rather than theScopedArray
really is pretty legible code, but it is the case that we're talking a trivial amount of memory and this is a test program, so if you think this does improve readability, I'm good with it.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, I'd lost track of this one! I've pushed up the fixes.