1 /****************************************************************************** 2 * $Id: northwood.h 27044 2014-03-16 23:41:27Z rouault $ 3 * 4 * Project: GRC/GRD Reader 5 * Purpose: Northwood Technologies Grid format declarations 6 * Author: Perry Casson 7 * 8 ****************************************************************************** 9 * Copyright (c) 2007, Waypoint Information Technology 10 * Copyright (c) 2009-2011, Even Rouault <even dot rouault at mines-paris dot org> 11 * 12 * Permission is hereby granted, free of charge, to any person obtaining a 13 * copy of this software and associated documentation files (the "Software"), 14 * to deal in the Software without restriction, including without limitation 15 * the rights to use, copy, modify, merge, publish, distribute, sublicense, 16 * and/or sell copies of the Software, and to permit persons to whom the 17 * Software is furnished to do so, subject to the following conditions: 18 * 19 * The above copyright notice and this permission notice shall be included 20 * in all copies or substantial portions of the Software. 21 * 22 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 23 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 24 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 25 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 26 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 27 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 28 * DEALINGS IN THE SOFTWARE. 29 ****************************************************************************/ 30 31 #ifdef NOT_GDAL 32 #include <stdio.h> 33 #define VSILFILE FILE 34 #define VSIFOpenL fopen 35 #define VSIFCloseL fclose 36 #define VSIFSeekL fseek 37 #define VSIFReadL fread 38 #else 39 #include "cpl_vsi.h" 40 #endif 41 42 #ifndef MAX 43 #define MAX(a, b) (a > b ? a : b) 44 #endif 45 46 #ifndef MIN 47 #define MIN(a, b) (a < b ? a : b) 48 #endif 49 50 51 typedef struct 52 { 53 int row; 54 unsigned char *r; 55 unsigned char *g; 56 unsigned char *b; 57 } NWT_RGB_ROW; 58 59 typedef struct 60 { 61 unsigned char r; 62 unsigned char g; 63 unsigned char b; 64 } NWT_RGB; 65 66 typedef struct 67 { 68 short h; 69 short l; 70 short s; 71 } HLS; 72 73 typedef struct 74 { 75 float zVal; 76 unsigned char r; 77 unsigned char g; 78 unsigned char b; 79 } NWT_INFLECTION; 80 81 typedef struct 82 { 83 unsigned short usPixVal; 84 unsigned char res1; // unknown 85 unsigned char r; 86 unsigned char g; 87 unsigned char b; 88 unsigned char res2; // unknown 89 unsigned short usLen; 90 char szClassName[256]; 91 } NWT_CLASSIFIED_ITEM; 92 93 typedef struct 94 { 95 unsigned int nNumClassifiedItems; 96 // NWT_CLASSIFIED_ITEM *stClassifedItem[4096]; //hack - it could be up to 64K 97 NWT_CLASSIFIED_ITEM **stClassifedItem; //hack - it could be up to 64K 98 } NWT_CLASSIFIED_DICT; 99 100 typedef struct 101 { 102 char szFileName[256]; 103 VSILFILE *fp; 104 float fVersion; 105 unsigned char cFormat; //0x00 16 bit, 0x01 32 bit, 0x80 8 bit classifed, 0x81 16 bit classified 106 unsigned int nBitsPerPixel; 107 unsigned int nXSide; 108 unsigned int nYSide; 109 double dfStepSize; 110 double dfMinX; 111 double dfMaxX; 112 double dfMinY; 113 double dfMaxY; 114 float fZMin; 115 float fZMax; 116 float fZMinScale; 117 float fZMaxScale; 118 int iZUnits; 119 char cDescription[32]; //?? 120 char cZUnits[32]; //?? 121 char cMICoordSys[256]; 122 unsigned short iNumColorInflections; 123 NWT_INFLECTION stInflection[32]; 124 bool bHillShadeExists; 125 bool bShowGradient; 126 bool bShowHillShade; 127 char cHillShadeBrightness; 128 char cHillShadeContrast; 129 float fHillShadeAzimuth; 130 float fHillShadeAngle; 131 NWT_CLASSIFIED_DICT *stClassDict; 132 NWT_RGB_ROW stRGBRow; 133 } NWT_GRID; 134 135 int nwt_ParseHeader( NWT_GRID * pGrd, char *nwHeader ); 136 NWT_GRID *nwtOpenGrid( char *filename ); 137 void nwtCloseGrid( NWT_GRID * pGrd ); 138 void nwtPrintGridHeader( NWT_GRID * pGrd ); 139 int nwt_LoadColors( NWT_RGB * pMap, int mapSize, NWT_GRID * pGrd ); 140 void nwt_HillShade( unsigned char *r, unsigned char *g, unsigned char *b, 141 char *h ); 142 143 void createIP( int index, unsigned char r, unsigned char g, unsigned char b, 144 NWT_RGB * map, int *pnWarkerMark ); 145 void linearColor( NWT_RGB * pRGB, NWT_INFLECTION * pIPLow, NWT_INFLECTION * pIPHigh, 146 float fMid ); 147 148 #define HLSMAX 1024 /* H,L, and S vary over 0-HLSMAX */ 149 #define RGBMAX 255 /* R,G, and B vary over 0-RGBMAX */ 150 /* HLSMAX BEST IF DIVISIBLE BY 6 */ 151 /* RGBMAX, HLSMAX must each fit in a byte. */ 152 153 /* Hue is undefined if Saturation is 0 (grey-scale) */ 154 /* This value determines where the Hue scrollbar is */ 155 /* initially set for achromatic colors */ 156 #define UNDEFINED (HLSMAX*2/3) 157 158 HLS RGBtoHLS (NWT_RGB rgb); 159 NWT_RGB HLStoRGB (HLS hls); 160