Return-Path: <tiff-admin@remotesensing.org>
Received: from cee.skynet.be (cee.skynet.be [195.238.2.101])
        by twentyeight.skynet.be (8.12.9/8.12.9/Skynet-MAILSTORE-2.14) with ESMTP id i0FHxqsI005380
        for <joris.at.lebbeke@skynet.be>; Thu, 15 Jan 2004 19:00:14 +0100
        (envelope-from <tiff-admin@remotesensing.org>)
Received: from yoda.imagelinks.com ([208.24.120.42])
        by cee.skynet.be (8.12.9/8.12.9/Skynet-IN-2.32) with ESMTP id i0FHemLf031936
        for <joris.at.lebbeke@skynet.be>; Thu, 15 Jan 2004 18:40:49 +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 i0FHP4l05918;
	Thu, 15 Jan 2004 12:25:04 -0500
Received: from mailrelay2.megawebservers.com (mailrelay2-6.megawebservers.com [216.251.32.116])
	by yoda.imagelinks.com (8.11.6/8.11.2) with ESMTP id i0FHOPl05896
	for <tiff@remotesensing.org>; Thu, 15 Jan 2004 12:24:25 -0500
Received: from web215.megawebservers.com (web215.megawebservers.com [216.251.42.35])
	by mailrelay2.megawebservers.com (8.12.10/8.12.10) with ESMTP id i0FHO25p015421;
	Thu, 15 Jan 2004 12:24:05 -0500
Received: from web215.megawebservers.com (localhost [127.0.0.1])
	by web215.megawebservers.com (8.12.10/8.12.6/SuSE Linux 0.6) with ESMTP id i0FHO2Vj014278;
	Thu, 15 Jan 2004 12:24:02 -0500
Received: (from webmail.es.inter.net@localhost)
	by web215.megawebservers.com (8.12.10/8.12.6/Submit) id i0FHO1fT014277;
	Thu, 15 Jan 2004 12:24:01 -0500
Message-Id: <200401151724.i0FHO1fT014277@web215.megawebservers.com>
X-Authentication-Warning: web215.megawebservers.com: webmail.es.inter.net set sender to sales@littlecms.com using -f
To: "Andy Cave" <andy.cave@hamillroad.com>,
   "Marti Maria" <sales@littlecms.com>, <tiff@remotesensing.org>
Subject:  Re: [Tiff] COLORMAP and byte padding
From: <sales@littlecms.com>
X-Mailer: TWIG 2.7.5
In-Reply-To: <041701c3dad7$5b859210$0200a8c0@PLATO>
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: Thu, 15 Jan 2004 17:24:01 -0000
X-UIDL: 615b5ff0910789f914cab46a67d217e0



Hi,

> 
> Your code will produce false results. Although I'd divide by 256, I would
> not multiple by 256 (which is where your errors come in). You'd still need
> to multiple by 257 so as to re-map the range back correctly, so a16_by256
> should use the same calculation as a16_by257.

Ok, I have replaced the multiplication by 

a16_by256 = ((unsigned short) (a8_by256 << 8) | a8_by256 );

And the results are still:

Max error:  by 256 = 255, by 257 = 128
Mean error: by 256 = 85.3333, by 257 = 64.249

I was proposing the macro: 

#define RGB_16_TO_8(rgb) (BYTE) ((((rgb)*65281+8388608)>>24)&0xFF)

Because this *does* produce same results as floor(rgb / 257.0 + 0.5)

Max error:  by macro = 128, by double = 128
Mean error: by macro = 64.249, by double = 64.249

Check it by yourself :-)

Regards,
Marti.


#include <stdio.h>
#include <stdlib.h>
#include <math.h>

#define RGB_16_TO_8(rgb) (unsigned char) ((((rgb)*65281+8388608)>>24)&0xFF)
#define RGB_8_TO_16(rgb) (unsigned short)((((unsigned short)(rgb))<<8)|rgb)) 

 int main()
 {
    int i;
    unsigned char byMacro_8, byDouble_8;
    unsigned short byMacro_16, byDouble_16;
    int errorMacro, errorDouble;
    int maxMacro = 0, maxDouble = 0;
    double sumMacro=0., sumDouble=0.;

    for (i=0; i < 0xFFFF; i++) {

       byMacro_8 = (unsigned char) RGB_16_TO_8(i); 
       byDouble_8 = (unsigned char) (double) floor(i/257.+.5);

       byMacro_16 = (unsigned short) RGB_8_TO_16(byMacro_8);
       byDouble_16 = (unsigned short) (double) floor(byDouble_8*257.0+0.5);

       errorMacro = abs(byMacro_16 - i);
       errorDouble = abs(byDouble_16 - i);

       if (errorMacro > maxMacro) maxMacro = errorMacro;
       if (errorDouble > maxDouble) maxDouble = errorDouble;

       sumMacro += errorMacro;
       sumDouble += errorDouble;
    }

    printf("Max error:  by macro = %d, by double = %d\n", maxMacro, 
maxDouble);
    printf("Mean error: by macro = %g, by double = %g\n", sumMacro / 65535., 
sumDouble / 65535.);

    return 0;
 }

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