Skip to content
Snippets Groups Projects
Commit 4e40a07b authored by Julien Malik's avatar Julien Malik
Browse files

BUG: fix GDALImageIO streaming support

parent 907cb3a1
No related branches found
No related tags found
No related merge requests found
...@@ -27,7 +27,7 @@ ...@@ -27,7 +27,7 @@
#include "otbMacro.h" #include "otbMacro.h"
#include "otbSystem.h" #include "otbSystem.h"
#include "otbImage.h" #include "otbImage.h"
#include "itkArray.h" #include "itkVariableLengthVector.h"
#include "itkMetaDataObject.h" #include "itkMetaDataObject.h"
#include "otbMetaDataKey.h" #include "otbMetaDataKey.h"
...@@ -236,7 +236,7 @@ void GDALImageIO::Read(void* buffer) ...@@ -236,7 +236,7 @@ void GDALImageIO::Read(void* buffer)
std::streamoff lNbPixels = (static_cast<std::streamoff>(lNbColumns)) * (static_cast<std::streamoff>(lNbLines)); std::streamoff lNbPixels = (static_cast<std::streamoff>(lNbColumns)) * (static_cast<std::streamoff>(lNbLines));
std::streamoff lBufferSize = static_cast<std::streamoff>(m_NbOctetPixel) * lNbPixels; std::streamoff lBufferSize = static_cast<std::streamoff>(m_NbOctetPixel) * lNbPixels;
itk::Array<unsigned char> value(lBufferSize); itk::VariableLengthVector<unsigned char> value(lBufferSize);
CPLErr lCrGdal; CPLErr lCrGdal;
std::streamoff cpt(0); std::streamoff cpt(0);
...@@ -249,7 +249,7 @@ void GDALImageIO::Read(void* buffer) ...@@ -249,7 +249,7 @@ void GDALImageIO::Read(void* buffer)
lFirstLine, lFirstLine,
lNbColumns, lNbColumns,
lNbLines, lNbLines,
value.data_block(), const_cast<unsigned char*>(value.GetDataPointer()),
lNbColumns, lNbColumns,
lNbLines, lNbLines,
m_PxType, m_PxType,
...@@ -276,7 +276,7 @@ void GDALImageIO::Read(void* buffer) ...@@ -276,7 +276,7 @@ void GDALImageIO::Read(void* buffer)
lFirstLine, lFirstLine,
lNbColumns, lNbColumns,
lNbLines, lNbLines,
value.data_block(), const_cast<unsigned char*>(value.GetDataPointer()),
lNbColumns, lNbColumns,
lNbLines, lNbLines,
m_PxType, m_PxType,
...@@ -312,7 +312,7 @@ void GDALImageIO::Read(void* buffer) ...@@ -312,7 +312,7 @@ void GDALImageIO::Read(void* buffer)
lFirstLine, lFirstLine,
lNbColumns, lNbColumns,
lNbLines, lNbLines,
value.data_block(), const_cast<unsigned char*>(value.GetDataPointer()),
lNbColumns, lNbColumns,
lNbLines, lNbLines,
m_PxType, m_PxType,
...@@ -793,6 +793,8 @@ void GDALImageIO::InternalReadImageInformation() ...@@ -793,6 +793,8 @@ void GDALImageIO::InternalReadImageInformation()
bool GDALImageIO::CanWriteFile(const char* name) bool GDALImageIO::CanWriteFile(const char* name)
{ {
m_FileName = name;
// First check the filename // First check the filename
if (name == NULL) if (name == NULL)
{ {
...@@ -823,6 +825,7 @@ bool GDALImageIO::CanStreamWrite() ...@@ -823,6 +825,7 @@ bool GDALImageIO::CanStreamWrite()
// Get the GDAL format ID from the name // Get the GDAL format ID from the name
std::string gdalDriverShortName = FilenameToGdalDriverShortName(m_FileName); std::string gdalDriverShortName = FilenameToGdalDriverShortName(m_FileName);
GDALDriver* driver = GDALDriverManagerWrapper::GetInstance().GetDriverByName(gdalDriverShortName); GDALDriver* driver = GDALDriverManagerWrapper::GetInstance().GetDriverByName(gdalDriverShortName);
if (driver == NULL) if (driver == NULL)
{ {
itkDebugMacro(<< "Unable to instantiate driver " << gdalDriverShortName); itkDebugMacro(<< "Unable to instantiate driver " << gdalDriverShortName);
...@@ -873,7 +876,7 @@ void GDALImageIO::Write(const void* buffer) ...@@ -873,7 +876,7 @@ void GDALImageIO::Write(const void* buffer)
std::streamoff lBufferSize = static_cast<std::streamoff> (m_NbOctetPixel) * lNbPixels; std::streamoff lBufferSize = static_cast<std::streamoff> (m_NbOctetPixel) * lNbPixels;
otbMsgDevMacro(<< " BufferSize allocated : " << lBufferSize); otbMsgDevMacro(<< " BufferSize allocated : " << lBufferSize);
itk::Array<unsigned char> value(lBufferSize); itk::VariableLengthVector<unsigned char> value(lBufferSize);
if (m_CanStreamWrite) if (m_CanStreamWrite)
{ {
...@@ -895,7 +898,7 @@ void GDALImageIO::Write(const void* buffer) ...@@ -895,7 +898,7 @@ void GDALImageIO::Write(const void* buffer)
} }
GDALRasterBand *poBand = m_Dataset->GetDataSet()->GetRasterBand(nbComponents+1); GDALRasterBand *poBand = m_Dataset->GetDataSet()->GetRasterBand(nbComponents+1);
lCrGdal = poBand->RasterIO(GF_Write, lFirstColumn, lFirstLine, lNbColumns, lNbLines, value.data_block(), lCrGdal = poBand->RasterIO(GF_Write, lFirstColumn, lFirstLine, lNbColumns, lNbLines, const_cast<unsigned char*>(value.GetDataPointer()),
lNbColumns, lNbLines, m_PxType, 0, 0); lNbColumns, lNbLines, m_PxType, 0, 0);
if (lCrGdal == CE_Failure) if (lCrGdal == CE_Failure)
{ {
...@@ -1125,7 +1128,7 @@ void GDALImageIO::InternalWriteImageInformation(const void* buffer) ...@@ -1125,7 +1128,7 @@ void GDALImageIO::InternalWriteImageInformation(const void* buffer)
/* Set the six coefficients of affine geoTtransform */ /* Set the six coefficients of affine geoTtransform */
/* -------------------------------------------------------------------- */ /* -------------------------------------------------------------------- */
itk::Array<double> geoTransform(6); itk::VariableLengthVector<double> geoTransform(6);
/// Reporting origin and spacing /// Reporting origin and spacing
geoTransform[0] = m_Origin[0]; geoTransform[0] = m_Origin[0];
geoTransform[3] = m_Origin[1]; geoTransform[3] = m_Origin[1];
...@@ -1135,7 +1138,7 @@ void GDALImageIO::InternalWriteImageInformation(const void* buffer) ...@@ -1135,7 +1138,7 @@ void GDALImageIO::InternalWriteImageInformation(const void* buffer)
// FIXME: Here component 1 and 4 should be replaced by the orientation parameters // FIXME: Here component 1 and 4 should be replaced by the orientation parameters
geoTransform[2] = 0.; geoTransform[2] = 0.;
geoTransform[4] = 0.; geoTransform[4] = 0.;
dataset->SetGeoTransform(geoTransform.data_block()); dataset->SetGeoTransform(const_cast<double*>(geoTransform.GetDataPointer()));
/* -------------------------------------------------------------------- */ /* -------------------------------------------------------------------- */
/* Report metadata. */ /* Report metadata. */
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment