Handling Huge TIFF

I have been using Christian’s excellent TIFFPictureMBS and I could get away with just using the following statement to open the TIFF file

t = new TIFFPictureMBS
call t.open(f)

to handle my needs.

I just received an email from a customer who tried to open a huge TIFF 1 bit file which is like 9888 x 13992 pixels and apparently the above code didn’t work. Ended up not being able to load the file. I tried Preview app and it very fast.

I saw a Huge TIFF example on Monkeybread which reads

[quote] dim f as FolderItem
dim t as TiffPictureMBS
dim p as PictureMBS

f=SpecialFolder.Desktop.Child(“test.tif”)

if f<>Nil then
t=new TiffPictureMBS

if t.Open(f) then
  
  dim row as MemoryBlock
  dim h as integer=t.Height-1
  
  for i as integer=0 to h
    row=t.Scanline(i)
  next
  
  t.Close
  
  MsgBox "Read TIFF file."
  
end if

end if[/quote]

Looks good but how do I adapt this code to convert the TIFF to a PictureMBS ? I am pretty rusty when it comes to Memoryblock. I saw the Dim statement for P but nothing in the code seems to convert that to the picture.

Thanks.

this picture would be as RGB about 500 MB in size. This could work with normal code, but could hit memory limits.

You could use ReadBW function to read portions of image, e.g. first half/second half.

Thanks Christian. Do you have any code samples ? I’ve no experience with MemoryBlock and now I am using this code for what I am doing right now.

[quote] call timport.open(f)

  if timport.BitsPerSample > 1 then
    call timport.ReadRGB 
  else
    call timport.readbw
  end if [/quote]

does it work this way?

Nope, it doesn’t with that particular TIFF file. Basically, it didn’t load as the dimensions came back as 0 or Nil. But when I manually resized the same images to under 4000 pixels for both its width and height in Preview, it loads after that. I am not sure what maximum dimension, it supports up to.

You mentioned that the file is a 1-bit TIFF. Do you know anything about the type of compression that’s used?

TIFF supports a number of 1-bit compression schemes, and it may be that Christian’s plug-in doesn’t support them all?

One more thought: You say that it works after re-sizing and saving from Preview. What happens if you simply re-save the file from Preview WITHOUT resizing?

This would server to indicate if it’s pixel dimension(s) or something about how this particular file is written.

Well, maybe email me a link to download a tiff and a sample test project?
I could take a closer look.

Thanks Guys.

I’ve given the file another look and the original file uses LZW compression and the Color Depth reported as 1 Bit. If I duplicate the file, it still shows the same.

However when resizing the file and saving it, it still uses LZW but the depth is now 8.

Okay, I just did an experiment and resized the file down by 2 pixels and saved it in Preview which converted it to a 8 Bit TIFF LZW. This time the file opens. So it is possible that the 1 Bit handling might be the issue. This is giving me something to look into.

Thanks.

An Update. Although it is a 1 bit file, when I tried to open it using the ReadBW, it fails but reverting it to ReadRGB, it worked. Strange.

Please note that ReadRGB needs about twice the memory for the picture.
Once for the buffer and once for the xojo picture.