本文整理汇总了C++中TIFFSetDirectory函数的典型用法代码示例。如果您正苦于以下问题:C++ TIFFSetDirectory函数的具体用法?C++ TIFFSetDirectory怎么用?C++ TIFFSetDirectory使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了TIFFSetDirectory函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: tif_DirCount
tdir_t tif_DirCount(TIFF* tif)
{
tdir_t dirCurrent = TIFFCurrentDirectory(tif);
int dirCount = 0;
TIFFSetDirectory(tif, 0);
do{
dirCount++;
}
while(TIFFReadDirectory(tif));
TIFFSetDirectory(tif, dirCurrent);
return dirCount;
}
示例2: raster_special
static void
raster_special(int key, int x, int y)
{
(void) x;
(void) y;
switch (key) {
case GLUT_KEY_PAGE_UP: /* previous logical image */
if (TIFFCurrentDirectory(tif) > 0) {
if (TIFFSetDirectory(tif,
TIFFCurrentDirectory(tif)-1)) {
initImage();
setWindowSize();
}
} else {
TIFFRGBAImageEnd(&img);
prevImage();
initImage();
setWindowSize();
}
break;
case GLUT_KEY_PAGE_DOWN: /* next logical image */
if (!TIFFLastDirectory(tif)) {
if (TIFFReadDirectory(tif)) {
initImage();
setWindowSize();
}
} else {
TIFFRGBAImageEnd(&img);
nextImage();
initImage();
setWindowSize();
}
break;
case GLUT_KEY_HOME: /* 1st image in current file */
if (TIFFSetDirectory(tif, 0)) {
TIFFRGBAImageEnd(&img);
initImage();
setWindowSize();
}
break;
case GLUT_KEY_END: /* last image in current file */
TIFFRGBAImageEnd(&img);
while (!TIFFLastDirectory(tif))
TIFFReadDirectory(tif);
initImage();
setWindowSize();
break;
}
glutPostRedisplay();
}
示例3: paint_region
static bool paint_region(openslide_t *osr, cairo_t *cr,
int64_t x, int64_t y,
struct _openslide_level *level,
int32_t w, int32_t h,
GError **err) {
struct generic_tiff_ops_data *data = osr->data;
struct level *l = (struct level *) level;
bool success = false;
TIFF *tiff = _openslide_tiffcache_get(data->tc, err);
if (tiff == NULL) {
return false;
}
if (TIFFSetDirectory(tiff, l->tiffl.dir)) {
success = _openslide_grid_paint_region(l->grid, cr, tiff,
x / l->base.downsample,
y / l->base.downsample,
level, w, h,
err);
} else {
g_set_error(err, OPENSLIDE_ERROR, OPENSLIDE_ERROR_FAILED,
"Cannot set TIFF directory");
}
_openslide_tiffcache_put(data->tc, tiff);
return success;
}
示例4: TIFFSetWarningHandler
void *image_read_tif(const char *name, int *w, int *h, int *c, int *b, int n)
{
TIFF *T = 0;
void *p = 0;
TIFFSetWarningHandler(0);
if ((T = TIFFOpen(name, "r")))
{
if ((n == 0) || TIFFSetDirectory(T, n))
{
uint32 i, s = (uint32) TIFFScanlineSize(T);
uint32 W, H;
uint16 B, C;
TIFFGetField(T, TIFFTAG_IMAGEWIDTH, &W);
TIFFGetField(T, TIFFTAG_IMAGELENGTH, &H);
TIFFGetField(T, TIFFTAG_BITSPERSAMPLE, &B);
TIFFGetField(T, TIFFTAG_SAMPLESPERPIXEL, &C);
if ((p = malloc(H * s)))
{
for (i = 0; i < H; ++i)
TIFFReadScanline(T, (uint8 *) p + i * s, i, 0);
*w = (int) W;
*h = (int) H;
*b = (int) B / 8;
*c = (int) C;
}
}
TIFFClose(T);
}
return p;
}
示例5: _declspec
_declspec (dllexport) int readImage(TIFF* tif, // TIFF handle - IN
const int directory, // page ordinal number - IN
uint8_t* redvals) // OUT, caller allocates memory
{
TIFFSetDirectory(tif, directory);
int err = 0;
uint32_t w, h;
size_t npixels;
TIFFGetField(tif, TIFFTAG_IMAGEWIDTH, &w);
TIFFGetField(tif, TIFFTAG_IMAGELENGTH, &h);
//TIFFGetField(tif, TIFFTAG_BITSPERSAMPLE, bits);
npixels = w * h;
uint32_t* raster = (uint32_t*) _TIFFmalloc(npixels * sizeof (uint32_t));
if (raster != NULL) {
err = TIFFReadRGBAImage(tif, w, h, raster, 1);
if (err != 1) {
return err;
}
uint32_t* pFrom = raster;
uint8_t* pTo = redvals;
for (int i = 0; i < npixels; i++, ++pFrom) {
*pTo++ = (uint8_t) TIFFGetR(*pFrom);
}
}
_TIFFfree(raster);
return err;
}
示例6: TIFFSetDirectory
char *appendSlice2Tiff3DFile ( void *fhandler, int slice, unsigned char *img, unsigned int img_width, unsigned int img_height, int spp, int bpp, int NPages ) {
TIFF *output = (TIFF *) fhandler;
TIFFSetDirectory(output,slice); // WARNING: slice must be the first page after the last, otherwise the file can be corrupted
TIFFSetField(output, TIFFTAG_IMAGEWIDTH, img_width);
TIFFSetField(output, TIFFTAG_IMAGELENGTH, img_height);
TIFFSetField(output, TIFFTAG_BITSPERSAMPLE, (uint16)bpp);
TIFFSetField(output, TIFFTAG_SAMPLESPERPIXEL, (uint16)spp);
TIFFSetField(output, TIFFTAG_ROWSPERSTRIP, img_height);
TIFFSetField(output, TIFFTAG_COMPRESSION, COMPRESSION_LZW);
//TIFFSetField(output, TIFFTAG_COMPRESSION, COMPRESSION_NONE);
TIFFSetField(output, TIFFTAG_PLANARCONFIG,PLANARCONFIG_CONTIG);
TIFFSetField(output, TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_MINISBLACK);
//TIFFSetField(output, TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_RGB);
// We are writing single page of the multipage file
TIFFSetField(output, TIFFTAG_SUBFILETYPE, FILETYPE_PAGE);
TIFFSetField(output, TIFFTAG_PAGENUMBER, (uint16)slice, (uint16)NPages);
TIFFWriteEncodedStrip(output, 0, img, img_width * img_height * spp * (bpp/8));
//img += img_width * img_height;
TIFFWriteDirectory(output);
return (char *) 0;
}
示例7: lock
bool
TIFFInput::seek_subimage (int subimage, int miplevel, ImageSpec &newspec)
{
if (subimage < 0) // Illegal
return false;
if (m_emulate_mipmap) {
// Emulating MIPmap? Pretend one subimage, many MIP levels.
if (subimage != 0)
return false;
subimage = miplevel;
} else {
// No MIPmap emulation
if (miplevel != 0)
return false;
}
if (subimage == m_subimage) {
// We're already pointing to the right subimage
newspec = m_spec;
return true;
}
// If we're emulating a MIPmap, only resolution is allowed to change
// between MIP levels, so if we already have a valid level in m_spec,
// we don't need to re-parse metadata, it's guaranteed to be the same.
bool read_meta = !(m_emulate_mipmap && m_tif && m_subimage >= 0);
if (! m_tif) {
// Use our own error handler to keep libtiff from spewing to stderr
lock_guard lock (lasterr_mutex);
TIFFSetErrorHandler (my_error_handler);
TIFFSetWarningHandler (my_error_handler);
}
if (! m_tif) {
m_tif = TIFFOpen (m_filename.c_str(), "rm");
if (m_tif == NULL) {
error ("Could not open file: %s",
lasterr.length() ? lasterr.c_str() : m_filename.c_str());
return false;
}
m_subimage = 0;
}
m_next_scanline = 0; // next scanline we'll read
if (TIFFSetDirectory (m_tif, subimage)) {
m_subimage = subimage;
readspec (read_meta);
newspec = m_spec;
if (newspec.format == TypeDesc::UNKNOWN) {
error ("No support for data format of \"%s\"", m_filename.c_str());
return false;
}
return true;
} else {
error ("%s", lasterr.length() ? lasterr.c_str() : m_filename.c_str());
m_subimage = -1;
return false;
}
}
示例8: TIFFSetDirectory
char *appendSlice2Tiff3DFile ( void *fhandler, int slice, unsigned char *img, unsigned int img_width, unsigned int img_height, int spp, int bpp, int NPages ) {
TIFF *output = (TIFF *) fhandler;
TIFFSetDirectory(output,slice); // WARNING: slice must be the first page after the last, otherwise the file can be corrupted
TIFFSetField(output, TIFFTAG_IMAGEWIDTH, img_width);
TIFFSetField(output, TIFFTAG_IMAGELENGTH, img_height);
TIFFSetField(output, TIFFTAG_BITSPERSAMPLE, (uint16)bpp);
TIFFSetField(output, TIFFTAG_SAMPLESPERPIXEL, (uint16)spp);
TIFFSetField(output, TIFFTAG_ROWSPERSTRIP, (rowsPerStrip == -1) ? img_height : rowsPerStrip);
TIFFSetField(output, TIFFTAG_ORIENTATION, ORIENTATION_TOPLEFT);
TIFFSetField(output, TIFFTAG_COMPRESSION, COMPRESSION_LZW);
//TIFFSetField(output, TIFFTAG_COMPRESSION, COMPRESSION_NONE);
TIFFSetField(output, TIFFTAG_PLANARCONFIG,PLANARCONFIG_CONTIG);
TIFFSetField(output, TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_MINISBLACK);
//TIFFSetField(output, TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_RGB);
// We are writing single page of the multipage file
TIFFSetField(output, TIFFTAG_SUBFILETYPE, FILETYPE_PAGE);
TIFFSetField(output, TIFFTAG_PAGENUMBER, (uint16)slice, (uint16)NPages);
if ( rowsPerStrip == -1 )
TIFFWriteEncodedStrip(output, 0, img, img_width * img_height * spp * (bpp/8));
else {
int check,StripsPerImage,LastStripSize;
uint32 rps = rowsPerStrip;
unsigned char *buf = img;
StripsPerImage = (img_height + rps - 1) / rps;
LastStripSize = img_height % rps;
if (LastStripSize==0)
LastStripSize=rps;
for (int i=0; i < StripsPerImage-1; i++){
//if (comp==1) {
// TIFFReadRawStrip(input, i, buf, spp * rps * img_width * (bpp/8));
// buf = buf + spp * rps * img_width * (bpp/8);
//}
//else{
TIFFWriteEncodedStrip(output, i, buf, spp * rps * img_width * (bpp/8));
buf = buf + spp * rps * img_width * (bpp/8);
//}
}
//if (comp==1) {
// TIFFReadRawStrip(input, StripsPerImage-1, buf, spp * LastStripSize * img_width * (bpp/8));
//}
//else{
TIFFReadEncodedStrip(output, StripsPerImage-1, buf, spp * LastStripSize * img_width * (bpp/8));
//}
buf = buf + spp * LastStripSize * img_width * (bpp/8);
}
//img += img_width * img_height;
TIFFWriteDirectory(output);
return (char *) 0;
}
示例9: Java_com_troop_androiddng_RawToDng_WriteDNG
JNIEXPORT void JNICALL Java_com_troop_androiddng_RawToDng_WriteDNG(JNIEnv *env, jobject thiz, jobject handler)
{
uint64 dir_offset = 0, dir_offset2 = 0, gpsIFD_offset = 0;
DngWriter* writer = (DngWriter*) env->GetDirectBufferAddress(handler);
FILE* fptr = fopen(writer->fileSavePath,"w+");
writeIfd0(fptr, writer);
TIFFSetField (tif, TIFFTAG_EXIFIFD, dir_offset);
LOGD("set exif");
//CheckPOINT to KEEP EXIF IFD in MEMory
//Try FiX DIR
if(writer->gps == true)
{
makeGPS_IFD(tif, writer);
TIFFCheckpointDirectory(tif);
TIFFWriteCustomDirectory(tif, &gpsIFD_offset);
TIFFSetDirectory(tif, 0);
}
writeExifIfd(tif,writer);
//Check Point & Write are require checkpoint to update Current IFD Write Well to Write Close And Create IFD
TIFFCheckpointDirectory(tif); //This Was missing it without it EXIF IFD was not being updated after adding SUB IFD
TIFFWriteCustomDirectory(tif, &dir_offset);
///////////////////// GO Back TO IFD 0
TIFFSetDirectory(tif, 0);
if(writer->gps)
TIFFSetField (tif, TIFFTAG_GPSIFD, gpsIFD_offset);
///////////////////////////// WRITE THE SUB IFD's SUB IFD + EXIF IFD AGain GPS IFD would also go here as well as other cust IFD
TIFFSetField(tif, TIFFTAG_EXIFIFD, dir_offset);
writeRawStuff(tif,writer);
if (writer->bayerBytes == NULL)
return;
delete[] writer->bayerBytes;
writer->bayerBytes = NULL;
}
示例10: lock
bool
TIFFInput::seek_subimage (int subimage, int miplevel, ImageSpec &newspec)
{
if (subimage < 0) // Illegal
return false;
if (m_emulate_mipmap) {
// Emulating MIPmap? Pretend one subimage, many MIP levels.
if (subimage != 0)
return false;
subimage = miplevel;
} else {
// No MIPmap emulation
if (miplevel != 0)
return false;
}
if (subimage == m_subimage) {
// We're already pointing to the right subimage
newspec = m_spec;
return true;
}
if (! m_tif) {
// Use our own error handler to keep libtiff from spewing to stderr
lock_guard lock (lasterr_mutex);
TIFFSetErrorHandler (my_error_handler);
TIFFSetWarningHandler (my_error_handler);
}
if (! m_tif) {
m_tif = TIFFOpen (m_filename.c_str(), "rm");
if (m_tif == NULL) {
error ("Could not open file: %s",
lasterr.length() ? lasterr.c_str() : m_filename.c_str());
return false;
}
m_subimage = 0;
}
m_next_scanline = 0; // next scanline we'll read
if (TIFFSetDirectory (m_tif, subimage)) {
m_subimage = subimage;
readspec ();
newspec = m_spec;
if (newspec.format == TypeDesc::UNKNOWN) {
error ("No support for data format of \"%s\"", m_filename.c_str());
return false;
}
return true;
} else {
error ("%s", lasterr.length() ? lasterr.c_str() : m_filename.c_str());
m_subimage = -1;
return false;
}
}
示例11: openIndex
ome::compat::shared_ptr<IFD>
TIFF::getDirectoryByIndex(directory_index_type index) const
{
Sentry sentry;
if (!TIFFSetDirectory(impl->tiff, index))
sentry.error();
ome::compat::shared_ptr<TIFF> t(ome::compat::const_pointer_cast<TIFF>(shared_from_this()));
return IFD::openIndex(t, index);
}
示例12: findPage
int
findPage(TIFF* tif, int pageNumber)
{
uint16 pn = (uint16) -1;
uint16 ptotal = (uint16) -1;
if (GetPageNumber(tif)) {
while (pn != pageNumber && TIFFReadDirectory(tif) && GetPageNumber(tif))
;
return (pn == pageNumber);
} else
return (TIFFSetDirectory(tif, pageNumber-1));
}
示例13: tif_load
/* tif load function */
int tif_load(uint16 *image)
{
int r, c; // height index, width index
uint16 s;
uint16 *scanline;
long int image_offset;
if((scanline = (uint16 *)_TIFFmalloc(info->line_size)) == NULL){
fprintf(stderr, "Could not allocate enough memory for the scan buffer!\n");
exit(42);
}
image_offset = 0;
printf("-- loading tif files ... \n");
TIFFSetDirectory(tif, 0);
do {
if (info->config == PLANARCONFIG_CONTIG){
for(r = 0; r < info->length; r++){
TIFFReadScanline(tif, scanline, r, s);
for(c = 0; c < info->width; c++)
{
image[image_offset + info->width * r + c] = *(scanline + c);
}
}
} else if (info->config == PLANARCONFIG_SEPARATE){
for(s = 0; s < info->spp; s++){
for(r = 0; r < info->length; r++){
TIFFReadScanline(tif, scanline, r, s);
for(c = 0; c < info->width; c++)
{
image[image_offset + info->width * r + c] = *(scanline + c);
}
}
}
}
image_offset += info->image_size/sizeof(uint16);
} while (TIFFReadDirectory(tif));
_TIFFfree(scanline);
TIFFClose(tif);
return 0;
}
示例14: get_tiff_total_pages
int get_tiff_total_pages(const char *file)
{
TIFF *tiff_file;
int max;
if ((tiff_file = TIFFOpen(file, "r")) == NULL)
return -1;
/* Each page *should* contain the total number of pages, but can this be
trusted? Some files say 0. Actually searching for the last page is
more reliable. */
max = 0;
while (TIFFSetDirectory(tiff_file, (tdir_t) max))
max++;
TIFFClose(tiff_file);
return max;
}
示例15: write_tiff_image
static int write_tiff_image(t4_rx_state_t *s)
{
t4_rx_tiff_state_t *t;
#if defined(SPANDSP_SUPPORT_TIFF_FX)
uint64_t offset;
#endif
t = &s->tiff;
if (t->image_buffer == NULL || t->image_size <= 0)
return -1;
/* Set up the TIFF directory info... */
set_tiff_directory_info(s);
/* ...Put the directory in the file before the image data, to get them in the order specified
for TIFF/F files... */
if (!TIFFCheckpointDirectory(t->tiff_file))
span_log(&s->logging, SPAN_LOG_WARNING, "%s: Failed to checkpoint directory for page %d.\n", t->file, s->current_page);
/* ...and write out the image... */
if (TIFFWriteEncodedStrip(t->tiff_file, 0, t->image_buffer, t->image_size) < 0)
span_log(&s->logging, SPAN_LOG_WARNING, "%s: Error writing TIFF strip.\n", t->file);
/* ...then finalise the directory entry, and libtiff is happy. */
if (!TIFFWriteDirectory(t->tiff_file))
span_log(&s->logging, SPAN_LOG_WARNING, "%s: Failed to write directory for page %d.\n", t->file, s->current_page);
#if defined(SPANDSP_SUPPORT_TIFF_FX)
if (s->current_page == 0)
{
if (!TIFFCreateCustomDirectory(t->tiff_file, &tiff_fx_field_array))
{
TIFFSetField(t->tiff_file, TIFFTAG_FAXPROFILE, PROFILETYPE_G3_FAX);
TIFFSetField(t->tiff_file, TIFFTAG_PROFILETYPE, FAXPROFILE_F);
TIFFSetField(t->tiff_file, TIFFTAG_VERSIONYEAR, "1998");
offset = 0;
if (!TIFFWriteCustomDirectory(t->tiff_file, &offset))
printf("Failed to write custom directory.\n");
/* Now go back and patch in the pointer to the new IFD */
if (!TIFFSetDirectory(t->tiff_file, s->current_page))
printf("Failed to set directory.\n");
if (!TIFFSetField(t->tiff_file, TIFFTAG_GLOBALPARAMETERSIFD, offset))
printf("Failed to set field.\n");
if (!TIFFWriteDirectory(t->tiff_file))
span_log(&s->logging, SPAN_LOG_WARNING, "%s: Failed to write directory for page %d.\n", t->file, s->current_page);
}
}
#endif
return 0;
}