Unverified Commit eb989cb9 authored by Jesse Mapel's avatar Jesse Mapel Committed by GitHub
Browse files

Fixed signed int TIFF export in isis2std (#4983)

* Fixed sInt16 support in TiffExporter

* Added Kirsten to authors

* Convert isis2std to callable

* first new isis2std test

* Fixed QString include

* Removed old isis2std bmp test

* Migrated extension test

* Finished isis2std test conversion
parent 005f5c48
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -51,6 +51,9 @@
    {
      "name": "Barrett, Janet"
    },
    {
      "name": "Bauck, Kirsten"
    },
    {
      "name": "Bauers, Joni"
    },
+2 −0
Original line number Diff line number Diff line
@@ -51,8 +51,10 @@ release.
- Added check to determine if poles were a valid projection point in ImagePolygon when generating footprint for a map projected image. [#4390](https://github.com/USGS-Astrogeology/ISIS3/issues/4390)
- Fixed the Mars Express HRSC SRC camera and serial number to use the StartTime instead of the StartClockCount  [#4803](https://github.com/USGS-Astrogeology/ISIS3/issues/4803)
- Fixed algorithm for applying rolling shutter jitter. Matches implementation in USGSCSM.
- Fixed isis2std incorrectly outputing signed 16 bit tiff files. [#4897](https://github.com/USGS-Astrogeology/ISIS3/issues/4897)
- Fixed CNetCombinePt logging functionality such that only merged points are included in the log. [#4973](https://github.com/USGS-Astrogeology/ISIS3/issues/4973)


## [7.0.0] - 2022-02-11

### Changed
+145 −0
Original line number Diff line number Diff line
/** This is free and unencumbered software released into the public domain.

The authors of ISIS do not claim copyright on the contents of this file.
For more details about the LICENSE terms and the AUTHORS, you will
find files of those names at the top level of this repository. **/

/* SPDX-License-Identifier: CC0-1.0 */

#include "ExportDescription.h"
#include "FileName.h"
#include "ImageExporter.h"
#include "UserInterface.h"


using namespace std;

namespace Isis  {

  int addChannel(UserInterface &ui, ExportDescription &desc, QString param, QString mode);
  void addResults(PvlGroup &results, ImageExporter *exporter, QString channel, int index);


  void isis2std(UserInterface &ui, Pvl *log) {
    QString format = ui.GetString("FORMAT");
    ImageExporter *exporter = ImageExporter::fromFormat(format);

    ExportDescription desc;
    if (ui.GetString("BITTYPE") == "8BIT") {
      desc.setPixelType(UnsignedByte);
    }
    else if (ui.GetString("BITTYPE") == "U16BIT") {
      desc.setPixelType(UnsignedWord);
    }
    else { //if (ui.GetString("BITTYPE") == "S16BIT")
      desc.setPixelType(SignedWord);
    }

    int redIndex = -1;
    int greenIndex = -1;
    int blueIndex = -1;
    int alphaIndex = -1;

    QString mode = ui.GetString("MODE");
    if (mode == "GRAYSCALE") {
      addChannel(ui, desc, "FROM", mode);
      exporter->setGrayscale(desc);
    }
    else {
      redIndex = addChannel(ui, desc, "RED", mode);
      greenIndex = addChannel(ui, desc, "GREEN", mode);
      blueIndex = addChannel(ui, desc, "BLUE", mode);

      if (mode == "ARGB") {
        alphaIndex = addChannel(ui, desc, "ALPHA", mode);
        exporter->setRgba(desc);
      }

      else {
        exporter->setRgb(desc);
      }
    }

    FileName outputName = ui.GetFileName("TO");
    int quality = ui.GetInteger("QUALITY");


    QString compression;
    if (format == "TIFF") {
      compression = ui.GetString("COMPRESSION").toLower();

    }
    else {
      compression = "none";
    }

    exporter->write(outputName, quality, compression, &ui);

    if (mode != "GRAYSCALE" && ui.GetString("STRETCH") != "MANUAL") {
      ui.Clear("MINIMUM");
      ui.Clear("MAXIMUM");

      ui.PutDouble("RMIN", exporter->inputMinimum(redIndex));
      ui.PutDouble("RMAX", exporter->inputMaximum(redIndex));
      ui.PutDouble("GMIN", exporter->inputMinimum(greenIndex));
      ui.PutDouble("GMAX", exporter->inputMaximum(greenIndex));
      ui.PutDouble("BMIN", exporter->inputMinimum(blueIndex));
      ui.PutDouble("BMAX", exporter->inputMaximum(blueIndex));

      if (mode == "ARGB") {
        ui.PutDouble("AMIN", exporter->inputMinimum(alphaIndex));
        ui.PutDouble("AMAX", exporter->inputMaximum(alphaIndex));
      }
    }

    // Write out the results
    PvlGroup results("Results");
    results += PvlKeyword("OutputFileName", outputName.expanded());

    if (mode == "GRAYSCALE") {
      addResults(results, exporter, "", 0);
    }
    else {
      addResults(results, exporter, "Red", redIndex);
      addResults(results, exporter, "Green", greenIndex);
      addResults(results, exporter, "Blue", blueIndex);

      if (mode == "ARGB") addResults(results, exporter, "Alpha", alphaIndex);
    }

    if (log) {
      log->addGroup(results);
    }

    delete exporter;
  }


  int addChannel(UserInterface &ui, ExportDescription &desc, QString param, QString mode) {
    FileName name = ui.GetCubeName(param);
    CubeAttributeInput &att = ui.GetInputAttribute(param);

    int index = -1;
    if (mode != "GRAYSCALE" && ui.GetString("STRETCH") == "MANUAL") {
      QString bandId = param.mid(0, 1);
      double min = ui.GetDouble(bandId + "MIN");
      double max = ui.GetDouble(bandId + "MAX");

      index = desc.addChannel(name, att, min, max);
    }
    else {
      index = desc.addChannel(name, att);
    }

    return index;
  }


  void addResults(PvlGroup &results, ImageExporter *exporter,
      QString channel, int index) {

    results += PvlKeyword(channel + "InputMinimum", toString(exporter->inputMinimum(index)));
    results += PvlKeyword(channel + "InputMaximum", toString(exporter->inputMaximum(index)));
  }

}
 No newline at end of file
+19 −0
Original line number Diff line number Diff line
#ifndef isis2std_h
#define isis2std_h

/** This is free and unencumbered software released into the public domain.

The authors of ISIS do not claim copyright on the contents of this file.
For more details about the LICENSE terms and the AUTHORS, you will
find files of those names at the top level of this repository. **/

/* SPDX-License-Identifier: CC0-1.0 */

#include "UserInterface.h"
#include "Pvl.h"

namespace Isis {
  extern void isis2std(UserInterface &ui, Pvl *log = nullptr);
}

#endif
 No newline at end of file
+20 −125
Original line number Diff line number Diff line
#include "Isis.h"
/** This is free and unencumbered software released into the public domain.

#include "ExportDescription.h"
#include "FileName.h"
#include "ImageExporter.h"
#include "UserInterface.h"
The authors of ISIS do not claim copyright on the contents of this file.
For more details about the LICENSE terms and the AUTHORS, you will
find files of those names at the top level of this repository. **/

using namespace Isis;
using namespace std;
/* SPDX-License-Identifier: CC0-1.0 */

#include "Isis.h"

#include "isis2std.h"

int addChannel(ExportDescription &desc, QString param, QString mode);
void addResults(PvlGroup &results, ImageExporter *exporter,
    QString channel, int index);
#include "Pvl.h"
#include "UserInterface.h"

using namespace Isis;

void IsisMain() {
  UserInterface &ui = Application::GetUserInterface();

  QString format = ui.GetString("FORMAT");
  ImageExporter *exporter = ImageExporter::fromFormat(format);

  ExportDescription desc;
  if (ui.GetString("BITTYPE") == "8BIT") {
    desc.setPixelType(UnsignedByte);
  }
  else if (ui.GetString("BITTYPE") == "U16BIT") {
    desc.setPixelType(UnsignedWord);
  }
  else { //if (ui.GetString("BITTYPE") == "S16BIT")
    desc.setPixelType(SignedWord);
  }

  int redIndex = -1;
  int greenIndex = -1;
  int blueIndex = -1;
  int alphaIndex = -1;

  QString mode = ui.GetString("MODE");
  if (mode == "GRAYSCALE") {
    addChannel(desc, "FROM", mode);
    exporter->setGrayscale(desc);
  }
  else {
    redIndex = addChannel(desc, "RED", mode);
    greenIndex = addChannel(desc, "GREEN", mode);
    blueIndex = addChannel(desc, "BLUE", mode);

    if (mode == "ARGB") {
      alphaIndex = addChannel(desc, "ALPHA", mode);
      exporter->setRgba(desc);
    }

    else {
      exporter->setRgb(desc);
    }
  }

  FileName outputName = ui.GetFileName("TO");
  int quality = ui.GetInteger("QUALITY");


  QString compression;
  if (format == "TIFF") {
    compression = ui.GetString("COMPRESSION").toLower();

  Pvl appLog;
  try {
    isis2std(ui, &appLog);
  }
  else {
    compression = "none";
  catch (...) {
    for (auto grpIt = appLog.beginGroup(); grpIt!= appLog.endGroup(); grpIt++) {
      Application::Log(*grpIt);
    }

  exporter->write(outputName, quality, compression);

  if (mode != "GRAYSCALE" && ui.GetString("STRETCH") != "MANUAL") {
    ui.Clear("MINIMUM");
    ui.Clear("MAXIMUM");

    ui.PutDouble("RMIN", exporter->inputMinimum(redIndex));
    ui.PutDouble("RMAX", exporter->inputMaximum(redIndex));
    ui.PutDouble("GMIN", exporter->inputMinimum(greenIndex));
    ui.PutDouble("GMAX", exporter->inputMaximum(greenIndex));
    ui.PutDouble("BMIN", exporter->inputMinimum(blueIndex));
    ui.PutDouble("BMAX", exporter->inputMaximum(blueIndex));

    if (mode == "ARGB") {
      ui.PutDouble("AMIN", exporter->inputMinimum(alphaIndex));
      ui.PutDouble("AMAX", exporter->inputMaximum(alphaIndex));
    }
  }

  // Write out the results
  PvlGroup results("Results");
  results += PvlKeyword("OutputFileName", outputName.expanded());

  if (mode == "GRAYSCALE") {
    addResults(results, exporter, "", 0);
  }
  else {
    addResults(results, exporter, "Red", redIndex);
    addResults(results, exporter, "Green", greenIndex);
    addResults(results, exporter, "Blue", blueIndex);

    if (mode == "ARGB") addResults(results, exporter, "Alpha", alphaIndex);
  }

  Application::Log(results);

  delete exporter;
}


int addChannel(ExportDescription &desc, QString param, QString mode) {
  UserInterface &ui = Application::GetUserInterface();
  FileName name = ui.GetCubeName(param);
  CubeAttributeInput &att = ui.GetInputAttribute(param);

  int index = -1;
  if (mode != "GRAYSCALE" && ui.GetString("STRETCH") == "MANUAL") {
    QString bandId = param.mid(0, 1);
    double min = ui.GetDouble(bandId + "MIN");
    double max = ui.GetDouble(bandId + "MAX");

    index = desc.addChannel(name, att, min, max);
  }
  else {
    index = desc.addChannel(name, att);
    throw;
  }

  return index;
  for (auto grpIt = appLog.beginGroup(); grpIt!= appLog.endGroup(); grpIt++) {
    Application::Log(*grpIt);
  }


void addResults(PvlGroup &results, ImageExporter *exporter,
    QString channel, int index) {

  results += PvlKeyword(channel + "InputMinimum", toString(exporter->inputMinimum(index)));
  results += PvlKeyword(channel + "InputMaximum", toString(exporter->inputMaximum(index)));
}
Loading