// $Id: LUTutil.h,v 1.14 2007/10/09 19:01:38 hvengel Exp $
//  Little cms Profiler
// Copyright (C) 2007 Hal Engel
//
// THIS SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND,
// EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY
// WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
//
// IN NO EVENT SHALL THE DEVELOPERS BE LIABLE FOR ANY SPECIAL, INCIDENTAL,
// INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND,
// OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
// WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF
// LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
// OF THIS SOFTWARE.
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// 
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
// 
// You should have received a copy of the GNU General Public License
// along with this program.  If not, see <http://www.gnu.org/licenses/>.
//
// Version 1.11

#ifndef LUTUTIL_H
#define LUTUTIL_H

#if !defined(__WIN32__) && (defined(_WIN32) || defined(WIN32))
#define __WIN32__
#endif

typedef double ramp_type;

#ifdef __WIN32__
   #include <windows.h>
   typedef unsigned short ramp_type_private;
   typedef HDC displayHandle;
#elif defined (__APPLE__)
   #ifndef DEBUG
      #define DEBUG 0
   #endif
   #include <Carbon/Carbon.h>
   #include <CoreServices/CoreServices.h>
   #include <IOKit/Graphics/IOGraphicsLib.h>
   typedef CGGammaValue ramp_type_private;
   typedef CGDirectDisplayID displayHandle;
#elif defined (UNIX)
   typedef unsigned short ramp_type_private;
   typedef int displayHandle;
#else
   // This means this is being built on a system that is not currently supported.
   // This does not mean that this code will not work on the unsupported system.
   // Rather that the developers don't know what will work and have not
   // coded anything for your system.
   //
   // Users running into this error message are asked to provide bug reports
   // and, even better, patches.
   //
   // There is a related section of code in src/moncalqt/monitorcal.cpp that
   // will likely also need to be updated if this code is changed.
   // Please see the
   // #else
   // ....
   // #error
   // section in function void MonitorCal::Go() of src/moncalqt/monitorcal.cpp
   //
   // In addition if the video card gamma table data type on your
   // platform is not one of those above. you will also likely need to add
   // a new src/videoLUTutils/LUTutil<your platform>.cpp file
   // that contains the implementation code for this functionality on your
   // platform.  build_config.py will also need to be updated to build the
   // added platform specific code
   //
   #error "no typedef for ramp_type_private and displayHandle are available for your platform"
#endif

class gamma_ramp
{
    public:
       int size;
       ramp_type *red, *green, *blue;
      
       gamma_ramp(int screen, int leftIn, int topIn);  // screen is ignored on OS/X and Windows
                                                       // leftIn and topIn are ignored on X11

       ~gamma_ramp();
       void getGammaRamp();  // returns size
       void setGammaRamp();

       void setLinearGammaRamp();

    private:
       int getGammaRampSize();
       void convertPrivShort2ramp_type();
       void convert_ramp_type2short();

       ramp_type_private* ramp_buffer;
       int screen, left, top;
       displayHandle display;
};

#endif
