29 #include <vigra/tiff.hxx>
30 #include <vigra/imageinfo.hxx>
31 #include <vigra/transformimage.hxx>
32 #include <vigra/functorexpression.hxx>
59 const std::string & documentname,
60 const std::string comp,
61 uint16_t page, uint16_t nImg,
63 vigra::Size2D fullSize,
64 const vigra::ImageExportInfo::ICCProfile & icc)
66 const float dpi = 150;
77 TIFFCreateDirectory (tiff);
79 TIFFSetField (tiff, TIFFTAG_SUBFILETYPE, FILETYPE_PAGE);
80 TIFFSetField (tiff, TIFFTAG_PAGENUMBER, (
unsigned short)page, (
unsigned short)nImg);
82 TIFFSetField (tiff, TIFFTAG_XRESOLUTION, (
float) dpi);
83 TIFFSetField (tiff, TIFFTAG_YRESOLUTION, (
float) dpi);
87 TIFFSetField (tiff, TIFFTAG_XPOSITION, (
float)(offset.x / dpi));
88 TIFFSetField (tiff, TIFFTAG_YPOSITION, (
float)(offset.y / dpi));
95 TIFFSetField(tiff, TIFFTAG_PIXAR_IMAGEFULLWIDTH, fullSize.x);
96 TIFFSetField(tiff, TIFFTAG_PIXAR_IMAGEFULLLENGTH, fullSize.y);
99 TIFFSetField (tiff, TIFFTAG_DOCUMENTNAME, documentname.c_str());
100 TIFFSetField (tiff, TIFFTAG_PAGENAME, pagename.c_str() );
102 TIFFSetField (tiff, TIFFTAG_IMAGEDESCRIPTION,
"stitched with hugin");
105 unsigned short tiffcomp;
106 if ( comp ==
"JPEG" )
107 tiffcomp = COMPRESSION_OJPEG;
108 else if ( comp ==
"LZW" )
109 tiffcomp = COMPRESSION_LZW;
110 else if ( comp ==
"DEFLATE" )
111 tiffcomp = COMPRESSION_DEFLATE;
112 else if ( comp ==
"PACKBITS" )
113 tiffcomp = COMPRESSION_PACKBITS;
115 tiffcomp = COMPRESSION_NONE;
117 TIFFSetField(tiff, TIFFTAG_COMPRESSION, tiffcomp);
122 TIFFSetField(tiff, TIFFTAG_ICCPROFILE, icc.size(), icc.begin());
129 template <
class ImageIterator,
class ImageAccessor,
130 class AlphaIterator,
class AlphaAccessor>
134 AlphaIterator alphaUpperleft, AlphaAccessor alphaA,
135 vigra::TiffImage * tiff,
int sampleformat)
137 typedef typename ImageAccessor::value_type PixelType;
139 int w = lowerright.x - upperleft.x;
140 int h = lowerright.y - upperleft.y;
142 TIFFSetField(tiff, TIFFTAG_IMAGEWIDTH, w);
143 TIFFSetField(tiff, TIFFTAG_IMAGELENGTH, h);
144 TIFFSetField(tiff, TIFFTAG_BITSPERSAMPLE,
sizeof(PixelType) * 8);
145 TIFFSetField(tiff, TIFFTAG_SAMPLESPERPIXEL, 2);
146 TIFFSetField(tiff, TIFFTAG_PLANARCONFIG, PLANARCONFIG_CONTIG);
147 TIFFSetField(tiff, TIFFTAG_SAMPLEFORMAT, sampleformat);
148 TIFFSetField(tiff, TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_MINISBLACK);
149 TIFFSetField(tiff, TIFFTAG_ROWSPERSTRIP, 1);
153 uint16_t nextra_samples = 1;
154 uint16_t extra_samples = EXTRASAMPLE_UNASSALPHA;
155 TIFFSetField (tiff, TIFFTAG_EXTRASAMPLES, nextra_samples, &extra_samples);
157 int bufsize = TIFFScanlineSize(tiff);
158 tdata_t * buf =
new tdata_t[bufsize];
160 ImageIterator ys(upperleft);
161 AlphaIterator ya(alphaUpperleft);
165 for(
int y=0; y<
h; ++y, ++ys.y, ++ya.y)
167 PixelType * pg = (PixelType *)buf;
168 PixelType * alpha = pg+1;
170 ImageIterator xs(ys);
171 AlphaIterator xa(ya);
173 for(
int x=0; x<w; ++x, ++xs.x, pg+=2, alpha+=2, ++xa.x)
178 TIFFWriteScanline(tiff, buf, y);
190 template <
class ImageIterator,
class ImageAccessor,
191 class AlphaIterator,
class AlphaAccessor>
195 AlphaIterator alphaUpperleft, AlphaAccessor alphaA,
196 vigra::TiffImage * tiff,
int sampleformat)
198 typedef typename ImageAccessor::value_type PType;
199 typedef typename PType::value_type PixelType;
201 int w = lowerright.x - upperleft.x;
202 int h = lowerright.y - upperleft.y;
204 TIFFSetField(tiff, TIFFTAG_IMAGEWIDTH, w);
205 TIFFSetField(tiff, TIFFTAG_IMAGELENGTH, h);
206 TIFFSetField(tiff, TIFFTAG_BITSPERSAMPLE,
sizeof(PixelType) * 8);
207 TIFFSetField(tiff, TIFFTAG_SAMPLESPERPIXEL, 4);
208 TIFFSetField(tiff, TIFFTAG_PLANARCONFIG, PLANARCONFIG_CONTIG);
209 TIFFSetField(tiff, TIFFTAG_SAMPLEFORMAT, sampleformat);
210 TIFFSetField(tiff, TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_RGB);
211 TIFFSetField(tiff, TIFFTAG_ROWSPERSTRIP, 1);
215 uint16_t nextra_samples = 1;
216 uint16_t extra_samples = EXTRASAMPLE_UNASSALPHA;
217 TIFFSetField (tiff, TIFFTAG_EXTRASAMPLES, nextra_samples, &extra_samples);
219 int bufsize = TIFFScanlineSize(tiff);
220 tdata_t * buf =
new tdata_t[bufsize];
222 ImageIterator ys(upperleft);
223 AlphaIterator ya(alphaUpperleft);
227 for(
int y=0; y<
h; ++y, ++ys.y, ++ya.y)
229 PixelType * pr = (PixelType *)buf;
230 PixelType * pg = pr+1;
231 PixelType * pb = pg+1;
232 PixelType * alpha = pb+1;
234 ImageIterator xs(ys);
235 AlphaIterator xa(ya);
237 for(
int x=0; x<w; ++x, ++xs.x, pr+=4, pg+=4, pb+=4, alpha+=4, ++xa.x)
244 TIFFWriteScanline(tiff, buf, y);
265 template <
class ImageIterator,
class ImageAccessor,
266 class AlphaIterator,
class AlphaAccessor>
267 static void exec(ImageIterator iUL, ImageIterator iLR,
271 vigra::TiffImage * tiff)
281 template <
class ImageIterator,
class ImageAccessor,
282 class AlphaIterator,
class AlphaAccessor>
283 static void exec(ImageIterator iUL, ImageIterator iLR,
287 vigra::TiffImage * tiff)
291 mA(vigra::ScalarIntensityTransform<short>(128), aA);
293 tiff, SAMPLEFORMAT_INT);
300 template <
class ImageIterator,
class ImageAccessor,
301 class AlphaIterator,
class AlphaAccessor>
302 static void exec(ImageIterator iUL, ImageIterator iLR,
306 vigra::TiffImage * tiff)
309 mA(vigra::ScalarIntensityTransform<unsigned short>(256), aA);
311 tiff, SAMPLEFORMAT_UINT);
320 template <
class ImageIterator,
class ImageAccessor,
321 class AlphaIterator,
class AlphaAccessor>
322 static void exec(ImageIterator iUL, ImageIterator iLR,
326 vigra::TiffImage * tiff)
329 mA(vigra::ScalarIntensityTransform<int>(8388608), aA);
331 tiff, SAMPLEFORMAT_INT);
338 template <
class ImageIterator,
class ImageAccessor,
339 class AlphaIterator,
class AlphaAccessor>
340 static void exec(ImageIterator iUL, ImageIterator iLR,
344 vigra::TiffImage * tiff)
347 mA(vigra::ScalarIntensityTransform<unsigned int>(16777216), aA);
349 tiff, SAMPLEFORMAT_UINT);
357 template <
class ImageIterator,
class ImageAccessor,
358 class AlphaIterator,
class AlphaAccessor>
359 static void exec(ImageIterator iUL, ImageIterator iLR,
363 vigra::TiffImage * tiff)
366 mA(vigra::ScalarIntensityTransform<float>(1.0f/255), aA);
368 tiff, SAMPLEFORMAT_IEEEFP);
376 template <
class ImageIterator,
class ImageAccessor,
377 class AlphaIterator,
class AlphaAccessor>
378 static void exec(ImageIterator iUL, ImageIterator iLR,
382 vigra::TiffImage * tiff)
385 mA(vigra::ScalarIntensityTransform<double>(1.0f/255),aA);
387 tiff, SAMPLEFORMAT_IEEEFP);
399 template <
class ImageIterator,
class ImageAccessor,
400 class AlphaIterator,
class AlphaAccessor>
401 static void exec(ImageIterator iUL, ImageIterator iLR,
405 vigra::TiffImage * tiff)
415 template <
class ImageIterator,
class ImageAccessor,
416 class AlphaIterator,
class AlphaAccessor>
417 static void exec(ImageIterator iUL, ImageIterator iLR,
421 vigra::TiffImage * tiff)
424 mA(vigra::ScalarIntensityTransform<short>(128), aA);
431 template <
class ImageIterator,
class ImageAccessor,
432 class AlphaIterator,
class AlphaAccessor>
433 static void exec(ImageIterator iUL, ImageIterator iLR,
437 vigra::TiffImage * tiff)
440 mA(vigra::ScalarIntensityTransform<unsigned short>(256), aA);
449 template <
class ImageIterator,
class ImageAccessor,
450 class AlphaIterator,
class AlphaAccessor>
451 static void exec(ImageIterator iUL, ImageIterator iLR,
455 vigra::TiffImage * tiff)
458 mA(vigra::ScalarIntensityTransform<int>(8388608), aA);
466 template <
class ImageIterator,
class ImageAccessor,
467 class AlphaIterator,
class AlphaAccessor>
468 static void exec(ImageIterator iUL, ImageIterator iLR,
472 vigra::TiffImage * tiff)
475 mA(vigra::ScalarIntensityTransform<unsigned int>(16777216), aA);
484 template <
class ImageIterator,
class ImageAccessor,
485 class AlphaIterator,
class AlphaAccessor>
486 static void exec(ImageIterator iUL, ImageIterator iLR,
490 vigra::TiffImage * tiff)
493 mA(vigra::ScalarIntensityTransform<float>(1.0f/255), aA);
502 template <
class ImageIterator,
class ImageAccessor,
503 class AlphaIterator,
class AlphaAccessor>
504 static void exec(ImageIterator iUL, ImageIterator iLR,
508 vigra::TiffImage * tiff)
511 mA(vigra::ScalarIntensityTransform<double>(1.0f/255), aA);
519 template <
class ImageIterator,
class ImageAccessor,
520 class AlphaIterator,
class AlphaAccessor>
524 AlphaIterator alphaUpperleft, AlphaAccessor alphaA,
525 vigra::TiffImage * tiff)
529 exec(upperleft, lowerright, a,
530 alphaUpperleft, alphaA, tiff);
542 template <
class ImageIterator,
class ImageAccessor,
543 class AlphaIterator,
class BImageAccessor>
547 vigra::pair<AlphaIterator, BImageAccessor> alpha,
548 vigra::TiffImage * tiff)
551 alpha.first, alpha.second, tiff);
566 #endif // _TIFFUTILS_H
static void exec(ImageIterator iUL, ImageIterator iLR, ImageAccessor iA, AlphaIterator aUL, AlphaAccessor aA, vigra::TiffImage *tiff)
static void exec(ImageIterator iUL, ImageIterator iLR, ImageAccessor iA, AlphaIterator aUL, AlphaAccessor aA, vigra::TiffImage *tiff)
static void exec(ImageIterator iUL, ImageIterator iLR, ImageAccessor iA, AlphaIterator aUL, AlphaAccessor aA, vigra::TiffImage *tiff)
static void exec(ImageIterator iUL, ImageIterator iLR, ImageAccessor iA, AlphaIterator aUL, AlphaAccessor aA, vigra::TiffImage *tiff)
#define DEBUG_ASSERT(cond)
static void exec(ImageIterator iUL, ImageIterator iLR, ImageAccessor iA, AlphaIterator aUL, AlphaAccessor aA, vigra::TiffImage *tiff)
static void exec(ImageIterator iUL, ImageIterator iLR, ImageAccessor iA, AlphaIterator aUL, AlphaAccessor aA, vigra::TiffImage *tiff)
static void exec(ImageIterator iUL, ImageIterator iLR, ImageAccessor iA, AlphaIterator aUL, AlphaAccessor aA, vigra::TiffImage *tiff)
void createAlphaTiffImage(ImageIterator upperleft, ImageIterator lowerright, ImageAccessor a, AlphaIterator alphaUpperleft, AlphaAccessor alphaA, vigra::TiffImage *tiff)
static void exec(ImageIterator iUL, ImageIterator iLR, ImageAccessor iA, AlphaIterator aUL, AlphaAccessor aA, vigra::TiffImage *tiff)
void createTiffDirectory(vigra::TiffImage *tiff, const std::string &pagename, const std::string &documentname, const std::string comp, uint16_t page, uint16_t nImg, vigra::Diff2D offset, vigra::Size2D fullSize, const vigra::ImageExportInfo::ICCProfile &icc)
write a new Tiff directory, for a new layer
static void createScalarATiffImage(ImageIterator upperleft, ImageIterator lowerright, ImageAccessor a, AlphaIterator alphaUpperleft, AlphaAccessor alphaA, vigra::TiffImage *tiff, int sampleformat)
internal function to create a scalar tiff image with alpha channel
static void exec(ImageIterator iUL, ImageIterator iLR, ImageAccessor iA, AlphaIterator aUL, AlphaAccessor aA, vigra::TiffImage *tiff)
This class can be used to apply a function when reading the input image.
static void exec(ImageIterator iUL, ImageIterator iLR, ImageAccessor iA, AlphaIterator aUL, AlphaAccessor aA, vigra::TiffImage *tiff)
static void exec(ImageIterator iUL, ImageIterator iLR, ImageAccessor iA, AlphaIterator aUL, AlphaAccessor aA, vigra::TiffImage *tiff)
static void exec(ImageIterator iUL, ImageIterator iLR, ImageAccessor iA, AlphaIterator aUL, AlphaAccessor aA, vigra::TiffImage *tiff)
void createRGBATiffImage(ImageIterator upperleft, ImageIterator lowerright, ImageAccessor a, AlphaIterator alphaUpperleft, AlphaAccessor alphaA, vigra::TiffImage *tiff, int sampleformat)
internal function to create a RGB tiff image with alpha channel
static void exec(ImageIterator iUL, ImageIterator iLR, ImageAccessor iA, AlphaIterator aUL, AlphaAccessor aA, vigra::TiffImage *tiff)
static void exec(ImageIterator iUL, ImageIterator iLR, ImageAccessor iA, AlphaIterator aUL, AlphaAccessor aA, vigra::TiffImage *tiff)