Initial commit: ArgyllCMS v3.5.0 and multichannel profiling research

This commit is contained in:
2026-10-31 14:27:14 +03:30
commit 66f664fc82
1828 changed files with 1123613 additions and 0 deletions

View File

@@ -0,0 +1,882 @@
/* Convert the ICC V4.4 Reference Medium Gamut to Argyll Lab Gamut */
/* Copyright 2005, 2024 by Graeme W. Gill */
/* All rights reserved. */
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <fcntl.h>
#include <string.h>
#include <math.h>
#include "aconfig.h"
#include "numlib.h"
#include "icc.h"
#include "cgats.h"
#include "conv.h"
#include "xicc.h"
#include "xcam.h"
#include "gamut.h"
/* Gamut surface points in LCh space */
/* + black and white points */
#define NPOINTS (684+2+3)
double points[NPOINTS][3] = {
{ 100, 0, 0 }, /* White */
{ 3.1373, 0, 0 }, /* Black */
{ 98.75, 30.75, 90 }, /* Three extra values along yellow ridge */
{ 97.5, 61.5, 90 },
{ 96.25, 92.25, 90 },
{ 5, 11, 0 },
{ 10, 26, 0 },
{ 15, 39, 0 },
{ 20, 52, 0 },
{ 25, 64, 0 },
{ 30, 74, 0 },
{ 35, 83, 0 },
{ 40, 91, 0 },
{ 45, 92, 0 },
{ 50, 91, 0 },
{ 55, 87, 0 },
{ 60, 82, 0 },
{ 65, 75, 0 },
{ 70, 67, 0 },
{ 75, 57, 0 },
{ 80, 47, 0 },
{ 85, 37, 0 },
{ 90, 25, 0 },
{ 95, 13, 0 },
{ 5, 10, 10 },
{ 10, 24, 10 },
{ 15, 38, 10 },
{ 20, 50, 10 },
{ 25, 62, 10 },
{ 30, 73, 10 },
{ 35, 82, 10 },
{ 40, 90, 10 },
{ 45, 92, 10 },
{ 50, 91, 10 },
{ 55, 87, 10 },
{ 60, 82, 10 },
{ 65, 75, 10 },
{ 70, 67, 10 },
{ 75, 58, 10 },
{ 80, 48, 10 },
{ 85, 37, 10 },
{ 90, 26, 10 },
{ 95, 13, 10 },
{ 5, 10, 20 },
{ 10, 23, 20 },
{ 15, 37, 20 },
{ 20, 50, 20 },
{ 25, 62, 20 },
{ 30, 73, 20 },
{ 35, 84, 20 },
{ 40, 93, 20 },
{ 45, 94, 20 },
{ 50, 94, 20 },
{ 55, 90, 20 },
{ 60, 85, 20 },
{ 65, 78, 20 },
{ 70, 70, 20 },
{ 75, 60, 20 },
{ 80, 50, 20 },
{ 85, 39, 20 },
{ 90, 27, 20 },
{ 95, 14, 20 },
{ 5, 9, 30 },
{ 10, 22, 30 },
{ 15, 35, 30 },
{ 20, 48, 30 },
{ 25, 61, 30 },
{ 30, 74, 30 },
{ 35, 86, 30 },
{ 40, 98, 30 },
{ 45, 100, 30 },
{ 50, 101, 30 },
{ 55, 96, 30 },
{ 60, 90, 30 },
{ 65, 83, 30 },
{ 70, 75, 30 },
{ 75, 65, 30 },
{ 80, 54, 30 },
{ 85, 42, 30 },
{ 90, 30, 30 },
{ 95, 15, 30 },
{ 5, 8, 40 },
{ 10, 21, 40 },
{ 15, 34, 40 },
{ 20, 47, 40 },
{ 25, 60, 40 },
{ 30, 73, 40 },
{ 35, 83, 40 },
{ 40, 93, 40 },
{ 45, 97, 40 },
{ 50, 101, 40 },
{ 55, 99, 40 },
{ 60, 97, 40 },
{ 65, 90, 40 },
{ 70, 83, 40 },
{ 75, 73, 40 },
{ 80, 61, 40 },
{ 85, 47, 40 },
{ 90, 34, 40 },
{ 95, 17, 40 },
{ 5, 8, 50 },
{ 10, 20, 50 },
{ 15, 32, 50 },
{ 20, 43, 50 },
{ 25, 55, 50 },
{ 30, 66, 50 },
{ 35, 77, 50 },
{ 40, 88, 50 },
{ 45, 95, 50 },
{ 50, 99, 50 },
{ 55, 101, 50 },
{ 60, 100, 50 },
{ 65, 98, 50 },
{ 70, 92, 50 },
{ 75, 85, 50 },
{ 80, 72, 50 },
{ 85, 56, 50 },
{ 90, 40, 50 },
{ 95, 20, 50 },
{ 5, 7, 60 },
{ 10, 17, 60 },
{ 15, 27, 60 },
{ 20, 37, 60 },
{ 25, 47, 60 },
{ 30, 57, 60 },
{ 35, 67, 60 },
{ 40, 76, 60 },
{ 45, 84, 60 },
{ 50, 91, 60 },
{ 55, 96, 60 },
{ 60, 100, 60 },
{ 65, 102, 60 },
{ 70, 103, 60 },
{ 75, 98, 60 },
{ 80, 90, 60 },
{ 85, 72, 60 },
{ 90, 51, 60 },
{ 95, 26, 60 },
{ 5, 6, 70 },
{ 10, 16, 70 },
{ 15, 25, 70 },
{ 20, 34, 70 },
{ 25, 43, 70 },
{ 30, 52, 70 },
{ 35, 60, 70 },
{ 40, 68, 70 },
{ 45, 76, 70 },
{ 50, 83, 70 },
{ 55, 90, 70 },
{ 60, 96, 70 },
{ 65, 100, 70 },
{ 70, 104, 70 },
{ 75, 107, 70 },
{ 80, 109, 70 },
{ 85, 100, 70 },
{ 90, 74, 70 },
{ 95, 37, 70 },
{ 5, 6, 80 },
{ 10, 15, 80 },
{ 15, 23, 80 },
{ 20, 32, 80 },
{ 25, 40, 80 },
{ 30, 48, 80 },
{ 35, 57, 80 },
{ 40, 64, 80 },
{ 45, 71, 80 },
{ 50, 78, 80 },
{ 55, 85, 80 },
{ 60, 91, 80 },
{ 65, 97, 80 },
{ 70, 103, 80 },
{ 75, 107, 80 },
{ 80, 110, 80 },
{ 85, 113, 80 },
{ 90, 110, 80 },
{ 95, 70, 80 },
{ 5, 6, 90 },
{ 10, 14, 90 },
{ 15, 22, 90 },
{ 20, 30, 90 },
{ 25, 39, 90 },
{ 30, 47, 90 },
{ 35, 55, 90 },
{ 40, 62, 90 },
{ 45, 68, 90 },
{ 50, 75, 90 },
{ 55, 82, 90 },
{ 60, 88, 90 },
{ 65, 95, 90 },
{ 70, 101, 90 },
{ 75, 106, 90 },
{ 80, 112, 90 },
{ 85, 117, 90 },
{ 90, 120, 90 },
{ 95, 123, 90 },
{ 5, 6, 100 },
{ 10, 14, 100 },
{ 15, 22, 100 },
{ 20, 30, 100 },
{ 25, 38, 100 },
{ 30, 46, 100 },
{ 35, 54, 100 },
{ 40, 61, 100 },
{ 45, 68, 100 },
{ 50, 74, 100 },
{ 55, 81, 100 },
{ 60, 88, 100 },
{ 65, 94, 100 },
{ 70, 100, 100 },
{ 75, 106, 100 },
{ 80, 109, 100 },
{ 85, 112, 100 },
{ 90, 112, 100 },
{ 95, 92, 100 },
{ 5, 6, 110 },
{ 10, 14, 110 },
{ 15, 22, 110 },
{ 20, 31, 110 },
{ 25, 39, 110 },
{ 30, 47, 110 },
{ 35, 55, 110 },
{ 40, 63, 110 },
{ 45, 69, 110 },
{ 50, 76, 110 },
{ 55, 83, 110 },
{ 60, 89, 110 },
{ 65, 96, 110 },
{ 70, 100, 110 },
{ 75, 103, 110 },
{ 80, 106, 110 },
{ 85, 107, 110 },
{ 90, 102, 110 },
{ 95, 75, 110 },
{ 5, 6, 120 },
{ 10, 15, 120 },
{ 15, 24, 120 },
{ 20, 32, 120 },
{ 25, 41, 120 },
{ 30, 49, 120 },
{ 35, 58, 120 },
{ 40, 66, 120 },
{ 45, 73, 120 },
{ 50, 80, 120 },
{ 55, 87, 120 },
{ 60, 93, 120 },
{ 65, 98, 120 },
{ 70, 101, 120 },
{ 75, 102, 120 },
{ 80, 99, 120 },
{ 85, 91, 120 },
{ 90, 73, 120 },
{ 95, 50, 120 },
{ 5, 6, 130 },
{ 10, 16, 130 },
{ 15, 25, 130 },
{ 20, 35, 130 },
{ 25, 44, 130 },
{ 30, 54, 130 },
{ 35, 63, 130 },
{ 40, 72, 130 },
{ 45, 80, 130 },
{ 50, 87, 130 },
{ 55, 93, 130 },
{ 60, 97, 130 },
{ 65, 101, 130 },
{ 70, 99, 130 },
{ 75, 94, 130 },
{ 80, 86, 130 },
{ 85, 73, 130 },
{ 90, 56, 130 },
{ 95, 34, 130 },
{ 5, 7, 140 },
{ 10, 18, 140 },
{ 15, 28, 140 },
{ 20, 38, 140 },
{ 25, 48, 140 },
{ 30, 57, 140 },
{ 35, 67, 140 },
{ 40, 77, 140 },
{ 45, 86, 140 },
{ 50, 95, 140 },
{ 55, 98, 140 },
{ 60, 101, 140 },
{ 65, 97, 140 },
{ 70, 93, 140 },
{ 75, 85, 140 },
{ 80, 75, 140 },
{ 85, 61, 140 },
{ 90, 44, 140 },
{ 95, 26, 140 },
{ 5, 7, 150 },
{ 10, 19, 150 },
{ 15, 30, 150 },
{ 20, 40, 150 },
{ 25, 51, 150 },
{ 30, 62, 150 },
{ 35, 72, 150 },
{ 40, 83, 150 },
{ 45, 92, 150 },
{ 50, 97, 150 },
{ 55, 99, 150 },
{ 60, 96, 150 },
{ 65, 91, 150 },
{ 70, 85, 150 },
{ 75, 76, 150 },
{ 80, 66, 150 },
{ 85, 52, 150 },
{ 90, 37, 150 },
{ 95, 22, 150 },
{ 5, 7, 160 },
{ 10, 20, 160 },
{ 15, 32, 160 },
{ 20, 44, 160 },
{ 25, 56, 160 },
{ 30, 68, 160 },
{ 35, 80, 160 },
{ 40, 92, 160 },
{ 45, 96, 160 },
{ 50, 99, 160 },
{ 55, 97, 160 },
{ 60, 92, 160 },
{ 65, 87, 160 },
{ 70, 79, 160 },
{ 75, 70, 160 },
{ 80, 59, 160 },
{ 85, 46, 160 },
{ 90, 33, 160 },
{ 95, 19, 160 },
{ 5, 8, 170 },
{ 10, 20, 170 },
{ 15, 32, 170 },
{ 20, 43, 170 },
{ 25, 53, 170 },
{ 30, 64, 170 },
{ 35, 75, 170 },
{ 40, 85, 170 },
{ 45, 91, 170 },
{ 50, 96, 170 },
{ 55, 93, 170 },
{ 60, 89, 170 },
{ 65, 82, 170 },
{ 70, 75, 170 },
{ 75, 65, 170 },
{ 80, 55, 170 },
{ 85, 42, 170 },
{ 90, 30, 170 },
{ 95, 17, 170 },
{ 5, 8, 180 },
{ 10, 20, 180 },
{ 15, 31, 180 },
{ 20, 41, 180 },
{ 25, 52, 180 },
{ 30, 62, 180 },
{ 35, 72, 180 },
{ 40, 81, 180 },
{ 45, 87, 180 },
{ 50, 92, 180 },
{ 55, 90, 180 },
{ 60, 86, 180 },
{ 65, 79, 180 },
{ 70, 71, 180 },
{ 75, 61, 180 },
{ 80, 52, 180 },
{ 85, 40, 180 },
{ 90, 28, 180 },
{ 95, 15, 180 },
{ 5, 8, 190 },
{ 10, 20, 190 },
{ 15, 30, 190 },
{ 20, 40, 190 },
{ 25, 50, 190 },
{ 30, 60, 190 },
{ 35, 68, 190 },
{ 40, 76, 190 },
{ 45, 82, 190 },
{ 50, 87, 190 },
{ 55, 85, 190 },
{ 60, 82, 190 },
{ 65, 76, 190 },
{ 70, 69, 190 },
{ 75, 60, 190 },
{ 80, 50, 190 },
{ 85, 39, 190 },
{ 90, 27, 190 },
{ 95, 14, 190 },
{ 5, 8, 200 },
{ 10, 20, 200 },
{ 15, 30, 200 },
{ 20, 38, 200 },
{ 25, 47, 200 },
{ 30, 56, 200 },
{ 35, 63, 200 },
{ 40, 70, 200 },
{ 45, 76, 200 },
{ 50, 82, 200 },
{ 55, 81, 200 },
{ 60, 77, 200 },
{ 65, 72, 200 },
{ 70, 66, 200 },
{ 75, 58, 200 },
{ 80, 49, 200 },
{ 85, 38, 200 },
{ 90, 27, 200 },
{ 95, 14, 200 },
{ 5, 8, 210 },
{ 10, 20, 210 },
{ 15, 29, 210 },
{ 20, 37, 210 },
{ 25, 46, 210 },
{ 30, 53, 210 },
{ 35, 60, 210 },
{ 40, 66, 210 },
{ 45, 73, 210 },
{ 50, 79, 210 },
{ 55, 80, 210 },
{ 60, 75, 210 },
{ 65, 70, 210 },
{ 70, 64, 210 },
{ 75, 57, 210 },
{ 80, 49, 210 },
{ 85, 38, 210 },
{ 90, 27, 210 },
{ 95, 14, 210 },
{ 5, 8, 220 },
{ 10, 20, 220 },
{ 15, 29, 220 },
{ 20, 37, 220 },
{ 25, 45, 220 },
{ 30, 52, 220 },
{ 35, 59, 220 },
{ 40, 65, 220 },
{ 45, 71, 220 },
{ 50, 76, 220 },
{ 55, 75, 220 },
{ 60, 72, 220 },
{ 65, 68, 220 },
{ 70, 63, 220 },
{ 75, 56, 220 },
{ 80, 48, 220 },
{ 85, 38, 220 },
{ 90, 27, 220 },
{ 95, 14, 220 },
{ 5, 9, 230 },
{ 10, 20, 230 },
{ 15, 29, 230 },
{ 20, 38, 230 },
{ 25, 46, 230 },
{ 30, 53, 230 },
{ 35, 59, 230 },
{ 40, 65, 230 },
{ 45, 70, 230 },
{ 50, 75, 230 },
{ 55, 73, 230 },
{ 60, 71, 230 },
{ 65, 66, 230 },
{ 70, 61, 230 },
{ 75, 54, 230 },
{ 80, 46, 230 },
{ 85, 36, 230 },
{ 90, 26, 230 },
{ 95, 13, 230 },
{ 5, 10, 240 },
{ 10, 22, 240 },
{ 15, 31, 240 },
{ 20, 40, 240 },
{ 25, 48, 240 },
{ 30, 55, 240 },
{ 35, 61, 240 },
{ 40, 67, 240 },
{ 45, 71, 240 },
{ 50, 74, 240 },
{ 55, 70, 240 },
{ 60, 66, 240 },
{ 65, 61, 240 },
{ 70, 56, 240 },
{ 75, 49, 240 },
{ 80, 41, 240 },
{ 85, 32, 240 },
{ 90, 23, 240 },
{ 95, 12, 240 },
{ 5, 11, 250 },
{ 10, 24, 250 },
{ 15, 34, 250 },
{ 20, 43, 250 },
{ 25, 51, 250 },
{ 30, 59, 250 },
{ 35, 65, 250 },
{ 40, 70, 250 },
{ 45, 73, 250 },
{ 50, 71, 250 },
{ 55, 68, 250 },
{ 60, 63, 250 },
{ 65, 58, 250 },
{ 70, 52, 250 },
{ 75, 45, 250 },
{ 80, 38, 250 },
{ 85, 30, 250 },
{ 90, 21, 250 },
{ 95, 11, 250 },
{ 5, 14, 260 },
{ 10, 27, 260 },
{ 15, 38, 260 },
{ 20, 48, 260 },
{ 25, 57, 260 },
{ 30, 64, 260 },
{ 35, 69, 260 },
{ 40, 73, 260 },
{ 45, 73, 260 },
{ 50, 70, 260 },
{ 55, 66, 260 },
{ 60, 61, 260 },
{ 65, 56, 260 },
{ 70, 50, 260 },
{ 75, 43, 260 },
{ 80, 35, 260 },
{ 85, 28, 260 },
{ 90, 20, 260 },
{ 95, 10, 260 },
{ 5, 17, 270 },
{ 10, 32, 270 },
{ 15, 45, 270 },
{ 20, 55, 270 },
{ 25, 65, 270 },
{ 30, 70, 270 },
{ 35, 75, 270 },
{ 40, 75, 270 },
{ 45, 73, 270 },
{ 50, 70, 270 },
{ 55, 66, 270 },
{ 60, 61, 270 },
{ 65, 55, 270 },
{ 70, 49, 270 },
{ 75, 42, 270 },
{ 80, 34, 270 },
{ 85, 27, 270 },
{ 90, 19, 270 },
{ 95, 10, 270 },
{ 5, 21, 280 },
{ 10, 42, 280 },
{ 15, 55, 280 },
{ 20, 68, 280 },
{ 25, 75, 280 },
{ 30, 81, 280 },
{ 35, 80, 280 },
{ 40, 79, 280 },
{ 45, 76, 280 },
{ 50, 72, 280 },
{ 55, 67, 280 },
{ 60, 61, 280 },
{ 65, 55, 280 },
{ 70, 49, 280 },
{ 75, 41, 280 },
{ 80, 34, 280 },
{ 85, 26, 280 },
{ 90, 18, 280 },
{ 95, 9, 280 },
{ 5, 26, 290 },
{ 10, 52, 290 },
{ 15, 68, 290 },
{ 20, 83, 290 },
{ 25, 86, 290 },
{ 30, 89, 290 },
{ 35, 87, 290 },
{ 40, 84, 290 },
{ 45, 80, 290 },
{ 50, 75, 290 },
{ 55, 69, 290 },
{ 60, 63, 290 },
{ 65, 57, 290 },
{ 70, 50, 290 },
{ 75, 42, 290 },
{ 80, 35, 290 },
{ 85, 27, 290 },
{ 90, 18, 290 },
{ 95, 10, 290 },
{ 5, 25, 300 },
{ 10, 69, 300 },
{ 15, 82, 300 },
{ 20, 95, 300 },
{ 25, 94, 300 },
{ 30, 93, 300 },
{ 35, 91, 300 },
{ 40, 88, 300 },
{ 45, 85, 300 },
{ 50, 79, 300 },
{ 55, 73, 300 },
{ 60, 66, 300 },
{ 65, 59, 300 },
{ 70, 52, 300 },
{ 75, 44, 300 },
{ 80, 36, 300 },
{ 85, 28, 300 },
{ 90, 19, 300 },
{ 95, 10, 300 },
{ 5, 21, 310 },
{ 10, 51, 310 },
{ 15, 74, 310 },
{ 20, 91, 310 },
{ 25, 97, 310 },
{ 30, 100, 310 },
{ 35, 98, 310 },
{ 40, 95, 310 },
{ 45, 90, 310 },
{ 50, 84, 310 },
{ 55, 77, 310 },
{ 60, 70, 310 },
{ 65, 63, 310 },
{ 70, 55, 310 },
{ 75, 47, 310 },
{ 80, 39, 310 },
{ 85, 30, 310 },
{ 90, 20, 310 },
{ 95, 10, 310 },
{ 5, 18, 320 },
{ 10, 41, 320 },
{ 15, 62, 320 },
{ 20, 79, 320 },
{ 25, 91, 320 },
{ 30, 102, 320 },
{ 35, 101, 320 },
{ 40, 98, 320 },
{ 45, 95, 320 },
{ 50, 89, 320 },
{ 55, 83, 320 },
{ 60, 76, 320 },
{ 65, 68, 320 },
{ 70, 60, 320 },
{ 75, 51, 320 },
{ 80, 42, 320 },
{ 85, 32, 320 },
{ 90, 22, 320 },
{ 95, 11, 320 },
{ 5, 16, 330 },
{ 10, 35, 330 },
{ 15, 53, 330 },
{ 20, 71, 330 },
{ 25, 82, 330 },
{ 30, 91, 330 },
{ 35, 100, 330 },
{ 40, 104, 330 },
{ 45, 102, 330 },
{ 50, 98, 330 },
{ 55, 91, 330 },
{ 60, 84, 330 },
{ 65, 76, 330 },
{ 70, 67, 330 },
{ 75, 57, 330 },
{ 80, 47, 330 },
{ 85, 36, 330 },
{ 90, 24, 330 },
{ 95, 12, 330 },
{ 5, 14, 340 },
{ 10, 31, 340 },
{ 15, 46, 340 },
{ 20, 61, 340 },
{ 25, 73, 340 },
{ 30, 83, 340 },
{ 35, 92, 340 },
{ 40, 101, 340 },
{ 45, 103, 340 },
{ 50, 99, 340 },
{ 55, 95, 340 },
{ 60, 89, 340 },
{ 65, 80, 340 },
{ 70, 71, 340 },
{ 75, 61, 340 },
{ 80, 50, 340 },
{ 85, 38, 340 },
{ 90, 26, 340 },
{ 95, 13, 340 },
{ 5, 12, 350 },
{ 10, 28, 350 },
{ 15, 42, 350 },
{ 20, 55, 350 },
{ 25, 68, 350 },
{ 30, 77, 350 },
{ 35, 86, 350 },
{ 40, 94, 350 },
{ 45, 96, 350 },
{ 50, 93, 350 },
{ 55, 90, 350 },
{ 60, 85, 350 },
{ 65, 77, 350 },
{ 70, 68, 350 },
{ 75, 58, 350 },
{ 80, 48, 350 },
{ 85, 37, 350 },
{ 90, 25, 350 },
{ 95, 13, 350 },
};
/* selected "cusp" points in LCh */
double cpoints[6][3] = {
{ 41, 98, 29 }, /* Red */
{ 95, 123, 90 }, /* Yellow */
{ 60, 100, 140 }, /* Green */
{ 50, 76, 220 }, /* Cyan */
{ 21, 95, 300 }, /* Blue */
{ 42, 102, 340 }, /* Megenta */
};
/* Our idealised cusp point angles for Lab in degrees: */
/* 36.0, Red */
/* 101.0, Yellow */
/* 149.0, Green */
/* 225.0, Cyan */
/* 300.0, Blue */
/* 337.0 Magenta */
#define GAMRES 1.0 /* Default surface resolution */
void usage(char *diag) {
fprintf(stderr,"Generate Reference Medium Gamut Version %s\n",ARGYLL_VERSION_STR);
fprintf(stderr,"Author: Graeme W. Gill, licensed under the AGPL Version 3\n");
fprintf(stderr,"usage: GenRMGam [options] [outputname]\n");
if (diag != NULL)
fprintf(stderr,"Diagnostic: %s\n",diag);
fprintf(stderr," -v Verbose\n");
fprintf(stderr," -l L*a*b* output rather than Jab ISO-3664 P2\n");
fprintf(stderr," outputname output name rather than default RefMediumGamut.gam\n");
fprintf(stderr,"\n");
exit(1);
}
int
main(int argc, char *argv[]) {
int fa, nfa; /* argument we're looking at */
int verb = 0;
int dolab = 0;
icxcam *cam = NULL; /* Used for Jab conversion */
static char out_name[MAXNAMEL+1]; /* VRML output file */
double gamres = GAMRES; /* Surface resolution */
gamut *gam;
double wp[3], bp[3];
int i;
error_program = "GenRMGam";
/* Process the arguments */
for(fa = 1;fa < argc;fa++) {
nfa = fa; /* skip to nfa if next argument is used */
if (argv[fa][0] == '-') { /* Look for any flags */
char *na = NULL; /* next argument after flag, null if none */
if (argv[fa][2] != '\000')
na = &argv[fa][2]; /* next is directly after flag */
else {
if ((fa+1) < argc) {
if (argv[fa+1][0] != '-') {
nfa = fa + 1;
na = argv[nfa]; /* next is seperate non-flag argument */
}
}
}
if (argv[fa][1] == '?')
usage(NULL);
/* Verbosity */
else if (argv[fa][1] == 'v') {
verb = 1;
}
/* Lab */
else if (argv[fa][1] == 'l') {
dolab = 1;
}
else
usage("Unknown flag");
} else
break;
}
if (fa >= argc || argv[fa][0] == '-') {
strcpy(out_name, "RefMediumGamut.gam");
} else {
strncpy(out_name,argv[1],MAXNAMEL); out_name[MAXNAMEL] = '\000';
}
{
double *wp = icmD50_ary3;
icxViewCond vc;
/* ISO-3664 P2 */
if (xicc_enum_viewcond(NULL, &vc, -2, "pp", 0, wp) == -999)
error("Urecognised Enumerated Viewing conditions '%s'","pp");
if (verb)
xicc_dump_viewcond(&vc);
if ((cam = new_icxcam(cam_CIECAM02)) == NULL)
error("new_icxcam failed");
cam->set_view_vc(cam, &vc);
// if (verb)
// cam->dump(cam);
}
/* Creat a gamut surface */
gam = new_gamut(gamres, cam != NULL, 0);
/* For all the supplied surface points, */
/* add them to the gamut */
for (i = 0; i < NPOINTS; i++) {
double lab[3];
icmLCh2Lab(lab, points[i]);
//printf("~1 LCh %f %f %f -> Lab %f %f %f\n", points[i][0], points[i][1], points[i][2], lab[0], lab[1], lab[2]);
/* Convert to appearance space */
if (cam != NULL) {
icmLab2XYZ(&icmD50, lab, lab);
cam->XYZ_to_cam(cam, lab, lab);
//printf("~1 Jab %f %f %f\n", lab[0], lab[1], lab[2]);
}
gam->expand(gam, lab);
}
/* Add selected cusp points to set cusp values */
gam->setcusps(gam, 0, NULL);
for (i = 0; i < 6; i++) {
double lab[3];
icmLCh2Lab(lab, cpoints[i]);
//printf("~1 LCh %f %f %f -> Lab %f %f %f\n", points[i][0], points[i][1], points[i][2], lab[0], lab[1], lab[2]);
/* Convert to appearance space */
if (cam != NULL) {
icmLab2XYZ(&icmD50, lab, lab);
cam->XYZ_to_cam(cam, lab, lab);
}
gam->setcusps(gam, 1, lab);
}
gam->setcusps(gam, 2, NULL);
/* Add colorspace white and black points so that this gamut can substitute */
/* for source colorspace gamut */
wp[0] = 100.0;
wp[1] = 0.0;
wp[2] = 0.0;
bp[0] = 0.0;
bp[1] = 0.0;
bp[2] = 0.0;
gam->setwb(gam, wp, bp, NULL);
if (gam->write_gam(gam, out_name))
error ("write gamut failed on '%s'",out_name);
gam->del(gam);
return 0;
}

