Merge lp:~noskcaj/ubuntu/trusty/argyll/merge into lp:ubuntu/trusty/argyll

Proposed by Jackson Doak
Status: Needs review
Proposed branch: lp:~noskcaj/ubuntu/trusty/argyll/merge
Merge into: lp:ubuntu/trusty/argyll
Diff against target: 326971 lines (+68439/-215524)
811 files modified
.pc/03_kfreebsd.diff/spectro/usbio.c (+0/-1806)
.pc/04_CVE-2012-4405.diff/icc/icc.c (+0/-17408)
.pc/05_ftbfs-underlinkage.diff/imdi/Makefile.am (+0/-40)
.pc/05_ftbfs-underlinkage.diff/xicc/Makefile.am (+0/-28)
.pc/06_fix_udev_rule.patch/libusb/55-Argyll.rules (+0/-64)
.pc/06_fix_udev_rule.patch/libusb1/55-Argyll.rules (+0/-64)
.pc/applied-patches (+0/-7)
.pc/drop-usb-db.patch/libusb/55-Argyll.rules (+0/-64)
.pc/drop-usb-db.patch/libusb1/55-Argyll.rules (+0/-64)
Jambase (+103/-30)
Jamfile (+18/-8)
Jamtop (+37/-14)
Makefile.am (+0/-28)
Makefile.shared (+0/-14)
Readme.txt (+3/-3)
aclocal.m4 (+0/-988)
adirs (+1/-5)
cgats/Makefile.am (+0/-9)
cgats/cgats.c (+55/-73)
cgats/pars.c (+93/-15)
cgats/pars.h (+20/-5)
cgats/parsstd.c (+37/-2)
config.guess (+0/-1530)
config.h.in (+0/-95)
config.sub (+0/-1782)
configure (+0/-15135)
configure.ac (+0/-133)
debian/applycal.1 (+3/-3)
debian/argyll.install (+3/-5)
debian/argyll.manpages (+1/-3)
debian/average.1 (+3/-3)
debian/cb2ti3.1 (+3/-3)
debian/cctiff.1 (+142/-132)
debian/ccttest.1 (+2/-2)
debian/ccxxmake.1 (+39/-35)
debian/changelog (+53/-0)
debian/chartread.1 (+27/-19)
debian/collink.1 (+3/-3)
debian/colprof.1 (+33/-25)
debian/control (+5/-5)
debian/dispcal.1 (+33/-49)
debian/dispread.1 (+25/-37)
debian/dispwin.1 (+15/-15)
debian/extracticc.1 (+5/-5)
debian/extractttag.1 (+3/-3)
debian/fakeCMY.1 (+3/-3)
debian/fakeread.1 (+3/-3)
debian/greytiff.1 (+3/-3)
debian/i1d3ccss.1 (+0/-39)
debian/iccdump.1 (+3/-3)
debian/iccgamut.1 (+3/-3)
debian/icclu.1 (+3/-3)
debian/illumread.1 (+7/-13)
debian/invprofcheck.1 (+3/-3)
debian/kodak2ti3.1 (+3/-3)
debian/mppcheck.1 (+5/-5)
debian/mpplu.1 (+4/-4)
debian/mppprof.1 (+5/-5)
debian/oeminst.1 (+49/-0)
debian/patches/01_autotools-support.diff (+1484/-10638)
debian/patches/03_usb-db.diff (+10/-0)
debian/patches/04_CVE-2012-4405.diff (+1/-1)
debian/patches/05_external-yajl.diff (+19/-0)
debian/patches/05_ftbfs-underlinkage.diff (+0/-27)
debian/patches/06_fix_udev_rule.patch (+22/-38)
debian/patches/drop-usb-db.patch (+0/-24)
debian/patches/series (+1/-3)
debian/pathplot.1 (+3/-3)
debian/printcal.1 (+23/-11)
debian/printtarg.1 (+15/-3)
debian/profcheck.1 (+21/-13)
debian/refine.1 (+23/-15)
debian/revfix.1 (+3/-3)
debian/rules (+57/-53)
debian/scanin.1 (+3/-3)
debian/simpprof.1 (+4/-4)
debian/spec2cie.1 (+31/-23)
debian/specplot.1 (+8/-2)
debian/splitti3.1 (+3/-3)
debian/spotread.1 (+48/-38)
debian/spyd2en.1 (+0/-31)
debian/spyd4en.1 (+0/-31)
debian/synthcal.1 (+3/-3)
debian/synthread.1 (+3/-3)
debian/targen.1 (+5/-5)
debian/tiffgamut.1 (+5/-5)
debian/txt2ti3.1 (+3/-3)
debian/verify.1 (+19/-13)
debian/viewgam.1 (+3/-3)
debian/xicclu.1 (+9/-3)
depcomp (+0/-708)
doc/ArgyllDoc.html (+3064/-210)
doc/ChangesSummary.html (+146/-2)
doc/ColorManagement.html (+165/-157)
doc/Compiling.html (+2/-1)
doc/Environment.html (+123/-94)
doc/FWA.html (+259/-245)
doc/File_Formats.html (+92/-173)
doc/Installing.html (+46/-43)
doc/Installing_Linux.html (+87/-30)
doc/Installing_MSWindows.html (+485/-394)
doc/Installing_OSX.html (+1/-1)
doc/Makefile.am (+0/-6)
doc/SG_header.txt (+3/-4)
doc/Scenarios.html (+93/-21)
doc/afiles (+7/-4)
doc/calvschar.html (+59/-54)
doc/ccmxs.html (+406/-382)
doc/ccmxs/DTP-94_Dell_U2410.ccmx (+25/-0)
doc/ccmxs/Spyder3_NEC_PA301W.ccmx (+25/-0)
doc/ccxxmake.html (+408/-59)
doc/chartread.html (+216/-283)
doc/collink.html (+535/-642)
doc/colprof.html (+702/-497)
doc/dispcal.html (+696/-79)
doc/dispread.html (+343/-67)
doc/dispwin.html (+107/-18)
doc/i1d3ccss.html (+0/-120)
doc/iccgamut.html (+330/-272)
doc/illumread.html (+316/-259)
doc/instruments.html (+829/-216)
doc/mpplu.html (+1/-1)
doc/oeminst.html (+323/-0)
doc/printcal.html (+389/-347)
doc/printtarg.html (+328/-431)
doc/profcheck.html (+247/-203)
doc/refine.html (+351/-327)
doc/scanin.html (+578/-450)
doc/sepgen.html (+0/-81)
doc/spec2cie.html (+203/-186)
doc/specplot.html (+44/-31)
doc/spotread.html (+512/-91)
doc/spyd2en.html (+0/-113)
doc/spyd4en.html (+0/-107)
doc/targen.html (+941/-819)
doc/ti3_format.html (+125/-159)
doc/verify.html (+116/-162)
firmware-package-builder/argyll-firmware-spyder2/debian/changelog (+0/-12)
firmware-package-builder/argyll-firmware-spyder2/debian/compat (+0/-1)
firmware-package-builder/argyll-firmware-spyder2/debian/control (+0/-17)
firmware-package-builder/argyll-firmware-spyder2/debian/copyright (+0/-8)
firmware-package-builder/argyll-firmware-spyder2/debian/install (+0/-1)
firmware-package-builder/argyll-firmware-spyder2/debian/rules (+0/-10)
gamut/Jamfile (+2/-0)
gamut/Makefile.am (+0/-27)
gamut/gammap.c (+9/-2)
gamut/maptest.c (+1/-1)
gamut/nearsmth.c (+1/-1)
h/Makefile.am (+0/-3)
h/aconfig.h (+9/-7)
h/copyright.h (+1/-1)
h/counters.h (+44/-0)
icc/Makefile.am (+0/-22)
icc/Readme.txt (+2/-3)
icc/icc.c (+598/-178)
icc/icc.h (+41/-10)
icc/iccdump.c (+7/-8)
icc/icclu.c (+2/-2)
icc/iccrw.c (+3/-3)
icc/iccstd.c (+28/-2)
icc/icctest.c (+2/-2)
icc/log.txt (+13/-2)
icc/lutest.c (+2/-2)
icc/mcheck.c (+1/-1)
imdi/Jamfile (+15/-3)
imdi/Makefile.am (+0/-40)
imdi/Readme.txt (+1/-1)
imdi/cctiff.c (+41/-16)
imdi/imdi_k.h (+0/-572)
imdi/imdi_make.c (+45/-26)
imdi/imdi_utl.h (+5/-3)
install-sh (+0/-527)
jcnf/Makefile.am (+0/-15)
jcnf/test.c (+1/-0)
jcnf/yajl/Makefile.am (+0/-13)
jpg/Jamfile (+2/-2)
libusb/45-Argyll.rules (+0/-48)
libusb/55-Argyll.rules (+0/-64)
libusb/AUTHORS (+0/-3)
libusb/Argyll (+0/-9)
libusb/Argyll.kext/Info.plist (+0/-30)
libusb/Argyll.usermap (+0/-40)
libusb/COPYING (+0/-504)
libusb/ChangeLog (+0/-7)
libusb/Doxyfile (+0/-1091)
libusb/Doxyfile.in (+0/-1091)
libusb/INSTALL.libusb (+0/-59)
libusb/INSTALL.libusb.in (+0/-59)
libusb/Jamfile (+0/-31)
libusb/LICENSE (+0/-47)
libusb/Makefile.am (+0/-94)
libusb/Makefile.in (+0/-938)
libusb/NEWS (+0/-1)
libusb/README (+0/-106)
libusb/README.in (+0/-94)
libusb/acinclude.m4 (+0/-101)
libusb/aclocal.m4 (+0/-6869)
libusb/afiles (+0/-71)
libusb/apidocs/footer.html (+0/-11)
libusb/apidocs/header.html (+0/-34)
libusb/binfiles (+0/-10)
libusb/bsd.c (+0/-637)
libusb/compile (+0/-136)
libusb/config.guess (+0/-1411)
libusb/config.h.in (+0/-97)
libusb/config.sub (+0/-1500)
libusb/configure (+0/-23510)
libusb/configure.in (+0/-263)
libusb/darwin.c (+0/-1236)
libusb/depcomp (+0/-520)
libusb/descriptors.c (+0/-520)
libusb/doc/Makefile.am (+0/-31)
libusb/doc/Makefile.in (+0/-366)
libusb/doc/api.sgml (+0/-38)
libusb/doc/functions.sgml (+0/-540)
libusb/doc/intro.sgml (+0/-17)
libusb/doc/manual.sgml (+0/-75)
libusb/doc/website.dsl (+0/-197)
libusb/error.c (+0/-36)
libusb/error.h (+0/-31)
libusb/install-sh (+0/-316)
libusb/install_kext.sh (+0/-6)
libusb/libusb-config.in (+0/-79)
libusb/libusb.pc.in (+0/-11)
libusb/libusb.spec (+0/-65)
libusb/libusb.spec.in (+0/-65)
libusb/linux.c (+0/-894)
libusb/linux.h (+0/-119)
libusb/ltmain.sh (+0/-6425)
libusb/missing (+0/-360)
libusb/tests/Makefile.am (+0/-37)
libusb/tests/Makefile.in (+0/-640)
libusb/tests/descriptor_test.cpp (+0/-82)
libusb/tests/driver_name.cpp (+0/-63)
libusb/tests/find_hubs.cpp (+0/-37)
libusb/tests/find_mice.cpp (+0/-53)
libusb/tests/get_resolution.cpp (+0/-71)
libusb/tests/hub_strings.cpp (+0/-83)
libusb/tests/id_test.cpp (+0/-50)
libusb/tests/testlibusb.c (+0/-154)
libusb/usb.c (+0/-311)
libusb/usb.h.in (+0/-337)
libusb/usbi.h (+0/-74)
libusb/usbpp.cpp (+0/-581)
libusb/usbpp.h (+0/-855)
libusb1/45-Argyll.rules (+0/-48)
libusb1/55-Argyll.rules (+0/-64)
libusb1/AUTHORS (+0/-23)
libusb1/Argyll (+0/-9)
libusb1/Argyll.kext/Info.plist (+0/-30)
libusb1/Argyll.usermap (+0/-49)
libusb1/COPYING (+0/-504)
libusb1/COPYING_GPL (+0/-340)
libusb1/ColorHug.cat (+0/-3)
libusb1/ColorHug.inf (+0/-320)
libusb1/ColorHug.sed (+0/-7)
libusb1/ColorHug_x64.cat (+0/-3)
libusb1/ColorMunki.cat (+0/-3)
libusb1/ColorMunki.inf (+0/-320)
libusb1/ColorMunki.sed (+0/-7)
libusb1/ColorMunki_x64.cat (+0/-3)
libusb1/DTP20.cat (+0/-3)
libusb1/DTP20.inf (+0/-320)
libusb1/DTP20.sed (+0/-7)
libusb1/DTP20_x64.cat (+0/-3)
libusb1/DTP92.cat (+0/-3)
libusb1/DTP92.inf (+0/-320)
libusb1/DTP92.sed (+0/-7)
libusb1/DTP92_x64.cat (+0/-3)
libusb1/DTP94.cat (+0/-3)
libusb1/DTP94.inf (+0/-320)
libusb1/DTP94.sed (+0/-7)
libusb1/DTP94_x64.cat (+0/-3)
libusb1/HCFR3.1.cat (+0/-3)
libusb1/HCFR3.1.inf (+0/-320)
libusb1/HCFR3.1.sed (+0/-7)
libusb1/HCFR4.0.cat (+0/-3)
libusb1/HCFR4.0.inf (+0/-320)
libusb1/HCFR4.0.sed (+0/-7)
libusb1/Huey.cat (+0/-3)
libusb1/Huey.inf (+0/-320)
libusb1/Huey.sed (+0/-7)
libusb1/Huey_x64.cat (+0/-3)
libusb1/INSTALL (+0/-234)
libusb1/Jamfile (+0/-199)
libusb1/KDRIVER_LICENSE (+0/-15)
libusb1/Makefile.am (+0/-28)
libusb1/MonacoOptix.cat (+0/-3)
libusb1/MonacoOptix.inf (+0/-320)
libusb1/MonacoOptix.sed (+0/-7)
libusb1/MonacoOptix_x64.cat (+0/-3)
libusb1/NEWS (+0/-49)
libusb1/PORTING (+0/-95)
libusb1/README (+0/-21)
libusb1/README_MSVC.txt (+0/-25)
libusb1/Readme.txt (+0/-35)
libusb1/Spyd2.cat (+0/-3)
libusb1/Spyd2.inf (+0/-320)
libusb1/Spyd2.sed (+0/-7)
libusb1/Spyd3.cat (+0/-3)
libusb1/Spyd3.inf (+0/-320)
libusb1/Spyd3.sed (+0/-7)
libusb1/Spyd3_x64.cat (+0/-3)
libusb1/Spyd4.cat (+0/-3)
libusb1/Spyd4.inf (+0/-320)
libusb1/Spyd4.sed (+0/-7)
libusb1/Spyd4_x64.cat (+0/-3)
libusb1/THANKS (+0/-8)
libusb1/TODO (+0/-9)
libusb1/WinCoInstallerLicense.txt (+0/-20)
libusb1/afiles (+0/-198)
libusb1/autogen.sh (+0/-18)
libusb1/binfiles.msw (+0/-63)
libusb1/binfiles.osx (+0/-7)
libusb1/binfiles.unix (+0/-9)
libusb1/configure.ac (+0/-157)
libusb1/ddk_build.cmd (+0/-147)
libusb1/doc/Makefile.am (+0/-10)
libusb1/doc/doxygen.cfg.in (+0/-1294)
libusb1/examples/Jamfile (+0/-25)
libusb1/examples/Makefile.am (+0/-23)
libusb1/examples/dpfp.c (+0/-514)
libusb1/examples/dpfp_threaded.c (+0/-552)
libusb1/examples/lsusb.c (+0/-67)
libusb1/examples/lsusb.dsp (+0/-103)
libusb1/examples/lsusb_2005.vcproj (+0/-368)
libusb1/examples/lsusb_2008.vcproj (+0/-351)
libusb1/examples/lsusb_sources (+0/-25)
libusb1/examples/makefile.ddk (+0/-1)
libusb1/examples/xusb.c (+0/-811)
libusb1/examples/xusb.dsp (+0/-102)
libusb1/examples/xusb_2005.vcproj (+0/-352)
libusb1/examples/xusb_2008.vcproj (+0/-351)
libusb1/examples/xusb_sources (+0/-26)
libusb1/i1D3.cat (+0/-3)
libusb1/i1D3.inf (+0/-320)
libusb1/i1D3.sed (+0/-7)
libusb1/i1Disp.cat (+0/-3)
libusb1/i1Disp.inf (+0/-320)
libusb1/i1Disp.sed (+0/-7)
libusb1/i1Disp_x64.cat (+0/-3)
libusb1/i1Monitor.cat (+0/-3)
libusb1/i1Monitor.inf (+0/-320)
libusb1/i1Monitor.sed (+0/-7)
libusb1/i1Monitor_x64.cat (+0/-3)
libusb1/i1Pro.cat (+0/-3)
libusb1/i1Pro.inf (+0/-320)
libusb1/i1Pro.sed (+0/-7)
libusb1/install_kext.sh (+0/-6)
libusb1/libusb-X.X.pc.in (+0/-11)
libusb1/libusb-dll_2005.vcproj (+0/-461)
libusb1/libusb-dll_2008.vcproj (+0/-398)
libusb1/libusb-static_2005.vcproj (+0/-346)
libusb1/libusb-static_2008.vcproj (+0/-344)
libusb1/libusb.h (+0/-1273)
libusb1/libusb/Jamfile (+0/-38)
libusb1/libusb/Makefile.am (+0/-34)
libusb1/libusb/core.c (+0/-1709)
libusb1/libusb/core.d (+0/-65)
libusb1/libusb/descriptor.c (+0/-720)
libusb1/libusb/descriptor.d (+0/-64)
libusb1/libusb/io.c (+0/-2354)
libusb1/libusb/libusb-X.X.def (+0/-59)
libusb1/libusb/libusb-X.X.rc (+0/-120)
libusb1/libusb/libusb.h (+0/-1273)
libusb1/libusb/libusbi.h (+0/-871)
libusb1/libusb/os/darwin_usb.c (+0/-1543)
libusb1/libusb/os/darwin_usb.h (+0/-162)
libusb1/libusb/os/driver/abort_endpoint.c (+0/-59)
libusb1/libusb/os/driver/claim_interface.c (+0/-58)
libusb1/libusb/os/driver/clear_feature.c (+0/-69)
libusb1/libusb/os/driver/common.rc (+0/-53)
libusb1/libusb/os/driver/dispatch.c (+0/-95)
libusb1/libusb/os/driver/driver_api.h (+0/-165)
libusb1/libusb/os/driver/driver_debug.c (+0/-75)
libusb1/libusb/os/driver/driver_debug.h (+0/-30)
libusb1/libusb/os/driver/driver_registry.c (+0/-134)
libusb1/libusb/os/driver/get_configuration.c (+0/-58)
libusb1/libusb/os/driver/get_descriptor.c (+0/-158)
libusb1/libusb/os/driver/get_interface.c (+0/-67)
libusb1/libusb/os/driver/get_status.c (+0/-77)
libusb1/libusb/os/driver/ioctl.c (+0/-332)
libusb1/libusb/os/driver/libusb_driver.c (+0/-463)
libusb1/libusb/os/driver/libusb_driver.h (+0/-234)
libusb1/libusb/os/driver/libusb_driver_rc.rc (+0/-25)
libusb1/libusb/os/driver/makefile.ddk (+0/-1)
libusb1/libusb/os/driver/pnp.c (+0/-216)
libusb1/libusb/os/driver/power.c (+0/-205)
libusb1/libusb/os/driver/release_interface.c (+0/-69)
libusb1/libusb/os/driver/reset_device.c (+0/-46)
libusb1/libusb/os/driver/reset_endpoint.c (+0/-59)
libusb1/libusb/os/driver/set_configuration.c (+0/-170)
libusb1/libusb/os/driver/set_descriptor.c (+0/-77)
libusb1/libusb/os/driver/set_feature.c (+0/-71)
libusb1/libusb/os/driver/set_interface.c (+0/-123)
libusb1/libusb/os/driver/sources (+0/-33)
libusb1/libusb/os/driver/transfer.c (+0/-238)
libusb1/libusb/os/driver/usbd.def (+0/-35)
libusb1/libusb/os/driver/usbdlib_gcc.h (+0/-308)
libusb1/libusb/os/driver/vendor_request.c (+0/-138)
libusb1/libusb/os/linux_usbfs.c (+0/-2226)
libusb1/libusb/os/linux_usbfs.h (+0/-138)
libusb1/libusb/os/makefile.ddk (+0/-1)
libusb1/libusb/os/poll_posix.h (+0/-12)
libusb1/libusb/os/poll_windows.c (+0/-988)
libusb1/libusb/os/poll_windows.h (+0/-164)
libusb1/libusb/os/sources (+0/-31)
libusb1/libusb/os/threads_posix.h (+0/-50)
libusb1/libusb/os/threads_windows.c (+0/-211)
libusb1/libusb/os/threads_windows.h (+0/-88)
libusb1/libusb/os/windows_usb.c (+0/-5193)
libusb1/libusb/os/windows_usb.h (+0/-787)
libusb1/libusb/sync.c (+0/-310)
libusb1/libusbDrivers.sed (+0/-10)
libusb1/libusb_2005.sln (+0/-78)
libusb1/libusb_2008.sln (+0/-53)
libusb1/libusb_dll.dsp (+0/-190)
libusb1/libusb_static.dsp (+0/-170)
libusb1/libusb_vc6.dsw (+0/-71)
libusb1/license.rtf (+0/-699)
libusb1/msvc/config.h (+0/-27)
libusb1/msvc/inttypes.h (+0/-305)
libusb1/msvc/libusb-X.X.rc (+0/-126)
libusb1/msvc/resource.h (+0/-15)
libusb1/msvc/stdint.h (+0/-251)
libusb1/template_cat (+0/-3)
libusb1/template_inf (+0/-320)
libusb1/winusbDrivers.sed (+0/-10)
libusbw/AUTHORS.txt (+0/-12)
libusbw/COPYING_GPL.txt (+0/-340)
libusbw/COPYING_LGPL.txt (+0/-504)
libusbw/ColorMunki.cat (+0/-3)
libusbw/ColorMunki.inf (+0/-138)
libusbw/ColorMunki_x64.cat (+0/-3)
libusbw/DTP20.cat (+0/-3)
libusbw/DTP20.inf (+0/-138)
libusbw/DTP20_x64.cat (+0/-3)
libusbw/DTP92.cat (+0/-3)
libusbw/DTP92.inf (+0/-138)
libusbw/DTP92_x64.cat (+0/-3)
libusbw/DTP94.cat (+0/-3)
libusbw/DTP94.inf (+0/-138)
libusbw/DTP94_x64.cat (+0/-3)
libusbw/HCFR.cat (+0/-3)
libusbw/HCFR.inf (+0/-138)
libusbw/HCFR_x64.cat (+0/-3)
libusbw/Huey.cat (+0/-3)
libusbw/Huey.inf (+0/-138)
libusbw/Huey_x64.cat (+0/-3)
libusbw/Jamfile (+0/-39)
libusbw/LICENSE.txt (+0/-9)
libusbw/Makefile (+0/-263)
libusbw/MonacoOptix.cat (+0/-3)
libusbw/MonacoOptix.inf (+0/-138)
libusbw/MonacoOptix_x64.cat (+0/-3)
libusbw/README.in (+0/-12)
libusbw/Spyd2.cat (+0/-3)
libusbw/Spyd2.inf (+0/-138)
libusbw/Spyd2_x64.cat (+0/-3)
libusbw/Spyd3.cat (+0/-3)
libusbw/Spyd3.inf (+0/-138)
libusbw/Spyd3_x64.cat (+0/-3)
libusbw/afiles (+0/-119)
libusbw/binfiles (+0/-43)
libusbw/changes.txt (+0/-26)
libusbw/ddk_make/make_all.bat (+0/-8)
libusbw/ddk_make/make_clean.bat (+0/-30)
libusbw/ddk_make/make_dll.bat (+0/-19)
libusbw/ddk_make/make_driver.bat (+0/-16)
libusbw/ddk_make/make_super_clean.bat (+0/-12)
libusbw/ddk_make/make_test.bat (+0/-15)
libusbw/ddk_make/make_test_win.bat (+0/-17)
libusbw/ddk_make/makefile (+0/-1)
libusbw/ddk_make/readme.txt (+0/-19)
libusbw/ddk_make/sources_dll (+0/-21)
libusbw/ddk_make/sources_drv (+0/-34)
libusbw/ddk_make/sources_test (+0/-19)
libusbw/ddk_make/sources_test_win (+0/-22)
libusbw/examples/driver_installer_template.iss (+0/-50)
libusbw/i1Disp.cat (+0/-3)
libusbw/i1Disp.inf (+0/-138)
libusbw/i1Disp_x64.cat (+0/-3)
libusbw/i1Monitor.cat (+0/-3)
libusbw/i1Monitor.inf (+0/-138)
libusbw/i1Monitor_x64.cat (+0/-3)
libusbw/i1Pro.cat (+0/-3)
libusbw/i1Pro.inf (+0/-138)
libusbw/i1Pro_x64.cat (+0/-3)
libusbw/inf-wizard.exe.manifest (+0/-22)
libusbw/install.iss.in (+0/-78)
libusbw/installer_license.txt (+0/-869)
libusbw/libusb0.def (+0/-48)
libusbw/libusb0_drv.def (+0/-2)
libusbw/manifest.txt (+0/-22)
libusbw/src/common.rc (+0/-53)
libusbw/src/descriptors.c (+0/-520)
libusbw/src/driver/abort_endpoint.c (+0/-59)
libusbw/src/driver/claim_interface.c (+0/-58)
libusbw/src/driver/clear_feature.c (+0/-69)
libusbw/src/driver/dispatch.c (+0/-95)
libusbw/src/driver/driver_api.h (+0/-165)
libusbw/src/driver/driver_debug.c (+0/-75)
libusbw/src/driver/driver_debug.h (+0/-30)
libusbw/src/driver/driver_registry.c (+0/-134)
libusbw/src/driver/get_configuration.c (+0/-58)
libusbw/src/driver/get_descriptor.c (+0/-158)
libusbw/src/driver/get_interface.c (+0/-67)
libusbw/src/driver/get_status.c (+0/-77)
libusbw/src/driver/ioctl.c (+0/-332)
libusbw/src/driver/libusb_driver.c (+0/-462)
libusbw/src/driver/libusb_driver.h (+0/-234)
libusbw/src/driver/libusb_driver_rc.rc (+0/-25)
libusbw/src/driver/pnp.c (+0/-216)
libusbw/src/driver/power.c (+0/-205)
libusbw/src/driver/release_interface.c (+0/-69)
libusbw/src/driver/reset_device.c (+0/-46)
libusbw/src/driver/reset_endpoint.c (+0/-59)
libusbw/src/driver/set_configuration.c (+0/-170)
libusbw/src/driver/set_descriptor.c (+0/-77)
libusbw/src/driver/set_feature.c (+0/-71)
libusbw/src/driver/set_interface.c (+0/-123)
libusbw/src/driver/transfer.c (+0/-238)
libusbw/src/driver/usbd.def (+0/-35)
libusbw/src/driver/usbdlib_gcc.h (+0/-308)
libusbw/src/driver/vendor_request.c (+0/-138)
libusbw/src/error.c (+0/-116)
libusbw/src/error.h (+0/-22)
libusbw/src/inf_wizard.c (+0/-748)
libusbw/src/inf_wizard_rc.rc (+0/-99)
libusbw/src/install.c (+0/-824)
libusbw/src/install_filter.c (+0/-53)
libusbw/src/libusb_dyn.c (+0/-496)
libusbw/src/registry.c (+0/-1069)
libusbw/src/registry.h (+0/-82)
libusbw/src/resource.rc (+0/-26)
libusbw/src/usb.c (+0/-302)
libusbw/src/usb.h (+0/-394)
libusbw/src/usbi.h (+0/-78)
libusbw/src/windows.c (+0/-1248)
libusbw/testlibusb-win.exe.manifest (+0/-22)
libusbw/tests/testlibusb.c (+0/-163)
libusbw/tests/testlibusb_win.c (+0/-444)
libusbw/tests/testlibusb_win_rc.rc (+0/-26)
link/Makefile.am (+0/-11)
link/collink.c (+8/-8)
log.txt (+351/-5)
ltmain.sh (+0/-9661)
m4/libtool.m4 (+0/-7983)
m4/ltoptions.m4 (+0/-384)
m4/ltsugar.m4 (+0/-123)
m4/ltversion.m4 (+0/-23)
m4/lt~obsolete.m4 (+0/-98)
makeall.sh (+0/-2)
makeinstall.sh (+0/-2)
makepackagebin.sh (+65/-46)
missing (+0/-331)
numlib/LUtest.c (+9/-10)
numlib/Makefile.am (+0/-15)
numlib/dnsq.c (+4/-2)
numlib/numsup.c (+359/-99)
numlib/numsup.h (+228/-88)
plot/Jamfile (+8/-0)
plot/Makefile.am (+0/-12)
plot/afiles (+5/-0)
plot/osx/Jamfile (+21/-0)
plot/osx/Readme.txt (+1/-0)
plot/osx/acoccoa.h (+402/-0)
plot/osx/helloc.c (+313/-0)
plot/osx/hellom.m (+181/-0)
plot/plot.c (+395/-416)
profile/Jamfile (+3/-3)
profile/Makefile.am (+0/-28)
profile/afiles (+0/-1)
profile/colprof.c (+95/-28)
profile/invprofcheck.c (+2/-2)
profile/mppcheck.c (+1/-1)
profile/mppprof.c (+4/-4)
profile/printcal.c (+37/-17)
profile/prof.h (+4/-1)
profile/profcheck.c (+63/-9)
profile/profin.c (+190/-142)
profile/profout.c (+108/-29)
profile/sepgen.c (+0/-481)
profile/splitti3.c (+1/-0)
profile/txt2ti3.c (+2/-0)
profile/verify.c (+66/-11)
ref/CRT.ccss (+4/-0)
ref/ColorCheckerPassport.cht (+122/-0)
ref/ColorCheckerPassport.cie (+64/-0)
ref/Makefile.am (+0/-7)
ref/QPcard_202.cht (+80/-0)
ref/QPcard_202.cie (+48/-0)
ref/afiles (+4/-0)
ref/linear.cal (+1/-1)
ref/strange.cal (+1/-1)
render/Makefile.am (+0/-13)
render/render.c (+18/-3)
render/render.h (+11/-2)
render/thscreen.c (+1/-1)
rspl/Makefile.am (+0/-15)
rspl/gam.h (+1/-1)
rspl/rev.c (+29/-20)
rspl/rev.h (+5/-4)
rspl/rspl.c (+12/-4)
rspl/rspl.h (+10/-10)
rspl/rspl1.c (+27/-32)
scanin/ColorCheckerPassport.cht (+122/-0)
scanin/ColorCheckerPassport.cie (+64/-0)
scanin/Jamfile (+2/-1)
scanin/Makefile.am (+0/-19)
scanin/QPcard_202.cht (+80/-0)
scanin/QPcard_202.cie (+48/-0)
scanin/afiles (+9/-7)
scanin/scanin.c (+9/-0)
scanin/scanrd.c (+6/-4)
spectro/Jamfile (+94/-53)
spectro/Makefile.SA (+31/-40)
spectro/Makefile.UNIX (+1/-1)
spectro/Makefile.am (+0/-54)
spectro/afiles (+14/-5)
spectro/aglob.c (+12/-3)
spectro/ccxxmake.c (+201/-86)
spectro/chartread.c (+333/-326)
spectro/colorhug.c (+432/-341)
spectro/colorhug.h (+11/-9)
spectro/conv.c (+119/-212)
spectro/conv.h (+58/-25)
spectro/dispcal.c (+371/-309)
spectro/dispread.c (+167/-129)
spectro/dispsup.c (+658/-585)
spectro/dispsup.h (+40/-33)
spectro/dispwin.c (+1283/-323)
spectro/dispwin.h (+30/-19)
spectro/dtp20.c (+359/-344)
spectro/dtp20.h (+6/-11)
spectro/dtp22.c (+301/-252)
spectro/dtp22.h (+3/-8)
spectro/dtp41.c (+335/-266)
spectro/dtp41.h (+5/-10)
spectro/dtp51.c (+215/-185)
spectro/dtp51.h (+3/-8)
spectro/dtp92.c (+555/-329)
spectro/dtp92.h (+9/-8)
spectro/fakeread.c (+2/-2)
spectro/hcfr.c (+342/-294)
spectro/hcfr.h (+12/-17)
spectro/hidio.c (+307/-352)
spectro/hidio.h (+20/-13)
spectro/huey.c (+366/-355)
spectro/huey.h (+9/-10)
spectro/i1d3.c (+1447/-693)
spectro/i1d3.h (+29/-13)
spectro/i1d3ccss.c (+0/-1908)
spectro/i1disp.c (+778/-426)
spectro/i1disp.h (+20/-13)
spectro/i1pro.c (+304/-249)
spectro/i1pro.h (+4/-3)
spectro/i1pro_imp.c (+6494/-2856)
spectro/i1pro_imp.h (+381/-167)
spectro/icoms.c (+484/-0)
spectro/icoms.h (+190/-231)
spectro/icoms_nt.c (+563/-0)
spectro/icoms_ux.c (+739/-0)
spectro/ifiles (+14/-0)
spectro/illumread.c (+123/-106)
spectro/inflate.c (+1/-1)
spectro/inst.c (+801/-515)
spectro/inst.h (+581/-355)
spectro/instappsup.c (+556/-0)
spectro/instappsup.h (+100/-0)
spectro/instlib.ksh (+127/-31)
spectro/insttypeinst.h (+1/-1)
spectro/insttypes.c (+120/-40)
spectro/insttypes.h (+16/-7)
spectro/iusb.h (+131/-0)
spectro/linear.cal (+1/-1)
spectro/mongoose.c (+1130/-557)
spectro/mongoose.h (+96/-26)
spectro/munki.c (+363/-276)
spectro/munki.h (+4/-3)
spectro/munki_imp.c (+2738/-1720)
spectro/munki_imp.h (+125/-99)
spectro/ntio.c (+0/-696)
spectro/oemarch.c (+2610/-0)
spectro/oemarch.h (+102/-0)
spectro/oeminst.c (+276/-0)
spectro/spec2cie.c (+65/-16)
spectro/spotread.c (+566/-308)
spectro/spyd2.c (+934/-875)
spectro/spyd2.h (+27/-18)
spectro/spyd2en.c (+0/-902)
spectro/spyd2setup.h (+10/-4)
spectro/spyd4en.c (+0/-709)
spectro/ss.c (+450/-379)
spectro/ss.h (+7/-7)
spectro/ss_imp.c (+5/-24)
spectro/ss_imp.h (+1/-5)
spectro/strange.cal (+1/-1)
spectro/unixio.c (+0/-906)
spectro/usbio.c (+326/-1543)
spectro/usbio.h (+203/-16)
spectro/usbio_lusb.c (+897/-0)
spectro/usbio_lx.c (+1069/-0)
spectro/usbio_nt.c (+898/-0)
spectro/usbio_ox.c (+986/-0)
spectro/vinflate.c (+45/-43)
spectro/webwin.c (+55/-9)
spectro/webwin.h (+1/-1)
spectro/xdg_bds.c (+287/-233)
spectro/xdg_bds.h (+17/-2)
target/Makefile.am (+0/-28)
target/ofps.c (+26/-13)
target/prand.c (+2/-1)
target/printtarg.c (+122/-45)
target/targen.c (+22/-22)
tiff/Jamfile (+8/-2)
ttbd.txt (+8/-12)
tweak/Makefile.am (+0/-11)
tweak/refine.c (+72/-17)
ucmm/Makefile.am (+0/-9)
usb/45-Argyll.rules (+62/-0)
usb/55-Argyll.rules (+90/-0)
usb/Argyll (+9/-0)
usb/Argyll.kext/Info.plist (+30/-0)
usb/Argyll.usermap (+53/-0)
usb/ArgyllCMS.cat (+3/-0)
usb/ArgyllCMS.inf (+213/-0)
usb/ArgyllCMS.inf.d (+34/-0)
usb/ArgyllCMS.inf.t (+111/-0)
usb/ArgyllCMS_x64.cat (+3/-0)
usb/Jamfile (+52/-0)
usb/Readme.txt (+8/-0)
usb/afiles (+60/-0)
usb/bin/libusb-win32-bin-README.txt (+27/-0)
usb/binfiles.lx (+4/-0)
usb/binfiles.msw (+6/-0)
usb/binfiles.osx (+2/-0)
usb/driver/AUTHORS.txt (+16/-0)
usb/driver/COPYING_GPL.txt (+674/-0)
usb/driver/LICENSE.txt (+9/-0)
usb/driver/Makefile (+261/-0)
usb/driver/README.txt (+12/-0)
usb/driver/abort_endpoint.c (+56/-0)
usb/driver/claim_interface.c (+89/-0)
usb/driver/clear_feature.c (+64/-0)
usb/driver/dispatch.c (+99/-0)
usb/driver/driver_api.h (+400/-0)
usb/driver/driver_debug.c (+75/-0)
usb/driver/driver_debug.h (+30/-0)
usb/driver/driver_registry.c (+376/-0)
usb/driver/get_configuration.c (+56/-0)
usb/driver/get_descriptor.c (+289/-0)
usb/driver/get_interface.c (+109/-0)
usb/driver/get_status.c (+74/-0)
usb/driver/ioctl.c (+795/-0)
usb/driver/libusb-win32-README-1.2.6.0.txt (+239/-0)
usb/driver/libusb_driver.c (+971/-0)
usb/driver/libusb_driver.h (+429/-0)
usb/driver/libusb_driver_rc.rc (+25/-0)
usb/driver/lusb_defdi_guids.h (+45/-0)
usb/driver/pnp.c (+302/-0)
usb/driver/power.c (+269/-0)
usb/driver/release_interface.c (+105/-0)
usb/driver/reset_device.c (+56/-0)
usb/driver/reset_endpoint.c (+56/-0)
usb/driver/set_configuration.c (+205/-0)
usb/driver/set_descriptor.c (+71/-0)
usb/driver/set_feature.c (+67/-0)
usb/driver/set_interface.c (+124/-0)
usb/driver/transfer.c (+1493/-0)
usb/driver/usbd.def (+35/-0)
usb/driver/usbdlib_gcc.h (+310/-0)
usb/driver/vendor_request.c (+143/-0)
usb/install_kext.sh (+6/-0)
xicc/Jamfile (+16/-11)
xicc/Makefile.am (+0/-29)
xicc/afiles (+0/-2)
xicc/cam02.c (+192/-110)
xicc/cam02.h (+0/-1)
xicc/cam02test.c (+28/-16)
xicc/ccmx.c (+243/-61)
xicc/ccmx.h (+13/-2)
xicc/ccss.c (+220/-50)
xicc/ccss.h (+13/-3)
xicc/ccttest.c (+2/-0)
xicc/extracticc.c (+1/-1)
xicc/extractttag.c (+1/-1)
xicc/iccgamut.c (+1/-1)
xicc/moncurve.c (+1/-1)
xicc/mpp.c (+2/-2)
xicc/mpplu.c (+4/-1)
xicc/specplot.c (+11/-7)
xicc/specsubsamp.c (+6/-4)
xicc/spectest.c (+3/-3)
xicc/spectest2.c (+2/-2)
xicc/tiffgamut.c (+1/-1)
xicc/xcam.h (+4/-0)
xicc/xfit.c (+414/-122)
xicc/xfit.h (+13/-4)
xicc/xicc.c (+22/-8)
xicc/xicc.h (+52/-44)
xicc/xicclu.c (+44/-10)
xicc/xlut.c (+244/-82)
xicc/xlutfix.c (+98/-90)
xicc/xmatrix.c (+599/-262)
xicc/xmono.c (+8/-0)
xicc/xsep.c (+0/-246)
xicc/xsep.h (+0/-160)
xicc/xspect.c (+661/-402)
xicc/xspect.h (+58/-34)
ziparch.sh (+1/-1)
To merge this branch: bzr merge lp:~noskcaj/ubuntu/trusty/argyll/merge
Reviewer Review Type Date Requested Status
Michael Terry Needs Fixing
Review via email: mp+199879@code.launchpad.net

