Commit d9dc690e authored by Ian Humphrey's avatar Ian Humphrey
Browse files

Added CHECKSUM parameter to isis2pds to generate an MD5 sum from the raw image...

Added CHECKSUM parameter to isis2pds to generate an MD5 sum from the raw image data and attach to output label. CHECKSUM is false by default. Fixes #1013.

git-svn-id: http://subversion.wr.usgs.gov/repos/prog/isis3/trunk@7674 41f8697f-d340-4b68-9986-7bafba869bb8
parent 56ffbefb
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -63,6 +63,10 @@ void IsisMain() {
  if(ui.GetString("LABTYPE") == "FIXED")
    p.SetExportType(ProcessExportPds::Fixed);

  if (ui.GetBoolean("CHECKSUM")) {
    p.setCanGenerateChecksum(true);
  }

  //Set the resolution to  Kilometers
  p.SetPdsResolution(ProcessExportPds::Kilometer);

@@ -73,6 +77,9 @@ void IsisMain() {
  ofstream oCube(outFileName.toLatin1().data());
  p.OutputLabel(oCube);
  p.StartProcess(oCube);
  if (ui.GetBoolean("CHECKSUM")) {
    p.updateChecksumInLabel(oCube);
  }
  oCube.close();
  p.EndProcess();

+19 −6
Original line number Diff line number Diff line
@@ -24,6 +24,10 @@
    <change name="Kristin Berry" date="2014-06-06">
      Changed to assume that radii without units in the input Isis cube are in meters, map scales without units are in meters/pixel, and map resolutions without units are in pixels/degree.
    </change>
    <change name="Makayla Shepherd and Ian Humphrey" date="2017-05-17">
      Added CHECKSUM parameter to optionally generate and attach an MD5 checksum to the exported
      image label. This checksum is generated from the image data. Fixes #1013.
    </change>
    </history>

  <groups>
@@ -187,6 +191,15 @@
          file as well as displayed onscreen.
        </description>
      </parameter>
      <parameter name="CHECKSUM">
        <type>boolean</type>
        <default><item>false</item></default>
        <brief>Generates and attaches an MD5 checksum to the labels.</brief>
        <description>
          If set to true, then an MD5 checksum will be generated from the image data and
          attached to the output image labels.
        </description>
      </parameter>
    </group>

    <group name="Stretch Options">
+27 −0
Original line number Diff line number Diff line
# Checks the MD5 checksum (CHECKSUM=yes) functionality.
# Note that the md5sum.txt is generated by md5sum and should match labels.pvl's CHECKSUM value.
APPNAME = isis2pds

include $(ISISROOT)/make/isismake.tsts

commands:
	$(APPNAME) from=$(INPUT)/ab102401.cub \
	  to=$(OUTPUT)/ab102401.img \
	  bittype=u16bit \
	  checksum=yes \
	  > /dev/null;
	catlab from=$(OUTPUT)/ab102401.img to=$(OUTPUT)/labels.pvl > /dev/null;
	pds2isis from=$(OUTPUT)/ab102401.img to=$(OUTPUT)/ab102401.cub > /dev/null;
	dd if=$(OUTPUT)/ab102401.img \
	bs=`getkey from=$(OUTPUT)/ab102401.img keyword=^IMAGE` \
	count=1 >& $(OUTPUT)/TEMP.txt > $(OUTPUT)/labelsEOL.txt; 
	# do a cubeit to extract only data and perform md5sum on it to compare
	$(LS) -1 $(INPUT)/*.cub > $(OUTPUT)/cube.lis;
	cubeit from=$(OUTPUT)/cube.lis \
	  to=$(OUTPUT)/cubeit.cub+Lsb+BandSequential+Detached \
	  > /dev/null;
	md5sum $(OUTPUT)/cubeit.cub > $(OUTPUT)/md5sum.txt;
	$(RM) $(OUTPUT)/cube.lis > /dev/null;
	$(RM) $(OUTPUT)/cubeit* > /dev/null;
	$(RM) $(OUTPUT)/ab102401.img > /dev/null;
	$(RM) $(OUTPUT)/TEMP.txt > /dev/null;
+99 −16
Original line number Diff line number Diff line
@@ -21,6 +21,9 @@
 */
#include <iostream>
#include <iomanip>
#include <QCryptographicHash>
#include <QString>

#include "ProcessExport.h"
#include "Preference.h"
#include "IException.h"
@@ -59,6 +62,9 @@ namespace Isis {
    p_His_Set = false;
    p_Hrs_Set = false;

    m_cryptographicHash = new QCryptographicHash(QCryptographicHash::Md5);
    m_canGenerateChecksum = false;

    p_progress->SetText("Exporting");
  }

@@ -72,6 +78,8 @@ namespace Isis {
      delete p_str[i];
    }
    p_str.clear();

    delete m_cryptographicHash;
  }


@@ -665,6 +673,56 @@ namespace Isis {
  }


  /**
   * @description Set m_canGenerateChecksum which determines if we can generate a MD5 checksum on
   * the image data.
   *
   * @param flag boolean to generate the checksum or not
   *
   */
  void ProcessExport::setCanGenerateChecksum(bool flag) {
    m_canGenerateChecksum = flag;
  }


  /**
   * @description Return if we can generate a checksum
   *
   * @return Boolean to generate the checksum or not
   *
   */
  bool ProcessExport::canGenerateChecksum() {
    return m_canGenerateChecksum;
  }


  /**
   * @description Generates a file checksum. This must be called after StartProcess.
   *
   * @return QString Returns a QString of the checksum.
   */
  QString ProcessExport::checksum() {

    QString checksum;

    if (!m_canGenerateChecksum) {
      QString msg = "Cannot generate a checksum. Call setGenerateChecksum(true) before startProcess";
      throw IException(IException::Programmer, msg, _FILEINFO_);
    }
    else {
      if (m_cryptographicHash == NULL) {
        QString msg = "Unable to generate a checksum. Did you call startProcess?";
        throw IException(IException::Programmer, msg, _FILEINFO_);
        return checksum;
      }

      checksum = m_cryptographicHash->result().toHex();
    }

    return checksum;
  }


  /**
  * @brief Set cube up for processing
  *
@@ -984,13 +1042,17 @@ namespace Isis {
      throw IException(IException::Programmer, m, _FILEINFO_);
    }

    //This if is the changed one
    if (m_canGenerateChecksum) {
      // Loop for each line of data
      for(buff->begin(); !buff->end(); buff->next()) {
        // Read a line of data
        InputCubes[0]->read(*buff);
        QByteArray byteArray;
        // Stretch the pixels into the desired range
        for(int i = 0; i < buff->size(); i++) {
          (*buff)[i] = p_str[0]->Map((*buff)[i]);
          byteArray.append((*buff)[i]);
        }
        if(p_pixelType == Isis::UnsignedByte)
          isisOut8(*buff, fout);
@@ -1001,6 +1063,27 @@ namespace Isis {
        else if(p_pixelType == Isis::Real)
          isisOut32(*buff, fout);
        p_progress->CheckStatus();
        m_cryptographicHash->addData(byteArray);
      }
    }
    else {
      for(buff->begin(); !buff->end(); buff->next()) {
        // Read a line of data
        InputCubes[0]->read(*buff);
        // Stretch the pixels into the desired range
        for(int i = 0; i < buff->size(); i++) {
          (*buff)[i] = p_str[0]->Map((*buff)[i]);
        }
        if(p_pixelType == Isis::UnsignedByte)
          isisOut8(*buff, fout);
        else if(p_pixelType == Isis::UnsignedWord)
          isisOut16u(*buff, fout);
        else if(p_pixelType == Isis::SignedWord)
          isisOut16s(*buff, fout);
        else if(p_pixelType == Isis::Real)
          isisOut32(*buff, fout);
        p_progress->CheckStatus();
      }
    }
    delete buff;
    return;
+21 −6
Original line number Diff line number Diff line
@@ -27,6 +27,9 @@
#include <iostream>
#include <string>

#include <QCryptographicHash>
#include <QString>

#include "Buffer.h"
#include "BufferManager.h"
#include "Endian.h"
@@ -107,6 +110,10 @@ namespace Isis {
   *                                            child classes.  Added virtual keyword
   *                                            to destructor.  References #2215.
   *  @history 2016-04-21 Makayla Shepherd - Added UnsignedWord pixel type handling.
   *  @history 2017-05-17 Makayla Shepherd - Added setCanGenerateChecksum(), canGenerateChecksum(),
   *                          and checksum(). Added m_cryptographicHash and m_canGenerateChecksum.
   *                          This allows an MD5 checksum to be generated when exporting an image.
   *                          This checksum is generated based on the image data. Fixes #1013.
   *
   *  @todo 2005-02-09 Stuart Sides - write documentation for CreateWorldFile
   *                                  method
@@ -154,6 +161,10 @@ namespace Isis {
      void SetOutputEndian(enum ByteOrder endianness);
      void SetOutputType(Isis::PixelType pixelIn);

      void setCanGenerateChecksum(bool flag);
      bool canGenerateChecksum();
      QString checksum();

      double GetInputMinimum(unsigned int n=0) const;
      double GetInputMaximum(unsigned int n=0) const;

@@ -265,6 +276,10 @@ namespace Isis {
      bool p_Hrs_Set;  /**< Indicates whether p_Hrs has been set
                            (i.e. if setHrs() has been called).*/

      QCryptographicHash *m_cryptographicHash; /**< A cryptographic hash that will generate an MD5
                                                    checksum of the image data. */
      bool m_canGenerateChecksum;  /**< Flag to determine if a file checksum will be generated. */

    private:
      //!Method for writing 8-bit unsigned pixel data to a file stream
      void isisOut8(Buffer &in, std::ofstream &fout);
Loading