// $Id: LUTutil.cpp,v 1.8 2008/02/19 21:03:03 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

#include "LUTutil.h"

void gamma_ramp::convertPrivShort2ramp_type()
{
    for (int i=0; i < size; i++)
    {  // normalize values to be 0 .. 1.0
        red[i] = (ramp_type) ramp_buffer[i]  / 65535.0;
        green[i] = (ramp_type) ramp_buffer[i+size] / 65535.0;
        blue[i] = (ramp_type) ramp_buffer[i+size*2] / 65535.0;
    }
}

void gamma_ramp::convert_ramp_type2short()
{
    for (int i=0; i < size; i++)
    {
        ramp_buffer[i] = ramp_type_private ((red[i]) * 65535.0);
        ramp_buffer[i+size] = ramp_type_private ((green[i]) * 65535.0);
        ramp_buffer[i+size*2] = ramp_type_private ((blue[i]) * 65535.0);
    }
}

void gamma_ramp::setLinearGammaRamp()
{

    gamma_ramp* temp;

    temp = new gamma_ramp(this -> screen, this -> left, this -> top);

    for (int i=0; i< temp -> size; i++)
    {
        temp -> red[i] = temp -> green[i] = temp -> blue[i] = i * (1.0/temp -> size);
    }
    temp -> setGammaRamp();

    delete temp;
}
