File indexing completed on 2024-04-21 04:20:22

0001 /********************************************************************
0002  KolorServer - color server based on the X Color Management Specification
0003  This file is part of the KDE project.
0004 
0005 Copyright (C) 2012 Casian Andrei <skeletk13@gmail.com>
0006 
0007 Redistribution and use in source and binary forms, with or without
0008 modification, are permitted provided that the following conditions
0009 are met:
0010 
0011 1. Redistributions of source code must retain the above copyright
0012    notice, this list of conditions and the following disclaimer.
0013 2. Redistributions in binary form must reproduce the above copyright
0014    notice, this list of conditions and the following disclaimer in the
0015    documentation and/or other materials provided with the distribution.
0016 
0017 THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
0018 IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
0019 OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
0020 IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
0021 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
0022 NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
0023 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
0024 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
0025 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
0026 THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
0027 *********************************************************************/
0028 
0029 #ifndef KOLOR_SERVER_CONTEXT_H_
0030 #define KOLOR_SERVER_CONTEXT_H_
0031 
0032 #include "color-lookup-table.h"
0033 
0034 #include <QString>
0035 
0036 struct oyConfig_s;
0037 struct oyProfile_s;
0038 
0039 namespace KolorServer
0040 {
0041 
0042 /**
0043  *  Used to create and use a color conversion.
0044  * \li lookup texture data
0045  * \li the source ICC profile for reference
0046  * \li the target profile for the used monitor.
0047  *
0048  * \note PrivColorContext
0049  */
0050 class ColorContext
0051 {
0052 public:
0053     ColorContext();
0054     virtual ~ColorContext();
0055 
0056     /**
0057      * \return Source profile for this context
0058      */
0059     oyProfile_s *sourceProfile();
0060 
0061     /**
0062      * \return Destination profile for this context
0063      */
0064     oyProfile_s *destinationProfile();
0065 
0066     /**
0067      * Set a custom destination profile for this color context.
0068      * Any existing destination profile will be discarded.
0069      */
0070     void setDestinationProfile(oyProfile_s *profile);
0071 
0072     /**
0073      * \return Name of the intended output device
0074      */
0075     const QString& outputName();
0076 
0077     /**
0078      * \return The color lookup table for this context
0079      */
0080     const Clut& colorLookupTable() const;
0081 
0082     /**
0083      * Setup for an output with the given name.
0084      * - put cc.src_profile as sRGB (web)
0085      * - copy output name into cc
0086      * - call setupColourTable
0087      */
0088     void setup(const QString &name);
0089 
0090     /**
0091      * Fetches the device profile for the given device.
0092      * Check out if the profile is sRGB (web thing), return error if so.
0093      *
0094      * \return True if successful
0095      */
0096     bool getDeviceProfile(oyConfig_s *device);
0097 
0098 private:
0099     /**
0100      * \note setupColourTable
0101      * - prepare src_profile, dst_profile if necessary
0102      * - create oyImage_s for src_profile, dst_profile
0103      * - create oyConversion_s
0104      * - search for clut in cache, if not present do conversion
0105      * - probably the clut is properly set up after all this
0106      *
0107      * Used by: setupOutputTable
0108      *
0109      * \param advanced got from getDisplayAdvanced
0110      */
0111     void setupColorLookupTable(bool advanced);
0112 
0113 private:
0114     oyProfile_s *m_srcProfile;          ///< the data profile or device link
0115     oyProfile_s *m_dstProfile;          ///< the monitor profile or none
0116     QString m_outputName;               ///< the intended output device
0117     int icc_profile_flags;              ///< profile selection flags from oyProfile_s.h
0118 
0119     /// Color lookup table (for color conversion)
0120     Clut m_clut;
0121 };
0122 
0123 } // KolorServer namespace
0124 
0125 #endif // KOLOR_SERVER_CONTEXT_H_