Commit e3f7cb54 authored by Cédric Traizet's avatar Cédric Traizet

BUG: handle band extended filename in imageFileWriter

parent 0daac4e9
Pipeline #5182 failed with stages
in 90 minutes and 16 seconds
......@@ -567,6 +567,11 @@ protected:
/** Image metadata pre-parsed by the ImageIO */
ImageMetadata m_Imd;
/** Mapping between origin components and output components. Note that the buffer is
already mapped after calling the DoMapBuffer method. This attribute is useful to write
band related metadatas. */
std::vector<unsigned int> m_BandList;
private:
ImageIOBase(const Self&) = delete;
void operator=(const Self&) = delete;
......
......@@ -1194,6 +1194,8 @@ std::vector<double> ImageIOBase::GetDefaultDirection(unsigned int k) const
void ImageIOBase::DoMapBuffer(void* buffer, size_t numberOfPixels, std::vector<unsigned int>& bandList)
{
m_BandList = bandList;
size_t componentSize = this->GetComponentSize();
size_t inPixelSize = componentSize * this->GetNumberOfComponents();
size_t outPixelSize = componentSize * bandList.size();
......
......@@ -1294,9 +1294,19 @@ void GDALImageIO::InternalWriteImageInformation(const void* buffer)
// char ** papszOptions = NULL;
std::string driverShortName;
m_NbBands = this->GetNumberOfComponents();
// If the band mapping is different from the one of the input (e.g. because an extended filename
// has been set, the bands in the imageMetadata object needs to be reorganized.
if (!m_BandList.empty())
{
ImageMetadata::ImageMetadataBandsType bandRangeMetadata;
for (auto elem: m_BandList)
{
bandRangeMetadata.push_back(m_Imd.Bands[elem]);
}
m_Imd.Bands = bandRangeMetadata;
}
std::cout << m_Imd << std::endl;
std::cout << "m_NbBands " << (std::size_t)m_NbBands << std::endl;
std::cout << "m_ImdBands size " << m_Imd.Bands.size() << std::endl;
if ( !m_Imd.Bands.empty() && (std::size_t)m_NbBands != m_Imd.Bands.size())
{
......
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