View File

@@ -0,0 +1,187 @@
/* Generate the visual gamut in L*a*b* space */
/* Copyright 2006 by Graeme W. Gill */
/* All rights reserved. */
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <fcntl.h>
#include <string.h>
#include <math.h>
#include "numlib.h"
#include "icc.h"
#include "cgats.h"
#include "gamut.h"
/* 2 degree spectrum locus in xy coordinates */
/* nm, x, y, Y CMC */
double sl[65][4] = {
{ 380, 0.1741, 0.0050, 0.000039097450 },
{ 385, 0.1740, 0.0050, 0.000065464490 },
{ 390, 0.1738, 0.0049, 0.000121224052 },
{ 395, 0.1736, 0.0049, 0.000221434140 },
{ 400, 0.1733, 0.0048, 0.000395705080 },
{ 405, 0.1730, 0.0048, 0.000656030940 },
{ 410, 0.1726, 0.0048, 0.001222776600 },
{ 415, 0.1721, 0.0048, 0.002210898200 },
{ 420, 0.1714, 0.0051, 0.004069952000 },
{ 425, 0.1703, 0.0058, 0.007334133400 },
{ 430, 0.1689, 0.0069, 0.011637600000 },
{ 435, 0.1669, 0.0086, 0.016881322000 },
{ 440, 0.1644, 0.0109, 0.023015402000 },
{ 445, 0.1611, 0.0138, 0.029860866000 },
{ 450, 0.1566, 0.0177, 0.038072300000 },
{ 455, 0.1510, 0.0227, 0.048085078000 },
{ 460, 0.1440, 0.0297, 0.060063754000 },
{ 465, 0.1355, 0.0399, 0.074027114000 },
{ 470, 0.1241, 0.0578, 0.091168598000 },
{ 475, 0.1096, 0.0868, 0.112811680000 },
{ 480, 0.0913, 0.1327, 0.139122260000 },
{ 485, 0.0686, 0.2007, 0.169656160000 },
{ 490, 0.0454, 0.2950, 0.208513180000 },
{ 495, 0.0235, 0.4127, 0.259083420000 },
{ 500, 0.0082, 0.5384, 0.323943280000 },
{ 505, 0.0039, 0.6548, 0.407645120000 },
{ 510, 0.0139, 0.7502, 0.503483040000 },
{ 515, 0.0389, 0.8120, 0.608101540000 },
{ 520, 0.0743, 0.8338, 0.709073280000 },
{ 525, 0.1142, 0.8262, 0.792722560000 },
{ 530, 0.1547, 0.8059, 0.861314320000 },
{ 535, 0.1929, 0.7816, 0.914322820000 },
{ 540, 0.2296, 0.7543, 0.953482260000 },
{ 545, 0.2658, 0.7243, 0.979818740000 },
{ 550, 0.3016, 0.6923, 0.994576720000 },
{ 555, 0.3373, 0.6589, 0.999604300000 },
{ 560, 0.3731, 0.6245, 0.994513460000 },
{ 565, 0.4087, 0.5896, 0.978204680000 },
{ 570, 0.4441, 0.5547, 0.951588260000 },
{ 575, 0.4788, 0.5202, 0.915060800000 },
{ 580, 0.5125, 0.4866, 0.869647940000 },
{ 585, 0.5448, 0.4544, 0.816076000000 },
{ 590, 0.5752, 0.4242, 0.756904640000 },
{ 595, 0.6029, 0.3965, 0.694818180000 },
{ 600, 0.6270, 0.3725, 0.630997820000 },
{ 605, 0.6482, 0.3514, 0.566802360000 },
{ 610, 0.6658, 0.3340, 0.503096860000 },
{ 615, 0.6801, 0.3197, 0.441279360000 },
{ 620, 0.6915, 0.3083, 0.380961920000 },
{ 625, 0.7006, 0.2993, 0.321156580000 },
{ 630, 0.7079, 0.2920, 0.265374180000 },
{ 635, 0.7140, 0.2859, 0.217219520000 },
{ 640, 0.7190, 0.2809, 0.175199900000 },
{ 645, 0.7230, 0.2770, 0.138425720000 },
{ 650, 0.7260, 0.2740, 0.107242628000 },
{ 655, 0.7283, 0.2717, 0.081786794000 },
{ 660, 0.7300, 0.2700, 0.061166218000 },
{ 665, 0.7311, 0.2689, 0.044729418000 },
{ 670, 0.7320, 0.2680, 0.032160714000 },
{ 675, 0.7327, 0.2673, 0.023307860000 },
{ 680, 0.7334, 0.2666, 0.017028548000 },
{ 685, 0.7340, 0.2660, 0.011981432000 },
{ 690, 0.7344, 0.2656, 0.008259734600 },
{ 695, 0.7346, 0.2654, 0.005758363200 },
{ 700, 0.7347, 0.2653, 0.004117206200 }
};
#define GAMRES 5.0 /* Default surface resolution */
int
main(int argc, char *argv[]) {
int i, j, e;
double Yxy[3], XYZ[3], Lab[3];
static char out_name[MAXNAMEL+1]; /* VRML output file */
double big[3] = { 0.0, 0.0, 0.0 }, bc;
double low[3] = { 1e6, 1e6, 1e6 };
double high[3] = { -1e6, -1e6, -1e6 };
// double limit = 5.0; /* Limit multiplier of light at maximum sensitivity */
double gamres = GAMRES; /* Surface resolution */
gamut *gam;
strcpy(out_name, "VisGamut.gam");
/* Creat a gamut surface */
gam = new_gamut(gamres, 0, 0);
bc = 0.0;
/* The monochromic boundary with a unit energy monochromic source */
for (j = 0; j < 50; j++) {
double Y = j/(50 - 1.0);
Y = Y * Y;
for (i = 0; i < 65; i++) {
// Yxy[0] = Y * limit * sl[i][3];
// if (Yxy[0] > Y)
Yxy[0] = Y;
Yxy[1] = sl[i][1];
Yxy[2] = sl[i][2];
icmYxy2XYZ(XYZ, Yxy);
icmXYZ2Lab(&icmD50, Lab, XYZ);
gam->expand(gam, Lab);
for (e = 0; e < 3; e++) {
if (Lab[e] < low[e])
low[e] = Lab[e];
if (Lab[e] > high[e])
high[e] = Lab[e];
}
if ((Lab[1] * Lab[1] + Lab[2] * Lab[2]) > bc) {
bc = Lab[1] * Lab[1] + Lab[2] * Lab[2];
big[0] = Lab[0], big[1] = Lab[1], big[2] = Lab[2];
}
}
/* Do the purple line */
for (i = 0; i < 20; i++) {
double b = i/(20 - 1.0);
// Yxy[0] = (b * sl[0][3] + (1.0 - b) * sl[64][3]) * limit * Y;
// if (Yxy[0] > Y)
Yxy[0] = Y;
Yxy[1] = b * sl[0][1] + (1.0 - b) * sl[64][1];
Yxy[2] = b * sl[0][2] + (1.0 - b) * sl[64][2];
icmYxy2XYZ(XYZ, Yxy);
icmXYZ2Lab(&icmD50, Lab, XYZ);
gam->expand(gam, Lab);
for (e = 0; e < 3; e++) {
if (Lab[e] < low[e])
low[e] = Lab[e];
if (Lab[e] > high[e])
high[e] = Lab[e];
}
if ((Lab[1] * Lab[1] + Lab[2] * Lab[2]) > bc) {
bc = Lab[1] * Lab[1] + Lab[2] * Lab[2];
big[0] = Lab[0], big[1] = Lab[1], big[2] = Lab[2];
}
}
}
/* How to fill in less saturated, lighter area of gamut within */
/* our maximum monochrome level limit ? */
/* ~~~999 */
/* Fill in white point */
Lab[0] = 100.0;
Lab[1] = 0.0;
Lab[2] = 0.0;
gam->expand(gam, Lab);
printf("Bigest = %f %f %f\n",big[0],big[1],big[2]);
printf("Low = %f %f %f\n",low[0],low[1],low[2]);
printf("High = %f %f %f\n",high[0],high[1],high[2]);
if (gam->write_gam(gam, out_name))
error ("write gamut failed on '%s'",out_name);
gam->del(gam);
return 0;
}

93
Argyll_V3.5.0/gamut/Jamfile Executable file
View File

@@ -0,0 +1,93 @@
# Optimization and Debug flags
#PREF_CCFLAGS += $(CCOPTFLAG) ; # Turn optimisation on
PREF_CCFLAGS += $(CCDEBUGFLAG) ; # Debugging flags
#PREF_CCFLAGS += $(CCHEAPDEBUG) ; # Heap Debugging flags
PREF_LINKFLAGS += $(LINKDEBUGFLAG) ; # Link with debug info
#PREF_CCFLAGS += $(CCPROFFLAG) ; # Profile flags
#PREF_LINKFLAGS += $(LINKPROFFLAG) ; # Profile flags
#Products
Libraries = libgamut libgammap ;
Executables = viewgam ;
Samples = RefMediumGamut.gam ;
Headers = gammap.h gamut.h ;
#Install
InstallBin $(DESTDIR)$(PREFIX)/bin : $(Executables) ;
InstallFile $(DESTDIR)$(PREFIX)/$(REFSUBDIR) : $(Samples) ;
#InstallFile $(DESTDIR)$(PREFIX)/h : $(Headers) ;
#InstallLib $(DESTDIR)$(PREFIX)lib : $(Libraries) ;
# Header search path
HDRS = ../h ../icc ../rspl ../numlib ../plot ../xicc ../cgats ../spectro ../gamut ;
# Gamut handling library
Library libgamut : gamut.c ;
# Gamut mapping library
Library libgammap : gammap.c nearsmth.c ;
LINKLIBS = libgammap libgamut ../xicc/libxicc ../rspl/librspl ../icc/libicc ../cgats/libcgats
../plot/libplot ../numlib/libnum ../numlib/libui ../plot/libvrml ;
# Utilities
Main viewgam : viewgam.c ;
# Link all the tests and utils with these libraries
# Smoothed nearpoint test routine
Main smthtest : smthtest.c ;
# ICC V4 Reference Medium Gamut
Main GenRMGam : GenRMGam.c ;
# Generate reference medium gamut
# (NoUpdate so that Cross Compile Win64 hack works)
NNoUpdate RefMediumGamut.gam ;
GenFile RefMediumGamut.gam : GenRMGam ;
# Visual gamut
Main GenVisGam : GenVisGam.c ;
# Develop hue sensitive parameter interpolation */
#Main tttt : tttt.c ;
LINKLIBS = libgammap libgamut ../icc/libicc ../cgats/libcgats ../xicc/libxicc
../rspl/librspl ../plot/libplot ../plot/libvrml ../numlib/libnum ../numlib/libui ;
# Mapping test routine
Main maptest : maptest.c ;
# Fake test gamut generatio
Main fakegam : fakegam.c ;
# Surfacing test routine
Main surftest : surftest.c ;
# Filtering test cpde
#Main filt : filt.c ;
#Main tt : tt.c ;
if $(BUILD_JUNK) {
# Gamut creation test routine
Main gamtest : gamtest.c ;
# Group finding test.
Main gtest : gtest.c ;
# Test routine
Main test : test.c ;
Main tt : tt.c ;
# Atan aproximation test
Main xtan : xtan.c ;
# Bit vector class test
Main bvtest : bvtest.c ;
}

662
Argyll_V3.5.0/gamut/License.txt Executable file
View File

@@ -0,0 +1,662 @@
GNU AFFERO GENERAL PUBLIC LICENSE
Version 3, 19 November 2007
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
Preamble
The GNU Affero General Public License is a free, copyleft license for
software and other kinds of works, specifically designed to ensure
cooperation with the community in the case of network server software.
The licenses for most software and other practical works are designed
to take away your freedom to share and change the works. By contrast,
our General Public Licenses are intended to guarantee your freedom to
share and change all versions of a program--to make sure it remains free
software for all its users.
When we speak of free software, we are referring to freedom, not
price. Our General Public Licenses are designed to make sure that you
have the freedom to distribute copies of free software (and charge for
them if you wish), that you receive source code or can get it if you
want it, that you can change the software or use pieces of it in new
free programs, and that you know you can do these things.
Developers that use our General Public Licenses protect your rights
with two steps: (1) assert copyright on the software, and (2) offer
you this License which gives you legal permission to copy, distribute
and/or modify the software.
A secondary benefit of defending all users' freedom is that
improvements made in alternate versions of the program, if they
receive widespread use, become available for other developers to
incorporate. Many developers of free software are heartened and
encouraged by the resulting cooperation. However, in the case of
software used on network servers, this result may fail to come about.
The GNU General Public License permits making a modified version and
letting the public access it on a server without ever releasing its
source code to the public.
The GNU Affero General Public License is designed specifically to
ensure that, in such cases, the modified source code becomes available
to the community. It requires the operator of a network server to
provide the source code of the modified version running there to the
users of that server. Therefore, public use of a modified version, on
a publicly accessible server, gives the public access to the source
code of the modified version.
An older license, called the Affero General Public License and
published by Affero, was designed to accomplish similar goals. This is
a different license, not a version of the Affero GPL, but Affero has
released a new version of the Affero GPL which permits relicensing under
this license.
The precise terms and conditions for copying, distribution and
modification follow.
TERMS AND CONDITIONS
0. Definitions.
"This License" refers to version 3 of the GNU Affero General Public License.
"Copyright" also means copyright-like laws that apply to other kinds of
works, such as semiconductor masks.
"The Program" refers to any copyrightable work licensed under this
License. Each licensee is addressed as "you". "Licensees" and
"recipients" may be individuals or organizations.
To "modify" a work means to copy from or adapt all or part of the work
in a fashion requiring copyright permission, other than the making of an
exact copy. The resulting work is called a "modified version" of the
earlier work or a work "based on" the earlier work.
A "covered work" means either the unmodified Program or a work based
on the Program.
To "propagate" a work means to do anything with it that, without
permission, would make you directly or secondarily liable for
infringement under applicable copyright law, except executing it on a
computer or modifying a private copy. Propagation includes copying,
distribution (with or without modification), making available to the
public, and in some countries other activities as well.
To "convey" a work means any kind of propagation that enables other
parties to make or receive copies. Mere interaction with a user through
a computer network, with no transfer of a copy, is not conveying.
An interactive user interface displays "Appropriate Legal Notices"
to the extent that it includes a convenient and prominently visible
feature that (1) displays an appropriate copyright notice, and (2)
tells the user that there is no warranty for the work (except to the
extent that warranties are provided), that licensees may convey the
work under this License, and how to view a copy of this License. If
the interface presents a list of user commands or options, such as a
menu, a prominent item in the list meets this criterion.
1. Source Code.
The "source code" for a work means the preferred form of the work
for making modifications to it. "Object code" means any non-source
form of a work.
A "Standard Interface" means an interface that either is an official
standard defined by a recognized standards body, or, in the case of
interfaces specified for a particular programming language, one that
is widely used among developers working in that language.
The "System Libraries" of an executable work include anything, other
than the work as a whole, that (a) is included in the normal form of
packaging a Major Component, but which is not part of that Major
Component, and (b) serves only to enable use of the work with that
Major Component, or to implement a Standard Interface for which an
implementation is available to the public in source code form. A
"Major Component", in this context, means a major essential component
(kernel, window system, and so on) of the specific operating system
(if any) on which the executable work runs, or a compiler used to
produce the work, or an object code interpreter used to run it.
The "Corresponding Source" for a work in object code form means all
the source code needed to generate, install, and (for an executable
work) run the object code and to modify the work, including scripts to
control those activities. However, it does not include the work's
System Libraries, or general-purpose tools or generally available free
programs which are used unmodified in performing those activities but
which are not part of the work. For example, Corresponding Source
includes interface definition files associated with source files for
the work, and the source code for shared libraries and dynamically
linked subprograms that the work is specifically designed to require,
such as by intimate data communication or control flow between those
subprograms and other parts of the work.
The Corresponding Source need not include anything that users
can regenerate automatically from other parts of the Corresponding
Source.
The Corresponding Source for a work in source code form is that
same work.
2. Basic Permissions.
All rights granted under this License are granted for the term of
copyright on the Program, and are irrevocable provided the stated
conditions are met. This License explicitly affirms your unlimited
permission to run the unmodified Program. The output from running a
covered work is covered by this License only if the output, given its
content, constitutes a covered work. This License acknowledges your
rights of fair use or other equivalent, as provided by copyright law.
You may make, run and propagate covered works that you do not
convey, without conditions so long as your license otherwise remains
in force. You may convey covered works to others for the sole purpose
of having them make modifications exclusively for you, or provide you
with facilities for running those works, provided that you comply with
the terms of this License in conveying all material for which you do
not control copyright. Those thus making or running the covered works
for you must do so exclusively on your behalf, under your direction
and control, on terms that prohibit them from making any copies of
your copyrighted material outside their relationship with you.
Conveying under any other circumstances is permitted solely under
the conditions stated below. Sublicensing is not allowed; section 10
makes it unnecessary.
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
No covered work shall be deemed part of an effective technological
measure under any applicable law fulfilling obligations under article
11 of the WIPO copyright treaty adopted on 20 December 1996, or
similar laws prohibiting or restricting circumvention of such
measures.
When you convey a covered work, you waive any legal power to forbid
circumvention of technological measures to the extent such circumvention
is effected by exercising rights under this License with respect to
the covered work, and you disclaim any intention to limit operation or
modification of the work as a means of enforcing, against the work's
users, your or third parties' legal rights to forbid circumvention of
technological measures.
4. Conveying Verbatim Copies.
You may convey verbatim copies of the Program's source code as you
receive it, in any medium, provided that you conspicuously and
appropriately publish on each copy an appropriate copyright notice;
keep intact all notices stating that this License and any
non-permissive terms added in accord with section 7 apply to the code;
keep intact all notices of the absence of any warranty; and give all
recipients a copy of this License along with the Program.
You may charge any price or no price for each copy that you convey,
and you may offer support or warranty protection for a fee.
5. Conveying Modified Source Versions.
You may convey a work based on the Program, or the modifications to
produce it from the Program, in the form of source code under the
terms of section 4, provided that you also meet all of these conditions:
a) The work must carry prominent notices stating that you modified
it, and giving a relevant date.
b) The work must carry prominent notices stating that it is
released under this License and any conditions added under section
7. This requirement modifies the requirement in section 4 to
"keep intact all notices".
c) You must license the entire work, as a whole, under this
License to anyone who comes into possession of a copy. This
License will therefore apply, along with any applicable section 7
additional terms, to the whole of the work, and all its parts,
regardless of how they are packaged. This License gives no
permission to license the work in any other way, but it does not
invalidate such permission if you have separately received it.
d) If the work has interactive user interfaces, each must display
Appropriate Legal Notices; however, if the Program has interactive
interfaces that do not display Appropriate Legal Notices, your
work need not make them do so.
A compilation of a covered work with other separate and independent
works, which are not by their nature extensions of the covered work,
and which are not combined with it such as to form a larger program,
in or on a volume of a storage or distribution medium, is called an
"aggregate" if the compilation and its resulting copyright are not
used to limit the access or legal rights of the compilation's users
beyond what the individual works permit. Inclusion of a covered work
in an aggregate does not cause this License to apply to the other
parts of the aggregate.
6. Conveying Non-Source Forms.
You may convey a covered work in object code form under the terms
of sections 4 and 5, provided that you also convey the
machine-readable Corresponding Source under the terms of this License,
in one of these ways:
a) Convey the object code in, or embodied in, a physical product
(including a physical distribution medium), accompanied by the
Corresponding Source fixed on a durable physical medium
customarily used for software interchange.
b) Convey the object code in, or embodied in, a physical product
(including a physical distribution medium), accompanied by a
written offer, valid for at least three years and valid for as
long as you offer spare parts or customer support for that product
model, to give anyone who possesses the object code either (1) a
copy of the Corresponding Source for all the software in the
product that is covered by this License, on a durable physical
medium customarily used for software interchange, for a price no
more than your reasonable cost of physically performing this
conveying of source, or (2) access to copy the
Corresponding Source from a network server at no charge.
c) Convey individual copies of the object code with a copy of the
written offer to provide the Corresponding Source. This
alternative is allowed only occasionally and noncommercially, and
only if you received the object code with such an offer, in accord
with subsection 6b.
d) Convey the object code by offering access from a designated
place (gratis or for a charge), and offer equivalent access to the
Corresponding Source in the same way through the same place at no
further charge. You need not require recipients to copy the
Corresponding Source along with the object code. If the place to
copy the object code is a network server, the Corresponding Source
may be on a different server (operated by you or a third party)
that supports equivalent copying facilities, provided you maintain
clear directions next to the object code saying where to find the
Corresponding Source. Regardless of what server hosts the
Corresponding Source, you remain obligated to ensure that it is
available for as long as needed to satisfy these requirements.
e) Convey the object code using peer-to-peer transmission, provided
you inform other peers where the object code and Corresponding
Source of the work are being offered to the general public at no
charge under subsection 6d.
A separable portion of the object code, whose source code is excluded
from the Corresponding Source as a System Library, need not be
included in conveying the object code work.
A "User Product" is either (1) a "consumer product", which means any
tangible personal property which is normally used for personal, family,
or household purposes, or (2) anything designed or sold for incorporation
into a dwelling. In determining whether a product is a consumer product,
doubtful cases shall be resolved in favor of coverage. For a particular
product received by a particular user, "normally used" refers to a
typical or common use of that class of product, regardless of the status
of the particular user or of the way in which the particular user
actually uses, or expects or is expected to use, the product. A product
is a consumer product regardless of whether the product has substantial
commercial, industrial or non-consumer uses, unless such uses represent
the only significant mode of use of the product.
"Installation Information" for a User Product means any methods,
procedures, authorization keys, or other information required to install
and execute modified versions of a covered work in that User Product from
a modified version of its Corresponding Source. The information must
suffice to ensure that the continued functioning of the modified object
code is in no case prevented or interfered with solely because
modification has been made.
If you convey an object code work under this section in, or with, or
specifically for use in, a User Product, and the conveying occurs as
part of a transaction in which the right of possession and use of the
User Product is transferred to the recipient in perpetuity or for a
fixed term (regardless of how the transaction is characterized), the
Corresponding Source conveyed under this section must be accompanied
by the Installation Information. But this requirement does not apply
if neither you nor any third party retains the ability to install
modified object code on the User Product (for example, the work has
been installed in ROM).
The requirement to provide Installation Information does not include a
requirement to continue to provide support service, warranty, or updates
for a work that has been modified or installed by the recipient, or for
the User Product in which it has been modified or installed. Access to a
network may be denied when the modification itself materially and
adversely affects the operation of the network or violates the rules and
protocols for communication across the network.
Corresponding Source conveyed, and Installation Information provided,
in accord with this section must be in a format that is publicly
documented (and with an implementation available to the public in
source code form), and must require no special password or key for
unpacking, reading or copying.
7. Additional Terms.
"Additional permissions" are terms that supplement the terms of this
License by making exceptions from one or more of its conditions.
Additional permissions that are applicable to the entire Program shall
be treated as though they were included in this License, to the extent
that they are valid under applicable law. If additional permissions
apply only to part of the Program, that part may be used separately
under those permissions, but the entire Program remains governed by
this License without regard to the additional permissions.
When you convey a copy of a covered work, you may at your option
remove any additional permissions from that copy, or from any part of
it. (Additional permissions may be written to require their own
removal in certain cases when you modify the work.) You may place
additional permissions on material, added by you to a covered work,
for which you have or can give appropriate copyright permission.
Notwithstanding any other provision of this License, for material you
add to a covered work, you may (if authorized by the copyright holders of
that material) supplement the terms of this License with terms:
a) Disclaiming warranty or limiting liability differently from the
terms of sections 15 and 16 of this License; or
b) Requiring preservation of specified reasonable legal notices or
author attributions in that material or in the Appropriate Legal
Notices displayed by works containing it; or
c) Prohibiting misrepresentation of the origin of that material, or
requiring that modified versions of such material be marked in
reasonable ways as different from the original version; or
d) Limiting the use for publicity purposes of names of licensors or
authors of the material; or
e) Declining to grant rights under trademark law for use of some
trade names, trademarks, or service marks; or
f) Requiring indemnification of licensors and authors of that
material by anyone who conveys the material (or modified versions of
it) with contractual assumptions of liability to the recipient, for
any liability that these contractual assumptions directly impose on
those licensors and authors.
All other non-permissive additional terms are considered "further
restrictions" within the meaning of section 10. If the Program as you
received it, or any part of it, contains a notice stating that it is
governed by this License along with a term that is a further
restriction, you may remove that term. If a license document contains
a further restriction but permits relicensing or conveying under this
License, you may add to a covered work material governed by the terms
of that license document, provided that the further restriction does
not survive such relicensing or conveying.
If you add terms to a covered work in accord with this section, you
must place, in the relevant source files, a statement of the
additional terms that apply to those files, or a notice indicating
where to find the applicable terms.
Additional terms, permissive or non-permissive, may be stated in the
form of a separately written license, or stated as exceptions;
the above requirements apply either way.
8. Termination.
You may not propagate or modify a covered work except as expressly
provided under this License. Any attempt otherwise to propagate or
modify it is void, and will automatically terminate your rights under
this License (including any patent licenses granted under the third
paragraph of section 11).
However, if you cease all violation of this License, then your
license from a particular copyright holder is reinstated (a)
provisionally, unless and until the copyright holder explicitly and
finally terminates your license, and (b) permanently, if the copyright
holder fails to notify you of the violation by some reasonable means
prior to 60 days after the cessation.
Moreover, your license from a particular copyright holder is
reinstated permanently if the copyright holder notifies you of the
violation by some reasonable means, this is the first time you have
received notice of violation of this License (for any work) from that
copyright holder, and you cure the violation prior to 30 days after
your receipt of the notice.
Termination of your rights under this section does not terminate the
licenses of parties who have received copies or rights from you under
this License. If your rights have been terminated and not permanently
reinstated, you do not qualify to receive new licenses for the same
material under section 10.
9. Acceptance Not Required for Having Copies.
You are not required to accept this License in order to receive or
run a copy of the Program. Ancillary propagation of a covered work
occurring solely as a consequence of using peer-to-peer transmission
to receive a copy likewise does not require acceptance. However,
nothing other than this License grants you permission to propagate or
modify any covered work. These actions infringe copyright if you do
not accept this License. Therefore, by modifying or propagating a
covered work, you indicate your acceptance of this License to do so.
10. Automatic Licensing of Downstream Recipients.
Each time you convey a covered work, the recipient automatically
receives a license from the original licensors, to run, modify and
propagate that work, subject to this License. You are not responsible
for enforcing compliance by third parties with this License.
An "entity transaction" is a transaction transferring control of an
organization, or substantially all assets of one, or subdividing an
organization, or merging organizations. If propagation of a covered
work results from an entity transaction, each party to that
transaction who receives a copy of the work also receives whatever
licenses to the work the party's predecessor in interest had or could
give under the previous paragraph, plus a right to possession of the
Corresponding Source of the work from the predecessor in interest, if
the predecessor has it or can get it with reasonable efforts.
You may not impose any further restrictions on the exercise of the
rights granted or affirmed under this License. For example, you may
not impose a license fee, royalty, or other charge for exercise of
rights granted under this License, and you may not initiate litigation
(including a cross-claim or counterclaim in a lawsuit) alleging that
any patent claim is infringed by making, using, selling, offering for
sale, or importing the Program or any portion of it.
11. Patents.
A "contributor" is a copyright holder who authorizes use under this
License of the Program or a work on which the Program is based. The
work thus licensed is called the contributor's "contributor version".
A contributor's "essential patent claims" are all patent claims
owned or controlled by the contributor, whether already acquired or
hereafter acquired, that would be infringed by some manner, permitted
by this License, of making, using, or selling its contributor version,
but do not include claims that would be infringed only as a
consequence of further modification of the contributor version. For
purposes of this definition, "control" includes the right to grant
patent sublicenses in a manner consistent with the requirements of
this License.
Each contributor grants you a non-exclusive, worldwide, royalty-free
patent license under the contributor's essential patent claims, to
make, use, sell, offer for sale, import and otherwise run, modify and
propagate the contents of its contributor version.
In the following three paragraphs, a "patent license" is any express
agreement or commitment, however denominated, not to enforce a patent
(such as an express permission to practice a patent or covenant not to
sue for patent infringement). To "grant" such a patent license to a
party means to make such an agreement or commitment not to enforce a
patent against the party.
If you convey a covered work, knowingly relying on a patent license,
and the Corresponding Source of the work is not available for anyone
to copy, free of charge and under the terms of this License, through a
publicly available network server or other readily accessible means,
then you must either (1) cause the Corresponding Source to be so
available, or (2) arrange to deprive yourself of the benefit of the
patent license for this particular work, or (3) arrange, in a manner
consistent with the requirements of this License, to extend the patent
license to downstream recipients. "Knowingly relying" means you have
actual knowledge that, but for the patent license, your conveying the
covered work in a country, or your recipient's use of the covered work
in a country, would infringe one or more identifiable patents in that
country that you have reason to believe are valid.
If, pursuant to or in connection with a single transaction or
arrangement, you convey, or propagate by procuring conveyance of, a
covered work, and grant a patent license to some of the parties
receiving the covered work authorizing them to use, propagate, modify
or convey a specific copy of the covered work, then the patent license
you grant is automatically extended to all recipients of the covered
work and works based on it.
A patent license is "discriminatory" if it does not include within
the scope of its coverage, prohibits the exercise of, or is
conditioned on the non-exercise of one or more of the rights that are
specifically granted under this License. You may not convey a covered
work if you are a party to an arrangement with a third party that is
in the business of distributing software, under which you make payment
to the third party based on the extent of your activity of conveying
the work, and under which the third party grants, to any of the
parties who would receive the covered work from you, a discriminatory
patent license (a) in connection with copies of the covered work
conveyed by you (or copies made from those copies), or (b) primarily
for and in connection with specific products or compilations that
contain the covered work, unless you entered into that arrangement,
or that patent license was granted, prior to 28 March 2007.
Nothing in this License shall be construed as excluding or limiting
any implied license or other defenses to infringement that may
otherwise be available to you under applicable patent law.
12. No Surrender of Others' Freedom.
If conditions are imposed on you (whether by court order, agreement or
otherwise) that contradict the conditions of this License, they do not
excuse you from the conditions of this License. If you cannot convey a
covered work so as to satisfy simultaneously your obligations under this
License and any other pertinent obligations, then as a consequence you may
not convey it at all. For example, if you agree to terms that obligate you
to collect a royalty for further conveying from those to whom you convey
the Program, the only way you could satisfy both those terms and this
License would be to refrain entirely from conveying the Program.
13. Remote Network Interaction; Use with the GNU General Public License.
Notwithstanding any other provision of this License, if you modify the
Program, your modified version must prominently offer all users
interacting with it remotely through a computer network (if your version
supports such interaction) an opportunity to receive the Corresponding
Source of your version by providing access to the Corresponding Source
from a network server at no charge, through some standard or customary
means of facilitating copying of software. This Corresponding Source
shall include the Corresponding Source for any work covered by version 3
of the GNU General Public License that is incorporated pursuant to the
following paragraph.
Notwithstanding any other provision of this License, you have
permission to link or combine any covered work with a work licensed
under version 3 of the GNU General Public License into a single
combined work, and to convey the resulting work. The terms of this
License will continue to apply to the part which is the covered work,
but the work with which it is combined will remain governed by version
3 of the GNU General Public License.
14. Revised Versions of this License.
The Free Software Foundation may publish revised and/or new versions of
the GNU Affero General Public License from time to time. Such new versions
will be similar in spirit to the present version, but may differ in detail to
address new problems or concerns.
Each version is given a distinguishing version number. If the
Program specifies that a certain numbered version of the GNU Affero General
Public License "or any later version" applies to it, you have the
option of following the terms and conditions either of that numbered
version or of any later version published by the Free Software
Foundation. If the Program does not specify a version number of the
GNU Affero General Public License, you may choose any version ever published
by the Free Software Foundation.
If the Program specifies that a proxy can decide which future
versions of the GNU Affero General Public License can be used, that proxy's
public statement of acceptance of a version permanently authorizes you
to choose that version for the Program.
Later license versions may give you additional or different
permissions. However, no additional obligations are imposed on any
author or copyright holder as a result of your choosing to follow a
later version.
15. Disclaimer of Warranty.
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
16. Limitation of Liability.
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
SUCH DAMAGES.
17. Interpretation of Sections 15 and 16.
If the disclaimer of warranty and limitation of liability provided
above cannot be given local legal effect according to their terms,
reviewing courts shall apply local law that most closely approximates
an absolute waiver of all civil liability in connection with the
Program, unless a warranty or assumption of liability accompanies a
copy of the Program in return for a fee.
END OF TERMS AND CONDITIONS
How to Apply These Terms to Your New Programs
If you develop a new program, and you want it to be of the greatest
possible use to the public, the best way to achieve this is to make it
free software which everyone can redistribute and change under these terms.
To do so, attach the following notices to the program. It is safest
to attach them to the start of each source file to most effectively
state the exclusion of warranty; and each file should have at least
the "copyright" line and a pointer to where the full notice is found.
<one line to give the program's name and a brief idea of what it does.>
Copyright (C) <year> <name of author>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
Also add information on how to contact you by electronic and paper mail.
If your software can interact with users remotely through a computer
network, you should also make sure that it provides a way for users to
get its source. For example, if your program is a web application, its
interface could display a "Source" link that leads users to an archive
of the code. There are many ways you could offer source, and different
solutions will be better for different programs; see section 13 for the
specific requirements.
You should also get your employer (if you work as a programmer) or school,
if any, to sign a "copyright disclaimer" for the program, if necessary.
For more information on this, and how to apply and follow the GNU AGPL, see
<http://www.gnu.org/licenses/>.

25
Argyll_V3.5.0/gamut/Readme.txt Executable file
View File

@@ -0,0 +1,25 @@
This directory contains the gamut boundary
finding, and gamut mapping code.
It also contains utilities for generating
3D visualisations of gamut boundaries.
iccgamut:
Take an icc profile, and derive a gamut surface from one
of the forward or reverse transforms, using the desired
intent. Output the result as a CGATS format .gam file,
and optionaly as a VRML model file.
tiffgamut:
Take an tiff file and an icc profile, and derive a gamut
surface from the forward absolute profile and the tiff
image. Output the result as a CGATS format .gam file,
and optionaly as a VRML model file.
viewgam:
This program reads one or more CGATS format triangular gamut
surface descriptions (.gam), and combines them into a VRML file,
so that the gamuts can be visually compared.
Allowance is made for representing the gamuts as solid or
tranparent surfaces, wire frames, and coloring the gamut
with natural or uniform colors.

19
Argyll_V3.5.0/gamut/afiles Executable file
View File

@@ -0,0 +1,19 @@
Readme.txt
gammap.txt
License.txt
afiles
Jamfile
gamut.c
gamut.h
isecvol.c
viewgam.c
gammap.c
gammap.h
nearsmth.c
nearsmth.h
maptest.c
smthtest.c
surftest.c
fakegam.c
GenRMGam.c
GenVisGam.c

View File

@@ -0,0 +1,326 @@
/*
* Gamut test code. Generate a fake gamut surface
*
* Author: Graeme W. Gill
* Date: 23/10/2008
* Version: 1.00
*
* Copyright 2008, Graeme W. Gill
* All rights reserved.
*
* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :-
* see the License.txt file for licencing details.
*/
/* TTBD:
*
*/
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <fcntl.h>
#include <string.h>
#include <math.h>
#include "copyright.h"
#include "aconfig.h"
#include "numlib.h"
#include "cgats.h"
#include "gamut.h"
int get_value(double val[3]);
#define DEF_POINTS 10
void usage(char *diag) {
fprintf(stderr,"Generate a test gamut Version %s\n",ARGYLL_VERSION_STR);
fprintf(stderr,"Author: Graeme W. Gill, licensed under the AGPL Version 3\n");
fprintf(stderr,"usage: gamtest [options] outputname\n");
if (diag != NULL)
fprintf(stderr,"Diagnostic: %s\n",diag);
fprintf(stderr," -v Verbose\n");
fprintf(stderr," -n num Number of points to use (default %d)\n",DEF_POINTS);
fprintf(stderr," -c rad Create a cube\n");
fprintf(stderr," -p rad Create a sphere\n");
fprintf(stderr," -s w,d,h Create a sphereoid\n");
fprintf(stderr," -b w,d,h Create a box\n");
fprintf(stderr," -S nw,pw,nd,pd,nh,ph Create an asymetric sphereoid\n");
fprintf(stderr," -B nw,pw,nd,pd,nh,ph Create an asymetric box\n");
fprintf(stderr," -o x,y,z Offset the shape\n");
fprintf(stderr," -w Create WRL\n");
fprintf(stderr," -x No WRL axes\n");
fprintf(stderr,"\n");
exit(1);
}
int
main(int argc, char *argv[]) {
int fa,nfa; /* argument we're looking at */
static char *xl, out_name[MAXNAMEL+1];
int npoints = DEF_POINTS;
gamut *gam;
int shape = 1; /* 0 = sphereoid, 1 = box */
double bsize[6] = { 20.0, 20.0, 20.0, 20.0, 20.0, 20.0 }; /* box/spheroid size */
double goff[3] = { 0.0, 0.0, 0.0 }; /* Gamut position offset */
double co[3];
double wp[3] = { -1e6, 0.0, 0.0 }, bp[3] = { 1e6, 0.0, 0.0 };
int verb = 0;
int dowrl = 0;
int doaxes = 1;
int i;
#ifdef NUMSUP_H
error_program = "fakegam";
#endif
/* Process the arguments */
for(fa = 1;fa < argc;fa++) {
nfa = fa; /* skip to nfa if next argument is used */
if (argv[fa][0] == '-') { /* Look for any flags */
char *na = NULL; /* next argument after flag, null if none */
if (argv[fa][2] != '\000')
na = &argv[fa][2]; /* next is directly after flag */
else {
if ((fa+1) < argc) {
if (argv[fa+1][0] != '-') {
nfa = fa + 1;
na = argv[nfa]; /* next is seperate non-flag argument */
}
}
}
if (argv[fa][1] == '?')
usage(NULL);
/* Verbosity */
else if (argv[fa][1] == 'v' || argv[fa][1] == 'V') {
verb = 1;
}
/* VRML */
else if (argv[fa][1] == 'w' || argv[fa][1] == 'W') {
dowrl = 1;
}
/* No axis output */
else if (argv[fa][1] == 'x' || argv[fa][1] == 'X') {
doaxes = 0;
}
/* Sphere */
else if (argv[fa][1] == 'p') {
double radius;
fa = nfa;
if (na == NULL) usage("No parameter after flag -h");
radius = atof(na);
bsize[0] = bsize[2] = bsize[4] = 2.0 * radius;
bsize[1] = bsize[3] = bsize[5] = 2.0 * radius;
shape = 0;
}
/* Cube */
else if (argv[fa][1] == 'c' || argv[fa][1] == 'C') {
double radius;
fa = nfa;
if (na == NULL) usage("No parameter after flag -h");
radius = atof(na);
bsize[0] = bsize[2] = bsize[4] = 2.0 * radius;
bsize[1] = bsize[3] = bsize[5] = 2.0 * radius;
shape = 1;
}
/* Sphereoid */
else if (argv[fa][1] == 's') {
if (na == NULL) usage("Expect parameter to -b");
fa = nfa;
if (sscanf(na, " %lf , %lf , %lf ",&bsize[1], &bsize[3], &bsize[5]) == 3) {
bsize[0] = bsize[1];
bsize[2] = bsize[3];
bsize[4] = bsize[5];
} else
usage("Couldn't parse sphereoid size (-b) values");
shape = 0;
}
/* Box */
else if (argv[fa][1] == 'b') {
if (na == NULL) usage("Expect parameter to -b");
fa = nfa;
if (sscanf(na, " %lf , %lf , %lf ",&bsize[1], &bsize[3], &bsize[5]) == 3) {
bsize[0] = bsize[1];
bsize[2] = bsize[3];
bsize[4] = bsize[5];
} else
usage("Couldn't parse box size (-b) values");
shape = 1;
}
/* Asymetric Sphereoid */
else if (argv[fa][1] == 'S') {
if (na == NULL) usage("Expect parameter to -S");
fa = nfa;
if (sscanf(na, " %lf , %lf , %lf , %lf , %lf , %lf ",
&bsize[0], &bsize[1], &bsize[2], &bsize[3], &bsize[4], &bsize[5]) == 6) {
bsize[0] *= 2.0;
bsize[1] *= 2.0;
bsize[2] *= 2.0;
bsize[3] *= 2.0;
bsize[4] *= 2.0;
bsize[5] *= 2.0;
} else
usage("Couldn't parse sphereoid size (-S) values");
shape = 0;
}
/* Asymetric Box */
else if (argv[fa][1] == 'B') {
if (na == NULL) usage("Expect parameter to -B");
fa = nfa;
if (sscanf(na, " %lf , %lf , %lf , %lf , %lf , %lf ",
&bsize[0], &bsize[1], &bsize[2], &bsize[3], &bsize[4], &bsize[5]) == 6) {
bsize[0] *= 2.0;
bsize[1] *= 2.0;
bsize[2] *= 2.0;
bsize[3] *= 2.0;
bsize[4] *= 2.0;
bsize[5] *= 2.0;
} else
usage("Couldn't parse box size (-B) values");
shape = 1;
}
/* Number of construction points */
else if (argv[fa][1] == 'n' || argv[fa][1] == 'N') {
fa = nfa;
if (na == NULL) usage("No parameter after flag -t");
npoints = atoi(na);
}
/* Gamut offset */
else if (argv[fa][1] == 'o' || argv[fa][1] == 'O') {
if (na == NULL) usage("Expect parameter to -o");
fa = nfa;
if (sscanf(na, " %lf , %lf , %lf ",&goff[0], &goff[1], &goff[2]) == 3) {
} else
usage("Couldn't parse gamut offset (-o) value");
}
else
usage("Unknown flag");
} else
break;
}
if (fa >= argc || argv[fa][0] == '-') usage("Output filename expected");
strncpy(out_name,argv[fa++],MAXNAMEL); out_name[MAXNAMEL] = '\000';
if ((xl = strrchr(out_name, '.')) == NULL) { /* Add .gam extention if there isn't one */
xl = out_name + strlen(out_name);
strcpy(xl,".gam");
}
if (verb) {
printf("Number of construction points = %d\n",npoints * npoints * npoints);
}
/* Creat a gamut object */
if ((gam = new_gamut(5.0, 0, 0)) == NULL)
error("Failed to create aa gamut object\n");
/* Create and add our gridded test points */
for (co[0] = 0; co[0] < npoints; co[0]++) {
for (co[1] = 0; co[1] < npoints; co[1]++) {
for (co[2] = 0; co[2] < npoints; co[2]++) {
double pp[3], sum, rad;
int m, n;
/* Make sure at least one coords are 0 & 1 */
for (n = m = 0; m < 3; m++) {
if (co[m] == 0 || co[m] == (npoints-1))
n++;
}
if (n < 1)
continue;
if (shape == 0) { /* Sphereoid */
pp[0] = (co[0]/(npoints-1.0) - 0.5);
pp[1] = (co[1]/(npoints-1.0) - 0.5);
pp[2] = (co[2]/(npoints-1.0) - 0.5);
/* vector length */
for (sum = 0.0, m = 0; m < 3; m++) {
sum += pp[m] * pp[m];
}
if (sum < 1e-6)
continue;
sum = sqrt(sum);
/* Make sum of squares == 0.5 */
for (m = 0; m < 3; m++) {
pp[m] /= sum;
pp[m] *= 0.5;
}
/* And then scale it */
if (pp[0] < 0.0)
pp[0] = bsize[4] * pp[0];
else
pp[0] = bsize[5] * pp[0];
if (pp[1] < 0.0)
pp[1] = bsize[0] * pp[1];
else
pp[1] = bsize[1] * pp[1];
if (pp[2] < 0.0)
pp[2] = bsize[2] * pp[2];
else
pp[2] = bsize[3] * pp[2];
} else { /* Box */
if (co[0] < 0.0)
pp[0] = bsize[4] * (co[0]/(npoints-1.0) - 0.5);
else
pp[0] = bsize[4] * (co[0]/(npoints-1.0) - 0.5);
if (co[1] < 0.0)
pp[1] = bsize[0] * (co[1]/(npoints-1.0) - 0.5);
else
pp[1] = bsize[1] * (co[1]/(npoints-1.0) - 0.5);
if (co[2] < 0.0)
pp[2] = bsize[1] * (co[2]/(npoints-1.0) - 0.5);
else
pp[2] = bsize[2] * (co[2]/(npoints-1.0) - 0.5);
}
pp[0] += 50.0 + goff[2];
pp[1] += goff[0];
pp[2] += goff[1];
//printf("~1 point %f %f %f\n",pp[0],pp[1],pp[2]);
gam->expand(gam, pp);
if (pp[0] > wp[0])
wp[0] = pp[0];
if (pp[0] < bp[0])
bp[0] = pp[0];
}
}
}
gam->setwb(gam, wp, bp, NULL);
/* Write out the gamut */
if (gam->write_gam(gam, out_name))
error ("write gamut failed on '%s'",out_name);
if (dowrl) {
strcpy(xl,".wrl");
if (gam->write_vrml(gam, out_name, doaxes, 0))
error ("write vrml failed on '%s'",out_name);
}
if (verb)
printf("Written out the gamut surface\n");
gam->del(gam);
return 0;
}

2771
Argyll_V3.5.0/gamut/gammap.c Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,80 @@
#ifndef GAMMAP_H
#define GAMMAP_H
/*
* Argyll Gamut Mapping Library
*
* Author: Graeme W. Gill
* Date: 1/10/2000
* Version: 2.00
*
* Copyright 2000 - 2006 Graeme W. Gill
* All rights reserved.
*
* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :-
* see the License.txt file for licencing details.
*/
/* Gamut mapping object */
struct _gammap {
/* Private: */
int dbg; /* NZ to turn on debug messages */
/* neutral axis alignment transform applied to source: */
double grot[3][4]; /* Incoming grey axis rotation matrix */
double igrot[3][4]; /* Inverse of above */
rspl *grey; /* Forward L map */
rspl *igrey; /* Inverse L map */
/* Source to destination gamut map applied */
/* to transformed source: */
rspl *map; /* Rotated, L mapped Lab -> Lab gamut map */
double imin[3], imax[3]; /* Input range limits of map */
double cent[3]; /* Destination gamut center */
double tv[3]; /* Powell inversion target value */
/* Public: */
/* Methods */
void (*del)(struct _gammap *s); /* Free ourselves */
void (*domap)(struct _gammap *s, double *out, double *in); /* Do the mapping */
void (*inv_domap)(struct _gammap *s, double *out, double *in); /* Do the inverse mapping */
void (*invdomap1)(struct _gammap *s, double *out, double *in);
/* Do the inverse mapping using powell */
}; typedef struct _gammap gammap;
#ifdef NEVER /* This is decalared in xicc.h */
/* Method of black point adaptation */
typedef enum {
gmm_BPadpt = 0, /* Adapt source black point to destination */
gmm_noBPadpt = 1, /* Don't adapt black point to destination */
gmm_bendBP = 2, /* Don't adapt black point, bend it to dest. at end */
gmm_clipBP = 3 /* Don't adapt black point, clip it to dest. at end */
} gmm_BPmap;
#endif
/* Creator */
gammap *new_gammap(
int verb, /* Verbose flag */
gamut *sc_gam, /* Source colorspace gamut */
gamut *s_gam, /* Source image gamut (NULL if none) */
gamut *d_gam, /* Destination colorspace gamut */
icxGMappingIntent *gmi, /* Gamut mapping specification */
gamut *sh_gam, /* If not NULL, then use sc_gam for the luminence */
/* mapping, and sh_gam for the hull mapping (i.e. general compression) */
int src_kbp, /* Use K only black point as src gamut black point */
int dst_kbp, /* Use K only black point as dst gamut black point */
int dst_cmymap, /* masks C = 1, M = 2, Y = 4 to force 100% cusp map */
int rel_oride, /* 0 = normal, 1 = override min relative, 2 = max relative */
int mapres, /* Gamut map resolution, typically 9 - 33 */
double *mn, /* If not NULL, set minimum mapping input range */
double *mx, /* for rspl grid */
char *diagname /* If non-NULL, write a gamut mapping diagnostic WRL */
);
#endif /* GAMMAP_H */

259
Argyll_V3.5.0/gamut/gammap.txt Executable file
View File

@@ -0,0 +1,259 @@
Author: Graeme W. Gill
Date: 2000/10/28
Updated: 2006/1/17
Discussion of the gamut mapping algorithm used in Argyll:
Jam Morovic provides an extensive summary of previous Gamut Mapping Algoriths
(GMA) in his thesis "To Develop a Universal Gamut Mapping Algorithm".
Mark Fairchild and Gustav Braun also discuss some interesting aspects of
gamut mapping in "General-Purpose Gamut-Mapping Algorithms: Evaluation
of Contrast-Preserving Rescaling Functions for Color Gamut Mapping".
One thing that is striking in reading the current Gamut Mapping
literature, is the schism between gamut mapping, and gammut clipping.
A number of studies have indicated the satisfactory results from performing
gamut clipping by mapping out of gamut points to the closest point
within gamut, using a minumim delta E criteria. Ideally this would be
in a perceptually uniform space, and in practical spaces (ie L*a*b* space),
it appears a mapping that weightes luminance errors twice as much as
hue and saturation errors is the most satisfactory
(ie. Katoh & Ito 1996, Ebner & Fairchild 1997).
This approach makes perfect sense if the perceptually linear
delta E spaces is working as its should :- providing a means of
computing the minimal perceptual error between two colors.
Almost all the gamut mapping algorithms on the other hand, take a
completely different approach. They are dominated by algorithms with
appeal for their mathematical and algorithmic simplicity, rather than
any objective sense. Clipping along a line of constant hue, in a
particular direction, with some sort of compression along line
length curve seems to be a favourite.
My own experience with such an approach used for gamut clipping
shows up the logical flaws in this approach. In printed media, for
instance, the yellow dye tends to have a very sharp cusp in (say) Lab
space. When mapping along a line towards the neutral axis, it is almost
impossible to come up with a choice of line direction that
doesn't severly distort the clipped color. It is often extremely
de-saturated at the point the line hits the gamut boundary. Line
directions that take some account of the equivalent yellow cusp
in the target gamut improve the situation, but it seems highly
illogical to choosing an algorithm that gives a result with such
high delta E's, measured in any colorspace !
My conclusion is this: If we are working in a good perceptually
uniform space (ie. L*a*b*, Luv or CIECAM02), then we want to minimise
the delta E of the gamut mapped points at all times (this is the point
of using a perceptually uniform space !). This means that points
on the source gamut surface, should map to the target surface in
a very similar way to which they would be mapped using gamut clipping,
ie. minimum delta E. The distinction between gamut mapping and clipping
only becomes evident then, when we consider points that fall within
both gamuts. For pure gamut clipping, these points should not be
modified. For gamut mapping they should be modified in a way that
trades off increased absolute delta E, for reduced delta E relative
to surrounding colors.
[ Saturation intent brings some factors other than minimum
delta E into the picture, but minumum delta E is a good
starting point. ]
Gamut clipping should not be something separate to gamut mapping,
but should just be one extreme in a continuum of gamut mapping
choices.
A consideration revealed by Jam Morovic's work, is that it may be
desirable to treat colors on and close to the neutral axis a little
differently that those saturated colors near the gamut surface.
It seems desirable to align and compress the neutral axis to
give a good gray-scale mapping, as well as preserving the
relative colorimetry of low saturation colors.
Mark fairchild's work also indicates the desirablility of
trying to maintain the relative contrast of image data after
compression. This can be achieved by using a sigmoidal
mapping during compression (often called a soft knee compression
characteristic), rather than linear compression. Gamut
clipping can be considered to be an extreme example of
knee compression, where the knee is "hard".
A final consideration is how the various user intents are going
to be accomodated. One of the nice features of a consistent
clipping/compression approach is that many of the distinctions
between different intents seems to disappear.
Description of algorithms used:
The algorithm chosen here is (as far as I am aware) a new one,
that tries to combine all the considerations made above.
The gamut mapping is divided into two parts, mapping the luminance
axis orthogonally to other considerations, and then dealling
with any remaining gamut compression or expansion.
The basic transform mechanism is broken down into three part;
Aligning the neutral axes, mapping the luminence coordinate,
performing an overall 3D -> 3D mapping to compress and/or
expand the gamut surface. The rotation uses a matrix, the 1D -> 1D
luminence mapping uses a RSPL regular spline that is available
in Argyll, and the 3D -> 3D mapping also uses a RSPL.
By controlling the number, extent and strength of the sample
point mapping used to create the RSPL, it is possible to arrive
at a smooth mapping that has (controllable) areas of influence
between different regions, and can achieve sigmoid like "soft"
clipping curves.
Aligning the neutral axes.
The first step is to align the neutral axes. If the
colorspace used is an appearance space (Such as CIECAM02 Jab),
then the white points will already be close together, but may not
exactly cooincide. The black points will also probably differ.
There are a number of options for dealing with this. One
option would be to assume that people adapt to black points
the same way they adapt to the white points of a colorspace
or image. Research and experiemnce indicates that this
may not be the case though. If we assume that people
do not in general adapt to the black points of a colorspace,
then a consequence is that it is difficult to fully exploit
the full dynamic range of the colorspace, since a
source black that is misaligned with the destination black
will probably not be able to achieve as low a J value,
and this can noticably affect the percieved quality of
an image.
The compromise I deemed the best in Argyll, is to
assume that people do not adapt to black points,
and that therefore only the white points should be
aligned by rotating the source space around 0,0,0
to line them up. The minimum J value on the other hand,
is mapped as if the black points were being fully
adapted to, and at the point that the source
neutral axis would leave the destination gamut,
it is clipped to the destination.
This gives a neutral axis in the destination that looks
the same as that of the source, while fully exploiting the
dynamic range of the destination colorspace. Since
the departure of the mapped neutral axis from neutral
only occurs in very dark colors, its deviation is not
usually visible.
[ The code allows for 4 possible black point/neutral
axis mapping algorithm, set by the value of bph:
Adapt source black point to destination, giving full black range.
Don't adapt black point to destination, giving compromised black range.
Don't adapt black point, bend it to dest. at end, giving full black range.
Don't adapt black point, clip it to dest. at end, giving full black range.
]
Note that the black point mapping is performed by manipulating
J independently of the color components (a & b). In adapting
color from one space to another, this proves to be the correct
approach, maintaining the appearance of an image when
transformed to different device colorspaces.
This should not be confused with the situation where
optical flare or haze is being removed or simulated,
in which case the black point mapping should be done in a
linear light colorspace (such as XYZ), and will have an
effect simulaniously on lightness and saturation.
Mapping the luminence range.
The luminence mapping is acheived by created a small number of
mapping points, and then created a detailed RSPL (Regular Spline)
based on the points. The end points (which are heavily weighted
to ensure the overall range mapping is useful) are created
simply from the known J values of the source and destination
white and black points (taking into consuideration what
J values will result from possible gamut boundary clipping).
Middle points are introduced to either give a linear mapping (in J),
or to introduce a slight range compression aimed at preserving
the contrast ratio of the image.
Maping 3D gamut points.
The mapping points created for determinining the 3D compression or
expansioin are created from the source gamut surface verticies
that lie outside the destinatio gamut. The raw mapping for the
outside of the gamut is created by itterative optimisation,
that strikes a weighted balance between three different
factors: Mapping to the closest point on the destination surface,
Mapping in a way that is smoothly consistent with neighbour
mapping rays, and Mapping radially to the center of the colorspace.
By manipulating the weighting factors (held in a gammapweights
structure), it is possible to control to some degree the
nature of the gamut mapping.
Some compensation is applied to the vectors to try and counteract
the effects of the vector and (subsequent) RSPL smoothing.
This smoothing may cause the mapping to end up outside the
destination gamut, so we try and make sure that such smoothing
effects over rather than under-compress.
In addition to the suface mapping points, the 1D neutral axis
mapping is maintained by introducing a string of points
down the 3D neutral axis, to ensure that the 3D surface mappings
do not alter it.
Closer to the surface, optional "knee" mapping points
are also added, in an attempt to cause the inner
3D mapping to be more linear, with the compression (or
expansion) being concentrated near the surface of the
gamuts ("Sigma" compression).
Limitations and future challenges:
After re-working the gamut mapping in December 2005/January 2006,
the following challenges remain:
1) For saturation mapping in particular, the handling of hue
mapping using the "nearest" weighting isn't very flexible.
It's not possible to map RGB Cyan to CMYK Cyan without
introducing unacceptable side effects.
To solve this, I would have to add some extra mapping controls
and gamut information. For each gamut the 6 major "cusps" would
have to be identified (either directly from the colorant
combinations, or indrectly by locating the point on the gamut
surface with the largest C (?) in each hextant), and
then a means of warping the hue angle (and Luminence ??)
in each hextant.
The gammapweights structure would be expanded to add a weight
as to how much the source hue cusps would be distorted.
[Added to the code by Feb '06]
2) There is not much flexibility in what the gammapweights
weightings can achive. Some controls simply don't work
very well. Often increases in saturation in one area (at
the transitions between major colors) are bought at the
expense of the middle of the major colors becomming
very "flat" and desaturated. This is generally when we
are in a region in which the source gamut is within the
destination gamut.
3) Geting smoothness and saturation is very difficult
for some reason. The "relative error" weights do spread
things out, but at the cost of obvious banding (why ? -
possible answer - reflects the roughness of the gamut surface.
Solution is to use better algorithm for gamut surface extraction ?? ).
Increasing the 3D RSPL smoothness seems to have no
effect (why ?). Reducing absolute chroma weight improves
smoothness, but at the cost of reduced saturation and increased
lightness.

