Return-Path: <tiff-admin@remotesensing.org>
Received: from inmx009.isp.belgacom.be (inmx009.isp.belgacom.be [195.238.3.146])
        by mailst006.isp.belgacom.be (8.12.9/8.12.9/Skynet-MAILSTORE-2.14) with ESMTP id i4LJYYpx032649
        for <joris.at.lebbeke@skynet.be>; Fri, 21 May 2004 21:34:34 +0200
        (envelope-from <tiff-admin@remotesensing.org>)
Received: from yoda.imagelinks.com ([208.24.120.44])
        by inmx009.isp.belgacom.be (8.12.9/8.12.9/Skynet-IN-2.32) with ESMTP id i4LJYQfC025658
        for <joris.at.lebbeke@skynet.be>; Fri, 21 May 2004 21:34:27 +0200
        (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.6) with ESMTP id i4LJXZn01980;
	Fri, 21 May 2004 15:33:35 -0400
Received: from smtp-relay-8.adobe.com (smtp-relay-8.adobe.com [192.150.22.8])
	by yoda.imagelinks.com (8.11.6/8.11.6) with ESMTP id i4LJWtn01901
	for <tiff@remotesensing.org>; Fri, 21 May 2004 15:32:55 -0400
Received: from inner-relay-3.corp.adobe.com (inner-relay-3 [153.32.251.51])
	by smtp-relay-8.adobe.com (8.12.10/8.12.10) with ESMTP id i4LJVs6P011144;
	Fri, 21 May 2004 12:31:59 -0700 (PDT)
Received: from mailsj-dev (mailsj-dev.corp.adobe.com [153.32.1.192])
	by inner-relay-3.corp.adobe.com (8.12.9/8.12.9) with ESMTP id i4LJTjm0025537;
	Fri, 21 May 2004 12:31:48 -0700 (PDT)
Received: from [153.32.48.223] (noname.corp.adobe.com [153.32.48.223])
 by mailsj-v1.corp.adobe.com
 (iPlanet Messaging Server 5.2 HotFix 1.21 (built Sep  8 2003))
 with ESMTP id <0HY20035DWWBXA@mailsj-v1.corp.adobe.com>; Fri,
 21 May 2004 12:31:24 -0700 (PDT)
From: Chris Cox <ccox@adobe.com>
In-reply-to: <1085122777.40ada8d9963d1@203.197.175.3>
X-Sender: ccox@mailsj.corp.adobe.com
To: mayankg@iiitb.ac.in
Cc: tiff@remotesensing.org
Message-id: <p05210601bcd4078e3a18@[153.32.48.223]>
MIME-version: 1.0
Content-type: text/plain; charset=us-ascii; format=flowed
Content-transfer-encoding: 7BIT
References: <1085032117.40ac46b52bc83@203.197.175.3>
 <p05210603bcd2f24c3e1a@[153.32.48.223]>
 <1085122777.40ada8d9963d1@203.197.175.3>
Subject: [Tiff] Re: Un-premultiplying the color data
Sender: tiff-admin@remotesensing.org
Errors-To: tiff-admin@remotesensing.org
X-BeenThere: tiff@remotesensing.org
X-Mailman-Version: 2.0.13
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: Fri, 21 May 2004 12:30:44 -0700
X-UIDL: 329899804291fb47c6af96c4f2f2a611

At 12:05 PM +0000 5/21/04, mayankg@iiitb.ac.in wrote:
>Hi chris,
>Here is what I am trying in my code to un-premultiply the color data in the
>image attached with this message:
>
>source: is the buffer returned by the libtiff functions.
>dest: is the destination buffer
>the image is: contig, strip, CMYK, 8-bits per channel, with one associated
>alpha channel
>since i have to gather the color values in my dest buffer in the order KCMY,
>that is why i take dest[0] = source[3] and so on.
>
>alpha = source[4];
>if(alpha != 0)
>{
>dest[0] = ( (source[3]*255) + alpha/2 )/alpha;
>dest[1] = ( (source[0]*255) + alpha/2 )/alpha;
>dest[2] = ( (source[1]*255) + alpha/2 )/alpha;
>dest[3] = ( (source[2]*255) + alpha/2 )/alpha;
>}

It would run faster is you used a lookup table for the divide and 
multiply by 255.
Divides are slow on all modern CPUs, and even a 64k lookup table is 
faster -- unless you've got someone who can write really good SSE or 
AltiVec code.
Also, using a lookup table would avoid divides by zero, and you can 
special case top == 0 (which should return zero) and bottom <= top 
(which should return 255) without any branches.

Also, CMYK is white matted - what you're doing is black matting and 
only suitable for RGB data.

To white matte:
	out_matted = 255 - (alpha * in + 127) / 255;
To un-white matte:
	out = 255 - ( (255* (255 - in_matted) + (alpha/2)) / alpha );


>There are two questions here:
>1. How do you know come to know about the color information, if alpha had been
>zero?

You don't.  If the area is fully transparent, there is no color information.



>2. Is the procedure above correct?

Nope.

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