Tizen 2.0 Release
[external/lcms.git] / utils / samples / vericc.c
1 //---------------------------------------------------------------------------------
2 //
3 //  Little Color Management System
4 //  Copyright (c) 1998-2010 Marti Maria Saguer
5 //
6 // Permission is hereby granted, free of charge, to any person obtaining 
7 // a copy of this software and associated documentation files (the "Software"), 
8 // to deal in the Software without restriction, including without limitation 
9 // the rights to use, copy, modify, merge, publish, distribute, sublicense, 
10 // and/or sell copies of the Software, and to permit persons to whom the Software 
11 // is furnished to do so, subject to the following conditions:
12 //
13 // The above copyright notice and this permission notice shall be included in 
14 // all copies or substantial portions of the Software.
15 //
16 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 
17 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO 
18 // THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 
19 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 
20 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 
21 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 
22 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 //
24 //---------------------------------------------------------------------------------
25 //
26
27 #include "lcms2.h"
28 #include <string.h>
29 #include <math.h>
30
31 static
32 int PrintUsage(void)
33 {
34         fprintf(stderr, "Sets profile version\n\nUsage: vericc --r<version> iccprofile.icc\n"); 
35         return 0; 
36 }
37
38 int main(int argc, char *argv[])
39 {
40        cmsHPROFILE hProfile;
41            char* ptr;
42            cmsFloat64Number Version;
43
44            if (argc != 3)  return PrintUsage();
45
46            ptr = argv[1];
47            if (strncmp(ptr, "--r", 3) != 0) return PrintUsage();
48            ptr += 3;
49            if (!*ptr) { fprintf(stderr, "Wrong version number\n"); return 1; }
50
51            Version = atof(ptr); 
52
53            hProfile = cmsOpenProfileFromFile(argv[2], "r");
54            if (hProfile == NULL) { fprintf(stderr, "'%s': cannot open\n", argv[2]); return 1; }
55
56            cmsSetProfileVersion(hProfile, Version);
57            cmsSaveProfileToFile(hProfile, "$$tmp.icc");
58            cmsCloseProfile(hProfile);
59
60            remove(argv[2]);
61            rename("$$tmp.icc", argv[2]);
62            return 0;
63
64
65 }