6930
Argyll_V3.5.0/gamut/gamut.c Normal file

File diff suppressed because it is too large Load Diff

420
Argyll_V3.5.0/gamut/gamut.h Normal file
View File

@@ -0,0 +1,420 @@
#ifndef GAMUT_H
#define GAMUT_H
/*
* gamut
*
* Gamut support routines.
*
* Author: Graeme W. Gill
* Date: 9/3/2000
* Version: 1.00
*
* Copyright 2000-2006 Graeme W. Gill
* All rights reserved.
*
* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :-
* see the License.txt file for licencing details.
*/
/*
Note that the input and output are expected to be Lab style
color coordinates, and that L->Z, a->X, b->Y.
*/
#include "../h/llist.h"
#define BSPDEPTH 100 /* Maximum BSP tree depth */
#define PFARNDIST 0.1 /* Positive (inwards) far "near" distance */
#define NFARNDIST -200.0 /* Negative (outwards) far "near" distance */
#define MFARNDIST PFARNDIST /* Minimum (absolute) of the two */
#define MAXGAMN 10 /* Maximum gamut point neighbors returned */
#define NSLOTS 6 /* Number of maximum direction slots */
struct _vrml; /* Declared in vrml.h, which may be #included after this */
/* ------------------------------------ */
#define NODE_STRUCT \
int tag; /* Type of node, 1 = vertex, 2 = quad */ \
double w, h; /* longitude width, latitude height of this box */ \
double hc, vc; /* longitude center, latitude center of this box */ \
struct _gnode {
NODE_STRUCT
}; typedef struct _gnode gnode;
/* ------------------------------------ */
/* Vertex node */
struct _gvert {
NODE_STRUCT
int rc; /* reference count */
struct _gvert *ul; /* Unused list */
int n; /* Index number of vertex */
int sn; /* Set Index number of vertex */
int tn; /* Triangulated Index number of vertex */
int f; /* Flag value */
#define GVERT_NONE 0x0000 /* No flags */
#define GVERT_SET 0x0001 /* Value has been set */
#define GVERT_TRI 0x0002 /* Vertex has been added to triangulation (Exclsv with _INSIDE) */
#define GVERT_INSIDE 0x0004 /* Vertex is inside the log hull (Exclusive with _TRI) */
#define GVERT_ISOS 0x0008 /* Intersecting gamuts "outside other gamut" flag */
#define GVERT_ESTP 0x0010 /* Non-fake establishment point */
#define GVERT_FAKE 0x0020 /* Fake establishment point */
int k0; /* k0 direction reference count */
double p[3]; /* Point in xyz rectangular coordinates, absolute */
double r[3]; /* Radial coordinates */
double lr0; /* log scaled r[0] */
double sp[3]; /* Point mapped to surface of unit sphere, relative to center */
double ch[3]; /* Point mapped for convex hull testing, relative to center */
int as; /* Assert checking flag, expdstbysrcmdst flag */
}; typedef struct _gvert gvert;
/* ------------------------------------ */
/* Quadtree node */
struct _gquad {
NODE_STRUCT
gnode *qt[4][NSLOTS];
/* Child nodes, NULL if none, */
/* Nodes are ordered: */
/* --------- */
/* | 2 | 3 | */
/* --------- */
/* | 0 | 1 | */
/* --------- */
/* and each node contains NSLOTS slots. */
/* If the quadtree recurses, the first slot containts another */
/* quadtree, otherwise the slots contain pointers to the */
/* four best vertices in the various directions. */
}; typedef struct _gquad gquad;
/* ------------------------------------ */
/* Common base class of BSP nodes */
#define BSP_STRUCT \
int tag; /* Type of node, 1 = bsp node, 2 = triangle, 3 = list */ \
double rs0, rs1; /* min/max radius squared from origin of all contained triangles */
struct _gbsp {
BSP_STRUCT
}; typedef struct _gbsp gbsp;
/* ------------------------------------ */
/* A BSP tree decision node */
struct _gbspn {
BSP_STRUCT
int n; /* Serial number */
double pe[4]; /* Plane equation values (center relative) */
struct _gbsp *po; /* Positive branch */
struct _gbsp *ne; /* Negative branch */
}; typedef struct _gbspn gbspn;
/* ------------------------------------ */
/* A BSP tree triangle list node */
struct _gbspl {
BSP_STRUCT
int n; /* Serial number */
int nt; /* Number of triangles in the list */
struct _gtri *t[]; /* List of triangles - allocated with struct */
}; typedef struct _gbspl gbspl;
/* ------------------------------------ */
/* A triangle in the surface mesh */
struct _gtri {
BSP_STRUCT
int n; /* Serial number */
struct _gvert *v[3]; /* Vertices in cw order */
struct _gedge *e[3]; /* Edges v[n] - v[n+1] */
int ei[3]; /* Index within edge structure of this triangle [0..1] */
double pe[4]; /* Vertex plane equation (absolute) */
/* (The first three elements is the unit normal vector to the plane, */
/* which points inwards) */
double che[4]; /* convex hull testing triangle plane equation (relative) */
double spe[4]; /* sphere mapped triangle plane equation (relative) */
double ee[3][4]; /* sphere sp[] Edge triangle plane equations for opposite edge (relative) */
int sort; /* lookup: Plane sorting result for each try */
int bsort; /* lookup: Current best tries sort */
unsigned int touch; /* nn: Per value touch count */
double mix[2][3]; /* nn: Bounding box min and max */
double area; /* Area - computed by nssverts() */
int ssverts; /* Number of stratified sampling verts needed - computed by nssverts() */
LINKSTRUCT(struct _gtri); /* Linked list structure */
}; typedef struct _gtri gtri;
/* ------------------------------------ */
/* An edge shared by two triangle in the mesh */
struct _gedge {
int n; /* Serial number */
struct _gvert *v[2]; /* Vertices of edge */
struct _gtri *t[2]; /* Triangles edge is part of */
int ti[2]; /* record of indexes of edge within the triangles [0..2]*/
double re[4]; /* Radial edge plane equation (relative) */
int as; /* Assert checking flag */
LINKSTRUCT(struct _gedge); /* Linked list structure */
}; typedef struct _gedge gedge;
/* ------------------------------------ */
/* The gamut nearest neighbor search structure */
struct _gnn {
struct _gamut *s; /* Base gamut object */
int n; /* Number of points stored */
gtri **sax[3 * 2]; /* Sorted axis pointers, one for each direction */
unsigned int tbase; /* Touch base value for this pass */
unsigned int ttarget; /* Touch target value for this pass */
}; typedef struct _gnn gnn;
/* ------------------------------------ */
/* A vector intersction point */
struct _gispnt {
double ip[3]; /* Intersecion Point */
double pv; /* Parameter value at intersection */
int dir; /* Direction: 1 = into gamut, 0 = out of gamut */
int edge; /* Edge: 2 = no isect, 1 = on edge, 0 = not on edge */
gtri *tri; /* Pointer to intersection triangle */
}; typedef struct _gispnt gispnt;
/* Gamut object */
struct _gamut {
/* Private: */
double sres; /* Surface triangle resolution */
int isJab; /* nz if Jab CIECAM02 type space rather than L*a*b* */
int isRast; /* nz if raster file point cloud, else colorspace */
/* (This affects convex hull filtering) */
double cent[3]; /* Gamut center for radial conversion. Default 50.0,0,0 */
/* Must be same to compare radial values. */
int nv; /* Number of vertices used out of allocation */
gvert *ul; /* Linked list of unused vertices */
int na; /* Number of vertices allocated */
int nsv; /* Number of vertices that have been set */
int ntv; /* Number of vertices used in triangulation */
gvert **verts; /* Pointers to allocated vertices */
int read_inited; /* Flag set if gamut was initialised from a read */
int lu_inited; /* Flag set if radial surface lookup is inited */
int ne_inited; /* Flag set if nearest lookup is inited */
int cu_inited; /* Flag set if cusp values inited and trustworthy */
int nofilter; /* Flag, skip segmented maxima filtering */
int no2pass; /* Flag, do only one pass of convex hull */
int doingfake; /* Internal transient state */
int pass; /* Pass number for multi-pass */
double logpow; /* Convex hull compression power (default 0.25) */
gquad *tl, *tr; /* Top left and quadtree elements */
gtri *tris; /* Surface triangles linked list */
gedge *edges; /* Edges between the triangles linked list */
gbsp *lutree; /* Lookup function BSP tree root */
gnn *nns; /* nearest neighbor acceleration structure */
int cswbset; /* Flag to indicate that the cs white & black points are set */
double cs_wp[3]; /* Color spaces white point */
double cs_bp[3]; /* Color spaces black point */
double cs_kp[3]; /* Color spaces K only black point */
int gawbset; /* Flag to indicate that the gamut white & black points are set */
double ga_wp[3]; /* Gamut white point */
double ga_bp[3]; /* Gamut black point */
double ga_kp[3]; /* Gamut K only black point */
int dcuspixs; /* Cusp we're up to */
double dcusps[6][3];/* Entered cusp values to setcusps(, 3, ) */
double cusps[6][3]; /* Cusp values for red, yellow, green, cyan, blue & magenta */
/* if cu_inited nz */
double mx[3], mn[3]; /* Range covered by input points */
double xvra; /* Extra vertex ratio - set/used by nssverts() */
int ssnverts; /* total ss vertices - set/used by nssverts() */
int ssvertn; /* Number of verts created for current triangle */
sobol *ss; /* Sobol ss generator currently being used */
gtri *nexttri; /* Context for getnexttri() */
/* Public: */
/* Methods */
void (*del)(struct _gamut *s); /* Free ourselves */
gvert *(*expand)(struct _gamut *s, double in[3]); /* Expand the gamut surface */
void (*set_cs_bp_kp_ovrd)(struct _gamut *s, double *bk, double *kp); /* Override cs black points */
int (*getisjab)(struct _gamut *s); /* Return the isJab flag value */
int (*getisrast)(struct _gamut *s); /* Return the isRast flag value */
void (*setnofilt)(struct _gamut *s); /* Disable segmented maxima filtering */
void (*getcent)(struct _gamut *s, double *cent); /* Return the gamut center location */
void (*getrange)(struct _gamut *s, double *min, double *max); /* Return the gamut range */
double (*getsres)(struct _gamut *s); /* Return the surface resolution */
int (*compatible)(struct _gamut *s, struct _gamut *t); /* Return the nz if compatible gamuts */
int (*nrawverts)(struct _gamut *s); /* Return the number of raw vertices */
int (*getrawvert)(struct _gamut *s, double pos[3], int ix);
/* Return the raw vertices location */
int (*nraw0verts)(struct _gamut *s); /* Return the number of raw vertices in */
/* the radial maxima direction*/
int (*getraw0vert)(struct _gamut *s, double pos[3], int ix);
/* Return the raw 0 direction vertices location */
int (*nverts)(struct _gamut *s); /* Return the number of surface vertices */
int (*getvert)(struct _gamut *s, double *rad, double pos[3], int ix);
/* Return the surface triangle vertices location and radius */
/* start at 0, and returns value is next index or -1 if last */
/* rad and/or pos may be NULL */
int (*nssverts)(struct _gamut *s, double vpua);
/* Return the number of stratified sampling surface vertices, */
/* for the given vertices per unit area parameter. */
int (*getssvert)(struct _gamut *s, double *rad, double pos[3], double norn[3], int ix);
/* Return the stratified sampling surface vertices */
/* location and radius. nssverts() sets vpua */
/* norm will contain the normal of the triangle */
/* the point originates from. */
void (*startnexttri)(struct _gamut *s); /* Reset indexing through triangles for getnexttri() */
int (*getnexttri)(struct _gamut *s, int v[3]);
/* Return the next surface triange, nz on no more */
/* Index v[] corresponds to order of getvert() */
double (*volume)(struct _gamut *s);
/* Return the total volume enclosed by the gamut */
int (*intersect)(struct _gamut *s, struct _gamut *s1, struct _gamut *s2);
/* Initialise this gamut with the intersection of the */
/* the two given gamuts. */
int (*exp_cyl)(struct _gamut *s, struct _gamut *s1, double ratio);
/* Initialise this gamut with the source gamut */
/* expanded cylindrically around the nautral axis by */
/* the given ratio. */
int (*nexpintersect)(struct _gamut *s, struct _gamut *s1, struct _gamut *s2);
/* Initialise this gamut with neutral axis points from sa, */
/* and then intersected with sb. */
int (*expdstbysrcmdst)(struct _gamut *s,
struct _gamut *dst, struct _gamut *sc, struct _gamut *dc,
void (*cvect)(void *cntx, double *p2, double *p1), void *cntx);
/* Expand dst by ((dc - sc) > 0) */
/* Initialise this gamut with the image/destination gamut sc */
/* expanded by the amount that dest (dc) colorspace is outside */
/* the source colorspace gamut. */
double (*radial)(struct _gamut *s, double out[3], double in[3]);
/* return point on surface in same radial direction. */
/* Return the radial radius to the surface point in */
/* colorspace units. out[] may be NULL */
double (*nradial)(struct _gamut *s, double out[3], double in[3]);
/* return point on surface in same radial direction, */
/* and normalised radial radius. This will be <= 1.0 if within */
/* gamut, and > 1.0 if out of gamut. out[] may be NULL */
void (*nearest)(struct _gamut *s, double out[3], double in[3]);
/* return point on surface closest to input */
void (*nearest_tri)(struct _gamut *s, double out[3], double in[3], gtri **ctri);
/* return point on surface closest to input & triangle */
int (*vector_isect)(struct _gamut *s, double *p1, double *p2, double *min, double *max,
double *mint, double *maxt,
gtri **mntri, gtri **mxtri);
/* Compute the intersection of the (extended to infinity) vector */
/* p1->p2 with the gamut surface. */
/* min is the intersection in the p1 direction, */
/* max is intersection in the p2 direction. mint and maxt are */
/* the parameter values at the two intersection points, a value of 0 */
/* being at p1 and 1 being at p2. mintri and maxtri return the */
/* intersection triangles. min, max, mint, maxt, */
/* mintri & maxtri may be NULL */
/* Return 0 if there is no intersection with the gamut. */
int (*vector_isectns)(struct _gamut *s, double *p1, double *p2, gispnt *lp, int ll);
/* Compute all the intersection pairs of the vector p1->p2 with */
/* the gamut surface. lp points to an array of ll gispnt to be */
/* filled in. If the list is too small, intersections will be */
/* arbitrarily ignored. */
/* Return the number of intersections set in list. Will be even. */
/* These will all be in then out pairs in direction p1->p2. */
void (*setwb)(struct _gamut *s, double *wp, double *bp, double *kp);
/* Define the colorspaces white, black and K only black points. */
/* May be NULL if unknown, and will be set to a default. */
/* Same colorspace as gamut */
int (*getwb)(struct _gamut *s, double *cswp, double *csbp, double *cskp,
double *gawp, double *gabp, double *gakp);
/* Get the colorspace and gamut white, black and K only black points. */
/* Return non-zero if not possible. Same colorspace as gamut */
void (*setcusps)(struct _gamut *s, int flag, double in[3]); /* Set potential cusp values. */
/* flag == 0 = reset, */
/* flag == 1 = add general point, */
/* flag == 3 = add definite point, */
/* flag == 2 = finish */
int (*getcusps)(struct _gamut *s, double cusps[6][3]); /* Get the cusp values for */
/* red, yellow, green, cyan, */
/* blue & magenta. Return */
/* nz if no cusps available. */
/* Following return nz on error: */
int (*write_to_vrml)(struct _gamut *s, struct _vrml *wrl, double trans, int docusps);
/* Append gamut surface to vrml. See also vrml->make_gamut_surface() etc. */
int (*write_vrml)(struct _gamut *s, char *filename,
int doaxes, int docusps); /* Write to a VRML .wrl/.x3d file */
int (*write_gam)(struct _gamut *s, char *filename); /* Write to a CGATS .gam file */
int (*read_gam)(struct _gamut *s, char *filename); /* Read from a CGATS .gam file */
int (*read_gam_fp)(struct _gamut *s, cgatsFile *fp, char *filename); /* Read using fp */
int (*write_trans_vrml)(struct _gamut *s, char *filename, /* Write transformed VRML/X3D .wrl */
int doaxes, int docusps, void (*transform)(void *cntx, double out[3], double in[3]), /* with xform */
void *cntx);
}; typedef struct _gamut gamut;
/* Creator */
gamut *new_gamut(double sres, int isJab, int isRast); /* Surface resolution, 0.0 = default */
/* Utility */
void gamut_rect2radial(gamut *s, double out[3], double in[3]);
void gamut_radial2rect(gamut *s, double out[3], double in[3]);
void gamut_Lab2RGB(double *in, double *out);
extern double gam_hues[2][7]; /* Generic Lab & Jab color hues in degrees */
#endif /* GAMUT_H */

View File

