Commit 97674187 authored by Marina Bertolino's avatar Marina Bertolino

ENH: move DoMapBuffer function in otbImageIOBase

parent cabcb2d2
......@@ -298,7 +298,6 @@ public:
virtual void SetOutputImagePixelType( bool isComplexInternalPixelType,
bool isVectorImage) = 0;
/*-------- This part of the interfaces deals with reading data ----- */
/** Determine the file type. Returns true if this ImageIO can read the
......@@ -416,6 +415,12 @@ public:
*/
const ArrayOfExtensionsType & GetSupportedWriteExtensions() const;
/** Remap band order in an input buffer using band mapping bandList
* This operation is done in-place. The buffer size should enough to
* contain extracted bands before and after mapping. bandList mapping
* between origin components and output components (before any
* conversion)*/
void DoMapBuffer(void* buffer, size_t numberOfPixels, std::vector<unsigned int>& bandList);
protected:
ImageIOBase();
......
......@@ -1264,6 +1264,53 @@ ImageIOBase
return axis;
}
void
ImageIOBase
::DoMapBuffer(void* buffer, size_t numberOfPixels, std::vector<unsigned int>& bandList)
{
std::cout << "bandList =" << bandList[0] << std::endl;
size_t componentSize = this->GetComponentSize();
size_t inPixelSize = componentSize * this->GetNumberOfComponents();
size_t outPixelSize = componentSize * bandList.size();
char* inPos = static_cast<char*>(buffer);
char* outPos = static_cast<char*>(buffer);
bool workBackward = (outPixelSize > inPixelSize);
char *pixBuffer = new char[outPixelSize];
if (workBackward)
{
inPos = inPos + numberOfPixels*inPixelSize;
outPos = outPos + numberOfPixels*outPixelSize;
for (size_t n=0 ; n<numberOfPixels ; n++)
{
inPos -= inPixelSize;
outPos -= outPixelSize;
for (unsigned int i=0 ; i < bandList.size() ; i++)
{
memcpy(pixBuffer + i*componentSize, inPos + bandList[i]*componentSize, componentSize);
}
// copy pixBuffer to output
memcpy(outPos, pixBuffer, outPixelSize);
}
}
else
{
for (size_t n=0 ; n<numberOfPixels ; n++)
{
for (unsigned int i=0 ; i < bandList.size() ; i++)
{
memcpy(pixBuffer + i*componentSize, inPos + bandList[i]*componentSize, componentSize);
}
// copy pixBuffer to output
memcpy(outPos, pixBuffer, outPixelSize);
inPos += inPixelSize;
outPos += outPixelSize;
}
}
delete[] pixBuffer;
}
void ImageIOBase::PrintSelf(std::ostream& os, itk::Indent indent) const
{
Superclass::PrintSelf(os, indent);
......
......@@ -166,11 +166,6 @@ protected:
/** Convert a block of pixels from one type to another. */
void DoConvertBuffer(void* buffer, size_t numberOfPixels);
/** Remap band order in an input buffer using band mapping m_BandList
* This operation is done in-place. The buffer size should enough to
* contain extracted bands before and after mapping. */
void DoMapBuffer(void* buffer, size_t numberOfPixels);
private:
/** Test whether the given filename exist and it is readable,
this is intended to be called before attempting to use
......
......@@ -213,7 +213,7 @@ ImageFileReader<TOutputImage, ConvertPixelTraits>
this->m_ImageIO->Read(loadBuffer);
if (m_FilenameHelper->BandRangeIsSet())
this->DoMapBuffer(loadBuffer, region.GetNumberOfPixels());
this->m_ImageIO->DoMapBuffer(loadBuffer, region.GetNumberOfPixels(), this->m_BandList);
this->DoConvertBuffer(loadBuffer, region.GetNumberOfPixels());
......@@ -941,52 +941,6 @@ ImageFileReader<TOutputImage, ConvertPixelTraits>
#undef OTB_CONVERT_CBUFFER_IF_BLOCK
}
template <class TOutputImage, class ConvertPixelTraits>
void
ImageFileReader<TOutputImage, ConvertPixelTraits>
::DoMapBuffer(void* buffer, size_t numberOfPixels)
{
size_t componentSize = this->m_ImageIO->GetComponentSize();
size_t inPixelSize = componentSize * this->m_ImageIO->GetNumberOfComponents();
size_t outPixelSize = componentSize * m_BandList.size();
char* inPos = static_cast<char*>(buffer);
char* outPos = static_cast<char*>(buffer);
bool workBackward = (outPixelSize > inPixelSize);
char *pixBuffer = new char[outPixelSize];
if (workBackward)
{
inPos = inPos + numberOfPixels*inPixelSize;
outPos = outPos + numberOfPixels*outPixelSize;
for (size_t n=0 ; n<numberOfPixels ; n++)
{
inPos -= inPixelSize;
outPos -= outPixelSize;
for (unsigned int i=0 ; i < m_BandList.size() ; i++)
{
memcpy(pixBuffer + i*componentSize, inPos + m_BandList[i]*componentSize, componentSize);
}
// copy pixBuffer to output
memcpy(outPos, pixBuffer, outPixelSize);
}
}
else
{
for (size_t n=0 ; n<numberOfPixels ; n++)
{
for (unsigned int i=0 ; i < m_BandList.size() ; i++)
{
memcpy(pixBuffer + i*componentSize, inPos + m_BandList[i]*componentSize, componentSize);
}
// copy pixBuffer to output
memcpy(outPos, pixBuffer, outPixelSize);
inPos += inPixelSize;
outPos += outPixelSize;
}
}
delete[] pixBuffer;
}
} //namespace otb
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment