Return-Path: <tiff-bounces@lists.maptools.org>
Received: from mailgate001.isp.belgacom.be (mailgate001.isp.belgacom.be [195.238.6.86])
        by maildelivery004.isp.belgacom.be (8.12.11.20060308/8.12.11/Skynet-IN-2.32) with ESMTP id l6C5bDJS014025
        for <joris.at.lebbeke@skynet.be>; Thu, 12 Jul 2007 07:37:13 +0200
        (envelope-from <tiff-bounces@lists.maptools.org>)
Received: from r153.dmsolutions.ca (HELO duke.maptools.org) ([209.217.116.153])
  by in.mx.skynet.be with ESMTP; 12 Jul 2007 07:37:12 +0200
Received: from duke.maptools.org (duke.maptools.org [127.0.0.1])
	by duke.maptools.org (8.12.11/8.12.10) with ESMTP id l6C5PI5I022274;
	Thu, 12 Jul 2007 01:26:00 -0400
Received: from scooby.simplesystems.org (scooby.simplesystems.org
	[65.66.246.67])
	by duke.maptools.org (8.12.11/8.12.10) with ESMTP id l6C5PCtV022271
	for <tiff@lists.maptools.org>; Thu, 12 Jul 2007 01:25:12 -0400
Received: from blade.simplesystems.org (blade.simplesystems.org [65.66.246.74])
	by scooby.simplesystems.org (8.12.10+Sun/8.12.10) with ESMTP id
	l6C5P6W7013919; Thu, 12 Jul 2007 00:25:07 -0500 (CDT)
Date: Thu, 12 Jul 2007 00:25:06 -0500 (CDT)
From: Bob Friesenhahn <bfriesen@simple.dallas.tx.us>
X-X-Sender: bfriesen@blade.simplesystems.org
To: Oliver Geisen <oliver.geisen@kreisbote.de>
Subject: Re: [Tiff] how to handle pixel vs. byte-boundary
In-Reply-To: <EDC66D32-6A16-429A-8C68-FEA2A0E5FFCF@kreisbote.de>
Message-ID: <Pine.SOC.4.60.0707120016050.922@blade.simplesystems.org>
References: <EDC66D32-6A16-429A-8C68-FEA2A0E5FFCF@kreisbote.de>
MIME-Version: 1.0
Content-Type: MULTIPART/MIXED; BOUNDARY="-559023410-2141490574-1184217906=:922"
Cc: tiff@lists.maptools.org
X-BeenThere: tiff@lists.maptools.org
X-Mailman-Version: 2.1.4
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>
Sender: tiff-bounces@lists.maptools.org
Errors-To: tiff-bounces@lists.maptools.org
X-UIDL: 000000000023ceae.000025ff
X-MSP-STORE: Thu, 12 Jul 2007 07:37:21 +0200
Status: RO

  This message is in MIME format.  The first part should be readable text,
  while the remaining parts are likely unreadable without MIME-aware tools.

---559023410-2141490574-1184217906=:922
Content-Type: TEXT/PLAIN; charset=US-ASCII; format=flowed

On Wed, 11 Jul 2007, Oliver Geisen wrote:
>
> as i try to deal with bilevel images, where 1 pixel equals 1 bit, i ran more 
> and more into problems.
>
> I want to place a bilevel TIFF onto another one (digital mounting).
> Therefore i specifiy x,y-offsets in pixels where to place the second image on 
> the first.
> But if the offset-value isn't divideable by 8 without remainder (=don't fit 
> into byte-boundary), it seems that i had to shift ALL bytes in the scanline 
> to fit into the new position.

It does not seem to me that you need to shift any bytes into a new 
position, but you will need to decode starting with the byte where the 
first bit is, and ending in the last byte where the last bit of the 
altered part of the image row is.  You can invent a scheme where you 
decode a byte, perform any boolean operations necessary on the bits, 
and then re-encode the byte.  This approach would avoid the need for 
extra buffering.

