ch2-tiff
Chapter_2 test | RTLD |
CONTENTS: image.ppm tifftest.c
Note: We used a simple ASCII ppm_image, which we turned into a tiff_image (with GIMP).
image.ppm (Source: Netpbm on Wikipedia)
P3
# "P3" means this is a RGB color image in ASCII
# "3 2" is the width and height of the image in pixels
# "255" is the maximum value for each color
# This, up through the "255" line below are the header.
# Everything after that is the image data: RGB triplets.
# In order: red, green, blue, yellow, white, and black.
3 2
255
255 0 0
0 255 0
0 0 255
255 255 0
255 255 255
0 0 0
tifftest.c ALP, p. 46-47
#include <stdio.h> // printf(), fprintf(), stderr()
#include <tiffio.h> // for TIFF, TIFFOpen(), TIFFClose(), TIFFGetField
// /usr/include/x86_64-linux-gnu/tiffio.h includes
// /usr/include/x86_64-linux-gnu/tiff.h, which defines:
// TIFFTAG_IMAGEWIDTH, TIFFTAG_IMAGELENGTH,
// TIFFTAG_XRESOLUTION, TIFFTAG_YRESOLUTION
int main (int argc, char** argv)
{
if (argc != 2)
{
fprintf(stderr, "Usage: ./tifftest image.tiff\n");
return 1; // end program, signalling error
}
// else
int w, h;
float xdpi, ydpi;
TIFF *tiff;
tiff = TIFFOpen (argv[1], "r"); // open for reading
TIFFGetField(tiff, TIFFTAG_IMAGEWIDTH, &w);
TIFFGetField(tiff, TIFFTAG_IMAGELENGTH, &h);
TIFFGetField(tiff, , &xdpi);
TIFFGetField(tiff, TIFFTAG_YRESOLUTION, &ydpi);
TIFFClose (tiff);
printf("Image width: %d\n", w);
printf("Image hight: %d\n", h);
printf("X Resolution: %g dpi\n", xdpi);
printf("Y Resolution: %g dpi\n", ydpi);
return 0;
}
/*
sudo apt-get install zlib1g-dev libpng-dev libpng++-dev libtiff5-dev
gcc tifftest.c -static -ltiff -o tifftest
// unresolved symbols
gcc tifftest.c -ltiff -o tifftest // use shared library
./tifftest
Usage: ./tifftest image.tiff
ldd tifftest
libc.so...
libjpeg.so...
libz.so...
libm.so...
./tifftest image.tiff
Image width: 3
Image hight: 2
X Resolution: 72 dpi
Y Resolution: 72 dpi
*/
Note: See also TIFF_in_C on StackOverflow.
Chapter_2 test | BACK_TO_TOP | RTLD |
Comments
Post a Comment