Return-Path: <tiff-admin@remotesensing.org>
Received: from dee.skynet.be (dee.skynet.be [195.238.2.100])
        by twentyeight.skynet.be (8.12.9/8.12.9/Skynet-MAILSTORE-2.14) with ESMTP id i0EIPVku024841
        for <joris.at.lebbeke@skynet.be>; Wed, 14 Jan 2004 19:25:31 +0100
        (envelope-from <tiff-admin@remotesensing.org>)
Received: from yoda.imagelinks.com ([208.24.120.42])
        by dee.skynet.be (8.12.9/8.12.9/Skynet-IN-2.32) with ESMTP id i0EINftO018614
        for <joris.at.lebbeke@skynet.be>; Wed, 14 Jan 2004 19:23:43 +0100
        (envelope-from <tiff-admin@remotesensing.org>)
Received: from yoda.imagelinks.com (localhost.localdomain [127.0.0.1])
	by yoda.imagelinks.com (8.11.6/8.11.2) with ESMTP id i0EIJ9l21553;
	Wed, 14 Jan 2004 13:19:09 -0500
Received: from mail120.megamailservers.com (mail120.megamailservers.com [216.251.41.140])
	by yoda.imagelinks.com (8.11.6/8.11.2) with ESMTP id i0EII2l21083
	for <tiff@remotesensing.org>; Wed, 14 Jan 2004 13:18:02 -0500
X-POP-User: info.littlecms.com
Received: from mm2000 (5.Red-213-97-41.pooles.rima-tde.net [213.97.41.5])
	by mail120.megamailservers.com (8.12.10/8.12.9) with SMTP id i0EIHxgt019779
	for <tiff@remotesensing.org>; Wed, 14 Jan 2004 13:18:00 -0500 (EST)
Message-ID: <000c01c3daca$d64ac860$02001aac@mm2000>
From: "Marti Maria" <sales@littlecms.com>
To: <tiff@remotesensing.org>
References: <20040114170004.27948.11478.Mailman@yoda.imagelinks.com>
Subject: Re: [Tiff] COLORMAP and byte padding
Organization: LittleCMS
MIME-Version: 1.0
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: 7bit
X-Priority: 3
X-MSMail-Priority: Normal
X-Mailer: Microsoft Outlook Express 6.00.2800.1158
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
Sender: tiff-admin@remotesensing.org
Errors-To: tiff-admin@remotesensing.org
X-BeenThere: tiff@remotesensing.org
X-Mailman-Version: 2.0.11
Precedence: bulk
List-Help: <mailto:tiff-request@remotesensing.org?subject=help>
List-Post: <mailto:tiff@remotesensing.org>
List-Subscribe: <http://remotesensing.org/mailman/listinfo/tiff>,
	<mailto:tiff-request@remotesensing.org?subject=subscribe>
List-Id: TIFF and libtiff discussion <tiff.remotesensing.org>
List-Unsubscribe: <http://remotesensing.org/mailman/listinfo/tiff>,
	<mailto:tiff-request@remotesensing.org?subject=unsubscribe>
List-Archive: <http://remotesensing.org/pipermail/tiff/>
Date: Wed, 14 Jan 2004 19:18:38 +0100
X-UIDL: 0f3dac3459a31fd5e4e6230bb6594ac0
Status: U

Hi,

>For the perfectionists who are wondering: multiplying by 257 works perfectly. In
> effect, it makes the least significant byte a copy of the most significant byte 
> of the 16-bit value. In C:
>
>uint16val = ((uint8val << 8) | uint8val);
>
>Note that when reducing the 16-bit value to 8-bit, you could divide by 257 
> and round, but it's way faster to simply take the upper byte (the same as 
> an integer division by 256, truncating everything after the decimal point). 
> Don't divide by 256 and round, because you will end up 1 too high in 
> 50% of the cases. In C:
>
>uint8val = (uint16val >> 8);
>

Yep, that is fast, but unfortunately can give significant errors, since that is same than 
dividing by 256.

Here are a couple of macros that does the trick. 

#define RGB_8_TO_16(rgb) (WORD) ((((WORD) (rgb)) << 8)|(rgb))
#define RGB_16_TO_8(rgb) (BYTE) ((((rgb) * 65281 + 8388608) >> 24) & 0xFF)


Regards,
Marti Maria
The little cms project
http://www.littlecms.com
marti@littlecms.com

_______________________________________________
Tiff mailing list
Tiff@remotesensing.org
http://remotesensing.org/mailman/listinfo/tiff
