2004.12.11 02:06 "[Tiff] TIFF Pyramid", by Eric Vergnaud

2004.12.13 11:38 "Re: [Tiff] TIFF Pyramid", by Joris Van Damme

Look at the contrib/addtiffo directory. addtiffo output organized a bit differently from Photoshop, but it works with major geospatial image processing packages. You can easily modify this utility to get results you want.

It doesn't write SubIFDs, does it?

I've tested what I found out about writing the SubIFDs tag, and it works as I expected. You can write a chain of IFDs the normal way, and whenever you write a value n to the SubIFDs tag, the next n directories you write are appended as a SubIFD chain instead of being appended in the normal main IFD chain.

The code below is my test code. It's Pascal, of course, using LibTiffDelphi, and it uses the Delphi VCL TBitmap object which is essentially a Windows DIB wrapper, and thus needs some RGB swopping and such, but it's still short and easy to understand and should illustrate the point. There's no error checking/handling and such though.

It loads a bitmap image, and next writes a chain of first that image, an image resampled to half that width and height, an image resampled to half previous width and height, etc. In the first image IFD, the SubIFDs tag is set with value 3, and that yields a file with one main (biggest) image and 3 downsample SubIFDs. If I change the value 3 of the SubIFDs tag to e.g. 2, it works as expected, one main image is written, 2 SubIFDs are linked to that main image, and the last is again written as a top-level IFD.

The images are written tiled. Tile size is fixed 128*128, even though in my test the last image was smaller. That all works like a charm.

  m: PTIFF;
  n: Integer;
  oa,ob: TBitmap;
  px,py: Integer;
  pt: Integer;
  q: Pointer;
  qa,qb: PByte;
  qx,qy: Integer;
  rr,rg,rb: Integer;
  if m=nil then exit;
  for n:=0 to 3 do
    if n=0 then
      ob.Width:=(oa.Width div 2);
      ob.Height:=(oa.Height div 2);
    if n=0 then
    while py<oa.Height do
      while px<oa.Width do
        while (qy<128) and (py+qy<oa.Height) do
          while (qx<128) and (px+qx<oa.Width) do

Joris Van Damme
Download your free TIFF tag viewer for windows here: