File failed to load: https://isis.astrogeology.usgs.gov/6.0.0/Object/assets/jax/output/NativeMML/config.js
Isis 3 Programmer Reference
JP2Importer.cpp
1 
6 /* SPDX-License-Identifier: CC0-1.0 */
7 #include "JP2Importer.h"
8 
9 #include "FileName.h"
10 #include "IException.h"
11 #include "JP2Decoder.h"
12 #include "ProcessImport.h"
13 
14 using namespace Isis;
15 
16 
17 namespace Isis {
24  m_decoder = NULL;
25  m_buffer = NULL;
26 
27  try {
28  // Determine if input file is a JPEG2000 file
29  m_decoder = new JP2Decoder(inputName.expanded());
31  setSamples(m_decoder->GetSampleDimension());
32  setLines(m_decoder->GetLineDimension());
33  setBands(m_decoder->GetBandDimension());
34 
35  int pixelBytes = m_decoder->GetPixelBytes();
36  if (pixelBytes == 1) {
37  m_pixelType = Isis::UnsignedByte;
38  }
39  else if (pixelBytes == 2) {
40  bool signedData = m_decoder->GetSignedData();
41  m_pixelType = signedData ? Isis::SignedWord : Isis::UnsignedWord;
42  }
43  else {
45  "The file [" + filename().expanded() +
46  "] contains unsupported data type",
47  _FILEINFO_);
48  }
49 
50  int pixelSize = Isis::SizeOf(m_pixelType);
51  int readBytes = pixelSize * samples() * bands();
52 
53  m_buffer = new char* [bands()];
54  for (int i = 0; i < bands(); i++) m_buffer[i] = new char [readBytes];
55  }
56  catch (IException &e) {
58  "The file [" + inputName.expanded() +
59  "] cannot be opened as a JPEG 2000 file",
60  _FILEINFO_);
61  }
62  }
63 
64 
69  delete m_decoder;
70  m_decoder = NULL;
71 
72  delete [] m_buffer;
73  m_buffer = NULL;
74  }
75 
76 
83  bool JP2Importer::isGrayscale() const {
84  return m_decoder->GetBandDimension() == 1;
85  }
86 
87 
93  bool JP2Importer::isRgb() const {
94  return m_decoder->GetBandDimension() == 3;
95  }
96 
97 
103  bool JP2Importer::isArgb() const {
104  return m_decoder->GetBandDimension() == 4;
105  }
106 
107 
116  void JP2Importer::updateRawBuffer(int line, int band) const {
117  // Only read a new chunk of data when we move to a new line, since we read
118  // all the input bands for the current line at once
119  // NOTE m_buffer is changed in this method, making the const-ness a lie
120  // TODO make the buffer local to the operator() method and read all bands of
121  // a line at a time with a ProcessByBrick
122  if (band == 1) {
123  if (m_pixelType == Isis::UnsignedByte)
124  m_decoder->Read((unsigned char **) m_buffer);
125  else
126  m_decoder->Read((short int **) m_buffer);
127  }
128  }
129 
130 
144  int JP2Importer::getPixel(int s, int l) const {
145  return s;
146  }
147 
148 
158  int JP2Importer::getGray(int pixel) const {
159  return isGrayscale() ? getFromBuffer(pixel, 0) : convertRgbToGray(pixel);
160  }
161 
162 
171  int JP2Importer::getRed(int pixel) const {
172  return getFromBuffer(pixel, 0);
173  }
174 
175 
184  int JP2Importer::getGreen(int pixel) const {
185  return getFromBuffer(pixel, 1);
186  }
187 
188 
197  int JP2Importer::getBlue(int pixel) const {
198  return getFromBuffer(pixel, 2);
199  }
200 
201 
210  int JP2Importer::getAlpha(int pixel) const {
211  return getFromBuffer(pixel, 3);
212  }
213 
214 
225  int JP2Importer::getFromBuffer(int s, int b) const {
226  int value;
227 
228  switch (m_pixelType) {
229  case Isis::UnsignedByte:
230  value = (int) ((unsigned char *) m_buffer[b])[s];
231  break;
232  case Isis::UnsignedWord:
233  value = (int) ((unsigned short int *) m_buffer[b])[s];
234  break;
235  case Isis::SignedWord:
236  value = (int) ((short int *) m_buffer[b])[s];
237  break;
238  default:
240  "Unknown pixel type [" + IString(m_pixelType) + "]",
241  _FILEINFO_);
242  }
243 
244  return value;
245  }
246 };
247 
Isis::SizeOf
int SizeOf(Isis::PixelType pixelType)
Returns the number of bytes of the specified PixelType.
Definition: PixelType.h:46
Isis::JP2Importer::getGreen
virtual int getGreen(int pixel) const
Retrieves the green component of the given pixel from the second band of the input buffer.
Definition: JP2Importer.cpp:184
Isis::ImageImporter::convertRgbToGray
virtual int convertRgbToGray(int pixel) const
Convert the current pixel, taken from an RGB/A image, and blend its RGB components into a single gray...
Definition: ImageImporter.cpp:399
Isis::ImageImporter::setSamples
void setSamples(int s)
Set the sample dimension (width) of the output image.
Definition: ImageImporter.cpp:241
Isis::JP2Decoder::OpenFile
void OpenFile()
Open the JPEG2000 file.
Definition: JP2Decoder.cpp:52
Isis::JP2Importer::isArgb
virtual bool isArgb() const
Tests to see if the input image is quadruple-banded, implying RGBA.
Definition: JP2Importer.cpp:103
Isis::FileName
File name manipulation and expansion.
Definition: FileName.h:100
Isis::JP2Decoder::Read
void Read(unsigned char **inbuf)
Read data from JP2 file containing 8-bit data.
Definition: JP2Decoder.cpp:168
Isis::JP2Importer::getAlpha
virtual int getAlpha(int pixel) const
Retrieves the alpha component of the given pixel from the fourth band of the input buffer.
Definition: JP2Importer.cpp:210
Isis::JP2Importer::m_buffer
char ** m_buffer
Buffer that stores a line of JPEG 2000 data and all its color bands.
Definition: JP2Importer.h:56
Isis::ImageImporter
Imports images with standard formats into Isis as cubes.
Definition: ImageImporter.h:39
Isis::JP2Importer::JP2Importer
JP2Importer(FileName inputName)
Construct the importer.
Definition: JP2Importer.cpp:23
Isis::JP2Importer::getRed
virtual int getRed(int pixel) const
Retrieves the red component of the given pixel from the first band of the input buffer.
Definition: JP2Importer.cpp:171
Isis::ImageImporter::bands
int bands() const
The band dimension (depth) of the output image.
Definition: ImageImporter.cpp:298
Isis::FileName::expanded
QString expanded() const
Returns a QString of the full file name including the file path, excluding the attributes.
Definition: FileName.cpp:196
Isis::ImageImporter::samples
int samples() const
The sample dimension (width) of the output image.
Definition: ImageImporter.cpp:278
Isis::JP2Importer::m_decoder
JP2Decoder * m_decoder
Takes a raw stream of JPEG 2000 data and reads it into a buffer.
Definition: JP2Importer.h:53
Isis::JP2Importer::getPixel
virtual int getPixel(int s, int l) const
Returns a representation of a pixel for the input format that can then be broken down into specific g...
Definition: JP2Importer.cpp:144
Isis::ImageImporter::setBands
void setBands(int b)
Set the band dimension (depth) of the output image.
Definition: ImageImporter.cpp:263
Isis::JP2Importer::getGray
virtual int getGray(int pixel) const
Retrieves the gray component of the given pixel.
Definition: JP2Importer.cpp:158
Isis::IException
Isis exception class.
Definition: IException.h:91
Isis::ImageImporter::setLines
void setLines(int l)
Set the line dimension (height) of the output image.
Definition: ImageImporter.cpp:251
Isis::JP2Importer::getBlue
virtual int getBlue(int pixel) const
Retrieves the blue component of the given pixel from the third band of the input buffer.
Definition: JP2Importer.cpp:197
Isis::JP2Decoder
JPEG2000 decoder class.
Definition: JP2Decoder.h:83
Isis::IException::Programmer
@ Programmer
This error is for when a programmer made an API call that was illegal.
Definition: IException.h:146
Isis::JP2Importer::m_pixelType
Isis::PixelType m_pixelType
Pixel type of the input image needed for reading data into the buffer.
Definition: JP2Importer.h:59
Isis::ImageImporter::filename
FileName filename() const
The filename of the input image this instance was constructed with.
Definition: ImageImporter.cpp:308
Isis::JP2Importer::~JP2Importer
virtual ~JP2Importer()
Destruct the importer.
Definition: JP2Importer.cpp:68
Isis::JP2Importer::updateRawBuffer
virtual void updateRawBuffer(int line, int band) const
Updates the buffer used to store chunks of the input data at a time.
Definition: JP2Importer.cpp:116
Isis::IString
Adds specific functionality to C++ strings.
Definition: IString.h:165
Isis::JP2Importer::isGrayscale
virtual bool isGrayscale() const
Tests to see if the input image is single-banded, implying grayscale (no RGB/A).
Definition: JP2Importer.cpp:83
Isis::JP2Importer::getFromBuffer
int getFromBuffer(int s, int b) const
Retrieves the pixel value from the input buffer corresponding to the given sample and band (the buffe...
Definition: JP2Importer.cpp:225
Isis::JP2Importer::isRgb
virtual bool isRgb() const
Tests to see if the input image is triple-banded, implying RGB (no alpha).
Definition: JP2Importer.cpp:93
Isis
This is free and unencumbered software released into the public domain.
Definition: Apollo.h:16
Isis::IException::User
@ User
A type of error that could only have occurred due to a mistake on the user's part (e....
Definition: IException.h:126

U.S. Department of the Interior | U.S. Geological Survey
ISIS | Privacy & Disclaimers | Astrogeology Research Program
To contact us, please post comments and questions on the USGS Astrogeology Discussion Board
To report a bug, or suggest a feature go to: ISIS Github
File Modified: 07/13/2023 15:16:44