Bit shifting can indeed be slow.  Some algorithms are much faster than 
others.  Performance is very compiler and CPU sensitive.  I have 
attached a little benchmark program that I wrote some years ago in 
order to test the performance of various bit shift algorithms.  Maybe 
one of these algorithms is best for you?

Bob
======================================
Bob Friesenhahn
bfriesen@simple.dallas.tx.us, http://www.simplesystems.org/users/bfriesen/
GraphicsMagick Maintainer,    http://www.GraphicsMagick.org/

---559023410-2141490574-1184217906=:922
Content-Type: TEXT/plain; charset=US-ASCII; name="test2.c"
Content-Transfer-Encoding: BASE64
Content-ID: <Pine.SOC.4.60.0707120025060.922@blade.simplesystems.org>
Content-Description: 
Content-Disposition: attachment; filename="test2.c"

I2luY2x1ZGUgPHN0ZGlvLmg+DQoNCmludCBtYWluICggaW50IGFyZ2MsIGNo
YXIgKmFyZ3ZbXSkNCnsNCiAgcmVnaXN0ZXIgbG9uZw0KICAgIGJpdDsNCg0K
ICByZWdpc3RlciB1bnNpZ25lZCBpbnQNCiAgICBpLA0KICAgIHJlcCwNCiAg
ICB4Ow0KDQogIHVuc2lnbmVkIGludA0KICAgIGFsZ29yaXRobSwNCiAgICBy
ZXBzOw0KDQogIHJlZ2lzdGVyIHVuc2lnbmVkIGNoYXINCiAgICBjLA0KICAg
ICpyOw0KDQogIHVuc2lnbmVkIGNoYXINCiAgICByZXN1bHRbOF07DQoNCiAg
dm9sYXRpbGUgdW5zaWduZWQgY2hhcg0KICAgIHZhbHVlOw0KDQogIGlmIChh
cmdjICE9IDQpDQogICAgew0KICAgICAgcHJpbnRmKCJ1c2FnZTogJXMgcmVw
ZXRpdGlvbnMgYWxnb3JpdGhtIHZhbHVlXG4iLCBhcmd2WzBdKTsNCiAgICAg
IGV4aXQoMSk7DQogICAgfQ0KDQogIHJlcHMgPSBhdG9pKGFyZ3ZbMV0pOw0K
DQogIGFsZ29yaXRobSA9IGF0b2koYXJndlsyXSk7DQoNCiAgdmFsdWUgPSBh
dG9pKGFyZ3ZbM10pOw0KDQogIGZvciAocmVwPXJlcHM7IHJlcCA+IDA7IHJl
cC0tKQ0KICAgIHsNCiAgICAgIHN3aXRjaCAoYWxnb3JpdGhtKQ0KICAgICAg
ICB7DQogICAgICAgIGNhc2UgMToNCiAgICAgICAgICBmb3IgKHg9cmVwczsg
eCA+IDA7IHgtLSkNCiAgICAgICAgICAgIHsNCiAgICAgICAgICAgICAgcj1y
ZXN1bHQ7DQogICAgICAgICAgICAgIGM9dmFsdWU7DQogICAgICAgICAgICAg
IGZvciAoYml0PTc7IGJpdCA+PSAwOyBiaXQtLSkNCiAgICAgICAgICAgICAg
ICAqcisrPSgoYykgJiAoMHgwMSA8PCBiaXQpID8gMHgwMSA6IDB4MDApOw0K
ICAgICAgICAgICAgfQ0KICAgICAgICAgIGJyZWFrOw0KICAgICAgICBjYXNl
IDI6DQogICAgICAgICAgZm9yICh4PXJlcHM7IHggPiAwOyB4LS0pDQogICAg
ICAgICAgICB7DQogICAgICAgICAgICAgIHI9cmVzdWx0Ow0KICAgICAgICAg
ICAgICBjPXZhbHVlOw0KICAgICAgICAgICAgICBmb3IgKGJpdD03OyBiaXQg
Pj0gMDsgYml0LS0pDQogICAgICAgICAgICAgICAgKnIrKz0oYyA+PiBiaXQp
ICYgMHgwMTsNCiAgICAgICAgICAgIH0NCiAgICAgICAgICBicmVhazsNCiAg
ICAgICAgY2FzZSAzOg0KICAgICAgICAgIGZvciAoeD1yZXBzOyB4ID4gMDsg
eC0tKQ0KICAgICAgICAgICAgew0KICAgICAgICAgICAgICByPXJlc3VsdDsN
CiAgICAgICAgICAgICAgYz12YWx1ZTsNCiAgICAgICAgICAgICAgKnIrKz0o
YyA+PiA3KSA7DQogICAgICAgICAgICAgICpyKys9KGMgPj4gNiApICYgMHgw
MTsNCiAgICAgICAgICAgICAgKnIrKz0oYyA+PiA1ICkgJiAweDAxOw0KICAg
ICAgICAgICAgICAqcisrPShjID4+IDQgKSAmIDB4MDE7DQogICAgICAgICAg
ICAgICpyKys9KGMgPj4gMyApICYgMHgwMTsNCiAgICAgICAgICAgICAgKnIr
Kz0oYyA+PiAyICkgJiAweDAxOw0KICAgICAgICAgICAgICAqcisrPShjID4+
IDEgKSAmIDB4MDE7DQogICAgICAgICAgICAgICpyKys9KGMpICYgMHgwMTsN
CiAgICAgICAgICAgIH0NCiAgICAgICAgICBicmVhazsNCiAgICAgICAgY2Fz
ZSA0Og0KICAgICAgICAgIGZvciAoeD1yZXBzOyB4ID4gMDsgeC0tKQ0KICAg
ICAgICAgICAgew0KICAgICAgICAgICAgICByPXJlc3VsdDsNCiAgICAgICAg
ICAgICAgYz12YWx1ZTsNCiAgICAgICAgICAgICAgKnIrKz0oYyAmIDB4ODAp
ID4+IDc7DQogICAgICAgICAgICAgICpyKys9KGMgJiAweDQwKSA+PiA2Ow0K
ICAgICAgICAgICAgICAqcisrPShjICYgMHgyMCkgPj4gNTsNCiAgICAgICAg
ICAgICAgKnIrKz0oYyAmIDB4MTApID4+IDQ7DQogICAgICAgICAgICAgICpy
Kys9KGMgJiAweDA4KSA+PiAzOw0KICAgICAgICAgICAgICAqcisrPShjICYg
MHgwNCkgPj4gMjsNCiAgICAgICAgICAgICAgKnIrKz0oYyAmIDB4MDIpID4+
IDE7DQogICAgICAgICAgICAgICpyKys9KGMgJiAweDAxKTsNCiAgICAgICAg
ICAgIH0NCiAgICAgICAgICBicmVhazsNCiAgICAgICAgZGVmYXVsdDoNCiAg
ICAgICAgICB7DQogICAgICAgICAgICBwcmludGYoIlVuc3VwcG9ydGVkIGFs
Z29yaXRobVxuIik7DQogICAgICAgICAgICBleGl0KDEpOw0KICAgICAgICAg
IH0NCiAgICAgICAgfQ0KICAgIH0NCg0KICByPXJlc3VsdDsNCiAgZm9yKGk9
MDsgaTw4OyBpKyspDQogICAgcHJpbnRmKCIlZCIsICpyKyspOw0KICBwcmlu
dGYoIlxuIiwgcmVzdWx0KTsNCg0KICByZXR1cm4gMDsNCn0NCg==

---559023410-2141490574-1184217906=:922
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/
---559023410-2141490574-1184217906=:922--
