7#include "TiffExporter.h"
13#include "IException.h"
15#include "UserInterface.h"
52 int mult = (type == Isis::UnsignedByte) ? 1 : 2;
59 throw IException(IException::Unknown,
60 "Could not allocate enough memory", _FILEINFO_);
77 outputName = outputName.addExtension(
extension());
80 m_image = TIFFOpen(outputName.expanded().toLatin1().data(),
"w");
83 throw IException(IException::Programmer,
84 "Could not open output image", _FILEINFO_);
89 TIFFSetField(
m_image, TIFFTAG_ROWSPERSTRIP, 1);
90 if (compression ==
"packbits") {
91 TIFFSetField(
m_image, TIFFTAG_COMPRESSION, COMPRESSION_PACKBITS);
93 else if (compression ==
"lzw") {
94 TIFFSetField(
m_image, TIFFTAG_COMPRESSION, COMPRESSION_LZW);
96 else if (compression ==
"deflate") {
97 TIFFSetField(
m_image, TIFFTAG_COMPRESSION, COMPRESSION_ADOBE_DEFLATE);
99 else if (compression ==
"none") {
100 TIFFSetField(
m_image, TIFFTAG_COMPRESSION, COMPRESSION_NONE);
103 QString msg =
"Invalid TIFF compression algorithm: " + compression;
104 throw IException(IException::Programmer, msg, _FILEINFO_);
106 TIFFSetField(
m_image, TIFFTAG_PLANARCONFIG, PLANARCONFIG_CONTIG);
107 TIFFSetField(
m_image, TIFFTAG_PHOTOMETRIC,
108 bands() == 1 ? PHOTOMETRIC_MINISBLACK : PHOTOMETRIC_RGB);
111 int bps = (type == Isis::UnsignedByte) ? 8 : 16;
112 TIFFSetField(
m_image, TIFFTAG_BITSPERSAMPLE, bps);
113 int sampleFormat = (type == Isis::SignedWord) ? 2 : 1 ;
114 TIFFSetField(
m_image, TIFFTAG_SAMPLEFORMAT, sampleFormat);
116 TIFFSetField(
m_image, TIFFTAG_SAMPLESPERPIXEL,
bands());
132 int index = s *
bands() + b;
136 m_raster[index] = (
unsigned char) dn;
139 ((
short int *)
m_raster)[index] = (
short int) dn;
142 ((
short unsigned int *)
m_raster)[index] = (
short unsigned int) dn;
145 throw IException(IException::Programmer,
146 "Invalid pixel type for data [" +
toString(type) +
"]",
159 throw IException(IException::Programmer,
160 "Could not write image", _FILEINFO_);
173 return format ==
"tiff";
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.
StreamExporter()
Construct the stream exporter.
static bool canWriteFormat(QString format)
Returns true if the format is "tiff".
virtual void writeLine(int l) const
Writes a line of buffered data to the output image on disk.
TIFF * m_image
Object responsible for writing data to the output image.
virtual void setBuffer(int s, int b, int dn) const
Set the DN value at the given sample and band, resolved to a single index, of the line buffer.
virtual void write(FileName outputName, int quality=100, QString compression="none", UserInterface *ui=nullptr)
Open the output file for writing, initialize its fields, then let the base ImageExporter handle the g...
TiffExporter()
Construct the TIFF exporter.
unsigned char * m_raster
Array containing all color channels for a line.
virtual ~TiffExporter()
Destruct the exporter.
virtual void createBuffer()
Creates the buffer to store a chunk of streamed line data with one or more bands.
Command Line and Xml loader, validation, and access.
This is free and unencumbered software released into the public domain.
QString toString(const LinearAlgebra::Vector &vector, int precision)
A global function to format LinearAlgebra::Vector as a QString with the given precision.