5 #include <QDomDocument> 31 if ((
m_image = XTIFFOpen(inputName.
expanded().toLatin1().data(),
"r")) == NULL) {
33 QString(
"Could not open TIFF image [") + inputName.
expanded().toLatin1().data() +
"]",
_FILEINFO_);
39 TIFFGetField(
m_image, TIFFTAG_IMAGELENGTH, &height);
43 TIFFGetField(
m_image, TIFFTAG_IMAGEWIDTH, &width);
51 if ((
m_raster = (uint32 *) malloc(
sizeof(uint32) * imagesize)) == NULL) {
53 "Could not allocate enough memory",
_FILEINFO_);
65 "Image has an undefined photometric interpretation",
_FILEINFO_);
110 geocode_t rasterType;
111 geocode_t coordSysType;
113 if ((GTIFKeyGet(
m_geotiff, GTModelTypeGeoKey, &modelType, 0, 1) == 1) &&
114 ((modelType == 1) || (modelType == 2))) {
116 if ((GTIFKeyGet(
m_geotiff, GTRasterTypeGeoKey, &rasterType, 0, 1) == 1) &&
117 (rasterType == 1 || rasterType == 2)) {
122 if (GTIFKeyGet(
m_geotiff, ProjectedCSTypeGeoKey, &coordSysType, 0, 1) == 1) {
125 FileName transFile((QString)
"$base/translations/geotiff/" +
131 geoTiffCodeTranslater.
Auto(outPvl);
139 if (GTIFKeyGet(
m_geotiff, GeographicTypeGeoKey, &geoCode, 0, 1) == 1) {
140 std::cout <<
"GeographicTypeGeoKey = " << geoCode << std::endl;
143 std::cout <<
"no GeographicTypeGeoKey" << std::endl;
146 if (GTIFKeyGet(
m_geotiff, GeogAngularUnitsGeoKey, &geoCode, 0, 1) == 1) {
147 std::cout <<
"GeogAngularUnitsGeoKey = " << geoCode << std::endl;
150 std::cout <<
"no GeogAngularUnitsGeoKey" << std::endl;
153 if (GTIFKeyGet(
m_geotiff, GeogEllipsoidGeoKey, &geoCode, 0, 1) == 1) {
154 std::cout <<
"GeogEllipsoidGeoKey = " << geoCode << std::endl;
157 std::cout <<
"no GeogEllipsoidGeoKey" << std::endl;
160 if (GTIFKeyGet(
m_geotiff, GeogSemiMajorAxisGeoKey, &geoCode, 0, 1) == 1) {
161 std::cout <<
"GeogSemiMajorAxisGeoKey = " << geoCode << std::endl;
164 std::cout <<
"no GeogSemiMajorAxisGeoKey" << std::endl;
167 if (GTIFKeyGet(
m_geotiff, GeogSemiMinorAxisGeoKey, &geoCode, 0, 1) == 1) {
168 std::cout <<
"GeogSemiMinorAxisGeoKey = " << geoCode << std::endl;
171 std::cout <<
"no GeogSemiMinorAxisGeoKey" << std::endl;
174 if (GTIFKeyGet(
m_geotiff, GeogInvFlatteningGeoKey, &geoCode, 0, 1) == 1) {
175 std::cout <<
"GeogInvFlatteningGeoKey = " << geoCode << std::endl;
178 std::cout <<
"no GeogInvFlatteningGeoKey" << std::endl;
181 if (GTIFKeyGet(
m_geotiff, ProjCoordTransGeoKey, &geoCode, 0, 1) == 1) {
182 std::cout <<
"ProjCoordTransGeoKey = " << geoCode << std::endl;
185 std::cout <<
"no ProjCoordTransGeoKey" << std::endl;
188 if (GTIFKeyGet(
m_geotiff, ProjLinearUnitsGeoKey, &geoCode, 0, 1) == 1) {
189 std::cout <<
"ProjLinearUnitsGeoKey = " << geoCode << std::endl;
192 std::cout <<
"no ProjLinearUnitsGeoKey" << std::endl;
195 if (GTIFKeyGet(
m_geotiff, ProjStdParallel1GeoKey, &geoCode, 0, 1) == 1) {
196 std::cout <<
"ProjStdParallel1GeoKey = " << geoCode << std::endl;
199 std::cout <<
"no ProjStdParallel1GeoKey" << std::endl;
202 if (GTIFKeyGet(
m_geotiff, ProjStdParallel2GeoKey, &geoCode, 0, 1) == 1) {
203 std::cout <<
"ProjStdParallel2GeoKey = " << geoCode << std::endl;
206 std::cout <<
"no ProjStdParallel2GeoKey" << std::endl;
209 if (GTIFKeyGet(
m_geotiff, ProjNatOriginLongGeoKey, &geoCode, 0, 1) == 1) {
210 std::cout <<
"ProjNatOriginLongGeoKey = " << geoCode << std::endl;
213 std::cout <<
"no ProjNatOriginLongGeoKey" << std::endl;
216 if (GTIFKeyGet(
m_geotiff, ProjNatOriginLatGeoKey, &geoCode, 0, 1) == 1) {
217 std::cout <<
"ProjNatOriginLatGeoKey = " << geoCode << std::endl;
220 std::cout <<
"no ProjNatOriginLatGeoKey" << std::endl;
223 if (GTIFKeyGet(
m_geotiff, ProjFalseEastingGeoKey, &geoCode, 0, 1) == 1) {
224 std::cout <<
"ProjFalseEastingGeoKey = " << geoCode << std::endl;
227 std::cout <<
"no ProjFalseEastingGeoKey" << std::endl;
230 if (GTIFKeyGet(
m_geotiff, ProjFalseNorthingGeoKey, &geoCode, 0, 1) == 1) {
231 std::cout <<
"ProjFalseNorthingGeoKey = " << geoCode << std::endl;
234 std::cout <<
"no ProjFalseNorthingGeoKey" << std::endl;
237 if (GTIFKeyGet(
m_geotiff, ProjFalseOriginLongGeoKey, &geoCode, 0, 1) == 1) {
238 std::cout <<
"ProjFalseOriginLongGeoKey = " << geoCode << std::endl;
241 std::cout <<
"no ProjFalseOriginLongGeoKey" << std::endl;
244 if (GTIFKeyGet(
m_geotiff, ProjFalseOriginLatGeoKey, &geoCode, 0, 1) == 1) {
245 std::cout <<
"ProjFalseOriginLatGeoKey = " << geoCode << std::endl;
248 std::cout <<
"no ProjFalseOriginLatGeoKey" << std::endl;
251 if (GTIFKeyGet(
m_geotiff, ProjFalseOriginEastingGeoKey, &geoCode, 0, 1) == 1) {
252 std::cout <<
"ProjFalseOriginEastingGeoKey = " << geoCode << std::endl;
255 std::cout <<
"no ProjFalseOriginEastingGeoKey" << std::endl;
258 if (GTIFKeyGet(
m_geotiff, ProjFalseOriginNorthingGeoKey, &geoCode, 0, 1) == 1) {
259 std::cout <<
"ProjFalseOriginNorthingGeoKey = " << geoCode << std::endl;
262 std::cout <<
"no ProjFalseOriginNorthingGeoKey" << std::endl;
265 if (GTIFKeyGet(
m_geotiff, ProjCenterLongGeoKey, &geoCode, 0, 1) == 1) {
266 std::cout <<
"ProjCenterLongGeoKey = " << geoCode << std::endl;
269 std::cout <<
"no ProjCenterLongGeoKey" << std::endl;
272 if (GTIFKeyGet(
m_geotiff, ProjCenterLatGeoKey, &geoCode, 0, 1) == 1) {
273 std::cout <<
"ProjCenterLatGeoKey = " << geoCode << std::endl;
276 std::cout <<
"no ProjCenterLatGeoKey" << std::endl;
279 if (GTIFKeyGet(
m_geotiff, ProjCenterEastingGeoKey, &geoCode, 0, 1) == 1) {
280 std::cout <<
"ProjCenterEastingGeoKey = " << geoCode << std::endl;
283 std::cout <<
"no ProjCenterEastingGeoKey" << std::endl;
286 if (GTIFKeyGet(
m_geotiff, ProjCenterNorthingGeoKey, &geoCode, 0, 1) == 1) {
287 std::cout <<
"ProjCenterNorthingGeoKey = " << geoCode << std::endl;
290 std::cout <<
"no ProjCenterNorthingGeoKey" << std::endl;
293 if (GTIFKeyGet(
m_geotiff, ProjScaleAtNatOriginGeoKey, &geoCode, 0, 1) == 1) {
294 std::cout <<
"ProjScaleAtNatOriginGeoKey = " << geoCode << std::endl;
297 std::cout <<
"no ProjScaleAtNatOriginGeoKey" << std::endl;
300 if (GTIFKeyGet(
m_geotiff, ProjAzimuthAngleGeoKey, &geoCode, 0, 1) == 1) {
301 std::cout <<
"ProjAzimuthAngleGeoKey = " << geoCode << std::endl;
304 std::cout <<
"no ProjAzimuthAngleGeoKey" << std::endl;
307 if (GTIFKeyGet(
m_geotiff, ProjStraightVertPoleLongGeoKey, &geoCode, 0, 1) == 1) {
308 std::cout <<
"ProjStraightVertPoleLongGeoKey = " << geoCode << std::endl;
311 std::cout <<
"no ProjStraightVertPoleLongGeoKey" << std::endl;
314 if (GTIFKeyGet(
m_geotiff, VerticalUnitsGeoKey, &geoCode, 0, 1) == 1) {
315 std::cout <<
"VerticalUnitsGeoKey = " << geoCode << std::endl;
318 std::cout <<
"no VerticalUnitsGeoKey" << std::endl;
343 double pixelResolution = mapGroup[
"PixelResolution"];
345 double localRadius = proj->
LocalRadius(trueScaleLat);
347 double scale = (2.0 *
Isis::PI * localRadius) / (360.0 * pixelResolution);
371 char *gdalMetadataBuf;
372 short int gdalMetadataCount = 0;
374 if (TIFFGetField(
m_image, 42112, &gdalMetadataCount, &gdalMetadataBuf) == 1) {
376 QString gdalMetadataQstring(gdalMetadataBuf);
378 QDomDocument gdalDoc(
"GDALMetaData");
379 if (gdalDoc.setContent(gdalMetadataQstring)) {
380 QDomElement gdalRoot = gdalDoc.documentElement();
381 if (gdalRoot.tagName() ==
"GDALMetadata") {
383 QDomNode gdalNode = gdalRoot.firstChild();
384 while (!gdalNode.isNull()) {
385 QDomElement gdalElement = gdalNode.toElement();
386 if (!gdalElement.isNull() ) {
387 if (gdalElement.tagName() ==
"Item") {
388 if (gdalElement.attribute(
"name",
"") ==
"WEST_LONGITUDE") {
389 QString westLon = gdalElement.text();
392 else if (gdalElement.attribute(
"name",
"") ==
"EAST_LONGITUDE") {
393 QString eastLon = gdalElement.text();
396 else if (gdalElement.attribute(
"name",
"") ==
"SOUTH_LATITUDE") {
397 QString southLat = gdalElement.text();
400 else if (gdalElement.attribute(
"name",
"") ==
"NORTH_LATITUDE") {
401 QString northLat = gdalElement.text();
407 gdalNode = gdalNode.nextSibling();
429 double *tiePoints = NULL;
430 short int tieCount = 0;
431 if (TIFFGetField(
m_image, TIFFTAG_GEOTIEPOINTS, &tieCount, &tiePoints) == 1) {
435 if (tiePoints[0] == 0.0 && tiePoints[1] == 0.0) {
438 x = (double)map[
"FalseEasting"] + tiePoints[3];
444 y = (double)map[
"FalseNorthing"] + tiePoints[4];
452 QString msg =
"The upper left X and Y can not be calculated. Unsupported tiepoint " 453 "type in Tiff file (i.e., not ( 0.0, 0.0))";
475 double *scales = NULL;
476 short int scaleCount = 0;
477 if (TIFFGetField(
m_image, TIFFTAG_GEOPIXELSCALE, &scaleCount, &scales) == 1) {
481 if ((scaleCount == 3) && (scales[0] > 0.0 && scales[1] > 0.0) && (scales[0] == scales[1])) {
485 QString msg =
"The pixel resolution could not be retrieved from the TIFF file. Unsupported " 486 "PixelScale tag values.";
517 m_photo == PHOTOMETRIC_MINISWHITE ||
518 m_photo == PHOTOMETRIC_MINISBLACK;
594 return TIFFGetR(pixel);
606 return TIFFGetG(pixel);
618 return TIFFGetB(pixel);
630 return TIFFGetA(pixel);
static Isis::Projection * Create(Isis::Pvl &label, bool allowDefaults=false)
This method returns a pointer to a Projection object.
virtual ~TiffImporter()
Destruct the importer.
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...
bool hasKeyword(const QString &name) const
Check to see if a keyword exists.
PvlGroupIterator findGroup(const QString &name, PvlGroupIterator beg, PvlGroupIterator end)
Find a group with the specified name, within these indexes.
virtual PvlGroup convertProjection() const
Convert any projection information associated with the input image to an ISIS Mapping group in PVL fo...
File name manipulation and expansion.
int samples() const
The sample dimension (width) of the output image.
uint16 m_photo
The enumerated photometric interpretation of the input image.
const double PI
The mathematical constant PI.
TIFF * m_image
LibTIFF representation of the input image.
uint16 m_samplesPerPixel
The number of "samples" (bands in Isis terms) in the input image.
Base class for Map TProjections.
void setDefaultBands()
Set the number of bands to be created for the output cube based on the number of color channels in th...
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...
void addGroup(const Isis::PvlGroup &group)
Add a group to the object.
uint32 * m_raster
Buffer holding the raw TIFF image in memory.
GTIF * m_geotiff
GeoTiff hanele.
QString toString(bool boolToConvert)
Global function to convert a boolean to a string.
virtual int getAlpha(int pixel) const
Retrieves the alpha component of the given pixel.
Allows applications to translate simple text files.
This error is for when a programmer made an API call that was illegal.
Pvl upperLeftXY(const Pvl &inLab) const
Convert the Tiff Tiepoint tag data to Upper Left X & Y values for the ISIS cube label mapping group...
int lines() const
The line dimension (height) of the output image.
Pvl resolution(const Pvl &inLab) const
Convert the Tiff PixelScale tag data to a singe resolution for the ISIS cube label mapping group...
virtual bool isRgb() const
Tests to see if the input image is neither grayscale nor has more than three samples per pixel...
Pvl gdalItems(const Pvl &outPvl) const
Convert items in the GDAL tag to the ISIS mapping group.
Contains multiple PvlContainers.
#define _FILEINFO_
Macro for the filename and line number.
void setSamples(int s)
Set the sample dimension (width) of the output image.
A type of error that could only have occurred due to a mistake on the user's part (e...
A single keyword-value pair.
double LocalRadius(double lat) const
This method returns the local radius in meters at the specified latitude position.
QString expanded() const
Returns a QString of the full file name including the file path, excluding the attributes.
void setLines(int l)
Set the line dimension (height) of the output image.
TiffImporter(FileName inputName)
Construct the importer.
Container for cube-like labels.
virtual int getBlue(int pixel) const
Retrieves the blue component of the given pixel.
Defines an angle and provides unit conversions.
virtual int getRed(int pixel) const
Retrieves the red component of the given pixel.
virtual int getGreen(int pixel) const
Retrieves the green component of the given pixel.
Namespace for ISIS/Bullet specific routines.
void Auto(Pvl &outputLabel)
Automatically translate all the output names found in the translation table If a output name does not...
int samplesPerPixel() const
The number of "samples" (bands in Isis terms) per pixel in the input image.
virtual void updateRawBuffer(int line, int band) const
Does nothing as LibTIFF reads the entire input image into memory, and therefore does not need to be u...
Imports images with standard formats into Isis as cubes.
virtual bool isArgb() const
Tests to see if the input image is not grayscale and has more than three samples per pixel...
virtual bool isGrayscale() const
Tests to see if the input image has a "min is white" or "min is black" photometric interpretation...
bool fileExists() const
Returns true if the file exists; false otherwise.
virtual int getGray(int pixel) const
Retrieves the gray component of the given pixel.
virtual double TrueScaleLatitude() const
This method returns the latitude of true scale.
void deleteKeyword(const QString &name)
Remove a specified keyword.