From f3e58244100550b5764983dd82184097b2247382 Mon Sep 17 00:00:00 2001
From: Julien Malik <julien.malik@c-s.fr>
Date: Sun, 18 Nov 2012 13:09:08 +0100
Subject: [PATCH] TEST: add tests for GDALImageIO creation options

---
 Testing/Code/IO/CMakeLists.txt         | 77 ++++++++++++++++++++++++-
 Testing/Code/IO/otbGDALImageIOTest.cxx | 79 ++++++++++++++++++++++++++
 Testing/Code/IO/otbIOTests2.cxx        |  2 +
 3 files changed, 157 insertions(+), 1 deletion(-)
 create mode 100644 Testing/Code/IO/otbGDALImageIOTest.cxx

diff --git a/Testing/Code/IO/CMakeLists.txt b/Testing/Code/IO/CMakeLists.txt
index 4801509b86..2ce629166f 100644
--- a/Testing/Code/IO/CMakeLists.txt
+++ b/Testing/Code/IO/CMakeLists.txt
@@ -456,7 +456,6 @@ ADD_TEST(ioTvStreamingPipeline_TIF2PNG ${IO_TESTS2}
          ${TEMP}/ioPipeline.png
          )
 
-
 # --- Image FLOAT
 ADD_TEST(ioTvImageFileReaderFloatBSQ2HDR ${IO_TESTS2}
   --compare-image ${EPSILON_9}        ${INPUTDATA}/poupees_R4.hd
@@ -542,7 +541,82 @@ ADD_TEST(ioTvStreamingWithIFWriterBSQWithStreaming ${IO_TESTS2}
 SET_TESTS_PROPERTIES(ioTvStreamingWithIFWriterBSQWithStreaming PROPERTIES DEPENDS ioTvImageFileReaderPNG2BSQ)
 
 
+ADD_TEST(ioTvGDALImageIO_Tiff_NoOption ${IO_TESTS2}
+   --compare-image ${NOTOL} ${INPUTDATA}/maur_rgb.tif
+                            ${TEMP}/ioTvGDALImageIO_Tiff_NoOption.tif
+         otbGDALImageIOTest_uint16
+         ${INPUTDATA}/maur_rgb.tif
+         ${TEMP}/ioTvGDALImageIO_Tiff_NoOption.tif
+         )
+
+ADD_TEST(ioTvGDALImageIO_Tiff_12bits ${IO_TESTS2}
+   --compare-image ${NOTOL} ${INPUTDATA}/maur_rgb.tif
+                            ${TEMP}/ioTvGDALImageIO_Tiff_12bits.tif
+         otbGDALImageIOTest_uint16
+         ${INPUTDATA}/maur_rgb.tif
+         ${TEMP}/ioTvGDALImageIO_Tiff_12bits.tif
+         "NBITS=12"
+         )
+
+ADD_TEST(ioTvGDALImageIO_Tiff_Stripped ${IO_TESTS2}
+   --compare-image ${NOTOL} ${INPUTDATA}/maur_rgb.tif
+                            ${TEMP}/ioTvGDALImageIO_Tiff_stripped.tif
+         otbGDALImageIOTest_uint16
+         ${INPUTDATA}/maur_rgb.tif
+         ${TEMP}/ioTvGDALImageIO_Tiff_stripped.tif
+         "BLOCKYSIZE=10"
+         )
+
+ADD_TEST(ioTvGDALImageIO_Tiff_Tiled_16x16 ${IO_TESTS2}
+   --compare-image ${NOTOL} ${INPUTDATA}/maur_rgb.tif
+                            ${TEMP}/ioTvGDALImageIO_Tiff_tiled_16x16.tif
+         otbGDALImageIOTest_uint16
+         ${INPUTDATA}/maur_rgb.tif
+         ${TEMP}/ioTvGDALImageIO_Tiff_tiled_16x16.tif
+         "TILED=YES"
+         "BLOCKXSIZE=16"
+         "BLOCKYSIZE=16"
+         )
 
+ADD_TEST(ioTvGDALImageIO_Tiff_JPEG_20 ${IO_TESTS2}
+   --compare-image ${NOTOL} ${BASELINE}/ioTvGDALImageIO_Tiff_JPEG_20.tif
+                            ${TEMP}/ioTvGDALImageIO_Tiff_JPEG_20.tif
+         otbGDALImageIOTest_uint8
+         ${INPUTDATA}/maur_rgb_24bpp.tif
+         ${TEMP}/ioTvGDALImageIO_Tiff_JPEG_20.tif
+         "COMPRESS=JPEG"
+         "JPEG_QUALITY=20"
+         "PHOTOMETRIC=YCBCR"
+         )
+
+ADD_TEST(ioTvGDALImageIO_Tiff_JPEG_99 ${IO_TESTS2}
+   --compare-image ${NOTOL} ${BASELINE}/ioTvGDALImageIO_Tiff_JPEG_99.tif
+                            ${TEMP}/ioTvGDALImageIO_Tiff_JPEG_99.tif
+         otbGDALImageIOTest_uint8
+         ${INPUTDATA}/maur_rgb_24bpp.tif
+         ${TEMP}/ioTvGDALImageIO_Tiff_JPEG_99.tif
+         "COMPRESS=JPEG"
+         "JPEG_QUALITY=99"
+         "PHOTOMETRIC=YCBCR"
+         )
+
+ADD_TEST(ioTvGDALImageIO_JPEG_20 ${IO_TESTS2}
+   --compare-image ${NOTOL} ${BASELINE}/ioTvGDALImageIO_JPEG_20.jpg
+                            ${TEMP}/ioTvGDALImageIO_JPEG_20.jpg
+         otbGDALImageIOTest_uint8
+         ${INPUTDATA}/maur_rgb_24bpp.tif
+         ${TEMP}/ioTvGDALImageIO_JPEG_20.jpg
+         "QUALITY=20"
+         )
+
+ADD_TEST(ioTvGDALImageIO_JPEG_99 ${IO_TESTS2}
+   --compare-image ${NOTOL} ${BASELINE}/ioTvGDALImageIO_JPEG_99.jpg
+                            ${TEMP}/ioTvGDALImageIO_JPEG_99.jpg
+         otbGDALImageIOTest_uint8
+         ${INPUTDATA}/maur_rgb_24bpp.tif
+         ${TEMP}/ioTvGDALImageIO_JPEG_99.jpg
+         "QUALITY=99"
+         )
 
 # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ otbIOTests3 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -3674,6 +3748,7 @@ otbDoubleImageIOTest.cxx
 otbStreamingImageFilterTest.cxx
 otbStreamingImageFileWriterTest.cxx
 otbPipeline.cxx
+otbGDALImageIOTest.cxx
 )
 SET(BasicIO_SRCS3
 otbIOTests3.cxx
diff --git a/Testing/Code/IO/otbGDALImageIOTest.cxx b/Testing/Code/IO/otbGDALImageIOTest.cxx
new file mode 100644
index 0000000000..a747ec662e
--- /dev/null
+++ b/Testing/Code/IO/otbGDALImageIOTest.cxx
@@ -0,0 +1,79 @@
+/*=========================================================================
+
+  Program:   ORFEO Toolbox
+  Language:  C++
+  Date:      $Date$
+  Version:   $Revision$
+
+
+  Copyright (c) Centre National d'Etudes Spatiales. All rights reserved.
+  See OTBCopyright.txt for details.
+
+
+  This software is distributed WITHOUT ANY WARRANTY; without even
+  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+  PURPOSE.  See the above copyright notices for more information.
+
+=========================================================================*/
+
+
+
+#include "otbVectorImage.h"
+#include "itkMacro.h"
+#include <iostream>
+
+#include "otbImageFileReader.h"
+#include "otbStreamingImageFileWriter.h"
+#include "otbGDALImageIO.h"
+
+template<class PixelType>
+int otbGenericGDALImageIOTest(int argc, char* argv[])
+{
+  // Verify the number of parameters in the command line
+  const char * inputFilename  = argv[1];
+  const char * outputFilename = argv[2];
+
+  std::vector<std::string> creationOptions;
+  for (int curArg = 3; curArg < argc; curArg++)
+    {
+    creationOptions.push_back(argv[curArg]);
+    std::cout << "Creation option : " << argv[curArg] << std::endl;
+    }
+
+  typedef PixelType InputPixelType;
+  typedef PixelType OutputPixelType;
+  const unsigned int Dimension = 2;
+
+  typedef otb::VectorImage<InputPixelType,  Dimension> InputImageType;
+  typedef otb::VectorImage<OutputPixelType, Dimension> OutputImageType;
+
+  typedef otb::ImageFileReader<InputImageType>  ReaderType;
+  typedef otb::StreamingImageFileWriter<OutputImageType> WriterType;
+
+  typename ReaderType::Pointer reader = ReaderType::New();
+  typename WriterType::Pointer writer = WriterType::New();
+
+
+  reader->SetFileName(inputFilename);
+  writer->SetFileName(outputFilename);
+
+  // Be sure to use GDALImageIO
+  otb::GDALImageIO::Pointer io = otb::GDALImageIO::New();
+  io->SetOptions(creationOptions);
+  writer->SetImageIO(io.GetPointer());
+
+  writer->SetInput(reader->GetOutput());
+  writer->Update();
+
+  return EXIT_SUCCESS;
+}
+
+int otbGDALImageIOTest_uint8(int argc, char* argv[])
+{
+  return otbGenericGDALImageIOTest<unsigned char>(argc, argv);
+}
+
+int otbGDALImageIOTest_uint16(int argc, char* argv[])
+{
+  return otbGenericGDALImageIOTest<unsigned short>(argc, argv);
+}
diff --git a/Testing/Code/IO/otbIOTests2.cxx b/Testing/Code/IO/otbIOTests2.cxx
index d0298b9eba..80c24b3e1a 100644
--- a/Testing/Code/IO/otbIOTests2.cxx
+++ b/Testing/Code/IO/otbIOTests2.cxx
@@ -31,4 +31,6 @@ void RegisterTests()
   REGISTER_TEST(otbStreamingImageFilterTest);
   REGISTER_TEST(otbStreamingImageFileWriterTest);
   REGISTER_TEST(otbPipeline);
+  REGISTER_TEST(otbGDALImageIOTest_uint8);
+  REGISTER_TEST(otbGDALImageIOTest_uint16);
 }
-- 
GitLab