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.b-one.net (Postfix) with ESMTP id 1D01C801671FE
	for <filtered@awaresystems.be>; Mon, 16 Jul 2012 18:10:24 +0200 (CEST)
X-Virus-Scanned: by one.com
Received-SPF: pass (mx-r: domain of awaresystems.be+caf_=filtered=awaresystems.be@gmail.com designates 209.85.212.48 as permitted sender)
X-Greylist: whitelisted by SQLgrey-1.8.0-rc2
Received: from mail-vb0-f48.google.com (mail-vb0-f48.google.com [209.85.212.48])
	by mx-r.one.com (Postfix) with ESMTP id AF3002642458
	for <filtered@awaresystems.be>; Mon, 16 Jul 2012 16:10:23 +0000 (UTC)
Received: by vbjk17 with SMTP id k17so5118634vbj.21
        for <filtered@awaresystems.be>; Mon, 16 Jul 2012 09:10:22 -0700 (PDT)
Received: by 10.220.107.198 with SMTP id c6mr5597084vcp.54.1342455022746;
        Mon, 16 Jul 2012 09:10:22 -0700 (PDT)
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.58.208.231 with SMTP id mh7csp273166vec;
        Mon, 16 Jul 2012 09:10:22 -0700 (PDT)
Received: by 10.52.27.72 with SMTP id r8mr4798397vdg.14.1342455021983;
        Mon, 16 Jul 2012 09:10:21 -0700 (PDT)
Received-SPF: softfail (google.com: best guess record for domain of transitioning tiff-bounces@lists.maptools.org does not designate 91.198.169.249 as permitted sender) client-ip=91.198.169.249;
Received: by 10.220.204.81 with POP3 id fl17mf3918922vcb.26;
        Mon, 16 Jul 2012 09:10:21 -0700 (PDT)
X-Gmail-Fetch-Info: info@awaresystems.be 1 pop.awaresystems.be 110 info@awaresystems.be
Delivered-To: info@awaresystems.be
Received: from mx-r.one.com (mx-r.one.com [91.198.169.249])
	by mail6.b-one.net (Postfix) with ESMTP id B0EB1801671FE
	for <info@awaresystems.be>; Mon, 16 Jul 2012 18:07:06 +0200 (CEST)
X-Greylist: domain auto-whitelisted by SQLgrey-1.8.0-rc2
Received: from lists.maptools.org (lists.maptools.org [65.39.174.144])
	by mx-r.one.com (Postfix) with ESMTP id 56BED2635A43
	for <info@awaresystems.be>; Mon, 16 Jul 2012 16:07:06 +0000 (UTC)
Received: from localhost.localdomain (localhost.localdomain [127.0.0.1])
	by lists.maptools.org (Postfix) with ESMTP id C49411EDB62;
	Mon, 16 Jul 2012 11:05:34 -0500 (EST)
Received: from mail-lb0-f172.google.com (mail-lb0-f172.google.com
	[209.85.217.172])
	by lists.maptools.org (Postfix) with ESMTPS id 8B3291EDB5F
	for <tiff@lists.maptools.org>; Mon, 16 Jul 2012 10:55:52 -0500 (EST)
Received: by lbbgo11 with SMTP id go11so7495071lbb.3
	for <tiff@lists.maptools.org>; Mon, 16 Jul 2012 08:55:50 -0700 (PDT)
Received: by 10.112.83.228 with SMTP id t4mr5718934lby.74.1342454149895; Mon,
	16 Jul 2012 08:55:49 -0700 (PDT)
MIME-Version: 1.0
Received: by 10.114.0.227 with HTTP; Mon, 16 Jul 2012 08:55:29 -0700 (PDT)
From: Sergius Bobrovsky <sergius.bobrovsky@gmail.com>
Date: Mon, 16 Jul 2012 22:55:29 +0700
Message-ID: <CAFf4dxGRZKp9OpWgxxzcupD8Xrhi6e7xT8u49_bNxcSQ+br3=A@mail.gmail.com>
To: Tiff List <tiff@lists.maptools.org>
Subject: [Tiff] CCITTFaxDecode with EncodedByteAlign. How to create a TIFF
	from that.
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: text/plain; charset="us-ascii"
Content-Transfer-Encoding: 7bit
Sender: tiff-bounces@lists.maptools.org
Errors-To: tiff-bounces@lists.maptools.org

Hello!

I am trying to extract a CCITTFaxDecode encoded image from a PDF as
TIFF and the code that works just fine with many other similar images
fails.

The image in PDF is specified as following
<<
/Type /XObject
/Subtype /Image
/Name /Im1
/Filter [ /CCITTFaxDecode ]
/Width 3504 /Height 2480 /BitsPerComponent 1
/ColorSpace /DeviceGray
/Length 2 0 R
/DecodeParms [ <</K 0 /Columns 3504 /Rows 2480 /EncodedByteAlign true
/EndOfBlock false>> ]
>>

So, it looks like it's a CCITT Group 3 fax image with two extra
options: /EncodedByteAlign true /EndOfBlock false.

I tried to create a TIFF from it using following code
TIFF* image = TIFFOpen("out.tiff", "w");
TIFFSetField(image, TIFFTAG_IMAGEWIDTH, 3504);
TIFFSetField(image, TIFFTAG_IMAGELENGTH, 2480);
TIFFSetField(image, TIFFTAG_BITSPERSAMPLE, 1);
TIFFSetField(image, TIFFTAG_SAMPLESPERPIXEL, 1);
TIFFSetField(image, TIFFTAG_PLANARCONFIG, PLANARCONFIG_CONTIG);
TIFFSetField(image, TIFFTAG_ROWSPERSTRIP, 2480);
TIFFSetField(image, TIFFTAG_COMPRESSION, COMPRESSION_CCITTFAX3);
TIFFSetField(image, TIFFTAG_T4OPTIONS, GROUP3OPT_FILLBITS);
TIFFSetField(image, TIFFTAG_FAXMODE, FAXMODE_BYTEALIGN | FAXMODE_CLASSF);
TIFFSetField(image, TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_MINISWHITE);

FILE* raw = fopen("out.raw", "r");
unsigned char* rawBuf = new unsigned char[78808];
fread(rawBuf, 1, 78808, raw);
fclose(raw);

TIFFWriteRawStrip(image, 0, rawBuf, 78808);
TIFFClose(image);
delete rawBuf;
return 0;

But the output TIFF displays as a black rectangle in Windows Photo
Viewer and tiff2rgba utility can not decode the image also. The
utility issues multiple warnings about line length mismatch and
premature EOL and basically that's all.

fax2tiff utility with following options
-A -X 3504 out.raw
produce basically the same.

How am I supposed to create a valid TIFF from the data described
above? Is it supported by libtiff at all?

out.raw can be downloaded using following link:
https://dl.dropbox.com/u/3070948/out.raw.zip

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