AWARE [SYSTEMS]
AWare Systems, , Home TIFF and LibTiff Mailing List Archive

LibTiff Mailing List

TIFF and LibTiff Mailing List Archive
November 2012

Previous Thread
Next Thread

Previous by Thread
Next by Thread

Previous by Date
Next by Date

Contact

The TIFF Mailing List Homepage
Archive maintained by AWare Systems



New Datamatrix section



Valid HTML 4.01!



Thread

2012.11.22 11:11 "TIFF 16 bit grayscale images", by Bharat Singh
2012.11.22 11:31 "Re: TIFF 16 bit grayscale images", by <jcupitt@gmail.com>
2012.11.22 12:50 "Re: TIFF 16 bit grayscale images", by Bharat Singh

2012.11.22 11:31 "Re: TIFF 16 bit grayscale images", by <jcupitt@gmail.com>

Your code looks fine, the bug must somewhere else. I would set
ROWSPERSTRIP, otherwise the whole file will be in a single big lump (I
think).

Here's a complete example. This should work for you too.

----
/* compile with
 *
 *      gcc -g try189.c -l tiff
 */

#include <tiffio.h>

#define SIZE_X (100)
#define SIZE_Y (100)

unsigned short buffer[SIZE_X * SIZE_Y];

int
main (int argc, char **argv)
{
  TIFF *img;
  int i;

  if (!(img = TIFFOpen (argv[1], "w")))
    return -1;

  for (i = 0; i < SIZE_X * SIZE_Y; i++)
    buffer[i] = i;

  TIFFSetField (img, TIFFTAG_IMAGEWIDTH, SIZE_X);
  TIFFSetField (img, TIFFTAG_IMAGELENGTH, SIZE_Y);
  TIFFSetField (img, TIFFTAG_SAMPLESPERPIXEL, 1);
  TIFFSetField (img, TIFFTAG_BITSPERSAMPLE, 16);
  TIFFSetField (img, TIFFTAG_COMPRESSION, COMPRESSION_NONE);
  TIFFSetField (img, TIFFTAG_ORIENTATION, ORIENTATION_TOPLEFT);
  TIFFSetField (img, TIFFTAG_PLANARCONFIG, PLANARCONFIG_CONTIG);
  TIFFSetField (img, TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_MINISBLACK);
  TIFFSetField (img, TIFFTAG_ROWSPERSTRIP, 16);

  for (i = 0; i < SIZE_Y; i++)
    {
      if (TIFFWriteScanline (img, buffer + i * SIZE_X, i, 0) < 0)
        return -1;
    }

  TIFFClose (img);

  return 0;
}
---

John


On 22 November 2012 11:11, Bharat Singh <bharatsingh430@gmail.com> wrote:

> Hello everyone,
>
> I am trying to write 16bit grayscale images, however when I open the
> image, the viewer says, Offset + image size > file length (image viewer if
> fiji), there is no error when I write the image
>
> Here is my code snippet
>
>         TIFF* img = TIFFOpen(location, "w");
> TIFFSetField(img, TIFFTAG_IMAGEWIDTH, size_x);
>  TIFFSetField(img, TIFFTAG_IMAGELENGTH, size_y);
> TIFFSetField(img, TIFFTAG_SAMPLESPERPIXEL, 1);
>  TIFFSetField(img, TIFFTAG_BITSPERSAMPLE, 16);
> TIFFSetField(img, TIFFTAG_COMPRESSION, COMPRESSION_NONE);
>  TIFFSetField(img, TIFFTAG_ORIENTATION, ORIENTATION_TOPLEFT);
> TIFFSetField(img, TIFFTAG_PLANARCONFIG, PLANARCONFIG_CONTIG);
>  TIFFSetField(img, TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_MINISBLACK);
>         for (int i = 0; i < size_y; i++) {
>  TIFFWriteScanline(img, buffer + i*size_x, i, 0);
> }
> TIFFClose(img);
>
> matlab I can open the image but, it is a random output  which doesn't make
> any sense. It would be of great help if some one could tell me if there is
> a bug in this code. Also while compiling I have this warning,  defaultlib
> 'LIBCMT' conflicts with use of other libs;
>
> IDE - visual studio 2008, OS - windows 7
>
> --
> Bharat
>
> _______________________________________________
> Tiff mailing list: Tiff@lists.maptools.org
> http://lists.maptools.org/mailman/listinfo/tiff
> http://www.remotesensing.org/libtiff/
>