Description of the change

Merge from debian

To post a comment you must log in.
Revision history for this message
Michael Terry (mterry) wrote :

Looks good, except that drop-usb-db.patch isn't droppable. The patched file moved to usb/55-Argyll.rules, but it's still there.

review: Needs Fixing
Revision history for this message
Jackson Doak (noskcaj) wrote :

Is there any chance you could check the patch? I don't know how it works
and it no longer applies even with the different target

On Wed, Jan 15, 2014 at 3:03 AM, Michael Terry
<email address hidden>wrote:

> Review: Needs Fixing
>
> Looks good, except that drop-usb-db.patch isn't droppable. The patched
> file moved to usb/55-Argyll.rules, but it's still there.
> --
>
> https://code.launchpad.net/~noskcaj/ubuntu/trusty/argyll/merge/+merge/199879
> You are the owner of lp:~noskcaj/ubuntu/trusty/argyll/merge.
>

Unmerged revisions

29. By Jackson Doak

* Merge from debian. Remaining changes:
  - drop obsolete consolekit Recommends
  - Build-depend on libtiff-dev rather than libtiff4-dev
  - 06_fix_udev_rule.patch: Fix udev rules to actually work;
    ENV{ACL_MANAGE} has stopped working ages ago, and with logind
    it's now the "uaccess" tag.
* Drop 05_ftbfs-underlinkage.diff, not needed
* Drop drop-usb-db.patch, fixed in debian

28. By Jackson Doak

