# Requirements that Processing has for loading TIFF files

**URL:** <https://discourse.processing.org/t/requirements-that-processing-has-for-loading-tiff-files/19281>\
**Category:** Coding Questions\
**Created:** [April 1, 2020, 12:24pm UTC](https://discourse.processing.org/t/requirements-that-processing-has-for-loading-tiff-files/19281 "2020-04-01T12:24:12Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![paulstgeorge](https://avatars.discourse-cdn.com/v4/letter/p/53a042/32.png) [@paulstgeorge](https://discourse.processing.org/u/paulstgeorge)\
**Post date:** [April 1, 2020, 12:24pm UTC](https://discourse.processing.org/t/requirements-that-processing-has-for-loading-tiff-files/19281/1 "2020-04-01T12:24:12Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![behreajj](https://avatars.discourse-cdn.com/v4/letter/b/b5a626/32.png) [@behreajj](https://discourse.processing.org/u/behreajj)\
**Post date:** [April 1, 2020, 12:35pm UTC](https://discourse.processing.org/t/requirements-that-processing-has-for-loading-tiff-files/19281/2 "2020-04-01T12:35:14Z")

</div>

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](https://github.com/processing/processing/blob/3952f6f7247dba50920662da3276e91166426fb7/core/src/processing/core/PImage.java#L2961). It is triggered a few lines later due to this condition:

```auto
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](https://github.com/processing/processing/blob/master/core/src/processing/core/PImage.java#L3012) function is not far below. In that function, the array elements compared above are set like this:

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

```

Hope that helps a bit,  
Jeremy

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [April 1, 2020, 1:52pm UTC](https://discourse.processing.org/t/requirements-that-processing-has-for-loading-tiff-files/19281/3 "2020-04-01T13:52:47Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![jeremydouglass](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jeremydouglass/32/20_2.png) [@jeremydouglass](https://discourse.processing.org/u/jeremydouglass)\
**Post date:** [April 1, 2020, 2:35pm UTC](https://discourse.processing.org/t/requirements-that-processing-has-for-loading-tiff-files/19281/4 "2020-04-01T14:35:44Z")

</div>

Consider undocumented loadImageIO (untested)

- [https://forum.processing.org/two/discussion/17132/radio-button-labels-in-controlp5](https://forum.processing.org/two/discussion/17132/radio-button-labels-in-controlp5)

---

<div class="post-metadata">

**Author:** ![paulstgeorge](https://avatars.discourse-cdn.com/v4/letter/p/53a042/32.png) [@paulstgeorge](https://discourse.processing.org/u/paulstgeorge)\
**Post date:** [March 30, 2020, 8:07pm UTC](https://discourse.processing.org/t/requirements-that-processing-has-for-loading-tiff-files/19281/5 "2020-03-30T20:07:42Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![jeremydouglass](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jeremydouglass/32/20_2.png) [@jeremydouglass](https://discourse.processing.org/u/jeremydouglass)\
**Post date:** [April 1, 2020, 3:34pm UTC](https://discourse.processing.org/t/requirements-that-processing-has-for-loading-tiff-files/19281/6 "2020-04-01T15:34:48Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![paulstgeorge](https://avatars.discourse-cdn.com/v4/letter/p/53a042/32.png) [@paulstgeorge](https://discourse.processing.org/u/paulstgeorge)\
**Post date:** [April 1, 2020, 6:25pm UTC](https://discourse.processing.org/t/requirements-that-processing-has-for-loading-tiff-files/19281/7 "2020-04-01T18:25:18Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![paulstgeorge](https://avatars.discourse-cdn.com/v4/letter/p/53a042/32.png) [@paulstgeorge](https://discourse.processing.org/u/paulstgeorge)\
**Post date:** [April 1, 2020, 6:49pm UTC](https://discourse.processing.org/t/requirements-that-processing-has-for-loading-tiff-files/19281/8 "2020-04-01T18:49:59Z")

</div>

> [@jeremydouglass](#):
>
> Consider undocumented loadImageIO (untested)
> 
> - [[https://forum.processing.org/two/discussion/17132/radio-button-labels-in-controlp5](https://forum.processing.org/two/discussion/17132/radio-button-labels-in-controlp5) ]

Thanks @jeremydouglass  
I tried:

```auto
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?

---

<div class="post-metadata">

**Author:** ![glv](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/glv/32/18785_2.png) [@glv](https://discourse.processing.org/u/glv)\
**Post date:** [April 1, 2020, 7:17pm UTC](https://discourse.processing.org/t/requirements-that-processing-has-for-loading-tiff-files/19281/9 "2020-04-01T19:17:58Z")

</div>

Hello,

> [@paulstgeorge](#):
>
> I might as well use PNG or JPG images as you suggest.

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:

 ![image](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/7/7a7d54ad6d1637c46f0db5e7aef53b514aa9455c.png)

`:)`

---

<div class="post-metadata">

**Author:** ![paulstgeorge](https://avatars.discourse-cdn.com/v4/letter/p/53a042/32.png) [@paulstgeorge](https://discourse.processing.org/u/paulstgeorge)\
**Post date:** [April 1, 2020, 7:29pm UTC](https://discourse.processing.org/t/requirements-that-processing-has-for-loading-tiff-files/19281/10 "2020-04-01T19:29:11Z")

</div>

> [@behreajj](#):
>
> I think a place to start would be to look through the source code to find where the message comes from

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

---

<div class="post-metadata">

**Author:** ![paulstgeorge](https://avatars.discourse-cdn.com/v4/letter/p/53a042/32.png) [@paulstgeorge](https://discourse.processing.org/u/paulstgeorge)\
**Post date:** [April 1, 2020, 7:31pm UTC](https://discourse.processing.org/t/requirements-that-processing-has-for-loading-tiff-files/19281/11 "2020-04-01T19:31:51Z")

</div>

> [@glv](#):
>
> If you want to preserve quality in conversion use a lossless format that such as PNG, TGA or TIFF.

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?

---

<div class="post-metadata">

**Author:** ![jeremydouglass](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jeremydouglass/32/20_2.png) [@jeremydouglass](https://discourse.processing.org/u/jeremydouglass)\
**Post date:** [April 1, 2020, 7:33pm UTC](https://discourse.processing.org/t/requirements-that-processing-has-for-loading-tiff-files/19281/12 "2020-04-01T19:33:26Z")

</div>

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:

```auto
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:

> <https://github.com/processing/processing/commit/ee8594558450cafc655af1daed0149a8adeca816>

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

- [https://github.com/processing/processing/tree/master/build/shared/tools/MovieMaker/tool](https://github.com/processing/processing/tree/master/build/shared/tools/MovieMaker/tool)

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

---

<div class="post-metadata">

**Author:** ![glv](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/glv/32/18785_2.png) [@glv](https://discourse.processing.org/u/glv)\
**Post date:** [April 1, 2020, 7:48pm UTC](https://discourse.processing.org/t/requirements-that-processing-has-for-loading-tiff-files/19281/13 "2020-04-01T19:48:20Z")

</div>

> [@paulstgeorge](#):
>
> 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?

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/](https://online-image-comparison.com/)

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

Bob.gif

 ![Bob_1 (1)](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/a/aad5087be270c09adf8a1edd3c63dd6501780b2d.gif)  
Bob.jpg  
 ![Bob_1 (1)](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/5/563e250abd3d9890a93a4636339aa1e868d9a963.jpeg)

Stay well!

---

<div class="post-metadata">

**Author:** ![paulstgeorge](https://avatars.discourse-cdn.com/v4/letter/p/53a042/32.png) [@paulstgeorge](https://discourse.processing.org/u/paulstgeorge)\
**Post date:** [April 1, 2020, 7:58pm UTC](https://discourse.processing.org/t/requirements-that-processing-has-for-loading-tiff-files/19281/14 "2020-04-01T19:58:35Z")

</div>

> [@jeremydouglass](#):
>
> Your TIFF is loaded as a PImage and displayed.

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!

---

<div class="post-metadata">

**Author:** ![paulstgeorge](https://avatars.discourse-cdn.com/v4/letter/p/53a042/32.png) [@paulstgeorge](https://discourse.processing.org/u/paulstgeorge)\
**Post date:** [April 1, 2020, 8:00pm UTC](https://discourse.processing.org/t/requirements-that-processing-has-for-loading-tiff-files/19281/15 "2020-04-01T20:00:46Z")

</div>

> [@glv](#):
>
> There are tools out there to compare images.

This is great, thank you!