@@ -0,0 +1,320 @@
/*
* Compute the intersection volume of two gamuts.
*
* Author: Graeme W. Gill
* Date: 2008/1/7
* Version: 1.00
*
* Copyright 2008 Graeme W. Gill
* All rights reserved.
* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :-
* see the License.txt file for licencing details.
*/
/*
* TTBD:
*
*/
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <fcntl.h>
#include <string.h>
#include <math.h>
#include "icc.h"
#include "numlib.h"
#include "gamut.h"
/* Compute a triangles area */
static double tri_area(
double v1[3],
double v2[3],
double v3[3]) {
int i, j;
double sp, ss[3]; /* Triangle side lengths */
double area; /* Area of this triangle */
double *vv[3]; /* Pointers to vertexes */
vv[0] = v1;
vv[1] = v2;
vv[2] = v3;
/* Compute the full triangles area */
for (i = 0; i < 3; i++) { /* For each edge */
for (ss[i] = 0.0, j = 0; j < 3; j++) {
double dd = vv[i][j] - vv[(i+1) % 3][j];
ss[i] += dd * dd;
}
ss[i] = sqrt(ss[i]);
}
sp = 0.5 * (ss[0] + ss[1] + ss[2]); /* semi-perimeter */
area = sqrt(fabs(sp * (sp - ss[0]) * (sp - ss[1]) * (sp - ss[2]))); /* Area of triangle */
return area;
}
/* See if the given edge intersects a given triangle. */
/* Return 1 if it does, 0 if it doesn't */
static int edge_tri_isect(
gamut *s, /* Gamut the triangle is in */
double *ip, /* return intersection point */
gtri *t, /* Triangle in question */
gedge *e /* edge to test (may be from another gamut) */
) {
double rv; /* Axis parameter value */
double gv[3]; /* Grey axis vector */
double ival[3]; /* Intersection value */
double den;
int j;
gv[0] = e->v[1]->p[0] - e->v[0]->p[0];
gv[1] = e->v[1]->p[1] - e->v[0]->p[1];
gv[2] = e->v[1]->p[2] - e->v[0]->p[2];
den = t->pe[0] * gv[0] + t->pe[1] * gv[1] + t->pe[2] * gv[2];
if (fabs(den) < 1e-10) {
return 0;
}
/* Compute the intersection of the grey axis vector with the triangle plane */
rv = -(t->pe[0] * e->v[0]->p[0]
+ t->pe[1] * e->v[0]->p[1]
+ t->pe[2] * e->v[0]->p[2]
+ t->pe[3])/den;
/* Compute the actual intersection point */
ival[0] = e->v[0]->p[0] + rv * gv[0];
ival[1] = e->v[0]->p[1] + rv * gv[1];
ival[2] = e->v[0]->p[2] + rv * gv[2];
/* Check if the intersection is on the edge */
if (rv < 0.0 || rv > 1.0)
return 0;
/* Check if the intersection point is within the triangle */
for (j = 0; j < 3; j++) {
double ds;
ds = t->ee[j][0] * (ival[0] - s->cent[0]) /* Convert to relative for edge check */
+ t->ee[j][1] * (ival[1] - s->cent[1])
+ t->ee[j][2] * (ival[2] - s->cent[2])
+ t->ee[j][3];
if (ds > 1e-8) {
return 0; /* Not within triangle */
}
}
/* Got an intersection point */
ip[0] = ival[0];
ip[1] = ival[1];
ip[2] = ival[2];
return 1;
}
/* Return the total volume of the gamut */
/* Return -1.0 if incompatible gamuts */
double isect_volume(
gamut *s1,
gamut *s2
) {
int i, j, k;
gtri *tp1, *tp2; /* Triangle pointer */
double vol; /* Gamut volume */
if (s1->compatible(s1, s2) == 0)
return -1.0;
if IS_LIST_EMPTY(s1->tris)
s1->triangulate(s1);
if IS_LIST_EMPTY(s2->tris)
s2->triangulate(s2);
vol = 0.0;
/* For first gamut then second gamut */
for (k = 0; k < 2; k++) {
if (k == 1) { /* Swap the two gamuts roles */
gamut *st = s1;
s1 = s2;
s2 = st;
printf("~1 doing second gamut inside first\n");
} else {
printf("~1 doing first gamut inside second\n");
}
/* Compute the area of each triangle in the list that is within, */
/* the other gamut, and accumulate the gamut volume. */
tp1 = s1->tris;
FOR_ALL_ITEMS(gtri, tp1) {
double sp, ss[3]; /* Triangle side lengths */
double area; /* Area of this triangle */
double dp; /* Dot product of point in triangle and normal */
int inout[3]; /* 0 = inside, 1 = outside */
int nout; /* Number that are out */
printf("~1 doing triangle %d from %s gamut\n",tp1->n,k == 0 ? "first" : "second");
/* See how many vertices in the triangle are contained within */
/* the other gamut. */
nout = 0;
for (i = 0; i < 3; i++) { /* For each vertex */
double pl;
pl = s2->nradial(s2, NULL, tp1->v[i]->p);
/* We add a slight hysterysis to avoid issues */
/* with identical triangles in two gamuts. */
if ((k == 0 && pl > (1.0 + 1e-10))
|| (k == 1 && pl > (1.0 - 1e-10))) {
nout++;
inout[i] = 1;
} else
inout[i] = 0;
}
printf("~1 vertices outside = %d\n",nout);
/* If none are in, skip this triangle */
if (nout == 3)
continue;
/* Compute the full triangles area */
area = tri_area(tp1->v[0]->p, tp1->v[1]->p, tp1->v[2]->p);
printf("~1 full triangle area = %f\n",area);
/* If the triangle is not completely in, locate all the intersections */
/* between it and triangles in the other gamut */
if (nout != 0) {
gvert *opv; /* Pointer to the one "in" or "out" vertex */
double parea = 0.0; /* Total partial area */
/* Locate the odd point out of the three */
if (nout == 2) { /* Look for the one "in" point */
for (j = 0; j < 3; j++) {
if (inout[j] == 0)
break;
}
} else { /* Look for the one "out" point */
for (j = 0; j < 3; j++) {
if (inout[j] == 1)
break;
}
}
opv = tp1->v[j];
tp2 = s2->tris;
FOR_ALL_ITEMS(gtri, tp2) { /* Other gamut triangles */
double isps[2][3]; /* Intersection npoints */
int nisps; /* Number of intersection points */
double isp[3]; /* New intersection point */
int kk;
/* Do a min/max intersection elimination test */
for (i = 0; i < 3; i++) {
if (tp2->mix[1][i] < tp1->mix[0][i]
|| tp2->mix[0][i] > tp1->mix[1][i])
break; /* min/max don't overlap */
}
if (i < 3)
continue; /* Skip this triangle, it can't intersect */
//printf("~1 located possible intersecting triangle %d\n",tp2->n);
/* Locate intersection of all sides of one triangle with */
/* the plane of the other. Keep the two points of */
/* intersection that lie within the triangles. */
nisps = 0;
//printf("~1 initial nisps = %d\n",nisps);
for (kk = 0; kk < 2; kk++) {
gamut *ts; /* Triangle gamut */
gtri *tpa; /* Triangle pointer */
gtri *tpb; /* Other triangle pointer */
if (kk == 0) {
ts = s1;
tpa = tp1;
tpb = tp2;
} else {
ts = s2;
tpa = tp2;
tpb = tp1;
}
/* For each edge */
for (j = 0; j < 3; j++) {
if (edge_tri_isect(ts, isp, tpa, tpb->e[j]) != 0) {
//printf("~1 isect %f %f %f\n", isp[0],isp[1],isp[2]);
if (nisps < 2) {
//printf("~1 added at %d\n",nisps);
icmAry2Ary(isps[nisps], isp);
nisps++;
} else { /* Figure which one to replace */
int xx;
/* Replace the one closest to the new one, */
/* if the new one is further from the other one */
if (icmNorm33sq(isps[0], isp) < icmNorm33sq(isps[1], isp))
xx = 0;
else
xx = 1;
if (icmNorm33sq(isps[xx ^ 1], isp)
> icmNorm33sq(isps[xx ^ 1], isps[xx])) {
//printf("~1 replaced %d\n",xx);
icmAry2Ary(isps[xx], isp);
}
}
}
}
}
if (nisps == 0) {
//printf("~1 no intersection\n");
continue;
} else if (nisps == 2) {
double sarea;
printf("~1 sub triangle =\n");
printf("~1 com %f %f %f\n", opv->p[0], opv->p[1], opv->p[2]);
printf("~1 1st %f %f %f\n", isps[0][0], isps[0][1], isps[0][2]);
printf("~1 2nd %f %f %f\n", isps[1][0], isps[1][1], isps[1][2]);
/* Accumulate area of these two points + odd point */
sarea = tri_area(opv->p, isps[0], isps[1]);
printf("~1 located intersecting triangle %d\n",tp2->n);
printf("~1 got sub area %f\n",sarea);
parea += sarea;
} else { /* Hmm */
printf("~1 unexpectedly got %d intersection points in triangle\n",nisps);
}
} END_FOR_ALL_ITEMS(tp2);
if (nout == 2) { /* One "in" point */
area = parea;
} else { /* One "out" point */
area = area - parea;
}
printf("~1 partial area = %f\n",area);
}
/* Dot product between first vertex in triangle and the unit normal vector */
dp = tp1->v[0]->p[0] * tp1->pe[0]
+ tp1->v[0]->p[1] * tp1->pe[1]
+ tp1->v[0]->p[2] * tp1->pe[2];
printf("~1 vector volume = %f\n",dp * area);
/* Accumulate gamut volume */
vol += dp * area;
} END_FOR_ALL_ITEMS(tp1);
}
printf("~1 volume sum = %f\n",vol);
vol = fabs(vol)/3.0;
printf("~1 final volume = %f\n",vol);
return vol;
}

View File

