Skip to content

Instantly share code, notes, and snippets.

@hyounggyu
Created April 1, 2013 07:27
Show Gist options
  • Select an option

  • Save hyounggyu/5283646 to your computer and use it in GitHub Desktop.

Select an option

Save hyounggyu/5283646 to your computer and use it in GitHub Desktop.
/**cc -oreadtiff -L/usr/lib/ -ltiff readtiff.c **/
/**cc -oreadtiff -ltiff readtiff.c **/
#include <tiffio.h>
#include <stdlib.h>
uint32 w,h,*raster;
size_t npixels;
int main(int argc, char* argv[])
{
TIFF* tif = TIFFOpen(argv[1], "r");
if(tif){
read_image_size(tif);
read_directory(tif);
raster = (uint32*)_TIFFmalloc(npixels * sizeof(uint32));
if (raster != NULL) {
if (TIFFReadRGBAImage(tif, w, h, raster, 0)) {
test_raster();
}
_TIFFfree(raster);
}
TIFFClose(tif);
}
exit(0);
}
read_image_size(TIFF* tif){
TIFFGetField(tif, TIFFTAG_IMAGEWIDTH, &w);
TIFFGetField(tif, TIFFTAG_IMAGELENGTH, &h);
npixels = w * h;
printf("%5d %5d %5u\n",w,h,npixels);
}
read_directory(TIFF* tif){
int dircount = 0;
do{
dircount++;
} while (TIFFReadDirectory(tif));
printf("%d directories\n",dircount);
}
test_raster(){
int i;
for(i=0; i < npixels; i++)
printf("%5d %5d : %10d %10d %10d %10d\n", i % w, i / w,
TIFFGetR(raster[i]), TIFFGetG(raster[i]),
TIFFGetB(raster[i]), TIFFGetA(raster[i]));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment