| 1 | /****************************************************************************** |
| 2 | * |
| 3 | * Project: GRC/GRD Reader |
| 4 | * Purpose: Northwood Format basic implementation |
| 5 | * Author: Perry Casson |
| 6 | * |
| 7 | ****************************************************************************** |
| 8 | * Copyright (c) 2007, Waypoint Information Technology |
| 9 | * Copyright (c) 2009-2011, Even Rouault <even dot rouault at spatialys.com> |
| 10 | * |
| 11 | * SPDX-License-Identifier: MIT |
| 12 | ****************************************************************************/ |
| 13 | |
| 14 | #include "gdal_pam.h"cxx . . $ `<file>/gcore/gdal_pam.h`/ |
| 15 | |
| 16 | #include "northwood.h"cxx . . $ `<file>/frmts/northwood/northwood.h`/ |
| 17 | |
| 18 | #include <algorithm> |
| 19 | #include <cassert> |
| 20 | #include <limits> |
| 21 | #include <string> |
| 22 | |
| 23 | int nwt_ParseHeadercxx . . $ nwt_ParseHeader(96f01bc82aa1c573).(NWT_GRIDcxx . . $ NWT_GRID# *pGrd, const unsigned char *nwtHeader) |
| 24 | { |
| 25 | /* double dfTmp; */ |
| 26 | |
| 27 | if (nwtHeader[4] == '1') |
| 28 | pGrd->cFormatcxx . . $ $anonymous_type_37fb98c99edfb69d_7#cFormat. = 0x00; // grd - surface type |
| 29 | else if (nwtHeader[4] == '8') |
| 30 | pGrd->cFormatcxx . . $ $anonymous_type_37fb98c99edfb69d_7#cFormat. = 0x80; // grc classified type |
| 31 | |
| 32 | pGrd->stClassDictcxx . . $ $anonymous_type_37fb98c99edfb69d_7#stClassDict. = nullptr; |
| 33 | |
| 34 | memcpy(&pGrd->fVersioncxx . . $ $anonymous_type_37fb98c99edfb69d_7#fVersion., &nwtHeader[5], sizeof(pGrd->fVersioncxx . . $ $anonymous_type_37fb98c99edfb69d_7#fVersion.)); |
| 35 | CPL_LSBPTR32cxx . . $ `port/cpl_port.h:761:9`!(&pGrd->fVersion); |
| 36 | |
| 37 | unsigned short usTmp; |
| 38 | memcpy(&usTmp, &nwtHeader[9], 2); |
| 39 | CPL_LSBPTR16cxx . . $ `port/cpl_port.h:754:9`!(&usTmp); |
| 40 | pGrd->nXSidecxx . . $ $anonymous_type_37fb98c99edfb69d_7#nXSide. = static_cast<unsigned int>(usTmp); |
| 41 | if (pGrd->nXSidecxx . . $ $anonymous_type_37fb98c99edfb69d_7#nXSide. == 0) |
| 42 | { |
| 43 | memcpy(&pGrd->nXSidecxx . . $ $anonymous_type_37fb98c99edfb69d_7#nXSide., &nwtHeader[128], sizeof(pGrd->nXSidecxx . . $ $anonymous_type_37fb98c99edfb69d_7#nXSide.)); |
| 44 | CPL_LSBPTR32cxx . . $ `port/cpl_port.h:761:9`!(&pGrd->nXSide); |
| 45 | } |
| 46 | if (pGrd->nXSidecxx . . $ $anonymous_type_37fb98c99edfb69d_7#nXSide. <= 1) |
| 47 | return FALSEcxx . . $ `port/cpl_port.h:1180:9`!; |
| 48 | |
| 49 | memcpy(&usTmp, &nwtHeader[11], 2); |
| 50 | CPL_LSBPTR16cxx . . $ `port/cpl_port.h:754:9`!(&usTmp); |
| 51 | pGrd->nYSidecxx . . $ $anonymous_type_37fb98c99edfb69d_7#nYSide. = static_cast<unsigned int>(usTmp); |
| 52 | if (pGrd->nYSidecxx . . $ $anonymous_type_37fb98c99edfb69d_7#nYSide. == 0) |
| 53 | { |
| 54 | memcpy(&pGrd->nYSidecxx . . $ $anonymous_type_37fb98c99edfb69d_7#nYSide., &nwtHeader[132], sizeof(pGrd->nYSidecxx . . $ $anonymous_type_37fb98c99edfb69d_7#nYSide.)); |
| 55 | CPL_LSBPTR32cxx . . $ `port/cpl_port.h:761:9`!(&pGrd->nYSide); |
| 56 | } |
| 57 | |
| 58 | memcpy(&pGrd->dfMinXcxx . . $ $anonymous_type_37fb98c99edfb69d_7#dfMinX., &nwtHeader[13], sizeof(pGrd->dfMinXcxx . . $ $anonymous_type_37fb98c99edfb69d_7#dfMinX.)); |
| 59 | CPL_LSBPTR64cxx . . $ `port/cpl_port.h:768:9`!(&pGrd->dfMinX); |
| 60 | memcpy(&pGrd->dfMaxXcxx . . $ $anonymous_type_37fb98c99edfb69d_7#dfMaxX., &nwtHeader[21], sizeof(pGrd->dfMaxXcxx . . $ $anonymous_type_37fb98c99edfb69d_7#dfMaxX.)); |
| 61 | CPL_LSBPTR64cxx . . $ `port/cpl_port.h:768:9`!(&pGrd->dfMaxX); |
| 62 | memcpy(&pGrd->dfMinYcxx . . $ $anonymous_type_37fb98c99edfb69d_7#dfMinY., &nwtHeader[29], sizeof(pGrd->dfMinYcxx . . $ $anonymous_type_37fb98c99edfb69d_7#dfMinY.)); |
| 63 | CPL_LSBPTR64cxx . . $ `port/cpl_port.h:768:9`!(&pGrd->dfMinY); |
| 64 | memcpy(&pGrd->dfMaxYcxx . . $ $anonymous_type_37fb98c99edfb69d_7#dfMaxY., &nwtHeader[37], sizeof(pGrd->dfMaxYcxx . . $ $anonymous_type_37fb98c99edfb69d_7#dfMaxY.)); |
| 65 | CPL_LSBPTR64cxx . . $ `port/cpl_port.h:768:9`!(&pGrd->dfMaxY); |
| 66 | |
| 67 | assertcxx . . $ `<external>/4398592474888995393/assert.h:137:11`!(pGrd->nXSide > 1); |
| 68 | pGrd->dfStepSizecxx . . $ $anonymous_type_37fb98c99edfb69d_7#dfStepSize. = (pGrd->dfMaxXcxx . . $ $anonymous_type_37fb98c99edfb69d_7#dfMaxX. - pGrd->dfMinXcxx . . $ $anonymous_type_37fb98c99edfb69d_7#dfMinX.) / (pGrd->nXSidecxx . . $ $anonymous_type_37fb98c99edfb69d_7#nXSide. - 1); |
| 69 | /* dfTmp = (pGrd->dfMaxY - pGrd->dfMinY) / (pGrd->nYSide - 1); */ |
| 70 | |
| 71 | memcpy(&pGrd->fZMincxx . . $ $anonymous_type_37fb98c99edfb69d_7#fZMin., &nwtHeader[45], sizeof(pGrd->fZMincxx . . $ $anonymous_type_37fb98c99edfb69d_7#fZMin.)); |
| 72 | CPL_LSBPTR32cxx . . $ `port/cpl_port.h:761:9`!(&pGrd->fZMin); |
| 73 | memcpy(&pGrd->fZMaxcxx . . $ $anonymous_type_37fb98c99edfb69d_7#fZMax., &nwtHeader[49], sizeof(pGrd->fZMaxcxx . . $ $anonymous_type_37fb98c99edfb69d_7#fZMax.)); |
| 74 | CPL_LSBPTR32cxx . . $ `port/cpl_port.h:761:9`!(&pGrd->fZMax); |
| 75 | memcpy(&pGrd->fZMinScalecxx . . $ $anonymous_type_37fb98c99edfb69d_7#fZMinScale., &nwtHeader[53], sizeof(pGrd->fZMinScalecxx . . $ $anonymous_type_37fb98c99edfb69d_7#fZMinScale.)); |
| 76 | CPL_LSBPTR32cxx . . $ `port/cpl_port.h:761:9`!(&pGrd->fZMinScale); |
| 77 | memcpy(&pGrd->fZMaxScalecxx . . $ $anonymous_type_37fb98c99edfb69d_7#fZMaxScale., &nwtHeader[57], sizeof(pGrd->fZMaxScalecxx . . $ $anonymous_type_37fb98c99edfb69d_7#fZMaxScale.)); |
| 78 | CPL_LSBPTR32cxx . . $ `port/cpl_port.h:761:9`!(&pGrd->fZMaxScale); |
| 79 | |
| 80 | memcpy(&pGrd->cDescriptioncxx . . $ $anonymous_type_37fb98c99edfb69d_7#cDescription., &nwtHeader[61], sizeof(pGrd->cDescriptioncxx . . $ $anonymous_type_37fb98c99edfb69d_7#cDescription.)); |
| 81 | memcpy(&pGrd->cZUnitscxx . . $ $anonymous_type_37fb98c99edfb69d_7#cZUnits., &nwtHeader[93], sizeof(pGrd->cZUnitscxx . . $ $anonymous_type_37fb98c99edfb69d_7#cZUnits.)); |
| 82 | |
| 83 | int i; |
| 84 | memcpy(&i, &nwtHeader[136], 4); |
| 85 | CPL_LSBPTR32cxx . . $ `port/cpl_port.h:761:9`!(&i); |
| 86 | |
| 87 | if (i == 1129336130) |
| 88 | { // BMPC |
| 89 | if (nwtHeader[140] & 0x01) |
| 90 | { |
| 91 | pGrd->cHillShadeBrightnesscxx . . $ $anonymous_type_37fb98c99edfb69d_7#cHillShadeBrightness. = nwtHeader[144]; |
| 92 | pGrd->cHillShadeContrastcxx . . $ $anonymous_type_37fb98c99edfb69d_7#cHillShadeContrast. = nwtHeader[145]; |
| 93 | } |
| 94 | } |
| 95 | |
| 96 | memcpy(&pGrd->cMICoordSyscxx . . $ $anonymous_type_37fb98c99edfb69d_7#cMICoordSys., &nwtHeader[256], sizeof(pGrd->cMICoordSyscxx . . $ $anonymous_type_37fb98c99edfb69d_7#cMICoordSys.)); |
| 97 | pGrd->cMICoordSyscxx . . $ $anonymous_type_37fb98c99edfb69d_7#cMICoordSys.[sizeof(pGrd->cMICoordSyscxx . . $ $anonymous_type_37fb98c99edfb69d_7#cMICoordSys.) - 1] = '\0'; |
| 98 | |
| 99 | pGrd->iZUnitscxx . . $ $anonymous_type_37fb98c99edfb69d_7#iZUnits. = nwtHeader[512]; |
| 100 | |
| 101 | if (nwtHeader[513] & 0x80) |
| 102 | pGrd->bShowGradientcxx . . $ $anonymous_type_37fb98c99edfb69d_7#bShowGradient. = true; |
| 103 | |
| 104 | if (nwtHeader[513] & 0x40) |
| 105 | pGrd->bShowHillShadecxx . . $ $anonymous_type_37fb98c99edfb69d_7#bShowHillShade. = true; |
| 106 | |
| 107 | if (nwtHeader[513] & 0x20) |
| 108 | pGrd->bHillShadeExistscxx . . $ $anonymous_type_37fb98c99edfb69d_7#bHillShadeExists. = true; |
| 109 | |
| 110 | memcpy(&pGrd->iNumColorInflectionscxx . . $ $anonymous_type_37fb98c99edfb69d_7#iNumColorInflections., &nwtHeader[516], 2); |
| 111 | CPL_LSBPTR16cxx . . $ `port/cpl_port.h:754:9`!(&pGrd->iNumColorInflections); |
| 112 | |
| 113 | if (pGrd->iNumColorInflectionscxx . . $ $anonymous_type_37fb98c99edfb69d_7#iNumColorInflections. > 32) |
| 114 | { |
| 115 | CPLError(CE_Failure, CPLE_AppDefinedcxx . . $ `port/cpl_error.h:108:9`!, "Corrupt header"); |
| 116 | pGrd->iNumColorInflectionscxx . . $ $anonymous_type_37fb98c99edfb69d_7#iNumColorInflections. = 0; |
| 117 | return FALSEcxx . . $ `port/cpl_port.h:1180:9`!; |
| 118 | } |
| 119 | |
| 120 | for (i = 0; i < pGrd->iNumColorInflectionscxx . . $ $anonymous_type_37fb98c99edfb69d_7#iNumColorInflections.; i++) |
| 121 | { |
| 122 | memcpy(&pGrd->stInflectioncxx . . $ $anonymous_type_37fb98c99edfb69d_7#stInflection.[i].zValcxx . . $ $anonymous_type_37fb98c99edfb69d_3#zVal., &nwtHeader[518 + (7 * i)], 4); |
| 123 | CPL_LSBPTR32cxx . . $ `port/cpl_port.h:761:9`!(&pGrd->stInflection[i].zVal); |
| 124 | memcpy(&pGrd->stInflectioncxx . . $ $anonymous_type_37fb98c99edfb69d_7#stInflection.[i].rcxx . . $ $anonymous_type_37fb98c99edfb69d_3#r., &nwtHeader[522 + (7 * i)], 1); |
| 125 | memcpy(&pGrd->stInflectioncxx . . $ $anonymous_type_37fb98c99edfb69d_7#stInflection.[i].gcxx . . $ $anonymous_type_37fb98c99edfb69d_3#g., &nwtHeader[523 + (7 * i)], 1); |
| 126 | memcpy(&pGrd->stInflectioncxx . . $ $anonymous_type_37fb98c99edfb69d_7#stInflection.[i].bcxx . . $ $anonymous_type_37fb98c99edfb69d_3#b., &nwtHeader[524 + (7 * i)], 1); |
| 127 | } |
| 128 | |
| 129 | memcpy(&pGrd->fHillShadeAzimuthcxx . . $ $anonymous_type_37fb98c99edfb69d_7#fHillShadeAzimuth., &nwtHeader[966], |
| 130 | sizeof(pGrd->fHillShadeAzimuthcxx . . $ $anonymous_type_37fb98c99edfb69d_7#fHillShadeAzimuth.)); |
| 131 | CPL_LSBPTR32cxx . . $ `port/cpl_port.h:761:9`!(&pGrd->fHillShadeAzimuth); |
| 132 | memcpy(&pGrd->fHillShadeAnglecxx . . $ $anonymous_type_37fb98c99edfb69d_7#fHillShadeAngle., &nwtHeader[970], |
| 133 | sizeof(pGrd->fHillShadeAnglecxx . . $ $anonymous_type_37fb98c99edfb69d_7#fHillShadeAngle.)); |
| 134 | CPL_LSBPTR32cxx . . $ `port/cpl_port.h:761:9`!(&pGrd->fHillShadeAngle); |
| 135 | |
| 136 | pGrd->cFormatcxx . . $ $anonymous_type_37fb98c99edfb69d_7#cFormat. += nwtHeader[1023]; // the msb for grd/grc was already set |
| 137 | |
| 138 | // there are more types than this - need to build other types for testing |
| 139 | if (pGrd->cFormatcxx . . $ $anonymous_type_37fb98c99edfb69d_7#cFormat. & 0x80) |
| 140 | { |
| 141 | if (nwtHeader[1023] == 0) |
| 142 | pGrd->nBitsPerPixelcxx . . $ $anonymous_type_37fb98c99edfb69d_7#nBitsPerPixel. = 16; |
| 143 | else |
| 144 | pGrd->nBitsPerPixelcxx . . $ $anonymous_type_37fb98c99edfb69d_7#nBitsPerPixel. = nwtHeader[1023] * 4; |
| 145 | } |
| 146 | else |
| 147 | pGrd->nBitsPerPixelcxx . . $ $anonymous_type_37fb98c99edfb69d_7#nBitsPerPixel. = nwtHeader[1023] * 8; |
| 148 | |
| 149 | if (pGrd->cFormatcxx . . $ $anonymous_type_37fb98c99edfb69d_7#cFormat. & 0x80) // if is GRC load the Dictionary |
| 150 | { |
| 151 | vsi_l_offset nPixels = |
| 152 | static_cast<vsi_l_offset>(pGrd->nXSidecxx . . $ $anonymous_type_37fb98c99edfb69d_7#nXSide.) * pGrd->nYSidecxx . . $ $anonymous_type_37fb98c99edfb69d_7#nYSide.; |
| 153 | unsigned int nBytesPerPixel = pGrd->nBitsPerPixelcxx . . $ $anonymous_type_37fb98c99edfb69d_7#nBitsPerPixel. / 8; |
| 154 | if (nPixels > 0 && |
| 155 | (nBytesPerPixel > |
| 156 | stdcxx . . $ std/::numeric_limits<vsi_l_offset>::max() / nPixels || |
| 157 | nPixels * nBytesPerPixel > |
| 158 | stdcxx . . $ std/::numeric_limits<vsi_l_offset>::max() - 1024)) |
| 159 | { |
| 160 | CPLError(CE_Failure, CPLE_FileIOcxx . . $ `port/cpl_error.h:112:9`!, |
| 161 | "Invalid file dimension / bits per pixel"); |
| 162 | return FALSEcxx . . $ `port/cpl_port.h:1180:9`!; |
| 163 | } |
| 164 | VSIFSeekL(pGrd->fpcxx . . $ $anonymous_type_37fb98c99edfb69d_7#fp., 1024 + nPixels * nBytesPerPixel, SEEK_SETcxx . . $ `<external>/232824719582829767/stdio.h:114:9`!); |
| 165 | |
| 166 | if (!VSIFReadL(&usTmp, 2, 1, pGrd->fpcxx . . $ $anonymous_type_37fb98c99edfb69d_7#fp.)) |
| 167 | { |
| 168 | CPLError(CE_Failure, CPLE_FileIOcxx . . $ `port/cpl_error.h:112:9`!, "Read failure, file short?"); |
| 169 | return FALSEcxx . . $ `port/cpl_port.h:1180:9`!; |
| 170 | } |
| 171 | CPL_LSBPTR16cxx . . $ `port/cpl_port.h:754:9`!(&usTmp); |
| 172 | pGrd->stClassDictcxx . . $ $anonymous_type_37fb98c99edfb69d_7#stClassDict. = reinterpret_cast<NWT_CLASSIFIED_DICTcxx . . $ NWT_CLASSIFIED_DICT# *>( |
| 173 | calloccxx . . $ calloc(95acc9b79bb49189).(1, sizeof(NWT_CLASSIFIED_DICTcxx . . $ NWT_CLASSIFIED_DICT#))); |
| 174 | if (!pGrd->stClassDictcxx . . $ $anonymous_type_37fb98c99edfb69d_7#stClassDict.) |
| 175 | { |
| 176 | return FALSEcxx . . $ `port/cpl_port.h:1180:9`!; |
| 177 | } |
| 178 | |
| 179 | pGrd->stClassDictcxx . . $ $anonymous_type_37fb98c99edfb69d_7#stClassDict.->nNumClassifiedItemscxx . . $ $anonymous_type_37fb98c99edfb69d_5#nNumClassifiedItems. = usTmp; |
| 180 | |
| 181 | pGrd->stClassDictcxx . . $ $anonymous_type_37fb98c99edfb69d_7#stClassDict.->stClassifiedItemcxx . . $ $anonymous_type_37fb98c99edfb69d_5#stClassifiedItem. = |
| 182 | reinterpret_cast<NWT_CLASSIFIED_ITEMcxx . . $ NWT_CLASSIFIED_ITEM# **>( |
| 183 | calloccxx . . $ calloc(95acc9b79bb49189).(pGrd->stClassDictcxx . . $ $anonymous_type_37fb98c99edfb69d_7#stClassDict.->nNumClassifiedItemscxx . . $ $anonymous_type_37fb98c99edfb69d_5#nNumClassifiedItems. + 1, |
| 184 | sizeof(NWT_CLASSIFIED_ITEMcxx . . $ NWT_CLASSIFIED_ITEM# *))); |
| 185 | if (!pGrd->stClassDictcxx . . $ $anonymous_type_37fb98c99edfb69d_7#stClassDict.->stClassifiedItemcxx . . $ $anonymous_type_37fb98c99edfb69d_5#stClassifiedItem.) |
| 186 | { |
| 187 | pGrd->stClassDictcxx . . $ $anonymous_type_37fb98c99edfb69d_7#stClassDict.->nNumClassifiedItemscxx . . $ $anonymous_type_37fb98c99edfb69d_5#nNumClassifiedItems. = 0; |
| 188 | return FALSEcxx . . $ `port/cpl_port.h:1180:9`!; |
| 189 | } |
| 190 | |
| 191 | // load the dictionary |
| 192 | for (unsigned int iItem = 0; |
| 193 | iItem < pGrd->stClassDictcxx . . $ $anonymous_type_37fb98c99edfb69d_7#stClassDict.->nNumClassifiedItemscxx . . $ $anonymous_type_37fb98c99edfb69d_5#nNumClassifiedItems.; iItem++) |
| 194 | { |
| 195 | NWT_CLASSIFIED_ITEMcxx . . $ NWT_CLASSIFIED_ITEM# *psItem = |
| 196 | pGrd->stClassDictcxx . . $ $anonymous_type_37fb98c99edfb69d_7#stClassDict.->stClassifiedItemcxx . . $ $anonymous_type_37fb98c99edfb69d_5#stClassifiedItem.[iItem] = |
| 197 | reinterpret_cast<NWT_CLASSIFIED_ITEMcxx . . $ NWT_CLASSIFIED_ITEM# *>( |
| 198 | calloccxx . . $ calloc(95acc9b79bb49189).(1, sizeof(NWT_CLASSIFIED_ITEMcxx . . $ NWT_CLASSIFIED_ITEM#))); |
| 199 | if (!psItem) |
| 200 | { |
| 201 | return FALSEcxx . . $ `port/cpl_port.h:1180:9`!; |
| 202 | } |
| 203 | |
| 204 | unsigned char cTmp[256]; |
| 205 | if (!VSIFReadL(&cTmp, 9, 1, pGrd->fpcxx . . $ $anonymous_type_37fb98c99edfb69d_7#fp.)) |
| 206 | { |
| 207 | CPLError(CE_Failure, CPLE_FileIOcxx . . $ `port/cpl_error.h:112:9`!, "Read failure, file short?"); |
| 208 | return FALSEcxx . . $ `port/cpl_port.h:1180:9`!; |
| 209 | } |
| 210 | memcpy(&psItem->usPixValcxx . . $ $anonymous_type_37fb98c99edfb69d_4#usPixVal., &cTmp[0], 2); |
| 211 | CPL_LSBPTR16cxx . . $ `port/cpl_port.h:754:9`!(&psItem->usPixVal); |
| 212 | memcpy(&psItem->res1cxx . . $ $anonymous_type_37fb98c99edfb69d_4#res1., &cTmp[2], 1); |
| 213 | memcpy(&psItem->rcxx . . $ $anonymous_type_37fb98c99edfb69d_4#r., &cTmp[3], 1); |
| 214 | memcpy(&psItem->gcxx . . $ $anonymous_type_37fb98c99edfb69d_4#g., &cTmp[4], 1); |
| 215 | memcpy(&psItem->bcxx . . $ $anonymous_type_37fb98c99edfb69d_4#b., &cTmp[5], 1); |
| 216 | memcpy(&psItem->res2cxx . . $ $anonymous_type_37fb98c99edfb69d_4#res2., &cTmp[6], 1); |
| 217 | memcpy(&psItem->usLencxx . . $ $anonymous_type_37fb98c99edfb69d_4#usLen., &cTmp[7], 2); |
| 218 | CPL_LSBPTR16cxx . . $ `port/cpl_port.h:754:9`!(&psItem->usLen); |
| 219 | |
| 220 | if (psItem->usLencxx . . $ $anonymous_type_37fb98c99edfb69d_4#usLen. > sizeof(psItem->szClassNamecxx . . $ $anonymous_type_37fb98c99edfb69d_4#szClassName.) - 1) |
| 221 | { |
| 222 | CPLError(CE_Failure, CPLE_AppDefinedcxx . . $ `port/cpl_error.h:108:9`!, |
| 223 | "Unexpected long class name, %d characters long - " |
| 224 | "unable to read file.", |
| 225 | psItem->usLencxx . . $ $anonymous_type_37fb98c99edfb69d_4#usLen.); |
| 226 | return FALSEcxx . . $ `port/cpl_port.h:1180:9`!; |
| 227 | } |
| 228 | |
| 229 | // 0-len class names are possible |
| 230 | psItem->szClassNamecxx . . $ $anonymous_type_37fb98c99edfb69d_4#szClassName.[0] = '\0'; |
| 231 | if (psItem->usLencxx . . $ $anonymous_type_37fb98c99edfb69d_4#usLen. > 0 && |
| 232 | !VSIFReadL(&psItem->szClassNamecxx . . $ $anonymous_type_37fb98c99edfb69d_4#szClassName., psItem->usLencxx . . $ $anonymous_type_37fb98c99edfb69d_4#usLen., 1, pGrd->fpcxx . . $ $anonymous_type_37fb98c99edfb69d_7#fp.)) |
| 233 | return FALSEcxx . . $ `port/cpl_port.h:1180:9`!; |
| 234 | } |
| 235 | } |
| 236 | |
| 237 | return TRUEcxx . . $ `port/cpl_port.h:1184:9`!; |
| 238 | } |
| 239 | |
| 240 | // Create a color gradient ranging from ZMin to Zmax using the color |
| 241 | // inflections defined in grid |
| 242 | int nwt_LoadColorscxx . . $ nwt_LoadColors(ee1b946f365b181c).(NWT_RGBcxx . . $ NWT_RGB# *pMap, int mapSize, NWT_GRIDcxx . . $ NWT_GRID# *pGrd) |
| 243 | { |
| 244 | int i; |
| 245 | NWT_RGBcxx . . $ NWT_RGB# sColor; |
| 246 | int nWarkerMark = 0; |
| 247 | |
| 248 | createIPcxx . . $ createIP(3dd3bd1cc37c8594).(0, 255, 255, 255, pMap, &nWarkerMark); |
| 249 | if (pGrd->iNumColorInflectionscxx . . $ $anonymous_type_37fb98c99edfb69d_7#iNumColorInflections. == 0) |
| 250 | return 0; |
| 251 | |
| 252 | // If Zmin is less than the 1st inflection use the 1st inflections color to |
| 253 | // the start of the ramp |
| 254 | if (pGrd->fZMincxx . . $ $anonymous_type_37fb98c99edfb69d_7#fZMin. <= pGrd->stInflectioncxx . . $ $anonymous_type_37fb98c99edfb69d_7#stInflection.[0].zValcxx . . $ $anonymous_type_37fb98c99edfb69d_3#zVal.) |
| 255 | { |
| 256 | createIPcxx . . $ createIP(3dd3bd1cc37c8594).(1, pGrd->stInflectioncxx . . $ $anonymous_type_37fb98c99edfb69d_7#stInflection.[0].rcxx . . $ $anonymous_type_37fb98c99edfb69d_3#r., pGrd->stInflectioncxx . . $ $anonymous_type_37fb98c99edfb69d_7#stInflection.[0].gcxx . . $ $anonymous_type_37fb98c99edfb69d_3#g., |
| 257 | pGrd->stInflectioncxx . . $ $anonymous_type_37fb98c99edfb69d_7#stInflection.[0].bcxx . . $ $anonymous_type_37fb98c99edfb69d_3#b., pMap, &nWarkerMark); |
| 258 | } |
| 259 | // find what inflections zmin is between |
| 260 | for (i = 1; i < pGrd->iNumColorInflectionscxx . . $ $anonymous_type_37fb98c99edfb69d_7#iNumColorInflections.; i++) |
| 261 | { |
| 262 | if (pGrd->fZMincxx . . $ $anonymous_type_37fb98c99edfb69d_7#fZMin. < pGrd->stInflectioncxx . . $ $anonymous_type_37fb98c99edfb69d_7#stInflection.[i].zValcxx . . $ $anonymous_type_37fb98c99edfb69d_3#zVal.) |
| 263 | { |
| 264 | // then we must be between i and i-1 |
| 265 | linearColorcxx . . $ linearColor(d0e5c0aa73dbcbcd).(&sColor, &pGrd->stInflectioncxx . . $ $anonymous_type_37fb98c99edfb69d_7#stInflection.[i - 1], |
| 266 | &pGrd->stInflectioncxx . . $ $anonymous_type_37fb98c99edfb69d_7#stInflection.[i], pGrd->fZMincxx . . $ $anonymous_type_37fb98c99edfb69d_7#fZMin.); |
| 267 | createIPcxx . . $ createIP(3dd3bd1cc37c8594).(1, sColor.rcxx . . $ $anonymous_type_37fb98c99edfb69d_1#r., sColor.gcxx . . $ $anonymous_type_37fb98c99edfb69d_1#g., sColor.bcxx . . $ $anonymous_type_37fb98c99edfb69d_1#b., pMap, &nWarkerMark); |
| 268 | break; |
| 269 | } |
| 270 | } |
| 271 | // the interesting case of zmin beig higher than the max inflection value |
| 272 | if (i >= pGrd->iNumColorInflectionscxx . . $ $anonymous_type_37fb98c99edfb69d_7#iNumColorInflections.) |
| 273 | { |
| 274 | createIPcxx . . $ createIP(3dd3bd1cc37c8594).(1, pGrd->stInflectioncxx . . $ $anonymous_type_37fb98c99edfb69d_7#stInflection.[pGrd->iNumColorInflectionscxx . . $ $anonymous_type_37fb98c99edfb69d_7#iNumColorInflections. - 1].rcxx . . $ $anonymous_type_37fb98c99edfb69d_3#r., |
| 275 | pGrd->stInflectioncxx . . $ $anonymous_type_37fb98c99edfb69d_7#stInflection.[pGrd->iNumColorInflectionscxx . . $ $anonymous_type_37fb98c99edfb69d_7#iNumColorInflections. - 1].gcxx . . $ $anonymous_type_37fb98c99edfb69d_3#g., |
| 276 | pGrd->stInflectioncxx . . $ $anonymous_type_37fb98c99edfb69d_7#stInflection.[pGrd->iNumColorInflectionscxx . . $ $anonymous_type_37fb98c99edfb69d_7#iNumColorInflections. - 1].bcxx . . $ $anonymous_type_37fb98c99edfb69d_3#b., pMap, |
| 277 | &nWarkerMark); |
| 278 | createIPcxx . . $ createIP(3dd3bd1cc37c8594).(mapSize - 1, |
| 279 | pGrd->stInflectioncxx . . $ $anonymous_type_37fb98c99edfb69d_7#stInflection.[pGrd->iNumColorInflectionscxx . . $ $anonymous_type_37fb98c99edfb69d_7#iNumColorInflections. - 1].rcxx . . $ $anonymous_type_37fb98c99edfb69d_3#r., |
| 280 | pGrd->stInflectioncxx . . $ $anonymous_type_37fb98c99edfb69d_7#stInflection.[pGrd->iNumColorInflectionscxx . . $ $anonymous_type_37fb98c99edfb69d_7#iNumColorInflections. - 1].gcxx . . $ $anonymous_type_37fb98c99edfb69d_3#g., |
| 281 | pGrd->stInflectioncxx . . $ $anonymous_type_37fb98c99edfb69d_7#stInflection.[pGrd->iNumColorInflectionscxx . . $ $anonymous_type_37fb98c99edfb69d_7#iNumColorInflections. - 1].bcxx . . $ $anonymous_type_37fb98c99edfb69d_3#b., pMap, |
| 282 | &nWarkerMark); |
| 283 | } |
| 284 | else |
| 285 | { |
| 286 | int index = 0; |
| 287 | for (; i < pGrd->iNumColorInflectionscxx . . $ $anonymous_type_37fb98c99edfb69d_7#iNumColorInflections.; i++) |
| 288 | { |
| 289 | if (pGrd->fZMaxcxx . . $ $anonymous_type_37fb98c99edfb69d_7#fZMax. < pGrd->stInflectioncxx . . $ $anonymous_type_37fb98c99edfb69d_7#stInflection.[i].zValcxx . . $ $anonymous_type_37fb98c99edfb69d_3#zVal.) |
| 290 | { |
| 291 | // then we must be between i and i-1 |
| 292 | linearColorcxx . . $ linearColor(d0e5c0aa73dbcbcd).(&sColor, &pGrd->stInflectioncxx . . $ $anonymous_type_37fb98c99edfb69d_7#stInflection.[i - 1], |
| 293 | &pGrd->stInflectioncxx . . $ $anonymous_type_37fb98c99edfb69d_7#stInflection.[i], pGrd->fZMaxcxx . . $ $anonymous_type_37fb98c99edfb69d_7#fZMax.); |
| 294 | index = mapSize - 1; |
| 295 | createIPcxx . . $ createIP(3dd3bd1cc37c8594).(index, sColor.rcxx . . $ $anonymous_type_37fb98c99edfb69d_1#r., sColor.gcxx . . $ $anonymous_type_37fb98c99edfb69d_1#g., sColor.bcxx . . $ $anonymous_type_37fb98c99edfb69d_1#b., pMap, |
| 296 | &nWarkerMark); |
| 297 | break; |
| 298 | } |
| 299 | // save the inflections between zmin and zmax |
| 300 | index = |
| 301 | static_cast<int>(((pGrd->stInflectioncxx . . $ $anonymous_type_37fb98c99edfb69d_7#stInflection.[i].zValcxx . . $ $anonymous_type_37fb98c99edfb69d_3#zVal. - pGrd->fZMincxx . . $ $anonymous_type_37fb98c99edfb69d_7#fZMin.) / |
| 302 | (pGrd->fZMaxcxx . . $ $anonymous_type_37fb98c99edfb69d_7#fZMax. - pGrd->fZMincxx . . $ $anonymous_type_37fb98c99edfb69d_7#fZMin.)) * |
| 303 | mapSize); |
| 304 | |
| 305 | if (index >= mapSize) |
| 306 | index = mapSize - 1; |
| 307 | createIPcxx . . $ createIP(3dd3bd1cc37c8594).(index, pGrd->stInflectioncxx . . $ $anonymous_type_37fb98c99edfb69d_7#stInflection.[i].rcxx . . $ $anonymous_type_37fb98c99edfb69d_3#r., pGrd->stInflectioncxx . . $ $anonymous_type_37fb98c99edfb69d_7#stInflection.[i].gcxx . . $ $anonymous_type_37fb98c99edfb69d_3#g., |
| 308 | pGrd->stInflectioncxx . . $ $anonymous_type_37fb98c99edfb69d_7#stInflection.[i].bcxx . . $ $anonymous_type_37fb98c99edfb69d_3#b., pMap, &nWarkerMark); |
| 309 | } |
| 310 | if (index < mapSize - 1) |
| 311 | createIPcxx . . $ createIP(3dd3bd1cc37c8594).(mapSize - 1, |
| 312 | pGrd->stInflectioncxx . . $ $anonymous_type_37fb98c99edfb69d_7#stInflection.[pGrd->iNumColorInflectionscxx . . $ $anonymous_type_37fb98c99edfb69d_7#iNumColorInflections. - 1].rcxx . . $ $anonymous_type_37fb98c99edfb69d_3#r., |
| 313 | pGrd->stInflectioncxx . . $ $anonymous_type_37fb98c99edfb69d_7#stInflection.[pGrd->iNumColorInflectionscxx . . $ $anonymous_type_37fb98c99edfb69d_7#iNumColorInflections. - 1].gcxx . . $ $anonymous_type_37fb98c99edfb69d_3#g., |
| 314 | pGrd->stInflectioncxx . . $ $anonymous_type_37fb98c99edfb69d_7#stInflection.[pGrd->iNumColorInflectionscxx . . $ $anonymous_type_37fb98c99edfb69d_7#iNumColorInflections. - 1].bcxx . . $ $anonymous_type_37fb98c99edfb69d_3#b., pMap, |
| 315 | &nWarkerMark); |
| 316 | } |
| 317 | return 0; |
| 318 | } |
| 319 | |
| 320 | // solve for a color between pIPLow and pIPHigh |
| 321 | void linearColorcxx . . $ linearColor(d0e5c0aa73dbcbcd).(NWT_RGBcxx . . $ NWT_RGB# *pRGB, NWT_INFLECTIONcxx . . $ NWT_INFLECTION# *pIPLow, NWT_INFLECTIONcxx . . $ NWT_INFLECTION# *pIPHigh, |
| 322 | float fMid) |
| 323 | { |
| 324 | if (fMid < pIPLow->zValcxx . . $ $anonymous_type_37fb98c99edfb69d_3#zVal.) |
| 325 | { |
| 326 | pRGB->rcxx . . $ $anonymous_type_37fb98c99edfb69d_1#r. = pIPLow->rcxx . . $ $anonymous_type_37fb98c99edfb69d_3#r.; |
| 327 | pRGB->gcxx . . $ $anonymous_type_37fb98c99edfb69d_1#g. = pIPLow->gcxx . . $ $anonymous_type_37fb98c99edfb69d_3#g.; |
| 328 | pRGB->bcxx . . $ $anonymous_type_37fb98c99edfb69d_1#b. = pIPLow->bcxx . . $ $anonymous_type_37fb98c99edfb69d_3#b.; |
| 329 | } |
| 330 | else if (fMid > pIPHigh->zValcxx . . $ $anonymous_type_37fb98c99edfb69d_3#zVal.) |
| 331 | { |
| 332 | pRGB->rcxx . . $ $anonymous_type_37fb98c99edfb69d_1#r. = pIPHigh->rcxx . . $ $anonymous_type_37fb98c99edfb69d_3#r.; |
| 333 | pRGB->gcxx . . $ $anonymous_type_37fb98c99edfb69d_1#g. = pIPHigh->gcxx . . $ $anonymous_type_37fb98c99edfb69d_3#g.; |
| 334 | pRGB->bcxx . . $ $anonymous_type_37fb98c99edfb69d_1#b. = pIPHigh->bcxx . . $ $anonymous_type_37fb98c99edfb69d_3#b.; |
| 335 | } |
| 336 | else |
| 337 | { |
| 338 | float scale = (fMid - pIPLow->zValcxx . . $ $anonymous_type_37fb98c99edfb69d_3#zVal.) / (pIPHigh->zValcxx . . $ $anonymous_type_37fb98c99edfb69d_3#zVal. - pIPLow->zValcxx . . $ $anonymous_type_37fb98c99edfb69d_3#zVal.); |
| 339 | pRGB->rcxx . . $ $anonymous_type_37fb98c99edfb69d_1#r. = static_cast<unsigned char>(scale * (pIPHigh->rcxx . . $ $anonymous_type_37fb98c99edfb69d_3#r. - pIPLow->rcxx . . $ $anonymous_type_37fb98c99edfb69d_3#r.) + |
| 340 | pIPLow->rcxx . . $ $anonymous_type_37fb98c99edfb69d_3#r. + 0.5); |
| 341 | pRGB->gcxx . . $ $anonymous_type_37fb98c99edfb69d_1#g. = static_cast<unsigned char>(scale * (pIPHigh->gcxx . . $ $anonymous_type_37fb98c99edfb69d_3#g. - pIPLow->gcxx . . $ $anonymous_type_37fb98c99edfb69d_3#g.) + |
| 342 | pIPLow->gcxx . . $ $anonymous_type_37fb98c99edfb69d_3#g. + 0.5); |
| 343 | pRGB->bcxx . . $ $anonymous_type_37fb98c99edfb69d_1#b. = static_cast<unsigned char>(scale * (pIPHigh->bcxx . . $ $anonymous_type_37fb98c99edfb69d_3#b. - pIPLow->bcxx . . $ $anonymous_type_37fb98c99edfb69d_3#b.) + |
| 344 | pIPLow->bcxx . . $ $anonymous_type_37fb98c99edfb69d_3#b. + 0.5); |
| 345 | } |
| 346 | } |
| 347 | |
| 348 | // insert IP's into the map filling as we go |
| 349 | void createIPcxx . . $ createIP(3dd3bd1cc37c8594).(int index, unsigned char r, unsigned char g, unsigned char b, |
| 350 | NWT_RGBcxx . . $ NWT_RGB# *map, int *pnWarkerMark) |
| 351 | { |
| 352 | int i; |
| 353 | |
| 354 | if (index == 0) |
| 355 | { |
| 356 | map[0].rcxx . . $ $anonymous_type_37fb98c99edfb69d_1#r. = r; |
| 357 | map[0].gcxx . . $ $anonymous_type_37fb98c99edfb69d_1#g. = g; |
| 358 | map[0].bcxx . . $ $anonymous_type_37fb98c99edfb69d_1#b. = b; |
| 359 | *pnWarkerMark = 0; |
| 360 | return; |
| 361 | } |
| 362 | |
| 363 | if (index <= *pnWarkerMark) |
| 364 | return; |
| 365 | |
| 366 | int wm = *pnWarkerMark; |
| 367 | |
| 368 | float rslope = |
| 369 | static_cast<float>(r - map[wm].rcxx . . $ $anonymous_type_37fb98c99edfb69d_1#r.) / static_cast<float>(index - wm); |
| 370 | float gslope = |
| 371 | static_cast<float>(g - map[wm].gcxx . . $ $anonymous_type_37fb98c99edfb69d_1#g.) / static_cast<float>(index - wm); |
| 372 | float bslope = |
| 373 | static_cast<float>(b - map[wm].bcxx . . $ $anonymous_type_37fb98c99edfb69d_1#b.) / static_cast<float>(index - wm); |
| 374 | for (i = wm + 1; i < index; i++) |
| 375 | { |
| 376 | map[i].rcxx . . $ $anonymous_type_37fb98c99edfb69d_1#r. = |
| 377 | static_cast<unsigned char>(map[wm].rcxx . . $ $anonymous_type_37fb98c99edfb69d_1#r. + ((i - wm) * rslope) + 0.5); |
| 378 | map[i].gcxx . . $ $anonymous_type_37fb98c99edfb69d_1#g. = |
| 379 | static_cast<unsigned char>(map[wm].gcxx . . $ $anonymous_type_37fb98c99edfb69d_1#g. + ((i - wm) * gslope) + 0.5); |
| 380 | map[i].bcxx . . $ $anonymous_type_37fb98c99edfb69d_1#b. = |
| 381 | static_cast<unsigned char>(map[wm].bcxx . . $ $anonymous_type_37fb98c99edfb69d_1#b. + ((i - wm) * bslope) + 0.5); |
| 382 | } |
| 383 | map[index].rcxx . . $ $anonymous_type_37fb98c99edfb69d_1#r. = r; |
| 384 | map[index].gcxx . . $ $anonymous_type_37fb98c99edfb69d_1#g. = g; |
| 385 | map[index].bcxx . . $ $anonymous_type_37fb98c99edfb69d_1#b. = b; |
| 386 | *pnWarkerMark = index; |
| 387 | return; |
| 388 | } |
| 389 | |
| 390 | void nwt_HillShadecxx . . $ nwt_HillShade(12cd247497002909).(unsigned char *r, unsigned char *g, unsigned char *b, |
| 391 | unsigned char *h) |
| 392 | { |
| 393 | HLScxx . . $ HLS# hls; |
| 394 | NWT_RGBcxx . . $ NWT_RGB# rgb; |
| 395 | rgb.rcxx . . $ $anonymous_type_37fb98c99edfb69d_1#r. = *r; |
| 396 | rgb.gcxx . . $ $anonymous_type_37fb98c99edfb69d_1#g. = *g; |
| 397 | rgb.bcxx . . $ $anonymous_type_37fb98c99edfb69d_1#b. = *b; |
| 398 | hls =cxx . . $ $anonymous_type_37fb98c99edfb69d_2#`operator=`(c1f7d4d0c553af4c). RGBtoHLScxx . . $ RGBtoHLS(994f12391a4ebe75).(rgb); |
| 399 | hls.lcxx . . $ $anonymous_type_37fb98c99edfb69d_2#l. = static_cast<short>(hls.lcxx . . $ $anonymous_type_37fb98c99edfb69d_2#l. + (*h) * HLSMAXcxx . . $ `frmts/northwood/northwood.h:140:9`! / 256); |
| 400 | rgb =cxx . . $ $anonymous_type_37fb98c99edfb69d_1#`operator=`(7b2f9507f9c3d5cd). HLStoRGBcxx . . $ HLStoRGB(6b86351e82852edb).(hls); |
| 401 | |
| 402 | *r = rgb.rcxx . . $ $anonymous_type_37fb98c99edfb69d_1#r.; |
| 403 | *g = rgb.gcxx . . $ $anonymous_type_37fb98c99edfb69d_1#g.; |
| 404 | *b = rgb.bcxx . . $ $anonymous_type_37fb98c99edfb69d_1#b.; |
| 405 | return; |
| 406 | } |
| 407 | |
| 408 | NWT_GRIDcxx . . $ NWT_GRID# *nwtOpenGridcxx . . $ nwtOpenGrid(60ad827dfb207a18).(char *filename) |
| 409 | { |
| 410 | unsigned char nwtHeader[1024]; |
| 411 | VSILFILE *fp = VSIFOpenL(filename, "rb"); |
| 412 | |
| 413 | if (fp == nullptr) |
| 414 | { |
| 415 | CPLError(CE_Failure, CPLE_OpenFailedcxx . . $ `port/cpl_error.h:114:9`!, "Can't open %s", filename); |
| 416 | return nullptr; |
| 417 | } |
| 418 | |
| 419 | if (!VSIFReadL(nwtHeader, 1024, 1, fp)) |
| 420 | { |
| 421 | VSIFCloseL(fp); |
| 422 | return nullptr; |
| 423 | } |
| 424 | |
| 425 | if (nwtHeader[0] != 'H' || nwtHeader[1] != 'G' || nwtHeader[2] != 'P' || |
| 426 | nwtHeader[3] != 'C') |
| 427 | { |
| 428 | VSIFCloseL(fp); |
| 429 | return nullptr; |
| 430 | } |
| 431 | |
| 432 | NWT_GRIDcxx . . $ NWT_GRID# *pGrd = static_cast<NWT_GRIDcxx . . $ NWT_GRID# *>(calloccxx . . $ calloc(95acc9b79bb49189).(1, sizeof(NWT_GRIDcxx . . $ NWT_GRID#))); |
| 433 | if (!pGrd) |
| 434 | { |
| 435 | VSIFCloseL(fp); |
| 436 | return nullptr; |
| 437 | } |
| 438 | |
| 439 | if (nwtHeader[4] == '1') |
| 440 | pGrd->cFormatcxx . . $ $anonymous_type_37fb98c99edfb69d_7#cFormat. = 0x00; // grd - surface type |
| 441 | else if (nwtHeader[4] == '8') |
| 442 | pGrd->cFormatcxx . . $ $anonymous_type_37fb98c99edfb69d_7#cFormat. = 0x80; // grc classified type |
| 443 | else |
| 444 | { |
| 445 | CPLError(CE_Failure, CPLE_NotSupportedcxx . . $ `port/cpl_error.h:118:9`!, |
| 446 | "Unhandled Northwood format type = %0xd", nwtHeader[4]); |
| 447 | VSIFCloseL(fp); |
| 448 | freecxx . . $ free(bd21765a0afc8e3c).(pGrd); |
| 449 | return nullptr; |
| 450 | } |
| 451 | |
| 452 | strncpy(pGrd->szFileNamecxx . . $ $anonymous_type_37fb98c99edfb69d_7#szFileName., filename, sizeof(pGrd->szFileNamecxx . . $ $anonymous_type_37fb98c99edfb69d_7#szFileName.)); |
| 453 | pGrd->szFileNamecxx . . $ $anonymous_type_37fb98c99edfb69d_7#szFileName.[sizeof(pGrd->szFileNamecxx . . $ $anonymous_type_37fb98c99edfb69d_7#szFileName.) - 1] = '\0'; |
| 454 | pGrd->fpcxx . . $ $anonymous_type_37fb98c99edfb69d_7#fp. = fp; |
| 455 | nwt_ParseHeadercxx . . $ nwt_ParseHeader(96f01bc82aa1c573).(pGrd, nwtHeader); |
| 456 | |
| 457 | return pGrd; |
| 458 | } |
| 459 | |
| 460 | // close the file and free the mem |
| 461 | void nwtCloseGridcxx . . $ nwtCloseGrid(14a30ce7a9685423).(NWT_GRIDcxx . . $ NWT_GRID# *pGrd) |
| 462 | { |
| 463 | if ((pGrd->cFormatcxx . . $ $anonymous_type_37fb98c99edfb69d_7#cFormat. & 0x80) && |
| 464 | pGrd->stClassDictcxx . . $ $anonymous_type_37fb98c99edfb69d_7#stClassDict.) // if is GRC - free the Dictionary |
| 465 | { |
| 466 | for (unsigned int i = 0; i < pGrd->stClassDictcxx . . $ $anonymous_type_37fb98c99edfb69d_7#stClassDict.->nNumClassifiedItemscxx . . $ $anonymous_type_37fb98c99edfb69d_5#nNumClassifiedItems.; |
| 467 | i++) |
| 468 | { |
| 469 | freecxx . . $ free(bd21765a0afc8e3c).(pGrd->stClassDictcxx . . $ $anonymous_type_37fb98c99edfb69d_7#stClassDict.->stClassifiedItemcxx . . $ $anonymous_type_37fb98c99edfb69d_5#stClassifiedItem.[i]); |
| 470 | } |
| 471 | freecxx . . $ free(bd21765a0afc8e3c).(pGrd->stClassDictcxx . . $ $anonymous_type_37fb98c99edfb69d_7#stClassDict.->stClassifiedItemcxx . . $ $anonymous_type_37fb98c99edfb69d_5#stClassifiedItem.); |
| 472 | freecxx . . $ free(bd21765a0afc8e3c).(pGrd->stClassDictcxx . . $ $anonymous_type_37fb98c99edfb69d_7#stClassDict.); |
| 473 | } |
| 474 | if (pGrd->fpcxx . . $ $anonymous_type_37fb98c99edfb69d_7#fp.) |
| 475 | VSIFCloseL(pGrd->fpcxx . . $ $anonymous_type_37fb98c99edfb69d_7#fp.); |
| 476 | freecxx . . $ free(bd21765a0afc8e3c).(pGrd); |
| 477 | return; |
| 478 | } |
| 479 | |
| 480 | void nwtPrintGridHeadercxx . . $ nwtPrintGridHeader(14a30ce7a9685423).(NWT_GRIDcxx . . $ NWT_GRID# *pGrd) |
| 481 | { |
| 482 | if (pGrd->cFormatcxx . . $ $anonymous_type_37fb98c99edfb69d_7#cFormat. & 0x80) |
| 483 | { |
| 484 | printf("\n%s\n\nGrid type is Classified ", pGrd->szFileNamecxx . . $ $anonymous_type_37fb98c99edfb69d_7#szFileName.); /*ok*/ |
| 485 | if (pGrd->cFormatcxx . . $ $anonymous_type_37fb98c99edfb69d_7#cFormat. == 0x81) |
| 486 | printf("4 bit (Less than 16 Classes)"); /*ok*/ |
| 487 | else if (pGrd->cFormatcxx . . $ $anonymous_type_37fb98c99edfb69d_7#cFormat. == 0x82) |
| 488 | printf("8 bit (Less than 256 Classes)"); /*ok*/ |
| 489 | else if (pGrd->cFormatcxx . . $ $anonymous_type_37fb98c99edfb69d_7#cFormat. == 0x84) |
| 490 | printf("16 bit (Less than 65536 Classes)"); /*ok*/ |
| 491 | else |
| 492 | { |
| 493 | printf("GRC - Unhandled Format or Type %d", pGrd->cFormatcxx . . $ $anonymous_type_37fb98c99edfb69d_7#cFormat.); /*ok*/ |
| 494 | return; |
| 495 | } |
| 496 | } |
| 497 | else |
| 498 | { |
| 499 | printf("\n%s\n\nGrid type is Numeric ", pGrd->szFileNamecxx . . $ $anonymous_type_37fb98c99edfb69d_7#szFileName.); /*ok*/ |
| 500 | if (pGrd->cFormatcxx . . $ $anonymous_type_37fb98c99edfb69d_7#cFormat. == 0x00) |
| 501 | printf("16 bit (Standard Precision)"); /*ok*/ |
| 502 | else if (pGrd->cFormatcxx . . $ $anonymous_type_37fb98c99edfb69d_7#cFormat. == 0x01) |
| 503 | printf("32 bit (High Precision)"); /*ok*/ |
| 504 | else |
| 505 | { |
| 506 | printf("GRD - Unhandled Format or Type %d", pGrd->cFormatcxx . . $ $anonymous_type_37fb98c99edfb69d_7#cFormat.); /*ok*/ |
| 507 | return; |
| 508 | } |
| 509 | } |
| 510 | printf("\nDim (x,y) = (%u,%u)", pGrd->nXSidecxx . . $ $anonymous_type_37fb98c99edfb69d_7#nXSide., pGrd->nYSidecxx . . $ $anonymous_type_37fb98c99edfb69d_7#nYSide.); /*ok*/ |
| 511 | printf("\nStep Size = %f", pGrd->dfStepSizecxx . . $ $anonymous_type_37fb98c99edfb69d_7#dfStepSize.); /*ok*/ |
| 512 | printf("\nBounds = (%f,%f) (%f,%f)", pGrd->dfMinXcxx . . $ $anonymous_type_37fb98c99edfb69d_7#dfMinX., pGrd->dfMinYcxx . . $ $anonymous_type_37fb98c99edfb69d_7#dfMinY., /*ok*/ |
| 513 | pGrd->dfMaxXcxx . . $ $anonymous_type_37fb98c99edfb69d_7#dfMaxX., pGrd->dfMaxYcxx . . $ $anonymous_type_37fb98c99edfb69d_7#dfMaxY.); |
| 514 | printf("\nCoordinate System = %s", pGrd->cMICoordSyscxx . . $ $anonymous_type_37fb98c99edfb69d_7#cMICoordSys.); /*ok*/ |
| 515 | |
| 516 | if (!(pGrd->cFormatcxx . . $ $anonymous_type_37fb98c99edfb69d_7#cFormat. & 0x80)) // print the numeric specific stuff |
| 517 | { |
| 518 | printf("\nMin Z = %f Max Z = %f Z Units = %d \"%s\"", /*ok*/ |
| 519 | pGrd->fZMincxx . . $ $anonymous_type_37fb98c99edfb69d_7#fZMin., pGrd->fZMaxcxx . . $ $anonymous_type_37fb98c99edfb69d_7#fZMax., pGrd->iZUnitscxx . . $ $anonymous_type_37fb98c99edfb69d_7#iZUnits., pGrd->cZUnitscxx . . $ $anonymous_type_37fb98c99edfb69d_7#cZUnits.); |
| 520 | |
| 521 | printf("\n\nDisplay Mode ="); /*ok*/ |
| 522 | if (pGrd->bShowGradientcxx . . $ $anonymous_type_37fb98c99edfb69d_7#bShowGradient.) |
| 523 | printf(" Color Gradient"); /*ok*/ |
| 524 | |
| 525 | if (pGrd->bShowGradientcxx . . $ $anonymous_type_37fb98c99edfb69d_7#bShowGradient. && pGrd->bShowHillShadecxx . . $ $anonymous_type_37fb98c99edfb69d_7#bShowHillShade.) |
| 526 | printf(" and"); /*ok*/ |
| 527 | |
| 528 | if (pGrd->bShowHillShadecxx . . $ $anonymous_type_37fb98c99edfb69d_7#bShowHillShade.) |
| 529 | printf(" Hill Shading"); /*ok*/ |
| 530 | |
| 531 | for (int i = 0; i < pGrd->iNumColorInflectionscxx . . $ $anonymous_type_37fb98c99edfb69d_7#iNumColorInflections.; i++) |
| 532 | { |
| 533 | printf("\nColor Inflection %d - %f (%d,%d,%d)", i + 1, /*ok*/ |
| 534 | pGrd->stInflectioncxx . . $ $anonymous_type_37fb98c99edfb69d_7#stInflection.[i].zValcxx . . $ $anonymous_type_37fb98c99edfb69d_3#zVal., pGrd->stInflectioncxx . . $ $anonymous_type_37fb98c99edfb69d_7#stInflection.[i].rcxx . . $ $anonymous_type_37fb98c99edfb69d_3#r., |
| 535 | pGrd->stInflectioncxx . . $ $anonymous_type_37fb98c99edfb69d_7#stInflection.[i].gcxx . . $ $anonymous_type_37fb98c99edfb69d_3#g., pGrd->stInflectioncxx . . $ $anonymous_type_37fb98c99edfb69d_7#stInflection.[i].bcxx . . $ $anonymous_type_37fb98c99edfb69d_3#b.); |
| 536 | } |
| 537 | |
| 538 | if (pGrd->bHillShadeExistscxx . . $ $anonymous_type_37fb98c99edfb69d_7#bHillShadeExists.) |
| 539 | { |
| 540 | printf("\n\nHill Shade Azumith = %.1f Inclination = %.1f " /*ok*/ |
| 541 | "Brightness = %d Contrast = %d", |
| 542 | pGrd->fHillShadeAzimuthcxx . . $ $anonymous_type_37fb98c99edfb69d_7#fHillShadeAzimuth., pGrd->fHillShadeAnglecxx . . $ $anonymous_type_37fb98c99edfb69d_7#fHillShadeAngle., |
| 543 | pGrd->cHillShadeBrightnesscxx . . $ $anonymous_type_37fb98c99edfb69d_7#cHillShadeBrightness., pGrd->cHillShadeContrastcxx . . $ $anonymous_type_37fb98c99edfb69d_7#cHillShadeContrast.); |
| 544 | } |
| 545 | else |
| 546 | printf("\n\nNo Hill Shade Data"); /*ok*/ |
| 547 | } |
| 548 | else // print the classified specific stuff |
| 549 | { |
| 550 | printf("\nNumber of Classes defined = %u", /*ok*/ |
| 551 | pGrd->stClassDictcxx . . $ $anonymous_type_37fb98c99edfb69d_7#stClassDict.->nNumClassifiedItemscxx . . $ $anonymous_type_37fb98c99edfb69d_5#nNumClassifiedItems.); |
| 552 | for (int i = 0; |
| 553 | i < static_cast<int>(pGrd->stClassDictcxx . . $ $anonymous_type_37fb98c99edfb69d_7#stClassDict.->nNumClassifiedItemscxx . . $ $anonymous_type_37fb98c99edfb69d_5#nNumClassifiedItems.); i++) |
| 554 | { |
| 555 | printf("\n%s - (%d,%d,%d) Raw = %d %d %d", /*ok*/ |
| 556 | pGrd->stClassDictcxx . . $ $anonymous_type_37fb98c99edfb69d_7#stClassDict.->stClassifiedItemcxx . . $ $anonymous_type_37fb98c99edfb69d_5#stClassifiedItem.[i]->szClassNamecxx . . $ $anonymous_type_37fb98c99edfb69d_4#szClassName., |
| 557 | pGrd->stClassDictcxx . . $ $anonymous_type_37fb98c99edfb69d_7#stClassDict.->stClassifiedItemcxx . . $ $anonymous_type_37fb98c99edfb69d_5#stClassifiedItem.[i]->rcxx . . $ $anonymous_type_37fb98c99edfb69d_4#r., |
| 558 | pGrd->stClassDictcxx . . $ $anonymous_type_37fb98c99edfb69d_7#stClassDict.->stClassifiedItemcxx . . $ $anonymous_type_37fb98c99edfb69d_5#stClassifiedItem.[i]->gcxx . . $ $anonymous_type_37fb98c99edfb69d_4#g., |
| 559 | pGrd->stClassDictcxx . . $ $anonymous_type_37fb98c99edfb69d_7#stClassDict.->stClassifiedItemcxx . . $ $anonymous_type_37fb98c99edfb69d_5#stClassifiedItem.[i]->bcxx . . $ $anonymous_type_37fb98c99edfb69d_4#b., |
| 560 | pGrd->stClassDictcxx . . $ $anonymous_type_37fb98c99edfb69d_7#stClassDict.->stClassifiedItemcxx . . $ $anonymous_type_37fb98c99edfb69d_5#stClassifiedItem.[i]->usPixValcxx . . $ $anonymous_type_37fb98c99edfb69d_4#usPixVal., |
| 561 | pGrd->stClassDictcxx . . $ $anonymous_type_37fb98c99edfb69d_7#stClassDict.->stClassifiedItemcxx . . $ $anonymous_type_37fb98c99edfb69d_5#stClassifiedItem.[i]->res1cxx . . $ $anonymous_type_37fb98c99edfb69d_4#res1., |
| 562 | pGrd->stClassDictcxx . . $ $anonymous_type_37fb98c99edfb69d_7#stClassDict.->stClassifiedItemcxx . . $ $anonymous_type_37fb98c99edfb69d_5#stClassifiedItem.[i]->res2cxx . . $ $anonymous_type_37fb98c99edfb69d_4#res2.); |
| 563 | } |
| 564 | } |
| 565 | } |
| 566 | |
| 567 | HLScxx . . $ HLS# RGBtoHLScxx . . $ RGBtoHLS(994f12391a4ebe75).(NWT_RGBcxx . . $ NWT_RGB# rgb) |
| 568 | { |
| 569 | /* get R, G, and B out of DWORD */ |
| 570 | short R = rgb.rcxx . . $ $anonymous_type_37fb98c99edfb69d_1#r.; |
| 571 | short G = rgb.gcxx . . $ $anonymous_type_37fb98c99edfb69d_1#g.; |
| 572 | short B = rgb.bcxx . . $ $anonymous_type_37fb98c99edfb69d_1#b.; |
| 573 | |
| 574 | /* calculate lightness */ |
| 575 | unsigned char cMax = |
| 576 | static_cast<unsigned char>(stdcxx . . $ std/::maxcxx . . $ std/max(2a338fce5842aa6a).(stdcxx . . $ std/::maxcxx . . $ std/max(2a338fce5842aa6a).(R, G), B)); |
| 577 | unsigned char cMin = |
| 578 | static_cast<unsigned char>(stdcxx . . $ std/::mincxx . . $ std/min(2a338fce5842aa6a).(stdcxx . . $ std/::mincxx . . $ std/min(2a338fce5842aa6a).(R, G), B)); |
| 579 | HLScxx . . $ HLS# hls; |
| 580 | hls.lcxx . . $ $anonymous_type_37fb98c99edfb69d_2#l. = (((cMax + cMin) * HLSMAXcxx . . $ `frmts/northwood/northwood.h:140:9`!) + RGBMAXcxx . . $ `frmts/northwood/northwood.h:141:9`!) / (2 * RGBMAXcxx . . $ `frmts/northwood/northwood.h:141:9`!); |
| 581 | |
| 582 | short Rdelta, Gdelta, Bdelta; /* intermediate value: % of spread from max */ |
| 583 | if (cMax == cMin) |
| 584 | { /* r=g=b --> achromatic case */ |
| 585 | hls.scxx . . $ $anonymous_type_37fb98c99edfb69d_2#s. = 0; /* saturation */ |
| 586 | hls.hcxx . . $ $anonymous_type_37fb98c99edfb69d_2#h. = UNDEFINEDcxx . . $ `frmts/northwood/northwood.h:148:9`!; /* hue */ |
| 587 | } |
| 588 | else |
| 589 | { /* chromatic case */ |
| 590 | /* saturation */ |
| 591 | if (hls.lcxx . . $ $anonymous_type_37fb98c99edfb69d_2#l. <= (HLSMAXcxx . . $ `frmts/northwood/northwood.h:140:9`! / 2)) |
| 592 | hls.scxx . . $ $anonymous_type_37fb98c99edfb69d_2#s. = (((cMax - cMin) * HLSMAXcxx . . $ `frmts/northwood/northwood.h:140:9`!) + ((cMax + cMin) / 2)) / |
| 593 | (cMax + cMin); |
| 594 | else |
| 595 | hls.scxx . . $ $anonymous_type_37fb98c99edfb69d_2#s. = |
| 596 | (((cMax - cMin) * HLSMAXcxx . . $ `frmts/northwood/northwood.h:140:9`!) + ((2 * RGBMAXcxx . . $ `frmts/northwood/northwood.h:141:9`! - cMax - cMin) / 2)) / |
| 597 | (2 * RGBMAXcxx . . $ `frmts/northwood/northwood.h:141:9`! - cMax - cMin); |
| 598 | |
| 599 | /* hue */ |
| 600 | Rdelta = |
| 601 | (((cMax - R) * (HLSMAXcxx . . $ `frmts/northwood/northwood.h:140:9`! / 6)) + ((cMax - cMin) / 2)) / (cMax - cMin); |
| 602 | Gdelta = |
| 603 | (((cMax - G) * (HLSMAXcxx . . $ `frmts/northwood/northwood.h:140:9`! / 6)) + ((cMax - cMin) / 2)) / (cMax - cMin); |
| 604 | Bdelta = |
| 605 | (((cMax - B) * (HLSMAXcxx . . $ `frmts/northwood/northwood.h:140:9`! / 6)) + ((cMax - cMin) / 2)) / (cMax - cMin); |
| 606 | |
| 607 | if (R == cMax) |
| 608 | hls.hcxx . . $ $anonymous_type_37fb98c99edfb69d_2#h. = Bdelta - Gdelta; |
| 609 | else if (G == cMax) |
| 610 | hls.hcxx . . $ $anonymous_type_37fb98c99edfb69d_2#h. = (HLSMAXcxx . . $ `frmts/northwood/northwood.h:140:9`! / 3) + Rdelta - Bdelta; |
| 611 | else /* B == cMax */ |
| 612 | hls.hcxx . . $ $anonymous_type_37fb98c99edfb69d_2#h. = ((2 * HLSMAXcxx . . $ `frmts/northwood/northwood.h:140:9`!) / 3) + Gdelta - Rdelta; |
| 613 | |
| 614 | if (hls.hcxx . . $ $anonymous_type_37fb98c99edfb69d_2#h. < 0) |
| 615 | hls.hcxx . . $ $anonymous_type_37fb98c99edfb69d_2#h. += HLSMAXcxx . . $ `frmts/northwood/northwood.h:140:9`!; |
| 616 | if (hls.hcxx . . $ $anonymous_type_37fb98c99edfb69d_2#h. > HLSMAXcxx . . $ `frmts/northwood/northwood.h:140:9`!) |
| 617 | hls.hcxx . . $ $anonymous_type_37fb98c99edfb69d_2#h. -= HLSMAXcxx . . $ `frmts/northwood/northwood.h:140:9`!; |
| 618 | } |
| 619 | return hls; |
| 620 | } |
| 621 | |
| 622 | /* utility routine for HLStoRGB */ |
| 623 | static short HueToRGBcxx . . $ HueToRGB(9a3fce0d34302b3b).(short n1, short n2, short hue) |
| 624 | { |
| 625 | /* range check: note values passed add/subtract thirds of range */ |
| 626 | if (hue < 0) |
| 627 | hue += HLSMAXcxx . . $ `frmts/northwood/northwood.h:140:9`!; |
| 628 | |
| 629 | if (hue > HLSMAXcxx . . $ `frmts/northwood/northwood.h:140:9`!) |
| 630 | hue -= HLSMAXcxx . . $ `frmts/northwood/northwood.h:140:9`!; |
| 631 | |
| 632 | /* return r,g, or b value from this tridrant */ |
| 633 | if (hue < (HLSMAXcxx . . $ `frmts/northwood/northwood.h:140:9`! / 6)) |
| 634 | return n1 + (((n2 - n1) * hue + (HLSMAXcxx . . $ `frmts/northwood/northwood.h:140:9`! / 12)) / (HLSMAXcxx . . $ `frmts/northwood/northwood.h:140:9`! / 6)); |
| 635 | if (hue < (HLSMAXcxx . . $ `frmts/northwood/northwood.h:140:9`! / 2)) |
| 636 | return n2; |
| 637 | if (hue < ((HLSMAXcxx . . $ `frmts/northwood/northwood.h:140:9`! * 2) / 3)) |
| 638 | return n1 + (((n2 - n1) * (((HLSMAXcxx . . $ `frmts/northwood/northwood.h:140:9`! * 2) / 3) - hue) + (HLSMAXcxx . . $ `frmts/northwood/northwood.h:140:9`! / 12)) / |
| 639 | (HLSMAXcxx . . $ `frmts/northwood/northwood.h:140:9`! / 6)); |
| 640 | else |
| 641 | return n1; |
| 642 | } |
| 643 | |
| 644 | NWT_RGBcxx . . $ NWT_RGB# HLStoRGBcxx . . $ HLStoRGB(6b86351e82852edb).(HLScxx . . $ HLS# hls) |
| 645 | { |
| 646 | NWT_RGBcxx . . $ NWT_RGB# rgb; |
| 647 | |
| 648 | if (hls.scxx . . $ $anonymous_type_37fb98c99edfb69d_2#s. == 0) |
| 649 | { /* achromatic case */ |
| 650 | rgb.rcxx . . $ $anonymous_type_37fb98c99edfb69d_1#r. = static_cast<unsigned char>((hls.lcxx . . $ $anonymous_type_37fb98c99edfb69d_2#l. * RGBMAXcxx . . $ `frmts/northwood/northwood.h:141:9`!) / HLSMAXcxx . . $ `frmts/northwood/northwood.h:140:9`!); |
| 651 | rgb.gcxx . . $ $anonymous_type_37fb98c99edfb69d_1#g. = rgb.rcxx . . $ $anonymous_type_37fb98c99edfb69d_1#r.; |
| 652 | rgb.bcxx . . $ $anonymous_type_37fb98c99edfb69d_1#b. = rgb.rcxx . . $ $anonymous_type_37fb98c99edfb69d_1#r.; |
| 653 | if (hls.hcxx . . $ $anonymous_type_37fb98c99edfb69d_2#h. != UNDEFINEDcxx . . $ `frmts/northwood/northwood.h:148:9`!) |
| 654 | { |
| 655 | /* ERROR */ |
| 656 | } |
| 657 | } |
| 658 | else |
| 659 | { /* chromatic case */ |
| 660 | /* set up magic numbers */ |
| 661 | short Magic1, Magic2; /* calculated magic numbers (really!) */ |
| 662 | if (hls.lcxx . . $ $anonymous_type_37fb98c99edfb69d_2#l. <= (HLSMAXcxx . . $ `frmts/northwood/northwood.h:140:9`! / 2)) |
| 663 | Magic2 = (hls.lcxx . . $ $anonymous_type_37fb98c99edfb69d_2#l. * (HLSMAXcxx . . $ `frmts/northwood/northwood.h:140:9`! + hls.scxx . . $ $anonymous_type_37fb98c99edfb69d_2#s.) + (HLSMAXcxx . . $ `frmts/northwood/northwood.h:140:9`! / 2)) / HLSMAXcxx . . $ `frmts/northwood/northwood.h:140:9`!; |
| 664 | else |
| 665 | Magic2 = hls.lcxx . . $ $anonymous_type_37fb98c99edfb69d_2#l. + hls.scxx . . $ $anonymous_type_37fb98c99edfb69d_2#s. - ((hls.lcxx . . $ $anonymous_type_37fb98c99edfb69d_2#l. * hls.scxx . . $ $anonymous_type_37fb98c99edfb69d_2#s.) + (HLSMAXcxx . . $ `frmts/northwood/northwood.h:140:9`! / 2)) / HLSMAXcxx . . $ `frmts/northwood/northwood.h:140:9`!; |
| 666 | Magic1 = 2 * hls.lcxx . . $ $anonymous_type_37fb98c99edfb69d_2#l. - Magic2; |
| 667 | |
| 668 | /* get RGB, change units from HLSMAX to RGBMAX */ |
| 669 | rgb.rcxx . . $ $anonymous_type_37fb98c99edfb69d_1#r. = static_cast<unsigned char>( |
| 670 | (HueToRGBcxx . . $ HueToRGB(9a3fce0d34302b3b).(Magic1, Magic2, hls.hcxx . . $ $anonymous_type_37fb98c99edfb69d_2#h. + (HLSMAXcxx . . $ `frmts/northwood/northwood.h:140:9`! / 3)) * RGBMAXcxx . . $ `frmts/northwood/northwood.h:141:9`! + |
| 671 | (HLSMAXcxx . . $ `frmts/northwood/northwood.h:140:9`! / 2)) / |
| 672 | HLSMAXcxx . . $ `frmts/northwood/northwood.h:140:9`!); |
| 673 | rgb.gcxx . . $ $anonymous_type_37fb98c99edfb69d_1#g. = static_cast<unsigned char>( |
| 674 | (HueToRGBcxx . . $ HueToRGB(9a3fce0d34302b3b).(Magic1, Magic2, hls.hcxx . . $ $anonymous_type_37fb98c99edfb69d_2#h.) * RGBMAXcxx . . $ `frmts/northwood/northwood.h:141:9`! + (HLSMAXcxx . . $ `frmts/northwood/northwood.h:140:9`! / 2)) / HLSMAXcxx . . $ `frmts/northwood/northwood.h:140:9`!); |
| 675 | rgb.bcxx . . $ $anonymous_type_37fb98c99edfb69d_1#b. = static_cast<unsigned char>( |
| 676 | (HueToRGBcxx . . $ HueToRGB(9a3fce0d34302b3b).(Magic1, Magic2, hls.hcxx . . $ $anonymous_type_37fb98c99edfb69d_2#h. - (HLSMAXcxx . . $ `frmts/northwood/northwood.h:140:9`! / 3)) * RGBMAXcxx . . $ `frmts/northwood/northwood.h:141:9`! + |
| 677 | (HLSMAXcxx . . $ `frmts/northwood/northwood.h:140:9`! / 2)) / |
| 678 | HLSMAXcxx . . $ `frmts/northwood/northwood.h:140:9`!); |
| 679 | } |
| 680 | |
| 681 | return rgb; |
| 682 | } |