Path: blob/master/3rdparty/openexr/IlmImf/ImfConvert.h
16337 views
///////////////////////////////////////////////////////////////////////////1//2// Copyright (c) 2002, Industrial Light & Magic, a division of Lucas3// Digital Ltd. LLC4//5// All rights reserved.6//7// Redistribution and use in source and binary forms, with or without8// modification, are permitted provided that the following conditions are9// met:10// * Redistributions of source code must retain the above copyright11// notice, this list of conditions and the following disclaimer.12// * Redistributions in binary form must reproduce the above13// copyright notice, this list of conditions and the following disclaimer14// in the documentation and/or other materials provided with the15// distribution.16// * Neither the name of Industrial Light & Magic nor the names of17// its contributors may be used to endorse or promote products derived18// from this software without specific prior written permission.19//20// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS21// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT22// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR23// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT24// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,25// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT26// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,27// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY28// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT29// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE30// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.31//32///////////////////////////////////////////////////////////////////////////333435#ifndef INCLUDED_IMF_CONVERT_H36#define INCLUDED_IMF_CONVERT_H3738//-----------------------------------------------------------------------------39//40// Routines for converting between pixel data types,41// with well-defined behavior for exceptional cases,42// without depending on how hardware and operating43// system handle integer overflows and floating-point44// exceptions.45//46//-----------------------------------------------------------------------------4748#include "half.h"495051namespace Imf {5253//---------------------------------------------------------54// Conversion from half or float to unsigned int:55//56// input result57// ---------------------------------------------------58//59// finite, >= 0 input, cast to unsigned int60// (rounds towards zero)61//62// finite, < 0 063//64// NaN 065//66// +infinity UINT_MAX67//68// -infinity 069//70//---------------------------------------------------------7172unsigned int halfToUint (half h);73unsigned int floatToUint (float f);747576//---------------------------------------------------------77// Conversion from unsigned int or float to half:78//79// input result80// ---------------------------------------------------81//82// finite, closest possible half83// magnitude <= HALF_MAX84//85// finite, > HALF_MAX +infinity86//87// finite, < -HALF_MAX -infinity88//89// NaN NaN90//91// +infinity +infinity92//93// -infinity -infinity94//95//---------------------------------------------------------9697half uintToHalf (unsigned int ui);98half floatToHalf (float f);99100101} // namespace Imf102103#endif104105106