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

230
Argyll_V3.5.0/xicc/Jamfile Executable file
View File

@@ -0,0 +1,230 @@
#PREF_CCFLAGS += $(CCOPTFLAG) ; # Turn optimisation on
PREF_CCFLAGS += $(CCDEBUGFLAG) ; # Debugging flags
#PREF_CCFLAGS += $(CCHEAPDEBUG) ; # Heap Debugging flags
PREF_LINKFLAGS += $(LINKDEBUGFLAG) ; # Link debugging flags
#Products
Libraries = libxicc libxcolorants libxutils ;
Executables = fakeCMY iccgamut mpplu revfix tiffgamut xicclu extracticc extractttag specplot ;
Headers = xicc.h ;
ExeDoc = License.txt ;
#Install
InstallBin $(DESTDIR)$(PREFIX)/bin : $(Executables) ;
InstallFile $(DESTDIR)$(PREFIX)/bin : $(ExeDoc) ;
#InstallFile $(DESTDIR)$(PREFIX)/h : $(Headers) ;
#InstallLib $(DESTDIR)$(PREFIX)/lib : $(Libraries) ;
if $(USE_PLOT) = true {
DEFINES += EN_PLOT ;
} else {
UNDEFS += $(UNDEFFLAG)EN_PLOT ;
}
HDRS = ../h ../icc ../rspl ../cgats ../numlib ../gamut ../spectro ../profile
../plot ../render $(TIFFINC) $(JPEGINC) $(LibWinH) ;
# XICC library
Library libxicc : xicc.c xspect.c xcolorants.c xutils.c iccjpeg.c
xcam.c cam97s3.c cam02.c mpp.c ccmx.c ccss.c xfit.c moncurve.c xcal.c
bt1886.c tm3015.c ;
# colorant library. Use instead of libxicc
Object xcolorants2 : xcolorants.c ;
LibraryFromObjects libxcolorants : xcolorants2 ;
# standalone utilities library. Use instead of libxicc
Object xutils2 : xutils.c ;
Object iccjpeg2 : iccjpeg.c ;
LibraryFromObjects libxutils : xutils2 iccjpeg2 ;
# mpp #2 $(MPP2LIBSRC)
if [ GLOB [ NormPaths . ] : mpp2.c ] {
Library libmpp2 : mpp2.c ;
LIBMPP2 += libmpp2 ;
}
# Utilities / test programs
LINKLIBS = libxicc ../spectro/libinsttypes ../gamut/libgamut ../rspl/librspl
../cgats/libcgats ../icc/libicc ../plot/libplot ../plot/libvrml $(LIBMPP2)
../spectro/libconv ../numlib/libnum ../numlib/libui
$(TIFFLIB) $(JPEGLIB) ;
LINKFLAGS += $(GUILINKFLAGS) ;
# Not created yet
#Main xicctest : xicctest.c ;
# Not created yet
#Main xlutest : xlutest.c ;
# expanded version of icclu
Main xicclu : xicclu.c ;
# expanded version of iccgamut - does Jab and ink limiting
Main iccgamut : iccgamut.c ;
# tiff file gamut utility
Main tiffgamut : tiffgamut.c : : : $(TIFFINC) $(JPEGINC) : : ;
# diagnostic utility
if [ GLOB [ NormPaths . ] : tiffgmts.c ] {
Main tiffgmts : tiffgmts.c : : : $(TIFFINC) $(JPEGINC) : : ../plot/libvrml ;
}
# Reverse profile fixer
Main revfix : revfix.c ;
# MPP lookup test utility
Main mpplu : mpplu.c ;
# Embedded ICC profile extractor
Main extracticc : extracticc.c : : : $(TIFFINC) $(JPEGINC) : : ;
# Text tag from ICC profile extracto
Main extractttag : extractttag.c : : : $(TIFFINC) $(JPEGINC) : : ;
# xcolorant lookup test
Main xcolorantslu : xcolorantslu.c ;
# Individual stand alone test of IES TM-30-15 */
MainVariant tm3015 : tm3015.c : : STANDALONE_TEST ;
#test program for viewing inverse algorithm
#Should be in JUNK ??
Main fbview : fbview.c ;
Main fakeCMY : fakeCMY.c : : : ../target ;
Main xfbview : xfbview.c ;
Main icheck : icheck.c ;
# Test FWA in xspect
Main spectest : spectest.c ;
# Test FWA in xspect 2
Main spectest2 : spectest2.c : : : : : ../spectro/libinsttypes ;
# Spectral plotting and CCT test
Main ccttest : ccttest.c ;
# transfer curve plotting
Main transplot : transplot.c ;
# CGATS .ti3 plotting
Main cgatsplot : cgatsplot.c ;
# per channel curve testing
Main cv : cv.c ;
# per channel curve fitting testing
Main cvtest : cvtest.c ;
# per channel curve fitting testing
Main cvtest : cvtest.c ;
# Generate sub sampled illuminants or observers */
Main specsubsamp : specsubsamp.c ;
# Plot spectrum and test CCT spectrum code and illuminant utility
Main specplot : specplot.c ;
# CAM test routines
Main bluelin : bluelin.c ;
Main cam02test : cam02test.c ;
Main cam02test : cam02test.c ;
# Test utility for moncurve
Main monctest : monctest.c ;
#Main cam02vecplot : cam02vecplot.c : : : : : ../plot/libvrml ;
#Home = ' d:\usr\graeme ' and PWD = ' /src/argyll/xicc '
if $(HOME) = "D:\\usr\\graeme" && $(PWD) = "/src/argyll/xicc" {
Echo "Creating test utilities" ;
#Create test TIFF file for cam02 conversion
Main cam02plot : cam02plot.c : : : $(TIFFINC) $(JPEGINC) : : ;
Main cam02logplot : cam02logplot.c : : : $(TIFFINC) $(JPEGINC) : : ;
Main cam02delplot : cam02delplot.c : : : $(TIFFINC) $(JPEGINC) : : ;
Main cam02vecplot : cam02vecplot.c : : : : : ../plot/libvrml ;
Main cusptest : cusptest.c : : : : : ../plot/libvrml ;
}
#Main t : t.c ;
# diagnostic utility
if [ GLOB [ NormPaths . ] : tennm.c ] {
Main tennm : tennm.c ;
}
if [ GLOB [ NormPaths . ] : cam16.c ] {
Main cam16vecplot : cam16vecplot.c cam16.c ;
}
if [ GLOB [ NormPaths . ] : voltest.c ] {
Main voltest : voltest.c ;
}
if [ GLOB [ NormPaths . ] : areatest.c ] {
Main areatest : areatest.c ;
}
if [ GLOB [ NormPaths . ] : chebtest.c ] {
Main chebtest : chebtest.c ;
}
#Main Lpttune : Lpttune.c ;
if $(BUILD_JUNK) {
LINKLIBS += ../render/librender ;
Main Lpttune : Lpttune.c ;
Main illlocus : illlocus.c ;
Main illlocus2 : illlocus2.c ;
Main slocustest : slocustest.c ;
MainsFromSources t1.c t2.c t22.c t23.c t24.c t3.c ;
Main test : test.c ;
Main t : t.c ;
# CAM97s3 matrix inversion calc
Main cammatrix : cammatrix.c ;
# test matrix deriv version
Main t : t.c ;
# Develop conjgrad version of code for profile
Main tt3 : tt3.c ;
# test icx_icc_cv_to_colorant_comb()
Main tcc : tcc.c ;
# Develop conjgrad version of code for profile
Main tt4 : tt4.c ;
# Test viewing conditions extractor
Main vctest : vctest.c ;
# ~~~ test code
Main lseptest : lseptest.c ;
# ~~~ test code
Main llseptest : llseptest.c ;
if [ GLOB [ NormPaths . ] : berntest.c ] {
Main berntest : berntest.c ;
}
if [ GLOB [ NormPaths . ] : chebytest.c ] {
Main chebytest : chebytest.c ;
}
}

662
Argyll_V3.5.0/xicc/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/>.

15
Argyll_V3.5.0/xicc/Readme.txt Executable file
View File

@@ -0,0 +1,15 @@
This directory holds the "expansion" icc libraries.
These suplement the base icc library with enhanced
profile functionality, such as smoothed interpolation,
reverse interpolation, table creation from scattered
data etc.
Most of this functionality is based on the rspl and icc libraries.
This is where ink limiting and black generation policies
for CMYK devices is implemented.
xicclu.exe is the analog of the icclib utility icclu, but
expands the capability to reverse lookup the
Lut tables.

68
Argyll_V3.5.0/xicc/afiles Executable file
View File

@@ -0,0 +1,68 @@
Readme.txt
License.txt
afiles
Jamfile
xicc.h
xicc.c
xmono.c
xmatrix.c
xlut.c
xcal.h
xcal.c
mpp.h
mpp.c
mpplu.c
ccmx.h
ccmx.c
ccss.h
ccss.c
xcolorants.h
xcolorants.c
xcolorantslu.c
xutils.h
xutils.c
iccjpeg.h
iccjpeg.c
xfit.h
xfit.c
xspect.h
xspect.c
specplot.c
specsubsamp.c
example.sp
xicclu.c
iccgamut.c
tiffgamut.c
tiffgmts.c
revfix.c
fakeCMY.c
xcam.h
xcam.c
cam97s3.c
cam97s3.h
cam97test.c
cam02.c
cam02.h
cam02ref.h
cam02test.c
cam02plot.c
bluelin.c
tm3015.h
tm3015.c
moncurve.c
moncurve.h
monctest.c
bt1886.h
bt1886.c
fbview.c
xfbview.c
icheck.c
transplot.c
cgatsplot.c
spectest.c
spectest2.c
ccttest.c
cv.c
cvtest.c
extracticc.c
extractttag.c

View File

@@ -0,0 +1,408 @@
/*
* International Color Consortium color transform expanded support
*
* Author: Graeme W. Gill
* Date: 23/22/2021
* Version: 1.00
*
* Copyright 2011-2021 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.
*
*/
/*
* Code for the cicam02 blue linearization hack.
*
* Inspired by "Color gamut mapping in a hue-linearized CIELAB color space"
* by Gustav Braun and Mark Fairchild.
*/
#include <stdio.h>
#include <stdarg.h>
#include <math.h>
#include "aconfig.h"
#include "icc.h"
#include "numlib.h"
#include "plot.h"
#include "xcam.h"
#include "cam02.h"
//#include "xicc.h"
#include "ui.h"
#define BLUELIN_h0 210.0 /* Low limit of hue angle to tweak */
#define BLUELIN_h1 330.0 /* High limit of hue angle at C0 to tweak */
#define BLUELIN_C0 50.0 /* Low limit of Chroma to tweak */
#define BLUELIN_C10 80.0 /* High end of Chroma to tweak */
#define BLUELIN_C11 140.0 /* High end of Hue and Chroma to tweak */
#define BLUELIN_AMNT 0.60 /* Amount to tweak hue (< 1.0 increases tweak) */
/* We are using simple linear interpolation for this. */
static void bluelin_fwd(double out[3], double in[3]) {
double J, C, h;
C = sqrt(in[1] * in[1] + in[2] * in[2]);
h = (180.0/DBL_PI) * atan2(in[2], in[1]);
h = (h < 0.0) ? h + 360.0 : h;
if (h >= BLUELIN_h0 && h <= BLUELIN_h1
&& C > BLUELIN_C0) {
double hh = (h - BLUELIN_h0)/(BLUELIN_h1 - BLUELIN_h0);
double gr, c1, amnt;
c1 = (1.0 - hh) * BLUELIN_C10 + hh * BLUELIN_C11;
gr = (C - BLUELIN_C0)/(c1 - BLUELIN_C0);
if (gr < 0.0)
gr = 0.0;
else if (gr > 1.0)
gr = 1.0;
amnt = (1.0 - gr) * 1.0 + gr * BLUELIN_AMNT;
if (hh < 0.5) {
hh = hh * amnt;
} else {
hh = (0.5 * amnt) + (hh - 0.5) * (1.0 - 0.5 * amnt)/0.5;
}
h = BLUELIN_h0 + hh * (BLUELIN_h1 - BLUELIN_h0);
}
h = DBL_PI/180.0 * h;
out[0] = in[0];
out[1] = C * cos(h);
out[2] = C * sin(h);
}
static void bluelin_bwd(double out[3], double in[3]) {
double J, C, h;
C = sqrt(in[1] * in[1] + in[2] * in[2]);
h = (180.0/DBL_PI) * atan2(in[2], in[1]);
h = (h < 0.0) ? h + 360.0 : h;
if (h >= BLUELIN_h0 && h <= BLUELIN_h1
&& C > BLUELIN_C0) {
double hh = (h - BLUELIN_h0)/(BLUELIN_h1 - BLUELIN_h0);
double ho = hh;
double gr, c1 = 0.0, pc1 = -100.0, amnt;
int j;
/* Should be able to compute inverse analytically, but for the moment */
/* we'll simply itterate to sufficient accuracy... */
for (j = 0; fabs(c1 - pc1) > 0.02 && j < 20; j++) {
pc1 = c1;
c1 = (1.0 - ho) * BLUELIN_C10 + ho * BLUELIN_C11;
gr = (C - BLUELIN_C0)/(c1 - BLUELIN_C0);
if (gr < 0.0)
gr = 0.0;
else if (gr > 1.0)
gr = 1.0;
amnt = (1.0 - gr) * 1.0 + gr * BLUELIN_AMNT;
if (hh < (0.5 * amnt)) {
ho = hh / amnt;
} else {
ho = 0.5 + (hh - 0.5 * amnt) * (1.0 - 0.5)/(1.0 - 0.5 * amnt);
}
}
h = BLUELIN_h0 + ho * (BLUELIN_h1 - BLUELIN_h0);
}
h = DBL_PI/180.0 * h;
out[0] = in[0];
out[1] = C * cos(h);
out[2] = C * sin(h);
}
typedef double xyzarray[3];
xyzarray bandh[];
xyzarray eandf[];
int
main(void) {
double in[3], lin[3], out[3];
double C, h;
cam02 *cam;
plot_g _g, *g = &_g;
double x1, y1;
double maxde = 0.0;
int hstart = 0;
int i, j;
float black[3] = { 0.0, 0.0, 0.0 };
init_g(g);
/* Explore effect and check it inverts */
for (h = 0.0; h <= 360.0; h += 10.0) {
for (C = 0.0; C <= 150.0; C += 2.0) {
double de;
in[0] = 50.0;
in[1] = C;
in[2] = h;
icmLCh2Lab(in, in);
bluelin_fwd(lin, in);
bluelin_bwd(out, lin);
icmLab2LCh(in, in);
icmLab2LCh(lin, lin);
icmLab2LCh(out, out);
/* We're plotting hue, Chromaticity */
if (C > 0.0) {
add_vec_g(g, x1, y1, lin[2], lin[1], NULL);
x1 = lin[2];
y1 = lin[1];
} else {
x1 = h;
y1 = C;
}
de = icmNorm33(in, out);
if (de > maxde)
maxde = de;
if (de > 0.01) {
printf("%f %f %f -> %f %f %f de %f\n", in[0], in[1], in[2], out[0], out[1], out[2], de);
}
}
}
printf("Maxde = %f\n",maxde);
printf("Hue transformation:\n");
do_plot_g(g, 0.0, 0.0, 0.0, 0.0, 1.0, 0, 1);
clear_g(g);
/* Plot the constant hue data */
cam = new_cam02();
/* Data has D65 white point */
cam->set_view(cam, vc_average, icmD65_ary3, 33, 0.2, 0.0, 0.0, 0.0, icmD65_ary3, 0, 0.0, 0.0, NULL);
cam->bluelin = 0; /* Turn off built in version */
#ifndef NEVER
hstart = 0;
for (i = 0; ; i++) {
double xyz[3], Jab[3];
if (bandh[i][1] < 0.0)
break;
if (bandh[i][1] == 0.0) {
hstart = 1;
}
icmScale3(xyz, bandh[i], 0.01);
cam->XYZ_to_cam(cam, Jab, xyz);
bluelin_fwd(Jab, Jab);
if (hstart) {
x1 = Jab[1];
y1 = Jab[2];
hstart = 0;
} else {
add_vec_g(g, x1, y1, Jab[1], Jab[2], NULL);
x1 = Jab[1];
y1 = Jab[2];
}
// add_sym_g(g, Jab[1], Jab[2], plotDiamond, black, NULL);
}
printf("Berns and Hung::\n");
do_plot_g(g, 0.0, 0.0, 0.0, 0.0, 1.0, 0, 1);
clear_g(g);
#endif // NEVER
#ifndef NEVER
hstart = 0;
for (i = 0; ; i++) {
double xyz[3], Jab[3];
if (eandf[i][1] < 0.0)
break;
if (eandf[i][1] == 0.0) {
hstart = 1;
}
icmScale3(xyz, eandf[i], 0.01);
cam->XYZ_to_cam(cam, Jab, xyz);
bluelin_fwd(Jab, Jab);
if (hstart) {
x1 = Jab[1];
y1 = Jab[2];
hstart = 0;
} else {
add_vec_g(g, x1, y1, Jab[1], Jab[2], NULL);
x1 = Jab[1];
y1 = Jab[2];
}
}
printf("Ebner and Fairchil:\n");
do_plot_g(g, 0.0, 0.0, 0.0, 0.0, 1.0, 0, 1);
clear_g(g);
#endif
return 0;
}
/* Constant hue reference data */
/* 0,0,0 marks start of a hue */
/* -1,-1,-1 marks end of data */
/* Berns and Hung (1995) data set, table IV, variable luminance */
xyzarray bandh[] = {
0,0,0,
4.74,2.99,0.48,
10.36,6.24,0.95,
19.13,11.25,1.19,
32.06,18.42,2.00,
49.21,28.12,2.58,
59.12,40.75,14.70,
68.39,56.68,35.70,
82.47,76.30,68.26,
54.45,30.90,2.54,
0,0,0,
3.48,2.99,0.85,
7.24,6.24,1.49,
12.97,11.25,2.34,
20.97,18.42,3.40,
31.96,28.12,4.78,
45.10,40.75,5.83,
62.88,56.68,7.85,
77.59,76.30,41.69,
68.22,61.38,7.91,
0,0,0,
3.04,2.99,0.83,
6.24,6.24,1.41,
10.62,11.25,2.05,
16.55,18.42,3.00,
25.72,28.12,4.52,
36.51,40.75,6.30,
49.80,56.68,8.62,
65.79,76.30,11.49,
86.15,100.41,14.92,
0,0,0,
2.55,2.99,0.60,
5.07,6.24,1.11,
8.99,11.25,1.82,
14.15,18.42,3.04,
20.85,28.12,4.57,
29.27,40.75,6.77,
40.71,56.68,9.19,
53.86,76.30,12.42,
65.62,94.72,15.28,
0,0,0,
1.81,2.99,0.68,
3.19,6.24,1.44,
5.99,11.25,2.77,
9.31,18.42,4.10,
14.29,28.12,6.38,
20.22,40.75,8.20,
27.52,56.68,10.67,
36.43,76.30,14.41,
35.93,77.65,13.93,
0,0,0,
2.03,2.99,4.54,
4.21,6.24,9.44,
7.36,11.25,15.44,
11.98,18.42,25.00,
17.52,28.12,33.65,
24.98,40.75,45.66,
34.39,56.68,61.34,
45.77,76.30,79.24,
50.38,84.76,86.02,
0,0,0,
2.64,2.99,6.14,
5.18,6.24,12.38,
8.99,11.25,21.68,
14.05,18.42,34.08,
21.06,28.12,51.05,
29.14,40.75,69.47,
39.60,56.68,93.01,
56.89,76.30,116.12,
49.55,72.27,114.91,
0,0,0,
2.87,2.99,7.64,
5.88,6.24,16.11,
10.23,11.25,28.98,
15.91,18.42,46.23,
24.24,28.12,70.16,
33.44,40.75,98.09,
48.22,56.68,108.94,
70.64,76.30,113.17,
37.25,45.26,111.12,
0,0,0,
5.20,2.99,23.94,
11.35,6.24,54.22,
20.31,11.25,96.15,
22.80,18.42,92.90,
30.05,28.12,101.82,
39.46,40.75,105.02,
53.22,56.68,107.06,
71.87,76.30,109.79,
21.68,10.77,105.09,
0,0,0,
5.27,2.99,8.50,
11.40,6.24,21.73,
20.97,11.25,43.13,
34.75,18.42,78.57,
47.15,28.12,107.15,
55.18,40.75,109.58,
66.66,56.68,111.96,
79.84,76.30,115.40,
44.79,23.30,105.63,
0,0,0,
5.26,2.99,5.82,
11.20,6.24,14.50,
20.53,11.25,27.51,
33.79,18.42,45.88,
51.91,28.12,75.26,
70.08,40.75,105.76,
76.29,56.68,110.69,
85.39,76.30,114.39,
68.73,36.83,106.85,
0,0,0,
11.06,6.24,10.47,
19.96,11.25,16.62,
32.72,18.42,25.91,
50.38,28.12,40.77,
68.29,40.75,65.68,
77.47,56.68,86.26,
88.50,76.30,104.63,
64.36,35.53,53.66,
65.64,35.53,45.43,
-1,-1,-1
};
/* Ebner and Fairchild (1998) set */
xyzarray eandf[] = {
0,0,0, 2.4951, 1.9086, 2.0329, 3.3296, 1.9086, 2.1063, 5.7386, 2.9891, 3.2447, 7.3706, 6.2359, 7.0514, 9.0418, 6.2359, 6.8901, 10.9443, 6.2359, 6.7881, 12.0597, 6.2359, 6.6805, 21.6475, 11.251, 12.3602, 20.4172, 18.4187, 20.1965, 23.6417, 18.4187, 20.1739, 27.1865, 18.4187, 19.5653, 31.0729, 18.4187, 19.715, 35.5801, 18.4187, 18.1154, 52.2309, 28.1233, 30.6758, 43.6118, 40.7494, 44.221, 48.8989, 40.7494, 44.8546, 54.6008, 40.7494, 44.2074, 59.4653, 40.7494, 45.0086, 69.1717, 56.6813, 61.9143, 80.3849, 76.3034, 83.6166,
0,0,0, 2.3295, 2.9891, 1.2151, 5.0776, 6.2359, 3.235, 4.5813, 6.2359, 1.0648, 12.3217, 14.5417, 9.1954, 11.1245, 14.5417, 4.5894, 13.1275, 18.4187, 2.587, 24.2342, 28.1233, 20.1576, 22.2813, 28.1233, 12.0243, 20.4891, 28.1233, 6.415, 20.0979, 28.1233, 4.006, 42.0356, 48.2781, 37.6153, 39.2198, 48.2781, 24.84, 36.5407, 48.2781, 15.3761, 34.4596, 48.2781, 8.4394, 40.0128, 56.6813, 8.182, 52.6749, 76.3034, 11.314, 67.2532, 76.3034, 62.5084, 62.8152, 76.3034, 44.9196, 58.6004, 76.3034, 30.9764, 55.5877, 76.3034, 19.4968,
0,0,0, 2.057, 2.9891, 1.6832, 1.3952, 2.9891, 0.8032, 8.6184, 11.251, 8.5273, 6.9267, 11.251, 5.3448, 5.5532, 11.251, 2.8928, 8.2777, 18.4187, 4.1966, 22.8649, 28.1233, 23.4216, 19.4735, 28.1233, 17.196, 16.3555, 28.1233, 12.4344, 13.8615, 28.1233, 7.9293, 12.6312, 28.1233, 6.3504, 28.1591, 56.6813, 16.2474, 25.2804, 56.6813, 12.9911, 47.6451, 56.6813, 49.9746, 41.9222, 56.6813, 39.8854, 37.2596, 56.6813, 29.3883, 32.1493, 56.6813, 23.1624, 29.5765, 66.007, 14.7727, 47.6799, 76.3034, 35.121, 70.119, 87.6183, 69.0486,
0,0,0, 2.108, 2.9891, 2.7904, 1.6702, 2.9891, 2.3311, 3.4115, 6.2359, 5.1996, 8.8419, 11.251, 11.3399, 7.2572, 11.251, 9.8606, 6.1947, 11.251, 9.3344, 10.0632, 18.4187, 15.1057, 23.2833, 28.1233, 28.5625, 20.1319, 28.1233, 26.9643, 17.3352, 28.1233, 24.4685, 15.2558, 28.1233, 23.2349, 22.1968, 40.7494, 33.9779, 48.3497, 56.6813, 57.9764, 43.2329, 56.6813, 54.4056, 38.5515, 56.6813, 50.1932, 34.1577, 56.6813, 47.0353, 30.8994, 56.6813, 44.527, 35.9901, 66.007, 50.7477, 49.0016, 76.3034, 63.8159, 62.2486, 82.967, 76.3862,
0,0,0, 2.3453, 2.9891, 3.7174, 1.926, 2.9891, 4.4245, 4.0173, 6.2359, 9.6191, 9.4684, 11.251, 13.3777, 8.3988, 11.251, 15.2001, 7.3638, 11.251, 16.5584, 11.6981, 18.4187, 25.5249, 24.3887, 28.1233, 31.9199, 22.2844, 28.1233, 34.5849, 20.2715, 28.1233, 36.817, 18.2763, 28.1233, 37.3909, 25.4976, 40.7494, 52.8133, 50.1257, 56.6813, 64.0076, 46.5487, 56.6813, 66.0339, 43.1626, 56.6813, 68.3981, 39.8701, 56.6813, 69.2512, 35.2616, 56.6813, 70.4797, 46.08, 74.1641, 88.1726, 58.2443, 80.7044, 93.9569, 71.4332, 87.6183, 99.9575,
0,0,0, 2.4666, 2.9891, 4.4851, 2.2448, 2.9891, 5.9111, 4.6165, 6.2359, 12.0332, 9.74, 11.251, 14.9949, 8.8882, 11.251, 18.3141, 8.1128, 11.251, 21.4127, 13.2261, 18.4187, 34.5513, 24.8999, 28.1233, 35.3653, 23.1907, 28.1233, 40.724, 21.6271, 28.1233, 46.921, 19.8433, 28.1233, 50.4344, 28.2041, 40.7494, 69.0229, 50.8535, 56.6813, 68.8802, 47.8889, 56.6813, 76.2798, 44.6584, 56.6813, 82.046, 41.6195, 56.6813, 88.1993, 39.0704, 56.6813, 94.4482, 49.8666, 66.007, 100.2007, 62.9735, 76.3034, 103.0157, 78.0945, 87.6183, 105.3757,
0,0,0, 2.4364, 1.9086, 1.4688, 3.168, 1.9086, 0.9391, 5.5818, 2.9891, 1.1895, 7.265, 6.2359, 5.462, 8.7473, 6.2359, 4.1462, 10.3312, 6.2359, 2.8546, 11.6178, 6.2359, 2.127, 20.8807, 11.251, 3.7728, 20.1146, 18.4187, 16.7921, 23.0654, 18.4187, 14.2768, 26.3119, 18.4187, 12.1097, 29.4922, 18.4187, 9.1904, 33.7924, 18.4187, 5.6569, 41.9121, 22.9298, 6.3588, 52.713, 34.0472, 18.642, 43.1587, 40.7494, 39.0086, 47.8373, 40.7494, 33.728, 52.8667, 40.7494, 29.0411, 66.526, 56.6813, 45.7942, 79.0894, 76.3034, 74.2766,
0,0,0, 2.6197, 2.9891, 4.9052, 2.4789, 2.9891, 6.9067, 5.0943, 6.2359, 14.577, 10.1162, 11.251, 15.9858, 9.6673, 11.251, 20.6324, 9.2055, 11.251, 26.0341, 14.8942, 18.4187, 42.8274, 25.5352, 28.1233, 37.1142, 24.4632, 28.1233, 44.6614, 23.4074, 28.1233, 53.131, 22.2932, 28.1233, 62.3583, 31.9264, 40.7494, 92.1437, 44.1905, 48.2781, 61.8135, 42.3672, 48.2781, 71.7357, 40.7141, 48.2781, 82.9579, 39.2461, 48.2781, 95.6828, 47.2962, 56.6813, 100.3071, 57.2536, 66.007, 101.5921, 67.9355, 76.3034, 103.436,
0,0,0, 2.7982, 2.9891, 8.6685, 4.1208, 4.4155, 7.1309, 4.1612, 4.4155, 10.1433, 6.0966, 6.2359, 18.7302, 10.5606, 11.251, 16.4317, 10.4042, 11.251, 21.4695, 10.4747, 11.251, 27.5383, 10.5836, 11.251, 33.8709, 18.1547, 18.4187, 55.3577, 26.2553, 28.1233, 38.0059, 25.8303, 28.1233, 46.5439, 25.9521, 28.1233, 56.6217, 26.7324, 28.1233, 68.0523, 28.0301, 28.1233, 84.418, 33.806, 34.0472, 96.8792, 42.4315, 45.1644, 99.9617, 52.8874, 56.6813, 73.1468, 52.3387, 56.6813, 86.2998, 52.4765, 56.6813, 101.3278, 70.8398, 76.3034, 102.9002,
0,0,0, 3.0398, 2.9891, 6.1233, 3.3574, 2.9891, 10.1548, 3.7776, 2.9891, 14.0607, 8.1239, 6.2359, 28.9466, 8.3832, 8.4984, 14.7224, 8.87, 8.4984, 21.8435, 9.7338, 8.4984, 30.3378, 11.1523, 8.4984, 39.3449, 15.0163, 11.251, 50.4059, 17.9346, 18.4187, 28.9351, 18.4058, 18.4187, 40.1114, 19.842, 18.4187, 52.7573, 21.8326, 18.4187, 66.4797, 24.474, 18.4187, 83.4294, 32.3931, 28.1233, 95.1349, 32.5501, 34.0472, 50.2969, 33.1968, 34.0472, 66.2406, 35.3672, 34.0472, 83.913, 36.8082, 34.0472, 96.9789, 45.6537, 45.1644, 100.359, 53.8261, 56.6813, 80.0104, 55.3271, 56.6813, 101.2963, 72.3061, 76.3034, 105.1867,
0,0,0, 3.7048, 2.9891, 5.9648, 4.754, 2.9891, 9.7663, 6.0374, 2.9891, 14.6405, 7.3117, 2.9891, 19.7734, 15.1352, 6.2359, 42.7145, 19.0702, 8.4984, 52.0012, 9.6873, 8.4984, 14.6268, 11.4333, 8.4984, 22.0239, 13.6517, 8.4984, 30.3894, 16.1808, 8.4984, 40.3975, 27.2723, 11.251, 78.181, 34.004, 18.4187, 85.7156, 19.9887, 18.4187, 29.2578, 22.6043, 18.4187, 41.2528, 26.022, 18.4187, 53.9744, 29.6726, 18.4187, 69.3691, 42.7495, 28.1233, 95.3079, 35.8782, 34.0472, 51.104, 39.7286, 34.0472, 68.1086, 44.5219, 34.0472, 86.2127, 52.0133, 40.7494, 99.9868, 58.4479, 56.6813, 81.8948, 63.3425, 56.6813, 104.0201, 77.4496, 76.3034, 106.882,
0,0,0, 5.9792, 2.9891, 6.7983, 5.6611, 4.4155, 6.4892, 7.4487, 4.4155, 8.4184, 12.5371, 6.2359, 14.8021, 16.887, 14.5417, 19.8849, 20.5757, 14.5417, 23.2471, 24.6615, 14.5417, 27.6573, 29.0646, 14.5417, 33.9618, 37.1009, 18.4187, 44.326, 55.3607, 28.1233, 75.2024, 31.4203, 28.1233, 36.8351, 36.8426, 28.1233, 42.4991, 42.7739, 28.1233, 49.2386, 48.8039, 28.1233, 60.1262, 65.0875, 40.7494, 82.7335, 52.4811, 48.2781, 61.791, 59.8114, 48.2781, 71.3579, 67.3205, 48.2781, 84.8059, 72.5461, 56.6813, 91.3143, 82.5715, 76.3034, 98.8142,
0,0,0, 3.6781, 2.9891, 1.4811, 4.3912, 2.9891, 0.4572, 7.2096, 6.2359, 3.6436, 8.6369, 6.2359, 1.6378, 9.3726, 6.2359, 0.7023, 17.1277, 11.251, 1.2299, 15.9324, 14.5417, 9.8473, 18.4248, 14.5417, 5.7809, 20.8121, 14.5417, 2.8115, 27.2709, 18.4187, 1.7329, 30.0809, 28.1233, 21.2298, 33.7425, 28.1233, 14.0395, 37.1325, 28.1233, 8.2291, 38.9601, 28.1233, 3.5885, 40.9676, 28.1233, 2.275, 52.976, 40.7494, 11.72, 50.1955, 48.2781, 38.0164, 54.5519, 48.2781, 26.1853, 63.3032, 56.6813, 32.6901, 77.0216, 76.3034, 65.1076,
0,0,0, 3.3197, 2.9891, 1.148, 3.5138, 2.9891, 0.6227, 6.6846, 6.2359, 3.0931, 7.4603, 6.2359, 1.1325, 13.4731, 11.251, 1.8616, 14.8686, 14.5417, 8.7303, 16.3904, 14.5417, 4.3255, 21.7903, 18.4187, 2.9308, 28.5178, 28.1233, 19.2981, 30.4615, 28.1233, 11.2259, 32.3158, 28.1233, 5.7361, 33.187, 28.1233, 4.2045, 46.0119, 40.7494, 5.6175, 48.3113, 48.2781, 35.8235, 50.4509, 48.2781, 22.8894, 52.5746, 48.2781, 13.4945, 54.6262, 48.2781, 7.0769, 61.6913, 56.6813, 16.4547, 67.8322, 66.007, 33.3101, 75.4525, 76.3034, 54.1791,
0,0,0, 2.8909, 2.9891, 1.0142, 5.9861, 6.2359, 2.8395, 6.187, 6.2359, 1.0384, 10.8221, 11.251, 1.7582, 13.8453, 14.5417, 8.4043, 14.0725, 14.5417, 3.7708, 17.4718, 18.4187, 2.7642, 26.6956, 28.1233, 18.6195, 26.7106, 28.1233, 10.2615, 26.5222, 28.1233, 4.8764, 37.8172, 40.7494, 6.0499, 45.2991, 48.2781, 34.9471, 44.8363, 48.2781, 21.7887, 44.4752, 48.2781, 12.426, 51.2315, 56.6813, 8.5942, 70.9748, 76.3034, 58.9282, 70.1174, 76.3034, 39.8412, 69.8154, 76.3034, 25.3302, 70.5383, 76.3034, 14.8054, 70.4427, 76.3034, 11.249,
-1,-1,-1
};

348
Argyll_V3.5.0/xicc/bt1886.c Normal file
View File

@@ -0,0 +1,348 @@
/*
* Author: Graeme W. Gill
* Date: 16/8/13
* Version: 1.00
*
* Copyright 2013, 2014 Graeme W. Gill
* All rights reserved.
*
* This material is licenced under the GNU AFFERO GENERAL PUB LICENSE Version 3 :-
* see the License.txt file for licencing details.
*
*/
/* BT.1886 type input offset transfer curve, */
/* + general gamma + input + output offset curve support. */
#include <sys/types.h>
#include <string.h>
#include <ctype.h>
#ifdef __sun
#include <unistd.h>
#endif
#include "numlib.h"
#include "icc.h" /* definitions for this library */
#include "bt1886.h" /* definitions for this library */
#undef DEBUG
/* BT.1886 support */
/* This is both a EOTF curve, and a white point */
/* adjustment. */
/* Compute technical gamma from effective gamma in BT.1886 style */
/* Info for optimization */
typedef struct {
double wp; /* 100% input target */
double thyr; /* 50% input target */
double bp; /* 0% input target */
} gam_fits;
/* gamma + input offset function handed to powell() */
static double gam_fit(void *dd, double *v) {
gam_fits *gf = (gam_fits *)dd;
double gamma = v[0];
double a, b;
double rv = 0.0;
double t1, t2;
if (gamma < 0.0) {
rv += 100.0 * -gamma;
gamma = 1e-4;
}
t1 = pow(gf->bp, 1.0/gamma);
t2 = pow(gf->wp, 1.0/gamma);
b = t1/(t2 - t1); /* Offset */
a = pow(t2 - t1, gamma); /* Gain */
/* Comput 50% output for this technical gamma */
/* (All values are without output offset being added in) */
t1 = a * pow((0.5 + b), gamma);
t1 = t1 - gf->thyr;
rv += t1 * t1;
return rv;
}
/* Given the effective gamma and the output offset Y, */
/* return the technical gamma needed for the correct 50% response. */
static double xicc_tech_gamma(
double egamma, /* effective gamma needed */
double off, /* Output offset required */
double outoprop /* Prop. of offset to be accounted for on output */
) {
gam_fits gf;
double outo;
double op[1], sa[1], rv;
if (off <= 0.0) {
return egamma;
}
/* We set up targets without outo being added */
outo = off * outoprop; /* Offset acounted for in output */
gf.bp = off - outo; /* Black value for 0 % input */
gf.wp = 1.0 - outo; /* White value for 100% input */
gf.thyr = pow(0.5, egamma) - outo; /* Advetised 50% target */
op[0] = egamma;
sa[0] = 0.1;
if (powell(&rv, 1, op, sa, 1e-6, 500, gam_fit, (void *)&gf, NULL, NULL) != 0)
warning("Computing effective gamma and input offset is inaccurate");
return op[0];
}
/* Set the bt1886_info to a default do nothing state */
void bt1886_setnop(bt1886_info *p) {
icmXYZ2XYZ(p->w, icmD50);
p->ingo = 0.0;
p->outsc = 1.0;
p->outo = 0.0;
p->outL = 0.0;
p->tab[0] = 0.0;
p->tab[1] = 0.0;
}
/* Setup the bt1886_info for the given target black point, proportion of */
/* offset to be accounted for on output, and gamma. */
/* wp XYZ simply sets the L*a*b* reference */
/* Pure BT.1886 will have outopro = 0.0 and gamma = 2.4 */
void bt1886_setup(
bt1886_info *p,
icmXYZNumber *w, /* wp used for L*a*b* conversion */
double *XYZbp, /* normalised bp used for black offset and black point hue "bend" */
double outoprop, /* 0..1 proportion of output black point compensation */
double gamma, /* technical or effective gamma */
int effg /* nz if effective gamma, z if technical gamma */
) {
double Lab[3], ino, bkipow, wtipow;
icmXYZ2XYZ(p->w, *w);
#ifdef DEBUG
a1logd(g_log, 2, "bt1886_setup wp.Y %f, bp.Y %f, outprop %f, gamma %f, effg %d", p->w.Y, XYZbp[1], outoprop, gamma, effg);
#endif
if (effg) {
p->gamma = xicc_tech_gamma(gamma, XYZbp[1], outoprop);
#ifdef DEBUG
a1logd(g_log, 2, "bt1886_setup tgamma %f", p->gamma);
#endif
} else {
p->gamma = gamma;
}
icmXYZ2Lab(&p->w, Lab, XYZbp);
p->outL = Lab[0]; /* For bp blend comp. */
p->tab[0] = Lab[1]; /* a* b* correction needed */
p->tab[1] = Lab[2];
#ifdef DEBUG
a1logd(g_log, 2, "bt1886_setup bend Lab = %f %f %f", p->outL, p->tab[0], p->tab[1]);
#endif
if (XYZbp[1] < 0.0)
XYZbp[1] = 0.0;
p->outo = XYZbp[1] * outoprop; /* Offset acounted for in output */
ino = XYZbp[1] - p->outo; /* Balance of offset accounted for in input */
bkipow = pow(ino, 1.0/p->gamma); /* Input offset black to 1/pow */
wtipow = pow((1.0 - p->outo), 1.0/p->gamma); /* Input offset white to 1/pow */
#ifdef DEBUG
a1logd(g_log, 2, "bt1886_setup outo %f, ino %f, bkipow %f, wtipow %f", p->outo, ino, bkipow, wtipow);
#endif
p->ingo = bkipow/(wtipow - bkipow); /* non-linear Y that makes input offset */
/* proportion of black point */
p->outsc = pow(wtipow - bkipow, p->gamma); /* Scale to make input of 1 map to */
/* 1.0 - p->outo */
#ifdef DEBUG
a1logd(g_log, 2, "bt1886_setup ingo %f, outsc %f", p->ingo, p->outsc);
#endif
}
/* Apply BT.1886 eotf curve to the device RGB value */
/* to produce a linear light RGB. We pass xvYCC out of range values through. */
void bt1886_fwd_curve(bt1886_info *p, double *out, double *in) {
int j;
#ifdef DEBUG
a1logd(g_log, 2, "bt1886 Dev RGB in %f %f %f, pow %f\n", in[0],in[1],in[2], p->gamma);
a1logd(g_log, 2, "outo %f, outsc %f, pow %f\n", p->outo, p->outsc, 1.0/p->gamma);
a1logd(g_log, 2, "ingo %f, pow %f, outsc %f, outo %f\n", p->ingo, p->gamma, p->outsc,p->outo);
#endif
for (j = 0; j < 3; j++) {
int neg = 0;
double vv = in[j];
if (vv < 0.0) { /* Allow for xvYCC */
neg = 1;
vv = -vv;
}
/* Apply input offset */
vv += p->ingo;
/* Apply power and scale */
if (vv > 0.0)
vv = p->outsc * pow(vv, p->gamma);
/* Apply output portion of offset */
vv += p->outo;
if (neg)
vv = -vv;
out[j] = vv;
}
#ifdef DEBUG
a1logd(g_log, 2, "bt1886 linear RGB out %f %f %f\n", out[0],out[1],out[2]);
#endif
}
/* Apply inverse BT.1886 eotf curve to the linear light RGB to produce */
/* device RGB values. We pass xvYCC out of range values through. */
void bt1886_bwd_curve(bt1886_info *p, double *out, double *in) {
int j;
#ifdef DEBUG
a1logd(g_log, 2, "bt1886 linear RGB in %f %f %f\n", in[0],in[1],in[2]);
a1logd(g_log, 2, "outo %f, outsc %f, pow %f, ingo %f\n", p->outo, p->outsc, 1.0/p->gamma,p->ingo);
#endif
for (j = 0; j < 3; j++) {
int neg = 0;
double vv = in[j];
if (vv < 0.0) { /* Allow for xvYCC */
neg = 1;
vv = -vv;
}
/* Un-apply output portion of offset */
vv -= p->outo;
/* Un-apply power and scale */
if (vv > 0.0)
vv = pow(vv/p->outsc, 1.0/p->gamma);
/* Un-apply input offset */
vv -= p->ingo;
if (neg)
vv = -vv;
out[j] = vv;
}
#ifdef DEBUG
a1logd(g_log, 2, "bt1886 Dev RGB out %f %f %f\n", in[0],in[1],in[2]);
#endif
}
/* Apply BT.1886 processing black point hue adjustment to the XYZ value */
void bt1886_wp_adjust(bt1886_info *p, double *out, double *in) {
double vv;
#ifdef DEBUG
a1logd(g_log, 2, "bt1886 XYZ wp adj. in %f %f %f\n", in[0],in[1],in[2]);
#endif
icmXYZ2Lab(&p->w, out, in);
#ifdef DEBUG
a1logd(g_log, 2, "bt1886 Lab wp adj. in %f %f %f\n", out[0],out[1],out[2]);
#endif
/* Blend ab to required black point offset p->tab[] as L approaches black. */
vv = (out[0] - p->outL)/(100.0 - p->outL); /* 0 at bp, 1 at wp */
vv = 1.0 - vv;
if (vv < 0.0)
vv = 0.0;
else if (vv > 1.0)
vv = 1.0;
vv = pow(vv, 40.0);
out[1] += vv * p->tab[0];
out[2] += vv * p->tab[1];
#ifdef DEBUG
a1logd(g_log, 2, "bt1886 Lab after wp adj. %f %f %f\n", out[0],out[1],out[2]);
#endif
icmLab2XYZ(&p->w, out, out);
#ifdef DEBUG
a1logd(g_log, 2, "bt1886 XYZ after wp adj. %f %f %f\n", out[0],out[1],out[2]);
#endif
}
/* Apply inverse BT.1886 processing black point hue adjustment to the XYZ value */
void bt1886_inv_wp_adjust(bt1886_info *p, double *out, double *in) {
double vv;
#ifdef DEBUG
a1logd(g_log, 2, "bt1886 XYZ inv. wp adj. in %f %f %f\n", in[0],in[1],in[2]);
#endif
icmXYZ2Lab(&p->w, out, in);
#ifdef DEBUG
a1logd(g_log, 2, "bt1886 Lab inv. wp adj. in %f %f %f\n", out[0],out[1],out[2]);
#endif
/* Blend ab to required black point offset p->tab[] as L approaches black. */
vv = (out[0] - p->outL)/(100.0 - p->outL); /* 0 at bp, 1 at wp */
vv = 1.0 - vv;
if (vv < 0.0)
vv = 0.0;
else if (vv > 1.0)
vv = 1.0;
vv = pow(vv, 40.0);
out[1] -= vv * p->tab[0];
out[2] -= vv * p->tab[1];
#ifdef DEBUG
a1logd(g_log, 2, "bt1886 Lab after inv. wp adj. %f %f %f\n", out[0],out[1],out[2]);
#endif
icmLab2XYZ(&p->w, out, out);
#ifdef DEBUG
a1logd(g_log, 2, "bt1886 XYZ after inv. wp adj. %f %f %f\n", out[0],out[1],out[2]);
#endif
}

View File

@@ -0,0 +1,93 @@
#ifndef BT1886_H
#define BT1886_H
/*
* Author: Graeme W. Gill
* Date: 16/8/13
* Version: 1.00
*
* Copyright 2013, 2014 Graeme W. Gill
* All rights reserved.
*
* This material is licenced under the GNU AFFERO GENERAL PUB LICENSE Version 3 :-
* see the License.txt file for licencing details.
*
*/
/* BT.1886 type input offset transfer curve, */
/* + general gamma + input + output offset curve support. */
typedef struct {
icmXYZNumber w; /* White point for Lab conversion */
double ingo; /* input Y offset for bt1886 */
double outsc; /* output Y scale for bt1886 */
double outo; /* output Y offset */
double outL; /* output black point L value */
double tab[2]; /* Target ab offset value at zero input for bt1886 */
double gamma; /* bt.1886 technical gamma to apply */
} bt1886_info;
/* Set the bt1886_info to a default do nothing state */
void bt1886_setnop(bt1886_info *p);
/* Setup the bt1886_info for the given target */
void bt1886_setup(
bt1886_info *p,
icmXYZNumber *w, /* wp used for L*a*b* conversion */
double *XYZbp, /* normalised bp used for black offset and black point hue "bend" */
double outoprop, /* 0..1 proportion of output black point compensation */
double gamma, /* technical or effective gamma */
int effg /* nz if effective gamma, z if technical gamma */
);
/* Apply BT.1886 eotf curve to the device RGB value */
/* to produce a linear light RGB. We pass xvYCC out of range values through. */
void bt1886_fwd_curve(bt1886_info *p, double *out, double *in);
/* Apply BT.1886 processing black point hue adjustment to the XYZ value */
void bt1886_wp_adjust(bt1886_info *p, double *out, double *in);
/* Apply inverse BT.1886 eotf curve to the device RGB value */
/* to produce a linear light RGB. We pass xvYCC out of range values through. */
void bt1886_bwd_curve(bt1886_info *p, double *out, double *in);
/* Apply inverse BT.1886 processing black point hue adjustment to the XYZ value */
void bt1886_inv_wp_adjust(bt1886_info *p, double *out, double *in);
#endif /* BT1886_H */

1582
Argyll_V3.5.0/xicc/cam02.c Normal file

File diff suppressed because it is too large Load Diff

239
Argyll_V3.5.0/xicc/cam02.h Normal file
View File

@@ -0,0 +1,239 @@
/*
* cam02
*
* Color Appearance Model, based on
* CIECAM02, "The CIECAM02 Color Appearance Model"
* by Nathan Moroney, Mark D. Fairchild, Robert W.G. Hunt, Changjun Li,
* M. Ronnier Luo and Todd Newman, IS&T/SID Tenth Color Imaging
* Conference, with the addition of a Viewing Flare+Glare
* model, and the Helmholtz-Kohlrausch effect, using the equation
* the Bradford-Hunt 96C model as detailed in Mark Fairchilds
* book "Color Appearance Models".
*
* Author: Graeme W. Gill
* Date: 17/1/2004
* Version: 1.00
*
* This file is based on cam97s3.h by Graeme Gill.
*
* Copyright 2004 - 2014 Graeme W. Gill
* Please refer to COPYRIGHT file for details.
* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :-
* see the License.txt file for licencing details.
*/
/* Definitions assumed here:
Stimulus field is the 2 degrees field of view of the sample
being characterised.
Viewing/Scene/Image field is the area of the whole image or
display surface that the stimulus is part of.
Background field is 10-12 degree field immediately surrounding the stimulus field.
This may be within, overlap or encompass the Viewing/Scene/Image field.
Visual field is the 130 degree angular field that is seen by the eyes.
Surround/Adapting field is the visual field minus the background field,
and is what is assumed to be setting the viewers light adaptation level.
Ambient field is general illumination from the sun or general lighting,
and is the whole surrounding environmental light field.
Illuminating field is the field that illuminates the reflective
Scene/Image. It may be the same as the Ambient field or it could
be a specific light source that is directed to the viewing scene..
NOTE: In "Digital Color Management", Giorgianni and Madden use the term
"Surround" to mean the same thing as "Background" in the CIECAM02 terminology.
The ICC standard doesn't define what it means by "Surround illumination".
*/
/* Rules of Thumb: */
/* Ambient Luminance (Lamb, cd/m^2) is Ambient Illuminance (Eamb, Lux) divided by PI. */
/* i.e. Lamb = Eamb/PI */ /* (1 foot candle = 0.0929 lux) */
/* Illuminating field Luminance (Li, cd/m^2) is the Illuminating field Illuminance (Ei, Lux) */
/* divide by PI. i.e. Li = Ei/PI */
/* The Adapting/Surround Luminance is La often taken to be */
/* the 20% of the Ambient Luminance (gray world, 50% perceptual) */
/* i.e. La = Lamb/5 = Eamb/15.7 */
/* If the Illuminating field covers the Adapting/surround, the it will be 20% of the */
/* Illuminating field. */
/* For a reflective print, the Viewing/Scene/Image luminance (Lv, cd/m^2), */
/* will be the Illuminating Luminance (Li, cd/m^2) or the Ambient Luminance (Lamb, cd/m^2) */
/* reflected by the media white point (Yw) */
/* If there is no special illumination for a reflective print, */
/* then the Illuminating Luminance (Li) will be the Ambient Luminance (Lamb) */
/* An emisive display will have an independently determined Lv. */
/* The classification of the type of surround is */
/* determined by comparing the Adapting/Surround luminance (La, cd/m^2) */
/* with the average luminance of the Viewing/Scene/Image field (Lv, cd/m^2) */
/* La/Lv == 0%, dark */
/* La/Lv 0 - 20%, dim */
/* La/Lv > 20%, average */
/* special, cut sheet */
/* The Background relative luminance Yb is typically assumed to */
/* be 0.18 .. 0.2, and is assumed to be grey. */
/* Flare is assumed to be stray light from light parts of the */
/* image illuminating dark parts of the image, and is display technology dependent. */
/* In theory reflective systems have little Flare ? */
/* Glare is assumed to be stray ambient light reflecting from the display */
/* surface, dust, or entering the observers eye directly, and as a result */
/* fogging the dark parts of the image. */
/* This is typically the major source of veiling light ? */
/* By separatedly specifiying these two, the effect can be automatically */
/* scalled according to the ambient light level, modelling the effect of */
/* reduced glare in a darkened viewing environment. */
/*
Typical adapting field luminances and white luminance in reflective setup:
E = illuminance in Lux
Lv = White luminance assuming 100% reflectance in cd/m^2
La = Adapting field luminance in cd/m^2, assuming 20% reflectance from surround
E La Lv Condition
11 0.7 4 Twilight
32 2 10 Subdued indoor lighting
64 4 20 Less than typical office light; sometimes recommended for
display-only workplaces (sRGB)
350 22 111 Typical Office (sRGB annex D)
500 32 160 Practical print evaluationa (ISO-3664 P2)
1000 64 318 Good Print evaluation (CIE 116-1995)
1000 64 318 Television Studio lighting
1000 64 318 Overcast Outdoors
2000 127 637 Critical print evaluation (ISO-3664 P1)
10000 637 3183 Typical outdoors, full daylight
50000 3185 15915 Bright summers day
*/
/* ---------------------------------- */
struct _cam02 {
/* Public: */
void (*del)(struct _cam02 *s); /* We're done with it */
int (*set_view)(
struct _cam02 *s,
ViewingCondition Ev, /* Enumerated Viewing Condition */
double Wxyz[3], /* Reference/Adapted White XYZ (Y scale 1.0) */
double La, /* Adapting/Surround Luminance cd/m^2 */
double Yb, /* Luminance of Background relative to reference white (range 0.0 .. 1.0) */
double Lv, /* Luminance of white in the Viewing/Scene/Image field (cd/m^2) */
/* Ignored if Ev is set */
double Yf, /* Flare as a fraction of the reference white (range 0.0 .. 1.0) */
double Yg, /* Glare as a fraction of the adapting/surround (range 0.0 .. 1.0) */
double Gxyz[3], /* The Glare white coordinates (ie. the Ambient color) */
/* If <= 0 will Wxyz will be used. */
int hk, /* Flag, NZ to use Helmholtz-Kohlrausch effect */
double hkscale, /* HK effect scaling factor */
double mtaf, /* Mid tone partial adapation factor from Wxyz to Wxyz2, <= 0.0 if none */
double Wxyz2[3] /* Mid tone Adapted White XYZ (Y range 0.0 .. 1.0) */
);
/* Conversions. Return nz on error (Y scale 1.0) */
int (*XYZ_to_cam)(struct _cam02 *s, double *out, double *in);
int (*cam_to_XYZ)(struct _cam02 *s, double *out, double *in);
/* Dump the viewing conditions to stdout */
void (*dump)(struct _cam02 *s);
/* Private: */
/* Scene parameters */
ViewingCondition Ev; /* Enumerated Viewing Condition */
double Lv; /* Luminance of white in the Viewing/Image cd/m^2 */
double La; /* Adapting/Surround Luminance cd/m^2 */
double Wxyz[3]; /* Reference/Adapted White XYZ (Y range 0.0 .. 1.0) */
double Yb; /* Relative Luminance of Background to reference white (Y range 0.0 .. 1.0) */
double Yf; /* Flare as a fraction of the reference white (Y range 0.0 .. 1.0) */
double Yg; /* Glare as a fraction of the adapting/surround (Y range 0.0 .. 1.0) */
double Gxyz[3]; /* The Glare white coordinates (typically the Ambient color) */
/* Partial mid-tone adapation hack parameters */
double Wxyz2[3];/* Mid tone Adapted White XYZ (Y range 0.0 .. 1.0) */
double mtaf; /* Mid tone blend factor between Wxyz and Wxyz2 */
/* Internal parameters */
double C; /* Surround Impact */
double Nc; /* Chromatic Induction */
double F; /* Adaptation Degree */
/* Pre-computed values */
double cc[3][3]; /* Forward cone and chromatic transform */
double icc[3][3]; /* Reverse cone and chromatic transform */
double crange[3]; /* ENABLE_COMPR compression range */
double Va[3], Vb[3], VttA[3], Vttd[3]; /* rgba vectors */
double dcomp[3]; /* Vttd in terms of VttA, Va, Vb */
double Fsc; /* Flare+Glare scale */
double Fisc; /* Inverse Flare+Glare scale */
double Fsxyz[3]; /* Scaled Flare+Glare color coordinates */
double rgbW[3]; /* Sharpened cone response white values */
double D; /* Degree of chromatic adaption */
double Drgb[3]; /* Chromatic transformation value */
double rgbcW[3]; /* Chromatically transformed white value */
double rgbpW[3]; /* Hunt-Pointer-Estevez cone response space white */
double n; /* Background induction factor */
double nn; /* Precomuted function of n */
double Fl; /* Lightness contrast factor ?? */
double Nbb; /* Background brightness induction factors */
double Ncb; /* Chromatic brightness induction factors */
double z; /* Base exponential nonlinearity */
double rgbaW[3]; /* Post-adapted cone response of white */
double Aw; /* Achromatic response of white */
double nldxval; /* Non-linearity output value at lower crossover to linear */
double nldxslope; /* Non-linearity slope at lower crossover to linear */
double nluxval; /* Non-linearity value at upper crossover to linear */
double nluxslope; /* Non-linearity slope at upper crossover to linear */
double lA; /* JLIMIT Limited A */
/* Partial mid-tone adapation hack pre-computed values */
int pmta_en; /* NZ if enabled */
double mtap; /* Mid tone blend rate (power) between Wxyz and Wxyz2 */
double rgbW2[3]; /* Mid etone sharpened cone response white values */
double Drgb2[3]; /* Mid tone chromatic transformation value */
double rgbcW2[3]; /* Mid tone chromatically transformed white value */
double rgbpW2[3]; /* Mid tone hunt-Pointer-Estevez cone response space white */
double cc2[3][3]; /* Mide tone forward cone and chromatic transform */
double icc2[3][3]; /* Mide tone reverse cone and chromatic transform */
/* Option flags, code not always enabled */
int hk; /* Use Helmholtz-Kohlrausch effect */
int hkscale; /* [1.0] Scale HK effect up/down from default */
int bluelin; /* Use blue hue linearization */
int trace; /* Trace values through computation */
int retss; /* Return ss rather than Jab */
int range; /* (for cam02ref.h) return on range error */
double nldlimit; /* value of NLDLIMIT, sets non-linearity lower limit */
double nldicept; /* value of NLDLICEPT, sets straight line intercept with 0.1 output */
double nlulimit; /* value of NLULIMIT, sets non-linearity upper limit (tangent) */
double ddllimit; /* value of DDLLIMIT, sets fwd k3 to k2 limit */
double ddulimit; /* value of DDULIMIT, sets bwd k3 to k1 limit */
double ssmincj; /* value of SSMINJ, sets cJ minimum value */
double jlimit; /* value of JLIMIT, sets cutover to straight line for J point */
double hklimit; /* value of HKLIMIT, sets HK factor upper limit */
}; typedef struct _cam02 cam02;
/* Create a cam02 conversion class, with default viewing conditions */
cam02 *new_cam02(void);

View File

@@ -0,0 +1,853 @@
/*
* International Color Consortium color transform expanded support
*
* Author: Graeme W. Gill
* Date: 11/11/2004
* Version: 1.00
*
* Copyright 2000-2004 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.
*
*/
/*
* This is some test code to test the CIECAM02 continuity.
* This test creates file "cam02plot.tif" containing values that
* have been converted to and back from CIECAM02 space.
*/
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include "copyright.h"
#include "aconfig.h"
#include "numlib.h"
#include "icc.h"
#include "xcam.h"
#include "cam02.h"
#include "tiffio.h"
#include "cam02ref.h"
#define DEFRES 100 /* Default cube resolution */
#define NORMAL_XYZ2RGB
#undef NIEVE_XYZ2RGB
#undef COMPLEX_XYZ2RGB
#define SCALE 1.0 /* Compress RGB by scale towards grey */
#ifndef _isnan
#define _isnan(x) ((x) != (x))
#define _finite(x) ((x) == 0.0 || (x) * 1.0000001 != (x))
#endif
static void
Lab2XYZ(double *out, double *in) {
double L = in[0], a = in[1], b = in[2];
double x,y,z,fx,fy,fz;
if (L > 8.0) {
fy = (L + 16.0)/116.0;
y = pow(fy,3.0);
} else {
y = L/903.2963058;
fy = 7.787036979 * y + 16.0/116.0;
}
fx = a/500.0 + fy;
if (fx > 24.0/116.0)
x = pow(fx,3.0);
else
x = (fx - 16.0/116.0)/7.787036979;
fz = fy - b/200.0;
if (fz > 24.0/116.0)
z = pow(fz,3.0);
else
z = (fz - 16.0/116.0)/7.787036979;
out[0] = x * 0.9642;
out[1] = y * 1.0000;
out[2] = z * 0.8249;
}
/* CIE XYZ to perceptual Lab */
static void
XYZ2Lab(double *out, double *in) {
double X = in[0], Y = in[1], Z = in[2];
double x,y,z,fx,fy,fz;
x = X/0.9642;
y = Y/1.0000;
z = Z/0.8249;
if (x > 0.008856451586)
fx = pow(x,1.0/3.0);
else
fx = 7.787036979 * x + 16.0/116.0;
if (y > 0.008856451586)
fy = pow(y,1.0/3.0);
else
fy = 7.787036979 * y + 16.0/116.0;
if (z > 0.008856451586)
fz = pow(z,1.0/3.0);
else
fz = 7.787036979 * z + 16.0/116.0;
out[0] = 116.0 * fy - 16.0;
out[1] = 500.0 * (fx - fy);
out[2] = 200.0 * (fy - fz);
}
#ifdef NORMAL_XYZ2RGB
static double sign(double x) {
if (x < 0.0)
return -1.0;
else
return 1.0;
}
/* Version with reasonable clipping. Converts to Lab, */
/* clips the Lab an then converts to sRGB */
/* Convert from XYZ to sRGB */
void XYZ2sRGB(double *out, double *in, int trace) {
double lab[3];
double tmp[3];
double scale = SCALE; /* Scale RGB towards grey */
double mat[3][3] =
{
{ 3.2410, -1.5374, -0.4986 },
{ -0.9692, 1.8760, 0.0416 },
{ 0.0556, -0.2040, 1.0570 }
};
int i;
// ~~999
trace = 0;
/* Copy from input */
for(i = 0; i < 3; i++)
tmp[i] = in[i];
if (trace) printf("XYZ to RGB\n");
if (trace) printf("input XYZ %f %f %f\n",tmp[0],tmp[1],tmp[2]);
/* Clip to reasonable range */
// if (tmp[1] <= 0.0)
// tmp[0] = tmp[2] = 0.0;
XYZ2Lab(lab, tmp);
if (trace) printf("Lab %f %f %f\n",tmp[0],tmp[1],tmp[2]);
icmClipLab(lab, lab);
if (trace) printf("Clipped Lab %f %f %f\n",tmp[0],tmp[1],tmp[2]);
/* We're going to assume that L == 0 is always black */
if (lab[0] <= 0.0) {
lab[1] = lab[2] = 0.0;
}
if (trace) printf("Clipped Lab2 %f %f %f\n",tmp[0],tmp[1],tmp[2]);
Lab2XYZ(tmp, lab);
if (trace) printf("XYZ %f %f %f\n",tmp[0],tmp[1],tmp[2]);
icmClipXYZ(tmp, tmp);
if (trace) printf("clipped XYZ %f %f %f\n",tmp[0],tmp[1],tmp[2]);
/* Now convert to sRGB assuming D50 (??) white point */
icmMulBy3x3(tmp, mat, tmp);
/* Scale */
for(i = 0; i < 3; i++) {
tmp[i] = ((tmp[i] - 0.5) * scale) + 0.5;
}
if (trace) printf("raw RGB %f %f %f\n",tmp[0],tmp[1],tmp[2]);
/* Apply gamma */
for(i = 0; i < 3; i++) {
if (tmp[i] < 0.00304) {
tmp[i] = tmp[i] * 12.92;
} else {
tmp[i] = 1.055 * pow(tmp[i], 1.0/2.4) - 0.055;
}
}
if (trace) printf("gamma corrected RGB %f %f %f\n",tmp[0],tmp[1],tmp[2]);
#ifndef NEVER
/* Clip to nearest */
for(i = 0; i < 3; i++) {
if (tmp[i] < 0.0)
tmp[i] = 0.0;
else if (tmp[i] > 1.0)
tmp[i] = 1.0;
}
#else
/* Clip towards center */
{
double biggest = -100.0;
for(i = 0; i < 3; i++) {
tmp[i] -= 0.5;
if (fabs(tmp[i]) > biggest)
biggest = fabs(tmp[i]);
}
for(i = 0; i < 3; i++) {
if (biggest > 0.5)
tmp[i] *= 0.5/biggest;
tmp[i] += 0.5;
}
}
#endif
if (trace) printf("output clipped RGB %f %f %f\n",tmp[0],tmp[1],tmp[2]);
/* Copy to output */
for(i = 0; i < 3; i++)
out[i] = tmp[i];
}
#endif /* NORMAL_XYZ2RGB */
#ifdef NIEVE_XYZ2RGB
/* Nieve version with RGB clipping */
/* Convert from XYZ to sRGB */
void XYZ2sRGB(double *out, double *in, int trace) {
double tmp[3];
double scale = SCALE; /* Scale RGB towards grey */
double mat[3][3] =
{
{ 3.2410, -1.5374, -0.4986 },
{ -0.9692, 1.8760, 0.0416 },
{ 0.0556, -0.2040, 1.0570 }
};
int i;
if (trace) printf("XYZ to RGB\n");
if (trace) printf("input XYZ %f %f %f\n",in[0],in[1],in[2]);
/* Now convert to sRGB assuming D50 (??) white point */
icmMulBy3x3(tmp, mat, in);
/* Scale */
for(i = 0; i < 3; i++) {
tmp[i] = ((tmp[i] - 0.5) * scale) + 0.5;
}
if (trace) printf("raw RGB %f %f %f\n",tmp[0],tmp[1],tmp[2]);
/* Clip to nearest */
for(i = 0; i < 3; i++) {
if (tmp[i] < 0.0)
tmp[i] = 0.0;
else if (tmp[i] > 1.0)
tmp[i] = 1.0;
}
if (trace) printf("clipped RGB %f %f %f\n",tmp[0],tmp[1],tmp[2]);
/* Apply gamma */
for(i = 0; i < 3; i++) {
if (tmp[i] < 0.00304) {
tmp[i] = tmp[i] * 12.92;
} else {
tmp[i] = 1.055 * pow(tmp[i], 1.0/2.4) - 0.055;
}
}
if (trace) printf("output gamma corrected RGB %f %f %f\n",tmp[0],tmp[1],tmp[2]);
/* Copy to output */
for(i = 0; i < 3; i++)
out[i] = tmp[i];
}
#endif /* NIEVE_XYZ2RGB */
#ifdef COMPLEX_XYZ2RGB
/* Complex version using powell to ensure good clipping */
/* Callback context */
typedef struct {
double scale;
double lab[3];
double imat[3][3];
} ctx;
double clipf(void *fdata, double tp[]) {
ctx *x = (ctx *)fdata;
double lab[3], tmp[3], tt;
int k;
double rv = 0.0;
//printf("\n");
//printf("~1 clipf got %f %f %f\n",tp[0],tp[1],tp[2]);
/* Penalize for being out of gamut */
for (k = 0; k < 3; k++) {
if (tp[k] < 0.0) {
tt = 100000.0 * (0.0 - tp[k]);
rv += tt * tt;
} else if (tp[k] > 1.0) {
tt = 100000.0 * (tp[k] - 1.0);
rv += tt * tt;
}
}
//printf("~1 rv out of gamut = %f\n",rv);
/* Unscale it */
for(k = 0; k < 3; k++)
tmp[k] = ((tp[k] - 0.5) / x->scale) + 0.5;
//printf("~1 unscale %f %f %f\n",tmp[0],tmp[1],tmp[2]);
icmMulBy3x3(tmp, x->imat, tmp); /* To XYZ */
//printf("~1 xyz %f %f %f\n",tmp[0],tmp[1],tmp[2]);
XYZ2Lab(lab, tmp); /* To Lab */
//printf("~1 lab = %f %f %f\n",lab[0],lab[1],lab[2]);
//printf("~1 target = %f %f %f\n",x->lab[0],x->lab[1],x->lab[2]);
/* Compute an error to the goal */
tt = 10000.0 * (lab[0] - x->lab[0]);
rv += tt * tt;
tt = 1.0 * (lab[1] - x->lab[1]);
rv += tt * tt;
tt = 1.0 * (lab[2] - x->lab[2]);
rv += tt * tt;
//printf("~1 rv = %f\n",rv);
return rv;
}
/* Convert from XYZ to sRGB */
void XYZ2sRGB(double *out, double *in, int trace) {
double lab[3], tmp[3];
double scale = SCALE; /* Scale RGB towards grey */
double mat[3][3] =
{
{ 3.2410, -1.5374, -0.4986 },
{ -0.9692, 1.8760, 0.0416 },
{ 0.0556, -0.2040, 1.0570 }
};
int i;
/* Copy from input */
for(i = 0; i < 3; i++)
tmp[i] = in[i];
if (trace) printf("XYZ to RGB\n");
if (trace) printf("input XYZ %f %f %f\n",tmp[0],tmp[1],tmp[2]);
XYZ2Lab(lab, tmp);
if (trace) printf("Lab %f %f %f\n",lab[0],lab[1],lab[2]);
icmClipLab(lab, lab);
if (trace) printf("Clipped Lab %f %f %f\n",lab[0],lab[1],lab[2]);
/* Now convert to sRGB assuming D50 (??) white point */
Lab2XYZ(tmp, lab);
icmMulBy3x3(tmp, mat, tmp);
/* Scale */
for(i = 0; i < 3; i++) {
tmp[i] = ((tmp[i] - 0.5) * scale) + 0.5;
}
if (trace) printf("raw RGB %f %f %f\n",tmp[0],tmp[1],tmp[2]);
/* See if it need clipping */
for(i = 0; i < 3; i++) {
if (tmp[i] < 0.0 || tmp[i] > 1.0)
break;
}
/* It needs more clipping */
if (i < 3) {
ctx x;
double ss[3] = { 0.1, 0.1, 0.1 };
x.lab[0] = lab[0];
x.lab[1] = lab[1];
x.lab[2] = lab[2];
x.scale = scale;
icmInverse3x3(x.imat, mat);
if (powell(NULL, 3, tmp, ss, 1e-6, 1000, clipf, (void *)&x) < 0.0)
error("RGB clip failed");
}
if (trace) printf("RGB clip %f %f %f\n",tmp[0],tmp[1],tmp[2]);
/* Clip to nearest */
for(i = 0; i < 3; i++) {
if (tmp[i] < 0.0)
tmp[i] = 0.0;
else if (tmp[i] > 1.0)
tmp[i] = 1.0;
}
if (trace) printf("clip to nearest RGB %f %f %f\n",tmp[0],tmp[1],tmp[2]);
/* Apply gamma */
for(i = 0; i < 3; i++) {
if (tmp[i] < 0.00304) {
tmp[i] = tmp[i] * 12.92;
} else {
tmp[i] = 1.055 * pow(tmp[i], 1.0/2.4) - 0.055;
}
}
if (trace) printf("gamma corrected RGB %f %f %f\n",tmp[0],tmp[1],tmp[2]);
/* Copy to output */
for(i = 0; i < 3; i++)
out[i] = tmp[i];
}
#endif /* COMPLEX_XYZ2RGB */
void usage(char *diag) {
fprintf(stderr,"Create a 3D slice plot of XYZ/Lab <-> Jab, Version %s\n",ARGYLL_VERSION_STR);
fprintf(stderr,"Author: Graeme W. Gill, licensed under the AGPL Version 3\n");
if (diag != NULL)
fprintf(stderr,"Diagnostic '%s'\n",diag);
fprintf(stderr,"usage: cam02plot [-options] x y\n");
fprintf(stderr,"'cam02plot -l -o' shows problem best\n");
fprintf(stderr," -v level Verbosity level 0 - 2 (default = 1)\n");
fprintf(stderr," -n Don't use Helmholtz-Kohlraush flag\n");
fprintf(stderr," -f Use the reference CIECAM transform\n");
fprintf(stderr," -r res Resolution (default %d)\n",DEFRES);
fprintf(stderr," -l Lab source cube (default XYZ source cube)\n");
fprintf(stderr," -i XYZ/Lab -> Jab (default XYZ/Lab -> Lab)\n");
fprintf(stderr," -o Jab -> XYZ -> RGB (defult Lab -> XYZ -> RGB\n");
fprintf(stderr," -s XYZ/Lab -> ab scale as RGB\n");
fprintf(stderr," -x Cross section plots\n");
fprintf(stderr," x y Return input color for this coordinate\n");
exit(1);
}
int
main(int argc, char *argv[]) {
int fa,nfa; /* argument we're looking at */
char *tiffname = "cam02plot.tif";
TIFF *wh = NULL;
uint16 resunits = RESUNIT_INCH;
float resx = 75.0, resy = 75.0;
tdata_t *obuf;
unsigned char *ob;
int verb = 0;
int transl = 0; /* Translate x,y into input color */
int tx = 0, ty = 0; /* coordinate to translate */
int use_hk = 1; /* Use Helmholtz-Kohlraush flag */
int use_ref = 0; /* Use reference transform rather than working code */
int lab_plot = 0; /* Lab <-> Jab plot, else XYZ <-> Jab */
int to_jab = 0; /* Convert to Jab, else convert to Lab */
int from_jab = 0; /* Convert from Jab, else convert from Lab */
int to_ss = 0; /* Convert from XYZ/Lab to abs scale ss */
int xsect = 0; /* Cross section plots */
double white[9][3] = {
{ 0.964242, 1.000000, 0.825124 }, /* 0: D50 */
{ 1.098494, 1.000000, 0.355908 }, /* 1: A */
{ 0.908731, 1.000000, 0.987233 }, /* 2: F5 */
{ 1.128981, 1.000000, 0.305862 }, /* 3: D25 */
{ 0.950471, 1.000000, 1.088828 }, /* 4: D65 */
{ 0.949662, 1.000000, 1.160438 }, /* 5: D80 */
{ 0.949662, 1.000000, 1.160438 }, /* 6: D80 */
{ 0.951297, 1.000000, 1.338196 }, /* 7: D85 */
{ 0.952480, 1.000000, 1.386693 } /* 8: D90 */
};
#ifdef NEVER
double La[6] = { 10.0, 31.83, 100.0, 318.31, 1000.83, 3183.1 };
ViewingCondition Vc[4] = {
vc_average,
vc_dark,
vc_dim,
vc_cut_sheet
};
#endif /* NEVER */
int i, j, k, m;
double xyz[3], Jab[3], rgb[3];
cam02 *cam1, *cam2;
int res = DEFRES; /* Resolution of scan through space */
int ares; /* Array of 2d sub-rasters */
int w, h; /* Width and height of raster */
int x, y;
int sp = 5; /* Spacing beween resxres sub-images */
error_program = argv[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) < argc) {
if (argv[fa+1][0] != '-') {
nfa = fa + 1;
na = argv[nfa]; /* next is seperate non-flag argument */
}
}
}
if (argv[fa][1] == '?')
usage("Requested usage");
/* Verbosity */
else if (argv[fa][1] == 'v' || argv[fa][1] == 'V') {
fa = nfa;
if (na == NULL)
verb = 2;
else {
if (na[0] == '0')
verb = 0;
else if (na[0] == '1')
verb = 1;
else if (na[0] == '2')
verb = 2;
else
usage("Illegal verbosity level");
}
}
else if (argv[fa][1] == 'r' || argv[fa][1] == 'R') {
fa = nfa;
if (na == NULL)
usage("Need resolution after -r");
res = atoi(na);
if (res < 2 || res > 1000)
usage("Resolution is out of range");
}
else if (argv[fa][1] == 'n' || argv[fa][1] == 'N') {
use_hk = 0;
}
else if (argv[fa][1] == 'f' || argv[fa][1] == 'F') {
use_ref = 1;
}
else if (argv[fa][1] == 'l' || argv[fa][1] == 'L') {
lab_plot = 1;
}
else if (argv[fa][1] == 'i' || argv[fa][1] == 'I') {
to_jab = 1;
}
else if (argv[fa][1] == 'o' || argv[fa][1] == 'O') {
from_jab = 1;
}
else if (argv[fa][1] == 's' || argv[fa][1] == 'S') {
to_ss = 1;
}
else if (argv[fa][1] == 'x' || argv[fa][1] == 'X') {
xsect = 1;
}
else
usage("Unknown flag");
} else
break;
}
if ((fa+1) < argc) {
tx = atoi(argv[fa]);
ty = atoi(argv[fa+1]);
transl = 1;
}
/* Setup cam to convert to Jab */
if (use_ref)
cam1 = new_cam02ref();
else
cam1 = new_cam02();
cam1->set_view(
cam1,
vc_average, /* Enumerated Viewing Condition */
white[4], /* Reference/Adapted White XYZ (Y range 0.0 .. 1.0) */
1000.0, /* Adapting/Surround Luminance cd/m^2 */
0.20, /* Relative Luminance of Background to reference white */
0.0, /* Luminance of white in image - not used */
0.00, /* Flare as a fraction of the reference white (Y range 0.0 .. 1.0) */
0.00, /* Glare as a fraction of the ambient (Y range 0.0 .. 1.0) */
white[4], /* The Glare color coordinates (typically the Ambient color) */
use_hk, /* use Helmholtz-Kohlraush flag */
1.0, /* HK scaling factor */
0.0, /* No mid-tone hack */
NULL
);
/* Setup cam to convert from Jab */
if (use_ref)
cam2 = new_cam02ref();
else
cam2 = new_cam02();
cam2->set_view(
cam2,
vc_average, /* Enumerated Viewing Condition */
white[4], /* Reference/Adapted White XYZ (Y range 0.0 .. 1.0) */
1000.0, /* Adapting/Surround Luminance cd/m^2 */
0.20, /* Relative Luminance of Background to reference white */
0.0, /* Luminance of white in image - not used */
0.00, /* Flare as a fraction of the reference white (Y range 0.0 .. 1.0) */
0.00, /* Glare as a fraction of the ambient (Y range 0.0 .. 1.0) */
white[4], /* The Glare color coordinates (typically the Ambient color) */
use_hk, /* use Helmholtz-Kohlraush flag */
1.0, /* HK scaling factor */
0.0, /* No mid-tone hack */
NULL
);
/* Figure out the size of the raster */
ares = (int)ceil(sqrt((double)res));
if (verb)
printf("For res %d, ares = %d\n",res,ares);
w = ares * res + sp * (ares+1);
h = ares * res + sp * (ares+1);
if (to_ss) {
cam1->retss = 1;
}
if (transl) {
int ix,iy,iz;
double dx,dy,dz;
double tmp[3], lab[3];
cam1->trace = 1;
cam2->trace = 1;
//printf("~1 translate %d %d\n",tx,ty);
tx -= sp; /* Border at base */
ty -= sp;
//printf("~1 offset %d %d\n",tx,ty);
ix = tx % (res + sp);
iy = ty % (res + sp);
iz = (ty / (res + sp)) * ares + (tx / (res + sp));
//printf("~1 x y z = %d %d %d\n", ix,iy,iz);
dx = ix/(res-1.0);
dy = iy/(res-1.0);
dz = iz/((ares * ares)-1.0);
//printf("~1 X Y Z = %f %f %f\n", dx,dy,dz);
/* Source range is extended L*a*b* type */
if (lab_plot) {
if (xsect) {
lab[0] = 180.0 * dz - 40.0;
lab[1] = 300.0 * dy - 150.0;
lab[2] = 300.0 * dx - 150.0;
} else {
lab[0] = 180.0 * dx - 40.0;
lab[1] = 300.0 * dy - 150.0;
lab[2] = 300.0 * dz - 150.0;
}
//printf("~1 Lab = %f %f %f\n", lab[0],lab[1],lab[2]);
Lab2XYZ(tmp, lab);
printf("======================================================\n");
printf("%d,%d -> Lab %f %f %f\n", tx+sp, ty+sp, lab[0],lab[1],lab[2]);
printf(" == XYZ %f %f %f\n", tmp[0],tmp[1],tmp[2]);
/* Else source range is extended XYZ type */
} else {
if (xsect) {
tmp[0] = 1.4 * dz - 0.2;
tmp[1] = 1.4 * dy - 0.2;
tmp[2] = 1.6 * dx - 0.2;
} else {
tmp[0] = 1.4 * dx - 0.2;
tmp[1] = 1.4 * dy - 0.2;
tmp[2] = 1.6 * dz - 0.2;
}
printf("%d,%d -> Input color XYZ %f %f %f\n", tx, ty, tmp[0],tmp[1],tmp[2]);
}
if (to_ss) {
cam1->XYZ_to_cam(cam1, Jab, tmp);
printf(" XYZ -> ss %f %f %f\n", Jab[0],Jab[1],Jab[2]);
/* Convert XYZ through cam and back, then to RGB */
} else if (to_jab) {
cam1->XYZ_to_cam(cam1, Jab, tmp);
if (to_ss) {
printf(" XYZ -> ss %f %f %f\n", Jab[0],Jab[1],Jab[2]);
} else {
printf(" XYZ -> ss %f %f %f\n", Jab[0],Jab[1],Jab[2]);
}
/* Else convert XYZ to L*a*b* */
} else {
XYZ2Lab(Jab, tmp);
printf(" XYZ -> Lab %f %f %f\n", Jab[0],Jab[1],Jab[2]);
}
/* Convert from Jab back to XYZ */
if (from_jab) {
cam2->cam_to_XYZ(cam2, rgb, Jab);
printf(" Jab -> XYZ %f %f %f\n", rgb[0],rgb[1],rgb[2]);
/* Else convert from Lab back to XYZ */
} else {
Lab2XYZ(rgb, Jab);
printf(" Lab -> XYZ %f %f %f\n", rgb[0],rgb[1],rgb[2]);
}
XYZ2Lab(tmp, rgb);
printf(" == Lab %f %f %f\n", tmp[0],tmp[1],tmp[2]);
/* Interpret XYZ as RGB color */
XYZ2sRGB(rgb, rgb, 1);
printf(" XYZ -> RGB %f %f %f\n", rgb[0],rgb[1],rgb[2]);
cam1->trace = 0;
cam2->trace = 0;
printf("\n");
exit(0);
}
if (verb)
printf("Raster width = %d, height = %d\n",w,h);
/* Setup the tiff file */
if ((wh = TIFFOpen(tiffname, "w")) == NULL)
error("Can\'t create TIFF file '%s'!",tiffname);
TIFFSetField(wh, TIFFTAG_IMAGEWIDTH, w);
TIFFSetField(wh, TIFFTAG_IMAGELENGTH, h);
TIFFSetField(wh, TIFFTAG_ORIENTATION, ORIENTATION_TOPLEFT);
TIFFSetField(wh, TIFFTAG_SAMPLESPERPIXEL, 3);
TIFFSetField(wh, TIFFTAG_BITSPERSAMPLE, 8);
TIFFSetField(wh, TIFFTAG_PLANARCONFIG, PLANARCONFIG_CONTIG);
TIFFSetField(wh, TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_RGB);
TIFFSetField(wh, TIFFTAG_COMPRESSION, COMPRESSION_NONE);
TIFFSetField(wh, TIFFTAG_RESOLUTIONUNIT, resunits);
TIFFSetField(wh, TIFFTAG_XRESOLUTION, resx);
TIFFSetField(wh, TIFFTAG_YRESOLUTION, resy);
TIFFSetField(wh, TIFFTAG_IMAGEDESCRIPTION, "cam02plot");
obuf = _TIFFmalloc(TIFFScanlineSize(wh));
ob = (unsigned char *)obuf;
y = 0;
/* Fill sp lines with black */
for (x = 0, m = 0; m < w; m++) {
ob[x] = ob[x+1] = ob[x+2] = 0;
x += 3;
}
for (j = 0; j < sp; j++, y++) {
TIFFWriteScanline(wh, ob, y, 0);
}
for (i = 0; i < ares; i++) { /* Vertical blocks (rows) */
for (j = 0; j < res; j++, y++) { /* Vertical in block (y = Y/a*) */
xyz[1] = j/(res-1.0);
x = 0;
/* Fill sp pixels with black */
for (m = 0; m < sp; m++) {
ob[x] = ob[x+1] = ob[x+2] = 0;
x += 3;
}
for (k = 0; k < ares; k++) { /* Horizontal blocks (columns) */
int zv = i * ares + k;
if (zv >= res) {
/* Fill res pixels with black */
for (m = 0; m < res; m++) {
ob[x] = ob[x+1] = ob[x+2] = 0;
x += 3;
}
} else {
xyz[2] = zv/(res-1.0); /* z = block = Z/b* */
for (m = 0; m < res; m++) { /* Horizontal in block (x = X/L*) */
double tmp[3], xyz2[3];
xyz[0] = m/(res-1.0);
if (lab_plot) {
if (xsect) {
tmp[0] = 180.0 * xyz[2] - 40.0;
tmp[1] = 300.0 * xyz[1] - 150.0;
tmp[2] = 300.0 * xyz[0] - 150.0;
} else {
tmp[0] = 180.0 * xyz[0] - 40.0;
tmp[1] = 300.0 * xyz[1] - 150.0;
tmp[2] = 300.0 * xyz[2] - 150.0;
}
Lab2XYZ(tmp, tmp);
} else {
if (xsect) {
tmp[0] = 1.4 * xyz[2] - 0.2;
tmp[1] = 1.4 * xyz[1] - 0.2;
tmp[2] = 1.6 * xyz[0] - 0.2;
} else {
tmp[0] = 1.4 * xyz[0] - 0.2;
tmp[1] = 1.4 * xyz[1] - 0.2;
tmp[2] = 1.6 * xyz[2] - 0.2;
}
}
/* Convert XYZ through cam and back, then to RGB */
if (to_jab || to_ss)
cam1->XYZ_to_cam(cam1, Jab, tmp);
else
XYZ2Lab(Jab, tmp);
if (to_ss) {
rgb[0] = Jab[0];
rgb[1] = Jab[1];
rgb[2] = Jab[2];
} else {
if (from_jab)
cam2->cam_to_XYZ(cam2, xyz2, Jab);
else
Lab2XYZ(xyz2, Jab);
XYZ2sRGB(rgb, xyz2, 0);
}
/* Fill with pixel value */
ob[x+0] = (int)(rgb[0] * 255.0 + 0.5);
ob[x+1] = (int)(rgb[1] * 255.0 + 0.5);
ob[x+2] = (int)(rgb[2] * 255.0 + 0.5);
x += 3;
}
}
/* Fill sp pixels with black */
for (m = 0; m < sp; m++) {
ob[x] = ob[x+1] = ob[x+2] = 0;
x += 3;
}
}
TIFFWriteScanline(wh, ob, y, 0);
}
/* Fill sp lines with black */
for (x = m = 0; m < w; m++) {
ob[x] = ob[x+1] = ob[x+2] = 0;
x += 3;
}
for (j = 0; j < sp; j++, y++) {
TIFFWriteScanline(wh, ob, y, 0);
}
}
cam1->del(cam1);
cam2->del(cam2);
/* Write TIFF file */
TIFFClose(wh);
return 0;
}

View File

@@ -0,0 +1,645 @@
/*
* cam02, unoptimised, untweaked reference version for testing.
* with optional trace/range error flags.
*
* Color Appearance Model.
*
* Author: Graeme W. Gill
* Date: 17/1/2004
* Version: 1.00
*
* This file is based on cam97s3.c by Graeme Gill.
*
* Copyright 2004, 2007 Graeme W. Gill
* Please refer to COPYRIGHT file for details.
* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :-
* see the License.txt file for licencing details.
*/
/* Note that XYZ values are normalised to 1.0 consistent */
/* with the ICC convention (not 100.0 as assumed by the CIECAM spec.) */
/* Note that all whites are assumed to be normalised (ie. Y = 1.0) */
#define HHKR_MUL 0.25
#undef DIAG /* Print internal value diagnostics for each conversion */
/* ---------------------------------- */
#ifdef NEVER
struct _cam02ref {
/* Public: */
void (*del)(struct _cam02ref *s); /* We're done with it */
int (*set_view)(
struct _cam02ref *s,
ViewingCondition Ev, /* Enumerated Viewing Condition */
double Wxyz[3], /* Reference/Adapted White XYZ (Y scale 1.0) */
double La, /* Adapting/Surround Luminance cd/m^2 */
double Yb, /* Luminance of Background relative to reference white (range 0.0 .. 1.0) */
double Lv, /* Luminance of white in the Viewing/Scene/Image field (cd/m^2) */
/* Ignored if Ev is set */
double Yf, /* Flare as a fraction of the reference white (range 0.0 .. 1.0) */
double Yg, /* Glare as a fraction of the adapting/surround (range 0.0 .. 1.0) */
double Gxyz[3], /* The Glare white coordinates (typically the Ambient color) */
int hk, /* Flag, NZ to use Helmholtz-Kohlraush effect */
double hkscale, /* HK effect scaling factor */
double mtaf, /* Mid tone partial adapation factor from Wxyz to Wxyz2, <= 0.0 if none */
double Wxyz2[3] /* Mid tone Adapted White XYZ (Y range 0.0 .. 1.0) */
);
/* Conversions */
int (*XYZ_to_cam)(struct _cam02ref *s, double *out, double *in);
/* Private: */
/* Scene parameters */
ViewingCondition Ev; /* Enumerated Viewing Condition */
double Lv; /* Luminance of white in the Viewing/Image cd/m^2 */
double La; /* Adapting/Surround Luminance cd/m^2 */
double Wxyz[3]; /* Reference/Adapted White XYZ (Y range 0.0 .. 1.0) */
double Yb; /* Relative Luminance of Background to reference white (Y range 0.0 .. 1.0) */
double Yf; /* Flare as a fraction of the reference white (Y range 0.0 .. 1.0) */
double Fxyz[3]; /* The Flare white coordinates (typically the Ambient color) */
/* Internal parameters */
double C; /* Surround Impact */
double Nc; /* Chromatic Induction */
double F; /* Adaptation Degree */
/* Pre-computed values */
double Fsc; /* Flare scale */
double Fisc; /* Inverse flare scale */
double Fsxyz[3]; /* Scaled Flare color coordinates */
double rgbW[3]; /* Sharpened cone response white values */
double D; /* Degree of chromatic adaption */
double Drgb[3]; /* Chromatic transformation value */
double rgbcW[3]; /* Chromatically transformed white value */
double rgbpW[3]; /* Hunt-Pointer-Estevez cone response space white */
double n; /* Background induction factor */
double nn; /* Precomuted function of n */
double Fl; /* Lightness contrast factor ?? */
double Nbb; /* Background brightness induction factors */
double Ncb; /* Chromatic brightness induction factors */
double z; /* Base exponential nonlinearity */
double rgbaW[3]; /* Post-adapted cone response of white */
double Aw; /* Achromatic response of white */
/* Option flags */
int hk; /* Use Helmholtz-Kohlraush effect */
int trace; /* Trace internal values */
double range; /* Return error if there is a range error */
double nldlimit; /* range error if nlinear is less than this */
double jlimit; /* range error if J is less than this */
}; typedef struct _cam02ref cam02ref;
#else
typedef struct _cam02 cam02ref;
#endif
/* ---------------------------------- */
/* Utility function */
/* Return a viewing condition enumeration from the given Ambient and */
/* Adapting/Surround Luminance. */
static ViewingCondition cam02ref_Ambient2VC(
double La, /* Ambient Luminence (cd/m^2) */
double Lv /* Luminence of white in the Viewing/Scene/Image field (cd/m^2) */
) {
double r;
if (fabs(La) < 1e-10) /* Hmm. */
r = 1.0;
else
r = La/Lv;
if (r < 0.01)
return vc_dark;
if (r < 0.2)
return vc_dim;
return vc_average;
}
static void cam02ref_free(cam02ref *s);
static int cam02ref_set_view(cam02ref *s, ViewingCondition Ev, double Wxyz[3],
double Yb, double La, double Lv, double Yf, double Yg, double Gxyz[3],
int hk, double hkscale, double mtaf, double Wxyz2[3]);
static int cam02ref_XYZ_to_cam(cam02ref *s, double *Jab, double *xyz);
static int cam02ref_cam_to_XYZ(cam02ref *s, double XYZ[3], double Jab[3]);
/* Create a cam02 conversion object, with default viewing conditions */
cam02ref *new_cam02ref(void) {
cam02ref *s;
if ((s = (cam02ref *)malloc(sizeof(cam02ref))) == NULL) {
fprintf(stderr,"cam02: malloc failed allocating object\n");
exit(-1);
}
/* Initialise methods */
s->del = cam02ref_free;
s->set_view = cam02ref_set_view;
s->XYZ_to_cam = cam02ref_XYZ_to_cam;
s->cam_to_XYZ = cam02ref_cam_to_XYZ;
return s;
}
static void cam02ref_free(cam02ref *s) {
if (s != NULL)
free(s);
}
static int cam02ref_set_view(
cam02ref *s,
ViewingCondition Ev, /* Enumerated Viewing Condition */
double Wxyz[3], /* Reference/Adapted White XYZ (Y range 0.0 .. 1.0) */
double La, /* Adapting/Surround Luminance cd/m^2 */
double Yb, /* Relative Luminence of Background to reference white */
double Lv, /* Luminence of white in the Viewing/Scene/Image field (cd/m^2) */
/* Ignored if Ev is set to other than vc_none */
double Yf, /* Flare as a fraction of the reference white (Y range 0.0 .. 1.0) */
double Yg, /* Glare as a fraction of the adapting/surround (Y range 0.0 .. 1.0) */
double Gxyz[3], /* The Glare white coordinates (typically the Ambient color) */
int hk, /* Flag, NZ to use Helmholtz-Kohlraush effect */
double hkscale, /* HK effect scaling factor */
double mtaf, /* Mid tone partial adapation factor from Wxyz to Wxyz2, <= 0.0 if none */
double Wxyz2[3] /* Mid tone Adapted White XYZ (Y range 0.0 .. 1.0) */
) {
double tt;
if (Ev == vc_none) /* Compute enumerated viewing condition */
Ev = cam02ref_Ambient2VC(La, Lv);
/* Transfer parameters to the object */
s->Ev = Ev;
s->Wxyz[0] = Wxyz[0];
s->Wxyz[1] = Wxyz[1];
s->Wxyz[2] = Wxyz[2];
s->Yb = Yb > 0.005 ? Yb : 0.005; /* Set minimum to avoid divide by 0.0 */
s->La = La;
s->Yf = Yf;
if (Gxyz[0] > 0.0 && Gxyz[1] > 0.0 && Gxyz[2] > 0.0) {
tt = Wxyz[1]/Gxyz[1]; /* Scale to white ref white */
s->Gxyz[0] = tt * Gxyz[0];
s->Gxyz[1] = tt * Gxyz[1];
s->Gxyz[2] = tt * Gxyz[2];
} else {
s->Gxyz[0] = Wxyz[0];
s->Gxyz[1] = Wxyz[1];
s->Gxyz[2] = Wxyz[2];
}
s->hk = hk;
s->hkscale = hkscale;
/* Compute the internal parameters by category */
switch(s->Ev) {
case vc_dark:
s->C = 0.525;
s->Nc = 0.8;
s->F = 0.8;
Lv = La/0.033;
break;
case vc_dim:
s->C = 0.59;
s->Nc = 0.95;
s->F = 0.9;
Lv = La/0.1;
break;
case vc_average:
default: /* average */
s->C = 0.69;
s->Nc = 1.0;
s->F = 1.0;
Lv = La/0.2;
break;
case vc_cut_sheet:
s->C = 0.41;
s->Nc = 0.8;
s->F = 0.8;
Lv = La/0.02; // ???
break;
}
s->Lv = Lv;
/* Compute values that only change with viewing parameters */
/* Figure out the Flare contribution to the flareless XYZ input */
s->Fsxyz[0] = s->Yf * s->Wxyz[0];
s->Fsxyz[1] = s->Yf * s->Wxyz[1];
s->Fsxyz[2] = s->Yf * s->Wxyz[2];
/* Add in the Glare contribution from the adapting/surround */
tt = s->Yg * s->La/s->Lv;
s->Fsxyz[0] += tt * s->Gxyz[0];
s->Fsxyz[1] += tt * s->Gxyz[1];
s->Fsxyz[2] += tt * s->Gxyz[2];
/* Sharpened cone response white values */
s->rgbW[0] = 0.7328 * s->Wxyz[0] + 0.4296 * s->Wxyz[1] - 0.1624 * s->Wxyz[2];
s->rgbW[1] = -0.7036 * s->Wxyz[0] + 1.6975 * s->Wxyz[1] + 0.0061 * s->Wxyz[2];
s->rgbW[2] = 0.0000 * s->Wxyz[0] + 0.0000 * s->Wxyz[1] + 1.0000 * s->Wxyz[2];
/* Degree of chromatic adaption */
s->D = s->F * (1.0 - exp((-s->La - 42.0)/92.0)/3.6);
/* Precompute Chromatic transform values */
s->Drgb[0] = s->D * (s->Wxyz[1]/s->rgbW[0]) + 1.0 - s->D;
s->Drgb[1] = s->D * (s->Wxyz[1]/s->rgbW[1]) + 1.0 - s->D;
s->Drgb[2] = s->D * (s->Wxyz[1]/s->rgbW[2]) + 1.0 - s->D;
/* Chromaticaly transformed white value */
s->rgbcW[0] = s->Drgb[0] * s->rgbW[0];
s->rgbcW[1] = s->Drgb[1] * s->rgbW[1];
s->rgbcW[2] = s->Drgb[2] * s->rgbW[2];
/* Transform from spectrally sharpened, to Hunt-Pointer_Estevez cone space */
s->rgbpW[0] = 0.7409744840453773 * s->rgbcW[0]
+ 0.2180245944753982 * s->rgbcW[1]
+ 0.0410009214792244 * s->rgbcW[2];
s->rgbpW[1] = 0.2853532916858801 * s->rgbcW[0]
+ 0.6242015741188157 * s->rgbcW[1]
+ 0.0904451341953042 * s->rgbcW[2];
s->rgbpW[2] = -0.0096276087384294 * s->rgbcW[0]
- 0.0056980312161134 * s->rgbcW[1]
+ 1.0153256399545427 * s->rgbcW[2];
/* Background induction factor */
s->n = s->Yb/ s->Wxyz[1];
s->nn = pow(1.64 - pow(0.29, s->n), 0.73); /* Pre computed value */
/* Lightness contrast factor ?? */
{
double k;
k = 1.0 / (5.0 * s->La + 1.0);
s->Fl = 0.2 * pow(k , 4.0) * 5.0 * s->La
+ 0.1 * pow(1.0 - pow(k , 4.0) , 2.0) * pow(5.0 * s->La , 1.0/3.0);
}
/* Background and Chromatic brightness induction factors */
s->Nbb = 0.725 * pow(1.0/s->n, 0.2);
s->Ncb = s->Nbb;
/* Base exponential nonlinearity */
s->z = 1.48 + pow(s->n , 0.5);
/* Post-adapted cone response of white */
tt = pow(s->Fl * s->rgbpW[0], 0.42);
s->rgbaW[0] = (400.1 * tt + 2.713) / (tt + 27.13);
tt = pow(s->Fl * s->rgbpW[1], 0.42);
s->rgbaW[1] = (400.1 * tt + 2.713) / (tt + 27.13);
tt = pow(s->Fl * s->rgbpW[2], 0.42);
s->rgbaW[2] = (400.1 * tt + 2.713) / (tt + 27.13);
/* Achromatic response of white */
s->Aw = (2.0 * s->rgbaW[0] + s->rgbaW[1] + (1.0/20.0) * s->rgbaW[2] - 0.305) * s->Nbb;
#ifdef DIAG
printf("Ref. Scene parameters:\n");
printf("Viewing condition Ev = %d\n",s->Ev);
printf("Ref white Wxyz = %f %f %f\n", s->Wxyz[0], s->Wxyz[1], s->Wxyz[2]);
printf("Relative liminance of background Yb = %f\n", s->Yb);
printf("Adapting liminance La = %f\n", s->La);
printf("Flare Yf = %f\n", s->Yf);
printf("Flare color Fxyz = %f %f %f\n", s->Fxyz[0], s->Fxyz[1], s->Fxyz[2]);
printf("Internal parameters:\n");
printf("Surround Impact C = %f\n", s->C);
printf("Chromatic Induction Nc = %f\n", s->Nc);
printf("Adaption Degree F = %f\n", s->F);
printf("Pre-computed values\n");
printf("Sharpened cone white rgbW = %f %f %f\n", s->rgbW[0], s->rgbW[1], s->rgbW[2]);
printf("Degree of chromatic adaption D = %f\n", s->D);
printf("Chromatic transform values Drgb = %f %f %f\n", s->Drgb[0], s->Drgb[1], s->Drgb[2]);
printf("Chromatically transformed white rgbcW = %f %f %f\n", s->rgbcW[0], s->rgbcW[1], s->rgbcW[2]);
printf("Hunter-P-E cone response white rgbpW = %f %f %f\n", s->rgbpW[0], s->rgbpW[1], s->rgbpW[2]);
printf("Background induction factor n = %f\n", s->n);
printf("Lightness contrast factor Fl = %f\n", s->Fl);
printf("Background brightness induction factor Nbb = %f\n", s->Nbb);
printf("Chromatic brightness induction factor Ncb = %f\n", s->Ncb);
printf("Base exponential nonlinearity z = %f\n", s->z);
printf("Post adapted cone response white rgbaW = %f %f %f\n", s->rgbaW[0], s->rgbaW[1], s->rgbaW[2]);
printf("Achromatic response of white Aw = %f\n", s->Aw);
printf("\n");
#endif
return 0;
}
/* A version of the pow() function that preserves the */
/* sign of its first argument. */
static double spow(double x, double y) {
return x < 0.0 ? -pow(-x,y) : pow(x,y);
}
#define REFTRACE(xxxx) if (s->trace) printf xxxx ;
/* Conversion. Returns NZ and -1, -1, -1 if input is out of range */
static int cam02ref_XYZ_to_cam(
cam02ref *s,
double Jab[3],
double XYZ[3]
) {
int i;
double xyz[3], rgb[3], rgbp[3], rgba[3], rgbaW[3], rgbc[3], rgbcW[3];
double a, b, rS, J, C, h, e, A, ss;
double ttd, tt;
REFTRACE(("\nReference forward conversion:\n"))
REFTRACE(("XYZ %f %f %f\n",XYZ[0], XYZ[1], XYZ[2]))
/* Add in flare */
xyz[0] = s->Fsc * XYZ[0] + s->Fsxyz[0];
xyz[1] = s->Fsc * XYZ[1] + s->Fsxyz[1];
xyz[2] = s->Fsc * XYZ[2] + s->Fsxyz[2];
REFTRACE(("Including flare XYZ = %f %f %f\n", xyz[0], xyz[1], xyz[2]))
/* Spectrally sharpened cone responses */
rgb[0] = 0.7328 * xyz[0] + 0.4296 * xyz[1] - 0.1624 * xyz[2];
rgb[1] = -0.7036 * xyz[0] + 1.6975 * xyz[1] + 0.0061 * xyz[2];
rgb[2] = 0.0000 * xyz[0] + 0.0000 * xyz[1] + 1.0000 * xyz[2];
REFTRACE(("Sharpened cone sample rgb = %f %f %f\n", rgb[0], rgb[1], rgb[2]))
/* Chromaticaly transformed sample value */
rgbc[0] = s->Drgb[0] * rgb[0];
rgbc[1] = s->Drgb[1] * rgb[1];
rgbc[2] = s->Drgb[2] * rgb[2];
REFTRACE(("Chromatically transformed sample value rgbc = %f %f %f\n", rgb[0], rgb[1], rgb[2]))
/* Transform from spectrally sharpened, to Hunt-Pointer_Estevez cone space */
rgbp[0] = 0.7409744840453773 * rgbc[0]
+ 0.2180245944753982 * rgbc[1]
+ 0.0410009214792244 * rgbc[2];
rgbp[1] = 0.2853532916858801 * rgbc[0]
+ 0.6242015741188157 * rgbc[1]
+ 0.0904451341953042 * rgbc[2];
rgbp[2] = -0.0096276087384294 * rgbc[0]
- 0.0056980312161134 * rgbc[1]
+ 1.0153256399545427 * rgbc[2];
REFTRACE(("rgbp = %f %f %f\n", rgbp[0], rgbp[1], rgbp[2]))
/* Post-adapted cone response of sample. */
/* rgba[] has a minimum value of 0.1 for XYZ[] = 0 and no flare. */
/* We add a symetric negative compression region */
for (i = 0; i < 3; i++) {
if (s->range && (rgbp[i] < 0.0 || rgbp[i] < s->nldlimit)) {
Jab[0] = Jab[1] = Jab[2] = -1.0;
return 1;
}
if (rgbp[i] < 0.0) {
tt = pow(s->Fl * -rgbp[i], 0.42);
rgba[i] = (2.713 - 397.387 * tt) / (tt + 27.13);
} else {
tt = pow(s->Fl * rgbp[i], 0.42);
rgba[i] = (400.1 * tt + 2.713) / (tt + 27.13);
}
}
REFTRACE(("rgba = %f %f %f\n", rgba[0], rgba[1], rgba[2]))
/* Preliminary red-green & yellow-blue opponent dimensions */
a = rgba[0] - 12.0 * rgba[1]/11.0 + rgba[2]/11.0;
b = (1.0/9.0) * (rgba[0] + rgba[1] - 2.0 * rgba[2]);
rS = sqrt(a * a + b * b); /* Normalised a, b */
/* Preliminary Saturation */
/* Note that the minimum values for rgba[] for XYZ = 0 is 0.1 */
/* Hence magic 0.305 below comes from the following weighting of rgba[] */
ttd = rgba[0] + rgba[1] + (21.0/20.0) * rgba[2];
/* Achromatic response */
/* Note that the minimum values of rgba[] for XYZ = 0 is 0.1, */
/* hence magic 0.305 below comes from the following weighting of rgba[], */
/* to base A at 0.0 */
A = (2.0 * rgba[0] + rgba[1] + (1.0/20.0) * rgba[2] - 0.305) * s->Nbb;
REFTRACE(("a = %f, b = %f, ttd = %f, rS = %f, A = %f\n", a, b, ttd, rS, A))
/* Lightness */
J = pow(A/s->Aw, s->C * s->z); /* J/100 - keep Sign */
/* Hue angle */
h = (180.0/DBL_PI) * atan2(b,a);
h = (h < 0.0) ? h + 360.0 : h;
/* Eccentricity factor */
e = (cos(h * DBL_PI/180.0 + 2.0) + 3.8);
if (s->range && (J < DBL_EPSILON || J < s->jlimit || ttd < DBL_EPSILON)) {
REFTRACE(("J = %f, ttd = %f, exit with error\n", J, ttd))
Jab[0] = Jab[1] = Jab[2] = -1.0;
return 1;
}
ss = (12500.0/13.0 * s->Nc * s->Ncb * rS * e) / ttd;
/* Chroma */
C = pow(ss, 0.9) * sqrt(J) * s->nn;
REFTRACE(("ss = %f, C = %f\n", ss, C))
/* Helmholtz-Kohlraush effect */
if (s->hk && J < 1.0) {
double JJ, kk = s->hkscale * HHKR_MUL * C/300.0 * sin(DBL_PI * fabs(0.5 * (h - 90.0))/180.0);
if (kk > 0.9) /* Limit kk to a reasonable range */
kk = 0.9;
JJ = J + (1.0 - J) * kk;
REFTRACE(("JJ = %f from J = %f, kk = %f\n",JJ,J,kk))
J = JJ;
}
J *= 100.0; /* Scale J */
/* Compute Jab value */
Jab[0] = J;
if (rS >= DBL_EPSILON) {
Jab[1] = C * a/rS;
Jab[2] = C * b/rS;
} else {
Jab[1] = 0.0;
Jab[2] = 0.0;
}
REFTRACE(("Returning Jab %f %f %f\n", Jab[0],Jab[1],Jab[2]))
#ifdef DIAG
printf("Processing:\n");
printf("XYZ = %f %f %f\n", XYZ[0], XYZ[1], XYZ[2]);
printf("Including flare XYZ = %f %f %f\n", xyz[0], xyz[1], xyz[2]);
printf("Sharpened cone sample rgb = %f %f %f\n", rgb[0], rgb[1], rgb[2]);
printf("Chromatically transformed sample value rgbc = %f %f %f\n", rgbc[0], rgbc[1], rgbc[2]);
printf("Hunt-P-E cone space rgbp = %f %f %f\n", rgbp[0], rgbp[1], rgbp[2]);
printf("Post adapted cone response rgba = %f %f %f\n", rgba[0], rgba[1], rgba[2]);
printf("Prelim red green a = %f, b = %f\n", a, b);
printf("Hue angle h = %f\n", h);
printf("Eccentricity factor e = %f\n", e);
printf("Achromatic response A = %f\n", A);
printf("Lightness J = %f\n", J);
printf("Prelim Saturation ss = %f\n", ss);
printf("Chroma C = %f\n", C);
printf("Jab = %f %f %f\n", Jab[0], Jab[1], Jab[2]);
printf("\n");
#endif
return 0;
}
static int cam02ref_cam_to_XYZ(
cam02ref *s,
double XYZ[3],
double Jab[3]
) {
int i;
double xyz[3], rgb[3], rgbp[3], rgba[3], rgbaW[3], rgbc[3], rgbcW[3];
double ja, jb, aa, ab, a, b, J, C, h, e, A, ss;
double tt, ttA, tte;
J = Jab[0] * 0.01; /* J/100 */
ja = Jab[1];
jb = Jab[2];
/* Compute hue angle */
h = (180.0/DBL_PI) * atan2(jb, ja);
h = (h < 0.0) ? h + 360.0 : h;
/* Compute chroma value */
C = sqrt(ja * ja + jb * jb); /* Must be Always +ve */
/* Helmholtz-Kohlraush effect */
if (s->hk && J < 1.0) {
double kk = s->hkscale * HHKR_MUL * C/300.0 * sin(DBL_PI * fabs(0.5 * (h - 90.0))/180.0);
if (kk > 0.9) /* Limit kk to a reasonable range */
kk = 0.9;
J = (J - kk)/(1.0 - kk);
}
/* Eccentricity factor */
e = (cos(h * DBL_PI/180.0 + 2.0) + 3.8);
/* Achromatic response */
A = spow(J, 1.0/(s->C * s->z)) * s->Aw; /* Keep sign of J */
/* Preliminary Saturation - keep +ve */
tt = fabs(J);
ss = pow(C/(sqrt(tt) * s->nn), 1.0/0.9); /* keep +ve */
/* Compute a & b, taking care of numerical problems */
aa = fabs(ja);
ab = fabs(jb);
ttA = (A/s->Nbb)+0.305; /* Common factor */
tte = 12500.0/13.0 * e * s->Nc * s->Ncb; /* Common factor */
if (aa < 1e-10 && ab < 1e-10) {
a = ja;
b = jb;
} else if (aa > ab) {
double tanh = jb/ja;
double sign = (h > 90.0 && h <= 270.0) ? -1.0 : 1.0;
if (ttA < 0.0)
sign = -sign;
a = (ss * ttA)
/ (sign * sqrt(1.0 + tanh * tanh) * tte + (ss * (11.0/23.0 + (108.0/23.0) * tanh)));
b = a * tanh;
} else { /* ab > aa */
double itanh = ja/jb;
double sign = (h > 180.0 && h <= 360.0) ? -1.0 : 1.0;
if (ttA < 0.0)
sign = -sign;
b = (ss * ttA)
/ (sign * sqrt(1.0 + itanh * itanh) * tte + (ss * (108.0/23.0 + (11.0/23.0) * itanh)));
a = b * itanh;
}
/* Post-adapted cone response of sample */
rgba[0] = (20.0/61.0) * ttA
+ ((41.0 * 11.0)/(61.0 * 23.0)) * a
+ ((288.0 * 1.0)/(61.0 * 23.0)) * b;
rgba[1] = (20.0/61.0) * ttA
- ((81.0 * 11.0)/(61.0 * 23.0)) * a
- ((261.0 * 1.0)/(61.0 * 23.0)) * b;
rgba[2] = (20.0/61.0) * ttA
- ((20.0 * 11.0)/(61.0 * 23.0)) * a
- ((20.0 * 315.0)/(61.0 * 23.0)) * b;
/* Hunt-Pointer_Estevez cone space */
tt = 1.0/s->Fl;
for (i = 0; i < 3; i++) {
if (rgba[i] < 0.1) {
double ta = rgba[i] > -396.387 ? rgba[i] : -396.387;
rgbp[i] = -tt * pow((2.713 - 27.13 * rgba[i] )/(397.387 + ta), 1.0/0.42);
} else {
double ta = rgba[i] < 399.1 ? rgba[i] : 399.1;
rgbp[i] = tt * pow((27.13 * rgba[i] -2.713)/(400.1 - ta), 1.0/0.42);
}
}
/* Chromaticaly transformed sample value */
rgbc[0] = 1.5591523979049677 * rgbp[0]
- 0.5447226796590880 * rgbp[1]
- 0.0144453097698588 * rgbp[2];
rgbc[1] = -0.7143267176368630 * rgbp[0]
+ 1.8503099728895096 * rgbp[1]
- 0.1359761119854705 * rgbp[2];
rgbc[2] = 0.0107755117023383 * rgbp[0]
+ 0.0052187662221759 * rgbp[1]
+ 0.9840056143203700 * rgbp[2];
/* Spectrally sharpened cone responses */
rgb[0] = rgbc[0]/s->Drgb[0];
rgb[1] = rgbc[1]/s->Drgb[1];
rgb[2] = rgbc[2]/s->Drgb[2];
/* XYZ values */
xyz[0] = 1.0961238208355140 * rgb[0]
- 0.2788690002182872 * rgb[1]
+ 0.1827451793827730 * rgb[2];
xyz[1] = 0.4543690419753590 * rgb[0]
+ 0.4735331543074120 * rgb[1]
+ 0.0720978037172291 * rgb[2];
xyz[2] = -0.0096276087384294 * rgb[0]
- 0.0056980312161134 * rgb[1]
+ 1.0153256399545427 * rgb[2];
/* Subtract flare */
XYZ[0] = s->Fisc * (xyz[0] - s->Fsxyz[0]);
XYZ[1] = s->Fisc * (xyz[1] - s->Fsxyz[1]);
XYZ[2] = s->Fisc * (xyz[2] - s->Fsxyz[2]);
#ifdef DIAG
printf("Processing:\n");
printf("Jab = %f %f %f\n", Jab[0], Jab[1], Jab[2]);
printf("Chroma C = %f\n", C);
printf("Preliminary Saturation ss = %f\n", ss);
printf("Lightness J = %f\n", J * 100.0);
printf("Achromatic response A = %f\n", A);
printf("Eccentricity factor e = %f\n", e);
printf("Hue angle h = %f\n", h);
printf("Prelim red green a = %f, b = %f\n", a, b);
printf("Post adapted cone response rgba = %f %f %f\n", rgba[0], rgba[1], rgba[2]);
printf("Hunt-P-E cone space rgbp = %f %f %f\n", rgbp[0], rgbp[1], rgbp[2]);
printf("Chromatically transformed sample value rgbc = %f %f %f\n", rgbc[0], rgbc[1], rgbc[2]);
printf("Sharpened cone sample rgb = %f %f %f\n", rgb[0], rgb[1], rgb[2]);
printf("Including flare XYZ = %f %f %f\n", xyz[0], xyz[1], xyz[2]);
printf("XYZ = %f %f %f\n", XYZ[0], XYZ[1], XYZ[2]);
printf("\n");
#endif
return 0;
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,596 @@
/*
* cam97s3hk
*
* Color Appearance Model, based on
* CIECAM97, "Revision for Practical Applications"
* by Mark D. Fairchild, with the addition of the Viewing Flare
* model described on page 487 of "Digital Color Management",
* by Edward Giorgianni and Thomas Madden, and the
* Helmholtz-Kohlraush effect, using the equation
* the Bradford-Hunt 96C model as detailed in Mark Fairchilds
* book "Color Appearance Models".
*
* Author: Graeme W. Gill
* Date: 5/10/00
* Version: 1.20
*
* Copyright 2000, 2002 Graeme W. Gill
* Please refer to COPYRIGHT file for details.
* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :-
* see the License.txt file for licencing details.
*/
/* Note that XYZ values are normalised to 1.0 consistent */
/* with the ICC convention (not 100.0 as assumed by the CIECAM spec.) */
/* Note that all whites are assumed to be normalised (ie. Y = 1.0) */
/* Various changes have been made to allow the CAM conversions to */
/* function over a much greater range of XYZ and Jab values that */
/* the functions are described in the above references. This is */
/* because such values arise in the process of gamut mapping, and */
/* in scanning through the grid of PCS values needed to fill in */
/* the A2B table of an ICC profile. Such values have no correlation */
/* to a real color value, but none the less need to be handled without */
/* causing an exception, in a geometrically consistent and reversible */
/* fashion. */
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include "xcam.h"
#include "cam97s3.h"
#undef DIAG /* Print internal value diagnostics for each conversion */
#define CAM_PI 3.14159265359
/* Utility function */
/* Return a viewing condition enumeration from the given Ambient and */
/* Adapting/Surround Luminance. */
static ViewingCondition cam97_Ambient2VC(
double La, /* Ambient Luminance (cd/m^2) */
double Lv /* Luminance of white in the Viewing/Scene/Image field (cd/m^2) */
) {
double r;
if (fabs(La) < 1e-10) /* Hmm. */
r = 1.0;
else
r = La/Lv;
if (r < 0.01)
return vc_dark;
if (r < 0.2)
return vc_dim;
return vc_average;
}
static void cam_free(cam97s3 *s);
static int set_view(struct _cam97s3 *s, ViewingCondition Ev, double Wxyz[3],
double La, double Yb, double Lv, double Yf, double Fxyz[3],
int hk);
static int XYZ_to_cam(struct _cam97s3 *s, double *Jab, double *xyz);
static int cam_to_XYZ(struct _cam97s3 *s, double *xyz, double *Jab);
/* Create a cam97s3 conversion object, with default viewing conditions */
cam97s3 *new_cam97s3(void) {
cam97s3 *s;
// double D50[3] = { 0.9642, 1.0000, 0.8249 };
if ((s = (cam97s3 *)calloc(1, sizeof(cam97s3))) == NULL) {
fprintf(stderr,"cam97s3: malloc failed allocating object\n");
exit(-1);
}
/* Initialise methods */
s->del = cam_free;
s->set_view = set_view;
s->XYZ_to_cam = XYZ_to_cam;
s->cam_to_XYZ = cam_to_XYZ;
/* Set a default viewing condition ?? */
/* set_view(s, vc_average, D50, 33.0, 0.2, 0.0, 0.0, D50, 0); */
return s;
}
static void cam_free(cam97s3 *s) {
if (s != NULL)
free(s);
}
/* A version of the pow() function that preserves the */
/* sign of its first argument. */
static double spow(double x, double y) {
return x < 0.0 ? -pow(-x,y) : pow(x,y);
}
static int set_view(
cam97s3 *s,
ViewingCondition Ev, /* Enumerated Viewing Condition */
double Wxyz[3], /* Reference/Adapted White XYZ (Y range 0.0 .. 1.0) */
double La, /* Adapting/Surround Luminance cd/m^2 */
double Yb, /* Relative Luminance of Background to reference white */
double Lv, /* Luminance of white in the Viewing/Scene/Image field (cd/m^2) */
/* Ignored if Ev is set to other than vc_none */
double Yf, /* Flare as a fraction of the reference white (Y range 0.0 .. 1.0) */
double Fxyz[3], /* The Flare white coordinates (typically the Ambient color) */
int hk /* Flag, NZ to use Helmholtz-Kohlraush effect */
) {
double tt;
if (Ev == vc_none) /* Compute enumerated viewing condition */
Ev = cam97_Ambient2VC(La, Lv);
/* Transfer parameters to the object */
s->Ev = Ev;
s->Wxyz[0] = Wxyz[0];
s->Wxyz[1] = Wxyz[1];
s->Wxyz[2] = Wxyz[2];
s->Yb = Yb > 0.005 ? Yb : 0.005; /* Set minimum to avoid divide by 0.0 */
s->La = La;
s->Yf = Yf;
s->Fxyz[0] = Fxyz[0];
s->Fxyz[1] = Fxyz[1];
s->Fxyz[2] = Fxyz[2];
s->hk = hk;
/* Compute the internal parameters by category */
switch(s->Ev) {
case vc_dark:
s->C = 0.525;
s->Nc = 0.8;
s->F = 0.9;
break;
case vc_dim:
s->C = 0.59;
s->Nc = 0.95;
s->F = 0.9;
break;
case vc_cut_sheet:
s->C = 0.41;
s->Nc = 0.8;
s->F = 0.9;
break;
default: /* average */
s->C = 0.69;
s->Nc = 1.0;
s->F = 1.0;
break;
}
/* Compute values that only change with viewing parameters */
/* Figure out the Flare contribution to the flareless XYZ input */
tt = s->Yf * s->Wxyz[1]/s->Fxyz[1];
s->Fsxyz[0] = tt * s->Fxyz[0];
s->Fsxyz[1] = tt * s->Fxyz[1];
s->Fsxyz[2] = tt * s->Fxyz[2];
/* Rescale so that the sum of the flare and the input doesn't exceed white */
s->Fsc = s->Wxyz[1]/(s->Fsxyz[1] + s->Wxyz[1]);
s->Fsxyz[0] *= s->Fsc;
s->Fsxyz[1] *= s->Fsc;
s->Fsxyz[2] *= s->Fsc;
s->Fisc = 1.0/s->Fsc;
/* Sharpened cone response white values */
s->rgbW[0] = 0.8562 * s->Wxyz[0] + 0.3372 * s->Wxyz[1] - 0.1934 * s->Wxyz[2];
s->rgbW[1] = -0.8360 * s->Wxyz[0] + 1.8327 * s->Wxyz[1] + 0.0033 * s->Wxyz[2];
s->rgbW[2] = 0.0357 * s->Wxyz[0] - 0.0469 * s->Wxyz[1] + 1.0112 * s->Wxyz[2];
/* Degree of chromatic adaptation */
s->D = s->F - (s->F / (1.0 + 2.0 * pow(s->La, 0.25) + s->La * s->La / 300.0) );
/* Chromaticaly transformed white value */
s->rgbcW[0] = (s->D * (1.0/s->rgbW[0]) + 1.0 - s->D ) * s->rgbW[0];
s->rgbcW[1] = (s->D * (1.0/s->rgbW[1]) + 1.0 - s->D ) * s->rgbW[1];
s->rgbcW[2] = (s->D * (1.0/s->rgbW[2]) + 1.0 - s->D ) * s->rgbW[2];
/* Transform from spectrally sharpened, to Hunt-Pointer_Estevez cone space */
s->rgbpW[0] = 0.6962394300923847 * s->rgbcW[0]
+ 0.2492311682812913 * s->rgbcW[1]
+ 0.0545394016263241 * s->rgbcW[2];
s->rgbpW[1] = 0.3054822636273227 * s->rgbcW[0]
+ 0.5921282520433844 * s->rgbcW[1]
+ 0.1023894843292929 * s->rgbcW[2];
s->rgbpW[2] = -0.0139683251072516 * s->rgbcW[0]
+ 0.0278065725014340 * s->rgbcW[1]
+ 0.9861617526058175 * s->rgbcW[2];
/* Background induction factor */
s->n = s->Yb/ s->Wxyz[1];
s->nn = pow((1.64 - pow(0.29, s->n)), 1.41); /* Pre computed value */
/* Lightness contrast factor ?? */
{
double k;
k = 1.0 / (5.0 * s->La + 1.0);
s->Fl = 0.2 * pow(k , 4.0) * 5.0 * s->La
+ 0.1 * pow(1.0 - pow(k , 4.0) , 2.0) * pow(5.0 * s->La , 1.0/3.0);
}
/* Background and Chromatic brightness induction factors */
s->Nbb = 0.725 * pow(1.0/s->n, 0.2);
s->Ncb = s->Nbb;
/* Base exponential nonlinearity */
s->z = 1.0 + pow(s->n , 0.5);
/* Post-adapted cone response of white */
tt = pow(s->Fl * s->rgbpW[0], 0.73);
s->rgbaW[0] = (40.0 * tt / (tt + 2.0)) + 1.0;
tt = pow(s->Fl * s->rgbpW[1], 0.73);
s->rgbaW[1] = (40.0 * tt / (tt + 2.0)) + 1.0;
tt = pow(s->Fl * s->rgbpW[2], 0.73);
s->rgbaW[2] = (40.0 * tt / (tt + 2.0)) + 1.0;
/* Achromatic response of white */
s->Aw = (2.0 * s->rgbaW[0] + s->rgbaW[1] + (1.0/20.0) * s->rgbaW[2] - 3.05) * s->Nbb;
#ifdef DIAG
printf("Scene parameters:\n");
printf("Viewing condition Ev = %d\n",s->Ev);
printf("Ref white Wxyz = %f %f %f\n", s->Wxyz[0], s->Wxyz[1], s->Wxyz[2]);
printf("Relative liminance of background Yb = %f\n", s->Yb);
printf("Adapting liminance La = %f\n", s->La);
printf("Flare Yf = %f\n", s->Yf);
printf("Flare color Fxyz = %f %f %f\n", s->Fxyz[0], s->Fxyz[1], s->Fxyz[2]);
printf("Internal parameters:\n");
printf("Surround Impact C = %f\n", s->C);
printf("Chromatic Induction Nc = %f\n", s->Nc);
printf("Adaptation Degree F = %f\n", s->F);
printf("Pre-computed values\n");
printf("Sharpened cone white rgbW = %f %f %f\n", s->rgbW[0], s->rgbW[1], s->rgbW[2]);
printf("Degree of chromatic adaptation D = %f\n", s->D);
printf("Chromatically transformed white rgbcW = %f %f %f\n", s->rgbcW[0], s->rgbcW[1], s->rgbcW[2]);
printf("Hunter-P-E cone response white rgbpW = %f %f %f\n", s->rgbpW[0], s->rgbpW[1], s->rgbpW[2]);
printf("Background induction factor n = %f\n", s->n);
printf("Lightness contrast factor Fl = %f\n", s->Fl);
printf("Background brightness induction factor Nbb = %f\n", s->Nbb);
printf("Chromatic brightness induction factor Ncb = %f\n", s->Ncb);
printf("Base exponential nonlinearity z = %f\n", s->z);
printf("Post adapted cone response white rgbaW = %f %f %f\n", s->rgbaW[0], s->rgbaW[1], s->rgbaW[2]);
printf("Achromatic response of white Aw = %f\n", s->Aw);
#endif
return 0;
}
/* Conversions */
static int XYZ_to_cam(
struct _cam97s3 *s,
double Jab[3],
double XYZ[3]
) {
int i;
double xyz[3], rgb[3], rgbp[3], rgba[3], rgbc[3];
double a, b, nab, J, C, h, e, A, ss;
double ttd, tt;
/* Add in flare */
xyz[0] = s->Fsc * XYZ[0] + s->Fsxyz[0];
xyz[1] = s->Fsc * XYZ[1] + s->Fsxyz[1];
xyz[2] = s->Fsc * XYZ[2] + s->Fsxyz[2];
/* Spectrally sharpened cone responses */
rgb[0] = 0.8562 * xyz[0] + 0.3372 * xyz[1] - 0.1934 * xyz[2];
rgb[1] = -0.8360 * xyz[0] + 1.8327 * xyz[1] + 0.0033 * xyz[2];
rgb[2] = 0.0357 * xyz[0] - 0.0469 * xyz[1] + 1.0112 * xyz[2];
/* Chromaticaly transformed sample value */
rgbc[0] = (s->D * (1.0/s->rgbW[0]) + 1.0 - s->D ) * rgb[0];
rgbc[1] = (s->D * (1.0/s->rgbW[1]) + 1.0 - s->D ) * rgb[1];
rgbc[2] = (s->D * (1.0/s->rgbW[2]) + 1.0 - s->D ) * rgb[2];
/* Transform from spectrally sharpened, to Hunt-Pointer_Estevez cone space */
rgbp[0] = 0.6962394300923847 * rgbc[0]
+ 0.2492311682812913 * rgbc[1]
+ 0.0545394016263241 * rgbc[2];
rgbp[1] = 0.3054822636273227 * rgbc[0]
+ 0.5921282520433844 * rgbc[1]
+ 0.1023894843292929 * rgbc[2];
rgbp[2] = -0.0139683251072516 * rgbc[0]
+ 0.0278065725014340 * rgbc[1]
+ 0.9861617526058175 * rgbc[2];
/* Post-adapted cone response of sample. */
/* rgba[] has a minimum value of 1.0 for XYZ[] = 0 and no flare. */
/* We add linear segments at the ends of this conversion to */
/* allow numerical handling of a wider range of values */
for (i = 0; i < 3; i++) {
if (rgbp[i] < 0.0) {
tt = pow(s->Fl * -rgbp[i], 0.73);
if (tt < 78.0)
rgba[i] = (2.0 - 39.0 * tt) / (tt + 2.0);
else
rgba[i] = (2.0 - tt) / 2.0;
} else {
tt = pow(s->Fl * rgbp[i], 0.73);
if (tt < 78.0)
rgba[i] = (41.0 * tt + 2.0) / (tt + 2.0);
else
rgba[i] = (tt + 2.0) / 2.0;
}
}
/* Preliminary red-green & yellow-blue opponent dimensions */
a = rgba[0] - 12.0 * rgba[1]/11.0 + rgba[2]/11.0;
b = (1.0/9.0) * (rgba[0] + rgba[1] - 2.0 * rgba[2]);
nab = sqrt(a * a + b * b); /* Normalised a, b */
/* Hue angle */
h = (180.0/CAM_PI) * atan2(b,a);
h = (h < 0.0) ? h + 360.0 : h;
/* Eccentricity factor */
{
double r, e1, e2, h1, h2;
if (h <= 20.14)
e1 = 0.8565, e2 = 0.8, h1 = 0.0, h2 = 20.14;
else if (h <= 90.0)
e1 = 0.8, e2 = 0.7, h1 = 20.14, h2 = 90.0;
else if (h <= 164.25)
e1 = 0.7, e2 = 1.0, h1 = 90.0, h2 = 164.25;
else if (h <= 237.53)
e1 = 1.0, e2 = 1.2, h1 = 164.25, h2 = 237.53;
else
e1 = 1.2, e2 = 0.8565, h1 = 237.53, h2 = 360.0;
r = (h-h1)/(h2-h1);
#ifdef CIECAM97S3_SPLINE_E
r = r * r * (3.0 - 2.0 * r);
#endif
e = e1 + r * (e2-e1);
}
/* Achromatic response */
/* Note that the minimum values of rgba[] for XYZ = 0 is 1.0, */
/* hence magic 3.05 below comes from the following weighting of rgba[], */
/* to base A at 0.0 */
A = (2.0 * rgba[0] + rgba[1] + (1.0/20.0) * rgba[2] - 3.05) * s->Nbb;
/* Lightness */
J = spow(A/s->Aw, s->C * s->z); /* J/100 - keep Sign */
/* Saturation */
/* Note that the minimum values for rgba[] for XYZ = 0 is 1.0 */
/* Hence magic 3.05 below comes from the following weighting of rgba[] */
ttd = rgba[0] + rgba[1] + (21.0/20.0) * rgba[2];
ttd = fabs(ttd);
if (ttd < 3.05) { /* If not physically realisable, limit denominator */
ttd = 3.05; /* hence limit max ss value */
}
ss = (50000.0/13.0 * s->Nc * s->Ncb * nab * e) / ttd;
/* Chroma - Keep C +ve and make sure J doesn't force it to 0 */
tt = fabs(J);
if (tt < 0.01)
tt = 0.01;
C = 0.7487 * pow(ss, 0.973) * pow(tt, 0.945 * s->n) * s->nn;
/* Helmholtz-Kohlraush effect */
if (s->hk) {
double kk = C/300.0 * sin(CAM_PI * fabs(0.5 * (h - 90.0))/180.0);
if (kk > 0.9) /* Limit kk to a reasonable range */
kk = 0.9;
J = J + (1.0 - J) * kk;
}
J *= 100.0; /* Scale J */
/* Compute Jab value */
Jab[0] = J;
if (nab > 1e-10) {
Jab[1] = C * a/nab;
Jab[2] = C * b/nab;
} else {
Jab[1] = 0.0;
Jab[2] = 0.0;
}
#ifdef DIAG
printf("Processing:\n");
printf("XYZ = %f %f %f\n", XYZ[0], XYZ[1], XYZ[2]);
printf("Including flare XYZ = %f %f %f\n", xyz[0], xyz[1], xyz[2]);
printf("Sharpened cone sample rgb = %f %f %f\n", rgb[0], rgb[1], rgb[2]);
printf("Chromatically transformed sample value rgbc = %f %f %f\n", rgbc[0], rgbc[1], rgbc[2]);
printf("Hunt-P-E cone space rgbp = %f %f %f\n", rgbp[0], rgbp[1], rgbp[2]);
printf("Post adapted cone response rgba = %f %f %f\n", rgba[0], rgba[1], rgba[2]);
printf("Prelim red green a = %f, b = %f\n", a, b);
printf("Hue angle h = %f\n", h);
printf("Eccentricity factor e = %f\n", e);
printf("Achromatic response A = %f\n", A);
printf("Lightness J = %f\n", J);
printf("Saturation ss = %f\n", ss);
printf("Chroma C = %f\n", C);
printf("Jab = %f %f %f\n", Jab[0], Jab[1], Jab[2]);
#endif
return 0;
}
static int cam_to_XYZ(
struct _cam97s3 *s,
double XYZ[3],
double Jab[3]
) {
int i;
double xyz[3], rgb[3], rgbp[3], rgba[3], rgbc[3];
double ja, jb, aa, ab, a, b, J, C, h, e, A, ss;
double tt, ttA, tte;
J = Jab[0] * 0.01; /* J/100 */
ja = Jab[1];
jb = Jab[2];
/* Compute hue angle */
h = (180.0/CAM_PI) * atan2(jb, ja);
h = (h < 0.0) ? h + 360.0 : h;
/* Compute chroma value */
C = sqrt(ja * ja + jb * jb); /* Must be Always +ve */
/* Helmholtz-Kohlraush effect */
if (s->hk) {
double kk = C/300.0 * sin(CAM_PI * fabs(0.5 * (h - 90.0))/180.0);
if (kk > 0.9) /* Limit kk to a reasonable range */
kk = 0.9;
J = (J - kk)/(1.0 - kk);
}
/* Eccentricity factor */
{
double r, e1, e2, h1, h2;
if (h <= 20.14)
e1 = 0.8565, e2 = 0.8, h1 = 0.0, h2 = 20.14;
else if (h <= 90.0)
e1 = 0.8, e2 = 0.7, h1 = 20.14, h2 = 90.0;
else if (h <= 164.25)
e1 = 0.7, e2 = 1.0, h1 = 90.0, h2 = 164.25;
else if (h <= 237.53)
e1 = 1.0, e2 = 1.2, h1 = 164.25, h2 = 237.53;
else
e1 = 1.2, e2 = 0.8565, h1 = 237.53, h2 = 360.0;
r = (h-h1)/(h2-h1);
#ifdef CIECAM97S3_SPLINE_E
r = r * r * (3.0 - 2.0 * r);
#endif
e = e1 + r * (e2-e1);
}
/* Achromatic response */
A = spow(J, 1.0/(s->C * s->z)) * s->Aw; /* Keep sign of J */
/* Saturation - keep +ve and make sure J = 0 doesn't blow it up. */
tt = fabs(J);
if (tt < 0.01)
tt = 0.01;
ss = pow(C/(0.7487 * pow(tt, 0.945 * s->n) * s->nn), 1.0/0.973); /* keep +ve */
/* Compute a & b, taking care of numerical problems */
aa = fabs(ja);
ab = fabs(jb);
ttA = (A/s->Nbb)+3.05; /* Common factor */
tte = 50000.0/13.0 * e * s->Nc * s->Ncb; /* Common factor */
if (aa < 1e-10 && ab < 1e-10) {
a = ja;
b = jb;
} else if (aa > ab) {
double tanh = jb/ja;
double sign = (h > 90.0 && h <= 270.0) ? -1.0 : 1.0;
if (ttA < 0.0)
sign = -sign;
a = (ss * ttA)
/ (sign * sqrt(1.0 + tanh * tanh) * tte + (ss * (11.0/23.0 + (108.0/23.0) * tanh)));
b = a * tanh;
} else { /* ab > aa */
double itanh = ja/jb;
double sign = (h > 180.0 && h <= 360.0) ? -1.0 : 1.0;
if (ttA < 0.0)
sign = -sign;
b = (ss * ttA)
/ (sign * sqrt(1.0 + itanh * itanh) * tte + (ss * (108.0/23.0 + (11.0/23.0) * itanh)));
a = b * itanh;
}
{ /* Check if we have a limited saturation because it is non-realisable */
double tts;
double nab = sqrt(a * a + b * b); /* Normalised a, b */
tts = (nab * tte) / 3.05; /* Limited saturation number */
if (tts < ss) { /* Saturation exceeds it anyway so must have limited denom. */
a *= ss/tts; /* Rescale a & b to account for extra ss */
b *= ss/tts; /* even though denom was limited (since nab was in numerator). */
}
}
/* Post-adapted cone response of sample */
rgba[0] = (20.0/61.0) * ttA
+ ((41.0 * 11.0)/(61.0 * 23.0)) * a
+ ((288.0 * 1.0)/(61.0 * 23.0)) * b;
rgba[1] = (20.0/61.0) * ttA
- ((81.0 * 11.0)/(61.0 * 23.0)) * a
- ((261.0 * 1.0)/(61.0 * 23.0)) * b;
rgba[2] = (20.0/61.0) * ttA
- ((20.0 * 11.0)/(61.0 * 23.0)) * a
- ((20.0 * 315.0)/(61.0 * 23.0)) * b;
/* Hunt-Pointer_Estevez cone space */
/* (with linear segments at the ends0 */
tt = 1.0/s->Fl;
for (i = 0; i < 3; i++) {
if (rgba[i] < 1.0) {
double ta = rgba[i] > -38.0 ? rgba[i] : -38.0;
rgbp[i] = -tt * pow((2.0 - 2.0 * rgba[i] )/(39.0+ ta), 1.0/0.73);
} else {
double ta = rgba[i] < 40.0 ? rgba[i] : 40.0;
rgbp[i] = tt * pow((2.0 * rgba[i] -2.0)/(41.0 - ta), 1.0/0.73);
}
}
/* Chromaticaly transformed sample value */
rgbc[0] = 1.7605948990728097 * rgbp[0]
- 0.7400833814121892 * rgbp[1]
- 0.0205291236096116 * rgbp[2];
rgbc[1] = -0.9170843265341294 * rgbp[0]
+ 2.0826033118941054 * rgbp[1]
- 0.1655098145167107 * rgbp[2];
rgbc[2] = 0.0507964678367941 * rgbp[0]
- 0.0692054676442407 * rgbp[1]
+ 1.0184084918427683 * rgbp[2];
/* Spectrally sharpened cone responses */
rgb[0] = rgbc[0]/(s->D * (1.0/s->rgbW[0]) + 1.0 - s->D);
rgb[1] = rgbc[1]/(s->D * (1.0/s->rgbW[1]) + 1.0 - s->D);
rgb[2] = rgbc[2]/(s->D * (1.0/s->rgbW[2]) + 1.0 - s->D);
/* XYZ values */
xyz[0] = 0.9873999149199270 * rgb[0]
- 0.1768250198556842 * rgb[1]
+ 0.1894251049357572 * rgb[2];
xyz[1] = 0.4504351090445316 * rgb[0]
+ 0.4649328977527109 * rgb[1]
+ 0.0846319932027575 * rgb[2];
xyz[2] = -0.0139683251072516 * rgb[0]
+ 0.0278065725014340 * rgb[1]
+ 0.9861617526058175 * rgb[2];
/* Subtract flare */
XYZ[0] = s->Fisc * (xyz[0] - s->Fsxyz[0]);
XYZ[1] = s->Fisc * (xyz[1] - s->Fsxyz[1]);
XYZ[2] = s->Fisc * (xyz[2] - s->Fsxyz[2]);
#ifdef DIAG
printf("Processing:\n");
printf("Jab = %f %f %f\n", Jab[0], Jab[1], Jab[2]);
printf("Chroma C = %f\n", C);
printf("Saturation ss = %f\n", ss);
printf("Lightness J = %f\n", J * 100.0);
printf("Achromatic response A = %f\n", A);
printf("Eccentricity factor e = %f\n", e);
printf("Hue angle h = %f\n", h);
printf("Prelim red green a = %f, b = %f\n", a, b);
printf("Post adapted cone response rgba = %f %f %f\n", rgba[0], rgba[1], rgba[2]);
printf("Hunt-P-E cone space rgbp = %f %f %f\n", rgbp[0], rgbp[1], rgbp[2]);
printf("Chromatically transformed sample value rgbc = %f %f %f\n", rgbc[0], rgbc[1], rgbc[2]);
printf("Sharpened cone sample rgb = %f %f %f\n", rgb[0], rgb[1], rgb[2]);
printf("Including flare XYZ = %f %f %f\n", xyz[0], xyz[1], xyz[2]);
printf("XYZ = %f %f %f\n", XYZ[0], XYZ[1], XYZ[2]);
#endif
return 0;
}

View File

@@ -0,0 +1,169 @@
/*
* cam97s3
*
* Color Appearance Model, based on
* CIECAM97, "Revision for Practical Applications"
* by Mark D. Fairchild, with the addition of the Viewing Flare
* model described on page 487 of "Digital Color Management",
* by Edward Giorgianni and Thomas Madden, and the
* Helmholtz-Kohlraush effect, using the equation
* the Bradford-Hunt 96C model as detailed in Mark Fairchilds
* book "Color Appearance Models".
*
* Author: Graeme W. Gill
* Date: 5/10/00
* Version: 1.20
*
* Copyright 2000 Graeme W. Gill
* Please refer to COPYRIGHT file for details.
* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :-
* see the License.txt file for licencing details.
*/
/* Algorithm tweaks */
#define CIECAM97S3_SPLINE_E /* Use spline interpolation for eccentricity factor */
/* Definitions assumed here:
Stimulus field is the 2 degrees field of view of the sample
being characterised.
Viewing/Scene/Image field is the area of the whole image or
display surface that the stimulus is part of.
Background field is 10-12 degree field surrounding the stimulus field.
This may be within, overlap or encompass the Viewing/Scene/Image field.
Surround/Adapting field is the visual field minus the background field.
Visual field is the 130 degree angular field that is seen by the eyes.
Illuminating field is the field that illuminates the reflective
Scene/Image. It may be the same as the Ambient field.
Ambient field is the whole surrounding environmental light field.
NOTE: In "Digital Color Management", Giorgianni and Madden use the term
"Surround" to mean the same thing as "Background" in the CIECAM97 terminology.
The ICC standard doesn't define what it means by "Surround illumination".
*/
/* Rules of Thumb: */
/* Ambient Luminance (Lat, cd/m^2) is Ambient Illuminance (Lux) divided by PI. */
/* i.e. Lat = Iat/PI */ /* (1 foot candle = 0.0929 lux) */
/* The Adapting/Surround Luminance is often taken to be */
/* the 20% of the Ambient Luminance. (gray world) */
/* i.e. La = Lat/5 = Iat/15.7 */
/* For a reflective print, the Viewing/Scene/Image luminance (Lv, cd/m^2), */
/* will be the Illuminating Luminance (Li, cd/m^2) reflected by the */
/* media white point (Yw) */
/* If there is no special illumination for a reflective print, */
/* then the Illuminating Luminance (Li) will be the Ambient Luminance (Lat) */
/* An emisive display will have an independently determined Lv. */
/* The classification of the type of surround is */
/* determined by comparing the Adapting/Surround luminance (La, cd/m^2) */
/* with the average luminance of the Viewing/Scene/Image field (Lv, cd/m^2) */
/* La/Lv == 0%, dark */
/* La/Lv 0 - 20%, dim */
/* La/Lv > 20%, average */
/* special, cut sheet */
/* The Background relative luminance Yb is typically assumed to */
/* be 0.18 .. 0.2, and is assumed to be grey. */
/* The source of flare light depends on the type of display system. */
/* For a CRT, it will be the Ambient light reflecting off the glass surface. */
/* (This implies Yf = Lat * reflectance/Lv) */
/* For a reflection print, it will be the Illuminant reflecting from the media */
/* surface. (Yf = Li * reflectance) */
/* For a projected image, it will be stray projector light, scattered by the */
/* surround, screen and air particles. (Yf = Li * reflectance_and_scattering) */
/*
Typical Ambient Illuminance brightness
(Lux) La Condition
11 1 Twilight
32 2 Subdued indoor lighting
64 4 Less than typical office light; sometimes recommended for
display-only workplaces (sRGB)
350 22 Typical Office (sRGB annex D)
500 32 Practical print evaluationa (ISO-3664 P2)
1000 64 Good Print evaluation (CIE 116-1995)
1000 64 Overcast Outdoors
2000 127 Critical print evaluation (ISO-3664 P1)
10000 637 Typical outdoors, full daylight
50000 3185 Bright summers day
*/
/* ---------------------------------- */
struct _cam97s3 {
/* Public: */
void (*del)(struct _cam97s3 *s); /* We're done with it */
int (*set_view)(
struct _cam97s3 *s,
ViewingCondition Ev, /* Enumerated Viewing Condition */
double Wxyz[3], /* Reference/Adapted White XYZ (Y scale 1.0) */
double La, /* Adapting/Surround Luminance cd/m^2 */
double Yb, /* Luminance of Background relative to reference white (range 0.0 .. 1.0) */
double Lv, /* Luminance of white in the Viewing/Scene/Image field (cd/m^2) */
/* Ignored if Ev is set */
double Yf, /* Flare as a fraction of the reference white (range 0.0 .. 1.0) */
double Fxyz[3], /* The Flare white coordinates (typically the Ambient color) */
int hk /* Flag, NZ to use Helmholtz-Kohlraush effect */
);
/* Conversions */
int (*XYZ_to_cam)(struct _cam97s3 *s, double *out, double *in);
int (*cam_to_XYZ)(struct _cam97s3 *s, double *out, double *in);
/* Private: */
/* Scene parameters */
ViewingCondition Ev; /* Enumerated Viewing Condition */
double Wxyz[3]; /* Reference/Adapted White XYZ (Y range 0.0 .. 1.0) */
double Yb; /* Relative Luminance of Background to reference white (Y range 0.0 .. 1.0) */
double La; /* Adapting/Surround Luminance cd/m^2 */
double Yf; /* Flare as a fraction of the reference white (Y range 0.0 .. 1.0) */
double Fxyz[3]; /* The Flare white coordinates (typically the Ambient color) */
/* Internal parameters */
double C; /* Surround Impact */
double Nc; /* Chromatic Induction */
double F; /* Adaptation Degree */
/* Pre-computed values */
double Fsc; /* Flare scale */
double Fisc; /* Inverse flare scale */
double Fsxyz[3]; /* Scaled Flare color coordinates */
double rgbW[3]; /* Sharpened cone response white values */
double D; /* Degree of chromatic adaption */
double rgbcW[3]; /* Chromatically transformed white value */
double rgbpW[3]; /* Hunt-Pointer-Estevez cone response space white */
double n; /* Background induction factor */
double nn; /* Precomuted function of n */
double Fl; /* Lightness contrast factor ?? */
double Nbb; /* Background brightness induction factors */
double Ncb; /* Chromatic brightness induction factors */
double z; /* Base exponential nonlinearity */
double rgbaW[3]; /* Post-adapted cone response of white */
double Aw; /* Achromatic response of white */
/* Flags */
int hk; /* If NZ, use Helmholtz-Kohlraush effect */
int trace; /* Trace values through computation */
}; typedef struct _cam97s3 cam97s3;
/* Create a cam97s3 conversion class, with default viewing conditions */
cam97s3 *new_cam97s3(void);

View File

@@ -0,0 +1,456 @@
/*
* International Color Consortium color transform expanded support
*
* Author: Graeme W. Gill
* Date: 1/5/01
* Version: 1.20
*
* Copyright 2000-2004 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.
*
*/
/*
* This is some test code to test the CIECAM97s3 functionality.
*/
#include <stdio.h>
#include <math.h>
#include "xcam.h"
#include "cam97s3.h"
#define DIAG /* Print internal value diagnostics for each conversion */
#define SPOTTEST /* Test known spot colors */
#undef INVTEST /* Lab cube to XYZ to Jab to XYZ */
#undef INVTEST2 /* Jab cube to XYZ to Jab */
#define TRES 33
#define USE_HK 0 /* Use Helmholtz-Kohlraush */
#define NOCAMCLIP 1 /* Don't clip before XYZ2Jab */
#ifndef _isnan
#define _isnan(x) ((x) != (x))
#define _finite(x) ((x) == (x))
#endif
static void
Lab2XYZ(double *out, double *in) {
double L = in[0], a = in[1], b = in[2];
double x,y,z,fx,fy,fz;
if (L > 8.0) {
fy = (L + 16.0)/116.0;
y = pow(fy,3.0);
} else {
y = L/903.2963058;
fy = 7.787036979 * y + 16.0/116.0;
}
fx = a/500.0 + fy;
if (fx > 24.0/116.0)
x = pow(fx,3.0);
else
x = (fx - 16.0/116.0)/7.787036979;
fz = fy - b/200.0;
if (fz > 24.0/116.0)
z = pow(fz,3.0);
else
z = (fz - 16.0/116.0)/7.787036979;
out[0] = x * 0.9642;
out[1] = y * 1.0000;
out[2] = z * 0.8249;
}
/* CIE XYZ to perceptual Lab */
static void
XYZ2Lab(double *out, double *in) {
double X = in[0], Y = in[1], Z = in[2];
double x,y,z,fx,fy,fz;
x = X/0.9642;
y = Y/1.0000;
z = Z/0.8249;
if (x > 0.008856451586)
fx = pow(x,1.0/3.0);
else
fx = 7.787036979 * x + 16.0/116.0;
if (y > 0.008856451586)
fy = pow(y,1.0/3.0);
else
fy = 7.787036979 * y + 16.0/116.0;
if (z > 0.008856451586)
fz = pow(z,1.0/3.0);
else
fz = 7.787036979 * z + 16.0/116.0;
out[0] = 116.0 * fy - 16.0;
out[1] = 500.0 * (fx - fy);
out[2] = 200.0 * (fy - fz);
}
/* Return maximum difference */
double maxdiff(double in1[3], double in2[3]) {
int i;
double tt, rv = 0.0;
/* Deal with the possibility that we have nan's */
for (i = 0; i < 3; i++) {
tt = fabs(in1[i] - in2[i]);
if (_isnan(tt))
return tt;
if (tt > rv)
rv = tt;
}
return rv;
}
/* Return absolute difference */
double absdiff(double in1[3], double in2[3]) {
double tt, rv = 0.0;
tt = in1[0] - in2[0];
rv += tt * tt;
tt = in1[1] - in2[1];
rv += tt * tt;
tt = in1[2] - in2[2];
rv += tt * tt;
return sqrt(rv);
}
/* Return maximum Lab difference of XYZ */
double maxxyzdiff(double i1[3], double i2[3]) {
int i;
double tt, rv = 0.0;
double in1[3], in2[3];
XYZ2Lab(in1, i1);
XYZ2Lab(in2, i2);
/* Deal with the possibility that we have nan's */
for (i = 0; i < 3; i++) {
tt = fabs(in1[i] - in2[i]);
if (_isnan(tt))
return tt;
if (tt > rv)
rv = tt;
}
return rv;
}
int
main(void) {
int ok = 1;
double white[6][3] = {
{ 0.9505, 1.000, 1.0888 },
{ 0.9505, 1.000, 1.0888 },
{ 1.0985, 1.000, 0.3558 },
{ 1.0985, 1.000, 0.3558 },
{ 0.9505, 1.000, 1.0888 },
{ 0.9642, 1.000, 0.8249 } /* D50 for inversion tests */
};
double La[6] = { 318.31, 31.83, 318.31, 31.83, 318.31, 150.0 };
double sample[5][3] = {
{ 0.1901, 0.2000, 0.2178 },
{ 0.5706, 0.4306, 0.3196 },
{ 0.0353, 0.0656, 0.0214 },
{ 0.1901, 0.2000, 0.2178 },
{ 0.9505, 1.000, 1.0888 } /* Check white */
};
#ifdef CIECAM97S3_HK
#ifdef CIECAM97S3_SPLINE_E
double correct[5][4] = { /* Hue range is last two */
{ 41.14, 0.06, 225.3, 251.9 },
{ 69.04, 71.04, 19.4, 19.4 },
{ 35.09, 87.15, 175.3, 175.3 },
{ 55.64, 82.43, 252.5, 252.5 },
{ 100.00000, 0.0, 0.0, 360.0 }
};
#else
double correct[5][4] = { /* Hue range is last two */
{ 41.14, 0.06, 225.3, 251.9 },
{ 69.056048, 71.20763, 19.4, 19.4 },
{ 35.365009, 88.65238, 175.3, 175.3 },
{ 55.266184, 80.55128, 252.5, 252.5 },
{ 100.00000, 0.0, 0.0, 360.0 }
};
#endif
#else
double correct[5][4] = { /* Hue range is last two */
{ 41.13, 0.05, 225.3, 251.9 },
{ 64.14, 71.22, 19.4, 19.4 },
{ 19.18, 88.64, 175.3, 175.3 },
{ 39.11, 80.55, 252.5, 252.5 },
{ 100.0, 0.00, 0.0, 360.0 } /* Check white */
};
#endif
double Jab[3];
double res[3];
cam97s3 *cam;
int c;
cam = new_cam97s3();
#ifdef SPOTTEST
for (c = 0; c < 5; c++) {
#ifdef DIAG
printf("Case %d:\n",c);
#endif /* DIAG */
cam->set_view(
cam,
vc_average, /* Enumerated Viewing Condition */
white[c], /* Reference/Adapted White XYZ (Y range 0.0 .. 1.0) */
La[c], /* Adapting/Surround Luminance cd/m^2 */
0.20, /* Relative Luminance of Background to reference white */
0.0, /* Luminance of white in image - not used */
0.00, /* Flare as a fraction of the reference white (Y range 0.0 .. 1.0) */
white[c], /* The Flare color coordinates (typically the Ambient color) */
USE_HK
);
#ifdef DIAG
printf("\n");
#endif /* DIAG */
{
double JCh[3], target[3];
cam->XYZ_to_cam(cam, Jab, sample[c]);
/* Convert to JCh for checking */
JCh[0] = Jab[0];
/* Compute hue angle */
JCh[2] = (180.0/3.14159265359) * atan2(Jab[2], Jab[1]);
JCh[2] = (JCh[2] < 0.0) ? JCh[2] + 360.0 : JCh[2];
/* Compute chroma value */
JCh[1] = sqrt(Jab[1] * Jab[1] + Jab[2] * Jab[2]);
target[0] = correct[c][0];
target[1] = correct[c][1];
if (JCh[2] >= correct[c][2] && JCh[2] <= correct[c][3]) {
target[2] = JCh[2];
} else {
if (fabs(JCh[2] - correct[c][2]) < fabs(JCh[2] - correct[c][3]))
target[2] = correct[c][2];
else
target[2] = correct[c][3];
}
cam->cam_to_XYZ(cam, res, Jab);
if (maxdiff(JCh, target) > 0.05) {
printf("Spottest: Excesive error in conversion to CAM %f\n",maxdiff(JCh, target));
ok = 0;
}
if (maxdiff(sample[c], res) > 1e-5) {
printf("Spottest: Excessive error in inversion %f\n",maxdiff(sample[c], res));
ok = 0;
}
#ifdef DIAG
printf("Jab is %f %f %f, Jch is %f %f %f\n",
Jab[0], Jab[1], Jab[2],
JCh[0], JCh[1], JCh[2]);
printf("Error to expected value = %f\n",maxdiff(JCh, target));
printf("XYZ is %f %f %f\n",res[0], res[1], res[2]);
printf("Inversion error = %f\n",maxdiff(sample[c], res));
#endif /* DIAG */
}
}
#endif /* SPOTTEST */
#ifdef INVTEST
for (c = 5; c < 6; c++) {
/* Get the range of Jab values */
double min[3] = { 1e6, 1e6, 1e6 };
double max[3] = { -1e6, -1e6, -1e6 };
cam->set_view(
cam,
vc_average, /* Enumerated Viewing Condition */
white[c], /* Reference/Adapted White XYZ (Y range 0.0 .. 1.0) = D50 */
34.0, /* Adapting/Surround Luminance cd/m^2 */
0.20, /* Relative Luminance of Background to reference white */
0.0, /* Luminance of white in image - not used */
0.01, /* Flare as a fraction of the reference white (Y range 0.0 .. 1.0) */
white[c], /* The Flare color coordinates (typically the Ambient color) */
USE_HK
);
{
int co0, co1, co2; /* (using co[3] triggers compiler bug) */
double merr = 0.0;
double xyz[3], Lab[3], Jab[3], checkxyz[3];
#ifdef NEVER
/* Test case */
Lab[0] = 0.0;
Lab[1] = -180.0;
Lab[2] = -180.0;
Lab2XYZ(xyz, Lab);
cam->XYZ_to_cam(cam, Jab, xyz);
cam->cam_to_XYZ(cam, checkxyz, Jab);
#else /* !NEVER */
/* itterate through Lab space */
for (co0 = 0; co0 < TRES; co0++) {
Lab[0] = co0/(TRES-1.0);
Lab[0] = Lab[0] * 100.0;
for (co1 = 0; co1 < TRES; co1++) {
Lab[1] = co1/(TRES-1.0);
Lab[1] = (Lab[1] - 0.5) * 256.0;
for (co2 = 0; co2 < TRES; co2++) {
double mxd;
int i;
Lab[2] = co2/(TRES-1.0);
Lab[2] = (Lab[2] - 0.5) * 256.0;
Lab2XYZ(xyz, Lab);
cam->XYZ_to_cam(cam, Jab, xyz);
for (i = 0; i < 3; i++) {
if (Jab[i] < min[i])
min[i] = Jab[i];
if (Jab[i] > max[i])
max[i] = Jab[i];
}
cam->cam_to_XYZ(cam, checkxyz, Jab);
/* Check the result */
mxd = maxxyzdiff(checkxyz, xyz);
if (_finite(merr) && (_isnan(mxd) || mxd > merr))
merr = mxd;
#ifdef DIAG
if (_isnan(mxd) || mxd > 0.1) {
printf("\n");
printf("Lab = %f %f %f\n",Lab[0], Lab[1], Lab[2]);
printf("%f %f %f -> %f %f %f -> %f %f %f [%f]\n",
xyz[0],xyz[1],xyz[2],Jab[0],Jab[1],Jab[2],
checkxyz[0],checkxyz[1],checkxyz[2],
maxxyzdiff(checkxyz, xyz));
}
#endif /* DIAG */
}
}
}
if (_isnan(merr) || merr > 0.1) {
printf("Excessive error in inversion check %f\n",merr);
ok = 0;
}
#ifdef DIAG
printf("Inversion check complete, peak error = %f\n",merr);
#endif /* !NEVER */
#endif /* DIAG */
printf("\n");
printf("Range of Jab values was:\n");
printf("J: %f -> %f\n", min[0], max[0]);
printf("a: %f -> %f\n", min[1], max[1]);
printf("b: %f -> %f\n", min[2], max[2]);
}
}
#endif /* INVTEST */
#ifdef INVTEST2
for (c = 5; c < 6; c++) {
cam->set_view(
cam,
vc_average, /* Enumerated Viewing Condition */
white[c], /* Reference/Adapted White XYZ (Y range 0.0 .. 1.0) = D50 */
34.0, /* Adapting/Surround Luminance cd/m^2 */
0.20, /* Relative Luminance of Background to reference white */
0.0, /* Luminance of white in image - not used */
0.01, /* Flare as a fraction of the reference white (Y range 0.0 .. 1.0) */
white[c], /* The Flare color coordinates (typically the Ambient color) */
USE_HK
);
{
int co0, co1, co2; /* (using co[3] triggers compiler bug) */
double merr = 0.0;
double xyz[3], Jab[3], checkJab[3];
#ifdef NEVER
/* Test case */
#ifdef NEVER
Jab[0] = 0.0;
Jab[1] = -180.0;
Jab[2] = -180.0;
cam->cam_to_XYZ(cam, xyz, Jab);
cam->XYZ_to_cam(cam, checkJab, xyz);
#else
xyz[0] = 555.365115;
xyz[1] = -518.091908;
xyz[2] = -1591.731701;
cam->XYZ_to_cam(cam, Jab, xyz);
cam->cam_to_XYZ(cam, xyz, Jab);
#endif
#else /* !NEVER */
/* itterate through Jab space */
for (co0 = 0; co0 < TRES; co0++) {
Jab[0] = co0/(TRES-1.0);
Jab[0] = 0.0 + Jab[0] * 100.0;
for (co1 = 0; co1 < TRES; co1++) {
Jab[1] = co1/(TRES-1.0);
Jab[1] = (Jab[1] - 0.5) * 256.0;
for (co2 = 0; co2 < TRES; co2++) {
double mxd;
Jab[2] = co2/(TRES-1.0);
Jab[2] = (Jab[2] - 0.5) * 256.0;
cam->cam_to_XYZ(cam, xyz, Jab);
cam->XYZ_to_cam(cam, checkJab, xyz);
/* Check the result */
mxd = maxdiff(checkJab, Jab);
if (_finite(merr) && (_isnan(mxd) || mxd > merr))
merr = mxd;
#ifdef DIAG
if (_isnan(mxd) || mxd > 0.1) {
printf("\n");
printf("Jab = %f %f %f\n",Jab[0], Jab[1], Jab[2]);
printf("%f %f %f -> %f %f %f -> %f %f %f [%f]\n",
Jab[0],Jab[1],Jab[2], xyz[0],xyz[1],xyz[2],
checkJab[0],checkJab[1],checkJab[2],
maxdiff(checkJab, Jab));
}
#endif /* DIAG */
}
}
}
if (_isnan(merr) || merr > 1.0) {
printf("Excessive error in inversion check 2 %f\n",merr);
ok = 0;
}
#ifdef DIAG
printf("Inversion check 2 complete, peak error = %f\n",merr);
#endif /* DIAG */
#endif /* !NEVER */
}
}
#endif /* INVTEST2 */
printf("\n");
if (ok == 0) {
printf("Cam testing FAILED\n");
} else {
printf("Cam testing OK\n");
}
return 0;
}

828
Argyll_V3.5.0/xicc/ccmx.c Normal file
View File

@@ -0,0 +1,828 @@
/*
* Argyll Color Management System
* Colorimeter Correction Matrix
*
*/
/*
* Author: Graeme W. Gill
* Date: 19/8/2010
*
* Copyright 2010 Graeme W. Gill
* All rights reserved.
*
* This material is licenced under the GNU GENERAL PUBLIC LICENSE Version 2 or later :-
* see the License2.txt file for licencing details.
*
* NOTE though that if SALONEINSTLIB is not defined, that this file depends
* on other libraries that are licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3.
*/
/*
* TTBD:
*/
#undef DEBUG
#define verbo stdout
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <sys/types.h>
#include <time.h>
#ifndef SALONEINSTLIB
#include "numlib.h"
#include "icc.h"
#else
#include "numsup.h"
#include "sa_conv.h"
#endif
#include "cgats.h"
#include "disptechs.h"
#include "ccmx.h"
#ifdef NT /* You'd think there might be some standards.... */
# ifndef __BORLANDC__
# define stricmp _stricmp
# endif
#else
# define stricmp strcasecmp
#endif
/* Forward declarations */
/* Utilities */
/* Method implimentations */
/* Write out the ccmx to a CGATS format .ccmx file */
/* Return nz on error */
static int create_ccmx_cgats(
ccmx *p, /* This */
cgats **pocg /* return CGATS structure */
) {
int i, j, n;
time_t clk = time(0);
struct tm *tsp = localtime(&clk);
char *atm = asctime(tsp); /* Ascii time */
cgats *ocg; /* CGATS structure */
char buf[100];
atm[strlen(atm)-1] = '\000'; /* Remove \n from end */
/* Setup output cgats file */
ocg = new_cgats(); /* Create a CGATS structure */
ocg->add_other(ocg, "CCMX"); /* our special type is Colorimeter Correction Matrix */
ocg->add_table(ocg, tt_other, 0); /* Start the first table */
if (p->desc != NULL)
ocg->add_kword(ocg, 0, "DESCRIPTOR", p->desc,NULL);
ocg->add_kword(ocg, 0, "INSTRUMENT",p->inst, NULL);
if (p->disp != NULL)
ocg->add_kword(ocg, 0, "DISPLAY",p->disp, NULL);
ocg->add_kword(ocg, 0, "TECHNOLOGY", disptech_get_id(p->dtech)->strid,NULL);
if (p->cc_cbid != 0) {
sprintf(buf, "%d", p->cc_cbid);
ocg->add_kword(ocg, 0, "DISPLAY_TYPE_BASE_ID", buf, NULL);
}
if (p->refrmode >= 0)
ocg->add_kword(ocg, 0, "DISPLAY_TYPE_REFRESH", p->refrmode ? "YES" : "NO", NULL);
if (p->sel != NULL)
ocg->add_kword(ocg, 0, "UI_SELECTORS", p->sel, NULL);
if (p->ref != NULL)
ocg->add_kword(ocg, 0, "REFERENCE",p->ref, NULL);
if (p->oem != 0)
ocg->add_kword(ocg, 0, "OEM","YES", NULL);
ocg->add_kword(ocg, 0, "ORIGINATOR", "Argyll ccmx", NULL);
ocg->add_kword(ocg, 0, "CREATED",atm, NULL);
ocg->add_kword(ocg, 0, "COLOR_REP", "XYZ", NULL);
/* Add fields for the matrix */
ocg->add_field(ocg, 0, "XYZ_X", r_t);
ocg->add_field(ocg, 0, "XYZ_Y", r_t);
ocg->add_field(ocg, 0, "XYZ_Z", r_t);
/* Write out the matrix values */
for (i = 0; i < 3; i++) {
ocg->add_set(ocg, 0, p->matrix[i][0], p->matrix[i][1], p->matrix[i][2]);
}
if (pocg != NULL)
*pocg = ocg;
return 0;
}
/* Write out the ccmx to a CGATS format .ccmx file */
/* Return nz on error */
static int write_ccmx(
ccmx *p, /* This */
char *outname /* Filename to write to */
) {
int rv;
cgats *ocg; /* CGATS structure */
/* Create CGATS elements */
if ((rv = create_ccmx_cgats(p, &ocg)) != 0) {
return rv;
}
/* Write it to file */
if (ocg->write_name(ocg, outname)) {
strcpy(p->e.m, ocg->e.m);
ocg->del(ocg); /* Clean up */
return 1;
}
ocg->del(ocg); /* Clean up */
return 0;
}
/* write to a CGATS .ccmx file to a memory buffer. */
/* return nz on error, with message in err[] */
static int buf_write_ccmx(
ccmx *p,
unsigned char **buf, /* Return allocated buffer */
size_t *len /* Return length */
) {
int rv;
cgats *ocg; /* CGATS structure */
cgatsFile *fp;
/* Create CGATS elements */
if ((rv = create_ccmx_cgats(p, &ocg)) != 0) {
return rv;
}
if ((fp = new_cgatsFileMem(NULL, 0)) == NULL) {
strcpy(p->e.m, "new_cgatsFileMem failed");
return 2;
}
/* Write it to file */
if (ocg->write(ocg, fp)) {
strcpy(p->e.m, ocg->e.m);
ocg->del(ocg); /* Clean up */
fp->del(fp);
return 1;
}
/* Get the buffer the ccmx has been written to */
if (fp->get_buf(fp, buf, (size_t *)len)) {
strcpy(p->e.m, "cgatsFileMem get_buf failed");
return 2;
}
ocg->del(ocg); /* Clean up */
fp->del(fp);
return 0;
}
/* Read in the ccmx CGATS .ccmx file */
/* Return nz on error */
static int read_ccmx_cgats(
ccmx *p, /* This */
cgats *icg /* input cgats structure */
) {
int i, j, n, ix;
int ti; /* Temporary CGATs index */
int spi[3]; /* CGATS indexes for each band */
char *xyzfname[3] = { "XYZ_X", "XYZ_Y", "XYZ_Z" };
if (icg->ntables == 0 || icg->t[0].tt != tt_other || icg->t[0].oi != 0) {
sprintf(p->e.m, "read_ccmx: Input file isn't a CCMX format file");
return 1;
}
if (icg->ntables != 1) {
sprintf(p->e.m, "Input file doesn't contain exactly one table");
return 1;
}
if ((ti = icg->find_kword(icg, 0, "COLOR_REP")) < 0) {
sprintf(p->e.m, "read_ccmx: Input file doesn't contain keyword COLOR_REP");
return 1;
}
if (strcmp(icg->t[0].kdata[ti],"XYZ") != 0) {
sprintf(p->e.m, "read_ccmx: Input file doesn't have COLOR_REP of XYZ");
return 1;
}
if ((ti = icg->find_kword(icg, 0, "DESCRIPTOR")) >= 0) {
if ((p->desc = strdup(icg->t[0].kdata[ti])) == NULL) {
sprintf(p->e.m, "read_ccmx: malloc failed");
return 2;
}
}
if ((ti = icg->find_kword(icg, 0, "INSTRUMENT")) < 0) {
sprintf(p->e.m, "read_ccmx: Input file doesn't contain keyword INSTRUMENT");
return 1;
}
if ((p->inst = strdup(icg->t[0].kdata[ti])) == NULL) {
sprintf(p->e.m, "read_ccmx: malloc failed");
return 2;
}
if ((ti = icg->find_kword(icg, 0, "DISPLAY")) >= 0) {
if ((p->disp = strdup(icg->t[0].kdata[ti])) == NULL) {
sprintf(p->e.m, "read_ccmx: malloc failed");
return 2;
}
}
if ((ti = icg->find_kword(icg, 0, "TECHNOLOGY")) >= 0) {
if ((p->tech = strdup(icg->t[0].kdata[ti])) == NULL) {
sprintf(p->e.m, "read_ccmx: malloc failed");
return 2;
}
/* Get disptech enum from standard TECHNOLOGY string */
p->dtech = disptech_get_strid(p->tech)->dtech;
}
if (p->disp == NULL && p->tech == NULL) {
sprintf(p->e.m, "read_ccmx: Input file doesn't contain keyword DISPLAY or TECHNOLOGY");
return 1;
}
if ((ti = icg->find_kword(icg, 0, "DISPLAY_TYPE_REFRESH")) >= 0) {
if (stricmp(icg->t[0].kdata[ti], "YES") == 0)
p->refrmode = 1;
else if (stricmp(icg->t[0].kdata[ti], "NO") == 0)
p->refrmode = 0;
} else {
p->refrmode = -1;
}
if ((ti = icg->find_kword(icg, 0, "DISPLAY_TYPE_BASE_ID")) >= 0) {
p->cc_cbid = atoi(icg->t[0].kdata[ti]);
} else {
p->cc_cbid = 0;
}
if ((ti = icg->find_kword(icg, 0, "UI_SELECTORS")) >= 0) {
if ((p->sel = strdup(icg->t[0].kdata[ti])) == NULL) {
sprintf(p->e.m, "read_ccmx: malloc failed");
return 2;
}
}
if ((ti = icg->find_kword(icg, 0, "REFERENCE")) >= 0) {
if ((p->ref = strdup(icg->t[0].kdata[ti])) == NULL) {
sprintf(p->e.m, "read_ccmx: malloc failed");
return 2;
}
}
if ((ti = icg->find_kword(icg, 0, "OEM")) >= 0) {
if (stricmp(icg->t[0].kdata[ti], "YES") == 0)
p->oem = 1;
else if (stricmp(icg->t[0].kdata[ti], "NO") == 0)
p->oem = 0;
} else {
p->oem = 0;
}
/* Locate the fields */
for (i = 0; i < 3; i++) { /* XYZ fields */
if ((spi[i] = icg->find_field(icg, 0, xyzfname[i])) < 0) {
sprintf(p->e.m, "read_ccmx: Input file doesn't contain field %s", xyzfname[i]);
return 1;
}
if (icg->t[0].ftype[spi[i]] != r_t) {
sprintf(p->e.m, "read_ccmx: Input file field %s is wrong type", xyzfname[i]);
return 1;
}
}
if (icg->t[0].nsets != 3) {
sprintf(p->e.m, "read_ccmx: Input file doesn't have exactly 3 sets");
return 1;
}
/* Read the matrix values */
for (ix = 0; ix < icg->t[0].nsets; ix++) {
p->matrix[ix][0] = *((double *)icg->t[0].fdata[ix][spi[0]]);
p->matrix[ix][1] = *((double *)icg->t[0].fdata[ix][spi[1]]);
p->matrix[ix][2] = *((double *)icg->t[0].fdata[ix][spi[2]]);
}
return 0;
}
/* Read in the ccmx CGATS .ccmx file */
/* Return nz on error */
static int read_ccmx(
ccmx *p, /* This */
char *inname /* Filename to read from */
) {
int rv;
cgats *icg; /* input cgats structure */
/* Open and look at the .ccmx */
if ((icg = new_cgats()) == NULL) { /* Create a CGATS structure */
sprintf(p->e.m, "read_ccmx: new_cgats() failed");
return 2;
}
icg->add_other(icg, "CCMX"); /* our special type is Model Printer Profile */
if (icg->read_name(icg, inname)) {
strcpy(p->e.m, icg->e.m);
icg->del(icg);
return 1;
}
if ((rv = read_ccmx_cgats(p, icg)) != 0) {
icg->del(icg);
return rv;
}
icg->del(icg); /* Clean up */
return 0;
}
/* Read in the ccmx CGATS .ccmx file from a memory buffer */
/* Return nz on error */
static int buf_read_ccmx(
ccmx *p, /* This */
unsigned char *buf,
size_t len
) {
int rv;
cgatsFile *fp;
cgats *icg; /* input cgats structure */
if ((fp = new_cgatsFileMem(buf, len)) == NULL) {
strcpy(p->e.m, "new_cgatsFileMem failed");
return 2;
}
/* Open and look at the .ccmx file */
if ((icg = new_cgats()) == NULL) { /* Create a CGATS structure */
sprintf(p->e.m, "read_ccmx: new_cgats() failed");
fp->del(fp);
return 2;
}
icg->add_other(icg, "CCMX"); /* our special type is Model Printer Profile */
if (icg->read(icg, fp)) {
strcpy(p->e.m, icg->e.m);
icg->del(icg);
fp->del(fp);
return 1;
}
fp->del(fp);
if ((rv = read_ccmx_cgats(p, icg)) != 0) {
icg->del(icg); /* Clean up */
return rv;
}
icg->del(icg); /* Clean up */
return 0;
}
/* Lookup an XYZ or Lab color */
static void xform(
ccmx *p, /* This */
double *out, /* Output XYZ */
double *in /* Input XYZ */
) {
icmMulBy3x3(out, p->matrix, in);
}
/* Set the contents of the ccmx. return nz on error. */
static int set_ccmx(ccmx *p,
char *desc, /* General description (optional) */
char *inst, /* Instrument description to copy from */
char *disp, /* Display make and model (optional) */
disptech dtech, /* Display technology enum */
int refrmode, /* Display refresh mode, -1 = unknown, 0 = n, 1 = yes */
int cbid, /* Display type calibration base ID, 0 = unknown */
char *sel, /* UI selector characters - NULL for none */
char *refd, /* Reference spectrometer description (optional) */
int oem, /* NZ if OEM source */
double mtx[3][3] /* Transform matrix to copy from */
) {
if ((p->desc = desc) != NULL && (p->desc = strdup(desc)) == NULL) {
sprintf(p->e.m, "set_ccmx: malloc failed");
return 2;
}
if ((p->inst = inst) != NULL && (p->inst = strdup(inst)) == NULL) {
sprintf(p->e.m, "set_ccmx: malloc failed");
return 2;
}
if ((p->disp = disp) != NULL && (p->disp = strdup(disp)) == NULL) {
sprintf(p->e.m, "set_ccmx: malloc failed");
return 2;
}
p->dtech = dtech;
p->refrmode = refrmode;
p->cc_cbid = cbid;
if (sel != NULL) {
if ((p->sel = strdup(sel)) == NULL) {
sprintf(p->e.m, "set_ccmx: malloc sel failed");
return 2;
}
}
if ((p->ref = refd) != NULL && (p->ref = strdup(refd)) == NULL) {
sprintf(p->e.m, "set_ccmx: malloc failed");
return 2;
}
p->oem = oem;
icmCpy3x3(p->matrix, mtx);
return 0;
}
#ifndef SALONEINSTLIB
/* ------------------------------------------- */
/* Modified version that de-weights Luminance errors by 5: */
/* Return the CIE94 Delta E color difference measure, squared */
static double wCIE94sq(double Lab0[3], double Lab1[3]) {
double desq, dhsq;
double dlsq, dcsq;
double c12;
{
double dl, da, db;
dl = Lab0[0] - Lab1[0];
dlsq = dl * dl; /* dl squared */
da = Lab0[1] - Lab1[1];
db = Lab0[2] - Lab1[2];
/* Compute normal Lab delta E squared */
desq = dlsq + da * da + db * db;
}
{
double c1, c2, dc;
/* Compute chromanance for the two colors */
c1 = sqrt(Lab0[1] * Lab0[1] + Lab0[2] * Lab0[2]);
c2 = sqrt(Lab1[1] * Lab1[1] + Lab1[2] * Lab1[2]);
c12 = sqrt(c1 * c2); /* Symetric chromanance */
/* delta chromanance squared */
dc = c2 - c1;
dcsq = dc * dc;
}
/* Compute delta hue squared */
if ((dhsq = desq - dlsq - dcsq) < 0.0)
dhsq = 0.0;
{
double sc, sh;
/* Weighting factors for delta chromanance & delta hue */
sc = 1.0 + 0.048 * c12;
sh = 1.0 + 0.014 * c12;
return 0.2 * 0.2 * dlsq + dcsq/(sc * sc) + dhsq/(sh * sh);
}
}
/* ------------------------------------------- */
#undef REGULARIZE /* [und] Test how strong the fit is */
/* Context for optimisation callback */
typedef struct {
int npat;
double (*refs)[3]; /* Array of XYZ values from spectrometer */
double (*cols)[3]; /* Array of XYZ values from colorimeter */
int wix; /* White index, -1 if none. */
icmXYZNumber wh; /* White reference */
} cntx;
/* Optimisation function */
/* Compute the sum of delta E's squared for the */
/* tp will be the 9 matrix values */
/* It's not clear if the white weighting is advantagous or not. */
double optf(void *fdata, double *tp) {
cntx *cx = (cntx *)fdata;
int i;
double de;
double m[3][3];
m[0][0] = tp[0];
m[0][1] = tp[1];
m[0][2] = tp[2];
m[1][0] = tp[3];
m[1][1] = tp[4];
m[1][2] = tp[5];
m[2][0] = tp[6];
m[2][1] = tp[7];
m[2][2] = tp[8];
for (de = 0.0, i = 0; i < cx->npat; i++) {
double tlab[3], xyz[3], lab[3];
icmXYZ2Lab(&cx->wh, tlab, cx->refs[i]);
icmMulBy3x3(xyz, m, cx->cols[i]);
icmXYZ2Lab(&cx->wh, lab, xyz);
if (i == cx->wix)
de += cx->npat/4.0 * wCIE94sq(tlab, lab); /* Make white weight = 1/4 all others */
else
de += wCIE94sq(tlab, lab);
//printf("~1 %d: txyz %f %f %f, tlab %f %f %f\n", i,cx->refs[i][0], cx->refs[i][1], cx->refs[i][2], tlab[0], tlab[1], tlab[2]);
//printf("~1 %d: xyz %f %f %f\n", i,cx->cols[i][0], cx->cols[i][1], cx->cols[i][2]);
//printf("~1 %d: mxyz %f %f %f, lab %f %f %f\n", i,xyz[0], xyz[1], xyz[2], lab[0], lab[1], lab[2]);
//printf("~1 %d: de %f\n", i,wCIE94(tlab, lab));
}
de /= cx->npat;
#ifdef REGULARIZE
# pragma message("!!!!!!!!!!!! REGULARIZE is enabled !!!!!!!!!")
/* Regularize against unity matrix */
{
double res = 0.0;
int j;
for (i = 0; i < 3; i++) {
for (j = 0; j < 3; j++) {
double vv = m[i][j];
if (i == j)
vv -= 1.0;
res += vv * vv;
}
}
de += 1e-3 * res;
}
#endif
#ifdef DEBUG
// printf("~1 return values = %f\n",de);
#endif
return de;
}
/* Create a ccmx from measurements. return nz on error. */
static int create_ccmx(ccmx *p,
char *desc, /* General description (optional) */
char *inst, /* Instrument description to copy from */
char *disp, /* Display make and model (optional) */
disptech dtech, /* Display technology enum */
int refrmode, /* Display refresh mode, -1 = unknown, 0 = n, 1 = yes */
int cbid, /* Display type calibration base index, 0 = unknown */
char *sel, /* UI selector characters - NULL for none */
char *refd, /* Reference spectrometer description (optional) */
int oem, /* NZ if OEM source */
int npat, /* Number of samples in following arrays */
double (*refs)[3], /* Array of XYZ values from spectrometer */
double (*cols)[3] /* Array of XYZ values from colorimeter */
) {
int i, mxix;
double maxy = -1e6;
cntx cx;
double cp[9], sa[9];
if (npat < 3) {
sprintf(p->e.m, "create_ccmx: need at least 3 samples");
return 1;
}
if ((p->desc = desc) != NULL && (p->desc = strdup(desc)) == NULL) {
sprintf(p->e.m, "create_ccmx: malloc failed");
return 2;
}
if ((p->inst = inst) != NULL && (p->inst = strdup(inst)) == NULL) {
sprintf(p->e.m, "create_ccmx: malloc failed");
return 2;
}
if ((p->disp = disp) != NULL && (p->disp = strdup(disp)) == NULL) {
sprintf(p->e.m, "create_ccmx: malloc failed");
return 2;
}
p->dtech = dtech;
p->refrmode = refrmode;
p->cc_cbid = cbid;
if (sel != NULL) {
if ((p->sel = strdup(sel)) == NULL) {
sprintf(p->e.m, "create_ccmx: malloc sel failed");
return 2;
}
}
if ((p->ref = refd) != NULL && (p->ref = strdup(refd)) == NULL) {
sprintf(p->e.m, "create_ccmx: malloc failed");
return 2;
}
p->oem = oem;
/* Find the white patch */
cx.npat = npat;
cx.refs = refs;
cx.cols = cols;
for (i = 0; i < npat; i++) {
if (refs[i][1] > maxy) {
maxy = refs[i][1];
cx.wix = i;
}
}
/* L*a*b* reference white */
cx.wh.X = refs[cx.wix][0];
cx.wh.Y = refs[cx.wix][1];
cx.wh.Z = refs[cx.wix][2];
/* Check that the white looks neutralish.. */
{
icmXYZNumber w;
double lab[3];
/* Ideally we would see how far out white patch is from */
/* the illuminant locus... */
/* D65 scaled to wix Y level */
w.XYZ[0] = icmD65_ary3[0] * refs[cx.wix][1]/icmD65_ary3[1];
w.XYZ[1] = refs[cx.wix][1];
w.XYZ[2] = icmD65_ary3[2] * refs[cx.wix][1]/icmD65_ary3[1];
icmXYZ2Lab(&w, lab, refs[cx.wix]);
#ifdef DEBUG
printf("white D65 = a* %f b* %f\n",lab[1],lab[2]);
#endif
/* Hmm. Not looking like a white */
if (fabs(lab[1]) > 10.0 || fabs(lab[2]) > 30.0) {
/* Use D65 as our L*a*b* DE white reference */
cx.wh.X = w.XYZ[0];
cx.wh.Y = w.XYZ[1];
cx.wh.Z = w.XYZ[2];
cx.wix = -1; /* Don't de-weight any patches */
#ifdef DEBUG
printf(" no white patch detected\n");
#endif
}
}
if (npat <= 3) {
cx.wix = -1; /* Don't de-weight any patches */
}
#ifdef DEBUG
printf("white ref. = %f %f %f\n",cx.wh.X, cx.wh.Y, cx.wh.Z);
#endif
/* Starting matrix */
cp[0] = 1.0; cp[1] = 0.0; cp[2] = 0.0;
cp[3] = 0.0; cp[4] = 1.0; cp[5] = 0.0;
cp[6] = 0.0; cp[7] = 0.0; cp[8] = 1.0;
for (i = 0; i < 9; i++)
sa[i] = 0.1;
if (powell(NULL, 9, cp, sa, 1e-6, 2000, optf, &cx, NULL, NULL) < 0.0) {
sprintf(p->e.m, "create_ccmx: powell() failed");
return 1;
}
p->matrix[0][0] = cp[0];
p->matrix[0][1] = cp[1];
p->matrix[0][2] = cp[2];
p->matrix[1][0] = cp[3];
p->matrix[1][1] = cp[4];
p->matrix[1][2] = cp[5];
p->matrix[2][0] = cp[6];
p->matrix[2][1] = cp[7];
p->matrix[2][2] = cp[8];
/* Compute the average and max errors */
p->av_err = p->mx_err = 0.0;
for (i = 0; i < npat; i++) {
double tlab[3], xyz[3], lab[3], de;
icmXYZ2Lab(&cx.wh, tlab, cx.refs[i]);
icmMulBy3x3(xyz, p->matrix, cx.cols[i]);
icmXYZ2Lab(&cx.wh, lab, xyz);
de = icmCIE94(tlab, lab);
p->av_err += de;
if (de > p->mx_err) {
p->mx_err = de;
mxix = i;
}
//printf("~1 %d: de %f, tlab %f %f %f, lab %f %f %f\n",i,de,tlab[0], tlab[1], tlab[2], lab[0], lab[1], lab[2]);
}
p->av_err /= (double)npat;
//printf("~1 max error is index %d\n",mxix);
#ifdef DEBUG
printf("Average error %f, max %f\n",p->av_err,p->mx_err);
printf("Correction matrix is:\n");
printf(" %f %f %f\n", cp[0], cp[1], cp[2]);
printf(" %f %f %f\n", cp[3], cp[4], cp[5]);
printf(" %f %f %f\n", cp[6], cp[7], cp[8]);
#endif
return 0;
}
#else /* SALONEINSTLIB */
/* Create a ccmx from measurements. return nz on error. */
static int create_ccmx(ccmx *p,
char *desc, /* General description (optional) */
char *inst, /* Instrument description to copy from */
char *disp, /* Display make and model (optional) */
disptech dtech, /* Display technology enum */
int refrmode, /* Display refresh mode, -1 = unknown, 0 = n, 1 = yes */
int cbid, /* Display type calibration base index, 0 = unknown */
char *sel, /* UI selector characters - NULL for none */
char *refd, /* Reference spectrometer description (optional) */
int oem, /* NZ if OEM source */
int npat, /* Number of samples in following arrays */
double (*refs)[3], /* Array of XYZ values from spectrometer */
double (*cols)[3] /* Array of XYZ values from colorimeter */
) {
sprintf(p->e.m, "create_ccmx: not implemented in ccmx.c");
return 1;
}
#endif /* SALONEINSTLIB */
/* Delete it */
static void del_ccmx(ccmx *p) {
if (p != NULL) {
if (p->desc != NULL)
free(p->desc);
if (p->inst != NULL)
free(p->inst);
if (p->disp != NULL)
free(p->disp);
if (p->tech != NULL)
free(p->tech);
if (p->sel != NULL)
free(p->sel);
if (p->ref != NULL)
free(p->ref);
free(p);
}
}
/* Allocate a new, uninitialised ccmx */
/* Note thate black and white points aren't allocated */
ccmx *new_ccmx(void) {
ccmx *p;
if ((p = (ccmx *)calloc(1, sizeof(ccmx))) == NULL)
return NULL;
p->refrmode = -1;
p->cc_cbid = 0;
/* Init method pointers */
p->del = del_ccmx;
p->set_ccmx = set_ccmx;
p->create_ccmx = create_ccmx;
p->write_ccmx = write_ccmx;
p->buf_write_ccmx = buf_write_ccmx;
p->read_ccmx = read_ccmx;
p->buf_read_ccmx = buf_read_ccmx;
p->xform = xform;
return p;
}

133
Argyll_V3.5.0/xicc/ccmx.h Normal file
View File

@@ -0,0 +1,133 @@
#ifndef CCMX_H
#define CCMX_H
/*
* Argyll Color Management System
* Colorimeter Correction Matrix support.
*
*/
/*
* Author: Graeme W. Gill
* Date: 19/8/2010
*
* Copyright 2010 Graeme W. Gill
* All rights reserved.
*
* This material is licenced under the GNU GENERAL PUBLIC LICENSE Version 2 or later :-
* see the License2.txt file for licencing details.
*
* NOTE though that if SALONEINSTLIB is not defined, that this file depends
* on other libraries that are licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3.
*
*/
#ifdef __cplusplus
extern "C" {
#endif
/*
* This object provides storage and application of a 3x3 XYZ
* corretion matrix suitable for corrected a particular
* display colorimeter for a particular display.
*/
/* ------------------------------------------------------------------------------ */
struct _ccmx {
/* Public: */
void (*del)(struct _ccmx *p);
/* Set the contents of the ccmx. return nz on error. */
int (*set_ccmx)(struct _ccmx *p, char *desc, char *inst, char *disp, disptech dtech,
int refrmode, int cbid, char *sel, char *refd, int oem, double mtx[3][3]);
/* Create a ccmx from measurements. return nz on error. */
int (*create_ccmx)(struct _ccmx *p, char *desc, char *inst, char *disp, disptech dtech,
int refrmode, int cbid, char *sel, char *refd, int oem,
int nsamples, double (*refs)[3], double (*cols)[3]);
/* write to a CGATS .ccmx file */
int (*write_ccmx)(struct _ccmx *p, char *filename);
/* write a CGATS .ccmx file to a memory buffer. */
/* return nz on error, with message in err[] */
int (*buf_write_ccmx)(struct _ccmx *p, unsigned char **buf, size_t *len);
/* read from a CGATS .ccmx file */
int (*read_ccmx)(struct _ccmx *p, char *filename);
/* read from a CGATS .ccmx file from a memory buffer. */
int (*buf_read_ccmx)(struct _ccmx *p, unsigned char *buf, size_t len);
/* Correct an XYZ value */
void (*xform) (struct _ccmx *p,
double *out, /* Output XYZ */
double *in); /* Input XYZ */
/* Private: */
/* (All char * are owned by ccmx) */
char *desc; /* Desciption (optional) */
char *inst; /* Name of colorimeter instrument */
char *disp; /* Name of display (optional if tech) */
disptech dtech; /* Display Technology enumeration (optional if disp) */
char *tech; /* Technology string (Looked up from dtech enum) */
int cc_cbid; /* Calibration display type base ID required, 0 if not known */
int refrmode; /* Refresh mode, -1 if unknown, 0 of no, 1 if yes */
char *sel; /* Optional UI selector characters. May be NULL */
char *ref; /* Name of spectrometer instrument (optional) */
int oem; /* nz if oem origin */
double matrix[3][3]; /* Transform matrix */
double av_err; /* Average error of fit */
double mx_err; /* Maximum error of fit */
/* Houskeeping */
icmErr e; /* Error code & message */
}; typedef struct _ccmx ccmx;
/* Create a new, uninitialised ccmx */
ccmx *new_ccmx(void);
#ifdef __cplusplus
}
#endif
#endif /* CCMX_H */

653
Argyll_V3.5.0/xicc/ccss.c Normal file
View File

@@ -0,0 +1,653 @@
/*
* Argyll Color Management System
* Colorimeter Correction Matrix
*/
/*
* Author: Graeme W. Gill
* Date: 9/8/2010
*
* Copyright 2010 Graeme W. Gill
* All rights reserved.
*
* This material is licenced under the GNU GENERAL PUBLIC LICENSE Version 2 or later :-
* see the License2.txt file for licencing details.
*/
/*
* TTBD:
*/
#undef DEBUG
#define verbo stdout
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <sys/types.h>
#include <time.h>
#ifndef SALONEINSTLIB
# include "aconfig.h"
# include "numlib.h"
# include "icc.h"
# include "plot.h" /* For debugging */
#else
# include "numsup.h"
# include "sa_conv.h"
#endif
#include "cgats.h"
#include "xspect.h"
#include "disptechs.h"
#include "ccss.h"
#ifdef NT /* You'd think there might be some standards.... */
# ifndef __BORLANDC__
# define stricmp _stricmp
# endif
#else
# define stricmp strcasecmp
#endif
/* Forward declarations */
static void free_ccss(ccss *p);
/* Utilities */
/* Method implimentations */
/* Write out the ccss to a CGATS format object */
/* Return nz on error */
static int create_ccss_cgats(
ccss *p, /* This */
cgats **pocg /* return CGATS structure */
) {
int i, j;
time_t clk = time(0);
struct tm *tsp = localtime(&clk);
char *atm = asctime(tsp); /* Ascii time */
cgats *ocg; /* CGATS structure */
int nsetel = 0;
cgats_set_elem *setel; /* Array of set value elements */
char buf[100];
atm[strlen(atm)-1] = '\000'; /* Remove \n from end */
/* Setup output cgats file */
ocg = new_cgats(); /* Create a CGATS structure */
ocg->add_other(ocg, "CCSS"); /* Type is Colorimeter Calibration Spectral Set */
ocg->add_table(ocg, tt_other, 0); /* Start the first table */
if (p->desc != NULL)
ocg->add_kword(ocg, 0, "DESCRIPTOR", p->desc,NULL);
if (p->orig != NULL)
ocg->add_kword(ocg, 0, "ORIGINATOR", p->orig, NULL);
else
ocg->add_kword(ocg, 0, "ORIGINATOR", "Argyll ccss", NULL);
if (p->crdate != NULL)
ocg->add_kword(ocg, 0, "CREATED",p->crdate, NULL);
else
ocg->add_kword(ocg, 0, "CREATED",atm, NULL);
if (p->disp)
ocg->add_kword(ocg, 0, "DISPLAY",p->disp, NULL);
if ((p->tech = strdup(disptech_get_id(p->dtech)->strid)) == NULL) {
sprintf(p->e.m, "strdup of tech string faile!");
ocg->del(ocg); /* Clean up */
return 2;
}
ocg->add_kword(ocg, 0, "TECHNOLOGY", p->tech, NULL);
if (p->disp == NULL && p->tech == NULL) {
sprintf(p->e.m, "write_ccss: ccss doesn't contain display or techology strings");
ocg->del(ocg);
return 1;
}
if (p->refrmode >= 0)
ocg->add_kword(ocg, 0, "DISPLAY_TYPE_REFRESH", p->refrmode ? "YES" : "NO", NULL);
if (p->sel != NULL)
ocg->add_kword(ocg, 0, "UI_SELECTORS", p->sel, NULL);
if (p->ref != NULL)
ocg->add_kword(ocg, 0, "REFERENCE",p->ref, NULL);
if (p->oem != 0)
ocg->add_kword(ocg, 0, "OEM","YES", NULL);
sprintf(buf,"%d", p->samples[0].spec_n);
ocg->add_kword(ocg, 0, "SPECTRAL_BANDS",buf, NULL);
sprintf(buf,"%f", p->samples[0].spec_wl_short);
ocg->add_kword(ocg, 0, "SPECTRAL_START_NM",buf, NULL);
sprintf(buf,"%f", p->samples[0].spec_wl_long);
ocg->add_kword(ocg, 0, "SPECTRAL_END_NM",buf, NULL);
sprintf(buf,"%f", p->samples[0].norm);
ocg->add_kword(ocg, 0, "SPECTRAL_NORM",buf, NULL);
/* Fields we want */
if (ocg->add_field(ocg, 0, "SAMPLE_ID", nqcs_t) < 0) {
sprintf(p->e.m, "cgats add_field SAMPLE_ID failed with '%s'!",ocg->e.m);
ocg->del(ocg); /* Clean up */
return 2;
}
nsetel += 1; /* For id */
/* Generate fields for spectral values */
for (i = 0; i < p->samples[0].spec_n; i++) {
int nm;
/* Compute nearest integer wavelength */
nm = (int)(p->samples[0].spec_wl_short + ((double)i/(p->samples[0].spec_n-1.0))
* (p->samples[0].spec_wl_long - p->samples[0].spec_wl_short) + 0.5);
sprintf(buf,"SPEC_%03d",nm);
if (ocg->add_field(ocg, 0, buf, r_t) < 0) {
sprintf(p->e.m, "cgats add_field %s failed with '%s'",buf,ocg->e.m);
ocg->del(ocg); /* Clean up */
return 2;
}
}
nsetel += p->samples[0].spec_n; /* Spectral values */
if ((setel = (cgats_set_elem *)malloc(sizeof(cgats_set_elem) * nsetel)) == NULL) {
strcpy(p->e.m, "Malloc failed!");
ocg->del(ocg); /* Clean up */
return 2;
}
/* Write out the patch info to the output CGATS file */
for (i = 0; i < p->no_samp; i++) {
int k = 0;
sprintf(buf,"%d",i+1);
setel[k++].c = buf;
for (j = 0; j < p->samples[i].spec_n; j++)
setel[k++].d = p->samples[i].spec[j];
ocg->add_setarr(ocg, 0, setel);
}
free(setel);
if (pocg != NULL)
*pocg = ocg;
return 0;
}
/* Write out the ccss to a CGATS format .ccss file */
/* Return nz on error */
static int write_ccss(
ccss *p, /* This */
char *outname /* Filename to write to */
) {
int rv;
cgats *ocg; /* CGATS structure */
if (p->no_samp < 3) {
strcpy(p->e.m, "Need at least three spectral samples");
return 1;
}
/* Create CGATS elements */
if ((rv = create_ccss_cgats(p, &ocg)) != 0) {
return rv;
}
/* Write it to file */
if (ocg->write_name(ocg, outname)) {
strcpy(p->e.m, ocg->e.m);
ocg->del(ocg); /* Clean up */
return 1;
}
ocg->del(ocg); /* Clean up */
return 0;
}
/* write to a CGATS .ccss file to a memory buffer. */
/* return nz on error, with message in err[] */
static int buf_write_ccss(
ccss *p,
unsigned char **buf, /* Return allocated buffer */
size_t *len /* Return length */
) {
int rv;
cgats *ocg; /* CGATS structure */
cgatsFile *fp;
if (p->no_samp < 3) {
strcpy(p->e.m, "Need at least three spectral samples");
return 1;
}
/* Create CGATS elements */
if ((rv = create_ccss_cgats(p, &ocg)) != 0) {
return rv;
}
if ((fp = new_cgatsFileMem(NULL, 0)) == NULL) {
strcpy(p->e.m, "new_cgatsFileMem failed");
return 2;
}
/* Write it to file */
if (ocg->write(ocg, fp)) {
strcpy(p->e.m, ocg->e.m);
ocg->del(ocg); /* Clean up */
fp->del(fp);
return 1;
}
/* Get the buffer the ccss has been written to */
if (fp->get_buf(fp, buf, len)) {
strcpy(p->e.m, "cgatsFileMem get_buf failed");
return 2;
}
ocg->del(ocg); /* Clean up */
fp->del(fp);
return 0;
}
/* Read in the ccss CGATS .ccss file from cgats */
/* Return nz on error */
static int read_ccss_cgats(
ccss *p, /* This */
cgats *icg /* input cgats structure */
) {
int i, j;
int ti, ii; /* Temporary CGATs index */
int spi[XSPECT_MAX_BANDS]; /* CGATS indexes for each wavelength */
xspect sp;
if (icg->ntables == 0 || icg->t[0].tt != tt_other || icg->t[0].oi != 0) {
sprintf(p->e.m, "read_ccss: Input file isn't a CCSS format file");
return 1;
}
if (icg->ntables != 1) {
sprintf(p->e.m, "Input file doesn't contain exactly one table");
return 1;
}
free_ccss(p);
if ((ti = icg->find_kword(icg, 0, "DESCRIPTOR")) >= 0) {
if ((p->desc = strdup(icg->t[0].kdata[ti])) == NULL) {
sprintf(p->e.m, "read_ccss: malloc failed");
return 2;
}
}
if ((ti = icg->find_kword(icg, 0, "ORIGINATOR")) >= 0) {
if ((p->orig = strdup(icg->t[0].kdata[ti])) == NULL) {
sprintf(p->e.m, "read_ccss: malloc failed");
return 2;
}
}
if ((ti = icg->find_kword(icg, 0, "CREATED")) >= 0) {
if ((p->crdate = strdup(icg->t[0].kdata[ti])) == NULL) {
sprintf(p->e.m, "read_ccss: malloc failed");
return 2;
}
}
if ((ti = icg->find_kword(icg, 0, "DISPLAY")) >= 0) {
if ((p->disp = strdup(icg->t[0].kdata[ti])) == NULL) {
sprintf(p->e.m, "read_ccss: malloc failed");
return 2;
}
}
if ((ti = icg->find_kword(icg, 0, "TECHNOLOGY")) >= 0) {
if ((p->tech = strdup(icg->t[0].kdata[ti])) == NULL) {
sprintf(p->e.m, "read_ccss: malloc failed");
return 2;
}
/* Get disptech enum from standard TECHNOLOGY string */
p->dtech = disptech_get_strid(p->tech)->dtech;
}
if (p->disp == NULL && p->tech == NULL) {
sprintf(p->e.m, "read_ccss: Input file doesn't contain keyword DISPLAY or TECHNOLOGY");
return 1;
}
p->refrmode = -1;
if ((ti = icg->find_kword(icg, 0, "DISPLAY_TYPE_REFRESH")) >= 0) {
if (stricmp(icg->t[0].kdata[ti], "YES") == 0)
p->refrmode = 1;
else if (stricmp(icg->t[0].kdata[ti], "NO") == 0)
p->refrmode = 0;
}
if ((ti = icg->find_kword(icg, 0, "UI_SELECTORS")) >= 0) {
if ((p->sel = strdup(icg->t[0].kdata[ti])) == NULL) {
sprintf(p->e.m, "read_ccss: malloc failed");
return 2;
}
}
if ((ti = icg->find_kword(icg, 0, "REFERENCE")) >= 0) {
if ((p->ref = strdup(icg->t[0].kdata[ti])) == NULL) {
sprintf(p->e.m, "read_ccss: malloc failed");
return 2;
}
}
if ((ti = icg->find_kword(icg, 0, "OEM")) >= 0) {
if (stricmp(icg->t[0].kdata[ti], "YES") == 0)
p->oem = 1;
else if (stricmp(icg->t[0].kdata[ti], "NO") == 0)
p->oem = 0;
} else {
p->oem = 0;
}
if ((ii = icg->find_kword(icg, 0, "SPECTRAL_BANDS")) < 0) {
sprintf(p->e.m,"Input file doesn't contain keyword SPECTRAL_BANDS");
return 1;
}
sp.spec_n = atoi(icg->t[0].kdata[ii]);
if ((ii = icg->find_kword(icg, 0, "SPECTRAL_START_NM")) < 0) {
sprintf(p->e.m,"Input file doesn't contain keyword SPECTRAL_START_NM");
return 1;
}
sp.spec_wl_short = atof(icg->t[0].kdata[ii]);
if ((ii = icg->find_kword(icg, 0, "SPECTRAL_END_NM")) < 0) {
sprintf(p->e.m,"Input file doesn't contain keyword SPECTRAL_END_NM");
return 1;
}
sp.spec_wl_long = atof(icg->t[0].kdata[ii]);
if ((ii = icg->find_kword(icg, 0, "SPECTRAL_NORM")) < 0) {
sp.norm = 1.0; /* Older versions don't have SPECTRAL_NORM */
} else {
sp.norm = atof(icg->t[0].kdata[ii]);
}
/* Find the fields for spectral values */
for (j = 0; j < sp.spec_n; j++) {
char buf[100];
int nm;
/* Compute nearest integer wavelength */
nm = (int)(sp.spec_wl_short + ((double)j/(sp.spec_n-1.0))
* (sp.spec_wl_long - sp.spec_wl_short) + 0.5);
sprintf(buf,"SPEC_%03d",nm);
if ((spi[j] = icg->find_field(icg, 0, buf)) < 0) {
sprintf(p->e.m,"Input file doesn't contain field %s",buf);
return 1;
}
}
if ((p->no_samp = icg->t[0].nsets) < 3) {
sprintf(p->e.m, "Input file doesn't contain at least three spectral samples");
p->no_samp = 0;
return 1;
}
/* Allocate spectral array */
if ((p->samples = (xspect *)malloc(sizeof(xspect) * p->no_samp)) == NULL) {
strcpy(p->e.m, "Malloc failed!");
p->no_samp = 0;
return 2;
}
/* Fill sample array with the data */
for (i = 0; i < p->no_samp; i++) {
XSPECT_COPY_INFO(&p->samples[i], &sp);
/* Read the spectral values for this patch */
for (j = 0; j < sp.spec_n; j++) {
p->samples[i].spec[j] = *((double *)icg->t[0].fdata[i][spi[j]]);
}
}
return 0;
}
/* Read in the ccss CGATS .ccss file */
/* Return nz on error */
static int read_ccss(
ccss *p, /* This */
char *inname /* Filename to read from */
) {
int rv;
cgats *icg; /* input cgats structure */
/* Open and look at the .ccss file */
if ((icg = new_cgats()) == NULL) { /* Create a CGATS structure */
sprintf(p->e.m, "read_ccss: new_cgats() failed");
return 2;
}
icg->add_other(icg, "CCSS"); /* our special type is Model Printer Profile */
if (icg->read_name(icg, inname)) {
strcpy(p->e.m, icg->e.m);
icg->del(icg);
return 1;
}
if ((rv = read_ccss_cgats(p, icg)) != 0) {
icg->del(icg); /* Clean up */
return rv;
}
icg->del(icg); /* Clean up */
return 0;
}
/* Read in the ccss CGATS .ccss file from a memory buffer */
/* Return nz on error */
static int buf_read_ccss(
ccss *p, /* This */
unsigned char *buf,
size_t len
) {
int rv;
cgatsFile *fp;
cgats *icg; /* input cgats structure */
if ((fp = new_cgatsFileMem(buf, len)) == NULL) {
strcpy(p->e.m, "new_cgatsFileMem failed");
return 2;
}
/* Open and look at the .ccss file */
if ((icg = new_cgats()) == NULL) { /* Create a CGATS structure */
sprintf(p->e.m, "read_ccss: new_cgats() failed");
fp->del(fp);
return 2;
}
icg->add_other(icg, "CCSS"); /* our special type is Model Printer Profile */
if (icg->read(icg, fp)) {
strcpy(p->e.m, icg->e.m);
icg->del(icg);
fp->del(fp);
return 1;
}
fp->del(fp);
if ((rv = read_ccss_cgats(p, icg)) != 0) {
icg->del(icg); /* Clean up */
return rv;
}
icg->del(icg); /* Clean up */
return 0;
}
/* Set the contents of the ccss. return nz on error. */
/* (Copy all the values) */
static int set_ccss(ccss *p,
char *orig, /* Originator (May be NULL) */
char *crdate, /* Creation date in ctime() format (May be NULL) */
char *desc, /* General description (optional) */
char *disp, /* Display make and model (optional) */
disptech dtech, /* Display technology enum */
int refrmode, /* Display refresh mode, -1 = unknown, 0 = n, 1 = yes */
char *sel, /* UI selector characters - NULL for none */
char *refd, /* Reference spectrometer description (optional) */
int oem, /* NZ if OEM source */
xspect *samples, /* Arry of spectral samples. All assumed to be same dim as first */
int no_samp /* Number of spectral samples */
) {
int i;
free_ccss(p);
if (orig != NULL) {
if ((p->orig = strdup(orig)) == NULL) {
sprintf(p->e.m, "set_ccss: malloc orig failed");
return 2;
}
}
if (desc != NULL) {
if ((p->desc = strdup(desc)) == NULL) {
sprintf(p->e.m, "set_ccss: malloc desc failed");
return 2;
}
}
if (crdate != NULL) {
if ((p->crdate = strdup(crdate)) == NULL) {
sprintf(p->e.m, "set_ccss: malloc crdate failed");
return 2;
}
}
if (disp != NULL) {
if ((p->disp = strdup(disp)) == NULL) {
sprintf(p->e.m, "set_ccss: malloc disp failed");
return 2;
}
}
p->dtech = dtech;
p->refrmode = refrmode;
if (sel != NULL) {
if ((p->sel = strdup(sel)) == NULL) {
sprintf(p->e.m, "set_ccss: malloc sel failed");
return 2;
}
}
if (refd != NULL) {
if ((p->ref = strdup(refd)) == NULL) {
sprintf(p->e.m, "set_ccss: malloc ref failed");
return 2;
}
}
p->oem = oem;
if (p->samples != NULL) {
free(p->samples);
p->samples = NULL;
}
if ((p->no_samp = no_samp) < 3) {
strcpy(p->e.m, "Must be at least three spectral samples");
p->no_samp = 0;
return 1;
}
/* Allocate spectral array */
if ((p->samples = (xspect *)malloc(sizeof(xspect) * p->no_samp)) == NULL) {
strcpy(p->e.m, "Malloc failed!");
p->no_samp = 0;
return 2;
}
/* And copy all the values */
for (i = 0; i < p->no_samp; i++) {
p->samples[i] = samples[i];
}
return 0;
}
/* Free the contents */
static void free_ccss(ccss *p) {
if (p != NULL) {
if (p->desc != NULL)
free(p->desc);
p->desc = NULL;
if (p->orig != NULL)
free(p->orig);
p->orig = NULL;
if (p->crdate != NULL)
free(p->crdate);
p->crdate = NULL;
if (p->disp != NULL)
free(p->disp);
p->disp = NULL;
if (p->tech != NULL)
free(p->tech);
p->tech = NULL;
if (p->sel != NULL)
free(p->sel);
p->sel = NULL;
if (p->ref != NULL)
free(p->ref);
p->ref = NULL;
if (p->samples != NULL)
free(p->samples);
p->samples = NULL;
p->no_samp = 0;
}
}
/* Delete it */
static void del_ccss(ccss *p) {
if (p != NULL) {
free_ccss(p);
free(p);
}
}
/* Allocate a new, uninitialised ccss */
/* Note thate black and white points aren't allocated */
ccss *new_ccss(void) {
ccss *p;
if ((p = (ccss *)calloc(1, sizeof(ccss))) == NULL)
return NULL;
/* Init method pointers */
p->del = del_ccss;
p->set_ccss = set_ccss;
p->write_ccss = write_ccss;
p->buf_write_ccss = buf_write_ccss;
p->read_ccss = read_ccss;
p->buf_read_ccss = buf_read_ccss;
return p;
}

131
Argyll_V3.5.0/xicc/ccss.h Normal file
View File

@@ -0,0 +1,131 @@
#ifndef CCSS_H
#define CCSS_H
/*
* Argyll Color Management System
* Colorimeter Calibration Spectral Set support.
*/
/*
* Author: Graeme W. Gill
* Date: 18/8/2011
*
* Copyright 2010 Graeme W. Gill
* All rights reserved.
*
* This material is licenced under the GNU GENERAL PUBLIC LICENSE Version 2 or later :-
* see the License2.txt file for licencing details.
*
* Based on ccmx.h
*/
#ifdef __cplusplus
extern "C" {
#endif
/*
* This object provides storage and application of emissive spectral
* samples that can be used to compute calibration for suitable
* colorimeters (such as the i1d3) tuned for particular types of displays.
*
* (Note that I suggested this idea publically on the ArgyllCMS mailing
* list in Jan 2008:
* <https://www.freelists.org/post/argyllcms/Calibrate-a-HCFR-hardware,9>
* well before X-Rite & DataColor released instruments that used this approach,
* And in more detail in April 2010:
* <https://www.freelists.org/post/argyllcms/Correction-for-wide-gamut-screens-andor-RGBLED,1>)
*/
/* ------------------------------------------------------------------------------ */
struct _ccss {
/* Public: */
void (*del)(struct _ccss *p);
/* Set the contents of the ccss. return nz on error. */
/* (Makes copies of all parameters) */
int (*set_ccss)(struct _ccss *p, char *orig, char *cdate,
char *desc, char *disp, disptech dtech, int refrmode, char *sel,
char *ref, int oem, xspect *samples, int no_samp);
/* write to a CGATS .ccss file */
/* return nz on error, with message in err[] */
int (*write_ccss)(struct _ccss *p, char *filename);
/* write a CGATS .ccss file to a memory buffer. */
/* return nz on error, with message in err[] */
int (*buf_write_ccss)(struct _ccss *p, unsigned char **buf, size_t *len);
/* read from a CGATS .ccss file */
/* return nz on error, with message in err[] */
int (*read_ccss)(struct _ccss *p, char *filename);
/* read from a CGATS .ccss file from a memory buffer. */
/* return nz on error, with message in err[] */
int (*buf_read_ccss)(struct _ccss *p, unsigned char *buf, size_t len);
/* Private: */
/* (All char * are owned by ccss) */
char *orig; /* Originator. May be NULL */
char *crdate; /* Creation date (in ctime() format). May be NULL */
char *desc; /* General Description (optional) */
char *disp; /* Description of the display (Manfrr and Model No) (optional if tech) */
disptech dtech; /* Display Technology enumeration (optional if disp) */
char *tech; /* Technology string (Looked up from dtech enum or read from file) */
int refrmode; /* Refresh mode, -1 if unknown, 0 of no, 1 if yes */
char *sel; /* Optional UI selector characters. May be NULL */
char *ref; /* Name of reference spectrometer instrument (optional) */
int oem; /* nz if oem origin */
xspect *samples; /* Set of spectral samples */
int no_samp; /* Number of samples */
/* Houskeeping - should switch this to a1log ? */
icmErr e; /* Error code & message */
}; typedef struct _ccss ccss;
/* Create a new, uninitialised ccss */
ccss *new_ccss(void);
#ifdef __cplusplus
}
#endif
#endif /* CCSS_H */

View File

@@ -0,0 +1,320 @@
/*
* International Color Consortium color transform expanded support
*
* Author: Graeme W. Gill
* Date: 2006/5/9
* Version: 1.00
*
* Copyright 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.
*
*/
/*
* This is some test code to test the Daylight and Plankian spectra,
* Correlated and Visual Color Temperatures, and CRI.
*/
#include <stdio.h>
#include <stdarg.h>
#include <math.h>
#include "aconfig.h"
#include "cgats.h"
#include "xspect.h"
#include "numlib.h"
#include "plot.h"
#include "ui.h"
#define PLANKIAN
#define XRES 500
#ifdef PLANKIAN
#define BBTYPE icxIT_Ptemp
#else
#define BBTYPE icxIT_Dtemp
#endif
static int do_spec(char *name, xspect *sp) {
int i;
double xyz[3]; /* Color temperature */
double Yxy[3];
double xx[XRES];
double y1[XRES];
double cct, vct;
double cct_xyz[3], vct_xyz[3];
double cct_lab[3], vct_lab[3];
icmXYZNumber wp;
double de;
printf("\n");
/* Compute normalise XYZ of illuminant */
if (icx_ill_sp2XYZ(xyz, icxOT_CIE_1931_2, NULL, icxIT_custom, 0, sp, 0) != 0)
error ("icx_sp_temp2XYZ returned error");
icmXYZ2Yxy(Yxy, xyz);
printf("Type = %s\n",name);
printf("XYZ = %f %f %f, x,y = %f %f\n", xyz[0], xyz[1], xyz[2], Yxy[1], Yxy[2]);
/* Compute CCT */
if ((cct = icx_XYZ2ill_ct(cct_xyz, BBTYPE, icxOT_CIE_1931_2, NULL, xyz, NULL, 0)) < 0)
error ("Got bad cct\n");
/* Compute VCT */
if ((vct = icx_XYZ2ill_ct(vct_xyz, BBTYPE, icxOT_CIE_1931_2, NULL, xyz, NULL, 1)) < 0)
error ("Got bad vct\n");
#ifdef PLANKIAN
printf("CCT = %f, VCT = %f\n",cct, vct);
#else
printf("CDT = %f, VDT = %f\n",cct, vct);
#endif
{
int invalid = 0;
double RR[14];
double cri;
cri = icx_CIE1995_CRI(&invalid, RR, sp);
printf("CRI = %.1f [ R9 = %.1f ]%s\n",cri,RR[9],invalid ? " (Invalid)" : "");
}
/* Use modern color difference - gives a better visual match */
icmAry2XYZ(wp, vct_xyz);
icmXYZ2Lab(&wp, cct_lab, cct_xyz);
icmXYZ2Lab(&wp, vct_lab, vct_xyz);
de = icmCIE2K(cct_lab, vct_lab);
printf("CIEDE2000 Delta E = %f\n",de);
/* Plot spectrum out */
for (i = 0; i < XRES; i++) {
double ww;
ww = (sp->spec_wl_long - sp->spec_wl_short)
* ((double)i/(XRES-1.0)) + sp->spec_wl_short;
xx[i] = ww;
y1[i] = value_xspect(sp, ww);
}
do_plot(xx,y1,NULL,NULL,i);
return 0;
}
void usage(void) {
fprintf(stderr,"Plot spectrum and calculate CCT and VCT\n");
fprintf(stderr,"Author: Graeme W. Gill\n");
fprintf(stderr,"usage: ccttest [infile.sp]\n");
fprintf(stderr," [infile.sp] spectrum to plot\n");
fprintf(stderr," default is all built in illuminants\n");
exit(1);
}
int
main(
int argc,
char *argv[]
) {
int fa,nfa; /* argument we're looking at */
int k;
int verb = 0;
static char in_name[MAXNAMEL+1] = { '\000' }; /* Spectrum name */
double temp;
xspect sp; /* Spectra */
icxIllumeType ilType;
char buf[200];
error_program = argv[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) < argc) {
if (argv[fa+1][0] != '-') {
nfa = fa + 1;
na = argv[nfa]; /* next is seperate non-flag argument */
}
}
}
/* Verbosity */
if (argv[fa][1] == 'v' || argv[fa][1] == 'V') {
verb = 1;
} else {
usage();
}
}
else
break;
}
if (fa < argc && argv[fa][0] != '-')
strncpy(in_name,argv[fa++],MAXNAMEL); in_name[MAXNAMEL] = '\000';
#ifndef NEVER /* hack test */
{
#define NTESTS 5
int i;
double cct, vct;
double de1, de2;
double xyz[NTESTS][3] = {
{ 92.250000, 97.750000, 89.650000 }, /* Rogers spotread verification result */
{ 94.197915, 97.686362, 80.560411, }, /* Rogers target */
{ 93.51, 97.12, 80.86 }, /* Rogers test ? */
{ 75.31, 78.20, 64.59 }, /* Mac LCD test */
{ 42.98, 44.62, 36.95 } /* Hitachie CRT test */
};
double axyz[3];
double lab[3], alab[3];
for (i = 0; i < NTESTS; i++) {
/* Compute CCT */
if ((cct = icx_XYZ2ill_ct(axyz, icxIT_Ptemp, icxOT_CIE_1931_2, NULL, xyz[i], NULL, 0)) < 0)
error ("Got bad cct\n");
axyz[0] /= axyz[1];
axyz[2] /= axyz[1];
axyz[1] /= axyz[1];
icmXYZ2Lab(&icmD50, alab, axyz);
axyz[0] = xyz[i][0] / xyz[i][1];
axyz[2] = xyz[i][2] / xyz[i][1];
axyz[1] = xyz[i][1] / xyz[i][1];
icmXYZ2Lab(&icmD50, lab, axyz);
de1 = icmCIE2K(lab, alab);
/* Compute VCT */
if ((vct = icx_XYZ2ill_ct(axyz, icxIT_Ptemp, icxOT_CIE_1931_2, NULL, xyz[i], NULL, 1)) < 0)
error ("Got bad vct\n");
axyz[0] /= axyz[1];
axyz[2] /= axyz[1];
axyz[1] /= axyz[1];
icmXYZ2Lab(&icmD50, alab, axyz);
axyz[0] = xyz[i][0] / xyz[i][1];
axyz[2] = xyz[i][2] / xyz[i][1];
axyz[1] = xyz[i][1] / xyz[i][1];
icmXYZ2Lab(&icmD50, lab, axyz);
de2 = icmCIE2K(lab, alab);
printf("XYZ %f %f %f, CCT = %f de %f, VCT = %f de %f\n",xyz[i][0], xyz[i][1], xyz[i][2], cct, de1, vct, de1);
/* Compute CCT */
if ((cct = icx_XYZ2ill_ct(axyz, icxIT_Dtemp, icxOT_CIE_1931_2, NULL, xyz[i], NULL, 0)) < 0)
error ("Got bad cct\n");
axyz[0] /= axyz[1];
axyz[2] /= axyz[1];
axyz[1] /= axyz[1];
icmXYZ2Lab(&icmD50, alab, axyz);
axyz[0] = xyz[i][0] / xyz[i][1];
axyz[2] = xyz[i][2] / xyz[i][1];
axyz[1] = xyz[i][1] / xyz[i][1];
icmXYZ2Lab(&icmD50, lab, axyz);
de1 = icmCIE2K(lab, alab);
/* Compute VCT */
if ((vct = icx_XYZ2ill_ct(axyz, icxIT_Dtemp, icxOT_CIE_1931_2, NULL, xyz[i], NULL, 1)) < 0)
error ("Got bad vct\n");
axyz[0] /= axyz[1];
axyz[2] /= axyz[1];
axyz[1] /= axyz[1];
icmXYZ2Lab(&icmD50, alab, axyz);
axyz[0] = xyz[i][0] / xyz[i][1];
axyz[2] = xyz[i][2] / xyz[i][1];
axyz[1] = xyz[i][1] / xyz[i][1];
icmXYZ2Lab(&icmD50, lab, axyz);
de2 = icmCIE2K(lab, alab);
printf("XYZ %f %f %f, CDT = %f de %f, VDT = %f de %f\n",xyz[i][0], xyz[i][1], xyz[i][2], cct, de1, vct, de2);
}
}
#endif
if (in_name[0] != '\000') {
inst_meas_type mt;
if (read_xspect(&sp, &mt, NULL, in_name) != 0)
error ("Unable to read custom spectrum '%s'",in_name);
if (mt != inst_mrt_none
&& mt != inst_mrt_emission
&& mt != inst_mrt_ambient
&& mt != inst_mrt_emission_flash
&& mt != inst_mrt_ambient_flash)
error("Custom illuminant '%s' is wrong measurement type",in_name);
sprintf(buf, "File '%s'",in_name);
do_spec(buf, &sp);
} else {
/* For each standard illuminant */
for (ilType = icxIT_A; ilType <= icxIT_F10; ilType++) {
char *inm = NULL;
switch (ilType) {
case icxIT_A:
inm = "A"; break;
case icxIT_C:
inm = "C"; break;
case icxIT_D50:
inm = "D50"; break;
case icxIT_D50M2:
inm = "D50M2"; break;
case icxIT_D65:
inm = "D65"; break;
case icxIT_F5:
inm = "F5"; break;
case icxIT_F8:
inm = "F8"; break;
case icxIT_F10:
inm = "F10"; break;
default:
inm = "Unknown"; break;
break;
}
if (standardIlluminant(&sp, ilType, 0) != 0)
error ("standardIlluminant returned error");
do_spec(inm, &sp);
}
/* For each material and illuminant */
for (temp = 2500; temp <= 9000; temp += 500) {
for (k = 0; k < 2; k++) {
ilType = k == 0 ? icxIT_Dtemp : icxIT_Ptemp;
if (standardIlluminant(&sp, ilType, temp) != 0)
error ("standardIlluminant returned error");
sprintf(buf, "%s at %f", k == 0 ? "Daylight" : "Black body", temp);
do_spec(buf, &sp);
}
}
}
return 0;
}

View File

@@ -0,0 +1,277 @@
/*
* Very simple, dumb plot of .ti3 data.
*
* Author: Graeme W. Gill
* Date: 2005/10/12
* Version: 1.0
*
* Copyright 2000 - 2005 Graeme W. Gill
* Please refer to License.txt file for details.
*/
/* TTBD:
*
*/
#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 "xcolorants.h"
#include "sort.h"
#include "plot.h"
#include "ui.h"
void usage(void) {
fprintf(stderr,"Simple 2D plot of CGATS .ti3 data\n");
fprintf(stderr,"Author: Graeme W. Gill\n");
fprintf(stderr,"usage: cgatssplot [-v] infile\n");
fprintf(stderr," -v verbose\n");
fprintf(stderr," -x plot XYZ");
fprintf(stderr," -0 .. -9 Choose channel to plot against (dflt: index)\n");
exit(1);
}
/* Patch value type */
typedef struct {
double d[ICX_MXINKS]; /* Device values */
double v[3]; /* CIE value */
} pval;
int
main(
int argc,
char *argv[]
) {
int fa,nfa; /* argument we're looking at */
int verb = 0;
int chan = -1; /* Chosen channel to plot against, -1 for index */
static char in_name[MAXNAMEL+1];
char *buf, *outc;
int ti;
cgats *cgf = NULL; /* cgats file data */
int isLab = 0; /* cgats output is Lab, else XYZ */
int wantLab = 1; /* cgats output is Lab, else XYZ */
char *xyzfname[3] = { "XYZ_X", "XYZ_Y", "XYZ_Z" };
char *labfname[3] = { "LAB_L", "LAB_A", "LAB_B" };
int npat; /* Number of patches */
inkmask nmask; /* Device inkmask */
int nchan; /* Number of input chanels */
char *bident; /* Base ident */
int chix[ICX_MXINKS]; /* Device chanel indexes */
int pcsix[3]; /* Device chanel indexes */
pval *pat; /* patch values */
int i, j;
error_program = argv[0];
if (argc < 2)
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 */
}
}
}
/* Verbosity */
if (argv[fa][1] == 'v') {
verb = 1;
}
else if (argv[fa][1] == 'x') {
wantLab = 0;
}
else if (argv[fa][1] >= '0' && argv[fa][1] <= '9') {
chan = argv[fa][1] - '0';
}
else if (argv[fa][1] == '?')
usage();
else
usage();
}
else
break;
}
if (fa >= argc || argv[fa][0] == '-') usage();
strncpy(in_name,argv[fa++],MAXNAMEL); in_name[MAXNAMEL] = '\000';
/* Open CIE target values */
cgf = new_cgats(); /* Create a CGATS structure */
cgf->add_other(cgf, "CTI3");/* our special input type is Calibration Target Information 3 */
if (cgf->read_name(cgf, in_name))
error("CGATS file read error %s on file '%s'",cgf->e.m, in_name);
if (cgf->ntables == 0 || cgf->t[0].tt != tt_other || cgf->t[0].oi != 0)
error ("Profile file '%s' isn't a CTI3 format file",in_name);
if (cgf->ntables < 1)
error ("Input file '%s' doesn't contain at least one table",in_name);
if ((ti = cgf->find_kword(cgf, 0, "COLOR_REP")) < 0)
error("Input file doesn't contain keyword COLOR_REPS");
if ((buf = strdup(cgf->t[0].kdata[ti])) == NULL)
error("Malloc failed");
/* Split COLOR_REP into device and PCS space */
if ((outc = strchr(buf, '_')) == NULL)
error("COLOR_REP '%s' invalid", cgf->t[0].kdata[ti]);
*outc++ = '\000';
if (strcmp(outc, "XYZ") == 0) {
isLab = 0;
} else if (strcmp(outc, "LAB") == 0) {
isLab = 1;
} else
error("COLOR_REP '%s' invalid (Neither XYZ nor LAB)", cgf->t[0].kdata[ti]);
if ((nmask = icx_char2inkmask(buf)) == 0) {
error ("File '%s' keyword COLOR_REPS has unknown device value '%s'",in_name,buf);
}
free(buf);
nchan = icx_noofinks(nmask);
bident = icx_inkmask2char(nmask, 0); /* Base ident (No possible 'i') */
/* Find device fields */
for (j = 0; j < nchan; j++) {
int ii, imask;
char fname[100];
imask = icx_index2ink(nmask, j);
sprintf(fname,"%s_%s",nmask == ICX_W || nmask == ICX_K ? "GRAY" : bident,
icx_ink2char(imask));
if ((ii = cgf->find_field(cgf, 0, fname)) < 0)
error ("Input file doesn't contain field %s",fname);
if (cgf->t[0].ftype[ii] != r_t)
error ("Field %s is wrong type",fname);
chix[j] = ii;
}
/* Find PCS fields */
for (j = 0; j < 3; j++) {
int ii;
if ((ii = cgf->find_field(cgf, 0, isLab ? labfname[j] : xyzfname[j])) < 0)
error ("Input file doesn't contain field %s",isLab ? labfname[j] : xyzfname[j]);
if (cgf->t[0].ftype[ii] != r_t)
error ("Field %s is wrong type",isLab ? labfname[j] : xyzfname[j]);
pcsix[j] = ii;
}
npat = cgf->t[0].nsets; /* Number of patches */
if (npat <= 0)
error("No sets of data in file '%s'",in_name);
/* Allocate arrays to hold test patch input and output values */
if ((pat = (pval *)malloc(sizeof(pval) * npat)) == NULL)
error("Malloc failed - pat[]");
/* Grab all the values */
for (i = 0; i < npat; i++) {
pat[i].v[0] = *((double *)cgf->t[0].fdata[i][pcsix[0]]);
pat[i].v[1] = *((double *)cgf->t[0].fdata[i][pcsix[1]]);
pat[i].v[2] = *((double *)cgf->t[0].fdata[i][pcsix[2]]);
if (!isLab) {
pat[i].v[0] /= 100.0; /* Normalise XYZ to range 0.0 - 1.0 */
pat[i].v[1] /= 100.0;
pat[i].v[2] /= 100.0;
}
if (wantLab && !isLab) { /* Convert test patch result XYZ to PCS (D50 Lab) */
icmXYZ2Lab(&icmD50, pat[i].v, pat[i].v);
} else if (!wantLab && isLab) {
icmLab2XYZ(&icmD50, pat[i].v, pat[i].v);
}
if (!wantLab) {
pat[i].v[0] *= 100.0; /* Normalise XYZ to range 0.0 - 100.0 */
pat[i].v[1] *= 100.0;
pat[i].v[2] *= 100.0;
}
for (j = 0; j < nchan; j++) {
pat[i].d[j] = *((double *)cgf->t[0].fdata[i][chix[j]]);
}
}
isLab = wantLab;
#ifdef NEVER
/* Sort by the selected channel */
if (chan >= 0 && chan < nchan) {
#define HEAP_COMPARE(A,B) (A.d[chan] < B.d[chan])
HEAPSORT(pval, pat, npat);
#undef HEAP_COMPARE
}
#endif
/* Create the plot */
{
int i;
double *xx;
double *y0;
double *y1;
double *y2;
if ((xx = (double *)malloc(sizeof(double) * npat)) == NULL)
error("Malloc failed - xx[]");
if ((y0 = (double *)malloc(sizeof(double) * npat)) == NULL)
error("Malloc failed - y0[]");
if ((y1 = (double *)malloc(sizeof(double) * npat)) == NULL)
error("Malloc failed - y1[]");
if ((y2 = (double *)malloc(sizeof(double) * npat)) == NULL)
error("Malloc failed - y2[]");
printf("~1 chan = %d\n",chan);
for (i = 0; i < npat; i++) {
if (chan >= 0 && chan < nchan)
xx[i] = pat[i].d[chan];
else
xx[i] = (double)i;
if (isLab) {
y0[i] = pat[i].v[0];
y1[i] = 50.0 + pat[i].v[1]/2.0;
y2[i] = 50.0 + pat[i].v[2]/2.0;
} else {
y0[i] = pat[i].v[0];
y1[i] = pat[i].v[1];
y2[i] = pat[i].v[2];
}
printf("~1 %d: xx = %f, y = %f %f %f\n",i,xx[i],y0[i],y1[i],y2[i]);
}
do_plot6(xx,y0,y1,NULL,NULL,y2,NULL,npat);
free(y2);
free(y1);
free(y0);
free(xx);
}
free(pat);
cgf->del(cgf);
return 0;
}

138
Argyll_V3.5.0/xicc/cv.c Normal file
View File

@@ -0,0 +1,138 @@
/**********************************************************/
/* Investigate Graphics GEMS transfer curve function parameters */
/**********************************************************/
/* Author: Graeme Gill
* Date: 2003/12/1
*
* Copyright 2003 Graeme W. Gill
*
* 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 <math.h>
#include <numlib.h>
#include "aconfig.h"
#include "plot.h"
#include "ui.h"
void usage(void);
#define XRES 100 /* Plot resolution */
/* Per transfer function */
static double tfunc(
double *v, /* Pointer to first parameter */
int luord, /* Curve order n..MPP_MXTCORD */
double vv /* Source of value */
) {
double g;
int ord;
if (vv < 0.0)
vv = 0.0;
else if (vv > 1.0)
vv = 1.0;
/* Process all the shaper orders from high to low. */
/* [These shapers were inspired by a Graphics Gem idea */
/* (Gems IV, VI.3, "Fast Alternatives to Perlin's Bias and */
/* Gain Functions, pp 401). */
/* They have the nice properties that they are smooth, and */
/* can't be non-monotonic. The control parameter has been */
/* altered to have a range from -oo to +oo rather than 0.0 to 1.0 */
/* so that the search space is less non-linear. ] */
for (ord = luord-1; ord >= 0; ord--) {
int nsec; /* Number of sections */
double sec; /* Section */
g = v[ord]; /* Parameter */
// nsec = 1 << ord; /* Double sections for each order */
nsec = ord + 1; /* Sections for each order */
vv *= (double)nsec;
sec = floor(vv);
if (((int)sec) & 1)
g = -g; /* Alternate action in each section */
vv -= sec;
if (g >= 0.0) {
vv = vv/(g - g * vv + 1.0);
} else {
vv = (vv - g * vv)/(1.0 - g * vv);
}
vv += sec;
vv /= (double)nsec;
}
return vv;
}
#define MAX_PARM 10
int
main(int argc, char *argv[]) {
int fa,nfa; /* argument we're looking at */
int np = 0; /* Current number of input parameters */
double params[MAX_PARM] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
int i;
double x;
double xx[XRES];
double y1[XRES];
error_program = "cv";
/* Process the arguments */
for(fa = 1;fa < argc;fa++) {
nfa = fa; /* skip to nfa if next argument is used */
if (np >= MAX_PARM)
break;
params[np++] = atof(argv[fa]);
}
if (np == 0)
np = 1;
printf("There are %d parameters:\n",np); fflush(stdout);
for (i = 0; i < np; i++) {
printf("Paramter %d = %f\n",i, params[i]); fflush(stdout);
}
/* Display the result */
for (i = 0; i < XRES; i++) {
x = i/(double)(XRES-1);
xx[i] = x;
y1[i] = tfunc(params, np, x);
if (y1[i] < -0.2)
y1[i] = -0.2;
else if (y1[i] > 1.2)
y1[i] = 1.2;
}
do_plot(xx,y1,NULL,NULL,XRES);
return 0;
}
/******************************************************************/
/* Error/debug output routines */
/******************************************************************/
void
usage(void) {
puts("usage: cv param0 [param1] [param2] ... ");
exit(1);
}

405
Argyll_V3.5.0/xicc/cvtest.c Normal file
View File

@@ -0,0 +1,405 @@
/**********************************************************/
/* Investigate GEMS transfer curve function approximation */
/**********************************************************/
/* Standard test + Random testing */
/* Author: Graeme Gill
* Date: 2003/12/1
*
* Copyright 2003 Graeme W. Gill
* Parts derived from rspl/c1.c
*
* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :-
* see the License.txt file for licencing details.
*/
#undef DIAG
#undef TEST_SYM /* Test forcing center to zero (a*, b* constraint) */
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <math.h>
#include "aconfig.h"
#include "numlib.h"
#include "plot.h"
#include "ui.h"
#define MAX_PARM 40 /* Make > SHAPE_ORDS */
#define POWTOL 1e-5
#define MAXITS 10000
/* SHAPE_BASE doesn't seem extremely critical. It is centered in +/- 1 magnitude */
/* 10 x more filters out noise reasonably heaviliy, 10 x less gives noticable */
/* overshoot Range 0.00001 .. 0.001 */
/* SHAPE_HBASE is more critical. */
/* Range 0.00005 .. 0.001 */
//#define SHAPE_BASE 0.00001 /* 0 & 1 harmonic weight */
//#define SHAPE_HBASE 0.0002 /* 2nd and higher additional weight */
//#define SHAPE_ORDS 20
#define SHAPE_BASE 0.00001 /* 0 & 1 harmonic weight */
#define SHAPE_HBASE 0.0001 /* 2nd and higher additional weight */
#define SHAPE_ORDS 20
/* Interface coordinate value */
typedef struct {
double p; /* coordinate position */
double v; /* function values */
} co;
double lin(double x, double xa[], double ya[], int n);
static double tfunc(double *v, int luord, double vv);
void fit(double *params, int np, co *test_points, int pnts);
void usage(void);
#define TRIALS 40 /* Number of random trials */
#define SKIP 0 /* Number of random trials to skip */
#define ABS_MAX_PNTS 100
#define MIN_PNTS 2
#define MAX_PNTS 20
#define MIN_RES 20
#define MAX_RES 500
double xa[ABS_MAX_PNTS];
double ya[ABS_MAX_PNTS];
#define XRES 100
#define TSETS 4
#define PNTS 11
#define GRES 100
int t1p[TSETS] = {
4,
11,
11,
11
};
double t1xa[TSETS][PNTS] = {
{ 0.0, 0.2, 0.8, 1.0 },
{ 0.0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0 },
{ 0.0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0 },
{ 0.0, 0.25, 0.30, 0.35, 0.40, 0.44, 0.48, 0.51, 0.64, 0.75, 1.0 }
};
double t1ya[TSETS][PNTS] = {
{ 0.0, 0.5, 0.6, 1.0 },
{ 0.0, 0.10, 0.22, 0.35, 0.52, 0.65, 0.78, 0.91, 1.0, 0.9, 0.85 },
{ 0.0, 0.0, 0.5, 0.5, 0.5, 0.5, 0.5, 0.8, 1.0, 1.0, 1.0 },
{ 0.0, 0.35, 0.4, 0.41, 0.42, 0.46, 0.5, 0.575, 0.48, 0.75, 1.0 }
};
co test_points[ABS_MAX_PNTS];
double lin(double x, double xa[], double ya[], int n);
int main(void) {
int i, n;
double x;
double xx[XRES];
double y1[XRES];
double y2[XRES];
int np = SHAPE_ORDS; /* Number of harmonics */
double params[MAX_PARM]; /* Harmonic parameters */
error_program = "Curve1";
for (n = 0; n < TRIALS; n++) {
double lrand; /* Amount of level randomness */
int pnts;
if (n < TSETS) /* Standard versions */ {
pnts = t1p[n];
for (i = 0; i < pnts; i++) {
xa[i] = t1xa[n][i];
ya[i] = t1ya[n][i];
}
} else if (n == TSETS) { /* Exponential function aproximation */
double ex = 2.2;
pnts = MAX_PNTS;
printf("Trial %d, no points = %d, exponential %f\n",n,pnts,ex);
/* Create X values */
for (i = 0; i < pnts; i++)
xa[i] = i/(pnts-1.0);
for (i = 0; i < pnts; i++)
ya[i] = pow(xa[i], ex);
} else if (n == (TSETS+1)) { /* Exponential function aproximation */
double ex = 1.0/2.2;
pnts = MAX_PNTS;
printf("Trial %d, no points = %d, exponential %f\n",n,pnts,ex);
/* Create X values */
for (i = 0; i < pnts; i++)
xa[i] = i/(pnts-1.0);
for (i = 0; i < pnts; i++)
ya[i] = pow(xa[i], ex);
} else { /* Random versions */
lrand = d_rand(0.0,0.2); /* Amount of level randomness */
lrand *= lrand;
pnts = i_rand(MIN_PNTS,MAX_PNTS);
printf("Trial %d, no points = %d, level randomness = %f\n",n,pnts,lrand);
/* Create X values */
xa[0] = 0.0;
for (i = 1; i < pnts; i++)
xa[i] = xa[i-1] + d_rand(0.5,1.0);
for (i = 0; i < pnts; i++) /* Divide out */
xa[i] = (xa[i]/xa[pnts-1]);
/* Create y values */
ya[0] = xa[0];
for (i = 1; i < pnts; i++)
ya[i] = ya[i-1] + d_rand(0.1,1.0) + d_rand(-0.1,0.4) + d_rand(-0.4,0.5);
for (i = 0; i < pnts; i++) { /* Divide out */
ya[i] = (ya[i]/ya[pnts-1]);
if (ya[i] < 0.0)
ya[i] = 0.0;
else if (ya[i] > 1.0)
ya[i] = 1.0;
}
}
if (n < SKIP)
continue;
for (i = 0; i < pnts; i++) {
test_points[i].p = xa[i];
test_points[i].v = ya[i];
}
for (np = 2; np <= SHAPE_ORDS; np++) {
/* Fit to scattered data */
fit(params, /* Parameters to return */
np, /* Number of parameters */
test_points, /* Test points */
pnts /* Number of test points */
);
printf("Number params = %d\n",np);
for (i = 0; i < np; i++) {
printf("Param %d = %f\n",i,params[i]);
}
/* Display the result */
for (i = 0; i < XRES; i++) {
x = i/(double)(XRES-1);
xx[i] = x;
y1[i] = lin(x,xa,ya,pnts);
y2[i] = tfunc(params, np, x);
if (y2[i] < -0.2)
y2[i] = -0.2;
else if (y2[i] > 1.2)
y2[i] = 1.2;
}
do_plot(xx,y1,y2,NULL,XRES);
}
} /* next trial */
return 0;
}
double lin(
double x,
double xa[],
double ya[],
int n) {
int i;
double y;
if (x < xa[0])
return ya[0];
else if (x > xa[n-1])
return ya[n-1];
for (i = 0; i < (n-1); i++)
if (x >=xa[i] && x <= xa[i+1])
break;
x = (x - xa[i])/(xa[i+1] - xa[i]);
y = ya[i] + (ya[i+1] - ya[i]) * x;
return y;
}
/******************************************************************/
/* Error/debug output routines */
/******************************************************************/
void
usage(void) {
puts("usage: curve");
exit(1);
}
/*******************************************************************/
/* Grapic gems based, monotonic 1D function transfer curve. */
/* Per transfer function */
static double tfunc(
double *v, /* Pointer to first parameter */
int luord, /* Curve order n..MPP_MXTCORD */
double vv /* Source of value */
) {
double g;
int ord;
if (vv < 0.0)
vv = 0.0;
else if (vv > 1.0)
vv = 1.0;
/* Process all the shaper orders from high to low. */
/* [These shapers were inspired by a Graphics Gem idea */
/* (Gems IV, VI.3, "Fast Alternatives to Perlin's Bias and */
/* Gain Functions, pp 401). */
/* They have the nice properties that they are smooth, and */
/* can't be non-monotonic. The control parameter has been */
/* altered to have a range from -oo to +oo rather than 0.0 to 1.0 */
/* so that the search space is less non-linear. ] */
for (ord = 0; ord < luord; ord++) {
int nsec; /* Number of sections */
double sec; /* Section */
g = v[ord]; /* Parameter */
nsec = ord + 1; /* Increase sections for each order */
vv *= (double)nsec;
sec = floor(vv);
if (((int)sec) & 1)
g = -g; /* Alternate action in each section */
vv -= sec;
if (g >= 0.0) {
vv = vv/(g - g * vv + 1.0);
} else {
vv = (vv - g * vv)/(1.0 - g * vv);
}
vv += sec;
vv /= (double)nsec;
}
return vv;
}
/* return the sum of the squares of the current shaper parameters */
static double shapmag(
double *v, /* Pointer to first parameter */
int luord
) {
double tt, w, tparam = 0.0;
int f;
for (f = 0; f < luord; f++) {
tt = v[f];
tt *= tt;
/* Weigh to suppress ripples */
if (f <= 1)
w = SHAPE_BASE;
else {
w = SHAPE_BASE + (f-1) * SHAPE_HBASE;
}
tparam += w * tt;
}
return tparam;
}
/* Context for optimising function fit */
typedef struct {
int luord; /* shaper order */
co *points; /* List of test points */
int nodp; /* Number of data points */
} luopt;
/* Shaper+Matrix optimisation function handed to powell() */
static double luoptfunc(void *edata, double *v) {
luopt *p = (luopt *)edata;
double rv = 0.0, smv;
double out;
int i;
/* For all our data points */
for (i = 0; i < p->nodp; i++) {
double ev;
/* Apply our function */
out = tfunc(v, p->luord, p->points[i].p);
ev = out - p->points[i].v;
#ifdef NEVER
ev = fabs(ev);
rv += ev * ev * ev;
#else
rv += ev * ev;
#endif
}
/* Normalise error to be an average delta E squared */
rv /= (double)p->nodp;
/* Sum with shaper parameters squared, to */
/* minimise unsconstrained "wiggles" */
smv = shapmag(v, p->luord);
rv += smv;
#ifdef TEST_SYM
{
double tt;
tt = tfunc(v, p->luord, 0.5) - 0.5;
tt *= tt;
rv += 200.0 * tt;
}
#endif
printf("~1 rv = %f (%f)\n",rv,smv);
return rv;
}
/* Fitting function */
void fit(
double *params, /* Parameters to return */
int np, /* Number of parameters */
co *test_points, /* Test points */
int pnts /* Number of test points */
) {
int i;
double sa[MAX_PARM]; /* Search area */
luopt os;
os.luord = np;
os.points= test_points;
os.nodp = pnts;
for (i = 0; i < np; i++) {
sa[i] = 0.5;
params[i] = 0.0;
}
if (powell(NULL, np, params, sa, POWTOL, MAXITS, luoptfunc, (void *)&os, NULL, NULL) != 0)
error ("Powell failed");
}

130
Argyll_V3.5.0/xicc/example.sp Executable file
View File

@@ -0,0 +1,130 @@
SPECT
DESCRIPTOR "Argyll Example Spectral power/reflectance information (D50)"
ORIGINATOR "Argyll CMS"
CREATED "Fri Jul 06 17:49:57 2001"
KEYWORD "SPECTRAL_BANDS"
SPECTRAL_BANDS "107"
KEYWORD "SPECTRAL_START_NM"
SPECTRAL_START_NM "300.000000"
KEYWORD "SPECTRAL_END_NM"
SPECTRAL_END_NM "830.000000"
KEYWORD "SPECTRAL_NORM"
SPECTRAL_NORM "100.000000"
KEYWORD "SPEC_300"
KEYWORD "SPEC_305"
KEYWORD "SPEC_310"
KEYWORD "SPEC_315"
KEYWORD "SPEC_320"
KEYWORD "SPEC_325"
KEYWORD "SPEC_330"
KEYWORD "SPEC_335"
KEYWORD "SPEC_340"
KEYWORD "SPEC_345"
KEYWORD "SPEC_350"
KEYWORD "SPEC_355"
KEYWORD "SPEC_360"
KEYWORD "SPEC_365"
KEYWORD "SPEC_370"
KEYWORD "SPEC_375"
KEYWORD "SPEC_380"
KEYWORD "SPEC_385"
KEYWORD "SPEC_390"
KEYWORD "SPEC_395"
KEYWORD "SPEC_400"
KEYWORD "SPEC_405"
KEYWORD "SPEC_410"
KEYWORD "SPEC_415"
KEYWORD "SPEC_420"
KEYWORD "SPEC_425"
KEYWORD "SPEC_430"
KEYWORD "SPEC_435"
KEYWORD "SPEC_440"
KEYWORD "SPEC_445"
KEYWORD "SPEC_450"
KEYWORD "SPEC_455"
KEYWORD "SPEC_460"
KEYWORD "SPEC_465"
KEYWORD "SPEC_470"
KEYWORD "SPEC_475"
KEYWORD "SPEC_480"
KEYWORD "SPEC_485"
KEYWORD "SPEC_490"
KEYWORD "SPEC_495"
KEYWORD "SPEC_500"
KEYWORD "SPEC_505"
KEYWORD "SPEC_510"
KEYWORD "SPEC_515"
KEYWORD "SPEC_520"
KEYWORD "SPEC_525"
KEYWORD "SPEC_530"
KEYWORD "SPEC_535"
KEYWORD "SPEC_540"
KEYWORD "SPEC_545"
KEYWORD "SPEC_550"
KEYWORD "SPEC_555"
KEYWORD "SPEC_560"
KEYWORD "SPEC_565"
KEYWORD "SPEC_570"
KEYWORD "SPEC_575"
KEYWORD "SPEC_580"
KEYWORD "SPEC_585"
KEYWORD "SPEC_590"
KEYWORD "SPEC_595"
KEYWORD "SPEC_600"
KEYWORD "SPEC_605"
KEYWORD "SPEC_610"
KEYWORD "SPEC_615"
KEYWORD "SPEC_620"
KEYWORD "SPEC_625"
KEYWORD "SPEC_630"
KEYWORD "SPEC_635"
KEYWORD "SPEC_640"
KEYWORD "SPEC_645"
KEYWORD "SPEC_650"
KEYWORD "SPEC_655"
KEYWORD "SPEC_660"
KEYWORD "SPEC_665"
KEYWORD "SPEC_670"
KEYWORD "SPEC_675"
KEYWORD "SPEC_680"
KEYWORD "SPEC_685"
KEYWORD "SPEC_690"
KEYWORD "SPEC_695"
KEYWORD "SPEC_700"
KEYWORD "SPEC_705"
KEYWORD "SPEC_710"
KEYWORD "SPEC_715"
KEYWORD "SPEC_720"
KEYWORD "SPEC_725"
KEYWORD "SPEC_730"
KEYWORD "SPEC_735"
KEYWORD "SPEC_740"
KEYWORD "SPEC_745"
KEYWORD "SPEC_750"
KEYWORD "SPEC_755"
KEYWORD "SPEC_760"
KEYWORD "SPEC_765"
KEYWORD "SPEC_770"
KEYWORD "SPEC_775"
KEYWORD "SPEC_780"
KEYWORD "SPEC_785"
KEYWORD "SPEC_790"
KEYWORD "SPEC_795"
KEYWORD "SPEC_800"
KEYWORD "SPEC_805"
KEYWORD "SPEC_810"
KEYWORD "SPEC_815"
KEYWORD "SPEC_820"
KEYWORD "SPEC_825"
KEYWORD "SPEC_830"
NUMBER_OF_FIELDS 107
BEGIN_DATA_FORMAT
SPEC_300 SPEC_305 SPEC_310 SPEC_315 SPEC_320 SPEC_325 SPEC_330 SPEC_335 SPEC_340 SPEC_345 SPEC_350 SPEC_355 SPEC_360 SPEC_365 SPEC_370 SPEC_375 SPEC_380 SPEC_385 SPEC_390 SPEC_395 SPEC_400 SPEC_405 SPEC_410 SPEC_415 SPEC_420 SPEC_425 SPEC_430 SPEC_435 SPEC_440 SPEC_445 SPEC_450 SPEC_455 SPEC_460 SPEC_465 SPEC_470 SPEC_475 SPEC_480 SPEC_485 SPEC_490 SPEC_495 SPEC_500 SPEC_505 SPEC_510 SPEC_515 SPEC_520 SPEC_525 SPEC_530 SPEC_535 SPEC_540 SPEC_545 SPEC_550 SPEC_555 SPEC_560 SPEC_565 SPEC_570 SPEC_575 SPEC_580 SPEC_585 SPEC_590 SPEC_595 SPEC_600 SPEC_605 SPEC_610 SPEC_615 SPEC_620 SPEC_625 SPEC_630 SPEC_635 SPEC_640 SPEC_645 SPEC_650 SPEC_655 SPEC_660 SPEC_665 SPEC_670 SPEC_675 SPEC_680 SPEC_685 SPEC_690 SPEC_695 SPEC_700 SPEC_705 SPEC_710 SPEC_715 SPEC_720 SPEC_725 SPEC_730 SPEC_735 SPEC_740 SPEC_745 SPEC_750 SPEC_755 SPEC_760 SPEC_765 SPEC_770 SPEC_775 SPEC_780 SPEC_785 SPEC_790 SPEC_795 SPEC_800 SPEC_805 SPEC_810 SPEC_815 SPEC_820 SPEC_825 SPEC_830
END_DATA_FORMAT
NUMBER_OF_SETS 1
BEGIN_DATA
0.020000 1.0300 2.0500 4.9100 7.7800 11.260 14.750 16.350 17.950 19.480 21.010 22.480 23.940 25.450 26.960 25.720 24.490 27.180 29.870 39.590 49.310 52.910 56.510 58.270 60.030 58.930 57.820 66.320 74.820 81.040 87.250 88.930 90.610 90.990 91.370 93.240 95.110 93.540 91.960 93.840 95.720 96.170 96.610 96.870 97.130 99.610 102.10 101.43 100.75 101.54 102.32 101.16 100.00 98.870 97.740 98.330 98.920 96.210 93.500 95.590 97.690 98.480 99.270 99.160 99.040 97.380 95.720 97.290 98.860 97.260 95.670 96.930 98.190 100.60 103.00 101.07 99.130 93.260 87.380 89.490 91.600 92.250 92.890 84.870 76.850 81.680 86.510 89.550 92.580 85.400 78.230 67.960 57.690 70.310 82.920 80.600 78.270 78.910 79.550 76.480 73.400 68.660 63.920 67.350 70.780 72.610 74.440
END_DATA

View File

@@ -0,0 +1,225 @@
/*
* Extract an ICC profile from a TIFF file.
*
* Author: Graeme W. Gill
* Date: 2008/5/18
* 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 <setjmp.h>
#include <string.h>
#include <math.h>
#include "numlib.h"
#include "tiffio.h"
#include "jpeglib.h"
#include "iccjpeg.h"
#include "copyright.h"
#include "aconfig.h"
#include "icc.h"
void usage(char *diag, ...) {
int i;
fprintf(stderr,"Extract an ICC profile from a TIFF or JPEG file, 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: extracticc [-v] infile.tif/jpg outfile%s\n",ICC_FILE_EXT);
fprintf(stderr," -v Verbose\n");
exit(1);
}
/* ------------------------------------------------------ */
/* JPEG error information */
typedef struct {
jmp_buf env; /* setjmp/longjmp environment */
char message[JMSG_LENGTH_MAX];
} jpegerrorinfo;
/* JPEG error handler */
static void jpeg_error(j_common_ptr cinfo) {
jpegerrorinfo *p = (jpegerrorinfo *)cinfo->client_data;
(*cinfo->err->format_message) (cinfo, p->message);
longjmp(p->env, 1);
}
/* ------------------------------------------------------ */
int
main(int argc, char *argv[]) {
int fa,nfa; /* argument we're looking at */
static char in_name[MAXNAMEL+1]; /* TIFF input name */
static char out_name[MAXNAMEL+1]; /* ICC output name */
int verb = 0;
TIFFErrorHandler olderrh, oldwarnh;
TIFFErrorHandlerExt olderrhx, oldwarnhx;
TIFF *rh;
int size = 0;
void *buf = NULL;
icmFile *fp;
icmErr err = { 0, { '\000'} };
int rv = 0;
error_program = argv[0];
if (argc < 3)
usage("Too few parameters");
/* 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;
}
else
usage("Unknown flag '%c'",argv[fa][1]);
} else
break;
}
if (fa >= argc || argv[fa][0] == '-') usage("Missing input TIFF file");
strncpy(in_name,argv[fa++],MAXNAMEL); in_name[MAXNAMEL] = '\000';
if (fa >= argc || argv[fa][0] == '-') usage("Missing output ICC profile");
strncpy(out_name,argv[fa++],MAXNAMEL); out_name[MAXNAMEL] = '\000';
/* - - - - - - - - - - - - - - - */
/* Open up input tiff file ready for reading */
/* Got arguments, so setup to process the file */
olderrh = TIFFSetErrorHandler(NULL);
oldwarnh = TIFFSetWarningHandler(NULL);
olderrhx = TIFFSetErrorHandlerExt(NULL);
oldwarnhx = TIFFSetWarningHandlerExt(NULL);
if ((rh = TIFFOpen(in_name, "r")) != NULL) {
TIFFSetErrorHandler(olderrh);
TIFFSetWarningHandler(oldwarnh);
TIFFSetErrorHandlerExt(olderrhx);
TIFFSetWarningHandlerExt(oldwarnhx);
if (TIFFGetField(rh, TIFFTAG_ICCPROFILE, &size, &buf) == 0 || size == 0) {
error("unable to find ICC profile tag in TIFF file '%s'",in_name);
}
if ((fp = new_icmFileStd_name(&err,out_name, "w")) == NULL) {
error("unable to open output ICC profile '%s' (0x%x, '%s')",out_name,err.c,err.m);
}
if (fp->write(fp, buf, 1, size) != size) {
error("error writing file '%s'",out_name);
}
if (fp->del(fp) != 0) {
error("error closing file '%s'",out_name);
}
TIFFClose(rh); /* Close Input file and free field buffer */
} else {
jpegerrorinfo jpeg_rerr;
FILE *rf = NULL;
struct jpeg_decompress_struct rj;
struct jpeg_error_mgr jerr;
TIFFSetErrorHandler(olderrh);
TIFFSetWarningHandler(oldwarnh);
TIFFSetErrorHandlerExt(olderrhx);
TIFFSetWarningHandlerExt(oldwarnhx);
/* We cope with the horrible ijg jpeg library error handling */
/* by using a setjmp/longjmp. */
jpeg_std_error(&jerr);
jerr.error_exit = jpeg_error;
if (setjmp(jpeg_rerr.env)) {
jpeg_destroy_decompress(&rj);
fclose(rf);
error("error opening read file '%s'",in_name);
}
rj.err = &jerr;
rj.client_data = &jpeg_rerr;
jpeg_create_decompress(&rj);
#if defined(O_BINARY) || defined(_O_BINARY)
if ((rf = fopen(in_name,"rb")) == NULL)
#else
if ((rf = fopen(in_name,"r")) == NULL)
#endif
{
jpeg_destroy_decompress(&rj);
error("error opening read file '%s'",in_name);
}
jpeg_stdio_src(&rj, rf);
setup_read_icc_profile(&rj);
/* we'll longjmp on error */
jpeg_read_header(&rj, TRUE);
if (!read_icc_profile(&rj, (unsigned char **)&buf, (unsigned int *)&size)) {
jpeg_destroy_decompress(&rj);
fclose(rf);
error("unable to find ICC profile marker in JPEG file '%s'",in_name);
}
jpeg_destroy_decompress(&rj);
fclose(rf);
if ((fp = new_icmFileStd_name(&err,out_name, "w")) == NULL) {
error("unable to open output ICC profile '%s' (0x%x, '%s')",out_name,err.c,err.m);
}
if (fp->write(fp, buf, 1, size) != size) {
error("error writing file '%s'",out_name);
}
if (fp->del(fp) != 0) {
error("error closing file '%s'",out_name);
}
free(buf);
}
return 0;
}

View File

@@ -0,0 +1,224 @@
/*
* Extract a CGATS file from an ICC profile tag.
* (Can also extract a tag of unknown format as a binary lump).
*
* Author: Graeme W. Gill
* Date: 2008/5/18
* 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:
*
* Should uncompress ZXML type tag using zlib.
*
*/
#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 "conv.h"
#include "xicc.h"
#define MXTGNMS 30
void usage(char *diag, ...) {
int i;
fprintf(stderr,"Extract a text tag from an ICC profile, 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: extractttag [-v] infile%s outfile\n",ICC_FILE_EXT);
fprintf(stderr," -v Verbose\n");
fprintf(stderr," -t tag Extract this tag rather than default 'targ'\n");
fprintf(stderr," -c Extract calibration file from 'targ' tag\n");
exit(1);
}
int
main(int argc, char *argv[]) {
int fa,nfa; /* argument we're looking at */
static char in_name[MAXNAMEL+1]; /* TIFF input name */
static char out_name[MAXNAMEL+1]; /* ICC output name */
char tag_name[MXTGNMS] = { 't','a','r','g' };
int docal = 0;
icc *icco;
icTagSignature sig;
icmText *ro;
icmUnknown *uro;
icmFile *ifp, *ofp;
icmErr err = { 0, { '\000'} };
int verb = 0;
int size = 0;
void *buf = NULL;
int rv = 0;
error_program = argv[0];
if (argc < 3)
usage("Too few parameters");
/* 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;
}
/* Tag name */
else if (argv[fa][1] == 't' || argv[fa][1] == 'T') {
fa = nfa;
if (na == NULL) usage("Expect tag name after -t");
strncpy(tag_name,na,4);
tag_name[4] = '\000';
}
/* Calibration */
else if (argv[fa][1] == 'c' || argv[fa][1] == 'C') {
docal = 1;
}
else
usage("Unknown flag '%c'",argv[fa][1]);
} else
break;
}
if (fa >= argc || argv[fa][0] == '-') usage("Missing input ICC profile");
strncpy(in_name,argv[fa++],MAXNAMEL); in_name[MAXNAMEL] = '\000';
if (fa >= argc || argv[fa][0] == '-') usage("Missing output filename");
strncpy(out_name,argv[fa++],MAXNAMEL); out_name[MAXNAMEL] = '\000';
/* - - - - - - - - - - - - - - - */
/* Open up the file for reading */
if ((ifp = new_icmFileStd_name(&err,in_name,"r")) == NULL)
error ("Can't open file '%s' (0x%x, '%s')",in_name,err.c,err.m);
if ((icco = new_icc(&err)) == NULL)
error ("Creation of ICC object failed (0x%x, '%s')",err.c,err.m);
if ((rv = icco->read(icco,ifp,0)) != 0)
error ("%d, %s",rv,icco->e.m);
sig = icmstr2tag(tag_name);
if ((ro = (icmText *)icco->read_tag_any(icco, sig)) == NULL) {
error("%d, %s",icco->e.c, icco->e.m);
}
if (ro->ttype == icmSigUnknownType) {
uro = (icmUnknown *)ro;
} else if (ro->ttype != icSigTextType) {
error("Tag isn't TextType or UnknownType");
}
if (docal) {
cgatsFile *cgf;
cgats *icg;
int tab, oi;
xcal *cal;
if ((icg = new_cgats()) == NULL) {
error("new_cgats() failed");
}
if ((cgf = new_cgatsFileMem(ro->desc, ro->count)) == NULL) {
error("new_cgatsFileMem() failed");
}
icg->add_other(icg, "CTI3");
oi = icg->add_other(icg, "CAL");
if (icg->read(icg, cgf) != 0) {
error("failed to parse tag contents as a CGATS file");
}
for (tab = 0; tab < icg->ntables; tab++) {
if (icg->t[tab].tt == tt_other && icg->t[tab].oi == oi) {
break;
}
}
if (tab >= icg->ntables) {
error("Failed to locate CAL table in CGATS");
}
if ((cal = new_xcal()) == NULL) {
error("new_xcal() failed");
}
if (cal->read_cgats(cal, icg, tab, in_name) != 0) {
error("Parsing CAL table failed");
}
icg->del(icg);
cgf->del(cgf);
if (cal->write(cal, out_name) != 0) {
error("writing to file '%s' failed\n",out_name);
}
} else {
if ((ofp = new_icmFileStd_name(&err, out_name, "w")) == NULL) {
error("unable to open output file '%s' (0x%x, '%s')",out_name,err.c,err.m);
}
if (ro->ttype == icmSigUnknownType) {
if (ofp->write(ofp, uro->data, 1, uro->count) != (uro->count)) {
error("writing to file '%s' failed",out_name);
}
} else {
if (ofp->write(ofp, ro->desc, 1, ro->count-1) != (ro->count-1)) {
error("writing to file '%s' failed",out_name);
}
}
if (ofp->del(ofp) != 0) {
error("closing file '%s' failed",out_name);
}
}
icco->del(icco);
ifp->del(ifp);
return 0;
}

View File

@@ -0,0 +1,535 @@
/*
* Create a synthetic .ti3 file for a CMY "device",
* that exactly maps to the surface points and neutral
* axis of the CMYK profile it is derived from.
*
* Author: Graeme W. Gill
* Date: 2004/6/27
* Version: 1.00
*
* Copyright 2004 Graeme W. Gill
* Please refer to License.txt file for details.
*/
/* TTBD:
*
* Add a flag to create RGB instead, by simply inverting the CMY values
* when writing to the .ti3 file.
*/
#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 "conv.h"
#include "xicc.h"
#include "cgats.h"
#include "targen.h"
#define EXTRA_NEUTRAL 50 /* Crude way of increasing weighting */
/* ---------------------------------------- */
void usage(char *diag) {
fprintf(stderr,"Create a fake CMY data file from a CMYK profile, Version %s\n",ARGYLL_VERSION_STR);
fprintf(stderr,"Author: Graeme W. Gill, licensed under the AGPL Version 3\n");
fprintf(stderr,"usage: fakeCMY [option] profile.icm fake.ti3\n");
if (diag != NULL)
fprintf(stderr,"Diagnostic: %s\n",diag);
fprintf(stderr," -v verbose\n");
fprintf(stderr," -r res set surface point resolution (default 3)\n");
fprintf(stderr," -l tlimit set total ink limit, 0 - 400%% (estimate by default)\n");
fprintf(stderr," -L klimit set black ink limit, 0 - 100%% (estimate by default)\n");
fprintf(stderr," -g output fake RGB values instead of CMY\n");
fprintf(stderr,"profile%s CMYK ICC input profile to use\n",ICC_FILE_EXT);
fprintf(stderr,"outfile.ti3 Name for output .ti3 file\n");
exit(1);
}
/* Fake up a vector direction clip in Lab space */
static void visect(
icxLuBase *luo, /* xicc lookup object */
double *pout, /* PCS result (may be NULL) */
double *dout, /* Device result (may be NULL) */
double *orig, /* Origin of vector (PCS) */
double *vec /* Input vector (PCS) */
) {
int i;
int rv;
double sum, step, inc[3]; /* 1 Delta E increment */
double try[3]; /* Trial PCS */
double res[4]; /* Trial result device values */
for (sum = 0.0, i = 0; i < 3; i++) {
double tt = vec[i] - orig[i];
sum += tt * tt;
}
sum = sqrt(sum);
for (i = 0; i < 3; i++) {
inc[i] = (vec[i] - orig[i])/sum;
}
//printf("~1 orig %f %f %f, vec %f %f %f\n",orig[0],orig[1],orig[2],vec[0],vec[1],vec[3]);
//printf("~1 inc %f %f %f\n",inc[0],inc[1],inc[2]);
/* Increment in vector direction until we clip */
for (i = 0; i < 3; i++)
try[i] = 0.5 * (orig[i] + vec[i]);
for (step = 20.0;;) {
rv = luo->inv_lookup(luo, res, try);
if (rv > 1)
error ("inv_lookup failed");
//printf("~1 trial %f %f %f returned %d\n",try[0],try[1],try[2],rv);
if (rv == 1) {
if (step <= 0.1)
break;
/* Back off, and use smaller steps */
for (i = 0; i < 3; i++)
try[i] -= step * inc[i];
step *= 0.5;
}
for (i = 0; i < 3; i++)
try[i] += step * inc[i];
}
if (dout != NULL)
for (i = 0; i < 3; i++)
dout[i] = res[i];
/* Lookup the clipped PCS */
if (pout != NULL)
luo->lookup(luo, pout, res);
}
int main(int argc, char *argv[]) {
int fa,nfa; /* argument we're looking at */
int verb = 0;
int dorgb = 0; /* Create fake RGB values */
double tlimit = -1.0; /* Total ink limit */
double klimit = -1.0; /* Black ink limit */
int tres = 3; /* Resolution of suface grid */
int gres = tres+2; /* Resolution of grey points */
static char in_name[MAXNAMEL+1];
static char out_name[MAXNAMEL+1];
icmFile *rd_fp;
icc *rd_icco;
icmErr err = { 0, { '\000'} };
int rv = 0;
icColorSpaceSignature ins, outs; /* Type of input and output spaces */
xicc *xicco;
icxLuBase *luo;
icxInk ink; /* Ink parameters */
fxpos *fxlist = NULL; /* Fixed point list for full spread */
int fxlist_a = 0; /* Fixed point list allocation */
int fxno = 0; /* The number of fixed points */
int gc[MXTD]; /* Grid coordinate */
cgats *ocg; /* output cgats structure */
time_t clk = time(0);
struct tm *tsp = localtime(&clk);
char *atm = asctime(tsp); /* Ascii time */
int i, j;
error_program = argv[0];
if (argc < 2)
usage("Not enough arguments");
/* 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 */
}
}
}
/* Verbosity */
if (argv[fa][1] == 'v') {
verb = 1;
}
/* Ink limits */
else if (argv[fa][1] == 'l') {
fa = nfa;
if (na == NULL) usage("No parameter after flag -l");
tlimit = atoi(na)/100.0;
}
else if (argv[fa][1] == 'L') {
fa = nfa;
if (na == NULL) usage("No parameter after flag -L");
klimit = atoi(na)/100.0;
}
/* Resolution */
else if (argv[fa][1] == 'r') {
fa = nfa;
if (na == NULL) usage("No parameter after flag -r");
tres = atoi(na);
}
/* RGB ? */
else if (argv[fa][1] == 'g') {
dorgb = 1;
}
else if (argv[fa][1] == '?')
usage(NULL);
else
usage("Unknown flag");
}
else
break;
}
if (fa >= argc || argv[fa][0] == '-') usage("Expected input profile name");
strncpy(in_name,argv[fa++],MAXNAMEL); in_name[MAXNAMEL] = '\000';
if (fa >= argc || argv[fa][0] == '-') usage("Expected output .ti3 name");
strncpy(out_name,argv[fa++],MAXNAMEL); out_name[MAXNAMEL] = '\000';
/* Open up the file for reading */
if ((rd_fp = new_icmFileStd_name(&err,in_name,"r")) == NULL)
error ("Read: Can't open file '%s' (0x%x, '%s')",in_name,err.c,err.m);
if ((rd_icco = new_icc(&err)) == NULL)
error ("Read: Creation of ICC object failed (0x%x, '%s')",err.c,err.m);
/* Read the header and tag list */
if ((rv = rd_icco->read(rd_icco,rd_fp,0)) != 0)
error ("Read: %d, %s",rv,rd_icco->e.m);
/* Wrap with an expanded icc */
if ((xicco = new_xicc(rd_icco)) == NULL)
error ("Creation of xicc failed");
/* Setup ink limit */
/* Set the default ink limits if not set on command line */
icxDefaultLimits(xicco, &ink.tlimit, tlimit, &ink.klimit, klimit);
if (verb) {
if (ink.tlimit >= 0.0)
printf("Total ink limit assumed is %3.0f%%\n",100.0 * ink.tlimit);
if (ink.klimit >= 0.0)
printf("Black ink limit assumed is %3.0f%%\n",100.0 * ink.klimit);
}
ink.c.Ksmth = ICXINKDEFSMTH; /* Default smoothing */
ink.c.Kskew = ICXINKDEFSKEW; /* default curve skew */
ink.c.Kstle = 0.5; /* Min K at white end */
ink.c.Kstpo = 0.5; /* Start of transition is at white */
ink.c.Kenle = 0.5; /* Max K at black end */
ink.c.Kenpo = 0.5; /* End transition at black */
ink.c.Kshap = 1.0; /* Linear transition */
gres = tres + 2;
/* Get a Device to PCS conversion object */
if ((luo = xicco->get_luobj(xicco, ICX_CLIP_NEAREST, icmFwd, icAbsoluteColorimetric, icSigLabData, icmLuOrdNorm, NULL, &ink)) == NULL) {
error ("%d, %s",rd_icco->e.c, rd_icco->e.m);
}
/* Get details of conversion */
luo->spaces(luo, &ins, NULL, &outs, NULL, NULL, NULL, NULL, NULL);
if (ins != icSigCmykData) {
error("Expecting CMYK device");
}
/* Make a default allocation */
fxlist_a = 4;
if ((fxlist = (fxpos *)malloc(sizeof(fxpos) * fxlist_a)) == NULL)
error ("Failed to malloc fxlist");
/* init coords */
for (j = 0; j < 3; j++)
gc[j] = 0;
/* Add CMY grid surface points */
for (;;) { /* Generate all grid points */
/* Check if this position is on the CMY surface */
for (j = 0; j < 3; j++) {
if (gc[j] == 0 || gc[j] == (tres-1))
break;
}
if (j < 3) { /* On the surface, so add a point */
/* Make sure there is room */
if (fxno >= fxlist_a) {
fxlist_a *= 2;
if ((fxlist = (fxpos *)realloc(fxlist, sizeof(fxpos) * fxlist_a)) == NULL)
error ("Failed to malloc fxlist");
}
for (j = 0; j < 3; j++)
fxlist[fxno].p[j] = gc[j]/(tres-1.0);
fxlist[fxno].p[3] = 0.0; /* K = 0 */
fxno++;
}
/* Increment grid index and position */
for (j = 0; j < 3; j++) {
gc[j]++;
if (gc[j] < tres)
break; /* No carry */
gc[j] = 0;
}
if (j >= 3)
break; /* Done grid */
}
/* Add neutral axis points */
for (i = 1; i < ((EXTRA_NEUTRAL * gres)-1); i++) {
/* Make sure there is room */
if (fxno >= fxlist_a) {
fxlist_a *= 2;
if ((fxlist = (fxpos *)realloc(fxlist, sizeof(fxpos) * fxlist_a)) == NULL)
error ("Failed to malloc fxlist");
}
for (j = 0; j < 3; j++)
fxlist[fxno].p[j] = i/((EXTRA_NEUTRAL * gres)-1.0);
fxlist[fxno].p[3] = 0.0; /* K = 0 */
fxno++;
}
/* Convert CMY values into CMY0 Lab values */
for (i = 0; i < fxno; i++) {
if ((rv = luo->lookup(luo, fxlist[i].v, fxlist[i].p)) > 1)
error ("%d, %s",rd_icco->e.c,rd_icco->e.m);
//printf("~1 initial lookup %f %f %f -> %f %f %f\n", fxlist[i].p[0], fxlist[i].p[1], fxlist[i].p[2], fxlist[i].v[0], fxlist[i].v[1], fxlist[i].v[2]);
}
/* A CMYK black will be deeper than CMY0, so we need to figure out */
/* how to scale the initial values to fully occupy the CMYK gamut. */
/* Figure out the general scale at the black end */
{
double dval[4];
double wt[3] = { 100.0, 0, 0 }; /* Approximate white PCS */
double ac[3] = { 50.0, 0, 0 }; /* Adjustment center */
double lab_wt[3]; /* Media Whitepoint PCS */
double xyz_wt[3]; /* Media Whitepoint PCS */
icmXYZNumber XYZ_WT;
double k_bk[3]; /* K black PCS */
double cmyk_bk[3]; /* CMYK black PCS */
double toAbs[3][3];
double fromAbs[3][3];
/* Discover the Lab of the CMYK media */
for (j = 0; j < 4; j++)
dval[j] = 0.0;
luo->lookup(luo, lab_wt, dval);
icmLab2XYZ(&icmD50, xyz_wt, lab_wt);
icmAry2XYZ(XYZ_WT, xyz_wt);
/* Create the XYZ chromatic transform from relative to absolute and back */
icmChromAdaptMatrix(ICM_CAM_BRADFORD, XYZ_WT, icmD50, toAbs);
icmChromAdaptMatrix(ICM_CAM_BRADFORD, icmD50, XYZ_WT, fromAbs);
/* Discover the Lab of the CMY black and CMYK black */
for (j = 0; j < 3; j++)
dval[j] = 0.0;
dval[j] = 1.0;
luo->lookup(luo, k_bk, dval);
visect(luo, cmyk_bk, NULL, wt, k_bk);
if (verb)
printf("K black %f %f %f, CMYK black %f %f %f\n", k_bk[0], k_bk[1], k_bk[2], cmyk_bk[0], cmyk_bk[1], cmyk_bk[2]);
/* Scale the CMY values that will be influenced by the K component to a darker */
/* black. */
for (i = 0; i < fxno; i++) {
/* Treat grey axis points differently */
if (fxlist[i].p[0] != 0.0
&& fxlist[i].p[0] == fxlist[i].p[1]
&& fxlist[i].p[0] == fxlist[i].p[2]) {
double xyz[3]; /* Temporary */
double lab[3]; /* Temporary */
//printf("~1 scaled neutral L value from %f",fxlist[i].v[0]);
/* Scale L value from K to CMYK black */
fxlist[i].v[0] = lab_wt[0] + (fxlist[i].v[0] - lab_wt[0]) *
(cmyk_bk[0] - lab_wt[0])/(k_bk[0] - lab_wt[0]);
//printf(" to %f\n",fxlist[i].v[0]);
#ifdef NEVER
/* Make a & b values same as CMYK black */
/* Pivot around white point */
fxlist[i].v[1] = wt[1] + (cmyk_bk[1] - wt[1]) *
(fxlist[i].v[0] - wt[0])/(cmyk_bk[0] - wt[0]);
fxlist[i].v[2] = wt[2] + (cmyk_bk[2] - wt[2]) *
(fxlist[i].v[0] - wt[0])/(cmyk_bk[0] - wt[0]);
#else
/* Convert absolute target Lab to relative Lab */
icmLab2XYZ(&icmD50, xyz, fxlist[i].v);
icmMulBy3x3(xyz, fromAbs, xyz);
icmXYZ2Lab(&icmD50, lab, xyz);
/* Make sure the equivalent relative value is neutral */
lab[1] = lab[2] = 0.0;
/* Convert back to absolute Lab */
icmLab2XYZ(&icmD50, xyz, lab);
icmMulBy3x3(xyz, toAbs, xyz);
icmXYZ2Lab(&icmD50, lab, xyz);
//printf("~1 corrected neutral value from Lab %f %f %f to %f %f %f\n", fxlist[i].v[0], fxlist[i].v[1], fxlist[i].v[2], lab[0], lab[1], lab[2]);
for (j = 0; j < 3; j++)
fxlist[i].v[j] = lab[j];
#endif
} else {
for (j = 0; j < 3; j++) {
if (fxlist[i].p[j] == 0.0)
break; /* Not a dark color */
}
if (j >= 3) {
/* Scale by CMYK/K black vector */
for (j = 0; j < 3; j++) {
fxlist[i].v[j] = lab_wt[j] + (fxlist[i].v[j] - lab_wt[j]) *
(cmyk_bk[j] - lab_wt[j])/(k_bk[j] - lab_wt[j]);
}
}
//printf("[%4.2f %4.2f %4.2f] %f %f %f becomes",
//fxlist[i].p[0], fxlist[i].p[1], fxlist[i].p[2], fxlist[i].v[0], fxlist[i].v[1], fxlist[i].v[2]);
/* Now clip non-neutrals to the gamut surface */
visect(luo, fxlist[i].v, NULL, ac, fxlist[i].v);
//printf("%f %f %f\n", fxlist[i].v[0], fxlist[i].v[1], fxlist[i].v[2]);
}
}
}
if (verb) {
for (i = 0; i < fxno; i++) {
if (dorgb) {
printf("Point %d = %f %f %f -> %f %f %f\n",i,
1.0 - fxlist[i].p[0], 1.0 - fxlist[i].p[1], 1.0 - fxlist[i].p[2],
fxlist[i].v[0], fxlist[i].v[1], fxlist[i].v[2]);
} else {
printf("Point %d = %f %f %f -> %f %f %f\n",i,
fxlist[i].p[0], fxlist[i].p[1], fxlist[i].p[2],
fxlist[i].v[0], fxlist[i].v[1], fxlist[i].v[2]);
}
}
}
/* Setup output cgats file */
{
char buf[1000];
cgats_set_elem *setel; /* Array of set value elements */
ocg = new_cgats(); /* Create a CGATS structure */
ocg->add_other(ocg, "CTI3"); /* our special type is Calibration Target Information 3 */
ocg->add_table(ocg, tt_other, 0); /* Start the first table */
ocg->add_kword(ocg, 0, "DESCRIPTOR", "Argyll Calibration Target chart information 3",NULL);
if (dorgb)
ocg->add_kword(ocg, 0, NULL, NULL, "Fake RGB device data for profile or RGB->CMYK link");
else
ocg->add_kword(ocg, 0, NULL, NULL, "Fake CMY device data for profile or CMY->CMYK link");
ocg->add_kword(ocg, 0, "ORIGINATOR", "Argyll fakeCMY", NULL);
atm[strlen(atm)-1] = '\000'; /* Remove \n from end */
ocg->add_kword(ocg, 0, "CREATED",atm, NULL);
ocg->add_kword(ocg, 0, "DEVICE_CLASS","OUTPUT", NULL);
if (dorgb)
ocg->add_kword(ocg, 0, "COLOR_REP","RGB_LAB", NULL);
else
ocg->add_kword(ocg, 0, "COLOR_REP","CMY_LAB", NULL);
if (!dorgb) {
if (tlimit >= 0) {
sprintf(buf,"%.0f",tlimit * 100.0);
ocg->add_kword(ocg, 0, "TOTAL_INK_LIMIT",buf, NULL);
}
if (klimit >= 0) {
sprintf(buf,"%.0f",klimit * 100.0);
ocg->add_kword(ocg, 0, "BLACK_INK_LIMIT",buf, NULL);
}
}
/* Fields we want */
ocg->add_field(ocg, 0, "SAMPLE_ID", nqcs_t);
if (dorgb) {
ocg->add_field(ocg, 0, "RGB_R", r_t);
ocg->add_field(ocg, 0, "RGB_G", r_t);
ocg->add_field(ocg, 0, "RGB_B", r_t);
} else {
ocg->add_field(ocg, 0, "CMY_C", r_t);
ocg->add_field(ocg, 0, "CMY_M", r_t);
ocg->add_field(ocg, 0, "CMY_Y", r_t);
}
ocg->add_field(ocg, 0, "LAB_L", r_t);
ocg->add_field(ocg, 0, "LAB_A", r_t);
ocg->add_field(ocg, 0, "LAB_B", r_t);
if ((setel = (cgats_set_elem *)malloc(sizeof(cgats_set_elem) * 7)) == NULL)
error("Malloc failed!");
/* Write out test values. */
for (i = 0; i < fxno; i++) {
sprintf(buf, "%d", i+1);
setel[0].c = buf;
if (dorgb) {
setel[1].d = 100.0 * (1.0 - fxlist[i].p[0]);
setel[2].d = 100.0 * (1.0 - fxlist[i].p[1]);
setel[3].d = 100.0 * (1.0 - fxlist[i].p[2]);
} else {
setel[1].d = 100.0 * fxlist[i].p[0];
setel[2].d = 100.0 * fxlist[i].p[1];
setel[3].d = 100.0 * fxlist[i].p[2];
}
setel[4].d = fxlist[i].v[0];
setel[5].d = fxlist[i].v[1];
setel[6].d = fxlist[i].v[2];
ocg->add_setarr(ocg, 0, setel);
}
free(setel);
if (ocg->write_name(ocg, out_name))
error("Write error : %s",ocg->e.m);
ocg->del(ocg);
}
luo->del(luo);
xicco->del(xicco);
rd_icco->del(rd_icco);
rd_fp->del(rd_fp);
return 0;
}

259
Argyll_V3.5.0/xicc/fbview.c Normal file
View File

@@ -0,0 +1,259 @@
/*
* See xfbview !
*
* International Color Consortium Format Library (icclib)
* View the gamut clipping implemented by the bwd profile.
* abscol intent, asumes CMYK
*
* Author: Graeme W. Gill
* Date: 2000/12/8
* Version: 1.23
*
* Copyright 2000 Graeme W. Gill
* Please refer to License.txt file for 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 "icc.h"
#include "vrml.h"
#define TRES 43
/* - - - - - - - - - - - - - */
/* Return maximum difference */
double maxdiff(double in1[3], double in2[3]) {
double tt, rv = 0.0;
if ((tt = fabs(in1[0] - in2[0])) > rv)
rv = tt;
if ((tt = fabs(in1[1] - in2[1])) > rv)
rv = tt;
if ((tt = fabs(in1[2] - in2[2])) > rv)
rv = tt;
return rv;
}
/* Return absolute difference */
double absdiff(double in1[3], double in2[3]) {
double tt, rv = 0.0;
tt = in1[0] - in2[0];
rv += tt * tt;
tt = in1[1] - in2[1];
rv += tt * tt;
tt = in1[2] - in2[2];
rv += tt * tt;
return sqrt(rv);
}
/* ---------------------------------------- */
void usage(void) {
fprintf(stderr,"View abscol bwd table clipping of an ICC file, , Version %s\n",ARGYLL_VERSION_STR);
fprintf(stderr,"Author: Graeme W. Gill, licensed under the AGPL Version 3\n");
fprintf(stderr,"usage: fbtest [-v] infile\n");
fprintf(stderr," -v verbose\n");
fprintf(stderr," [[ output is infile.wrl ]]\n");
exit(1);
}
int
main(
int argc,
char *argv[]
) {
int fa,nfa; /* argument we're looking at */
int verb = 0;
int doaxes = 0;
static char in_name[MAXNAMEL+1];
static char *xl, out_name[MAXNAMEL+1];
icmFile *rd_fp;
icc *rd_icco;
icmErr err = { 0, { '\000'} };
int rv = 0;
icColorSpaceSignature ins, outs; /* Type of input and output spaces */
/* Check variables */
int co[4];
double in[4], out[4], check[4], temp[4];
error_program = argv[0];
if (argc < 2)
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 */
}
}
}
/* Verbosity */
if (argv[fa][1] == 'v' || argv[fa][1] == 'V') {
verb = 1;
}
else if (argv[fa][1] == '?')
usage();
else
usage();
}
else
break;
}
if (fa >= argc || argv[fa][0] == '-') usage();
strncpy(in_name,argv[fa++],MAXNAMEL); in_name[MAXNAMEL] = '\000';
strcpy(out_name, in_name);
if ((xl = strrchr(out_name, '.')) == NULL) /* Figure where extention is */
xl = out_name + strlen(out_name);
xl[0] = '\000'; /* Remove extension */
/* Open up the file for reading */
if ((rd_fp = new_icmFileStd_name(&err,in_name,"r")) == NULL)
error ("Read: Can't open file '%s' (0x%x, '%s')",in_name,err.c,err.m);
if ((rd_icco = new_icc(&err)) == NULL)
error ("Read: Creation of ICC object failed (0x%x, '%s')",err.c,err.m);
/* Read the header and tag list */
if ((rv = rd_icco->read(rd_icco,rd_fp,0)) != 0)
error ("Read: %d, %s",rv,rd_icco->e.m);
/* Run the target Lab values through the bwd and fwd tables, */
/* to compute the overall error. */
{
#define GAMUT_LCENT 50.0
double merr = 0.0;
double aerr = 0.0;
double nsamps = 0.0;
icmLuSpace *luo1, *luo2;
int doaxes = 1;
vrml *wrl;
int i, j;
/* Get a Device to PCS conversion object */
if ((luo1 = (icmLuSpace *)rd_icco->get_luobj(rd_icco, icmFwd, icAbsoluteColorimetric, icSigLabData, icmLuOrdNorm)) == NULL) {
if ((luo1 = (icmLuSpace *)rd_icco->get_luobj(rd_icco, icmFwd, icmDefaultIntent, icSigLabData, icmLuOrdNorm)) == NULL)
error ("%d, %s",rd_icco->e.c, rd_icco->e.m);
}
/* Get details of conversion */
{
icmCSInfo ini, outi;
luo1->spaces(luo1, &ini, NULL, &outi, NULL, NULL, NULL, NULL, NULL, NULL);
ins = ini.sig;
outs = outi.sig;
}
if (ins != icSigCmykData) {
error("Expecting CMYK device");
}
/* Get a PCS to Device conversion object */
if ((luo2 = (icmLuSpace *)rd_icco->get_luobj(rd_icco, icmBwd, icAbsoluteColorimetric,
icSigLabData, icmLuOrdNorm)) == NULL) {
if ((luo2 = (icmLuSpace *)rd_icco->get_luobj(rd_icco, icmBwd, icmDefaultIntent,
icSigLabData, icmLuOrdNorm)) == NULL)
error ("%d, %s",rd_icco->e.c, rd_icco->e.m);
}
if ((wrl = new_vrml(out_name, doaxes, vrml_lab)) == NULL) {
error("new_vrml for '%s%s' failed\n",out_name,vrml_ext());
}
wrl->start_line_set(wrl, 0);
i = 0;
// for (co[0] = 0; co[0] < TRES; co[0]++) {
for (co[1] = 0; co[1] < TRES; co[1]++) {
for (co[2] = 0; co[2] < TRES; co[2]++) {
int rv1, rv2;
double mxd, absd;
// temp[0] = co[0]/(TRES-1.0);
temp[1] = co[1]/(TRES-1.0);
temp[2] = co[2]/(TRES-1.0);
// in[0] = temp[0] * 100.0;
in[0] = 0.0;
in[1] = 200.0 * temp[1] -100.0;
in[2] = 200.0 * temp[2] -100.0;
/* PCS -> Device */
if ((rv2 = luo2->lookup_fwd(luo2, out, in)) & icmPe_lurv_err)
error ("%d, %s",rd_icco->e.c,rd_icco->e.m);
/* Device -> PCS */
if ((rv1 = luo1->lookup_fwd(luo1, check, out)) & icmPe_lurv_err)
error ("%d, %s",rd_icco->e.c,rd_icco->e.m);
if (verb) {
printf("%f %f %f -> %f %f %f %f -> %f %f %f [%f]\n",
in[0],in[1],in[2],out[0],out[1],out[2],out[3],check[0],check[1],check[2],
maxdiff(check, in));
}
/* Check the result */
mxd = maxdiff(check, in);
if (mxd > merr)
merr = mxd;
nsamps++;
absd = absdiff(check, in);
aerr += absd;
if (absd > 3.0) {
wrl->add_vertex(wrl, 0, in);
wrl->add_vertex(wrl, 0, check);
i++;
}
}
}
// }
wrl->make_lines(wrl, 0, 2);
if (wrl->flush(wrl) != 0) {
fprintf(stderr,"Error writint output file '%s%s'\n",out_name,vrml_ext());
return 2;
}
wrl->del(wrl);
printf("bwd to fwd check complete, peak err = %f, avg err = %f\n",merr,aerr/nsamps);
/* Done with lookup object */
luo1->del(luo1);
luo2->del(luo2);
}
rd_icco->del(rd_icco);
rd_fp->del(rd_fp);
return 0;
}

View File

@@ -0,0 +1,971 @@
/*
* iccgamut
*
* Produce color surface gamut of an ICC profile.
*
* Author: Graeme W. Gill
* Date: 19/3/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:
* To support CIACAM02 properly, need to cope with viewing parameters ?
*/
#define SURFACE_ONLY
#define GAMRES 10.0 /* Default surface resolution */
#define USE_CAM_CLIP_OPT /* Use CAM space to clip in */
#define RGBRES 33 /* 33 */
#define CMYKRES 17 /* 17 */
#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 "conv.h"
#include "xicc.h"
#include "gamut.h"
#include "counters.h"
#include "vrml.h"
static void face_plot(icxLuBase *luo, double gamres, int doaxes, double trans, char *outname);
void usage(char *diag) {
int i;
fprintf(stderr,"Create ICC profile Lab/Jab gamut & plot Version %s\n",ARGYLL_VERSION_STR);
fprintf(stderr,"Author: Graeme W. Gill, licensed under the AGPL Version 3\n");
fprintf(stderr,"usage: iccgamut [options] profile\n");
if (diag != NULL)
fprintf(stderr,"Diagnostic: %s\n",diag);
fprintf(stderr," -v Verbose\n");
fprintf(stderr," -d sres Surface resolution details 1.0 - 50.0\n");
fprintf(stderr," -w emit %s %s file as well as CGATS .gam file\n",vrml_format(),vrml_ext());
fprintf(stderr," -n Don't add %s axes or white/black point\n",vrml_format());
fprintf(stderr," -k Add %s markers for prim. & sec. \"cusp\" points\n",vrml_format());
fprintf(stderr," (Set env. ARGYLL_3D_DISP_FORMAT to VRML, X3D or X3DOM to change format)\n");
fprintf(stderr," -e Create %s edge plot\n",vrml_format());
fprintf(stderr," -E Create %s all possible edge plot\n",vrml_format());
fprintf(stderr," -F Create %s face plot\n",vrml_format());
fprintf(stderr," -f function f = forward*, b = backwards\n");
fprintf(stderr," -i intent p = perceptual, r = relative colorimetric,\n");
fprintf(stderr," s = saturation, a = absolute (default), d = profile default\n");
// fprintf(stderr," P = absolute perceptual, S = absolute saturation\n");
fprintf(stderr," -p oride l = Lab_PCS (default), j = %s Appearance Jab\n",icxcam_description(cam_default));
fprintf(stderr," -o order n = normal (priority: lut > matrix > monochrome)\n");
fprintf(stderr," r = reverse (priority: monochrome > matrix > lut)\n");
fprintf(stderr," -l tlimit set total ink limit, 0 - 400%% (estimate by default)\n");
fprintf(stderr," -L klimit set black ink limit, 0 - 100%% (estimate by default)\n");
fprintf(stderr," -c viewcond set viewing conditions for %s,\n",icxcam_description(cam_default));
fprintf(stderr," either an enumerated choice, or a series of parameter:value changes\n");
for (i = 0; ; i++) {
icxViewCond vc;
if (xicc_enum_viewcond(NULL, &vc, i, NULL, 1, NULL) == -999)
break;
fprintf(stderr," %s\n",vc.desc);
}
fprintf(stderr," s:surround n = auto, a = average, m = dim, d = dark,\n");
fprintf(stderr," c = transparency (default average)\n");
fprintf(stderr," w:X:Y:Z Adapted white point as XYZ (default media white)\n");
fprintf(stderr," w:x:y Adapted white point as x, y\n");
fprintf(stderr," a:adaptation Adaptation luminance in cd.m^2 (default 50.0)\n");
fprintf(stderr," b:background Background %% of image luminance (default 20)\n");
fprintf(stderr," l:imagewhite Image white in cd.m^2 if surround = auto (default 250)\n");
fprintf(stderr," f:flare Flare light %% of image luminance (default 0)\n");
fprintf(stderr," g:glare Flare light %% of ambient (default %d)\n",XICC_DEFAULT_GLARE);
fprintf(stderr," g:X:Y:Z Flare color as XYZ (default media white, Abs: D50)\n");
fprintf(stderr," g:x:y Flare color as x, y\n");
fprintf(stderr," h:hkscale Helmholtz-Kohlrausch effect scale factor (default 1.0)\n");
fprintf(stderr," m:mtaf Mid-tone partial adaptation factor (default 0.0)\n");
fprintf(stderr," m:X:Y:Z Mid-tone Adaptation white as XYZ (default D50)\n");
fprintf(stderr," m:x:y Mid-tone Adaptation white as x, y\n");
fprintf(stderr," -x pcent Expand/compress gamut cylindrically by percent\n");
fprintf(stderr,"\n");
exit(1);
}
int
main(int argc, char *argv[]) {
int fa,nfa; /* argument we're looking at */
static char prof_name[MAXNAMEL+1];
static char *xl, out_name[MAXNAMEL+4+1];
icmFile *fp;
icc *icco;
icmErr err = { 0, { '\000'} };
xicc *xicco;
gamut *gam;
int verb = 0;
int rv = 0;
int dovrml = 0;
int doaxes = 1;
int docusps = 0;
double gamres = 0; /* Surface resolution */
int doedgepl = 0; /* Create edge plot */
int dofacepl = 0; /* Create face plot */
int special = 0; /* Special surface plot */
int fl = 0; /* luobj flags */
icxInk ink; /* Ink parameters */
int tlimit = -1; /* Total ink limit as a % */
int klimit = -1; /* Black ink limit as a % */
icxViewCond vc; /* Viewing Condition for CIECAM */
int vc_e = -1; /* Enumerated viewing condition */
int vc_s = -1; /* Surround override */
double vc_wXYZ[3] = {-1.0, -1.0, -1.0}; /* Adapted white override in XYZ */
double vc_wxy[2] = {-1.0, -1.0}; /* Adapted white override in x,y */
double vc_a = -1.0; /* Adapted luminance */
double vc_b = -1.0; /* Background % overide */
double vc_l = -1.0; /* Scene luminance override */
double vc_f = -1.0; /* Flare % overide */
double vc_g = -1.0; /* Glare % overide */
double vc_gXYZ[3] = {-1.0, -1.0, -1.0}; /* Glare color override in XYZ */
double vc_gxy[2] = {-1.0, -1.0}; /* Glare color override in x,y */
double vc_hkscale = -1.0; /* HK scaling factor */
double vc_mtaf = -1.0; /* Mid tone partial adapation factor from Wxyz to Wxyz2 */
double vc_Wxyz2[3] = {-1.0, -1.0, -1.0}; /* Adapted white override in XYZ */
double expand = 1.0; /* Expand gamut cylindrically */
icxLuBase *luo;
/* Lookup parameters */
icmLookupFunc func = icmFwd; /* Default */
icRenderingIntent intent = -1; /* Default */
icColorSpaceSignature pcsor = icSigLabData; /* Default */
icmLookupOrder order = icmLuOrdNorm; /* Default */
error_program = argv[0];
if (argc < 2)
usage("Too few parameters");
/* 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);
/* function */
else if (argv[fa][1] == 'f') {
fa = nfa;
if (na == NULL) usage("No parameter after flag -f");
switch (na[0]) {
case 'f':
case 'F':
func = icmFwd;
break;
case 'b':
case 'B':
func = icmBwd;
break;
default:
usage("Unrecognised parameter after flag -f");
}
}
/* Intent */
else if (argv[fa][1] == 'i') {
fa = nfa;
if (na == NULL) usage("No parameter after flag -i");
switch (na[0]) {
case 'd':
intent = icmDefaultIntent;
break;
case 'a':
intent = icAbsoluteColorimetric;
break;
case 'p':
intent = icPerceptual;
break;
case 'r':
intent = icRelativeColorimetric;
break;
case 's':
intent = icSaturation;
break;
/* Argyll special intents to check spaces underlying */
/* icxPerceptualAppearance & icxSaturationAppearance */
case 'P':
intent = icmAbsolutePerceptual;
break;
case 'S':
intent = icmAbsoluteSaturation;
break;
default:
usage("Unrecognised parameter after flag -i");
}
}
/* Search order */
else if (argv[fa][1] == 'o') {
fa = nfa;
if (na == NULL) usage("No parameter after flag -o");
switch (na[0]) {
case 'n':
case 'N':
order = icmLuOrdNorm;
break;
case 'r':
case 'R':
order = icmLuOrdRev;
break;
default:
usage("Unrecognised parameter after flag -o");
}
}
/* PCS override */
else if (argv[fa][1] == 'p') {
fa = nfa;
if (na == NULL) usage("No parameter after flag -p");
switch (na[0]) {
case 'l':
pcsor = icSigLabData;
break;
case 'j':
pcsor = icxSigJabData;
break;
default:
usage("Unrecognised parameter after flag -p");
}
}
/* Verbosity */
else if (argv[fa][1] == 'v') {
verb = 1;
}
/* VRML output */
else if (argv[fa][1] == 'w') {
dovrml = 1;
}
/* No axis output in vrml */
else if (argv[fa][1] == 'n') {
doaxes = 0;
}
/* Do cusp markers in vrml */
else if (argv[fa][1] == 'k') {
docusps = 1;
}
/* Edge plot */
else if (argv[fa][1] == 'e')
doedgepl = 1;
else if (argv[fa][1] == 'E')
doedgepl = 2;
/* Face plot */
else if (argv[fa][1] == 'F')
dofacepl = 1;
/* Special */
else if (argv[fa][1] == 's') {
special = 1;
}
/* Ink limit */
else if (argv[fa][1] == 'l') {
fa = nfa;
if (na == NULL) usage("No parameter after flag -l");
tlimit = atoi(na);
}
else if (argv[fa][1] == 'L') {
fa = nfa;
if (na == NULL) usage("No parameter after flag -L");
klimit = atoi(na);
}
/* Surface Detail */
else if (argv[fa][1] == 'd') {
fa = nfa;
if (na == NULL) usage("No parameter after flag -d");
gamres = atof(na);
if (gamres < 0.1 || gamres > 50.0)
usage("Parameter after flag -d seems out of range");
}
/* Expand gamut cylindrically */
else if (argv[fa][1] == 'x') {
double rr;
fa = nfa;
if (na == NULL) usage("No parameter after flag -x");
rr = atof(na)/100.0;
if (rr < 0.01 || rr > 100.0)
usage("-x ratio is out of range");
expand = rr;
}
/* Viewing conditions */
else if (argv[fa][1] == 'c') {
fa = nfa;
if (na == NULL) usage("No parameter after flag -c");
#ifdef NEVER
if (na[0] >= '0' && na[0] <= '9') {
vc_e = atoi(na);
} else
#endif
if (na[1] != ':') {
if ((vc_e = xicc_enum_viewcond(NULL, NULL, -2, na, 1, NULL)) == -999)
usage("Urecognised Enumerated Viewing conditions");
} else if (na[0] == 's' || na[0] == 'S') {
if (na[1] != ':')
usage("Unrecognised parameters after -cs");
if (na[2] == 'n' || na[2] == 'N') {
vc_s = vc_none; /* Automatic from Lv */
} else if (na[2] == 'a' || na[2] == 'A') {
vc_s = vc_average;
} else if (na[2] == 'm' || na[2] == 'M') {
vc_s = vc_dim;
} else if (na[2] == 'd' || na[2] == 'D') {
vc_s = vc_dark;
} else if (na[2] == 'c' || na[2] == 'C') {
vc_s = vc_cut_sheet;
} else
usage("Unrecognised parameters after -cs:");
} else if (na[0] == 'w' || na[0] == 'W') {
double x, y, z;
if (sscanf(na+1,":%lf:%lf:%lf",&x,&y,&z) == 3) {
vc_wXYZ[0] = x; vc_wXYZ[1] = y; vc_wXYZ[2] = z;
} else if (sscanf(na+1,":%lf:%lf",&x,&y) == 2) {
vc_wxy[0] = x; vc_wxy[1] = y;
} else
usage("Unrecognised parameters after -cw");
} else if (na[0] == 'a' || na[0] == 'A') {
if (na[1] != ':')
usage("Unrecognised parameters after -ca");
vc_a = atof(na+2);
} else if (na[0] == 'b' || na[0] == 'B') {
if (na[1] != ':')
usage("Unrecognised parameters after -cb");
vc_b = atof(na+2);
} else if (na[0] == 'l' || na[0] == 'L') {
if (na[1] != ':')
usage("Viewing conditions (-cl) missing ':'");
vc_l = atof(na+2);
} else if (na[0] == 'f' || na[0] == 'F') {
if (na[1] != ':')
usage("Viewing conditions (-cf) missing ':'");
vc_f = atof(na+2);
} else if (na[0] == 'g' || na[0] == 'G') {
double x, y, z;
if (sscanf(na+1,":%lf:%lf:%lf",&x,&y,&z) == 3) {
vc_gXYZ[0] = x; vc_gXYZ[1] = y; vc_gXYZ[2] = z;
} else if (sscanf(na+1,":%lf:%lf",&x,&y) == 2) {
vc_gxy[0] = x; vc_gxy[1] = y;
} else if (sscanf(na+1,":%lf",&x) == 1) {
vc_g = x;
} else
usage("Unrecognised parameters after -cg");
} else if (na[0] == 'h' || na[0] == 'H') {
if (na[1] != ':')
usage("Unrecognised parameters after -ch");
vc_hkscale = atof(na+2);
} else if (na[0] == 'm' || na[0] == 'M') {
double x, y, z;
if (sscanf(na+1,":%lf:%lf:%lf",&x,&y,&z) == 3) {
vc_Wxyz2[0] = x; vc_Wxyz2[1] = y; vc_Wxyz2[2] = z;
} else if (sscanf(na+1,":%lf:%lf",&x,&y) == 2) {
vc_Wxyz2[0] = x; vc_Wxyz2[1] = y; vc_Wxyz2[2] = -1;
} else if (sscanf(na+1,":%lf",&x) == 1) {
vc_mtaf = x;
} else
usage("Unrecognised parameters after -cm");
} else
usage("Unrecognised parameters after -c");
/* Make sure we output perceptual space */
pcsor = icxSigJabData;
}
else
usage("Unknown flag");
} else
break;
}
if (intent == -1) {
if (pcsor == icxSigJabData)
intent = icRelativeColorimetric; /* Default to icxAppearance */
else
intent = icAbsoluteColorimetric; /* Default to icAbsoluteColorimetric */
}
if (fa >= argc || argv[fa][0] == '-') usage("Expected profile name");
strncpy(prof_name, argv[fa],MAXNAMEL); prof_name[MAXNAMEL] = '\000';
/* Open up the profile for reading */
if ((fp = new_icmFileStd_name(&err, prof_name,"r")) == NULL)
error ("Can't open file '%s' (0x%x, '%s')",prof_name,err.c,err.m);
if ((icco = new_icc(&err)) == NULL)
error ("Creation of ICC object failed (0x%x, '%s')",err.c,err.m);
if ((rv = icco->read(icco,fp,0)) != 0)
error ("%d, %s",rv,icco->e.m);
if (verb) {
icmFile *op;
if ((op = new_icmFileStd_fp(&err, stdout)) == NULL)
error ("Can't open stdout (0x%x, '%s')",err.c,err.m);
icco->header->dump(icco->header, op, 1);
op->del(op);
}
/* Wrap with an expanded icc */
if ((xicco = new_xicc(icco)) == NULL)
error ("Creation of xicc failed");
/* Set the ink limits */
icxDefaultLimits(xicco, &ink.tlimit, tlimit/100.0, &ink.klimit, klimit/100.0);
if (verb) {
if (ink.tlimit >= 0.0)
printf("Total ink limit assumed is %3.0f%%\n",100.0 * ink.tlimit);
if (ink.klimit >= 0.0)
printf("Black ink limit assumed is %3.0f%%\n",100.0 * ink.klimit);
}
/* Setup a safe ink generation (not used) */
ink.KonlyLmin = 0; /* Use normal black Lmin for locus */
ink.k_rule = icxKluma5k;
ink.c.Ksmth = ICXINKDEFSMTH; /* Default smoothing */
ink.c.Kskew = ICXINKDEFSKEW; /* default curve skew */
ink.c.Kstle = 0.0; /* Min K at white end */
ink.c.Kstpo = 0.0; /* Start of transition is at white */
ink.c.Kenle = 1.0; /* Max K at black end */
ink.c.Kenpo = 1.0; /* End transition at black */
ink.c.Kshap = 1.0; /* Linear transition */
/* Setup the default viewing conditions */
if (xicc_enum_viewcond(xicco, &vc, -1, NULL, 0, NULL) == -2)
error ("%d, %s",xicco->e.c, xicco->e.m);
if (vc_e != -1)
if (xicc_enum_viewcond(xicco, &vc, vc_e, NULL, 0, NULL) == -2)
error ("%d, %s",xicco->e.c, xicco->e.m);
if (vc_s >= 0)
vc.Ev = vc_s;
if (vc_wXYZ[1] > 0.0) {
/* Normalise it to current media white */
vc.Wxyz[0] = vc_wXYZ[0]/vc_wXYZ[1] * vc.Wxyz[1];
vc.Wxyz[2] = vc_wXYZ[2]/vc_wXYZ[1] * vc.Wxyz[1];
}
if (vc_wxy[0] >= 0.0) {
double x = vc_wxy[0];
double y = vc_wxy[1]; /* If Y == 1.0, then X+Y+Z = 1/y */
double z = 1.0 - x - y;
vc.Wxyz[0] = x/y * vc.Wxyz[1];
vc.Wxyz[2] = z/y * vc.Wxyz[1];
}
if (vc_a >= 0.0)
vc.La = vc_a;
if (vc_b >= 0.0)
vc.Yb = vc_b/100.0;
if (vc_l >= 0.0)
vc.Lv = vc_l;
if (vc_f >= 0.0)
vc.Yf = vc_f/100.0;
if (vc_g >= 0.0)
vc.Yg = vc_g/100.0;
if (vc_gXYZ[1] > 0.0) {
/* Normalise it to current media white */
vc.Gxyz[0] = vc_gXYZ[0]/vc_gXYZ[1] * vc.Gxyz[1];
vc.Gxyz[2] = vc_gXYZ[2]/vc_gXYZ[1] * vc.Gxyz[1];
}
if (vc_gxy[0] >= 0.0) {
double x = vc_gxy[0];
double y = vc_gxy[1]; /* If Y == 1.0, then X+Y+Z = 1/y */
double z = 1.0 - x - y;
vc.Gxyz[0] = x/y * vc.Gxyz[1];
vc.Gxyz[2] = z/y * vc.Gxyz[1];
}
if (vc_hkscale >= 0.0)
vc.hkscale = vc_hkscale;
if (vc_mtaf >= 0.0)
vc.mtaf = vc_mtaf;
if (vc_Wxyz2[0] >= 0.0 && vc_Wxyz2[1] > 0.0 && vc_Wxyz2[2] >= 0.0) {
/* Normalise XYZ */
vc.Wxyz2[0] = vc_Wxyz2[0]/vc_Wxyz2[1] * vc.Wxyz2[1];
vc.Wxyz2[2] = vc_Wxyz2[2]/vc_Wxyz2[1] * vc.Wxyz2[1];
}
if (vc_Wxyz2[0] >= 0.0 && vc_Wxyz2[1] >= 0.0 && vc_Wxyz2[2] < 0.0) {
/* Convert Yxy to XYZ */
double x = vc_Wxyz2[0];
double y = vc_Wxyz2[1]; /* If Y == 1.0, then X+Y+Z = 1/y */
double z = 1.0 - x - y;
vc.Wxyz2[0] = x/y * vc.Wxyz2[1];
vc.Wxyz2[2] = z/y * vc.Wxyz2[1];
}
fl |= ICX_CLIP_NEAREST; /* Don't setup rev uncessarily */
#ifdef USE_CAM_CLIP_OPT
fl |= ICX_CAM_CLIP;
#endif
#ifdef NEVER
printf("~1 output space flags = 0x%x\n",fl);
printf("~1 output space intent = %s\n",icx2str(icmRenderingIntent,intent));
printf("~1 output space pcs = %s\n",icx2str(icmColorSpaceSig,pcsor));
printf("~1 output space viewing conditions =\n"); xicc_dump_viewcond(&vc);
printf("~1 output space inking =\n"); xicc_dump_inking(&ink);
#endif
strcpy(out_name, prof_name);
if ((xl = strrchr(out_name, '.')) == NULL) /* Figure where extention is */
xl = out_name + strlen(out_name);
strcpy(xl,".gam");
/* Get a expanded color conversion object */
if ((luo = xicco->get_luobj(xicco, fl, func, intent, pcsor, order, &vc, &ink)) == NULL)
error ("%d, %s",xicco->e.c, xicco->e.m);
{
double gres = gamres;
if (gres == 0.0)
gres = GAMRES;
/* Creat a gamut surface */
if ((gam = luo->get_gamut(luo, gres)) == NULL)
error ("%d, %s",xicco->e.c, xicco->e.m);
if (verb) {
double cs_wp[3], cs_bp[3];
double ga_wp[3], ga_bp[3];
if (gam->getwb(gam, cs_wp, cs_bp, NULL, ga_wp, ga_bp, NULL)) {
fprintf(stderr,"gamut map: Unable to read gamut white and black points\n");
} else {
printf(" Colorspace white/black are %f %f %f, %f %f %f\n",
cs_wp[0], cs_wp[1], cs_wp[2], cs_bp[0], cs_bp[1], cs_bp[2]);
printf(" Gamut white/black are %f %f %f, %f %f %f\n\n",
ga_wp[0], ga_wp[1], ga_wp[2], ga_bp[0], ga_bp[1], ga_bp[2]);
}
}
/* Expand gamut cylindrically */
if (expand != 1.0) {
gamut *xgam;
if ((xgam = new_gamut(1.0, 0, 0)) == NULL
|| xgam->exp_cyl(xgam, gam, expand)) {
error ("Creating expanded gamut failed");
}
gam->del(gam);
gam = xgam;
}
if (gam->write_gam(gam, out_name))
error ("write gamut failed on '%s'",out_name);
if (dovrml) {
xl[0] = '\000'; /* remove extension */
if (gam->write_vrml(gam,out_name, doaxes, docusps))
error ("write vrml failed on '%s%s'",out_name, vrml_ext());
}
if (verb) {
printf("Total volume of gamut is %f cubic colorspace units\n",gam->volume(gam));
}
gam->del(gam);
}
/* Create separate plot of edges */
if (doedgepl == 1) {
vrml *wrl = NULL;
char *xl, edge_name[MAXNAMEL+1];
int docusps = 1;
double in[MAX_CHAN], out[MAX_CHAN];
int devn;
double gres = gamres;
int lres;
int cc, i, j;
if (gres <= 0.0)
gres = 5.0;
lres = (int)(100.0/gres + 0.5);
if (lres < 1)
lres = 1;
strcpy(edge_name, prof_name);
if ((xl = strrchr(edge_name, '.')) == NULL) /* Figure where extention is */
xl = edge_name + strlen(edge_name);
strcpy(xl,"_e");
luo->spaces(luo, NULL, &devn, NULL, NULL, NULL, NULL, NULL, NULL);
wrl = new_vrml(edge_name, doaxes, vrml_lab);
/* For all verticies minus one dimension */
for (cc = 0; cc < (1 << (devn-1)); cc++) {
/* For the other dimension being each channel */
for (i = 0; i < devn; i++) {
int ii, mm;
/* Set static input values */
for (mm = 1, ii = 0; ii < devn; ii++) {
if (i == ii)
continue; /* Skip channel we're going to step along */
if (cc & mm)
in[ii] = 1.0;
else
in[ii] = 0.0;
mm <<= 1;
}
wrl->start_line_set(wrl, 0);
/* Step along the edge */
for (j = 0; j < lres; j++) {
in[i] = j/(lres-1.0);
luo->lookup(luo, out, in);
wrl->add_vertex(wrl, 0, out);
}
wrl->make_last_vertex(wrl, 0);
wrl->make_lines(wrl, 0, 0);
}
}
wrl->del(wrl);
/* All possible edges */
} else if (doedgepl == 2) {
vrml *wrl = NULL;
char *xl, edge_name[MAXNAMEL+1];
int docusps = 1;
double in[MAX_CHAN], out[MAX_CHAN];
int devn;
double gres = gamres;
int lres;
int c1, c2, i, j;
if (gres <= 0.0)
gres = 5.0;
lres = (int)(100.0/gres + 0.5);
if (lres < 1)
lres = 1;
strcpy(edge_name, prof_name);
if ((xl = strrchr(edge_name, '.')) == NULL) /* Figure where extention is */
xl = edge_name + strlen(edge_name);
strcpy(xl,"_e");
luo->spaces(luo, NULL, &devn, NULL, NULL, NULL, NULL, NULL, NULL);
wrl = new_vrml(edge_name, doaxes, vrml_lab);
/* For all verticies */
for (c1 = 0; c1 < (1 << devn)-1; c1++) {
/* For all other verticies */
for (c2 = c1 + 1; c2 < (1 << devn); c2++) {
double p1[MAX_CHAN], p2[MAX_CHAN];
int ii, mm;
/* Set static input values */
for (mm = 1, ii = 0; ii < devn; ii++) {
if (c1 & mm)
p1[ii] = 1.0;
else
p1[ii] = 0.0;
if (c2 & mm)
p2[ii] = 1.0;
else
p2[ii] = 0.0;
mm <<= 1;
}
wrl->start_line_set(wrl, 0);
/* Step along the edge */
for (j = 0; j < lres; j++) {
double bl = j/(lres-1.0);
vect_blend(in, p1, p2, bl, devn);
luo->lookup(luo, out, in);
wrl->add_vertex(wrl, 0, out);
}
wrl->make_last_vertex(wrl, 0);
wrl->make_lines(wrl, 0, 0);
}
}
wrl->del(wrl);
}
if (dofacepl) {
vrml *wrl = NULL;
char *xl, face_name[MAXNAMEL+1];
double trans = 0.0; /* Transparency */
if (gamres <= 0.0)
gamres = 20.0;
strcpy(face_name, prof_name);
if ((xl = strrchr(face_name, '.')) == NULL) /* Figure where extention is */
xl = face_name + strlen(face_name);
strcpy(xl,"_f");
face_plot(luo, gamres, doaxes, trans, face_name);
}
luo->del(luo); /* Done with lookup object */
xicco->del(xicco); /* Expansion wrapper */
icco->del(icco); /* Icc */
fp->del(fp);
return 0;
}
/* -------------------------------------------- */
#define GAMUT_LCENT 50
/* Create a face gamut, illustrating */
/* device space "fold-over" */
/* (This will be in the current PCS, but assumed to be Lab) */
static void face_plot(
icxLuBase *luo,
double detail, /* Gamut resolution detail */
int doaxes,
double trans, /* Transparency */
char *outname /* Output VRML/X3D file (no extension) */
) {
int i, j;
vrml *wrl;
int vix; /* Vertex index */
int nix; /* Node index */
int fix;
double col[MPP_MXCCOMB][3]; /* Color asigned to each major vertex */
int n, nn;
int res;
DCOUNT(coa, MAX_CHAN, 0, 0, 0, 2);
luo->spaces(luo, NULL, &n, NULL, NULL, NULL, NULL, NULL, NULL);
n = n;
nn = 1 << n;
coa_di = n;
/* Asign some colors to the combination nodes */
for (i = 0; i < nn; i++) {
int a, b, c, j;
double h;
j = (i ^ 0x5a5a5a5a) % nn;
h = (double)j/(nn-1);
/* Make fully saturated with chosen hue */
if (h < 1.0/3.0) {
a = 0;
b = 1;
c = 2;
} else if (h < 2.0/3.0) {
a = 1;
b = 2;
c = 0;
h -= 1.0/3.0;
} else {
a = 2;
b = 0;
c = 1;
h -= 2.0/3.0;
}
h *= 3.0;
col[i][a] = (1.0 - h);
col[i][b] = h;
col[i][c] = d_rand(0.0, 1.0);
}
if (detail > 0.0)
res = (int)(100.0/detail); /* Establish an appropriate sampling density */
else
res = 4;
if (res < 2)
res = 2;
if ((wrl = new_vrml(outname, doaxes, vrml_lab)) == NULL)
error("new_vrml faile for file '%s%s'",outname,vrml_ext());
wrl->start_line_set(wrl, 0);
/* Itterate over all the faces in the device space */
/* generating the vertex positions. */
DC_INIT(coa);
vix = 0;
nix = 0;
fix = 0;
while(!DC_DONE(coa)) {
int e, m1, m2;
double in[MAX_CHAN];
double out[3];
double sum;
double xb, yb;
/* Scan only device surface */
for (m1 = 0; m1 < n; m1++) {
if (coa[m1] != 0)
continue;
for (m2 = m1 + 1; m2 < n; m2++) {
int x, y;
double fcol[3];
if (coa[m2] != 0)
continue;
for (sum = 0.0, e = 0; e < n; e++)
in[e] = (double)coa[e]; /* Base value */
fcol[0] = d_rand(0.0, 1.0);
fcol[1] = d_rand(0.0, 1.0);
fcol[2] = d_rand(0.0, 1.0);
fix++;
/* Scan over 2D device space face */
for (x = 0; x < res; x++) { /* step over surface */
xb = in[m1] = x/(res - 1.0);
for (y = 0; y < res; y++) {
int v0, v1, v2, v3;
double rgb[3];
yb = in[m2] = y/(res - 1.0);
/* Lookup PCS value */
luo->lookup(luo, out, in);
#ifdef NEVER
/* Create a color */
for (v0 = 0, e = 0; e < n; e++)
v0 |= coa[e] ? (1 << e) : 0; /* Binary index */
v1 = v0 | (1 << m2); /* Y offset */
v2 = v0 | (1 << m2) | (1 << m1); /* X+Y offset */
v3 = v0 | (1 << m1); /* Y offset */
/* Linear interp between the main vertices */
for (j = 0; j < 3; j++) {
rgb[j] = (1.0 - yb) * (1.0 - xb) * col[v0][j]
+ yb * (1.0 - xb) * col[v1][j]
+ (1.0 - yb) * xb * col[v3][j]
+ yb * xb * col[v2][j];
}
wrl->add_col_vertex(wrl, 0, out, rgb);
#else
wrl->add_col_vertex(wrl, 0, out, fcol);
#endif
vix++;
}
}
}
}
/* Increment index within block */
DC_INC(coa);
nix++;
}
/* Itterate over all the faces in the device space */
/* generating the quadrilateral indexes. */
DC_INIT(coa);
vix = 0;
while(!DC_DONE(coa)) {
int e, m1, m2;
double in[MAX_CHAN];
double sum;
/* Scan only device surface */
for (m1 = 0; m1 < n; m1++) {
if (coa[m1] != 0)
continue;
for (m2 = m1 + 1; m2 < n; m2++) {
int x, y;
if (coa[m2] != 0)
continue;
for (sum = 0.0, e = 0; e < n; e++)
in[e] = (double)coa[e]; /* Base value */
/* Scan over 2D device space face */
for (x = 0; x < res; x++) { /* step over surface */
for (y = 0; y < res; y++) {
if (x < (res-1) && y < (res-1)) {
int ix[4];
/* Hmm. add both directions to avoid figuring orientation... */
ix[0] = vix;
ix[1] = vix + 1;
ix[2] = vix + 1 + res;
ix[3] = vix + res;
wrl->add_quad(wrl, 0, ix);
ix[0] = vix;
ix[1] = vix + res;
ix[2] = vix + 1 + res;
ix[3] = vix + 1;
wrl->add_quad(wrl, 0, ix);
}
vix++;
}
}
}
}
/* Increment index within block */
DC_INC(coa);
}
wrl->make_quads_vc(wrl, 0, trans);
if (wrl->flush(wrl) != 0)
error("Error closing output file '%s%s'",outname,vrml_ext());
wrl->del(wrl);
}

View File

@@ -0,0 +1,271 @@
/*
Little CMS
Copyright (c) 1998-2010 Marti Maria Saguer
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and as
sociated documentation files (the "Software"), to deal in the Software without restriction, includin
g without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subj
ect to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial
portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NO
T LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABI
LITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WIT
H THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
/*
* iccjpeg.c
*
* This file provides code to read and write International Color Consortium
* (ICC) device profiles embedded in JFIF JPEG image files. The ICC has
* defined a standard format for including such data in JPEG "APP2" markers.
* The code given here does not know anything about the internal structure
* of the ICC profile data; it just knows how to put the profile data into
* a JPEG file being written, or get it back out when reading.
*
* This code depends on new features added to the IJG JPEG library as of
* IJG release 6b; it will not compile or work with older IJG versions.
*
* NOTE: this code would need surgery to work on 16-bit-int machines
* with ICC profiles exceeding 64K bytes in size. If you need to do that,
* change all the "unsigned int" variables to "INT32". You'll also need
* to find a malloc() replacement that can allocate more than 64K.
*/
#include "iccjpeg.h"
#include <stdlib.h> /* define malloc() */
/*
* Since an ICC profile can be larger than the maximum size of a JPEG marker
* (64K), we need provisions to split it into multiple markers. The format
* defined by the ICC specifies one or more APP2 markers containing the
* following data:
* Identifying string ASCII "ICC_PROFILE\0" (12 bytes)
* Marker sequence number 1 for first APP2, 2 for next, etc (1 byte)
* Number of markers Total number of APP2's used (1 byte)
* Profile data (remainder of APP2 data)
* Decoders should use the marker sequence numbers to reassemble the profile,
* rather than assuming that the APP2 markers appear in the correct sequence.
*/
#define ICC_MARKER (JPEG_APP0 + 2) /* JPEG marker code for ICC */
#define ICC_OVERHEAD_LEN 14 /* size of non-profile data in APP2 */
#define MAX_BYTES_IN_MARKER 65533 /* maximum data len of a JPEG marker */
#define MAX_DATA_BYTES_IN_MARKER (MAX_BYTES_IN_MARKER - ICC_OVERHEAD_LEN)
/*
* This routine writes the given ICC profile data into a JPEG file.
* It *must* be called AFTER calling jpeg_start_compress() and BEFORE
* the first call to jpeg_write_scanlines().
* (This ordering ensures that the APP2 marker(s) will appear after the
* SOI and JFIF or Adobe markers, but before all else.)
*/
void
write_icc_profile (j_compress_ptr cinfo,
const JOCTET *icc_data_ptr,
unsigned int icc_data_len)
{
unsigned int num_markers; /* total number of markers we'll write */
int cur_marker = 1; /* per spec, counting starts at 1 */
unsigned int length; /* number of bytes to write in this marker */
/* Calculate the number of markers we'll need, rounding up of course */
num_markers = icc_data_len / MAX_DATA_BYTES_IN_MARKER;
if (num_markers * MAX_DATA_BYTES_IN_MARKER != icc_data_len)
num_markers++;
while (icc_data_len > 0) {
/* length of profile to put in this marker */
length = icc_data_len;
if (length > MAX_DATA_BYTES_IN_MARKER)
length = MAX_DATA_BYTES_IN_MARKER;
icc_data_len -= length;
/* Write the JPEG marker header (APP2 code and marker length) */
jpeg_write_m_header(cinfo, ICC_MARKER,
(unsigned int) (length + ICC_OVERHEAD_LEN));
/* Write the marker identifying string "ICC_PROFILE" (null-terminated).
* We code it in this less-than-transparent way so that the code works
* even if the local character set is not ASCII.
*/
jpeg_write_m_byte(cinfo, 0x49);
jpeg_write_m_byte(cinfo, 0x43);
jpeg_write_m_byte(cinfo, 0x43);
jpeg_write_m_byte(cinfo, 0x5F);
jpeg_write_m_byte(cinfo, 0x50);
jpeg_write_m_byte(cinfo, 0x52);
jpeg_write_m_byte(cinfo, 0x4F);
jpeg_write_m_byte(cinfo, 0x46);
jpeg_write_m_byte(cinfo, 0x49);
jpeg_write_m_byte(cinfo, 0x4C);
jpeg_write_m_byte(cinfo, 0x45);
jpeg_write_m_byte(cinfo, 0x0);
/* Add the sequencing info */
jpeg_write_m_byte(cinfo, cur_marker);
jpeg_write_m_byte(cinfo, (int) num_markers);
/* Add the profile data */
while (length--) {
jpeg_write_m_byte(cinfo, *icc_data_ptr);
icc_data_ptr++;
}
cur_marker++;
}
}
/*
* Prepare for reading an ICC profile
*/
void
setup_read_icc_profile (j_decompress_ptr cinfo)
{
/* Tell the library to keep any APP2 data it may find */
jpeg_save_markers(cinfo, ICC_MARKER, 0xFFFF);
}
/*
* Handy subroutine to test whether a saved marker is an ICC profile marker.
*/
static boolean
marker_is_icc (jpeg_saved_marker_ptr marker)
{
return
marker->marker == ICC_MARKER &&
marker->data_length >= ICC_OVERHEAD_LEN &&
/* verify the identifying string */
GETJOCTET(marker->data[0]) == 0x49 &&
GETJOCTET(marker->data[1]) == 0x43 &&
GETJOCTET(marker->data[2]) == 0x43 &&
GETJOCTET(marker->data[3]) == 0x5F &&
GETJOCTET(marker->data[4]) == 0x50 &&
GETJOCTET(marker->data[5]) == 0x52 &&
GETJOCTET(marker->data[6]) == 0x4F &&
GETJOCTET(marker->data[7]) == 0x46 &&
GETJOCTET(marker->data[8]) == 0x49 &&
GETJOCTET(marker->data[9]) == 0x4C &&
GETJOCTET(marker->data[10]) == 0x45 &&
GETJOCTET(marker->data[11]) == 0x0;
}
/*
* See if there was an ICC profile in the JPEG file being read;
* if so, reassemble and return the profile data.
*
* TRUE is returned if an ICC profile was found, FALSE if not.
* If TRUE is returned, *icc_data_ptr is set to point to the
* returned data, and *icc_data_len is set to its length.
*
* IMPORTANT: the data at **icc_data_ptr has been allocated with malloc()
* and must be freed by the caller with free() when the caller no longer
* needs it. (Alternatively, we could write this routine to use the
* IJG library's memory allocator, so that the data would be freed implicitly
* at jpeg_finish_decompress() time. But it seems likely that many apps
* will prefer to have the data stick around after decompression finishes.)
*
* NOTE: if the file contains invalid ICC APP2 markers, we just silently
* return FALSE. You might want to issue an error message instead.
*/
boolean
read_icc_profile (j_decompress_ptr cinfo,
JOCTET **icc_data_ptr,
unsigned int *icc_data_len)
{
jpeg_saved_marker_ptr marker;
int num_markers = 0;
int seq_no;
JOCTET *icc_data;
unsigned int total_length;
#define MAX_SEQ_NO 255 /* sufficient since marker numbers are bytes */
char marker_present[MAX_SEQ_NO+1]; /* 1 if marker found */
unsigned int data_length[MAX_SEQ_NO+1]; /* size of profile data in marker */
unsigned int data_offset[MAX_SEQ_NO+1]; /* offset for data in marker */
*icc_data_ptr = NULL; /* avoid confusion if FALSE return */
*icc_data_len = 0;
/* This first pass over the saved markers discovers whether there are
* any ICC markers and verifies the consistency of the marker numbering.
*/
for (seq_no = 1; seq_no <= MAX_SEQ_NO; seq_no++)
marker_present[seq_no] = 0;
for (marker = cinfo->marker_list; marker != NULL; marker = marker->next) {
if (marker_is_icc(marker)) {
if (num_markers == 0)
num_markers = GETJOCTET(marker->data[13]);
else if (num_markers != GETJOCTET(marker->data[13]))
return FALSE; /* inconsistent num_markers fields */
seq_no = GETJOCTET(marker->data[12]);
if (seq_no <= 0 || seq_no > num_markers)
return FALSE; /* bogus sequence number */
if (marker_present[seq_no])
return FALSE; /* duplicate sequence numbers */
marker_present[seq_no] = 1;
data_length[seq_no] = marker->data_length - ICC_OVERHEAD_LEN;
}
}
if (num_markers == 0)
return FALSE;
/* Check for missing markers, count total space needed,
* compute offset of each marker's part of the data.
*/
total_length = 0;
for (seq_no = 1; seq_no <= num_markers; seq_no++) {
if (marker_present[seq_no] == 0)
return FALSE; /* missing sequence number */
data_offset[seq_no] = total_length;
total_length += data_length[seq_no];
}
if (total_length <= 0)
return FALSE; /* found only empty markers? */
/* Allocate space for assembled data */
icc_data = (JOCTET *) malloc(total_length * sizeof(JOCTET));
if (icc_data == NULL)
return FALSE; /* oops, out of memory */
/* and fill it in */
for (marker = cinfo->marker_list; marker != NULL; marker = marker->next) {
if (marker_is_icc(marker)) {
JOCTET FAR *src_ptr;
JOCTET *dst_ptr;
unsigned int length;
seq_no = GETJOCTET(marker->data[12]);
dst_ptr = icc_data + data_offset[seq_no];
src_ptr = marker->data + ICC_OVERHEAD_LEN;
length = data_length[seq_no];
while (length--) {
*dst_ptr++ = *src_ptr++;
}
}
}
*icc_data_ptr = icc_data;
*icc_data_len = total_length;
return TRUE;
}

View File

@@ -0,0 +1,73 @@
/*
* iccprofile.h
*
* This file provides code to read and write International Color Consortium
* (ICC) device profiles embedded in JFIF JPEG image files. The ICC has
* defined a standard format for including such data in JPEG "APP2" markers.
* The code given here does not know anything about the internal structure
* of the ICC profile data; it just knows how to put the profile data into
* a JPEG file being written, or get it back out when reading.
*
* This code depends on new features added to the IJG JPEG library as of
* IJG release 6b; it will not compile or work with older IJG versions.
*
* NOTE: this code would need surgery to work on 16-bit-int machines
* with ICC profiles exceeding 64K bytes in size. See iccprofile.c
* for details.
*/
#include <stdio.h> /* needed to define "FILE", "NULL" */
#include "jpeglib.h"
/*
* This routine writes the given ICC profile data into a JPEG file.
* It *must* be called AFTER calling jpeg_start_compress() and BEFORE
* the first call to jpeg_write_scanlines().
* (This ordering ensures that the APP2 marker(s) will appear after the
* SOI and JFIF or Adobe markers, but before all else.)
*/
extern void write_icc_profile JPP((j_compress_ptr cinfo,
const JOCTET *icc_data_ptr,
unsigned int icc_data_len));
/*
* Reading a JPEG file that may contain an ICC profile requires two steps:
*
* 1. After jpeg_create_decompress() but before jpeg_read_header(),
* call setup_read_icc_profile(). This routine tells the IJG library
* to save in memory any APP2 markers it may find in the file.
*
* 2. After jpeg_read_header(), call read_icc_profile() to find out
* whether there was a profile and obtain it if so.
*/
/*
* Prepare for reading an ICC profile
*/
extern void setup_read_icc_profile JPP((j_decompress_ptr cinfo));
/*
* See if there was an ICC profile in the JPEG file being read;
* if so, reassemble and return the profile data.
*
* TRUE is returned if an ICC profile was found, FALSE if not.
* If TRUE is returned, *icc_data_ptr is set to point to the
* returned data, and *icc_data_len is set to its length.
*
* IMPORTANT: the data at **icc_data_ptr has been allocated with malloc()
* and must be freed by the caller with free() when the caller no longer
* needs it. (Alternatively, we could write this routine to use the
* IJG library's memory allocator, so that the data would be freed implicitly
* at jpeg_finish_decompress() time. But it seems likely that many apps
* will prefer to have the data stick around after decompression finishes.)
*/
extern boolean read_icc_profile JPP((j_decompress_ptr cinfo,
JOCTET **icc_data_ptr,
unsigned int *icc_data_len));

340
Argyll_V3.5.0/xicc/icheck.c Normal file
View File

@@ -0,0 +1,340 @@
/*
* Argyll.
*
* Check for B2A table PCS->Device interpolation faults
*
* Author: Graeme W. Gill
* Date: 2000/12/11
* Version: 1.00
*
* Copyright 2000,2025 Graeme W. Gill
* Please refer to License.txt file for details.
*/
/*
Estimate PCS->device interpolation error by comparing
the interpolated PCS value in the cell to the PCS computed
from the corners of the cell.
*/
/* TTBD:
*
*/
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <fcntl.h>
#include <string.h>
#include <math.h>
#include "numlib.h"
#include "copyright.h"
#include "aconfig.h"
#include "icc.h"
#include "vrml.h"
void usage(void) {
fprintf(stderr,"Check PCS->Device Interpolation faults of ICC file, Version %s\n",ARGYLL_VERSION_STR);
fprintf(stderr,"Author: Graeme W. Gill, licensed under the AGPL Version 3\n");
fprintf(stderr,"usage: icheck [-v] [-w] infile\n");
fprintf(stderr," -v verbose\n");
fprintf(stderr," -a Show all interpolation errors, not just worst\n");
fprintf(stderr," -w create %s visualisation\n",vrml_format());
fprintf(stderr," -x Use %s axies\n",vrml_format());
exit(1);
}
int
main(
int argc,
char *argv[]
) {
int fa,nfa; /* argument we're looking at */
int verb = 0;
int doall = 0;
int dovrml = 0;
int doaxes = 0;
static char in_name[MAXNAMEL+1];
static char out_name[MAXNAMEL+1], *xl;
icmFile *rd_fp;
icc *rd_icco;
icmErr err = { 0, { '\000'} };
int i, rv = 0;
/* Check variables */
icmLuSpace *luof, *luob; /* A2B and B2A table lookups */
icmPeClut *lluof, *lluob; /* cLut Pe */
icmPeContainer *ltuof, *ltuob; /* tail transforms after cluts */
int gres[MAX_CHAN]; /* Grid resolution of B2A */
icColorSpaceSignature ins, outs; /* Type of input and output spaces */
int inn; /* Number of input chanels */
vrml *wrl = NULL;
error_program = argv[0];
if (argc < 2)
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 */
}
}
}
/* Verbosity */
if (argv[fa][1] == 'v' || argv[fa][1] == 'V') {
verb = 1;
}
/* VRML/X3D */
else if (argv[fa][1] == 'w' || argv[fa][1] == 'W') {
dovrml = 1;
}
/* Axes */
else if (argv[fa][1] == 'x' || argv[fa][1] == 'X') {
doaxes = 1;
}
else if (argv[fa][1] == 'a') {
doall = 1;
}
else if (argv[fa][1] == '?')
usage();
else
usage();
}
else
break;
}
if (fa >= argc || argv[fa][0] == '-') usage();
strncpy(in_name,argv[fa++],MAXNAMEL); in_name[MAXNAMEL] = '\000';
strcpy(out_name, in_name);
if ((xl = strrchr(out_name, '.')) == NULL) /* Figure where extention is */
xl = out_name + strlen(out_name);
xl[0] = '\000'; /* Remove extension */
/* Open up the file for reading */
if ((rd_fp = new_icmFileStd_name(&err, in_name,"r")) == NULL)
error ("Read: Can't open file '%s' (0x%x, '%s')",in_name,err.c,err.m);
if ((rd_icco = new_icc(&err)) == NULL)
error ("Read: Creation of ICC object failed (0x%x, '%s')",err.c,err.m);
/* Read the header and tag list */
if ((rv = rd_icco->read(rd_icco,rd_fp,0)) != 0)
error ("Read: %d, %s",rv,rd_icco->e.m);
/* Get a Device to PCS conversion object */
if ((luof = (icmLuSpace *)rd_icco->get_luobj(rd_icco, icmFwd, icAbsoluteColorimetric, icSigLabData, icmLuOrdNorm)) == NULL) {
if ((luof = (icmLuSpace *)rd_icco->get_luobj(rd_icco, icmFwd, icmDefaultIntent, icSigLabData, icmLuOrdNorm)) == NULL)
error ("%d, %s",rd_icco->e.c, rd_icco->e.m);
}
/* Get a PCS to Device conversion object */
if ((luob = (icmLuSpace *)rd_icco->get_luobj(rd_icco, icmBwd, icAbsoluteColorimetric, icSigLabData, icmLuOrdNorm)) == NULL) {
if ((luob = (icmLuSpace *)rd_icco->get_luobj(rd_icco, icmBwd, icmDefaultIntent, icSigLabData, icmLuOrdNorm)) == NULL)
error ("%d, %s",rd_icco->e.c, rd_icco->e.m);
}
/* Get details of conversion (for B2A direction) */
{
icmCSInfo ini, outi;
luob->spaces(luob, &outi, &ini, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
outs = outi.sig;
ins = ini.sig;
inn = ini.nch;
}
if (outs != icSigLabData) {
error("Expecting Lab PCS");
}
if ((lluof = luof->get_lut(luof, &ltuof)) == NULL)
error("Forward transform doesn't contain cLut");
if ((lluob = luob->get_lut(luob, &ltuob)) == NULL)
error("Backwards transform doesn't contain cLut");
for (i = 0; i < inn; i++)
gres[i] = lluob->clutPoints[i];
if (dovrml) {
wrl = new_vrml(out_name, doaxes, vrml_lab);
if (wrl == NULL)
error("new_vrml failed for '%s%s'",out_name,vrml_ext());
wrl->start_line_set(wrl, 0);
}
{
double aerr = 0.0;
double ccount = 0.0;
double merr = 0.0;
double tcount = 0.0;
int co[3]; /* PCS grid counter */
/* Itterate throught the PCS clut grid cells */
for (co[2] = 0; co[2] < (gres[2]-1); co[2]++) {
for (co[1] = 0; co[1] < (gres[1]-1); co[1]++) {
for (co[0] = 0; co[0] < (gres[0]-1); co[0]++) {
int j, k, m;
int cc[3]; /* Cube corner offsets */
double pcs[8][3], wpcsd;
double apcs[3];
double adev[MAX_CHAN];
double check[3]; /* Check PCS */
double ier; /* Interpolation error */
apcs[0] = apcs[1] = apcs[2] = 0.0;
for (k = 0; k < inn; k++)
adev[k] = 0.0;
/* For each corner of the PCS grid based at the current point, */
/* average the PCS and Device values */
m = 0;
for (cc[2] = 0; cc[2] < 2; cc[2]++) {
for (cc[1] = 0; cc[1] < 2; cc[1]++) {
for (cc[0] = 0; cc[0] < 2; cc[0]++, m++) {
double dev[MAX_CHAN];
pcs[m][0] = (co[0] + cc[0])/(gres[0] - 1.0);
pcs[m][1] = (co[1] + cc[1])/(gres[1] - 1.0);
pcs[m][2] = (co[2] + cc[2])/(gres[2] - 1.0);
/* Match icclib settable() range */
pcs[m][0] = pcs[m][0] * 100.0;
pcs[m][1] = (pcs[m][1] * 254.0) - 127.0;
pcs[m][2] = (pcs[m][2] * 254.0) - 127.0;
//printf("Input PCS %f %f %f\n", pcs[m][0], pcs[m][1], pcs[m][2]);
/* PCS to (cliped) Device */
if ((rv = lluob->lookup_fwd(lluob, dev, pcs[m])) & icmPe_lurv_err)
error ("%d, %s",rd_icco->e.c,rd_icco->e.m);
/* (clipped) Device to (clipped) PCS */
if ((rv = lluof->lookup_fwd(lluof, pcs[m], dev)) & icmPe_lurv_err)
error ("%d, %s",rd_icco->e.c,rd_icco->e.m);
apcs[0] += pcs[m][0];
apcs[1] += pcs[m][1];
apcs[2] += pcs[m][2];
//printf("Corner PCS %f %f %f -> %f %f %f %f\n",
//pcs[m][0], pcs[m][1], pcs[m][2], dev[0], dev[1], dev[2], dev[3]);
for (k = 0; k < inn; k++)
adev[k] += dev[k];
}
}
}
for (j = 0; j < 3; j++)
apcs[j] /= 8.0;
for (k = 0; k < inn; k++)
adev[k] /= 8.0;
/* Compute worst case distance of PCS corners to PCS of average dev */
wpcsd = 0.0;
for (m = 0; m < 8; m++) {
double ss;
for (ss = 0.0, j = 0; j < 3; j++) {
double tt = pcs[m][j] - apcs[j];
ss += tt * tt;
}
ss = sqrt(ss);
if (ss > wpcsd)
wpcsd = ss;
}
wpcsd *= 0.15; /* Set threshold at 75% of most distant corner */
//printf("~1 wpcsd = %f\n",wpcsd);
/* Set a worst case */
if (wpcsd < 1.0)
wpcsd = 1.0;
// else if (wpcsd > 3.0)
// wpcsd = 3.0;
//printf("Average PCS %f %f %f, Average Device %f %f %f %f\n",
//apcs[0], apcs[1], apcs[2], adev[0], adev[1], adev[2], adev[3]);
/* Average Device to PCS */
if ((rv = lluof->lookup_fwd(lluof, check, adev)) & icmPe_lurv_err)
error ("%d, %s",rd_icco->e.c,rd_icco->e.m);
//printf("Check PCS %f %f %f\n",
//check[0], check[1], check[2]);
/* Compute error in PCS vs. Device interpolation */
for (ier = 0.0, j = 0; j < 3; j++) {
double tt = apcs[j] - check[j];
ier += tt * tt;
}
ier = sqrt(ier);
//printf("Average PCS %f %f %f, Check PCS %f %f %f, error %f\n",
//apcs[0], apcs[1], apcs[2], check[0], check[1], check[2], ier);
aerr += ier;
ccount++;
if (ier > merr)
merr = ier;
if (doall || ier > wpcsd) {
tcount++;
printf("ier = %f, Dev = %f %f %f %f\n",
ier, adev[0], adev[1], adev[2], adev[3]);
if (dovrml) {
wrl->add_vertex(wrl, 0, apcs);
wrl->add_vertex(wrl, 0, check);
}
}
//printf("~1 ier = %f\n",ier);
//printf("\n");
if (verb)
printf("."), fflush(stdout);
}
}
}
if (dovrml) {
wrl->make_lines(wrl, 0, 2);
wrl->del(wrl);
}
aerr /= ccount;
printf("Average interpolation error %f, maximum %f\n",aerr, merr);
printf("Number outside corner radius = %f%%\n",tcount * 100.0/ccount);
}
/* Done with lookup objects */
luof->del(luof);
luob->del(luob);
rd_icco->del(rd_icco);
rd_fp->del(rd_fp);
return 0;
}

View File

@@ -0,0 +1,263 @@
/*
* Author: Graeme Gill
* Date: 30/10/2005
*
* Copyright 2005 Graeme W. Gill
* Parts derived from rspl/c1.c, cv.c etc.
*
* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :-
* see the License.txt file for licencing details.
*
* Test monocurve class.
*
*/
#undef DIAG
#undef TEST_SYM
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <math.h>
#include "copyright.h"
#include "aconfig.h"
#include "numlib.h"
#include "moncurve.h"
#include "plot.h"
#include "ui.h"
double lin(double x, double xa[], double ya[], int n);
void usage(void);
#define TRIALS 30 /* Number of random trials */
#define SKIP 0 /* Number of random trials to skip */
#undef NORMONLY /* Defined to use 0.0 - 1.0 limited curve */
#undef ORDER_STEP /* Step orders from 2 to SHAPE_ORDERS */
//#define SHAPE_ORDS 30 /* Number of order to use */
#define SHAPE_ORDS 12 /* Number of order to use */
#define ABS_MAX_PNTS 100
#define MIN_PNTS 2
#define MAX_PNTS 20
#define MIN_RES 20
#define MAX_RES 500
double xa[ABS_MAX_PNTS];
double ya[ABS_MAX_PNTS];
#define XRES 100
#define TSETS 3 /* Number of special test sets */
#define PNTS 11
#define GRES 100
int t1p[TSETS] = {
4,
11,
11
};
double t1xa[TSETS][PNTS] = {
{ 0.0, 0.2, 0.8, 1.0 },
{ 0.0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0 },
{ 0.0, 0.25, 0.30, 0.35, 0.40, 0.44, 0.48, 0.51, 0.64, 0.75, 1.0 }
};
double t1ya[TSETS][PNTS] = {
{ 0.0, 0.5, 0.6, 1.0 },
{ 0.0, 0.0, 0.5, 0.5, 0.5, 0.5, 0.5, 0.8, 1.0, 1.0, 1.0 },
{ 0.0, 0.35, 0.4, 0.41, 0.42, 0.46, 0.5, 0.575, 0.48, 0.75, 1.0 }
};
mcvco test_points[ABS_MAX_PNTS];
double lin(double x, double xa[], double ya[], int n);
void
usage(void) {
puts("usage: monctest");
exit(1);
}
int main() {
mcv *p;
int i, n;
double x, y;
double xx[XRES];
double y1[XRES];
double y2[XRES];
int np = SHAPE_ORDS; /* Number of harmonics */
error_program = "monctest";
#ifdef NORMONLY
printf("Testing fixed offset = 0 and scale = 1.0\n");
if ((p = new_mcv_noos()) == NULL)
#else
if ((p = new_mcv()) == NULL)
#endif
error("new_mcv failed");
for (n = 0; n < TRIALS; n++) {
double lrand; /* Amount of level randomness */
int pnts;
if (n < TSETS) /* Standard versions */ {
pnts = t1p[n];
for (i = 0; i < pnts; i++) {
xa[i] = t1xa[n][i];
ya[i] = t1ya[n][i];
}
} else if (n == TSETS) { /* Exponential function aproximation */
double ex = 2.4;
pnts = MAX_PNTS;
printf("Trial %d, no points = %d, exponential %f\n",n,pnts,ex);
/* Create X values */
for (i = 0; i < pnts; i++)
xa[i] = pow(i/(pnts-1.0), 1.0);
for (i = 0; i < pnts; i++)
ya[i] = pow(xa[i], ex);
} else if (n == TSETS + 1) { /* inverse exponential function aproximation */
double ex = 1.0/2.4;
pnts = MAX_PNTS;
printf("Trial %d, no points = %d, exponential %f\n",n,pnts,ex);
/* Create X values */
for (i = 0; i < pnts; i++)
xa[i] = pow(i/(pnts-1.0), 3.0);
for (i = 0; i < pnts; i++)
ya[i] = pow(xa[i], ex);
} else { /* Random versions */
double ymax;
lrand = d_rand(0.0,0.2); /* Amount of level randomness */
lrand *= lrand;
pnts = i_rand(MIN_PNTS,MAX_PNTS);
printf("Trial %d, no points = %d, level randomness = %f\n",n,pnts,lrand);
/* Create X values */
xa[0] = 0.0;
for (i = 1; i < pnts; i++)
xa[i] = xa[i-1] + d_rand(0.5,1.0);
for (i = 0; i < pnts; i++) /* Divide out */
xa[i] = (xa[i]/xa[pnts-1]);
/* Create y values */
ya[0] = xa[0] + d_rand(-0.2, 0.7);
for (i = 1; i < pnts; i++)
ya[i] = ya[i-1] + d_rand(0.1,1.0) + d_rand(-0.1,0.4) + d_rand(-0.4,0.5);
ymax = d_rand(0.6, 10.2); /* Scale target */
for (i = 0; i < pnts; i++) {
ya[i] = ymax * (ya[i]/ya[pnts-1]);
// if (ya[i] < 0.0)
// ya[i] = 0.0;
// else if (ya[i] > 1.0)
// ya[i] = 1.0;
}
}
if (n < SKIP)
continue;
for (i = 0; i < pnts; i++) {
test_points[i].p = xa[i];
test_points[i].v = ya[i];
test_points[i].w = 1.0;
}
/* Test weighting */
test_points[pnts-1].w = 1.0;
#ifdef ORDER_STEP
for (np = 2; np <= SHAPE_ORDS; np++) {
#else /* Full number of orders */
for (np = SHAPE_ORDS; np <= SHAPE_ORDS; np++) {
#endif
/* Fit to scattered data */
p->fit(p,
1, /* Vebose */
np, /* Number of curve parameters */
test_points, /* Test points */
pnts, /* Number of test points */
1.0 /* Smoothing */
);
printf("Residual = %f\n",p->resid);
printf("Total number of params = %d\n",p->luord);
for (i = 0; i < p->luord; i++) {
printf("Param %d = %f\n",i,p->pms[i]);
}
/* Display the result */
for (i = 0; i < XRES; i++) {
x = i/(double)(XRES-1);
xx[i] = x;
y1[i] = lin(x,xa,ya,pnts);
y2[i] = p->interp(p, x);
y = p->inv_interp(p, y2[i]);
if (fabs(x - y) > 0.00001)
printf("Inverse mismatch: %f -> %f -> %f\n",x,y2[i],y);
// if (y2[i] < -0.2)
// y2[i] = -0.2;
// else if (y2[i] > 1.2)
// y2[i] = 1.2;
}
do_plot(xx,y1,y2,NULL,XRES);
}
} /* next trial */
p->del(p);
return 0;
}
double lin(
double x,
double xa[],
double ya[],
int n) {
int i;
double y;
if (x < xa[0])
return ya[0];
else if (x > xa[n-1])
return ya[n-1];
for (i = 0; i < (n-1); i++)
if (x >=xa[i] && x <= xa[i+1])
break;
x = (x - xa[i])/(xa[i+1] - xa[i]);
y = ya[i] + (ya[i+1] - ya[i]) * x;
return y;
}

View File

@@ -0,0 +1,691 @@
/*
* Argyll Color Management System
* Monotonic curve class for display calibration.
*
* Author: Graeme W. Gill
* Date: 30/10/2005
*
* Copyright 2005 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.
*
* This is based on the monotonic curve equations used elsewhere,
* but currently intended to support the display calibration process.
* moncurve is not currently general, missing input scaling.
*
*/
#undef DEBUG /* Input points */
#undef DEBUG2 /* Detailed progress */
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <math.h>
#include "copyright.h"
#include "aconfig.h"
#include "numlib.h"
#include "moncurve.h"
#define POWTOL 1e-5 /* [1e-5] Powell optimiser tollerance (was 1e-5 ?) */
#define MAXITS 10000 /* [10000] */
#define USE_CONJGRAD /* [def] Else use Powell */
#ifdef USE_CONJGRAD
# undef TEST_PDE /* [und] Check partial derivative calcs */
#endif
#define HW01 0.01 /* 0 & 1 harmonic weights */
#define HBREAK 3 /* Harmonic that has HWBR */
#define HWBR 0.5 /* Base weight of harmonics HBREAK up */
#define HWINC 0.7 /* Increase in weight for each harmonic above HWBR */
static void mcv_del(mcv *p);
static void mcv_fit(mcv *p, int verb, int order, mcvco *d, int ndp, double smooth);
static void mcv_force_0(mcv *p, double target);
static void mcv_force_1(mcv *p, double target);
static void mcv_force_scale(mcv *p, double target);
static int mcv_get_params(mcv *p, double **rp);
static double mcv_interp(struct _mcv *p, double in);
static double mcv_inv_interp(struct _mcv *p, double in);
static double mcv_interp_p(struct _mcv *p, double *pms, double in);
static double mcv_shweight_p(mcv *p, double *v, double smooth);
double mcv_dinterp_p(mcv *p, double *pms, double *dv, double vv);
static double mcv_dshweight_p(mcv *p, double *v, double *dv, double smooth);
/* Set parameter counts etc. given p->luord and flags */
static void set_counts(mcv *p) {
p->cvemin = 2; /* Curve params start here in full param array */
if (p->noos)
p->fitmin = 2; /* Params to fit start here in full param array */
else
p->fitmin = 0; /* Params to fit start here in full param array */
p->fitcvemin = p->cvemin - p->fitmin; /* Index of first curve parameter in fit array */
p->nfitp = p->luord - p->fitmin; /* Number of params to fit */
#ifdef DEBUG
printf("noos = %d\n",p->noos);
printf("luord = %d\n",p->luord);
printf("fitmin = %d\n",p->fitmin);
printf("nfitp = %d\n",p->nfitp);
printf("cvemin = %d\n",p->cvemin);
printf("fitcvemin = %d\n",p->fitcvemin);
#endif
}
/* Create a new, uninitialised mcv that will fit with offset and scale */
/* (Note thate black and white points aren't allocated) */
mcv *new_mcv(void) {
mcv *p;
if ((p = (mcv *)calloc(1, sizeof(mcv))) == NULL)
return NULL;
/* Init method pointers */
p->del = mcv_del;
p->fit = mcv_fit;
p->force_0 = mcv_force_0;
p->force_1 = mcv_force_1;
p->force_scale = mcv_force_scale;
p->get_params = mcv_get_params;
p->interp = mcv_interp;
p->inv_interp = mcv_inv_interp;
p->interp_p = mcv_interp_p;
p->shweight_p = mcv_shweight_p;
p->dinterp_p = mcv_dinterp_p;
p->dshweight_p = mcv_dshweight_p;
p->luord = 0;
p->pms = NULL;
return p;
}
/* Create a new mcv initiated with the given total parameters */
/* that include offset & scale. */
mcv *new_mcv_p(double *pp, int np) {
int i;
mcv *p;
if ((p = new_mcv()) == NULL)
return p;
p->luord = np;
if ((p->pms = (double *)calloc(p->luord, sizeof(double))) == NULL)
error ("Malloc failed");
for (i = 0; i < np; i++)
p->pms[i] = *pp++;
set_counts(p);
return p;
}
/* Create a new, uninitialised mcv with offset and scale not to be fitted, */
/* with these defaulting to 0.0 and 1.0 */
/* (Note thate black and white points aren't allocated) */
mcv *new_mcv_noos(void) {
mcv *p;
if ((p = new_mcv()) == NULL)
return p;
p->noos = 2;
return p;
}
/* Delete an mcv */
static void mcv_del(mcv *p) {
if (p->pms != NULL)
free(p->pms);
free(p);
}
#ifdef TEST_PDE
# pragma message("!!!!!!!!!!!! TEST_PDE is enabled !!!!!!!!!!!")
# define mcv_opt_func mcv_opt_func_
#endif
/* Shaper optimisation function handed to powell() */
static double mcv_opt_func(void *edata, double *v) {
mcv *p = (mcv *)edata;
double totw = 0.0;
double ev = 0.0, rv, smv;
double out;
int i;
#ifdef DEBUG2
printf("params =");
for (i = 0; i < p->nfitp; i++)
printf(" %f",v[i]);
printf("\n");
#endif
/* For all our data points */
for (i = 0; i < p->ndp; i++) {
double del;
/* Apply our function */
out = p->interp_p(p, v, p->d[i].p);
del = out - p->d[i].v;
ev += p->d[i].w * del * del;
totw += p->d[i].w;
}
/* Normalise error to be an average delta E squared */
totw = (100.0 * 100.0)/(p->dra * p->dra * totw);
ev *= totw;
/* Sum with shaper parameters squared, to */
/* minimise unsconstrained "wiggles" */
smv = mcv_shweight_p(p, v, p->smooth);
rv = ev + smv;
#ifdef DEBUG2
printf("rv = %f (er %f + sm %f)\n",rv,ev,smv);
#endif
return rv;
}
/* Shaper optimisation function handed to conjgrad() */
static double mcv_dopt_func(void *edata, double *dv, double *v) {
mcv *p = (mcv *)edata;
double totw = 0.0;
double ev = 0.0, rv, smv;
double out;
int i, j;
#ifdef DEBUG2
printf("params =");
for (i = 0; i < (p->nfitp); i++)
printf(" %f",v[i]);
printf("\n");
#endif
/* Zero the dv's */
for (j = 0; j < p->nfitp; j++)
dv[j] = 0.0;
/* For all our data points */
for (i = 0; i < p->ndp; i++) {
double del;
/* Apply our function with dv's */
out = p->dinterp_p(p, v, p->dv, p->d[i].p);
//printf("~1 point %d: p %f, v %f, func %f\n",i,p->d[i].p,p->d[i].v,out);
del = out - p->d[i].v;
ev += p->d[i].w * del * del;
//printf("~1 del %f, ev %f\n",del,ev);
/* Sum the dv's */
for (j = 0; j < p->nfitp; j++) {
dv[j] += p->d[i].w * 2.0 * del * p->dv[j];
//printf("~1 dv[%d] = %f\n",j,dv[j]);
}
totw += p->d[i].w;
}
//printf("~1 totw = %f, dra = %f\n",totw, p->dra);
/* Normalise error to be an average delta E squared */
totw = (100.0 * 100.0)/(p->dra * p->dra * totw);
ev *= totw;
for (j = 0; j < p->nfitp; j++) {
dv[j] *= totw;
//printf("~1 norm dv[%d] = %f\n",j,dv[j]);
}
/* Sum with shaper parameters squared, to */
/* minimise unsconstrained "wiggles", */
/* with partial derivatives */
smv = mcv_dshweight_p(p, v, dv, p->smooth);
rv = ev + smv;
#ifdef DEBUG2
printf("drv = %f (er %f + sm %f)\n",rv,ev,smv);
#endif
return rv;
}
#ifdef TEST_PDE
/* Check partial derivative function */
#undef mcv_opt_func
static double mcv_opt_func(void *edata, double *v) {
mcv *p = (mcv *)edata;
int i;
double dv[500];
double rv, drv;
double trv;
rv = mcv_opt_func_(edata, v);
drv = mcv_dopt_func(edata, dv, v);
if (fabs(rv - drv) > 1e-6)
printf("######## RV MISMATCH is %f should be %f ########\n",rv,drv);
/* Check each parameter delta */
for (i = 0; i < p->nfitp; i++) {
double del;
v[i] += 1e-7;
trv = mcv_opt_func_(edata, v);
v[i] -= 1e-7;
/* Check that del is correct */
del = (trv - rv)/1e-7;
if (fabs(dv[i] - del) > 0.04) {
//printf("~1 del = %f from (trv %f - rv %f)/0.1\n",del,trv,rv);
printf("######## DV EXCESSIVE at v[%d] is %f should be %f ########\n",i,dv[i],del);
}
}
return rv;
}
#endif /* TEST_PDE */
/* Fit the curve to the given points */
static void mcv_fit(mcv *p,
int verb, /* Vebosity level, 0 = none */
int order, /* Number of curve orders, 1..MCV_MAXORDER */
mcvco *d, /* Array holding scattered initialisation data */
int ndp, /* Number of data points */
double smooth /* Degree of smoothing, 1.0 = normal */
) {
int i;
double *sa; /* Search area */
double *pms; /* Parameters to optimise */
double min, max;
p->verb = verb;
p->smooth = smooth;
p->luord = order+2; /* Add two for offset and scale */
set_counts(p);
if (p->pms != NULL)
free(p->pms);
if ((p->pms = (double *)calloc(p->luord, sizeof(double))) == NULL)
error ("Malloc failed");
if ((pms = (double *)calloc(p->luord, sizeof(double))) == NULL)
error ("Malloc failed");
if ((sa = (double *)calloc(p->luord, sizeof(double))) == NULL)
error ("Malloc failed");
if ((p->dv = (double *)calloc(p->luord, sizeof(double))) == NULL)
error ("Malloc failed");
#ifdef DEBUG
printf("mcv_fit with %d points (noos = %d)\n",ndp,p->noos);
#endif
/* Establish the range of data values */
min = 1e38; /* Locate min, and make that offset */
max = -1e38; /* Locate max */
for (i = 0; i < ndp; i++) {
if (d[i].v < min)
min = d[i].v;
if (d[i].v > max)
max = d[i].v;
#ifdef DEBUG
printf("point %d is %f %f\n",i,d[i].p,d[i].v);
#endif
}
if (p->noos) {
p->pms[0] = min = 0.0;
p->pms[1] = max = 1.0;
} else {
/* Set offset and scale to reasonable initial values */
p->pms[0] = min;
p->pms[1] = max - min;
}
p->dra = max - min;
if (p->dra <= 1e-12)
error("Mcv max - min %e too small",p->dra);
/* Use powell to minimise the sum of the squares of the */
/* input points to the curvem, plus a parameter damping factor. */
p->d = d;
p->ndp = ndp;
for (i = 0; i < p->luord; i++)
sa[i] = 0.2;
#ifdef USE_CONJGRAD
if (conjgrad(&p->resid, p->nfitp, p->pms+p->fitmin, sa+p->fitmin, POWTOL, MAXITS,
mcv_opt_func, mcv_dopt_func, (void *)p, NULL, NULL) != 0) {
#ifndef NEVER
fprintf(stderr,"Mcv fit conjgrad failed with %d points:\n",ndp);
for (i = 0; i < ndp; i++) {
fprintf(stderr," %d: %f -> %f\n",i,d->p, d->v);
}
#endif
error ("Mcv fit conjgrad failed");
}
#else
if (powell(&p->resid, p->nfitp, p->pms+p->fitmin, sa+p->fitmin, POWTOL, MAXITS,
mcv_opt_func, (void *)p, NULL, NULL) != 0)
error ("Mcv fit powell failed");
#endif
free(p->dv);
p->dv = NULL;
free(sa);
free(pms);
}
/* The native values from the curve parameters are 0 - 1.0, */
/* then the scale is applied, then the offset added, so the */
/* output always ranges from (offset) to (offset + scale). */
/* Offset the the output so that the value for input 0.0, */
/* is the given value. Don't change the output for 1.0 */
void mcv_force_0(
mcv *p,
double target /* Target output value */
) {
if (p->luord > 0) {
target -= p->pms[0]; /* Change */
if (p->luord > 1)
p->pms[1] -= target; /* Adjust scale to leave 1.0 output untouched */
p->pms[0] += target; /* Adjust offset */
}
}
/* Scale the the output so that the value for input 1.0, */
/* is the given target value. Don't change the output for 0.0 */
static void mcv_force_1(
mcv *p,
double target /* Target output value */
) {
if (p->luord > 1) {
target -= p->pms[0]; /* Offset */
p->pms[1] = target; /* Scale */
}
}
/* Scale the the output so that the value for input 1.0, */
/* is the given target value. Scale the value for 0 in proportion. */
static void mcv_force_scale(
mcv *p,
double target /* Target output value */
) {
if (p->luord > 1) {
p->pms[0] *= target/(p->pms[0] + p->pms[1]); /* Offset */
p->pms[1] = target - p->pms[0]; /* Scale */
}
}
/* Return the number of parameters and the parameters in */
/* an allocated array. free() when done. */
/* The parameters are the offset, scale, then all the other parameters */
static int mcv_get_params(mcv *p, double **rp) {
double *pp;
int np, i;
np = p->luord;
if ((pp = (double *)malloc(np * sizeof(double))) == NULL)
error("mcb_get_params malloc failed");
*rp = pp;
for (i = 0; i < np; i++)
*pp++ = p->pms[i];
return np;
}
/* Translate a value through the curve */
/* using the currently set pms */
static double mcv_interp(struct _mcv *p,
double vv /* Input value */
) {
return mcv_interp_p(p, p->pms + p->fitmin, vv);
}
/* Translate a value backwards through the current curve */
static double mcv_inv_interp(struct _mcv *p,
double vv /* Input value */
) {
double g;
int pix;
/* Process everything in reverse order to mcv_interp */
if (p->noos == 0) {
/* Undo order 0 & 1, the offset and scale */
vv -= p->pms[0];
vv /= p->pms[1];
}
for (pix = p->luord-1; pix >= p->cvemin; pix--) {
int nsec; /* Number of sections */
double sec; /* Section */
g = -p->pms[pix]; /* Inverse parameter */
nsec = 1 + pix - p->cvemin; /* Increase sections for each order */
vv *= (double)nsec;
sec = floor(vv);
if (((int)sec) & 1)
g = -g; /* Alternate action in each section */
vv -= sec;
if (g >= 0.0) {
vv = vv/(g - g * vv + 1.0);
} else {
vv = (vv - g * vv)/(1.0 - g * vv);
}
vv += sec;
vv /= (double)nsec;
}
return vv;
}
/* Translate a value through the curve */
/* using the given fit parameters */
static double mcv_interp_p(
mcv *p,
double *pms, /* Fit parameters to use - may exclude offset, scale and slope */
double vv /* Input value */
) {
double g;
int pix;
/* Process all the shaper orders from low to high. */
/* [These shapers were inspired by a Graphics Gem idea */
/* (Gems IV, VI.3, "Fast Alternatives to Perlin's Bias and */
/* Gain Functions, pp 401). */
/* They have the nice properties that they are smooth, and */
/* are monotonic. The control parameter has been */
/* altered to have a range from -oo to +oo rather than 0.0 to 1.0 */
/* so that the search space is less non-linear. */
for (pix = p->fitcvemin; pix < p->nfitp; pix++) {
int nsec; /* Number of sections */
double sec; /* Section */
g = pms[pix]; /* Parameter */
nsec = 1 + pix - p->fitcvemin; /* Increase sections for each order */
vv *= (double)nsec;
sec = floor(vv);
if (((int)sec) & 1)
g = -g; /* Alternate action in each section */
vv -= sec;
if (g >= 0.0) {
vv = vv/(g - g * vv + 1.0);
} else {
vv = (vv - g * vv)/(1.0 - g * vv);
}
vv += sec;
vv /= (double)nsec;
}
if (p->noos == 0) {
vv *= pms[1]; /* Scale */
vv += pms[0]; /* Offset */
}
return vv;
}
/* Return the shaper parameters regularizing weight */
static double mcv_shweight_p(
mcv *p,
double *pms, /* Fit parameters to use - may exclude offset and scale */
double smooth) {
double smv;
int pix;
/* Sum with shaper parameters squared, to */
/* minimise unsconstrained "wiggles" */
/* Note:- we start at 2, to skip offset and scale. */
smv = 0.0;
for (pix = p->fitcvemin; pix < p->nfitp; pix++) {
double w, tt;
int cx; /* Curve index starting at 0 */
cx = pix - p->fitcvemin;
tt = pms[pix];
/* Weigh to suppress ripples */
if (cx <= 1) {
w = HW01;
} else if (cx <= HBREAK) {
double bl = (cx - 1.0)/(HBREAK - 1.0);
w = (1.0 - bl) * HW01 + bl * HWBR * smooth;
} else {
w = HWBR + (cx-HBREAK) * HWINC * smooth;
}
tt *= tt;
smv += w * tt;
}
return smv;
}
/* Transfer function with partial derivative */
/* with respect to the given parameters. */
double mcv_dinterp_p(mcv *p,
double *pms, /* Fit parameters to use - may exclude offset, scale and slope */
double *dv, /* Return derivative wrt each parameter - may exclude offset and scale */
double vv /* Source of value */
) {
double g;
int pix, i;
/* Process all the shaper orders from low to high. */
for (pix = p->fitcvemin; pix < p->nfitp; pix++) {
double dsv; /* del for del in g */
double ddv; /* del for del in vv */
int nsec; /* Number of sections */
double sec; /* Section */
g = pms[pix]; /* Parameter */
nsec = 1 + pix - p->fitcvemin; /* Increase sections for each order */
vv *= (double)nsec;
sec = floor(vv);
if (((int)sec) & 1) {
g = -g; /* Alternate action in each section */
}
vv -= sec;
if (g >= 0.0) {
double tt = g - g * vv + 1.0;
dsv = (vv * vv - vv)/(tt * tt);
ddv = (g + 1.0)/(tt * tt);
vv = vv/tt;
} else {
double tt = 1.0 - g * vv;
dsv = (vv * vv - vv)/(tt * tt);
ddv = (1.0 - g)/(tt * tt);
vv = (vv - g * vv)/tt;
}
vv += sec;
vv /= (double)nsec;
dsv /= (double)nsec;
if (((int)sec) & 1)
dsv = -dsv;
dv[pix] = dsv;
for (i = pix - 1; i >= p->fitcvemin; i--)
dv[i] *= ddv;
}
if (p->noos == 0) {
/* Scale */
if (p->luord > 1) {
dv[1] = vv;
for (i = 2; i < p->nfitp; i++)
dv[i] *= pms[1];
vv *= pms[1];
}
/* Offset */
if (p->luord > 0) {
dv[0] = 1.0;
vv += pms[0];
}
}
return vv;
}
/* Return the shaper parameters regularizing weight, */
/* and add in partial derivatives. */
/* Weight error and derivatrive by wht */
static double mcv_dshweight_p(
mcv *p,
double *pms, /* Fit parameters to use - may exclude offset and scale */
double *dpms,
double smooth) {
double smv;
int pix;
/* Sum with shaper parameters squared, to */
/* minimise unsconstrained "wiggles", */
/* with partial derivatives */
smv = 0.0;
for (pix = p->fitcvemin; pix < p->nfitp; pix++) {
double w, tt;
int cx; /* Curve index starting at 0 */
cx = pix - p->fitcvemin;
tt = pms[pix];
/* Weigh to suppress ripples */
if (cx <= 1) { /* First or second curves */
w = HW01;
} else if (cx <= HBREAK) { /* First or second curves */
double bl = (cx - 1.0)/(HBREAK - 1.0);
w = (1.0 - bl) * HW01 + bl * HWBR * smooth;
} else {
w = HWBR + (cx-HBREAK) * HWINC * smooth;
}
dpms[pix] += w * 2.0 * tt;
tt *= tt;
smv += w * tt;
}
return smv;
}

View File

@@ -0,0 +1,123 @@
#ifndef MCV_H
#define MCV_H
/*
* Argyll Color Management System
* Monotonic curve class for display calibration.
*
* Author: Graeme W. Gill
* Date: 30/10/2005
*
* Copyright 2005 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.
*
* This is based on the monotonic curve equations used elsewhere,
* but currently intended to support the display calibration process.
* moncurve is not currently general, missing input scaling :-
* the input range is fixed at 0.0 .. 1.0.
*
*/
/* A test patch value */
typedef struct {
double p; /* Position */
double v; /* Value */
double w; /* Weighting, nominally 1.0 */
} mcvco;
struct _mcv {
/* Public: */
void (*del)(struct _mcv *p);
/* Fit the curve to the given points */
void (*fit) (struct _mcv *p,
int verb, /* Vebosity level, 0 = none */
int order, /* Number of curve orders, 1..MCV_MAXORDER */
mcvco *d, /* Array holding scattered initialisation data */
int ndp, /* Number of data points */
double smooth /* Degree of smoothing, 1.0 = normal */
);
/* Offset the the output so that the value for input 0.0, */
/* is the given value. Don't change the 1.0 output */
void (*force_0) (struct _mcv *p,
double target /* Target output value */
);
/* Scale the the output so that the value for input 1.0, */
/* is the given value. Don't change the 0.0 output */
void (*force_1) (struct _mcv *p,
double target /* Target output value */
);
/* Scale the the output so that the value for input 1.0, */
/* is the given target value. Scale the value for 0.0 too. */
void (*force_scale) (struct _mcv *p,
double target /* Target output value */
);
/* Return the number of parameters and the parameters in */
/* an allocated array. free() when done. */
/* The parameters are the offset, scale, (optionally slope) then all the other parameters */
int (*get_params)(struct _mcv *p, double **rp);
/* Translate a value through the current curve */
double (*interp) (struct _mcv *p,
double in); /* Input value */
/* Translate a value backwards through the current curve */
/* (Invalid for general curve) */
double (*inv_interp) (struct _mcv *p,
double in); /* Input value */
/* Translate a value given the parametrs */
double (*interp_p) (struct _mcv *p,
double *pms, double in); /* Input value */
/* return the shaper parameters normalising weight */
double (*shweight_p)(struct _mcv *p, double *v, double smooth);
/* Translate a value given the parametrs, with partial derivatives */
double (*dinterp_p) (struct _mcv *p, double *pms, double *dv, double vv);
/* return the shaper parameters normalising weight, with partial derivatives */
double (*dshweight_p)(struct _mcv *p, double *v, double *dv, double smooth);
/* Private: */
int verb; /* Verbose */
int noos; /* flag, 2 = offset and scale not fitted, fixed at 0 & 1 */
int luord; /* Number of params including offset, scale and (optionally) slope */
int fitmin; /* Index of first fit parameter in full param array */
int nfitp; /* Number of parameters to fit */
int cvemin; /* Index of first curve parameter in full param array */
int fitcvemin; /* Index of first curve parameter in fit array */
double *pms; /* Allocated curve parameters */
double *dv; /* Work space for dv's during optimisation */
double resid; /* Residual fit error */
mcvco *d; /* Array holding scattered initialisation data */
int ndp; /* Number of data points */
double dra; /* Data range */
double smooth; /* Smoothing factor */
}; typedef struct _mcv mcv;
/* Create a new, uninitialised mcv that will fit with offset and scale */
mcv *new_mcv(void);
/* Create a new mcv initiated with the given curve parameters */
mcv *new_mcv_p(double *pp, int np);
/* Create a new, uninitialised mcv with offset and scale not to be fitted, */
/* with these defaulting to 0.0 and 1.0 */
mcv *new_mcv_noos(void);
#endif /* MCV */

5100
Argyll_V3.5.0/xicc/mpp.c Normal file

File diff suppressed because it is too large Load Diff

292
Argyll_V3.5.0/xicc/mpp.h Normal file
View File

@@ -0,0 +1,292 @@
#ifndef MPP_H
#define MPP_H
/*
* Argyll Color Management System
* Model Printer Profile object.
*
* Author: Graeme W. Gill
* Date: 24/2/2002
*
* 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.
*
*/
/* This version (based on mpp_x1) has n * 2^(n-1) shape params, */
/* used for linear interpolation of the shaping correction. */
/*
* This object provides a model based printer forward profile
* functionality, to support forward profiling and optimised
* separation of printing devices with more than 4 inks.
*/
/* ------------------------------------------------------------------------------ */
#define MPP_MXINKS 8 /* Would like to be ICX_MXINKS but need more dynamic allocation */
#define MPP_MXTCORD 20 /* Maximum shaper harmonic orders to use */
#define MPP_MXCCOMB (1 << MPP_MXINKS) /* Maximum number of primary combinations */
#define MPP_MXPARMS (MPP_MXINKS * MPP_MXTCORD + (MPP_MXINKS * MPP_MXCCOMB/2) + MPP_MXCCOMB)
/* Maximum total parameters for a band */
#define MPP_MXBANDS 61 /* Maximum number of spectral bands (enought for 10nm) */
/* A test patch value */
typedef struct {
/* public: */
double *nv; /* [MPP_MXINKS] Device values */
double *band; /* [3+MPP_MXBANDS]; Target XYZ & Spectral reflectance values */
/* private: */
double w; /* Weight for this pass */
double *lband; /* [3+MPP_MXBANDS]; L* scale Target XYZ & Spectral reflectance values */
double Lab[3]; /* Target Lab value */
double tpcnv, tpcnv1; /* Intermediate values for band oba without channel och */
double *tcnv; /* [MPP_MXINKS] Transfer curve corrected device values */
double *scnv; /* [MPP_MXINKS] Ideal shape correction values for device input */
double *pcnv; /* [MPP_MXCCOMB] Primary combination values (pre or post shape) */
double *fcnv; /* [MPP_MXINKS * MPP_MXCCOMB/2] shape interpolation weights for och */
double cXYZ[3]; /* Current model XYZ value */
double err; /* Delta E squared */
} mppcol;
struct _mpp {
/* Public: */
int version; /* 1 */
void (*del)(struct _mpp *p);
/* Create the mpp from scattered data points */
/* Returns nz on error */
int (*create) (struct _mpp *p,
int verb, /* Vebosity level, 0 = none */
int quality, /* Profile quality, 0..3 */
int display, /* non-zero if display device */
double limit, /* Total ink limit (not %) (if not display) */
inkmask imask, /* Inkmask describing device colorspace */
int spec_n, /* Number of spectral bands, 0 if not valid */
double spec_wl_short, /* First reading wavelength in nm (shortest) */
double spec_wl_long, /* Last reading wavelength in nm (longest) */
double norm, /* Normalising scale value */
instType itype, /* Spectral instrument type (if not display) */
int no, /* Number of points */
mppcol *points); /* Array of input points */
int (*write_mpp)(struct _mpp *p, char *filename, int lab); /* write to a CGATS .mpp file */
int (*read_mpp)(struct _mpp *p, char *filename); /* read from a CGATS .mpp file */
/* Get various types of information about the mpp */
void (*get_info) (struct _mpp *p,
inkmask *imask, /* Inkmask, describing device colorspace */
int *nodchan, /* Number of device channels */
double *limit, /* Total ink limit (0.0 .. devchan) */
int *spec_n, /* Number of spectral bands, 0 if none */
double *spec_wl_short,/* First reading wavelength in nm (shortest) */
double *spec_wl_long, /* Last reading wavelength in nm (longest) */
instType *itype, /* Instrument type */
int *display); /* NZ if display type */
/* Set an illuminant and observer to use spectral model */
/* for CIE lookup with optional FWA. Set both to default for XYZ mpp model. */
/* Return 0 on OK, 1 on spectral not supported */
/* If the model is for a display, the illuminant will be ignored. */
int (*set_ilob) (struct _mpp *p,
icxIllumeType ilType, /* Illuminant type (icxIT_default for none) */
xspect *custIllum, /* Custom illuminant (NULL for none) */
icxObserverType obType, /* Observer type (icxOT_default for none) */
xspect custObserver[3], /* Custom observer (NULL for none) */
icColorSpaceSignature rcs, /* Return color space, icSigXYZData or icSigLabData */
int use_fwa /* NZ to involke FWA. */
);
/* Get the white and black points for this profile (default XYZ) */
void (*get_wb) (struct _mpp *p,
double *white,
double *black,
double *kblack);
/* Lookup an XYZ or Lab color (default XYZ) */
/* [will use spectral and FWA if configured] */
void (*lookup) (struct _mpp *p,
double *out, /* Returned XYZ or Lab */
double *in); /* Input device values */
/* Lookup an XYZ or Lab color with its partial derivative. */
/* [will ignore spectral and FWA even if configured] */
void (*dlookup)(struct _mpp *p,
double *out, /* Return the XYZ or Lab */
double **dout, /* Return the partial derivative dout[3][n] */
double *dev);
/* Lookup an XYZ value. (never FWA corrected) */
void (*lookup_xyz) (struct _mpp *p,
double *out, /* Returned XYZ value */
double *in); /* Input device values */
/* Lookup a spectral value. (never FWA corrected) */
void (*lookup_spec) (struct _mpp *p,
xspect *out, /* Returned spectral value */
double *in); /* Input device values */
/* Return a gamut object, return NULL on error */
gamut *(*get_gamut)(struct _mpp *p, double detail); /* detail level 0.0 = default */
/* Private: */
int verb; /* Verbose */
/* General model information */
int display; /* Non-zero if display profile rather than output */
inkmask imask; /* Inkmask describing device space */
double limit; /* Total ink limit (If output device) */
int spec_n; /* Number of spectral bands, 0 if not valid */
double spec_wl_short; /* First reading wavelength in nm (shortest) */
double spec_wl_long; /* Last reading wavelength in nm (longest) */
double norm; /* Normalising scale value (will be 1.0) */
instType itype; /* Spectral instrument type (If output device) */
mppcol white, black; /* White and black points */
mppcol kblack; /* K only black point */
/* Foward model parameters */
int n; /* Number of chanels */
int nn; /* Number of primary combinations = 1 << n */
int nnn2; /* Total shape combinations (= no of pairs?) = n * nn/2 */
int cord; /* Device transfer curve order (must be 1 <= cord <= MPP_MXTCORD) */
double tc[MPP_MXINKS][3+MPP_MXBANDS][MPP_MXTCORD]; /* Device transfer curve parameters */
int useshape; /* Flag, NZ if shape parameters are being used */
double ***shape; /* [MPP_MXINKS][MPP_MXCCOMB][3+MPP_MXBANDS] Extra shaping parameters */
double pc[MPP_MXCCOMB][3+MPP_MXBANDS]; /* Primary overlay combinations color values */
/* Model housekeeping */
/* Translate sparse shape color combo to compacted parameters and back */
int f2c[MPP_MXINKS][MPP_MXCCOMB]; /* Full to Compact */
struct { int ink; int comb; } c2f[MPP_MXINKS * MPP_MXCCOMB/2]; /* Compact to Full */
/* Optimisation state */
mppcol *otp; /* Optimisation test point */
int oit, ott; /* Optimisation itteration and total itterations */
int och; /* Optimisation device channel 0..n-1 */
int oba; /* Optimisation band, 0..2 are XYZ, 3..spec_n+3 are spectral */
double lpca[MPP_MXCCOMB][MPP_MXBANDS]; /* Primary combinations anchor L* band values */
int nodp; /* Number of device data points */
mppcol *cols; /* List of test points */
double spmax; /* Maximum spectral value of any sample and band */
/* Lookup */
icColorSpaceSignature pcs; /* PCS to return, XYZ, Lab */
xsp2cie *spc; /* Spectral to CIE converter (NULL if using XYZ model) */
/* Houskeeping */
icmErr e; /* Error code & message */
}; typedef struct _mpp mpp;
/* Create a new, uninitialised mpp */
mpp *new_mpp(void);
/* - - - - - - - - - - - - - */
/* mppcol utility functions */
/* Allocate the data portion of an mppcol */
/* Return NZ if malloc error */
int new_mppcol(
mppcol *p, /* mppcol to allocate */
int n, /* Number of inks */
int nb /* Number of spectral bands */
);
/* Free the data allocation of an mppcol */
void del_mppcol(
mppcol *p, /* mppcol to free */
int n, /* Number of inks */
int nb /* Number of spectral bands */
);
/* Copy the contents of one mppcol to another */
void copy_mppcol(
mppcol *d, /* Destination */
mppcol *s, /* Source */
int n, /* Number of inks */
int nb /* Number of spectral bands */
);
/* Allocate an array of mppcol, */
/* Return NULL if malloc error */
mppcol *new_mppcols(
int no, /* Number in array */
int n, /* Number of inks */
int nb /* Number of spectral bands */
);
/* Free an array of mppcol */
void del_mppcols(
mppcol *p, /* mppcol array to be free'd */
int no, /* Number in array */
int n, /* Number of inks */
int nb /* Number of spectral bands */
);
/* ================================ */
#ifdef COMMPLUS /* Commercial+ */
/* A channel change */
typedef struct {
inkmask im; /* Identity of ink */
int add; /* nz to add, z to delete */
xspect sp; /* If not NULL, spectra of colorant to add */
double Lab[3]; /* or if L > 0.0, L*a*b* of colorant to add */
double mix[MPP_MXINKS]; /* or mix of input profile colorants (can be < 0.0 and > 1.0) */
} mppchch;
/* Create a modified mpp */
mpp *mpp_modify(
mppchch *chl, /* List of changes */
int nil, /* Number in list */
mpp *p /* mpp2 to use as base */
);
#endif /* COMMPLUS Commercial+ */
#endif /* MPP_H */

1752
Argyll_V3.5.0/xicc/mpplu.c Normal file

File diff suppressed because it is too large Load Diff

835
Argyll_V3.5.0/xicc/revfix.c Normal file
View File

@@ -0,0 +1,835 @@
/*
* ICC reprocess to give true BtoA1 by inverting
* the AtoB1 table, and also correct the neutral
* axis of the BtoA0 and BtoA2 tables.
*
* Currently this only works with profiles with icSigLut16Type & icSigLut8Type Luts.
*
* Author: Graeme W. Gill
* Date: 9/7/00
* Version: 1.00
*
* Copyright 2000 Graeme W. Gill
* Please refer to License.txt file for details.
*/
/* TTBD:
*
* Add support for proper gamut mapping, just like profile,
* or deprecate revfix by modifying profile to work from
* an existing profile ?
*
* Remove the auxiliary fixup stuff when we have implemented
* optimised separations.
*
*/
#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"
#define USE_CAM_CLIP_OPT /* Clip in CAM Jab space rather than Lab */
#undef DEBUG /* Print each value changed */
typedef icmLut1 icmLut; /* Will only work for icSigLut16Type & icSigLut8Type */
void usage(void) {
fprintf(stderr,"Invert AtoB1 to make BtoA1 for CMYK profiles, Version %s\n",ARGYLL_VERSION_STR);
fprintf(stderr,"Author: Graeme W. Gill, licensed under the AGPL Version 3\n");
fprintf(stderr,"usage: revfix [-options] iccin iccout\n");
fprintf(stderr," -v Verbose\n");
fprintf(stderr," -0 Process perceptual\n");
fprintf(stderr," -1 Process absolute/relative colorimetric\n");
fprintf(stderr," -2 Process saturation\n");
fprintf(stderr," -r res Override BtoA1 Clut res\n");
fprintf(stderr," -k [ezhxr] e = same K as existing BtoA table (def)\n");
fprintf(stderr," z = zero, h = 0.5 K, x = max K, r = ramp K\n");
fprintf(stderr," -k p stle stpo enle enpo shape\n");
fprintf(stderr," p = curve parameters\n");
fprintf(stderr," stle: K level at White 0.0 - 1.0\n");
fprintf(stderr," stpo: start point of transition Wh 0.0 - Bk 1.0\n");
fprintf(stderr," enpo: End point of transition Wh 0.0 - Bk 1.0\n");
fprintf(stderr," enle: K level at Black 0.0 - 1.0\n");
fprintf(stderr," shape: 1.0 = straight, 0.0-1.0 concave, 1.0-2.0 convex\n");
fprintf(stderr," -K parameters Same as -k, but target is K locus rather than K value itself\n");
fprintf(stderr," -l tlimit set total ink limit, 0 - 400%% (estimate by default)\n");
fprintf(stderr," -L klimit set black ink limit, 0 - 100%% (estimate by default)\n");
fprintf(stderr," -p absprof Include abstract profile in output tables\n");
// fprintf(stderr," -s Use internal optimized separation for CMYK\n");
exit(1);
}
/* ------------------------------------------- */
/* structure to support icc Lut initialisation calbacks */
/* ~~~Note that we're not coping with a matrix or XYZ PCS properly here. */
struct _callback {
int verb; /* Verbosity */
int total, count, last; /* Progress count information */
icColorSpaceSignature pcsspace;
int inking; /* k inking algorithm */
icxLuLut *BtoA; /* BtoA of table being processed */
icxLuLut *AtoB; /* AtoB of table being processed */
icxLuLut *AtoB1; /* AtoB of colorimetric table */
icRenderingIntent abs_intent; /* Desired abstract profile rendering intent */
icxLuBase *abs_luo; /* abstract profile tranform in PCS, NULL if none */
}; typedef struct _callback callback;
/* Utility to handle abstract profile application to PCS */
/* PCS in creating output table is always XYZ or Lab relative colorimetric, */
/* and abstract profile is absolute or relative, and will be */
/* XYZ if absolute, and PCS if relative. */
static void do_abstract(callback *p, double out[3], double in[3]) {
out[0] = in[0];
out[1] = in[1];
out[2] = in[2];
//printf("~1 do_abstract got %f %f %f\n",in[0],in[1],in[2]);
if (p->abs_intent == icAbsoluteColorimetric) {
if (p->pcsspace == icSigLabData) {
icmLab2XYZ(&icmD50, out, out);
//printf("~1 after Lab 2 XYZ got %f %f %f\n",out[0],out[1],out[2]);
}
p->AtoB1->plu->XYZ_Rel2Abs(p->AtoB1->plu, out, out);
//printf("~1 after rel to abs got %f %f %f\n",out[0],out[1],out[2]);
}
p->abs_luo->lookup(p->abs_luo, out, out);
//printf("~1 after abs_luo got %f %f %f\n",out[0],out[1],out[2]);
if (p->abs_intent == icAbsoluteColorimetric) {
p->AtoB1->plu->XYZ_Abs2Rel(p->AtoB1->plu, out, out);
//printf("~1 after abs2rel got %f %f %f\n",out[0],out[1],out[2]);
if (p->pcsspace == icSigLabData) {
icmXYZ2Lab(&icmD50, out, out);
//printf("~1 after XYZ to Lab got %f %f %f\n",out[0],out[1],out[2]);
}
}
//printf("~1 returning %f %f %f\n\n",out[0],out[1],out[2]);
}
/* - - - - - - - - - */
/* New input table */
void Lab_Labp(void *cntx, double out[3], double in[3]
, int tn
) {
callback *p = (callback *)cntx;
#ifdef DEBUG
printf("Got Lab %f %f %f\n",in[0],in[1],in[2]);
#endif
if (p->AtoB != p->AtoB1) {
/* Non-colorimetric, use existing input table */
if (p->BtoA->input(p->BtoA, out, in) > 1)
error ("%d, %s",p->BtoA->pp->e.c,p->BtoA->pp->e.m);
} else {
/* Colorimetric, use inverse AtoB output */
if (p->AtoB1->inv_output(p->AtoB1, out, in) > 1)
error ("%d, %s",p->AtoB1->pp->e.c,p->AtoB1->pp->e.m);
}
#ifdef DEBUG
printf("New Lab' %f %f %f\n",out[0],out[1],out[2]);
#endif
}
/* - - - - */
/* clut */
/* Normal CLUT routine */
void Labp_CMYKp(void *cntx, double out[4], double in[3]
, int tn
) {
double temp[4], targetk = 0.0;
int rv;
callback *p = (callback *)cntx;
#ifdef DEBUG
printf("Got Lab' %f %f %f\n",in[0],in[1],in[2]);
#endif
if (p->inking == 0) { /* If we are copying existing K value */
/* Figure out what K value was previously here */
if (p->AtoB != p->AtoB1) {
/* Simple because BtoA input & output tables don't change */
/* Figure out what DEV' K value the BtoA table currently has for this PCS' */
if (p->BtoA->clut(p->BtoA, temp, in) > 1)
error ("%d, %s",p->BtoA->pp->e.c,p->BtoA->pp->e.m);
/* Convert DEV' to DEV */
if (p->BtoA->output(p->BtoA, temp, temp) > 1)
error ("%d, %s",p->BtoA->pp->e.c,p->AtoB->pp->e.m);
} else {
/* More complicated because old BtoA in/out tables are different */
/* from the new ones. */
/* We know that new BtoA in/out tables are inverse of AtoB in/out, */
/* so we don't have to use BtoA1->inv_input, & BtoA1->inv_output */
/* Convert PCS' to PCS */
if (p->AtoB->output(p->AtoB, temp, in) > 1)
error ("%d, %s",p->AtoB->pp->e.c,p->AtoB->pp->e.m);
/* Figure out what DEV K value the BtoA table currently has for this PCS */
if (((icxLuBase *)p->BtoA)->lookup((icxLuBase *)p->BtoA, temp, temp) > 1)
error ("%d, %s",p->BtoA->pp->e.c,p->BtoA->pp->e.m);
}
targetk = temp[3];
#ifdef DEBUG
printf("Got existing CMYK %f %f %f %f\n",temp[0],temp[1],temp[2],temp[3]);
#endif
}
/* Copy the Lab in */
temp[0] = in[0];
temp[1] = in[1];
temp[2] = in[2];
if (p->AtoB != p->AtoB1) {
double tt[4];
/* Can't assume B2A in/out tables are inverses of AtoB */
/* Convert PCS' -> PCS for this table */
if (p->BtoA->inv_input(p->BtoA, temp, temp) > 1)
error ("%d, %s",p->BtoA->pp->e.c,p->BtoA->pp->e.m);
/* Convert PCS -> PCS' for colorimetric */
if (p->AtoB1->inv_output(p->AtoB1, temp, temp) > 1)
error ("%d, %s",p->AtoB->pp->e.c,p->AtoB->pp->e.m);
}
/* Abstract profile applied before inversion */
if (p->abs_luo != NULL) {
do_abstract(p, temp, temp);
}
/* Invert AtoB1 clut, using set inking policy */
out[3] = targetk;
/* PCS' -> DEV' colorimetric (aux target is DEV space) */
if ((rv = p->AtoB1->inv_clut(p->AtoB1, out, temp)) > 1)
error ("%d, %s",p->AtoB1->pp->e.c,p->AtoB1->pp->e.m);
/* ~~~ Note that the ink limit will be wrong for non-colorimetric, */
/* since AtoB1->inv_clut will be assuming A->toB1->inv_input as the output table, */
/* while we will actually be using BtoA->output ~~~~ */
/* Need to override ink limit computation function in icx for non-colorimetric. */
//#ifdef DEBUG
// if (rv != 0) {
// printf("Inversion clipped\n");
// }
//#endif
if (p->AtoB != p->AtoB1) {
/* Can't assume B2A in/out tables are inverses of AtoB */
/* Converts DEV' -> DEV colorimetric */
if (p->AtoB1->inv_input(p->AtoB1, out, out) > 1)
error ("%d, %s",p->AtoB->pp->e.c,p->AtoB->pp->e.m);
/* Convert DEV -> DEV' for this table */
if (p->BtoA->inv_output(p->BtoA, out, out) > 1)
error ("%d, %s",p->BtoA->pp->e.c,p->BtoA->pp->e.m);
}
#ifdef DEBUG
printf("New CMYK' %f %f %f %f\n",out[0],out[1],out[2],out[3]);
printf("\n");
#endif
if (p->verb) { /* Output percent intervals */
int pc;
p->count++;
pc = (int)(p->count * 100.0/p->total + 0.5);
if (pc != p->last) {
printf("%c%2d%%",cr_char,pc), fflush(stdout);
p->last = pc;
}
}
}
/* - - - - - - - - - */
/* New output table */
void CMYKp_CMYK(void *cntx, double out[4], double in[4]
, int tn
) {
callback *p = (callback *)cntx;
#ifdef DEBUG
printf("Got CMYK' %f %f %f %f\n",in[0],in[1],in[2],in[3]);
#endif
if (p->AtoB != p->AtoB1) {
/* Non-colorimetric, use existing output table */
if (p->BtoA->output(p->BtoA, out, in) > 1)
error ("%d, %s",p->BtoA->pp->e.c,p->BtoA->pp->e.m);
} else {
/* Colorimetric, use inverse AtoB input */
if (p->AtoB1->inv_input(p->AtoB1, out, in) > 1)
error ("%d, %s",p->AtoB1->pp->e.c,p->AtoB1->pp->e.m);
}
#ifdef DEBUG
printf("New CMYK %f %f %f %f\n",out[0],out[1],out[2],out[3]);
#endif
}
/* ------------------------------------------- */
int
main(int argc, char *argv[]) {
int fa,nfa; /* argument we're looking at */
static char in_name[MAXNAMEL+1];
static char out_name[MAXNAMEL+1];
static char abs_name[MAXNAMEL+1] = "\000"; /* Abstract profile name */
icmFile *rd_fp, *wr_fp;
icc *icco;
icmErr err = { 0, { '\000'} };
int verb = 0;
int clutres = 0;
int do0 = 0;
int do1 = 0;
int do2 = 0;
int inking = 0; /* Default copy from existing */
int locus = 0; /* Default K value target */
double Kstle = 0.0, Kstpo = 0.0, Kenle = 0.0, Kenpo = 0.0, Kshap = 0.0;
double tlimit = -1.0; /* Total ink limit */
double klimit = -1.0; /* Black ink limit */
int intsep = 0; /* Not implemented in xicc yet ??? */
int rv = 0;
error_program = argv[0];
check_if_not_interactive();
if (argc < 2)
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;
}
else if (argv[fa][1] == '0') {
do0 = 1;
}
else if (argv[fa][1] == '1') {
do1 = 1;
}
else if (argv[fa][1] == '2') {
do2 = 1;
}
else if (argv[fa][1] == 'r' || argv[fa][1] == 'R') {
fa = nfa;
if (na == NULL) usage();
clutres = atoi(na);
}
/* Inking rule */
else if (argv[fa][1] == 'k' || argv[fa][1] == 'K') {
fa = nfa;
if (na == NULL) usage();
if (argv[fa][1] == 'k')
locus = 0; /* K value target */
else
locus = 1; /* K locus target */
switch (na[0]) {
case 'e':
case 'E':
inking = 0; /* Use existing table as guide */
break;
case 'z':
case 'Z':
inking = 1; /* Use minimum k */
break;
case 'h':
case 'H':
inking = 2; /* Use 0.5 k */
break;
case 'x':
case 'X':
inking = 3; /* Use maximum k */
break;
case 'r':
case 'R':
inking = 4; /* Use ramp */
break;
case 'p':
case 'P':
inking = 5; /* Use curve parameter */
++fa;
if (fa >= argc) usage();
Kstle = atof(argv[fa]);
++fa;
if (fa >= argc) usage();
Kstpo = atof(argv[fa]);
++fa;
if (fa >= argc || argv[fa][0] == '-') usage();
Kenpo = atof(argv[fa]);
++fa;
if (fa >= argc) usage();
Kenle = atof(argv[fa]);
++fa;
if (fa >= argc || argv[fa][0] == '-') usage();
Kshap = atof(argv[fa]);
break;
default:
usage();
}
}
else if (argv[fa][1] == 'l') {
fa = nfa;
if (na == NULL) usage();
tlimit = atoi(na)/100.0;
}
else if (argv[fa][1] == 'L') {
fa = nfa;
if (na == NULL) usage();
klimit = atoi(na)/100.0;
}
/* Use internal separation */
else if (argv[fa][1] == 's' || argv[fa][1] == 'S') {
intsep = 1;
}
/* Abstract profile */
else if (argv[fa][1] == 'p' || argv[fa][1] == 'P') {
if (na == NULL) usage();
fa = nfa;
strncpy(abs_name,na,MAXNAMEL); abs_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';
/* Open up the profile for reading */
if ((rd_fp = new_icmFileStd_name(&err, in_name,"r")) == NULL)
error ("Can't open file '%s' (0x%x, '%s')",in_name,err.c,err.m);
if ((icco = new_icc(&err)) == NULL)
error ("Creation of ICC object failed (0x%x, '%s')",err.c,err.m);
/* Read header etc. */
if ((rv = icco->read(icco,rd_fp,0)) != 0)
error ("%d, %s",rv,icco->e.m);
/* Read every tag */
if (icco->read_all_tags(icco) != 0) {
error("Unable to read all tags: %d, %s",icco->e.c,icco->e.m);
}
rd_fp->del(rd_fp);
/* ======================= */
/* Check that it is a suitable icc */
{
icmHeader *rh = icco->header;
if (rh->deviceClass != icSigOutputClass)
error("Profile isn't an output device profile");
if (rh->colorSpace != icSigCmykData)
error("Profile isn't for a CMYK device");
if (rh->pcs != icSigLabData)
error("Profile is not using a PCS of Lab - can't cope with this yet");
}
if (verb && inking == 5) {
double tL;
printf("K parameters are are %f %f %f %f %f\n",Kstle, Kstpo, Kenpo, Kenle, Kshap);
for (tL = 100.0; tL >= 0.0; tL -= 10.0) {
double rv, L;
L = 0.01 * tL;
/* Code from xlut.c: */
/* Invert sense of L, so that 0.0 = white, 1.0 = black */
L = 1.0 - L;
if (L <= Kstpo && L <= Kenpo) {
/* We are at white level */
rv = Kstle;
} else if (L >= Kstpo && L >= Kenpo) {
/* We are at black level */
rv = Kenle;
} else {
double g;
/* We must be on the curve from start to end levels */
if (Kstpo > Kenpo) {
rv = (L - Kenpo)/(Kstpo - Kenpo);
} else {
rv = (L - Kstpo)/(Kenpo - Kstpo);
}
g = Kshap/2.0;
/* A value of 0.5 will be tranlated to g */
rv = rv/((1.0/g - 2.0) * (1.0 - rv) + 1.0);
/* Transition between start end end levels */
rv = rv * (Kenle - Kstle) + Kstle;
}
/* To be safe */
if (rv < 0.0)
rv = 0.0;
else if (rv > 1.0)
rv = 1.0;
printf("L = %f, K %s = %f\n",tL, locus ? "locus" : "value", rv);
}
}
/* ======================= */
{
int ii; /* Current intent */
icmLut *done[3]; /* record pointers to done Luts here */
icRenderingIntent intent = 0;
icTagSignature sig = 0;
xicc *xicco;
callback cb; /* Callback support stucture */
icxInk ink; /* Ink parameters */
icmLuAlgType alg; /* Type of lookup algorithm */
icmFile *abs_fp = NULL; /* Abstract profile transform: */
icc *abs_icc = NULL;
xicc *abs_xicc = NULL;
/* Wrap with an expanded icc */
if ((xicco = new_xicc(icco)) == NULL)
error ("Creation of xicc failed");
/* Setup CMYK -> Lab conversion (Fwd) object */
/* Set the default ink limits if not set on command line */
icxDefaultLimits(xicco, &ink.tlimit, tlimit, &ink.klimit, klimit);
if (verb) {
if (!do0 && !do1 && !do2)
printf("WARNING: nothing to do!\n");
if (ink.tlimit >= 0.0)
printf("Total ink limit assumed is %3.0f%%\n",100.0 * ink.tlimit);
if (ink.klimit >= 0.0)
printf("Black ink limit assumed is %3.0f%%\n",100.0 * ink.klimit);
}
ink.KonlyLmin = 0; /* Use normal black Lmin for locus */
ink.c.Ksmth = ICXINKDEFSMTH; /* Default curve smoothing */
ink.c.Kskew = ICXINKDEFSKEW; /* default curve skew */
ink.x.Ksmth = ICXINKDEFSMTH;
ink.x.Kskew = ICXINKDEFSKEW;
if (inking == 0) {
ink.k_rule = icxKvalue; /* K is auxiliary target */
} else if (inking == 1) { /* Use minimum */
ink.k_rule = locus ? icxKluma5 : icxKluma5k;
ink.c.Kstle = 0.0;
ink.c.Kstpo = 0.0;
ink.c.Kenpo = 1.0;
ink.c.Kenle = 0.0;
ink.c.Kshap = 1.0;
} else if (inking == 2) { /* Use 0.5 */
ink.k_rule = locus ? icxKluma5 : icxKluma5k;
ink.c.Kstle = 0.5;
ink.c.Kstpo = 0.0;
ink.c.Kenpo = 1.0;
ink.c.Kenle = 0.5;
ink.c.Kshap = 1.0;
} else if (inking == 3) { /* Use maximum */
ink.k_rule = locus ? icxKluma5 : icxKluma5k;
ink.c.Kstle = 1.0;
ink.c.Kstpo = 0.0;
ink.c.Kenpo = 1.0;
ink.c.Kenle = 1.0;
ink.c.Kshap = 1.0;
} else if (inking == 4) { /* Use ramp */
ink.k_rule = locus ? icxKluma5 : icxKluma5k;
ink.c.Kstle = 0.0;
ink.c.Kstpo = 0.0;
ink.c.Kenpo = 1.0;
ink.c.Kenle = 1.0;
ink.c.Kshap = 1.0;
} else { /* Use specified curve */
ink.k_rule = locus ? icxKluma5 : icxKluma5k;
ink.c.Kstle = Kstle;
ink.c.Kstpo = Kstpo;
ink.c.Kenpo = Kenpo;
ink.c.Kenle = Kenle;
ink.c.Kshap = Kshap;
}
cb.verb = verb;
cb.count = 0;
cb.last = -1;
cb.inking = inking;
/* Setup our access to the device characteristic */
if ((cb.AtoB1 = (icxLuLut *)xicco->get_luobj(xicco,
ICX_CLIP_NEAREST
#ifdef USE_CAM_CLIP_OPT
| ICX_CAM_CLIP
#endif
| (intsep ? ICX_INT_SEPARATE : 0),
icmFwd, icRelativeColorimetric,
icmSigDefaultData, icmLuOrdNorm, NULL, &ink)) == NULL)
error ("%d, %s",xicco->e.c, xicco->e.m);
cb.AtoB1->spaces((icxLuBase *)cb.AtoB1, NULL, NULL, NULL, NULL, &alg,
NULL, NULL, &cb.pcsspace);
if (alg != icmLutType)
error("Forward conversion is not a Lut");
/* Open up the abstract profile if supplied, and setup luo */
if (abs_name[0] != '\000') {
if ((abs_fp = new_icmFileStd_name(&err, abs_name,"r")) == NULL)
error ("Can't open abstract profile file '%s' (0x%x, '%s')",abs_name,err.c,err.m);
if ((abs_icc = new_icc(&err)) == NULL)
error ("Creation of Abstract profile ICC object failed (0x%x, '%s')",err.c,err.m);
/* Read header etc. */
if ((rv = abs_icc->read(abs_icc,abs_fp,0)) != 0)
error ("%d, %s",rv,abs_icc->e.m);
if (abs_icc->header->deviceClass != icSigAbstractClass)
error("Abstract profile isn't an abstract profile");
/* Take intended abstract intent from profile itself */
if ((cb.abs_intent = abs_icc->header->renderingIntent) != icAbsoluteColorimetric)
cb.abs_intent = icRelativeColorimetric;
/* Wrap with an expanded icc */
if ((abs_xicc = new_xicc(abs_icc)) == NULL)
error ("Creation of abstract profile xicc failed");
/* The abstract profile intent is assumed to determine how it gets applied. */
/* Make abstract PCS XYZ if icAbsoluteColorimetric is needed. */
if ((cb.abs_luo = abs_xicc->get_luobj(abs_xicc, ICX_CLIP_NEAREST, icmFwd, cb.abs_intent,
(cb.pcsspace == icSigLabData && cb.abs_intent == icRelativeColorimetric)
? icSigLabData : icSigXYZData,
icmLuOrdNorm, NULL, NULL)) == NULL)
error ("%d, %s",abs_icc->e.c, abs_icc->e.m);
} else {
cb.abs_luo = NULL;
}
/* for all intents, and not already processed */
for (ii = 0; ii <= 2; ii++) {
int i;
icmLut *wo;
switch(ii) {
case 0:
intent = icRelativeColorimetric;
sig = icSigBToA1Tag;
if (do1 == 0)
continue;
break;
case 1:
intent = icPerceptual;
sig = icSigBToA0Tag;
if (do0 == 0)
continue;
break;
case 2:
intent = icSaturation;
sig = icSigBToA2Tag;
if (do2 == 0)
continue;
break;
}
if (intent == icRelativeColorimetric) {
cb.AtoB = cb.AtoB1;
} else {
/* Setup CMYK -> Lab conversion (Fwd) object */
if ((cb.AtoB = (icxLuLut *)xicco->get_luobj(xicco, ICX_CLIP_NEAREST, icmFwd, intent,
icmSigDefaultData, icmLuOrdNorm, NULL, NULL)) == NULL)
error ("%d, %s",xicco->e.c, xicco->e.m);
cb.AtoB->spaces((icxLuBase *)cb.AtoB, NULL, NULL, NULL, NULL, &alg, NULL, NULL, NULL);
if (alg != icmLutType)
error("Forwards conversion is not a Lut");
}
/* Setup Lab -> CMYK conversion (Bwd) object */
if ((cb.BtoA = (icxLuLut *)xicco->get_luobj(xicco, ICX_CLIP_NEAREST, icmBwd, intent,
icmSigDefaultData, icmLuOrdNorm, NULL, NULL)) == NULL)
error ("%d, %s",xicco->e.c, xicco->e.m);
cb.BtoA->spaces((icxLuBase *)cb.BtoA, NULL, NULL, NULL, NULL, &alg, NULL, NULL, NULL);
if (alg != icmLutType)
error("Backwards conversion is not a Lut");
/* Try and read the tag from the file */
wo = (icmLut *)icco->read_tag(icco, sig);
if (wo == NULL)
error("Can't find %s", icm2str(icmRenderingIntent, intent));
/* Need to check that the cast is appropriate. */
if (wo->ttype != icSigLut16Type && wo->ttype != icSigLut8Type)
error("Lut table isn't Lut8 or Lut16 Type");
/* Make sure that we don't process a table twice */
done[ii] = wo;
for (i = ii-1; i >= 0; i--) {
if (done[i] == wo) {
break;
}
}
if (i >= 0) {
if (verb)
printf("Skipping %s table - already done\n", icm2str(icmRenderingIntent, intent));
} else {
icmXformSigs sigs[1];
unsigned int inputEnt;
unsigned int cres, clutPoints[MAX_CHAN];
unsigned int outputEnt;
sigs[0].sig = sig;
sigs[0].ttype = icSigLut16Type;
if ((inputEnt = cb.AtoB->plu->max_out_res(cb.AtoB->plu, NULL)) == 0)
inputEnt = 1024;
if ((cres = cb.AtoB->plu->max_clut_res(cb.AtoB->plu, NULL)) == 0)
cres = 17;
/* Let user override for BtoA1 */
if (sig == icSigBToA1Tag && clutres > 0) {
if (verb)
printf("Overriding existing clut resolution %d with %d\n",cres,clutres);
cres = clutres;
}
for (i = 0; i < 3; i++)
clutPoints[i] = cres;
if ((outputEnt = cb.AtoB->plu->max_in_res(cb.AtoB->plu, NULL)) == 0)
outputEnt = 1024;
if (verb)
printf("About to start processing %s\n", icm2str(icmRenderingIntent, intent));
if (cb.verb) {
unsigned int ui;
int extra;
for (cb.total = 1, ui = 0; ui < 3; cb.total *= clutPoints[ui], ui++)
;
/* Add in cell center points */
for (extra = 1, ui = 0; ui < 3; extra *= clutPoints[ui]-1, ui++)
;
cb.total += extra;
printf(" 0%%"), fflush(stdout);
}
if (icco->create_lut_xforms(
icco,
ICM_CLUT_SET_APXLS,
&cb, /* Context */
1, /* One table */
sigs, /* signatures and tag types for each table */
2, /* Bytes per value of AToB or BToA CLUT, 1 or 2 */
inputEnt, clutPoints, outputEnt, /* Table resolutions */
icSigLabData, /* Input color space */
icSigCmykData, /* Output color space */
NULL, NULL, /* Use default input range */
Lab_Labp, /* Linear input transform Lab->Lab' */
NULL, NULL, /* Use default Lab' range */
Labp_CMYKp, /* Lab' -> CMYK' transfer function */
NULL, NULL, /* Use default CMYK' range */
CMYKp_CMYK, /* Output transfer function, CMYK'->CMYK */
NULL, NULL /* default APXLS range */
) != ICM_ERR_OK)
error("Setting 16 bit Lab->CMYK Lut failed: %d, %s",icco->e.c,icco->e.m);
if (verb)
printf("\nDone processing %s\n", icm2str(icmRenderingIntent, intent));
}
/* Done with this intents lookup object */
cb.BtoA->del((icxLuBase *)cb.BtoA);
if (cb.AtoB != cb.AtoB1)
cb.AtoB->del((icxLuBase *)cb.AtoB);
}
/* Done with colorimetric intents AtoB1 lookup objects, and xicc */
cb.AtoB1->del((icxLuBase *)cb.AtoB1);
xicco->del(xicco);
if (cb.abs_luo != NULL) { /* Free up abstract transform */
cb.abs_luo->del(cb.abs_luo);
abs_xicc->del(abs_xicc);
abs_icc->del(abs_icc);
abs_fp->del(abs_fp);
}
}
/* ======================================= */
/* Open up the other profile for writing */
if ((wr_fp = new_icmFileStd_name(&err, out_name,"w")) == NULL)
error ("Can't open file '%s' (0x%x, '%s')",out_name,err.c,err.m);
/* Relax format so we don't barf on input profile contents */
icco->set_cflag(icco, icmCFlagWrFormatWarn);
icco->set_cflag(icco, icmCFlagWrVersionWarn);
if ((rv = icco->write(icco,wr_fp,0)) != 0)
error ("Write file: %d, %s",rv,icco->e.m);
wr_fp->del(wr_fp);
icco->del(icco);
return 0;
}

View File

@@ -0,0 +1,540 @@
/*
* International Color Consortium color transform expanded support
*
* Author: Graeme W. Gill
* Date: 2006/5/9
* Version: 1.00
*
* Copyright 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.
*
*/
/*
* This is some test code to test the Daylight and Plankian spectra,
* Correlated and Visual Color Temperatures, and CRI.
* and plot a spectrum, CMF or CCSS.
*/
#include <stdio.h>
#include <stdarg.h>
#include <math.h>
#include "aconfig.h"
#include "cgats.h"
#include "xspect.h"
#include "numlib.h"
#include "plot.h"
#include "ui.h"
#define PLANKIAN
#define XRES 500
#define MAXGRAPHS 10
/* Display a spectrum etc. */
/* We are guaranteed that the x range/increments are identical, */
/* and that there is only one spectrum if douv */
static int do_spec(
char name[MAXGRAPHS][200],
xspect *sp,
int nsp, /* Number of sp */
inst_meas_type mt, /* Measurement type */
int dozero, /* Include zero in the range */
int noplot, /* Don't actually plot */
icxDensityType dens, /* Density type to print */
int douv, /* Do variation of added UV test */
icxObserverType obType, /* Observer (defaults to 1931 2 degree) */
xspect *custObserver, /* If obType = icxOT_custom */
double uvmin,
double uvmax
) {
int n, i, j, k, m;
double wl_short, wl_long; /* Common range */
double xyz[3]; /* Color temperature */
double Yxy[3];
double Lab[3]; /* D50 Lab value */
double xx[XRES];
double yy[10][XRES];
double *yp[10];
double cct, vct;
double cct_xyz[3], vct_xyz[3];
double cct_lab[3], vct_lab[3];
double cdt, vdt;
double cdt_xyz[3], vdt_xyz[3];
double cdt_lab[3], vdt_lab[3];
icmXYZNumber wp;
double de;
double uv = uvmin;
double step = 0.1;
xspect tsp; /* Spectrum with possible UV added */
char *color[] = {
"Black", "Red", "Green", "Blue", "Yellow", "Purple", "Brown", "Orange", "Grey", "Magenta"
};
printf("\n");
for (j = 0; j < 10; j++)
yp[j] = NULL;
if (nsp > 10)
nsp = 10;
m = 0; /* offset in output array */
n = 1;
wl_short = 1e6;
wl_long = -1e6;
for (k = 0; k < nsp; k++) {
if (sp[k].spec_wl_long > wl_long)
wl_long = sp[k].spec_wl_long;
if (sp[k].spec_wl_short < wl_short)
wl_short = sp[k].spec_wl_short;
}
if (douv) {
n = 1 + (int)(0.5 + (uvmax-uvmin)/0.1);
if (n > 9)
n = 9; /* Don't use white */
if (n > 1)
step = (uvmax-uvmin)/(n-1.0);
}
for (k = 0; k < nsp; k++) {
tsp = sp[k];
for (uv = uvmax, j = 0; j < n; j++, uv -= step) {
if (douv) {
printf("UV level = %f\n",uv);
xsp_setUV(&tsp, &sp[k], uv);
}
printf("Type = %s [%s]\n",name[k], color[k]);
if (mt == inst_mrt_none
|| mt == inst_mrt_emission
|| mt == inst_mrt_ambient
|| mt == inst_mrt_emission_flash
|| mt == inst_mrt_ambient_flash) {
/* Compute absolute XYZ of illuminant */
if (icx_ill_sp2XYZ(xyz, obType, custObserver, icxIT_custom, 0, &tsp, 1) != 0)
warning("icx_ill_sp2XYZ returned error");
printf("Abs. Y = %f\n", xyz[1]);
/* Normalise to Y = 1 */
xyz[0] /= xyz[1];
xyz[2] /= xyz[1];
xyz[1] /= xyz[1];
icmXYZ2Yxy(Yxy, xyz);
icmXYZ2Lab(&icmD50, Lab, xyz);
printf("XYZ = %f %f %f, x,y = %f %f\n", xyz[0], xyz[1], xyz[2], Yxy[1], Yxy[2]);
printf("D50 L*a*b* = %f %f %f\n", Lab[0], Lab[1], Lab[2]);
/* Compute CCT */
if ((cct = icx_XYZ2ill_ct(cct_xyz, icxIT_Ptemp, obType, custObserver, xyz, NULL, 0)) < 0)
warning("Got bad cct\n");
/* Compute VCT */
if ((vct = icx_XYZ2ill_ct(vct_xyz, icxIT_Ptemp, obType, custObserver, xyz, NULL, 1)) < 0)
warning("Got bad vct\n");
printf("CCT = %f, VCT = %f\n",cct, vct);
/* Compute CDT */
if ((cct = icx_XYZ2ill_ct(cct_xyz, icxIT_Dtemp, obType, custObserver, xyz, NULL, 0)) < 0)
warning("Got bad cct\n");
/* Compute VDT */
if ((vct = icx_XYZ2ill_ct(vct_xyz, icxIT_Dtemp, obType, custObserver, xyz, NULL, 1)) < 0)
warning("Got bad vct\n");
printf("CDT = %f, VDT = %f\n",cct, vct);
{
int invalid = 0;
double RR[14];
double cri;
cri = icx_CIE1995_CRI(&invalid, RR, &tsp);
printf("CRI = %.1f [ R9 = %.1f ]%s\n",cri,RR[9-1],invalid ? " (Invalid)" : "");
}
{
int invalid = 0;
double tlci;
tlci = icx_EBU2012_TLCI(&invalid, &tsp);
printf("TLCI = %.1f%s\n",tlci,invalid ? " (Invalid)" : "");
}
/* Use modern color difference - gives a better visual match */
icmAry2XYZ(wp, vct_xyz);
icmXYZ2Lab(&wp, cct_lab, cct_xyz);
icmXYZ2Lab(&wp, vct_lab, vct_xyz);
de = icmCIE2K(cct_lab, vct_lab);
printf("CIEDE2000 Delta E = %f\n",de);
} else if (mt == inst_mrt_none
|| mt == inst_mrt_reflective
|| mt == inst_mrt_transmissive) {
double cmyv[4];
printf("CIE values under D50 illuminant:\n");
if (icx_sp2XYZ(xyz, obType, custObserver, icxIT_D50, 0, NULL, &tsp) != 0)
warning("icx_sp2XYZ returned error");
icmXYZ2Yxy(Yxy, xyz);
icmXYZ2Lab(&icmD50, Lab, xyz);
printf("XYZ = %f %f %f, x,y = %f %f\n", xyz[0], xyz[1], xyz[2], Yxy[1], Yxy[2]);
printf("D50 L*a*b* = %f %f %f\n", Lab[0], Lab[1], Lab[2]);
if (dens != icxDT_none) {
/* Density */
xsp_density(cmyv, &tsp, dens);
printf("CMYV %s = %f %f %f %f\n", xsp_density_desc(dens), cmyv[0], cmyv[1], cmyv[2], cmyv[3]);
}
} else {
printf("Unhandled measurement type '%s'\n",meas_type2str(mt));
}
/* Plot spectrum out */
for (i = 0; i < XRES; i++) {
double ww;
ww = (wl_long - wl_short)
* ((double)i/(XRES-1.0)) + wl_short;
xx[i] = ww;
yy[(m + k + j) % 10][i] = value_xspect(&tsp, ww);
}
yp[(m + k + j) % 10] = &yy[(m + k + j) % 10][0];
printf("\n");
}
}
if (!noplot) {
do_plot10(xx, yp[0], yp[1], yp[2], yp[3], yp[4], yp[5], yp[6], yp[7], yp[8], yp[9], XRES, dozero);
}
return 0;
}
void usage(void) {
fprintf(stderr,"Plot spectrum and calculate CCT and VCT\n");
fprintf(stderr,"Author: Graeme W. Gill, licensed under the AGPL Version 3\n");
fprintf(stderr,"usage: specplot [infile.sp]\n");
fprintf(stderr," -v verbose\n");
fprintf(stderr," -c combine multiple files into one plot\n");
fprintf(stderr," -n normalize max level\n");
fprintf(stderr," -z don't make range cover zero\n");
fprintf(stderr," -s don't plot spectra\n");
fprintf(stderr," -d I|A|M|T|E print density values\n");
fprintf(stderr," -u level plot effect of adding estimated UV level\n");
fprintf(stderr," -U plot effect of adding range of estimated UV level\n");
fprintf(stderr," -o observ Choose CIE Observer for spectral data:\n");
fprintf(stderr," 1931_2 (def), 1964_10, 2015_2, 2015_10, S&B 1955_2, shaw, J&V 1978_2, or file.cmf\n");
fprintf(stderr," [infile.sp ...] spectrum files to plot\n");
fprintf(stderr," default is all built in illuminants\n");
exit(1);
}
int main(int argc, char *argv[]) {
int fa, nfa; /* argument we're looking at */
int k;
int verb = 0;
int comb = 0;
int norm = 0;
int zero = 1;
int noplot = 0;
icxDensityType dens = icxDT_none;
double temp;
icxObserverType obType = icxOT_CIE_1931_2; /* Observer */
xspect custObserver[3]; /* If obType = icxOT_custom */
xspect sp[MAXGRAPHS];
icxIllumeType ilType;
int douv = 0;
double uvmin = -1.0, uvmax = 1.0;
char buf[MAXGRAPHS][200];
error_program = argv[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) < argc) {
if (argv[fa+1][0] != '-') {
nfa = fa + 1;
na = argv[nfa]; /* next is seperate non-flag argument */
}
}
}
/* Show added UV */
if (argv[fa][1] == 'u') {
douv = 1;
fa = nfa;
if (na == NULL)
usage();
uvmin = uvmax = atof(na);
if (uvmin < -10.0 || uvmax > 10.0)
usage();
}
else if (argv[fa][1] == 'U') {
douv = 1;
}
/* Spectral Observer type */
else if (argv[fa][1] == 'o') {
if (na == NULL) usage();
fa = nfa;
if (strcmp(na, "1931_2") == 0) { /* Classic 2 degree */
obType = icxOT_CIE_1931_2;
} else if (strcmp(na, "1964_10") == 0) { /* Classic 10 degree */
obType = icxOT_CIE_1964_10;
} else if (strcmp(na, "2015_2") == 0) { /* Latest 2 degree */
obType = icxOT_CIE_2015_2;
} else if (strcmp(na, "2015_10") == 0) { /* Latest 10 degree */
obType = icxOT_CIE_2015_10;
} else if (strcmp(na, "1955_2") == 0) { /* Stiles and Burch 1955 2 degree */
obType = icxOT_Stiles_Burch_2;
} else if (strcmp(na, "1978_2") == 0) { /* Judd and Voss 1978 2 degree */
obType = icxOT_Judd_Voss_2;
} else if (strcmp(na, "shaw") == 0) { /* Shaw and Fairchilds 1997 2 degree */
obType = icxOT_Shaw_Fairchild_2;
} else { /* Assume it's a filename */
obType = icxOT_custom;
if (read_cmf(custObserver, na) != 0) {
fprintf(stderr,"Failed to read custom observer CMF from -o file '%s'\n",na);
usage();
}
}
}
/* Verbosity */
else if (argv[fa][1] == 'v') {
verb = 1;
} else if (argv[fa][1] == 'c') {
comb = 1;
} else if (argv[fa][1] == 'n') {
norm = 1;
} else if (argv[fa][1] == 'z') {
zero = 0;
} else if (argv[fa][1] == 's') {
noplot = 1;
} else if (argv[fa][1] == 'd') {
if (na == NULL)
usage();
switch(na[0]) {
case 'N':
dens = icxDT_none;
break;
case 'I':
dens = icxDT_ISO;
break;
case 'A':
dens = icxDT_A;
break;
case 'M':
dens = icxDT_M;
break;
case 'T':
dens = icxDT_T;
break;
case 'E':
dens = icxDT_E;
break;
default:
usage();
}
fa = nfa;
} else {
usage();
}
}
else
break;
}
if (fa < argc && argv[fa][0] != '-') { /* Got file arguments */
int nsp = 0; /* Current number in sp[] */
int soff = 0; /* Offset within file */
int maxgraphs = MAXGRAPHS;
int eof;
if (douv)
maxgraphs = 1;
nsp = 0;
/* Until we run out */
for (;;) {
int i, nret, nreq;
inst_meas_type mt;
inst_meas_cond mc;
/* If we've got to the limit of each plot, */
/* or at least one and we're not combining files and at start of a new file, */
/* or at least one and there are no more files */
if (nsp >= MAXGRAPHS || (nsp > 0 && ((!comb && soff == 0) || fa >= argc))) {
if (norm) {
int j;
double mlev = 0.0;
for (i = 0; i < nsp; i++) {
xspect_denorm(&sp[i]);
for (j = 0; j < sp[i].spec_n; j++) {
if (sp[i].spec[j] > mlev)
mlev = sp[i].spec[j];
}
}
if (mlev > 1e-6) {
for (i = 0; i < nsp; i++) {
double mm = 0.0;
for (j = 0; j < sp[i].spec_n; j++) {
if (sp[i].spec[j] > mm)
mm = sp[i].spec[j];
}
if (mm > 1e-6) {
mm = mlev/mm;
for (j = 0; j < sp[i].spec_n; j++) {
sp[i].spec[j] *= mm;
}
}
}
}
}
/* Plot what we've got */
do_spec(buf, sp, nsp, mt, zero, noplot, dens, douv, obType, custObserver, uvmin, uvmax);
nsp = 0;
}
if (fa >= argc) /* No more files */
break;
/* Read as many spectra from the file as possible */
nreq = MAXGRAPHS - nsp;
if (read_nxspect(&sp[nsp], &mt, &mc, argv[fa], &nret, soff, nreq, 0) != 0) {
error ("Unable to read custom spectrum, CMF or CCSS '%s'",argv[fa]);
}
for (i = 0; i < nret; i++) {
xspect_denorm(&sp[nsp + i]);
sprintf(buf[nsp + i],"File '%s' spect %d",argv[fa], soff + i);
}
nsp += nret;
soff += nret;
if (nret < nreq) { /* We're done with this file */
fa++;
soff = 0;
}
}
} else {
/* For each standard illuminant */
for (ilType = icxIT_A; ilType <= icxIT_F10; ilType++) {
char *inm = NULL;
switch (ilType) {
case icxIT_A:
inm = "A"; break;
case icxIT_C:
inm = "C"; break;
case icxIT_D50:
inm = "D50"; break;
case icxIT_D50M2:
inm = "D50M2"; break;
case icxIT_D55:
inm = "D55"; break;
case icxIT_D65:
inm = "D65"; break;
case icxIT_D75:
inm = "D75"; break;
case icxIT_E:
inm = "E"; break;
case icxIT_F5:
inm = "F5"; break;
case icxIT_F8:
inm = "F8"; break;
case icxIT_F10:
inm = "F10"; break;
default:
inm = "Unknown"; break;
break;
}
if (standardIlluminant(&sp[0], ilType, 0) != 0)
error ("standardIlluminant returned error for %d (%s)",ilType,inm);
strcpy(buf[0],inm);
do_spec(buf, sp, 1, inst_mrt_ambient, zero, noplot, dens, douv, obType, custObserver, uvmin, uvmax);
}
/* For each material and illuminant */
for (k = 0; k < 2; k++) {
double start, end;
if (k == 0)
start = 3400, end = 9000;
else
start = 500, end = 9000;
for (temp = start; temp <= end; temp += 500) {
ilType = k == 0 ? icxIT_Dtemp : icxIT_Ptemp;
if (standardIlluminant(&sp[0], ilType, temp) != 0)
error ("standardIlluminant returned error for %s temp %f",
k == 0 ? "Daylight" : "Plankian", temp);
sprintf(buf[0], "%s at %f", k == 0 ? "Daylight" : "Black body", temp);
do_spec(buf, sp, 1, inst_mrt_ambient, zero, noplot, dens, douv, obType, custObserver, uvmin, uvmax);
}
}
}
return 0;
}

View File

@@ -0,0 +1,260 @@
/*
* Author: Graeme W. Gill
* Date: 2007/3/21
* Version: 1.00
*
* Copyright 2007 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.
*
*/
/*
* This is some utility code to subsample the 1 and 5nm spectral
* data in xspect to wider spacings using ANSI-CGATS the recommended
* triangular filter.
*/
#include <stdio.h>
#include <math.h>
#include "aconfig.h"
#include "cgats.h"
#include "xspect.h"
#include "numlib.h"
#include "ui.h"
void usage(void) {
fprintf(stderr,"Downsample spectral data\n");
fprintf(stderr,"Author: Graeme W. Gill\n");
fprintf(stderr,"usage: specsubsamp -options\n");
fprintf(stderr," -i illum Choose illuminant for print/transparency spectral data:\n");
fprintf(stderr," A, C, D50, D50M2, D65, F5, F8, F10 or file.sp\n");
fprintf(stderr," -o observ Choose CIE Observer for spectral data:\n");
fprintf(stderr," 1931_2, 1964_10, 2015_2, 2015_10, S&B 1955_2, shaw, J&V 1978_2 or file.cmf\n");
fprintf(stderr," -w st,en,sp Output start, end and spacing nm\n");
fprintf(stderr," -5 Comment output wavelegths every 5\n");
exit(1);
}
int
main(
int argc,
char *argv[]
) {
int fa,nfa; /* argument we're looking at */
int verb = 0;
icxIllumeType illum = icxIT_D50; /* Spectral defaults */
xspect cust_illum; /* Custom illumination spectrum */
icxObserverType obType = icxOT_CIE_1931_2;
xspect custObserver[3]; /* If obType = icxOT_custom */
int obs = 0; /* If nz output observer */
double wl_short = 380.0, wl_long = 730.0, wl_width = 10.0;
int wl_n = 0;
int evy5 = 0;
error_program = argv[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) < argc) {
if (argv[fa+1][0] != '-') {
nfa = fa + 1;
na = argv[nfa]; /* next is seperate non-flag argument */
}
}
}
/* Spectral Illuminant type */
if (argv[fa][1] == 'i' || argv[fa][1] == 'I') {
fa = nfa;
if (na == NULL) usage();
if (strcmp(na, "A") == 0) {
illum = icxIT_A;
} else if (strcmp(na, "C") == 0) {
illum = icxIT_C;
} else if (strcmp(na, "D50") == 0) {
illum = icxIT_D50;
} else if (strcmp(na, "D50M2") == 0) {
illum = icxIT_D50M2;
} else if (strcmp(na, "D65") == 0) {
illum = icxIT_D65;
} else if (strcmp(na, "F5") == 0) {
illum = icxIT_F5;
} else if (strcmp(na, "F8") == 0) {
illum = icxIT_F8;
} else if (strcmp(na, "F10") == 0) {
illum = icxIT_F10;
} else { /* Assume it's a filename */
inst_meas_type mt;
illum = icxIT_custom;
if (read_xspect(&cust_illum, &mt, NULL, na) != 0)
usage();
if (mt != inst_mrt_none
&& mt != inst_mrt_emission
&& mt != inst_mrt_ambient
&& mt != inst_mrt_emission_flash
&& mt != inst_mrt_ambient_flash)
error("Custom illuminant '%s' is wrong measurement type",na);
}
}
/* Spectral Observer type */
else if (argv[fa][1] == 'o' || argv[fa][1] == 'O') {
fa = nfa;
if (na == NULL) usage();
if (strcmp(na, "1931_2") == 0) { /* Classic 2 degree */
obs = 1;
obType = icxOT_CIE_1931_2;
} else if (strcmp(na, "1964_10") == 0) { /* Classic 10 degree */
obs = 1;
obType = icxOT_CIE_1964_10;
} else if (strcmp(na, "2015_2") == 0) { /* Latest 2 degree */
obs = 1;
obType = icxOT_CIE_2015_2;
} else if (strcmp(na, "2015_10") == 0) { /* Latest 10 degree */
obs = 1;
obType = icxOT_CIE_2015_10;
} else if (strcmp(na, "1955_2") == 0) { /* Stiles and Burch 1955 2 degree */
obs = 1;
obType = icxOT_Stiles_Burch_2;
} else if (strcmp(na, "1978_2") == 0) { /* Judd and Voss 1978 2 degree */
obs = 1;
obType = icxOT_Judd_Voss_2;
} else if (strcmp(na, "shaw") == 0) { /* Shaw and Fairchilds 1997 2 degree */
obs = 1;
obType = icxOT_Shaw_Fairchild_2;
} else { /* Assume it's a filename */
obs = 1;
obType = icxOT_custom;
if (read_cmf(custObserver, na) != 0)
usage();
}
}
else if (argv[fa][1] == 'w' || argv[fa][1] == 'W') {
fa = nfa;
if (na == NULL) usage();
if (sscanf(na, " %lf,%lf,%lf ",&wl_short,&wl_long,&wl_width) != 3)
if (wl_short > wl_long)
usage();
}
else if (argv[fa][1] == '5') {
evy5 = 1;
}
/* Verbosity */
else if (argv[fa][1] == 'v' || argv[fa][1] == 'V') {
verb = 1;
} else {
usage();
}
}
else
break;
}
wl_n = (int)((wl_long - wl_short)/wl_width + 1.5);
if ((fabs(wl_short + (wl_n - 1.0) * wl_width) - wl_long) > 0.001)
error("Not an integer number of output samples");
if (obs) {
int i, j, k;
xspect *sp[3];
if (obType == icxOT_custom) {
sp[0] = &custObserver[0];
sp[1] = &custObserver[1];
sp[2] = &custObserver[2];
} else {
if (standardObserver(sp, obType) != 0)
error ("standardObserver returned error");
}
printf("/* %f - %f, %f spacing, %d samples */\n",wl_short,wl_long,wl_width,wl_n);
printf("{\n");
for (k = 0; k < 3; k++) {
printf(" {\n");
for (i = 0; i < wl_n; i++) {
double cwl, swl, sw, tw, outv;
int ns;
cwl = XSPECT_WL(wl_short, wl_long, wl_n, i);
ns = (int)(wl_width/0.1 + 0.5);
tw = outv = 0.0;
for (j = -ns; j <= ns; j++) {
swl = cwl + (j * wl_width)/ns;
sw = (ns - abs(j))/(double)ns;
tw += sw;
outv += sw * value_xspect(sp[k], swl);
}
outv /= tw;
if (!evy5 || i % 5 == 0)
printf(" /* %3.1f */ %1.10f%s\n",cwl,outv, i < (wl_n-1) ? "," : "");
else
printf(" %1.10f%s\n",outv, i < (wl_n-1) ? "," : "");
}
printf(" }%s\n",k < (3-1) ? "," : "");
}
printf("}\n");
} else {
int i, j;
xspect sp;
if (illum == icxIT_custom)
sp = cust_illum;
else {
if (standardIlluminant(&sp, illum, 0) != 0)
error ("standardIlluminant returned error");
}
printf("/* %f - %f, %f spacing, %d samples */\n",wl_short,wl_long,wl_width,wl_n);
printf("{\n");
for (i = 0; i < wl_n; i++) {
double cwl, swl, sw, tw, outv;
int ns;
cwl = XSPECT_WL(wl_short, wl_long, wl_n, i);
//printf("~1 output %f\n",cwl);
ns = (int)(wl_width/0.1 + 0.5);
tw = outv = 0.0;
for (j = -ns; j <= ns; j++) {
swl = cwl + (j * wl_width)/ns;
sw = (ns - abs(j))/(double)ns;
tw += sw;
//printf("~1 sample %f weight %f\n",swl,sw);
outv += sw * value_xspect(&sp, swl);
}
outv /= tw;
if (!evy5 || i % 5 == 0)
printf(" /* %3.1f */ %1.10f%s\n",cwl,outv, i < (wl_n-1) ? "," : "");
else
printf(" %1.10f%s\n",outv, i < (wl_n-1) ? "," : "");
}
printf("}\n");
}
return 0;
}

View File

@@ -0,0 +1,754 @@
/*
* International Color Consortium color transform expanded support
*
* Author: Graeme W. Gill
* Date: 8/5/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.
*
*/
/*
* This is some test code to test the FWA compensation
* feature of the spectal to CIE conversion.
*
*/
#define FILTERED_D65 /* Use Spectrolino filtered D65 instead of ideal D65 */
#define DOPLOT /* Graphs: Black = target curve */
/* Red = uncorrected curve */
/* Green = corrected curve */
#define DATAFILE /* Write the plot data to a data file */
#include <stdio.h>
#include <stdarg.h>
#include <math.h>
#include "aconfig.h"
#include "numlib.h"
#include "cgats.h"
#include "xspect.h"
#ifdef DOPLOT
# include "plot.h"
# include "ui.h"
#endif
/* Spectrolino filter "D65" illuminant */
static xspect il_sod65 = {
36, 380.0, 730.0, /* 36 bands from 380 to 730 in 10nm steps */
100.0, /* Scale factor */
{
17.42, 29.51, 36.54, 38.39, 38.15,
39.68, 44.7, 53.6, 64.26, 74.01,
82.39, 89.9, 93.45, 94.05, 91.59,
89.4, 93.69, 100.85, 99.66, 87.12,
78.34, 82.95, 91.31, 98.18, 99.99,
104.38, 120.06, 145.35, 172.8, 190.38,
192.46, 181.28, 163.7, 143.14, 123.57,
104.67
}
};
/* Material/illuminant record */
struct {
char *media; /* Media/process identifier */
char *illum; /* Primary illuminant identifier */
icxIllumeType ill; /* Illuminant used to get reflectance spectrum */
xspect white; /* Media on its own spectrum */
xspect black; /* Media with maximum colorant */
struct {
char *pdesc; /* Description of sample */
xspect s; /* Spectrum of it */
} patches[6];
} matilum[2][2] = { /* [Cromalin, Epson 10K] [A, D65] */
{
{
"Cromalin", /* Paper measured */
"Illuminant A", /* Illuminant measured under */
icxIT_A,
{ /* White */
36, 380.0, 730.0, /* 36 bands from 380 to 730 in 10nm steps */
1.0, /* Scale factor */
{
0.0376, 0.0217, 0.0325, 0.1779, 0.5891,
0.9366, 1.0307, 1.0241, 0.9996, 0.9738,
0.9521, 0.9355, 0.9245, 0.9174, 0.9147,
0.9113, 0.9112, 0.9118, 0.9111, 0.9148,
0.9147, 0.9162, 0.9172, 0.9185, 0.9197,
0.9194, 0.9213, 0.9239, 0.9259, 0.9257,
0.9259, 0.9250, 0.9271, 0.9293, 0.9296, 0.9310
}
},
{ /* Black */
36, 380.0, 730.0, /* 36 bands from 380 to 730 in 10nm steps */
1.0, /* Scale factor */
{
0.0000, 0.0000, 0.0000, 0.0000, 0.0000,
0.0000, 0.0000, 0.0000, 0.0000, 0.0000,
0.0000, 0.0000, 0.0000, 0.0000, 0.0000,
0.0000, 0.0000, 0.0000, 0.0000, 0.0000,
0.0000, 0.0000, 0.0000, 0.0000, 0.0000,
0.0000, 0.0000, 0.0000, 0.0000, 0.0000,
0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000
}
},
{
{
"30% Y",
{
36, 380.0, 730.0, /* 36 bands from 380 to 730 in 10nm steps */
1.0, /* Scale factor */
{
0.0274, 0.0161, 0.0218, 0.1072, 0.3077,
0.4280, 0.4532, 0.4530, 0.4508, 0.4498,
0.4585, 0.5019, 0.6137, 0.7716, 0.8680,
0.8939, 0.9000, 0.8999, 0.9015, 0.9098,
0.9153, 0.9193, 0.9212, 0.9230, 0.9245,
0.9247, 0.9267, 0.9294, 0.9317, 0.9315,
0.9317, 0.9317, 0.9331, 0.9354, 0.9357, 0.9366
}
}
},
{
"60% Y",
{
36, 380.0, 730.0, /* 36 bands from 380 to 730 in 10nm steps */
1.0, /* Scale factor */
{
0.0225, 0.0130, 0.0169, 0.0613, 0.1512,
0.1951, 0.2039, 0.2059, 0.2095, 0.2149,
0.2301, 0.2850, 0.4283, 0.6585, 0.8249,
0.8767, 0.8878, 0.8860, 0.8887, 0.9017,
0.9115, 0.9181, 0.9202, 0.9219, 0.9232,
0.9229, 0.9247, 0.9269, 0.9289, 0.9283,
0.9280, 0.9277, 0.9292, 0.9307, 0.9305, 0.9315
}
}
},
{
"90% Y",
{
36, 380.0, 730.0, /* 36 bands from 380 to 730 in 10nm steps */
1.0, /* Scale factor */
{
0.0195, 0.0114, 0.0140, 0.0314, 0.0568,
0.0664, 0.0691, 0.0708, 0.0760, 0.0836,
0.1003, 0.1571, 0.3087, 0.5728, 0.7861,
0.8602, 0.8759, 0.8737, 0.8781, 0.8952,
0.9094, 0.9185, 0.9215, 0.9234, 0.9250,
0.9248, 0.9267, 0.9292, 0.9312, 0.9307,
0.9305, 0.9300, 0.9313, 0.9328, 0.9321, 0.9339
}
}
},
{
"30% K",
{
36, 380.0, 730.0, /* 36 bands from 380 to 730 in 10nm steps */
1.0, /* Scale factor */
{
0.0163, 0.0117, 0.0181, 0.1018, 0.3029,
0.4324, 0.4585, 0.4539, 0.4437, 0.4330,
0.4247, 0.4180, 0.4140, 0.4113, 0.4108,
0.4095, 0.4097, 0.4101, 0.4100, 0.4117,
0.4119, 0.4126, 0.4133, 0.4141, 0.4152,
0.4156, 0.4169, 0.4187, 0.4200, 0.4206,
0.4211, 0.4214, 0.4224, 0.4240, 0.4243, 0.4256
}
}
},
{
"60% K",
{
36, 380.0, 730.0, /* 36 bands from 380 to 730 in 10nm steps */
1.0, /* Scale factor */
{
0.0087, 0.0070, 0.0138, 0.0539, 0.1378,
0.1802, 0.1872, 0.1840, 0.1794, 0.1748,
0.1711, 0.1686, 0.1669, 0.1661, 0.1659,
0.1656, 0.1657, 0.1661, 0.1660, 0.1670,
0.1670, 0.1675, 0.1680, 0.1686, 0.1693,
0.1700, 0.1707, 0.1720, 0.1728, 0.1735,
0.1740, 0.1745, 0.1749, 0.1761, 0.1759, 0.1779
}
}
},
{
"90% K",
{
36, 380.0, 730.0, /* 36 bands from 380 to 730 in 10nm steps */
1.0, /* Scale factor */
{
0.0044, 0.0040, 0.0090, 0.0243, 0.0430,
0.0503, 0.0508, 0.0485, 0.0460, 0.0440,
0.0423, 0.0412, 0.0406, 0.0404, 0.0404,
0.0404, 0.0407, 0.0409, 0.0411, 0.0415,
0.0418, 0.0422, 0.0424, 0.0429, 0.0434,
0.0440, 0.0444, 0.0452, 0.0459, 0.0465,
0.0469, 0.0473, 0.0477, 0.0483, 0.0489, 0.0496
}
}
}
}
},
{
"Cromalin",
"Illuminant filtered D65",
icxIT_D65,
{ /* White */
36, 380.0, 730.0, /* 36 bands from 380 to 730 in 10nm steps */
1.0, /* Scale factor */
{
0.0096, 0.0082, 0.0242, 0.1791, 0.6547,
1.0944, 1.2012, 1.1545, 1.0891, 1.0388,
1.0009, 0.9725, 0.9552, 0.9442, 0.9384,
0.9313, 0.9266, 0.9235, 0.9213, 0.9250,
0.9249, 0.9247, 0.9239, 0.9248, 0.9253,
0.9249, 0.9267, 0.9293, 0.9310, 0.9308,
0.9307, 0.9311, 0.9309, 0.9335, 0.9263, 0.8774
}
},
{ /* Black */
36, 380.0, 730.0, /* 36 bands from 380 to 730 in 10nm steps */
1.0, /* Scale factor */
{
0.0000, 0.0000, 0.0000, 0.0000, 0.0000,
0.0000, 0.0000, 0.0000, 0.0000, 0.0000,
0.0000, 0.0000, 0.0000, 0.0000, 0.0000,
0.0000, 0.0000, 0.0000, 0.0000, 0.0000,
0.0000, 0.0000, 0.0000, 0.0000, 0.0000,
0.0000, 0.0000, 0.0000, 0.0000, 0.0000,
0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000
}
},
{
{
"30% Y",
{
36, 380.0, 730.0, /* 36 bands from 380 to 730 in 10nm steps */
1.0, /* Scale factor */
{
0.0054, 0.0050, 0.0157, 0.1084, 0.3443,
0.4998, 0.5278, 0.5108, 0.4915, 0.4802,
0.4823, 0.5221, 0.6331, 0.7929, 0.8894,
0.9116, 0.9134, 0.9095, 0.9097, 0.9176,
0.9222, 0.9245, 0.9251, 0.9267, 0.9278,
0.9275, 0.9293, 0.9323, 0.9344, 0.9346,
0.9348, 0.9346, 0.9344, 0.9354, 0.9252, 0.8748
}
}
},
{
"60% Y",
{
36, 380.0, 730.0, /* 36 bands from 380 to 730 in 10nm steps */
1.0, /* Scale factor */
{
0.0039, 0.0042, 0.0117, 0.0632, 0.1733,
0.2333, 0.2430, 0.2364, 0.2315, 0.2315,
0.2440, 0.2976, 0.4421, 0.6777, 0.8461,
0.8950, 0.9014, 0.8967, 0.8971, 0.9095,
0.9187, 0.9234, 0.9242, 0.9263, 0.9270,
0.9257, 0.9280, 0.9303, 0.9326, 0.9322,
0.9315, 0.9317, 0.9314, 0.9306, 0.9169, 0.8664
}
}
},
{
"90% Y",
{
36, 380.0, 730.0, /* 36 bands from 380 to 730 in 10nm steps */
1.0, /* Scale factor */
{
0.0032, 0.0038, 0.0099, 0.0342, 0.0716,
0.0889, 0.0918, 0.0884, 0.0887, 0.0931,
0.1086, 0.1652, 0.3190, 0.5892, 0.8060,
0.8777, 0.8891, 0.8839, 0.8863, 0.9022,
0.9158, 0.9230, 0.9259, 0.9269, 0.9283,
0.9266, 0.9304, 0.9327, 0.9350, 0.9344,
0.9342, 0.9336, 0.9328, 0.9323, 0.9175, 0.8589
}
}
},
{
"30% K",
{
36, 380.0, 730.0, /* 36 bands from 380 to 730 in 10nm steps */
1.0, /* Scale factor */
{
0.0047, 0.0049, 0.0153, 0.1046, 0.3404,
0.5036, 0.5317, 0.5102, 0.4828, 0.4620,
0.4468, 0.4358, 0.4293, 0.4249, 0.4232,
0.4207, 0.4191, 0.4181, 0.4172, 0.4188,
0.4190, 0.4194, 0.4191, 0.4196, 0.4203,
0.4204, 0.4218, 0.4236, 0.4251, 0.4255,
0.4258, 0.4259, 0.4267, 0.4276, 0.4249, 0.4031
}
}
},
{
"60% K",
{
36, 380.0, 730.0, /* 36 bands from 380 to 730 in 10nm steps */
1.0, /* Scale factor */
{
0.0042, 0.0047, 0.0126, 0.0586, 0.1584,
0.2146, 0.2206, 0.2101, 0.1978, 0.1885,
0.1820, 0.1774, 0.1748, 0.1730, 0.1726,
0.1714, 0.1710, 0.1703, 0.1704, 0.1712,
0.1709, 0.1717, 0.1713, 0.1724, 0.1730,
0.1732, 0.1738, 0.1753, 0.1759, 0.1768,
0.1766, 0.1778, 0.1774, 0.1775, 0.1774, 0.1707
}
}
},
{
"90% K",
{
36, 380.0, 730.0, /* 36 bands from 380 to 730 in 10nm steps */
1.0, /* Scale factor */
{
0.0018, 0.0039, 0.0103, 0.0293, 0.0560,
0.0677, 0.0676, 0.0611, 0.0551, 0.0505,
0.0475, 0.0452, 0.0441, 0.0434, 0.0430,
0.0430, 0.0428, 0.0428, 0.0427, 0.0433,
0.0433, 0.0434, 0.0441, 0.0438, 0.0448,
0.0457, 0.0453, 0.0468, 0.0471, 0.0477,
0.0483, 0.0483, 0.0487, 0.0486, 0.0492, 0.0500
}
}
}
}
}
},
{
{
"Epson10K",
"Illuminant A",
icxIT_A,
{ /* White */
36, 380.0, 730.0, /* 36 bands from 380 to 730 in 10nm steps */
1.0, /* Scale factor */
{
0.4561, 0.4677, 0.5052, 0.6477, 0.8785,
0.9929, 1.0127, 0.9909, 0.9676, 0.9539,
0.9420, 0.9330, 0.9277, 0.9246, 0.9236,
0.9205, 0.9200, 0.9191, 0.9172, 0.9198,
0.9184, 0.9185, 0.9181, 0.9189, 0.9204,
0.9207, 0.9228, 0.9256, 0.9277, 0.9276,
0.9284, 0.9286, 0.9304, 0.9332, 0.9321, 0.9349
}
},
{ /* Black */
36, 380.0, 730.0, /* 36 bands from 380 to 730 in 10nm steps */
1.0, /* Scale factor */
{
0.0000, 0.0000, 0.0000, 0.0000, 0.0000,
0.0000, 0.0000, 0.0000, 0.0000, 0.0000,
0.0000, 0.0000, 0.0000, 0.0000, 0.0000,
0.0000, 0.0000, 0.0000, 0.0000, 0.0000,
0.0000, 0.0000, 0.0000, 0.0000, 0.0000,
0.0000, 0.0000, 0.0000, 0.0000, 0.0000,
0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000
}
},
{
{
"30% Y",
{
36, 380.0, 730.0, /* 36 bands from 380 to 730 in 10nm steps */
1.0, /* Scale factor */
{
0.3650, 0.3689, 0.3908, 0.4912, 0.6549,
0.7395, 0.7667, 0.7745, 0.7868, 0.8103,
0.8385, 0.8663, 0.8869, 0.8983, 0.9037,
0.9028, 0.9031, 0.9024, 0.9006, 0.9030,
0.9018, 0.9016, 0.9007, 0.9011, 0.9013,
0.9002, 0.9015, 0.9032, 0.9048, 0.9043,
0.9040, 0.9038, 0.9050, 0.9073, 0.9062, 0.9082
}
}
},
{
"60% Y",
{
36, 380.0, 730.0, /* 36 bands from 380 to 730 in 10nm steps */
1.0, /* Scale factor */
{
0.2376, 0.2286, 0.2349, 0.2856, 0.3740,
0.4290, 0.4642, 0.5005, 0.5513, 0.6172,
0.6959, 0.7750, 0.8340, 0.8683, 0.8848,
0.8884, 0.8901, 0.8900, 0.8884, 0.8906,
0.8892, 0.8893, 0.8884, 0.8885, 0.8886,
0.8875, 0.8885, 0.8903, 0.8917, 0.8910,
0.8911, 0.8908, 0.8924, 0.8951, 0.8940, 0.8962
}
}
},
{
"90% Y",
{
36, 380.0, 730.0, /* 36 bands from 380 to 730 in 10nm steps */
1.0, /* Scale factor */
{
0.0482, 0.0362, 0.0314, 0.0323, 0.0373,
0.0448, 0.0570, 0.0829, 0.1310, 0.2130,
0.3465, 0.5227, 0.6838, 0.7871, 0.8409,
0.8622, 0.8713, 0.8749, 0.8752, 0.8787,
0.8783, 0.8787, 0.8781, 0.8784, 0.8784,
0.8773, 0.8780, 0.8794, 0.8802, 0.8789,
0.8783, 0.8773, 0.8778, 0.8794, 0.8775, 0.8779
}
}
},
{
"30% K",
{
36, 380.0, 730.0, /* 36 bands from 380 to 730 in 10nm steps */
1.0, /* Scale factor */
{
0.3304, 0.3398, 0.3632, 0.4562, 0.6018,
0.6702, 0.6808, 0.6663, 0.6520, 0.6434,
0.6362, 0.6311, 0.6285, 0.6272, 0.6269,
0.6253, 0.6253, 0.6253, 0.6247, 0.6274,
0.6280, 0.6301, 0.6320, 0.6351, 0.6385,
0.6414, 0.6464, 0.6530, 0.6593, 0.6643,
0.6692, 0.6727, 0.6770, 0.6811, 0.6826, 0.6856
}
}
},
{
"60% K",
{
36, 380.0, 730.0, /* 36 bands from 380 to 730 in 10nm steps */
1.0, /* Scale factor */
{
0.1735, 0.1784, 0.1886, 0.2295, 0.2936,
0.3232, 0.3279, 0.3227, 0.3177, 0.3152,
0.3133, 0.3126, 0.3126, 0.3131, 0.3141,
0.3142, 0.3151, 0.3160, 0.3169, 0.3195,
0.3217, 0.3251, 0.3287, 0.3335, 0.3386,
0.3439, 0.3511, 0.3599, 0.3692, 0.3775,
0.3853, 0.3919, 0.3982, 0.4036, 0.4068, 0.4109
}
}
},
{
"90% K",
{
36, 380.0, 730.0, /* 36 bands from 380 to 730 in 10nm steps */
1.0, /* Scale factor */
{
0.0197, 0.0198, 0.0201, 0.0201, 0.0208,
0.0207, 0.0204, 0.0202, 0.0200, 0.0197,
0.0194, 0.0194, 0.0193, 0.0192, 0.0191,
0.0191, 0.0190, 0.0190, 0.0190, 0.0192,
0.0194, 0.0198, 0.0205, 0.0212, 0.0221,
0.0230, 0.0244, 0.0261, 0.0282, 0.0304,
0.0326, 0.0346, 0.0366, 0.0383, 0.0396, 0.0412
}
}
}
}
},
{
"Epson10K",
"Illuminant filtered D65",
icxIT_D65,
{ /* White */
36, 380.0, 730.0, /* 36 bands from 380 to 730 in 10nm steps */
1.0, /* Scale factor */
{
0.4452, 0.4631, 0.5041, 0.6692, 0.9582,
1.1083, 1.1289, 1.0717, 1.0191, 0.9929,
0.9721, 0.9560, 0.9483, 0.9439, 0.9419,
0.9374, 0.9357, 0.9337, 0.9313, 0.9340,
0.9330, 0.9329, 0.9320, 0.9328, 0.9341,
0.9339, 0.9366, 0.9387, 0.9406, 0.9405,
0.9404, 0.9405, 0.9414, 0.9455, 0.9369, 0.9289
}
},
{ /* Black */
36, 380.0, 730.0, /* 36 bands from 380 to 730 in 10nm steps */
1.0, /* Scale factor */
{
0.0000, 0.0000, 0.0000, 0.0000, 0.0000,
0.0000, 0.0000, 0.0000, 0.0000, 0.0000,
0.0000, 0.0000, 0.0000, 0.0000, 0.0000,
0.0000, 0.0000, 0.0000, 0.0000, 0.0000,
0.0000, 0.0000, 0.0000, 0.0000, 0.0000,
0.0000, 0.0000, 0.0000, 0.0000, 0.0000,
0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000
}
},
{
{
"30% Y",
{
36, 380.0, 730.0, /* 36 bands from 380 to 730 in 10nm steps */
1.0, /* Scale factor */
{
0.3538, 0.3632, 0.3888, 0.5058, 0.7111,
0.8221, 0.8512, 0.8334, 0.8251, 0.8392,
0.8609, 0.8832, 0.9013, 0.9113, 0.9157,
0.9137, 0.9128, 0.9113, 0.9086, 0.9111,
0.9103, 0.9094, 0.9091, 0.9083, 0.9085,
0.9080, 0.9091, 0.9104, 0.9118, 0.9104,
0.9099, 0.9099, 0.9094, 0.9111, 0.9054, 0.8793
}
}
},
{
"60% Y",
{
36, 380.0, 730.0, /* 36 bands from 380 to 730 in 10nm steps */
1.0, /* Scale factor */
{
0.2220, 0.2209, 0.2299, 0.2901, 0.4010,
0.4716, 0.5092, 0.5337, 0.5732, 0.6337,
0.7095, 0.7848, 0.8422, 0.8755, 0.8907,
0.8933, 0.8938, 0.8927, 0.8909, 0.8929,
0.8922, 0.8912, 0.8897, 0.8902, 0.8900,
0.8893, 0.8896, 0.8915, 0.8932, 0.8918,
0.8921, 0.8915, 0.8921, 0.8939, 0.8825, 0.8575
}
}
},
{
"90% Y",
{
36, 380.0, 730.0, /* 36 bands from 380 to 730 in 10nm steps */
1.0, /* Scale factor */
{
0.0326, 0.0287, 0.0269, 0.0295, 0.0376,
0.0469, 0.0605, 0.0862, 0.1343, 0.2162,
0.3503, 0.5257, 0.6862, 0.7889, 0.8420,
0.8632, 0.8719, 0.8753, 0.8753, 0.8784,
0.8776, 0.8778, 0.8778, 0.8783, 0.8775,
0.8772, 0.8777, 0.8791, 0.8808, 0.8793,
0.8784, 0.8770, 0.8758, 0.8757, 0.8626, 0.8106
}
}
},
{
"30% K",
{
36, 380.0, 730.0, /* 36 bands from 380 to 730 in 10nm steps */
1.0, /* Scale factor */
{
0.3243, 0.3369, 0.3635, 0.4708, 0.6532,
0.7439, 0.7542, 0.7167, 0.6839, 0.6673,
0.6546, 0.6454, 0.6412, 0.6387, 0.6380,
0.6357, 0.6351, 0.6341, 0.6334, 0.6363,
0.6367, 0.6388, 0.6400, 0.6431, 0.6465,
0.6491, 0.6532, 0.6591, 0.6656, 0.6699,
0.6743, 0.6778, 0.6816, 0.6859, 0.6815, 0.6758
}
}
},
{
"60% K",
{
36, 380.0, 730.0, /* 36 bands from 380 to 730 in 10nm steps */
1.0, /* Scale factor */
{
0.1707, 0.1772, 0.1895, 0.2374, 0.3174,
0.3566, 0.3616, 0.3464, 0.3329, 0.3272,
0.3228, 0.3201, 0.3196, 0.3198, 0.3208,
0.3203, 0.3207, 0.3217, 0.3221, 0.3249,
0.3269, 0.3295, 0.3339, 0.3375, 0.3427,
0.3483, 0.3545, 0.3635, 0.3726, 0.3808,
0.3881, 0.3949, 0.4003, 0.4053, 0.4052, 0.3962
}
}
},
{
"90% K",
{
36, 380.0, 730.0, /* 36 bands from 380 to 730 in 10nm steps */
1.0, /* Scale factor */
{
0.0206, 0.0205, 0.0202, 0.0205, 0.0213,
0.0217, 0.0210, 0.0207, 0.0202, 0.0199,
0.0198, 0.0197, 0.0197, 0.0195, 0.0196,
0.0193, 0.0192, 0.0194, 0.0194, 0.0194,
0.0197, 0.0198, 0.0204, 0.0214, 0.0223,
0.0236, 0.0242, 0.0265, 0.0283, 0.0306,
0.0330, 0.0347, 0.0370, 0.0389, 0.0394, 0.0383
}
}
}
}
}
}
};
/* ---------------------------------------------------------- */
int
main(void) {
int m, ps, ss, pn;
#ifdef DATAFILE
FILE *df;
#endif
printf("Hi there\n");
#ifdef DATAFILE
if ((df = fopen("spectest.dat", "w")) == NULL)
error ("Unable to open data file '%s'","spectest.dat");
#endif
/* For each material and illuminant */
for (m = 0; m < 2; m++) {
printf("Material '%s'\n", matilum[m][0].media);
/* For each light source as primary (target/check), other as secondary (instrument) */
for (ps = 0; ps < 2; ps++) {
xsp2cie *pcon, *scon; /* Conversions */
xspect pill, sill; /* Illuminants */
ss = 1 - ps; /* Opposite */
#ifdef FILTERED_D65
if (matilum[m][ps].ill == icxIT_D65)
pill = il_sod65;
else
#endif
standardIlluminant(&pill, matilum[m][ps].ill, 0); /* Target/check */
#ifdef FILTERED_D65
if (matilum[m][ss].ill == icxIT_D65)
sill = il_sod65;
else
#endif
standardIlluminant(&sill, matilum[m][ss].ill, 0); /* Instrument */
/* Create two conversions for the target/check illuminant */
if ((pcon = new_xsp2cie(icxIT_custom, 0.0, &pill, icxOT_Shaw_Fairchild_2,
NULL, icSigLabData, 1)) == NULL)
error ("Creating conversion failed");
if ((scon = new_xsp2cie(icxIT_custom, 0.0, &pill, icxOT_Shaw_Fairchild_2,
NULL, icSigLabData, 1)) == NULL)
error ("Creating conversion failed");
/* Tell the secondary conversion to allow for instrument illuminant */
if (scon->set_fwa(scon, &sill, NULL, &matilum[m][ss].white))
error ("Setting FWA compensation failed");
printf("Primary (Target/Check) '%s', Secondary (Instrument)'%s'\n",
matilum[m][ps].illum, matilum[m][ss].illum);
/* For each test patch */
for (pn = 0; pn < 6; pn++) {
int i, j;
double plab[3];
double slab[3];
double sclab[3];
xspect psp; /* Reference spectrum */
xspect ssp; /* un-compensated spectrum */
xspect scsp; /* Compensated spectrum */
double de, cde;
#ifdef DOPLOT
#define XRES 400
double xx[XRES];
double y1[XRES];
double y2[XRES];
double y3[XRES];
#endif /* DOPLOT */
/* Compute reference value for target illuminant */
pcon->sconvert(pcon, &psp, plab, &matilum[m][ps].patches[pn].s);
/* Compute uncompensated value for target illuminant */
pcon->sconvert(pcon, &ssp, slab, &matilum[m][ss].patches[pn].s);
/* Compute compensated value for target illuminant */
scon->sconvert(scon, &scsp, sclab, &matilum[m][ss].patches[pn].s);
de = 0.0;
for (j = 0; j < 3; j++) {
double tt = plab[j] - slab[j];
de += tt * tt;
}
de = sqrt(de);
printf("Patch '%s', Ref %f %f %f, Other %f %f %f DE %f\n",
matilum[m][ps].patches[pn].pdesc, plab[0], plab[1], plab[2],
slab[0], slab[1], slab[2], de);
cde = 0.0;
for (j = 0; j < 3; j++) {
double tt = plab[j] - sclab[j];
cde += tt * tt;
}
cde = sqrt(cde);
printf("Patch '%s', Ref %f %f %f, COther %f %f %f DE %f\n",
matilum[m][ps].patches[pn].pdesc, plab[0], plab[1], plab[2],
sclab[0], sclab[1], sclab[2], cde);
printf("DE change %f\n",cde - de);
printf("\n");
#ifdef DOPLOT
for (i = 0; i < psp.spec_n; i++) {
double ww;
ww = (psp.spec_wl_long - psp.spec_wl_short)
* ((double)i/(psp.spec_n-1.0)) + psp.spec_wl_short;
xx[i] = ww;
y1[i] = ssp.spec[i]; /* Black - Input */
y2[i] = scsp.spec[i]; /* Red - Estimate */
y3[i] = psp.spec[i]; /* Green - Target */
}
do_plot(xx,y1,y2,y3,i);
#endif /* DOPLOT */
#ifdef DATAFILE
fprintf(df,"\nPrimary (Target/Check) '%s', Secondary (Instrument)'%s'\n",
matilum[m][ps].illum, matilum[m][ss].illum);
fprintf(df,"Patch '%s', Ref %f %f %f, Other %f %f %f DE %f\n",
matilum[m][ps].patches[pn].pdesc, plab[0], plab[1], plab[2],
slab[0], slab[1], slab[2], de);
fprintf(df,"Patch '%s', Ref %f %f %f, COther %f %f %f DE %f\n",
matilum[m][ps].patches[pn].pdesc, plab[0], plab[1], plab[2],
sclab[0], sclab[1], sclab[2], cde);
fprintf(df,"NM Ref. Un-comp. Comp.\n");
for (i = 0; i < psp.spec_n; i++) {
double ww;
ww = (psp.spec_wl_long - psp.spec_wl_short)
* ((double)i/(psp.spec_n-1.0)) + psp.spec_wl_short;
fprintf(df,"%d %f %f %f\n",((int)ww), psp.spec[i], ssp.spec[i], scsp.spec[i]);
}
#endif /* DATAFILE */
}
pcon->del(pcon);
scon->del(scon);
}
}
#ifdef DATAFILE
fclose(df);
#endif
return 0;
}

View File

@@ -0,0 +1,274 @@
/*
* International Color Consortium color transform expanded support
*
* Author: Graeme W. Gill
* Date: 30/3/2007
* Version: 1.00
*
* Copyright 2002 - 2007 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.
*
*/
/*
* This is some more test code to test the FWA compensation
* feature of the spectal to CIE conversion.
* Check how well the FWA is estimated from some paper samples.
*/
#define DOPLOT /* Graphs: Black = target curve */
/* Red = uncorrected curve */
/* Green = corrected curve */
#include <stdio.h>
#include <stdarg.h>
#include <math.h>
#include "aconfig.h"
#include "cgats.h"
#include "xspect.h"
#include "insttypes.h"
//#include "inst.h"
#include "numlib.h"
#ifdef DOPLOT
# include "plot.h"
# include "ui.h"
#endif
/* Normal 'A' spectra, then UV filtered version */
xspect mat[2][20] = {
/* 'A' illuminant */
{
{ /* 1 */
36, 380.0, 730.0, /* 36 bands from 380 to 730 in 10nm steps */
100.0, /* Scale factor */
{
14.267, 15.584, 20.723, 41.993, 84.338, 104.728, 108.065, 104.009, 98.717, 95.746, 93.079, 90.568, 88.689, 87.157, 85.795, 84.303, 83.109, 81.981, 80.966, 80.685, 80.361, 80.369, 80.530, 81.249, 82.823, 85.006, 87.685, 90.146, 91.902, 92.799, 93.246, 93.458, 93.767, 94.212, 94.372, 94.651
}
},
{ /* 2 */
36, 380.0, 730.0, /* 36 bands from 380 to 730 in 10nm steps */
100.0, /* Scale factor */
{
14.983, 16.831, 22.426, 43.716, 84.430, 105.538, 109.685, 105.582, 100.060, 96.944, 94.119, 91.251, 88.909, 86.894, 84.962, 83.264, 82.636, 82.203, 81.208, 80.950, 81.420, 82.457, 83.033, 83.040, 83.033, 83.700, 85.422, 87.339, 88.728, 89.234, 89.152, 88.913, 89.203, 89.990, 90.613, 91.301
}
},
{ /* 3 */
36, 380.0, 730.0, /* 36 bands from 380 to 730 in 10nm steps */
100.0, /* Scale factor */
{
24.488, 29.581, 37.749, 69.706, 94.472, 100.591, 100.273, 98.291, 97.532, 96.351, 95.134, 94.261, 93.428, 92.569, 91.950, 91.181, 90.660, 90.115, 89.426, 89.326, 89.147, 89.154, 89.151, 89.321, 89.636, 89.984, 90.717, 91.607, 92.478, 93.171, 93.867, 94.470, 95.044, 95.638, 95.840, 96.071
}
},
{ /* 4 */
36, 380.0, 730.0, /* 36 bands from 380 to 730 in 10nm steps */
100.0, /* Scale factor */
{
44.123, 45.345, 46.333, 52.603, 77.805, 95.763, 102.401, 99.326, 95.610, 95.188, 94.009, 92.570, 92.002, 91.687, 91.396, 90.911, 90.662, 90.464, 90.104, 90.172, 89.881, 89.799, 89.690, 89.664, 89.708, 89.679, 89.894, 90.203, 90.473, 90.556, 90.720, 90.841, 91.078, 91.416, 91.445, 91.559
}
},
{ /* 5 */
36, 380.0, 730.0, /* 36 bands from 380 to 730 in 10nm steps */
100.0, /* Scale factor */
{
59.175, 67.893, 72.295, 79.833, 89.531, 92.976, 93.994, 93.660, 93.322, 93.028, 92.527, 91.913, 91.195, 90.494, 89.974, 89.258, 88.761, 88.208, 87.470, 87.222, 86.769, 86.608, 86.590, 86.842, 87.344, 87.956, 88.924, 90.036, 91.088, 91.870, 92.720, 93.474, 94.280, 95.064, 95.370, 95.685
}
},
{ /* 6 */
36, 380.0, 730.0, /* 36 bands from 380 to 730 in 10nm steps */
100.0, /* Scale factor */
{
37.749, 42.672, 50.439, 75.066, 95.496, 97.450, 98.295, 95.268, 93.331, 92.634, 91.847, 91.403, 91.410, 91.538, 91.791, 91.771, 91.955, 92.073, 91.974, 92.312, 92.335, 92.575, 92.698, 92.835, 93.066, 93.277, 93.761, 94.294, 94.661, 94.719, 94.749, 94.757, 95.001, 95.429, 95.619, 95.931
}
},
{ /* 7 */
36, 380.0, 730.0, /* 36 bands from 380 to 730 in 10nm steps */
100.0, /* Scale factor */
{
57.122, 62.955, 67.576, 72.801, 76.460, 78.437, 79.846, 80.856, 81.509, 82.098, 82.427, 82.523, 82.718, 82.593, 82.345, 82.122, 82.183, 82.198, 82.035, 82.353, 82.618, 83.188, 83.512, 83.549, 83.583, 84.044, 85.291, 86.585, 87.429, 87.476, 87.439, 87.590, 88.241, 89.077, 89.530, 90.008
}
},
{ /* 8 */
36, 380.0, 730.0, /* 36 bands from 380 to 730 in 10nm steps */
100.0, /* Scale factor */
{
58.637, 64.082, 68.830, 73.651, 76.911, 78.772, 80.309, 81.192, 82.121, 82.541, 82.893, 83.226, 83.147, 83.038, 83.058, 82.702, 82.727, 83.025, 82.982, 83.281, 83.705, 84.410, 84.663, 84.619, 84.804, 85.372, 86.410, 87.352, 88.013, 88.340, 88.616, 88.753, 89.031, 89.572, 89.914, 90.712
}
},
{ /* 9 */
36, 380.0, 730.0, /* 36 bands from 380 to 730 in 10nm steps */
100.0, /* Scale factor */
{
32.774, 38.428, 47.037, 72.668, 97.391, 102.330, 102.404, 99.655, 97.093, 95.368, 93.825, 92.567, 91.674, 90.957, 90.507, 89.992, 89.784, 89.565, 89.259, 89.610, 89.881, 90.199, 90.325, 90.465, 90.671, 90.878, 91.428, 92.051, 92.507, 92.607, 92.842, 93.236, 93.963, 94.682, 94.942, 95.146
}
},
{ /* 10 */
36, 380.0, 730.0, /* 36 bands from 380 to 730 in 10nm steps */
100.0, /* Scale factor */
{
66.797, 69.934, 72.229, 74.822, 76.630, 78.036, 78.706, 79.021, 79.371, 79.281, 79.175, 79.144, 79.095, 79.119, 79.272, 79.143, 79.064, 78.924, 78.588, 78.615, 78.296, 78.132, 77.969, 77.909, 77.943, 77.812, 77.925, 78.115, 78.213, 78.133, 78.181, 78.345, 78.757, 79.268, 79.782, 80.318
}
},
{ /* 11 */
36, 380.0, 730.0, /* 36 bands from 380 to 730 in 10nm steps */
100.0, /* Scale factor */
{
29.478, 33.585, 40.588, 60.658, 85.350, 92.218, 93.564, 91.366, 88.913, 87.742, 86.793, 86.094, 85.874, 85.915, 86.117, 86.130, 86.333, 86.510, 86.589, 87.051, 87.157, 87.444, 87.677, 88.083, 88.545, 88.907, 89.442, 90.002, 90.440, 90.591, 90.787, 91.029, 91.434, 91.878, 92.014, 92.373
}
},
{ /* 12 */
0, 380.0, 730.0, /* 36 bands from 380 to 730 in 10nm steps */
100.0, /* Scale factor */
{
0.0
}
}
},
/* UV filtered */
{
{ /* 1 */
36, 380.0, 730.0, /* 36 bands from 380 to 730 in 10nm steps */
100.0, /* Scale factor */
{
28.419, 33.018, 42.215, 51.413, 69.808, 85.626, 88.515, 88.544, 88.433, 88.268, 87.971, 87.553, 86.919, 86.138, 85.337, 84.207, 83.249, 82.288, 81.393, 81.182, 80.923, 80.961, 81.138, 81.828, 83.388, 85.583, 88.212, 90.650, 92.373, 93.250, 93.633, 93.778, 94.089, 94.424, 94.498, 94.910
}
},
{ /* 2 */
36, 380.0, 730.0, /* 36 bands from 380 to 730 in 10nm steps */
100.0, /* Scale factor */
{
28.104, 32.711, 41.924, 51.137, 69.563, 85.811, 89.046, 89.203, 89.062, 88.799, 88.455, 87.735, 86.713, 85.504, 84.103, 82.802, 82.413, 82.146, 81.252, 81.067, 81.568, 82.671, 83.263, 83.214, 83.248, 83.963, 85.592, 87.499, 88.976, 89.428, 89.257, 89.095, 89.302, 90.015, 90.578, 91.308
}
},
{ /* 3 */
36, 380.0, 730.0, /* 36 bands from 380 to 730 in 10nm steps */
100.0, /* Scale factor */
{
70.653, 72.514, 76.238, 79.961, 87.407, 92.047, 92.848, 93.040, 93.369, 93.389, 93.257, 93.088, 92.713, 92.239, 91.847, 91.231, 90.837, 90.378, 89.765, 89.702, 89.530, 89.587, 89.577, 89.724, 90.020, 90.395, 91.115, 91.948, 92.866, 93.526, 94.160, 94.800, 95.340, 95.785, 96.001, 96.205
}
},
{ /* 4 */
36, 380.0, 730.0, /* 36 bands from 380 to 730 in 10nm steps */
100.0, /* Scale factor */
{
39.580, 43.280, 50.681, 58.081, 72.882, 86.792, 90.031, 90.136, 90.086, 90.403, 90.619, 90.769, 90.883, 90.942, 91.074, 90.832, 90.758, 90.656, 90.367, 90.489, 90.233, 90.180, 90.049, 90.013, 90.100, 90.021, 90.238, 90.576, 90.811, 90.900, 91.031, 91.114, 91.314, 91.537, 91.438, 91.634
}
},
{ /* 5 */
36, 380.0, 730.0, /* 36 bands from 380 to 730 in 10nm steps */
100.0, /* Scale factor */
{
77.775, 78.760, 80.729, 82.698, 86.637, 89.962, 90.821, 91.214, 91.679, 91.804, 91.748, 91.501, 91.059, 90.523, 90.154, 89.541, 89.136, 88.644, 87.956, 87.743, 87.265, 87.155, 87.163, 87.349, 87.809, 88.407, 89.293, 90.340, 91.417, 92.181, 92.880, 93.690, 94.331, 94.912, 95.209, 95.549
}
},
{ /* 6 */
36, 380.0, 730.0, /* 36 bands from 380 to 730 in 10nm steps */
100.0, /* Scale factor */
{
70.130, 71.508, 74.263, 77.018, 82.527, 85.915, 86.959, 87.455, 88.211, 88.869, 89.502, 90.186, 90.813, 91.367, 91.951, 92.170, 92.518, 92.720, 92.703, 93.117, 93.192, 93.453, 93.621, 93.771, 94.057, 94.262, 94.695, 95.157, 95.508, 95.572, 95.574, 95.771, 96.080, 96.418, 96.573, 96.865
}
},
{ /* 7 */
36, 380.0, 730.0, /* 36 bands from 380 to 730 in 10nm steps */
100.0, /* Scale factor */
{
70.903, 71.374, 72.316, 73.259, 75.144, 77.016, 78.664, 79.797, 80.774, 81.501, 81.859, 82.236, 82.471, 82.309, 82.265, 82.050, 82.044, 82.123, 82.052, 82.288, 82.492, 83.143, 83.510, 83.466, 83.495, 84.034, 85.312, 86.528, 87.301, 87.403, 87.410, 87.697, 88.149, 88.800, 89.108, 89.670
}
},
{ /* 8 */
36, 380.0, 730.0, /* 36 bands from 380 to 730 in 10nm steps */
100.0, /* Scale factor */
{
71.356, 71.858, 72.862, 73.867, 75.875, 77.895, 79.391, 80.476, 81.601, 82.106, 82.559, 83.048, 83.056, 83.041, 83.107, 82.713, 82.781, 83.133, 83.088, 83.355, 83.790, 84.538, 84.821, 84.683, 84.892, 85.550, 86.553, 87.512, 88.192, 88.505, 88.733, 88.959, 89.162, 89.539, 89.868, 90.603
}
},
{ /* 9 */
36, 380.0, 730.0, /* 36 bands from 380 to 730 in 10nm steps */
100.0, /* Scale factor */
{
68.893, 70.690, 74.285, 77.880, 85.070, 89.766, 90.646, 90.753, 90.971, 90.955, 90.895, 90.798, 90.641, 90.406, 90.284, 89.991, 89.943, 89.840, 89.591, 89.991, 90.279, 90.608, 90.760, 90.860, 91.096, 91.360, 91.836, 92.435, 92.923, 93.002, 93.227, 93.684, 94.312, 94.851, 95.151, 95.382
}
},
{ /* 10 */
36, 380.0, 730.0, /* 36 bands from 380 to 730 in 10nm steps */
100.0, /* Scale factor */
{
71.725, 72.140, 72.969, 73.798, 75.457, 76.827, 77.511, 78.066, 78.560, 78.621, 78.659, 78.711, 78.736, 78.759, 78.905, 78.808, 78.824, 78.662, 78.369, 78.382, 78.062, 77.906, 77.778, 77.756, 77.796, 77.681, 77.606, 77.754, 77.733, 77.637, 77.658, 77.616, 77.867, 78.183, 78.446, 78.888
}
},
{ /* 11 */
36, 380.0, 730.0, /* 36 bands from 380 to 730 in 10nm steps */
100.0, /* Scale factor */
{
56.723, 58.809, 62.983, 67.157, 75.504, 81.580, 82.970, 83.489, 84.048, 84.454, 84.913, 85.415, 85.885, 86.365, 86.852, 87.052, 87.381, 87.634, 87.777, 88.262, 88.371, 88.665, 88.885, 89.250, 89.674, 89.930, 90.462, 90.913, 91.339, 91.367, 91.548, 91.681, 92.032, 92.466, 92.440, 92.765
}
},
{ /* 12 */
0, 380.0, 730.0, /* 36 bands from 380 to 730 in 10nm steps */
100.0, /* Scale factor */
{
0.0
}
}
}
};
int
main(void) {
int m, i;
xspect insp;
double xx[500],y1[500],y2[500],y3[500];
if (inst_illuminant(&insp, instSpectrolino) != 0)
error ("Instrument doesn't have an FWA illuminent");
printf("Hi there\n");
/* For each material */
for (m = 0; ; m++) {
xsp2cie *con; /* Conversions */
if (mat[0][m].spec_n == 0)
break;
printf("Material %d\n", m+1);
/* Create two conversions for the target/check illuminant */
if ((con = new_xsp2cie(icxIT_D50, 0.0, NULL, icxOT_CIE_1931_2,
NULL, icSigLabData, 1)) == NULL)
error ("Creating conversion failed");
if (con->set_fwa(con, &insp, NULL, &mat[0][m]))
error ("Setting FWA compensation failed");
for (i = 0; i < mat[0][m].spec_n; i++) {
double ww;
ww = (mat[0][m].spec_wl_long - mat[0][m].spec_wl_short)
* ((double)i/(mat[0][m].spec_n-1.0)) + mat[0][m].spec_wl_short;
xx[i] = ww;
y1[i] = mat[0][m].spec[i]; /* 'A' Black = Input Measurement */
y2[i] = con->media.spec[i] * 100.0; /* Red = Estimated media */
y3[i] = mat[1][m].spec[i]; /* Green = Target Measurement with UV */
}
// do_plot(xx,y1,y2,y3,i);
do_plot_x(xx,y1,y2,y3,i,
1, 370.0, 740.0, 0.0, 120.0, 2.0);
con->del(con);
}
return 0;
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

992
Argyll_V3.5.0/xicc/tm3015.c Normal file
View File

@@ -0,0 +1,992 @@
/*
* Author: Graeme W. Gill
* Date: 4/1/19
* Version: 1.00
*
* Copyright 2019 Graeme W. Gill
* All rights reserved.
*
* This material is licenced under the GNU GENERAL PUBLIC LICENSE Version 2 or later :-
* see the License2.txt file for licencing details.
*
* Based on icx_CIE1995_CRI() and icx_EBU2012_TLCI()
*/
/*
* These functions compute IES TM-30-15,
* "IES Method for Evaluating Light Source Color Rendition"
*/
/*
* TTBD:
*
*/
#include <stdlib.h>
#include <sys/types.h>
#include <time.h>
#include <string.h>
#include <math.h>
# include "aconfig.h"
#ifndef SALONEINSTLIB
# include "numlib.h"
# include "plot.h" /* For debugging */
# include "ui.h"
#else
# include "numsup.h"
# include "sa_conv.h"
#endif
#include "cgats.h"
#include "conv.h"
#include "xspect.h"
#undef DEBUG
#undef TRACE_CAT
#undef USE_5NM /* To match spreadsheet */
#ifdef DEBUG
# define DBGA g_log, 0 /* First argument to DBGF() */
# define DBGF(xx) a1logd xx ;
#else
# define DBG(xx)
# define DBGF(xx)
#endif
#ifdef DEBUG
# define REFTRACE(xxxx) fprintf xxxx ;
# define REFOUT stderr
#else
# define REFTRACE(xxxx)
#endif
#ifndef STANDALONE_TEST
static double MCAT02[3][3] = {
{ 0.7328, 0.4296, -0.1624 },
{ -0.7036, 1.6975, 0.0061 },
{ 0.0030, 0.0136, 0.9834 }
};
static double MHPE[3][3] = {
{ 0.38971, 0.68898, -0.07868 },
{ -0.22981, 1.18340, 0.04641 },
{ 0.00000, 0.00000, 1.00000 }
};
/* Create the CIECAM02 conversion from XYZ10 to R'G'B' given the XYZ white point */
/* Returns Aw */
static double comp_rgbd_mtx(double mat[3][3], double wXYZ[3]) {
double wRGB[3]; /* White RGB values */
double vkmat[3][3]; /* Von Kries matrix */
double iMCAT02[3][3];
double wRGBd[3], wRGBda[3];
double Aw;
int j;
// mat = xyz -> RGB /= RwGwBw -> inv MCAT02 -> MHPE
REFTRACE((REFOUT, "comp_rgbd_mtx with XYZ %f %f %f\n", wXYZ[0], wXYZ[1], wXYZ[2]))
// Start with CAT matrix
icmCpy3x3(mat, MCAT02);
/* Setup the Von Kries white point adaptation matrix */
icmSetUnity3x3(vkmat);
icmMulBy3x3(wRGB, MCAT02, wXYZ); // Wxyz -> MCAT02 -> RwGwBw
vkmat[0][0] = 1.0/wRGB[0];
vkmat[1][1] = 1.0/wRGB[1];
vkmat[2][2] = 1.0/wRGB[2];
icmMul3x3(mat, vkmat);
icmInverse3x3(iMCAT02, MCAT02);
icmMul3x3(mat, iMCAT02);
icmMul3x3(mat, MHPE);
/* White XYZ to chromaticly adjusted RGB' */
icmMulBy3x3(wRGBd, mat, wXYZ);
for (j = 0; j < 3; j++) {
double tt = pow(0.7937 * wRGBd[j], 0.42);
wRGBda[j] = (400.0 * tt) / (27.13 + tt) + 0.1;
}
/* Achromatic response of white */
Aw = (2.0 * wRGBda[0] + wRGBda[1] + (1.0/20.0) * wRGBda[2] - 0.305) * 1.0003;
REFTRACE((REFOUT, " wRGBda %f %f %f Aw %f\n", wRGBda[0], wRGBda[1], wRGBda[2], Aw))
return Aw;
}
#ifdef TRACE_CAT
static void apply_mtx_trace(double rgb[3], double inXYZ[3], double wXYZ[3]) {
double wRGB[3]; /* White RGB values */
double iMCAT02[3][3];
double sXYZ[3]; /* Sample RGB */
double sRGB[3]; /* Sample RGB */
printf("\napply_mtx_trace:\n");
printf(" wXYZ %f %f %f\n", wXYZ[0], wXYZ[1], wXYZ[2]);
// Wxyz -> MCAT02 -> RwGwBw
icmMulBy3x3(wRGB, MCAT02, wXYZ);
printf(" wRGB %f %f %f\n", wRGB[0], wRGB[1], wRGB[2]);
// ---------------------------
//mat = xyz -> RGB /= RwGwBw -> inv MCAT02 -> MHPE
icmCpy3(sXYZ, inXYZ);
printf(" sXYZ %f %f %f\n", sXYZ[0], sXYZ[1], sXYZ[2]);
icmMulBy3x3(sRGB, MCAT02, sXYZ);
printf(" sRGB %f %f %f\n", sRGB[0], sRGB[1], sRGB[2]);
sRGB[0] *= 1.0/wRGB[0];
sRGB[1] *= 1.0/wRGB[1];
sRGB[2] *= 1.0/wRGB[2];
printf(" CAT sRGB %f %f %f\n", sRGB[0], sRGB[1], sRGB[2]);
icmInverse3x3(iMCAT02, MCAT02);
icmMulBy3x3(sXYZ, iMCAT02, sRGB);
printf(" CAT sXYZ %f %f %f\n", sXYZ[0], sXYZ[1], sXYZ[2]);
icmMulBy3x3(rgb, MHPE, sXYZ);
printf(" sRGBd %f %f %f\n", rgb[0], rgb[1], rgb[2]);
printf("\n");
}
#endif /* TRACE_CAT */
/* Convert XYZ to CIECAM02 UCS */
/* mat is the XYZ10 to R'G'B' for the given white (see above) */
/* Aw is the acromatic response of white (see above) */
static void ciecam02_ucs(double Jabd[3], double Aw, double mat[3][3], double inXYZ[3]) {
double iRGBd[3];
double iRGBda[3];
double a, b;
double rS, ttd;
double A, J, h, e, ss, C, M;
double Jd, ad, bd, Md;
int j;
REFTRACE((REFOUT, "ciecam02_ucs with XYZ %f %f %f\n", inXYZ[0], inXYZ[1], inXYZ[2]))
/* XYZ to chromaticly adjusted RGB' */
icmMulBy3x3(iRGBd, mat, inXYZ);
REFTRACE((REFOUT, " iRGBd %f %f %f\n", iRGBd[0], iRGBd[1], iRGBd[2]))
/* Post-adapted cone response of white */
for (j = 0; j < 3; j++) {
double tt = pow(0.7937 * iRGBd[j], 0.42);
iRGBda[j] = (400.0 * tt) / (27.13 + tt) + 0.1;
}
REFTRACE((REFOUT, " iRGBda %f %f %f\n", iRGBda[0], iRGBda[1], iRGBda[2]))
/* Preliminary red-green & yellow-blue opponent dimensions */
a = iRGBda[0] - 12.0 * iRGBda[1]/11.0 + iRGBda[2]/11.0;
b = (1.0/9.0) * (iRGBda[0] + iRGBda[1] - 2.0 * iRGBda[2]);
rS = sqrt(a * a + b * b); /* Normalised a, b */
/* Preliminary Saturation */
ttd = iRGBda[0] + iRGBda[1] + (21.0/20.0) * iRGBda[2];
/* Achromatic response */
/* Note that the minimum values of rgba[] for XYZ = 0 is 0.1, */
/* hence magic 0.305 below comes from the following weighting of rgba[], */
/* to base A at 0.0 */
A = (2.0 * iRGBda[0] + iRGBda[1] + (1.0/20.0) * iRGBda[2] - 0.305) * 1.0003;
REFTRACE((REFOUT, " a = %f, b = %f, ttd = %f, rS = %f, A = %f\n", a, b, ttd, rS, A))
/* Lightness */
J = pow(A/Aw, 0.69 * 1.9272); /* J/100 - keep Sign */
/* Hue angle */
h = (180.0/DBL_PI) * atan2(b, a);
h = (h < 0.0) ? h + 360.0 : h;
REFTRACE((REFOUT, " J = %f, h = %f\n", J, h))
/* Eccentricity factor */
e = 0.25 * (cos(h * DBL_PI/180.0 + 2.0) + 3.8);
ss = (50000.0/13.0 * 1.0 * 1.0003 * e * rS) / ttd;
/* Chroma */
C = pow(ss, 0.9) * sqrt(J) * 0.895217884; /* 0.895217884 = (1.64 - 0.29^0.2)^.73 */
M = C * 0.943874156; /* 0.943874156 = 0.7937^0.25 */
REFTRACE((REFOUT, " e = %f ss = %f C = %f M = %f\n", e, ss, C, M))
J *= 100.0; /* Scale J to 100 */
Md = (1.0/ 0.0228) * log(1.0 + 0.0228 * M);
REFTRACE((REFOUT, " J = %f Md = %f\n", J, Md))
/* Compute CIECAM02 UCS value */
Jd = (1.0 + 100.0 * 0.007) * J/(1.0 + 0.007 * J);
ad = Md * cos(h * DBL_PI/180.0);
bd = Md * sin(h * DBL_PI/180.0);
REFTRACE((REFOUT, " Jabd %f %f %f\n",Jd, ad, bd))
Jabd[0] = Jd;
Jabd[1] = ad;
Jabd[2] = bd;
}
/* IES TM-30-15 evaluation samples */
static xspect TM3015_ECS[IES_TM_30_15_ESAMPLES]; /* Forward declaration */
/* Comute IES TM-30-15 */
/* Return 1 on invalid, 2 on error */
/* Invalid is when sample is not white enough. */
int icx_IES_TM_30_15(
double *pRf, /* Return Rf */
double *pRg, /* Return Rg */
double *pcct, /* Return correlated color temperature */
double *pdc, /* Return signed dU'V' to locus */
double pbins[IES_TM_30_15_BINS][2][3], /* If not NULL, return ref & tsamp Jab */
xspect *tsamp /* Illuminant test sample to compute TLCI of */
) {
// Test source = input test sample
// Ref. source = reference Plankian/D type illuminant
// Use 380 - 780 nm, 1nm spectral calculation
// XYZ values are normalized to have Y == 1
// Normalize plankian and D type to have Y == 100 before blending
// and scale result so that Y == 100
// Compute 10 degree XYZ values for all CES for test & ref. illuminants,
// and normalize each to Y = 100.
// Convert to CIECAM02 Jab using the fom detailed in 3.7.1 thru 3.7.23
// Compute Rf according to 3.9.1 & 3.9.2
// Compute Rg according to 3.10.1
int i;
double cct; /* CCT of test sample */
xsp2cie *tocie2; /* spectral illuminant to XYZ conversion 2 degree */
xsp2cie *tocie10; /* spectral illuminant to XYZ conversion 10 degree */
xsp2cie *tocie10r, *tocie10s; /* spectral reflectance to XYZ conversion 10 degree */
xspect rspec; /* Reference white spectrum */
double tiXYZ[3]; /* Sample illuminant XYZ */
double riXYZ[3]; /* Reference illuminant XYZ */
double tUCS[3]; /* Sample CIE 1960 UCS */
double rUCS[3]; /* Reference CIE 1960 UCS */
double tYxy[3], rYxy[3];
double tsampnorm;
double dc; /* delta of test sample to reference white in 1960 UCS */
double rcat[3][3], tcat[3][3]; /* Ref White chromatic adapation matrix */
double rAw, tAw; /* acromatic response of white */
double mdE; /* Mean delta E */
double Rfd;
double esamps[IES_TM_30_15_ESAMPLES][2][3]; /* Evaluation sample Jab values */
int bcount[IES_TM_30_15_BINS];
double _bins[IES_TM_30_15_BINS][2][3];
double (*bins)[2][3];
double rArea, tArea;
double Rf = -1.0, Rg = -1.0;
int rv = 0;
DBGF((DBGA,"icx_IES_TM_30_15 called\n"))
bins = (pbins != NULL) ? pbins : _bins;
// Use CIE1931 2 deg for CCT, xy anxd u'v'
/* Create spectral to XYZ for CCT etc. */
if ((tocie2 = new_xsp2cie(icxIT_none, 0.0, NULL, icxOT_CIE_1931_2, NULL, icSigXYZData, 1)) == NULL) {
//DBGF((DBGA,"Ref new_xsp2cie 2 degreefailed\n"))
return 2;
}
#ifdef USE_5NM
# pragma message("###### tm3015.c set to 5nm !!! ######")
tocie2->set_int_steps(tocie2, 5.0, 380.0, 780.0);
#endif
/* Compute the 2 degree XYZ of the test sample */
tocie2->convert(tocie2, tiXYZ, tsamp);
/* Find the standard 2 degree observer CIE 15:2004 Plankian CCT (exp 1.4388e-2) */
if ((cct = icx_XYZ2ill_ct(NULL, icxIT_Ptemp, icxOT_CIE_1931_2, NULL, tiXYZ, NULL, 0)) < 0.0)
{
//DBGF((DBGA,"Ref icx_XYZ2ill_ct failed\n"))
return 2;
}
DBGF((DBGA,"CCT = %f\n", cct))
// For CCT <= 4500 generate plankian using 3.3.1
// For CCT >= 5500 generate Daylight according to 3.3.3
// For 4500 < CCT < 5500 then blend according to 3.3.9
/* Hmm. Note we're using Appendix C improved Daylight, not the IES TM-30-15 3.3.3 */
/* Create a reference white spectrum with the same CCT. */
if (cct <= 4500.0) {
if (standardIlluminant(&rspec, icxIT_Ptemp, cct)) {
//DBGF((DBGA,"planckian_il failed\n"))
return 2;
}
} else if (cct >= 5500.0) {
if (standardIlluminant(&rspec, icxIT_Dtemp, cct)) {
//DBGF((DBGA,"daylight_il failed\n"))
return 2;
}
/* It's a linear blend between plankian(4500) and daylight(5500) */
} else {
double dwt; /* Blend weight */
xspect dspec; /* Daylight spectrum */
double pXYZ[3], dXYZ[3]; /* Plankian and Dalight Y values */
if (standardIlluminant(&rspec, icxIT_Ptemp, 4500.0)) {
//DBGF((DBGA,"planckian_il failed\n"))
return 2;
}
tocie2->convert(tocie2, pXYZ, &rspec);
DBGF((DBGA," plank Y %f\n", pXYZ[1]))
if (standardIlluminant(&dspec, icxIT_Dtemp, 5500.0)) {
//DBGF((DBGA,"daylight_il failed\n"))
return 2;
}
tocie2->convert(tocie2, dXYZ, &dspec);
DBGF((DBGA," D Y %f\n", dXYZ[1]))
dwt = (cct - 4500)/(5500.0 - 4500.0);
DBGF((DBGA,"creating hybrid spectrum with %f Plankian & %f Daylight\n",(1.0 - dwt),dwt))
/* Blend Y normalized values */
for (i = 0; i < rspec.spec_n; i++) {
double wl = XSPECT_XWL(&rspec, i); /* Wavelength in meters */
rspec.spec[i] = dwt * 1.0/dXYZ[1] * value_xspect(&dspec, wl)
+ (1.0 - dwt) * 1.0/pXYZ[1] * rspec.spec[i];
}
}
/* Compute the 2 degree XYZ of the reference white */
tocie2->convert(tocie2, riXYZ, &rspec);
DBGF((DBGA,"ref. XYZ = %f %f %f\n",riXYZ[0],riXYZ[1],riXYZ[2]))
DBGF((DBGA,"test XYZ = %f %f %f\n",tiXYZ[0],tiXYZ[1],tiXYZ[2]))
/* Normalize the spectra so as to create a Y = 1.0 normalized white */
rspec.norm *= riXYZ[1];
tsampnorm = tsamp->norm; /* Save this so we can restore it before returning */
tsamp->norm *= tiXYZ[1];
tocie2->convert(tocie2, riXYZ, &rspec);
tocie2->convert(tocie2, tiXYZ, tsamp);
DBGF((DBGA,"norm XYZ ref. = %f %f %f\n",riXYZ[0],riXYZ[1],riXYZ[2]))
DBGF((DBGA,"norm XYZ test = %f %f %f\n",tiXYZ[0],tiXYZ[1],tiXYZ[2]))
/* Convert to perceptual CIE 1960 UCS */
icmXYZ21960UCS(rUCS, riXYZ); /* 1960 UCS Yuv reference white */
icmXYZ21960UCS(tUCS, tiXYZ); /* 1960 UCS Yuv test sample white */
DBGF((DBGA,"UCS ref. = %f %f %f\n",rUCS[0],rUCS[1],rUCS[2]))
DBGF((DBGA,"UCS test = %f %f %f\n",tUCS[0],tUCS[1],tUCS[2]))
/* Distance in UCS uv from test sample to reference illuminant */
dc = icmNorm22(&rUCS[1], &tUCS[1]);
DBGF((DBGA,"dc = %f (fraction of thresh. %f)\n",dc,dc/0.0054))
#ifdef DEBUG
if (dc > 0.0054)
DBGF((DBGA,"TM-30-15 is invalid\n"))
#endif
/* If dc > 0.0054 we should abort computing the CRI, */
/* but this means we fail on lots of real world lighting. */
if (dc > 0.0054)
rv = 1;
/* Comute dc sign */
icmXYZ2Yxy(rYxy, riXYZ);
icmXYZ2Yxy(tYxy, tiXYZ);
/* Dot product of vector from aprox. locus curve "center" */
/* xy 0.5, 0.25 with vector from */
if ((tYxy[1] - rYxy[1]) * (rYxy[1] - 0.5)
+ (tYxy[2] - rYxy[2]) * (rYxy[2] - 0.25) < 0.0)
dc = -dc;
// Use CIE1931 10 deg for comparison tristimulus values
if ((tocie10 = new_xsp2cie(icxIT_none, 0.0, &rspec, icxOT_CIE_1964_10, NULL, icSigXYZData, 0)) == NULL) {
//DBGF((DBGA,"Ref new_xsp2cie 10 degree failed\n"))
return 2;
}
/* Create spectral to XYZ with illuminants for delta E's */
if ((tocie10r = new_xsp2cie(icxIT_custom, 0.0, &rspec, icxOT_CIE_1964_10, NULL, icSigXYZData, 0)) == NULL) {
//DBGF((DBGA,"Ref new_xsp2cie 10 degree ref. failed\n"))
return 2;
}
if ((tocie10s = new_xsp2cie(icxIT_custom, 0.0, tsamp, icxOT_CIE_1964_10, NULL, icSigXYZData, 0)) == NULL) {
//DBGF((DBGA,"Ref new_xsp2cie 10 degree ref. failed\n"))
return 2;
}
#ifdef USE_5NM
# pragma message("###### tm3015.c set to 5nm !!! ######")
tocie10->set_int_steps(tocie10, 5.0, 380.0, 780.0);
tocie10r->set_int_steps(tocie10r, 5.0, 380.0, 780.0);
tocie10s->set_int_steps(tocie10s, 5.0, 380.0, 780.0);
#endif
/* Compute the 10 degree XYZ of the test sample and reference */
rspec.norm = 1.0;
tsamp->norm = 1.0;
tocie10->convert(tocie10, tiXYZ, tsamp);
tocie10->convert(tocie10, riXYZ, &rspec);
/* Normalize the spectra so as to create a Y = 1.0 normalized white */
rspec.norm *= riXYZ[1];
tsamp->norm *= tiXYZ[1];
tocie10->convert(tocie10, riXYZ, &rspec);
tocie10->convert(tocie10, tiXYZ, tsamp);
/* Compute CIECAM02 constants */
rAw = comp_rgbd_mtx(rcat, riXYZ);
tAw = comp_rgbd_mtx(tcat, tiXYZ);
DBGF((DBGA,"rAw %f tAw\n",rAw, tAw))
/* ------------------------------------------------------ */
/* Compute delta Jab for each evaluation sample from reference white */
mdE = 0.0;
for (i = 0; i < IES_TM_30_15_ESAMPLES; i++) {
double rXYZ[3];
double sXYZ[3];
double dE;
tocie10r->convert(tocie10r, rXYZ, &TM3015_ECS[i]);
#ifdef TRACE_CAT
apply_mtx_trace(esamps[i][0], rXYZ, riXYZ);
#endif /* TRACE_CAT */
ciecam02_ucs(esamps[i][0], rAw, rcat, rXYZ);
tocie10s->convert(tocie10s, sXYZ, &TM3015_ECS[i]);
#ifdef TRACE_CAT
apply_mtx_trace(esamps[i][1], sXYZ, tiXYZ);
#endif /* TRACE_CAT */
ciecam02_ucs(esamps[i][1], tAw, tcat, sXYZ);
dE = icmNorm33(esamps[i][0], esamps[i][1]);
DBGF((DBGA," Sample %d XYZ ref. %f %f %f test %f %f %f\n", i, rXYZ[0], rXYZ[1], rXYZ[2], sXYZ[0], sXYZ[1], sXYZ[2]))
DBGF((DBGA," Jab ref. %f %f %f test %f %f %f dE %f\n", esamps[i][0][0], esamps[i][0][1], esamps[i][0][2], esamps[i][1][0], esamps[i][1][1], esamps[i][1][2], dE))
mdE += dE;
}
/* Note that CIE244 uses a scaling factor of 6.73 rather than 7.54 */
mdE /= (double)i;
Rfd = 100.0 - 7.54 * mdE;
if (Rfd < 0.0)
Rfd = 0.0;
Rf = 10.0 * log(exp(Rfd/10.0) + 1.0);
/* ------------------------------------------------------ */
/* Average evaluation sample Jab values into the hue bins */
for (i = 0; i < IES_TM_30_15_BINS; i++) {
icmSet3(bins[i][0], 0.0);
icmSet3(bins[i][1], 0.0);
bcount[i] = 0;
}
for (i = 0; i < IES_TM_30_15_ESAMPLES; i++) {
double h;
int bix;
h = atan2(esamps[i][0][2], esamps[i][0][1]) / (2.0 * DBL_PI); /* Reference ab */
h = (h < 0.0) ? h + 1.0 : h;
bix = (int)floor(IES_TM_30_15_BINS * h);
if (bix > (IES_TM_30_15_BINS-1)) /* Just in case */
bix = 0;
DBGF((DBGA," esamp %d Jab ref. %f %f %f test %f %f %f Bin %d\n",i, esamps[i][0][0], esamps[i][0][1], esamps[i][0][2], esamps[i][1][0], esamps[i][1][1], esamps[i][1][2], bix))
icmAdd3(bins[bix][0], bins[bix][0], esamps[i][0]);
icmAdd3(bins[bix][1], bins[bix][1], esamps[i][1]);
bcount[bix]++;
//DBGF((DBGA," Bin %d: ab ref. %f %f test %f %f cnt %d\n", bix, bins[bix][0][1], bins[bix][0][2], bins[bix][1][1], bins[bix][1][2], bcount[bix]))
}
for (i = 0; i < IES_TM_30_15_BINS; i++) {
if (bcount[i] > 0) {
icmScale3(bins[i][0], bins[i][0], 1.0/bcount[i]);
icmScale3(bins[i][1], bins[i][1], 1.0/bcount[i]);
}
DBGF((DBGA," Bin %d: ab ref. %f %f test %f %f\n", i, bins[i][0][1], bins[i][0][2], bins[i][1][1], bins[i][1][2]))
}
/* Compute areas */
rArea = tArea = 0.0;
for (i = 0; i < IES_TM_30_15_BINS; i++) {
int j = i < (IES_TM_30_15_BINS-1) ? i + 1 : 0;
rArea += bins[i][0][1] * bins[j][0][2] - bins[j][0][1] * bins[i][0][2];
tArea += bins[i][1][1] * bins[j][1][2] - bins[j][1][1] * bins[i][1][2];
}
rArea *= 0.5;
tArea *= 0.5;
DBGF((DBGA," Area: ref. %f test %f\n", rArea, tArea))
Rg = 100.0 * tArea/rArea;
tsamp->norm = tsampnorm; /* Restore this */
tocie2->del(tocie2);
tocie2 = NULL;
tocie10->del(tocie10);
tocie10r->del(tocie10r);
tocie10s->del(tocie10s);
//DBGF((DBGA,"returning Rf %f Rg %f\n",Rf,Rg))
if (pRf != NULL)
*pRf = Rf;
if (pRg != NULL)
*pRg = Rg;
if (pcct != NULL)
*pcct = cct;
if (pdc != NULL)
*pdc = dc;
return rv;
}
#else /* STANDALONE_TEST */
static void tm3015_plot(double bins[IES_TM_30_15_BINS][2][3]);
int
main() {
int rv;
double Rf = -1.0, Rg = -1.0;
double CCT = -1.0, duv = -1.0;
double bins[IES_TM_30_15_BINS][2][3];
/* Spreadsheet example */
xspect f4 = { 81, 380.0, 780.0, 1.0, { 0.0188243065, 0.0231175694, 0.0287318362, 0.0323645971, 0.0663804491, 0.4540951123, 0.0643989432, 0.0525099075, 0.0581241744, 0.0637384412, 0.0693527081, 1, 0.2651915456, 0.0842140026, 0.0891677675, 0.0931307794, 0.0961030383, 0.0987450462, 0.1003963012, 0.1017173052, 0.1020475561, 0.1020475561, 0.1036988111, 0.1010568032, 0.0990752972, 0.0984147952, 0.0994055482, 0.1036988111, 0.1126155878, 0.1287978864, 0.1548877147, 0.1918758256, 0.2417437252, 0.7460369881, 0.499009247, 0.4583883752, 0.5392998679, 0.6169088507, 0.6816380449, 0.8018494055, 0.8672391017, 0.7688243065, 0.7575957728, 0.7311756935, 0.6905548217, 0.641677675, 0.5858652576, 0.5284015852, 0.4762219287, 0.4147952444, 0.3609643329, 0.3143989432, 0.2701453104, 0.2315059445, 0.1981505945, 0.1687582563, 0.143989432, 0.1218626156, 0.1033685601, 0.0871862616, 0.0739762219, 0.0630779392, 0.0561426684, 0.0459048877, 0.0389696169, 0.034015852, 0.0290620872, 0.0244385733, 0.0211360634, 0.0178335535, 0.0161822985, 0.0151915456, 0.0138705416, 0.0122192867, 0.0122192867, 0.0108982827, 0.0115587847, 0.0118890357, 0.0102377807, 0.0085865258, 0.0062747688 } };
xspect f5 = {
81, 380.0, 780.0, /* 109 bands from 300 to 830 nm in 5nm steps */
1.0, /* Arbitrary scale factor */
{
/* 380 */ 1.87, 2.35, 2.92, 3.45, 5.10, 18.91, 6.00, 6.11, 6.85, 7.58,
/* 430 */ 8.31, 40.76, 16.06, 10.32, 10.91, 11.40, 11.83, 12.17, 12.40, 12.54,
/* 480 */ 12.58, 12.52, 12.47, 12.20, 11.89, 11.61, 11.33, 11.10, 10.96, 10.97,
/* 530 */ 11.16, 11.54, 12.12, 27.78, 17.73, 14.47, 15.20, 15.77, 16.10, 18.54,
/* 580 */ 19.50, 15.39, 14.64, 13.72, 12.69, 11.57, 10.45, 9.35, 8.29, 7.32,
/* 630 */ 6.41, 5.63, 4.90, 4.26, 3.72, 3.25, 2.83, 2.49, 2.19, 1.93,
/* 680 */ 1.71, 1.52, 1.48, 1.26, 1.13, 1.05, 0.96, 0.85, 0.78, 0.72,
/* 730 */ 0.68, 0.67, 0.65, 0.61, 0.62, 0.59, 0.62, 0.64, 0.55, 0.47,
/* 780 */ 0.40,
}
};
/* CIE F8 */
/* Fluorescent, Wide band 5000K, CRI 95 */
xspect f8 = {
81, 380.0, 780.0, /* 109 bands from 300 to 830 nm in 5nm steps */
1.0, /* Arbitrary scale factor */
{
/* 380 */ 1.21, 1.5, 1.81, 2.13, 3.17, 13.08, 3.83, 3.45, 3.86, 4.42,
/* 430 */ 5.09, 34.10, 12.42, 7.68, 8.6, 9.46, 10.24, 10.84, 11.33, 11.71,
/* 480 */ 11.98, 12.17, 12.28, 12.32, 12.35, 12.44, 12.55, 12.68, 12.77, 12.72,
/* 530 */ 12.60, 12.43, 12.22, 28.96, 16.51, 11.79, 11.76, 11.77, 11.84, 14.61,
/* 580 */ 16.11, 12.34, 12.53, 12.72, 12.92, 13.12, 13.34, 13.61, 13.87, 14.07,
/* 630 */ 14.20, 14.16, 14.13, 14.34, 14.50, 14.46, 14.00, 12.58, 10.99, 9.98,
/* 680 */ 9.22, 8.62, 8.07, 7.39, 6.71, 6.16, 5.63, 5.03, 4.46, 4.02,
/* 730 */ 3.66, 3.36, 3.09, 2.85, 2.65, 2.51, 2.37, 2.15, 1.89, 1.61,
/* 780 */ 1.32,
}
};
printf("Checking IES TM-30-15 CRI:\n");
rv = icx_IES_TM_30_15(&Rf, &Rg, &CCT, &duv, bins, &f4);
printf(" f4 returned %d Rf %f Rg %f CCT %f duv %f\n",rv,Rf,Rg,CCT,duv);
printf(" expect Rf 51.5 Rg 83.5\n\n");
tm3015_plot(bins);
rv = icx_IES_TM_30_15(&Rf, &Rg, &CCT, &duv, bins, &f5);
printf(" f5 returned %d Rf %f Rg %f CCT %f duv %f\n",rv,Rf,Rg,CCT,duv);
printf(" expect Rf 75.2 Rg 87.4\n\n");
tm3015_plot(bins);
rv = icx_IES_TM_30_15(&Rf, &Rg, &CCT, &duv, bins, &f8);
printf(" f8 returned %d Rf %f Rg %f CCT %f duv %f\n",rv,Rf,Rg,CCT,duv);
printf(" expect Rf 95.9 Rg 101.0\n\n");
tm3015_plot(bins);
return 0;
}
#define SSAMP 4
// Note that bins is modified
static void tm3015_plot(double bins[IES_TM_30_15_BINS][2][3]) {
double rvecs[SSAMP * 16][2]; // DEBUG ref light circle vectors
double tvecs[SSAMP * 16][2]; // test light circle vectors
double shvec[2 * 16][2]; // Shift vectors
int i, j, k;
double maxr = 0.0;
plot_g gg = { 0 };
float lblack[3] = { 0.5, 0.5, 0.5 };
float lred[3] = { 1.0, 0.5, 0.5 };
float black[3] = { 0.0, 0.0, 0.0 };
float red[3] = { 1.0, 0.0, 0.0 };
float blue[3] = { 0.2, 0.2, 1.0 };
#ifdef NEVER
clear_g(&gg);
for (i = 0; i < 16; i++) {
int ip1 = i < 15 ? i+1 : 0;
add_vec_g(&gg, bins[i][0][1], bins[i][0][2], bins[ip1][0][1], bins[ip1][0][2], lblack);
add_vec_g(&gg, bins[i][1][1], bins[i][1][2], bins[ip1][1][1], bins[ip1][1][2], lred);
}
do_plot_g(&gg, 0.0, 0.0, 0.0, 0.0, 1.0, 0, 1);
#endif
clear_g(&gg);
/* Copy raw shift vectors */
for (i = 0; i < 16; i++) {
shvec[2 * i + 0][0] = bins[i][0][1];
shvec[2 * i + 0][1] = bins[i][0][2];
shvec[2 * i + 1][0] = bins[i][1][1];
shvec[2 * i + 1][1] = bins[i][1][2];
}
// Convert to angle & radius
for (i = 0; i < 16; i++) {
for (j = 0; j < 2; j++) {
double x = bins[i][j][1];
double y = bins[i][j][2];
// atan2 returns -pi < val <= +pi
bins[i][j][1] = atan2(y, x);
bins[i][j][2] = sqrt(x * x + y * y);
}
}
// Interpolate test points, and normalize them by interp. reference points */
for (i = 0; i < 16; i++) {
int ip1 = i < 15 ? i+1 : 0;
int k = i, kp1 = ip1;
for (j = 0; j < SSAMP; j++) { // 4 x interpolation
double ra, rr, ta, tr;
double ra0, ra1, ta0, ta1;
double bl = (double)j/SSAMP;
double nf = 1.0;
//printf("i %d j %d\n",i,j);
ra0 = bins[i][0][1];
ra1 = bins[ip1][0][1];
ta0 = bins[i][1][1];
ta1 = bins[ip1][1][1];
// Make sure pairs are adjacent
if ((ra1 - ra0) > (1.0 * DBL_PI))
ra0 += 2.0 * DBL_PI;
else if ((ra1 - ra0) < -(1.0 * DBL_PI))
ra0 -= 2.0 * DBL_PI;
if ((ta1 - ta0) > (1.0 * DBL_PI))
ta0 += 2.0 * DBL_PI;
else if ((ta1 - ta0) < -(1.0 * DBL_PI))
ta0 -= 2.0 * DBL_PI;
// Interpolated values
ra = (1.0 - bl) * ra0 + bl * ra1;
rr = (1.0 - bl) * bins[i][0][2] + bl * bins[ip1][0][2];
ta = (1.0 - bl) * ta0 + bl * ta1;
tr = (1.0 - bl) * bins[i][1][2] + bl * bins[ip1][1][2];
//printf(" bl %f ar %f rr %f tr %f rr %f\n",bl, ra, rr, tr, rr);
nf = rr; // Normalization factor
tr /= nf;
rr /= nf;
if (tr > maxr)
maxr = tr;
//printf(" norm ta %f tr %f\n",ta,tr);
rvecs[SSAMP * i + j][0] = ra;
rvecs[SSAMP * i + j][1] = rr;
tvecs[SSAMP * i + j][0] = ta;
tvecs[SSAMP * i + j][1] = tr;
// Set shift vectors
if (j == 0) {
shvec[2 * i + 0][0] = ra;
shvec[2 * i + 0][1] = rr;
shvec[2 * i + 1][0] = ta;
shvec[2 * i + 1][1] = tr;
//printf(" Shift ra %f rr %f ta %f tr %f\n",bins[i][0][1],1.0,tr,ta);
}
//printf("\n");
}
}
//printf("Done all, convert back\n");
// Convert back to cartesian
for (i = 0; i < (SSAMP * 16); i++) {
double a = tvecs[i][0];
double r = tvecs[i][1];
tvecs[i][0] = r * cos(a);
tvecs[i][1] = r * sin(a);
//printf(" tvecs[%d] a %f r %f x %f y %f\n",i,a,r,tvecs[i][0],tvecs[i][1]);
}
for (i = 0; i < (SSAMP * 16); i++) {
double a = rvecs[i][0];
double r = rvecs[i][1];
rvecs[i][0] = r * cos(a);
rvecs[i][1] = r * sin(a);
//printf(" rvecs[%d] a %f r %f x %f y %f\n",i,a,r,tvecs[i][0],tvecs[i][1]);
}
for (i = 0; i < (2 * 16); i++) {
double a = shvec[i][0];
double r = shvec[i][1];
shvec[i][0] = r * cos(a);
shvec[i][1] = r * sin(a);
//printf(" shvec[%d] a %f r %f x %f y %f\n",i,a,r,shvec[i][0],shvec[i][1]);
}
//printf("About to plot\n");
for (i = 0; i < (SSAMP * 16); i++) {
int ip1 = i < (SSAMP * 16 -1) ? i+1 : 0;
double x0, y0, x1, y1, r0, r1;
x0 = tvecs[i][0];
y0 = tvecs[i][1];
x1 = tvecs[ip1][0];
y1 = tvecs[ip1][1];
r0 = sqrt(x0 * x0 + y0 * y0);
r1 = sqrt(x1 * x1 + y1 * y1);
add_vec_g(&gg, x0/r0, y0/r0, x1/r1, y1/r1, black);
// add_vec_g(&gg, rvecs[i][0], rvecs[i][1], rvecs[ip1][0], rvecs[ip1][1], black);
add_vec_g(&gg, x0, y0, x1, y1, red);
}
for (i = 0; i < 16; i++) {
add_vec_g(&gg, shvec[2 * i + 0][0], shvec[2 * i + 0][1],
shvec[2 * i + 1][0], shvec[2 * i + 1][1], blue);
}
do_plot_g(&gg, 0.0, 0.0, 0.0, 0.0, 1.0, 0, 1);
}
#undef SSAMP
#endif /* STANDALONE_TEST */
/* ------------------------------------------------------ */
#ifndef STANDALONE_TEST
/* IES TM-30-15 evaluation samples */
/* 99 samples, 360 .. 830 at 5nm intervals */
static xspect TM3015_ECS[IES_TM_30_15_ESAMPLES] = {
{ 95, 360.0, 830.0, 1.0, { 0.61947, 0.61947, 0.61947, 0.61947, 0.61947, 0.62357, 0.62766, 0.63172, 0.63590, 0.64015, 0.64540, 0.64888, 0.65070, 0.65147, 0.65080, 0.64823, 0.64400, 0.63825, 0.63010, 0.61895, 0.60630, 0.59361, 0.58020, 0.56548, 0.55150, 0.54016, 0.53000, 0.51942, 0.50950, 0.50163, 0.49580, 0.49171, 0.48940, 0.48884, 0.48940, 0.49068, 0.49380, 0.50011, 0.51030, 0.52488, 0.54420, 0.56832, 0.59630, 0.62679, 0.65780, 0.68743, 0.71490, 0.73974, 0.76170, 0.78072, 0.79720, 0.81156, 0.82390, 0.83427, 0.84280, 0.84971, 0.85560, 0.86098, 0.86570, 0.86955, 0.87280, 0.87578, 0.87850, 0.88094, 0.88330, 0.88579, 0.88840, 0.89091, 0.89260, 0.89420, 0.89573, 0.89723, 0.89872, 0.90019, 0.90164, 0.90307, 0.90449, 0.90588, 0.90726, 0.90861, 0.90995, 0.91128, 0.91258, 0.91387, 0.91514, 0.91514, 0.91514, 0.91514, 0.91514, 0.91514, 0.91514, 0.91514, 0.91514, 0.91514, 0.91514 } },
{ 95, 360.0, 830.0, 1.0, { 0.25173, 0.25173, 0.25173, 0.25173, 0.25173, 0.25413, 0.25655, 0.25898, 0.26150, 0.26409, 0.26700, 0.26834, 0.26840, 0.26779, 0.26630, 0.26349, 0.25900, 0.25241, 0.24310, 0.23086, 0.21750, 0.20471, 0.19180, 0.17813, 0.16560, 0.15602, 0.14810, 0.14026, 0.13270, 0.12604, 0.12090, 0.11769, 0.11610, 0.11569, 0.11610, 0.11710, 0.11870, 0.12114, 0.12520, 0.13198, 0.14330, 0.16092, 0.18550, 0.21707, 0.25420, 0.29505, 0.33760, 0.37991, 0.42050, 0.45828, 0.49320, 0.52533, 0.55400, 0.57872, 0.60030, 0.61963, 0.63670, 0.65151, 0.66510, 0.67850, 0.69160, 0.70422, 0.71710, 0.73050, 0.74200, 0.74976, 0.75710, 0.76684, 0.77460, 0.78201, 0.78903, 0.79587, 0.80256, 0.80907, 0.81542, 0.82161, 0.82763, 0.83349, 0.83919, 0.84473, 0.85011, 0.85534, 0.86042, 0.86534, 0.87012, 0.87012, 0.87012, 0.87012, 0.87012, 0.87012, 0.87012, 0.87012, 0.87012, 0.87012, 0.87012 } },
{ 95, 360.0, 830.0, 1.0, { 0.00001, 0.00001, 0.00001, 0.00001, 0.00001, 0.00663, 0.01694, 0.01773, 0.01167, 0.00511, 0.00379, 0.00874, 0.01888, 0.02972, 0.04199, 0.04896, 0.05457, 0.05674, 0.05410, 0.05487, 0.05908, 0.06075, 0.06259, 0.06304, 0.06069, 0.05967, 0.05944, 0.05601, 0.05392, 0.05202, 0.04895, 0.04762, 0.04647, 0.04398, 0.04102, 0.04046, 0.04187, 0.04197, 0.04123, 0.04185, 0.04305, 0.04484, 0.04429, 0.04632, 0.04914, 0.05151, 0.05305, 0.05463, 0.05863, 0.06604, 0.07427, 0.08516, 0.09790, 0.10928, 0.12064, 0.12749, 0.13322, 0.14094, 0.15003, 0.15656, 0.16207, 0.17095, 0.18004, 0.18664, 0.18611, 0.18650, 0.19529, 0.20210, 0.20393, 0.21328, 0.21966, 0.22617, 0.23281, 0.23959, 0.24651, 0.25356, 0.26073, 0.26804, 0.27548, 0.28305, 0.29074, 0.29855, 0.30648, 0.31452, 0.32268, 0.32268, 0.32268, 0.32268, 0.32268, 0.32268, 0.32268, 0.32268, 0.32268, 0.32268, 0.32268 } },
{ 95, 360.0, 830.0, 1.0, { 0.47376, 0.47376, 0.47376, 0.47376, 0.47376, 0.47793, 0.46406, 0.44102, 0.42157, 0.40559, 0.38950, 0.37567, 0.36501, 0.35611, 0.34936, 0.34200, 0.33382, 0.32411, 0.31282, 0.29816, 0.27982, 0.26042, 0.24078, 0.22206, 0.20462, 0.18884, 0.17488, 0.16337, 0.15560, 0.15190, 0.15143, 0.15412, 0.16036, 0.17075, 0.18586, 0.20558, 0.22892, 0.25477, 0.28272, 0.31202, 0.34200, 0.37116, 0.39782, 0.42123, 0.44136, 0.45795, 0.47105, 0.48107, 0.48842, 0.49386, 0.49824, 0.50229, 0.50567, 0.50819, 0.51009, 0.51142, 0.51262, 0.51402, 0.51522, 0.51566, 0.51527, 0.51410, 0.51322, 0.51343, 0.51337, 0.51311, 0.51261, 0.51208, 0.51191, 0.51291, 0.51485, 0.51667, 0.51849, 0.52041, 0.52228, 0.52415, 0.52602, 0.52789, 0.52976, 0.53163, 0.53350, 0.53537, 0.53723, 0.53910, 0.54096, 0.54096, 0.54096, 0.54096, 0.54096, 0.54096, 0.54096, 0.54096, 0.54096, 0.54096, 0.54096 } },
{ 95, 360.0, 830.0, 1.0, { 0.13351, 0.13351, 0.13351, 0.13351, 0.13351, 0.13540, 0.13565, 0.13540, 0.13579, 0.13757, 0.14001, 0.14195, 0.14194, 0.13887, 0.13327, 0.12595, 0.11738, 0.10794, 0.09819, 0.08868, 0.07978, 0.07182, 0.06508, 0.05976, 0.05586, 0.05323, 0.05140, 0.04991, 0.04869, 0.04783, 0.04761, 0.04831, 0.05011, 0.05302, 0.05654, 0.06008, 0.06335, 0.06628, 0.06946, 0.07376, 0.08059, 0.09115, 0.10539, 0.12247, 0.13976, 0.15471, 0.16698, 0.17763, 0.19118, 0.21263, 0.24557, 0.29221, 0.35063, 0.41726, 0.48613, 0.55140, 0.61007, 0.66051, 0.70370, 0.74105, 0.77303, 0.79995, 0.82248, 0.84133, 0.85712, 0.87050, 0.88222, 0.89292, 0.90256, 0.91091, 0.91776, 0.92304, 0.92737, 0.93156, 0.93639, 0.93985, 0.94353, 0.94700, 0.95027, 0.95335, 0.95625, 0.95897, 0.96153, 0.96394, 0.96620, 0.96620, 0.96620, 0.96620, 0.96620, 0.96620, 0.96620, 0.96620, 0.96620, 0.96620, 0.96620 } },
{ 95, 360.0, 830.0, 1.0, { 0.04525, 0.04525, 0.04525, 0.04525, 0.04525, 0.05337, 0.06285, 0.07388, 0.08249, 0.10382, 0.11965, 0.13053, 0.13699, 0.13975, 0.14015, 0.13946, 0.13788, 0.13541, 0.13217, 0.12835, 0.12428, 0.12021, 0.11600, 0.11157, 0.10743, 0.10413, 0.10171, 0.09999, 0.09856, 0.09712, 0.09600, 0.09563, 0.09619, 0.09777, 0.10033, 0.10388, 0.10861, 0.11472, 0.12221, 0.13104, 0.14123, 0.15275, 0.16518, 0.17796, 0.19031, 0.20157, 0.21160, 0.22030, 0.22708, 0.23139, 0.23328, 0.23318, 0.23230, 0.23215, 0.23457, 0.24132, 0.25369, 0.27287, 0.30030, 0.33695, 0.38151, 0.43149, 0.48165, 0.52720, 0.56789, 0.60430, 0.63589, 0.66181, 0.68123, 0.70786, 0.73017, 0.75138, 0.77145, 0.79034, 0.80806, 0.82462, 0.84003, 0.85433, 0.86754, 0.87973, 0.89094, 0.90122, 0.91063, 0.91923, 0.92706, 0.92706, 0.92706, 0.92706, 0.92706, 0.92706, 0.92706, 0.92706, 0.92706, 0.92706, 0.92706 } },
{ 95, 360.0, 830.0, 1.0, { 0.06001, 0.06001, 0.06001, 0.06001, 0.06001, 0.05958, 0.05916, 0.05873, 0.05830, 0.05786, 0.05730, 0.05692, 0.05680, 0.05694, 0.05720, 0.05744, 0.05760, 0.05763, 0.05730, 0.05646, 0.05530, 0.05406, 0.05290, 0.05192, 0.05110, 0.05039, 0.04980, 0.04936, 0.04900, 0.04866, 0.04840, 0.04828, 0.04820, 0.04807, 0.04790, 0.04775, 0.04770, 0.04780, 0.04800, 0.04829, 0.04880, 0.04973, 0.05130, 0.05390, 0.05850, 0.06636, 0.07920, 0.09894, 0.12770, 0.16683, 0.21430, 0.26677, 0.31900, 0.36580, 0.40400, 0.43172, 0.45030, 0.46188, 0.46860, 0.47230, 0.47360, 0.47296, 0.47150, 0.47030, 0.46950, 0.46891, 0.46790, 0.46607, 0.46450, 0.46297, 0.46148, 0.45999, 0.45850, 0.45702, 0.45553, 0.45404, 0.45256, 0.45108, 0.44959, 0.44811, 0.44663, 0.44515, 0.44367, 0.44220, 0.44072, 0.44072, 0.44072, 0.44072, 0.44072, 0.44072, 0.44072, 0.44072, 0.44072, 0.44072, 0.44072 } },
{ 95, 360.0, 830.0, 1.0, { 0.05818, 0.05818, 0.05818, 0.05818, 0.05818, 0.05961, 0.05984, 0.05941, 0.05886, 0.05858, 0.05836, 0.05797, 0.05769, 0.05777, 0.05795, 0.05790, 0.05764, 0.05729, 0.05707, 0.05715, 0.05725, 0.05711, 0.05685, 0.05663, 0.05647, 0.05633, 0.05609, 0.05569, 0.05529, 0.05505, 0.05496, 0.05495, 0.05491, 0.05477, 0.05459, 0.05446, 0.05441, 0.05442, 0.05444, 0.05444, 0.05458, 0.05501, 0.05571, 0.05682, 0.05915, 0.06379, 0.07216, 0.08577, 0.10608, 0.13417, 0.16962, 0.21130, 0.25684, 0.30366, 0.34959, 0.39266, 0.43125, 0.46417, 0.49160, 0.51406, 0.53220, 0.54676, 0.55870, 0.56897, 0.57812, 0.58662, 0.59483, 0.60303, 0.61109, 0.61878, 0.62574, 0.63173, 0.63709, 0.64228, 0.64779, 0.65285, 0.65804, 0.66319, 0.66830, 0.67337, 0.67840, 0.68339, 0.68834, 0.69325, 0.69811, 0.69811, 0.69811, 0.69811, 0.69811, 0.69811, 0.69811, 0.69811, 0.69811, 0.69811, 0.69811 } },
{ 95, 360.0, 830.0, 1.0, { 0.04157, 0.04157, 0.04157, 0.04157, 0.04157, 0.04172, 0.04187, 0.04202, 0.04225, 0.04229, 0.04246, 0.04275, 0.04318, 0.04374, 0.04441, 0.04516, 0.04596, 0.04681, 0.04771, 0.04862, 0.04936, 0.04981, 0.05008, 0.05044, 0.05142, 0.05340, 0.05585, 0.05805, 0.05925, 0.05899, 0.05771, 0.05602, 0.05420, 0.05240, 0.05060, 0.04872, 0.04668, 0.04446, 0.04225, 0.04038, 0.03936, 0.03960, 0.04081, 0.04258, 0.04483, 0.04750, 0.05039, 0.05323, 0.05554, 0.05696, 0.05771, 0.05813, 0.05843, 0.05870, 0.05894, 0.05917, 0.05966, 0.06065, 0.06193, 0.06320, 0.06420, 0.06474, 0.06492, 0.06489, 0.06471, 0.06441, 0.06399, 0.06344, 0.06276, 0.06228, 0.06173, 0.06118, 0.06064, 0.06010, 0.05957, 0.05904, 0.05852, 0.05800, 0.05748, 0.05697, 0.05646, 0.05596, 0.05546, 0.05496, 0.05447, 0.05447, 0.05447, 0.05447, 0.05447, 0.05447, 0.05447, 0.05447, 0.05447, 0.05447, 0.05447 } },
{ 95, 360.0, 830.0, 1.0, { 0.17602, 0.17602, 0.17602, 0.17602, 0.17602, 0.18172, 0.18756, 0.19354, 0.19983, 0.20628, 0.21152, 0.20944, 0.20352, 0.19850, 0.19473, 0.19149, 0.18842, 0.18529, 0.18231, 0.17978, 0.17804, 0.17718, 0.17637, 0.17467, 0.17192, 0.16834, 0.16488, 0.16250, 0.16135, 0.16120, 0.16111, 0.16047, 0.16075, 0.16357, 0.16904, 0.17689, 0.18673, 0.19850, 0.21355, 0.23345, 0.25938, 0.29341, 0.34157, 0.40830, 0.48749, 0.57053, 0.64908, 0.71596, 0.76830, 0.80508, 0.82849, 0.84185, 0.84979, 0.85637, 0.86217, 0.86695, 0.87064, 0.87337, 0.87575, 0.87822, 0.88011, 0.88074, 0.88075, 0.88086, 0.88083, 0.88044, 0.88050, 0.88167, 0.88291, 0.88412, 0.88529, 0.88645, 0.88760, 0.88874, 0.88987, 0.89099, 0.89210, 0.89320, 0.89429, 0.89537, 0.89644, 0.89750, 0.89855, 0.89959, 0.90062, 0.90062, 0.90062, 0.90062, 0.90062, 0.90062, 0.90062, 0.90062, 0.90062, 0.90062, 0.90062 } },
{ 95, 360.0, 830.0, 1.0, { 0.03951, 0.03951, 0.03951, 0.03951, 0.03951, 0.04449, 0.05006, 0.05629, 0.06081, 0.07233, 0.08032, 0.08522, 0.08742, 0.08748, 0.08644, 0.08520, 0.08358, 0.08121, 0.07806, 0.07423, 0.06998, 0.06554, 0.06091, 0.05612, 0.05174, 0.04833, 0.04593, 0.04441, 0.04337, 0.04243, 0.04169, 0.04131, 0.04139, 0.04207, 0.04366, 0.04679, 0.05302, 0.06419, 0.08220, 0.10861, 0.14340, 0.18552, 0.23131, 0.27651, 0.31696, 0.34933, 0.37353, 0.39051, 0.40201, 0.40996, 0.41601, 0.42172, 0.42833, 0.43684, 0.44755, 0.46045, 0.47495, 0.49066, 0.50855, 0.52962, 0.55369, 0.57982, 0.60514, 0.62726, 0.64752, 0.66760, 0.68675, 0.70360, 0.71681, 0.73386, 0.74863, 0.76285, 0.77650, 0.78958, 0.80209, 0.81403, 0.82541, 0.83623, 0.84651, 0.85625, 0.86547, 0.87419, 0.88242, 0.89018, 0.89748, 0.89748, 0.89748, 0.89748, 0.89748, 0.89748, 0.89748, 0.89748, 0.89748, 0.89748, 0.89748 } },
{ 95, 360.0, 830.0, 1.0, { 0.24167, 0.24167, 0.24167, 0.24167, 0.24167, 0.21622, 0.18687, 0.16204, 0.14514, 0.12981, 0.11536, 0.10584, 0.10430, 0.09871, 0.09483, 0.09767, 0.09829, 0.09474, 0.09395, 0.09191, 0.08603, 0.08133, 0.07541, 0.06828, 0.06159, 0.05719, 0.05416, 0.05087, 0.04867, 0.04995, 0.05235, 0.05565, 0.05980, 0.06338, 0.07119, 0.08203, 0.09658, 0.11374, 0.13250, 0.15516, 0.18331, 0.21658, 0.25334, 0.29135, 0.33392, 0.37966, 0.42691, 0.47137, 0.51260, 0.54874, 0.57960, 0.60302, 0.62230, 0.63769, 0.64759, 0.65705, 0.66606, 0.67239, 0.67883, 0.67562, 0.67555, 0.67885, 0.67821, 0.67843, 0.68161, 0.68412, 0.68273, 0.68325, 0.68676, 0.68639, 0.68745, 0.68851, 0.68957, 0.69063, 0.69169, 0.69275, 0.69380, 0.69485, 0.69590, 0.69695, 0.69799, 0.69903, 0.70007, 0.70111, 0.70215, 0.70215, 0.70215, 0.70215, 0.70215, 0.70215, 0.70215, 0.70215, 0.70215, 0.70215, 0.70215 } },
{ 95, 360.0, 830.0, 1.0, { 0.04337, 0.04337, 0.04337, 0.04337, 0.04337, 0.04333, 0.04328, 0.04324, 0.04327, 0.04311, 0.04307, 0.04320, 0.04357, 0.04419, 0.04496, 0.04572, 0.04625, 0.04641, 0.04644, 0.04655, 0.04635, 0.04557, 0.04496, 0.04556, 0.04863, 0.05497, 0.06332, 0.07191, 0.07909, 0.08373, 0.08654, 0.08841, 0.08912, 0.08836, 0.08654, 0.08414, 0.08118, 0.07767, 0.07423, 0.07149, 0.06947, 0.06819, 0.06818, 0.07069, 0.07949, 0.09754, 0.12216, 0.14933, 0.17516, 0.19672, 0.21476, 0.23037, 0.24254, 0.25030, 0.25485, 0.25781, 0.26021, 0.26266, 0.26487, 0.26641, 0.26735, 0.26785, 0.26795, 0.26770, 0.26735, 0.26713, 0.26696, 0.26668, 0.26616, 0.26598, 0.26566, 0.26535, 0.26503, 0.26471, 0.26440, 0.26408, 0.26376, 0.26345, 0.26313, 0.26282, 0.26250, 0.26219, 0.26187, 0.26156, 0.26124, 0.26124, 0.26124, 0.26124, 0.26124, 0.26124, 0.26124, 0.26124, 0.26124, 0.26124, 0.26124 } },
{ 95, 360.0, 830.0, 1.0, { 0.33532, 0.33532, 0.33532, 0.33532, 0.33532, 0.33683, 0.33833, 0.33984, 0.34140, 0.34301, 0.34510, 0.34676, 0.34820, 0.34976, 0.35130, 0.35261, 0.35380, 0.35499, 0.35620, 0.35738, 0.35850, 0.35955, 0.36070, 0.36205, 0.36340, 0.36454, 0.36560, 0.36676, 0.36820, 0.37009, 0.37270, 0.37625, 0.38080, 0.38614, 0.39110, 0.39457, 0.39660, 0.39753, 0.39760, 0.39728, 0.39790, 0.40103, 0.40830, 0.42058, 0.43550, 0.45009, 0.46220, 0.47043, 0.47560, 0.47895, 0.48120, 0.48286, 0.48410, 0.48498, 0.48560, 0.48607, 0.48670, 0.48768, 0.48870, 0.48941, 0.48980, 0.48999, 0.49030, 0.49098, 0.49190, 0.49283, 0.49370, 0.49444, 0.49490, 0.49534, 0.49577, 0.49619, 0.49662, 0.49704, 0.49747, 0.49789, 0.49832, 0.49874, 0.49917, 0.49959, 0.50002, 0.50044, 0.50087, 0.50129, 0.50172, 0.50172, 0.50172, 0.50172, 0.50172, 0.50172, 0.50172, 0.50172, 0.50172, 0.50172, 0.50172 } },
{ 95, 360.0, 830.0, 1.0, { 0.16992, 0.16992, 0.16992, 0.16992, 0.16992, 0.17295, 0.17602, 0.17913, 0.18141, 0.18593, 0.18883, 0.19137, 0.19479, 0.20029, 0.20890, 0.22103, 0.23492, 0.24851, 0.26083, 0.27135, 0.28027, 0.28799, 0.29480, 0.30093, 0.30660, 0.31208, 0.31800, 0.32476, 0.33168, 0.33767, 0.34119, 0.34098, 0.33712, 0.33041, 0.32312, 0.31756, 0.31476, 0.31513, 0.31810, 0.32241, 0.32510, 0.32407, 0.32228, 0.32449, 0.33775, 0.36682, 0.40525, 0.44457, 0.47934, 0.50614, 0.52637, 0.54227, 0.55469, 0.56419, 0.57172, 0.57820, 0.58395, 0.58911, 0.59367, 0.59765, 0.60150, 0.60563, 0.60997, 0.61431, 0.61843, 0.62214, 0.62533, 0.62795, 0.62993, 0.63284, 0.63536, 0.63788, 0.64039, 0.64289, 0.64538, 0.64787, 0.65035, 0.65282, 0.65528, 0.65773, 0.66018, 0.66262, 0.66504, 0.66746, 0.66987, 0.66987, 0.66987, 0.66987, 0.66987, 0.66987, 0.66987, 0.66987, 0.66987, 0.66987, 0.66987 } },
{ 95, 360.0, 830.0, 1.0, { 0.03466, 0.03466, 0.03466, 0.03466, 0.03466, 0.03537, 0.03609, 0.03683, 0.03767, 0.03829, 0.03910, 0.04003, 0.04104, 0.04212, 0.04349, 0.04531, 0.04737, 0.04944, 0.05166, 0.05419, 0.05696, 0.05989, 0.06299, 0.06628, 0.06973, 0.07323, 0.07667, 0.07996, 0.08320, 0.08647, 0.08973, 0.09289, 0.09576, 0.09824, 0.10056, 0.10293, 0.10535, 0.10777, 0.11015, 0.11250, 0.11485, 0.11730, 0.12026, 0.12415, 0.12934, 0.13622, 0.14527, 0.15696, 0.17140, 0.18852, 0.20764, 0.22810, 0.24970, 0.27223, 0.29483, 0.31669, 0.33780, 0.35841, 0.37905, 0.40003, 0.42039, 0.43917, 0.45673, 0.47371, 0.49042, 0.50703, 0.52319, 0.53846, 0.55239, 0.56804, 0.58283, 0.59748, 0.61196, 0.62624, 0.64030, 0.65413, 0.66770, 0.68100, 0.69401, 0.70672, 0.71912, 0.73119, 0.74292, 0.75432, 0.76537, 0.76537, 0.76537, 0.76537, 0.76537, 0.76537, 0.76537, 0.76537, 0.76537, 0.76537, 0.76537 } },
{ 95, 360.0, 830.0, 1.0, { 0.03080, 0.03080, 0.03080, 0.03080, 0.03080, 0.03310, 0.03556, 0.03820, 0.04031, 0.04443, 0.04751, 0.04967, 0.05105, 0.05186, 0.05253, 0.05346, 0.05470, 0.05623, 0.05805, 0.06016, 0.06249, 0.06492, 0.06732, 0.06952, 0.07145, 0.07306, 0.07441, 0.07559, 0.07648, 0.07701, 0.07747, 0.07817, 0.07924, 0.08086, 0.08358, 0.08811, 0.09531, 0.10580, 0.11916, 0.13450, 0.15040, 0.16541, 0.17859, 0.18928, 0.19761, 0.20396, 0.20914, 0.21381, 0.21771, 0.22041, 0.22166, 0.22146, 0.22077, 0.22081, 0.22303, 0.22881, 0.23900, 0.25451, 0.27704, 0.30800, 0.34672, 0.39138, 0.43730, 0.48016, 0.51979, 0.55666, 0.58977, 0.61775, 0.63924, 0.66823, 0.69292, 0.71656, 0.73905, 0.76037, 0.78045, 0.79930, 0.81691, 0.83330, 0.84849, 0.86252, 0.87545, 0.88732, 0.89819, 0.90812, 0.91717, 0.91717, 0.91717, 0.91717, 0.91717, 0.91717, 0.91717, 0.91717, 0.91717, 0.91717, 0.91717 } },
{ 95, 360.0, 830.0, 1.0, { 0.06498, 0.06498, 0.06498, 0.06498, 0.06498, 0.06692, 0.06890, 0.07094, 0.07310, 0.07538, 0.07850, 0.08130, 0.08410, 0.08752, 0.09180, 0.09696, 0.10250, 0.10789, 0.11290, 0.11747, 0.12180, 0.12611, 0.13040, 0.13466, 0.13900, 0.14355, 0.14840, 0.15359, 0.15900, 0.16433, 0.16880, 0.17166, 0.17280, 0.17246, 0.17160, 0.17132, 0.17250, 0.17559, 0.17960, 0.18329, 0.18580, 0.18685, 0.18810, 0.19170, 0.19990, 0.21409, 0.23220, 0.25140, 0.26940, 0.28450, 0.29690, 0.30720, 0.31570, 0.32272, 0.32890, 0.33486, 0.34080, 0.34674, 0.35240, 0.35758, 0.36260, 0.36783, 0.37320, 0.37853, 0.38360, 0.38829, 0.39300, 0.39783, 0.40120, 0.40448, 0.40765, 0.41084, 0.41403, 0.41723, 0.42043, 0.42364, 0.42686, 0.43008, 0.43332, 0.43655, 0.43979, 0.44304, 0.44629, 0.44955, 0.45281, 0.45281, 0.45281, 0.45281, 0.45281, 0.45281, 0.45281, 0.45281, 0.45281, 0.45281, 0.45281 } },
{ 95, 360.0, 830.0, 1.0, { 0.10927, 0.10927, 0.10927, 0.10927, 0.10927, 0.11190, 0.11458, 0.11733, 0.12020, 0.12316, 0.12590, 0.12589, 0.12450, 0.12359, 0.12320, 0.12298, 0.12300, 0.12334, 0.12380, 0.12417, 0.12450, 0.12484, 0.12510, 0.12518, 0.12510, 0.12501, 0.12560, 0.12801, 0.13480, 0.14805, 0.16640, 0.18711, 0.20520, 0.21662, 0.22330, 0.22905, 0.23930, 0.25936, 0.29250, 0.33928, 0.39140, 0.43925, 0.47690, 0.50097, 0.51460, 0.52210, 0.52600, 0.52810, 0.52900, 0.52902, 0.52860, 0.52810, 0.52750, 0.52676, 0.52600, 0.52534, 0.52460, 0.52361, 0.52260, 0.52181, 0.52110, 0.52029, 0.51950, 0.51887, 0.51820, 0.51729, 0.51620, 0.51512, 0.51440, 0.51370, 0.51303, 0.51235, 0.51168, 0.51100, 0.51033, 0.50965, 0.50897, 0.50830, 0.50762, 0.50695, 0.50627, 0.50560, 0.50492, 0.50425, 0.50357, 0.50357, 0.50357, 0.50357, 0.50357, 0.50357, 0.50357, 0.50357, 0.50357, 0.50357, 0.50357 } },
{ 95, 360.0, 830.0, 1.0, { 0.02509, 0.02509, 0.02509, 0.02509, 0.02509, 0.02701, 0.02908, 0.03129, 0.03197, 0.03714, 0.03952, 0.03916, 0.03614, 0.03094, 0.02572, 0.02242, 0.02035, 0.01859, 0.01787, 0.01943, 0.02472, 0.03577, 0.05650, 0.08996, 0.13394, 0.18288, 0.22320, 0.24320, 0.24664, 0.24070, 0.23085, 0.22122, 0.21248, 0.20455, 0.19769, 0.19234, 0.18925, 0.18913, 0.19252, 0.19974, 0.21059, 0.22470, 0.24147, 0.26062, 0.28317, 0.31075, 0.34583, 0.39045, 0.44412, 0.50458, 0.56506, 0.61852, 0.66127, 0.69166, 0.71270, 0.72818, 0.74021, 0.75035, 0.75977, 0.76939, 0.77972, 0.79098, 0.80256, 0.81379, 0.82440, 0.83423, 0.84297, 0.85030, 0.85588, 0.86331, 0.86964, 0.87572, 0.88156, 0.88715, 0.89252, 0.89765, 0.90257, 0.90728, 0.91178, 0.91609, 0.92020, 0.92413, 0.92788, 0.93146, 0.93487, 0.93487, 0.93487, 0.93487, 0.93487, 0.93487, 0.93487, 0.93487, 0.93487, 0.93487, 0.93487 } },
{ 95, 360.0, 830.0, 1.0, { 0.12356, 0.12356, 0.12356, 0.12356, 0.12356, 0.13071, 0.13822, 0.14608, 0.14874, 0.16578, 0.17316, 0.17444, 0.17316, 0.17220, 0.17167, 0.17114, 0.17068, 0.17047, 0.17068, 0.17150, 0.17316, 0.17586, 0.17962, 0.18430, 0.18935, 0.19425, 0.19927, 0.20499, 0.21238, 0.22278, 0.23849, 0.26174, 0.29340, 0.33353, 0.38028, 0.43126, 0.48394, 0.53577, 0.58432, 0.62791, 0.66763, 0.70476, 0.73852, 0.76792, 0.79343, 0.81553, 0.83334, 0.84628, 0.85638, 0.86565, 0.87355, 0.87932, 0.88378, 0.88789, 0.89152, 0.89442, 0.89689, 0.89928, 0.90145, 0.90319, 0.90443, 0.90521, 0.90572, 0.90617, 0.90672, 0.90745, 0.90830, 0.90916, 0.90989, 0.91076, 0.91157, 0.91237, 0.91316, 0.91394, 0.91472, 0.91550, 0.91626, 0.91703, 0.91778, 0.91853, 0.91927, 0.92001, 0.92074, 0.92146, 0.92218, 0.92218, 0.92218, 0.92218, 0.92218, 0.92218, 0.92218, 0.92218, 0.92218, 0.92218, 0.92218 } },
{ 95, 360.0, 830.0, 1.0, { 0.00012, 0.00012, 0.00012, 0.00012, 0.00012, 0.01062, 0.02084, 0.03107, 0.04157, 0.05232, 0.06229, 0.07034, 0.07607, 0.07961, 0.08233, 0.08564, 0.08976, 0.09456, 0.09986, 0.10554, 0.11177, 0.11877, 0.12662, 0.13529, 0.14440, 0.15365, 0.16337, 0.17397, 0.18569, 0.19876, 0.21356, 0.23039, 0.24906, 0.26935, 0.29154, 0.31594, 0.34258, 0.37131, 0.40142, 0.43235, 0.46450, 0.49808, 0.53141, 0.56281, 0.59236, 0.62034, 0.64620, 0.66928, 0.68945, 0.70682, 0.72194, 0.73531, 0.74695, 0.75689, 0.76575, 0.77407, 0.78137, 0.78720, 0.79221, 0.79723, 0.80262, 0.80842, 0.81375, 0.81785, 0.82133, 0.82495, 0.82862, 0.83218, 0.83587, 0.83979, 0.84305, 0.84486, 0.84588, 0.84712, 0.84960, 0.85043, 0.85190, 0.85335, 0.85480, 0.85624, 0.85766, 0.85907, 0.86047, 0.86186, 0.86323, 0.86323, 0.86323, 0.86323, 0.86323, 0.86323, 0.86323, 0.86323, 0.86323, 0.86323, 0.86323 } },
{ 95, 360.0, 830.0, 1.0, { 0.37853, 0.37853, 0.37853, 0.37853, 0.37853, 0.40061, 0.41716, 0.43082, 0.44274, 0.45364, 0.46388, 0.47366, 0.48294, 0.49171, 0.50041, 0.50937, 0.51814, 0.52630, 0.53427, 0.54260, 0.55151, 0.56099, 0.57041, 0.57915, 0.58732, 0.59526, 0.60357, 0.61278, 0.62303, 0.63425, 0.64599, 0.65789, 0.67036, 0.68406, 0.69997, 0.71856, 0.73784, 0.75548, 0.77019, 0.78135, 0.78986, 0.79689, 0.80310, 0.80879, 0.81341, 0.81640, 0.81801, 0.81876, 0.81934, 0.82031, 0.82163, 0.82311, 0.82467, 0.82636, 0.82855, 0.83152, 0.83481, 0.83794, 0.84114, 0.84471, 0.84844, 0.85209, 0.85572, 0.85943, 0.86329, 0.86723, 0.87082, 0.87373, 0.87657, 0.87984, 0.88271, 0.88441, 0.88579, 0.88770, 0.88946, 0.89030, 0.89074, 0.89141, 0.89200, 0.89212, 0.89200, 0.89196, 0.89200, 0.89204, 0.89200, 0.89200, 0.89200, 0.89200, 0.89200, 0.89200, 0.89200, 0.89200, 0.89200, 0.89200, 0.89200 } },
{ 95, 360.0, 830.0, 1.0, { 0.20026, 0.20026, 0.20026, 0.20026, 0.20026, 0.21220, 0.22466, 0.23763, 0.25150, 0.26605, 0.28120, 0.28563, 0.28380, 0.28249, 0.28200, 0.28135, 0.28100, 0.28161, 0.28320, 0.28567, 0.28900, 0.29330, 0.29910, 0.30695, 0.31700, 0.32939, 0.34470, 0.36343, 0.38540, 0.41039, 0.43860, 0.47037, 0.50620, 0.54626, 0.58940, 0.63410, 0.67880, 0.72176, 0.76060, 0.79314, 0.81870, 0.83727, 0.85000, 0.85830, 0.86340, 0.86637, 0.86780, 0.86812, 0.86770, 0.86688, 0.86590, 0.86494, 0.86390, 0.86263, 0.86100, 0.85898, 0.85700, 0.85543, 0.85410, 0.85264, 0.85040, 0.84708, 0.84390, 0.84212, 0.84150, 0.84134, 0.84070, 0.83899, 0.83740, 0.83582, 0.83428, 0.83273, 0.83116, 0.82958, 0.82800, 0.82640, 0.82478, 0.82316, 0.82152, 0.81988, 0.81822, 0.81655, 0.81486, 0.81317, 0.81146, 0.81146, 0.81146, 0.81146, 0.81146, 0.81146, 0.81146, 0.81146, 0.81146, 0.81146, 0.81146 } },
{ 95, 360.0, 830.0, 1.0, { 0.10281, 0.10281, 0.10281, 0.10281, 0.10281, 0.09292, 0.08404, 0.07621, 0.06814, 0.06240, 0.06158, 0.05854, 0.05464, 0.05502, 0.05832, 0.05840, 0.05462, 0.05290, 0.05304, 0.05210, 0.05075, 0.05128, 0.05300, 0.05316, 0.05188, 0.05240, 0.05510, 0.05851, 0.06343, 0.07062, 0.08218, 0.10589, 0.14388, 0.19506, 0.25332, 0.30750, 0.35271, 0.38845, 0.41659, 0.43753, 0.45206, 0.46315, 0.47193, 0.47900, 0.48644, 0.49282, 0.49629, 0.50020, 0.50456, 0.50626, 0.50779, 0.51042, 0.51055, 0.50984, 0.50953, 0.50935, 0.51270, 0.51496, 0.51194, 0.51094, 0.51107, 0.50985, 0.50758, 0.50201, 0.49937, 0.50130, 0.50444, 0.51390, 0.51821, 0.52735, 0.53455, 0.54175, 0.54893, 0.55608, 0.56322, 0.57032, 0.57740, 0.58445, 0.59146, 0.59844, 0.60537, 0.61227, 0.61911, 0.62592, 0.63267, 0.63267, 0.63267, 0.63267, 0.63267, 0.63267, 0.63267, 0.63267, 0.63267, 0.63267, 0.63267 } },
{ 95, 360.0, 830.0, 1.0, { 0.18151, 0.18151, 0.18151, 0.18151, 0.18151, 0.17829, 0.17511, 0.17198, 0.16880, 0.16558, 0.16160, 0.15900, 0.15810, 0.15881, 0.16130, 0.16571, 0.17170, 0.17895, 0.18760, 0.19777, 0.20900, 0.22112, 0.23560, 0.25362, 0.27340, 0.29329, 0.31500, 0.34048, 0.36920, 0.40017, 0.43290, 0.46717, 0.50320, 0.54088, 0.57840, 0.61400, 0.64770, 0.67979, 0.70970, 0.73677, 0.76070, 0.78141, 0.79940, 0.81523, 0.82920, 0.84155, 0.85240, 0.86185, 0.86990, 0.87659, 0.88230, 0.88735, 0.89160, 0.89487, 0.89740, 0.89946, 0.90110, 0.90232, 0.90330, 0.90419, 0.90500, 0.90570, 0.90630, 0.90680, 0.90720, 0.90752, 0.90790, 0.90840, 0.90880, 0.90918, 0.90956, 0.90993, 0.91030, 0.91066, 0.91103, 0.91140, 0.91176, 0.91212, 0.91249, 0.91285, 0.91320, 0.91356, 0.91392, 0.91427, 0.91463, 0.91463, 0.91463, 0.91463, 0.91463, 0.91463, 0.91463, 0.91463, 0.91463, 0.91463, 0.91463 } },
{ 95, 360.0, 830.0, 1.0, { 0.06462, 0.06462, 0.06462, 0.06462, 0.06462, 0.06500, 0.06620, 0.06758, 0.06839, 0.07185, 0.08117, 0.09389, 0.11434, 0.14548, 0.17980, 0.20758, 0.22587, 0.24072, 0.25486, 0.26272, 0.26805, 0.27812, 0.28681, 0.29048, 0.29200, 0.29516, 0.30288, 0.31468, 0.32907, 0.34463, 0.35691, 0.36974, 0.38422, 0.39686, 0.40592, 0.41045, 0.41237, 0.41646, 0.42207, 0.42657, 0.42941, 0.43090, 0.43186, 0.43417, 0.43799, 0.44134, 0.44276, 0.44410, 0.44574, 0.44656, 0.44617, 0.44794, 0.44909, 0.44919, 0.45155, 0.45456, 0.45681, 0.45528, 0.45003, 0.44666, 0.44579, 0.44445, 0.44430, 0.44272, 0.44242, 0.44704, 0.45358, 0.46121, 0.46357, 0.47205, 0.47816, 0.48429, 0.49042, 0.49655, 0.50268, 0.50881, 0.51494, 0.52106, 0.52718, 0.53329, 0.53939, 0.54548, 0.55155, 0.55761, 0.56365, 0.56365, 0.56365, 0.56365, 0.56365, 0.56365, 0.56365, 0.56365, 0.56365, 0.56365, 0.56365 } },
{ 95, 360.0, 830.0, 1.0, { 0.04580, 0.04580, 0.04580, 0.04580, 0.04580, 0.04489, 0.04394, 0.04317, 0.04467, 0.04650, 0.04793, 0.04699, 0.04621, 0.04400, 0.04456, 0.04653, 0.04711, 0.04794, 0.04801, 0.04537, 0.04556, 0.04574, 0.04704, 0.04889, 0.04999, 0.05113, 0.05184, 0.05266, 0.05780, 0.06583, 0.07923, 0.09316, 0.10443, 0.11237, 0.11717, 0.11799, 0.11843, 0.11869, 0.11877, 0.11740, 0.11503, 0.12031, 0.12027, 0.12087, 0.12009, 0.12214, 0.12237, 0.12116, 0.11951, 0.11896, 0.11864, 0.11826, 0.11813, 0.11937, 0.11881, 0.11634, 0.11621, 0.11637, 0.11656, 0.11571, 0.11537, 0.11267, 0.11420, 0.11624, 0.11636, 0.11320, 0.11456, 0.11781, 0.11627, 0.11443, 0.11559, 0.11697, 0.11711, 0.11871, 0.11979, 0.11884, 0.11780, 0.11833, 0.11880, 0.11906, 0.12030, 0.12106, 0.12099, 0.12120, 0.12123, 0.12123, 0.12123, 0.12123, 0.12123, 0.12123, 0.12123, 0.12123, 0.12123, 0.12123, 0.12123 } },
{ 95, 360.0, 830.0, 1.0, { 0.03981, 0.03981, 0.03981, 0.03981, 0.03981, 0.04155, 0.04336, 0.04525, 0.04798, 0.04887, 0.05115, 0.05478, 0.05972, 0.06611, 0.07483, 0.08683, 0.10270, 0.12281, 0.14711, 0.17523, 0.20611, 0.23842, 0.27043, 0.30066, 0.32892, 0.35533, 0.37997, 0.40328, 0.42723, 0.45369, 0.48277, 0.51378, 0.54473, 0.57367, 0.60006, 0.62365, 0.64365, 0.65956, 0.67224, 0.68280, 0.69184, 0.69975, 0.70674, 0.71305, 0.71910, 0.72521, 0.73114, 0.73663, 0.74196, 0.74751, 0.75350, 0.75999, 0.76667, 0.77308, 0.77882, 0.78351, 0.78709, 0.78962, 0.79148, 0.79321, 0.79597, 0.80060, 0.80638, 0.81236, 0.81832, 0.82419, 0.82976, 0.83482, 0.83915, 0.84423, 0.84885, 0.85335, 0.85775, 0.86203, 0.86621, 0.87028, 0.87424, 0.87810, 0.88185, 0.88551, 0.88906, 0.89252, 0.89589, 0.89916, 0.90233, 0.90233, 0.90233, 0.90233, 0.90233, 0.90233, 0.90233, 0.90233, 0.90233, 0.90233, 0.90233 } },
{ 95, 360.0, 830.0, 1.0, { 0.03043, 0.03043, 0.03043, 0.03043, 0.03043, 0.03198, 0.03135, 0.02956, 0.02799, 0.02943, 0.03159, 0.03054, 0.03068, 0.03510, 0.04618, 0.05858, 0.07378, 0.09711, 0.12843, 0.16071, 0.18945, 0.21301, 0.23025, 0.23860, 0.24313, 0.24970, 0.25715, 0.26432, 0.27011, 0.27155, 0.27200, 0.27353, 0.27630, 0.27819, 0.27862, 0.27889, 0.27955, 0.28173, 0.28524, 0.28833, 0.29177, 0.29664, 0.30154, 0.30507, 0.30871, 0.31340, 0.31903, 0.32509, 0.32974, 0.33388, 0.33894, 0.34220, 0.34451, 0.34661, 0.34779, 0.35040, 0.35438, 0.35485, 0.35338, 0.35403, 0.35561, 0.35852, 0.35971, 0.35739, 0.35449, 0.35373, 0.35540, 0.36075, 0.36514, 0.36959, 0.37419, 0.37882, 0.38348, 0.38815, 0.39284, 0.39756, 0.40229, 0.40704, 0.41181, 0.41660, 0.42140, 0.42622, 0.43105, 0.43589, 0.44074, 0.44074, 0.44074, 0.44074, 0.44074, 0.44074, 0.44074, 0.44074, 0.44074, 0.44074, 0.44074 } },
{ 95, 360.0, 830.0, 1.0, { 0.04401, 0.04401, 0.04401, 0.04401, 0.04401, 0.04373, 0.04499, 0.04761, 0.05142, 0.05624, 0.06182, 0.06809, 0.07569, 0.08532, 0.09712, 0.11108, 0.12710, 0.14513, 0.16551, 0.18850, 0.21364, 0.24081, 0.27189, 0.30813, 0.34621, 0.38299, 0.42055, 0.46097, 0.50101, 0.53702, 0.56908, 0.59786, 0.62260, 0.64264, 0.65921, 0.67373, 0.68657, 0.69790, 0.70804, 0.71734, 0.72615, 0.73467, 0.74241, 0.74895, 0.75484, 0.76070, 0.76648, 0.77190, 0.77655, 0.78017, 0.78326, 0.78641, 0.78978, 0.79338, 0.79694, 0.80012, 0.80264, 0.80445, 0.80640, 0.80916, 0.81170, 0.81302, 0.81388, 0.81524, 0.81722, 0.81966, 0.82215, 0.82429, 0.82611, 0.82769, 0.82899, 0.82993, 0.83048, 0.83060, 0.83026, 0.83060, 0.83067, 0.83074, 0.83081, 0.83088, 0.83095, 0.83102, 0.83109, 0.83116, 0.83123, 0.83123, 0.83123, 0.83123, 0.83123, 0.83123, 0.83123, 0.83123, 0.83123, 0.83123, 0.83123 } },
{ 95, 360.0, 830.0, 1.0, { 0.04628, 0.04628, 0.04628, 0.04628, 0.04628, 0.04542, 0.04457, 0.04374, 0.04290, 0.04206, 0.04110, 0.04069, 0.04100, 0.04209, 0.04400, 0.04679, 0.05050, 0.05522, 0.06130, 0.06913, 0.07890, 0.09077, 0.10500, 0.12180, 0.14120, 0.16307, 0.18690, 0.21218, 0.23870, 0.26636, 0.29520, 0.32517, 0.35580, 0.38644, 0.41620, 0.44402, 0.46830, 0.48756, 0.50130, 0.50941, 0.51240, 0.51113, 0.50720, 0.50235, 0.49800, 0.49512, 0.49310, 0.49093, 0.48760, 0.48248, 0.47630, 0.47030, 0.46630, 0.46623, 0.47200, 0.48518, 0.50610, 0.53447, 0.56880, 0.60699, 0.64570, 0.68173, 0.71380, 0.74151, 0.76620, 0.78956, 0.81310, 0.83652, 0.85260, 0.86699, 0.87979, 0.89151, 0.90221, 0.91196, 0.92083, 0.92887, 0.93615, 0.94273, 0.94867, 0.95403, 0.95885, 0.96318, 0.96707, 0.97057, 0.97370, 0.97370, 0.97370, 0.97370, 0.97370, 0.97370, 0.97370, 0.97370, 0.97370, 0.97370, 0.97370 } },
{ 95, 360.0, 830.0, 1.0, { 0.17315, 0.17315, 0.17315, 0.17315, 0.17315, 0.17955, 0.18551, 0.19147, 0.19787, 0.20470, 0.21023, 0.21321, 0.21595, 0.22112, 0.22921, 0.24063, 0.25764, 0.28283, 0.31841, 0.36487, 0.41631, 0.46632, 0.51290, 0.55466, 0.58809, 0.61048, 0.62424, 0.63310, 0.64079, 0.65018, 0.66068, 0.67101, 0.68048, 0.68881, 0.69672, 0.70489, 0.71287, 0.72001, 0.72588, 0.73048, 0.73522, 0.74123, 0.74699, 0.75091, 0.75383, 0.75692, 0.76021, 0.76361, 0.76763, 0.77265, 0.77797, 0.78271, 0.78627, 0.78844, 0.79028, 0.79278, 0.79528, 0.79706, 0.79877, 0.80118, 0.80412, 0.80718, 0.80995, 0.81215, 0.81403, 0.81593, 0.81807, 0.82055, 0.82326, 0.82593, 0.82804, 0.82924, 0.83027, 0.83213, 0.83581, 0.83693, 0.83904, 0.84114, 0.84321, 0.84525, 0.84728, 0.84929, 0.85127, 0.85323, 0.85517, 0.85517, 0.85517, 0.85517, 0.85517, 0.85517, 0.85517, 0.85517, 0.85517, 0.85517, 0.85517 } },
{ 95, 360.0, 830.0, 1.0, { 0.04354, 0.04354, 0.04354, 0.04354, 0.04354, 0.04363, 0.04371, 0.04380, 0.04389, 0.04397, 0.04404, 0.04401, 0.04400, 0.04411, 0.04433, 0.04464, 0.04511, 0.04589, 0.04721, 0.04923, 0.05164, 0.05427, 0.05796, 0.06361, 0.07121, 0.08063, 0.09207, 0.10573, 0.12138, 0.13906, 0.16048, 0.18727, 0.21932, 0.25474, 0.28642, 0.30780, 0.31975, 0.32497, 0.32621, 0.32579, 0.32446, 0.32253, 0.32020, 0.31762, 0.31486, 0.31189, 0.30849, 0.30443, 0.29971, 0.29443, 0.28917, 0.28446, 0.28043, 0.27707, 0.27414, 0.27141, 0.26885, 0.26649, 0.26449, 0.26303, 0.26213, 0.26186, 0.26248, 0.26410, 0.26609, 0.26786, 0.26981, 0.27228, 0.27417, 0.27602, 0.27782, 0.27963, 0.28144, 0.28326, 0.28509, 0.28692, 0.28876, 0.29061, 0.29247, 0.29433, 0.29620, 0.29808, 0.29996, 0.30185, 0.30375, 0.30375, 0.30375, 0.30375, 0.30375, 0.30375, 0.30375, 0.30375, 0.30375, 0.30375, 0.30375 } },
{ 95, 360.0, 830.0, 1.0, { 0.05265, 0.05265, 0.05265, 0.05265, 0.05265, 0.05260, 0.05255, 0.05250, 0.05245, 0.05239, 0.05217, 0.05170, 0.05108, 0.05042, 0.04980, 0.04932, 0.04899, 0.04883, 0.04885, 0.04903, 0.04929, 0.04960, 0.05029, 0.05178, 0.05440, 0.05841, 0.06371, 0.06999, 0.07648, 0.08244, 0.08763, 0.09226, 0.09785, 0.10570, 0.11485, 0.12372, 0.13045, 0.13368, 0.13428, 0.13355, 0.13216, 0.13054, 0.12886, 0.12720, 0.12554, 0.12381, 0.12196, 0.11992, 0.11767, 0.11522, 0.11283, 0.11074, 0.10894, 0.10738, 0.10598, 0.10468, 0.10349, 0.10242, 0.10154, 0.10088, 0.10041, 0.10012, 0.10019, 0.10071, 0.10131, 0.10168, 0.10213, 0.10293, 0.10364, 0.10434, 0.10502, 0.10571, 0.10640, 0.10709, 0.10779, 0.10850, 0.10920, 0.10991, 0.11063, 0.11135, 0.11207, 0.11279, 0.11353, 0.11426, 0.11500, 0.11500, 0.11500, 0.11500, 0.11500, 0.11500, 0.11500, 0.11500, 0.11500, 0.11500, 0.11500 } },
{ 95, 360.0, 830.0, 1.0, { 0.03431, 0.03431, 0.03431, 0.03431, 0.03431, 0.03708, 0.04283, 0.05358, 0.07506, 0.09776, 0.12729, 0.16371, 0.20727, 0.25618, 0.30712, 0.35739, 0.40413, 0.44397, 0.47549, 0.49917, 0.51519, 0.52400, 0.52781, 0.52870, 0.52832, 0.52853, 0.52959, 0.53055, 0.53092, 0.53193, 0.53347, 0.53402, 0.53283, 0.53039, 0.52860, 0.52848, 0.52890, 0.52837, 0.52700, 0.52649, 0.52843, 0.53210, 0.53516, 0.53670, 0.53798, 0.54007, 0.54310, 0.54624, 0.54817, 0.54899, 0.55035, 0.55266, 0.55518, 0.55746, 0.55801, 0.55702, 0.55717, 0.55869, 0.55967, 0.55989, 0.56082, 0.56192, 0.56165, 0.56041, 0.55912, 0.55486, 0.54941, 0.54330, 0.53563, 0.52630, 0.51786, 0.51116, 0.50353, 0.49575, 0.48819, 0.48065, 0.47311, 0.46558, 0.45806, 0.45057, 0.44310, 0.43562, 0.42817, 0.42076, 0.41339, 0.41339, 0.41339, 0.41339, 0.41339, 0.41339, 0.41339, 0.41339, 0.41339, 0.41339, 0.41339 } },
{ 95, 360.0, 830.0, 1.0, { 0.05028, 0.05028, 0.05028, 0.05028, 0.05028, 0.05023, 0.05019, 0.05014, 0.05000, 0.05009, 0.05000, 0.04991, 0.05000, 0.05039, 0.05100, 0.05177, 0.05300, 0.05490, 0.05700, 0.05875, 0.06000, 0.06073, 0.06100, 0.06109, 0.06200, 0.06454, 0.06800, 0.07115, 0.07200, 0.07038, 0.07400, 0.08994, 0.11500, 0.14309, 0.16700, 0.18168, 0.19200, 0.20293, 0.21000, 0.20811, 0.19900, 0.18615, 0.17300, 0.16242, 0.15500, 0.15106, 0.15200, 0.15771, 0.16100, 0.15559, 0.14600, 0.13792, 0.13100, 0.12386, 0.11700, 0.11101, 0.10500, 0.09848, 0.09400, 0.09471, 0.10310, 0.12080, 0.14660, 0.17877, 0.21630, 0.25833, 0.30380, 0.35162, 0.40070, 0.45484, 0.50886, 0.56267, 0.61505, 0.66489, 0.71130, 0.75367, 0.79164, 0.82512, 0.85421, 0.87917, 0.90035, 0.91817, 0.93303, 0.94536, 0.95553, 0.95553, 0.95553, 0.95553, 0.95553, 0.95553, 0.95553, 0.95553, 0.95553, 0.95553, 0.95553 } },
{ 95, 360.0, 830.0, 1.0, { 0.11323, 0.11323, 0.11323, 0.11323, 0.11323, 0.11525, 0.10979, 0.09541, 0.08689, 0.08224, 0.08142, 0.08681, 0.10151, 0.12741, 0.16431, 0.21014, 0.26265, 0.31889, 0.37622, 0.43060, 0.47844, 0.51829, 0.55029, 0.57599, 0.59562, 0.61049, 0.62077, 0.62698, 0.63270, 0.64011, 0.64719, 0.65171, 0.65373, 0.65447, 0.65538, 0.65739, 0.65954, 0.66027, 0.65923, 0.65779, 0.65799, 0.65940, 0.66049, 0.66094, 0.66122, 0.66190, 0.66315, 0.66458, 0.66544, 0.66585, 0.66684, 0.66881, 0.67060, 0.67138, 0.67119, 0.67049, 0.67041, 0.67108, 0.67106, 0.67024, 0.66944, 0.66846, 0.66851, 0.67028, 0.67149, 0.67258, 0.67428, 0.67638, 0.67857, 0.68190, 0.68592, 0.68952, 0.69328, 0.69711, 0.70083, 0.70452, 0.70819, 0.71183, 0.71544, 0.71903, 0.72258, 0.72615, 0.72967, 0.73316, 0.73661, 0.73661, 0.73661, 0.73661, 0.73661, 0.73661, 0.73661, 0.73661, 0.73661, 0.73661, 0.73661 } },
{ 95, 360.0, 830.0, 1.0, { 0.04566, 0.04566, 0.04566, 0.04566, 0.04566, 0.04573, 0.04580, 0.04588, 0.04606, 0.04597, 0.04606, 0.04634, 0.04678, 0.04741, 0.04823, 0.04925, 0.05039, 0.05160, 0.05297, 0.05453, 0.05595, 0.05698, 0.05791, 0.05932, 0.06224, 0.06742, 0.07389, 0.08031, 0.08563, 0.08916, 0.09130, 0.09256, 0.09254, 0.09086, 0.08800, 0.08461, 0.08110, 0.07777, 0.07461, 0.07165, 0.06935, 0.06811, 0.06770, 0.06784, 0.06863, 0.07018, 0.07224, 0.07444, 0.07646, 0.07805, 0.07924, 0.08017, 0.08089, 0.08147, 0.08192, 0.08233, 0.08295, 0.08401, 0.08532, 0.08661, 0.08759, 0.08807, 0.08821, 0.08823, 0.08821, 0.08818, 0.08811, 0.08796, 0.08769, 0.08760, 0.08743, 0.08727, 0.08711, 0.08694, 0.08678, 0.08662, 0.08645, 0.08629, 0.08613, 0.08597, 0.08581, 0.08565, 0.08549, 0.08533, 0.08517, 0.08517, 0.08517, 0.08517, 0.08517, 0.08517, 0.08517, 0.08517, 0.08517, 0.08517, 0.08517 } },
{ 95, 360.0, 830.0, 1.0, { 0.07500, 0.07500, 0.07500, 0.07500, 0.07500, 0.07502, 0.07503, 0.07504, 0.07522, 0.07498, 0.07502, 0.07534, 0.07595, 0.07683, 0.07801, 0.07950, 0.08130, 0.08347, 0.08625, 0.08964, 0.09243, 0.09371, 0.09480, 0.09794, 0.10655, 0.12302, 0.14427, 0.16617, 0.18600, 0.20198, 0.21465, 0.22435, 0.22825, 0.22393, 0.21393, 0.20158, 0.18858, 0.17596, 0.16384, 0.15244, 0.14313, 0.13716, 0.13396, 0.13286, 0.13458, 0.13978, 0.14736, 0.15579, 0.16364, 0.16980, 0.17456, 0.17846, 0.18157, 0.18391, 0.18569, 0.18725, 0.18930, 0.19238, 0.19610, 0.19976, 0.20259, 0.20400, 0.20434, 0.20413, 0.20352, 0.20254, 0.20115, 0.19927, 0.19682, 0.19524, 0.19333, 0.19144, 0.18956, 0.18769, 0.18584, 0.18400, 0.18218, 0.18037, 0.17857, 0.17679, 0.17502, 0.17327, 0.17153, 0.16981, 0.16809, 0.16809, 0.16809, 0.16809, 0.16809, 0.16809, 0.16809, 0.16809, 0.16809, 0.16809, 0.16809 } },
{ 95, 360.0, 830.0, 1.0, { 0.37973, 0.37973, 0.37973, 0.37973, 0.37973, 0.38712, 0.39455, 0.40204, 0.40980, 0.41775, 0.42690, 0.43209, 0.43680, 0.44546, 0.45770, 0.47231, 0.48950, 0.50977, 0.53330, 0.55996, 0.58880, 0.61854, 0.64750, 0.67396, 0.69650, 0.71398, 0.72620, 0.73336, 0.73640, 0.73638, 0.73420, 0.73061, 0.72610, 0.72102, 0.71550, 0.70967, 0.70390, 0.69860, 0.69410, 0.69062, 0.68810, 0.68630, 0.68460, 0.68243, 0.67990, 0.67729, 0.67490, 0.67300, 0.67180, 0.67137, 0.67140, 0.67164, 0.67250, 0.67464, 0.67890, 0.68616, 0.69710, 0.71218, 0.73100, 0.75284, 0.77640, 0.80025, 0.82300, 0.84343, 0.86090, 0.87518, 0.88720, 0.89754, 0.90410, 0.91008, 0.91555, 0.92071, 0.92558, 0.93018, 0.93451, 0.93859, 0.94243, 0.94604, 0.94945, 0.95264, 0.95565, 0.95847, 0.96112, 0.96360, 0.96594, 0.96594, 0.96594, 0.96594, 0.96594, 0.96594, 0.96594, 0.96594, 0.96594, 0.96594, 0.96594 } },
{ 95, 360.0, 830.0, 1.0, { 0.06598, 0.06598, 0.06598, 0.06598, 0.06598, 0.06537, 0.06477, 0.06418, 0.06374, 0.06292, 0.06235, 0.06213, 0.06235, 0.06307, 0.06414, 0.06540, 0.06682, 0.06845, 0.07050, 0.07328, 0.07725, 0.08275, 0.08966, 0.09786, 0.10793, 0.12099, 0.13980, 0.16761, 0.20821, 0.26399, 0.33133, 0.40352, 0.46746, 0.51124, 0.53408, 0.53861, 0.52991, 0.51304, 0.49059, 0.46466, 0.43777, 0.41211, 0.38793, 0.36527, 0.34523, 0.32877, 0.31534, 0.30404, 0.29410, 0.28480, 0.27563, 0.26625, 0.25696, 0.24839, 0.24177, 0.23840, 0.23909, 0.24436, 0.25398, 0.26709, 0.28089, 0.29267, 0.30194, 0.30939, 0.31803, 0.33103, 0.34980, 0.37529, 0.40848, 0.43191, 0.45996, 0.48826, 0.51664, 0.54491, 0.57290, 0.60042, 0.62733, 0.65347, 0.67872, 0.70296, 0.72611, 0.74810, 0.76889, 0.78845, 0.80677, 0.80677, 0.80677, 0.80677, 0.80677, 0.80677, 0.80677, 0.80677, 0.80677, 0.80677, 0.80677 } },
{ 95, 360.0, 830.0, 1.0, { 0.08862, 0.08862, 0.08862, 0.08862, 0.08862, 0.08277, 0.07727, 0.07211, 0.06710, 0.06228, 0.05620, 0.05196, 0.04970, 0.04885, 0.04890, 0.04950, 0.05090, 0.05356, 0.05820, 0.06544, 0.07510, 0.08761, 0.10660, 0.13515, 0.17100, 0.21203, 0.26190, 0.32330, 0.38910, 0.45024, 0.49970, 0.53263, 0.55070, 0.55722, 0.55550, 0.54854, 0.53800, 0.52506, 0.51020, 0.49382, 0.47680, 0.46002, 0.44390, 0.42861, 0.41390, 0.39905, 0.38200, 0.36163, 0.34190, 0.32717, 0.31840, 0.31512, 0.31440, 0.31336, 0.31170, 0.30968, 0.30730, 0.30349, 0.29310, 0.27208, 0.24480, 0.21777, 0.19760, 0.18894, 0.18850, 0.19437, 0.21810, 0.26567, 0.30730, 0.35107, 0.39594, 0.44264, 0.49037, 0.53828, 0.58549, 0.63118, 0.67464, 0.71528, 0.75271, 0.78669, 0.81713, 0.84409, 0.86771, 0.88823, 0.90592, 0.90592, 0.90592, 0.90592, 0.90592, 0.90592, 0.90592, 0.90592, 0.90592, 0.90592, 0.90592 } },
{ 95, 360.0, 830.0, 1.0, { 0.04163, 0.04163, 0.04163, 0.04163, 0.04163, 0.04219, 0.04274, 0.04331, 0.04390, 0.04451, 0.04520, 0.04555, 0.04570, 0.04589, 0.04610, 0.04629, 0.04650, 0.04676, 0.04700, 0.04714, 0.04720, 0.04724, 0.04740, 0.04779, 0.04830, 0.04879, 0.04930, 0.04986, 0.05040, 0.05082, 0.05110, 0.05122, 0.05120, 0.05107, 0.05090, 0.05076, 0.05060, 0.05036, 0.05010, 0.04987, 0.04960, 0.04922, 0.04890, 0.04879, 0.04880, 0.04880, 0.04880, 0.04882, 0.04880, 0.04868, 0.04860, 0.04868, 0.04890, 0.04918, 0.04950, 0.04984, 0.05020, 0.05057, 0.05100, 0.05150, 0.05200, 0.05242, 0.05270, 0.05278, 0.05270, 0.05252, 0.05230, 0.05211, 0.05200, 0.05189, 0.05179, 0.05168, 0.05158, 0.05147, 0.05137, 0.05127, 0.05116, 0.05106, 0.05096, 0.05085, 0.05075, 0.05065, 0.05055, 0.05045, 0.05034, 0.05034, 0.05034, 0.05034, 0.05034, 0.05034, 0.05034, 0.05034, 0.05034, 0.05034, 0.05034 } },
{ 95, 360.0, 830.0, 1.0, { 0.05540, 0.05540, 0.05540, 0.05540, 0.05540, 0.05519, 0.05609, 0.05723, 0.05760, 0.05773, 0.05841, 0.05900, 0.06076, 0.06181, 0.06364, 0.06536, 0.06841, 0.07063, 0.07333, 0.07831, 0.08470, 0.09311, 0.10313, 0.11523, 0.13064, 0.14961, 0.17359, 0.20369, 0.23996, 0.27414, 0.30443, 0.32537, 0.33756, 0.34253, 0.34239, 0.33797, 0.33044, 0.32147, 0.31229, 0.29914, 0.28479, 0.27639, 0.26307, 0.24861, 0.23426, 0.21943, 0.20576, 0.19114, 0.17990, 0.17159, 0.16571, 0.16047, 0.15739, 0.15454, 0.15364, 0.15204, 0.15024, 0.15039, 0.15037, 0.15041, 0.15234, 0.15367, 0.15924, 0.16394, 0.16737, 0.16914, 0.17330, 0.17773, 0.17987, 0.18020, 0.18000, 0.17773, 0.17586, 0.17644, 0.17847, 0.18116, 0.18747, 0.19526, 0.20319, 0.20930, 0.21407, 0.21864, 0.21997, 0.21784, 0.21926, 0.21926, 0.21926, 0.21926, 0.21926, 0.21926, 0.21926, 0.21926, 0.21926, 0.21926, 0.21926 } },
{ 95, 360.0, 830.0, 1.0, { 0.09982, 0.09982, 0.09982, 0.09982, 0.09982, 0.10287, 0.10599, 0.10920, 0.11260, 0.11615, 0.12020, 0.12231, 0.12350, 0.12532, 0.12800, 0.13152, 0.13620, 0.14245, 0.15070, 0.16141, 0.17520, 0.19261, 0.21370, 0.23822, 0.26510, 0.29289, 0.31950, 0.34297, 0.36240, 0.37735, 0.38800, 0.39477, 0.39830, 0.39931, 0.39860, 0.39682, 0.39400, 0.39003, 0.38490, 0.37870, 0.37190, 0.36490, 0.35750, 0.34938, 0.34030, 0.33000, 0.31810, 0.30447, 0.29020, 0.27656, 0.26440, 0.25433, 0.24630, 0.24004, 0.23490, 0.23025, 0.22600, 0.22218, 0.21890, 0.21633, 0.21470, 0.21422, 0.21480, 0.21628, 0.21840, 0.22098, 0.22420, 0.22799, 0.23080, 0.23356, 0.23624, 0.23895, 0.24168, 0.24443, 0.24720, 0.24999, 0.25280, 0.25564, 0.25849, 0.26137, 0.26426, 0.26718, 0.27011, 0.27307, 0.27605, 0.27605, 0.27605, 0.27605, 0.27605, 0.27605, 0.27605, 0.27605, 0.27605, 0.27605, 0.27605 } },
{ 95, 360.0, 830.0, 1.0, { 0.14254, 0.14254, 0.14254, 0.14254, 0.14254, 0.14305, 0.14356, 0.14407, 0.14460, 0.14514, 0.14580, 0.14646, 0.14840, 0.15294, 0.16010, 0.16970, 0.18200, 0.19737, 0.21620, 0.23886, 0.26560, 0.29650, 0.33100, 0.36800, 0.40480, 0.43811, 0.46400, 0.47933, 0.48480, 0.48229, 0.47450, 0.46402, 0.45220, 0.43995, 0.42770, 0.41577, 0.40450, 0.39412, 0.38450, 0.37543, 0.36690, 0.35895, 0.35180, 0.34575, 0.34130, 0.33870, 0.33700, 0.33506, 0.33220, 0.32808, 0.32320, 0.31848, 0.31560, 0.31636, 0.32210, 0.33395, 0.35250, 0.37809, 0.41040, 0.44884, 0.49220, 0.53897, 0.58690, 0.63375, 0.67790, 0.71834, 0.75580, 0.78958, 0.81150, 0.83107, 0.84844, 0.86431, 0.87876, 0.89187, 0.90371, 0.91438, 0.92396, 0.93256, 0.94024, 0.94710, 0.95321, 0.95864, 0.96347, 0.96776, 0.97155, 0.97155, 0.97155, 0.97155, 0.97155, 0.97155, 0.97155, 0.97155, 0.97155, 0.97155, 0.97155 } },
{ 95, 360.0, 830.0, 1.0, { 0.08776, 0.08776, 0.08776, 0.08776, 0.08776, 0.08843, 0.08933, 0.09022, 0.09089, 0.09134, 0.09245, 0.09578, 0.10461, 0.12154, 0.14474, 0.17179, 0.20227, 0.23616, 0.27292, 0.31153, 0.34940, 0.38408, 0.41516, 0.44282, 0.46753, 0.48971, 0.50918, 0.52583, 0.54042, 0.55383, 0.56646, 0.57838, 0.58866, 0.59648, 0.60236, 0.60683, 0.60921, 0.60857, 0.60427, 0.59607, 0.58490, 0.57159, 0.55521, 0.53495, 0.51211, 0.48821, 0.46354, 0.43824, 0.41298, 0.38846, 0.36486, 0.34231, 0.32117, 0.30177, 0.28420, 0.26844, 0.25429, 0.24158, 0.23040, 0.22080, 0.21248, 0.20511, 0.19862, 0.19300, 0.18827, 0.18444, 0.18137, 0.17893, 0.17713, 0.17599, 0.17550, 0.17564, 0.17652, 0.17830, 0.18111, 0.18243, 0.18437, 0.18633, 0.18831, 0.19030, 0.19230, 0.19433, 0.19637, 0.19842, 0.20049, 0.20049, 0.20049, 0.20049, 0.20049, 0.20049, 0.20049, 0.20049, 0.20049, 0.20049, 0.20049 } },
{ 95, 360.0, 830.0, 1.0, { 0.00057, 0.00057, 0.00057, 0.00057, 0.00057, 0.00739, 0.01389, 0.02038, 0.02720, 0.03434, 0.04051, 0.04446, 0.04633, 0.04675, 0.04681, 0.04748, 0.04889, 0.05103, 0.05418, 0.05879, 0.06559, 0.07524, 0.08795, 0.10363, 0.12163, 0.14087, 0.15921, 0.17469, 0.18701, 0.19627, 0.20241, 0.20542, 0.20553, 0.20313, 0.19895, 0.19369, 0.18754, 0.18056, 0.17279, 0.16436, 0.15574, 0.14741, 0.13947, 0.13197, 0.12523, 0.11951, 0.11449, 0.10977, 0.10532, 0.10120, 0.09750, 0.09436, 0.09190, 0.09028, 0.08950, 0.08951, 0.09004, 0.09084, 0.09188, 0.09319, 0.09465, 0.09614, 0.09758, 0.09892, 0.10023, 0.10164, 0.10336, 0.10553, 0.10789, 0.11019, 0.11246, 0.11484, 0.11757, 0.12090, 0.12509, 0.12825, 0.13195, 0.13574, 0.13962, 0.14359, 0.14766, 0.15182, 0.15608, 0.16044, 0.16489, 0.16489, 0.16489, 0.16489, 0.16489, 0.16489, 0.16489, 0.16489, 0.16489, 0.16489, 0.16489 } },
{ 95, 360.0, 830.0, 1.0, { 0.07883, 0.07883, 0.07883, 0.07883, 0.07883, 0.08225, 0.08580, 0.08949, 0.09339, 0.09727, 0.10142, 0.10575, 0.11016, 0.11458, 0.11919, 0.12413, 0.12931, 0.13467, 0.14052, 0.14714, 0.15412, 0.16118, 0.16930, 0.18000, 0.19580, 0.21832, 0.24453, 0.27019, 0.29107, 0.30412, 0.31122, 0.31477, 0.31449, 0.30979, 0.30149, 0.29047, 0.27638, 0.25896, 0.23937, 0.21933, 0.20136, 0.18742, 0.17665, 0.16780, 0.16107, 0.15676, 0.15442, 0.15328, 0.15223, 0.15040, 0.14826, 0.14662, 0.14618, 0.14745, 0.15005, 0.15358, 0.15829, 0.16436, 0.17109, 0.17743, 0.18201, 0.18381, 0.18359, 0.18240, 0.18052, 0.17803, 0.17486, 0.17093, 0.16613, 0.16279, 0.15896, 0.15521, 0.15154, 0.14793, 0.14440, 0.14093, 0.13754, 0.13421, 0.13096, 0.12777, 0.12464, 0.12159, 0.11859, 0.11566, 0.11280, 0.11280, 0.11280, 0.11280, 0.11280, 0.11280, 0.11280, 0.11280, 0.11280, 0.11280, 0.11280 } },
{ 95, 360.0, 830.0, 1.0, { 0.09950, 0.09950, 0.09950, 0.09950, 0.09950, 0.10406, 0.10880, 0.11373, 0.11889, 0.12416, 0.12971, 0.13543, 0.14122, 0.14703, 0.15303, 0.15937, 0.16583, 0.17226, 0.17913, 0.18680, 0.19471, 0.20244, 0.21118, 0.22283, 0.24056, 0.26640, 0.29663, 0.32597, 0.34883, 0.36119, 0.36570, 0.36586, 0.36203, 0.35401, 0.34248, 0.32800, 0.30983, 0.28742, 0.26249, 0.23757, 0.21634, 0.20167, 0.19213, 0.18575, 0.18280, 0.18373, 0.18766, 0.19304, 0.19699, 0.19725, 0.19521, 0.19302, 0.19233, 0.19418, 0.19788, 0.20264, 0.20890, 0.21709, 0.22617, 0.23465, 0.24066, 0.24281, 0.24224, 0.24044, 0.23778, 0.23432, 0.22994, 0.22450, 0.21783, 0.21320, 0.20789, 0.20268, 0.19757, 0.19256, 0.18764, 0.18282, 0.17810, 0.17347, 0.16894, 0.16450, 0.16016, 0.15591, 0.15175, 0.14769, 0.14371, 0.14371, 0.14371, 0.14371, 0.14371, 0.14371, 0.14371, 0.14371, 0.14371, 0.14371, 0.14371 } },
{ 95, 360.0, 830.0, 1.0, { 0.05860, 0.05860, 0.05860, 0.05860, 0.05860, 0.05842, 0.05824, 0.05806, 0.05802, 0.05765, 0.05750, 0.05753, 0.05771, 0.05801, 0.05853, 0.05937, 0.06059, 0.06229, 0.06471, 0.06784, 0.07048, 0.07175, 0.07306, 0.07679, 0.08687, 0.10600, 0.13056, 0.15571, 0.17817, 0.19575, 0.20908, 0.21853, 0.22052, 0.21204, 0.19630, 0.17770, 0.15900, 0.14200, 0.12623, 0.11115, 0.09810, 0.08841, 0.08151, 0.07650, 0.07296, 0.07063, 0.06935, 0.06891, 0.06884, 0.06872, 0.06863, 0.06872, 0.06894, 0.06923, 0.06966, 0.07040, 0.07182, 0.07418, 0.07708, 0.07997, 0.08223, 0.08342, 0.08378, 0.08364, 0.08306, 0.08200, 0.08048, 0.07849, 0.07605, 0.07441, 0.07251, 0.07065, 0.06884, 0.06707, 0.06535, 0.06366, 0.06202, 0.06041, 0.05885, 0.05732, 0.05583, 0.05438, 0.05296, 0.05158, 0.05023, 0.05023, 0.05023, 0.05023, 0.05023, 0.05023, 0.05023, 0.05023, 0.05023, 0.05023, 0.05023 } },
{ 95, 360.0, 830.0, 1.0, { 0.07278, 0.07278, 0.07278, 0.07278, 0.07278, 0.07402, 0.07528, 0.07656, 0.07790, 0.07930, 0.08120, 0.08291, 0.08480, 0.08736, 0.09050, 0.09403, 0.09800, 0.10263, 0.10860, 0.11658, 0.12670, 0.13900, 0.15380, 0.17152, 0.19280, 0.21822, 0.24790, 0.28105, 0.31370, 0.34111, 0.35850, 0.36251, 0.35540, 0.34058, 0.32030, 0.29646, 0.27060, 0.24412, 0.21820, 0.19387, 0.17170, 0.15204, 0.13470, 0.11940, 0.10590, 0.09403, 0.08390, 0.07567, 0.06940, 0.06504, 0.06220, 0.06044, 0.05940, 0.05878, 0.05840, 0.05812, 0.05790, 0.05775, 0.05790, 0.05855, 0.05960, 0.06093, 0.06250, 0.06428, 0.06610, 0.06780, 0.06950, 0.07121, 0.07240, 0.07356, 0.07471, 0.07586, 0.07704, 0.07823, 0.07943, 0.08066, 0.08190, 0.08316, 0.08443, 0.08572, 0.08704, 0.08837, 0.08971, 0.09108, 0.09247, 0.09247, 0.09247, 0.09247, 0.09247, 0.09247, 0.09247, 0.09247, 0.09247, 0.09247, 0.09247 } },
{ 95, 360.0, 830.0, 1.0, { 0.40857, 0.40857, 0.40857, 0.40857, 0.40857, 0.42408, 0.43973, 0.45551, 0.47190, 0.48883, 0.51160, 0.53114, 0.54880, 0.56754, 0.58620, 0.60333, 0.62040, 0.63907, 0.65890, 0.67891, 0.69800, 0.71523, 0.73050, 0.74379, 0.75470, 0.76285, 0.76840, 0.77166, 0.77300, 0.77289, 0.77220, 0.77164, 0.77090, 0.76950, 0.76730, 0.76421, 0.76000, 0.75437, 0.74680, 0.73691, 0.72520, 0.71226, 0.69820, 0.68280, 0.66490, 0.64336, 0.61800, 0.58959, 0.56170, 0.53802, 0.51990, 0.50780, 0.50090, 0.49798, 0.49760, 0.49839, 0.49950, 0.50065, 0.50320, 0.50874, 0.51800, 0.53104, 0.54610, 0.56122, 0.57550, 0.58862, 0.60150, 0.61435, 0.62320, 0.63169, 0.63982, 0.64787, 0.65583, 0.66371, 0.67150, 0.67920, 0.68680, 0.69430, 0.70170, 0.70899, 0.71618, 0.72326, 0.73023, 0.73709, 0.74383, 0.74383, 0.74383, 0.74383, 0.74383, 0.74383, 0.74383, 0.74383, 0.74383, 0.74383, 0.74383 } },
{ 95, 360.0, 830.0, 1.0, { 0.30073, 0.30073, 0.30073, 0.30073, 0.30073, 0.32661, 0.34992, 0.37230, 0.39416, 0.41553, 0.43632, 0.45652, 0.47668, 0.49725, 0.51775, 0.53774, 0.55789, 0.57898, 0.60125, 0.62458, 0.64804, 0.67049, 0.69066, 0.70754, 0.72132, 0.73246, 0.74115, 0.74752, 0.75151, 0.75312, 0.75259, 0.75010, 0.74537, 0.73810, 0.72853, 0.71689, 0.70284, 0.68608, 0.66694, 0.64607, 0.62480, 0.60444, 0.58562, 0.56856, 0.55242, 0.53611, 0.51865, 0.49975, 0.48196, 0.46791, 0.45788, 0.45146, 0.44792, 0.44644, 0.44631, 0.44699, 0.44862, 0.45160, 0.45656, 0.46396, 0.47319, 0.48341, 0.49376, 0.50347, 0.51212, 0.51931, 0.52450, 0.52735, 0.52854, 0.52899, 0.52954, 0.53109, 0.53478, 0.54158, 0.55168, 0.56548, 0.58514, 0.61045, 0.62991, 0.63369, 0.62991, 0.62865, 0.62991, 0.63117, 0.62991, 0.62991, 0.62991, 0.62991, 0.62991, 0.62991, 0.62991, 0.62991, 0.62991, 0.62991, 0.62991 } },
{ 95, 360.0, 830.0, 1.0, { 0.15521, 0.15521, 0.15521, 0.15521, 0.15521, 0.17199, 0.19018, 0.20980, 0.23150, 0.25503, 0.28201, 0.29616, 0.30297, 0.31130, 0.32158, 0.33253, 0.34437, 0.35808, 0.37612, 0.40032, 0.42836, 0.45815, 0.49262, 0.53399, 0.57658, 0.61368, 0.64244, 0.66137, 0.67063, 0.67106, 0.66461, 0.65332, 0.63836, 0.62052, 0.59994, 0.57664, 0.55071, 0.52241, 0.49259, 0.46218, 0.43191, 0.40231, 0.37328, 0.34465, 0.31651, 0.28904, 0.26263, 0.23787, 0.21609, 0.19856, 0.18547, 0.17653, 0.17054, 0.16621, 0.16281, 0.15981, 0.15704, 0.15455, 0.15295, 0.15286, 0.15443, 0.15772, 0.16295, 0.16994, 0.17687, 0.18216, 0.18699, 0.19243, 0.19647, 0.20045, 0.20436, 0.20833, 0.21235, 0.21642, 0.22056, 0.22475, 0.22899, 0.23330, 0.23765, 0.24207, 0.24654, 0.25106, 0.25564, 0.26027, 0.26496, 0.26496, 0.26496, 0.26496, 0.26496, 0.26496, 0.26496, 0.26496, 0.26496, 0.26496, 0.26496 } },
{ 95, 360.0, 830.0, 1.0, { 0.13470, 0.13470, 0.13470, 0.13470, 0.13470, 0.13497, 0.13470, 0.13370, 0.13470, 0.13984, 0.14600, 0.14999, 0.15360, 0.15934, 0.16770, 0.17857, 0.19160, 0.20654, 0.22380, 0.24394, 0.26740, 0.29427, 0.32340, 0.35336, 0.38270, 0.40983, 0.43250, 0.44870, 0.45800, 0.46055, 0.45710, 0.44861, 0.43620, 0.42088, 0.40300, 0.38264, 0.35940, 0.33313, 0.30510, 0.27694, 0.25030, 0.22651, 0.20550, 0.18674, 0.16940, 0.15247, 0.13470, 0.11572, 0.09900, 0.08790, 0.08160, 0.07827, 0.07630, 0.07448, 0.07290, 0.07173, 0.07010, 0.06692, 0.06130, 0.05304, 0.04440, 0.03781, 0.03390, 0.03263, 0.03320, 0.03593, 0.04650, 0.06786, 0.08660, 0.09028, 0.08660, 0.08561, 0.08660, 0.08686, 0.08660, 0.08653, 0.08660, 0.08662, 0.08660, 0.08660, 0.08660, 0.08660, 0.08660, 0.08660, 0.08660, 0.08660, 0.08660, 0.08660, 0.08660, 0.08660, 0.08660, 0.08660, 0.08660, 0.08660, 0.08660 } },
{ 95, 360.0, 830.0, 1.0, { 0.10606, 0.10606, 0.10606, 0.10606, 0.10606, 0.11035, 0.11514, 0.12020, 0.12531, 0.13033, 0.13550, 0.14114, 0.14747, 0.15464, 0.16259, 0.17128, 0.18103, 0.19242, 0.20673, 0.22518, 0.24804, 0.27486, 0.30339, 0.33116, 0.35681, 0.37901, 0.39557, 0.40468, 0.40690, 0.40341, 0.39562, 0.38483, 0.37179, 0.35707, 0.34094, 0.32357, 0.30490, 0.28488, 0.26380, 0.24215, 0.22077, 0.20033, 0.18041, 0.16051, 0.14091, 0.12209, 0.10463, 0.08914, 0.07639, 0.06696, 0.06048, 0.05632, 0.05385, 0.05246, 0.05170, 0.05122, 0.05094, 0.05089, 0.05139, 0.05276, 0.05499, 0.05802, 0.06171, 0.06589, 0.07020, 0.07429, 0.07806, 0.08141, 0.08396, 0.08534, 0.08554, 0.08476, 0.08362, 0.08285, 0.08317, 0.08202, 0.08147, 0.08092, 0.08037, 0.07983, 0.07929, 0.07876, 0.07822, 0.07769, 0.07717, 0.07717, 0.07717, 0.07717, 0.07717, 0.07717, 0.07717, 0.07717, 0.07717, 0.07717, 0.07717 } },
{ 95, 360.0, 830.0, 1.0, { 0.18471, 0.18471, 0.18471, 0.18471, 0.18471, 0.23474, 0.29345, 0.35993, 0.43450, 0.51357, 0.60420, 0.65038, 0.66450, 0.67117, 0.67560, 0.67830, 0.68050, 0.68332, 0.68690, 0.69119, 0.69650, 0.70332, 0.71260, 0.72513, 0.74050, 0.75796, 0.77650, 0.79473, 0.81000, 0.81990, 0.82440, 0.82407, 0.81960, 0.81160, 0.80030, 0.78591, 0.76890, 0.74963, 0.72790, 0.70380, 0.67930, 0.65657, 0.63660, 0.61990, 0.60610, 0.59451, 0.58410, 0.57394, 0.56400, 0.55461, 0.54680, 0.54140, 0.53770, 0.53473, 0.53190, 0.52908, 0.52750, 0.52840, 0.53160, 0.53599, 0.53820, 0.53583, 0.53260, 0.53260, 0.53530, 0.53839, 0.53720, 0.52892, 0.52050, 0.51216, 0.50406, 0.49595, 0.48784, 0.47974, 0.47166, 0.46358, 0.45553, 0.44749, 0.43949, 0.43152, 0.42358, 0.41568, 0.40783, 0.40002, 0.39226, 0.39226, 0.39226, 0.39226, 0.39226, 0.39226, 0.39226, 0.39226, 0.39226, 0.39226, 0.39226 } },
{ 95, 360.0, 830.0, 1.0, { 0.43710, 0.43710, 0.43710, 0.43710, 0.43710, 0.47272, 0.50312, 0.53129, 0.55735, 0.58083, 0.60183, 0.62063, 0.63777, 0.65381, 0.66908, 0.68370, 0.69721, 0.70918, 0.71973, 0.72912, 0.73751, 0.74500, 0.75159, 0.75729, 0.76220, 0.76636, 0.76953, 0.77145, 0.77193, 0.77082, 0.76796, 0.76324, 0.75680, 0.74895, 0.74036, 0.73159, 0.72237, 0.71241, 0.70206, 0.69189, 0.68268, 0.67515, 0.66956, 0.66589, 0.66336, 0.66107, 0.65854, 0.65553, 0.65249, 0.65002, 0.64874, 0.64903, 0.65032, 0.65199, 0.65430, 0.65764, 0.66202, 0.66738, 0.67372, 0.68090, 0.68803, 0.69419, 0.69911, 0.70280, 0.70579, 0.70842, 0.70991, 0.70960, 0.70853, 0.70807, 0.70918, 0.71261, 0.71859, 0.72710, 0.73766, 0.75043, 0.76850, 0.79265, 0.81153, 0.81521, 0.81153, 0.81030, 0.81153, 0.81276, 0.81153, 0.81153, 0.81153, 0.81153, 0.81153, 0.81153, 0.81153, 0.81153, 0.81153, 0.81153, 0.81153 } },
{ 95, 360.0, 830.0, 1.0, { 0.28873, 0.28873, 0.28873, 0.28873, 0.28873, 0.30831, 0.32860, 0.34955, 0.36977, 0.39383, 0.41611, 0.43654, 0.45502, 0.47151, 0.48618, 0.49915, 0.51039, 0.51992, 0.52806, 0.53497, 0.53987, 0.54220, 0.54344, 0.54563, 0.55128, 0.56200, 0.57549, 0.58884, 0.60070, 0.61031, 0.61757, 0.62184, 0.61965, 0.60824, 0.59038, 0.56965, 0.54731, 0.52399, 0.50027, 0.47704, 0.45660, 0.44088, 0.42892, 0.41930, 0.41175, 0.40621, 0.40242, 0.39998, 0.39815, 0.39634, 0.39478, 0.39387, 0.39388, 0.39495, 0.39686, 0.39943, 0.40282, 0.40710, 0.41175, 0.41604, 0.41909, 0.42028, 0.42008, 0.41917, 0.41780, 0.41607, 0.41393, 0.41127, 0.40798, 0.40562, 0.40289, 0.40017, 0.39746, 0.39475, 0.39205, 0.38936, 0.38667, 0.38399, 0.38132, 0.37865, 0.37599, 0.37334, 0.37070, 0.36806, 0.36544, 0.36544, 0.36544, 0.36544, 0.36544, 0.36544, 0.36544, 0.36544, 0.36544, 0.36544, 0.36544 } },
{ 95, 360.0, 830.0, 1.0, { 0.17009, 0.17009, 0.17009, 0.17009, 0.17009, 0.17930, 0.18890, 0.19888, 0.20849, 0.22043, 0.23133, 0.24199, 0.25317, 0.26551, 0.27899, 0.29357, 0.30976, 0.32796, 0.34749, 0.36733, 0.38621, 0.40281, 0.41600, 0.42493, 0.42990, 0.43128, 0.42890, 0.42262, 0.41302, 0.40101, 0.38820, 0.37623, 0.36636, 0.35908, 0.35246, 0.34451, 0.33558, 0.32660, 0.31870, 0.31303, 0.31076, 0.31238, 0.31572, 0.31825, 0.31870, 0.31651, 0.31274, 0.30881, 0.30579, 0.30449, 0.30480, 0.30627, 0.30778, 0.30843, 0.30877, 0.30964, 0.31175, 0.31579, 0.32267, 0.33330, 0.34848, 0.36893, 0.39515, 0.42758, 0.46663, 0.51216, 0.56194, 0.61321, 0.66321, 0.70794, 0.74967, 0.78723, 0.82050, 0.84956, 0.87463, 0.89604, 0.91415, 0.92936, 0.94204, 0.95256, 0.96125, 0.96840, 0.97427, 0.97907, 0.98299, 0.98299, 0.98299, 0.98299, 0.98299, 0.98299, 0.98299, 0.98299, 0.98299, 0.98299, 0.98299 } },
{ 95, 360.0, 830.0, 1.0, { 0.02353, 0.02353, 0.02353, 0.02353, 0.02353, 0.02714, 0.03128, 0.03604, 0.03956, 0.04880, 0.05538, 0.05973, 0.06229, 0.06356, 0.06429, 0.06519, 0.06650, 0.06835, 0.07080, 0.07393, 0.07801, 0.08318, 0.08883, 0.09427, 0.09914, 0.10306, 0.10525, 0.10508, 0.10285, 0.09908, 0.09414, 0.08838, 0.08232, 0.07644, 0.07090, 0.06586, 0.06169, 0.05878, 0.05728, 0.05732, 0.05899, 0.06227, 0.06670, 0.07168, 0.07651, 0.08049, 0.08302, 0.08366, 0.08262, 0.08028, 0.07721, 0.07397, 0.07080, 0.06788, 0.06539, 0.06346, 0.06189, 0.06055, 0.05979, 0.05995, 0.06109, 0.06312, 0.06589, 0.06936, 0.07381, 0.07946, 0.08592, 0.09264, 0.09904, 0.10694, 0.11492, 0.12341, 0.13244, 0.14202, 0.15216, 0.16290, 0.17424, 0.18619, 0.19876, 0.21197, 0.22580, 0.24026, 0.25534, 0.27102, 0.28730, 0.28730, 0.28730, 0.28730, 0.28730, 0.28730, 0.28730, 0.28730, 0.28730, 0.28730, 0.28730 } },
{ 95, 360.0, 830.0, 1.0, { 0.16989, 0.16989, 0.16989, 0.16989, 0.16989, 0.18211, 0.19500, 0.20857, 0.22326, 0.23893, 0.25743, 0.26842, 0.27548, 0.28427, 0.29488, 0.30635, 0.31906, 0.33377, 0.35150, 0.37310, 0.39842, 0.42668, 0.45565, 0.48271, 0.50514, 0.52064, 0.52858, 0.52895, 0.52250, 0.51016, 0.49295, 0.47185, 0.44761, 0.42095, 0.39281, 0.36403, 0.33487, 0.30556, 0.27667, 0.24893, 0.22344, 0.20115, 0.18221, 0.16643, 0.15310, 0.14145, 0.13099, 0.12147, 0.11320, 0.10657, 0.10171, 0.09859, 0.09675, 0.09567, 0.09500, 0.09454, 0.09440, 0.09475, 0.09577, 0.09754, 0.09981, 0.10231, 0.10484, 0.10725, 0.10932, 0.11084, 0.11159, 0.11151, 0.11115, 0.11079, 0.11044, 0.11008, 0.10973, 0.10938, 0.10903, 0.10869, 0.10834, 0.10799, 0.10765, 0.10730, 0.10696, 0.10662, 0.10628, 0.10594, 0.10560, 0.10560, 0.10560, 0.10560, 0.10560, 0.10560, 0.10560, 0.10560, 0.10560, 0.10560, 0.10560 } },
{ 95, 360.0, 830.0, 1.0, { 0.00602, 0.00602, 0.00602, 0.00602, 0.00602, 0.00905, 0.01360, 0.02039, 0.02949, 0.04609, 0.06811, 0.09024, 0.10713, 0.11533, 0.11875, 0.12207, 0.12550, 0.12850, 0.13206, 0.13733, 0.14467, 0.15417, 0.16581, 0.17902, 0.19103, 0.19880, 0.20027, 0.19443, 0.18339, 0.16987, 0.15589, 0.14313, 0.13275, 0.12537, 0.12004, 0.11552, 0.11101, 0.10609, 0.10157, 0.09857, 0.09810, 0.10068, 0.10475, 0.10827, 0.10922, 0.10612, 0.09949, 0.09047, 0.08072, 0.07169, 0.06355, 0.05616, 0.04935, 0.04295, 0.03694, 0.03133, 0.02631, 0.02207, 0.01867, 0.01613, 0.01430, 0.01301, 0.01211, 0.01150, 0.01112, 0.01094, 0.01092, 0.01106, 0.01132, 0.01139, 0.01154, 0.01169, 0.01184, 0.01200, 0.01216, 0.01232, 0.01248, 0.01265, 0.01281, 0.01298, 0.01315, 0.01332, 0.01350, 0.01368, 0.01386, 0.01386, 0.01386, 0.01386, 0.01386, 0.01386, 0.01386, 0.01386, 0.01386, 0.01386, 0.01386 } },
{ 95, 360.0, 830.0, 1.0, { 0.09963, 0.09963, 0.09963, 0.09963, 0.09963, 0.10544, 0.11155, 0.11796, 0.12490, 0.13231, 0.14130, 0.14721, 0.15180, 0.15780, 0.16550, 0.17467, 0.18540, 0.19798, 0.21300, 0.23107, 0.25240, 0.27660, 0.30110, 0.32295, 0.33970, 0.34943, 0.35190, 0.34737, 0.33650, 0.32016, 0.29980, 0.27692, 0.25270, 0.22820, 0.20430, 0.18174, 0.16090, 0.14202, 0.12520, 0.11054, 0.09830, 0.08866, 0.08130, 0.07575, 0.07150, 0.06811, 0.06530, 0.06290, 0.06090, 0.05933, 0.05820, 0.05751, 0.05710, 0.05680, 0.05660, 0.05650, 0.05650, 0.05658, 0.05680, 0.05720, 0.05770, 0.05822, 0.05870, 0.05910, 0.05940, 0.05961, 0.05970, 0.05967, 0.05960, 0.05953, 0.05947, 0.05940, 0.05933, 0.05927, 0.05920, 0.05914, 0.05907, 0.05900, 0.05894, 0.05887, 0.05881, 0.05874, 0.05868, 0.05861, 0.05854, 0.05854, 0.05854, 0.05854, 0.05854, 0.05854, 0.05854, 0.05854, 0.05854, 0.05854, 0.05854 } },
{ 95, 360.0, 830.0, 1.0, { 0.10927, 0.10927, 0.10927, 0.10927, 0.10927, 0.11775, 0.12680, 0.13644, 0.14700, 0.15842, 0.17220, 0.18102, 0.18720, 0.19467, 0.20420, 0.21573, 0.22910, 0.24431, 0.26200, 0.28281, 0.30680, 0.33330, 0.35940, 0.38192, 0.39890, 0.40878, 0.41030, 0.40282, 0.38790, 0.36754, 0.34330, 0.31661, 0.28890, 0.26145, 0.23510, 0.21043, 0.18760, 0.16666, 0.14770, 0.13090, 0.11670, 0.10545, 0.09680, 0.09021, 0.08510, 0.08095, 0.07740, 0.07421, 0.07140, 0.06907, 0.06740, 0.06650, 0.06610, 0.06589, 0.06570, 0.06547, 0.06540, 0.06569, 0.06630, 0.06714, 0.06800, 0.06869, 0.06910, 0.06920, 0.06910, 0.06891, 0.06860, 0.06816, 0.06780, 0.06745, 0.06712, 0.06679, 0.06646, 0.06613, 0.06580, 0.06548, 0.06516, 0.06483, 0.06451, 0.06419, 0.06387, 0.06356, 0.06324, 0.06293, 0.06262, 0.06262, 0.06262, 0.06262, 0.06262, 0.06262, 0.06262, 0.06262, 0.06262, 0.06262, 0.06262 } },
{ 95, 360.0, 830.0, 1.0, { 0.22149, 0.22149, 0.22149, 0.22149, 0.22149, 0.23594, 0.25104, 0.26676, 0.28245, 0.30036, 0.31769, 0.33467, 0.35149, 0.36826, 0.38457, 0.39997, 0.41415, 0.42690, 0.43836, 0.44837, 0.45536, 0.45810, 0.45804, 0.45745, 0.45897, 0.46435, 0.47144, 0.47732, 0.47999, 0.47816, 0.47257, 0.46378, 0.44970, 0.42856, 0.40271, 0.37520, 0.34809, 0.32279, 0.29914, 0.27704, 0.25793, 0.24313, 0.23196, 0.22349, 0.21784, 0.21519, 0.21485, 0.21593, 0.21763, 0.21934, 0.22104, 0.22281, 0.22444, 0.22571, 0.22681, 0.22807, 0.23021, 0.23373, 0.23804, 0.24224, 0.24535, 0.24669, 0.24669, 0.24599, 0.24484, 0.24338, 0.24154, 0.23921, 0.23629, 0.23428, 0.23192, 0.22958, 0.22726, 0.22495, 0.22267, 0.22039, 0.21814, 0.21590, 0.21368, 0.21147, 0.20928, 0.20711, 0.20495, 0.20282, 0.20069, 0.20069, 0.20069, 0.20069, 0.20069, 0.20069, 0.20069, 0.20069, 0.20069, 0.20069, 0.20069 } },
{ 95, 360.0, 830.0, 1.0, { 0.13225, 0.13225, 0.13225, 0.13225, 0.13225, 0.13933, 0.14672, 0.15443, 0.16220, 0.17098, 0.17961, 0.18831, 0.19733, 0.20679, 0.21630, 0.22540, 0.23381, 0.24136, 0.24814, 0.25399, 0.25741, 0.25724, 0.25494, 0.25267, 0.25277, 0.25679, 0.26298, 0.26902, 0.27359, 0.27587, 0.27606, 0.27413, 0.26802, 0.25609, 0.24031, 0.22327, 0.20640, 0.19064, 0.17600, 0.16260, 0.15168, 0.14438, 0.14004, 0.13802, 0.13932, 0.14481, 0.15313, 0.16242, 0.17116, 0.17820, 0.18373, 0.18816, 0.19156, 0.19396, 0.19558, 0.19682, 0.19847, 0.20117, 0.20444, 0.20756, 0.20980, 0.21071, 0.21063, 0.21003, 0.20908, 0.20784, 0.20630, 0.20442, 0.20218, 0.20051, 0.19863, 0.19676, 0.19491, 0.19307, 0.19124, 0.18942, 0.18762, 0.18584, 0.18406, 0.18230, 0.18055, 0.17882, 0.17709, 0.17538, 0.17369, 0.17369, 0.17369, 0.17369, 0.17369, 0.17369, 0.17369, 0.17369, 0.17369, 0.17369, 0.17369 } },
{ 95, 360.0, 830.0, 1.0, { 0.31794, 0.31794, 0.31794, 0.31794, 0.31794, 0.34608, 0.37534, 0.40554, 0.43537, 0.46845, 0.49988, 0.52990, 0.55872, 0.58644, 0.61261, 0.63672, 0.65857, 0.67805, 0.69495, 0.70890, 0.71896, 0.72438, 0.72576, 0.72392, 0.71916, 0.71161, 0.70123, 0.68800, 0.67187, 0.65288, 0.63147, 0.60796, 0.58201, 0.55343, 0.52327, 0.49283, 0.46320, 0.43523, 0.40899, 0.38458, 0.36303, 0.34528, 0.33078, 0.31880, 0.30924, 0.30208, 0.29698, 0.29355, 0.29142, 0.29027, 0.28997, 0.29041, 0.29121, 0.29206, 0.29307, 0.29450, 0.29688, 0.30057, 0.30502, 0.30941, 0.31264, 0.31392, 0.31378, 0.31299, 0.31182, 0.31034, 0.30852, 0.30629, 0.30358, 0.30160, 0.29933, 0.29708, 0.29484, 0.29260, 0.29038, 0.28817, 0.28597, 0.28377, 0.28159, 0.27942, 0.27726, 0.27511, 0.27296, 0.27083, 0.26871, 0.26871, 0.26871, 0.26871, 0.26871, 0.26871, 0.26871, 0.26871, 0.26871, 0.26871, 0.26871 } },
{ 95, 360.0, 830.0, 1.0, { 0.03646, 0.03646, 0.03646, 0.03646, 0.03646, 0.03952, 0.04283, 0.04641, 0.05040, 0.05485, 0.06170, 0.06943, 0.07860, 0.09002, 0.10340, 0.11814, 0.13360, 0.14925, 0.16520, 0.18141, 0.19670, 0.20953, 0.21820, 0.22140, 0.21950, 0.21333, 0.20390, 0.19206, 0.17800, 0.16197, 0.14520, 0.12916, 0.11530, 0.10467, 0.09690, 0.09100, 0.08500, 0.07718, 0.06770, 0.05734, 0.04730, 0.03901, 0.03430, 0.03478, 0.04080, 0.05134, 0.06120, 0.06540, 0.06410, 0.05901, 0.05300, 0.04859, 0.04590, 0.04443, 0.04370, 0.04331, 0.04310, 0.04314, 0.04410, 0.04681, 0.05200, 0.06016, 0.07080, 0.08316, 0.09630, 0.10963, 0.12420, 0.14004, 0.15140, 0.16305, 0.17496, 0.18755, 0.20083, 0.21480, 0.22946, 0.24480, 0.26083, 0.27752, 0.29486, 0.31280, 0.33133, 0.35040, 0.36995, 0.38994, 0.41031, 0.41031, 0.41031, 0.41031, 0.41031, 0.41031, 0.41031, 0.41031, 0.41031, 0.41031, 0.41031 } },
{ 95, 360.0, 830.0, 1.0, { 0.37756, 0.37756, 0.37756, 0.37756, 0.37756, 0.39319, 0.40905, 0.42509, 0.44022, 0.45815, 0.47443, 0.48877, 0.50091, 0.51073, 0.51874, 0.52556, 0.53162, 0.53716, 0.54203, 0.54598, 0.54903, 0.55122, 0.55254, 0.55300, 0.55264, 0.55149, 0.54955, 0.54681, 0.54326, 0.53894, 0.53389, 0.52809, 0.52121, 0.51298, 0.50390, 0.49461, 0.48566, 0.47742, 0.46979, 0.46263, 0.45609, 0.45034, 0.44537, 0.44115, 0.43795, 0.43598, 0.43496, 0.43460, 0.43496, 0.43610, 0.43774, 0.43955, 0.44114, 0.44227, 0.44310, 0.44397, 0.44537, 0.44767, 0.45052, 0.45332, 0.45526, 0.45577, 0.45536, 0.45475, 0.45433, 0.45436, 0.45475, 0.45534, 0.45598, 0.45652, 0.45709, 0.45767, 0.45825, 0.45883, 0.45941, 0.45998, 0.46056, 0.46114, 0.46172, 0.46230, 0.46288, 0.46346, 0.46404, 0.46462, 0.46519, 0.46519, 0.46519, 0.46519, 0.46519, 0.46519, 0.46519, 0.46519, 0.46519, 0.46519, 0.46519 } },
{ 95, 360.0, 830.0, 1.0, { 0.16160, 0.16160, 0.16160, 0.16160, 0.16160, 0.18016, 0.20034, 0.22217, 0.23998, 0.27370, 0.29807, 0.32072, 0.34930, 0.38927, 0.43737, 0.48744, 0.53051, 0.55904, 0.57419, 0.57916, 0.57668, 0.56907, 0.55741, 0.54267, 0.52663, 0.51095, 0.49575, 0.48059, 0.46418, 0.44544, 0.42486, 0.40323, 0.38078, 0.35769, 0.33451, 0.31157, 0.28794, 0.26281, 0.23701, 0.21187, 0.18905, 0.16994, 0.15459, 0.14279, 0.13464, 0.13012, 0.12858, 0.12914, 0.13086, 0.13275, 0.13364, 0.13271, 0.13047, 0.12777, 0.12550, 0.12447, 0.12520, 0.12807, 0.13295, 0.13949, 0.14695, 0.15462, 0.16234, 0.17089, 0.18428, 0.20617, 0.23561, 0.27055, 0.30889, 0.34890, 0.39166, 0.43615, 0.48169, 0.52754, 0.57293, 0.61712, 0.65946, 0.69940, 0.73652, 0.77057, 0.80140, 0.82900, 0.85348, 0.87497, 0.89371, 0.89371, 0.89371, 0.89371, 0.89371, 0.89371, 0.89371, 0.89371, 0.89371, 0.89371, 0.89371 } },
{ 95, 360.0, 830.0, 1.0, { 0.03388, 0.03388, 0.03388, 0.03388, 0.03388, 0.03483, 0.03581, 0.03682, 0.03783, 0.03893, 0.04001, 0.04112, 0.04230, 0.04360, 0.04508, 0.04678, 0.04885, 0.05133, 0.05391, 0.05623, 0.05798, 0.05898, 0.05937, 0.05937, 0.05927, 0.05923, 0.05888, 0.05785, 0.05629, 0.05448, 0.05282, 0.05164, 0.05083, 0.05013, 0.04915, 0.04764, 0.04597, 0.04463, 0.04398, 0.04429, 0.04547, 0.04724, 0.04885, 0.04958, 0.04934, 0.04829, 0.04686, 0.04551, 0.04448, 0.04393, 0.04378, 0.04390, 0.04408, 0.04420, 0.04428, 0.04442, 0.04478, 0.04555, 0.04706, 0.04965, 0.05351, 0.05890, 0.06642, 0.07676, 0.09035, 0.10762, 0.12907, 0.15524, 0.18665, 0.22083, 0.26013, 0.30371, 0.35111, 0.40165, 0.45437, 0.50813, 0.56171, 0.61388, 0.66357, 0.70988, 0.75220, 0.79016, 0.82368, 0.85284, 0.87789, 0.87789, 0.87789, 0.87789, 0.87789, 0.87789, 0.87789, 0.87789, 0.87789, 0.87789, 0.87789 } },
{ 95, 360.0, 830.0, 1.0, { 0.02919, 0.02919, 0.02919, 0.02919, 0.02919, 0.03355, 0.03853, 0.04422, 0.05090, 0.05866, 0.06910, 0.07815, 0.08670, 0.09650, 0.10760, 0.11962, 0.13220, 0.14512, 0.15870, 0.17307, 0.18690, 0.19843, 0.20550, 0.20636, 0.20120, 0.19094, 0.17740, 0.16234, 0.14650, 0.13040, 0.11480, 0.10054, 0.08860, 0.07973, 0.07360, 0.06947, 0.06600, 0.06197, 0.05720, 0.05188, 0.04670, 0.04255, 0.04050, 0.04145, 0.04540, 0.05156, 0.05680, 0.05823, 0.05620, 0.05198, 0.04730, 0.04369, 0.04130, 0.03997, 0.03950, 0.03970, 0.04030, 0.04114, 0.04260, 0.04518, 0.04930, 0.05525, 0.06270, 0.07116, 0.08000, 0.08885, 0.09840, 0.10867, 0.11600, 0.12346, 0.13106, 0.13904, 0.14743, 0.15623, 0.16546, 0.17512, 0.18522, 0.19576, 0.20675, 0.21819, 0.23008, 0.24241, 0.25519, 0.26840, 0.28204, 0.28204, 0.28204, 0.28204, 0.28204, 0.28204, 0.28204, 0.28204, 0.28204, 0.28204, 0.28204 } },
{ 95, 360.0, 830.0, 1.0, { 0.21199, 0.21199, 0.21199, 0.21199, 0.21199, 0.22951, 0.24803, 0.26752, 0.28860, 0.31111, 0.33960, 0.36066, 0.37770, 0.39675, 0.41750, 0.43808, 0.45680, 0.47192, 0.48120, 0.48293, 0.47790, 0.46766, 0.45430, 0.43959, 0.42360, 0.40603, 0.38690, 0.36621, 0.34350, 0.31848, 0.29190, 0.26503, 0.24020, 0.21929, 0.20150, 0.18521, 0.16840, 0.14935, 0.12800, 0.10516, 0.08340, 0.06563, 0.05420, 0.05104, 0.05680, 0.07068, 0.08720, 0.10057, 0.10850, 0.11045, 0.10940, 0.10857, 0.10870, 0.10986, 0.11190, 0.11481, 0.11940, 0.12646, 0.13580, 0.14672, 0.15740, 0.16579, 0.17020, 0.16964, 0.16570, 0.15994, 0.15120, 0.13917, 0.12970, 0.12095, 0.11294, 0.10540, 0.09831, 0.09165, 0.08540, 0.07953, 0.07404, 0.06889, 0.06408, 0.05959, 0.05539, 0.05147, 0.04781, 0.04440, 0.04123, 0.04123, 0.04123, 0.04123, 0.04123, 0.04123, 0.04123, 0.04123, 0.04123, 0.04123, 0.04123 } },
{ 95, 360.0, 830.0, 1.0, { 0.02805, 0.02805, 0.02805, 0.02805, 0.02805, 0.03537, 0.05422, 0.07830, 0.10593, 0.13046, 0.15591, 0.18140, 0.20586, 0.22735, 0.24649, 0.26234, 0.27425, 0.28313, 0.29062, 0.29480, 0.29517, 0.29327, 0.28875, 0.28176, 0.27334, 0.26346, 0.25141, 0.23809, 0.22535, 0.21297, 0.20098, 0.18934, 0.17750, 0.16598, 0.15478, 0.14464, 0.13534, 0.12632, 0.11734, 0.10870, 0.10113, 0.09491, 0.08967, 0.08526, 0.08169, 0.07914, 0.07764, 0.07707, 0.07730, 0.07825, 0.08023, 0.08357, 0.08886, 0.09681, 0.10784, 0.12216, 0.13992, 0.16133, 0.18574, 0.21193, 0.23877, 0.26496, 0.28852, 0.30737, 0.32249, 0.33247, 0.33782, 0.33897, 0.33667, 0.33133, 0.32425, 0.31788, 0.31165, 0.30494, 0.29854, 0.29222, 0.28597, 0.27981, 0.27373, 0.26774, 0.26182, 0.25589, 0.25007, 0.24437, 0.23878, 0.23878, 0.23878, 0.23878, 0.23878, 0.23878, 0.23878, 0.23878, 0.23878, 0.23878, 0.23878 } },
{ 95, 360.0, 830.0, 1.0, { 0.12947, 0.12947, 0.12947, 0.12947, 0.12947, 0.14167, 0.15481, 0.16893, 0.18120, 0.20172, 0.21754, 0.23408, 0.25676, 0.28940, 0.32944, 0.37206, 0.40977, 0.43567, 0.44790, 0.44654, 0.43439, 0.41472, 0.39001, 0.36265, 0.33550, 0.31099, 0.28943, 0.27027, 0.25170, 0.23219, 0.21258, 0.19421, 0.17803, 0.16458, 0.15330, 0.14323, 0.13285, 0.12098, 0.10823, 0.09570, 0.08469, 0.07633, 0.07069, 0.06766, 0.06722, 0.06932, 0.07348, 0.07900, 0.08479, 0.08966, 0.09254, 0.09274, 0.09095, 0.08820, 0.08559, 0.08415, 0.08450, 0.08701, 0.09155, 0.09774, 0.10495, 0.11256, 0.12024, 0.12850, 0.14079, 0.16039, 0.18676, 0.21842, 0.25388, 0.29220, 0.33405, 0.37868, 0.42547, 0.47364, 0.52230, 0.57054, 0.61747, 0.66232, 0.70442, 0.74331, 0.77869, 0.81043, 0.83857, 0.86323, 0.88465, 0.88465, 0.88465, 0.88465, 0.88465, 0.88465, 0.88465, 0.88465, 0.88465, 0.88465, 0.88465 } },
{ 95, 360.0, 830.0, 1.0, { 0.56749, 0.56749, 0.56749, 0.56749, 0.56749, 0.57857, 0.58956, 0.60046, 0.60662, 0.62422, 0.63353, 0.63805, 0.64127, 0.64576, 0.65031, 0.65295, 0.65239, 0.64837, 0.64415, 0.64297, 0.64445, 0.64684, 0.64673, 0.64119, 0.63104, 0.61778, 0.60176, 0.58330, 0.56373, 0.54443, 0.52600, 0.50863, 0.49145, 0.47370, 0.45601, 0.43928, 0.42404, 0.41066, 0.39922, 0.38961, 0.38145, 0.37420, 0.36715, 0.35995, 0.35394, 0.35060, 0.35017, 0.35247, 0.35672, 0.36207, 0.36794, 0.37408, 0.38115, 0.39035, 0.40398, 0.42415, 0.45114, 0.48460, 0.52342, 0.56583, 0.60811, 0.64650, 0.67910, 0.70496, 0.72516, 0.74134, 0.75525, 0.76868, 0.78344, 0.79525, 0.80745, 0.81908, 0.83016, 0.84069, 0.85069, 0.86016, 0.86913, 0.87760, 0.88559, 0.89313, 0.90023, 0.90690, 0.91317, 0.91906, 0.92458, 0.92458, 0.92458, 0.92458, 0.92458, 0.92458, 0.92458, 0.92458, 0.92458, 0.92458, 0.92458 } },
{ 95, 360.0, 830.0, 1.0, { 0.31684, 0.31684, 0.31684, 0.31684, 0.31684, 0.34433, 0.36972, 0.39599, 0.42314, 0.45025, 0.47575, 0.49823, 0.51751, 0.53377, 0.54733, 0.55847, 0.56720, 0.57340, 0.57683, 0.57723, 0.57441, 0.56815, 0.55801, 0.54360, 0.52497, 0.50256, 0.47780, 0.45229, 0.42720, 0.40344, 0.38140, 0.36127, 0.34289, 0.32612, 0.31138, 0.29903, 0.28877, 0.28021, 0.27333, 0.26820, 0.26479, 0.26307, 0.26304, 0.26462, 0.26728, 0.27052, 0.27437, 0.27890, 0.28390, 0.28921, 0.29508, 0.30178, 0.30938, 0.31796, 0.32802, 0.34004, 0.35416, 0.37048, 0.38943, 0.41133, 0.43586, 0.46260, 0.49134, 0.52196, 0.55435, 0.58815, 0.62191, 0.65419, 0.68463, 0.71299, 0.73843, 0.76029, 0.77927, 0.79615, 0.81061, 0.82241, 0.83267, 0.84211, 0.84839, 0.84957, 0.84839, 0.84800, 0.84839, 0.84878, 0.84839, 0.84839, 0.84839, 0.84839, 0.84839, 0.84839, 0.84839, 0.84839, 0.84839, 0.84839, 0.84839 } },
{ 95, 360.0, 830.0, 1.0, { 0.12067, 0.12067, 0.12067, 0.12067, 0.12067, 0.17602, 0.23298, 0.27447, 0.30442, 0.32357, 0.33682, 0.34501, 0.34763, 0.35069, 0.35500, 0.35271, 0.34519, 0.33814, 0.33335, 0.32585, 0.31343, 0.30296, 0.29343, 0.27907, 0.26179, 0.24644, 0.23007, 0.21652, 0.20356, 0.18994, 0.17481, 0.15838, 0.14046, 0.12315, 0.11069, 0.10618, 0.10310, 0.09997, 0.09749, 0.09121, 0.08211, 0.07440, 0.06799, 0.06738, 0.07171, 0.08124, 0.09024, 0.09630, 0.10233, 0.10517, 0.10010, 0.09536, 0.09978, 0.11368, 0.13297, 0.16167, 0.19616, 0.23898, 0.29173, 0.34345, 0.37835, 0.40403, 0.42472, 0.43600, 0.44674, 0.45591, 0.46076, 0.46165, 0.46531, 0.47145, 0.47513, 0.47881, 0.48250, 0.48618, 0.48987, 0.49356, 0.49725, 0.50094, 0.50463, 0.50832, 0.51201, 0.51570, 0.51938, 0.52307, 0.52675, 0.52675, 0.52675, 0.52675, 0.52675, 0.52675, 0.52675, 0.52675, 0.52675, 0.52675, 0.52675 } },
{ 95, 360.0, 830.0, 1.0, { 0.70772, 0.70772, 0.70772, 0.70772, 0.70772, 0.71503, 0.72222, 0.72930, 0.73650, 0.74377, 0.75320, 0.76059, 0.76660, 0.77259, 0.77790, 0.78171, 0.78450, 0.78682, 0.78820, 0.78804, 0.78620, 0.78261, 0.77710, 0.76964, 0.76100, 0.75186, 0.74180, 0.73044, 0.71880, 0.70796, 0.69790, 0.68834, 0.67900, 0.66980, 0.66150, 0.65484, 0.64970, 0.64587, 0.64380, 0.64381, 0.64510, 0.64674, 0.64830, 0.64956, 0.65070, 0.65200, 0.65380, 0.65629, 0.65910, 0.66177, 0.66390, 0.66528, 0.66630, 0.66737, 0.66840, 0.66966, 0.67350, 0.68201, 0.69420, 0.70871, 0.72580, 0.74588, 0.76840, 0.79213, 0.81420, 0.83253, 0.84990, 0.86826, 0.88140, 0.89315, 0.90355, 0.91304, 0.92167, 0.92952, 0.93663, 0.94307, 0.94889, 0.95414, 0.95888, 0.96314, 0.96698, 0.97044, 0.97354, 0.97632, 0.97882, 0.97882, 0.97882, 0.97882, 0.97882, 0.97882, 0.97882, 0.97882, 0.97882, 0.97882, 0.97882 } },
{ 95, 360.0, 830.0, 1.0, { 0.56349, 0.56349, 0.56349, 0.56349, 0.56349, 0.57154, 0.57956, 0.58753, 0.59570, 0.60396, 0.61320, 0.61739, 0.61800, 0.61762, 0.61590, 0.61213, 0.60710, 0.60152, 0.59440, 0.58478, 0.57360, 0.56173, 0.54790, 0.53111, 0.51360, 0.49766, 0.48270, 0.46771, 0.45300, 0.43916, 0.42670, 0.41592, 0.40640, 0.39769, 0.39000, 0.38378, 0.37970, 0.37817, 0.37830, 0.37928, 0.38180, 0.38643, 0.39180, 0.39639, 0.40010, 0.40309, 0.40520, 0.40630, 0.40670, 0.40672, 0.40620, 0.40499, 0.40330, 0.40177, 0.40240, 0.40703, 0.41560, 0.42779, 0.44420, 0.46526, 0.48980, 0.51664, 0.54610, 0.57781, 0.60700, 0.63023, 0.65360, 0.68162, 0.70290, 0.72287, 0.74141, 0.75913, 0.77600, 0.79202, 0.80717, 0.82147, 0.83492, 0.84755, 0.85937, 0.87042, 0.88072, 0.89031, 0.89921, 0.90746, 0.91511, 0.91511, 0.91511, 0.91511, 0.91511, 0.91511, 0.91511, 0.91511, 0.91511, 0.91511, 0.91511 } },
{ 95, 360.0, 830.0, 1.0, { 0.03375, 0.03375, 0.03375, 0.03375, 0.03375, 0.03555, 0.03745, 0.03943, 0.04138, 0.04379, 0.04605, 0.04830, 0.05071, 0.05334, 0.05597, 0.05829, 0.06004, 0.06105, 0.06153, 0.06171, 0.06143, 0.06054, 0.05935, 0.05833, 0.05816, 0.05926, 0.06103, 0.06267, 0.06351, 0.06315, 0.06193, 0.06027, 0.05806, 0.05512, 0.05170, 0.04814, 0.04456, 0.04107, 0.03781, 0.03496, 0.03285, 0.03177, 0.03156, 0.03212, 0.03394, 0.03742, 0.04208, 0.04716, 0.05170, 0.05496, 0.05726, 0.05907, 0.06044, 0.06132, 0.06183, 0.06214, 0.06252, 0.06316, 0.06391, 0.06457, 0.06500, 0.06512, 0.06500, 0.06478, 0.06451, 0.06423, 0.06391, 0.06349, 0.06292, 0.06257, 0.06214, 0.06171, 0.06128, 0.06085, 0.06043, 0.06001, 0.05959, 0.05918, 0.05877, 0.05836, 0.05795, 0.05755, 0.05715, 0.05675, 0.05635, 0.05635, 0.05635, 0.05635, 0.05635, 0.05635, 0.05635, 0.05635, 0.05635, 0.05635, 0.05635 } },
{ 95, 360.0, 830.0, 1.0, { 0.01425, 0.01425, 0.01425, 0.01425, 0.01425, 0.01292, 0.01731, 0.02444, 0.03831, 0.04940, 0.06324, 0.07955, 0.09523, 0.11233, 0.13166, 0.14950, 0.15820, 0.16275, 0.17107, 0.17496, 0.17395, 0.17370, 0.17216, 0.16727, 0.16007, 0.15576, 0.14927, 0.14321, 0.13436, 0.12644, 0.12123, 0.11599, 0.11004, 0.10400, 0.09716, 0.09359, 0.09213, 0.09261, 0.09066, 0.08902, 0.08907, 0.08792, 0.08794, 0.08588, 0.08463, 0.08725, 0.09088, 0.09758, 0.10274, 0.10874, 0.10959, 0.11171, 0.11603, 0.12276, 0.12916, 0.13826, 0.14464, 0.15049, 0.16785, 0.19265, 0.20784, 0.22794, 0.25255, 0.26974, 0.28737, 0.30481, 0.31630, 0.32417, 0.33878, 0.34908, 0.36054, 0.37215, 0.38392, 0.39582, 0.40785, 0.41999, 0.43223, 0.44455, 0.45694, 0.46938, 0.48186, 0.49436, 0.50687, 0.51938, 0.53185, 0.53185, 0.53185, 0.53185, 0.53185, 0.53185, 0.53185, 0.53185, 0.53185, 0.53185, 0.53185 } },
{ 95, 360.0, 830.0, 1.0, { 0.50252, 0.50252, 0.50252, 0.50252, 0.50252, 0.51400, 0.52546, 0.53689, 0.54636, 0.56056, 0.57138, 0.57981, 0.58686, 0.59284, 0.59520, 0.59176, 0.58448, 0.57575, 0.56542, 0.55287, 0.53821, 0.52174, 0.50366, 0.48437, 0.46484, 0.44597, 0.42761, 0.40934, 0.39068, 0.37145, 0.35265, 0.33549, 0.32078, 0.30890, 0.29884, 0.28927, 0.27879, 0.26664, 0.25456, 0.24483, 0.23947, 0.23969, 0.24364, 0.24875, 0.25258, 0.25331, 0.25139, 0.24833, 0.24771, 0.25339, 0.26836, 0.29491, 0.33339, 0.38325, 0.44221, 0.50670, 0.56969, 0.62438, 0.66837, 0.70087, 0.72318, 0.73733, 0.74601, 0.75185, 0.75644, 0.76102, 0.76637, 0.77313, 0.78195, 0.78747, 0.79409, 0.80056, 0.80687, 0.81303, 0.81904, 0.82490, 0.83060, 0.83616, 0.84157, 0.84683, 0.85195, 0.85693, 0.86177, 0.86647, 0.87103, 0.87103, 0.87103, 0.87103, 0.87103, 0.87103, 0.87103, 0.87103, 0.87103, 0.87103, 0.87103 } },
{ 95, 360.0, 830.0, 1.0, { 0.10613, 0.10613, 0.10613, 0.10613, 0.10613, 0.11586, 0.12635, 0.13764, 0.14596, 0.16476, 0.17753, 0.18653, 0.19401, 0.20193, 0.21099, 0.22114, 0.23055, 0.23700, 0.23849, 0.23384, 0.22469, 0.21322, 0.20076, 0.18829, 0.17614, 0.16448, 0.15340, 0.14290, 0.13255, 0.12197, 0.11120, 0.10054, 0.09085, 0.08296, 0.07705, 0.07288, 0.06921, 0.06482, 0.05957, 0.05375, 0.04826, 0.04403, 0.04140, 0.04111, 0.04617, 0.05927, 0.07933, 0.10352, 0.12550, 0.13984, 0.14804, 0.15301, 0.15638, 0.15927, 0.16204, 0.16492, 0.16820, 0.17215, 0.17684, 0.18200, 0.18627, 0.18830, 0.18796, 0.18571, 0.18319, 0.18185, 0.18120, 0.18026, 0.17803, 0.17751, 0.17632, 0.17513, 0.17395, 0.17278, 0.17161, 0.17045, 0.16929, 0.16814, 0.16700, 0.16586, 0.16473, 0.16361, 0.16249, 0.16138, 0.16027, 0.16027, 0.16027, 0.16027, 0.16027, 0.16027, 0.16027, 0.16027, 0.16027, 0.16027, 0.16027 } },
{ 95, 360.0, 830.0, 1.0, { 0.42640, 0.42640, 0.42640, 0.42640, 0.42640, 0.44033, 0.45435, 0.46845, 0.47490, 0.50054, 0.51283, 0.51584, 0.51363, 0.50938, 0.50280, 0.49313, 0.48116, 0.46804, 0.45465, 0.44164, 0.42903, 0.41662, 0.40401, 0.39068, 0.37591, 0.35912, 0.34056, 0.32103, 0.30254, 0.28662, 0.27176, 0.25598, 0.23869, 0.22042, 0.20493, 0.19580, 0.19252, 0.19315, 0.19401, 0.19190, 0.18706, 0.18151, 0.18071, 0.18983, 0.20940, 0.23795, 0.27076, 0.30302, 0.33272, 0.35883, 0.38147, 0.40076, 0.41563, 0.42508, 0.42953, 0.42990, 0.42774, 0.42497, 0.42427, 0.42833, 0.43926, 0.45877, 0.48761, 0.52562, 0.56992, 0.61695, 0.66286, 0.70375, 0.73574, 0.77275, 0.80334, 0.83071, 0.85496, 0.87625, 0.89481, 0.91086, 0.92467, 0.93649, 0.94656, 0.95511, 0.96235, 0.96846, 0.97360, 0.97793, 0.98156, 0.98156, 0.98156, 0.98156, 0.98156, 0.98156, 0.98156, 0.98156, 0.98156, 0.98156, 0.98156 } },
{ 95, 360.0, 830.0, 1.0, { 0.07275, 0.07275, 0.07275, 0.07275, 0.07275, 0.08208, 0.09249, 0.10408, 0.11546, 0.13191, 0.14757, 0.16011, 0.16724, 0.16828, 0.16927, 0.17537, 0.18160, 0.18230, 0.17906, 0.17458, 0.16856, 0.16017, 0.14940, 0.13679, 0.12423, 0.11336, 0.10344, 0.09358, 0.08459, 0.07741, 0.07195, 0.06776, 0.06420, 0.06078, 0.05768, 0.05526, 0.05381, 0.05358, 0.05483, 0.05763, 0.06145, 0.06564, 0.06961, 0.07304, 0.07664, 0.08120, 0.08693, 0.09386, 0.10181, 0.11045, 0.11913, 0.12714, 0.13391, 0.13922, 0.14390, 0.14909, 0.15603, 0.16583, 0.17906, 0.19607, 0.21697, 0.24170, 0.26986, 0.30107, 0.33549, 0.37309, 0.41253, 0.45219, 0.49039, 0.53155, 0.57117, 0.60989, 0.64728, 0.68294, 0.71658, 0.74797, 0.77696, 0.80350, 0.82757, 0.84925, 0.86864, 0.88587, 0.90110, 0.91449, 0.92621, 0.92621, 0.92621, 0.92621, 0.92621, 0.92621, 0.92621, 0.92621, 0.92621, 0.92621, 0.92621 } },
{ 95, 360.0, 830.0, 1.0, { 0.22178, 0.22178, 0.22178, 0.22178, 0.22178, 0.23127, 0.24103, 0.25108, 0.26170, 0.27271, 0.28380, 0.28598, 0.28220, 0.27711, 0.27030, 0.26063, 0.24900, 0.23663, 0.22390, 0.21107, 0.19870, 0.18718, 0.17590, 0.16417, 0.15200, 0.13979, 0.12870, 0.11977, 0.11260, 0.10642, 0.10020, 0.09321, 0.08600, 0.07945, 0.07430, 0.07114, 0.06990, 0.07019, 0.07090, 0.07109, 0.07110, 0.07175, 0.07450, 0.08084, 0.09190, 0.10811, 0.12760, 0.14791, 0.16650, 0.18130, 0.19230, 0.20011, 0.20570, 0.20999, 0.21340, 0.21626, 0.21890, 0.22164, 0.22460, 0.22768, 0.23010, 0.23137, 0.23290, 0.23606, 0.24010, 0.24393, 0.24720, 0.24973, 0.25120, 0.25261, 0.25397, 0.25533, 0.25670, 0.25807, 0.25945, 0.26083, 0.26222, 0.26362, 0.26501, 0.26642, 0.26782, 0.26923, 0.27065, 0.27207, 0.27350, 0.27350, 0.27350, 0.27350, 0.27350, 0.27350, 0.27350, 0.27350, 0.27350, 0.27350, 0.27350 } },
{ 95, 360.0, 830.0, 1.0, { 0.02966, 0.02966, 0.02966, 0.02966, 0.02966, 0.03379, 0.04777, 0.07917, 0.13075, 0.17691, 0.22905, 0.28446, 0.34279, 0.40110, 0.45479, 0.50150, 0.53963, 0.56762, 0.58708, 0.60061, 0.60850, 0.61064, 0.60879, 0.60406, 0.59734, 0.59009, 0.58275, 0.57511, 0.56692, 0.55949, 0.55297, 0.54597, 0.53793, 0.52943, 0.52207, 0.51669, 0.51244, 0.50807, 0.50371, 0.50097, 0.50109, 0.50342, 0.50601, 0.50809, 0.51072, 0.51513, 0.52154, 0.52925, 0.53705, 0.54511, 0.55458, 0.56537, 0.57661, 0.58749, 0.59586, 0.60146, 0.60694, 0.61324, 0.61886, 0.62331, 0.62790, 0.63150, 0.63258, 0.63234, 0.63235, 0.62884, 0.62321, 0.61633, 0.60749, 0.59715, 0.58830, 0.58146, 0.57354, 0.56538, 0.55745, 0.54949, 0.54151, 0.53350, 0.52548, 0.51744, 0.50940, 0.50135, 0.49329, 0.48523, 0.47718, 0.47718, 0.47718, 0.47718, 0.47718, 0.47718, 0.47718, 0.47718, 0.47718, 0.47718, 0.47718 } },
{ 95, 360.0, 830.0, 1.0, { 0.00526, 0.00526, 0.00526, 0.00526, 0.00526, 0.02448, 0.05165, 0.07373, 0.09670, 0.12048, 0.14705, 0.17355, 0.19903, 0.22337, 0.24497, 0.26321, 0.27932, 0.29203, 0.29990, 0.30270, 0.30154, 0.29826, 0.29386, 0.28892, 0.28247, 0.27445, 0.26514, 0.25488, 0.24532, 0.23679, 0.22756, 0.21696, 0.20634, 0.19676, 0.18816, 0.18045, 0.17340, 0.16725, 0.16263, 0.16000, 0.15893, 0.15868, 0.15918, 0.16048, 0.16283, 0.16661, 0.17222, 0.18041, 0.19233, 0.20953, 0.23350, 0.26384, 0.29850, 0.33518, 0.37373, 0.41399, 0.45456, 0.49236, 0.52439, 0.55001, 0.57049, 0.58799, 0.60570, 0.62287, 0.63523, 0.64717, 0.65931, 0.67212, 0.68575, 0.70060, 0.71303, 0.72275, 0.73370, 0.74439, 0.75455, 0.76442, 0.77403, 0.78335, 0.79239, 0.80115, 0.80963, 0.81816, 0.82632, 0.83411, 0.84154, 0.84154, 0.84154, 0.84154, 0.84154, 0.84154, 0.84154, 0.84154, 0.84154, 0.84154, 0.84154 } },
{ 95, 360.0, 830.0, 1.0, { 0.23077, 0.23077, 0.23077, 0.23077, 0.23077, 0.24352, 0.25636, 0.26920, 0.28195, 0.29460, 0.30754, 0.32130, 0.33662, 0.35357, 0.36925, 0.38105, 0.39054, 0.39975, 0.40839, 0.41539, 0.41877, 0.41719, 0.41283, 0.40771, 0.39971, 0.38682, 0.37157, 0.35700, 0.34356, 0.33108, 0.31952, 0.30897, 0.30003, 0.29316, 0.28788, 0.28365, 0.28066, 0.27914, 0.27880, 0.27935, 0.28107, 0.28419, 0.28827, 0.29295, 0.29889, 0.30683, 0.31670, 0.32832, 0.34189, 0.35764, 0.37558, 0.39567, 0.41783, 0.44204, 0.46840, 0.49679, 0.52606, 0.55502, 0.58337, 0.61088, 0.63663, 0.65968, 0.67984, 0.69709, 0.71148, 0.72321, 0.73309, 0.74189, 0.74957, 0.75581, 0.76013, 0.76226, 0.76306, 0.76369, 0.76530, 0.76570, 0.76658, 0.76746, 0.76833, 0.76920, 0.77007, 0.77094, 0.77181, 0.77267, 0.77353, 0.77353, 0.77353, 0.77353, 0.77353, 0.77353, 0.77353, 0.77353, 0.77353, 0.77353, 0.77353 } },
{ 95, 360.0, 830.0, 1.0, { 0.06102, 0.06102, 0.06102, 0.06102, 0.06102, 0.06701, 0.07354, 0.08065, 0.08810, 0.09694, 0.10607, 0.11496, 0.12312, 0.13016, 0.13629, 0.14162, 0.14547, 0.14718, 0.14700, 0.14528, 0.14180, 0.13637, 0.12955, 0.12194, 0.11362, 0.10476, 0.09637, 0.08937, 0.08341, 0.07795, 0.07299, 0.06865, 0.06493, 0.06185, 0.05952, 0.05800, 0.05727, 0.05727, 0.05788, 0.05896, 0.06033, 0.06187, 0.06370, 0.06599, 0.06891, 0.07264, 0.07748, 0.08381, 0.09218, 0.10311, 0.11679, 0.13341, 0.15364, 0.17791, 0.20530, 0.23477, 0.26624, 0.29975, 0.33484, 0.37096, 0.40773, 0.44475, 0.48134, 0.51686, 0.55127, 0.58455, 0.61630, 0.64600, 0.67316, 0.70121, 0.72707, 0.75148, 0.77439, 0.79576, 0.81558, 0.83389, 0.85071, 0.86610, 0.88012, 0.89286, 0.90440, 0.91481, 0.92418, 0.93259, 0.94014, 0.94014, 0.94014, 0.94014, 0.94014, 0.94014, 0.94014, 0.94014, 0.94014, 0.94014, 0.94014 } },
{ 95, 360.0, 830.0, 1.0, { 0.07372, 0.07372, 0.07372, 0.07372, 0.07372, 0.09065, 0.11100, 0.13525, 0.16428, 0.19678, 0.23541, 0.27695, 0.31816, 0.35643, 0.39144, 0.42267, 0.44627, 0.45905, 0.46390, 0.46464, 0.46288, 0.45926, 0.45279, 0.44269, 0.43067, 0.41862, 0.40662, 0.39437, 0.38166, 0.36832, 0.35445, 0.34032, 0.32703, 0.31562, 0.30624, 0.29880, 0.29299, 0.28848, 0.28494, 0.28227, 0.28117, 0.28238, 0.28596, 0.29206, 0.30186, 0.31662, 0.33692, 0.36293, 0.39399, 0.42915, 0.46746, 0.50750, 0.54614, 0.58068, 0.61187, 0.64119, 0.66965, 0.69796, 0.72611, 0.75367, 0.77900, 0.80048, 0.81742, 0.82988, 0.83974, 0.84881, 0.85666, 0.86235, 0.86492, 0.87151, 0.87627, 0.88089, 0.88535, 0.88966, 0.89384, 0.89787, 0.90177, 0.90553, 0.90917, 0.91267, 0.91606, 0.91932, 0.92247, 0.92551, 0.92844, 0.92844, 0.92844, 0.92844, 0.92844, 0.92844, 0.92844, 0.92844, 0.92844, 0.92844, 0.92844 } },
{ 95, 360.0, 830.0, 1.0, { 0.33851, 0.33851, 0.33851, 0.33851, 0.33851, 0.36145, 0.38504, 0.40918, 0.43394, 0.45859, 0.48408, 0.50808, 0.52830, 0.54340, 0.55592, 0.56810, 0.57702, 0.57960, 0.57732, 0.57245, 0.56571, 0.55731, 0.54695, 0.53443, 0.52046, 0.50593, 0.49141, 0.47729, 0.46359, 0.45025, 0.43720, 0.42459, 0.41355, 0.40517, 0.39949, 0.39625, 0.39511, 0.39575, 0.39816, 0.40244, 0.40897, 0.41800, 0.42915, 0.44206, 0.45737, 0.47574, 0.49692, 0.52053, 0.54655, 0.57500, 0.60596, 0.63909, 0.67241, 0.70387, 0.73294, 0.75943, 0.78318, 0.80405, 0.82201, 0.83704, 0.84892, 0.85751, 0.86339, 0.86749, 0.87174, 0.87761, 0.88387, 0.88860, 0.88988, 0.89554, 0.89928, 0.90290, 0.90640, 0.90979, 0.91307, 0.91624, 0.91930, 0.92226, 0.92513, 0.92789, 0.93056, 0.93314, 0.93563, 0.93803, 0.94035, 0.94035, 0.94035, 0.94035, 0.94035, 0.94035, 0.94035, 0.94035, 0.94035, 0.94035, 0.94035 } },
{ 95, 360.0, 830.0, 1.0, { 0.11931, 0.11931, 0.11931, 0.11931, 0.11931, 0.13183, 0.14544, 0.16019, 0.17660, 0.19451, 0.21470, 0.22438, 0.22750, 0.23063, 0.23420, 0.23707, 0.23810, 0.23625, 0.23090, 0.22182, 0.20980, 0.19595, 0.18170, 0.16814, 0.15480, 0.14093, 0.12640, 0.11163, 0.09880, 0.08993, 0.08480, 0.08234, 0.08030, 0.07659, 0.07100, 0.06414, 0.05820, 0.05623, 0.06330, 0.08396, 0.11870, 0.16498, 0.21210, 0.24927, 0.27350, 0.28466, 0.28610, 0.28181, 0.27470, 0.26721, 0.26090, 0.25685, 0.25500, 0.25496, 0.25620, 0.25835, 0.26200, 0.26778, 0.27570, 0.28525, 0.29450, 0.30142, 0.30490, 0.30450, 0.30140, 0.29673, 0.28970, 0.28021, 0.27280, 0.26568, 0.25889, 0.25222, 0.24566, 0.23922, 0.23290, 0.22669, 0.22060, 0.21463, 0.20878, 0.20305, 0.19743, 0.19193, 0.18655, 0.18129, 0.17614, 0.17614, 0.17614, 0.17614, 0.17614, 0.17614, 0.17614, 0.17614, 0.17614, 0.17614, 0.17614 } },
{ 95, 360.0, 830.0, 1.0, { 0.27425, 0.27425, 0.27425, 0.27425, 0.27425, 0.28297, 0.29185, 0.30090, 0.31040, 0.32028, 0.33277, 0.34184, 0.34836, 0.35424, 0.35855, 0.35975, 0.35650, 0.34789, 0.33440, 0.31699, 0.29728, 0.27687, 0.25673, 0.23768, 0.22049, 0.20561, 0.19230, 0.17970, 0.16765, 0.15642, 0.14727, 0.14136, 0.13849, 0.13788, 0.13781, 0.13679, 0.13518, 0.13405, 0.13543, 0.14163, 0.15519, 0.17835, 0.21210, 0.25629, 0.30765, 0.36205, 0.41520, 0.46276, 0.50047, 0.52541, 0.54006, 0.54796, 0.55154, 0.55303, 0.55484, 0.55912, 0.56677, 0.57838, 0.59454, 0.61548, 0.63996, 0.66655, 0.69439, 0.72255, 0.74925, 0.77306, 0.79489, 0.81494, 0.82814, 0.84022, 0.85125, 0.86163, 0.87141, 0.88058, 0.88919, 0.89725, 0.90478, 0.91182, 0.91838, 0.92450, 0.93019, 0.93548, 0.94040, 0.94496, 0.94920, 0.94920, 0.94920, 0.94920, 0.94920, 0.94920, 0.94920, 0.94920, 0.94920, 0.94920, 0.94920 } },
{ 95, 360.0, 830.0, 1.0, { 0.16958, 0.16958, 0.16958, 0.16958, 0.16958, 0.17882, 0.18846, 0.19848, 0.20920, 0.22044, 0.23190, 0.23457, 0.23160, 0.22794, 0.22340, 0.21695, 0.20920, 0.20100, 0.19260, 0.18414, 0.17580, 0.16773, 0.15980, 0.15183, 0.14380, 0.13581, 0.12840, 0.12204, 0.11650, 0.11137, 0.10610, 0.10032, 0.09440, 0.08894, 0.08470, 0.08227, 0.08150, 0.08193, 0.08270, 0.08309, 0.08340, 0.08441, 0.08770, 0.09508, 0.10830, 0.12914, 0.15950, 0.20020, 0.24750, 0.29719, 0.34770, 0.39782, 0.44510, 0.48712, 0.52280, 0.55159, 0.57370, 0.58975, 0.60130, 0.60992, 0.61620, 0.62057, 0.62380, 0.62656, 0.62880, 0.63041, 0.63170, 0.63294, 0.63380, 0.63463, 0.63542, 0.63622, 0.63702, 0.63782, 0.63861, 0.63941, 0.64020, 0.64099, 0.64179, 0.64258, 0.64337, 0.64416, 0.64495, 0.64574, 0.64652, 0.64652, 0.64652, 0.64652, 0.64652, 0.64652, 0.64652, 0.64652, 0.64652, 0.64652, 0.64652 } }
};
#endif /* !STANDALONE_TEST */

View File

@@ -0,0 +1,89 @@
#ifndef TM3015_H
#define TM3015_H
/*
* Author: Graeme W. Gill
* Date: 4/1/19
* Version: 1.00
*
* Copyright 2019 Graeme W. Gill
* All rights reserved.
*
* This material is licenced under the GNU GENERAL PUBLIC LICENSE Version 2 or later :-
* see the License2.txt file for licencing details.
*/
/*
* These functions compute IES TM-30-15,
* "IES Method for Evaluating Light Source Color Rendition"
*/
/*
* TTBD:
*
*/
#ifdef __cplusplus
extern "C" {
#endif
#define IES_TM_30_15_BINS 16
#define IES_TM_30_15_ESAMPLES 99
/* Compute the EBU TLCI-2012 Rf & Rg */
/* Return 1 on invalid, 2 on error */
/* Invalid is when sample is not white enough. */
int icx_IES_TM_30_15(
double *pRf, /* Return Rf */
double *pRg, /* Return Rg */
double *pcct, /* Return correlated color temperature */
double *pdc, /* Return signed Du'v' to locus */
double pbins[IES_TM_30_15_BINS][2][3], /* If not NULL, return ref & tsamp Jab */
xspect *tsamp /* Illuminant sample to compute TLCI of */
);
#ifdef __cplusplus
}
#endif
#endif /* TM3015_H */

View File

@@ -0,0 +1,342 @@
/*
* Check various aspects of RGB or CMYK device link,
* and RGB/CMYK profile transfer characteristics.
*
* Author: Graeme W. Gill
* Date: 2003/9/7
* Version: 1.0
*
* Copyright 2000 - 2003 Graeme W. Gill
* Please refer to License.txt file for details.
*/
/* TTBD:
*
* Make general device input, not just CMYK
*
* Allow specifying a vector in the range space.
*
*/
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <fcntl.h>
#include <string.h>
#include <math.h>
#include "aconfig.h"
#include "icc.h"
#include "numlib.h"
#include "plot.h"
#include "ui.h"
void usage(void) {
fprintf(stderr,"Check CMYK/RGB/PCS->PCS/CMYK/RGB transfer response\n");
fprintf(stderr,"Author: Graeme W. Gill\n");
fprintf(stderr,"usage: transplot [-v] infile\n");
fprintf(stderr," -v verbose\n");
fprintf(stderr," -i intent p = perceptual, r = relative colorimetric,\n");
fprintf(stderr," s = saturation, a = absolute\n");
fprintf(stderr," -o order n = normal (priority: lut > matrix > monochrome)\n");
fprintf(stderr," r = reverse (priority: monochrome > matrix > lut)\n");
fprintf(stderr," -c -m -y -k Check Cyan and/or Magenta and/or Yellow and/or Black input\n");
fprintf(stderr," -r -g -b Check Red and/or Green and/or Blue input\n");
fprintf(stderr," -L -A -B Check L and/or a* and/or b* input\n");
exit(1);
}
#define XRES 256
//#define XRES 11
int
main(
int argc,
char *argv[]
) {
int fa,nfa; /* argument we're looking at */
int verb = 0;
int chans[4] = { 0, 0, 0, 0 }; /* Flags indicating which channels to plot against */
static char in_name[MAXNAMEL+1];
icmFile *rd_fp;
icc *rd_icco; /* Keep object separate */
icmErr err = { 0, { '\000'} };
int rv = 0;
/* Lookup parameters */
icRenderingIntent intent = icmDefaultIntent; /* Default */
icmLookupOrder order = icmLuOrdNorm; /* Default */
/* Check variables */
icmLuSpace *luo;
icColorSpaceSignature ins, outs; /* Type of input and output spaces */
int inn; /* Number of input chanels */
int labin = 0; /* Flag */
int rgbin = 0; /* Flag */
int labout = 0; /* Flag */
int rgbout = 0; /* Flag */
error_program = argv[0];
if (argc < 2)
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 */
}
}
}
/* Verbosity */
if (argv[fa][1] == 'v' || argv[fa][1] == 'V') {
verb = 1;
}
/* Intent */
else if (argv[fa][1] == 'i' || argv[fa][1] == 'I') {
fa = nfa;
if (na == NULL) usage();
switch (na[0]) {
case 'p':
intent = icPerceptual;
break;
case 'r':
intent = icRelativeColorimetric;
break;
case 's':
intent = icSaturation;
break;
case 'a':
intent = icAbsoluteColorimetric;
break;
/* Special function icclib intents */
case 'P':
intent = icmAbsolutePerceptual;
break;
case 'S':
intent = icmAbsoluteSaturation;
break;
default:
usage();
}
}
/* Search order */
else if (argv[fa][1] == 'o' || argv[fa][1] == 'O') {
fa = nfa;
if (na == NULL) usage();
switch (na[0]) {
case 'n':
order = icmLuOrdNorm;
break;
case 'r':
order = icmLuOrdRev;
break;
default:
usage();
}
}
/* Cyan, Red */
else if (argv[fa][1] == 'c' || argv[fa][1] == 'C'
|| argv[fa][1] == 'r' || argv[fa][1] == 'R') {
chans[0] = 1;
}
/* Magenta, Green, a* */
else if (argv[fa][1] == 'm' || argv[fa][1] == 'M'
|| argv[fa][1] == 'g' || argv[fa][1] == 'G') {
chans[1] = 1;
}
/* Yellow, Blue, b* */
else if (argv[fa][1] == 'y' || argv[fa][1] == 'Y'
|| argv[fa][1] == 'b') {
chans[2] = 1;
}
/* L* */
else if (argv[fa][1] == 'L') {
chans[0] = 1;
labin = 1;
}
/* a* */
else if (argv[fa][1] == 'A') {
chans[1] = 1;
labin = 1;
}
/* Yellow, Blue, b* */
else if (argv[fa][1] == 'B') {
chans[2] = 1;
labin = 1;
}
/* Black */
else if (argv[fa][1] == 'k' || argv[fa][1] == 'K') {
chans[3] = 1;
}
else if (argv[fa][1] == '?')
usage();
else
usage();
}
else
break;
}
if (fa >= argc || argv[fa][0] == '-') usage();
strncpy(in_name,argv[fa++],MAXNAMEL); in_name[MAXNAMEL] = '\000';
/* Open up the file for reading */
if ((rd_fp = new_icmFileStd_name(&err, in_name,"r")) == NULL)
error ("Read: Can't open file '%s' (0x%x, '%s')",in_name, err.c,err.m);
if ((rd_icco = new_icc(&err)) == NULL)
error ("Read: Creation of ICC object failed (0x%x, '%s')", err.c,err.m);
/* Read the header and tag list */
if ((rv = rd_icco->read(rd_icco,rd_fp,0)) != 0)
error ("Read: %d, %s",rv,rd_icco->e.m);
if (labin) {
/* Get a Device to PCS conversion object */
if ((luo = (icmLuSpace *)rd_icco->get_luobj(rd_icco, icmBwd, intent, icSigLabData, order)) == NULL)
error ("%d, %s",rd_icco->e.c, rd_icco->e.m);
} else {
/* Get a PCS to Device conversion object */
if ((luo = (icmLuSpace *)rd_icco->get_luobj(rd_icco, icmFwd, intent, icSigLabData, order)) == NULL) {
if ((luo = (icmLuSpace *)rd_icco->get_luobj(rd_icco, icmFwd, intent, icmSigDefaultData, order)) == NULL) {
error ("%d, %s",rd_icco->e.c, rd_icco->e.m);
}
}
}
/* Get details of conversion */
{
icmCSInfo ini, outi;
luo->spaces(luo, &ini, &outi, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
ins = ini.sig;
inn = ini.nch;
outs = outi.sig;
}
if (labin) {
chans[3] = 0;
if (outs != icSigCmykData && outs != icSigRgbData) {
error("Expecting CMYK or RGB output space");
}
if (outs == icSigRgbData) {
rgbout = 1;
}
} else {
if (ins != icSigCmykData && ins != icSigRgbData) {
error("Expecting CMYK or RGB input space");
}
if (ins == icSigRgbData) {
rgbin = 1;
chans[3] = 0;
}
if (outs != icSigCmykData && outs != icSigLabData && outs != icSigRgbData) {
error("Expecting Lab or CMYK or RGB output space");
}
if (outs == icSigLabData)
labout = 1;
}
{
int i, j;
double xx[XRES];
double y0[XRES];
double y1[XRES];
double y2[XRES];
double y3[XRES];
for (i = 0; i < XRES; i++) {
double ival = (double)i/(XRES-1.0);
double in[4];
double out[4];
for (j = 0; j < 4; j++)
in[j] = 0.0;
if (labin) {
in[0] = 0.5;
in[1] = 0.5;
in[2] = 0.5;
}
if (chans[0])
in[0] = ival;
if (chans[1])
in[1] = ival;
if (chans[2])
in[2] = ival;
if (chans[3])
in[3] = ival;
if (labin) {
in[0] = in[0] * 100.0;
in[1] = (in[1] - 0.5) * 254.0;
in[2] = (in[2] - 0.5) * 254.0;
}
/* Do the conversion */
if ((rv = luo->lookup_fwd(luo, out, in)) & icmPe_lurv_err)
error ("%d, %s",rd_icco->e.c,rd_icco->e.m);
if (labout) {
//printf("~1 in %f %f %f %f, out %f %f %f\n",in[0],in[1],in[2],in[3],out[0],out[1],out[2]);
xx[i] = ival;
y0[i] = out[0]/1.0;
y1[i] = 50.0 + out[1]/2.0;
y2[i] = 50.0 + out[2]/2.0;
if (y1[i] < 0.0)
y1[i] = 0.0;
if (y1[i] > 100.0)
y1[i] = 100.0;
if (y2[i] < 0.0)
y2[i] = 0.0;
if (y2[i] > 100.0)
y2[i] = 100.0;
} else {
xx[i] = ival;
y0[i] = out[0];
y1[i] = out[1];
y2[i] = out[2];
y3[i] = out[3];
}
}
if (labout)
do_plot6(xx,y0,y1,NULL,NULL,y2,NULL,XRES);
else {
if (outs == icSigCmykData)
do_plot6(xx,y3,y1,NULL,y0,y2,NULL,XRES);
else /* Assume RGB */
do_plot6(xx,NULL,y0,y1,y2,NULL,NULL,XRES);
}
}
/* Done with lookup object */
luo->del(luo);
rd_icco->del(rd_icco);
rd_fp->del(rd_fp);
return 0;
}

734
Argyll_V3.5.0/xicc/xcal.c Normal file
View File

@@ -0,0 +1,734 @@
/*
* Calibration curve class.
*/
/*
*
* Argyll Color Management System
* Author: Graeme W. Gill
* Date: 30/10/2005
*
* Copyright 2005 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.
*
* This class allows reading and using a calibration file.
* Creation is currently left up to specialized programs (dispcal, printcal).
* This class doesn't handle the extra table that dispcal creates/uses.
*
*/
#undef DEBUG
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <math.h>
#include <sys/types.h>
#include <time.h>
#include <string.h>
#ifndef SALONEINSTLIB
#include "copyright.h"
#include "aconfig.h"
#include "numlib.h"
#include "plot.h"
#include "conv.h"
#include "xicc.h"
#else
#include "sa_config.h"
#include "numsup.h"
#include "rspl1.h"
#include "cgats.h"
#include "sa_conv.h"
#include "xcolorants.h"
#include "xcal.h"
#endif /* SALONEINSTLIB */
#ifdef NT /* You'd think there might be some standards.... */
# ifndef __BORLANDC__
# define stricmp _stricmp
# endif
#else
# define stricmp strcasecmp
#endif
/* rspl setting functions */
static void xcal_rsplset(void *cbntx, double *out, double *in) {
co *dpoints = (co *)cbntx;
int ix;
ix = *((int*)&in[-0-1]); /* Get grid index being looked up */
out[0] = dpoints[ix].v[0];
}
/* Read a calibration file from a cgats table */
/* "filename" is just for diagnostics */
/* Return nz if this fails */
static int xcal_read_cgats(xcal *p, cgats *tcg, int table, char *filename) {
int oi;
int i, j, ti;
char *ident;
char *bident;
int spi[1+MAX_CHAN]; /* CGATS indexes for each field */
char *ftname = "Calibration";
char buf[100];
oi = tcg->get_oi(tcg, "CAL");
if (oi < 0) {
sprintf(p->e.m, "Input file '%s' isn't a CAL format file", filename);
return p->e.c = 1;
}
if (tcg->t[table].tt != tt_other || tcg->t[table].oi != oi) {
sprintf(p->e.m, "Input file '%s' isn't a CAL format file", filename);
return p->e.c = 1;
}
/* Grab general information from it */
if ((ti = tcg->find_kword(tcg, table, "DESCRIPTOR")) >= 0) {
if ((p->descriptor = strdup(tcg->t[table].kdata[ti])) == NULL) {
sprintf(p->e.m, "%s file '%s' strdup of DESCRIPTOR failed",ftname,filename);
return p->e.c = 1;
}
}
if ((ti = tcg->find_kword(tcg, table, "ORIGINATOR")) >= 0) {
if ((p->originator = strdup(tcg->t[table].kdata[ti])) == NULL) {
sprintf(p->e.m, "%s file '%s' strdup of ORIGINATOR failed",ftname,filename);
return p->e.c = 1;
}
}
/* See what sort of device type this calibration is for */
if ((ti = tcg->find_kword(tcg, table, "DEVICE_CLASS")) < 0) {
sprintf(p->e.m, "%s file '%s' doesn't contain keyword DEVICE_CLASS",ftname,filename);
return p->e.c = 1;
}
if (strcmp(tcg->t[table].kdata[ti],"INPUT") == 0) {
p->devclass = icSigInputClass;
} else if (strcmp(tcg->t[table].kdata[ti],"OUTPUT") == 0) {
p->devclass = icSigOutputClass;
} else if (strcmp(tcg->t[table].kdata[ti],"DISPLAY") == 0) {
p->devclass = icSigDisplayClass;
} else {
sprintf(p->e.m,"%s file '%s' contain unknown DEVICE_CLASS '%s'",
ftname,filename,tcg->t[table].kdata[ti]);
return p->e.c = 1;
}
if ((ti = tcg->find_kword(tcg, table, "COLOR_REP")) < 0) {
/* Be backwards compatible with V1.0.4 display calibration files */
if (p->devclass != icSigDisplayClass) {
sprintf(p->e.m, "%s file '%s' doesn't contain keyword COLOR_REP",ftname,filename);
return p->e.c = 1;
}
warning("\n *** %s file '%s' doesn't contain keyword COLOR_REP, assuming RGB ***",ftname,filename);
if ((p->devmask = icx_char2inkmask("RGB") ) == 0) {
sprintf(p->e.m, "%s file '%s' has unrecognized COLOR_REP '%s'",
ftname,filename,tcg->t[table].kdata[ti]);
return p->e.c = 1;
}
} else {
if ((p->devmask = icx_char2inkmask(tcg->t[table].kdata[ti]) ) == 0) {
sprintf(p->e.m, "%s file '%s' has unrecognized COLOR_REP '%s'",
ftname,filename,tcg->t[table].kdata[ti]);
return p->e.c = 1;
}
}
if ((ti = tcg->find_kword(tcg, table, "VIDEO_LUT_CALIBRATION_POSSIBLE")) >= 0) {
if (stricmp(tcg->t[table].kdata[ti], "NO") == 0)
p->noramdac = 1;
}
if ((ti = tcg->find_kword(tcg, table, "TV_OUTPUT_ENCODING")) >= 0) {
if (strcmp(tcg->t[0].kdata[ti], "YES") == 0
|| strcmp(tcg->t[0].kdata[ti], "yes") == 0)
p->tvenc = 1;
}
p->colspace = icx_colorant_comb_to_icc(p->devmask); /* 0 if none */
p->devchan = icx_noofinks(p->devmask);
ident = icx_inkmask2char(p->devmask, 1);
bident = icx_inkmask2char(p->devmask, 0);
/* Grab any descriptive information */
if ((ti = tcg->find_kword(tcg, table, "MANUFACTURER")) >= 0)
p->xpi.deviceMfgDesc = strdup(tcg->t[table].kdata[ti]);
if ((ti = tcg->find_kword(tcg, table, "MODEL")) >= 0)
p->xpi.modelDesc = strdup(tcg->t[table].kdata[ti]);
if ((ti = tcg->find_kword(tcg, table, "DESCRIPTION")) >= 0)
p->xpi.profDesc = strdup(tcg->t[table].kdata[ti]);
if ((ti = tcg->find_kword(tcg, table, "COPYRIGHT")) >= 0)
p->xpi.copyright = strdup(tcg->t[table].kdata[ti]);
if (tcg->t[table].nsets <= 0) {
sprintf(p->e.m, "%s file '%s' has too few entries %d",
ftname,filename,tcg->t[table].nsets);
return p->e.c = 1;
}
/* Figure out the indexes of all the fields */
sprintf(buf, "%s_I",bident);
if ((spi[0] = tcg->find_field(tcg, table, buf)) < 0) {
sprintf(p->e.m,"%s file '%s' doesn't contain field '%s'",ftname,filename,buf);
return p->e.c = 1;
}
for (j = 0; j < p->devchan; j++) {
inkmask imask = icx_index2ink(p->devmask, j);
sprintf(buf, "%s_%s",bident,icx_ink2char(imask));
if ((spi[1+j] = tcg->find_field(tcg, table, buf)) < 0) {
sprintf(p->e.m,"%s file '%s' doesn't contain field '%s'",ftname,filename,buf);
return p->e.c = 1;
}
}
/* Read in each channels values and put them in a rspl */
for (j = 0; j < p->devchan; j++) {
datai low,high;
int gres[MXDI];
double smooth = 1.0;
co *dpoints;
low[0] = 0.0;
high[0] = 1.0;
gres[0] = tcg->t[table].nsets;
if ((p->cals[j] = new_rspl(RSPL_NOFLAGS,1, 1)) == NULL) {
sprintf(p->e.m,"new_rspl() failed");
return p->e.c = 2;
}
if ((dpoints = malloc(sizeof(co) * gres[0])) == NULL) {
sprintf(p->e.m,"malloc dpoints[%d] failed",gres[0]);
return p->e.c = 2;
}
/* Copy the points to our array */
for (i = 0; i < gres[0]; i++) {
dpoints[i].p[0] = i/(double)(gres[0]-1);
dpoints[i].v[0] = *((double *)tcg->t[table].fdata[i][spi[1+j]]);
}
/* Set the rspl */
p->cals[j]->set_rspl(p->cals[j],
0,
(void *)dpoints, /* Read points */
xcal_rsplset, /* Setting function */
low, high, gres, /* Low, high, resolution of grid */
NULL, NULL /* Default data scale */
);
free(dpoints);
}
free(ident);
free(bident);
return 0;
}
#ifndef SALONEINSTLIB
/* Read a calibration file from an ICC vcgt tag */
/* Return nz if this fails */
int xcal_read_icc(xcal *p, icc *c) {
icmVideoCardGamma *vg;
icmTextDescription *td;
icmText *tx;
int res, i, j;
/* See if there is a vcgt tag */
if ((vg = (icmVideoCardGamma *)c->read_tag(c, icSigVideoCardGammaTag)) == NULL) {
sprintf(p->e.m, "ICC profile has no vcgt");
return p->e.c = 1;
}
/* What sort of device the profile is for */
p->devclass = c->header->deviceClass;
p->colspace = c->header->colorSpace;
if ((p->devmask = icx_icc_to_colorant_comb(p->colspace, p->devclass)) == 0) {
sprintf(p->e.m, "Unable to determine inkmask from ICC profile");
return p->e.c = 1;
}
p->devchan = icx_noofinks(p->devmask);
/* Grab any descriptive information */
if ((td = (icmTextDescription *)c->read_tag(c, icSigDeviceMfgDescTag)) != NULL) {
p->xpi.deviceMfgDesc = strdup(td->desc);
}
if ((td = (icmTextDescription *)c->read_tag(c, icSigDeviceModelDescTag)) != NULL) {
p->xpi.modelDesc = strdup(td->desc);
}
if ((td = (icmTextDescription *)c->read_tag(c, icSigProfileDescriptionTag)) != NULL) {
p->xpi.profDesc = strdup(td->desc);
}
if ((tx = (icmText *)c->read_tag(c, icSigCopyrightTag)) != NULL) {
p->xpi.copyright = strdup(tx->desc);
}
/* Decide the lut resolution */
if (vg->tagType == icVideoCardGammaFormula)
res = 2048;
else
res = vg->u.table.entryCount;
/* Read in each channels values and put them in a rspl */
for (j = 0; j < p->devchan; j++) {
datai low,high;
int gres[MXDI];
double smooth = 1.0;
co *dpoints;
low[0] = 0.0;
high[0] = 1.0;
gres[0] = res;
if ((p->cals[j] = new_rspl(RSPL_NOFLAGS,1, 1)) == NULL) {
sprintf(p->e.m,"new_rspl() failed");
return p->e.c = 2;
}
if ((dpoints = malloc(sizeof(co) * gres[0])) == NULL) {
sprintf(p->e.m,"malloc dpoints[%d] failed",gres[0]);
return p->e.c = 2;
}
/* Copy the points to our array */
for (i = 0; i < gres[0]; i++) {
dpoints[i].p[0] = i/(double)(gres[0]-1);
dpoints[i].v[0] = vg->lookup(vg, j, dpoints[i].p[0]);
}
/* Set the rspl */
p->cals[j]->set_rspl(p->cals[j],
0,
(void *)dpoints, /* Read points */
xcal_rsplset, /* Setting function */
low, high, gres, /* Low, high, resolution of grid */
NULL, NULL /* Default data scale */
);
free(dpoints);
}
return 0;
}
#endif /* !SALONEINSTLIB */
/* Read a calibration file */
/* Return nz if this fails */
static int xcal_read(xcal *p, char *filename) {
cgats *tcg; /* .cal file */
int table = 0;
int rv;
if ((tcg = new_cgats()) == NULL) {
sprintf(p->e.m, "new_cgats() failed");
return p->e.c = 2;
}
tcg->add_other(tcg, "CAL"); /* our special input type is Calibration Table */
if (tcg->read_name(tcg, filename)) {
strcpy(p->e.m, tcg->e.m);
p->e.c = tcg->e.c;
tcg->del(tcg);
return p->e.c;
}
if (tcg->ntables < 1)
return 1;
rv = xcal_read_cgats(p, tcg, table, filename);
tcg->del(tcg);
return rv;
}
/* Write a calibration to a new cgats table */
/* Return nz if this fails */
static int xcal_write_cgats(xcal *p, cgats *tcg) {
int oi;
int table;
int i, j, ti;
char *ident, *bident;
time_t clk = time(0);
struct tm *tsp = localtime(&clk);
char *atm = asctime(tsp); /* Ascii time */
char buf[100];
cgats_set_elem *setel; /* Array of set value elements */
int nsetel = 0;
int calres;
oi = tcg->add_other(tcg, "CAL"); /* our special type is Calibration Target */
table = tcg->add_table(tcg, tt_other, oi); /* Add a table for calibration */
tcg->add_kword(tcg, table, "DESCRIPTOR", p->descriptor != NULL ? p->descriptor : "Argyll Device Calibration Curves",NULL);
tcg->add_kword(tcg, table, "ORIGINATOR", p->originator != NULL ? p->originator : "Argyll", NULL);
atm[strlen(atm)-1] = '\000'; /* Remove \n from end */
tcg->add_kword(tcg, table, "CREATED",atm, NULL);
if (p->devclass == icSigInputClass)
tcg->add_kword(tcg, table, "DEVICE_CLASS","INPUT", NULL);
else if (p->devclass == icSigOutputClass)
tcg->add_kword(tcg, table, "DEVICE_CLASS","OUTPUT", NULL);
else if (p->devclass == icSigDisplayClass)
tcg->add_kword(tcg, table, "DEVICE_CLASS","DISPLAY", NULL);
else {
#ifdef SALONEINSTLIB
sprintf(p->e.m,"Unknown device class 0x%x",p->devclass);
#else
sprintf(p->e.m,"Unknown device class '%s'",icm2str(icmProfileClassSig,p->devclass));
#endif
return p->e.c = 1;
}
/* Colorspace */
ident = icx_inkmask2char(p->devmask, 1);
bident = icx_inkmask2char(p->devmask, 0);
tcg->add_kword(tcg, table, "COLOR_REP", ident, NULL);
/* Other tags */
if (p->noramdac)
tcg->add_kword(tcg, table, "VIDEO_LUT_CALIBRATION_POSSIBLE", "NO", NULL);
if (p->tvenc)
tcg->add_kword(tcg, table, "TV_OUTPUT_ENCODING", "YES", NULL);
/* Grab any descriptive information */
if (p->xpi.deviceMfgDesc != NULL)
tcg->add_kword(tcg, table, "MANUFACTURER",p->xpi.deviceMfgDesc, NULL);
if (p->xpi.modelDesc != NULL)
tcg->add_kword(tcg, table, "MODEL",p->xpi.modelDesc, NULL);
if (p->xpi.profDesc != NULL)
tcg->add_kword(tcg, table, "DESCRIPTION",p->xpi.profDesc, NULL);
if (p->xpi.copyright != NULL)
tcg->add_kword(tcg, table, "COPYRIGHT",p->xpi.copyright, NULL);
sprintf(buf, "%s_I",bident);
tcg->add_field(tcg, table, buf, r_t);
nsetel++;
for (j = 0; j < p->devchan; j++) {
inkmask imask = icx_index2ink(p->devmask, j);
sprintf(buf, "%s_%s",bident,icx_ink2char(imask));
tcg->add_field(tcg, table, buf, r_t);
nsetel++;
}
if ((setel = (cgats_set_elem *)malloc(sizeof(cgats_set_elem) * nsetel)) == NULL) {
sprintf(p->e.m,"Malloc failed");
return p->e.c = 2;
}
calres = p->cals[0]->get_res(p->cals[0])[0];
for (i = 0; i < calres; i++) {
double vv = i/(calres-1.0);
co tp;
setel[0].d = vv;
for (j = 0; j < p->devchan; j++) {
tp.p[0] = vv;
p->cals[j]->interp(p->cals[j], &tp);
setel[j+1].d = tp.v[0];
}
tcg->add_setarr(tcg, table, setel);
}
free(setel);
free(ident);
free(bident);
return 0;
}
/* Write a calibration file */
/* Return nz if this fails */
static int xcal_write(xcal *p, char *filename) {
cgats *tcg; /* .cal file */
int table = 0;
int rv;
if ((tcg = new_cgats()) == NULL) {
sprintf(p->e.m, "new_cgats() failed");
return p->e.c = 2;
}
if ((rv = xcal_write_cgats(p, tcg)) != 0) {
strcpy(p->e.m, tcg->e.m);
p->e.c = tcg->e.c;
tcg->del(tcg);
return p->e.c;
}
if (tcg->write_name(tcg, filename)) {
strcpy(p->e.m, tcg->e.m);
p->e.c = tcg->e.c;
tcg->del(tcg);
return p->e.c;
}
tcg->del(tcg);
return rv;
}
/* Translate values through the curves. */
static void xcal_interp(xcal *p, double *out, double *in) {
int j;
co tp;
for (j = 0; j < p->devchan; j++) {
tp.p[0] = in[j];
p->cals[j]->interp(p->cals[j], &tp);
out[j] = tp.v[0];
}
}
#ifndef SALONEINSTLIB
#define MAX_INVSOLN 10 /* Rspl maximum reverse solutions */
/* Translate a value backwards through the curves. */
/* Return nz if the inversion fails */
static int xcal_inv_interp(xcal *p, double *out, double *in) {
int nsoln; /* Number of solutions found */
co pp[MAX_INVSOLN]; /* Room for all the solutions found */
int j, k; /* Chosen solution */
double dir = 0.5; /* target if multiple solutions */
int rv = 0;
for (j = 0; j < p->devchan; j++) {
pp[0].v[0] = in[j];
nsoln = p->cals[j]->rev_interp (
p->cals[j], /* this */
RSPL_NEARCLIP, /* Clip to nearest (faster than vector) */
MAX_INVSOLN, /* Maximum number of solutions allowed for */
NULL, /* No auxiliary input targets */
NULL, /* Clip vector direction and length */
pp); /* Input and output values */
nsoln &= RSPL_NOSOLNS; /* Get number of solutions */
if (nsoln == 1) { /* Exactly one solution */
k = 0;
} else if (nsoln == 0) { /* Zero solutions. This is unexpected. */
rv = 1;
return -1.0;
} else { /* Multiple solutions */
double bdist = 1e300;
int bsoln = 0;
for (k = 0; k < nsoln; k++) {
double tt;
tt = pp[k].p[0] - dir;
tt *= tt;
if (tt < bdist) { /* Better solution */
bdist = tt;
bsoln = k;
}
}
k = bsoln;
}
out[j] = pp[k].p[0];
}
return rv;
}
#endif /* !SALONEINSTLIB */
/* Translate a value through one of the curves */
static double xcal_interp_ch(xcal *p, int ch, double in) {
co tp;
if (ch < 0 || ch >= p->devchan)
return -1.0;
tp.p[0] = in;
p->cals[ch]->interp(p->cals[ch], &tp);
return tp.v[0];
}
#ifndef SALONEINSTLIB
/* Translate a value backwards through one of the curves */
/* Return -1.0 if the inversion fails */
static double xcal_inv_interp_ch(xcal *p, int ch, double in) {
int nsoln; /* Number of solutions found */
co pp[MAX_INVSOLN]; /* Room for all the solutions found */
int k; /* Chosen solution */
double dir = 0.5; /* target if multiple solutions */
if (ch < 0 || ch >= p->devchan)
return -1.0;
pp[0].v[0] = in;
nsoln = p->cals[ch]->rev_interp(
p->cals[ch], /* this */
RSPL_NEARCLIP, /* Clip to nearest (faster than vector) */
MAX_INVSOLN, /* Maximum number of solutions allowed for */
NULL, /* No auxiliary input targets */
NULL, /* Clip vector direction and length */
pp); /* Input and output values */
nsoln &= RSPL_NOSOLNS; /* Get number of solutions */
if (nsoln == 1) { /* Exactly one solution */
k = 0;
} else if (nsoln == 0) { /* Zero solutions. This is unexpected. */
return -1.0;
} else { /* Multiple solutions */
double bdist = 1e300;
int bsoln = 0;
for (k = 0; k < nsoln; k++) {
double tt;
tt = pp[k].p[0] - dir;
tt *= tt;
if (tt < bdist) { /* Better solution */
bdist = tt;
bsoln = k;
}
}
k = bsoln;
}
return pp[k].p[0];
}
#endif /* !SALONEINSTLIB */
/* Set the colorspace using an inkmask */
static void xcal_set_inkmask(xcal *p, inkmask devmask) {
p->devmask = devmask;
p->colspace = icx_colorant_comb_to_icc(p->devmask); /* 0 if none */
p->devchan = icx_noofinks(p->devmask);
}
/* Set the curve values (Need to have set_inkmask before calling!) */
/* Return nz on error */
static int xcal_set_curves(xcal *p, int res, double **curves) {
int j;
co *dpoints;
/* Free any existing rspl */
for (j = 0; j < p->devchan; j++) {
if (p->cals[j] != NULL)
p->cals[j]->del(p->cals[j]);
}
if ((dpoints = malloc(sizeof(co) * res)) == NULL) {
sprintf(p->e.m,"malloc dpoints[%d] failed",res);
return p->e.c = 2;
}
for (j = 0; j < p->devchan; j++) {
datai low,high;
int gres[MXDI];
double smooth = 1.0;
int i;
low[0] = 0.0;
high[0] = 1.0;
gres[0] = res;
if ((p->cals[j] = new_rspl(RSPL_NOFLAGS,1, 1)) == NULL) {
sprintf(p->e.m,"new_rspl() failed");
return p->e.c = 2;
}
/* Copy the points to our array */
for (i = 0; i < gres[0]; i++) {
dpoints[i].p[0] = i/(double)(gres[0]-1);
dpoints[i].v[0] = curves[j][i];
}
/* Set the rspl */
p->cals[j]->set_rspl(p->cals[j],
0,
(void *)dpoints, /* Read points */
xcal_rsplset, /* Setting function */
low, high, gres, /* Low, high, resolution of grid */
NULL, NULL /* Default data scale */
);
}
free(dpoints);
return 0;
}
/* Add a reference and return p */
static xcal *xcal_ref(xcal *p) {
p->refcount++;
return p;
}
/* Delete an xcal */
static void xcal_del(xcal *p) {
int j;
if (p != NULL && --p->refcount <= 0) {
if (p->descriptor != NULL)
free(p->descriptor);
if (p->originator != NULL)
free(p->originator);
if (p->xpi.deviceMfgDesc != NULL)
free(p->xpi.deviceMfgDesc);
if (p->xpi.modelDesc != NULL)
free(p->xpi.modelDesc);
if (p->xpi.profDesc != NULL)
free(p->xpi.profDesc);
if (p->xpi.copyright != NULL)
free(p->xpi.copyright);
for (j = 0; j < p->devchan; j++) {
if (p->cals[j] != NULL)
p->cals[j]->del(p->cals[j]);
}
free(p);
}
}
/* Create a new, uninitialised xcal */
xcal *new_xcal(void) {
xcal *p;
if ((p = (xcal *)calloc(1, sizeof(xcal))) == NULL)
return NULL;
/* Init method pointers */
p->ref = xcal_ref;
p->del = xcal_del;
p->read_cgats = xcal_read_cgats;
#ifndef SALONEINSTLIB
p->read_icc = xcal_read_icc;
#endif /* !SALONEINSTLIB */
p->read = xcal_read;
p->write_cgats = xcal_write_cgats;
p->write = xcal_write;
p->interp = xcal_interp;
#ifndef SALONEINSTLIB
p->inv_interp = xcal_inv_interp;
#endif /* !SALONEINSTLIB */
p->interp_ch = xcal_interp_ch;
#ifndef SALONEINSTLIB
p->inv_interp_ch = xcal_inv_interp_ch;
#endif /* !SALONEINSTLIB */
p->set_inkmask = xcal_set_inkmask;
p->set_curves = xcal_set_curves;
p->refcount++;
return p;
}

119
Argyll_V3.5.0/xicc/xcal.h Normal file
View File

@@ -0,0 +1,119 @@
#ifndef XCAL_H
#define XCAL_H
/*
* Calibration curve class.
*/
/*
* Argyll Color Management System
*
* Author: Graeme W. Gill
* Date: 30/10/2005
*
* Copyright 2005, 2025 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.
*
* This class allows reading and using a calibration file.
* Creation is currently left up to specialized programs (dispcal, printcal).
* This is also used by xicc to automatically take calibration into account
* when computing ink limits.
*/
#ifdef SALONEINSTLIB
/* Sub-set of profile Creation Suplimental Information structure */
struct _profxinf {
char *deviceMfgDesc; /* Manufacturer text description, NULL for none */
char *modelDesc; /* Model text description, NULL for none */
char *profDesc; /* Text profile description, NULL for default */
char *copyright; /* Copyrigh text, NULL for default */
char *chartarget; /* CharTaret text, NULL for none */
}; typedef struct _profxinf profxinf;
#endif /* SALONEINSTLIB */
struct _xcal {
int refcount;
/* Public: */
struct _xcal *(*ref)(struct _xcal *p); /* Add a reference and return p */
void (*del)(struct _xcal *p); /* Delete reference and free if now zero */
/* Read a calibration file from a CGATS table */
/* "filename" is just for diagnostics */
/* Return nz if this fails (filename is for error messages) */
int (*read_cgats) (struct _xcal *p, cgats *cg, int table, char *filename);
#ifndef SALONEINSTLIB
/* Read a calibration file from an ICC vcgt tag */
/* Return nz if this fails */
int (*read_icc) (struct _xcal *p, icc *c);
#endif
/* Read a calibration file */
/* Return nz if this fails */
int (*read) (struct _xcal *p, char *filename);
/* Write a calibration to a new cgats table */
/* Return nz if this fails */
int (*write_cgats)(struct _xcal *p, cgats *tcg);
/* Write a calibration file */
/* Return nz if this fails */
int (*write)(struct _xcal *p, char *filename);
/* Translate values through the curves. */
void (*interp) (struct _xcal *p, double *out, double *in);
#ifndef SALONEINSTLIB
/* Translate a value backwards through the curves. */
/* Return nz if the inversion fails */
int (*inv_interp) (struct _xcal *p, double *out, double *in);
#endif
/* Translate a value through one of the curves */
double (*interp_ch) (struct _xcal *p, int ch, double in);
#ifndef SALONEINSTLIB
/* Translate a value backwards through one of the curves */
/* Return -1.0 if the inversion fails */
double (*inv_interp_ch) (struct _xcal *p, int ch, double in);
#endif
/* Set the colorspace using an inkmask */
void (*set_inkmask)(struct _xcal *p, inkmask devmask);
/* Set the curve values (Need to have set_inkmask before calling!) */
/* Return nz on error */
int (*set_curves)(struct _xcal *p, int res, double **curves);
int noramdac; /* Set to nz if there was no VideoLUT access */
int tvenc; /* nz if this cal was created using (16-235)/255 Video encoding */
/* Private: */
icProfileClassSignature devclass; /* Type of device */
inkmask devmask; /* ICX ink mask of device space */
icColorSpaceSignature colspace; /* Corresponding ICC device space sig (0 if none) */
int devchan; /* Number of chanels in device space */
char *descriptor; /* If non-null, use to write DESCRIPTOR tag (freed with xcal) */
char *originator; /* If non-null, use to write ORIGINATOR tag (freed with xcal) */
profxinf xpi; /* Extra calibration description information */
icmErr e; /* Error code & message */
rspl *cals[MAX_CHAN];
}; typedef struct _xcal xcal;
/* Create a new, uninitialised xcal */
xcal *new_xcal(void);
#endif /* XCAL */

245
Argyll_V3.5.0/xicc/xcam.c Normal file
View File

@@ -0,0 +1,245 @@
/*
* Abstract interface to color appearance model transforms.
*
* This is to allow the rest of Argyll to use a default CAM.
*
* Author: Graeme W. Gill
* Date: 25/7/2004
* Version: 1.00
*
* Copyright 2004 Graeme W. Gill
* Please refer to COPYRIGHT file for details.
* 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 <math.h>
#include "xcam.h"
#include "cam97s3.h"
#include "cam02.h"
static void icx_cam_free(icxcam *s);
static int icx_set_view_vc(icxcam *s, icxViewCond *vc);
static int icx_set_view(icxcam *s, ViewingCondition Ev, double Wxyz[3],
double La, double Yb, double Lv, double Yf, double Yg, double Gxyz[3],
int hk, double hkscale, double mtaf, double Wxyz2[3]);
static int icx_XYZ_to_cam(struct _icxcam *s, double Jab[3], double XYZ[3]);
static int icx_cam_to_XYZ(struct _icxcam *s, double XYZ[3], double Jab[3]);
static void settrace(struct _icxcam *s, int tracev);
static void icx_cam_dump(struct _icxcam *s);
/* Return the default CAM */
icxCAM icxcam_default(void) {
// return cam_CIECAM97s3;
return cam_CIECAM02;
}
/* Return a string describing the given CAM */
char *icxcam_description(icxCAM which) {
if (which == cam_default)
which = icxcam_default();
switch(which) {
case cam_CIECAM97s3:
return "CIECAM97s3";
case cam_CIECAM02:
return "CIECAM02";
default:
break;
}
return "Unknown CAM";
}
/* Create a cam conversion object */
icxcam *new_icxcam(icxCAM which) {
icxcam *s;
if ((s = (icxcam *)calloc(1, sizeof(icxcam))) == NULL) {
fprintf(stderr,"icxcam: malloc failed allocating object\n");
return NULL;
}
/* Initialise methods */
s->del = icx_cam_free;
s->set_view_vc = icx_set_view_vc;
s->set_view = icx_set_view;
s->XYZ_to_cam = icx_XYZ_to_cam;
s->cam_to_XYZ = icx_cam_to_XYZ;
s->settrace = settrace;
s->dump = icx_cam_dump;
/* We set the default CAM here */
if (which == cam_default)
which = icxcam_default();
s->tag = which;
switch(which) {
case cam_CIECAM97s3:
if ((s->p = (void *)new_cam97s3()) == NULL) {
fprintf(stderr,"icxcam: malloc failed allocating object\n");
free(s);
return NULL;
}
break;
case cam_CIECAM02:
if ((s->p = (void *)new_cam02()) == NULL) {
fprintf(stderr,"icxcam: malloc failed allocating object\n");
free(s);
return NULL;
}
break;
default:
fprintf(stderr,"icxcam: unknown CAM type\n");
free(s);
return NULL;
}
return s;
}
static void icx_cam_free(icxcam *s) {
if (s != NULL) {
switch(s->tag) {
case cam_CIECAM97s3: {
cam97s3 *pp = (cam97s3 *)s->p;
pp->del(pp);
break;
}
case cam_CIECAM02: {
cam02 *pp = (cam02 *)s->p;
pp->del(pp);
break;
}
default:
break;
}
free(s);
}
}
static int icx_set_view_vc(
icxcam *s,
icxViewCond *vc
) {
return s->set_view(s,
vc->Ev, vc->Wxyz, vc->La, vc->Yb, vc->Lv,
vc->Yf, vc->Yg, vc->Gxyz,
vc->hk, vc->hkscale,
vc->mtaf, vc->Wxyz2);
}
static int icx_set_view(
icxcam *s,
ViewingCondition Ev, /* Enumerated Viewing Condition */
double Wxyz[3], /* Reference/Adapted White XYZ (Y range 0.0 .. 1.0) */
double La, /* Adapting/Surround Luminance cd/m^2 */
double Yb, /* Relative Luminance of Background to reference white */
double Lv, /* Luminance of white in the Viewing/Scene/Image field (cd/m^2) */
/* Ignored if Ev is set to other than vc_none */
double Yf, /* Flare as a fraction of the reference white (Y range 0.0 .. 1.0) */
double Yg, /* Glare as a fraction of the adapting/surround (Y range 0.0 .. 1.0) */
double Gxyz[3], /* The Glare white coordinates (typically the Ambient color) */
int hk, /* Flag, NZ to use Helmholtz-Kohlraush effect */
double hkscale, /* HK effect scaling factor */
double mtaf, /* Mid tone partial adapation factor from Wxyz to Wxyz2, <= 0.0 if none */
double Wxyz2[3] /* Mid tone Adapted White XYZ (Y range 0.0 .. 1.0) */
) {
s->Wxyz[0] = Wxyz[0];
s->Wxyz[1] = Wxyz[1];
s->Wxyz[2] = Wxyz[2];
switch(s->tag) {
case cam_CIECAM97s3: {
cam97s3 *pp = (cam97s3 *)s->p;
return pp->set_view(pp, Ev, Wxyz, La, Yb, Lv, 0.2 * Yg, Gxyz, hk);
}
case cam_CIECAM02: {
cam02 *pp = (cam02 *)s->p;
return pp->set_view(pp, Ev, Wxyz, La, Yb, Lv, Yf, Yg, Gxyz, hk, hkscale, mtaf, Wxyz2);
}
default:
break;
}
return 0;
}
/* Conversions */
static int icx_XYZ_to_cam(
struct _icxcam *s,
double Jab[3],
double XYZ[3]
) {
switch(s->tag) {
case cam_CIECAM97s3: {
cam97s3 *pp = (cam97s3 *)s->p;
return pp->XYZ_to_cam(pp, Jab, XYZ);
}
case cam_CIECAM02: {
cam02 *pp = (cam02 *)s->p;
return pp->XYZ_to_cam(pp, Jab, XYZ);
}
default:
break;
}
return 0;
}
static int icx_cam_to_XYZ(
struct _icxcam *s,
double XYZ[3],
double Jab[3]
) {
switch(s->tag) {
case cam_CIECAM97s3: {
cam97s3 *pp = (cam97s3 *)s->p;
return pp->cam_to_XYZ(pp, XYZ, Jab);
}
case cam_CIECAM02: {
cam02 *pp = (cam02 *)s->p;
return pp->cam_to_XYZ(pp, XYZ, Jab);
}
default:
break;
}
return 0;
}
/* Debug */
static void settrace(
struct _icxcam *s,
int tracev
) {
switch(s->tag) {
case cam_CIECAM97s3: {
cam97s3 *pp = (cam97s3 *)s->p;
pp->trace = tracev;
}
case cam_CIECAM02: {
cam02 *pp = (cam02 *)s->p;
pp->trace = tracev;
}
default:
break;
}
}
/* Dump the viewing conditions to stdout */
static void icx_cam_dump(struct _icxcam *s) {
switch(s->tag) {
case cam_CIECAM97s3: {
cam97s3 *pp = (cam97s3 *)s->p;
// pp->dump(pp);
}
case cam_CIECAM02: {
cam02 *pp = (cam02 *)s->p;
pp->dump(pp);
}
default:
break;
}
}

115
Argyll_V3.5.0/xicc/xcam.h Normal file
View File

@@ -0,0 +1,115 @@
#ifndef _XCAM_H_
/*
* Abstract interface to color appearance model transforms.
*
* This is to allow the rest of Argyll to use a default CAM.
*
* Author: Graeme W. Gill
* Date: 25/7/2004
* Version: 1.00
*
* Copyright 2004 Graeme W. Gill
* Please refer to COPYRIGHT file for details.
* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :-
* see the License.txt file for licencing details.
*/
/* ---------------------------------- */
/* The range of CAMs supported */
typedef enum {
cam_default = 0, /* Default CAM */
cam_CIECAM97s3 = 1, /* CIECAM97, version 3 */
cam_CIECAM02 = 2 /* CIECAM02 */
} icxCAM;
/* The enumerated viewing conditions: */
typedef enum {
vc_notset = -1,
vc_none = 0, /* Figure out from Lv and La */
vc_dark = 1,
vc_dim = 2,
vc_average = 3,
vc_cut_sheet = 4 /* Transparencies on a Light Box */
} ViewingCondition;
/* Structure to convey viewing conditions */
typedef struct {
ViewingCondition Ev;/* Enumerated Viewing Condition */
double Wxyz[3]; /* Reference/Adapted White XYZ (Y range 0.0 .. 1.0) */
double La; /* Adapting/Surround Luminance cd/m^2 */
double Yb; /* Relative Luminance of Background to reference white */
double Lv; /* Luminance of white in the Image/Scene/Viewing field (cd/m^2) */
/* Ignored if Ev is set to other than vc_none */
double Yf; /* Flare as a fraction of the reference white (Y range 0.0 .. 1.0) */
double Yg; /* Glare as a fraction of the adapting/surround (Y range 0.0 .. 1.0) */
double Gxyz[3]; /* The Glare white coordinates (ie the Ambient color) */
/* will be taken from Wxyz if Gxyz <= 0.0 */
int hk; /* Flag, NZ to use Helmholtz-Kohlraush effect */
double hkscale; /* [1.0] HK scaling factor */
double mtaf; /* [0.0] Mid tone partial adapation factor from Wxyz to Wxyz2 0.0 .. 1.0 */
double Wxyz2[3]; /* Mid tone Adapted White XYZ (Y range 0.0 .. 1.0) */
char *desc; /* Possible description of this VC */
} icxViewCond;
struct _icxcam {
/* Public: */
void (*del)(struct _icxcam *s); /* We're done with it */
/* Always returns 0 */
int (*set_view_vc)(
struct _icxcam *s,
icxViewCond *vc
);
/* Always returns 0 */
int (*set_view)(
struct _icxcam *s,
ViewingCondition Ev, /* Enumerated Viewing Condition */
double Wxyz[3], /* Reference/Adapted White XYZ (Y scale 1.0) */
double La, /* Adapting/Surround Luminance cd/m^2 */
double Yb, /* Luminance of Background relative to reference white (range 0.0 .. 1.0) */
double Lv, /* Luminance of white in the Viewing/Scene/Image field (cd/m^2) */
/* Ignored if Ev is set */
double Yf, /* Flare as a fraction of the reference white (range 0.0 .. 1.0) */
double Yg, /* Glare as a fraction of the adapting/surround (range 0.0 .. 1.0) */
double Gxyz[3], /* The Glare white coordinates (typically the Ambient color) */
int hk, /* Flag, NZ to use Helmholtz-Kohlraush effect */
double hkscale, /* HK effect scaling factor */
double mtaf, /* Mid tone partial adapation factor from Wxyz to Wxyz2, <= 0.0 if none */
double Wxyz2[3] /* Mid tone Adapted White XYZ (Y range 0.0 .. 1.0) */
);
/* Conversions */
int (*XYZ_to_cam)(struct _icxcam *s, double *out, double *in);
int (*cam_to_XYZ)(struct _icxcam *s, double *out, double *in);
/* Debug */
void (*settrace)(struct _icxcam *s, int tracev);
/* Dump the viewing conditions to stdout */
void (*dump)(struct _icxcam *s);
/* Private: */
icxCAM tag; /* Type */
void *p; /* Pointer to implementation */
double Wxyz[3]; /* Copy of Wxyz */
}; typedef struct _icxcam icxcam;
/* Create a new CAM conversion object */
icxcam *new_icxcam(icxCAM which);
/* Return the default CAM */
icxCAM icxcam_default();
/* Return a string describing the given CAM */
char *icxcam_description(icxCAM ct);
#define _XCAM_H_
#endif /* _XCAM_H_ */

View File

@@ -0,0 +1,783 @@
/*
* International Color Consortium color transform expanded support
* Known colorants support.
*/
/*
* Author: Graeme W. Gill
* Date: 24/2/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:
Would like to have some short string way of defining whether
the ink combination is additive or subtractive, instead
of just guessing.
*/
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <string.h>
#include <math.h>
#ifndef SALONEINSTLIB
#include "icc.h"
#else
#include "numsup.h"
#include "sa_conv.h"
#endif
#include "xcolorants.h"
#include "sort.h"
/* Colorant table for N color device characterisation. */
/* This is ordered to match the ICC colorspace convention. */
/* NOTE:- need to keep these in same order as ink mask */
/* enumeration (lsb to msb), or strange things result! */
static struct {
inkmask m; /* Mask value */
char *c; /* 1/2 Character name */
char *s; /* Everyday name */
char *ps; /* Postscript colorant name */
double aXYZ[3]; /* Rough XYZ values (0..1) for that additive colorant */
double sXYZ[3]; /* Rough XYZ values (0..1) for that subtractive colorant */
} icx_ink_table[] = {
{ ICX_CYAN, ICX_C_CYAN, ICX_S_CYAN, ICX_PS_CYAN,
{ 0.12, 0.18, 0.48 },
{ 0.12, 0.18, 0.48 } },
{ ICX_MAGENTA, ICX_C_MAGENTA, ICX_S_MAGENTA, ICX_PS_MAGENTA,
{ 0.38, 0.19, 0.20 },
{ 0.38, 0.19, 0.20 } },
{ ICX_YELLOW, ICX_C_YELLOW, ICX_S_YELLOW, ICX_PS_YELLOW,
{ 0.76, 0.81, 0.11 },
{ 0.76, 0.81, 0.11 } },
{ ICX_BLACK, ICX_C_BLACK, ICX_S_BLACK, ICX_PS_BLACK,
{ 0.01, 0.01, 0.01 },
{ 0.04, 0.04, 0.04 } },
{ ICX_ORANGE, ICX_C_ORANGE, ICX_S_ORANGE, ICX_PS_ORANGE,
{ 0.59, 0.41, 0.03 },
{ 0.59, 0.41, 0.05 } },
{ ICX_RED, ICX_C_RED, ICX_S_RED, ICX_PS_RED,
{ 0.412414, 0.212642, 0.019325 },
{ 0.40, 0.21, 0.05 } },
{ ICX_GREEN, ICX_C_GREEN, ICX_S_GREEN, ICX_PS_GREEN,
{ 0.357618, 0.715136, 0.119207 },
{ 0.11, 0.27, 0.21 } },
{ ICX_BLUE, ICX_C_BLUE, ICX_S_BLUE, ICX_PS_BLUE,
{ 0.180511, 0.072193, 0.950770 },
{ 0.11, 0.27, 0.47 } },
{ ICX_VIOLET, ICX_C_VIOLET, ICX_S_VIOLET, ICX_PS_VIOLET,
{ 0.0925, 0.0442, 0.244 },
{ 0.0925, 0.0442, 0.244 } },
{ ICX_WHITE, ICX_C_WHITE, ICX_S_WHITE, ICX_PS_WHITE,
{ 0.950543, 1.0, 1.089303 }, /* D65 ? */
{ 0.9642, 1.00, 0.8249 } }, /* D50 */
{ ICX_LIGHT_CYAN, ICX_C_LIGHT_CYAN, ICX_S_LIGHT_CYAN, ICX_PS_LIGHT_CYAN,
{ 0.76, 0.89, 1.08 },
{ 0.76, 0.89, 1.08 } },
{ ICX_LIGHT_MAGENTA, ICX_C_LIGHT_MAGENTA, ICX_S_LIGHT_MAGENTA, ICX_PS_LIGHT_MAGENTA,
{ 0.83, 0.74, 1.02 },
{ 0.83, 0.74, 1.02 } },
{ ICX_LIGHT_YELLOW, ICX_C_LIGHT_YELLOW, ICX_S_LIGHT_YELLOW, ICX_PS_LIGHT_YELLOW,
{ 0.88, 0.97, 0.72 },
{ 0.88, 0.97, 0.72 } },
{ ICX_LIGHT_BLACK, ICX_C_LIGHT_BLACK, ICX_S_LIGHT_BLACK, ICX_PS_LIGHT_BLACK,
{ 0.56, 0.60, 0.65 },
{ 0.56, 0.60, 0.65 } },
{ ICX_MEDIUM_CYAN, ICX_C_MEDIUM_CYAN, ICX_S_MEDIUM_CYAN, ICX_PS_MEDIUM_CYAN,
{ 0.61, 0.81, 1.07 },
{ 0.61, 0.81, 1.07 } },
{ ICX_MEDIUM_MAGENTA, ICX_C_MEDIUM_MAGENTA, ICX_S_MEDIUM_MAGENTA, ICX_PS_MEDIUM_MAGENTA,
{ 0.74, 0.53, 0.97 },
{ 0.74, 0.53, 0.97 } },
{ ICX_MEDIUM_YELLOW, ICX_C_MEDIUM_YELLOW, ICX_S_MEDIUM_YELLOW, ICX_PS_MEDIUM_YELLOW,
{ 0.82, 0.93, 0.40 },
{ 0.82, 0.93, 0.40 } },
{ ICX_MEDIUM_BLACK, ICX_C_MEDIUM_BLACK, ICX_S_MEDIUM_BLACK, ICX_PS_MEDIUM_BLACK,
{ 0.27, 0.29, 0.31 },
{ 0.27, 0.29, 0.31 } },
{ ICX_LIGHT_LIGHT_BLACK, ICX_C_LIGHT_LIGHT_BLACK, ICX_S_LIGHT_LIGHT_BLACK, ICX_PS_LIGHT_LIGHT_BLACK,
{ 0.76, 0.72, 0.65 }, /* Very rough - should substiture real numbers */
{ 0.76, 0.72, 0.65 } },
{ 0, "", "", "", { 0.0, 0.0, 0.0 }, { 0.0, 0.0, 0.0 } }
};
/* Colorant table for N color device characterisation */
static struct {
inkmask m; /* Mask combination */
inkmask rm; /* Light ink reduced mask combination */
icColorSpaceSignature psig; /* Appropriate primary ICC signature */
icColorSpaceSignature ssig; /* Appropriate secondary ICC signature */
char *desc; /* Description */
} icx_colcomb_table[] = {
{ ICX_K, ICX_K, icSigGrayData, icSigGrayData,
"Print grey" },
{ ICX_W, ICX_W, icSigGrayData, icSigGrayData,
"Video grey" },
{ ICX_IRGB, ICX_IRGB, icSigRgbData, icSigRgbData,
"Print RGB" },
{ ICX_RGB, ICX_RGB, icSigRgbData, icSigRgbData,
"Video RGB" },
{ ICX_CMYK, ICX_CMYK, icSigCmykData, icSigCmykData,
"CMYK" },
{ ICX_CMY, ICX_CMY, icSigCmyData, icSigCmyData,
"CMY" },
{ ICX_CMYKcm, ICX_CMYK, icSig6colorData, icSigMch6Data,
"CMYK + Light CM" },
{ ICX_CMYKcmk, ICX_CMYK, icSig7colorData, icSig7colorData,
"CMYK + Light CMK" },
{ ICX_CMYKRB, ICX_W, icSig6colorData, icSigMch6Data,
"CMYK + Red + Blue" },
{ ICX_CMYKOG, ICX_W, icSig6colorData, icSigMch6Data,
"CMYK + Orange + Green" },
{ ICX_CMYKRGB, ICX_W, icSig7colorData, icSigMch7Data,
"CMYK + Red + Green + Blue" },
{ ICX_CMYKOGV, ICX_W, icSig7colorData, icSigMch7Data,
"CMYK + Orange + Green + Violet" },
{ ICX_CMYKOGB, ICX_W, icSig7colorData, icSigMch7Data,
"CMYK + Orange + Green + Blue" },
{ ICX_CMYKcmk1k, ICX_CMYK, icSig8colorData, icSigMch8Data,
"CMYK + Light CMK + Light Light K" },
{ ICX_CMYKOGcm, ICX_CMYKOG, icSig8colorData, icSigMch8Data,
"CMYK + Orange + Green + Light CM" },
{ ICX_CMYKcm2c2m, ICX_CMYK, icSig8colorData, icSigMch8Data,
"CMYK + Light CM + Medium CM" },
{ 0, 0, 0, 0, "" }
};
/* Given an ink combination mask, return the number of recognised inks in it */
int icx_noofinks(inkmask mask) {
int i, count = 0;
for (i = 0; icx_ink_table[i].m != 0; i++) {
if (mask & icx_ink_table[i].m) {
count++;
}
}
return count;
}
/* Given an ink combination mask, return the 1-2 character based string */
/* If winv is nz, include ICX_INVERTED indicator if set */
/* Return NULL on error. free() after use */
char *icx_inkmask2char(inkmask mask, int winv) {
int i;
char *rv;
if ((rv = malloc(2 * ICX_MXINKS + 1)) == NULL)
return NULL;
*rv = '\000';
if (winv && (mask & ICX_INVERTED))
strcat(rv, "i");
for (i = 0; icx_ink_table[i].m != 0; i++) {
if (mask & icx_ink_table[i].m) {
strcat(rv, icx_ink_table[i].c);
}
}
return rv;
}
/* Given the 1-2 character string, return the ink combination mask */
/* Note that ICX_ADDITIVE will be guessed */
/* Return 0 if unrecognised character in string */
inkmask icx_char2inkmask(char *chstring) {
inkmask mask = 0;
int k, i;
char *cp;
cp = chstring;
for (k = 0; ; k++) {
if (*cp == '\000') {
break;
}
/* "Inverted" prefix ? */
if (k == 0 && *cp == 'i') {
mask |= ICX_INVERTED;
cp++;
continue;
}
/* Colorant ? */
for (i = 0; icx_ink_table[i].m != 0; i++) {
if (strncmp(cp, icx_ink_table[i].c, strlen(icx_ink_table[i].c)) == 0) {
mask |= icx_ink_table[i].m;
cp += strlen(icx_ink_table[i].c);
break;
}
}
if (icx_ink_table[i].m == 0) { /* oops - unrecognised character */
return 0;
}
}
/* Check it out againts known combinations to guess additive */
for (i = 0; icx_colcomb_table[i].m != 0; i++) {
if ((icx_colcomb_table[i].m & ~ICX_ADDITIVE) == mask) {
mask = icx_colcomb_table[i].m;
break;
}
}
return mask;
}
/* Given an ink combination mask that may contain light inks, */
/* return the corresponding ink mask without light inks. */
/* Return 0 if ink combination not recognised. */
inkmask icx_ink2primary_ink(inkmask mask) {
int i;
for (i = 0; icx_colcomb_table[i].m != 0; i++) {
if (mask == icx_colcomb_table[i].m) {
return icx_colcomb_table[i].rm;
}
}
return 0;
}
/* Given an ink combination mask and a single ink mask, */
/* return the index number within the set for that ink. */
/* Return -1 if mask1 not in mask */
int icx_ink2index(inkmask mask, inkmask mask1) {
int i, count = 0;
if ((mask1 & mask) == 0)
return -1;
for (i = 0; icx_ink_table[i].m != 0; i++) {
if (mask1 == icx_ink_table[i].m) {
return count;
}
if (mask & icx_ink_table[i].m) {
count++;
}
}
return -1;
}
/* Given an ink combination mask and a index number, */
/* return the single ink mask. */
/* Return 0 if there are no inks at that index */
inkmask icx_index2ink(inkmask mask, int ixno) {
int i, count = 0;
for (i = 0; icx_ink_table[i].m != 0; i++) {
if (mask & icx_ink_table[i].m) {
if (ixno == count)
return icx_ink_table[i].m;
count++;
}
}
return 0;
}
/* Given a single ink mask, */
/* return its string representation */
char *icx_ink2string(inkmask mask) {
int i;
for (i = 0; icx_ink_table[i].m != 0; i++) {
if (mask == icx_ink_table[i].m)
return icx_ink_table[i].s;
}
return NULL;
}
/* Given a single ink mask, */
/* return its 1-2 character representation */
char *icx_ink2char(inkmask mask) {
int i;
for (i = 0; icx_ink_table[i].m != 0; i++) {
if (mask == icx_ink_table[i].m)
return icx_ink_table[i].c;
}
return NULL;
}
/* Given a single ink mask, */
/* return its Postscript string representation */
char *icx_ink2psstring(inkmask mask) {
int i;
for (i = 0; icx_ink_table[i].m != 0; i++) {
if (mask == icx_ink_table[i].m)
return icx_ink_table[i].ps;
}
return NULL;
}
/* Return an enumerated single colorant description */
/* Return 0 if no such enumeration, single colorant mask if there is */
inkmask icx_enum_colorant(
int no, /* Enumeration mask index */
char **desc /* Return enumeration description */
) {
int i;
for (i = 0; icx_ink_table[i].m != 0; i++) {
if (i == no) {
if (desc != NULL)
*desc = icx_ink_table[i].s;
return icx_ink_table[i].m;
}
}
return 0;
}
/* Return an enumerated colorant combination */
/* Return 0 if no such enumeration, colorant combination mask if there is */
inkmask icx_enum_colorant_comb(
int no, /* Enumeration mask index */
char **desc /* Return enumeration description */
) {
int i;
for (i = 0; icx_colcomb_table[i].m != 0; i++) {
if (i == no) {
if (desc != NULL)
*desc = icx_colcomb_table[i].desc;
return icx_colcomb_table[i].m;
}
}
return 0;
}
/* Given an colorant combination mask, */
/* check if it matches the given ICC colorspace signature. */
/* return NZ if it does. */
/* (We don't check colorant colors for multi-colorant devices though) */
int icx_colorant_comb_match_icc(
inkmask mask, /* Colorant combination mask */
icColorSpaceSignature sig /* ICC signature */
) {
int i;
for (i = 0; icx_colcomb_table[i].m != 0; i++) {
if (mask == icx_colcomb_table[i].m) {
if (sig == icx_colcomb_table[i].psig
|| sig == icx_colcomb_table[i].ssig) {
return 1;
} else {
return 0;
}
}
}
return 0;
}
/* Given an ICC colorspace signature, return the appropriate */
/* colorant combination mask. Return 0 if ambiguous signature. */
inkmask icx_icc_to_colorant_comb(icColorSpaceSignature sig, icProfileClassSignature deviceClass) {
switch (sig) {
case icSigGrayData:
if (deviceClass == icSigOutputClass)
return ICX_K;
return ICX_W;
case icSigCmyData:
return ICX_CMY;
case icSigRgbData:
if (deviceClass == icSigOutputClass)
return ICX_IRGB;
return ICX_RGB;
case icSigCmykData:
return ICX_CMYK;
default:
break;
}
return 0;
}
/* Given an ICC colorspace signature, and a matching list */
/* of the D50 L*a*b* colors of the colorants, return the best matching */
/* colorant combination mask. Return 0 if not an applicable colorspace. */
/* (Note we're not dealing with colorant order here.) */
inkmask icx_icc_cv_to_colorant_comb(
icColorSpaceSignature sig, /* Input ICC colorspace signature */
icProfileClassSignature deviceClass, /* Device class */
double cvals[][3] /* Input L*a*b* colorant values */
) {
int i, j;
int imask;
int ninks, ncol;
double slab[ICX_MXINKS][3];
double alab[ICX_MXINKS][3];
typedef struct { int x; double v; } mchstr;
mchstr mch[MAX_CHAN][ICX_MXINKS]; /* match index */
int used[ICX_MXINKS];
int co[ICX_MXINKS]; /* Combination counter */
double cmv; /* Combination match value */
int bco[ICX_MXINKS]; /* Best Combinat */
double bcmv; /* Best Match value */
int order[MAX_CHAN]; /* Place holder, not currently used - return ink order */
switch (sig) {
case icSigXYZData:
case icSigLabData:
case icSigLuvData:
case icSigYCbCrData:
case icSigYxyData:
case icSigHsvData:
case icSigHlsData:
return 0;
case icSigGrayData:
if (deviceClass == icSigOutputClass)
return ICX_K;
return ICX_W;
case icSigCmyData:
return ICX_CMY;
case icSigRgbData:
if (deviceClass == icSigOutputClass)
return ICX_IRGB;
return ICX_RGB;
case icSigCmykData:
return ICX_CMYK;
default:
break;
}
#ifdef NEVER /* Rely on device class (above) */
if (sig == icSigGrayData) {
/* This only works reliably if we got the Lab data from a non-ICC */
/* conformant monochrome profile (one that doesn't force device 0 */
/* input of the grayTRTC to black), or uses a LUT based monochrome */
/* profile. */
/* It also won't work if someone uses a monochrome profile for a */
/* device with a non grey colorant. */
/* Really ICC should have icSigWhiteData, icSigBlackData, icSig1colorData ? */
if (cvals[0][0] > 50.0) {
return ICX_W;
} else {
return ICX_K;
}
}
#endif /* NEVER */
/* Compute Lab values of stock inks, and count them */
for (ninks = 0; ninks < ICX_MXINKS; ninks++) {
if (icx_ink_table[ninks].m == 0)
break;
icmXYZ2Lab(&icmD50, slab[ninks], icx_ink_table[ninks].sXYZ);
icmXYZ2Lab(&icmD50, alab[ninks], icx_ink_table[ninks].aXYZ);
}
ncol = icmCSSig2nchan(sig); /* Number of colorants */
/* Compute ideal matching of device colorants to stock inks */
for (i = 0; i < ncol; i++) {
for (j = 0; j < ninks; j++) {
double tt;
mch[i][j].x = j;
mch[i][j].v = icmCIE94sq(cvals[i], slab[j]);
tt = icmCIE94sq(cvals[i], alab[j]);
if (tt < mch[i][j].v)
mch[i][j].v = tt;
}
/* Sort the matches for this colorant */
#define HEAP_COMPARE(A,B) (A.v < B.v)
HEAPSORT(mchstr, mch[i], ninks)
#undef HEAP_COMPARE
//printf("\n~1 Colorant %d has best matches\n",i);
//for (j = 0; j < ninks; j++)
//printf("~1 ix %d color = '%s' dE %f\n",j, icx_ink_table[mch[i][j].x].s, mch[i][j].v);
}
/* Do exaustive combination search, using early */
/* out to keep combination count down.*/
/* Reset the combination counter */
for (j = 0; j < ninks; j++) /* Reset ink used flag */
used[j] = 0;
cmv = 0.0;
for (i = ncol-1; i >= 0; i--) {
for (j = 0; j < ninks; j++) { /* Set to lowest usable number */
if (used[mch[i][j].x] == 0) { /* Can use this one */
used[mch[i][j].x] = 1; /* Now it's matched */
cmv += mch[i][j].v;
co[i] = j;
break; /* we assume ncol < ninks */
}
}
}
//printf("\n~1 Initial combination has cmv = %f\n",cmv);
//for (i = 0; i < ncol; i++)
//printf("~1 Chan %d color = '%s'\n",i, icx_ink_table[mch[i][co[i]].x].s);
/* Set this as the best initial match */
for (i = 0; i < ncol; i++)
bco[i] = co[i];
bcmv = cmv;
/* Now go through all other combinations */
for (;;) {
/* Increment counter */
for (i = 0;;) {
/* Work up the digits, incrementing each one */
for (; i < ncol; i++) {
j = co[i];
used[mch[i][j].x] = 0;
cmv -= mch[i][j].v;
while (++j < ninks && (used[mch[i][j].x] != 0 || (cmv + mch[i][j].v) >= bcmv)) {
};
if (j < ninks) { /* No carry */
used[mch[i][j].x] = 1;
cmv += mch[i][j].v;
co[i] = j;
break;
}
/* Carry to next colorant */
}
if (i >= ncol)
break; /* Run out of digits to increment */
/* Now work down again, resetting digit */
for (--i; i >= 0; i--) {
for (j = 0; j < ninks; j++) { /* Set to lowest usable number */
if (used[mch[i][j].x] == 0 && (cmv + mch[i][j].v) < bcmv) {
/* Can use this one */
used[mch[i][j].x] = 1; /* Now it's matched */
cmv += mch[i][j].v;
co[i] = j;
break;
}
}
if (j >= ninks) { /* No combination is feasible */
i++; /* Go back to incrementing next highest digit */
break;
}
}
if (i < 0) /* We reset all the lower digits */
break; /* We're at a good combination, so done. */
}
if (i >= ncol)
break; /* We're done all combinations */
//printf("\n~1 New combination has cmv = %f\n",cmv);
//for (i = 0; i < ncol; i++)
//printf("~1 Chan %d color = '%s'\n",i, icx_ink_table[mch[i][co[i]].x].s);
/* See if this is better (it always should be !) */
if (cmv < bcmv) {
for (i = 0; i < ncol; i++)
bco[i] = co[i];
bcmv = cmv;
}
}
/* Compile the result */
for (imask = 0, i = 0; i < ncol; i++) {
imask |= icx_ink_table[mch[i][bco[i]].x].m;
order[i] = bco[i]; /* icx ink_table index corresponding to channel */
}
/* Slight hack to recognise some additive combinations */
if (imask == ICX_WHITE)
imask = ICX_W;
else if (imask == (ICX_RED | ICX_GREEN | ICX_BLUE))
imask = ICX_RGB;
return imask;
}
/* Given a colorant combination mask */
/* return the primary matching ICC colorspace signature. */
/* return 0 if there is no match */
icColorSpaceSignature icx_colorant_comb_to_icc(
inkmask mask /* Colorant combination mask */
) {
int i;
for (i = 0; icx_colcomb_table[i].m != 0; i++) {
if (mask == icx_colcomb_table[i].m)
return icx_colcomb_table[i].psig;
}
return 0;
}
/* - - - - - - - - - - - - - - - - - */
/* Approximate device colorant model */
/* Given device values, return an estimate of the XYZ value for that color. */
static void icxColorantLu_to_XYZ(
icxColorantLu *s,
double XYZ[3], /* Output */
double d[ICX_MXINKS] /* Input */
) {
int e, j;
if (s->mask & ICX_ADDITIVE ) {
/* We assume a simple additive model with gamma */
XYZ[0] = XYZ[1] = XYZ[2] = 0.0;
for (e = 0; e < s->di; e++) {
double v = d[e];
if (v < 0.0)
v = 0.0;
else if (v > 1.0)
v = 1.0;
if (v <= 0.03928)
v /= 12.92;
else
v = pow((0.055 + v)/1.055, 2.4); /* Gamma */
for (j = 0; j < 3; j++)
XYZ[j] += v * icx_ink_table[s->iix[e]].aXYZ[j];
}
/* Normalise Y to 1.0, & add black glare */
for (j = 0; j < 3; j++) {
XYZ[j] *= s->Ynorm;
XYZ[j] = XYZ[j] * (1.0 - icx_ink_table[s->bkix].aXYZ[j]) + icx_ink_table[s->bkix].aXYZ[j];
}
} else {
/* We assume a simple screened subtractive filter model, with dot gain */
/* start with white */
XYZ[0] = icx_ink_table[s->whix].sXYZ[0];
XYZ[1] = icx_ink_table[s->whix].sXYZ[1];
XYZ[2] = icx_ink_table[s->whix].sXYZ[2];
/* And filter it out for each component */
for (e = 0; e < s->di; e++) {
double v = d[e];
if (v < 0.0)
v = 0.0;
else if (v > 1.0)
v = 1.0;
v = 1.0 - pow(1.0 - v, 2.2); /* Compute dot gain */
for (j = 0; j < 3; j++) {
double fv;
/* Normalise filtering effect of this colorant */
fv = icx_ink_table[s->iix[e]].aXYZ[j]/icx_ink_table[s->whix].sXYZ[j];
/* Compute screened filtering effect */
fv = (1.0 - v) + v * fv;
/* Apply filter to our current value */
XYZ[j] *= fv;
}
}
}
}
/* Given device values, return an estimate of the */
/* relative Lab value for that color. */
static void icxColorantLu_to_rLab(
icxColorantLu *s,
double Lab[3], /* Output */
double d[ICX_MXINKS] /* Input */
) {
icxColorantLu_to_XYZ(s, Lab, d); /* Compute XYZ */
icmXYZ2Lab(&s->wp, Lab, Lab); /* Convert from XYZ to Lab */
}
/* We're done with aproximate device model */
static void icxColorantLu_del(icxColorantLu *s) {
if (s != NULL) {
free(s);
}
}
/* Given an ink definition, return an aproximate */
/* device to CIE color converted object. */
icxColorantLu *new_icxColorantLu(inkmask mask) {
int i, e;
icxColorantLu *s;
if ((s = (icxColorantLu *)malloc(sizeof(icxColorantLu))) == NULL) {
fprintf(stderr,"icxColorantLu: malloc failed allocating object\n");
exit(-1);
}
/* Initialise methods */
s->del = icxColorantLu_del;
s->dev_to_XYZ = icxColorantLu_to_XYZ;
s->dev_to_rLab = icxColorantLu_to_rLab;
/* Init */
s->mask = mask;
for (e = i = 0; icx_ink_table[i].m != 0; i++) {
if (ICX_WHITE == icx_ink_table[i].m)
s->whix = i;
if (ICX_BLACK == icx_ink_table[i].m)
s->bkix = i;
if (mask & icx_ink_table[i].m)
s->iix[e++] = i;
}
s->di = e;
s->Ynorm = 0.0;
if (mask & ICX_ADDITIVE ) {
for (e = 0; e < s->di; e++)
s->Ynorm += icx_ink_table[s->iix[e]].aXYZ[1];
s->Ynorm = 1.0/s->Ynorm;
icmAry2XYZ(s->wp, icx_ink_table[s->whix].aXYZ);
} else {
icmAry2XYZ(s->wp, icx_ink_table[s->whix].sXYZ);
}
return s;
}

View File

@@ -0,0 +1,359 @@
#ifndef XCOLORANTS_H
#define XCOLORANTS_H
/*
* International Color Consortium color transform expanded support
* Known colorant definitions.
*/
/*
* Author: Graeme W. Gill
* Date: 24/2/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.
*
*/
/* Some standard defines for known generic ink colors */
/*
Note that we don't handle the issue of an arbitrary ink order,
and we are only partially coping with multi-ink ICC profiles
mapping to xcolorants and back. This is supported by mapping
inkmask to ICC ColorantTable names and back (if needed),
or by guessing colorants to match profile (icx_icc_cv_to_colorant_comb()).
default xcolorant order matches the concrete ICC order, but
ICC icSigXXcolorData could be in any order, and xcolorants
currently doesn't handle it.
One way of encapsulating things would be to change inkmask to:
struct {
unsigned int attr; // Attributes (ie. Additive)
unsigned int mask[(ICX_MXINKS + 31)/32]; // Ink masks
int inks[MAX_CHAN]; // icx_ink_table[] index
} inkmask;
Then add appropriate macros & functions to replace current bit mask logic.
Would it be easier to make all Argyll internal handling conform
to the standard xcolorants order, and translate in the ICC file I/O ?
MPP and .ti? files are assumed/made to conform to xcolorants order.
Another change would be to make xcolorants an object,
with dynamic colorant and colorant combination values.
These would be initialised to defaults, but could then
be added to at run time, to support import/export to
other color data formats, and match arbitrary raster
file and ICC profile order etc.
Should add a colorant order structure + lib + created/dump
utility, + re-order function between two of them,
and then this can be given as argument to cctiff.
Would be nice to make cctiff auto re-order input file
if file format allows this.
Handling the "colorant" of non-device type color channels
is also a challenge (ie., Lab, Hsv etc.)
*/
/* Maximum number of simultanious inks allowed for */
#define ICX_MXINKS 31
/* Note that new inks need to be added to icx_ink_table[] in xcolorants.c ! */
/* The type of the inkmask (allow for expansion) */
typedef unsigned int inkmask;
/* The ink mask enumeration */
#define ICX_ADDITIVE 0x80000000 /* Special flag indicating addive colorants */
#define ICX_INVERTED 0x40000000 /* Special flag indicating actual device is */
/* the inverse of the perported additive/subtractive */
#define ICX_CYAN 0x00000001
#define ICX_MAGENTA 0x00000002
#define ICX_YELLOW 0x00000004
#define ICX_BLACK 0x00000008
#define ICX_ORANGE 0x00000010
#define ICX_RED 0x00000020
#define ICX_GREEN 0x00000040
#define ICX_BLUE 0x00000080
#define ICX_VIOLET 0x00000100
#define ICX_WHITE 0x00000200
#define ICX_LIGHT_CYAN 0x00010000
#define ICX_LIGHT_MAGENTA 0x00020000
#define ICX_LIGHT_YELLOW 0x00040000
#define ICX_LIGHT_BLACK 0x00080000
#define ICX_MEDIUM_CYAN 0x00100000
#define ICX_MEDIUM_MAGENTA 0x00200000
#define ICX_MEDIUM_YELLOW 0x00400000
#define ICX_MEDIUM_BLACK 0x00800000
#define ICX_LIGHT_LIGHT_BLACK 0x01000000
/* Character representation */
#define ICX_C_CYAN "C"
#define ICX_C_MAGENTA "M"
#define ICX_C_YELLOW "Y"
#define ICX_C_BLACK "K"
#define ICX_C_ORANGE "O"
#define ICX_C_RED "R"
#define ICX_C_GREEN "G"
#define ICX_C_BLUE "B"
#define ICX_C_VIOLET "V"
#define ICX_C_WHITE "W"
#define ICX_C_LIGHT_CYAN "c"
#define ICX_C_LIGHT_MAGENTA "m"
#define ICX_C_LIGHT_YELLOW "y"
#define ICX_C_LIGHT_BLACK "k"
#define ICX_C_MEDIUM_CYAN "2c"
#define ICX_C_MEDIUM_MAGENTA "2m"
#define ICX_C_MEDIUM_YELLOW "2y"
#define ICX_C_MEDIUM_BLACK "2k"
#define ICX_C_LIGHT_LIGHT_BLACK "1k"
/* Everyday String representation (max 31 chars) */
#define ICX_S_CYAN "Cyan"
#define ICX_S_MAGENTA "Magenta"
#define ICX_S_YELLOW "Yellow"
#define ICX_S_BLACK "Black"
#define ICX_S_ORANGE "Orange"
#define ICX_S_RED "Red"
#define ICX_S_GREEN "Green"
#define ICX_S_BLUE "Blue"
#define ICX_S_VIOLET "Violet"
#define ICX_S_WHITE "White"
#define ICX_S_LIGHT_CYAN "Light Cyan"
#define ICX_S_LIGHT_MAGENTA "Light Magenta"
#define ICX_S_LIGHT_YELLOW "Light Yellow"
#define ICX_S_LIGHT_BLACK "Light Black"
#define ICX_S_MEDIUM_CYAN "Medium Cyan"
#define ICX_S_MEDIUM_MAGENTA "Medium Magenta"
#define ICX_S_MEDIUM_YELLOW "Medium Yellow"
#define ICX_S_MEDIUM_BLACK "Medium Black"
#define ICX_S_LIGHT_LIGHT_BLACK "Light Light Black"
/* Postscript string representation */
#define ICX_PS_CYAN "Cyan"
#define ICX_PS_MAGENTA "Magenta"
#define ICX_PS_YELLOW "Yellow"
#define ICX_PS_BLACK "Black"
#define ICX_PS_ORANGE "Orange"
#define ICX_PS_RED "Red"
#define ICX_PS_GREEN "Green"
#define ICX_PS_BLUE "Blue"
#define ICX_PS_VIOLET "Violet"
#define ICX_PS_WHITE "White"
#define ICX_PS_LIGHT_CYAN "LightCyan"
#define ICX_PS_LIGHT_MAGENTA "LightMagenta"
#define ICX_PS_LIGHT_YELLOW "LightYellow"
#define ICX_PS_LIGHT_BLACK "LightBlack"
#define ICX_PS_MEDIUM_CYAN "MediumCyan"
#define ICX_PS_MEDIUM_MAGENTA "MediumMagenta"
#define ICX_PS_MEDIUM_YELLOW "MediumYellow"
#define ICX_PS_MEDIUM_BLACK "MediumBlack"
#define ICX_PS_LIGHT_LIGHT_BLACK "LightLightBlack"
/* Common colorant combinations */
#define ICX_W /* Video style "grey" */ \
(ICX_ADDITIVE | ICX_WHITE)
#define ICX_RGB /* Classic video RGB */ \
(ICX_ADDITIVE | ICX_RED | ICX_GREEN | ICX_BLUE)
#define ICX_K /* Printer style "grey" */ \
(ICX_BLACK)
#define ICX_CMY /* Classic printing CMY */ \
(ICX_CYAN | ICX_MAGENTA | ICX_YELLOW)
#define ICX_IRGB /* Fake printer RGB (== Inverted CMY) */ \
(ICX_ADDITIVE | ICX_INVERTED | ICX_RED | ICX_GREEN | ICX_BLUE)
#define ICX_CMYK /* Classic printing CMYK */ \
(ICX_CYAN | ICX_MAGENTA | ICX_YELLOW | ICX_BLACK)
#define ICX_CMYKcm /* Your bog standard "6 color" printers */ \
( ICX_CYAN | ICX_MAGENTA | ICX_YELLOW | ICX_BLACK \
| ICX_LIGHT_CYAN | ICX_LIGHT_MAGENTA)
#define ICX_CMYKcmk /* A more unusual "7 color" printer */ \
( ICX_CYAN | ICX_MAGENTA | ICX_YELLOW | ICX_BLACK \
| ICX_LIGHT_CYAN | ICX_LIGHT_MAGENTA | ICX_LIGHT_BLACK)
#define ICX_CMYKcmk1k /* A more unusual "8 color" printer */ \
( ICX_CYAN | ICX_MAGENTA | ICX_YELLOW | ICX_BLACK \
| ICX_LIGHT_CYAN | ICX_LIGHT_MAGENTA | ICX_LIGHT_BLACK \
| ICX_LIGHT_LIGHT_BLACK)
#define ICX_CMYKOG /* A "hexachrome" style extended gamut printer */ \
( ICX_CYAN | ICX_MAGENTA | ICX_YELLOW | ICX_BLACK \
| ICX_ORANGE | ICX_GREEN)
#define ICX_CMYKOGV /* A "hexachrome" + Violet style extended gamut printer */ \
( ICX_CYAN | ICX_MAGENTA | ICX_YELLOW | ICX_BLACK \
| ICX_ORANGE | ICX_GREEN | ICX_VIOLET)
#define ICX_CMYKOGB /* A "hexachrome" + Blue style extended gamut printer */ \
( ICX_CYAN | ICX_MAGENTA | ICX_YELLOW | ICX_BLACK \
| ICX_ORANGE | ICX_GREEN | ICX_BLUE)
#define ICX_CMYKRB /* A 6 color printer with red and blue. */ \
( ICX_CYAN | ICX_MAGENTA | ICX_YELLOW | ICX_BLACK \
| ICX_RED | ICX_BLUE)
#define ICX_CMYKRGB /* A 7 color printer with RGB */ \
( ICX_CYAN | ICX_MAGENTA | ICX_YELLOW | ICX_BLACK \
| ICX_RED | ICX_GREEN | ICX_BLUE)
#define ICX_CMYKOGcm /* An 8 color extended gamut printer */ \
( ICX_CYAN | ICX_MAGENTA | ICX_YELLOW | ICX_BLACK \
| ICX_ORANGE | ICX_GREEN | ICX_LIGHT_CYAN | ICX_LIGHT_MAGENTA)
#define ICX_CMYKcm2c2m /* An 8 color printer that wishes it had variable dot size */ \
( ICX_CYAN | ICX_MAGENTA | ICX_YELLOW | ICX_BLACK \
| ICX_LIGHT_CYAN | ICX_LIGHT_MAGENTA | ICX_MEDIUM_CYAN | ICX_MEDIUM_MAGENTA)
/* ------------------------------------------ */
/* Given an ink combination mask, return the number of recognised inks in it */
int icx_noofinks(inkmask mask);
/* Given an ink combination mask, return the 1-2 character based string */
/* If winv is nz, include ICX_INVERTED indicator if set */
/* Return NULL on error. free() after use */
char *icx_inkmask2char(inkmask mask, int winv);
/* Given the 1-2 character based string, return the ink combination mask */
/* Note that ICX_ADDITIVE will be guessed */
/* Return 0 if unrecognised character in string */
inkmask icx_char2inkmask(char *chstring);
/* Given an ink combination mask that may contain light inks, */
/* return the corresponding ink mask without light inks. */
/* Return 0 if ink combination not recognised. */
inkmask icx_ink2primary_ink(inkmask mask);
/* Given an ink combination mask and a single ink mask, */
/* return the index number for that ink within that set. */
/* Return -1 if mask1 not in mask */
int icx_ink2index(inkmask mask, inkmask mask1);
/* Given an ink combination mask and a index number, */
/* return the single ink mask. */
/* Return 0 if there are no inks at that index */
inkmask icx_index2ink(inkmask mask, int ixno);
/* Given a single ink mask, */
/* return its string representation */
char *icx_ink2string(inkmask mask);
/* Given a single ink mask, */
/* return its 1-2 character representation */
char *icx_ink2char(inkmask mask);
/* Given a single ink mask, */
/* return its Postscript string representation */
char *icx_ink2psstring(inkmask mask);
/* Return an enumerated single colorant description */
/* Return 0 if no such enumeration, single colorant mask if there is */
inkmask icx_enum_colorant(int no, char **desc);
/* Return an enumerated colorant combination inkmask and description */
/* Return 0 if no such enumeration, colorant combination mask if there is */
inkmask icx_enum_colorant_comb(int no, char **desc);
/* Given an colorant combination mask, */
/* check if it matches the given ICC colorspace signature. */
/* return NZ if it does. */
int icx_colorant_comb_match_icc(inkmask mask, icColorSpaceSignature sig);
#ifndef SALONEINSTLIB
/* Given an ICC colorspace signature, return the appropriate */
/* colorant combination mask. Return 0 if ambiguous signature. */
inkmask icx_icc_to_colorant_comb(icColorSpaceSignature sig, icProfileClassSignature deviceClass);
/* Given an ICC colorspace signature, and a matching list */
/* of the D50 L*a*b* colors of the colorants, return the best matching */
/* colorant combination mask. Return 0 if not applicable to colorspace. */
inkmask icx_icc_cv_to_colorant_comb(icColorSpaceSignature sig, icProfileClassSignature deviceClass,
double cvals[][3]);
#endif /* !SALONEINSTLIB */
/* Given an colorant combination mask */
/* return the primary matching ICC colorspace signature. */
/* return 0 if there is no match */
icColorSpaceSignature icx_colorant_comb_to_icc(inkmask mask);
/* --------------------------------------------------------- */
/* An aproximate device colorant model object lookup object: */
struct _icxColorantLu {
/* Public: */
void (*del)(struct _icxColorantLu *s); /* We're done with it */
/* Conversions */
void (*dev_to_XYZ)(struct _icxColorantLu *s, double *out, double *in); /* Absolute */
void (*dev_to_rLab)(struct _icxColorantLu *s, double *out, double *in); /* Relative */
/* Private: */
inkmask mask; /* Colorant mask for this instance */
int di; /* Dimensionality */
int whix, bkix; /* White and Black Indexes into icx_inkTable[] */
icmXYZNumber wp; /* White point XYZ value */
int iix[ICX_MXINKS]; /* Device Indexes into icx_inkTable[] */
double Ynorm; /* Y normalisation factor for Additive */
}; typedef struct _icxColorantLu icxColorantLu;
/* Create a icxColorantLu conversion object */
icxColorantLu *new_icxColorantLu(inkmask mask);
#endif /* XCOLORANTS_H */

View File

@@ -0,0 +1,228 @@
/*
* xcolorant lookup/test utility
*
* Author: Graeme W. Gill
* Date: 24/4/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:
*
*/
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <fcntl.h>
#include <string.h>
#include <math.h>
#include "icc.h"
#include "xcolorants.h"
void error(char *fmt, ...), warning(char *fmt, ...);
void usage(void) {
fprintf(stderr,"Translate colors through xcolorant model, V1.00\n");
fprintf(stderr,"Author: Graeme W. Gill\n");
fprintf(stderr,"usage: xcolorantlu \n");
fprintf(stderr," -v Verbose\n");
fprintf(stderr," -a Additive model (default subtractive)\n");
fprintf(stderr," -m mask Colorant mask combination, from:\n");
fprintf(stderr," C Cyan\n");
fprintf(stderr," M Magenta\n");
fprintf(stderr," Y Yellow\n");
fprintf(stderr," K Black\n");
fprintf(stderr," O Orange\n");
fprintf(stderr," R Red\n");
fprintf(stderr," G Green\n");
fprintf(stderr," B Blue\n");
fprintf(stderr," W White\n");
fprintf(stderr," c Light Cyan\n");
fprintf(stderr," m Light Magenta\n");
fprintf(stderr," y Light Yellow\n");
fprintf(stderr," k Light Black\n");
fprintf(stderr," 2c Medium Cyan\n");
fprintf(stderr," 2m Medium Magenta\n");
fprintf(stderr," 2y Medium Yellow\n");
fprintf(stderr," 2k Medium Black\n");
fprintf(stderr," -x XYZ output (default L*a*b*)\n");
fprintf(stderr,"\n");
fprintf(stderr," The colors to be translated should be fed into stdin,\n");
fprintf(stderr," one input color per line, white space separated.\n");
fprintf(stderr," A line starting with a # will be ignored.\n");
fprintf(stderr," A line not starting with a number will terminate the program.\n");
exit(1);
}
int
main(int argc, char *argv[]) {
int fa,nfa; /* argument we're looking at */
int verb = 0;
int rv = 0;
int mask = 0;
int xyz = 0;
char buf[200];
double in[MAX_CHAN], out[MAX_CHAN];
int inn, outn = 3;
icxColorantLu *luo;
char *ident;
char *odent;
if (argc < 2)
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;
}
/* Additive */
else if (argv[fa][1] == 'a' || argv[fa][1] == 'A') {
mask ^= ICX_ADDITIVE;
}
/* XYZ output */
else if (argv[fa][1] == 'x' || argv[fa][1] == 'X') {
verb = 1;
}
/* Mask */
else if (argv[fa][1] == 'm' || argv[fa][1] == 'm') {
int tm;
fa = nfa;
if (na == NULL) usage();
if ((tm = icx_char2inkmask(na)) == 0)
usage();
mask ^= tm;
}
else
usage();
} else
break;
}
inn = icx_noofinks(mask);
/* Create a icxColorantLu conversion object */
if ((luo = new_icxColorantLu(mask)) == NULL)
error ("Creating xcolorant lookup failed\n");
ident = icx_inkmask2char(mask, 1);
if (xyz)
odent = "XYZ";
else
odent = "Lab";
/* Process colors to translate */
for (;;) {
int i,j;
char *bp, *nbp;
/* Read in the next line */
if (fgets(buf, 200, stdin) == NULL)
break;
if (buf[0] == '#') {
fprintf(stdout,"%s\n",buf);
continue;
}
/* For each input number */
for (nbp = buf, i = 0; i < MAX_CHAN; i++) {
bp = nbp;
in[i] = strtod(bp, &nbp);
if (nbp == bp)
break; /* Failed */
}
if (i == 0)
break;
/* Do conversion */
if (xyz)
luo->dev_to_XYZ(luo, out, in);
else
luo->dev_to_rLab(luo, out, in);
/* Output the results */
for (j = 0; j < inn; j++) {
if (j > 0)
fprintf(stdout," %f",in[j]);
else
fprintf(stdout,"%f",in[j]);
}
printf(" [%s] -> ", ident);
for (j = 0; j < outn; j++) {
if (j > 0)
fprintf(stdout," %f",out[j]);
else
fprintf(stdout,"%f",out[j]);
}
printf(" [%s]", odent);
if (rv == 0)
fprintf(stdout,"\n");
else
fprintf(stdout," (clip)\n");
}
/* Done with lookup object */
luo->del(luo);
free(ident);
return 0;
}
/* 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");
}

View File

@@ -0,0 +1,709 @@
/*
* View inv fwd table device interp of an ICC file, V1.23\n");
*
* Author: Graeme W. Gill
* Date: 2000/12/8
* Version: 1.23
*
* Copyright 2000 Graeme W. Gill
* Please refer to License.txt file for details.
*/
/* TTBD:
*
* Should reject device link profiles ?
*
*/
#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 "conv.h"
#include "xicc.h"
#include "vrml.h"
#define RW 0.5 /* PCS Delta */
//#define FLAGS ICX_CLIP_NEAREST | ICX_CAM_CLIP | ICX_FAST_SETUP
//#define FLAGS ICX_CLIP_NEAREST | ICX_CAM_CLIP
//#define FLAGS ICX_CLIP_NEAREST | ICX_FAST_SETUP
#define FLAGS ICX_CLIP_NEAREST
/* - - - - - - - - - - - - - */
/* Return maximum difference */
double maxdiff(double in1[3], double in2[3]) {
double tt, rv = 0.0;
if ((tt = fabs(in1[0] - in2[0])) > rv)
rv = tt;
if ((tt = fabs(in1[1] - in2[1])) > rv)
rv = tt;
if ((tt = fabs(in1[2] - in2[2])) > rv)
rv = tt;
return rv;
}
/* Return absolute difference */
double absdiff(double in1[3], double in2[3]) {
double tt, rv = 0.0;
tt = in1[0] - in2[0];
rv += tt * tt;
tt = in1[1] - in2[1];
rv += tt * tt;
tt = in1[2] - in2[2];
rv += tt * tt;
return sqrt(rv);
}
/* ---------------------------------------- */
void usage(void) {
fprintf(stderr,"View inv fwd table device interp of an ICC file, Version %s\n",ARGYLL_VERSION_STR);
fprintf(stderr,"Author: Graeme W. Gill, licensed under the AGPL Version 3\n");
fprintf(stderr,"usage: fbtest [options] infile\n");
fprintf(stderr," -v verbose\n");
fprintf(stderr," -f Add PCS -inv(a2b)- device -a2b- PCS Vectors\n");
fprintf(stderr," -d Add ave(PCS + 4 x a*b* variations -inv(a2b)- device) -a2b- PCS\n");
fprintf(stderr," -b Add PCS -b2a- device -a2b- PCS Vectors\n");
fprintf(stderr," -e Add dif between inv(a2b) and b2a cliped vectors\n");
fprintf(stderr," -r res Resolution of test grid [Def 33]\n");
fprintf(stderr," -g Do full grid, not just cube\n");
fprintf(stderr," -a Do all values, not just clipped ones\n");
fprintf(stderr," -l tlimit set total ink limit, 0 - 400%% (estimate by default)\n");
fprintf(stderr," -L klimit set black ink limit, 0 - 100%% (estimate by default)\n");
fprintf(stderr," [[ output is infile.wrl ]]\n");
exit(1);
}
int
main(
int argc,
char *argv[]
) {
int fa,nfa; /* argument we're looking at */
int verb = 0;
int doaxes = 0;
double tlimit = -1.0; /* Total ink limit */
double klimit = -1.0; /* Black ink limit */
int tres = 33;
int doref = 0; /* Show reference lookups */
int dodelta = 0; /* Show device interp delta variation */
int dob2a = 0; /* Show B2A lookups */
int doeee = 0; /* Show clipped ref PCS to B2A clipped PCS */
int dogrid = 0; /* Do full grid, not just cube */
int doclip = 1; /* Do just clipped values */
static char in_name[MAXNAMEL+1];
static char *xl, out_name[MAXNAMEL+1];
icmFile *rd_fp;
icc *rd_icco;
icmErr err = { 0, { '\000'} };
int rv = 0;
icColorSpaceSignature ins, outs; /* Type of input and output spaces */
int inn; /* Number of device values */
double abscale = 128.0;
error_program = argv[0];
if (argc < 2)
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 */
}
}
}
/* Verbosity */
if (argv[fa][1] == 'v') {
verb = 1;
}
/* Show reference */
else if (argv[fa][1] == 'f') {
doref = 1;
}
/* Show device delta variation */
else if (argv[fa][1] == 'd') {
dodelta = 1;
}
/* Show B2A table lookup */
else if (argv[fa][1] == 'b') {
dob2a = 1;
}
/* Show reference clipped PCS to clipped B2A PCS */
else if (argv[fa][1] == 'e') {
doeee = 1;
}
/* Do full grid, not just cube */
else if (argv[fa][1] == 'g') {
dogrid = 1;
}
/* Do all values, not just clipped ones */
else if (argv[fa][1] == 'a') {
doclip = 0;
}
/* Ink limit */
else if (argv[fa][1] == 'l') {
fa = nfa;
if (na == NULL) usage();
tlimit = atoi(na)/100.0;
}
else if (argv[fa][1] == 'L') {
fa = nfa;
if (na == NULL) usage();
klimit = atoi(na)/100.0;
}
/* Resolution */
else if (argv[fa][1] == 'r') {
fa = nfa;
if (na == NULL) usage();
tres = atoi(na);
}
else if (argv[fa][1] == '?')
usage();
else
usage();
}
else
break;
}
if (fa >= argc || argv[fa][0] == '-') usage();
strncpy(in_name,argv[fa++],MAXNAMEL); in_name[MAXNAMEL] = '\000';
strcpy(out_name, in_name);
if ((xl = strrchr(out_name, '.')) == NULL) /* Figure where extention is */
xl = out_name + strlen(out_name);
xl[0] = '\000'; /* Remove extension */
/* Open up the file for reading */
if ((rd_fp = new_icmFileStd_name(&err,in_name,"r")) == NULL)
error ("Read: Can't open file '%s' (0x%x, '%s')",in_name,err.c,err.m);
if ((rd_icco = new_icc(&err)) == NULL)
error ("Read: Creation of ICC object failed (0x%x, '%s')",err.c,err.m);
/* Read the header and tag list */
if ((rv = rd_icco->read(rd_icco,rd_fp,0)) != 0)
error ("Read: %d, %s",rv,rd_icco->e.m);
/* Run the target Lab values through the bwd and fwd tables, */
/* to compute the overall error. */
{
#define GAMUT_LCENT 50.0
xicc *xicco;
icxLuBase *luo;
icxInk ink; /* Ink parameters */
vrml *wrl;
struct {
double x, y, z;
double wx, wy, wz;
double r, g, b;
} axes[5] = {
{ 0, 0, 50-GAMUT_LCENT, 2, 2, 100, .7, .7, .7 }, /* L axis */
{ 50, 0, 0-GAMUT_LCENT, 100, 2, 2, 1, 0, 0 }, /* +a (red) axis */
{ 0, -50, 0-GAMUT_LCENT, 2, 100, 2, 0, 0, 1 }, /* -b (blue) axis */
{ -50, 0, 0-GAMUT_LCENT, 100, 2, 2, 0, 1, 0 }, /* -a (green) axis */
{ 0, 50, 0-GAMUT_LCENT, 2, 100, 2, 1, 1, 0 }, /* +b (yellow) axis */
};
int coa[4];
int i, j;
/* Wrap with an expanded icc */
if ((xicco = new_xicc(rd_icco)) == NULL)
error ("Creation of xicc failed");
/* Set the default ink limits if not set on command line */
icxDefaultLimits(xicco, &ink.tlimit, tlimit, &ink.klimit, klimit);
if (verb) {
if (ink.tlimit >= 0.0)
printf("Total ink limit assumed is %3.0f%%\n",100.0 * ink.tlimit);
if (ink.klimit >= 0.0)
printf("Black ink limit assumed is %3.0f%%\n",100.0 * ink.klimit);
}
ink.c.Ksmth = ICXINKDEFSMTH; /* Default smoothing */
ink.c.Kskew = ICXINKDEFSKEW; /* default curve skew */
ink.c.Kstle = 0.5; /* Min K at white end */
ink.c.Kstpo = 0.5; /* Start of transition is at white */
ink.c.Kenle = 0.5; /* Max K at black end */
ink.c.Kenpo = 0.5; /* End transition at black */
ink.c.Kshap = 1.0; /* Linear transition */
/* Get a Device to PCS conversion object */
if ((luo = xicco->get_luobj(xicco, FLAGS, icmFwd, icAbsoluteColorimetric, icSigLabData, icmLuOrdNorm, NULL, &ink)) == NULL) {
if ((luo = xicco->get_luobj(xicco, FLAGS, icmFwd, icmDefaultIntent, icSigLabData, icmLuOrdNorm, NULL, &ink)) == NULL)
error ("%d, %s",rd_icco->e.c, rd_icco->e.m);
}
/* Get details of conversion */
luo->spaces(luo, &ins, &inn, &outs, NULL, NULL, NULL, NULL, NULL);
if (ins != icSigCmykData
&& ins != icSigRgbData) {
error("Expecting RGB or CMYK device");
}
if ((wrl = new_vrml(out_name, doaxes, vrml_lab)) == NULL) {
fprintf(stderr,"new_vrml failed for '%s%s'\n",out_name,vrml_ext());
return 2;
}
/* ---------------------------------------------- */
/* Clipping vectors of inverse a2b */
/* PCS -inv(a2b)- device -a2b- PCS Vectors */
/* PCS -> device -> PCS */
if (doref) {
double rgb[3];
if (verb)
printf("Adding PCS -inv(a2b)- device -a2b- PCS Vectors \n");
wrl->start_line_set(wrl, 0);
i = 0;
/* For range of PCS values */
for (coa[0] = 0; coa[0] < tres; coa[0]++) {
for (coa[1] = 0; coa[1] < tres; coa[1]++) {
for (coa[2] = 0; coa[2] < tres; coa[2]++) {
double in[4], dev[4], out[4];
double temp[4];
int rv1, rv2;
if (!dogrid
&& coa[0] != 0 && coa[0] != (tres-1)
&& coa[1] != 0 && coa[1] != (tres-1)
&& coa[2] != 0 && coa[2] != (tres-1)) {
continue;
}
temp[0] = coa[0]/(tres-1.0);
temp[1] = coa[1]/(tres-1.0);
temp[2] = coa[2]/(tres-1.0);
/* PCS values */
in[0] = temp[0] * 100.0;
in[1] = abscale * 2.0 * (temp[1] - 0.5);
in[2] = abscale * 2.0 * (temp[2] - 0.5);
/* Do reference lookup */
/* PCS -> Device */
if ((rv2 = luo->inv_lookup(luo, dev, in)) > 1)
error ("%d, %s",rd_icco->e.c,rd_icco->e.m);
if (doclip && rv2 != 1) /* Not clip */
continue;
/* Device -> PCS */
if ((rv1 = luo->lookup(luo, out, dev)) > 1)
error ("%d, %s",rd_icco->e.c,rd_icco->e.m);
if (verb)
printf("."), fflush(stdout);
/* Input PCS to ideal (Inverse AtoB) clipped PCS values */
wrl->add_vertex(wrl, 0, in);
wrl->add_vertex(wrl, 0, out);
i++;
}
}
}
if (verb)
printf("\n");
for (j = 0; j < i; j++) {
int ix[2];
ix[0] = j * 2;
ix[1] = j * 2 +1;
wrl->add_line(wrl, 0, ix);
}
rgb[0] = 1.0;
rgb[1] = 0.1;
rgb[2] = 0.1;
wrl->make_lines_cc(wrl, 0, 0.0, rgb);
}
/* ---------------------------------------------- */
/* Clipping vectors of average around PCS of inverse a2b */
/* Average of(PCS + 4 x a*b* variations -inv(a2b)- device) -a2b- PCS */
if (dodelta) {
double rgb[3];
if (verb)
printf("Adding ave(PCS + 4 x a*b* variations -inv(a2b)- device) -a2b- PCS\n");
wrl->start_line_set(wrl, 0);
i = 0;
/* For Lab values */
for (coa[0] = 0; coa[0] < tres; coa[0]++) {
for (coa[1] = 0; coa[1] < tres; coa[1]++) {
for (coa[2] = 0; coa[2] < tres; coa[2]++) {
double in[4], dev[4], out[4];
double in4[4], check[4];
double temp[4], adev[4];
double dev0[4], dev1[4], dev2[4], dev3[4];
int rv1, rv2;
if (!dogrid
&& coa[0] != 0
&& coa[0] != (tres-1)
&& coa[1] != 0
&& coa[1] != (tres-1)
&& coa[2] != 0
&& coa[2] != (tres-1))
continue;
temp[0] = coa[0]/(tres-1.0);
temp[1] = coa[1]/(tres-1.0);
temp[2] = coa[2]/(tres-1.0);
in[0] = temp[0] * 100.0;
in[1] = abscale * 2.0 * (temp[1] - 0.5);
in[2] = abscale * 2.0 * (temp[2] - 0.5);
/* Do reference lookup */
/* PCS -> ideal Device */
if ((rv2 = luo->inv_lookup(luo, dev, in)) > 1)
error ("%d, %s",rd_icco->e.c,rd_icco->e.m);
if (doclip && rv2 != 1) /* Not clip */
continue;
/* Device -> PCS check value - not used */
if ((rv1 = luo->lookup(luo, check, dev)) > 1)
error ("%d, %s",rd_icco->e.c,rd_icco->e.m);
/* - - - - - - - - - - - - - - - */
/* Now do average in device space of two points */
temp[0] = coa[0]/(tres-1.0);
temp[1] = (coa[1]-RW)/(tres-1.0);
temp[2] = (coa[2]-RW)/(tres-1.0);
in4[0] = temp[0] * 100.0;
in4[1] = abscale * 2.0 * (temp[1] - 0.5);
in4[2] = abscale * 2.0 * (temp[2] - 0.5);
/* PCS -> Device */
if ((rv2 = luo->inv_lookup(luo, dev0, in4)) > 1)
error ("%d, %s",rd_icco->e.c,rd_icco->e.m);
adev[0] = 0.25 * dev0[0];
adev[1] = 0.25 * dev0[1];
adev[2] = 0.25 * dev0[2];
adev[3] = 0.25 * dev0[3];
temp[0] = coa[0]/(tres-1.0);
temp[1] = (coa[1]+RW)/(tres-1.0);
temp[2] = (coa[2]-RW)/(tres-1.0);
in4[0] = temp[0] * 100.0;
in4[1] = abscale * 2.0 * (temp[1] - 0.5);
in4[2] = abscale * 2.0 * (temp[2] - 0.5);
/* PCS -> Device */
if ((rv2 = luo->inv_lookup(luo, dev1, in4)) > 1)
error ("%d, %s",rd_icco->e.c,rd_icco->e.m);
adev[0] += 0.25 * dev1[0];
adev[1] += 0.25 * dev1[1];
adev[2] += 0.25 * dev1[2];
adev[3] += 0.25 * dev1[3];
temp[0] = coa[0]/(tres-1.0);
temp[1] = (coa[1]-RW)/(tres-1.0);
temp[2] = (coa[2]+RW)/(tres-1.0);
in4[0] = temp[0] * 100.0;
in4[1] = abscale * 2.0 * (temp[1] - 0.5);
in4[2] = abscale * 2.0 * (temp[2] - 0.5);
/* PCS -> Device */
if ((rv2 = luo->inv_lookup(luo, dev2, in4)) > 1)
error ("%d, %s",rd_icco->e.c,rd_icco->e.m);
adev[0] += 0.25 * dev2[0];
adev[1] += 0.25 * dev2[1];
adev[2] += 0.25 * dev2[2];
adev[3] += 0.25 * dev2[3];
temp[0] = coa[0]/(tres-1.0);
temp[1] = (coa[1]+RW)/(tres-1.0);
temp[2] = (coa[2]+RW)/(tres-1.0);
in4[0] = temp[0] * 100.0;
in4[1] = abscale * 2.0 * (temp[1] - 0.5);
in4[2] = abscale * 2.0 * (temp[2] - 0.5);
/* PCS -> Device */
if ((rv2 = luo->inv_lookup(luo, dev3, in4)) > 1)
error ("%d, %s",rd_icco->e.c,rd_icco->e.m);
adev[0] += 0.25 * dev3[0];
adev[1] += 0.25 * dev3[1];
adev[2] += 0.25 * dev3[2];
adev[3] += 0.25 * dev3[3];
/* Average device -> PCS */
if ((rv1 = luo->lookup(luo, out, adev)) > 1)
error ("%d, %s",rd_icco->e.c,rd_icco->e.m);
if (verb)
printf("."), fflush(stdout);
wrl->add_vertex(wrl, 0, in);
wrl->add_vertex(wrl, 0, out);
i++;
}
}
}
if (verb)
printf("\n");
for (j = 0; j < i; j++) {
int ix[2];
ix[0] = j * 2;
ix[1] = j * 2 +1;
wrl->add_line(wrl, 0, ix);
}
rgb[0] = 0.9;
rgb[1] = 0.9;
rgb[2] = 0.9;
wrl->make_lines_cc(wrl, 0, 0.0, rgb);
}
/* ---------------------------------------------- */
/* Clipping vectors of b2a */
/* PCS -b2a- device -a2b- PCS Vectors */
if (dob2a) {
double rgb[3];
icxLuBase *luoB;
wrl->start_line_set(wrl, 0);
/* Get a B2A (PCS to Device) conversion object */
if ((luoB = xicco->get_luobj(xicco, FLAGS, icmBwd, icAbsoluteColorimetric,
icSigLabData, icmLuOrdNorm, NULL, &ink)) == NULL) {
if ((luoB = xicco->get_luobj(xicco, FLAGS, icmBwd, icmDefaultIntent,
icSigLabData, icmLuOrdNorm, NULL, &ink)) == NULL)
error ("%d, %s",rd_icco->e.c, rd_icco->e.m);
}
if (verb)
printf("Adding PCS -b2a- device -a2b- PCS Vectors\n");
i = 0;
/* For PCS values */
for (coa[0] = 0; coa[0] < tres; coa[0]++) {
for (coa[1] = 0; coa[1] < tres; coa[1]++) {
for (coa[2] = 0; coa[2] < tres; coa[2]++) {
double in[4], dev[4], out[4];
double temp[4];
int rv1, rv2;
if (!dogrid
&& coa[0] != 0
&& coa[0] != (tres-1)
&& coa[1] != 0
&& coa[1] != (tres-1)
&& coa[2] != 0
&& coa[2] != (tres-1))
continue;
temp[0] = coa[0]/(tres-1.0);
temp[1] = coa[1]/(tres-1.0);
temp[2] = coa[2]/(tres-1.0);
in[0] = temp[0] * 100.0;
in[1] = abscale * 2.0 * (temp[1] - 0.5);
in[2] = abscale * 2.0 * (temp[2] - 0.5);
/* PCS -> Device */
if ((rv2 = luoB->lookup(luoB, dev, in)) > 1)
error ("%d, %s",rd_icco->e.c,rd_icco->e.m);
if (doclip && rv2 != 1) /* Not clip */
continue;
/* Device -> PCS */
if ((rv1 = luo->lookup(luo, out, dev)) > 1)
error ("%d, %s",rd_icco->e.c,rd_icco->e.m);
if (verb)
printf("."), fflush(stdout);
wrl->add_vertex(wrl, 0, in);
wrl->add_vertex(wrl, 0, out);
i++;
}
}
}
if (verb)
printf("\n");
for (j = 0; j < i; j++) {
int ix[2];
ix[0] = j * 2;
ix[1] = j * 2 +1;
wrl->add_line(wrl, 0, ix);
}
rgb[0] = 0.9;
rgb[1] = 0.9;
rgb[2] = 0.9;
wrl->make_lines_cc(wrl, 0, 0.0, rgb);
luoB->del(luoB);
}
/* ---------------------------------------------- */
/* Difference between:
PCS -inv(a2b)- device -a2b- PCS
and
PCS -b2a- device -a2b- PCS
*/
if (doeee) {
double rgb[3];
icxLuBase *luoB;
wrl->start_line_set(wrl, 0);
/* Get a PCS to Device conversion object */
if ((luoB = xicco->get_luobj(xicco, FLAGS, icmBwd, icAbsoluteColorimetric,
icSigLabData, icmLuOrdNorm, NULL, &ink)) == NULL) {
if ((luoB = xicco->get_luobj(xicco, FLAGS, icmBwd, icmDefaultIntent,
icSigLabData, icmLuOrdNorm, NULL, &ink)) == NULL)
error ("%d, %s",rd_icco->e.c, rd_icco->e.m);
}
if (verb)
printf("Adding difference between inv(a2b) and b2a cliped vectors\n");
i = 0;
for (coa[0] = 0; coa[0] < tres; coa[0]++) {
for (coa[1] = 0; coa[1] < tres; coa[1]++) {
for (coa[2] = 0; coa[2] < tres; coa[2]++) {
double in[4], dev[4], out[4];
double check[4];
double temp[4];
int rv1, rv2;
if (!dogrid
&& coa[0] != 0
&& coa[0] != (tres-1)
&& coa[1] != 0
&& coa[1] != (tres-1)
&& coa[2] != 0
&& coa[2] != (tres-1))
continue;
temp[0] = coa[0]/(tres-1.0);
temp[1] = coa[1]/(tres-1.0);
temp[2] = coa[2]/(tres-1.0);
in[0] = temp[0] * 100.0;
in[1] = abscale * 2.0 * (temp[1] - 0.5);
in[2] = abscale * 2.0 * (temp[2] - 0.5);
/* Do reference lookup using inverse a2b */
/* PCS -> Device */
if ((rv1 = luo->inv_lookup(luo, dev, in)) > 1)
error ("%d, %s",rd_icco->e.c,rd_icco->e.m);
/* Device -> PCS */
if (luo->lookup(luo, check, dev) > 1)
error ("%d, %s",rd_icco->e.c,rd_icco->e.m);
/* Do B2A table lookup */
/* PCS -> Device */
if ((rv2 = luoB->lookup(luoB, dev, in)) > 1)
error ("%d, %s",rd_icco->e.c,rd_icco->e.m);
/* Device -> PCS */
if (luo->lookup(luo, out, dev) > 1)
error ("%d, %s",rd_icco->e.c,rd_icco->e.m);
if (doclip && rv1 != 1 && rv2 != 1) /* Not clip */
continue;
if (verb)
printf("."), fflush(stdout);
wrl->add_vertex(wrl, 0, check);
wrl->add_vertex(wrl, 0, out);
i++;
}
}
}
if (verb)
printf("\n");
for (j = 0; j < i; j++) {
int ix[2];
ix[0] = j * 2;
ix[1] = j * 2 +1;
wrl->add_line(wrl, 0, ix);
}
rgb[0] = 0.9;
rgb[1] = 0.9;
rgb[2] = 0.9;
wrl->make_lines_cc(wrl, 0, 0.0, rgb);
luoB->del(luoB);
}
/* ---------------------------------------------- */
if (wrl->flush(wrl) != 0) {
fprintf(stderr,"Error closing output file '%s%s'\n",out_name,vrml_ext());
return 2;
}
wrl->del(wrl);
/* Done with lookup object */
luo->del(luo);
xicco->del(xicco);
}
rd_icco->del(rd_icco);
rd_fp->del(rd_fp);
return 0;
}

3150
Argyll_V3.5.0/xicc/xfit.c Normal file

File diff suppressed because it is too large Load Diff

243
Argyll_V3.5.0/xicc/xfit.h Normal file
View File

@@ -0,0 +1,243 @@
#ifndef XFIT_H
#define XFIT_H
/*
* Clut per channel curve fitting
*
* Author: Graeme W. Gill
* Date: 27/5/2007
* Version: 1.00
*
* Copyright 2000 - 2007 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.
*
* Based on the rspl.c and xlut.c code.
*/
#define MXLUORD 60 /* Maximum possible shaper harmonic orders to use */
#define PCSD 3 /* PCS dimensions */
#define MXPARMS (2 * MXDI * MXLUORD + (1 << MXDI) * MXDO + MXDO * MXLUORD)
#define MAX_NTP 11 /* Maximum test points within spans */
/* Optimisation mask legal combinations */
typedef enum {
oc_i = 1, /* Input Shaper curve */
oc_p = 2, /* Input Positioning curve */
oc_m = 4, /* Temporary matrix */
oc_o = 8, /* Output */
oc_io = oc_i + oc_o,
oc_im = oc_i + oc_m,
oc_mo = oc_m + oc_o,
oc_imo = oc_i + oc_m + oc_o,
oc_pm = oc_p + oc_m,
oc_pmo = oc_p + oc_m + oc_o,
oc_ip = oc_i + oc_p,
oc_ipo = oc_i + oc_p + oc_o
} optcomb;
/* Flag values */
#define XFIT_VERB 0x0001 /* Verbose output during fitting */
#define XFIT_FM_INPUT 0x0002 /* Use input space for fit metric (default is output) */
#define XFIT_IN_ZERO 0x0004 /* Adjust input curves 1 & 2 for zero (~~not impd. yet) */
#define XFIT_OPTGRID_RANGE 0x0008 /* Optimize inner grid around used range (~~not impd. yet) */
#define XFIT_OUT_WP_REL 0x0010 /* Extract the white point and make output relative */
#define XFIT_OUT_WP_REL_US 0x0030 /* Same as above but scale to avoid clipping above WP */
#define XFIT_OUT_WP_REL_C 0x0050 /* Same as above but clip any cLUT values over D50 */
#define XFIT_CLIP_WP 0x0080 /* Clip white point to have Y <= 1.0 (conflict with above) */
#define XFIT_OUT_LAB 0x0100 /* Output space is LAB else XYZ for reading WP */
#define XFIT_OUT_ZERO 0x0200 /* Adjust output curves 1 & 2 for zero */
#define XFIT_MAKE_CLUT 0x1000 /* Create rspl clut, even if not needed */
/* xfit reverse transform information for each test point */
typedef struct {
double ide[MXDO][MXDI]; /* pseudo inverse: rout -> in */
} xfit_piv;
/* Context for optimising input and output luts */
struct _xfit {
icc *picc; /* ICC profile used to set cone space matrix, NULL for Bradford. */
int verb; /* Verbose */
int flags; /* Behaviour flags */
int di, fdi; /* Dimensionaluty of input and output */
optcomb tcomb; /* Target 1D curve elements to fit */
icxMatrixModel *skm; /* Optional skeleton model (used for input profiles) */
double *wp; /* Ref. to current white point if XFIT_OUT_WP_REL */
double *dw; /* Ref. to device value that should map to D50 if XFIT_OUT_WP_REL */
double fromAbs[3][3]; /* From abs to relative (used by caller) */
double toAbs[3][3]; /* To abs from relative (used by caller) */
int gres[MXDI]; /* clut resolutions being optimised for */
rspl *clut; /* final rspl clut */
void *cntx2; /* Context of callback */
double (*to_de2)(void *cntx, double *in1, double *in2);
/* callback to convert in or out value to fit metric squared */
double (*to_dde2)(void *cntx, double dout[2][MXDIDO], double *in1, double *in2);
/* Same, but with partial derivatives */
int iluord[MXDI]; /* Input Shaper order actualy used (must be <= MXLUORD) */
int sm_iluord; /* Smallest Input Shaper order used */
int oluord[MXDO]; /* Output Shaper order actualy used (must be <= MXLUORD) */
int sluord[MXDI]; /* Sub-grid shaper order */
double in_min[MXDI]; /* Input value scaling minimum */
double in_max[MXDI]; /* Input value scaling maximum */
double out_min[MXDO]; /* Output value scaling minimum */
double out_max[MXDO]; /* Output value scaling maximum */
int shp_off; /* Input parameters offset */
int shp_offs[MXDI]; /* Input parameter offsets for each in channel from v[0] */
int shp_cnt; /* Input parameters count */
int mat_off; /* Matrix parameters offset from v[0] */
int mat_offs[MXDO]; /* Matrix parameter offsets for each out channel from v[0] */
int mat_cnt; /* Matrix parameters count */
int out_off; /* Output parameters offset from v[0] */
int out_offs[MXDO]; /* Output parameter offsets for each out channel from v[0] */
int out_cnt; /* Output parameters count */
int pos_off; /* Position parameters offset */
int pos_offs[MXDI]; /* Position parameter offsets for each in channel from v[0] */
int pos_cnt; /* Position parameters count */
int tot_cnt; /* Total parameter count */
double *v; /* Holder for parameters */
/* Optimisation parameters are layed out: */
/* */
/* Input pos or shape curves:, di groups of iluord[e] parameters */
/* */
/* (temp) Matrix: fdi groups of 2 ^ di parameters */
/* */
/* Output curves:, fdi groups of oluord[f] parameters */
/* */
/* Shaper curves:, di groups of iluord[e] parameters */
/* */
int nodp; /* Number of data points */
cow *ipoints; /* Reference to test points as in->out */
cow *rpoints; /* Modified version of ipoints */
xfit_piv *piv; /* Point inverse information for XFIT_FM_INPUT */
double *uerrv; /* Array holding span width in DE for current opt chan */
double mat[3][3]; /* XYZ White point aprox relative to accurate relative matrix */
double cmat[3][3]; /* Final rspl correction matrix */
double shp_smooth[MXDI];/* Smoothing factors for each input shape curve, nom = 1.0 */
double out_smooth[MXDO];
/* Optimisation state */
optcomb opt_msk; /* Optimisation mask: 3 = i+m, 2 = m, 6 = m+o, 7 = i+m+o */
int opt_ssch; /* Single shaper channel mode flag */
int opt_off; /* Optimisation parameters offset from v[0] */
int opt_cnt; /* Optimisation parameters count */
double *wv; /* Parameters being optimised */
double *sa; /* Search area */
int opt_ch; /* Channel being optimized */
/* Methods */
void (*del)(struct _xfit *p);
/* Do the fitting. Return nz on error */
int (*fit)(
struct _xfit *p,
int flags, /* Xfit flag values */
int di, /* Input dimensions */
int fdi, /* Output dimensions */
int rsplflags, /* clut rspl creation flags */
double *wp, /* if flags & XFIT_OUT_WP_REL, */
/* Initial white point, returns final wp */
double *dw, /* Device white value to adjust to be D50 */
double wpscale, /* If >= 0.0 scale final wp */
double *dgw, /* Device space gamut boundary white for XFIT_OUT_WP_REL_US */
/* (ie. RGB 1,1,1 CMYK 0,0,0,0, etc) */
cow *ipoints, /* Array of data points to fit - referece taken */
int nodp, /* Number of data points */
icxMatrixModel *skm, /* Optional skeleton model (used for input profiles) */
double in_min[MXDI], /* Input value scaling/domain minimum */
double in_max[MXDI], /* Input value scaling/domain maximum */
int gres[MXDI], /* clut resolutions being optimised for/returned */
double out_min[MXDO], /* Output value scaling/range minimum */
double out_max[MXDO], /* Output value scaling/range maximum */
double smooth, /* clut rspl smoothing factor */
double oavgdev[MXDO], /* Average output value deviation */
double demph, /* dark emphasis factor for cLUT grid res. */
int iord[], /* Order of input positioning/shaper curve for each dimension */
int sord[], /* Order of input sub-grid shaper curve (not used) */
int oord[], /* Order of output shaper curve for each dimension */
double shp_smooth[MXDI],/* Smoothing factors for each curve, nom = 1.0 */
double out_smooth[MXDO],
optcomb tcomb, /* Flag - target elements to fit. */
void *cntx2, /* Context of callbacks */
/* Callback to convert two fit values delta E squared */
double (*to_de2)(void *cntx, double *in1, double *in2),
/* Same as above, with partial derivatives */
double (*to_dde2)(void *cntx, double dout[2][MXDIDO], double *in1, double *in2)
);
/* Lookup a value though a combined input positioning and shaper curves */
double (*incurve)(struct _xfit *p, double in, int chan);
/* Inverse Lookup a value though a combined input positioning and shaper curves */
double (*invincurve)(struct _xfit *p, double in, int chan);
/* Lookup a value though an output curve */
double (*outcurve)(struct _xfit *p, double in, int chan);
/* Inverse Lookup a value though an output curve */
double (*invoutcurve)(struct _xfit *p, double in, int chan);
}; typedef struct _xfit xfit;
/* The icc is to provide the cone space matrix. If NULL, Bradford will be used. */
xfit *new_xfit(icc *picc);
#endif /* XFIT_H */

3853
Argyll_V3.5.0/xicc/xicc.c Normal file

File diff suppressed because it is too large Load Diff

1037
Argyll_V3.5.0/xicc/xicc.h Normal file

File diff suppressed because it is too large Load Diff

1627
Argyll_V3.5.0/xicc/xicclu.c Normal file

File diff suppressed because it is too large Load Diff

4527
Argyll_V3.5.0/xicc/xlut.c Normal file

File diff suppressed because it is too large Load Diff

2103
Argyll_V3.5.0/xicc/xmatrix.c Normal file

File diff suppressed because it is too large Load Diff

401
Argyll_V3.5.0/xicc/xmono.c Normal file
View File

@@ -0,0 +1,401 @@
/*
* International Color Consortium color transform expanded support
*
* Author: Graeme W. Gill
* Date: 2/7/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.
*
* Based on the old iccXfm class.
*/
/*
* This module provides the expands icclib functionality
* for monochrome profiles.
* This file is #included in xicc.c, to keep its functions private.
*/
/*
* TTBD:
* Some of the error handling is crude. Shouldn't use
* error(), should return status.
*
*/
/* ============================================================= */
/* Forward and Backward Monochrome type conversion */
/* Return 0 on success, 1 if clipping occured, 2 on other error */
/* - - - - - - - - - - - - - - - - - - - - - */
/* Individual components of Fwd conversion: */
/* Because icm_lu4 sets up component conversions in the requested direction, */
/* but icxLuMonox expects component conversions as if the the matrix is */
/* fwd, we have if (dir) code to reverse things here. */
static int
icxLuMonoFwd_curve (
icxLuMono *p, /* This */
double *out, /* Vector of output values */
double *in /* Vector of input values */
) {
icmPe_lurv prv;
if (p->dir) {
prv = p->plu->output_fmt_bwd(p->plu, out, in); /* Should be NOP */
prv |= p->plu->output_pch_bwd(p->plu, out, out);
} else {
prv = p->plu->input_fmt_fwd(p->plu, out, in); /* Should be NOP */
prv |= p->plu->input_pch_fwd(p->plu, out, out);
}
return LUE2XLUE(prv);
}
static int
icxLuMonoFwd_map (
icxLuMono *p, /* This */
double *out, /* Vector of output values */
double *in /* Vector of input values */
) {
icmPe_lurv prv;
if (p->dir) {
prv = p->plu->core5_bwd(p->plu, out, in);
} else {
prv = p->plu->core5_fwd(p->plu, out, in);
}
return LUE2XLUE(prv);
}
static int
icxLuMonoFwd_abs (
icxLuMono *p, /* This */
double *out, /* Vector of output values */
double *in /* Vector of input values */
) {
int rv = 0;
icmPe_lurv prv;
if (p->dir) {
prv = p->plu->input_pch_bwd(p->plu, out, in); /* Should be NOP */
prv |= p->plu->input_fmt_bwd(p->plu, out, out);
} else {
prv = p->plu->output_pch_fwd(p->plu, out, in); /* Should be NOP */
prv |= p->plu->output_fmt_fwd(p->plu, out, out);
}
rv = LUE2XLUE(prv);
if (p->pcs == icxSigJabData) {
p->cam->XYZ_to_cam(p->cam, out, out);
}
return rv;
}
/* Overall Fwd conversion routine */
/* Note that the overall conversion is in the requested direction, */
/* as the setup code swaps icxLuMonoxFwd_lookup/icxLuMonoxBwd_lookup */
/* as needed. */
static int
icxLuMonoFwd_lookup (
icxLuBase *pp, /* This */
double *out, /* Vector of output values */
double *in /* Vector of input values */
) {
int rv = 0;
icxLuMono *p = (icxLuMono *)pp;
rv |= icxLuMonoFwd_curve(p, out, in);
rv |= icxLuMonoFwd_map(p, out, out);
rv |= icxLuMonoFwd_abs(p, out, out);
return rv;
}
/* - - - - - - - - - - - - - - - - - - - - - - - - - - */
/* Given a relative XYZ or Lab PCS value, convert in the fwd direction into */
/* the nominated output PCS (ie. Absolute, Jab etc.) */
/* (This is used in generating gamut compression in B2A tables) */
void icxLuMono_fwd_relpcs_outpcs(
icxLuBase *pp,
icColorSpaceSignature is, /* Input space, XYZ or Lab */
double *out, double *in) {
icxLuMono *p = (icxLuMono *)pp;
icmLab2XYZ(&icmD50, out, in);
if (is == icSigLabData && p->natpcs == icSigXYZData) {
icxLuMonoFwd_abs(p, out, out);
} else if (is == icSigXYZData && p->natpcs == icSigLabData) {
icxLuMonoFwd_abs(p, out, out);
}
}
/* - - - - - - - - - - - - - - - - - - - - - */
/* Individual components of Bwd conversion: */
static int
icxLuMonoBwd_abs (
icxLuMono *p, /* This */
double *out, /* Vector of output values */
double *in /* Vector of input values */
) {
icmPe_lurv prv;
int rv = 0;
if (p->pcs == icxSigJabData) {
p->cam->cam_to_XYZ(p->cam, out, in);
/* Hack to prevent CAM02 weirdness being amplified by */
/* any later per channel clipping. */
/* Limit -Y to non-stupid values by scaling */
if (out[1] < -0.1) {
out[0] *= -0.1/out[1];
out[2] *= -0.1/out[1];
out[1] = -0.1;
}
if (p->dir) {
prv = p->plu->input_fmt_fwd(p->plu, out, out);
prv |= p->plu->input_pch_fwd(p->plu, out, out); /* Should be NOP */
} else {
prv = p->plu->output_fmt_bwd(p->plu, out, out);
prv |= p->plu->output_pch_bwd(p->plu, out, out); /* Should be NOP */
}
rv = LUE2XLUE(prv);
} else {
if (p->dir) {
prv = p->plu->input_fmt_fwd(p->plu, out, in);
prv |= p->plu->input_pch_fwd(p->plu, out, out); /* Should be NOP */
} else {
prv = p->plu->output_fmt_bwd(p->plu, out, in);
prv |= p->plu->output_pch_bwd(p->plu, out, out); /* Should be NOP */
}
rv = LUE2XLUE(prv);
}
return rv;
}
static int
icxLuMonoBwd_map (
icxLuMono *p, /* This */
double *out, /* Vector of output values */
double *in /* Vector of input values */
) {
icmPe_lurv prv;
if (p->dir) {
prv = p->plu->core5_fwd(p->plu, out, in);
} else {
prv = p->plu->core5_bwd(p->plu, out, in);
}
return LUE2XLUE(prv);
}
static int
icxLuMonoBwd_curve (
icxLuMono *p, /* This */
double *out, /* Vector of output values */
double *in /* Vector of input values */
) {
icmPe_lurv prv;
if (p->dir) {
prv = p->plu->output_pch_fwd(p->plu, out, in);
prv |= p->plu->output_fmt_fwd(p->plu, out, out); /* Should be NOP */
} else {
prv = p->plu->input_pch_bwd(p->plu, out, in);
prv |= p->plu->input_fmt_bwd(p->plu, out, out); /* Should be NOP */
}
return LUE2XLUE(prv);
}
/* Overall Bwd conversion routine */
/* Note that the overall conversion is in the requested direction, */
/* as the setup code swaps icxLuMonoxFwd_lookup/icxLuMonoxBwd_lookup */
/* as needed. */
static int
icxLuMonoBwd_lookup (
icxLuBase *pp, /* This */
double *out, /* Vector of output values */
double *in /* Vector of input values */
) {
double temp[3];
int rv = 0;
icxLuMono *p = (icxLuMono *)pp;
rv |= icxLuMonoBwd_abs(p, temp, in);
rv |= icxLuMonoBwd_map(p, out, temp);
rv |= icxLuMonoBwd_curve(p, out, out);
return rv;
}
static void
icxLuMono_free(
icxLuBase *p
) {
p->plu->del(p->plu);
if (p->cam != NULL)
p->cam->del(p->cam);
free(p);
}
/* - - - - - - - - - - - - - - - - - - - - - - - - - - */
/* Given a nominated output PCS (ie. Absolute, Jab etc.), convert it in the bwd */
/* direction into a relative XYZ or Lab PCS value */
/* (This is used in generating gamut compression in B2A tables) */
void icxLuMono_bwd_outpcs_relpcs(
icxLuBase *pp,
icColorSpaceSignature os, /* Output space, XYZ or Lab */
double *out, double *in) {
icxLuMono *p = (icxLuMono *)pp;
if (os == icSigXYZData && p->natpcs == icSigLabData) {
icxLuMonoFwd_abs(p, out, in);
icmLab2XYZ(&icmD50, out, out);
} else if (os == icSigXYZData && p->natpcs == icSigLabData) {
icxLuMonoFwd_abs(p, out, in);
icmXYZ2Lab(&icmD50, out, out);
} else {
icxLuMonoFwd_abs(p, out, in);
}
}
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - */
static gamut *icxLuMonoGamut(icxLuBase *plu, double detail);
static icxCuspMap *icxLuMonoCuspMap(icxLuBase *plu, int res) { return NULL; };
static icxLuBase *
new_icxLuMono(
xicc *xicp,
int flags, /* clip, merge flags */
icmLuSpace *plu, /* Pointer to Lu we are expanding */
icmLookupFunc func, /* Functionality requested */
icRenderingIntent intent, /* Rendering intent */
icColorSpaceSignature pcsor, /* PCS override (0 = def) */
icxViewCond *vc, /* Viewing Condition (NULL if pcsor is not CIECAM) */
int dir /* 0 = fwd, 1 = bwd */
) {
icxLuMono *p;
/* Do the basic icxLuMono creation and initialisation */
if ((p = (icxLuMono *) calloc(1,sizeof(icxLuMono))) == NULL)
return NULL;
p->lutype = icxLuMonoType;
p->pp = xicp;
p->plu = plu;
p->del = icxLuMono_free;
p->lutspaces = icxLutSpaces;
p->spaces = icxLuSpaces;
p->get_native_ranges = icxLu_get_native_ranges;
p->get_ranges = icxLu_get_ranges;
p->efv_wh_bk_points = icxLuEfv_wh_bk_points;
p->get_gamut = icxLuMonoGamut;
p->get_cuspmap = icxLuMonoCuspMap;
p->fwd_relpcs_outpcs = icxLuMono_fwd_relpcs_outpcs;
p->bwd_outpcs_relpcs = icxLuMono_bwd_outpcs_relpcs;
p->nearclip = 0; /* Set flag defaults */
p->mergeclut = 0;
p->intsep = 0;
p->dir = dir;
p->fwd_lookup = icxLuMonoFwd_lookup;
p->fwd_curve = icxLuMonoFwd_curve;
p->fwd_map = icxLuMonoFwd_map;
p->fwd_abs = icxLuMonoFwd_abs;
p->bwd_lookup = icxLuMonoBwd_lookup;
p->bwd_abs = icxLuMonoBwd_abs;
p->bwd_map = icxLuMonoBwd_map;
p->bwd_curve = icxLuMonoBwd_curve;
if (dir) {
p->lookup = icxLuMonoBwd_lookup;
p->inv_lookup = icxLuMonoFwd_lookup;
} else {
p->lookup = icxLuMonoFwd_lookup;
p->inv_lookup = icxLuMonoBwd_lookup;
}
/* There are no mono specific flags */
p->flags = flags;
p->func = func;
/* Remember the effective intent */
p->intent = intent;
/* In general the native and effective space info of the icx will be the same as the */
/* underlying icm lookup object. */
{
icmCSInfo ini, outi, pcsi;
/* Get details of internal, native color space */
plu->native_spaces(p->plu, &ini, &outi, &pcsi);
p->natis = ini.sig;
p->natos = outi.sig;
p->natpcs = pcsi.sig;
icmCpyN(p->ninmin, ini.min, ini.nch);
icmCpyN(p->ninmax, ini.max, ini.nch);
icmCpyN(p->noutmin, outi.min, outi.nch);
icmCpyN(p->noutmax, outi.max, outi.nch);
/* Get details of external, effective color spaces */
plu->spaces(p->plu, &ini, &outi, &pcsi, NULL, NULL, NULL, NULL, NULL, NULL);
p->ins = ini.sig;
p->inputChan = ini.nch;
p->outs = outi.sig;
p->outputChan = outi.nch;
p->pcs = pcsi.sig;
icmCpyN(p->inmin, ini.min, ini.nch);
icmCpyN(p->inmax, ini.max, ini.nch);
icmCpyN(p->outmin, outi.min, outi.nch);
icmCpyN(p->outmax, outi.max, outi.nch);
}
/* Init the CAM model */
if (pcsor == icxSigJabData) {
p->vc = *vc; /* Copy the structure */
p->cam = new_icxcam(cam_default);
p->cam->set_view_vc(p->cam, vc);
} else
p->cam = NULL;
/* Override with pcsor */
if (pcsor == icxSigJabData) {
p->pcs = pcsor;
if (func == icmBwd || func == icmGamut || func == icmPreview)
p->ins = pcsor;
if (func == icmFwd || func == icmPreview)
p->outs = pcsor;
}
/* If we have a Jab PCS override, reflect this in the effective icx range. */
/* Note that the ab ranges are nominal. They will exceed this range */
/* for colors representable in L*a*b* PCS */
if (p->ins == icxSigJabData) {
p->inmin[0] = 0.0; p->inmax[0] = 100.0;
p->inmin[1] = -128.0; p->inmax[1] = 128.0;
p->inmin[2] = -128.0; p->inmax[2] = 128.0;
} else if (p->outs == icxSigJabData) {
p->outmin[0] = 0.0; p->outmax[0] = 100.0;
p->outmin[1] = -128.0; p->outmax[1] = 128.0;
p->outmin[2] = -128.0; p->outmax[2] = 128.0;
}
return (icxLuBase *)p;
}
/* ============================================================= */
/* Given an xicc lookup object, return a gamut object. */
/* Note that the PCS must be Lab or Jab */
/* Return NULL on error, check e.c+e.m for reason */
static gamut *icxLuMonoGamut(
icxLuBase *plu, /* this */
double detail /* gamut detail level, 0.0 = def */
) {
gamut *xgam;
xicc *p = plu->pp; /* parent xicc */
p->e.c = 1;
sprintf(p->e.m,"Creating Mono gamut surface not supported yet.");
plu->del(plu);
xgam = NULL;
return xgam;
}

9474
Argyll_V3.5.0/xicc/xspect.c Normal file

File diff suppressed because it is too large Load Diff

786
Argyll_V3.5.0/xicc/xspect.h Normal file
View File

@@ -0,0 +1,786 @@
#ifndef XSPECT_H
#define XSPECT_H
/*
* Author: Graeme W. Gill
* Date: 21/6/01
* Version: 1.00
*
* Copyright 2000 - 2010 Graeme W. Gill
* All rights reserved.
*
* This material is licenced under the GNU GENERAL PUBLIC LICENSE Version 2 or later :-
* see the License2.txt file for licencing details.
*/
/*
* This class supports converting spectral samples
* into CIE XYZ or D50 Lab tristimulous values.
*/
/*
* TTBD:
*
*/
#ifndef SALONEINSTLIB
# include "icc.h" /* icclib ICC definitions */
#else /* SALONEINSTLIB */
# include "sa_conv.h" /* fake icclib ICC definitions */
#endif /* SALONEINSTLIB */
#ifdef __cplusplus
extern "C" {
#endif
/* ------------------------------------------------------------------------------ */
/* Type of measurement result */
typedef enum { /* XYZ units, Spectral units */
inst_mrt_none = 0, /* Not set */
inst_mrt_emission = 1, /* cd/m^2, mW/(m^2.sr.nm) */
inst_mrt_ambient = 2, /* Lux mW/(m^2.nm) */
inst_mrt_emission_flash = 3, /* cd.s/m^2, mW.s/(m^2.sr.nm) */
inst_mrt_ambient_flash = 4, /* Lux.s mW.s/(m^2.nm) */
inst_mrt_reflective = 5, /* %, %/nm */
inst_mrt_transmissive = 6, /* %, %/nm */
inst_mrt_sensitivity = 7, /* %, %/nm (i.e. CMF) */
inst_mrt_frequency = 8 /* Hz */
} inst_meas_type;
/* Return a string describing the inst_meas_type */
char *meas_type2str(inst_meas_type mt);
/* Reflective measurement conditions */
typedef enum {
inst_mrc_none = 0, /* M0 - Default or N/A */
inst_mrc_D50 = 1, /* M1 - D50 illuminant */
inst_mrc_D65 = 2, /* D65 Illuminant */
inst_mrc_uvcut = 3, /* M2 - U.V. Cut */
inst_mrc_pol = 4, /* M3 - Polarized */
inst_mrc_custom = 5 /* Custom */
} inst_meas_cond;
/* Return a string describing the inst_meas_type */
char *meas_cond2str(inst_meas_cond mc);
/* ------------------------------------------------------------------------------ */
/* Structure for conveying spectral information */
/* NOTE :- should ditch norm, and replace it by */
/* "units", ie. reflectance/transmittance 0..1, 0..100%, */
/* W/nm/m^2 or mW/nm/m^2 */
/* NOTE :- there is an assumption in the .sp file format that */
/* resolution is always >= 1nm. Realistically this could only be */
/* lifted by making the spec[] allocation dynamic, which would involve */
/* a huge number of code changes. */
#define XSPECT_MAX_BANDS 601 /* Enought for 1nm from 300 to 900 */
typedef struct {
int spec_n; /* Number of spectral bands, 0 if not valid */
double spec_wl_short; /* First reading wavelength in nm (shortest) */
double spec_wl_long; /* Last reading wavelength in nm (longest) */
double norm; /* Normalising scale value, ie. 1, 100 etc. */
double spec[XSPECT_MAX_BANDS]; /* Spectral value, shortest to longest */
} xspect;
/* Some helpful macro's: */
/* Set the spectrums parameters */
#define XSPECT_SET_INFO(PDST, N, SHORT, LONG, NORM) \
(PDST)->spec_n = (N), \
(PDST)->spec_wl_short = (SHORT), \
(PDST)->spec_wl_long = (LONG), \
(PDST)->norm = (NORM)
/* Copy everything except the spectral values */
#define XSPECT_COPY_INFO(PDST, PSRC) \
(PDST)->spec_n = (PSRC)->spec_n, \
(PDST)->spec_wl_short = (PSRC)->spec_wl_short, \
(PDST)->spec_wl_long = (PSRC)->spec_wl_long, \
(PDST)->norm = (PSRC)->norm
/* True if the two xspecs match */
#define XSPECT_SAME_INFO(PDST, PSRC) \
((PDST)->spec_n == (PSRC)->spec_n \
&& (PDST)->spec_wl_short == (PSRC)->spec_wl_short \
&& (PDST)->spec_wl_long == (PSRC)->spec_wl_long \
&& (PDST)->norm == (PSRC)->norm)
/* Given an index and the sampling ranges, compute the sample wavelength */
#define XSPECT_WL(SHORT, LONG, N, IX) \
((SHORT) + (double)(IX) * ((LONG) - (SHORT))/((N)-1.0))
/* Given the address of an xspect and an index, compute the sample wavelegth */
#define XSPECT_XWL(PXSP, IX) \
(((PXSP)->spec_wl_short) + (double)(IX) * (((PXSP)->spec_wl_long) - ((PXSP)->spec_wl_short))/(((PXSP)->spec_n)-1.0))
/* Given a wavelength and the sampling ranges, compute the double index */
#define XSPECT_DIX(SHORT, LONG, N, WL) \
(((N)-1.0) * ((WL) - (SHORT))/((LONG) - (SHORT)))
/* Given the wavelength and address of an xspect, compute the double index */
#define XSPECT_XDIX(PXSP, WL) \
(((PXSP)->spec_n-1.0) * ((WL) - ((PXSP)->spec_wl_short))/(((PXSP)->spec_wl_long) - ((PXSP)->spec_wl_short)))
/* Given a wavelength and the sampling ranges, compute the nearest index */
#define XSPECT_IX(SHORT, LONG, N, WL) \
((int)floor(XSPECT_DIX(SHORT, LONG, N, WL) + 0.5))
/* Given a wavelength and address of an xspect, compute the nearest index */
#define XSPECT_XIX(PXSP, WL) \
((int)floor(XSPECT_XDIX(PXSP, WL) + 0.5))
/* Given the sampling ranges, compute the wavelegth interval */
#define XSPECT_WLI_EX(SHORT, LONG, N) (((LONG) - (SHORT))/((N)-1.0))
/* Given the address of an xspect, compute the wavelegth interval */
#define XSPECT_WLI(PXSP) \
((((PXSP)->spec_wl_long) - ((PXSP)->spec_wl_short))/(((PXSP)->spec_n)-1.0))
int write_xspect(char *fname, inst_meas_type mt, inst_meas_cond mc, xspect *s);
/* mt, mc may be NULL */
int read_xspect(xspect *sp, inst_meas_type *mt, inst_meas_cond *mc, char *fname);
/* Write an xspect in 'C' initialization form */
int write_C_xspect(char *fname, xspect *s);
#ifndef SALONEINSTLIB
/* Single spectrum utility functions. Return NZ if error */
/* Two step write & read spectrum, to be able to write & read extra kewords values */
/* Prepare to write spectrum, and return cgats */
int write_xspect_1(cgats **ocgp, inst_meas_type mt, inst_meas_cond mc, xspect *s);
/* Complete writing spectrum */
int write_xspect_2(cgats *ocg, char *fname);
/* Read spectrum and return cgats as well */
int read_xspect_1(cgats **picg, xspect *sp, inst_meas_type *mt, inst_meas_cond *mc, char *fname);
/* Complete reading spectrum */
int read_xspect_2(cgats *icg);
/* Save a set of nspec spectrum to a CGATS file. Return NZ if error */
/* type 0 = SPECT, 1 = CMF */
int write_nxspect(char *fname, inst_meas_type mt, inst_meas_cond mc, xspect *sp,
int nspec, int type);
/* Restore a set of up to nspec spectrum from a CGATS file. Return NZ if error */
/* type = any, 1 = SPECT, 2 = CMF, 3 = both */
int read_nxspect(xspect *sp, inst_meas_type *mt, inst_meas_cond *mc,
char *fname, int *nret, int off, int nspec, int type);
/* Two step write & read n spectrum, to be able to write & read extra kewords values */
/* (Alloactes cgats * on _1, free's it on _2) */
int write_nxspect_1(cgats **pocg, inst_meas_type mt, inst_meas_cond mc, xspect *sp,
int nspec, int type);
int write_nxspect_2(cgats *ocg, char *fname);
int read_nxspect_1(cgats **picg, xspect *sp, inst_meas_type *mt, inst_meas_cond *mc, char *fname,
int *nret, int off, int nspec, int type);
int read_nxspect_2(cgats *icg);
#endif /* !SALONEINSTLIB*/
/* CMF utility functions. Return NZ if error */
/* (See cmf/pcmf.h for write/read pcmf) */
int write_cmf(char *fname, xspect cmf[3]);
int read_cmf(xspect cmf[3], char *fname);
/* Get a (normalised) linearly or poly interpolated spectrum value. */
/* Return NZ if value is valid, Z and last valid value */
/* if outside the range */
int getval_xspec(xspect *sp, double *rv, double wl) ;
/* Get linear or poly interpolated value at wavelenth (not normalised) */
double value_xspect(xspect *sp, double wl);
/* Get linear or poly interpolated value at wavelenth (not normalised) */
double value_xspect_ex(int spec_n, double spec_wl_short, double spec_wl_long,
double *spec, double wl);
/* Get linear interpolated value at wavelenth (not normalised) */
double value_xspect_lin(xspect *sp, double wl);
/* Get a (normalised) linearly interpolated spectrum value. */
/* Return NZ if value is valid, Z and last valid value */
/* if outside the range */
int getval_lxspec(xspect *sp, double *rv, double wl);
/* Get poly interpolated value at wavelenth (not normalised) */
double value_xspect_poly(xspect *sp, double wl);
/* De-normalize and set normalisation factor to 1.0 */
void xspect_denorm(xspect *sp);
/* Scale the spectral values (don't alter norm) */
void xspect_scale(xspect *sp, double scale);
#ifndef SALONEINSTLIB
/* Convert from one xspect type to another with a wl offset from source, */
/* using point sampling of source. */
void xspect2xspect_wloff(xspect *dst, xspect *targ, xspect *src, double wloff);
/* Convert from one xspect type to another, */
/* using point sampling of source. */
void xspect2xspect(xspect *dst, xspect *targ, xspect *src);
/* Convert from one xspect type to another, */
/* using point resampling. */
void poi_resample_xspect(xspect *dst, xspect *src);
/* Convert from one xspect type to another, */
/* using point resampling. */
void poi_resample_xspect_ex(
int d_spec_n, double d_spec_wl_short, double d_spec_wl_long, double *d_spec,
int s_spec_n, double s_spec_wl_short, double s_spec_wl_long, double *s_spec);
/* Convert from one xspect type to another, */
/* using triangular resampling. */
void tri_resample_xspect(xspect *dst, xspect *src);
/* Convert from one xspect type to another, */
/* using triangular resampling. */
void tri_resample_xspect_ex(
int d_spec_n, double d_spec_wl_short, double d_spec_wl_long, double *d_spec,
int s_spec_n, double s_spec_wl_short, double s_spec_wl_long, double *s_spec);
/* Dump a spectra to stdout */
void xspect_dump(xspect *sp);
/* Plot up to 3 spectra */
void xspect_plot_w(xspect *sp1, xspect *sp2, xspect *sp3, int wait);
/* Plot up to 3 spectra & wait for key */
void xspect_plot(xspect *sp1, xspect *sp2, xspect *sp3);
/* Plot up to MXGPHS spectra in an array & wait for key */
void xspect_plotN(xspect *sp, int n);
/* Plot up to MXGPHS spectra pointed to by an array & wait for key */
void xspect_plotNp(xspect *sp[MXGPHS], int n);
/* Plot up to MXGPHS spectra pointed to by an array */
void xspect_plotNp_w(xspect *sp[MXGPHS], int n, int wait);
/* Plot up to MXGPHS spectra pointed to by an array, with optional wait and zero */
void xspect_plotNp_wz(xspect *sp[MXGPHS], int n, int wait, int zero);
/* Plot up to 12 spectra pointed to by an array over a wl range */
//void xspect_plotNp_w(xspect *sp[MXGPHS], int n, double shwl, double lowl, int wait);
#endif /* !SALONEINSTLIB*/
/* ------------------------------------------------------------------------------ */
/* Class for converting between spectral and CIE */
/* We build in some useful spectra */
/* Type of illumination */
typedef enum {
icxIT_default = 0, /* Default illuminant (usually D50) */
icxIT_none = 1, /* No illuminant - self luminous spectrum */
icxIT_custom = 2, /* Custom illuminant spectrum */
icxIT_A = 3, /* Standard Illuminant A */
icxIT_C = 4, /* Standard Illuminant C */
icxIT_D50 = 5, /* Daylight 5000K */
icxIT_D50M2 = 6, /* Daylight 5000K, UV filtered (M2) */
icxIT_D55 = 7, /* Daylight 5500K (use specified temperature) */
icxIT_D65 = 8, /* Daylight 6500K */
icxIT_D75 = 9, /* Daylight 7500K (uses specified temperature) */
icxIT_E = 10, /* Equal Energy = flat = 1.0 */
#ifndef SALONEINSTLIB
icxIT_F5 = 11, /* Fluorescent, Standard, 6350K, CRI 72 */
icxIT_F8 = 12, /* Fluorescent, Broad Band 5000K, CRI 95 */
icxIT_F10 = 13, /* Fluorescent Narrow Band 5000K, CRI 81 */
icxIT_Spectrocam = 14, /* Spectrocam Xenon Lamp */
#endif /* !SALONEINSTLIB*/
icxIT_ODtemp = 15, /* Old daylight at specified temperature */
icxIT_Dtemp = 16, /* CIE 15.2004 Appendix C daylight at specified temperature */
icxIT_OPtemp = 17, /* Old planckian at specified temperature */
icxIT_Ptemp = 18 /* CIE 15.2004 Planckian at specified temperature */
} icxIllumeType;
/* Fill in an xpsect with a standard illuminant spectrum */
/* return 0 on sucecss, nz if not matched */
int standardIlluminant(
xspect *sp, /* Xspect to fill in */
icxIllumeType ilType, /* Type of illuminant */
double temp); /* Optional temperature in degrees kelvin, For Dtemp and Ptemp */
/* Return a string describing the standard illuminant */
/* (Returns static buffer for temp based) */
char *standardIlluminant_name(
icxIllumeType ilType, /* Type of illuminant */
double temp); /* Optional temperature in degrees kelvin, For Dtemp and Ptemp */
/* Given an emission spectrum, set the UV output to the given level. */
/* The shape of the UV is taken from FWA1_stim, and the level is */
/* with respect to the average of the input spectrum. */
void xsp_setUV(xspect *out, xspect *in, double uvlevel);
/* General temperature Planckian (black body) spectra using CIE 15:2004 (exp 1.4388e-2) */
/* Fill in the given xspect with the specified Planckian illuminant */
/* normalised so that 560nm = 100. */
/* Return nz if temperature is out of range */
int planckian_il_sp(xspect *sp, double ct);
/* General temperature Planckian (black body) spectra using CIE 15:2004 (exp 1.4388e-2) */
/* Set the xspect to 300-830nm and fill with the specified Planckian illuminant */
/* normalised so that 560nm = 100. */
/* Return nz if temperature is out of range */
static int planckian_il(xspect *sp, double ct);
/* Type of observer */
typedef enum {
icxOT_default = 0, /* Default observer (usually CIE_1931_2) */
icxOT_none = 1, /* No observer - (don't compute XYZ) */
icxOT_custom = 2, /* Custom observer type weighting */
icxOT_CIE_1931_2 = 3, /* Standard CIE 1931 2 degree */
icxOT_CIE_1964_10 = 4, /* Standard CIE 1964 10 degree */
icxOT_CIE_2015_2 = 5, /* Standard CIE 2015 2 degree */
icxOT_CIE_2015_10 = 6, /* Standard CIE 2015 10 degree */
#ifndef SALONEINSTLIB
icxOT_Stiles_Burch_2 = 7, /* Stiles & Burch 1955 2 degree */
icxOT_Judd_Voss_2 = 8, /* Judd & Voss 1978 2 degree */
icxOT_CIE_1964_10c = 9, /* Standard CIE 1964 10 degree, 2 degree compatible */
icxOT_Shaw_Fairchild_2 = 10, /* Shaw & Fairchild 1997 2 degree */
icxOT_EBU_2012 = 11 /* EBU standard camera curves 2012 */
#endif /* !SALONEINSTLIB*/
} icxObserverType;
/* Return pointers to three xpsects with a standard observer weighting curves */
/* return 0 on sucecss, nz if not matched */
int standardObserver(xspect *sp[3], icxObserverType obType);
/* Return a string describing the standard observer */
char *standardObserverDescription(icxObserverType obType);
/* Type of density values */
typedef enum {
icxDT_none = 0, /* No density */
icxDT_ISO = 1, /* ISO Visual + Type 1 + Type 2 */
icxDT_A = 2, /* Status A */
icxDT_M = 3, /* Status M */
icxDT_T = 4, /* Status T */
icxDT_E = 5
} icxDensityType;
/* Clamping state */
typedef enum {
icxNoClamp = 0, /* Don't clamp XYZ/Lab to +ve */
icxClamp = 1, /* Clamp XYZ/Lab to +ve */
} icxClamping;
/* The conversion object */
struct _xsp2cie {
/* Private: */
xspect illuminant; /* Lookup conversion/observer illuminant */
int isemis; /* nz if we are doing an emission conversion */
xspect observer[3];
int doLab; /* 1 == Return D50 Lab result, 2 == D50 Lpt */
icxClamping clamp; /* Clamp XYZ and Lab to be +ve */
/* Integration range and steps - set to observer range and 1nm by default. */
int spec_bw; /* Integration bandwidth (nm) */
double spec_wl_short; /* Start wavelength (nm) */
double spec_wl_long; /* End wavelength (nm) */
#ifndef SALONEINSTLIB
/* FWA compensation */
double fwa_bw; /* Integration bandwidth */
xspect iillum; /* Y = 1 Normalised instrument illuminant spectrum */
xspect imedia; /* Instrument measured media */
xspect emits; /* Estimated FWA emmission spectrum */
xspect media; /* Estimated base media (ie. minus FWA) */
xspect tillum; /* Y = 1 Normalised target/simulated instrument illuminant spectrum */
/* Use oillum if tillum spec_n = 0 */
xspect oillum; /* Y = 1 Normalised observer illuminant spectrum */
double Sm; /* FWA Stimulation level for emits contribution */
double FWAc; /* FWA content (informational) */
int insteqtarget; /* iillum == tillum, bypass FWA */
#endif /* !SALONEINSTLIB*/
/* Public: */
void (*del)(struct _xsp2cie *p);
/* Override the integration wavelength range and step size */
void (*set_int_steps)(struct _xsp2cie *p, /* this */
double bw, /* Integration step size (nm) */
double shortwl, /* Starting nm */
double longwl /* Ending nm */
);
/* Convert spectrum from photometric to radiometric. */
/* Note that the input spectrum normalisation value is used. */
/* Emissive spectral values are assumed to be in mW/nm, and sampled */
/* rather than integrated if they are not at 1nm spacing. */
void (*photo2rad)(struct _xsp2cie *p, /* this */
double *rout, /* Return total lumens */
double *pout, /* Return total mW */
xspect *sout, /* Return input spectrum converted to lm/nm */
xspect *in /* Spectrum to be converted */
);
#ifndef SALONEINSTLIB
/* Convert (and possibly fwa correct) reflectance spectrum */
#else
/* Convert reflectance spectrum */
#endif
/* Note that the input spectrum normalisation value is used. */
/* Note that the returned XYZ is 0..1 range for reflectanc. */
/* Emissive spectral values are assumed to be in mW/nm, and sampled */
/* rather than integrated if they are not at 1nm spacing. */
void (*convert) (struct _xsp2cie *p, /* this */
double *out, /* Return XYZ or D50 Lab value */
xspect *in /* Spectrum to be converted, normalised by norm */
);
/* Convert and also return (possibly corrected) reflectance spectrum */
/* Spectrum will be same wlength range and readings as input spectrum */
/* Note that the returned XYZ is 0..1 range for reflectance. */
/* Emissive spectral values are assumed to be in mW/nm, and sampled */
/* rather than integrated if they are not at 1nm spacing. */
void (*sconvert) (struct _xsp2cie *p, /* this */
xspect *sout, /* Return corrected refl. spectrum (may be NULL) */
double *out, /* Return XYZ or D50 Lab value (may be NULL) */
xspect *in /* Spectrum to be converted, normalised by norm */
);
/* Get the XYZ of the illuminant being used to compute the CIE XYZ */
/* value. */
void (*get_cie_il)(struct _xsp2cie *p, /* this */
double *xyz /* Return the XYZ */
);
#ifndef SALONEINSTLIB
/* Set Fluorescent Whitening Agent compensation */
/* return NZ if error */
int (*set_fwa) (struct _xsp2cie *p, /* this */
xspect *iillum, /* Spectrum of instrument illuminant */
xspect *tillum, /* Spectrum of target/simulated instrument illuminant, */
/* NULL to use observer illuminant. */
xspect *white /* Spectrum of plain media */
);
/* Set FWA given updated conversion illuminants. */
/* (We assume that xsp2cie_set_fwa has been called first) */
/* return NZ if error */
int (*update_fwa_custillum) (struct _xsp2cie *p,
xspect *tillum, /* Spectrum of target/simulated instrument illuminant, */
/* NULL to use set_fwa() value. */
xspect *custIllum /* Spectrum of observer illuminant */
/* NULL to use new_xsp2cie() value. */
);
/* Get Fluorescent Whitening Agent compensation information */
/* return NZ if error */
void (*get_fwa_info) (struct _xsp2cie *p, /* this */
double *FWAc /* FWA content as a ratio. */
);
/* Set Media White. This enables extracting and applying the */
/* colorant reflectance value from/to the meadia. */
/* return NZ if error */
int (*set_mw) (struct _xsp2cie *p, /* this */
xspect *white /* Spectrum of plain media */
);
/* Extract the colorant reflectance value from the media. Takes FWA */
/* into account if set. Media white or FWA must be set. */
/* return NZ if error */
int (*extract) (struct _xsp2cie *p, /* this */
xspect *out, /* Extracted colorant refl. spectrum */
xspect *in /* Spectrum to be converted, normalised by norm */
);
/* Apply the colorant reflectance value from the media. Takes FWA */
/* into account if set. DOESN'T convert to FWA target illumination! */
/* FWA must be set. */
int (*apply) (struct _xsp2cie *p, /* this */
xspect *out, /* Applied refl. spectrum */
xspect *in /* Colorant reflectance to be applied */
);
#endif /* !SALONEINSTLIB*/
}; typedef struct _xsp2cie xsp2cie;
xsp2cie *new_xsp2cie(
icxIllumeType ilType, /* Observer Illuminant to use */
double temp, /* Optional temp. in degrees kelvin, if ilType = Dtemp etc */
xspect *custIllum, /* Custom illuminant if ilType == icxIT_custom */
icxObserverType obType, /* Observer */
xspect custObserver[3], /* Custom observer if obType == icxOT_custom */
icColorSpaceSignature rcs, /* Return color space, icSigXYZData or D50 icSigLabData */
/* or D50 icmSigLptData */
/* ** Must be icSigXYZData if SALONEINSTLIB ** */
icxClamping clamp /* NZ to clamp XYZ/Lab to be +ve */
);
/* ------------------------------------------------- */
/* Given a reflectance/transmittance spectrum, */
/* an illuminant definition and an observer model, return */
/* the XYZ value for that spectrum. */
/* Return 0 on sucess, 1 on error */
/* (One shot version of xsp2cie etc.) */
int icx_sp2XYZ(
double xyz[3], /* Return XYZ value */
icxObserverType obType, /* Observer */
xspect custObserver[3], /* Optional custom observer */
icxIllumeType ilType, /* Type of illuminant, icxIT_[O]Dtemp or icxIT_[O]Ptemp */
double ct, /* Input temperature in degrees K */
xspect *custIllum, /* Optional custom illuminant */
xspect *sp /* Spectrum to be converted */
);
/* Given an illuminant definition and an observer model, return */
/* the normalised XYZ value for that spectrum. */
/* Return 0 on sucess, 1 on error */
/* (One shot version of xsp2cie etc.) */
int icx_ill_sp2XYZ(
double xyz[3], /* Return XYZ value with Y == 1 */
icxObserverType obType, /* Observer */
xspect custObserver[3], /* Optional custom observer */
icxIllumeType ilType, /* Type of illuminant */
double temp, /* Input temperature in degrees K */
xspect *custIllum, /* Optional custom illuminant */
int abs /* If nz return absolute value in cd/m^2 or Lux */
/* else return Y = 1 normalised value */
);
#ifndef SALONEINSTLIB
/* --------------------------- */
/* Given a choice of temperature dependent illuminant (icxIT_[O]Dtemp or icxIT_[O]Ptemp), */
/* return the closest correlated color temperature to the XYZ. */
/* An observer type can be chosen for interpretting the spectrum of the input and */
/* the illuminant. */
/* Return -1.0 on erorr */
/* (Faster, slightly less accurate version of icx_XYZ2ill_ct()) */
double icx_XYZ2ill_ct2(
double txyz[3], /* If not NULL, return the XYZ of the locus temperature */
icxIllumeType ilType, /* Type of illuminant, icxIT_[O]Dtemp or icxIT_[O]Ptemp */
icxObserverType obType, /* Observer, CIE_1931_2 or CIE_1964_10 */
double xyz[3], /* Input XYZ value */
int viscct /* nz to use visual CIEDE2000, 0 to use CCT CIE 1960 UCS. */
);
/* Given a choice of temperature dependent illuminant (icxIT_[O]Dtemp or icxIT_[O]Ptemp), */
/* a color temperature and a Y value, return the corresponding XYZ */
/* An observer type can be chosen for interpretting the spectrum of the input and */
/* the illuminant. */
/* Return xyz[0] = -1.0 on erorr */
/* (Faster, slightly less accrurate alternative to standardIlluminant()) */
void icx_ill_ct2XYZ(
double xyz[3], /* Return the XYZ value */
icxIllumeType ilType, /* Type of illuminant, icxIT_[O]Dtemp or icx[O]IT_Ptemp */
icxObserverType obType, /* Observer, CIE_1931_2 or CIE_1964_10 */
int viscct, /* nz to use visual CIEDE2000, 0 to use CCT CIE 1960 UCS. */
double tin, /* Input temperature */
double Yin /* Input Y value */
);
/* --------------------------- */
/* Spectrum locus */
/* Return the spectrum locus range for the given observer. */
/* return 0 on sucecss, nz if observer not known */
int icx_spectrum_locus_range(double *min_wl, double *max_wl, icxObserverType obType);
/* Return an XYZ that is on the spectrum locus for the given observer. */
/* wl is the input wavelength in the range icx_chrom_locus_range(), */
/* and return clipped result if outside this range. */
/* Return nz if observer unknown. */
int icx_spectrum_locus(double xyz[3], double in, icxObserverType obType);
/* - - - - - - - - - - - - - - */
/* Chromaticity locus support */
typedef struct _xslpoly xslpoly;
typedef enum {
icxLT_none = 0,
icxLT_spectral = 1,
icxLT_daylight = 2,
icxLT_plankian = 3
} icxLocusType;
/* Return a pointer to the (static) chromaticity locus object */
/* return NULL on failure. */
xslpoly *chrom_locus_poligon(icxLocusType locus_type, icxObserverType obType, int cspace);
/* Determine whether the given XYZ is outside the chromaticity locus */
/* Return 0 if within locus */
/* Return 1 if outside locus */
int icx_outside_spec_locus(xslpoly *p, double xyz[3]);
/* ------------------------------------------------- */
/* Color temperature and CRI */
/* Given a choice of temperature dependent illuminant (icxIT_[O]Dtemp or icxIT_[O]Ptemp), */
/* return the closest correlated color temperature to the given spectrum or XYZ. */
/* An observer type can be chosen for interpretting the spectrum of the input and */
/* the illuminant. */
/* Return -1 on erorr */
double icx_XYZ2ill_ct(
double txyz[3], /* If not NULL, return the XYZ of the black body temperature */
icxIllumeType ilType, /* Type of illuminant, icxIT_[O]Dtemp or icxIT_[O]Ptemp */
icxObserverType obType, /* Observer */
xspect custObserver[3], /* Optional custom observer */
double xyz[3], /* Input XYZ value, NULL if spectrum intead */
xspect *insp0, /* Input spectrum value, NULL if xyz[] instead */
int viscct); /* nz to use visual CIEDE2000, 0 to use CCT CIE 1960 UCS. */
/* Compute the CIE1995 CRI: Ra */
/* Return < 0.0 on error */
/* If invalid is not NULL, set it to nz if CRI */
/* is invalid because the sample is not white enough. */
double icx_CIE1995_CRI(
int *invalid, /* if not NULL, set to nz if invalid */
double cris[14], /* If not NULL, return the TCS01-14 CRI's */
xspect *sample /* Illuminant sample to compute CRI of */
);
/* Compute the EBU TLCI-2012 Qa */
/* Return < 0.0 on error */
/* If invalid is not NULL, set it to nz if TLCI */
/* is invalid because the sample is not white enough. */
double icx_EBU2012_TLCI(
int *invalid, /* if not NULL, set to nz if invalid */
xspect *sample /* Illuminant sample to compute TLCI of */
);
#include "tm3015.h" /* IES TM-30-15 */
/* Return the maximum 24 hour exposure in seconds. */
/* Limit is 8 hours */
/* Returns -1 if the source sample doesn't go down to at least 350 nm */
double icx_ARPANSA_UV_exp(
xspect *sample /* Illuminant sample to compute UV_exp of */
);
/* Return a polinomial aproximation of CCT */
double aprox_CCT(double xyz[3]);
/* Aproximate x,y from CCT using Kim et al's cubic spline. */
/* Invalid < 1667 and > 25000 */
/* (Doesn't set Yxy[0]) */
void aprox_plankian(double Yxy[3], double ct);
/* --------------------------- */
/* Density and other functions */
/* Given a reflectance or transmition spectral product, (Relative */
/* to the scale factor), return CMYV log10 density values */
void xsp_density(
double out[4], /* Return CMYV density */
xspect *in, /* Spectral product to be converted */
icxDensityType dt /* Density type */
);
/* Return a string describing the type of density */
char *xsp_density_desc(icxDensityType dt);
/* Given a reflectance or transmission XYZ value, */
/* return approximate status T CMYV log10 density values */
void icx_XYZ2Tdens(
double *out, /* Return aproximate CMYV log10 density */
double *in /* Input XYZ values */
);
/* Given a reflectance or transmission XYZ value, */
/* return log10 XYZ density values */
void icx_XYZ2dens(
double *out, /* Return log10 XYZ density */
double *in /* Input XYZ values */
);
/* Given an XYZ value, */
/* return sRGB values */
void icx_XYZ2sRGB(
double *out, /* Return sRGB value */
double *wp, /* Input XYZ white point (D65 used if NULL) */
double *in /* Input XYZ values */
);
/* Given an RGB value, return XYZ values. */
/* This is a little slow */
void icx_sRGB2XYZ(
double *out, /* Return XYZ values */
double *wp, /* Output XYZ white point (D65 used if NULL) */
double *in /* Input sRGB values */
);
/* Given an XYZ value, return approximate RGB value */
/* Desaurate to white by the given amount */
void icx_XYZ2RGB_ds(
double *out, /* Return approximate sRGB values */
double *in, /* Input XYZ */
double desat /* 0.0 = full saturation, 1.0 = white */
);
/* Given a wavelengthm return approximate RGB value */
/* Desaurate to white by the given amount */
void icx_wl2RGB_ds(
double *out, /* Return approximate sRGB values */
double wl, /* Input wavelength in nm */
double desat /* 0.0 = full saturation, 1.0 = white */
);
#endif /* !SALONEINSTLIB*/
#ifdef __cplusplus
}
#endif
#endif /* XSPECTFM_H */

293
Argyll_V3.5.0/xicc/xutils.c Normal file
View File

@@ -0,0 +1,293 @@
/*
* xicc standalone utilities
*
* Author: Graeme W. Gill
* Date: 2/7/00
* 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.
*
*/
/*
* This module provides expanded capabilities,
* but is independent of other modules.
*/
#include <stdarg.h>
#include <sys/types.h>
#include <string.h>
#include <ctype.h>
#include <setjmp.h>
#ifdef __sun
#include <unistd.h>
#endif
#include "copyright.h"
#include "aconfig.h"
#include "icc.h"
#include "tiffio.h"
#include "jpeglib.h"
#include "iccjpeg.h"
#include "xutils.h" /* definitions for this library */
#undef DEBUG
#ifdef DEBUG
# define errout stderr
# define debug(xx) fprintf(errout, xx )
# define debug2(xx) fprintf xx
#else
# define debug(xx)
# define debug2(xx)
#endif
#if !defined(O_CREAT) && !defined(_O_CREAT)
# error "Need to #include fcntl.h!"
#endif
/* ------------------------------------------------------ */
/* Common clut table code */
/* Default table of clut resolutions */
/* See discussion in imdi/imdi_gen.c for ideal numbers */
static int lut_resolutions[9][4] = {
/* low, med, high, vhigh */
{ 0, 0, 0, 0 }, /* 0 */
{ 256, 772, 4370, 4370 }, /* 1 */
{ 86, 256, 256, 256 }, /* 2 */
{ 9, 17, 33, 52 }, /* 3 */
{ 6, 9, 18, 33 }, /* 4 */
{ 6, 9, 16, 18 }, /* 5 */
{ 6, 6, 9, 12 }, /* 6 */
{ 6, 7, 7, 9 }, /* 7 */
{ 3, 5, 5, 7 } /* 8 */
};
/* return a lut resolution given the input dimesion and quality */
/* Input dimension [0-8], quality: low 0, medium 1, high 2, very high 3 . */
/* A returned value of 0 indicates illegal. */
int dim_to_clutres(int dim, int quality) {
if (dim < 0)
dim = 0;
else if (dim > 8)
dim = 8;
if (quality < 0)
quality = 0;
if (quality > 3)
quality = 3;
return lut_resolutions[dim][quality];
}
/* ------------------------------------------------------ */
/* JPEG error information */
typedef struct {
jmp_buf env; /* setjmp/longjmp environment */
char message[JMSG_LENGTH_MAX];
} jpegerrorinfo;
/* JPEG error handler */
static void jpeg_error(j_common_ptr cinfo) {
jpegerrorinfo *p = (jpegerrorinfo *)cinfo->client_data;
(*cinfo->err->format_message) (cinfo, p->message);
longjmp(p->env, 1);
}
/* ------------------------------------------------------ */
/* Open an ICC file or a TIFF or JPEG file with an embedded ICC profile for reading. */
/* Return NULL on error */
icc *read_embedded_icc(char *file_name) {
TIFF *rh = NULL;
int size;
void *tag, *buf;
icmAlloc *al;
icmFile *fp;
icmErr err = { 0, { '\000'} };
icc *icco;
TIFFErrorHandler olderrh, oldwarnh;
TIFFErrorHandlerExt olderrhx, oldwarnhx;
int rv;
/* First see if the file can be opened as an ICC profile */
if ((fp = new_icmFileStd_name(&err, file_name,"r")) == NULL) {
debug2((errout,"Can't open file '%s' (0x%x, '%s')\n",file_name,err.c,err.m));
return NULL;
}
if ((icco = new_icc(&err)) == NULL) {
debug2(("Creation of ICC object failed (0x%x, '%s')\n",err.c,err.m));
fp->del(fp);
return NULL;
}
if ((rv = icco->read(icco,fp,0)) == 0) {
debug2((errout,"Opened '%s' as an icc profile\n",file_name));
return icco;
}
debug2((errout,"icc read failed with %d, %s\n",rv,icco->err));
icco->del(icco); /* icc wil fp->del() */
/* Not an ICC profile, see if it's a TIFF file */
olderrh = TIFFSetErrorHandler(NULL);
oldwarnh = TIFFSetWarningHandler(NULL);
olderrhx = TIFFSetErrorHandlerExt(NULL);
oldwarnhx = TIFFSetWarningHandlerExt(NULL);
if ((rh = TIFFOpen(file_name, "r")) != NULL) {
TIFFSetErrorHandler(olderrh);
TIFFSetWarningHandler(oldwarnh);
TIFFSetErrorHandlerExt(olderrhx);
TIFFSetWarningHandlerExt(oldwarnhx);
debug("TIFFOpen succeeded\n");
if (TIFFGetField(rh, TIFFTAG_ICCPROFILE, &size, &tag) == 0 || size == 0) {
debug2((errout,"no ICC profile found in '%s'\n",file_name));
TIFFClose(rh);
return NULL;
}
/* Make a copy of the profile to a memory buffer */
if ((al = new_icmAllocStd(&err)) == NULL) {
debug2(("new_icmAllocStd failed (0x%x, '%s')\n",err.c,err.m));
TIFFClose(rh);
return NULL;
}
if ((buf = al->malloc(al, size)) == NULL) {
debug("malloc of profile buffer failed\n");
al->del(al);
TIFFClose(rh);
return NULL;
}
memmove(buf, tag, size);
TIFFClose(rh);
} else {
jpegerrorinfo jpeg_rerr;
FILE *rf = NULL;
struct jpeg_decompress_struct rj;
struct jpeg_error_mgr jerr;
unsigned char *pdata;
unsigned int plen;
debug2((errout,"TIFFOpen failed for '%s'\n",file_name));
TIFFSetErrorHandler(olderrh);
TIFFSetWarningHandler(oldwarnh);
TIFFSetErrorHandlerExt(olderrhx);
TIFFSetWarningHandlerExt(oldwarnhx);
/* We cope with the horrible ijg jpeg library error handling */
/* by using a setjmp/longjmp. */
jpeg_std_error(&jerr);
jerr.error_exit = jpeg_error;
if (setjmp(jpeg_rerr.env)) {
debug2((errout,"jpeg_read_header failed for '%s'\n",file_name));
jpeg_destroy_decompress(&rj);
fclose(rf);
return NULL;
}
rj.err = &jerr;
rj.client_data = &jpeg_rerr;
jpeg_create_decompress(&rj);
#if defined(O_BINARY) || defined(_O_BINARY)
if ((rf = fopen(file_name,"rb")) == NULL)
#else
if ((rf = fopen(file_name,"r")) == NULL)
#endif
{
debug2((errout,"fopen failed for '%s'\n",file_name));
jpeg_destroy_decompress(&rj);
return NULL;
}
jpeg_stdio_src(&rj, rf);
setup_read_icc_profile(&rj);
/* we'll longjmp on error */
jpeg_read_header(&rj, TRUE);
if (!read_icc_profile(&rj, &pdata, &plen)) {
debug2((errout,"no ICC profile found in '%s'\n",file_name));
jpeg_destroy_decompress(&rj);
fclose(rf);
return NULL;
}
jpeg_destroy_decompress(&rj);
fclose(rf);
/* Make a copy of the profile to a memory buffer */
/* (icmAllocStd may not be the same as malloc ?) */
if ((al = new_icmAllocStd(&err)) == NULL) {
debug2(("new_icmAllocStd failed (0x%x, '%s')\n",err.c,err.m));
return NULL;
}
if ((buf = al->malloc(al, plen)) == NULL) {
debug("malloc of profile buffer failed\n");
al->del(al);
TIFFClose(rh);
return NULL;
}
memmove(buf, pdata, plen);
size = (int)plen;
free(pdata);
}
/* Memory File fp that will free the buffer when deleted: */
if ((fp = new_icmFileMem_ad(&err, buf, size, al)) == NULL) {
debug2(("Creating memory file from CMProfileLocation failed (0x%x, '%s')",err.c,err.m));
al->free(al, buf);
al->del(al);
return NULL;
}
if ((icco = new_icc(&err)) == NULL) {
debug2(("Creation of ICC object failed (0x%x, '%s')\n",err.c,err.m));
fp->del(fp); /* fp will delete al */
return NULL;
}
if ((rv = icco->read(icco,fp,0)) == 0) {
debug2((errout,"Opened '%s' embedded icc profile\n",file_name));
return icco;
}
debug2((errout,"Failed to read '%s' embedded icc profile\n",file_name));
icco->del(icco); /* icco will delete fp and al */
return NULL;
}
/* ------------------------------------------------------ */

View File

@@ -0,0 +1,69 @@
#ifndef XUTILS_H
#define XUTILS_H
/*
* xicc standalone utilities.
*
* Author: Graeme W. Gill
* Date: 28/6/00
* 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.
*
* Based on the old iccXfm class.
*/
/*
* These utilities, while living in xicc, are meant to
* not depend on other modules.
*/
/* Return a lut resolution given the input dimesion and quality */
/* Input dimension [0-8], quality: low, medium, high, very high. */
/* A returned value of 0 indicates illegal. */
int dim_to_clutres(int dim, int quality);
/* Open an ICC file or a TIFF or JPEG file with an embedded ICC profile for reading. */
/* Return NULL on error */
icc *read_embedded_icc(char *file_name);
#endif /* XUTILS_H */