Isis 3 Programmer Reference
JP2Exporter.cpp
1
6/* SPDX-License-Identifier: CC0-1.0 */
7#include "JP2Exporter.h"
8
9#include "Buffer.h"
10#include "FileName.h"
11#include "IException.h"
12#include "IString.h"
13#include "JP2Encoder.h"
14#include "UserInterface.h"
15
16using namespace Isis;
17
18
19namespace Isis {
24 m_encoder = NULL;
25 m_buffer = NULL;
26
27 setExtension("jp2");
28 }
29
30
35 delete m_encoder;
36 m_encoder = NULL;
37
38 delete [] m_buffer;
39 m_buffer = NULL;
40 }
41
42
48 PixelType type = pixelType();
49 int mult = (type == Isis::UnsignedByte) ? 1 : 2;
50
51 m_buffer = new char* [bands()];
52 for (int i = 0; i < bands(); i++)
53 m_buffer[i] = new char[samples() * mult];
54 }
55
56
65 void JP2Exporter::write(FileName outputName, int quality,
66 QString compression, UserInterface *ui) {
67
68 outputName = outputName.addExtension(extension());
69
70 PixelType type = pixelType();
72 outputName.expanded(), samples(), lines(), bands(), type);
74
75 ImageExporter::write(outputName, quality, compression, ui);
76 }
77
78
86 void JP2Exporter::setBuffer(int s, int b, int dn) const {
87 PixelType type = pixelType();
88 switch (type) {
89 case UnsignedByte:
90 ((unsigned char *) m_buffer[b])[s] = (unsigned char) dn;
91 break;
92 case SignedWord:
93 ((short int *) m_buffer[b])[s] = (short int) dn;
94 break;
95 case UnsignedWord:
96 ((short unsigned int *) m_buffer[b])[s] = (short unsigned int) dn;
97 break;
98 default:
100 "Invalid pixel type for data [" + toString(type) + "]",
101 _FILEINFO_);
102 }
103 }
104
105
111 void JP2Exporter::writeLine(int l) const {
112 PixelType type = pixelType();
113 if (type == Isis::UnsignedByte)
114 m_encoder->Write((unsigned char **) m_buffer);
115 else
116 m_encoder->Write((short int **) m_buffer);
117 }
118
119
127 bool JP2Exporter::canWriteFormat(QString format) {
128 return format == "jp2";
129 }
130};
131
File name manipulation and expansion.
Definition FileName.h:100
Isis exception class.
Definition IException.h:91
@ Programmer
This error is for when a programmer made an API call that was illegal.
Definition IException.h:146
int lines() const
Number of lines (rows) in the output image.
QString extension() const
Gets the extension for the output image.
int bands() const
Number of bands (channels) in the output image.
virtual void write(FileName outputName, int quality=100, QString compression="none", UserInterface *ui=nullptr)
Export the Isis cube channels to the given standard image.
int samples() const
Number of samples (columns) in the output image.
PixelType pixelType() const
Returns the pixel type.
void setExtension(QString extension)
Sets the extension for the output image and generates the extension for the world file from it.
JPEG2000 encoder class.
Definition JP2Encoder.h:67
void OpenFile()
Open the JPEG2000 file and initialize it.
void Write(unsigned char **inbuf)
Write 8-bit data to JP2 file.
static bool canWriteFormat(QString format)
Returns true if the format is "jp2".
virtual void writeLine(int l) const
Writes a line of buffered data to the output image on disk.
JP2Encoder * m_encoder
Object responsible for writing data to the output image.
Definition JP2Exporter.h:52
virtual void write(FileName outputName, int quality=100, QString compression="none", UserInterface *ui=nullptr)
Initialize the encoder, open the output file for writing, then let the base ImageExporter handle the ...
virtual ~JP2Exporter()
Destruct the exporter.
virtual void setBuffer(int s, int b, int dn) const
Set the DN value at the given sample and band of the line buffer.
JP2Exporter()
Construct the JPEG 2000 exporter.
virtual void createBuffer()
Creates the buffer to store a chunk of streamed line data with one or more bands.
char ** m_buffer
Two dimensional array containing all color channels for a line.
Definition JP2Exporter.h:55
Exports cubes into a standard format in incremental pieces.
Command Line and Xml loader, validation, and access.
This is free and unencumbered software released into the public domain.
Definition Apollo.h:16
QString toString(bool boolToConvert)
Global function to convert a boolean to a string.
Definition IString.cpp:211
PixelType
Enumerations for Isis Pixel Types.
Definition PixelType.h:27