| 1087 | // --------------------------------------------------------------------------- |
| 1088 | |
| 1089 | std::unique_ptr<GTiffGrid> GTiffDataset::nextGrid() { |
| 1090 | if (!m_hasNextGrid) |
| 1091 | return nullptr; |
| 1092 | if (m_nextDirOffset) { |
| 1093 | TIFFSetSubDirectory(m_hTIFF, m_nextDirOffset); |
| 1094 | } |
| 1095 | |
| 1096 | uint32_t width = 0; |
| 1097 | uint32_t height = 0; |
| 1098 | TIFFGetField(m_hTIFF, TIFFTAG_IMAGEWIDTH, &width); |
| 1099 | TIFFGetField(m_hTIFF, TIFFTAG_IMAGELENGTH, &height); |
| 1100 | if (width == 0 || height == 0 || width > INT_MAX || height > INT_MAX) { |
| 1101 | pj_log(m_ctx, PJ_LOG_ERROR, _("Invalid image size")); |
| 1102 | return nullptr; |
| 1103 | } |
| 1104 | |
| 1105 | uint16_t samplesPerPixel = 0; |
| 1106 | if (!TIFFGetField(m_hTIFF, TIFFTAG_SAMPLESPERPIXEL, &samplesPerPixel)) { |
| 1107 | pj_log(m_ctx, PJ_LOG_ERROR, _("Missing SamplesPerPixel tag")); |
| 1108 | return nullptr; |
| 1109 | } |
| 1110 | if (samplesPerPixel == 0) { |
| 1111 | pj_log(m_ctx, PJ_LOG_ERROR, _("Invalid SamplesPerPixel value")); |
| 1112 | return nullptr; |
| 1113 | } |
| 1114 | |
| 1115 | uint16_t bitsPerSample = 0; |
| 1116 | if (!TIFFGetField(m_hTIFF, TIFFTAG_BITSPERSAMPLE, &bitsPerSample)) { |
| 1117 | pj_log(m_ctx, PJ_LOG_ERROR, _("Missing BitsPerSample tag")); |
| 1118 | return nullptr; |
| 1119 | } |
| 1120 | |
| 1121 | uint16_t planarConfig = 0; |
| 1122 | if (!TIFFGetField(m_hTIFF, TIFFTAG_PLANARCONFIG, &planarConfig)) { |
| 1123 | pj_log(m_ctx, PJ_LOG_ERROR, _("Missing PlanarConfig tag")); |
| 1124 | return nullptr; |
| 1125 | } |
| 1126 | |
| 1127 | uint16_t sampleFormat = 0; |
| 1128 | if (!TIFFGetField(m_hTIFF, TIFFTAG_SAMPLEFORMAT, &sampleFormat)) { |
| 1129 | pj_log(m_ctx, PJ_LOG_ERROR, _("Missing SampleFormat tag")); |
| 1130 | return nullptr; |
| 1131 | } |
| 1132 | |
| 1133 | TIFFDataType dt; |
| 1134 | if (sampleFormat == SAMPLEFORMAT_INT && bitsPerSample == 16) |
| 1135 | dt = TIFFDataType::Int16; |
| 1136 | else if (sampleFormat == SAMPLEFORMAT_UINT && bitsPerSample == 16) |
| 1137 | dt = TIFFDataType::UInt16; |
| 1138 | else if (sampleFormat == SAMPLEFORMAT_INT && bitsPerSample == 32) |
| 1139 | dt = TIFFDataType::Int32; |
| 1140 | else if (sampleFormat == SAMPLEFORMAT_UINT && bitsPerSample == 32) |
| 1141 | dt = TIFFDataType::UInt32; |
| 1142 | else if (sampleFormat == SAMPLEFORMAT_IEEEFP && bitsPerSample == 32) |
| 1143 | dt = TIFFDataType::Float32; |
| 1144 | else if (sampleFormat == SAMPLEFORMAT_IEEEFP && bitsPerSample == 64) |
| 1145 | dt = TIFFDataType::Float64; |
| 1146 | else { |
no test coverage detected