| 1261 | /************************************************************************/ |
| 1262 | |
| 1263 | static int ParseGimpLUT( const char *lut_def, GByte *lut, int iColorIndex ) |
| 1264 | |
| 1265 | { |
| 1266 | int i; |
| 1267 | GByte lutValue[256]; |
| 1268 | GByte lutColorBand[256]; |
| 1269 | char **lines = |
| 1270 | CSLTokenizeStringComplex( lut_def, "\n", FALSE, FALSE ); |
| 1271 | |
| 1272 | if( !EQUALN(lines[0],"# GIMP Curves File",18) |
| 1273 | || CSLCount(lines) < 6 ) |
| 1274 | { |
| 1275 | msSetError(MS_MISCERR, |
| 1276 | "GIMP curve file appears corrupt.", |
| 1277 | "ParseGimpLUT()" ); |
| 1278 | return -1; |
| 1279 | } |
| 1280 | |
| 1281 | /* |
| 1282 | * Convert the overall curve, and the color band specific curve into LUTs. |
| 1283 | */ |
| 1284 | if( LutFromGimpLine( lines[1], lutValue ) != 0 |
| 1285 | || LutFromGimpLine( lines[iColorIndex + 1], lutColorBand ) != 0 ) |
| 1286 | { |
| 1287 | CSLDestroy( lines ); |
| 1288 | return -1; |
| 1289 | } |
| 1290 | CSLDestroy( lines ); |
| 1291 | |
| 1292 | /* |
| 1293 | * Compose the two luts as if the raw value passed through the color band |
| 1294 | * specific lut, and then the general value lut. Usually one or the |
| 1295 | * other will be the identity mapping, but not always. |
| 1296 | */ |
| 1297 | |
| 1298 | for( i = 0; i < 256; i++ ) |
| 1299 | { |
| 1300 | lut[i] = lutValue[lutColorBand[i]]; |
| 1301 | } |
| 1302 | |
| 1303 | return 0; |
| 1304 | } |
| 1305 | |
| 1306 | /************************************************************************/ |
| 1307 | /* ApplyLUT() */ |
no test coverage detected