@@ -0,0 +1,248 @@
/*
* Gamut mapping test code. Test the gamut mapping library.
*
* Author: Graeme W. Gill
* Date: 29/10/00
* Version: 1.00
*
* Copyright 2000, Graeme W. Gill
* All rights reserved.
*
* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :-
* see the License.txt file for licencing details.
*/
/* TTBD:
*
*/
#undef DEBUG /* test a single value out */
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <fcntl.h>
#include <string.h>
#include <math.h>
#include "copyright.h"
#include "aconfig.h"
#include "numlib.h"
#include "conv.h"
#include "xicc.h"
#include "gamut.h"
#include "rspl.h"
#include "gammap.h"
#include "vrml.h"
void usage(void) {
fprintf(stderr,"Map bteween two gamuts, Version %s\n",ARGYLL_VERSION_STR);
fprintf(stderr,"Author: Graeme W. Gill, licensed under the AGPL Version 3\n");
fprintf(stderr,"usage: maptest [options] ingamut outgamut diag_gamut\n");
fprintf(stderr," -v Verbose\n");
fprintf(stderr," -s Do saturation style expand/compress\n");
fprintf(stderr," -i imggamut.gam Use an image gamut\n");
exit(1);
}
int
main(int argc, char *argv[]) {
int fa, nfa, mfa;
char *xl;
static char in_name[MAXNAMEL+10+1];
static char img_name[MAXNAMEL+10+1] = "";
static char out_name[MAXNAMEL+10+1];
static char diag_name[MAXNAMEL+10+1];
int sat = 0;
int verb = 0;
gammap *map; /* Regular split gamut mapping */
icxGMappingIntent gmi;
char gammapwrl[30] = "gammap"; /* Diagnostic file name */
gamut *gin, *gout; /* Input and Output gamuts */
gamut *gimg = NULL; /* Optional image gamut */
error_program = argv[0];
strcat(gammapwrl, vrml_ext());
if (argc < 3)
usage();
/* Process the arguments */
mfa = 3; /* Minimum final arguments */
for(fa = 1;fa < argc;fa++) {
nfa = fa; /* skip to nfa if next argument is used */
if (argv[fa][0] == '-') { /* Look for any flags */
char *na = NULL; /* next argument after flag, null if none */
if (argv[fa][2] != '\000')
na = &argv[fa][2]; /* next is directly after flag */
else {
if ((fa+1+mfa) < argc) {
if (argv[fa+1][0] != '-') {
nfa = fa + 1;
na = argv[nfa]; /* next is seperate non-flag argument */
}
}
}
if (argv[fa][1] == '?')
usage();
/* Verbosity */
else if (argv[fa][1] == 'v' || argv[fa][1] == 'V') {
verb = 1;
}
/* Saturation */
else if (argv[fa][1] == 's' || argv[fa][1] == 'S') {
sat = 1;
}
/* Image gamut */
else if (argv[fa][1] == 'i' || argv[fa][1] == 'I') {
if (na == NULL) usage();
fa = nfa;
strncpy(img_name,na,MAXNAMEL); img_name[MAXNAMEL] = '\000';
}
else
usage();
} else
break;
}
if (fa >= argc || argv[fa][0] == '-') usage();
strncpy(in_name,argv[fa++],MAXNAMEL); in_name[MAXNAMEL] = '\000';
if (fa >= argc || argv[fa][0] == '-') usage();
strncpy(out_name,argv[fa++],MAXNAMEL); out_name[MAXNAMEL] = '\000';
if (fa >= argc || argv[fa][0] == '-') usage();
strncpy(diag_name,argv[fa++],MAXNAMEL); diag_name[MAXNAMEL] = '\000';
/* - - - - - - - - - - - - - - - - - - - */
/* read the input device gamut */
gin = new_gamut(0.0, 0, 0);
if ((xl = strrchr(in_name, '.')) == NULL) { /* Add .gam extention if there isn't one */
xl = in_name + strlen(in_name);
strcpy(xl,".gam");
}
if (gin->read_gam(gin, in_name))
error("Reading input gamut failed");
/* - - - - - - - - - - - - - - - - - - - */
/* read the optional image gamut */
if (img_name[0] != '\000') {
gimg = new_gamut(0.0, 0, 0);
if ((xl = strrchr(img_name, '.')) == NULL) { /* Add .gam extention if there isn't one */
xl = img_name + strlen(img_name);
strcpy(xl,".gam");
}
if (gimg->read_gam(gimg, img_name))
error("Reading image gamut failed");
} else {
gimg = gin;
}
/* - - - - - - - - - - - - - - - - - - - */
/* read the output device gamut */
gout = new_gamut(0.0, 0, 0);
if ((xl = strrchr(out_name, '.')) == NULL) { /* Add .gam extention if there isn't one */
xl = out_name + strlen(out_name);
strcpy(xl,".gam");
}
if (gout->read_gam(gout, out_name))
error("Reading output gamut failed");
/* - - - - - - - - - - - - - - - - - - - */
/* Create the gamut mapping */
gmi.usecas = 1; /* Abs. L*a*b* */
gmi.usemap = 1;
gmi.greymf = 1.0; /* Gray axis hue matching factor, 0.0 - 1.0 */
gmi.glumwcpf = 1.0; /* Grey axis luminance white compression factor, 0.0 - 1.0 */
gmi.glumwexf = 1.0; /* Grey axis luminance white expansion factor, 0.0 - 1.0 */
gmi.glumbcpf = 1.0; /* Grey axis luminance black compression factor, 0.0 - 1.0 */
gmi.glumbexf = 1.0; /* Grey axis luminance black expansion factor, 0.0 - 1.0 */
gmi.glumknf = 0.7; /* Gray axis luminance knee factor, 0.0 - 1.0 */
gmi.bph = gmm_bendBP; /* Extend and bend */
gmi.gamcpf = 1.0; /* Gamut compression factor, 0.0 - 1.0 */
if (sat)
gmi.gamexf = 1.0; /* Gamut expansion factor, 0.0 - 1.0 */
else
gmi.gamexf = 0.0; /* Gamut expansion factor, 0.0 - 1.0 */
gmi.gamcknf = 0.1; /* Gamut comp. knee factor, 0.0 - 1.0 */
gmi.gamxknf = 0.1; /* Gamut exp. knee factor, 0.0 - 1.0 */
if (sat) {
gmi.gampwf = 0.0; /* Gamut Perceptual Map weighting factor, 0.0 - 1.0 */
gmi.gamswf = 1.0; /* Gamut Saturation Map weighting factor, 0.0 - 1.0 */
} else {
gmi.gampwf = 1.0; /* Gamut Perceptual Map weighting factor, 0.0 - 1.0 */
gmi.gamswf = 0.0; /* Gamut Saturation Map weighting factor, 0.0 - 1.0 */
}
gmi.gamlpwf = 0.0; /* Gamut Lightness preserving perceptual Map whtg. factor, 0.0 - 1.0 */
gmi.satenh = 0.0; /* Saturation enhancement factor */
gmi.desc = "mapetest";
gmi.icci = 0;
map = new_gammap(
verb,
gin, /* Source gamut */
gimg, /* Image gamut */
gout, /* Destination gamut */
&gmi,
NULL, /* No gamut hull gamut */
0, 0, /* Normal black points */
0, /* Normal CMY cusp mapping */
0, /* No relative weighting override */
19, /* rspl resolution of 17 */
NULL, /* No input range override */
NULL,
gammapwrl /* Diagnostic plot */
);
if (map == NULL) {
error("new_gammap() failed\n");
}
if (verb)
printf("Got gamut mapping\n");
/* Transform the input gamut by the gamut mapping */
{ /* Bad - delving inside gamut! */
int i;
for (i = 0; i < gin->nv; i++) {
/* transform the input gamutboundary points */
map->domap(map, gin->verts[i]->p, gin->verts[i]->p);
}
}
/* Output a transformed gamut */
if ((xl = strrchr(diag_name, '.')) == NULL) { /* Add .gam extention if there isn't one */
xl = diag_name + strlen(diag_name);
strcpy(xl,".gam");
}
gin->write_gam(gin, diag_name);
/* Clean up */
gout->del(gout);
gin->del(gin);
if (gimg != gin)
gimg->del(gimg);
return 0;
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,301 @@
#ifndef NEARSMTH_H
#define NEARSMTH_H
/*
* nearsmth
*
* Gamut mapping support routine that creates a list of
* guide vectors from the source to destination
* gamut, smoothed to retain reasonably even spacing.
*
* Author: Graeme W. Gill
* Date: 17/1/2002
* Version: 1.00
*
* Copyright 2002 - 2006 Graeme W. Gill
* All rights reserved.
*
* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :-
* see the License.txt file for licencing details.
*/
/* Settings for nearsmth & gammap */
#define GAMMAP_RSPLFLAGS (0) /* Default rspl flags */
#define GAMMAP_RSPLAVGDEV 0.005 /* Default average deviation */
/* Structures to hold weightings */
/* Color x light & dark = 14 combinations */
typedef enum {
/* Combinations in prioroty order */
gmm_light_red = 0x101,
gmm_light_yellow = 0x102,
gmm_light_green = 0x104,
gmm_light_cyan = 0x108,
gmm_light_blue = 0x110,
gmm_light_magenta = 0x120,
gmm_light_neutral = 0x140,
gmm_dark_red = 0x201,
gmm_dark_yellow = 0x202,
gmm_dark_green = 0x204,
gmm_dark_cyan = 0x208,
gmm_dark_blue = 0x210,
gmm_dark_magenta = 0x220,
gmm_dark_neutral = 0x240,
gmm_l_d_red = 0x301,
gmm_l_d_yellow = 0x302,
gmm_l_d_green = 0x304,
gmm_l_d_cyan = 0x308,
gmm_l_d_blue = 0x310,
gmm_l_d_magenta = 0x320,
gmm_l_d_neutral = 0x340,
gmm_light_colors = 0x17f, /* All light colors */
gmm_dark_colors = 0x27f, /* All dark colors */
gmm_default = 0x37f, /* All light and dark colors */
gmm_end = 0x0000, /* Mark the end of the list */
gmm_ignore = 0x1001, /* Ignore this entry */
/* Components */
gmc_light = 0x100,
gmc_dark = 0x200,
gmc_l_d = 0x300, /* Both Light and dark */
gmc_red = 0x001,
gmc_yellow = 0x002,
gmc_green = 0x004,
gmc_cyan = 0x008,
gmc_blue = 0x010,
gmc_magenta = 0x020,
gmc_neutral = 0x040,
gmc_colors = 0x07f /* All colors */
} gmm_chex;
/* Single weight */
typedef struct {
double l,c,h;
} iweight;
/* Group of complete weights */
/* (Remeber to alter near_wcopy() and near_wblend() !!) */
typedef struct {
gmm_chex ch; /* Color hextant this applies to */
/* Cusp alignment control */
struct {
iweight w; /* Component alignment weights, 0 - 1 */
double tw; /* Alignment twist power, 0 = linear, 1 = curve, 2+ late curve */
/* Use > 0 to make cusp alignment only affect surface colors. */
double cx; /* Chroma expansion, 1 = none, > 1 = more */
} c;
/* Radial weighting (This seems to be not working at the moment ?) */
/* Weight to give to minimizing delta E to source mapped radially */
struct {
double o; /* Overall Radial weight */
double h; /* Hue dominance vs l+c, 0 - 1 */
double l; /* l dominance vs, c, 0 - 1 */
} l;
/* Absolute error weighting. */
/* Weight given to minimizing delta E to destination closest point */
struct {
double o; /* Overall Absolute weight */
double h; /* Hue dominance vs l+c, 0 - 1 */
double wl; /* White l dominance vs, c, 0 - 1 */
double gl; /* Grey l dominance vs, c, 0 - 1 */
double bl; /* Black l dominance vs, c, 0 - 1 */
double wlth; /* White l blend start radius, 0 - 1, at white = 0 */
double blpow; /* Black l blend power, linear = 1.0, enhance < 1.0 */
double lxpow; /* L error extra power, none = 1.0 */
double lxthr; /* L error xover threshold in DE */
} a;
/* Relative vector smoothing. */
struct {
double rdl; /* Direction smoothing radius L* dir. (delta E radius at src point)*/
double rdh; /* Direction smoothing radius H* (delta E radius at src point)*/
double dsm; /* Degree of smoothing (non-linear response) */
} r;
/* Depth room weighting. */
/* Weighing to give to minimizing depth ratio by mapping to/from adequate dest/src depth. */
/* The idea is to compromize luminance and/or hue to allow room for */
/* preserving saturation distinction under heavy compression. */
struct {
double co; /* Overall compression weighting */
double xo; /* Overall expansion weighting */
} d;
/* Fine tuning destination gamut mapping */
struct {
double x; /* Final expansion weight, 0 - 1 */
} f; /* Weights fine tuning to expand rather than just compress */
/* Internal use */
iweight rl; /* Resolved radial weight */
iweight ra; /* Resolved absolute weight */
int set; /* Whether this has been set */
} gammapweights;
/* Blend a two groups of weights into one, given two weightings */
void near_wblend(gammapweights *dst,
gammapweights *src1, double wgt1, gammapweights *src2, double wgt2);
/* A neighbour and it's weight for relative error */
typedef struct {
struct _nearsmth *n; /* Pointer to neigbor */
double rw; /* Raw neighbor interpolation weight (1.0 at point) */
double w; /* Neighbor interpolation weight (sums to 1.0) */
} neighb;
/* Returned point values. */
/* Note that source == input point, destination == output point */
/* (All the source values are in rotated L mapped partial gamut mapped space) */
struct _nearsmth {
/* Public: */
int uflag; /* Use flag, 0 = normal, 1 = grid surface point */
int gflag; /* Gamut direction flag. 0 = not determinable, 1 = comp., 2 = exp. */
int vflag; /* Vector direction flag. 0 = not determinable, 1 = comp., 2 = exp. */
/* sv2, dv2, sd3 etc. are valid if vflag != 0 */
/* Gamut surface mapping guide point */
double sv[3]; /* Source value (input, cusp aligned during fwd optimization) */
double sr; /* Corresponding source radius from center */
double drv[3]; /* Destination radial value (starting point & reference) */
double drr; /* Destination radial value radius from center */
double dv[3]; /* Output destination value */
double dr; /* Output destination value radius from center */
double div[3]; /* gam[cx]pf moderated dv[] value */
double w1; /* guide point weight */
/* Gamut sub-surface mapping guide point (knee shape controlled by gamcknf & gamxknf) */
double sv2[3]; /* Sub-surface source value */
double dv2[3]; /* Sub-surface knee'd adjusted destination value */
double div2[3]; /* gam[cx]pf moderated dv2[] value */
double w2; /* Sub-surface weight (set in nearsmth) */
double sd3[3]; /* Deep sub-surface source & destination value */
double w3; /* Deep sub-surface weight */
/* Diagnostic points */
double csv[3]; /* Non-cusp mapped source value */
/* Private to nearsmth: */
gammapweights wt; /* Weight for this point determined from original source location */
int swap; /* Swapped during nearest finding */
double mL, fmL; /* Mid point L value, filtered mid point L value */
double m2d[3][4]; /* Tangent alignment rotation for sv[] 3D -> 2D */
double m3d[3][4]; /* Tangent alignment rotation for 2D -> sv[] 3D */
double _sv[3]; /* Original (non cusp aligned) source value (input) */
double _sr; /* Original source radius */
double naxbf; /* Blend factor that goes to 0.0 at white & black points. */
double aodv[3]; /* Absolute error optimized destination value */
double nrdv[3]; /* No relative smoothed destination value */
double anv[3]; /* Average neighborhood target point (relative target) */
double tdst[3]; /* Target destination on gamut */
int nott; /* NZ if not a point that needs to land on gamut */
double evect[3]; /* Accumulated extension vector direction */
double clen; /* Current correction length needed */
double coff[3]; /* Correction offset */
double rext;
double temp[3]; /* General temporary */
gamut *sgam; /* Source gamut src_gam = intersection of src and img gamut gamut */
gamut *dgam; /* Intersected destination gamut dst_gam */
gamut *dcgam; /* Destination Colorspace gamut dc_gam */
int nnd, _nnd; /* No & size of direction neighbour list */
neighb *nd; /* Allocated list of neighbours */
double nscale[3]; /* Neighborhood scale change from sv to dv */
double dcratio; /* Depth compression ratio */
double dxratio; /* Depth expansion ratio */
int debug;
double dbgv[3]; /* Error components va, vr, vd on last itteration */
}; typedef struct _nearsmth nearsmth;
/* Return the upper bound on the number of points that will be generated */
int near_smooth_np(
gamut **pp_gam, /* Return gamut that was used for points */
gamut *sc_gam, /* Source colorspace gamut */
gamut *s_gam, /* Source image gamut (== sc_gam if none) */
gamut *d_gam, /* Destination colorspace gamut */
double xvra, /* Extra vertex ratio */
int gmult, /* Guide point multiplier, typically 4 */
int surfgres /* surface grid point resolution, 0 for none */
);
/* Return a list of points. Call free_nearsmth() after use */
/* Return NULL on error */
nearsmth *near_smooth(
int verb, /* Verbose flag */
int *npp, /* Return the number of points returned */
gamut *sc_gam, /* Source colorspace gamut */
gamut *s_gam, /* Source image gamut (== sc_gam if none) */
gamut *d_gam, /* Destination colorspace gamut */
int src_kbp, /* Use K only black point as src gamut black point */
int dst_kbp, /* Use K only black point as dst gamut black point */
double d_bp[3], /* Destination target black point - may be NULL */
gammapweights *wh, /* Structure holding weights */
double gamcknf, /* Gamut compression knee factor, 0.0 - 1.0 */
double gamxknf, /* Gamut expansion knee factor, 0.0 - 1.0 */
int usecomp, /* Flag indicating whether smoothed compressed value will be used */
int useexp, /* Flag indicating whether smoothed expanded value will be used */
double xvra, /* Extra vertex ratio */
int mapres, /* Target grid res for 3D RSPL, (allowing for gexp) */
double mapsmooth, /* Target smoothing for 3D RSPL */
double gexp, /* Total grid expansion ratio, none = 1.0 */
int surfgres, /* Surface grid point resolution, 0 for none */
datai map_il, /* Return input range */
datai map_ih,
datao map_ol, /* Return output range */
datao map_oh
);
/* Free the list of points that was returned */
void free_nearsmth(nearsmth *smp, int npp);
/* Expand the compact form of weights into the explicit form. */
int expand_weights(gammapweights out[14], gammapweights *in);
/* Blend two expanded groups of individual weights into one */
void near_xwblend(
gammapweights *dst,
gammapweights *src1, double wgt1,
gammapweights *src2, double wgt2
);
/* Blend three expanded groups of individual weights into one */
void near_xwblend3(
gammapweights *dst,
gammapweights *src1, double wgt1,
gammapweights *src2, double wgt2,
gammapweights *src3, double wgt3
);
/* Tweak weights according to extra cmy cusp flags or rel override */
void tweak_weights(gammapweights out[14], int dst_cmymap, int rel_oride);
#endif /* NEARSMTH_H */

View File

@@ -0,0 +1,247 @@
/*
* nearsmth test code. Test the smoothed nearpoint routine.
*
* Author: Graeme W. Gill
* Date: 17/1/2002
* Version: 1.00
*
* Copyright 2002, Graeme W. Gill
* All rights reserved.
*
* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :-
* see the License.txt file for licencing details.
*/
/* TTBD:
*
*/
#undef DEBUG /* test a single value out */
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <fcntl.h>
#include <string.h>
#include <math.h>
#include "copyright.h"
#include "aconfig.h"
#include "numlib.h"
#include "rspl.h"
#include "cgats.h"
#include "gamut.h"
#include "nearsmth.h"
#include "vrml.h"
double m21po[3] = { 2.0, 1.0, 2.0 }; /* Many to 1 filter mixing power LCh (theoretically 2) */
/* Mapping weights */
gammapweights weights[] = {
{
gmm_default, /* Non hue specific defaults */
{ /* Cusp alignment control */
{
0.1, /* Cusp luminance alignment weighting 0 = none, 1 = full */
0.0, /* Cusp chroma alignment weighting 0 = none, 1 = full */
0.3 /* Cusp hue alignment weighting 0 = none, 1 = full */
},
2.0, /* Alignment twist power, 0 = linear, 1 = curve, 2+ late curve */
1.00 /* Chroma expansion 1 = none */
},
{ /* Radial weighting (currently broken - need to fix) */
0.0, /* Radial error overall weight, 0 + */
0.5, /* Radial hue dominance vs l+c, 0 - 1 */
0.5 /* Radial l dominance vs, c, 0 - 1 */
},
{ /* Weighting of absolute error of destination from source */
1.0, /* Absolute error overall weight */
0.8, /* Hue dominance vs l+c, 0 - 1 */
0.8, /* White l dominance vs, c, 0 - 1 */
0.5, /* Grey l dominance vs, c, 0 - 1 */
0.93, /* Black l dominance vs, c, 0 - 1 */
0.4, /* White l blend start radius, 0 - 1, at white = 0 */
0.7, /* Black l blend power, linear = 1.0, enhance < 1.0 */
1.5, /* L error extra power with size, none = 1.0 */
10.0 /* L error extra xover threshold in DE */
},
{ /* Relative vector smoothing */
20.0, 30.0, /* Relative Smoothing radius L* H* */
0.9 /* Degree of smoothing */
},
{ /* Weighting of excessive compression error, which is */
/* the src->dst vector length over the available dst depth. */
/* The depth is half the distance to the intersection of the */
/* vector to the other side of the gamut. (doesn't get triggered much ?) */
5.0, /* Compression depth weight */
5.0 /* Expansion depth weight */
},
{
0.0 /* Fine tuning expansion weight, 0 - 1 */
}
}
};
#define OVERSHOOT 1.0
void usage(void) {
fprintf(stderr,"Create smoothed near mapping between two gamuts, Version %s\n",ARGYLL_VERSION_STR);
fprintf(stderr,"Author: Graeme W. Gill, licensed under the AGPL Version 3\n");
fprintf(stderr,"usage: smthtest [options] ingamut outgamut diag_vrml\n");
fprintf(stderr," -v Verbose\n");
// fprintf(stderr," -s nearf Absolute delta E weighting\n");
exit(1);
}
int
main(int argc, char *argv[]) {
int fa,nfa; /* argument we're looking at */
char *xl;
static char in_name[MAXNAMEL+10+1];
static char out_name[MAXNAMEL+10+1];
static char diag_name[MAXNAMEL+10+1];
int verb = 0;
double nearf = 1.0; /* Absolute delta E weightign */
datai il, ih; /* rspl input range */
datao ol, oh; /* rspl output range */
gamut *gin, *gout; /* Input and Output gamuts */
nearsmth *nsm; /* Returned list of near smooth points */
int nnsm; /* Number of near smoothed points */
int doaxes = 1;
vrml *wrl; /* VRML/X3D output file */
gammapweights xweights[14];
int i;
error_program = argv[0];
if (argc < 3)
usage();
/* Process the arguments */
for(fa = 1;fa < argc;fa++) {
nfa = fa; /* skip to nfa if next argument is used */
if (argv[fa][0] == '-') { /* Look for any flags */
char *na = NULL; /* next argument after flag, null if none */
if (argv[fa][2] != '\000')
na = &argv[fa][2]; /* next is directly after flag */
else {
if ((fa+1) < argc) {
if (argv[fa+1][0] != '-') {
nfa = fa + 1;
na = argv[nfa]; /* next is seperate non-flag argument */
}
}
}
if (argv[fa][1] == '?')
usage();
/* Verbosity */
else if (argv[fa][1] == 'v' || argv[fa][1] == 'V') {
verb = 1;
}
/* Smoothing factor */
else if (argv[fa][1] == 's' || argv[fa][1] == 'S') {
fa = nfa;
if (na == NULL) usage();
nearf = atof(na);
}
else
usage();
} else
break;
}
if (fa >= argc || argv[fa][0] == '-') usage();
strncpy(in_name,argv[fa++],MAXNAMEL); in_name[MAXNAMEL] = '\000';
if (fa >= argc || argv[fa][0] == '-') usage();
strncpy(out_name,argv[fa++],MAXNAMEL); out_name[MAXNAMEL] = '\000';
if (fa >= argc || argv[fa][0] == '-') usage();
strncpy(diag_name,argv[fa++],MAXNAMEL); diag_name[MAXNAMEL] = '\000';
/* - - - - - - - - - - - - - - - - - - - */
/* read the input device gamut */
gin = new_gamut(0.0, 0, 0);
if ((xl = strrchr(in_name, '.')) == NULL) { /* Add .gam extention if there isn't one */
xl = in_name + strlen(in_name);
strcpy(xl,".gam");
}
if (gin->read_gam(gin, in_name))
error("Reading input gamut failed");
/* - - - - - - - - - - - - - - - - - - - */
/* read the output device gamut */
gout = new_gamut(0.0, 0, 0);
if ((xl = strrchr(out_name, '.')) == NULL) { /* Add .gam extention if there isn't one */
xl = out_name + strlen(out_name);
strcpy(xl,".gam");
}
if (gout->read_gam(gout, out_name))
error("Reading output gamut failed");
/* - - - - - - - - - - - - - - - - - - - */
il[0] = ol[0] = 0.0;
il[1] = ol[1] = -128.0;
il[2] = ol[2] = -128.0;
ih[0] = oh[0] = 100.0;
ih[1] = oh[1] = 128.0;
ih[2] = oh[2] = 128.0;
/* Convert from compact to explicit hextant weightings */
expand_weights(xweights, weights);
/* Create the near point mapping */
nsm = near_smooth(verb, &nnsm, gin, gin, gout, 0, 0, NULL, xweights,
0.1, 0.1, 1, 1, 2.0, 19, 2.0, 1.20, 5, il, ih, ol, oh);
if (nsm == NULL)
error("Creating smoothed near points failed");
/* Output the src to smoothed near point vectors */
if ((xl = strrchr(diag_name, '.')) == NULL) /* Clear extension */
xl = diag_name + strlen(diag_name);
xl[0] = '\000';
if ((wrl = new_vrml(diag_name, doaxes, vrml_lab)) != 0) {
error("new_vrml failed for '%s%s'",diag_name,vrml_ext());
}
wrl->start_line_set(wrl, 0);
for (i = 0; i < nnsm; i++) {
wrl->add_vertex(wrl, 0, nsm[i].sv); /* Source gamut point */
wrl->add_vertex(wrl, 0, nsm[i].dv); /* Smoother destination value */
// add_vertex(wrl, nsm[i].drv); /* Radial points */
}
wrl->make_lines(wrl, 0, 2);
wrl->del(wrl); /* Write file */
/* Clean up */
free_nearsmth(nsm, nnsm);
gout->del(gout);
gin->del(gin);
return 0;
}

View File

@@ -0,0 +1,255 @@
/*
* surftest
*
* Do a torture test of the gamut surfacing algorithm in gamut.
*
* Author: Graeme W. Gill
* Date: 11/11/2006
* Version: 1.00
*
* Copyright 2000, 2006 Graeme W. Gill
* All rights reserved.
* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :-
* see the License.txt file for licencing details.
*/
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <fcntl.h>
#include <string.h>
#include <math.h>
#include "copyright.h"
#include "aconfig.h"
#include "numlib.h"
#include "icc.h"
#include "cgats.h"
#include "gamut.h"
#define DEF_POINTS 5
#define DEF_TPOINTS 50
#define DEF_HEIGHT 5.0
void usage(char *diag) {
fprintf(stderr,"Do gamut surface torture test, Version %s\n",ARGYLL_VERSION_STR);
fprintf(stderr,"Author: Graeme W. Gill, licensed under the AGPL Version 3\n");
fprintf(stderr,"usage: surftest [options] npoints\n");
if (diag != NULL)
fprintf(stderr,"Diagnostic: %s\n",diag);
fprintf(stderr," -v Verbose\n");
fprintf(stderr," -r Random points\n");
fprintf(stderr," -n Don't add VRML axes or white/black point\n");
fprintf(stderr," -h height Height above sqhere (default %f)\n",DEF_HEIGHT);
fprintf(stderr," -f Do segemented maxima filtering (default is not)\n");
fprintf(stderr," -t ntpoints Number of test points (default %d)\n",DEF_TPOINTS);
fprintf(stderr," npoints Number of random points, default %d^3\n",DEF_POINTS);
fprintf(stderr," Outputs surftest.wrl");
fprintf(stderr,"\n");
exit(1);
}
int
main(int argc, char *argv[]) {
int fa,nfa; /* argument we're looking at */
static char out_name[MAXNAMEL+1];
int npoints = DEF_POINTS;
int ntpoints = DEF_TPOINTS;
double height = DEF_HEIGHT;
gamut *gam;
int rand = 0;
int verb = 0;
int doaxes = 1;
int dofilt = 0;
int i;
#ifdef NUMSUP_H
error_program = "surftest";
#endif
/* Process the arguments */
for(fa = 1;fa < argc;fa++) {
nfa = fa; /* skip to nfa if next argument is used */
if (argv[fa][0] == '-') { /* Look for any flags */
char *na = NULL; /* next argument after flag, null if none */
if (argv[fa][2] != '\000')
na = &argv[fa][2]; /* next is directly after flag */
else {
if ((fa+1) < argc) {
if (argv[fa+1][0] != '-') {
nfa = fa + 1;
na = argv[nfa]; /* next is seperate non-flag argument */
}
}
}
if (argv[fa][1] == '?')
usage(NULL);
/* Verbosity */
else if (argv[fa][1] == 'v' || argv[fa][1] == 'V') {
verb = 1;
}
/* Random */
else if (argv[fa][1] == 'r' || argv[fa][1] == 'R') {
rand = 1;
}
/* No axis output */
else if (argv[fa][1] == 'n' || argv[fa][1] == 'N') {
doaxes = 0;
}
/* Segmented maxima filtering */
else if (argv[fa][1] == 'f' || argv[fa][1] == 'F') {
dofilt = 1;
}
/* Height */
else if (argv[fa][1] == 'h' || argv[fa][1] == 'H') {
fa = nfa;
if (na == NULL) usage("No parameter after flag -h");
height = atof(na);
}
/* Number of test points */
else if (argv[fa][1] == 't' || argv[fa][1] == 'T') {
fa = nfa;
if (na == NULL) usage("No parameter after flag -t");
ntpoints = atoi(na);
}
else
usage("Unknown flag");
} else
break;
}
if (fa < argc && argv[fa][0] != '-')
npoints = atoi(argv[fa]);
strcpy(out_name,"surftest.wrl");
if (verb) {
printf("Number of surface points = %d\n",npoints * npoints * npoints);
printf("Number of test points = %d\n",ntpoints);
}
/* Creat a gamut object */
if ((gam = new_gamut(0.0, 0, 0)) == NULL)
error("Failed to create aa gamut object\n");
if (dofilt == 0)
gam->setnofilt(gam);
if (rand) {
npoints = npoints * npoints * npoints;
/* Create and add our random test points */
for (i = 0; i < npoints;) {
int j;
double pp[3], sum, rad;
/* Make normalzed random direction vector on sphere radius 30 */
for (sum = 0.0, j = 0; j < 3; j++) {
double tt = d_rand(-1.0, 1.0);
pp[j] = tt;
sum += tt * tt;
}
if (sum < 1e-6)
continue;
sum = sqrt(sum);
rad = d_rand(30.0, 30.0 + height);
for (j = 0; j < 3; j++) {
pp[j] /= sum;
pp[j] *= rad;
}
pp[0] += 50.0;
//printf("~1 point %f %f %f\n",pp[0],pp[1],pp[2]);
// if (verb) printf("\r%d",i+1); fflush(stdout);
gam->expand(gam, pp);
i++;
}
// if (verb) printf("\n");
} else {
int co[3];
/* Create and add our gridded test points */
for (co[0] = 0; co[0] < npoints; co[0]++) {
for (co[1] = 0; co[1] < npoints; co[1]++) {
for (co[2] = 0; co[2] < npoints; co[2]++) {
double pp[3], sum, rad;
int m, n;
#ifndef NEVER
/* Make sure at least one coords are 0 & 1 */
for (n = m = 0; m < 3; m++) {
if (co[m] == 0 || co[m] == (npoints-1))
n++;
}
if (n < 1)
continue;
#endif
pp[0] = 2.0 * (co[0]/(npoints-1.0) - 0.5);
pp[1] = 2.0 * (co[1]/(npoints-1.0) - 0.5);
pp[2] = 2.0 * (co[2]/(npoints-1.0) - 0.5);
#ifdef NEVER
/* Make normalzed random direction vector on sphere radius 30 */
for (sum = 0.0, m = 0; m < 3; m++) {
sum += pp[m] * pp[m];
}
if (sum < 1e-6)
continue;
sum = sqrt(sum);
#else
sum = 1.0;
#endif /* NEVER */
rad = d_rand(30.0, 30.0 + height);
for (m = 0; m < 3; m++) {
pp[m] /= sum;
pp[m] *= rad;
}
pp[0] += 50.0;
//printf("~1 point %f %f %f\n",pp[0],pp[1],pp[2]);
gam->expand(gam, pp);
}
}
}
}
/* Write out the gamut surface */
if (gam->write_vrml(gam, out_name, doaxes, 0))
error ("write vrml failed on '%s'",out_name);
if (verb)
printf("Written out the gamut surface\n");
/* Test the gamut surface */
for (i = 0; i < ntpoints;) {
int j;
double pp[3], sum;
double r, out[3];
/* Make normalzed random direction vector on sphere */
for (sum = 0.0, j = 0; j < 3; j++) {
double tt = d_rand(-1.0, 1.0);
pp[j] = tt;
sum += tt * tt;
}
if (sum < 1e-6)
continue;
sum = sqrt(sum);
for (j = 0; j < 3; j++) {
pp[j] /= sum;
}
/* Test surface */
r = gam->radial(gam, out, pp);
i++;
}
gam->del(gam);
return 0;
}

View File

@@ -0,0 +1,728 @@
/*
* viewgam
*
* Gamut support routines.
*
* Author: Graeme W. Gill
* Date: 4/10/00
* Version: 1.00
*
* Copyright 2000 Graeme W. Gill
* All rights reserved.
*
* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :-
* see the License.txt file for licencing details.
*/
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <fcntl.h>
#include <string.h>
#include <math.h>
#include "copyright.h"
#include "aconfig.h"
#include "numlib.h"
#include "cgats.h"
#include "gamut.h"
#include "vrml.h"
#include "icc.h"
/*
This program reads one or more CGATS format triangular gamut
surface descriptions, and combines them into a VRML file,
so that the gamuts can be visually compared.
*/
/* TTBD:
*
*/
#undef DEBUG
#undef HALF_HACK /* 27.0 */ /* Crude cutting plane */
void usage(char *diag, ...) {
fprintf(stderr,"View gamuts Version %s\n",ARGYLL_VERSION_STR);
fprintf(stderr,"Author: Graeme W. Gill, licensed under the AGPL Version 3\n");
if (diag != NULL) {
va_list args;
fprintf(stderr,"Diagnostic: ");
va_start(args, diag);
vfprintf(stderr, diag, args);
va_end(args);
fprintf(stderr,"\n");
}
fprintf(stderr,"usage: viewgam { [-c color] [-t trans] [-w|s] infile.gam } ... outfile%s\n",vrml_ext());
fprintf(stderr," -c color Color to make gamut, r = red, g = green, b = blue\n");
fprintf(stderr," c = cyan, m = magenta, y = yellow, e = grey, w = white\n");
fprintf(stderr," n = natural color\n");
fprintf(stderr," -t trans Set transparency from 0.0 (opaque) to 1.0 (invisible)\n");
fprintf(stderr," -w Show as a wireframe\n");
fprintf(stderr," -s Show as a solid surace\n");
fprintf(stderr," infile.gam Name of .gam file\n");
fprintf(stderr," Repeat above for each input file\n");
fprintf(stderr," Default is colored solid, then white, red etc. wireframes.\n\n");
fprintf(stderr," -n Don't add Lab axes\n");
fprintf(stderr," -k Add markers for prim. & sec. \"cusp\" points\n");
fprintf(stderr," -i Compute and print intersecting volume of first 2 gamuts\n");
fprintf(stderr," -I isect.gam Same as -i, but save intersection gamut to isect.gam\n");
fprintf(stderr," (Set env. ARGYLL_3D_DISP_FORMAT to VRML, X3D or X3DOM to change format)\n");
fprintf(stderr," -o Print & plot points on first gamut that are outside second gamut\n");
fprintf(stderr," outfile Base name of output %s file\n",vrml_ext());
fprintf(stderr,"\n");
exit(1);
}
typedef enum {
gam_red = 0,
gam_green = 1,
gam_blue = 2,
gam_cyan = 3,
gam_magenta = 4,
gam_yellow = 5,
gam_grey = 6,
gam_white = 7,
gam_natural = 8
} gam_colors;
struct {
double rgb[3];
} color_rgb[8] = {
{ 1, 0, 0 }, /* gam_red */
{ 0, 1, 0 }, /* gam_green */
{ 0, 0, 1 }, /* gam_blue */
{ 0, 1, 1 }, /* gam_cyan */
{ 1, 0, 1 }, /* gam_magenta */
{ 1, 1, 0 }, /* gam_yellow */
{ .1, .1, .1 }, /* gam_grey */
{ .7, .7, .7 } /* gam_white */
};
typedef enum {
gam_solid = 0,
gam_wire = 1,
gam_points = 2
} gam_reps;
struct _gamdisp {
char in_name[MAXNAMEL+1];
gam_colors in_colors; /* Color enum for each input */
double in_trans; /* Transparency for each input */
gam_reps in_rep; /* Representation enum for each input */
}; typedef struct _gamdisp gamdisp;
/* Set a default for a given gamut */
static void set_default(gamdisp *gds, int n) {
gds[n].in_name[0] = '\000';
switch(n) {
case 0:
gds[n].in_colors = gam_natural;
gds[n].in_rep = gam_solid;
gds[n].in_trans = 0.0;
break;
case 1:
gds[n].in_colors = gam_white;
gds[n].in_rep = gam_wire;
gds[n].in_trans = 0.0;
break;
case 2:
gds[n].in_colors = gam_red;
gds[n].in_rep = gam_wire;
gds[n].in_trans = 0.0;
break;
case 3:
gds[n].in_colors = gam_cyan;
gds[n].in_rep = gam_wire;
gds[n].in_trans = 0.0;
break;
case 4:
gds[n].in_colors = gam_yellow;
gds[n].in_rep = gam_wire;
gds[n].in_trans = 0.2;
break;
case 5:
gds[n].in_colors = gam_green;
gds[n].in_rep = gam_wire;
gds[n].in_trans = 0.3;
break;
case 6:
gds[n].in_colors = gam_blue;
gds[n].in_rep = gam_wire;
gds[n].in_trans = 0.4;
break;
case 7:
gds[n].in_colors = gam_magenta;
gds[n].in_rep = gam_wire;
gds[n].in_trans = 0.5;
break;
default:
gds[n].in_colors = n % 6;
gds[n].in_rep = gam_wire;
gds[n].in_trans = 0.6;
break;
}
}
static int g_vect_isect(gamut *s, double *p, double *p1, double *p2);
int
main(int argc, char *argv[]) {
int fa, nfa, mfa; /* argument we're looking at */
int n, ng = 0; /* Current allocation, number of input gamuts */
gamdisp *gds; /* Definition of each gamut */
int doaxes = 1;
int docusps = 0;
int isect = 0;
int dooogamut = 0;
vrml *wrl;
static char out_name[MAXNAMEL+1+10];
static char iout_name[MAXNAMEL+1] = "\000";;
if (argc < 3)
usage("Too few arguments, got %d expect at least 2",argc-1);
mfa = 1; /* Minimum final arguments */
if ((gds = (gamdisp *)malloc((ng+1) * sizeof(gamdisp))) == NULL)
error("Malloc failed on gamdisp");
set_default(gds, 0);
/* Process the arguments */
for(fa = 1;fa < argc;fa++) {
nfa = fa; /* skip to nfa if next argument is used */
if (argv[fa][0] == '-') { /* Look for any flags */
char *na = NULL; /* next argument after flag, null if none */
if (argv[fa][2] != '\000')
na = &argv[fa][2]; /* next is directly after flag */
else {
if ((fa+1+mfa) < argc) {
if (argv[fa+1][0] != '-') {
nfa = fa + 1;
na = argv[nfa]; /* next is seperate non-flag argument */
}
}
}
if (argv[fa][1] == '?')
usage("Usage requested");
/* Color */
else if (argv[fa][1] == 'c') {
fa = nfa;
if (na == NULL) usage("Expect argument after flag -c");
switch (na[0]) {
case 'r':
case 'R':
gds[ng].in_colors = gam_red;
break;
case 'g':
case 'G':
gds[ng].in_colors = gam_green;
break;
case 'b':
case 'B':
gds[ng].in_colors = gam_blue;
break;
case 'c':
case 'C':
gds[ng].in_colors = gam_cyan;
break;
case 'm':
case 'M':
gds[ng].in_colors = gam_magenta;
break;
case 'y':
case 'Y':
gds[ng].in_colors = gam_yellow;
break;
case 'e':
case 'E':
gds[ng].in_colors = gam_grey;
break;
case 'w':
case 'W':
gds[ng].in_colors = gam_white;
break;
case 'n':
case 'N':
gds[ng].in_colors = gam_natural;
break;
default:
usage("Unknown argument after flag -c '%c'",na[0]);
}
}
/* Transparency */
else if (argv[fa][1] == 't') {
double v;
fa = nfa;
if (na == NULL) usage("Expect argument after flag -t");
v = atof(na);
if (v < 0.0)
v = 0.0;
else if (v > 1.0)
v = 1.0;
gds[ng].in_trans = v;
}
/* Solid output */
else if (argv[fa][1] == 's') {
gds[ng].in_rep = gam_solid;
}
/* Wireframe output */
else if (argv[fa][1] == 'w') {
gds[ng].in_rep = gam_wire;
}
/* No axis output */
else if (argv[fa][1] == 'n') {
doaxes = 0;
}
/* Add cusp markers */
else if (argv[fa][1] == 'k') {
docusps = 1;
}
/* Print intersecting volume */
else if (argv[fa][1] == 'i') {
isect = 1;
/* There is an intersection output gamut file */
if (argv[fa][1] == 'I' && na != NULL) {
fa = nfa;
strncpy(iout_name, na, MAXNAMEL); iout_name[MAXNAMEL] = '\000';
}
}
/* Print out of gamut points */
else if (argv[fa][1] == 'o') {
dooogamut = 1;
}
else
usage("Unknown flag '%c'",argv[fa][1]);
} else if (argv[fa][0] != '\000') { /* Got a non-flag */
strncpy(gds[ng].in_name,argv[fa],MAXNAMEL); gds[ng].in_name[MAXNAMEL] = '\000';
ng++;
if ((gds = (gamdisp *)realloc(gds, (ng+1) * sizeof(gamdisp))) == NULL)
error("Realloc failed on gamdisp");
set_default(gds, ng);
} else {
break;
}
}
/* The last "gamut" is actually the output VRML filename, */
/* so unwind it. */
if (ng < 2)
usage("Not enough arguments to specify output %s files",vrml_format());
strncpy(out_name, gds[--ng].in_name,MAXNAMEL); out_name[MAXNAMEL] = '\000';
#ifdef DEBUG
for (n = 0; n < ng; n++) {
printf("Input file %d is '%s'\n",n,gds[n].in_name);
printf("Input file %d has color %d\n",n,gds[n].in_colors);
printf("Input file %d has rep %d\n",n,gds[n].in_rep);
printf("Input file %d has trans %f\n",n,gds[n].in_trans);
}
printf("Output file is '%s'\n",out_name);
#endif /* DEBUG */
/* Create the VRML object */
if ((wrl = new_vrml(out_name, doaxes, vrml_lab)) == NULL)
error("Error creating %s object '%s%s'\n",vrml_format(),out_name,vrml_ext());
/* Read each input in turn */
for (n = 0; n < ng; n++) {
int i;
cgats *pp;
int nverts;
int ntris;
int Lf, af, bf; /* Fields holding L, a & b data */
int v0f, v1f, v2f; /* Fields holding vertices 0, 1 & 2 */
pp = new_cgats(); /* Create a CGATS structure */
/* Setup to cope with a gamut file */
pp->add_other(pp, "GAMUT");
if (pp->read_name(pp, gds[n].in_name))
error("Input file '%s' error : %s",gds[n].in_name, pp->e.m);
if (pp->t[0].tt != tt_other || pp->t[0].oi != 0)
error("Input file isn't a GAMUT format file");
if (pp->ntables != 2)
error("Input file doesn't contain exactly two tables");
if ((nverts = pp->t[0].nsets) <= 0)
error("No vertices");
if ((ntris = pp->t[1].nsets) <= 0)
error("No triangles");
if ((Lf = pp->find_field(pp, 0, "LAB_L")) < 0)
error("Input file doesn't contain field LAB_L");
if (pp->t[0].ftype[Lf] != r_t)
error("Field LAB_L is wrong type");
if ((af = pp->find_field(pp, 0, "LAB_A")) < 0)
error("Input file doesn't contain field LAB_A");
if (pp->t[0].ftype[af] != r_t)
error("Field LAB_A is wrong type");
if ((bf = pp->find_field(pp, 0, "LAB_B")) < 0)
error("Input file doesn't contain field LAB_B");
if (pp->t[0].ftype[bf] != r_t)
error("Field LAB_B is wrong type");
wrl->start_line_set(wrl, 0);
/* Spit out the point values, in order. */
/* Note that a->x, b->y, L->z */
for (i = 0; i < nverts; i++) {
double pos[3];
pos[0] = *((double *)pp->t[0].fdata[i][Lf]);
pos[1] = *((double *)pp->t[0].fdata[i][af]);
pos[2] = *((double *)pp->t[0].fdata[i][bf]);
wrl->add_vertex(wrl, 0, pos);
}
/* Write the triangles/wires out */
if ((v0f = pp->find_field(pp, 1, "VERTEX_0")) < 0)
error("Input file doesn't contain field VERTEX_0");
if (pp->t[1].ftype[v0f] != i_t)
error("Field VERTEX_0 is wrong type");
if ((v1f = pp->find_field(pp, 1, "VERTEX_1")) < 0)
error("Input file doesn't contain field VERTEX_1");
if (pp->t[1].ftype[v1f] != i_t)
error("Field VERTEX_1 is wrong type");
if ((v2f = pp->find_field(pp, 1, "VERTEX_2")) < 0)
error("Input file doesn't contain field VERTEX_2");
if (pp->t[1].ftype[v2f] != i_t)
error("Field VERTEX_2 is wrong type");
for (i = 0; i < ntris; i++) {
int v0, v1, v2;
v0 = *((int *)pp->t[1].fdata[i][v0f]);
v1 = *((int *)pp->t[1].fdata[i][v1f]);
v2 = *((int *)pp->t[1].fdata[i][v2f]);
#ifdef HALF_HACK
if (*((double *)pp->t[0].fdata[v0][Lf]) < HALF_HACK
|| *((double *)pp->t[0].fdata[v1][Lf]) < HALF_HACK
|| *((double *)pp->t[0].fdata[v2][Lf]) < HALF_HACK)
continue;
#endif /* HALF_HACK */
if (gds[n].in_rep == gam_wire) {
int ix[2];
if (v0 < v1) { /* Only output 1 wire of two on an edge */
ix[0] = v0;
ix[1] = v1;
wrl->add_line(wrl, 0, ix);
}
if (v1 < v2) {
ix[0] = v1;
ix[1] = v2;
wrl->add_line(wrl, 0, ix);
}
if (v2 < v0) {
ix[0] = v2;
ix[1] = v0;
wrl->add_line(wrl, 0, ix);
}
} else {
int ix[3];
ix[0] = v0;
ix[1] = v1;
ix[2] = v2;
wrl->add_triangle(wrl, 0, ix);
}
}
/* Write the wires or triangles out */
if (gds[n].in_rep == gam_wire) {
if (gds[n].in_colors == gam_natural)
wrl->make_lines_vc(wrl, 0, gds[n].in_trans);
else
wrl->make_lines_cc(wrl, 0, gds[n].in_trans, color_rgb[gds[n].in_colors].rgb);
} else {
if (gds[n].in_colors == gam_natural)
wrl->make_triangles_vc(wrl, 0, gds[n].in_trans);
else
wrl->make_triangles(wrl, 0, gds[n].in_trans, color_rgb[gds[n].in_colors].rgb);
}
/* See if there are cusp values */
if (docusps) {
int kk;
double rgb[3], Lab[3];
char buf1[50];
char *cnames[6] = { "RED", "YELLOW", "GREEN", "CYAN", "BLUE", "MAGENTA" };
for (i = 0; i < 6; i++) {
sprintf(buf1,"CUSP_%s", cnames[i]);
if ((kk = pp->find_kword(pp, 0, buf1)) < 0)
break;
if (sscanf(pp->t[0].kdata[kk], "%lf %lf %lf",
&Lab[0], &Lab[1], &Lab[2]) != 3) {
break;
}
if (gds[n].in_colors != gam_natural)
wrl->add_marker(wrl, Lab, color_rgb[gds[n].in_colors].rgb, 2.0);
else
wrl->add_marker(wrl, Lab, NULL, 2.0);
}
}
pp->del(pp); /* Clean up */
}
/* Write the file out */
if (wrl->flush(wrl))
error("Closing output file '%s%s'\n",out_name,vrml_ext());
wrl->del(wrl);
if (isect && ng >= 2) {
gamut *s, *s1, *s2;
double v1, v2, vi;
if ((s = new_gamut(0.0, 0, 0)) == NULL)
error("Creating gamut object failed");
if ((s1 = new_gamut(0.0, 0, 0)) == NULL)
error("Creating gamut object failed");
if ((s2 = new_gamut(0.0, 0, 0)) == NULL)
error("Creating gamut object failed");
if (s1->read_gam(s1, gds[0].in_name))
error("Input file '%s' read failed",gds[n].in_name[0]);
if (s2->read_gam(s2, gds[1].in_name))
error("Input file '%s' read failed",gds[n].in_name[1]);
v1 = s1->volume(s1);
v2 = s2->volume(s2);
if (s->intersect(s, s1, s2))
error("Gamuts are not compatible! (Colorspace, gamut center ?)");
vi = s->volume(s);
if (iout_name[0] != '\000') {
if (s->write_gam(s, iout_name))
error("Writing intersection gamut to '%s' failed",iout_name);
}
printf("Intersecting volume = %.1f cubic units\n",vi);
printf("'%s' volume = %.1f cubic units, intersect = %.2f%%\n",gds[0].in_name,v1,100.0 * vi/v1);
printf("'%s' volume = %.1f cubic units, intersect = %.2f%%\n",gds[1].in_name,v2,100.0 * vi/v2);
s1->del(s1);
s2->del(s2);
}
/* Print out of gamut points */
if (dooogamut && ng >= 2) {
gamut *s1, *s2;
int ix;
vrml *wrl;
static char oog_name[MAXNAMEL+1] = "\000", *xl;
if ((s1 = new_gamut(0.0, 0, 0)) == NULL)
error("Creating gamut object failed");
if ((s2 = new_gamut(0.0, 0, 0)) == NULL)
error("Creating gamut object failed");
if (s1->read_gam(s1, gds[0].in_name))
error("Input file '%s' read failed",gds[n].in_name[0]);
if (s2->read_gam(s2, gds[1].in_name))
error("Input file '%s' read failed",gds[n].in_name[1]);
/* For all gamut surface points of s1, print out of gamut */
for (ix = 0; ix >= 0;) {
double pos[3], nog, out[3];
ix = s1->getvert(s1, NULL, pos, ix);
if ((nog = s2->nradial(s2, out, pos)) > 1.0) {
double de;
de = icmLabDE(pos, out);
printf("[%f] %f %f %f\n",de,pos[0],pos[1],pos[2]);
}
}
strcpy(oog_name, out_name);
if ((xl = strrchr(oog_name, '.')) == NULL) /* Figure where extention is */
xl = oog_name + strlen(oog_name);
strcpy(xl,"_oog");
if ((wrl = new_vrml(oog_name, 1, vrml_lab)) == NULL)
error("new_vrml failed for '%s%s'\n",oog_name,vrml_ext());
/* Plot the oog triangles. */
s1->startnexttri(s1);
for (;;) {
int vix[3], i;
double pos[3][3];
int noog = 0;
int ig = -1, og = -1, xg = -1;
if (s1->getnexttri(s1, vix))
break;
/* See if any of the vertexes are out of gamut */
for (i = 0; i < 3; i++) {
s1->getvert(s1, NULL, pos[i], vix[i]);
if (s2->nradial(s2, NULL, pos[i]) > 1.0) {
noog++;
if (og < 0)
og = i;
else
xg = i;
} else {
if (ig < 0)
ig = i;
else
xg = i;
}
}
/* Note that clipping is imperfect because we use a straight */
/* line between clipped triangle edges, when in reality there */
/* could be a contour caused by multiple gamut surface triangles */
/* between these points... */
/* No clipping */
if (noog > 2) {
for (i = 0; i < 3; i++)
vix[i] = wrl->add_vertex(wrl, 0, pos[i]);
wrl->add_triangle(wrl, 0, vix);
ix = vix[0]; /* Add reverse direction tri so */
vix[0] = vix[1]; /* so that it's visible on both sides.. */
vix[1] = ix;
wrl->add_triangle(wrl, 0, vix);
/* Clip two vertexes */
} else if (noog == 1) {
int res = 1;
res = res && g_vect_isect(s2, pos[ig], pos[ig], pos[og]);
res = res && g_vect_isect(s2, pos[xg], pos[xg], pos[og]);
if (res) {
for (i = 0; i < 3; i++)
vix[i] = wrl->add_vertex(wrl, 0, pos[i]);
wrl->add_triangle(wrl, 0, vix);
/* Add reverse tri to make visible both sides*/
ix = vix[0]; vix[0] = vix[1]; vix[1] = ix;
wrl->add_triangle(wrl, 0, vix);
}
/* Clip one vertex to form a quad */
} else if (noog == 2) {
int cvix[4];
double cpos[4][3];
int res = 1;
res = res && g_vect_isect(s2, cpos[0], pos[ig], pos[og]);
icmCpy3(cpos[1], pos[og]);
icmCpy3(cpos[2], pos[xg]);
res = res && g_vect_isect(s2, cpos[3], pos[ig], pos[xg]);
if (res) {
for (i = 0; i < 4; i++)
cvix[i] = wrl->add_vertex(wrl, 0, cpos[i]);
wrl->add_quad(wrl, 0, cvix);
/* Add reverse quad to make visible both sides*/
ix = cvix[1]; cvix[1] = cvix[3]; cvix[3] = ix;
wrl->add_quad(wrl, 0, cvix);
}
wrl->add_quad(wrl, 0, cvix);
}
}
wrl->make_triangles_vc(wrl, 0, 0.0);
wrl->del(wrl); /* Write vrml file */
s1->del(s1);
s2->del(s2);
}
if (ng > 0)
free(gds);
return 0;
}
/* Clip the vector against the gamut surface and return */
/* nz if intersects, and the intersection point */
static int g_vect_isect(gamut *s, double *p, double *p1, double *p2) {
int res = 0;
double min[3], max[3];
double mint, maxt;
/* Compute the intersection with the line and gamut */
res = s->vector_isect(s, p1, p2, min, max, &mint, &maxt, NULL, NULL);
if (res == 0)
return 0;
if (mint >= -1e-6 && mint <= (1.0 + 1e-6)) {
if (p != NULL)
icmCpy3(p, min);
return 1;
}
if (maxt >= -1e-6 && maxt <= (1.0 + 1e-6)) {
if (p != NULL)
icmCpy3(p, max);
return 1;
}
return 0;
}
#ifdef NEVER
/* Basic printf type error() and warning() routines */
void
error(char *fmt, ...)
{
va_list args;
fprintf(stderr,"icclu: Error - ");
va_start(args, fmt);
vfprintf(stderr, fmt, args);
va_end(args);
fprintf(stderr, "\n");
exit (-1);
}
void
warning(char *fmt, ...)
{
va_list args;
fprintf(stderr,"icclu: Warning - ");
va_start(args, fmt);
vfprintf(stderr, fmt, args);
va_end(args);
fprintf(stderr, "\n");
}
#endif /* NEVER */