Requirements that Processing has for loading TIFF files

Is there a way to find out the requirements that Processing has for loading TIFF files? The documents say only gif, .jpg, .tga, or .png but I can load TIFF if the TIFF has been made by Processing.

Error: Processing can only read its own TIFF files.

So what or where is the difference between a proprietary TIFF and a Processing TIFF? If I know this I can go about translating my files so they will load.

Thanks in advance,
Paul

@jeremydouglass @Chrisir @glv @GoToLoop @kll @Lexyth @behreajj

1 Like

Hi @paulstgeorge,

I think a place to start would be to look through the source code to find where the message comes from: it’s a String in PImage here. It is triggered a few lines later due to this condition:

if ((tiff[42] != tiff[102]) ||  // width/height in both places
        (tiff[43] != tiff[103])) {
      System.err.println(TIFF_ERROR);
      return null;
}

Looks like the saveTIFF function is not far below. In that function, the array elements compared above are set like this:

tiff[42] = tiff[102] = (byte) ((pixelHeight >> 8) & 0xff);
tiff[43] = tiff[103] = (byte) ((pixelHeight) & 0xff);

Hope that helps a bit,
Jeremy

1 Like

When you have tiffs not generated by processing you want to load into processing:

Free programs like IrfanView have a Batch Mode to convert many images from tiff to jpg etc. in one go.

Chrisir

Consider undocumented loadImageIO (untested)

How do I load images that are .tiff format? loadImage() only works with ( .gif, .jpg, .tga, .png). I want to use tiff, not something else. Is there a different method, or a workaround? I saw loadImageIO() somewhere but it needs some Java to make that work.
Thanks!

(hmm – just tried to merge the above question, and it ended up on the bottom of the conversation. sorry for the mess)

Thanks @Chrisir
That is indeed my plan B. I don’t want to convert if I can avoid it but I am currently investigating whether PNG 24 is same image quality (ignoring meta data, layers, etc.) as TIFF. If it is, I might as well use PNG or JPG images as you suggest.

Thanks @jeremydouglass
I tried:

import java.io.*;

PImage img;
 
void setup()
{
  size(484, 480);
  img = loadImageIO("/Users/Lion/Documents/Processing/sketches/importIOtest/image.tif");
  image(img, 0, 0);
}

And get the error:

java.lang.NullPointerException
at processing.core.PApplet.loadImageIO(PApplet.java:5724)
at importIOtest.setup(importIOtest.java:26)
at processing.core.PApplet.handleDraw(PApplet.java:2432)
at processing.awt.PSurfaceAWT$12.callDraw(PSurfaceAWT.java:1547)
at processing.core.PSurfaceNone$AnimationThread.run(PSurfaceNone.java:313)

So, now I do not know whether the problem is with the code or the TIFF. I am hoping it is the code because that should be fairly easy to fix.

I have used the full path to the file rather than a relative path. Correct?

Hello,

When converting…
If you want to preserve quality in conversion use a lossless format that such as PNG, TGA or TIFF.
You can also use GIF but keep in mind this is 8-bit color.
JPG compression is a lossy algorithm and loses quality in compression; it may not be discernible for pictures but the quality (data) is lost.

I am confident that you will discover this in your investigation.

On a side note, I always save my images to TGA if I am saving frames in a Processing sketch for use later with Processing Movie Maker or other tools. TGA is so much faster for this; I have SSDs so writes are fast. PNG has the same quality but is so much slower to process because it has to compress it.

Processing Movie Maker uses:

:)

Thanks @behreajj
That is what I was looking for! (I think.)
I am assuming the widths and heights are to do with the TIFF HEADER and not the image. So, I’ll try removing the image preview (embedded thumbnail) first and then I’ll try stripping out the header. Or am I barking up the wrong tree?
/Paul

Thanks @glv I have no knowledge of TGA. Ignoring speed, would I be losing any image quality if I converted from TIFF to TGA? Ceteris paribus, which is better quality PNG or TGA?

If you want to add TIFF-loading support to your sketch, it looks like the missing resource is JAI 1.1, which for Java 8 adds TIFF support to imageio.

  1. create a /code subfolder in your sketch, and add jai_imageio-1.1.jar
  2. add a TIFF file to the sketch folder: test.tif
  3. run a sketch that uses the protected undocumented loadImageIO method of Processing’s PApplet:
PImage img;
 
void setup() {
  size(484, 480);
  background(128);
  img = this.loadImageIO("test.tif");
  image(img, 0, 0);
}

Your TIFF is loaded as a PImage and displayed.

Note that without JAI the default loadImageIO of Java 8 (used by Processing 3) does not have TIFF support. In Java 9+ this is not true.

FYI, JAI was added to the Processing MovieMaker tool ~2013 for just this reason:

…and so jai_imageio.jar is part of the Processing 3 source under tools

…just not automatically on the path of PApplet (not available by default to a sketch).

1 Like

There should be no loss converting from TIFF to TGA; I am assuming the software is trusted and you same the same format, color depth, etc. I will leave this part with you.
PNG and TGA should have the same quality; PNG is compressed (lossless) and TGA is not.

:)

There are tools out there to compare images.

Just for fun compare the GIF with JPG on this site:
https://online-image-comparison.com/

First see if you can tell the difference and then compare.

Bob.gif


Bob.jpg

Stay well!

2 Likes

Sacre bleu, it works!! I will not now try the other approaches (stripping headers, changing formats, etc.) but would be curious to know if that TIFF HEADER approach might have worked.

Thank you so much!

1 Like

This is great, thank you!