// EyeOne API wrapper // // Adapted for C# by Reprogroup // Maybe some Copyrights belong to X-Rite Inc. /* These are definitions of the EyeOne SKD 3.4.3 from x-rite. */ using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Runtime.InteropServices; using System.IO; namespace EyeOneWrapper { //++++++++++++++++++++++ BEGIN -- MeasurementConditions ++++++++++++++++ //------------------------------------------------------------------------ // definitions for string-constants used in MeasurementConditions //------------------------------------------------------------------------ //public const string UNDEFINED = "Undefined"; public enum I1_DeviceMessage { eDeviceButtonPressed, // button pressed on device eDeviceDisconnected // device disconnected #if I1_ADDITIONAL_MESSAGES , I1_ADDITIONAL_MESSAGES // extend messages #endif }; public enum I1_Status { eNoError, // no error eDeviceNotReady, // device not ready eDeviceNotConnected, // device not connected eDeviceNotCalibrated, // device not calibrated eKeyNotPressed, // if no key has been pressed eNoSubstrateWhite, // no substrate white reference set eWrongMeasureMode, // wrong measurement mode eStripRecognitionFailed, // if the measurement mode is set to scanning and recognition is enabled eNoDataAvailable, // measurement not triggered, index out of range (scanning) eException, // internal exception, use I1_GetOption(I1_LAST_ERROR) for more details eInvalidArgument, // if a passed method argument is invalid (i.e. NULL) eUnknownError, // unknown error occurred eWrongDeviceType // operation not supported by this device type #if I1_ADDITIONAL_ERRORS , I1_ADDITIONAL_ERRORS // extend error types #endif }; public struct Colorimetric { // # Illumination public const string ILLUMINATION_KEY = "Colorimetric.Illumination"; public const string ILLUMINATION_A = "A"; public const string ILLUMINATION_B = "B"; public const string ILLUMINATION_C = "C"; public const string ILLUMINATION_D50 = "D50"; public const string ILLUMINATION_D55 = "D55"; public const string ILLUMINATION_D65 = "D65"; public const string ILLUMINATION_D75 = "D75"; public const string ILLUMINATION_F2 = "F2"; public const string ILLUMINATION_F7 = "F7"; public const string ILLUMINATION_F11 = "F11"; public const string ILLUMINATION_EMISSION = "Emission"; // # Observer public const string OBSERVER_KEY = "Colorimetric.Observer"; public const string OBSERVER_TWO_DEGREE = "TwoDegree"; public const string OBSERVER_TEN_DEGREE = "TenDegree"; // # WhiteBase public const string WHITE_BASE_KEY = "Colorimetric.WhiteBase"; public const string WHITE_BASE_ABSOLUTE = "Absolute"; public const string WHITE_BASE_PAPER = "Paper"; public const string WHITE_BASE_AUTOMATIC = "Automatic"; // # DensityStandard public const string DENSITY_STANDARD_KEY = "Colorimetric.DensityStandard"; public const string DENSITY_STANDARD_DIN = "DIN"; public const string DENSITY_STANDARD_DINNB = "DINNB"; public const string DENSITY_STANDARD_ANSIA = "ANSIA"; public const string DENSITY_STANDARD_ANSIE = "ANSIE"; public const string DENSITY_STANDARD_ANSII = "ANSII"; public const string DENSITY_STANDARD_ANSIT = "ANSIT"; public const string DENSITY_STANDARD_SPI = "SPI"; // # DensityFilterMode public const string DENSITY_FILTER_MODE_KEY = "Colorimetric.DensityFilterMode"; public const string DENSITY_FILTER_MODE_BLACK = "Black"; public const string DENSITY_FILTER_MODE_CYAN = "Cyan"; public const string DENSITY_FILTER_MODE_MAGENTA = "Magenta"; public const string DENSITY_FILTER_MODE_YELLOW = "Yellow"; public const string DENSITY_FILTER_MODE_MAX = "Max"; public const string DENSITY_FILTER_MODE_AUTO = "Auto"; } public struct ColorSpace { public const string COLOR_SPACE_KEY = "ColorSpaceDescription.Type"; public const string COLOR_SPACE_CIELab = "CIELab"; public const string COLOR_SPACE_CIELCh = "CIELCh"; public const string COLOR_SPACE_CIELuv = "CIELuv"; public const string COLOR_SPACE_CIELChuv = "CIELChuv"; public const string COLOR_SPACE_CIE_UV_Y1960 = "CIEuvY1960"; public const string COLOR_SPACE_CIE_UV_Y1976 = "CIEuvY1976"; public const string COLOR_SPACE_CIEXYZ = "CIEXYZ"; public const string COLOR_SPACE_CIExyY = "CIExyY"; public const string COLOR_SPACE_HunterLab = "HunterLab"; public const string COLOR_SPACE_RXRYRZ = "RxRyRz"; public const string COLOR_SPACE_LAB_MG = "LABmg"; public const string COLOR_SPACE_LCH_MG = "LCHmg"; public const string COLOR_SPACE_RGB = "RGB"; } public struct Measurement { // # Maximum / minimum wavelength public const string WAVE_LENGTH_730 = "730nm"; public const string WAVE_LENGTH_380 = "380nm"; public const int SPECTRUM_SIZE = 36; public const int TRISTIMULUS_SIZE = 3; public const int DENSITY_SIZE = 4; } //#++++++++++++++++++++++ END -- MeasurementConditions ++++++++++++++++++ //#++++++++++++++++++++++++ BEGIN -- EyeOne +++++++++++++++++++++++++++++ public struct I1 { // # definitions for specific EyeOne key/values used with I1_GetOption() // # general key/values public const string I1_LAST_ERROR = "LastError"; public const string I1_EXTENDED_ERROR_INFORMATION = "ExtendedErrorInformation"; public const string I1_YES = "yes"; public const string I1_NO = "no"; // # EyeOne key/values public const string I1_VERSION = "Version"; public const string I1_MAJOR_VERSION = "MajorVersion"; public const string I1_MINOR_VERSION = "MinorVersion"; public const string I1_REVISION_VERSION = "RevisionVersion"; public const string I1_BUILD_VERSION = "BuildVersion"; public const string I1_SERIAL_NUMBER = "SerialNumber"; public const string I1_IS_CONNECTED = "Connection"; public const string I1_IS_KEY_PRESSED = "IsKeyPressed"; public const string I1_IS_RECOGNITION_ENABLED = "Recognition"; public const string I1_LAST_CALIBRATION_TIME = "LastCalibrationTime"; public const string I1_CALIBRATION_COUNT = "LastCalibrationCounter"; public const string I1_NUMBER_OF_AVAILABLE_SAMPLES = "AvailableSamples"; public const string I1_AVAILABLE_MEASUREMENT_MODES = "AvailableMeasurementModes"; public const string I1_IS_BEEP_ENABLED = "Beep"; public const string I1_LAST_AUTO_DENSITY_FILTER = "LastAutoDensityFilter"; public const string I1_IS_ADAPTIVE_MODE_ENABLED = "AdaptiveMode"; public const string I1_IS_NETPROFILER_ENABLED = "NetProfiler"; public const string I1_INTEGRATION_TIME = "IntegrationTime"; public const string I1_PHYSICAL_FILTER = "PhysicalFilter"; // # read only public const string I1_UNDEFINED_FILTER = "0"; public const string I1_NO_FILTER = "1"; public const string I1_UV_FILTER = "2"; public const string I1_SCREEN_TYPE = "ScreenType"; // # mandatory for i1-display public const string I1_LCD_SCREEN = "LCD"; public const string I1_CRT_SCREEN = "CRT"; public const string I1_PATCH_INTENSITY = "PatchIntensity";// # used with i1-display public const string I1_BLEAK = "Bleak"; public const string I1_BRIGHT = "Bright"; public const string I1_AUTO = "Auto"; public const string I1_DEVICE_TYPE = "DeviceType"; public const string I1_EYEONE = "EyeOne"; //# this is the default device public const string I1_EYEONE_1 = "EyeOne1"; // # this is the first alternative device found on the USB bus public const string I1_EYEONE_2 = "EyeOne2"; // # ... # all other definitions must be created on demand public const string I1_EYEONE_127 = "EyeOne127"; // # this is the last device on the bus public const string I1_DISPLAY = "EyeOneDisplay"; public const string I1_DEVICE_SUBTYPE = "DeviceSubType"; public const string I1_REGULAR = "Regular"; public const string I1_LT = "Lt"; public const string I1_MEASUREMENT_MODE = "MeasurementMode"; public const string I1_SINGLE_EMISSION = "SingleEmission"; public const string I1_SINGLE_REFLECTANCE = "SingleReflectance"; public const string I1_SINGLE_AMBIENT_LIGHT = "SingleAmbientLight"; public const string I1_SCANNING_REFLECTANCE = "ScanningReflectance"; public const string I1_SCANNING_AMBIENT_LIGHT = "ScanningAmbientLight"; public const string I1_RESET = "Reset"; // # reset command parameters: I1_ALL, DeviceTypes, MeasurementModes public const string I1_ALL = "All"; } //#++++++++++++++++++++++ END -- EyeOne +++++++++++++++++++++++++++++++++ public delegate void OnDeviceMessageDelegate(I1_DeviceMessage axMessage, string axSerialNumber); public delegate void OnErrorDelegate(string axContext, I1_Status axCode, string axText); public enum I1_MeasurementMode { SingleEmission, SingleReflectance, SingleAmbientLight, ScanningReflectance, ScanningAmbientLight }; public enum I1_ColorSpace { CIELab, CIELCh, CIELuv, CIELChuv, CIEuvY1960, CIEuvY1976, CIEXYZ, CIExyY, HunterLab, RxRyRz, LABmg, LCHmg, RGB }; public enum I1_Illumination { A, B, C, D50, D55, D65, D75, F2, F7, F11, Emission }; public enum I1_Observer { TwoDegree, TenDegree }; public enum I1_WhiteBase { Absolute, Paper, Automatic }; public enum I1_DensityStandard { DIN, DINNB, ANSIA, ANSIE, ANSII, ANSIT, SPI }; public enum I1_DensityFilter { Black, Cyan, Magenta, Yellow, Max, Auto }; public enum I1_DeviceSubType { Regular, Lt }; public enum I1_ScreenType { LCD, CRT }; /// /// Eye-One SDK for Windows. C# wrapper /// class EyeOne { public event OnDeviceMessageDelegate OnMessage; public event OnErrorDelegate OnError; private bool i1_IsCalibrated; private OnDeviceMessageDelegate pointerMessageHandler; private OnErrorDelegate pointerErrorHandler; private int pxAutoDensity; public EyeOne() { this.i1_IsCalibrated = false; if (File.Exists(Library)) { if (I1_IsConnected() == (int)I1_Status.eNoError) { this.pointerMessageHandler = new OnDeviceMessageDelegate(onMessage); I1_RegisterDeviceMessageHandler(this.pointerMessageHandler); this.pointerErrorHandler = new OnErrorDelegate(onError); I1_RegisterErrorHandler(this.pointerErrorHandler); } } else throw new Exception("Unable load DLL «" + Library + "»"); } /*-------------------------------- Properties -------------------------------*/ /// /// The automatic adaptation of the integration time is on/off /// public bool AdaptiveMode { set { I1_SetOption(new StringBuilder(I1.I1_IS_ADAPTIVE_MODE_ENABLED), new StringBuilder(value ? "1" : "0")); } get { return Marshal.PtrToStringAnsi(I1_GetOption(I1.I1_IS_ADAPTIVE_MODE_ENABLED)) == "1"; } } /// /// Number of currently available samples. /// public string AvailableSamples { get { return Marshal.PtrToStringAnsi(I1_GetOption(I1.I1_NUMBER_OF_AVAILABLE_SAMPLES)); } } /// /// Indicates which filter was dominant for the specified density reading (0-3 = CMYK) /// public int AutoDensity { get { return pxAutoDensity; } } /// /// Set the beep is on/off /// public bool Beep { set { I1_SetOption(new StringBuilder(I1.I1_IS_BEEP_ENABLED), new StringBuilder(value ? I1.I1_YES : I1.I1_NO)); } get { return Marshal.PtrToStringAnsi(I1_GetOption(I1.I1_IS_BEEP_ENABLED)) == I1.I1_YES; } } /// /// Returns the build version of this SDK release /// public string BuildVersion { get { return Marshal.PtrToStringAnsi(I1_GetOption(I1.I1_BUILD_VERSION)); } } /// /// Number of measurements since last calibration /// public string CalibrationCount { get { return Marshal.PtrToStringAnsi(I1_GetOption(I1.I1_CALIBRATION_COUNT)); } } /// /// Available color spaces /// public I1_ColorSpace ColorSpace { set { I1_SetOption(new StringBuilder(EyeOneWrapper.ColorSpace.COLOR_SPACE_KEY), new StringBuilder(value.ToString())); } get { string colorspace = Marshal.PtrToStringAnsi(I1_GetOption(EyeOneWrapper.ColorSpace.COLOR_SPACE_KEY)); return (I1_ColorSpace)Enum.Parse(typeof(I1_ColorSpace), colorspace); } } /// /// Returns the connection status /// public bool Connection { get { return Marshal.PtrToStringAnsi(I1_GetOption(I1.I1_IS_CONNECTED)) == I1.I1_YES; } } /// /// Needed for density calculations /// public I1_DensityStandard DensityStandard { set { I1_SetOption(new StringBuilder(Colorimetric.DENSITY_STANDARD_KEY), new StringBuilder(value.ToString())); } get { string density = Marshal.PtrToStringAnsi(I1_GetOption(Colorimetric.DENSITY_STANDARD_KEY)); return (I1_DensityStandard)Enum.Parse(typeof(I1_DensityStandard), density); } } /// /// Available filter modes /// public I1_DensityFilter DensityFilter { set { I1_SetOption(new StringBuilder(Colorimetric.DENSITY_FILTER_MODE_KEY), new StringBuilder(value.ToString())); } get { string filter = Marshal.PtrToStringAnsi(I1_GetOption(Colorimetric.DENSITY_FILTER_MODE_KEY)); return (I1_DensityFilter)Enum.Parse(typeof(I1_DensityFilter), filter); } } /// /// The SDK will identify the connected device type at startup time. /// If both device types are connected, the Eye-One Pro will be chosen. /// Use SetOption to switch between the two devices manually. /// public string DeviceType { set { I1_SetOption(new StringBuilder(I1.I1_DEVICE_TYPE), new StringBuilder(value)); } get { return Marshal.PtrToStringAnsi(I1_GetOption(I1.I1_DEVICE_TYPE)); } } /// /// Only used for Eye-One Display V2. /// This option has no effect on the Eye-One Pro. /// public I1_DeviceSubType DeviceSubType { set { I1_SetOption(new StringBuilder(I1.I1_DEVICE_SUBTYPE), new StringBuilder(value.ToString())); } get { string subtype = Marshal.PtrToStringAnsi(I1_GetOption(I1.I1_DEVICE_SUBTYPE)); return (I1_DeviceSubType)Enum.Parse(typeof(I1_DeviceSubType), subtype); } } /// /// Returns extended error information. /// public string ExtendedErrorInformation { get { return Marshal.PtrToStringAnsi(I1_GetOption(I1.I1_EXTENDED_ERROR_INFORMATION)); } } /// /// Used when converting a spectrum to a color space i.e. CIELab /// public I1_Illumination Illumination { set { I1_SetOption(new StringBuilder(Colorimetric.ILLUMINATION_KEY), new StringBuilder(value.ToString())); } get { string illumination = Marshal.PtrToStringAnsi(I1_GetOption(Colorimetric.ILLUMINATION_KEY)); return (I1_Illumination)Enum.Parse(typeof(I1_Illumination), illumination); } } /// /// Integration time in seconds for Eye-One Pro. /// A float number as string: 12 ms is "0.012" /// public string IntegrationTime { set { I1_SetOption(new StringBuilder(I1.I1_INTEGRATION_TIME), new StringBuilder(value.ToString())); } get { return Marshal.PtrToStringAnsi(I1_GetOption(I1.I1_INTEGRATION_TIME)); } } /// /// Tests the connection status /// public bool IsConnected { get { return I1_IsConnected() == (int)I1_Status.eNoError; } } /// /// Returns the calibration status /// public bool IsCalibrated { get { return i1_IsCalibrated; } } /// /// Tests if the key has been pressed /// public bool IsKeyPressed { get { return Marshal.PtrToStringAnsi(I1_GetOption(I1.I1_IS_KEY_PRESSED)) == I1.I1_YES; } } /// /// Time since last calibration (in seconds) /// public string LastCalibrationTime { get { return Marshal.PtrToStringAnsi(I1_GetOption(I1.I1_LAST_CALIBRATION_TIME)); } } /// /// Returns a descriptive error message /// public string LastError { get { return Marshal.PtrToStringAnsi(I1_GetOption(I1.I1_LAST_ERROR)); } } /// /// Returns the filter name in case of a density calculation with DENSITY_FILTER_MODE_AUTO /// public string LastAutoDensityFilter { get { return Marshal.PtrToStringAnsi(I1_GetOption(I1.I1_LAST_AUTO_DENSITY_FILTER)); } } /// /// Returns the major version of this SDK release /// public string MajorVersion { get { return Marshal.PtrToStringAnsi(I1_GetOption(I1.I1_MAJOR_VERSION)); } } /// /// Returns the minor version of this SDK release /// public string MinorVersion { get { return Marshal.PtrToStringAnsi(I1_GetOption(I1.I1_MINOR_VERSION)); } } /// /// Available measurement modes /// public I1_MeasurementMode MeasurementMode { set { I1_SetOption(new StringBuilder(I1.I1_MEASUREMENT_MODE), new StringBuilder(value.ToString())); } get { string mode = Marshal.PtrToStringAnsi(I1_GetOption(I1.I1_MEASUREMENT_MODE)); return (I1_MeasurementMode)Enum.Parse(typeof(I1_MeasurementMode), mode); } } /// /// Lists all available measure modes. /// The values are separated by a semi-colon «;» /// public string MeasurementModes { get { return Marshal.PtrToStringAnsi(I1_GetOption(I1.I1_AVAILABLE_MEASUREMENT_MODES)); } } /// /// Used when converting a spectrum to a color space i.e. CIELab /// public I1_Observer Observer { set { I1_SetOption(new StringBuilder(Colorimetric.OBSERVER_KEY), new StringBuilder(value.ToString())); } get { string observer = Marshal.PtrToStringAnsi(I1_GetOption(Colorimetric.OBSERVER_KEY)); return (I1_Observer)Enum.Parse(typeof(I1_Observer), observer); } } /// /// Specifies the intensity level of a measurement patch. /// By default, the SDK figures out the intensity level by it self (I1_AUTO). /// This option has no effect on the Eye-One Pro /// public string PatchIntensity { get { return Marshal.PtrToStringAnsi(I1_GetOption(I1.I1_PATCH_INTENSITY)); } } /// /// Returns: /// "0": undefined filter /// "1": no filter /// "2": UV-Cut /// public string PhysicalFilter { get { return Marshal.PtrToStringAnsi(I1_GetOption(I1.I1_PHYSICAL_FILTER)); } } /// /// Sets strip recognition is on/off /// public bool Recognition { set { I1_SetOption(new StringBuilder(I1.I1_IS_RECOGNITION_ENABLED), new StringBuilder(value ? I1.I1_YES : I1.I1_NO)); } get { return Marshal.PtrToStringAnsi(I1_GetOption(I1.I1_IS_RECOGNITION_ENABLED)) == I1.I1_YES; } } /// /// Returns the revision version of this SDK release /// public string RevisionVersion { get { return Marshal.PtrToStringAnsi(I1_GetOption(I1.I1_REVISION_VERSION)); } } /// /// Specify the display type if the measurement device is an Eye-One Display. /// This option has no effect on the Eye-One Pro /// public I1_ScreenType ScreenType { set { I1_SetOption(new StringBuilder(I1.I1_SCREEN_TYPE), new StringBuilder(value.ToString())); } get { string subtype = Marshal.PtrToStringAnsi(I1_GetOption(I1.I1_SCREEN_TYPE)); return (I1_ScreenType)Enum.Parse(typeof(I1_ScreenType), subtype); } } /// /// Returns the serial number of the hardware device /// public string SerialNumber { get { return Marshal.PtrToStringAnsi(I1_GetOption(I1.I1_SERIAL_NUMBER)); } } /// /// Returns the version number of this SDK release /// public string Version { get { return Marshal.PtrToStringAnsi(I1_GetOption(I1.I1_VERSION)); } } /// /// Needed for density calculations /// public I1_WhiteBase WhiteBase { set { I1_SetOption(new StringBuilder(Colorimetric.WHITE_BASE_KEY), new StringBuilder(value.ToString())); } get { string whitebase = Marshal.PtrToStringAnsi(I1_GetOption(Colorimetric.WHITE_BASE_KEY)); return (I1_WhiteBase)Enum.Parse(typeof(I1_WhiteBase), whitebase); } } /*---------------------------------- Events ---------------------------------*/ /// /// Registers a message handler callback function. In case of a device event, this handler is invoked in /// its own thread. Events will be queued. Only Eye-One Pro, Eye-One Monitor and Eye-One UVCut /// support events, Eye-One Display doesn’t. /// /// The message, which is the type of the message, i.e. eDeviceButtonPressed. /// The serial number of the Eye-One device. public void onMessage(I1_DeviceMessage axMessage, string axSerialNumber) { if (OnMessage != null) OnMessage(axMessage, axSerialNumber); } /// /// Registers an error handler callback function. In case of an error, this handler is invoked before /// returning from a call to the Eye-One-SDK. /// /// The context, which is the name of the invoked SDK method, i.e. I1_TriggerMeasurement(). /// The error code, which is normally returned by the SDK-call. /// The error text which normally would be retrieved by GetOption(I1_LAST_ERROR). public void onError(string axContext, I1_Status axCode, string axText) { if (OnError != null) OnError(axContext, axCode, axText); } /*--------------------------------- Methods ---------------------------------*/ // Returns information about the current state of the Eye-One hardware device and its measurement conditions. public string GetOption(string option) { return Marshal.PtrToStringAnsi(I1_GetOption(option)); } // Used to set the desired device type, measurement mode and physical measurement conditions. // It’s important to note that you must set the screen type (TFT, CRT) in case of using the Eye-One Display! public bool SetOption(string option, string value) { return I1_SetOption(new StringBuilder(option), new StringBuilder(value)) == (int)I1_Status.eNoError; } /// /// Reset modes. I1_ALL will reset the whole SDK. /// This is equivalent to unload/load the sdk. /// Afterwards the SDK is back into initial state. /// public void Reset() { I1_SetOption(new StringBuilder(I1.I1_RESET), new StringBuilder(I1.I1_ALL)); } /// /// Reset modes with param /// /// /// "All": /// Resets the whole SDK. /// "EyeOne", "EyeOne1", "EyeOne2", ..., "EyeOne127": /// Resets the EyeOne(Pro and Monitor) part back to initial state. /// The value for alternative devices contains an additional underscore with a number. /// (see below for further details) /// "EyeOneDisplay": /// Resets the EyeOne-Display part back to initial state /// "SingleEmission", "SingleReflectance", "SingleAmbientLight", "ScanningReflectance", "ScanningAmbientLight": /// Resets the corresponding measure mode /// public void Reset(string value) { I1_SetOption(new StringBuilder(I1.I1_RESET), new StringBuilder(value)); } /// /// Calibrates the Eye-One hardware device. Before any calibration is done, you should select your /// desired measurement mode via I1_SetOption(). A calibration is only applied to the current /// measurement mode. The first time you switch to a new measurement mode you have to calibrate /// it. Once calibrated there is not need for recalibration again for that specific measurement mode. /// Keep in mind that a calibration is not sustainable for too long due to temperature changes and /// other factors. /// public bool Calibrate() { return this.i1_IsCalibrated = I1_Calibrate() == (int)I1_Status.eNoError; } /// /// Triggers a measurement depending on the current measurement mode. Before a measurement /// can be triggered the device must be calibrated in the desired measurement mode. /// /// On success: true public bool Trigger() { return I1_TriggerMeasurement() == (int)I1_Status.eNoError; } /// /// Returns the number of available samples for the current measurement mode. /// /// /// 0 if no measurement has been triggered yet. 1 if the measurement mode is set to /// either I1_SINGLE_REFLECTANCE or I1_SINGLE_EMISSION or I1_SINGLE_AMBIENT_LIGHT and /// a measurement was done. For I1_SCANNING_REFLECTANCE or /// I1_SCANNING_AMBIENT_LIGHT the number of scanned samples is returned. /// On failure: -1 /// public int Samples() { return I1_GetNumberOfAvailableSamples(); } /// /// Get the tri-stimulus of a previous triggered measurement. /// /// /// zero-based index of the tristimulus. If the measurement mode is set to /// I1_SCANNING_REFLECTANCE any value between 0 and I1_GetNumberOfAvailableSamples() – 1 is valid. /// For spot measurement results use 0 (zero) /// /// the tristimulus at the desired index of the measurement results public float[] GetTriStimulus(int index) { float[] data = new float[Measurement.TRISTIMULUS_SIZE]; I1_GetTriStimulus(data, index); return data; } /// /// Get all possible densities (CMYK) of a previous triggered measurement. /// /// /// zero-based index of the density. If the measurement mode is set to /// I1_SCANNING_REFLECTANCE any value between 0 and I1_GetNumberOfAvailableSamples() – 1 is valid. /// For spot measurement results use 0 (zero) /// /// the densities at the desired index of the measurement results public float[] GetDensities(int index) { float[] data = new float[Measurement.DENSITY_SIZE]; I1_GetDensities(data, ref pxAutoDensity, index); return data; } /// /// Get the density of a previous triggered measurement. If DENSITY_FILTER_MODE_KEY has been /// set to DENSITY_FILTER_MODE_AUTO you can use /// I1_GetOption(I1_LAST_AUTO_DENSITY_FILTER) to retrieve the actual density filter name. /// /// /// zero-based index of the density. If the measurement mode is set to /// I1_SCANNING_REFLECTANCE any value between 0 and I1_GetNumberOfAvailableSamples() – 1 is valid. /// For spot measurement results use 0 (zero) /// /// the density at the desired index of the measurement results public float GetDensity(int index) { float data = 0f; I1_GetDensity(data, index); return data; } /// /// Get the spectrum of a previous triggered measurement. /// /// /// zero-based index of the spectrum. If the measurement mode is set to /// I1_SCANNING_REFLECTANCE any value between 0 and I1_GetNumberOfAvailableSamples() – 1 is valid. /// For spot measurement results use 0 (zero) /// /// the spectrum at the desired index of the measurement results public float[] GetSpectrum(int index) { float[] data = new float[Measurement.SPECTRUM_SIZE]; I1_GetSpectrum(data, index); return data; } /// /// Sets the substrate reference spectrum that is needed for density calculations. This method has to /// be called before the first call to I1_GetDensity() if you want paper based density. /// /// the spectrum of the substrate /// On success: true public bool SetSubstrate(float[] substrateSpectrum) { return I1_SetSubstrate(substrateSpectrum) == (int)I1_Status.eNoError; } /*--------------------- prototypes of exported functions --------------------*/ /* General remarks: The FPtr_I1_XXX typedefs (i.e. FPtr_I1_Calibrate) are declared to simplify the process of getting a reference to the desired method(s) while dynamic loading this library */ public const string Library = "EyeOne.dll"; /*------------------------------ error handling -----------------------------*/ /* void MyErrorHandlerFunction(const char *axContext, I1_ErrorType axCode, const char *axText); */ [DllImport(Library, CharSet = CharSet.Auto, CallingConvention = CallingConvention.Cdecl)] public static extern IntPtr I1_RegisterErrorHandler(OnErrorDelegate callback); /* void MyDeviceMessageFunction(const I1_DeviceMessage axMessage, const char *axText); */ [DllImport(Library, CharSet = CharSet.Auto, CallingConvention = CallingConvention.Cdecl)] public static extern IntPtr I1_RegisterDeviceMessageHandler(OnDeviceMessageDelegate callback); /*-------------------- Information about driver and API ---------------------*/ /* Test if the Eye-One is connected return eNoError if connected return eDeviceNotConnected if no Eye-One is present */ [DllImport(Library, CharSet = CharSet.Auto, CallingConvention = CallingConvention.Cdecl)] public static extern int I1_IsConnected(); /* Test if the button has been pressed return eNoError if button was pressed return eKeyNotPressed if button was not pressed */ [DllImport(Library, CharSet = CharSet.Auto, CallingConvention = CallingConvention.Cdecl)] public static extern int I1_KeyPressed(); /* returns amount of currently available samples */ [DllImport(Library, CharSet = CharSet.Auto, CallingConvention = CallingConvention.Cdecl)] public static extern int I1_GetNumberOfAvailableSamples(); /*------------------- trigger measurements / calibrations -------------------*/ /* Calibrate the Eye-One */ [DllImport(Library, CharSet = CharSet.Auto, CallingConvention = CallingConvention.Cdecl)] public static extern int I1_Calibrate(); /* Trigger measurement Triggers a meausrement depending on the measurement mode set by I1_SetOption If the measurement mode is set to I1_SINGLE_EMISSION or I1_SCANNING_REFLECTANCE it is necessary to calibrate the Eye-One before any measurement can be triggered use GetSpectrum(index), I1_GetTriStimulus(index) or I1_GetDensity(index) to fetch the result returns eDeviceNotConnected if no device is available returns eDeviceNotCalibrated if a (re)calibration is necessary */ [DllImport(Library, CharSet = CharSet.Auto, CallingConvention = CallingConvention.Cdecl)] public static extern int I1_TriggerMeasurement(); /*------------------------------- get samples -------------------------------*/ /*General remarks: Use 0 as Index, to fetch the result of a previously triggered single measurement To fetch a result of a previously triggered scan, specify an index between 0 - (I1_GetNumberOfScannedSamples() - 1) If no measurement has been triggered or if the specified index is out of range eNoDataAvailable is returned */ /* Get the spectrum of a previous triggered measurement Range: 380 ... 730 nm in 10nm steps */ [DllImport(Library, CharSet = CharSet.Auto, CallingConvention = CallingConvention.Cdecl)] public static extern int I1_GetSpectrum([In][MarshalAs(UnmanagedType.LPArray, SizeConst = Measurement.SPECTRUM_SIZE)]float[] data, long index); /* Get the color vector of a previous triggered measurement */ [DllImport(Library, CharSet = CharSet.Auto, CallingConvention = CallingConvention.Cdecl)] public static extern int I1_GetTriStimulus([In][MarshalAs(UnmanagedType.LPArray, SizeConst = Measurement.TRISTIMULUS_SIZE)]float[] data, long index); /* Get the all densities (cyan, magenta, yellow, black) of a previous triggered measurement if pxAutoDensity is not null, *pxAutoDensity will be set accordingly NOTE: pxAutoDensity indicates which filter was dominant for the specified density reading (0-3 = CMYK) */ [DllImport(Library, CharSet = CharSet.Auto, CallingConvention = CallingConvention.Cdecl)] public static extern int I1_GetDensities([In][MarshalAs(UnmanagedType.LPArray, SizeConst = Measurement.DENSITY_SIZE)]float[] data, ref int pxAutoDensity, long index); [DllImport(Library, CharSet = CharSet.Auto, CallingConvention = CallingConvention.Cdecl)] public static extern int I1_GetDensity([In][MarshalAs(UnmanagedType.LPArray, SizeConst = Measurement.DENSITY_SIZE)]float data, long index); /*--------------------- special functions for Density -----------------------*/ /* Set the substrate spectrum for density calculations This method has to be called before the first call to GetDensity() */ [DllImport(Library, CharSet = CharSet.Auto, CallingConvention = CallingConvention.Cdecl)] public static extern int I1_SetSubstrate([Out][MarshalAs(UnmanagedType.LPArray, SizeConst = Measurement.SPECTRUM_SIZE)]float[] data); /*------------------ setting measurement mode & conditions ------------------*/ /* possible options (see MeasurementConditions.h for possible values) COLOR_SPACE_KEY ILLUMINATION_KEY OBSERVER_KEY DENSITY_STANDARD_KEY DENSITY_FILTER_MODE_KEY I1_MEASUREMENT_MODE, possible values : I1_SINGLE_EMISSION, I1_SINGLE_REFLECTANCE, I1_SCANNING_REFLECTANCE default: I1_SCANNING_REFLECTANCE I1_IS_RECOGNITION_ENABLED, possible values : I1_YES, I1_NO, default : I1_NO */ [DllImport(Library, CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)] public static extern int I1_SetOption(StringBuilder option, StringBuilder value); [DllImport(Library, CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)] public static extern IntPtr I1_GetOption(string option); } }