title: Getting error when trying to apply "ExtraSamples" tag to a TIFF file to be written
body: <p>I have a program that takes an image and writes that out to a TIFF file.  The image can be grey scale (8 bit), grey scale with alpha channel (16 bit), RGB (24 bit), or ARGB (32 bit).  I don't have any problems writing out the images without an alpha channel, but for the images with alpha, when I try to set the extra samples tag, I get sent to the TIFF error handling routine set by TIFFSetErrorHandler.  The message that's passed in is <code>&lt;filename&gt;: Bad value 1 for "ExtraSamples"</code> in the _TIFFVSetField module.  Some sample code below:</p>
  
  <pre><code>#include "tiff.h"
  #include "tiffio.h"
  #include "xtiffio.h"
  //Other includes
  
  class MyTIFFWriter
  {
  public:
      MyTIFFWriter(void);
  
      ~MyTIFFWriter(void);
  
      bool writeFile(MyImage* outputImage);
      bool openFile(std::string filename);
      void closeFile();
  
  private:
      TIFF* m_tif;
  };
  
  //...
  
  bool MyTIFFWriter::writeFile(MyImage* outputImage)
  {
      // check that we have data and that the tiff is ready for writing
      if (outputImage-&gt;getHeight() == 0 || outputImage-&gt;getWidth() == 0 || !m_tif)
          return false;
  
      TIFFSetField(m_tif, TIFFTAG_IMAGEWIDTH, outputImage-&gt;getWidth());
      TIFFSetField(m_tif, TIFFTAG_IMAGELENGTH, outputImage-&gt;getHeight());
      TIFFSetField(m_tif, TIFFTAG_COMPRESSION, COMPRESSION_NONE);
      TIFFSetField(m_tif, TIFFTAG_PLANARCONFIG, PLANARCONFIG_CONTIG);
  
      if (outputImage-&gt;getColourMode() == MyImage::ARGB)
      {
          TIFFSetField(m_tif, TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_RGB);
          TIFFSetField(m_tif, TIFFTAG_BITSPERSAMPLE, outputImage-&gt;getBitDepth() / 4);
          TIFFSetField(m_tif, TIFFTAG_SAMPLESPERPIXEL, 4);
          TIFFSetField(m_tif, TIFFTAG_EXTRASAMPLES, EXTRASAMPLE_ASSOCALPHA);  //problem exists here
      } else if (/*other mode*/)
          //apply other mode settings
  
      //...
  
      return (TIFFWriteEncodedStrip(m_tif, 0, outputImage-&gt;getImgDataAsCharPtr(), 
          outputImage-&gt;getWidth() * outputImage-&gt;getHeight() *
          (outputImage-&gt;getBitDepth() / 8)) != -1);
  }
  </code></pre>
  
  <p>As far as I can see, the tag never gets written to the file.  Luckily, GIMP still recognizes that the additional channel is alpha, but some other programs that need to read these TIFFs aren't so generous.  Am I missing tags that must be set before TIFFTAG_EXTRASAMPLES?  Am I missing other tags that need to be there?  Any help would be appreciated.</p>