| 1310 | /************************************************************************/ |
| 1311 | |
| 1312 | static int ApplyLUT( int iColorIndex, layerObj *layer, |
| 1313 | GByte *buffer, int buf_xsize, int buf_ysize ) |
| 1314 | |
| 1315 | { |
| 1316 | const char *lut_def; |
| 1317 | char key[20], lut_def_fromfile[2500]; |
| 1318 | GByte lut[256]; |
| 1319 | int err, i; |
| 1320 | |
| 1321 | /* -------------------------------------------------------------------- */ |
| 1322 | /* Get lut specifier from processing directives. Do nothing if */ |
| 1323 | /* none are found. */ |
| 1324 | /* -------------------------------------------------------------------- */ |
| 1325 | sprintf( key, "LUT_%d", iColorIndex ); |
| 1326 | lut_def = msLayerGetProcessingKey( layer, key ); |
| 1327 | if( lut_def == NULL ) |
| 1328 | lut_def = msLayerGetProcessingKey( layer, "LUT" ); |
| 1329 | if( lut_def == NULL ) |
| 1330 | return 0; |
| 1331 | |
| 1332 | /* -------------------------------------------------------------------- */ |
| 1333 | /* Does this look like a file? If so, read it into memory. */ |
| 1334 | /* -------------------------------------------------------------------- */ |
| 1335 | if( strspn(lut_def,"0123456789:, ") != strlen(lut_def) ) |
| 1336 | { |
| 1337 | FILE *fp; |
| 1338 | char path[MS_MAXPATHLEN]; |
| 1339 | int len; |
| 1340 | msBuildPath(path, layer->map->mappath, lut_def); |
| 1341 | fp = fopen( path, "rb" ); |
| 1342 | if( fp == NULL ) |
| 1343 | { |
| 1344 | msSetError(MS_IOERR, |
| 1345 | "Failed to open LUT file '%s'.", |
| 1346 | "drawGDAL()", path ); |
| 1347 | return -1; |
| 1348 | } |
| 1349 | |
| 1350 | len = fread( lut_def_fromfile, 1, sizeof(lut_def_fromfile), fp ); |
| 1351 | fclose( fp ); |
| 1352 | |
| 1353 | if( len == sizeof(lut_def_fromfile) ) |
| 1354 | { |
| 1355 | msSetError(MS_IOERR, |
| 1356 | "LUT definition from file %s longer than maximum buffer size (%d bytes).", |
| 1357 | "drawGDAL()", |
| 1358 | path, sizeof(lut_def_fromfile) ); |
| 1359 | return -1; |
| 1360 | } |
| 1361 | |
| 1362 | lut_def_fromfile[len] = '\0'; |
| 1363 | |
| 1364 | lut_def = lut_def_fromfile; |
| 1365 | } |
| 1366 | |
| 1367 | /* -------------------------------------------------------------------- */ |
| 1368 | /* Parse the LUT description. */ |
| 1369 | /* -------------------------------------------------------------------- */ |
no test coverage detected