Return-Path: <awaresystems.be+caf_=filtered=awaresystems.be@gmail.com>
Delivered-To: filtered@awaresystems.be
Received: from mx-r.one.com (mx-r.one.com [91.198.169.249])
	by mail6.local (Postfix) with ESMTP id 7F321801104C4
	for <filtered@awaresystems.be>; Fri, 15 Feb 2013 15:12:53 +0100 (CET)
X-Virus-Scanned: by one.com
X-Amavis-Alert: BAD HEADER SECTION, Duplicate header field: "MIME-Version"
Received-SPF: pass (mx-r: domain of awaresystems.be+caf_=filtered=awaresystems.be@gmail.com designates 209.85.217.169 as permitted sender)
X-Greylist: whitelisted by SQLgrey-1.8.0-rc2
Received: from mail-lb0-f169.google.com (mail-lb0-f169.google.com [209.85.217.169])
	by mx-r.one.com (Postfix) with ESMTP id 44FA110FB6BE
	for <filtered@awaresystems.be>; Fri, 15 Feb 2013 14:12:53 +0000 (UTC)
Received: by mail-lb0-f169.google.com with SMTP id m4so2670181lbo.14
        for <filtered@awaresystems.be>; Fri, 15 Feb 2013 06:12:52 -0800 (PST)
X-Received: by 10.152.123.34 with SMTP id lx2mr2312760lab.52.1360937572797;
        Fri, 15 Feb 2013 06:12:52 -0800 (PST)
X-Forwarded-To: filtered@awaresystems.be
X-Forwarded-For: awaresystems.be@gmail.com filtered@awaresystems.be
Delivered-To: awaresystems.be@gmail.com
Received: by 10.114.70.11 with SMTP id i11csp114005ldu;
        Fri, 15 Feb 2013 06:12:52 -0800 (PST)
X-Received: by 10.112.84.130 with SMTP id z2mr2174590lby.65.1360937571277;
        Fri, 15 Feb 2013 06:12:51 -0800 (PST)
Received-SPF: neutral (google.com: 91.198.169.57 is neither permitted nor denied by best guess record for domain of tiff-bounces@lists.maptools.org) client-ip=91.198.169.57;
Received: by 10.152.97.180 with POP3 id eb20mf733635lab.39;
        Fri, 15 Feb 2013 06:12:50 -0800 (PST)
X-Gmail-Fetch-Info: info@awaresystems.be 1 pop.awaresystems.be 110 info@awaresystems.be
Delivered-To: info@awaresystems.be
Received: from mx-j.one.com (mx-j.one.com [91.198.169.57])
	by mail6.local (Postfix) with ESMTP id F05E3801104CF
	for <info@awaresystems.be>; Fri, 15 Feb 2013 15:12:14 +0100 (CET)
X-Amavis-Alert: BAD HEADER SECTION, Duplicate header field: "MIME-Version"
X-Greylist: domain auto-whitelisted by SQLgrey-1.8.0-rc2
Received: from lists.maptools.org (ks365428.kimsufi.com [94.23.4.142])
	by mx-j.one.com (Postfix) with ESMTP id B37D42522D2
	for <info@awaresystems.be>; Fri, 15 Feb 2013 14:12:14 +0000 (UTC)
Received: from [10.1.0.241] (localhost.localdomain [127.0.0.1])
	by lists.maptools.org (Postfix) with ESMTP id A48F035C041;
	Fri, 15 Feb 2013 09:10:32 -0500 (EST)
Received: from blu0-omc4-s3.blu0.hotmail.com (blu0-omc4-s3.blu0.hotmail.com
	[65.55.111.142])
	by lists.maptools.org (Postfix) with ESMTP id A351435C023
	for <tiff@lists.maptools.org>; Fri, 15 Feb 2013 09:09:24 -0500 (EST)
Received: from BLU165-W29 ([65.55.111.135]) by blu0-omc4-s3.blu0.hotmail.com
	with Microsoft SMTPSVC(6.0.3790.4675); 
	Fri, 15 Feb 2013 06:09:23 -0800
