AWARE [SYSTEMS] Imaging expertise for the Delphi developer
AWare Systems, Imaging expertise for the Delphi developer, Home TIFF and LibTiff Mailing List Archive

LibTiff Mailing List

TIFF and LibTiff Mailing List Archive
July 2007

Previous Thread
Next Thread

Previous by Thread
Next by Thread

Previous by Date
Next by Date

Contact

The TIFF Mailing List Homepage
This list is run by Frank Warmerdam
Archive maintained by AWare Systems



Valid HTML 4.01!



Thread

2007.07.13 16:19 "Re: Bit shifting and rotating of TIFF images", by Richard Nolde
2007.07.14 12:39 "Re: Bit shifting and rotating of TIFF images", by Oliver Geisen
2007.07.14 16:03 "Re: Bit shifting and rotating of TIFF images", by Bob Friesenhahn
2007.07.16 04:57 "Image Roation by 180 degrees", by Richard Nolde
2007.07.17 09:32 "Re: Bit shifting and rotating of TIFF images", by Oliver Geisen
2007.07.17 12:10 "Re: Bit shifting and rotating of TIFF images", by <ron@debian.org>
2007.07.18 00:33 "Re: Bit shifting and rotating of TIFF images", by Chris Cox
2007.07.20 04:26 "Bit shifts vs lookup tables", by Richard Nolde

2007.07.14 12:39 "Re: Bit shifting and rotating of TIFF images", by Oliver Geisen

Richard,

>   Concerning rotating TIFF images and compositing them onto a  
> background image. Check out the CVS release and find the new  
> utility tiffcrop in the utils directory. I am working on an update  
> to the currently available version but the code to rotate images   
> should work for you. Note that rotations of 90 or 270 degrees may  
> change the size of the buffer due to the handling of the padding  
> bytes at the end of each scanline.
I found your code, compiled it, and it worked well, good work!

But allow me some questions/conclusions about that:
What i want to do is, image rotation by 180 degrees only.
The whole point in processing images with libtiff is that one have  
only a limited part of the image inside a memoryblock to work with.
This is an advantage because some images (our own also) will get very  
big.
Special care must be taken if imagedata is bilevel (1 bit per pixel)  
but converting all the data  into an 8 bit pixel, process it and  
reconvert it to 1 bit pixels seems to be clumsy.

When only concerning bilevel images with 180 degree rotation, how  
could this be done ?

Here is my approach:
(for striped images)
   - open input tiff, determine number of strips and stripsize (in  
bytes)
   - create output tiff with almost the same IFD
   - create strip buffer for output tiff (equal size of input tiff)
   - loop through each strip of input tiff, from last to first
     - determine number of bytes per scanline (= StripSize/RowsPerStrip)
     - loop though each byte in scanline, from last to first
       - read byte value (= 8 Pixels)
       - "rotate" the value by using a lookup-table (each value from  
0-255 has an corresponding value with bits swapped)
       - write byte into the corresponing line of the output buffer
     - write rotated strip to output tiff
   - close tiff

(for tiled images)
   ? No clue ?

I look around to solve the bit-swapping problem and the best solution  
i found was a lookup table like:

idx   1 = 1000 0000
idx   2 = 1100 0000
...
idx 254 = 0000 0001

To get the bit-swapped result just use the current pixel-data as an  
index into this table.
   cswap = lookup[c];

One BIG problem is that if the width of an image (scanline) is not a  
multiple of 8, there is a remaining number of bits on the right side.  
If one rotate it by 180 deg. the remaining bits are on the left side  
now. So just swapping the byte value is not enough. Assume an image  
which is 10 pixels in width, this would be represented by 2 bytes.  
Now swap those bytes and the bits inside to achieve rotation. The  
image has virtually shiftet it's starting (left) position by 6 pixels  
(bits).
So after byte and bit swapping there must be also be a bit shifting  
by the amount of remaining bits (1..7).
This is a challenge, even if perfomance does not matter ;-)


Oliver Geisen
Systemadministrator
_____________________________
Kreisboten Verlag Mühlfellner KG
82362 Weilheim i. Ob.
Tel. 0881/686-904
Fax 0881/686-74
Sitz Weilheim, AG München, HRA 64016, p.h.G.:
Kreisboten-Verlag Verwaltungsgesellschaft mbH,
Weilheim, AG München, HRB 119773,
Geschäftsführer: Dr. Dirk Ippen, Dr. Gerd Waldenmaier