AWARE [SYSTEMS] Imaging expertise for the Delphi developer
AWare Systems, Imaging expertise for the Delphi developer, Home TIFF and LibTiff Mailing List Archive

LibTiff Mailing List

TIFF and LibTiff Mailing List Archive
October 2007

Previous Thread
Next Thread

Previous by Thread
Next by Thread

Previous by Date
Next by Date

Contact

The TIFF Mailing List Homepage
This list is run by Frank Warmerdam
Archive maintained by AWare Systems



Valid HTML 4.01!



Thread

2007.10.30 02:27 "Simple code to write Tiff images from Raw data", by Richard Nolde
2007.10.31 00:01 "Re: Rookie question", by Leonardo Serni
2007.11.15 02:19 "Re: Simple code to write Tiff images from Raw data", by Ron Croonenberg
2007.11.15 04:37 "Re: Simple code to write Tiff images from Raw data", by Frank Warmerdam
2007.11.15 15:36 "Re: Simple code to write Tiff images from Raw data", by Ron Croonenberg
2007.11.15 15:45 "Re: Simple code to write Tiff images from Raw data", by Frank Warmerdam
2007.11.15 11:42 "Re: Simple code to write Tiff images from Raw data", by Jason Tillett
2007.11.15 14:42 "Re: Simple code to write Tiff images from Raw data", by Ron Croonenberg

2007.10.31 00:01 "Re: Rookie question", by Leonardo Serni

>I am new to  libTiff. I am looking for a way to create TIF image files
>(or any other graphics format) from "raw" simulation data. (basically it
>is 3-d data projected on a 2-D plane.  What it comes down to is that I
>have a bunch of "pixels", a discrete coordinate (that translates to a
>pixel in an image) and RGB values. (I basically just want to create an
>image by doing something like "this pixel has these RGB values" and
>"stick them in an image file.
>
>It probably can be done with libTiff, right ?  are there any examples
>that I can take a look at ?

You can do this quite easily (no error checking included, see man pages):

#include <stdint.h>
#include "tiffio.h"

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

         char    buffer[3*1024];

         uint32_t        width = 1024, height = 768, row;

          if (2 != argc)
         {
                 fprintf(stderr, "syntax: %s outfile.tif\n", argv[0]);
                 return -1;
         }

         tif = TIFFOpen(argv[1], "w");

         TIFFSetField (tif, TIFFTAG_IMAGEWIDTH, width);
         TIFFSetField (tif, TIFFTAG_IMAGELENGTH, height);
         TIFFSetField (tif, TIFFTAG_PLANARCONFIG, PLANARCONFIG_CONTIG);
         TIFFSetField (tif, TIFFTAG_SAMPLESPERPIXEL,  3);
         TIFFSetField (tif, TIFFTAG_BITSPERSAMPLE,    8);
         TIFFSetField (tif, TIFFTAG_EXTRASAMPLES,     0, NULL);
         TIFFSetField (tif, TIFFTAG_ORIENTATION,      ORIENTATION_TOPLEFT);
         TIFFSetField (tif, TIFFTAG_PHOTOMETRIC,      PHOTOMETRIC_RGB);
         TIFFSetField (tif, TIFFTAG_IMAGEDESCRIPTION, "3D Simulation");
         /* Other compressions exist, of course */
         TIFFSetField (tif, TIFFTAG_COMPRESSION,      COMPRESSION_DEFLATE);
         TIFFSetField (tif, TIFFTAG_PREDICTOR,        1 /* experiment */);
         /* Suggest rps = 20000/width so that a strip is around 64K
            and possibly try to keep rps to a power of 2
            (unless width is itself a power of 2, of course)
          */
         TIFFSetField (tif, TIFFTAG_ROWSPERSTRIP,     16);

         for (row = 0; row < 768; row++)
         {
                 int i;
                 for (i = 0; i < 1024; i++)
                 {
                         buffer[3*i]   = row % 255;
                         buffer[3*i+1] = i % 255;
                         buffer[3*i+2] = (row >> 2) % 255;
                 }
                 TIFFWriteScanline(tif, buffer, row, 0);
         }
         TIFFClose(tif); tif = NULL;
         return 0;
}

Leonardo