X-EIP: [ZXKnZLKqtCzZ0pusGsSkVSvzFHJ4i9ha]
X-Originating-Email: [bumble731@msn.com]
Message-ID: <BLU165-W293D39FBC1B2A5357621BFE10E0@phx.gbl>
From: Charles Auer <bumble731@msn.com>
To: <richard.nolde@centurylink.net>, "tiff@lists.maptools.org"
	<tiff@lists.maptools.org>
Date: Fri, 15 Feb 2013 14:09:22 +0000
Importance: Normal
In-Reply-To: <511D3A69.5030608@centurylink.net>
References: <511D2149.20503@centurylink.net>,<511D3A69.5030608@centurylink.net>
MIME-Version: 1.0
X-OriginalArrivalTime: 15 Feb 2013 14:09:23.0219 (UTC)
	FILETIME=[0E34D630:01CE0B86]
Subject: Re: [Tiff] TIFF support for 16 bit floats
X-BeenThere: tiff@lists.maptools.org
X-Mailman-Version: 2.1.9
Precedence: list
List-Id: TIFF and libtiff discussion <tiff.lists.maptools.org>
List-Unsubscribe: <http://lists.maptools.org/mailman/listinfo/tiff>,
	<mailto:tiff-request@lists.maptools.org?subject=unsubscribe>
List-Archive: <http://lists.maptools.org/mailman/private/tiff>
List-Post: <mailto:tiff@lists.maptools.org>
List-Help: <mailto:tiff-request@lists.maptools.org?subject=help>
List-Subscribe: <http://lists.maptools.org/mailman/listinfo/tiff>,
	<mailto:tiff-request@lists.maptools.org?subject=subscribe>
Content-Type: multipart/mixed; boundary="===============0952459416=="
Mime-version: 1.0
Sender: tiff-bounces@lists.maptools.org
Errors-To: tiff-bounces@lists.maptools.org

--===============0952459416==
Content-Type: multipart/alternative;
	boundary="_3b2761ca-12b5-4e80-92b1-3b41c1ad9489_"

--_3b2761ca-12b5-4e80-92b1-3b41c1ad9489_
Content-Type: text/plain; charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable


//////////////////////////////////////////////////////
//
// CONVERT HALF FLOAT (16 BIT FLOAT) TO FLOAT
//
////////////////////////////////////////////////////// // -15 stored using =
a single precision bias of 127
const unsigned int  HALF_FLOAT_MIN_BIASED_EXP_AS_SINGLE_FP_EXP =3D 0x380000=
00=3B // max exponent value in single precision that will be converted
// to Inf or Nan when stored as a half-float
const unsigned int  HALF_FLOAT_MAX_BIASED_EXP_AS_SINGLE_FP_EXP =3D 0x478000=
00=3B // 255 is the max exponent biased value
const unsigned int  FLOAT_MAX_BIASED_EXP =3D (0xFF << 23)=3B const unsigned=
 int  HALF_FLOAT_MAX_BIASED_EXP =3D (0x1F << 10)=3B typedef unsigned short =
   hfloat=3B
float convertHFloatToFloat(hfloat hf)
{
    unsigned int    sign =3D (unsigned int)(hf >> 15)=3B
    unsigned int    mantissa =3D (unsigned int)(hf & ((1 << 10) - 1))=3B
    unsigned int    exp =3D (unsigned int)(hf & HALF_FLOAT_MAX_BIASED_EXP)=
=3B
    unsigned int    f=3B  if (exp =3D=3D HALF_FLOAT_MAX_BIASED_EXP)
    {
        // we have a half-float NaN or Inf
        // half-float NaNs will be converted to a single precision NaN
        // half-float Infs will be converted to a single precision Inf
        exp =3D FLOAT_MAX_BIASED_EXP=3B
        if (mantissa)
            mantissa =3D (1 << 23) - 1=3B    // set all bits to indicate a =
NaN
    }
    else if (exp =3D=3D 0x0)
    {
        // convert half-float zero/denorm to single precision value
        if (mantissa)
        {
           mantissa <<=3D 1=3B
           exp =3D HALF_FLOAT_MIN_BIASED_EXP_AS_SINGLE_FP_EXP=3B
           // check for leading 1 in denorm mantissa
           while ((mantissa & (1 << 10)) =3D=3D 0)
           {
               // for every leading 0=2C decrement single precision exponen=
t by 1
               // and shift half-float mantissa value to the left
               mantissa <<=3D 1=3B
               exp -=3D (1 << 23)=3B
            }
            // clamp the mantissa to 10-bits
            mantissa &=3D ((1 << 10) - 1)=3B
            // shift left to generate single-precision mantissa of 23-bits
            mantissa <<=3D 13=3B
        }
    }
    else
    {
        // shift left to generate single-precision mantissa of 23-bits
        mantissa <<=3D 13=3B
        // generate single precision biased exponent value
        exp =3D (exp << 13) + HALF_FLOAT_MIN_BIASED_EXP_AS_SINGLE_FP_EXP=3B
    }     f =3D (sign << 31) | exp | mantissa=3B
    return *((float *)&f)=3B
} 		 	   		  =