Merging shared upstream rev into target branch.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== removed directory '.pc/01_autotools-support.diff'
2=== removed file '.pc/01_autotools-support.diff/Makefile.am'
3=== removed file '.pc/01_autotools-support.diff/Makefile.shared'
4=== removed file '.pc/01_autotools-support.diff/aclocal.m4'
5=== removed directory '.pc/01_autotools-support.diff/cgats'
6=== removed file '.pc/01_autotools-support.diff/cgats/Makefile.am'
7=== removed file '.pc/01_autotools-support.diff/config.guess'
8=== removed file '.pc/01_autotools-support.diff/config.h.in'
9=== removed file '.pc/01_autotools-support.diff/config.sub'
10=== removed file '.pc/01_autotools-support.diff/configure'
11=== removed file '.pc/01_autotools-support.diff/configure.ac'
12=== removed file '.pc/01_autotools-support.diff/depcomp'
13=== removed directory '.pc/01_autotools-support.diff/doc'
14=== removed file '.pc/01_autotools-support.diff/doc/Makefile.am'
15=== removed directory '.pc/01_autotools-support.diff/gamut'
16=== removed file '.pc/01_autotools-support.diff/gamut/Makefile.am'
17=== removed directory '.pc/01_autotools-support.diff/h'
18=== removed file '.pc/01_autotools-support.diff/h/Makefile.am'
19=== removed directory '.pc/01_autotools-support.diff/icc'
20=== removed file '.pc/01_autotools-support.diff/icc/Makefile.am'
21=== removed directory '.pc/01_autotools-support.diff/imdi'
22=== removed file '.pc/01_autotools-support.diff/imdi/Makefile.am'
23=== removed file '.pc/01_autotools-support.diff/imdi/imdi_k.h'
24=== removed file '.pc/01_autotools-support.diff/install-sh'
25=== removed directory '.pc/01_autotools-support.diff/jcnf'
26=== removed file '.pc/01_autotools-support.diff/jcnf/Makefile.am'
27=== removed directory '.pc/01_autotools-support.diff/jcnf/yajl'
28=== removed file '.pc/01_autotools-support.diff/jcnf/yajl/Makefile.am'
29=== removed directory '.pc/01_autotools-support.diff/link'
30=== removed file '.pc/01_autotools-support.diff/link/Makefile.am'
31=== removed file '.pc/01_autotools-support.diff/ltmain.sh'
32=== removed directory '.pc/01_autotools-support.diff/m4'
33=== removed file '.pc/01_autotools-support.diff/m4/libtool.m4'
34=== removed file '.pc/01_autotools-support.diff/m4/ltoptions.m4'
35=== removed file '.pc/01_autotools-support.diff/m4/ltsugar.m4'
36=== removed file '.pc/01_autotools-support.diff/m4/ltversion.m4'
37=== removed file '.pc/01_autotools-support.diff/m4/lt~obsolete.m4'
38=== removed file '.pc/01_autotools-support.diff/missing'
39=== removed directory '.pc/01_autotools-support.diff/numlib'
40=== removed file '.pc/01_autotools-support.diff/numlib/Makefile.am'
41=== removed directory '.pc/01_autotools-support.diff/plot'
42=== removed file '.pc/01_autotools-support.diff/plot/Makefile.am'
43=== removed directory '.pc/01_autotools-support.diff/profile'
44=== removed file '.pc/01_autotools-support.diff/profile/Makefile.am'
45=== removed directory '.pc/01_autotools-support.diff/ref'
46=== removed file '.pc/01_autotools-support.diff/ref/Makefile.am'
47=== removed directory '.pc/01_autotools-support.diff/render'
48=== removed file '.pc/01_autotools-support.diff/render/Makefile.am'
49=== removed directory '.pc/01_autotools-support.diff/rspl'
50=== removed file '.pc/01_autotools-support.diff/rspl/Makefile.am'
51=== removed directory '.pc/01_autotools-support.diff/scanin'
52=== removed file '.pc/01_autotools-support.diff/scanin/Makefile.am'
53=== removed directory '.pc/01_autotools-support.diff/spectro'
54=== removed file '.pc/01_autotools-support.diff/spectro/Makefile.am'
55=== removed directory '.pc/01_autotools-support.diff/target'
56=== removed file '.pc/01_autotools-support.diff/target/Makefile.am'
57=== removed directory '.pc/01_autotools-support.diff/tweak'
58=== removed file '.pc/01_autotools-support.diff/tweak/Makefile.am'
59=== removed directory '.pc/01_autotools-support.diff/ucmm'
60=== removed file '.pc/01_autotools-support.diff/ucmm/Makefile.am'
61=== removed directory '.pc/01_autotools-support.diff/xicc'
62=== removed file '.pc/01_autotools-support.diff/xicc/Makefile.am'
63=== removed directory '.pc/02_firmware-package-builder.diff'
64=== removed directory '.pc/02_firmware-package-builder.diff/firmware-package-builder'
65=== removed directory '.pc/02_firmware-package-builder.diff/firmware-package-builder/argyll-firmware-spyder2'
66=== removed directory '.pc/02_firmware-package-builder.diff/firmware-package-builder/argyll-firmware-spyder2/debian'
67=== removed file '.pc/02_firmware-package-builder.diff/firmware-package-builder/argyll-firmware-spyder2/debian/changelog'
68=== removed file '.pc/02_firmware-package-builder.diff/firmware-package-builder/argyll-firmware-spyder2/debian/compat'
69=== removed file '.pc/02_firmware-package-builder.diff/firmware-package-builder/argyll-firmware-spyder2/debian/control'
70=== removed file '.pc/02_firmware-package-builder.diff/firmware-package-builder/argyll-firmware-spyder2/debian/copyright'
71=== removed file '.pc/02_firmware-package-builder.diff/firmware-package-builder/argyll-firmware-spyder2/debian/install'
72=== removed file '.pc/02_firmware-package-builder.diff/firmware-package-builder/argyll-firmware-spyder2/debian/rules'
73=== removed directory '.pc/03_kfreebsd.diff'
74=== removed directory '.pc/03_kfreebsd.diff/spectro'
75=== removed file '.pc/03_kfreebsd.diff/spectro/usbio.c'
76--- .pc/03_kfreebsd.diff/spectro/usbio.c 2012-04-24 07:49:03 +0000
77+++ .pc/03_kfreebsd.diff/spectro/usbio.c 1970-01-01 00:00:00 +0000
78@@ -1,1806 +0,0 @@
79-
80- /* General USB I/O support */
81-
82-/*
83- * Argyll Color Correction System
84- *
85- * Author: Graeme W. Gill
86- * Date: 2006/22/4
87- *
88- * Copyright 2006 - 2010 Graeme W. Gill
89- * All rights reserved.
90- *
91- * This material is licenced under the GNU GENERAL PUBLIC LICENSE Version 2 or later :-
92- * see the License2.txt file for licencing details.
93- */
94-
95-/* These routines supliement the class code in ntio.c and unixio.c */
96-/* with common and USB specific routines */
97-/* Rename to icoms.c ?? */
98-
99-#include <stdio.h>
100-#include <stdlib.h>
101-#include <time.h>
102-#include <signal.h>
103-#if defined(UNIX)
104-#include <termios.h>
105-#include <errno.h>
106-#include <unistd.h>
107-#endif
108-#ifndef SALONEINSTLIB
109-#include "copyright.h"
110-#include "aconfig.h"
111-#endif
112-#include "numsup.h"
113-#include "xspect.h"
114-#include "insttypes.h"
115-#include "icoms.h"
116-#include "conv.h"
117-#include "usbio.h"
118-#include "hidio.h"
119-
120-#ifdef USE_LIBUSB1
121-# include "libusb.h"
122-#else
123-# include "usb.h"
124-#endif
125-
126-#ifdef ENABLE_USB
127-
128-/* To simplify error messages: */
129-#ifdef USE_LIBUSB1
130-# define USB_STRERROR(RV) libusb_strerror(RV)
131-#else
132-# define USB_STRERROR(RV) usb_strerror()
133-#endif
134-
135-/* Check a USB Vendor and product ID, and add the device */
136-/* to the icoms path if it is supported. Return nz if it was added. */
137-static int usb_check_and_add(
138-struct _icoms *p,
139-struct usb_device *dev
140-) {
141- instType itype;
142- struct usb_device_descriptor descriptor;
143-
144-#ifdef USE_LIBUSB1
145- if (libusb_get_device_descriptor(dev, &descriptor) != LIBUSB_SUCCESS)
146- return 1;
147-#else
148- descriptor = dev->descriptor; /* Copy */
149-#endif
150- if (p->debug) fprintf(stderr,"usb_check_and_add() called with VID 0x%x, PID 0x%x\n",descriptor.idVendor, descriptor.idProduct);
151-
152-#ifdef USE_LIBUSB1
153-#if defined(NT) || defined(__APPLE__)
154- /* Ignore libusb1 HID driver capability */
155- {
156- struct libusb_config_descriptor *config = NULL;
157-
158- if (descriptor.bDeviceClass != LIBUSB_CLASS_HID
159- && libusb_get_config_descriptor(dev, 0, &config) != LIBUSB_SUCCESS) {
160- if (p->debug) fprintf(stderr,"Get config desc. 0 failed\n");
161- return 1;
162- }
163-
164- if (descriptor.bDeviceClass == LIBUSB_CLASS_HID
165- || (config->bNumInterfaces > 0
166- && config->interface[0]. num_altsetting > 0
167- && config->interface[0].altsetting[0].bInterfaceClass == LIBUSB_CLASS_HID)) {
168- int i;
169- /* See if this devices is already in the list via the HID interface */
170- /* (This may not be 100% correct in the face of multiple instances
171- of the same device, if Windows allows different drivers for different
172- instances of the same device type.) */
173- for (i = 0; i < p->npaths; i++) {
174- if (p->paths[i]->vid == descriptor.idVendor
175- && p->paths[i]->pid == descriptor.idProduct)
176- break; /* Yes */
177- }
178- if (i < p->npaths) {
179- if (p->debug) fprintf(stderr,"Is an HID device and already added\n");
180- if (config != NULL)
181- libusb_free_config_descriptor(config);
182- return 0;
183- }
184- }
185- if (config != NULL)
186- libusb_free_config_descriptor(config);
187- }
188-#endif
189-#endif
190- if ((itype = inst_usb_match(descriptor.idVendor, descriptor.idProduct))
191- != instUnknown) {
192- char pname[400];
193-
194- if (p->debug) fprintf(stderr,"usb_check_and_add() found known instrument\n");
195-
196- /* Create a path/identification */
197- /* (devnum doesn't seem valid ?) */
198-#ifdef USE_LIBUSB1
199- libusb_ref_device(dev); /* Keep it */
200- sprintf(pname,"usb:/bus%d/dev%d/ (%s)",libusb_get_bus_number(dev),libusb_get_device_address(dev), inst_name(itype));
201-#else
202-# if defined(UNIX)
203- sprintf(pname,"usb:/bus%d/dev%d (%s)",dev->bus->location >> 24, dev->devnum, inst_name(itype));
204-# else
205- sprintf(pname,"usb:/bus%lu/dev%d (%s)",dev->bus->location, dev->devnum, inst_name(itype));
206-# endif
207-#endif
208-
209- /* Add the path to the list */
210- if (p->paths == NULL) {
211- if ((p->paths = (icompath **)calloc(sizeof(icompath *), 1 + 1)) == NULL)
212- error("icoms: calloc failed!");
213- } else {
214- if ((p->paths = (icompath **)realloc(p->paths,
215- sizeof(icompath *) * (p->npaths + 2))) == NULL)
216- error("icoms: realloc failed!");
217- p->paths[p->npaths+1] = NULL;
218- }
219- if ((p->paths[p->npaths] = malloc(sizeof(icompath))) == NULL)
220- error("icoms: malloc failed!");
221- p->paths[p->npaths]->vid = descriptor.idVendor;
222- p->paths[p->npaths]->pid = descriptor.idProduct;
223- p->paths[p->npaths]->dev = dev;
224- p->paths[p->npaths]->hev = NULL;
225- p->paths[p->npaths]->itype = itype;
226- if ((p->paths[p->npaths]->path = strdup(pname)) == NULL)
227- error("icoms: strdup failed!");
228- p->npaths++;
229- p->paths[p->npaths] = NULL;
230- return 1;
231- }
232-
233- return 0;
234-}
235-
236-#endif /* ENABLE_USB */
237-
238-#ifdef USE_LIBUSB1
239-
240-/* Add paths to USB connected instruments, to the existing */
241-/* icompath paths in the icoms structure. */
242-void usb_get_paths(
243-struct _icoms *p
244-) {
245-#ifdef ENABLE_USB
246- ssize_t i, nlist;
247- struct libusb_device **list;
248-
249- /* Scan the USB busses for instruments we recognise */
250- /* We're not expecting any of our instruments to be an interface on a device. */
251-
252- if (p->ctx == NULL) {
253- int rv;
254- if ((rv = libusb_init(&p->ctx)) != 0) {
255- error("libusb_init() failed with %d",rv);
256- }
257- }
258-
259- if (p->debug > 8)
260- libusb_set_debug(p->ctx, p->debug);
261-
262- nlist = libusb_get_device_list(NULL, &list);
263-
264- if (p->debug) fprintf(stderr,"usb_get_paths about to look through devices:\n");
265-
266- for (i = 0; i < nlist; i++) {
267- usb_check_and_add(p, list[i]);
268- }
269-
270- libusb_free_device_list(list, 1);
271-#endif /* ENABLE_USB */
272-}
273-
274-#else /* !USE_LIBUSB1 */
275-
276-/* Add paths to USB connected instruments, to the existing */
277-/* icompath paths in the icoms structure. */
278-void usb_get_paths(
279-struct _icoms *p
280-) {
281-#ifdef ENABLE_USB
282- struct usb_bus *bus;
283-
284- /* Check that we've got an up to date version of libusb */
285- if (usb_argyll_patched() < 2)
286- error("usblib isn't up to date to work with this version of Argyll");
287-
288- if (p->debug > 8)
289- usb_set_debug(p->debug);
290-
291- /* Scan the USB busses for instruments we recognise */
292- /* We're not expecting any of our unstruments to be an interface on a device. */
293-
294- usb_init();
295- usb_find_busses();
296- usb_find_devices();
297-
298- if (p->debug) fprintf(stderr,"usb_get_paths about to look through buses:\n");
299-
300- for (bus = usb_get_busses(); bus != NULL; bus = bus->next) {
301- struct usb_device *dev;
302- if (p->debug) fprintf(stderr,"usb_get_paths about to look through devices:\n");
303- for (dev = bus->devices; dev != NULL; dev = dev->next) {
304- usb_check_and_add(p, dev);
305- }
306- }
307-#endif /* ENABLE_USB */
308-}
309-#endif /* !USE_LIBUSB1 */
310-
311-
312-/* Cleanup and then free a usb dev entry */
313-void usb_del_usb_device(struct usb_device *dev) {
314-
315- if (dev == NULL)
316- return;
317-
318-#ifdef USE_LIBUSB1
319- libusb_unref_device(dev);
320-#endif
321-}
322-
323-/* Cleanup any USB specific icoms */
324-void usb_del_usb(icoms *p) {
325-
326-#ifdef USE_LIBUSB1
327- if (p->ctx != NULL) {
328- libusb_exit(p->ctx);
329- p->ctx = NULL;
330- }
331-#endif /* USE_LIBUSB1 */
332-}
333-
334-/* Return the instrument type if the port number is USB, */
335-/* and instUnknown if it is not. */
336-instType usb_is_usb_portno(
337- icoms *p,
338- int port /* Enumerated port number, 1..n */
339-) {
340-
341- if (p->paths == NULL)
342- p->get_paths(p);
343-
344- if (port <= 0 || port > p->npaths)
345- error("icoms - usb_is_usb_portno: port number %d out of range %d - %d",port,1,p->npaths);
346-
347-#ifdef ENABLE_USB
348- if (p->paths[port-1]->dev != NULL)
349- return p->paths[port-1]->itype;
350-#endif /* ENABLE_USB */
351-
352- return instUnknown;
353-}
354-
355-
356-
357-/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
358-#ifdef ENABLE_USB
359-
360-/* Static list so that all open USB/HID connections can be closed on a SIGKILL */
361-static icoms *icoms_list = NULL;
362-
363-/* Counter set when we're in a USB read or write */
364-/* Note - this isn't perfectly thread safe */
365-static int in_usb_rw = 0;
366-
367-/* Clean up any open USB ports ready for exit */
368-static void icoms_cleanup() {
369- icoms *pp, *np;
370-//printf("~1 icoms_cleanipandexit invoked\n");
371-
372-#if defined(UNIX)
373- /* This is a bit of a hack to compensate for the fact */
374- /* that a ^C will kill the program while ICANON is off. */
375- /* It's really better to restore the original attributes, */
376- /* even when USB is not compiled in. */
377- struct termios news;
378- if (tcgetattr(STDIN_FILENO, &news) >= 0) {
379- news.c_lflag |= (ICANON | ECHO);
380- tcsetattr(STDIN_FILENO,TCSANOW, &news);
381- }
382-#endif
383-
384- for (pp = icoms_list; pp != NULL; pp = np) {
385- np = pp->next;
386-//printf("~1 closing usb port 0x%x\n",pp);
387- /* There's a problem here if have more than one USB port */
388- /* open - win32 doesn't return from the system call. */
389- /* Should we depend on usb read/write routines to call cleanup ? */
390- if (pp->is_usb)
391- usb_close_port(pp);
392- else if (pp->is_hid)
393- hid_close_port(pp);
394- }
395-}
396-
397-#ifdef NT
398-void (__cdecl *usbio_int)(int sig) = SIG_DFL;
399-void (__cdecl *usbio_term)(int sig) = SIG_DFL;
400-#endif
401-#ifdef UNIX
402-void (*usbio_hup)(int sig) = SIG_DFL;
403-void (*usbio_int)(int sig) = SIG_DFL;
404-void (*usbio_term)(int sig) = SIG_DFL;
405-#endif
406-
407-/* On something killing our process, deal with USB cleanup */
408-static void icoms_sighandler(int arg) {
409-//printf("~1 signal handler invoked\n");
410- if (in_usb_rw != 0)
411- in_usb_rw = -1;
412- icoms_cleanup();
413-#ifdef UNIX
414- if (arg == SIGHUP && usbio_hup != SIG_DFL && usbio_hup != SIG_IGN)
415- usbio_hup(arg);
416-#endif /* UNIX */
417- if (arg == SIGINT && usbio_int != SIG_DFL && usbio_int != SIG_IGN)
418- usbio_int(arg);
419- if (arg == SIGTERM && usbio_term != SIG_DFL && usbio_term != SIG_IGN)
420- usbio_term(arg);
421- exit(0);
422-}
423-
424-#ifdef USE_LIBUSB1
425-
426-/* Callback functions */
427-static void bulk_transfer_cb(struct libusb_transfer *transfer)
428-{
429- int *completed = transfer->user_data;
430- *completed = 1;
431- /* caller interprets results and frees transfer */
432-}
433-
434-/* Version of libusb1 sync to async code that returns the pointer */
435-/* to the transfer structure so that the transfer can be cancelled */
436-/* by another thread. */
437-/* Note that this isn't perfectly thread safe - there are race windows. */
438-/* Accessing the libusb_transfer * should at least be protected by a lock. */
439-/* (For Argyll use this problem is unlikely) */
440-static int do_sync_bulk_transfer(struct libusb_device_handle *dev_handle,
441- void **hcancel, unsigned char endpoint, unsigned char *buffer, int length,
442- int *transferred, unsigned int timeout, unsigned char type)
443-{
444- struct libusb_transfer *transfer = libusb_alloc_transfer(0);
445- int completed = 0;
446- int r;
447-
448- if (!transfer)
449- return LIBUSB_ERROR_NO_MEM;
450-
451- libusb_fill_bulk_transfer(transfer, dev_handle, endpoint, buffer, length,
452- bulk_transfer_cb, &completed, timeout);
453- transfer->type = type;
454-
455- r = libusb_submit_transfer(transfer);
456- if (r < 0) {
457- libusb_free_transfer(transfer);
458- return r;
459- }
460-
461- if (hcancel != NULL)
462- *hcancel = (void *)transfer;
463-
464- while (!completed) {
465- r = libusb_handle_events_check(NULL, &completed);
466- if (r < 0) {
467- if (r == LIBUSB_ERROR_INTERRUPTED)
468- continue;
469- libusb_cancel_transfer(transfer);
470- while (!completed) {
471- if (libusb_handle_events_check(NULL, &completed) < 0)
472- break;
473- }
474- if (hcancel != NULL)
475- *hcancel = NULL;
476- libusb_free_transfer(transfer);
477- return r;
478- }
479- }
480-
481- *transferred = transfer->actual_length;
482- switch (transfer->status) {
483- case LIBUSB_TRANSFER_COMPLETED:
484- r = 0;
485- break;
486- case LIBUSB_TRANSFER_TIMED_OUT:
487- r = LIBUSB_ERROR_TIMEOUT;
488- break;
489- case LIBUSB_TRANSFER_STALL:
490- r = LIBUSB_ERROR_PIPE;
491- break;
492- case LIBUSB_TRANSFER_OVERFLOW:
493- r = LIBUSB_ERROR_OVERFLOW;
494- break;
495- case LIBUSB_TRANSFER_NO_DEVICE:
496- r = LIBUSB_ERROR_NO_DEVICE;
497- break;
498- default:
499- r = LIBUSB_ERROR_OTHER;
500- }
501-
502- if (hcancel != NULL)
503- *hcancel = NULL;
504- libusb_free_transfer(transfer);
505-
506- return r;
507-}
508-#endif /* USE_LIBUSB1 */
509-
510-// !!! should fix all these to separate error from length transferred !!!
511-// !!! to take advantage of libus1 !!!
512-
513-/* Our versions of usblib read/write, that exit if a signal was caught */
514-/* This is so that MSWindows works properly */
515-static int icoms_usb_interrupt_write(usb_dev_handle *dev, void **hcancel, int ep, unsigned char *bytes, int size, int timeout) {
516-#ifdef USE_LIBUSB1
517- int tsize;
518-#endif
519- int rv;
520-
521- in_usb_rw++;
522-#ifdef USE_LIBUSB1
523- rv = do_sync_bulk_transfer(dev, hcancel, (unsigned char)ep, bytes, size, &tsize, timeout, LIBUSB_TRANSFER_TYPE_INTERRUPT);
524- if (rv == LIBUSB_SUCCESS)
525- rv = tsize;
526-#else
527- if (hcancel != NULL) *hcancel = (void *)ep;
528- rv = usb_interrupt_write(dev, ep, (char *)bytes, size, timeout);
529-#endif
530- if (in_usb_rw < 0)
531- exit(0);
532-
533- in_usb_rw--;
534- return rv;
535-}
536-
537-static int icoms_usb_interrupt_read(usb_dev_handle *dev, void **hcancel, int ep, unsigned char *bytes, int size, int timeout) {
538-#ifdef USE_LIBUSB1
539- int tsize;
540-#endif
541- int rv;
542-
543- in_usb_rw++;
544-#ifdef USE_LIBUSB1
545- rv = do_sync_bulk_transfer(dev, hcancel, (unsigned char)ep, bytes, size, &tsize, timeout, LIBUSB_TRANSFER_TYPE_INTERRUPT);
546- if (rv == LIBUSB_SUCCESS)
547- rv = tsize;
548-#else
549- if (hcancel != NULL) *hcancel = (void *)ep;
550- rv = usb_interrupt_read(dev, ep, (char *)bytes, size, timeout);
551-#endif
552- if (in_usb_rw < 0)
553- exit(0);
554-
555- in_usb_rw--;
556- return rv;
557-}
558-
559-static int icoms_usb_bulk_write(usb_dev_handle *dev, void **hcancel, int ep, unsigned char *bytes, int size, int timeout) {
560-#ifdef USE_LIBUSB1
561- int tsize;
562-#endif
563- int rv;
564-
565- in_usb_rw++;
566-#ifdef USE_LIBUSB1
567- rv = do_sync_bulk_transfer(dev, hcancel, (unsigned char)ep, bytes, size, &tsize, timeout, LIBUSB_TRANSFER_TYPE_BULK);
568- if (rv == LIBUSB_SUCCESS)
569- rv = tsize;
570-#else
571- if (hcancel != NULL) *hcancel = (void *)ep;
572- rv = usb_bulk_write(dev, ep, (char *)bytes, size, timeout);
573-#endif
574- if (in_usb_rw < 0)
575- exit(0);
576-
577- in_usb_rw--;
578- return rv;
579-}
580-
581-static int icoms_usb_bulk_read(usb_dev_handle *dev, void **hcancel, int ep, unsigned char *bytes, int size, int timeout) {
582-#ifdef USE_LIBUSB1
583- int tsize;
584-#endif
585- int rv;
586-
587- in_usb_rw++;
588-#ifdef USE_LIBUSB1
589- rv = do_sync_bulk_transfer(dev, hcancel, (unsigned char)ep, bytes, size, &tsize, timeout, LIBUSB_TRANSFER_TYPE_BULK);
590- if (rv == LIBUSB_SUCCESS)
591- rv = tsize;
592-#else
593- if (hcancel != NULL) *hcancel = (void *)ep;
594- rv = usb_bulk_read(dev, ep, (char *)bytes, size, timeout);
595-#endif
596- if (in_usb_rw < 0)
597- exit(0);
598-
599- in_usb_rw--;
600- return rv;
601-}
602-
603-
604-static int icoms_usb_control_msg(
605-usb_dev_handle *dev, int requesttype, int request,
606-int value, int index, unsigned char *bytes, int size,
607-int timeout) {
608- int rv;
609-
610- in_usb_rw++;
611-#ifdef USE_LIBUSB1
612- rv = libusb_control_transfer(dev, (uint8_t)requesttype, (uint8_t)request, (uint16_t)value, (uint16_t)index, bytes, (uint16_t)size, timeout);
613-#else
614- rv = usb_control_msg(dev, requesttype, request, value, index, (char *)bytes, size, timeout);
615-#endif
616- if (in_usb_rw < 0)
617- exit(0);
618-
619- in_usb_rw--;
620- return rv;
621-}
622-
623-#endif /* ENABLE_USB */
624-
625-/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
626-
627-/* Install the cleanup signal handlers */
628-void usb_install_signal_handlers(icoms *p) {
629- if (icoms_list == NULL) {
630-//printf("~1 installing signal handler\n");
631-#if defined(UNIX)
632- usbio_hup = signal(SIGHUP, icoms_sighandler);
633-#endif /* UNIX */
634- usbio_int = signal(SIGINT, icoms_sighandler);
635- usbio_term = signal(SIGTERM, icoms_sighandler);
636- }
637-
638- /* Add it to our static list, to allow automatic cleanup on signal */
639- p->next = icoms_list;
640- icoms_list = p;
641-}
642-
643-/* Delete an icoms from our static signal cleanup list */
644-void usb_delete_from_cleanup_list(icoms *p) {
645-
646- /* Find it and delete it from our static cleanup list */
647- if (icoms_list != NULL) {
648- if (icoms_list == p) {
649- icoms_list = p->next;
650- if (icoms_list == NULL) {
651-//printf("~1 removing signal handler\n");
652-#if defined(UNIX)
653- signal(SIGHUP, usbio_hup);
654-#endif /* UNIX */
655- signal(SIGINT, usbio_int);
656- signal(SIGTERM, usbio_term);
657- }
658- } else {
659- icoms *pp;
660- for (pp = icoms_list; pp != NULL; pp = pp->next) {
661- if (pp->next == p) {
662- pp->next = p->next;
663- break;
664- }
665- }
666- }
667- }
668-}
669-
670-/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
671-
672-/* Close an open USB port */
673-/* If we don't do this, the port and/or the device may be left in an unusable state. */
674-void usb_close_port(icoms *p) {
675-
676-#ifdef ENABLE_USB
677- if (p->debug) fprintf(stderr,"usb_close_port() called\n");
678-
679- if (p->is_open && p->usbh != NULL) {
680- int iface;
681-
682- for (iface = 0; iface < p->nifce; iface++)
683-#ifdef USE_LIBUSB1
684- libusb_release_interface(p->usbh, iface);
685-#else
686- usb_release_interface(p->usbh, iface);
687-#endif
688-
689- /* Workaround for some bugs */
690- if (p->uflags & icomuf_reset_before_close) {
691-#ifdef USE_LIBUSB1
692- libusb_reset_device(p->usbh);
693-#else
694- usb_reset(p->usbh);
695-#endif
696- }
697-
698- /* Close as well, othewise we can't re-open */
699- {
700-#ifdef USE_LIBUSB1
701- libusb_close(p->usbh);
702-#else
703- usb_close(p->usbh);
704-#endif
705- }
706- p->usbh = NULL;
707-
708- if (p->debug) fprintf(stderr,"usb port has been released and closed\n");
709- }
710- p->is_open = 0;
711- if (p->ppath != NULL) {
712- if (p->ppath->path != NULL)
713- free(p->ppath->path);
714- free(p->ppath);
715- p->ppath = NULL;
716- }
717-
718- /* Find it and delete it from our static cleanup list */
719- usb_delete_from_cleanup_list(p);
720-
721-#endif /* ENABLE_USB */
722-}
723-
724-/* Open a USB port for all our uses. */
725-static void usb_open_port(
726-icoms *p,
727-int port, /* USB com port, 1 - N, 0 for no change. */
728-int config, /* Configuration number */
729-int wr_ep, /* Write end point */
730-int rd_ep, /* Read end point */
731-icomuflags usbflags,/* Any special handling flags */
732-int retries, /* > 0 if we should retry set_configuration (100msec) */
733-char **pnames /* List of process names to try and kill before opening */
734-) {
735- int tries = 0;
736- if (p->debug) fprintf(stderr,"icoms: About to open the USB port, tries %d\n",retries);
737-
738- if (port >= 1) {
739- if (p->is_open && port != p->port) { /* If port number changes */
740- p->close_port(p);
741- }
742- }
743-
744- /* Make sure the port is open */
745- if (!p->is_open) {
746- struct usb_device_descriptor descriptor;
747-#ifdef USE_LIBUSB1
748- const struct libusb_interface_descriptor *ifd;
749- struct libusb_config_descriptor *confdesc;
750-#else
751- struct usb_interface_descriptor *ifd;
752-#endif
753- int rv, i, iface;
754- kkill_nproc_ctx *kpc = NULL;
755-
756- if (p->debug) fprintf(stderr,"icoms: USB port needs opening\n");
757-
758- /* Do open retries */
759- for (tries = 0; retries >= 0; retries--, tries++) {
760-
761- if (p->ppath != NULL) {
762- if (p->ppath->path != NULL)
763- free(p->ppath->path);
764- free(p->ppath);
765- }
766-
767- if (p->paths == NULL || tries > 0)
768- p->get_paths(p);
769-
770- if (port <= 0 || port > p->npaths)
771- error("icoms - usb_open_port: port number out of range!");
772-
773- if (p->paths[port-1]->dev == NULL)
774- error("icoms - usb_open_port: Not a USB port!");
775-
776- if ((p->ppath = malloc(sizeof(icompath))) == NULL)
777- error("malloc() failed on com port path");
778- *p->ppath = *p->paths[port-1]; /* Structure copy */
779- if ((p->ppath->path = strdup(p->paths[port-1]->path)) == NULL)
780- error("strdup() failed on com port path");
781- p->port = port;
782-
783- if (p->debug) fprintf(stderr,"icoms: About to open USB port '%s'\n",p->ppath->path);
784-
785- if (tries > 0) {
786- //msec_sleep(i_rand(50,100));
787- msec_sleep(77);
788- }
789- if (tries > 0 && pnames != NULL && kpc == NULL) {
790-#if defined(__APPLE__)
791- if ((kpc = kkill_nprocess(pnames, p->debug)) == NULL) {
792- if (p->debug) fprintf(stderr,"kkill_nprocess returned error!\n");
793- }
794-#endif /* !__APPLE__ */
795- }
796-
797-#ifdef USE_LIBUSB1
798- if ((rv = libusb_open(p->ppath->dev, &p->usbh)) != LIBUSB_SUCCESS)
799-#else
800- if ((p->usbh = usb_open(p->ppath->dev)) == NULL)
801-#endif
802- {
803- if (p->debug)
804- fprintf(stderr, "Opening USB port '%s' config %d failed (%s) (Permissions ?)",p->ppath->path,config,USB_STRERROR(rv));
805- if (retries <= 0) {
806- if (kpc != NULL)
807- kpc->del(kpc);
808- error("Opening USB port '%s' config %d failed (%s) (Permissions ?)",p->ppath->path,config,USB_STRERROR(rv));
809- }
810- continue;
811- } else if (p->debug)
812- fprintf(stderr,"open() of USB port '%s' suceeded\n",p->ppath->path);
813-
814- /* Get a copy of the device descriptor so we can see device params */
815-#ifdef USE_LIBUSB1
816- if (libusb_get_device_descriptor(p->ppath->dev, &descriptor) != LIBUSB_SUCCESS)
817- error("Get device descriptor on USB port '%s' failed with %d (%s)",p->ppath->path,rv,libusb_strerror(rv));
818-#else
819- descriptor = dev->descriptor; /* Copy */
820-#endif
821-
822- p->vid = p->ppath->vid;
823- p->pid = p->ppath->pid;
824- p->usbd = p->ppath->dev;
825-
826- p->cnfg = config;
827- p->uflags = usbflags;
828-
829-#ifdef USE_LIBUSB1
830- if (p->uflags & icomuf_detach) {
831- if (libusb_kernel_driver_active(p->usbh, 0) == 1) {
832- if (p->debug) fprintf(stderr,"icoms: detaching '%s'\n",p->ppath->path);
833- if (libusb_detach_kernel_driver(p->usbh, 0) != LIBUSB_SUCCESS) {
834- if (kpc != NULL)
835- kpc->del(kpc);
836- error("Detach kernel driver on USB port '%s' failed with %d (%s)",p->ppath->path,rv,libusb_strerror(rv));
837- }
838- }
839- }
840-#else
841-#if LIBUSB_HAS_DETACH_KERNEL_DRIVER_NP == 1
842- if (p->uflags & icomuf_detach) {
843- usb_detach_kernel_driver_np(p->usbh, 0);
844- }
845-#endif
846-#endif
847-
848- if (p->debug > 1) fprintf(stderr, "Number of configurations = %d\n",
849- descriptor.bNumConfigurations);
850-#if defined(UNIX) && !defined(__APPLE__)
851- /* only call set_configuration on Linux if the device has more than one */
852- /* possible configuration, because Linux does a set_configuration by default, */
853- /* and two of them mess up instruments like the Spyder2 */
854-
855- if (descriptor.bNumConfigurations > 1) {
856-#endif
857-
858- /* Can't skip this, as it is needed to setup the interface and end points on OS X */
859-#ifdef USE_LIBUSB1
860- if ((rv = libusb_set_configuration(p->usbh, p->cnfg)) < 0)
861-#else
862- if ((rv = usb_set_configuration(p->usbh, p->cnfg)) < 0)
863-#endif
864- {
865- if (p->debug)
866- fprintf(stderr,"Configuring USB port '%s' to %d failed with %d (%s)",p->ppath->path,config,rv,USB_STRERROR(rv));
867- if (retries <= 0) {
868- if (kpc != NULL)
869- kpc->del(kpc);
870- error("Configuring USB port '%s' to %d failed with %d (%s)",p->ppath->path,config,rv,USB_STRERROR(rv));
871- }
872-#ifdef USE_LIBUSB1
873- libusb_reset_device(p->usbh); // ~~999 ?????
874- libusb_close(p->usbh);
875-#else
876- usb_reset(p->usbh);
877- usb_close(p->usbh);
878-#endif
879- continue;
880- }
881-#if defined(UNIX) && !defined(__APPLE__)
882- } /* End of if bNumConfigurations > 1 */
883-#endif
884-
885- /* We're done */
886- break;
887- }
888-
889- if (kpc != NULL)
890- kpc->del(kpc);
891-
892- /* Claim all interfaces of this configuration */
893-#ifdef USE_LIBUSB1
894- if ((rv = libusb_get_active_config_descriptor(p->usbd, &confdesc)) != LIBUSB_SUCCESS) {
895- error("Getting config descriptor for USB port '%s' failed with %d (%s)",p->ppath->path,rv,libusb_strerror(rv));
896- }
897- p->nifce = confdesc->bNumInterfaces;
898-#else
899- p->nifce = p->usbd->config->bNumInterfaces;
900-#endif
901-
902-//printf("~1 Number of interfaces = %d\n",p->nifce);
903-
904- /* Claim all the interfaces */
905- for (iface = 0; iface < p->nifce; iface++) {
906- /* (Second parameter is bInterfaceNumber) */
907-
908-#ifdef USE_LIBUSB1
909- /* Should we do a libusb_kernel_driver_active() first ? */
910- if ((rv = libusb_claim_interface(p->usbh, iface)) < 0) {
911- /* Detatch the existing interface. */
912- if (p->uflags & icomuf_detach) {
913- libusb_detach_kernel_driver (p->usbh, iface);
914- if ((rv = libusb_claim_interface(p->usbh, iface)) < 0) {
915- error("Claiming USB port '%s' interface %d failed with %d",p->ppath->path,iface,rv);
916- }
917- }
918- }
919-#else
920- if ((rv = usb_claim_interface(p->usbh, iface)) < 0) {
921-#if LIBUSB_HAS_DETACH_KERNEL_DRIVER_NP == 1
922- /* Detatch the existing interface. */
923- if (p->uflags & icomuf_detach) {
924- usb_detach_kernel_driver_np(p->usbh, iface);
925- if ((rv = usb_claim_interface(p->usbh, iface)) < 0) {
926- error("Claiming USB port '%s' interface %d failed with %d",p->ppath->path,iface,rv);
927- }
928- }
929-#else
930- error("Claiming USB port '%s' interface %d failed with %d",p->ppath->path,iface,rv);
931-#endif
932- }
933-#endif
934-
935- /* Fill in the end point details */
936-#ifdef USE_LIBUSB1
937- ifd = &confdesc->interface[iface].altsetting[0];
938-#else
939- ifd = &p->usbd->config[p->cnfg-1].interface[iface].altsetting[0];
940-#endif
941-//printf("~1 Number of endpoints on iface %d = %d\n",iface, ifd->bNumEndpoints);
942- for (i = 0; i < ifd->bNumEndpoints; i++) {
943- int ad = ifd->endpoint[i].bEndpointAddress;
944- p->EPINFO(ad).valid = 1;
945- p->EPINFO(ad).addr = ad;
946- p->EPINFO(ad).packetsize = ifd->endpoint[i].wMaxPacketSize;
947- p->EPINFO(ad).type = ifd->endpoint[i].bmAttributes & USB_ENDPOINT_TYPE_MASK;
948- /* Some I/F seem to hang if we do this, some seem to hang if we don't ! */
949- if (!(p->uflags & icomuf_no_open_clear))
950-#ifdef USE_LIBUSB1
951- libusb_clear_halt(p->usbh, (unsigned char)ad);
952-#else
953- usb_clear_halt(p->usbh, ad);
954-#endif
955-//printf("~1 %d: endpoint addr %02x pktsze %d, type %d\n",i,ad,ifd->endpoint[i].wMaxPacketSize,p->EPINFO(ad).type);
956- }
957-
958-#ifdef NEVER
959- /* Get the serial number */
960- {
961- int rv;
962- struct usb_device_descriptor descriptor;
963-
964- if (p->debug) fprintf(stderr,"About to get device serial number\n");
965-#ifdef USE_LIBUSB1
966- if ((rv = libusb_get_device_descriptor(p->usbd, &descriptor)) != LIBUSB_SUCCESS)
967- error("get_device_descriptor failed with %d USB port '%s'",rv,p->ppath->path);
968-#else
969- descriptor = dev->descriptor; /* Copy */
970-#endif
971- if ((rv = libusb_get_string_descriptor_ascii(p->usbh, descriptor.iSerialNumber, p->serialno, 32)) <= 0) {
972- if (p->debug) fprintf(stderr,"Failed to get device serial number %d\n",rv);
973- p->serialno[0] = '\000';
974- }
975- if (p->debug) fprintf(stderr,"Device serial number = '%s'\n",p->serialno);
976- }
977-#endif /* NEVER */
978- }
979-
980- /* Set "serial" coms values */
981- p->wr_ep = wr_ep;
982- p->rd_ep = rd_ep;
983- p->rd_qa = p->EPINFO(rd_ep).packetsize;
984-//printf("~1 read quanta = packet size = %d\n",p->rd_qa);
985- if (p->rd_qa == 0)
986- p->rd_qa = 8;
987-
988- p->is_usb = 1;
989- p->is_open = 1;
990- if (p->debug) fprintf(stderr,"icoms: USB port is now open\n");
991- }
992-
993- if (p->debug) fprintf(stderr,"icoms: Clearing any USB errors\n");
994-
995- /* Install the cleanup signal handlers, and add to our cleanup list */
996- usb_install_signal_handlers(p);
997-}
998-
999-/* ========================================================= */
1000-/* USB write/read "serial" imitation */
1001-
1002-/* Write the characters in the buffer out */
1003-/* Data will be written up to the terminating nul */
1004-/* Return relevant error status bits */
1005-static int
1006-icoms_usb_ser_write(
1007-icoms *p,
1008-char *wbuf,
1009-double tout)
1010-{
1011- int c, len, wbytes;
1012- long toc, i, top; /* Timout count, counter, timeout period */
1013- int ep = p->wr_ep; /* End point */
1014- int bulk = 0; /* nz if bulk rather than interrupt read */
1015-
1016- if (p->debug) fprintf(stderr,"icoms: About to write '%s' ",icoms_fix(wbuf));
1017-
1018- if (!p->is_open)
1019- error("icoms_ser_write: not initialised");
1020-
1021- if (p->EPINFO(ep).valid == 0)
1022- error("icoms_ser_write invalid end point 0x%02x",ep);
1023-
1024- if (p->EPINFO(ep).type != ICOM_EP_TYPE_BULK
1025- && p->EPINFO(ep).type != ICOM_EP_TYPE_INTERRUPT)
1026- error("icoms_ser_write unhandled end point type %d",p->EPINFO(ep).type);
1027-
1028- if (p->EPINFO(ep).type == ICOM_EP_TYPE_BULK)
1029- bulk = 1;
1030-
1031- len = strlen(wbuf);
1032- tout *= 1000.0; /* Timout in msec */
1033- p->lerr = 0;
1034-
1035- top = (int)(tout + 0.5); /* Timeout period in msecs */
1036- toc = (int)(tout/top + 0.5); /* Number of timout periods in timeout */
1037- if (toc < 1)
1038- toc = 1;
1039-
1040-#ifdef ENABLE_USB
1041-
1042- /* Until data is all written, we time out, or the user aborts */
1043- for (i = toc; i > 0 && len > 0;) {
1044-//printf("~1 write: attempting to write %d bytes to usb top = %d, i = %d\n",len,top,i);
1045-
1046- if (bulk)
1047- wbytes = icoms_usb_bulk_write(p->usbh, NULL, ep, (unsigned char *)wbuf, len, top);
1048- else
1049- wbytes = icoms_usb_interrupt_write(p->usbh, NULL, ep, (unsigned char *)wbuf, len, top);
1050- if (wbytes < 0) {
1051-//printf("~1 usb_interrupt_write failed with %d = '%s'\n",wbytes,usb_strerror());
1052-#ifdef USE_LIBUSB1
1053- if (wbytes != LIBUSB_ERROR_TIMEOUT) /* Not a timeout */
1054-#else
1055-#if defined(UNIX)
1056- if (wbytes != 0 && wbytes != -ETIMEDOUT) /* Not a timeout } */
1057-#else
1058- if (wbytes != -116) /* Not a timeout */
1059-#endif /* UNIX */
1060-#endif
1061- {
1062- p->lerr |= ICOM_USBW;
1063- break;
1064- }
1065- i--; /* timeout */
1066- } else if (wbytes > 0) { /* Account for bytes written */
1067-//printf("~1 wrote %d bytes\n",wbytes);
1068- i = toc;
1069- wbuf += wbytes;
1070- len -= wbytes;
1071- }
1072- /* Check for user interrupt */
1073- if ((c = poll_con_char()) != 0 && p->uih[c] != ICOM_OK) {
1074- p->cut = c;
1075- p->lerr |= p->uih[c];
1076- }
1077- }
1078- if (i <= 0) /* Must have timed out */
1079- p->lerr |= ICOM_TO;
1080-
1081-#else /* !ENABLE_USB */
1082- p->lerr = ICOM_NOTS;
1083-#endif /* !ENABLE_USB */
1084-
1085- if (p->debug) fprintf(stderr,"ICOM err 0x%x\n",p->lerr);
1086- return p->lerr;
1087-}
1088-
1089-
1090-/* Read characters into the buffer */
1091-/* Return string will be terminated with a nul */
1092-/* Read only in paket sized chunks, and retry if */
1093-/* the bytes requested aren'r read, untill we get a */
1094-/* timeout or a terminating char is read */
1095-static int
1096-icoms_usb_ser_read(icoms *p,
1097-char *rbuf, /* Buffer to store characters read */
1098-int bsize, /* Buffer size */
1099-char tc, /* Terminating characer */
1100-int ntc, /* Number of terminating characters */
1101-double tout) /* Time out in seconds */
1102-{
1103- int c, j, rbytes;
1104- long toc, i, top; /* Timout count, counter, timeout period */
1105- char *rrbuf = rbuf; /* Start of return buffer */
1106- int ep = p->rd_ep; /* End point */
1107- int bulk = 0; /* nz if bulk rather than interrupt read */
1108-
1109- if (p->debug) fprintf(stderr,"icoms: Read called\n");
1110-
1111-#ifdef QUIET_MEMCHECKERS
1112- memset(rbuf, 0, bsize);
1113-#endif
1114-
1115- if (!p->is_open)
1116- error("icoms_usb_ser_read: not initialised");
1117-
1118- if (p->EPINFO(ep).valid == 0)
1119- error("icoms_usb_ser_read invalid end point 0x%02x",ep);
1120-
1121- if (p->EPINFO(ep).type != ICOM_EP_TYPE_BULK
1122- && p->EPINFO(ep).type != ICOM_EP_TYPE_INTERRUPT)
1123- error("icoms_usb_ser_read unhandled end point type %d",p->EPINFO(ep).type);
1124-
1125- if (p->EPINFO(ep).type == ICOM_EP_TYPE_BULK)
1126- bulk = 1;
1127-
1128- if (bsize < 3)
1129- error("icoms_usb_ser_read given too small a buffer");
1130-
1131-for (i = 0; i < bsize; i++) rbuf[i] = 0;
1132-
1133- p->lerr = 0;
1134- tout *= 1000.0; /* Timout in msec */
1135- bsize--; /* Allow space for null */
1136-
1137- /* Have to do this in one go, because libusb has no way */
1138- /* of timing out and returning the number of characters read */
1139- /* up to the timeout, and it looses characters. */
1140- top = (int)(tout + 0.5); /* Timeout period in msecs */
1141- toc = (int)(tout/top + 0.5); /* Number of timout periods in timeout */
1142- if (toc < 1)
1143- toc = 1;
1144-
1145-#ifdef ENABLE_USB
1146-//printf("~1 usb read end point 0x%x, read quanta %d\n",p->rd_ep,p->rd_qa);
1147- /* Until data is all read, we time out, or the user aborts */
1148- for (i = toc, j = 0; i > 0 && bsize > 1 && j < ntc ;) {
1149- int rsize = p->rd_qa < bsize ? p->rd_qa : bsize;
1150-
1151-//printf("~1 read: attempting to read %d bytes from usb, top = %d, i = %d, j = %d\n",bsize > p->rd_qa ? p->rd_qa : bsize,top,i,j);
1152- /* We read one read quanta at a time (usually 8 bytes), to avoid */
1153- /* problems with libusb loosing characters whenever it times out. */
1154- if (bulk)
1155- rbytes = icoms_usb_bulk_read(p->usbh, NULL, ep, (unsigned char *)rbuf, rsize, top);
1156- else
1157- rbytes = icoms_usb_interrupt_read(p->usbh, NULL, ep, (unsigned char *)rbuf, rsize, top);
1158- if (rbytes < 0) {
1159-//printf("~1 usb_interrupt_read failed with %d = '%s'\n",rbytes,usb_strerror());
1160-//printf("~1 rbuf = '%s'\n",icoms_fix(rrbuf));
1161-#ifdef USE_LIBUSB1
1162- if (rbytes != LIBUSB_ERROR_TIMEOUT) /* Not a timeout */
1163-#else
1164-#if defined(UNIX)
1165- if (rbytes != 0 && rbytes != -ETIMEDOUT) /* Not a timeout } */
1166-#else
1167- if (rbytes != -116) /* Not a timeout */
1168-#endif /* UNIX */
1169-#endif
1170- {
1171- p->lerr |= ICOM_USBR;
1172- break;
1173- }
1174- i--; /* Timeout */
1175- } else if (rbytes >= 0) { /* Account for bytes read */
1176-//printf("~1 rbuf = '%s'\n",icoms_fix(rrbuf));
1177-//printf("~1 read %d bytes,",rbytes);
1178- i = toc;
1179- bsize -= rbytes;
1180- while(rbytes) { /* Count termination characters */
1181- if (*rbuf++ == tc)
1182- j++;
1183- rbytes--;
1184- }
1185-//printf(" j = %d\n",j);
1186- }
1187- /* Check for user abort */
1188- if ((c = poll_con_char()) != 0 && p->uih[c] != ICOM_OK) {
1189- p->cut = c;
1190- p->lerr |= p->uih[c];
1191- }
1192- }
1193-
1194- if (i <= 0) /* Must have timed out */
1195- p->lerr |= ICOM_TO;
1196-
1197-#endif /* ENABLE_USB */
1198-
1199- *rbuf = '\000';
1200-
1201- if (p->debug) fprintf(stderr,"icoms: About to return read '%s' ICOM err 0x%x\n",icoms_fix(rrbuf),p->lerr);
1202-
1203- return p->lerr;
1204-}
1205-
1206-/* - - - - - - - - - - - - - */
1207-/* USB control message - thread friendly */
1208-static int
1209-icoms_usb_control_th(
1210-icoms *p,
1211-int requesttype, /* 8 bit request type (USB bmRequestType) */
1212-int request, /* 8 bit request code (USB bRequest) */
1213-int value, /* 16 bit value (USB wValue) */
1214-int index, /* 16 bit index (USB wIndex) */
1215-unsigned char *rwbuf, /* Write or read buffer */
1216-int rwsize, /* Bytes to read or write */
1217-double tout, /* Timeout in seconds */
1218-int debug, /* debug flag value */
1219-int *cut, /* Character that caused termination */
1220-int checkabort) { /* Check for abort from keyboard */
1221- int lerr; /* Last error */
1222- int c, rwbytes; /* Data bytes read or written */
1223- long top; /* timeout in msec */
1224-
1225- if (debug) {
1226- fprintf(stderr,"icoms: About to do control %02x, %02x %04x %04x %04x\n",
1227- requesttype, request, value, index, rwsize);
1228- if ((requesttype & USB_ENDPOINT_IN) == 0) {
1229- fprintf(stderr,"icoms: Writing control data %s\n",icoms_tohex(rwbuf, rwsize));
1230- }
1231- }
1232-
1233- if (!p->is_open)
1234- error("icoms_read: not initialised");
1235-
1236- lerr = 0;
1237- top = (int)(tout * 1000.0 + 0.5); /* Timout in msec */
1238-
1239-#ifdef QUIET_MEMCHECKERS
1240- if (requesttype & USB_ENDPOINT_IN)
1241- memset(rwbuf, 0, rwsize);
1242-#endif
1243-
1244-#ifdef ENABLE_USB
1245- rwbytes = icoms_usb_control_msg(p->usbh, requesttype, request, value, index,
1246- rwbuf, rwsize, top);
1247- if (rwbytes < 0) {
1248-#ifdef USE_LIBUSB1
1249- if (rwbytes != LIBUSB_ERROR_TIMEOUT) /* Not a timeout */
1250-#else
1251-#if defined(UNIX)
1252- if (rwbytes != 0 && rwbytes != -ETIMEDOUT) /* Not a timeout */
1253-#else
1254- if (rwbytes != -116) /* Not a timeout */
1255-#endif /* UNIX */
1256-#endif
1257- {
1258- lerr |= ICOM_USBW;
1259- } else {
1260- lerr |= ICOM_TO;
1261- }
1262- } else if (rwbytes != rwsize) {
1263- if (requesttype & USB_ENDPOINT_IN) /* Device to host */
1264- lerr |= ICOM_USBR; /* Read error */
1265- else
1266- lerr |= ICOM_USBW; /* Write error */
1267- }
1268-
1269- if (checkabort) {
1270- /* Check for user abort */
1271- if ((c = poll_con_char()) != 0 && p->uih[c] != ICOM_OK) {
1272- *cut = c;
1273- lerr |= p->uih[c];
1274-//printf("~1 got for user abort with char 0x%x, code 0x%x\n",c,p->uih[c]);
1275- }
1276- }
1277-
1278-#else /* !ENABLE_USB */
1279- lerr = ICOM_NOTS;
1280-#endif /* !ENABLE_USB */
1281-
1282- if (debug && (requesttype & USB_ENDPOINT_IN))
1283- fprintf(stderr,"icoms: Reading control data %s\n",icoms_tohex(rwbuf, rwsize));
1284- if (debug) fprintf(stderr,"icoms: About to return control ICOM err 0x%x\n",lerr);
1285-
1286- return lerr;
1287-}
1288-
1289-/* USB control message */
1290-/* Same as above, but set error state */
1291-static int
1292-icoms_usb_control(
1293-icoms *p,
1294-int requesttype, /* 8 bit request type (USB bmRequestType) */
1295-int request, /* 8 bit request code (USB bRequest) */
1296-int value, /* 16 bit value (USB wValue) */
1297-int index, /* 16 bit index (USB wIndex) */
1298-unsigned char *rwbuf, /* Write or read buffer */
1299-int rwsize, /* Bytes to read or write */
1300-double tout) {
1301- p->lerr = icoms_usb_control_th(p, requesttype, request, value, index, rwbuf, rwsize, tout,
1302- p->debug, &p->cut, 1);
1303- return p->lerr;
1304-}
1305-
1306-/* - - - - - - - - - - - - - */
1307-/* USB Read - thread friendly */
1308-/* Return error code (don't set error state). */
1309-/* Don't retry on a short read, return ICOM_SHORT. */
1310-static int
1311-icoms_usb_read_th(icoms *p,
1312- void **hcancel, /* Cancel handle */
1313- int ep, /* End point address */
1314- unsigned char *rbuf, /* Read buffer */
1315- int bsize, /* Bytes to read */
1316- int *breadp, /* Bytes read */
1317- double tout, /* Timeout in seconds */
1318- int debug, /* debug flag value */
1319- int *cut, /* Character that caused termination */
1320- int checkabort /* Check for abort from keyboard */
1321-) {
1322- int lerr; /* Last error */
1323- int bread, qa;
1324- long top; /* Timeout period */
1325- int bulk = 0; /* nz if bulk rather than interrupt read */
1326-
1327-#ifdef QUIET_MEMCHECKERS
1328- memset(rbuf, 0, bsize);
1329-#endif
1330-
1331- if (!p->is_open)
1332- error("icoms_usb_read: not initialised");
1333-
1334- if (p->EPINFO(ep).valid == 0)
1335- error("icoms_usb_read invalid end point 0x%02x",ep);
1336-
1337- if (p->EPINFO(ep).type != ICOM_EP_TYPE_BULK
1338- && p->EPINFO(ep).type != ICOM_EP_TYPE_INTERRUPT)
1339- error("icoms_usb_read unhandled end point type %d",p->EPINFO(ep).type);
1340-
1341- if (p->EPINFO(ep).type == ICOM_EP_TYPE_BULK)
1342- bulk = 1;
1343-
1344-// qa = p->EPINFO(ep).packetsize; /* For finer grained abort and partial reads */
1345- qa = bsize; /* For simpler tracing */
1346-
1347- lerr = 0;
1348- bread = 0;
1349-
1350- top = (int)(tout * 1000 + 0.5); /* Timeout period in msecs */
1351-
1352-#ifdef ENABLE_USB
1353-
1354- /* Bug workaround - on some OS's for some devices */
1355- if (p->uflags & icomuf_resetep_before_read) {
1356- msec_sleep(1); /* Let device recover ? */
1357- p->usb_resetep(p, ep);
1358- msec_sleep(1); /* Let device recover (ie. Spyder 3) */
1359- }
1360-
1361- /* Until data is all read, we get a short read, we time out, or the user aborts */
1362-//printf("~1 usb_read of %d bytes, timout %f\n",bsize,tout);
1363- while (bsize > 0) {
1364- int c, rbytes;
1365- int rsize = bsize > qa ? qa : bsize;
1366-
1367-//printf("~1 read %d bytes this time\n",rsize);
1368- if (bulk)
1369- rbytes = icoms_usb_bulk_read(p->usbh, hcancel, ep, rbuf, rsize, top);
1370- else
1371- rbytes = icoms_usb_interrupt_read(p->usbh, hcancel, ep, rbuf, rsize, top);
1372-//printf("~1 got result %d\n",rbytes);
1373- if (rbytes < 0) {
1374-#ifdef USE_LIBUSB1
1375- if (rbytes == LIBUSB_ERROR_TIMEOUT) /* A timeout */
1376-#else
1377-#if defined(UNIX)
1378- if (rbytes == -ETIMEDOUT) /* A timeout */
1379-#else
1380- if (rbytes == -116) /* A timeout */
1381-#endif /* UNIX */
1382-#endif
1383- lerr |= ICOM_TO;
1384- else
1385- lerr |= ICOM_USBR;
1386- break;
1387- } else { /* Account for bytes read */
1388- bsize -= rbytes;
1389- rbuf += rbytes;
1390- bread += rbytes;
1391- }
1392- if (rbytes != rsize) {
1393- lerr |= ICOM_SHORT;
1394- break;
1395- }
1396- if (checkabort) {
1397- /* Check for user abort */
1398- if ((c = poll_con_char()) != 0 && p->uih[c] != ICOM_OK) {
1399-//printf("~1 got for user abort with char 0x%x, code 0x%x\n",c,p->uih[c]);
1400- *cut = c;
1401- lerr |= p->uih[c];
1402- }
1403- }
1404- }
1405-
1406- if (breadp != NULL)
1407- *breadp = bread;
1408-
1409-//printf("~1 about to return 0x%x\n",lerr);
1410-
1411-#else /* !ENABLE_USB */
1412- lerr = ICOM_NOTS;
1413-#endif /* !ENABLE_USB */
1414-
1415- if (debug) fprintf(stderr,"icoms: About to return usb read %d bytes, ICOM err 0x%x\n",bread, lerr);
1416-
1417- return lerr;
1418-}
1419-
1420-/* USB Read */
1421-/* Same as above, but set error state */
1422-static int
1423-icoms_usb_read(
1424- icoms *p,
1425- int ep, /* End point address */
1426- unsigned char *rbuf, /* Read buffer */
1427- int rsize, /* Bytes to read */
1428- int *bread, /* Bytes read */
1429- double tout /* Timeout in seconds */
1430-) {
1431- p->lerr = icoms_usb_read_th(p, NULL, ep, rbuf, rsize, bread, tout, p->debug, &p->cut, 1);
1432-
1433- return p->lerr;
1434-}
1435-
1436-/* - - - - - - - - - - - - - */
1437-
1438-/* USB Write - thread friendly */
1439-/* Return error code (don't set error state). */
1440-/* Don't retry on a short read, return ICOM_SHORT. */
1441-static int
1442-icoms_usb_write_th(icoms *p,
1443- void **hcancel, /* Cancel handle */
1444- int ep, /* End point address */
1445- unsigned char *wbuf, /* Write buffer */
1446- int bsize, /* Bytes to write */
1447- int *bwrittenp, /* Bytes written */
1448- double tout, /* Timeout in seconds */
1449- int debug, /* debug flag value */
1450- int *cut, /* Character that caused termination */
1451- int checkabort /* Check for abort from keyboard */
1452-) {
1453- int lerr; /* Last error */
1454- int bwritten, qa;
1455- long top; /* Timout timeout period */
1456- int bulk = 0; /* nz if bulk rather than interrupt read */
1457-
1458- if (!p->is_open)
1459- error("icoms_usb_write: not initialised");
1460-
1461- if (p->EPINFO(ep).valid == 0)
1462- error("icoms_usb_write invalid end point 0x%02x",ep);
1463-
1464- if (p->EPINFO(ep).type != ICOM_EP_TYPE_BULK
1465- && p->EPINFO(ep).type != ICOM_EP_TYPE_INTERRUPT)
1466- error("icoms_usb_write unhandled end point type %d",p->EPINFO(ep).type);
1467-
1468- if (p->EPINFO(ep).type == ICOM_EP_TYPE_BULK)
1469- bulk = 1;
1470-
1471-// qa = p->EPINFO(ep).packetsize; /* For finer grained abort and partial reads */
1472- qa = bsize; /* For simpler tracing */
1473-
1474- lerr = 0;
1475- bwritten = 0;
1476-
1477- top = (int)(tout * 1000 + 0.5); /* Timeout period in msecs */
1478-
1479-#ifdef ENABLE_USB
1480-
1481- /* Until data is all written, we get a short write, we time out, or the user aborts */
1482- while (bsize > 0) {
1483- int c, wbytes;
1484- int wsize = bsize > qa ? qa : bsize;
1485-
1486- if (bulk)
1487- wbytes = icoms_usb_bulk_write(p->usbh, hcancel, ep, wbuf, wsize, top);
1488- else
1489- wbytes = icoms_usb_interrupt_write(p->usbh, hcancel, ep, wbuf, wsize, top);
1490- if (wbytes < 0) {
1491-#ifdef USE_LIBUSB1
1492- if (wbytes == LIBUSB_ERROR_TIMEOUT) /* A timeout */
1493-#else
1494-#if defined(UNIX)
1495- if (wbytes == -ETIMEDOUT) /* A timeout */
1496-#else
1497- if (wbytes == -116) /* A timeout */
1498-#endif /* UNIX */
1499-#endif
1500- lerr |= ICOM_TO;
1501- else
1502- lerr |= ICOM_USBR;
1503- break;
1504- } else { /* Account for bytes written */
1505- bsize -= wbytes;
1506- wbuf += wbytes;
1507- bwritten += wbytes;
1508- }
1509- if (wbytes != wsize) {
1510- lerr |= ICOM_SHORT;
1511- break;
1512- }
1513- if (checkabort) {
1514- /* Check for user abort */
1515- if ((c = poll_con_char()) != 0 && p->uih[c] != ICOM_OK) {
1516- *cut = c;
1517- lerr |= p->uih[c];
1518- }
1519- }
1520- }
1521-
1522- if (bwrittenp != NULL)
1523- *bwrittenp = bwritten;
1524-
1525-#else /* !ENABLE_USB */
1526- lerr = ICOM_NOTS;
1527-#endif /* !ENABLE_USB */
1528-
1529- if (debug) fprintf(stderr,"icoms: About to return usb write %d bytes, ICOM err 0x%x\n",bwritten, lerr);
1530-
1531- return lerr;
1532-}
1533-
1534-/* USB Write */
1535-/* Same as above, but set error state */
1536-static int
1537-icoms_usb_write(
1538- icoms *p,
1539- int ep, /* End point address */
1540- unsigned char *wbuf, /* Read buffer */
1541- int wsize, /* Bytes to write */
1542- int *bwritten, /* Bytes written */
1543- double tout /* Timeout in seconds */
1544-) {
1545- p->lerr = icoms_usb_write_th(p, NULL, ep, wbuf, wsize, bwritten, tout, p->debug, &p->cut, 1);
1546- return p->lerr;
1547-}
1548-
1549-
1550-/* - - - - - - - - - - - - - - - - - - - - - - - - - */
1551-/* Cancel i/o in another thread */
1552-/* NOTE this should reall be protected by a lock. */
1553-int icoms_usb_cancel_io(
1554- icoms *p,
1555- void *hcancel
1556-) {
1557- int rv = 0;
1558-#ifdef USE_LIBUSB1
1559- if (hcancel != NULL)
1560- rv = libusb_cancel_transfer((struct libusb_transfer *)hcancel);
1561-#else
1562- msec_sleep(1); /* Let device recover ? */
1563- rv = usb_resetep(p->usbh, (int)hcancel); /* Not reliable ? */
1564- msec_sleep(1); /* Let device recover ? */
1565-#endif
1566-
1567- if (rv == 0)
1568- return ICOM_OK;
1569-
1570- return ICOM_USBW;
1571-}
1572-
1573-/* - - - - - - - - - - - - - - - - - - - - - - - - - */
1574-/* Reset and end point data toggle to 0 */
1575-int icoms_usb_resetep(
1576- icoms *p,
1577- int ep /* End point address */
1578-) {
1579- int rv;
1580-#ifdef USE_LIBUSB1
1581- rv = libusb_resetep(p->usbh, (unsigned char)ep); /* Is this the same though ? */
1582-#else
1583- rv = usb_resetep(p->usbh, ep); /* Not reliable ? */
1584-#endif
1585-
1586- if (rv == 0)
1587- return ICOM_OK;
1588-
1589- return ICOM_USBW;
1590-}
1591-
1592-/* - - - - - - - - - - - - - - - - - - - - - - - - - */
1593-/* Clear a halt on an end point */
1594-int icoms_usb_clearhalt(
1595- icoms *p,
1596- int ep /* End point address */
1597-) {
1598- int rv;
1599-#ifdef USE_LIBUSB1
1600- rv = libusb_clear_halt(p->usbh, (unsigned char)ep);
1601-#else
1602- rv = usb_clear_halt(p->usbh, ep);
1603-#endif
1604-
1605- if (rv == 0)
1606- return ICOM_OK;
1607-
1608- return ICOM_USBW;
1609-}
1610-
1611-/* - - - - - - - - - - - - - - - - - - - - - - - - - */
1612-/* write and read */
1613-static int
1614-icoms_write_read(
1615-icoms *p,
1616-char *wbuf, /* Write puffer */
1617-char *rbuf, /* Read buffer */
1618-int bsize, /* Buffer size */
1619-char tc, /* Terminating characer */
1620-int ntc, /* Number of terminating characters */
1621-double tout
1622-) {
1623- int xuserm = 0; /* User flags from transmit operation */
1624- if (p->debug) fprintf(stderr,"\nicoms: Write_Read called with '%s'\n",icoms_fix(wbuf));
1625-
1626- p->lerr = 0;
1627-
1628- /* Flush any stray chars */
1629- /* (This doesn't work on USB because of libusb's problems with timeouts */
1630- if (!p->is_usb) {
1631- for (p->lerr = 0;;) { /* Until we get a timeout */
1632- int debug = p->debug; p->debug = 0;
1633- p->read(p, rbuf, bsize, '\000', 100000, 0.01);
1634- p->debug = debug;
1635- if (p->lerr != 0)
1636- break; /* Expect timeout with nothing to read */
1637- }
1638- if (p->lerr & ICOM_USERM) {
1639- return p->lerr; /* We got a user interrupt */
1640- }
1641- p->lerr = 0;
1642- }
1643-
1644- /* Write the write data */
1645- p->write(p, wbuf, tout);
1646-
1647- /* Return error if coms error or user abort. Save error if user terminate or command */
1648- if ((p->lerr & ~ICOM_USERM) != ICOM_OK || (p->lerr & ICOM_USERM) == ICOM_USER) {
1649- if (p->debug) fprintf(stderr,"icoms: Write_Read Write failed - returning 0x%x\n",p->lerr);
1650- return p->lerr;
1651- } else {
1652- xuserm = (p->lerr & ICOM_USERM);
1653- }
1654-
1655- /* Read response */
1656- p->read(p, rbuf, bsize, tc, ntc, tout);
1657- if (p->debug) {
1658- if (p->lerr != 0)
1659- fprintf(stderr,"icoms: Write_Read Write failed - returning 0x%x\n",p->lerr);
1660- else
1661- fprintf(stderr,"icoms: Write_Read Write_Read success, returning '%s'\n",icoms_fix(rbuf));
1662- }
1663- if (p->lerr == ICOM_OK && xuserm != ICOM_OK)
1664- return xuserm;
1665-
1666- return p->lerr;
1667-}
1668-
1669-/* ------------------------------------------------- */
1670-/* Set the usb port number and characteristics. */
1671-/* This may be called to re-establish a connection that has failed */
1672-static void
1673-icoms_set_usb_port(
1674-icoms *p,
1675-int port, /* USB com port, 1 - N, 0 for no change. */
1676-int config, /* Configuration */
1677-int wr_ep, /* "Serial" Write end point */
1678-int rd_ep, /* "Serial" Read end point */
1679-icomuflags usbflags, /* Any special handling flags */
1680-int retries, /* > 0 if we should retry set_configuration (100msec) */
1681-char **pnames /* List of process names to try and kill before opening */
1682-) {
1683- if (p->debug) fprintf(stderr,"icoms: About to set usb port characteristics\n");
1684-
1685- if (p->is_open)
1686- p->close_port(p);
1687-
1688- if (p->is_usb_portno(p, port) != instUnknown) {
1689-
1690- usb_open_port(p, port, config, wr_ep, rd_ep, usbflags, retries, pnames);
1691-
1692- p->write = icoms_usb_ser_write;
1693- p->read = icoms_usb_ser_read;
1694-
1695- }
1696- if (p->debug) fprintf(stderr,"icoms: usb port characteristics set ok\n");
1697-
1698- // ~~~999
1699-// if (p->debug)
1700-// usb_set_debug(p->debug);
1701-}
1702-
1703-/* Reset user interrupt handling to default (Esc, ^C, q or 'Q' = Abort) */
1704-static void icoms_reset_uih(
1705-icoms *p
1706-) {
1707- int i;
1708-
1709- for (i = 0; i < 255; i++)
1710- p->uih[i] = ICOM_OK;
1711-
1712- p->uih[0x1b] = ICOM_USER; /* Escape */
1713- p->uih['q'] = ICOM_USER; /* q */
1714- p->uih['Q'] = ICOM_USER; /* Q */
1715- p->uih[0x03] = ICOM_USER; /* ^C */
1716-}
1717-
1718-/* Set a key range to the given handling type */
1719-/* min & max are between 0 and 255, status is one of */
1720-static void icoms_set_uih(
1721-icoms *p,
1722-int min, /* Start key code */
1723-int max, /* End key code (inclusive) */
1724-int status /* ICOM_OK, ICOM_USER, ICOM_TERM, ICOM_TRIG, ICOM_CMND */
1725-) {
1726- int i;
1727-
1728- if (min < 0)
1729- min = 0;
1730- else if (min > 255)
1731- min = 255;
1732- if (max < 0)
1733- max = 0;
1734- else if (max > 255)
1735- max = 255;
1736-
1737- if (status != ICOM_OK
1738- && status != ICOM_USER
1739- && status != ICOM_TERM
1740- && status != ICOM_TRIG
1741- && status != ICOM_CMND)
1742- status = ICOM_OK;
1743-
1744- for (i = min; i <= max; i++) {
1745- p->uih[i] = status;
1746- }
1747-}
1748-
1749-/* Get the character that caused the user interrupt */
1750-/* Clear it to 0x00 after reading it */
1751-static int icoms_get_uih_char(icoms *p) {
1752- int c = p->cut;
1753- p->cut = 0;
1754- return c;
1755-}
1756-
1757-
1758-/* Poll for a user abort, terminate, trigger or command. */
1759-/* Wait for a key rather than polling, if wait != 0 */
1760-/* Return: */
1761-/* ICOM_OK if no key was hit or the key has no meaning. */
1762-/* ICOM_USER if User abort has been hit, */
1763-/* ICOM_TERM if User terminate has been hit. */
1764-/* ICOM_TRIG if User trigger has been hit */
1765-/* ICOM_CMND if User command has been hit */
1766-int icoms_poll_user(icoms *p, int wait) {
1767- int c;
1768-
1769- if (wait) {
1770- int rv;
1771- for (;;) {
1772- c = next_con_char();
1773- p->cut = c;
1774- rv = p->uih[c];
1775- if (rv != ICOM_OK)
1776- return rv;
1777- }
1778- } else {
1779- c = poll_con_char();
1780- if (c != 0) {
1781- p->cut = c;
1782- return p->uih[c];
1783- }
1784- }
1785- return ICOM_OK;
1786-}
1787-
1788-/* ---------------------------------------------------------------------------------*/
1789-
1790-/* Set the USB specific icoms methods */
1791-void usb_set_usb_methods(
1792-icoms *p
1793-) {
1794- p->write_read = icoms_write_read;
1795-
1796- p->reset_uih = icoms_reset_uih;
1797- p->set_uih = icoms_set_uih;
1798- p->get_uih_char = icoms_get_uih_char;
1799-
1800- p->is_usb_portno = usb_is_usb_portno;
1801- p->set_usb_port = icoms_set_usb_port;
1802- p->usb_control_th = icoms_usb_control_th;
1803- p->usb_control = icoms_usb_control;
1804- p->usb_read_th = icoms_usb_read_th;
1805- p->usb_read = icoms_usb_read;
1806- p->usb_write_th = icoms_usb_write_th;
1807- p->usb_write = icoms_usb_write;
1808- p->usb_cancel_io = icoms_usb_cancel_io;
1809- p->usb_resetep = icoms_usb_resetep;
1810- p->usb_clearhalt = icoms_usb_clearhalt;
1811-
1812- icoms_reset_uih(p);
1813-}
1814-
1815-/* ---------------------------------------------------------------------------------*/
1816-/* utilities */
1817-
1818-/* Emit a "normal" beep */
1819-void normal_beep() {
1820- /* 0msec delay, 1.0KHz for 200 msec */
1821- msec_beep(0, 1000, 200);
1822-}
1823-
1824-/* Emit a "good" beep */
1825-void good_beep() {
1826- /* 0msec delay, 1.2KHz for 200 msec */
1827- msec_beep(0, 1200, 200);
1828-}
1829-
1830-/* Emit a "bad" double beep */
1831-void bad_beep() {
1832- /* 0msec delay, 800Hz for 200 msec */
1833- msec_beep(0, 800, 200);
1834- /* 500msec delay, 800Hz for 200 msec */
1835- msec_beep(350, 800, 200);
1836-}
1837-
1838-/* Convert control chars to ^[A-Z] notation in a string */
1839-char *
1840-icoms_fix(char *ss) {
1841- static unsigned char buf[1005];
1842- unsigned char *d;
1843- unsigned char *s = (unsigned char *)ss;
1844- for(d = buf; (d - buf) < 1000;) {
1845- if (*s < ' ' && *s > '\000') {
1846- *d++ = '^';
1847- *d++ = *s++ + '@';
1848- } else if (*s >= 0x80) {
1849- *d++ = '\\';
1850- *d++ = '0' + ((*s >> 6) & 0x3);
1851- *d++ = '0' + ((*s >> 3) & 0x7);
1852- *d++ = '0' + ((*s++ >> 0) & 0x7);
1853- } else {
1854- *d++ = *s++;
1855- }
1856- if (s[-1] == '\000')
1857- break;
1858- }
1859- *d++ = '.';
1860- *d++ = '.';
1861- *d++ = '.';
1862- *d++ = '\000';
1863- return (char *)buf;
1864-}
1865-
1866-/* Convert a limited binary buffer to a list of hex */
1867-char *
1868-icoms_tohex(unsigned char *s, int len) {
1869- static char buf[64 * 3 + 10];
1870- int i;
1871- char *d;
1872-
1873- buf[0] = '\000';
1874- for(i = 0, d = buf; i < 64 && i < len; i++, s++) {
1875- sprintf(d, "%s%02x", i > 0 ? " " : "", *s);
1876- d += strlen(d);
1877- }
1878- if (i < len)
1879- sprintf(d, " ...");
1880-
1881- return buf;
1882-}
1883-
1884-/* ---------------------------------------------------------------------------------*/
1885
1886=== removed directory '.pc/04_CVE-2012-4405.diff'
1887=== removed directory '.pc/04_CVE-2012-4405.diff/icc'
1888=== removed file '.pc/04_CVE-2012-4405.diff/icc/icc.c'
1889--- .pc/04_CVE-2012-4405.diff/icc/icc.c 2012-09-11 13:45:12 +0000
1890+++ .pc/04_CVE-2012-4405.diff/icc/icc.c 1970-01-01 00:00:00 +0000
1891@@ -1,17408 +0,0 @@
1892-
1893-/*
1894- * International Color Consortium Format Library (icclib)
1895- * For ICC profile version 3.4
1896- *
1897- * Author: Graeme W. Gill
1898- * Date: 2002/04/22
1899- * Version: 2.13
1900- *
1901- * Copyright 1997 - 2012 Graeme W. Gill
1902- *
1903- * This material is licensed with an "MIT" free use license:-
1904- * see the License.txt file in this directory for licensing details.
1905- */
1906-
1907-/*
1908- * TTBD:
1909- *
1910- * Add a "warning mode" to file reading, in which file format
1911- * errors are ignored where possible, rather than generating
1912- * a fatal error (see ICM_STRICT #define).
1913- *
1914- * NameColor Dump doesn't handle device space correctly -
1915- * should use appropriate interpretation in case device is Lab etc.
1916- *
1917- * Should recognise & honour unicode 0xFFFE endian marker.
1918- * Should generate it on writing too ?
1919- *
1920- * Add support for copying tags from one icc to another.
1921- *
1922- * Should fix all write_number failure errors to indicate failed value.
1923- * (Partially implemented - need to check all write_number functions)
1924- *
1925- * Make write fail error messages be specific on which element failed.
1926- *
1927- * Should add named color space lookup function support.
1928- *
1929- * Would be nice to add generic ability to add new tag type handling,
1930- * so that the base library doesn't need to be modified (ie. VideoCardGamma) ?
1931- *
1932- * Need to add DeviceSettings and OutputResponse tags to bring up to
1933- * ICC.1:1998-09 [started but not complete]
1934- *
1935- */
1936-
1937-#undef ICM_STRICT /* Not fully implimented - switch off strict checking of file format */
1938-
1939-/* Make the default grid points of the Lab clut be symetrical about */
1940-/* a/b 0.0, and also make L = 100.0 fall on a grid point. */
1941-#define SYMETRICAL_DEFAULT_LAB_RANGE
1942-
1943-#define _ICC_C_ /* Turn on implimentation code */
1944-
1945-#undef DEBUG_SETLUT /* Show each value being set in setting lut contents */
1946-#undef DEBUG_SETLUT_CLIP /* Show clipped values when setting LUT */
1947-#undef DEBUG_LULUT /* Show each value being looked up from lut contents */
1948-#undef DEBUG_LLULUT /* Debug individual lookup steps (not fully implemented) */
1949-
1950-#include <stdio.h>
1951-#include <stdlib.h>
1952-#include <stdarg.h>
1953-#include <sys/types.h>
1954-#include <sys/stat.h>
1955-#include <fcntl.h>
1956-#include <string.h>
1957-#include <ctype.h>
1958-#include <math.h>
1959-#include <time.h>
1960-#ifdef __sun
1961-#include <unistd.h>
1962-#endif
1963-#if defined(__IBMC__) && defined(_M_IX86)
1964-#include <float.h>
1965-#endif
1966-#include "icc.h"
1967-
1968-#ifdef _MSC_VER
1969-#define vsnprintf _vsnprintf
1970-#define snprintf _snprintf
1971-#endif
1972-
1973-/* ========================================================== */
1974-/* Default system interface object implementations */
1975-
1976-#ifndef SEPARATE_STD
1977-#define COMBINED_STD
1978-
1979-#include "iccstd.c"
1980-
1981-#undef COMBINED_STD
1982-#endif /* SEPARATE_STD */
1983-
1984-/* Forced byte alignment for tag table and tags */
1985-#define ALIGN_SIZE 4
1986-
1987-/* =========================================================== */
1988-
1989-#ifdef DEBUG_SETLUT
1990-#undef DBGSL
1991-#define DBGSL(xxx) printf xxx ;
1992-#else
1993-#undef DBGSL
1994-#define DBGSL(xxx)
1995-#endif
1996-
1997-#if defined(DEBUG_SETLUT) || defined(DEBUG_SETLUT_CLIP)
1998-#undef DBGSLC
1999-#define DBGSLC(xxx) printf xxx ;
2000-#else
2001-#undef DBGSLC
2002-#define DBGSLC(xxx)
2003-#endif
2004-
2005-#ifdef DEBUG_LULUT
2006-#undef DBGLL
2007-#define DBGLL(xxx) printf xxx ;
2008-#else
2009-#undef DBGLL
2010-#define DBGLL(xxx)
2011-#endif
2012-
2013-#ifdef DEBUG_LLULUT
2014-#undef DBLLL
2015-#define DBLLL(xxx) printf xxx ;
2016-#else
2017-#undef DBLLL
2018-#define DBLLL(xxx)
2019-#endif
2020-
2021-/* =========================================================== */
2022-/* Overflow protected unsigned int arithmatic functions. */
2023-/* These functions saturate rather than wrapping around. */
2024-/* (Divide doesn't need protection) */
2025-/* They return UINT_MAX if there was an overflow */
2026-
2027-/* a + b */
2028-static unsigned int sat_add(unsigned int a, unsigned int b) {
2029- if (b > (UINT_MAX - a))
2030- return UINT_MAX;
2031- return a + b;
2032-}
2033-
2034-/* a - b */
2035-static unsigned int sat_sub(unsigned int a, unsigned int b) {
2036- if (a < b)
2037- return UINT_MAX;
2038- return a - b;
2039-}
2040-
2041-/* a * b */
2042-static unsigned int sat_mul(unsigned int a, unsigned int b) {
2043- unsigned int c;
2044-
2045- if (a == 0 || b == 0)
2046- return 0;
2047-
2048- if (a > (UINT_MAX/b))
2049- return UINT_MAX;
2050- else
2051- return a * b;
2052-}
2053-
2054-/* A + B + C */
2055-#define sat_addadd(A, B, C) sat_add(A, sat_add(B, C))
2056-
2057-/* A + B * C */
2058-#define sat_addmul(A, B, C) sat_add(A, sat_mul(B, C))
2059-
2060-/* A + B + C * D */
2061-#define sat_addaddmul(A, B, C, D) sat_add(A, sat_add(B, sat_mul(C, D)))
2062-
2063-/* A * B * C */
2064-#define sat_mul3(A, B, C) sat_mul(A, sat_mul(B, C))
2065-
2066-/* a ^ b */
2067-static unsigned int sat_pow(unsigned int a, unsigned int b) {
2068- unsigned int c = 1;
2069- for (; b > 0; b--) {
2070- c = sat_mul(c, a);
2071- if (c == UINT_MAX)
2072- break;
2073- }
2074- return c;
2075-}
2076-
2077-/* Alignment */
2078-static unsigned int sat_align(unsigned int align_size, unsigned int a) {
2079- align_size--;
2080-
2081- if (align_size > (UINT_MAX - a))
2082- return UINT_MAX;
2083-
2084- return (a + align_size) & ~align_size;
2085-}
2086-
2087-/* These test functions detect whether an overflow would occur */
2088-
2089-/* Return nz if add would overflow */
2090-static int ovr_add(unsigned int a, unsigned int b) {
2091-
2092- if (b > (UINT_MAX - a))
2093- return 1;
2094- return 0;
2095-}
2096-
2097-/* Return nz if sub would overflow */
2098-static int ovr_sub(unsigned int a, unsigned int b) {
2099- if (a < b)
2100- return 1;
2101- return 0;
2102-}
2103-
2104-/* Return nz if mult would overflow */
2105-static int ovr_mul(unsigned int a, unsigned int b) {
2106- if (a > (UINT_MAX/b))
2107- return 1;
2108- return 0;
2109-}
2110-
2111-
2112-/* size_t versions of saturating arithmatic */
2113-
2114-#ifndef SIZE_MAX
2115-# define SIZE_MAX ((size_t)(-1))
2116-#endif
2117-
2118-/* a + b */
2119-static size_t ssat_add(size_t a, size_t b) {
2120- if (b > (SIZE_MAX - a))
2121- return SIZE_MAX;
2122- return a + b;
2123-}
2124-
2125-/* a - b */
2126-static size_t ssat_sub(size_t a, size_t b) {
2127- if (a < b)
2128- return SIZE_MAX;
2129- return a - b;
2130-}
2131-
2132-/* a * b */
2133-static size_t ssat_mul(size_t a, size_t b) {
2134- size_t c;
2135-
2136- if (a == 0 || b == 0)
2137- return 0;
2138-
2139- if (a > (SIZE_MAX/b))
2140- return SIZE_MAX;
2141- else
2142- return a * b;
2143-}
2144-
2145-/* ------------------------------------------------- */
2146-/* Memory image icmFile compatible class */
2147-/* Buffer is assumed to be a fixed size, and externally allocated */
2148-/* Writes therefore don't expand the buffer. */
2149-
2150-/* Get the size of the file (Only valid for reading file). */
2151-static size_t icmFileMem_get_size(icmFile *pp) {
2152- return pp->size;
2153-}
2154-
2155-/* Set current position to offset. Return 0 on success, nz on failure. */
2156-static int icmFileMem_seek(
2157-icmFile *pp,
2158-unsigned int offset
2159-) {
2160- icmFileMem *p = (icmFileMem *)pp;
2161- unsigned char *np;
2162-
2163- np = p->start + offset;
2164- if (np < p->start || np >= p->end)
2165- return 1;
2166- p->cur = np;
2167- return 0;
2168-}
2169-
2170-/* Read count items of size length. Return number of items successfully read. */
2171-static size_t icmFileMem_read(
2172-icmFile *pp,
2173-void *buffer,
2174-size_t size,
2175-size_t count
2176-) {
2177- icmFileMem *p = (icmFileMem *)pp;
2178- size_t len;
2179-
2180- len = ssat_mul(size, count);
2181- if (len > (p->end - p->cur)) { /* Too much */
2182- if (size > 0)
2183- count = (p->end - p->cur)/size;
2184- else
2185- count = 0;
2186- }
2187- len = size * count;
2188- if (len > 0)
2189- memmove(buffer, p->cur, len);
2190- p->cur += len;
2191- return count;
2192-}
2193-
2194-/* write count items of size length. Return number of items successfully written. */
2195-static size_t icmFileMem_write(
2196-icmFile *pp,
2197-void *buffer,
2198-size_t size,
2199-size_t count
2200-) {
2201- icmFileMem *p = (icmFileMem *)pp;
2202- size_t len;
2203-
2204- len = ssat_mul(size, count);
2205- if (len > (p->end - p->cur)) { /* Too much */
2206- if (size > 0)
2207- count = (p->end - p->cur)/size;
2208- else
2209- count = 0;
2210- }
2211- len = size * count;
2212- if (len > 0)
2213- memmove(p->cur, buffer, len);
2214- p->cur += len;
2215- return count;
2216-}
2217-
2218-/* do a printf */
2219-static int icmFileMem_printf(
2220-icmFile *pp,
2221-const char *format,
2222-...
2223-) {
2224- int rv;
2225- va_list args;
2226- icmFileMem *p = (icmFileMem *)pp;
2227-
2228- va_start(args, format);
2229-
2230-#if ((defined(__IBMC__) || defined(__BORLANDC__)) && defined(_M_IX86))
2231- rv = vsprintf((char *)p->cur, format, args); /* This could overwrite the buffer !!! */
2232-#else
2233- rv = vsnprintf((char *)p->cur, (p->end - p->cur), format, args);
2234-#endif
2235-
2236- va_end(args);
2237- return rv;
2238-}
2239-
2240-
2241-/* flush all write data out to secondary storage. Return nz on failure. */
2242-static int icmFileMem_flush(
2243-icmFile *pp
2244-) {
2245- return 0;
2246-}
2247-
2248-/* we're done with the file object, return nz on failure */
2249-static int icmFileMem_delete(
2250-icmFile *pp
2251-) {
2252- icmFileMem *p = (icmFileMem *)pp;
2253- icmAlloc *al = p->al;
2254- int del_al = p->del_al;
2255-
2256- if (p->del_buf) /* Free the memory buffer */
2257- al->free(al, p->start);
2258- al->free(al, p); /* Free object */
2259- if (del_al) /* We are responsible for deleting allocator */
2260- al->del(al);
2261- return 0;
2262-}
2263-
2264-/* Create a memory image file access class with allocator */
2265-/* Buffer is used as is. */
2266-icmFile *new_icmFileMem_a(
2267-void *base, /* Pointer to base of memory buffer */
2268-size_t length, /* Number of bytes in buffer */
2269-icmAlloc *al /* heap allocator */
2270-) {
2271- icmFileMem *p;
2272-
2273- if ((p = (icmFileMem *) al->calloc(al, 1, sizeof(icmFileMem))) == NULL) {
2274- return NULL;
2275- }
2276- p->al = al; /* Heap allocator */
2277- p->get_size = icmFileMem_get_size;
2278- p->seek = icmFileMem_seek;
2279- p->read = icmFileMem_read;
2280- p->write = icmFileMem_write;
2281- p->gprintf = icmFileMem_printf;
2282- p->flush = icmFileMem_flush;
2283- p->del = icmFileMem_delete;
2284-
2285- p->start = (unsigned char *)base;
2286- p->cur = p->start;
2287- p->end = p->start + length;
2288-
2289- p->size = length;
2290-
2291- return (icmFile *)p;
2292-}
2293-
2294-/* Create a memory image file access class with given allocator */
2295-/* and delete base when icmFile is deleted. */
2296-icmFile *new_icmFileMem_ad(void *base, size_t length, icmAlloc *al) {
2297- icmFile *fp;
2298-
2299- if ((fp = new_icmFileMem_a(base, length, al)) != NULL) {
2300- ((icmFileMem *)fp)->del_buf = 1;
2301- }
2302-
2303- return fp;
2304-}
2305-
2306-/* ========================================================== */
2307-/* Conversion support functions */
2308-/* Convert between ICC storage types and native C types */
2309-/* Write routine return non-zero if numbers can't be represented */
2310-
2311-/* Unsigned */
2312-static unsigned int read_UInt8Number(char *p) {
2313- unsigned int rv;
2314- rv = (unsigned int)((ORD8 *)p)[0];
2315- return rv;
2316-}
2317-
2318-static int write_UInt8Number(unsigned int d, char *p) {
2319- if (d > 255)
2320- return 1;
2321- ((ORD8 *)p)[0] = (ORD8)d;
2322- return 0;
2323-}
2324-
2325-static unsigned int read_UInt16Number(char *p) {
2326- unsigned int rv;
2327- rv = 256 * (unsigned int)((ORD8 *)p)[0]
2328- + (unsigned int)((ORD8 *)p)[1];
2329- return rv;
2330-}
2331-
2332-static int write_UInt16Number(unsigned int d, char *p) {
2333- if (d > 65535)
2334- return 1;
2335- ((ORD8 *)p)[0] = (ORD8)(d >> 8);
2336- ((ORD8 *)p)[1] = (ORD8)(d);
2337- return 0;
2338-}
2339-
2340-static unsigned int read_UInt32Number(char *p) {
2341- unsigned int rv;
2342- rv = 16777216 * (unsigned int)((ORD8 *)p)[0]
2343- + 65536 * (unsigned int)((ORD8 *)p)[1]
2344- + 256 * (unsigned int)((ORD8 *)p)[2]
2345- + (unsigned int)((ORD8 *)p)[3];
2346- return rv;
2347-}
2348-
2349-static int write_UInt32Number(unsigned int d, char *p) {
2350- ((ORD8 *)p)[0] = (ORD8)(d >> 24);
2351- ((ORD8 *)p)[1] = (ORD8)(d >> 16);
2352- ((ORD8 *)p)[2] = (ORD8)(d >> 8);
2353- ((ORD8 *)p)[3] = (ORD8)(d);
2354- return 0;
2355-}
2356-
2357-static void read_UInt64Number(icmUint64 *d, char *p) {
2358- d->h = 16777216 * (unsigned int)((ORD8 *)p)[0]
2359- + 65536 * (unsigned int)((ORD8 *)p)[1]
2360- + 256 * (unsigned int)((ORD8 *)p)[2]
2361- + (unsigned int)((ORD8 *)p)[3];
2362- d->l = 16777216 * (unsigned int)((ORD8 *)p)[4]
2363- + 65536 * (unsigned int)((ORD8 *)p)[5]
2364- + 256 * (unsigned int)((ORD8 *)p)[6]
2365- + (unsigned int)((ORD8 *)p)[7];
2366-}
2367-
2368-static int write_UInt64Number(icmUint64 *d, char *p) {
2369- ((ORD8 *)p)[0] = (ORD8)(d->h >> 24);
2370- ((ORD8 *)p)[1] = (ORD8)(d->h >> 16);
2371- ((ORD8 *)p)[2] = (ORD8)(d->h >> 8);
2372- ((ORD8 *)p)[3] = (ORD8)(d->h);
2373- ((ORD8 *)p)[4] = (ORD8)(d->l >> 24);
2374- ((ORD8 *)p)[5] = (ORD8)(d->l >> 16);
2375- ((ORD8 *)p)[6] = (ORD8)(d->l >> 8);
2376- ((ORD8 *)p)[7] = (ORD8)(d->l);
2377- return 0;
2378-}
2379-
2380-static double read_U8Fixed8Number(char *p) {
2381- ORD32 o32;
2382- o32 = 256 * (ORD32)((ORD8 *)p)[0] /* Read big endian 16 bit unsigned */
2383- + (ORD32)((ORD8 *)p)[1];
2384- return (double)o32/256.0;
2385-}
2386-
2387-static int write_U8Fixed8Number(double d, char *p) {
2388- ORD32 o32;
2389- d = d * 256.0 + 0.5;
2390- if (d >= 65536.0)
2391- return 1;
2392- if (d < 0.0)
2393- return 1;
2394- o32 = (ORD32)d;
2395- ((ORD8 *)p)[0] = (ORD8)((o32) >> 8);
2396- ((ORD8 *)p)[1] = (ORD8)((o32));
2397- return 0;
2398-}
2399-
2400-static double read_U16Fixed16Number(char *p) {
2401- ORD32 o32;
2402- o32 = 16777216 * (ORD32)((ORD8 *)p)[0] /* Read big endian 32 bit unsigned */
2403- + 65536 * (ORD32)((ORD8 *)p)[1]
2404- + 256 * (ORD32)((ORD8 *)p)[2]
2405- + (ORD32)((ORD8 *)p)[3];
2406- return (double)o32/65536.0;
2407-}
2408-
2409-static int write_U16Fixed16Number(double d, char *p) {
2410- ORD32 o32;
2411- d = d * 65536.0 + 0.5;
2412- if (d >= 4294967296.0)
2413- return 1;
2414- if (d < 0.0)
2415- return 1;
2416- o32 = (ORD32)d;
2417- ((ORD8 *)p)[0] = (ORD8)((o32) >> 24);
2418- ((ORD8 *)p)[1] = (ORD8)((o32) >> 16);
2419- ((ORD8 *)p)[2] = (ORD8)((o32) >> 8);
2420- ((ORD8 *)p)[3] = (ORD8)((o32));
2421- return 0;
2422-}
2423-
2424-
2425-/* Signed numbers */
2426-static int read_SInt8Number(char *p) {
2427- int rv;
2428- rv = (int)((INR8 *)p)[0];
2429- return rv;
2430-}
2431-
2432-static int write_SInt8Number(int d, char *p) {
2433- if (d > 127)
2434- return 1;
2435- else if (d < -128)
2436- return 1;
2437- ((INR8 *)p)[0] = (INR8)d;
2438- return 0;
2439-}
2440-
2441-static int read_SInt16Number(char *p) {
2442- int rv;
2443- rv = 256 * (int)((INR8 *)p)[0]
2444- + (int)((ORD8 *)p)[1];
2445- return rv;
2446-}
2447-
2448-static int write_SInt16Number(int d, char *p) {
2449- if (d > 32767)
2450- return 1;
2451- else if (d < -32768)
2452- return 1;
2453- ((INR8 *)p)[0] = (INR8)(d >> 8);
2454- ((ORD8 *)p)[1] = (ORD8)(d);
2455- return 0;
2456-}
2457-
2458-static int read_SInt32Number(char *p) {
2459- int rv;
2460- rv = 16777216 * (int)((INR8 *)p)[0]
2461- + 65536 * (int)((ORD8 *)p)[1]
2462- + 256 * (int)((ORD8 *)p)[2]
2463- + (int)((ORD8 *)p)[3];
2464- return rv;
2465-}
2466-
2467-static int write_SInt32Number(int d, char *p) {
2468- ((INR8 *)p)[0] = (INR8)(d >> 24);
2469- ((ORD8 *)p)[1] = (ORD8)(d >> 16);
2470- ((ORD8 *)p)[2] = (ORD8)(d >> 8);
2471- ((ORD8 *)p)[3] = (ORD8)(d);
2472- return 0;
2473-}
2474-
2475-static void read_SInt64Number(icmInt64 *d, char *p) {
2476- d->h = 16777216 * (int)((INR8 *)p)[0]
2477- + 65536 * (int)((ORD8 *)p)[1]
2478- + 256 * (int)((ORD8 *)p)[2]
2479- + (int)((ORD8 *)p)[3];
2480- d->l = 16777216 * (unsigned int)((ORD8 *)p)[4]
2481- + 65536 * (unsigned int)((ORD8 *)p)[5]
2482- + 256 * (unsigned int)((ORD8 *)p)[6]
2483- + (unsigned int)((ORD8 *)p)[7];
2484-}
2485-
2486-static int write_SInt64Number(icmInt64 *d, char *p) {
2487- ((INR8 *)p)[0] = (INR8)(d->h >> 24);
2488- ((ORD8 *)p)[1] = (ORD8)(d->h >> 16);
2489- ((ORD8 *)p)[2] = (ORD8)(d->h >> 8);
2490- ((ORD8 *)p)[3] = (ORD8)(d->h);
2491- ((ORD8 *)p)[4] = (ORD8)(d->l >> 24);
2492- ((ORD8 *)p)[5] = (ORD8)(d->l >> 16);
2493- ((ORD8 *)p)[6] = (ORD8)(d->l >> 8);
2494- ((ORD8 *)p)[7] = (ORD8)(d->l);
2495- return 0;
2496-}
2497-
2498-static double read_S15Fixed16Number(char *p) {
2499- INR32 i32;
2500- i32 = 16777216 * (INR32)((INR8 *)p)[0] /* Read big endian 32 bit signed */
2501- + 65536 * (INR32)((ORD8 *)p)[1]
2502- + 256 * (INR32)((ORD8 *)p)[2]
2503- + (INR32)((ORD8 *)p)[3];
2504- return (double)i32/65536.0;
2505-}
2506-
2507-static int write_S15Fixed16Number(double d, char *p) {
2508- INR32 i32;
2509- d = floor(d * 65536.0 + 0.5); /* Beware! (int)(d + 0.5) doesn't work! */
2510- if (d >= 2147483648.0)
2511- return 1;
2512- if (d < -2147483648.0)
2513- return 1;
2514- i32 = (INR32)d;
2515- ((INR8 *)p)[0] = (INR8)((i32) >> 24); /* Write big endian 32 bit signed */
2516- ((ORD8 *)p)[1] = (ORD8)((i32) >> 16);
2517- ((ORD8 *)p)[2] = (ORD8)((i32) >> 8);
2518- ((ORD8 *)p)[3] = (ORD8)((i32));
2519- return 0;
2520-}
2521-
2522-/* Device coordinate as 8 bit value range 0.0 - 1.0 */
2523-static double read_DCS8Number(char *p) {
2524- unsigned int rv;
2525- rv = (unsigned int)((ORD8 *)p)[0];
2526- return (double)rv/255.0;
2527-}
2528-
2529-static int write_DCS8Number(double d, char *p) {
2530- ORD32 o32;
2531- d = d * 255.0 + 0.5;
2532- if (d >= 256.0)
2533- return 1;
2534- if (d < 0.0)
2535- return 1;
2536- o32 = (ORD32)d;
2537- ((ORD8 *)p)[0] = (ORD8)(o32);
2538- return 0;
2539-}
2540-
2541-/* Device coordinate as 16 bit value range 0.0 - 1.0 */
2542-static double read_DCS16Number(char *p) {
2543- unsigned int rv;
2544- rv = 256 * (unsigned int)((ORD8 *)p)[0]
2545- + (unsigned int)((ORD8 *)p)[1];
2546- return (double)rv/65535.0;
2547-}
2548-
2549-static int write_DCS16Number(double d, char *p) {
2550- ORD32 o32;
2551- d = d * 65535.0 + 0.5;
2552- if (d >= 65536.0)
2553- return 1;
2554- if (d < 0.0)
2555- return 1;
2556- o32 = (ORD32)d;
2557- ((ORD8 *)p)[0] = (ORD8)(o32 >> 8);
2558- ((ORD8 *)p)[1] = (ORD8)(o32);
2559- return 0;
2560-}
2561-
2562-static void Lut_Lut2XYZ(double *out, double *in);
2563-static void Lut_XYZ2Lut(double *out, double *in);
2564-static void Lut_Lut2Lab_8(double *out, double *in);
2565-static void Lut_Lab2Lut_8(double *out, double *in);
2566-static void Lut_Lut2LabV2_16(double *out, double *in);
2567-static void Lut_Lab2LutV2_16(double *out, double *in);
2568-static void Lut_Lut2LabV4_16(double *out, double *in);
2569-static void Lut_Lab2LutV4_16(double *out, double *in);
2570-
2571-static void Lut_Lut2Y(double *out, double *in);
2572-static void Lut_Y2Lut(double *out, double *in);
2573-static void Lut_Lut2L_8(double *out, double *in);
2574-static void Lut_L2Lut_8(double *out, double *in);
2575-static void Lut_Lut2LV2_16(double *out, double *in);
2576-static void Lut_L2LutV2_16(double *out, double *in);
2577-static void Lut_Lut2LV4_16(double *out, double *in);
2578-static void Lut_L2LutV4_16(double *out, double *in);
2579-
2580-//~~~~888888
2581-/* read a PCS number. PCS can be profile PCS, profile version Lab, */
2582-/* or a specific type of Lab, depending on the value of csig: */
2583-/* icmSigPCSData, icSigXYZData, icmSigLab8Data, icSigLabData, */
2584-/* icmSigLabV2Data or icmSigLabV4Data */
2585-/* Do nothing if not one of the above. */
2586-static void read_PCSNumber(icc *icp, icColorSpaceSignature csig, double pcs[3], char *p) {
2587-
2588- if (csig == icmSigPCSData)
2589- csig = icp->header->pcs;
2590- if (csig == icSigLabData) {
2591- if (icp->ver != 0)
2592- csig = icmSigLabV4Data;
2593- else
2594- csig = icmSigLabV2Data;
2595- }
2596-
2597- if (csig == icmSigLab8Data) {
2598- pcs[0] = read_DCS8Number(p);
2599- pcs[1] = read_DCS8Number(p+1);
2600- pcs[2] = read_DCS8Number(p+2);
2601- } else {
2602- pcs[0] = read_DCS16Number(p);
2603- pcs[1] = read_DCS16Number(p+2);
2604- pcs[2] = read_DCS16Number(p+4);
2605- }
2606- switch (csig) {
2607- case icSigXYZData:
2608- Lut_Lut2XYZ(pcs, pcs);
2609- break;
2610- case icmSigLab8Data:
2611- Lut_Lut2Lab_8(pcs, pcs);
2612- break;
2613- case icmSigLabV2Data:
2614- Lut_Lut2LabV2_16(pcs, pcs);
2615- break;
2616- case icmSigLabV4Data:
2617- Lut_Lut2LabV4_16(pcs, pcs);
2618- break;
2619- default:
2620- break;
2621- }
2622-}
2623-
2624-/* write a PCS number. PCS can be profile PCS, profile version Lab, */
2625-/* or a specific type of Lab, depending on the value of csig: */
2626-/* icmSigPCSData, icSigXYZData, icmSigLab8Data, icSigLabData, */
2627-/* icmSigLabV2Data or icmSigLabV4Data */
2628-/* Return 1 if error */
2629-static int write_PCSNumber(icc *icp, icColorSpaceSignature csig, double pcs[3], char *p) {
2630- double v[3];
2631- int j;
2632-
2633- if (csig == icmSigPCSData)
2634- csig = icp->header->pcs;
2635- if (csig == icSigLabData) {
2636- if (icp->ver != 0)
2637- csig = icmSigLabV4Data;
2638- else
2639- csig = icmSigLabV2Data;
2640- }
2641-
2642- switch (csig) {
2643- case icSigXYZData:
2644- Lut_XYZ2Lut(v, pcs);
2645- break;
2646- case icmSigLab8Data:
2647- Lut_Lab2Lut_8(v, pcs);
2648- break;
2649- case icmSigLabV2Data:
2650- Lut_Lab2LutV2_16(v, pcs);
2651- break;
2652- case icmSigLabV4Data:
2653- Lut_Lab2LutV4_16(v, pcs);
2654- break;
2655- default:
2656- return 1;
2657- }
2658- if (csig == icmSigLab8Data) {
2659- for (j = 0; j < 3; j++) {
2660- if (write_DCS8Number(v[j], p+j))
2661- return 1;
2662- }
2663- } else {
2664- for (j = 0; j < 3; j++) {
2665- if (write_DCS16Number(v[j], p+(2 * j)))
2666- return 1;
2667- }
2668- }
2669-
2670- return 0;
2671-}
2672-
2673-/* Read a given primitive type. Return non-zero on error */
2674-/* (Not currently used internaly ?) */
2675-/* Public: */
2676-int read_Primitive(icc *icp, icmPrimType ptype, void *prim, char *p) {
2677-
2678- switch(ptype) {
2679- case icmUInt8Number:
2680- *((unsigned int *)prim) = read_UInt8Number(p);
2681- return 0;
2682- case icmUInt16Number:
2683- *((unsigned int *)prim) = read_UInt16Number(p);
2684- return 0;
2685- case icmUInt32Number:
2686- *((unsigned int *)prim) = read_UInt32Number(p);
2687- return 0;
2688- case icmUInt64Number:
2689- read_UInt64Number((icmUint64 *)prim, p);
2690- return 0;
2691- case icmU8Fixed8Number:
2692- *((double *)prim) = read_U8Fixed8Number(p);
2693- return 0;
2694- case icmU16Fixed16Number:
2695- *((double *)prim) = read_U16Fixed16Number(p);
2696- return 0;
2697- case icmSInt8Number:
2698- *((int *)prim) = read_SInt8Number(p);
2699- return 0;
2700- case icmSInt16Number:
2701- *((int *)prim) = read_SInt16Number(p);
2702- return 0;
2703- case icmSInt32Number:
2704- *((int *)prim) = read_SInt32Number(p);
2705- return 0;
2706- case icmSInt64Number:
2707- read_SInt64Number((icmInt64 *)prim, p);
2708- return 0;
2709- case icmS15Fixed16Number:
2710- *((double *)prim) = read_S15Fixed16Number(p);
2711- return 0;
2712- case icmDCS8Number:
2713- *((double *)prim) = read_DCS8Number(p);
2714- return 0;
2715- case icmDCS16Number:
2716- *((double *)prim) = read_DCS16Number(p);
2717- return 0;
2718- case icmPCSNumber:
2719- read_PCSNumber(icp, icmSigPCSData, ((double *)prim), p);
2720- return 0;
2721- case icmPCSXYZNumber:
2722- read_PCSNumber(icp, icSigXYZData, ((double *)prim), p);
2723- return 0;
2724- case icmPCSLab8Number:
2725- read_PCSNumber(icp, icmSigLab8Data, ((double *)prim), p);
2726- return 0;
2727- case icmPCSLabNumber:
2728- read_PCSNumber(icp, icSigLabData, ((double *)prim), p);
2729- return 0;
2730- case icmPCSLabV2Number:
2731- read_PCSNumber(icp, icmSigLabV2Data, ((double *)prim), p);
2732- return 0;
2733- case icmPCSLabV4Number:
2734- read_PCSNumber(icp, icmSigLabV4Data, ((double *)prim), p);
2735- return 0;
2736- }
2737-
2738- return 2;
2739-}
2740-
2741-/* Write a given primitive type. Return non-zero on error */
2742-/* (Not currently used internaly ?) */
2743-/* Public: */
2744-int write_Primitive(icc *icp, icmPrimType ptype, char *p, void *prim) {
2745-
2746- switch(ptype) {
2747- case icmUInt8Number:
2748- return write_UInt8Number(*((unsigned int *)prim), p);
2749- case icmUInt16Number:
2750- return write_UInt16Number(*((unsigned int *)prim), p);
2751- case icmUInt32Number:
2752- return write_UInt32Number(*((unsigned int *)prim), p);
2753- case icmUInt64Number:
2754- return write_UInt64Number((icmUint64 *)prim, p);
2755- case icmU8Fixed8Number:
2756- return write_U8Fixed8Number(*((double *)prim), p);
2757- case icmU16Fixed16Number:
2758- return write_U16Fixed16Number(*((double *)prim), p);
2759- case icmSInt8Number:
2760- return write_SInt8Number(*((int *)prim), p);
2761- case icmSInt16Number:
2762- return write_SInt16Number(*((int *)prim), p);
2763- case icmSInt32Number:
2764- return write_SInt32Number(*((int *)prim), p);
2765- case icmSInt64Number:
2766- return write_SInt64Number((icmInt64 *)prim, p);
2767- case icmS15Fixed16Number:
2768- return write_S15Fixed16Number(*((double *)prim), p);
2769- case icmDCS8Number:
2770- return write_DCS8Number(*((double *)prim), p);
2771- case icmDCS16Number:
2772- return write_DCS16Number(*((double *)prim), p);
2773- case icmPCSNumber:
2774- return write_PCSNumber(icp, icmSigPCSData, ((double *)prim), p);
2775- case icmPCSXYZNumber:
2776- return write_PCSNumber(icp, icSigXYZData, ((double *)prim), p);
2777- case icmPCSLab8Number:
2778- return write_PCSNumber(icp, icmSigLab8Data, ((double *)prim), p);
2779- case icmPCSLabNumber:
2780- return write_PCSNumber(icp, icSigLabData, ((double *)prim), p);
2781- case icmPCSLabV2Number:
2782- return write_PCSNumber(icp, icmSigLabV2Data, ((double *)prim), p);
2783- case icmPCSLabV4Number:
2784- return write_PCSNumber(icp, icmSigLabV4Data, ((double *)prim), p);
2785- }
2786-
2787- return 2;
2788-}
2789-
2790-/* ---------------------------------------------------------- */
2791-/* Auiliary function - return a string that represents a tag */
2792-/* Note - returned buffers are static, can only be used 5 */
2793-/* times before buffers get reused. */
2794-char *tag2str(
2795- int tag
2796-) {
2797- int i;
2798- static int si = 0; /* String buffer index */
2799- static char buf[5][20]; /* String buffers */
2800- char *bp;
2801- unsigned char c[4];
2802-
2803- bp = buf[si++];
2804- si %= 5; /* Rotate through buffers */
2805-
2806- c[0] = 0xff & (tag >> 24);
2807- c[1] = 0xff & (tag >> 16);
2808- c[2] = 0xff & (tag >> 8);
2809- c[3] = 0xff & (tag >> 0);
2810- for (i = 0; i < 4; i++) { /* Can we represent it as a string ? */
2811- if (!isprint(c[i]))
2812- break;
2813- }
2814- if (i < 4) { /* Not printable - use hex */
2815- sprintf(bp,"0x%x",tag);
2816- } else { /* Printable */
2817- sprintf(bp,"'%c%c%c%c'",c[0],c[1],c[2],c[3]);
2818- }
2819- return bp;
2820-}
2821-
2822-/* Auiliary function - return a tag created from a string */
2823-/* Note there is also the icmMakeTag() macro */
2824-unsigned int str2tag(
2825- const char *str
2826-) {
2827- unsigned int tag;
2828- tag = (((unsigned int)str[0]) << 24)
2829- + (((unsigned int)str[1]) << 16)
2830- + (((unsigned int)str[2]) << 8)
2831- + (((unsigned int)str[3]));
2832- return tag;
2833-}
2834-
2835-/* helper - return 1 if the string doesn't have a */
2836-/* null terminator within len, return 0 if it does. */
2837-/* Note: will return 1 if len == 0 */
2838-static int check_null_string(char *cp, int len) {
2839- for (; len > 0; len--) {
2840- if (cp[0] == '\000')
2841- break;
2842- cp++;
2843- }
2844- if (len == 0)
2845- return 1;
2846- return 0;
2847-}
2848-
2849-/* helper - return 1 if the string doesn't have a */
2850-/* null terminator within len, return 0 if it does. */
2851-/* Note: will return 1 if len == 0 */
2852-/* Unicode version */
2853-static int check_null_string16(char *cp, int len) {
2854- for (; len > 0; len--) { /* Length is in characters */
2855- if (cp[0] == 0 && cp[1] == 0)
2856- break;
2857- cp += 2;
2858- }
2859- if (len == 0)
2860- return 1;
2861- return 0;
2862-}
2863-
2864-/* - - - - - - - - - - - - - - - - - - - - - - - - - - - */
2865-
2866-/* Color Space to number of component conversion */
2867-/* Return 0 on error */
2868-static unsigned int number_ColorSpaceSignature(icColorSpaceSignature sig) {
2869- switch(sig) {
2870- case icSigXYZData:
2871- return 3;
2872- case icSigLabData:
2873- return 3;
2874- case icSigLuvData:
2875- return 3;
2876- case icSigYCbCrData:
2877- return 3;
2878- case icSigYxyData:
2879- return 3;
2880- case icSigRgbData:
2881- return 3;
2882- case icSigGrayData:
2883- return 1;
2884- case icSigHsvData:
2885- return 3;
2886- case icSigHlsData:
2887- return 3;
2888- case icSigCmykData:
2889- return 4;
2890- case icSigCmyData:
2891- return 3;
2892- case icSig2colorData:
2893- return 2;
2894- case icSig3colorData:
2895- return 3;
2896- case icSig4colorData:
2897- return 4;
2898- case icSig5colorData:
2899- case icSigMch5Data:
2900- return 5;
2901- case icSig6colorData:
2902- case icSigMch6Data:
2903- return 6;
2904- case icSig7colorData:
2905- case icSigMch7Data:
2906- return 7;
2907- case icSig8colorData:
2908- case icSigMch8Data:
2909- return 8;
2910- case icSig9colorData:
2911- return 9;
2912- case icSig10colorData:
2913- return 10;
2914- case icSig11colorData:
2915- return 11;
2916- case icSig12colorData:
2917- return 12;
2918- case icSig13colorData:
2919- return 13;
2920- case icSig14colorData:
2921- return 14;
2922- case icSig15colorData:
2923- return 15;
2924-
2925- /* Non-standard and Pseudo spaces */
2926- case icmSigYData:
2927- return 1;
2928- case icmSigLData:
2929- return 1;
2930- case icmSigL8Data:
2931- return 1;
2932- case icmSigLV2Data:
2933- return 1;
2934- case icmSigLV4Data:
2935- return 1;
2936- case icmSigPCSData:
2937- return 3;
2938- case icmSigLab8Data:
2939- return 3;
2940- case icmSigLabV2Data:
2941- return 3;
2942- case icmSigLabV4Data:
2943- return 3;
2944-
2945- default:
2946- break;
2947- }
2948- return 0;
2949-}
2950-
2951-/* Public version of above */
2952-
2953-/* Return the number of channels for the given color space. Return 0 if unknown. */
2954-ICCLIB_API unsigned int icmCSSig2nchan(icColorSpaceSignature sig) {
2955- return number_ColorSpaceSignature(sig);
2956-}
2957-
2958-/* - - - - - - - - - - - - - - - - - - - - - - - - - - - */
2959-
2960-/* Return the individual channel names and number of channels give a colorspace signature. */
2961-/* Return 0 if it is not a colorspace that itself defines particular channels, */
2962-/* 1 if it is a colorant based colorspace, and 2 if it is not a colorant based space */
2963-static int chnames_ColorSpaceSignature(
2964-icColorSpaceSignature sig,
2965-char *cvals[] /* Pointers to return for each channel */
2966-) {
2967- switch (sig) {
2968- case icSigXYZData:
2969- cvals[0] = "CIE X";
2970- cvals[1] = "CIE Y";
2971- cvals[2] = "CIE Z";
2972- return 2;
2973-
2974- case icSigLabData:
2975- cvals[0] = "CIE L*";
2976- cvals[1] = "CIE a*";
2977- cvals[2] = "CIE b*";
2978- return 2;
2979-
2980- case icSigLuvData:
2981- cvals[0] = "CIE L*";
2982- cvals[1] = "CIE u*";
2983- cvals[2] = "CIE v*";
2984- return 2;
2985-
2986- /* Usually ITU-R BT.601 (was CCIR 601) */
2987- case icSigYCbCrData:
2988- cvals[0] = "ITU Y";
2989- cvals[1] = "ITU Cb";
2990- cvals[2] = "ITU Cr";
2991- return 2;
2992-
2993- case icSigYxyData:
2994- cvals[0] = "CIE Y";
2995- cvals[1] = "CIE x";
2996- cvals[2] = "CIE y";
2997- return 2;
2998-
2999- /* Alvy Ray Smith ? */
3000- case icSigHsvData:
3001- cvals[0] = "RGB Hue";
3002- cvals[1] = "RGB Saturation";
3003- cvals[2] = "RGB Value";
3004- return 2;
3005-
3006- /* GSPC ? */
3007- case icSigHlsData:
3008- cvals[0] = "RGB Hue";
3009- cvals[1] = "RGB Lightness";
3010- cvals[2] = "RGB Saturation";
3011- return 2;
3012-
3013- case icSigCmyData:
3014- cvals[0] = "Cyan";
3015- cvals[1] = "Magenta";
3016- cvals[2] = "Yellow";
3017- return 1;
3018-
3019- case icSigRgbData:
3020- cvals[0] = "Red";
3021- cvals[1] = "Green";
3022- cvals[2] = "Blue";
3023- return 1;
3024-
3025- case icSigCmykData:
3026- cvals[0] = "Cyan";
3027- cvals[1] = "Magenta";
3028- cvals[2] = "Yellow";
3029- cvals[3] = "Black";
3030- return 1;
3031-
3032-
3033- /* Non-standard and Pseudo spaces */
3034- case icmSigYData:
3035- cvals[0] = "CIE Y";
3036- return 2;
3037-
3038- case icmSigLData:
3039- cvals[0] = "CIE L*";
3040- return 2;
3041-
3042- default:
3043- break;
3044-
3045- }
3046- return 0;
3047-}
3048-
3049-/* Public version of above */
3050-
3051-/* Return the individual channel names and number of channels give a colorspace signature. */
3052-/* Return 0 if it is not a colorspace that itself defines particular channels, */
3053-/* 1 if it is a colorant based colorspace, and 2 if it is not a colorant based space */
3054-ICCLIB_API unsigned int icmCSSig2chanNames(icColorSpaceSignature sig, char *cvals[]) {
3055-
3056- return chnames_ColorSpaceSignature(sig, cvals);
3057-}
3058-
3059-/* ------------------------------------------------------- */
3060-/* Flag dump functions */
3061-/* Note - returned buffers are static, can only be used 5 */
3062-/* times before buffers get reused. */
3063-
3064-/* Screening Encodings */
3065-static char *string_ScreenEncodings(unsigned int flags) {
3066- static int si = 0; /* String buffer index */
3067- static char buf[5][80]; /* String buffers */
3068- char *bp, *cp;
3069-
3070- cp = bp = buf[si++];
3071- si %= 5; /* Rotate through buffers */
3072-
3073- if (flags & icPrtrDefaultScreensTrue) {
3074- sprintf(cp,"Default Screen");
3075- } else {
3076- sprintf(cp,"No Default Screen");
3077- }
3078- cp = cp + strlen(cp);
3079- if (flags & icLinesPerInch) {
3080- sprintf(cp,", Lines Per Inch");
3081- } else {
3082- sprintf(cp,", Lines Per cm");
3083- }
3084- cp = cp + strlen(cp);
3085-
3086- return bp;
3087-}
3088-
3089-/* Device attributes */
3090-static char *string_DeviceAttributes(unsigned int flags) {
3091- static int si = 0; /* String buffer index */
3092- static char buf[5][80]; /* String buffers */
3093- char *bp, *cp;
3094-
3095- cp = bp = buf[si++];
3096- si %= 5; /* Rotate through buffers */
3097-
3098- if (flags & icTransparency) {
3099- sprintf(cp,"Transparency");
3100- } else {
3101- sprintf(cp,"Reflective");
3102- }
3103- cp = cp + strlen(cp);
3104- if (flags & icMatte) {
3105- sprintf(cp,", Matte");
3106- } else {
3107- sprintf(cp,", Glossy");
3108- }
3109- cp = cp + strlen(cp);
3110- if (flags & icNegative) {
3111- sprintf(cp,", Negative");
3112- } else {
3113- sprintf(cp,", Positive");
3114- }
3115- cp = cp + strlen(cp);
3116- if (flags & icBlackAndWhite) {
3117- sprintf(cp,", BlackAndWhite");
3118- } else {
3119- sprintf(cp,", Color");
3120- }
3121- cp = cp + strlen(cp);
3122-
3123- return bp;
3124-}
3125-
3126-/* Profile header flags */
3127-static char *string_ProfileHeaderFlags(unsigned int flags) {
3128- static int si = 0; /* String buffer index */
3129- static char buf[5][80]; /* String buffers */
3130- char *bp, *cp;
3131-
3132- cp = bp = buf[si++];
3133- si %= 5; /* Rotate through buffers */
3134-
3135- if (flags & icEmbeddedProfileTrue) {
3136- sprintf(cp,"Embedded Profile");
3137- } else {
3138- sprintf(cp,"Not Embedded Profile");
3139- }
3140- cp = cp + strlen(cp);
3141- if (flags & icUseWithEmbeddedDataOnly) {
3142- sprintf(cp,", Use with embedded data only");
3143- } else {
3144- sprintf(cp,", Use anywhere");
3145- }
3146- cp = cp + strlen(cp);
3147-
3148- return bp;
3149-}
3150-
3151-
3152-static char *string_AsciiOrBinaryData(unsigned int flags) {
3153- static int si = 0; /* String buffer index */
3154- static char buf[5][80]; /* String buffers */
3155- char *bp, *cp;
3156-
3157- cp = bp = buf[si++];
3158- si %= 5; /* Rotate through buffers */
3159-
3160- if (flags & icBinaryData) {
3161- sprintf(cp,"Binary");
3162- } else {
3163- sprintf(cp,"Ascii");
3164- }
3165- cp = cp + strlen(cp);
3166-
3167- return bp;
3168-}
3169-
3170-/* ------------------------------------------------------------ */
3171-/* Enumeration dump functions */
3172-/* Note - returned buffers are static, can only be used once */
3173-/* before buffers get reused if type is unknown. */
3174-
3175-/* public tags and sizes */
3176-static const char *string_TagSignature(icTagSignature sig) {
3177- static char buf[80];
3178- switch(sig) {
3179- case icSigAToB0Tag:
3180- return "AToB0 Multidimentional Transform";
3181- case icSigAToB1Tag:
3182- return "AToB1 Multidimentional Transform";
3183- case icSigAToB2Tag:
3184- return "AToB2 Multidimentional Transform";
3185- case icSigBlueColorantTag:
3186- return "Blue Colorant";
3187- case icSigBlueTRCTag:
3188- return "Blue Tone Reproduction Curve";
3189- case icSigBToA0Tag:
3190- return "BToA0 Multidimentional Transform";
3191- case icSigBToA1Tag:
3192- return "BToA1 Multidimentional Transform";
3193- case icSigBToA2Tag:
3194- return "BToA2 Multidimentional Transform";
3195- case icSigCalibrationDateTimeTag:
3196- return "Calibration Date & Time";
3197- case icSigCharTargetTag:
3198- return "Characterization Target";
3199- case icSigCopyrightTag:
3200- return "Copyright";
3201- case icSigCrdInfoTag:
3202- return "CRD Info";
3203- case icSigDeviceMfgDescTag:
3204- return "Device Manufacturer Description";
3205- case icSigDeviceModelDescTag:
3206- return "Device Model Description";
3207- case icSigGamutTag:
3208- return "Gamut";
3209- case icSigGrayTRCTag:
3210- return "Gray Tone Reproduction Curve";
3211- case icSigGreenColorantTag:
3212- return "Green Colorant";
3213- case icSigGreenTRCTag:
3214- return "Green Tone Reproduction Curve";
3215- case icSigLuminanceTag:
3216- return "Luminance";
3217- case icSigMeasurementTag:
3218- return "Measurement";
3219- case icSigMediaBlackPointTag:
3220- return "Media Black Point";
3221- case icSigMediaWhitePointTag:
3222- return "Media White Point";
3223- case icSigNamedColorTag:
3224- return "Named Color";
3225- case icSigNamedColor2Tag:
3226- return "Named Color 2";
3227- case icSigPreview0Tag:
3228- return "Preview0";
3229- case icSigPreview1Tag:
3230- return "Preview1";
3231- case icSigPreview2Tag:
3232- return "Preview2";
3233- case icSigProfileDescriptionTag:
3234- return "Profile Description";
3235- case icSigProfileSequenceDescTag:
3236- return "Profile Sequence";
3237- case icSigPs2CRD0Tag:
3238- return "PS Level 2 CRD perceptual";
3239- case icSigPs2CRD1Tag:
3240- return "PS Level 2 CRD colorimetric";
3241- case icSigPs2CRD2Tag:
3242- return "PS Level 2 CRD saturation";
3243- case icSigPs2CRD3Tag:
3244- return "PS Level 2 CRD absolute";
3245- case icSigPs2CSATag:
3246- return "PS Level 2 color space array";
3247- case icSigPs2RenderingIntentTag:
3248- return "PS Level 2 Rendering Intent";
3249- case icSigRedColorantTag:
3250- return "Red Colorant";
3251- case icSigRedTRCTag:
3252- return "Red Tone Reproduction Curve";
3253- case icSigScreeningDescTag:
3254- return "Screening Description";
3255- case icSigScreeningTag:
3256- return "Screening Attributes";
3257- case icSigTechnologyTag:
3258- return "Device Technology";
3259- case icSigUcrBgTag:
3260- return "Under Color Removal & Black Generation";
3261- case icSigVideoCardGammaTag:
3262- return "Video Card Gamma Curve";
3263- case icSigViewingCondDescTag:
3264- return "Viewing Condition Description";
3265- case icSigViewingConditionsTag:
3266- return "Viewing Condition Paramaters";
3267- default:
3268- sprintf(buf,"Unrecognized - %s",tag2str(sig));
3269- return buf;
3270- }
3271-}
3272-
3273-/* technology signature descriptions */
3274-static const char *string_TechnologySignature(icTechnologySignature sig) {
3275- static char buf[80];
3276- switch(sig) {
3277- case icSigDigitalCamera:
3278- return "Digital Camera";
3279- case icSigFilmScanner:
3280- return "Film Scanner";
3281- case icSigReflectiveScanner:
3282- return "Reflective Scanner";
3283- case icSigInkJetPrinter:
3284- return "InkJet Printer";
3285- case icSigThermalWaxPrinter:
3286- return "Thermal WaxPrinter";
3287- case icSigElectrophotographicPrinter:
3288- return "Electrophotographic Printer";
3289- case icSigElectrostaticPrinter:
3290- return "Electrostatic Printer";
3291- case icSigDyeSublimationPrinter:
3292- return "DyeSublimation Printer";
3293- case icSigPhotographicPaperPrinter:
3294- return "Photographic Paper Printer";
3295- case icSigFilmWriter:
3296- return "Film Writer";
3297- case icSigVideoMonitor:
3298- return "Video Monitor";
3299- case icSigVideoCamera:
3300- return "Video Camera";
3301- case icSigProjectionTelevision:
3302- return "Projection Television";
3303- case icSigCRTDisplay:
3304- return "Cathode Ray Tube Display";
3305- case icSigPMDisplay:
3306- return "Passive Matrix Display";
3307- case icSigAMDisplay:
3308- return "Active Matrix Display";
3309- case icSigPhotoCD:
3310- return "Photo CD";
3311- case icSigPhotoImageSetter:
3312- return "Photo ImageSetter";
3313- case icSigGravure:
3314- return "Gravure";
3315- case icSigOffsetLithography:
3316- return "Offset Lithography";
3317- case icSigSilkscreen:
3318- return "Silkscreen";
3319- case icSigFlexography:
3320- return "Flexography";
3321- default:
3322- sprintf(buf,"Unrecognized - %s",tag2str(sig));
3323- return buf;
3324- }
3325-}
3326-
3327-/* type signatures */
3328-static const char *string_TypeSignature(icTagTypeSignature sig) {
3329- static char buf[80];
3330- switch(sig) {
3331- case icSigCurveType:
3332- return "Curve";
3333- case icSigDataType:
3334- return "Data";
3335- case icSigDateTimeType:
3336- return "DateTime";
3337- case icSigLut16Type:
3338- return "Lut16";
3339- case icSigLut8Type:
3340- return "Lut8";
3341- case icSigMeasurementType:
3342- return "Measurement";
3343- case icSigNamedColorType:
3344- return "Named Color";
3345- case icSigProfileSequenceDescType:
3346- return "Profile Sequence Desc";
3347- case icSigS15Fixed16ArrayType:
3348- return "S15Fixed16 Array";
3349- case icSigScreeningType:
3350- return "Screening";
3351- case icSigSignatureType:
3352- return "Signature";
3353- case icSigTextType:
3354- return "Text";
3355- case icSigTextDescriptionType:
3356- return "Text Description";
3357- case icSigU16Fixed16ArrayType:
3358- return "U16Fixed16 Array";
3359- case icSigUcrBgType:
3360- return "Under Color Removal & Black Generation";
3361- case icSigUInt16ArrayType:
3362- return "UInt16 Array";
3363- case icSigUInt32ArrayType:
3364- return "UInt32 Array";
3365- case icSigUInt64ArrayType:
3366- return "UInt64 Array";
3367- case icSigUInt8ArrayType:
3368- return "UInt8 Array";
3369- case icSigVideoCardGammaType:
3370- return "Video Card Gamma";
3371- case icSigViewingConditionsType:
3372- return "Viewing Conditions";
3373- case icSigXYZType:
3374- return "XYZ (Array?)";
3375- case icSigNamedColor2Type:
3376- return "Named Color 2";
3377- case icSigCrdInfoType:
3378- return "CRD Info";
3379- default:
3380- sprintf(buf,"Unrecognized - %s",tag2str(sig));
3381- return buf;
3382- }
3383-}
3384-
3385-/* Color Space Signatures */
3386-static const char *string_ColorSpaceSignature(icColorSpaceSignature sig) {
3387- static char buf[80];
3388- switch(sig) {
3389- case icSigXYZData:
3390- return "XYZ";
3391- case icSigLabData:
3392- return "Lab";
3393- case icSigLuvData:
3394- return "Luv";
3395- case icSigYCbCrData:
3396- return "YCbCr";
3397- case icSigYxyData:
3398- return "Yxy";
3399- case icSigRgbData:
3400- return "RGB";
3401- case icSigGrayData:
3402- return "Gray";
3403- case icSigHsvData:
3404- return "HSV";
3405- case icSigHlsData:
3406- return "HLS";
3407- case icSigCmykData:
3408- return "CMYK";
3409- case icSigCmyData:
3410- return "CMY";
3411- case icSig2colorData:
3412- return "2 Color";
3413- case icSig3colorData:
3414- return "3 Color";
3415- case icSig4colorData:
3416- return "4 Color";
3417- case icSig5colorData:
3418- case icSigMch5Data:
3419- return "5 Color";
3420- case icSig6colorData:
3421- case icSigMch6Data:
3422- return "6 Color";
3423- case icSig7colorData:
3424- case icSigMch7Data:
3425- return "7 Color";
3426- case icSig8colorData:
3427- case icSigMch8Data:
3428- return "8 Color";
3429- case icSig9colorData:
3430- return "9 Color";
3431- case icSig10colorData:
3432- return "10 Color";
3433- case icSig11colorData:
3434- return "11 Color";
3435- case icSig12colorData:
3436- return "12 Color";
3437- case icSig13colorData:
3438- return "13 Color";
3439- case icSig14colorData:
3440- return "14 Color";
3441- case icSig15colorData:
3442- return "15 Color";
3443-
3444- /* Non-standard and Pseudo spaces */
3445- case icmSigYData:
3446- return "Y";
3447- case icmSigLData:
3448- return "L";
3449- case icmSigL8Data:
3450- return "L";
3451- case icmSigLV2Data:
3452- return "L";
3453- case icmSigLV4Data:
3454- return "L";
3455- case icmSigPCSData:
3456- return "PCS";
3457- case icmSigLab8Data:
3458- return "Lab";
3459- case icmSigLabV2Data:
3460- return "Lab";
3461- case icmSigLabV4Data:
3462- return "Lab";
3463-
3464- default:
3465- sprintf(buf,"Unrecognized - %s",tag2str(sig));
3466- return buf;
3467- }
3468-}
3469-
3470-#ifdef NEVER
3471-/* Public version of above */
3472-char *ColorSpaceSignature2str(icColorSpaceSignature sig) {
3473- return string_ColorSpaceSignature(sig);
3474-}
3475-#endif
3476-
3477-
3478-/* profileClass enumerations */
3479-static const char *string_ProfileClassSignature(icProfileClassSignature sig) {
3480- static char buf[80];
3481- switch(sig) {
3482- case icSigInputClass:
3483- return "Input";
3484- case icSigDisplayClass:
3485- return "Display";
3486- case icSigOutputClass:
3487- return "Output";
3488- case icSigLinkClass:
3489- return "Link";
3490- case icSigAbstractClass:
3491- return "Abstract";
3492- case icSigColorSpaceClass:
3493- return "Color Space";
3494- case icSigNamedColorClass:
3495- return "Named Color";
3496- default:
3497- sprintf(buf,"Unrecognized - %s",tag2str(sig));
3498- return buf;
3499- }
3500-}
3501-
3502-/* Platform Signatures */
3503-static const char *string_PlatformSignature(icPlatformSignature sig) {
3504- static char buf[80];
3505- switch(sig) {
3506- case icSigMacintosh:
3507- return "Macintosh";
3508- case icSigMicrosoft:
3509- return "Microsoft";
3510- case icSigSolaris:
3511- return "Solaris";
3512- case icSigSGI:
3513- return "SGI";
3514- case icSigTaligent:
3515- return "Taligent";
3516- case icmSig_nix:
3517- return "*nix";
3518- default:
3519- sprintf(buf,"Unrecognized - %s",tag2str(sig));
3520- return buf;
3521- }
3522-}
3523-
3524-/* Measurement Geometry, used in the measurmentType tag */
3525-static const char *string_MeasurementGeometry(icMeasurementGeometry sig) {
3526- static char buf[30];
3527- switch(sig) {
3528- case icGeometryUnknown:
3529- return "Unknown";
3530- case icGeometry045or450:
3531- return "0/45 or 45/0";
3532- case icGeometry0dord0:
3533- return "0/d or d/0";
3534- default:
3535- sprintf(buf,"Unrecognized - 0x%x",sig);
3536- return buf;
3537- }
3538-}
3539-
3540-/* Rendering Intents, used in the profile header */
3541-static const char *string_RenderingIntent(icRenderingIntent sig) {
3542- static char buf[30];
3543- switch(sig) {
3544- case icPerceptual:
3545- return "Perceptual";
3546- case icRelativeColorimetric:
3547- return "Relative Colorimetric";
3548- case icSaturation:
3549- return "Saturation";
3550- case icAbsoluteColorimetric:
3551- return "Absolute Colorimetric";
3552- case icmAbsolutePerceptual: /* icclib specials */
3553- return "Absolute Perceptual";
3554- case icmAbsoluteSaturation: /* icclib specials */
3555- return "Absolute Saturation";
3556- case icmDefaultIntent: /* icclib specials */
3557- return "Default Intent";
3558- default:
3559- sprintf(buf,"Unrecognized - 0x%x",sig);
3560- return buf;
3561- }
3562-}
3563-
3564-/* Transform Lookup function */
3565-static const char *string_LookupFunc(icmLookupFunc sig) {
3566- static char buf[30];
3567- switch(sig) {
3568- case icmFwd:
3569- return "Forward";
3570- case icmBwd:
3571- return "Backward";
3572- case icmGamut:
3573- return "Gamut";
3574- case icmPreview:
3575- return "Preview";
3576- default:
3577- sprintf(buf,"Unrecognized - 0x%x",sig);
3578- return buf;
3579- }
3580-}
3581-
3582-
3583-/* Different Spot Shapes currently defined, used for screeningType */
3584-static const char *string_SpotShape(icSpotShape sig) {
3585- static char buf[30];
3586- switch(sig) {
3587- case icSpotShapeUnknown:
3588- return "Unknown";
3589- case icSpotShapePrinterDefault:
3590- return "Printer Default";
3591- case icSpotShapeRound:
3592- return "Round";
3593- case icSpotShapeDiamond:
3594- return "Diamond";
3595- case icSpotShapeEllipse:
3596- return "Ellipse";
3597- case icSpotShapeLine:
3598- return "Line";
3599- case icSpotShapeSquare:
3600- return "Square";
3601- case icSpotShapeCross:
3602- return "Cross";
3603- default:
3604- sprintf(buf,"Unrecognized - 0x%x",sig);
3605- return buf;
3606- }
3607-}
3608-
3609-/* Standard Observer, used in the measurmentType tag */
3610-static const char *string_StandardObserver(icStandardObserver sig) {
3611- static char buf[30];
3612- switch(sig) {
3613- case icStdObsUnknown:
3614- return "Unknown";
3615- case icStdObs1931TwoDegrees:
3616- return "1931 Two Degrees";
3617- case icStdObs1964TenDegrees:
3618- return "1964 Ten Degrees";
3619- default:
3620- sprintf(buf,"Unrecognized - 0x%x",sig);
3621- return buf;
3622- }
3623-}
3624-
3625-/* Pre-defined illuminants, used in measurement and viewing conditions type */
3626-static const char *string_Illuminant(icIlluminant sig) {
3627- static char buf[30];
3628- switch(sig) {
3629- case icIlluminantUnknown:
3630- return "Unknown";
3631- case icIlluminantD50:
3632- return "D50";
3633- case icIlluminantD65:
3634- return "D65";
3635- case icIlluminantD93:
3636- return "D93";
3637- case icIlluminantF2:
3638- return "F2";
3639- case icIlluminantD55:
3640- return "D55";
3641- case icIlluminantA:
3642- return "A";
3643- case icIlluminantEquiPowerE:
3644- return "Equi-Power(E)";
3645- case icIlluminantF8:
3646- return "F8";
3647- default:
3648- sprintf(buf,"Unrecognized - 0x%x",sig);
3649- return buf;
3650- }
3651-}
3652-
3653-/* Return a text abreviation of a color lookup algorithm */
3654-static const char *string_LuAlg(icmLuAlgType alg) {
3655- static char buf[80];
3656-
3657- switch(alg) {
3658- case icmMonoFwdType:
3659- return "MonoFwd";
3660- case icmMonoBwdType:
3661- return "MonoBwd";
3662- case icmMatrixFwdType:
3663- return "MatrixFwd";
3664- case icmMatrixBwdType:
3665- return "MatrixBwd";
3666- case icmLutType:
3667- return "Lut";
3668- default:
3669- sprintf(buf,"Unrecognized - %d",alg);
3670- return buf;
3671- }
3672-}
3673-
3674-/* Return a string description of the given enumeration value */
3675-/* Public: */
3676-const char *icm2str(icmEnumType etype, int enumval) {
3677-
3678- switch(etype) {
3679- case icmScreenEncodings:
3680- return string_ScreenEncodings((unsigned int) enumval);
3681- case icmDeviceAttributes:
3682- return string_DeviceAttributes((unsigned int) enumval);
3683- case icmProfileHeaderFlags:
3684- return string_ProfileHeaderFlags((unsigned int) enumval);
3685- case icmAsciiOrBinaryData:
3686- return string_AsciiOrBinaryData((unsigned int) enumval);
3687- case icmTagSignature:
3688- return string_TagSignature((icTagSignature) enumval);
3689- case icmTechnologySignature:
3690- return string_TechnologySignature((icTechnologySignature) enumval);
3691- case icmTypeSignature:
3692- return string_TypeSignature((icTagTypeSignature) enumval);
3693- case icmColorSpaceSignature:
3694- return string_ColorSpaceSignature((icColorSpaceSignature) enumval);
3695- case icmProfileClassSignature:
3696- return string_ProfileClassSignature((icProfileClassSignature) enumval);
3697- case icmPlatformSignature:
3698- return string_PlatformSignature((icPlatformSignature) enumval);
3699- case icmMeasurementGeometry:
3700- return string_MeasurementGeometry((icMeasurementGeometry) enumval);
3701- case icmRenderingIntent:
3702- return string_RenderingIntent((icRenderingIntent) enumval);
3703- case icmTransformLookupFunc:
3704- return string_LookupFunc((icmLookupFunc) enumval);
3705- case icmSpotShape:
3706- return string_SpotShape((icSpotShape) enumval);
3707- case icmStandardObserver:
3708- return string_StandardObserver((icStandardObserver) enumval);
3709- case icmIlluminant:
3710- return string_Illuminant((icIlluminant) enumval);
3711- case icmLuAlg:
3712- return string_LuAlg((icmLuAlgType) enumval);
3713- default:
3714- return "enum2str got unknown type";
3715- }
3716-}
3717-
3718-/* ========================================================== */
3719-/* Object I/O routines */
3720-/* ========================================================== */
3721-/* icmUnknown object */
3722-
3723-/* Return the number of bytes needed to write this tag */
3724-static unsigned int icmUnknown_get_size(
3725- icmBase *pp
3726-) {
3727- icmUnknown *p = (icmUnknown *)pp;
3728- unsigned int len = 0;
3729- len = sat_add(len, 8); /* 8 bytes for tag and padding */
3730- len = sat_addmul(len, p->size, 1); /* 1 byte for each unknown data */
3731- return len;
3732-}
3733-
3734-/* read the object, return 0 on success, error code on fail */
3735-static int icmUnknown_read(
3736- icmBase *pp,
3737- unsigned int len, /* tag length */
3738- unsigned int of /* start offset within file */
3739-) {
3740- icmUnknown *p = (icmUnknown *)pp;
3741- icc *icp = p->icp;
3742- int rv = 0;
3743- unsigned int i, size;
3744- char *bp, *buf;
3745-
3746- if (len < 8) {
3747- sprintf(icp->err,"icmUnknown_read: Tag too small to be legal");
3748- return icp->errc = 1;
3749- }
3750-
3751- /* Allocate a file read buffer */
3752- if ((buf = (char *) icp->al->malloc(icp->al, len)) == NULL) {
3753- sprintf(icp->err,"icmUnknown_read: malloc() failed");
3754- return icp->errc = 2;
3755- }
3756- bp = buf;
3757-
3758- /* Read portion of file into buffer */
3759- if ( icp->fp->seek(icp->fp, of) != 0
3760- || icp->fp->read(icp->fp, bp, 1, len) != len) {
3761- sprintf(icp->err,"icmUnknown_read: fseek() or fread() failed");
3762- icp->al->free(icp->al, buf);
3763- return icp->errc = 1;
3764- }
3765- p->size = size = (len - 8)/1; /* Number of elements in the array */
3766-
3767- if ((rv = p->allocate((icmBase *)p)) != 0) {
3768- icp->al->free(icp->al, buf);
3769- return rv;
3770- }
3771-
3772- /* Read type descriptor from the buffer */
3773- p->uttype = (icTagTypeSignature)read_SInt32Number(bp);
3774- bp += 8; /* Skip padding */
3775-
3776- /* Read all the data from the buffer */
3777- for (i = 0; i < size; i++, bp += 1) {
3778- p->data[i] = read_UInt8Number(bp);
3779- }
3780- icp->al->free(p->icp->al, buf);
3781- return 0;
3782-}
3783-
3784-/* Write the contents of the object. Return 0 on sucess, error code on failure */
3785-static int icmUnknown_write(
3786- icmBase *pp,
3787- unsigned int of /* File offset to write from */
3788-) {
3789- icmUnknown *p = (icmUnknown *)pp;
3790- icc *icp = p->icp;
3791- unsigned int i;
3792- unsigned int len;
3793- char *bp, *buf; /* Buffer to write from */
3794- int rv = 0;
3795-
3796- /* Allocate a file write buffer */
3797- if ((len = p->get_size((icmBase *)p)) == UINT_MAX) {
3798- sprintf(icp->err,"icmUnknown_write get_size overflow");
3799- return icp->errc = 1;
3800- }
3801- if ((buf = (char *) icp->al->malloc(icp->al, len)) == NULL) {
3802- sprintf(icp->err,"icmUnknown_write malloc() failed");
3803- return icp->errc = 2;
3804- }
3805- bp = buf;
3806-
3807- /* Write type descriptor to the buffer */
3808- if ((rv = write_SInt32Number((int)p->uttype,bp)) != 0) {
3809- sprintf(icp->err,"icmUnknown_write: write_SInt32Number() failed");
3810- icp->al->free(icp->al, buf);
3811- return icp->errc = rv;
3812- }
3813- write_SInt32Number(0,bp+4); /* Set padding to 0 */
3814- bp += 8; /* Skip padding */
3815-
3816- /* Write all the data to the buffer */
3817- for (i = 0; i < p->size; i++, bp += 1) {
3818- if ((rv = write_UInt8Number(p->data[i],bp)) != 0) {
3819- sprintf(icp->err,"icmUnknown_write: write_UInt8umber() failed");
3820- icp->al->free(icp->al, buf);
3821- return icp->errc = rv;
3822- }
3823- }
3824-
3825- /* Write to the file */
3826- if ( icp->fp->seek(icp->fp, of) != 0
3827- || icp->fp->write(icp->fp, buf, 1, len) != len) {
3828- sprintf(icp->err,"icmUnknown_write fseek() or fwrite() failed");
3829- icp->al->free(icp->al, buf);
3830- return icp->errc = 2;
3831- }
3832- icp->al->free(icp->al, buf);
3833- return 0;
3834-}
3835-
3836-/* Dump a text description of the object */
3837-static void icmUnknown_dump(
3838- icmBase *pp,
3839- icmFile *op, /* Output to dump to */
3840- int verb /* Verbosity level */
3841-) {
3842- icmUnknown *p = (icmUnknown *)pp;
3843- unsigned int i, ii, r, ph;
3844-
3845- if (verb <= 1)
3846- return;
3847-
3848- op->gprintf(op,"Unknown:\n");
3849- op->gprintf(op," Payload size in bytes = %u\n",p->size);
3850-
3851- /* Print one row of binary and ASCII interpretation if verb == 2, All if == 3 */
3852- /* else print all of it. */
3853- ii = i = ph = 0;
3854- for (r = 1;; r++) { /* count rows */
3855- int c = 1; /* Character location */
3856-
3857- c = 1;
3858- if (ph != 0) { /* Print ASCII under binary */
3859- op->gprintf(op," ");
3860- i = ii; /* Swap */
3861- c += 11;
3862- } else {
3863- op->gprintf(op," 0x%04lx: ",i);
3864- ii = i; /* Swap */
3865- c += 10;
3866- }
3867- while (i < p->size && c < 75) {
3868- if (ph == 0)
3869- op->gprintf(op,"%02x ",p->data[i]);
3870- else {
3871- if (isprint(p->data[i]))
3872- op->gprintf(op," %c ",p->data[i]);
3873- else
3874- op->gprintf(op," ",p->data[i]);
3875- }
3876- c += 3;
3877- i++;
3878- }
3879- if (ph == 0 || i < p->size)
3880- op->gprintf(op,"\n");
3881-
3882- if (ph == 1 && i >= p->size) {
3883- op->gprintf(op,"\n");
3884- break;
3885- }
3886- if (ph == 1 && r > 1 && verb < 3) {
3887- op->gprintf(op," ...\n");
3888- break; /* Print 1 row if not verbose */
3889- }
3890-
3891- if (ph == 0)
3892- ph = 1;
3893- else
3894- ph = 0;
3895-
3896- }
3897-}
3898-
3899-/* Allocate variable sized data elements */
3900-static int icmUnknown_allocate(
3901- icmBase *pp
3902-) {
3903- icmUnknown *p = (icmUnknown *)pp;
3904- icc *icp = p->icp;
3905-
3906- if (p->size != p->_size) {
3907- if (ovr_mul(p->size, sizeof(unsigned char))) {
3908- sprintf(icp->err,"icmUnknown_alloc: size overflow");
3909- return icp->errc = 1;
3910- }
3911- if (p->data != NULL)
3912- icp->al->free(icp->al, p->data);
3913- if ((p->data = (unsigned char *) icp->al->calloc(icp->al, p->size, sizeof(unsigned char)))
3914- == NULL) {
3915- sprintf(icp->err,"icmUnknown_alloc: malloc() of icmUnknown data failed");
3916- return icp->errc = 2;
3917- }
3918- p->_size = p->size;
3919- }
3920- return 0;
3921-}
3922-
3923-/* Free all storage in the object */
3924-static void icmUnknown_delete(
3925- icmBase *pp
3926-) {
3927- icmUnknown *p = (icmUnknown *)pp;
3928- icc *icp = p->icp;
3929-
3930- if (p->data != NULL)
3931- icp->al->free(icp->al, p->data);
3932- icp->al->free(icp->al, p);
3933-}
3934-
3935-/* Create an empty object. Return null on error */
3936-static icmBase *new_icmUnknown(
3937- icc *icp
3938-) {
3939- icmUnknown *p;
3940- if ((p = (icmUnknown *) icp->al->calloc(icp->al,1,sizeof(icmUnknown))) == NULL)
3941- return NULL;
3942- p->ttype = icmSigUnknownType;
3943- p->uttype = icmSigUnknownType;
3944- p->refcount = 1;
3945- p->get_size = icmUnknown_get_size;
3946- p->read = icmUnknown_read;
3947- p->write = icmUnknown_write;
3948- p->dump = icmUnknown_dump;
3949- p->allocate = icmUnknown_allocate;
3950- p->del = icmUnknown_delete;
3951- p->icp = icp;
3952-
3953- return (icmBase *)p;
3954-}
3955-
3956-/* ---------------------------------------------------------- */
3957-/* icmUInt8Array object */
3958-
3959-/* Return the number of bytes needed to write this tag */
3960-static unsigned int icmUInt8Array_get_size(
3961- icmBase *pp
3962-) {
3963- icmUInt8Array *p = (icmUInt8Array *)pp;
3964- unsigned int len = 0;
3965- len = sat_add(len, 8); /* 8 bytes for tag and padding */
3966- len = sat_addmul(len, p->size, 1); /* 1 byte for each UInt8 */
3967- return len;
3968-}
3969-
3970-/* read the object, return 0 on success, error code on fail */
3971-static int icmUInt8Array_read(
3972- icmBase *pp,
3973- unsigned int len, /* tag length */
3974- unsigned int of /* start offset within file */
3975-) {
3976- icmUInt8Array *p = (icmUInt8Array *)pp;
3977- icc *icp = p->icp;
3978- int rv = 0;
3979- unsigned int i, size;
3980- char *bp, *buf;
3981-
3982- if (len < 8) {
3983- sprintf(icp->err,"icmUInt8Array_read: Tag too small to be legal");
3984- return icp->errc = 1;
3985- }
3986-
3987- /* Allocate a file read buffer */
3988- if ((buf = (char *) icp->al->malloc(icp->al, len)) == NULL) {
3989- sprintf(icp->err,"icmUInt8Array_read: malloc() failed");
3990- return icp->errc = 2;
3991- }
3992- bp = buf;
3993-
3994- /* Read portion of file into buffer */
3995- if ( icp->fp->seek(icp->fp, of) != 0
3996- || icp->fp->read(icp->fp, bp, 1, len) != len) {
3997- sprintf(icp->err,"icmUInt8Array_read: fseek() or fread() failed");
3998- icp->al->free(icp->al, buf);
3999- return icp->errc = 1;
4000- }
4001- p->size = size = (len - 8)/1; /* Number of elements in the array */
4002-
4003- if ((rv = p->allocate((icmBase *)p)) != 0) {
4004- icp->al->free(icp->al, buf);
4005- return rv;
4006- }
4007-
4008- /* Read type descriptor from the buffer */
4009- if (((icTagTypeSignature)read_SInt32Number(bp)) != p->ttype) {
4010- icp->al->free(icp->al, buf);
4011- sprintf(icp->err,"icmUInt8Array_read: Wrong tag type for icmUInt8Array");
4012- return icp->errc = 1;
4013- }
4014- bp += 8; /* Skip padding */
4015-
4016- /* Read all the data from the buffer */
4017- for (i = 0; i < size; i++, bp += 1) {
4018- p->data[i] = read_UInt8Number(bp);
4019- }
4020- icp->al->free(p->icp->al, buf);
4021- return 0;
4022-}
4023-
4024-/* Write the contents of the object. Return 0 on sucess, error code on failure */
4025-static int icmUInt8Array_write(
4026- icmBase *pp,
4027- unsigned int of /* File offset to write from */
4028-) {
4029- icmUInt8Array *p = (icmUInt8Array *)pp;
4030- icc *icp = p->icp;
4031- unsigned int i;
4032- unsigned int len;
4033- char *bp, *buf; /* Buffer to write from */
4034- int rv = 0;
4035-
4036- /* Allocate a file write buffer */
4037- if ((len = p->get_size((icmBase *)p)) == UINT_MAX) {
4038- sprintf(icp->err,"icmUInt8Array_write get_size overflow");
4039- return icp->errc = 1;
4040- }
4041- if ((buf = (char *) icp->al->malloc(icp->al, len)) == NULL) {
4042- sprintf(icp->err,"icmUInt8Array_write malloc() failed");
4043- return icp->errc = 2;
4044- }
4045- bp = buf;
4046-
4047- /* Write type descriptor to the buffer */
4048- if ((rv = write_SInt32Number((int)p->ttype,bp)) != 0) {
4049- sprintf(icp->err,"icmUInt8Array_write: write_SInt32Number() failed");
4050- icp->al->free(icp->al, buf);
4051- return icp->errc = rv;
4052- }
4053- write_SInt32Number(0,bp+4); /* Set padding to 0 */
4054- bp += 8; /* Skip padding */
4055-
4056- /* Write all the data to the buffer */
4057- for (i = 0; i < p->size; i++, bp += 1) {
4058- if ((rv = write_UInt8Number(p->data[i],bp)) != 0) {
4059- sprintf(icp->err,"icmUInt8Array_write: write_UInt8umber() failed");
4060- icp->al->free(icp->al, buf);
4061- return icp->errc = rv;
4062- }
4063- }
4064-
4065- /* Write to the file */
4066- if ( icp->fp->seek(icp->fp, of) != 0
4067- || icp->fp->write(icp->fp, buf, 1, len) != len) {
4068- sprintf(icp->err,"icmUInt8Array_write fseek() or fwrite() failed");
4069- icp->al->free(icp->al, buf);
4070- return icp->errc = 2;
4071- }
4072- icp->al->free(icp->al, buf);
4073- return 0;
4074-}
4075-
4076-/* Dump a text description of the object */
4077-static void icmUInt8Array_dump(
4078- icmBase *pp,
4079- icmFile *op, /* Output to dump to */
4080- int verb /* Verbosity level */
4081-) {
4082- icmUInt8Array *p = (icmUInt8Array *)pp;
4083- if (verb <= 0)
4084- return;
4085-
4086- op->gprintf(op,"UInt8Array:\n");
4087- op->gprintf(op," No. elements = %lu\n",p->size);
4088- if (verb >= 2) {
4089- unsigned int i;
4090- for (i = 0; i < p->size; i++)
4091- op->gprintf(op," %lu: %u\n",i,p->data[i]);
4092- }
4093-}
4094-
4095-/* Allocate variable sized data elements */
4096-static int icmUInt8Array_allocate(
4097- icmBase *pp
4098-) {
4099- icmUInt8Array *p = (icmUInt8Array *)pp;
4100- icc *icp = p->icp;
4101-
4102- if (p->size != p->_size) {
4103- if (ovr_mul(p->size, sizeof(unsigned int))) {
4104- sprintf(icp->err,"icmUInt8Array_alloc: size overflow");
4105- return icp->errc = 1;
4106- }
4107- if (p->data != NULL)
4108- icp->al->free(icp->al, p->data);
4109- if ((p->data = (unsigned int *) icp->al->calloc(icp->al, p->size, sizeof(unsigned int)))
4110- == NULL) {
4111- sprintf(icp->err,"icmUInt8Array_alloc: malloc() of icmUInt8Array data failed");
4112- return icp->errc = 2;
4113- }
4114- p->_size = p->size;
4115- }
4116- return 0;
4117-}
4118-
4119-/* Free all storage in the object */
4120-static void icmUInt8Array_delete(
4121- icmBase *pp
4122-) {
4123- icmUInt8Array *p = (icmUInt8Array *)pp;
4124- icc *icp = p->icp;
4125-
4126- if (p->data != NULL)
4127- icp->al->free(icp->al, p->data);
4128- icp->al->free(icp->al, p);
4129-}
4130-
4131-/* Create an empty object. Return null on error */
4132-static icmBase *new_icmUInt8Array(
4133- icc *icp
4134-) {
4135- icmUInt8Array *p;
4136- if ((p = (icmUInt8Array *) icp->al->calloc(icp->al,1,sizeof(icmUInt8Array))) == NULL)
4137- return NULL;
4138- p->ttype = icSigUInt8ArrayType;
4139- p->refcount = 1;
4140- p->get_size = icmUInt8Array_get_size;
4141- p->read = icmUInt8Array_read;
4142- p->write = icmUInt8Array_write;
4143- p->dump = icmUInt8Array_dump;
4144- p->allocate = icmUInt8Array_allocate;
4145- p->del = icmUInt8Array_delete;
4146- p->icp = icp;
4147-
4148- return (icmBase *)p;
4149-}
4150-
4151-/* ---------------------------------------------------------- */
4152-/* icmUInt16Array object */
4153-
4154-/* Return the number of bytes needed to write this tag */
4155-static unsigned int icmUInt16Array_get_size(
4156- icmBase *pp
4157-) {
4158- icmUInt16Array *p = (icmUInt16Array *)pp;
4159- unsigned int len = 0;
4160- len = sat_add(len, 8); /* 8 bytes for tag and padding */
4161- len = sat_addmul(len, p->size, 2); /* 2 bytes for each UInt16 */
4162- return len;
4163-}
4164-
4165-/* read the object, return 0 on success, error code on fail */
4166-static int icmUInt16Array_read(
4167- icmBase *pp,
4168- unsigned int len, /* tag length */
4169- unsigned int of /* start offset within file */
4170-) {
4171- icmUInt16Array *p = (icmUInt16Array *)pp;
4172- icc *icp = p->icp;
4173- int rv = 0;
4174- unsigned int i, size;
4175- char *bp, *buf;
4176-
4177- if (len < 8) {
4178- sprintf(icp->err,"icmUInt16Array_read: Tag too small to be legal");
4179- return icp->errc = 1;
4180- }
4181-
4182- /* Allocate a file read buffer */
4183- if ((buf = (char *) icp->al->malloc(icp->al, len)) == NULL) {
4184- sprintf(icp->err,"icmUInt16Array_read: malloc() failed");
4185- return icp->errc = 2;
4186- }
4187- bp = buf;
4188-
4189- /* Read portion of file into buffer */
4190- if ( icp->fp->seek(icp->fp, of) != 0
4191- || icp->fp->read(icp->fp, bp, 1, len) != len) {
4192- sprintf(icp->err,"icmUInt16Array_read: fseek() or fread() failed");
4193- icp->al->free(icp->al, buf);
4194- return icp->errc = 1;
4195- }
4196- p->size = size = (len - 8)/2; /* Number of elements in the array */
4197-
4198- if ((rv = p->allocate((icmBase *)p)) != 0) {
4199- icp->al->free(icp->al, buf);
4200- return rv;
4201- }
4202-
4203- /* Read type descriptor from the buffer */
4204- if (((icTagTypeSignature)read_SInt32Number(bp)) != p->ttype) {
4205- sprintf(icp->err,"icmUInt16Array_read: Wrong tag type for icmUInt16Array");
4206- icp->al->free(icp->al, buf);
4207- return icp->errc = 1;
4208- }
4209- bp += 8; /* Skip padding */
4210-
4211- /* Read all the data from the buffer */
4212- for (i = 0; i < size; i++, bp += 2) {
4213- p->data[i] = read_UInt16Number(bp);
4214- }
4215- icp->al->free(icp->al, buf);
4216- return 0;
4217-}
4218-
4219-/* Write the contents of the object. Return 0 on sucess, error code on failure */
4220-static int icmUInt16Array_write(
4221- icmBase *pp,
4222- unsigned int of /* File offset to write from */
4223-) {
4224- icmUInt16Array *p = (icmUInt16Array *)pp;
4225- icc *icp = p->icp;
4226- unsigned int i;
4227- unsigned int len;
4228- char *bp, *buf; /* Buffer to write from */
4229- int rv = 0;
4230-
4231- /* Allocate a file write buffer */
4232- if ((len = p->get_size((icmBase *)p)) == UINT_MAX) {
4233- sprintf(icp->err,"icmUInt16Array_write get_size overflow");
4234- return icp->errc = 1;
4235- }
4236- if ((buf = (char *) icp->al->malloc(icp->al, len)) == NULL) {
4237- sprintf(icp->err,"icmUInt16Array_write malloc() failed");
4238- return icp->errc = 2;
4239- }
4240- bp = buf;
4241-
4242- /* Write type descriptor to the buffer */
4243- if ((rv = write_SInt32Number((int)p->ttype,bp)) != 0) {
4244- sprintf(icp->err,"icmUInt16Array_write: write_SInt32Number() failed");
4245- icp->al->free(icp->al, buf);
4246- return icp->errc = rv;
4247- }
4248- write_SInt32Number(0,bp+4); /* Set padding to 0 */
4249-
4250- /* Write all the data to the buffer */
4251- bp += 8; /* Skip padding */
4252- for (i = 0; i < p->size; i++, bp += 2) {
4253- if ((rv = write_UInt16Number(p->data[i],bp)) != 0) {
4254- sprintf(icp->err,"icmUInt16Array_write: write_UInt16umber() failed");
4255- icp->al->free(icp->al, buf);
4256- return icp->errc = rv;
4257- }
4258- }
4259-
4260- /* Write to the file */
4261- if ( icp->fp->seek(icp->fp, of) != 0
4262- || icp->fp->write(icp->fp, buf, 1, len) != len) {
4263- sprintf(icp->err,"icmUInt16Array_write fseek() or fwrite() failed");
4264- icp->al->free(icp->al, buf);
4265- return icp->errc = 2;
4266- }
4267- icp->al->free(icp->al, buf);
4268- return 0;
4269-}
4270-
4271-/* Dump a text description of the object */
4272-static void icmUInt16Array_dump(
4273- icmBase *pp,
4274- icmFile *op, /* Output to dump to */
4275- int verb /* Verbosity level */
4276-) {
4277- icmUInt16Array *p = (icmUInt16Array *)pp;
4278- if (verb <= 0)
4279- return;
4280-
4281- op->gprintf(op,"UInt16Array:\n");
4282- op->gprintf(op," No. elements = %lu\n",p->size);
4283- if (verb >= 2) {
4284- unsigned int i;
4285- for (i = 0; i < p->size; i++)
4286- op->gprintf(op," %lu: %u\n",i,p->data[i]);
4287- }
4288-}
4289-
4290-/* Allocate variable sized data elements */
4291-static int icmUInt16Array_allocate(
4292- icmBase *pp
4293-) {
4294- icmUInt16Array *p = (icmUInt16Array *)pp;
4295- icc *icp = p->icp;
4296-
4297- if (p->size != p->_size) {
4298- if (ovr_mul(p->size, sizeof(unsigned int))) {
4299- sprintf(icp->err,"icmUInt16Array_alloc:: size overflow");
4300- return icp->errc = 1;
4301- }
4302- if (p->data != NULL)
4303- icp->al->free(icp->al, p->data);
4304- if ((p->data = (unsigned int *) icp->al->calloc(icp->al, p->size, sizeof(unsigned int)))
4305- == NULL) {
4306- sprintf(icp->err,"icmUInt16Array_alloc: malloc() of icmUInt16Array data failed");
4307- return icp->errc = 2;
4308- }
4309- p->_size = p->size;
4310- }
4311- return 0;
4312-}
4313-
4314-/* Free all storage in the object */
4315-static void icmUInt16Array_delete(
4316- icmBase *pp
4317-) {
4318- icmUInt16Array *p = (icmUInt16Array *)pp;
4319- icc *icp = p->icp;
4320-
4321- if (p->data != NULL)
4322- icp->al->free(icp->al, p->data);
4323- icp->al->free(icp->al, p);
4324-}
4325-
4326-/* Create an empty object. Return null on error */
4327-static icmBase *new_icmUInt16Array(
4328- icc *icp
4329-) {
4330- icmUInt16Array *p;
4331- if ((p = (icmUInt16Array *) icp->al->calloc(icp->al,1,sizeof(icmUInt16Array))) == NULL)
4332- return NULL;
4333- p->ttype = icSigUInt16ArrayType;
4334- p->refcount = 1;
4335- p->get_size = icmUInt16Array_get_size;
4336- p->read = icmUInt16Array_read;
4337- p->write = icmUInt16Array_write;
4338- p->dump = icmUInt16Array_dump;
4339- p->allocate = icmUInt16Array_allocate;
4340- p->del = icmUInt16Array_delete;
4341- p->icp = icp;
4342-
4343- return (icmBase *)p;
4344-}
4345-
4346-/* ---------------------------------------------------------- */
4347-/* icmUInt32Array object */
4348-
4349-/* Return the number of bytes needed to write this tag */
4350-static unsigned int icmUInt32Array_get_size(
4351- icmBase *pp
4352-) {
4353- icmUInt32Array *p = (icmUInt32Array *)pp;
4354- unsigned int len = 0;
4355- len = sat_add(len, 8); /* 8 bytes for tag and padding */
4356- len = sat_addmul(len, p->size, 4); /* 4 bytes for each UInt32 */
4357- return len;
4358-}
4359-
4360-/* read the object, return 0 on success, error code on fail */
4361-static int icmUInt32Array_read(
4362- icmBase *pp,
4363- unsigned int len, /* tag length */
4364- unsigned int of /* start offset within file */
4365-) {
4366- icmUInt32Array *p = (icmUInt32Array *)pp;
4367- icc *icp = p->icp;
4368- int rv = 0;
4369- unsigned int i, size;
4370- char *bp, *buf;
4371-
4372- if (len < 8) {
4373- sprintf(icp->err,"icmUInt32Array_read: Tag too small to be legal");
4374- return icp->errc = 1;
4375- }
4376-
4377- /* Allocate a file read buffer */
4378- if ((buf = (char *) icp->al->malloc(icp->al, len)) == NULL) {
4379- sprintf(icp->err,"icmUInt32Array_read: malloc() failed");
4380- return icp->errc = 2;
4381- }
4382- bp = buf;
4383-
4384- /* Read portion of file into buffer */
4385- if ( icp->fp->seek(icp->fp, of) != 0
4386- || icp->fp->read(icp->fp, bp, 1, len) != len) {
4387- sprintf(icp->err,"icmUInt32Array_read: fseek() or fread() failed");
4388- icp->al->free(icp->al, buf);
4389- return icp->errc = 1;
4390- }
4391- p->size = size = (len - 8)/4; /* Number of elements in the array */
4392-
4393- if ((rv = p->allocate((icmBase *)p)) != 0) {
4394- icp->al->free(icp->al, buf);
4395- return rv;
4396- }
4397-
4398- /* Read type descriptor from the buffer */
4399- if (((icTagTypeSignature)read_SInt32Number(bp)) != p->ttype) {
4400- sprintf(icp->err,"icmUInt32Array_read: Wrong tag type for icmUInt32Array");
4401- icp->al->free(icp->al, buf);
4402- return icp->errc = 1;
4403- }
4404- bp += 8; /* Skip padding */
4405-
4406- /* Read all the data from the buffer */
4407- for (i = 0; i < size; i++, bp += 4) {
4408- p->data[i] = read_UInt32Number(bp);
4409- }
4410- icp->al->free(icp->al, buf);
4411- return 0;
4412-}
4413-
4414-/* Write the contents of the object. Return 0 on sucess, error code on failure */
4415-static int icmUInt32Array_write(
4416- icmBase *pp,
4417- unsigned int of /* File offset to write from */
4418-) {
4419- icmUInt32Array *p = (icmUInt32Array *)pp;
4420- icc *icp = p->icp;
4421- unsigned int i;
4422- unsigned int len;
4423- char *bp, *buf; /* Buffer to write from */
4424- int rv = 0;
4425-
4426- /* Allocate a file write buffer */
4427- if ((len = p->get_size((icmBase *)p)) == UINT_MAX) {
4428- sprintf(icp->err,"icmUInt32Array_write get_size overflow");
4429- return icp->errc = 1;
4430- }
4431- if ((buf = (char *) icp->al->malloc(icp->al, len)) == NULL) {
4432- sprintf(icp->err,"icmUInt32Array_write malloc() failed");
4433- return icp->errc = 2;
4434- }
4435- bp = buf;
4436-
4437- /* Write type descriptor to the buffer */
4438- if ((rv = write_SInt32Number((int)p->ttype,bp)) != 0) {
4439- sprintf(icp->err,"icmUInt32Array_write: write_SInt32Number() failed");
4440- icp->al->free(icp->al, buf);
4441- return icp->errc = rv;
4442- }
4443- write_SInt32Number(0,bp+4); /* Set padding to 0 */
4444-
4445- /* Write all the data to the buffer */
4446- bp += 8; /* Skip padding */
4447- for (i = 0; i < p->size; i++, bp += 4) {
4448- if ((rv = write_UInt32Number(p->data[i],bp)) != 0) {
4449- sprintf(icp->err,"icmUInt32Array_write: write_UInt32umber() failed");
4450- icp->al->free(icp->al, buf);
4451- return icp->errc = rv;
4452- }
4453- }
4454-
4455- /* Write to the file */
4456- if ( icp->fp->seek(icp->fp, of) != 0
4457- || icp->fp->write(icp->fp, buf, 1, len) != len) {
4458- sprintf(icp->err,"icmUInt32Array_write fseek() or fwrite() failed");
4459- icp->al->free(icp->al, buf);
4460- return icp->errc = 2;
4461- }
4462- icp->al->free(icp->al, buf);
4463- return 0;
4464-}
4465-
4466-/* Dump a text description of the object */
4467-static void icmUInt32Array_dump(
4468- icmBase *pp,
4469- icmFile *op, /* Output to dump to */
4470- int verb /* Verbosity level */
4471-) {
4472- icmUInt32Array *p = (icmUInt32Array *)pp;
4473- if (verb <= 0)
4474- return;
4475-
4476- op->gprintf(op,"UInt32Array:\n");
4477- op->gprintf(op," No. elements = %lu\n",p->size);
4478- if (verb >= 2) {
4479- unsigned int i;
4480- for (i = 0; i < p->size; i++)
4481- op->gprintf(op," %lu: %u\n",i,p->data[i]);
4482- }
4483-}
4484-
4485-/* Allocate variable sized data elements */
4486-static int icmUInt32Array_allocate(
4487- icmBase *pp
4488-) {
4489- icmUInt32Array *p = (icmUInt32Array *)pp;
4490- icc *icp = p->icp;
4491-
4492- if (p->size != p->_size) {
4493- if (ovr_mul(p->size, sizeof(unsigned int))) {
4494- sprintf(icp->err,"icmUInt32Array_alloc: size overflow");
4495- return icp->errc = 1;
4496- }
4497- if (p->data != NULL)
4498- icp->al->free(icp->al, p->data);
4499- if ((p->data = (unsigned int *) icp->al->calloc(icp->al, p->size, sizeof(unsigned int)))
4500- == NULL) {
4501- sprintf(icp->err,"icmUInt32Array_alloc: malloc() of icmUInt32Array data failed");
4502- return icp->errc = 2;
4503- }
4504- p->_size = p->size;
4505- }
4506- return 0;
4507-}
4508-
4509-/* Free all storage in the object */
4510-static void icmUInt32Array_delete(
4511- icmBase *pp
4512-) {
4513- icmUInt32Array *p = (icmUInt32Array *)pp;
4514- icc *icp = p->icp;
4515-
4516- if (p->data != NULL)
4517- icp->al->free(icp->al, p->data);
4518- icp->al->free(icp->al, p);
4519-}
4520-
4521-/* Create an empty object. Return null on error */
4522-static icmBase *new_icmUInt32Array(
4523- icc *icp
4524-) {
4525- icmUInt32Array *p;
4526- if ((p = (icmUInt32Array *) icp->al->calloc(icp->al,1,sizeof(icmUInt32Array))) == NULL)
4527- return NULL;
4528- p->ttype = icSigUInt32ArrayType;
4529- p->refcount = 1;
4530- p->get_size = icmUInt32Array_get_size;
4531- p->read = icmUInt32Array_read;
4532- p->write = icmUInt32Array_write;
4533- p->dump = icmUInt32Array_dump;
4534- p->allocate = icmUInt32Array_allocate;
4535- p->del = icmUInt32Array_delete;
4536- p->icp = icp;
4537-
4538- return (icmBase *)p;
4539-}
4540-
4541-/* ---------------------------------------------------------- */
4542-/* icmUInt64Array object */
4543-
4544-/* Return the number of bytes needed to write this tag */
4545-static unsigned int icmUInt64Array_get_size(
4546- icmBase *pp
4547-) {
4548- icmUInt64Array *p = (icmUInt64Array *)pp;
4549- unsigned int len = 0;
4550- len = sat_add(len, 8); /* 8 bytes for tag and padding */
4551- len = sat_addmul(len, p->size, 8); /* 8 bytes for each UInt64 */
4552- return len;
4553-}
4554-
4555-/* read the object, return 0 on success, error code on fail */
4556-static int icmUInt64Array_read(
4557- icmBase *pp,
4558- unsigned int len, /* tag length */
4559- unsigned int of /* start offset within file */
4560-) {
4561- icmUInt64Array *p = (icmUInt64Array *)pp;
4562- icc *icp = p->icp;
4563- int rv = 0;
4564- unsigned int i, size;
4565- char *bp, *buf;
4566-
4567- if (len < 8) {
4568- sprintf(icp->err,"icmUInt64Array_read: Tag too small to be legal");
4569- return icp->errc = 1;
4570- }
4571-
4572- /* Allocate a file read buffer */
4573- if ((buf = (char *) icp->al->malloc(icp->al, len)) == NULL) {
4574- sprintf(icp->err,"icmUInt64Array_read: malloc() failed");
4575- return icp->errc = 2;
4576- }
4577- bp = buf;
4578-
4579- /* Read portion of file into buffer */
4580- if ( icp->fp->seek(icp->fp, of) != 0
4581- || icp->fp->read(icp->fp, bp, 1, len) != len) {
4582- sprintf(icp->err,"icmUInt64Array_read: fseek() or fread() failed");
4583- icp->al->free(icp->al, buf);
4584- return icp->errc = 1;
4585- }
4586- p->size = size = (len - 8)/8; /* Number of elements in the array */
4587-
4588- if ((rv = p->allocate((icmBase *)p)) != 0) {
4589- icp->al->free(icp->al, buf);
4590- return rv;
4591- }
4592-
4593- /* Read type descriptor from the buffer */
4594- if (((icTagTypeSignature)read_SInt32Number(bp)) != p->ttype) {
4595- sprintf(icp->err,"icmUInt64Array_read: Wrong tag type for icmUInt64Array");
4596- icp->al->free(icp->al, buf);
4597- return icp->errc = 1;
4598- }
4599- bp += 8; /* Skip padding */
4600-
4601- /* Read all the data from the buffer */
4602- for (i = 0; i < size; i++, bp += 8) {
4603- read_UInt64Number(&p->data[i], bp);
4604- }
4605- icp->al->free(icp->al, buf);
4606- return 0;
4607-}
4608-
4609-/* Write the contents of the object. Return 0 on sucess, error code on failure */
4610-static int icmUInt64Array_write(
4611- icmBase *pp,
4612- unsigned int of /* File offset to write from */
4613-) {
4614- icmUInt64Array *p = (icmUInt64Array *)pp;
4615- icc *icp = p->icp;
4616- unsigned int i;
4617- unsigned int len;
4618- char *bp, *buf; /* Buffer to write from */
4619- int rv = 0;
4620-
4621- /* Allocate a file write buffer */
4622- if ((len = p->get_size((icmBase *)p)) == UINT_MAX) {
4623- sprintf(icp->err,"icmUInt64Array_write get_size overflow");
4624- return icp->errc = 1;
4625- }
4626- if ((buf = (char *) icp->al->malloc(icp->al, len)) == NULL) {
4627- sprintf(icp->err,"icmUInt64Array_write malloc() failed");
4628- return icp->errc = 2;
4629- }
4630- bp = buf;
4631-
4632- /* Write type descriptor to the buffer */
4633- if ((rv = write_SInt32Number((int)p->ttype,bp)) != 0) {
4634- sprintf(icp->err,"icmUInt64Array_write: write_SInt32Number() failed");
4635- icp->al->free(icp->al, buf);
4636- return icp->errc = rv;
4637- }
4638- write_SInt32Number(0,bp+4); /* Set padding to 0 */
4639-
4640- /* Write all the data to the buffer */
4641- bp += 8; /* Skip padding */
4642- for (i = 0; i < p->size; i++, bp += 8) {
4643- if ((rv = write_UInt64Number(&p->data[i],bp)) != 0) {
4644- sprintf(icp->err,"icmUInt64Array_write: write_UInt64umber() failed");
4645- icp->al->free(icp->al, buf);
4646- return icp->errc = rv;
4647- }
4648- }
4649-
4650- /* Write to the file */
4651- if ( icp->fp->seek(icp->fp, of) != 0
4652- || icp->fp->write(icp->fp, buf, 1, len) != len) {
4653- sprintf(icp->err,"icmUInt64Array_write fseek() or fwrite() failed");
4654- icp->al->free(icp->al, buf);
4655- return icp->errc = 2;
4656- }
4657- icp->al->free(icp->al, buf);
4658- return 0;
4659-}
4660-
4661-/* Dump a text description of the object */
4662-static void icmUInt64Array_dump(
4663- icmBase *pp,
4664- icmFile *op, /* Output to dump to */
4665- int verb /* Verbosity level */
4666-) {
4667- icmUInt64Array *p = (icmUInt64Array *)pp;
4668- if (verb <= 0)
4669- return;
4670-
4671- op->gprintf(op,"UInt64Array:\n");
4672- op->gprintf(op," No. elements = %lu\n",p->size);
4673- if (verb >= 2) {
4674- unsigned int i;
4675- for (i = 0; i < p->size; i++)
4676- op->gprintf(op," %lu: h=%lu, l=%lu\n",i,p->data[i].h,p->data[i].l);
4677- }
4678-}
4679-
4680-/* Allocate variable sized data elements */
4681-static int icmUInt64Array_allocate(
4682- icmBase *pp
4683-) {
4684- icmUInt64Array *p = (icmUInt64Array *)pp;
4685- icc *icp = p->icp;
4686-
4687- if (p->size != p->_size) {
4688- if (ovr_mul(p->size, sizeof(icmUint64))) {
4689- sprintf(icp->err,"icmUInt64Array_alloc: size overflow");
4690- return icp->errc = 1;
4691- }
4692- if (p->data != NULL)
4693- icp->al->free(icp->al, p->data);
4694- if ((p->data = (icmUint64 *) icp->al->calloc(icp->al, p->size, sizeof(icmUint64)))
4695- == NULL) {
4696- sprintf(icp->err,"icmUInt64Array_alloc: malloc() of icmUInt64Array data failed");
4697- return icp->errc = 2;
4698- }
4699- p->_size = p->size;
4700- }
4701- return 0;
4702-}
4703-
4704-/* Free all storage in the object */
4705-static void icmUInt64Array_delete(
4706- icmBase *pp
4707-) {
4708- icmUInt64Array *p = (icmUInt64Array *)pp;
4709- icc *icp = p->icp;
4710-
4711- if (p->data != NULL)
4712- icp->al->free(icp->al, p->data);
4713- icp->al->free(icp->al, p);
4714-}
4715-
4716-/* Create an empty object. Return null on error */
4717-static icmBase *new_icmUInt64Array(
4718- icc *icp
4719-) {
4720- icmUInt64Array *p;
4721- if ((p = (icmUInt64Array *) icp->al->calloc(icp->al,1,sizeof(icmUInt64Array))) == NULL)
4722- return NULL;
4723- p->ttype = icSigUInt64ArrayType;
4724- p->refcount = 1;
4725- p->get_size = icmUInt64Array_get_size;
4726- p->read = icmUInt64Array_read;
4727- p->write = icmUInt64Array_write;
4728- p->dump = icmUInt64Array_dump;
4729- p->allocate = icmUInt64Array_allocate;
4730- p->del = icmUInt64Array_delete;
4731- p->icp = icp;
4732-
4733- return (icmBase *)p;
4734-}
4735-
4736-/* ---------------------------------------------------------- */
4737-/* icmU16Fixed16Array object */
4738-
4739-/* Return the number of bytes needed to write this tag */
4740-static unsigned int icmU16Fixed16Array_get_size(
4741- icmBase *pp
4742-) {
4743- icmU16Fixed16Array *p = (icmU16Fixed16Array *)pp;
4744- unsigned int len = 0;
4745- len = sat_add(len, 8); /* 8 bytes for tag and padding */
4746- len = sat_addmul(len, p->size, 4); /* 4 byte for each U16Fixed16 */
4747- return len;
4748-}
4749-
4750-/* read the object, return 0 on success, error code on fail */
4751-static int icmU16Fixed16Array_read(
4752- icmBase *pp,
4753- unsigned int len, /* tag length */
4754- unsigned int of /* start offset within file */
4755-) {
4756- icmU16Fixed16Array *p = (icmU16Fixed16Array *)pp;
4757- icc *icp = p->icp;
4758- int rv = 0;
4759- unsigned int i, size;
4760- char *bp, *buf;
4761-
4762- if (len < 8) {
4763- sprintf(icp->err,"icmU16Fixed16Array_read: Tag too small to be legal");
4764- return icp->errc = 1;
4765- }
4766-
4767- /* Allocate a file read buffer */
4768- if ((buf = (char *) icp->al->malloc(icp->al, len)) == NULL) {
4769- sprintf(icp->err,"icmU16Fixed16Array_read: malloc() failed");
4770- return icp->errc = 2;
4771- }
4772- bp = buf;
4773-
4774- /* Read portion of file into buffer */
4775- if ( icp->fp->seek(icp->fp, of) != 0
4776- || icp->fp->read(icp->fp, bp, 1, len) != len) {
4777- sprintf(icp->err,"icmU16Fixed16Array_read: fseek() or fread() failed");
4778- icp->al->free(icp->al, buf);
4779- return icp->errc = 1;
4780- }
4781- p->size = size = (len - 8)/4; /* Number of elements in the array */
4782-
4783- if ((rv = p->allocate((icmBase *)p)) != 0) {
4784- icp->al->free(icp->al, buf);
4785- return rv;
4786- }
4787-
4788- /* Read type descriptor from the buffer */
4789- if (((icTagTypeSignature)read_SInt32Number(bp)) != p->ttype) {
4790- sprintf(icp->err,"icmU16Fixed16Array_read: Wrong tag type for icmU16Fixed16Array");
4791- icp->al->free(icp->al, buf);
4792- return icp->errc = 1;
4793- }
4794- bp += 8; /* Skip padding */
4795-
4796- /* Read all the data from the buffer */
4797- for (i = 0; i < size; i++, bp += 4) {
4798- p->data[i] = read_U16Fixed16Number(bp);
4799- }
4800- icp->al->free(icp->al, buf);
4801- return 0;
4802-}
4803-
4804-/* Write the contents of the object. Return 0 on sucess, error code on failure */
4805-static int icmU16Fixed16Array_write(
4806- icmBase *pp,
4807- unsigned int of /* File offset to write from */
4808-) {
4809- icmU16Fixed16Array *p = (icmU16Fixed16Array *)pp;
4810- icc *icp = p->icp;
4811- unsigned int i;
4812- unsigned int len;
4813- char *bp, *buf; /* Buffer to write from */
4814- int rv = 0;
4815-
4816- /* Allocate a file write buffer */
4817- if ((len = p->get_size((icmBase *)p)) == UINT_MAX) {
4818- sprintf(icp->err,"icmU16Fixed16Array_write get_size overflow");
4819- return icp->errc = 1;
4820- }
4821- if ((buf = (char *) icp->al->malloc(icp->al, len)) == NULL) {
4822- sprintf(icp->err,"icmU16Fixed16Array_write malloc() failed");
4823- return icp->errc = 2;
4824- }
4825- bp = buf;
4826-
4827- /* Write type descriptor to the buffer */
4828- if ((rv = write_SInt32Number((int)p->ttype,bp)) != 0) {
4829- sprintf(icp->err,"icmU16Fixed16Array_write: write_SInt32Number() failed");
4830- icp->al->free(icp->al, buf);
4831- return icp->errc = rv;
4832- }
4833- write_SInt32Number(0,bp+4); /* Set padding to 0 */
4834-
4835- /* Write all the data to the buffer */
4836- bp += 8; /* Skip padding */
4837- for (i = 0; i < p->size; i++, bp += 4) {
4838- if ((rv = write_U16Fixed16Number(p->data[i],bp)) != 0) {
4839- sprintf(icp->err,"icmU16Fixed16Array_write: write_U16Fixed16umber() failed");
4840- icp->al->free(icp->al, buf);
4841- return icp->errc = rv;
4842- }
4843- }
4844-
4845- /* Write to the file */
4846- if ( icp->fp->seek(icp->fp, of) != 0
4847- || icp->fp->write(icp->fp, buf, 1, len) != len) {
4848- sprintf(icp->err,"icmU16Fixed16Array_write fseek() or fwrite() failed");
4849- icp->al->free(icp->al, buf);
4850- return icp->errc = 2;
4851- }
4852- icp->al->free(icp->al, buf);
4853- return 0;
4854-}
4855-
4856-/* Dump a text description of the object */
4857-static void icmU16Fixed16Array_dump(
4858- icmBase *pp,
4859- icmFile *op, /* Output to dump to */
4860- int verb /* Verbosity level */
4861-) {
4862- icmU16Fixed16Array *p = (icmU16Fixed16Array *)pp;
4863- if (verb <= 0)
4864- return;
4865-
4866- op->gprintf(op,"U16Fixed16Array:\n");
4867- op->gprintf(op," No. elements = %lu\n",p->size);
4868- if (verb >= 2) {
4869- unsigned int i;
4870- for (i = 0; i < p->size; i++)
4871- op->gprintf(op," %lu: %f\n",i,p->data[i]);
4872- }
4873-}
4874-
4875-/* Allocate variable sized data elements */
4876-static int icmU16Fixed16Array_allocate(
4877- icmBase *pp
4878-) {
4879- icmU16Fixed16Array *p = (icmU16Fixed16Array *)pp;
4880- icc *icp = p->icp;
4881-
4882- if (p->size != p->_size) {
4883- if (ovr_mul(p->size, sizeof(double))) {
4884- sprintf(icp->err,"icmU16Fixed16Array_alloc: size overflow");
4885- return icp->errc = 1;
4886- }
4887- if (p->data != NULL)
4888- icp->al->free(icp->al, p->data);
4889- if ((p->data = (double *) icp->al->calloc(icp->al, p->size, sizeof(double))) == NULL) {
4890- sprintf(icp->err,"icmU16Fixed16Array_alloc: malloc() of icmU16Fixed16Array data failed");
4891- return icp->errc = 2;
4892- }
4893- p->_size = p->size;
4894- }
4895- return 0;
4896-}
4897-
4898-/* Free all storage in the object */
4899-static void icmU16Fixed16Array_delete(
4900- icmBase *pp
4901-) {
4902- icmU16Fixed16Array *p = (icmU16Fixed16Array *)pp;
4903- icc *icp = p->icp;
4904-
4905- if (p->data != NULL)
4906- icp->al->free(icp->al, p->data);
4907- icp->al->free(icp->al, p);
4908-}
4909-
4910-/* Create an empty object. Return null on error */
4911-static icmBase *new_icmU16Fixed16Array(
4912- icc *icp
4913-) {
4914- icmU16Fixed16Array *p;
4915- if ((p = (icmU16Fixed16Array *) icp->al->calloc(icp->al,1,sizeof(icmU16Fixed16Array))) == NULL)
4916- return NULL;
4917- p->ttype = icSigU16Fixed16ArrayType;
4918- p->refcount = 1;
4919- p->get_size = icmU16Fixed16Array_get_size;
4920- p->read = icmU16Fixed16Array_read;
4921- p->write = icmU16Fixed16Array_write;
4922- p->dump = icmU16Fixed16Array_dump;
4923- p->allocate = icmU16Fixed16Array_allocate;
4924- p->del = icmU16Fixed16Array_delete;
4925- p->icp = icp;
4926-
4927- return (icmBase *)p;
4928-}
4929-
4930-/* ---------------------------------------------------------- */
4931-/* icmS15Fixed16Array object */
4932-
4933-/* Return the number of bytes needed to write this tag */
4934-static unsigned int icmS15Fixed16Array_get_size(
4935- icmBase *pp
4936-) {
4937- icmS15Fixed16Array *p = (icmS15Fixed16Array *)pp;
4938- unsigned int len = 0;
4939- len = sat_add(len, 8); /* 8 bytes for tag and padding */
4940- len = sat_addmul(len, p->size, 4); /* 4 byte for each S15Fixed16 */
4941- return len;
4942-}
4943-
4944-/* read the object, return 0 on success, error code on fail */
4945-static int icmS15Fixed16Array_read(
4946- icmBase *pp,
4947- unsigned int len, /* tag length */
4948- unsigned int of /* start offset within file */
4949-) {
4950- icmS15Fixed16Array *p = (icmS15Fixed16Array *)pp;
4951- icc *icp = p->icp;
4952- int rv = 0;
4953- unsigned int i, size;
4954- char *bp, *buf;
4955-
4956- if (len < 8) {
4957- sprintf(icp->err,"icmS15Fixed16Array_read: Tag too small to be legal");
4958- return icp->errc = 1;
4959- }
4960-
4961- /* Allocate a file read buffer */
4962- if ((buf = (char *) icp->al->malloc(icp->al, len)) == NULL) {
4963- sprintf(icp->err,"icmS15Fixed16Array_read: malloc() failed");
4964- return icp->errc = 2;
4965- }
4966- bp = buf;
4967-
4968- /* Read portion of file into buffer */
4969- if ( icp->fp->seek(icp->fp, of) != 0
4970- || icp->fp->read(icp->fp, bp, 1, len) != len) {
4971- sprintf(icp->err,"icmS15Fixed16Array_read: fseek() or fread() failed");
4972- icp->al->free(icp->al, buf);
4973- return icp->errc = 1;
4974- }
4975- p->size = size = (len - 8)/4; /* Number of elements in the array */
4976-
4977- if ((rv = p->allocate((icmBase *)p)) != 0) {
4978- icp->al->free(icp->al, buf);
4979- return rv;
4980- }
4981-
4982- /* Read type descriptor from the buffer */
4983- if (((icTagTypeSignature)read_SInt32Number(bp)) != p->ttype) {
4984- sprintf(icp->err,"icmS15Fixed16Array_read: Wrong tag type for icmS15Fixed16Array");
4985- icp->al->free(icp->al, buf);
4986- return icp->errc = 1;
4987- }
4988- bp += 8; /* Skip padding */
4989-
4990- /* Read all the data from the buffer */
4991- for (i = 0; i < size; i++, bp += 4) {
4992- p->data[i] = read_S15Fixed16Number(bp);
4993- }
4994- icp->al->free(icp->al, buf);
4995- return 0;
4996-}
4997-
4998-/* Write the contents of the object. Return 0 on sucess, error code on failure */
4999-static int icmS15Fixed16Array_write(
5000- icmBase *pp,
The diff has been truncated for viewing.

Subscribers

People subscribed via source and target branches

to all changes: