Isis 3 Programmer Reference
JP2Exporter.cpp
1 #include "JP2Exporter.h"
2 
3 #include "Buffer.h"
4 #include "FileName.h"
5 #include "IException.h"
6 #include "IString.h"
7 #include "JP2Encoder.h"
8 
9 using namespace Isis;
10 
11 
12 namespace Isis {
17  m_encoder = NULL;
18  m_buffer = NULL;
19 
20  setExtension("jp2");
21  }
22 
23 
28  delete m_encoder;
29  m_encoder = NULL;
30 
31  delete [] m_buffer;
32  m_buffer = NULL;
33  }
34 
35 
41  PixelType type = pixelType();
42  int mult = (type == Isis::UnsignedByte) ? 1 : 2;
43 
44  m_buffer = new char* [bands()];
45  for (int i = 0; i < bands(); i++)
46  m_buffer[i] = new char[samples() * mult];
47  }
48 
49 
58  void JP2Exporter::write(FileName outputName, int quality,
59  QString compression) {
60 
61  outputName = outputName.addExtension(extension());
62 
63  PixelType type = pixelType();
64  m_encoder = new JP2Encoder(
65  outputName.expanded(), samples(), lines(), bands(), type);
67 
68  ImageExporter::write(outputName, quality);
69  }
70 
71 
79  void JP2Exporter::setBuffer(int s, int b, int dn) const {
80  PixelType type = pixelType();
81  switch (type) {
82  case UnsignedByte:
83  ((unsigned char *) m_buffer[b])[s] = (unsigned char) dn;
84  break;
85  case SignedWord:
86  ((short int *) m_buffer[b])[s] = (short int) dn;
87  break;
88  case UnsignedWord:
89  ((short unsigned int *) m_buffer[b])[s] = (short unsigned int) dn;
90  break;
91  default:
93  "Invalid pixel type for data [" + toString(type) + "]",
94  _FILEINFO_);
95  }
96  }
97 
98 
104  void JP2Exporter::writeLine(int l) const {
105  PixelType type = pixelType();
106  if (type == Isis::UnsignedByte)
107  m_encoder->Write((unsigned char **) m_buffer);
108  else
109  m_encoder->Write((short int **) m_buffer);
110  }
111 
112 
120  bool JP2Exporter::canWriteFormat(QString format) {
121  return format == "jp2";
122  }
123 };
124 
QString extension() const
Gets the extension for the output image.
File name manipulation and expansion.
Definition: FileName.h:116
char ** m_buffer
Two dimensional array containing all color channels for a line.
Definition: JP2Exporter.h:71
int bands() const
Number of bands (channels) in the output image.
virtual void setBuffer(int s, int b, int dn) const
Set the DN value at the given sample and band of the line buffer.
Definition: JP2Exporter.cpp:79
JP2Encoder * m_encoder
Object responsible for writing data to the output image.
Definition: JP2Exporter.h:68
FileName addExtension(const QString &extension) const
Adds a new extension to the file name.
Definition: FileName.cpp:241
int samples() const
Number of samples (columns) in the output image.
PixelType pixelType() const
Returns the pixel type.
QString toString(bool boolToConvert)
Global function to convert a boolean to a string.
Definition: IString.cpp:226
This error is for when a programmer made an API call that was illegal.
Definition: IException.h:162
virtual void createBuffer()
Creates the buffer to store a chunk of streamed line data with one or more bands. ...
Definition: JP2Exporter.cpp:40
void setExtension(QString extension)
Sets the extension for the output image and generates the extension for the world file from it...
PixelType
Enumerations for Isis Pixel Types.
Definition: PixelType.h:43
virtual void writeLine(int l) const
Writes a line of buffered data to the output image on disk.
void OpenFile()
Open the JPEG2000 file and initialize it.
Definition: JP2Encoder.cpp:124
virtual ~JP2Exporter()
Destruct the exporter.
Definition: JP2Exporter.cpp:27
void Write(unsigned char **inbuf)
Write 8-bit data to JP2 file.
Definition: JP2Encoder.cpp:276
#define _FILEINFO_
Macro for the filename and line number.
Definition: IException.h:40
QString expanded() const
Returns a QString of the full file name including the file path, excluding the attributes.
Definition: FileName.cpp:212
int lines() const
Number of lines (rows) in the output image.
static bool canWriteFormat(QString format)
Returns true if the format is "jp2".
virtual void write(FileName outputName, int quality=100, QString compression="none")
Export the Isis cube channels to the given standard image.
Isis exception class.
Definition: IException.h:107
Namespace for ISIS/Bullet specific routines.
Definition: Apollo.h:31
Exports cubes into a standard format in incremental pieces.
virtual void write(FileName outputName, int quality=100, QString compression="none")
Initialize the encoder, open the output file for writing, then let the base ImageExporter handle the ...
Definition: JP2Exporter.cpp:58
JPEG2000 encoder class.
Definition: JP2Encoder.h:83
JP2Exporter()
Construct the JPEG 2000 exporter.
Definition: JP2Exporter.cpp:16