--_3b2761ca-12b5-4e80-92b1-3b41c1ad9489_
Content-Type: text/html; charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

<html>
<head>
<style><!--
.hmmessage P
{
margin:0px=3B
padding:0px
}
body.hmmessage
{
font-size: 10pt=3B
font-family:Tahoma
}
--></style></head>
<body class=3D'hmmessage'><div dir=3D'ltr'>
//////////////////////////////////////////////////////<br>//<br>// CONVERT =
HALF FLOAT (16 BIT FLOAT) TO FLOAT<br>//<br>///////////////////////////////=
///////////////////////<BR>&nbsp=3B<BR>// -15 stored using a single precisi=
on bias of 127<br>const unsigned int&nbsp=3B HALF_FLOAT_MIN_BIASED_EXP_AS_S=
INGLE_FP_EXP =3D 0x38000000=3B<BR>&nbsp=3B<BR>// max exponent value in sing=
le precision that will be converted<br>// to Inf or Nan when stored as a ha=
lf-float<br>const unsigned int&nbsp=3B HALF_FLOAT_MAX_BIASED_EXP_AS_SINGLE_=
FP_EXP =3D 0x47800000=3B<BR>&nbsp=3B<BR>// 255 is the max exponent biased v=
alue<br>const unsigned int&nbsp=3B FLOAT_MAX_BIASED_EXP =3D (0xFF &lt=3B&lt=
=3B 23)=3B<BR>&nbsp=3B<BR>const unsigned int&nbsp=3B HALF_FLOAT_MAX_BIASED_=
EXP =3D (0x1F &lt=3B&lt=3B 10)=3B<BR>&nbsp=3B<BR>typedef unsigned short&nbs=
p=3B&nbsp=3B&nbsp=3B hfloat=3B<BR><br>float convertHFloatToFloat(hfloat hf)=
<br>{<br>&nbsp=3B&nbsp=3B&nbsp=3B unsigned int&nbsp=3B&nbsp=3B&nbsp=3B sign=
 =3D (unsigned int)(hf &gt=3B&gt=3B 15)=3B<br>&nbsp=3B&nbsp=3B&nbsp=3B unsi=
gned int&nbsp=3B&nbsp=3B&nbsp=3B mantissa =3D (unsigned int)(hf &amp=3B ((1=
 &lt=3B&lt=3B 10) - 1))=3B<br>&nbsp=3B&nbsp=3B&nbsp=3B unsigned int&nbsp=3B=
&nbsp=3B&nbsp=3B exp =3D (unsigned int)(hf &amp=3B HALF_FLOAT_MAX_BIASED_EX=
P)=3B<br>&nbsp=3B&nbsp=3B&nbsp=3B unsigned int&nbsp=3B&nbsp=3B&nbsp=3B f=3B=
<BR>&nbsp=3B<BR>&nbsp=3Bif (exp =3D=3D HALF_FLOAT_MAX_BIASED_EXP)<br>&nbsp=
=3B&nbsp=3B&nbsp=3B {<br>&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B&n=
bsp=3B // we have a half-float NaN or Inf<br>&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=
=3B&nbsp=3B&nbsp=3B&nbsp=3B // half-float NaNs will be converted to a singl=
e precision NaN<br>&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B=
 // half-float Infs will be converted to a single precision Inf<br>&nbsp=3B=
&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B exp =3D FLOAT_MAX_BIASED_E=
XP=3B<br>&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B if (manti=
ssa)<br>&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B&nb=
sp=3B&nbsp=3B&nbsp=3B mantissa =3D (1 &lt=3B&lt=3B 23) - 1=3B&nbsp=3B&nbsp=
=3B&nbsp=3B // set all bits to indicate a NaN<br>&nbsp=3B&nbsp=3B&nbsp=3B }=
<br>&nbsp=3B&nbsp=3B&nbsp=3B else if (exp =3D=3D 0x0)<br>&nbsp=3B&nbsp=3B&n=
bsp=3B {<br>&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B // con=
vert half-float zero/denorm to single precision value<br>&nbsp=3B&nbsp=3B&n=
bsp=3B&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B if (mantissa)<br>&nbsp=3B&nbsp=3B&nb=
sp=3B&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B {<br>&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B=
&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B mantissa &lt=3B&lt=3B=3D 1=
=3B<br>&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B&nbs=
p=3B&nbsp=3B exp =3D HALF_FLOAT_MIN_BIASED_EXP_AS_SINGLE_FP_EXP=3B<br>&nbsp=
=3B&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B=
 // check for leading 1 in denorm mantissa<br>&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=
=3B&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B while ((mantissa &amp=
=3B (1 &lt=3B&lt=3B 10)) =3D=3D 0)<br>&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=
=3B&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B {<br>&nbsp=3B&nbsp=3B&nbsp=3B&n=
bsp=3B&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=
=3B&nbsp=3B // for every leading 0=2C decrement single precision exponent b=
y 1<br>&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B&nbs=
p=3B&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B // and shift half-float mantis=
sa value to the left<br>&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B&nb=
sp=3B&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B mantissa &lt=
=3B&lt=3B=3D 1=3B<br>&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=
=3B&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B exp -=3D (1 &lt=
=3B&lt=3B 23)=3B<br>&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=
=3B&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B }<br>&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B&n=
bsp=3B&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B // clamp the mantiss=
a to 10-bits<br>&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B&nb=
sp=3B&nbsp=3B&nbsp=3B&nbsp=3B mantissa &amp=3B=3D ((1 &lt=3B&lt=3B 10) - 1)=
=3B<br>&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B&nbs=
p=3B&nbsp=3B&nbsp=3B // shift left to generate single-precision mantissa of=
 23-bits<br>&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=
=3B&nbsp=3B&nbsp=3B&nbsp=3B mantissa &lt=3B&lt=3B=3D 13=3B<br>&nbsp=3B&nbsp=
=3B&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B }<br>&nbsp=3B&nbsp=3B&nbsp=3B }=
<br>&nbsp=3B&nbsp=3B&nbsp=3B else<br>&nbsp=3B&nbsp=3B&nbsp=3B {<br>&nbsp=3B=
&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B // shift left to generate =
single-precision mantissa of 23-bits<br>&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B&nb=
sp=3B&nbsp=3B&nbsp=3B mantissa &lt=3B&lt=3B=3D 13=3B<br>&nbsp=3B&nbsp=3B&nb=
sp=3B&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B // generate single precision biased e=
xponent value<br>&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B&nbsp=3B e=
xp =3D (exp &lt=3B&lt=3B 13) + HALF_FLOAT_MIN_BIASED_EXP_AS_SINGLE_FP_EXP=
=3B<br>&nbsp=3B&nbsp=3B&nbsp=3B }<BR>&nbsp=3B<BR>&nbsp=3B&nbsp=3B&nbsp=3B f=
 =3D (sign &lt=3B&lt=3B 31) | exp | mantissa=3B<br>&nbsp=3B&nbsp=3B&nbsp=3B=
 return *((float *)&amp=3Bf)=3B<br>}<BR> 		 	   		  </div></body>
</html>=

--_3b2761ca-12b5-4e80-92b1-3b41c1ad9489_--

--===============0952459416==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

_______________________________________________
Tiff mailing list: Tiff@lists.maptools.org
http://lists.maptools.org/mailman/listinfo/tiff
http://www.remotesensing.org/libtiff/
--===============0952459416==--
