/* * Deal the stacks into separated files and append them. */ void dealStack(const fs::path &outdir, const std::string &prefix, const fs::path &imgPath, const uint16_t nLayer) { TIFF *in, *out; static uint16_t iLayer = 0; // Suppress the warnings. TIFFErrorHandler oldhandler = TIFFSetWarningHandler(NULL); // Open the file. in = TIFFOpen(imgPath.string().c_str(), "r"); if (in == NULL) { std::cerr << "Unable to read " << imgPath.filename() << std::endl; return; } // Identify the read mode. static char mode[3] = { 'x', 'b', 0 }; // Overwrite on the first run, and append for rest of the page. mode[0] = (mode[0] == 'x') ? 'w' : 'a'; mode[1] = (TIFFIsBigEndian(in)) ? 'b' : 'l'; // Iterate through the directories. int iFile = 0; do { std::string s = genPath(outdir, prefix, iFile); out = TIFFOpen(s.c_str(), mode); try { if (out == NULL) { throw -1; } else if (!cpTiff(in, out, iLayer, nLayer)) { throw -2; } } catch (int e) { if (e == -1) { std::cerr << "Unable to create output file" << std::endl; } else if (e == -2) { std::cerr << "Unable to copy the layer" << std::endl; } else { std::cerr << "Unknown error" << std::endl; } TIFFClose(in); TIFFClose(out); return; } TIFFClose(out); iFile++; } while (TIFFReadDirectory(in)); // Increment the layer variable for next write. iLayer++; TIFFClose(in); // Restore the warning. TIFFSetWarningHandler(oldhandler); }
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; } }
Tiio::Reader *Tiio::makeTziReader() { #ifdef _DEBUG TIFFSetErrorHandler(MyErrorHandler); TIFFSetWarningHandler(MyWarningHandler); #endif return new TifReader(true); }
void image_write_tif(const char *name, int w, int h, int c, int b, int n, void **p) { TIFF *T = 0; TIFFSetWarningHandler(0); if ((T = TIFFOpen(name, "w"))) { uint32 k, i, s; for (k = 0; k < n; ++k) { TIFFSetField(T, TIFFTAG_IMAGEWIDTH, w); TIFFSetField(T, TIFFTAG_IMAGELENGTH, h); TIFFSetField(T, TIFFTAG_BITSPERSAMPLE, 8*b); TIFFSetField(T, TIFFTAG_SAMPLESPERPIXEL, c); TIFFSetField(T, TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_RGB); TIFFSetField(T, TIFFTAG_PLANARCONFIG, PLANARCONFIG_CONTIG); TIFFSetField(T, TIFFTAG_ICCPROFILE, sRGB_icc_len, sRGB_icc); if (b == 4) TIFFSetField(T, TIFFTAG_SAMPLEFORMAT, SAMPLEFORMAT_IEEEFP); s = (uint32) TIFFScanlineSize(T); for (i = 0; i < h; ++i) TIFFWriteScanline(T, (uint8 *) p[k] + (h - i - 1) * s, i, 0); TIFFWriteDirectory(T); } TIFFClose(T); } }
// Read 3D image data unsigned char * // (OUTPUT) buffer containing the read image data iomanager::tiff3D::readData( std::string img_path, // (INPUT) image filepath int & img_width, // (INPUT/OUTPUT) image width (in pixels) int & img_height, // (INPUT/OUTPUT) image height (in pixels) int & img_depth, // (INPUT/OUTPUT) image depth (in pixels) int & img_bytes_x_chan, // (INPUT/OUTPUT) number of bytes per channel int & img_chans, // (INPUT/OUTPUT) number of channels to be read unsigned char *data, // (INPUT) image data int z0, // (INPUT) region of interest [x0,x1)[y0,y1)[z0,z1) to be set on the image int z1, // (INPUT) region of interest [x0,x1)[y0,y1)[z0,z1) to be set on the image const std::string & params) // (INPUT) additional parameters <param1=val, param2=val, ...> throw (iom::exception) { //throw iom::exception(iom::strprintf("not implemented yet"), __iom__current__function__); /**/iom::debug(iom::LEV3, iom::strprintf("img_path = %s, img_width = %d, img_height = %d, img_depth = %d, img_bytes_x_chan = %d, img_chans = %d, data = %p, z0 = %d, z1 = %d, params = \"%s\"", img_path.c_str(), img_width, img_height, img_depth, img_bytes_x_chan, img_chans, data, z0, z1, params.c_str()).c_str(), __iom__current__function__); //disable warning handler to avoid messages on unrecognized tags TIFFSetWarningHandler(0); unsigned int _width; unsigned int _height; unsigned int _depth; int _bytes_x_chan; unsigned int _chans; int b_swap; void *fhandle; int header_len; char *err_Tiff3Dfmt; if ( !data ) { // recover the metadata, allocate the buffer and set parameters if ( (err_Tiff3Dfmt = loadTiff3D2Metadata((char *)img_path.c_str(),_width,_height,_depth,_chans,_bytes_x_chan,b_swap,fhandle,header_len)) != 0 ) { throw iom::exception(iom::strprintf("(%s) unable to read meta data of tiff file %s",err_Tiff3Dfmt,img_path.c_str()), __iom__current__function__); } closeTiff3DFile(fhandle); data = new unsigned char[_width * _height * _depth * _chans * _bytes_x_chan]; img_width = _width; img_height = _height; img_depth = _depth; img_bytes_x_chan = _bytes_x_chan; img_chans = _chans; } // set the ROI z0 = (z0 < 0) ? 0: z0; z1 = (z1 < 0) ? img_depth : z1; if ( z0 >= z1 ) throw iom::exception(iom::strprintf("wrong slice indices (z0 = %d, z1 = %d)",z0, z1), __iom__current__function__); // get the image if ( (err_Tiff3Dfmt = readTiff3DFile2Buffer((char *)img_path.c_str(),data,img_width,img_height,z0,z1-1)) != 0 ) { throw iom::exception(iom::strprintf("(%s) unable to read tiff file %s in page range [%d,%d]",err_Tiff3Dfmt,img_path.c_str(),z0,z1-1), __iom__current__function__); } return data; }
TIFF * tiff_open (GFile *file, const gchar *mode, GError **error) { gchar *filename = g_file_get_path (file); TIFFSetWarningHandler (tiff_warning); TIFFSetErrorHandler (tiff_error); #ifdef G_OS_WIN32 gunichar2 *utf16_filename = g_utf8_to_utf16 (filename, -1, NULL, NULL, error); if (utf16_filename) { TIFF *tif = TIFFOpenW (utf16_filename, mode); g_free (utf16_filename); return tif; } return NULL; #else return TIFFOpen (filename, mode); #endif }
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; }
static void run (const gchar *name, gint nparams, const GimpParam *param, gint *nreturn_vals, GimpParam **return_vals) { static GimpParam values[2]; GimpPDBStatusType status = GIMP_PDB_SUCCESS; GimpParasite *parasite; gint32 image; gint32 drawable; gint32 orig_image; GimpExportReturn export = GIMP_EXPORT_CANCEL; GError *error = NULL; run_mode = param[0].data.d_int32; INIT_I18N (); gegl_init (NULL, NULL); *nreturn_vals = 1; *return_vals = values; values[0].type = GIMP_PDB_STATUS; values[0].data.d_status = GIMP_PDB_EXECUTION_ERROR; TIFFSetWarningHandler (tiff_warning); TIFFSetErrorHandler (tiff_error); if ((strcmp (name, SAVE_PROC) == 0) || (strcmp (name, SAVE2_PROC) == 0)) { /* Plug-in is either file_tiff_save or file_tiff_save2 */ image = orig_image = param[1].data.d_int32; drawable = param[2].data.d_int32; /* Do this right this time, if POSSIBLE query for parasites, otherwise or if there isn't one, choose the default comment from the gimprc. */ /* eventually export the image */ switch (run_mode) { case GIMP_RUN_INTERACTIVE: case GIMP_RUN_WITH_LAST_VALS: gimp_ui_init (PLUG_IN_BINARY, FALSE); export = gimp_export_image (&image, &drawable, NULL, (GIMP_EXPORT_CAN_HANDLE_RGB | GIMP_EXPORT_CAN_HANDLE_GRAY | GIMP_EXPORT_CAN_HANDLE_INDEXED | GIMP_EXPORT_CAN_HANDLE_ALPHA )); if (export == GIMP_EXPORT_CANCEL) { values[0].data.d_status = GIMP_PDB_CANCEL; return; } break; default: break; }
void sendRecvStatus(const char* modem, char* tag) { DIR* dir = opendir(FAX_RECVDIR); if (dir != NULL) { struct dirent* dp; TIFFSetErrorHandler(NULL); TIFFSetWarningHandler(NULL); while (dp = readdir(dir)) { char entry[1024]; struct stat sb; int fd; if (strncmp(dp->d_name, "fax", 3) != 0) continue; sprintf(entry, "%s/%s", FAX_RECVDIR, dp->d_name); if (stat(entry, &sb) < 0 || (sb.st_mode & S_IFMT) != S_IFREG) continue; fd = open(entry, RECV_OMODE); if (fd > 0) { int beingReceived = (flock(fd, LOCK_EX|LOCK_NB) < 0 && errno == EWOULDBLOCK); (void) readQFile(fd, entry, beingReceived, &sb); close(fd); } } closedir(dir); } else sendAndLogError("Can not access receive queue directory \"%s\".", FAX_RECVDIR); }
int main_rpc_warpabt(int c, char *v[]) { TIFFSetWarningHandler(NULL);//suppress warnings // input arguments if (c != 9) { fprintf(stderr, "usage:\n\t" "%s a.{tiff,rpc} b.{tiff,rpc} ax ay in.tif out.tif\n", *v); //0 1 2 3 4 5 6 7 8 return 1; } char *filename_a = v[1]; char *filename_rpca = v[2]; char *filename_b = v[3]; char *filename_rpcb = v[4]; double axyh[3] ={atof(v[5]), atof(v[6]), 0}; char *filename_h0 = v[7]; char *filename_out = v[8]; // read input images int megabytes = 800; struct tiff_tile_cache ta[1], tb[1]; tiff_tile_cache_init(ta, filename_a, megabytes); tiff_tile_cache_init(tb, filename_b, megabytes); int pd = ta->i->spp; if (pd != tb->i->spp) fail("image color depth mismatch\n"); // read input rpcs struct rpc rpca[1]; struct rpc rpcb[1]; read_rpc_file_xml(rpca, filename_rpca); read_rpc_file_xml(rpcb, filename_rpcb); // read initialized raster int w, h; float *in_h0 = iio_read_image_float(filename_h0, &w, &h); // allocate space for output raster float *out_h = xmalloc(w * h * sizeof*out_h); // run the algorithm float alpha2 = ALPHA()*ALPHA(); int niter = NITER(); int nwarps = NWARPS(); for (int i = 0; i < nwarps; i++) { mnehs_rpc(out_h, in_h0, w,h,ta,rpca,tb,rpcb,axyh, alpha2,niter); memcpy(in_h0, out_h, w*h*sizeof*in_h0); } // save the output raster iio_save_image_float(filename_out, out_h, w, h); // cleanup and exit free(in_h0); free(out_h); tiff_tile_cache_free(ta); tiff_tile_cache_free(tb); return 0; }
char *openTiff3DFile ( char *filename, char *mode, void *&fhandle ) { char *completeFilename = (char *) 0; int fname_len = (int) strlen(filename); char *suffix = strstr(filename,".tif"); while ( suffix && (fname_len - (suffix-filename) > 5) ) suffix = strstr(suffix+4,".tif"); //if ( (suffix != 0) && (fname_len - (suffix-filename) <= 5) ) { // a substring ".tif is already at the end of the filename if ( suffix ) { // a substring ".tif is already at the very end of the filename completeFilename = new char[fname_len+1]; strcpy(completeFilename,filename); } else { completeFilename = new char[fname_len+4+1]; strcpy(completeFilename,filename); strcat(completeFilename,"."); strcat(completeFilename,TIFF3D_SUFFIX); } //disable warning and error handlers to avoid messages on unrecognized tags TIFFSetWarningHandler(0); TIFFSetErrorHandler(0); fhandle = TIFFOpen(completeFilename,mode); if (!fhandle) { return ((char *) "Cannot open the file."); } return ((char *) 0); }
char *readTiff3DFile2Buffer ( char *filename, unsigned char *img, unsigned int img_width, unsigned int img_height, unsigned int first, unsigned int last, int downsamplingFactor, int starti, int endi, int startj, int endj ) { // 2015-01-30. Alessandro. @ADDED performance (time) measurement in all most time-consuming methods. #ifdef _VAA3D_TERAFLY_PLUGIN_MODE TERAFLY_TIME_START(TiffLoadData) #endif TIFF *input; //disable warning and error handlers to avoid messages on unrecognized tags TIFFSetWarningHandler(0); TIFFSetErrorHandler(0); input=TIFFOpen(filename,"r"); if (!input) { //throw iim::IOException(strprintf("in IOManager::readTiffMultipage(...): Cannot open the file %s",finName).c_str()); return ((char *) "Cannot open the file."); } int b_swap=TIFFIsByteSwapped(input); char *err_msg = readTiff3DFile2Buffer(input,img,img_width,img_height,first,last,b_swap,downsamplingFactor,starti,endi,startj,endj); TIFFClose(input); // 2015-01-30. Alessandro. @ADDED performance (time) measurement in all most time-consuming methods. #ifdef _VAA3D_TERAFLY_PLUGIN_MODE TERAFLY_TIME_STOP(TiffLoadData, tf::IO, tf::strprintf("loaded block x(%d), y(%d), z(%d-%d) from 3D tiff \"%s\"", img_width, img_height, first, last, filename)) #endif return err_msg; }
// Append a single slice at the bottom of a 3D image file void iomanager::tiff3D::appendSlice( std::string img_path, // (INPUT) image filepath (it includes the file extension) unsigned char * raw_img, // (INPUT) slice to be saved into the file int img_height, // (INPUT) slice height (in pixels) int img_width, // (INPUT) slice width (in pixels) int img_bytes_x_chan, // (INPUT) number of bytes per channel int img_chans, // (INPUT) number of channels int y0, // (INPUT) region of interest [x0,x1)[y0,y1) to be set on the image int y1, // (INPUT) region of interest [x0,x1)[y0,y1) to be set on the image int x0, // (INPUT) region of interest [x0,x1)[y0,y1) to be set on the image int x1, // (INPUT) region of interest [x0,x1)[y0,y1) to be set on the image int slice, // (INPUT) slice index const std::string & params) // (INPUT) additional parameters <param1=val, param2=val, ...> throw (iom::exception) { //throw iom::exception(iom::strprintf("not implemented yet"), __iom__current__function__); /**/iom::debug(iom::LEV3, iom::strprintf("img_path = %s, img_width = %d, img_height = %d, img_bytes_x_chan = %d, img_chans = %d, y0 = %d, y1 = %d, x0 = %d, x1 = %d, params = \"%s\"", img_path.c_str(), img_width, img_height, img_bytes_x_chan, img_chans, y0, y1, x0, x1, params.c_str()).c_str(), __iom__current__function__); //disable warning handler to avoid messages on unrecognized tags TIFFSetWarningHandler(0); iim::sint64 stridex = img_width * img_chans * img_bytes_x_chan; unsigned char *buf; // to scan the input buffer char *err_Tiff3Dfmt; y0 = (y0 < 0) ? 0: y0; y1 = (y1 < 0) ? img_height : y1; x0 = (x0 < 0) ? 0: x0; x1 = (x1 < 0) ? img_width : x1; if ( y0 >= y1 || x0 >= x1 ) throw iom::exception(iom::strprintf("wrong ROI (y0 = %d, y1 = %d, x0 = %d, x1 = %d)", y0, y1, x0, x1), __iom__current__function__); // append a slice buf = raw_img + x0*stridex + y0*img_chans*img_bytes_x_chan; // buf points to the first byte to be written if ( x0 == 0 && x1 == img_width && y0 == 0 && y1 == img_height ) { // all buffer must be written if ( (err_Tiff3Dfmt = appendSlice2Tiff3DFile((char *)img_path.c_str(),slice,buf,img_width,img_height)) != 0 ) { throw iom::exception(iom::strprintf("(%s) unable to write slice %d into file %s",err_Tiff3Dfmt,slice,img_path.c_str()), __iom__current__function__); } } else { // copy to a sub buffer before writing iim::sint64 stridex_ROI = (x1-x0) * img_chans * img_bytes_x_chan; iim::sint64 stridexy_ROI = stridex_ROI * (y1-y0); // just because required by 'copyBlock2SubBuf', not actually used iim::sint64 stridexy = stridex * img_height; // just because required by 'copyBlock2SubBuf', not actually used unsigned char *raw_img_ROI = new unsigned char[(y1-y0) * (x1-x0) * img_chans * img_bytes_x_chan]; iim::VirtualFmtMngr::copyBlock2SubBuf(buf,raw_img_ROI,(y1-y0),(x1-x0),1,img_bytes_x_chan,stridex,stridexy,stridex_ROI,stridexy_ROI); if ( (err_Tiff3Dfmt = appendSlice2Tiff3DFile((char *)img_path.c_str(),slice,raw_img_ROI,(x1-x0),(y1-y0))) != 0 ) { throw iom::exception(iom::strprintf("(%s) unable to write slice %d into file %s",err_Tiff3Dfmt,slice,img_path.c_str()), __iom__current__function__); } delete []raw_img_ROI; } }
// Create an empty 3D image void iomanager::tiff3D::create3Dimage( std::string img_path, // (INPUT) image filepath (it includes the file extension) int img_height, // (INPUT) image height (in pixels) int img_width, // (INPUT) image width (in pixels) int img_depth, // (INPUT) image depth (in pixels) int img_bytes_x_chan, // (INPUT) number of bytes per channel int img_chans, // (INPUT) number of channels const std::string & params) // (INPUT) additional parameters <param1=val, param2=val, ...> throw (iom::exception) { //throw iom::exception(iom::strprintf("not implemented yet"), __iom__current__function__); /**/iom::debug(iom::LEV3, iom::strprintf("img_path = %s, img_width = %d, img_height = %d, img_depth = %d, img_bytes_x_chan = %d, img_chans = %d, params = \"%s\"", img_path.c_str(), img_width, img_height, img_depth, img_bytes_x_chan, img_chans, params.c_str()).c_str(), __iom__current__function__); // disable warning handler to avoid messages on unrecognized tags TIFFSetWarningHandler(0); char *err_Tiff3Dfmt; // creates an empty file if ( (err_Tiff3Dfmt = initTiff3DFile((char *)img_path.c_str(),img_width,img_height,img_depth,img_chans,img_bytes_x_chan)) != 0 ) { throw iom::exception(iom::strprintf("(%s) unable to create an empty tiff file %s",err_Tiff3Dfmt,img_path.c_str()), __iom__current__function__); } }
// Only include the DLLMain with the dll build of pano13 BOOL WINAPI DllMain (HANDLE hDll, DWORD dwReason, LPVOID lpReserved) { switch (dwReason) { case DLL_PROCESS_ATTACH: hDllInstance = (HINSTANCE)hDll; // Code to run when the DLL is loaded // FS+ // disable warnings for unknown tags TIFFSetWarningHandler( 0 ); // FS- break; case DLL_PROCESS_DETACH: // Code to run when the DLL is freed break; case DLL_THREAD_ATTACH: // Code to run when a thread is created during the DLL's lifetime break; case DLL_THREAD_DETACH: // Code to run when a thread ends normally. break; } return TRUE; }
WidthAndHeight TifImageInfo::getSize(boost::filesystem::path & aPath) { WidthAndHeight result; static BOOL bFirstRun = true; if (bFirstRun) { TIFFSetWarningHandler(NULL); TIFFSetErrorHandler(NULL); bFirstRun = false; } TIFF *tif = TIFFOpen(aPath.file_string().data(), "r"); if (!tif) { throw std::runtime_error("cannot open file [" + aPath.file_string() + "]"); } BOOL success = FALSE; TIFFGetField(tif, TIFFTAG_IMAGEWIDTH, &result.width); TIFFGetField(tif, TIFFTAG_IMAGELENGTH, &result.height); TIFFClose(tif); return result; }
int main_rpc_warpabt(int c, char *v[]) { TIFFSetWarningHandler(NULL);//suppress warnings // input arguments if (c != 10) { fprintf(stderr, "usage:\n\t" "%s a.{tiff,rpc} b.{tiff,rpc} ax ay h0.tif o{a,b}.tiff\n", *v); //0 1 2 3 4 5 6 7 8 9 return 1; } char *filename_a = v[1]; char *filename_rpca = v[2]; char *filename_b = v[3]; char *filename_rpcb = v[4]; double axyh[3] ={atof(v[5]), atof(v[6]), 0}; char *filename_h0 = v[7]; char *filename_outa = v[8]; char *filename_outb = v[9]; // read input images and rpcs //int wa, wb, ha, hb, pd, pdb; //float *a = iio_read_image_float_vec(filename_a, &wa, &ha, &pd); //float *b = iio_read_image_float_vec(filename_b, &wb, &hb, &pdb); int megabytes = 800; struct tiff_tile_cache ta[1], tb[1]; tiff_tile_cache_init(ta, filename_a, megabytes); tiff_tile_cache_init(tb, filename_b, megabytes); int pd = ta->i->spp; if (pd != tb->i->spp) fail("image color depth mismatch\n"); struct rpc rpca[1]; struct rpc rpcb[1]; read_rpc_file_xml(rpca, filename_rpca); read_rpc_file_xml(rpcb, filename_rpcb); int w, h; float *h0 = iio_read_image_float(filename_h0, &w, &h); // allocate space for output images float *outa = xmalloc(w * h * pd * sizeof*outa); float *outb = xmalloc(w * h * pd * sizeof*outb); // run the algorithm rpc_warpabt(outa, outb, h0, w,h,pd, ta,rpca, tb,rpcb, axyh); // save the output images iio_save_image_float_vec(filename_outa, outa, w, h, pd); iio_save_image_float_vec(filename_outb, outb, w, h, pd); // cleanup and exit free(outa); free(outb); tiff_tile_cache_free(ta); tiff_tile_cache_free(tb); return 0; }
// read image metadata from a 2D image file void iomanager::tiff2D::readMetadata( std::string img_path, // (INPUT) image filepath int & img_width, // (OUTPUT) image width (in pixels) int & img_height, // (OUTPUT) image height (in pixels) int & img_bytes_x_chan, // (OUTPUT) number of bytes per channel int & img_chans, // (OUTPUT) number of channels const std::string & params) // (INPUT) additional parameters <param1=val, param2=val, ...> throw (iom::exception) { /**/iom::debug(iom::LEV3, iom::strprintf("img_path = \"%s\", params = \"%s\"",img_path.c_str(), params.c_str()).c_str(), __iom__current__function__); uint16 bpp; uint16 spp; //disable warning and error handlers to avoid messages on unrecognized tags TIFFSetWarningHandler(0); TIFFSetErrorHandler(0); TIFF* input=TIFFOpen(img_path.c_str(),"r"); if (!input) throw iom::exception(iom::strprintf("unable to open image \"%s\". Possible unsupported format or it isn't an image.\nSupported format is 2DTIFF", img_path.c_str()), __iom__current__function__); if (!TIFFGetField(input, TIFFTAG_IMAGEWIDTH, &img_width)) throw iom::exception(iom::strprintf("unable to determine 'TIFFTAG_IMAGEWIDTH' from image \"%s\". ", img_path.c_str()), __iom__current__function__); if (!TIFFGetField(input, TIFFTAG_IMAGELENGTH, &img_height)) throw iom::exception(iom::strprintf("unable to determine 'TIFFTAG_IMAGELENGTH' from image \"%s\". ", img_path.c_str()), __iom__current__function__); if (!TIFFGetField(input, TIFFTAG_BITSPERSAMPLE, &bpp)) throw iom::exception(iom::strprintf("unable to determine 'TIFFTAG_BITSPERSAMPLE' from image \"%s\". ", img_path.c_str()), __iom__current__function__); img_bytes_x_chan = bpp/8; if (!TIFFGetField(input, TIFFTAG_SAMPLESPERPIXEL, &spp)) spp = 1; //throw iom::exception(iom::strprintf("unable to determine 'TIFFTAG_SAMPLESPERPIXEL' from image \"%s\". ", img_path.c_str()), __iom__current__function__); img_chans = spp; // Onofri int img_depth; // image depth (in pixels) uint16 cpage; // Current page. We do not actually need it. uint16 npages; // Number of pages. int PNcheck=TIFFGetField(input, TIFFTAG_PAGENUMBER, &cpage, &npages); if (!PNcheck || npages==0) { // the tag has not been read correctly //iom::warning(iom::strprintf("unable to determine 'TIFFTAG_PAGENUMBER' from image file \"%s\". ", img_path.c_str()).c_str(),__iom__current__function__); img_depth = 0; do { img_depth++; } while (TIFFReadDirectory(input)); } else img_depth = npages; TIFFClose(input); // check the exception after closing the file if ( img_depth > 1 ) throw iom::exception(iom::strprintf("image \"%s\" has more than one page.\nSupported format is 2DTIFF", img_path.c_str()), __iom__current__function__); }
TifReader::TifReader(bool isTzi) : m_tiff(0), m_row(0), m_rowsPerStrip(0), m_stripIndex(-1) //, m_stripBuffer(0) , m_rowLength(0), m_xdpi(0), m_ydpi(0), m_rowOrder(Tiio::TOP2BOTTOM), is16bitEnabled(true), m_isTzi(isTzi), m_tmpRas(0) { TIFFSetWarningHandler(0); }
Tiio::Writer *Tiio::makeTifWriter() { #ifdef _DEBUG TIFFSetErrorHandler(MyErrorHandler); TIFFSetWarningHandler(MyWarningHandler); #endif return new TifWriter(); }
static void raster_keys(unsigned char key, int x, int y) { (void) x; (void) y; switch (key) { case 'b': /* photometric MinIsBlack */ photo = PHOTOMETRIC_MINISBLACK; initImage(); break; case 'l': /* lsb-to-msb FillOrder */ order = FILLORDER_LSB2MSB; initImage(); break; case 'm': /* msb-to-lsb FillOrder */ order = FILLORDER_MSB2LSB; initImage(); break; case 'w': /* photometric MinIsWhite */ photo = PHOTOMETRIC_MINISWHITE; initImage(); break; case 'W': /* toggle warnings */ owarning = TIFFSetWarningHandler(owarning); initImage(); break; case 'E': /* toggle errors */ oerror = TIFFSetErrorHandler(oerror); initImage(); break; case 'z': /* reset to defaults */ case 'Z': order = order0; photo = photo0; if (owarning == NULL) owarning = TIFFSetWarningHandler(NULL); if (oerror == NULL) oerror = TIFFSetErrorHandler(NULL); initImage(); break; case 'q': /* exit */ case '\033': cleanup_and_exit(); } glutPostRedisplay(); }
wxTIFFHandler::wxTIFFHandler() { m_name = wxT("TIFF file"); m_extension = wxT("tif"); m_type = wxBITMAP_TYPE_TIF; m_mime = wxT("image/tiff"); TIFFSetWarningHandler((TIFFErrorHandler) TIFFwxWarningHandler); TIFFSetErrorHandler((TIFFErrorHandler) TIFFwxErrorHandler); }
static void tiff_push_handlers (void) { if (global_error) g_warning ("TIFF loader left crufty global_error around, FIXME"); orig_error_handler = TIFFSetErrorHandler (tiff_error_handler); orig_warning_handler = TIFFSetWarningHandler (tiff_warning_handler); }
static gboolean process(GeglOperation *operation, GeglBuffer *input, const GeglRectangle *result, int level) { GeglProperties *o = GEGL_PROPERTIES(operation); Priv *p = g_new0(Priv, 1); gboolean status = TRUE; GError *error = NULL; g_assert(p != NULL); o->user_data = (void*) p; p->stream = gegl_gio_open_output_stream(NULL, o->path, &p->file, &error); if (p->stream != NULL && p->file != NULL) p->can_seek = g_seekable_can_seek(G_SEEKABLE(p->stream)); if (p->stream == NULL) { status = FALSE; g_warning("%s", error->message); goto cleanup; } TIFFSetErrorHandler(error_handler); TIFFSetWarningHandler(warning_handler); p->tiff = TIFFClientOpen("GEGL-tiff-save", "w", (thandle_t) p, read_from_stream, write_to_stream, seek_in_stream, close_stream, get_file_size, NULL, NULL); if (p->tiff == NULL) { status = FALSE; g_warning("failed to open TIFF from %s", o->path); goto cleanup; } if (export_tiff(operation, input, result)) { status = FALSE; g_warning("could not export TIFF file"); goto cleanup; } cleanup: cleanup(operation); if (o->user_data != NULL) g_free(o->user_data); o->user_data = NULL; if (error != NULL) g_error_free(error); return status; }
PVOID ReadTIFF ( LPCTSTR lpszPath ) { void* pDIB = 0; TIFFErrorHandler wh; wh = TIFFSetWarningHandler(MyWarningHandler); if (ChkTIFF(lpszPath)) { TIFF* tif = TIFFOpen(lpszPath, "r"); if (tif) { char emsg[1024]; if (TIFFRGBAImageOK(tif, emsg)) { TIFFDibImage img; char emsg[1024]; if (TIFFRGBAImageBegin(&img.tif, tif, -1, emsg)) { size_t npixels; uint32* raster; DibInstallHack(&img); npixels = img.tif.width * img.tif.height; raster = (uint32*) _TIFFmalloc(npixels * sizeof (uint32)); if (raster != NULL) { if (TIFFRGBAImageGet(&img.tif, raster, img.tif.width, img.tif.height)) { pDIB = TIFFRGBA2DIB(&img, raster); } } _TIFFfree(raster); } TIFFRGBAImageEnd(&img.tif); } else { TRACE("Unable to open image(%s): %s\n", lpszPath, emsg ); } TIFFClose(tif); } } TIFFSetWarningHandler(wh); return pDIB; }
static void ufo_tiff_reader_init (UfoTiffReader *self) { UfoTiffReaderPrivate *priv = NULL; self->priv = priv = UFO_TIFF_READER_GET_PRIVATE (self); priv->tiff = NULL; priv->more = FALSE; TIFFSetWarningHandler(NULL); }
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; } }
// Turn off the error and warning handlers to check if a valid file. // Necessary because of the way that the Doc loads images and restart files. int ChkTIFF ( LPCTSTR lpszPath ) { int rtn = 0; TIFFErrorHandler eh; TIFFErrorHandler wh; eh = TIFFSetErrorHandler(NULL); wh = TIFFSetWarningHandler(NULL); TIFF* tif = TIFFOpen(lpszPath, "r"); if (tif) { rtn = 1; TIFFClose(tif); } TIFFSetErrorHandler(eh); TIFFSetWarningHandler(wh); return rtn; }
ossimImageHandlerFactory* ossimImageHandlerFactory::instance() { if(!theInstance) { theInstance = new ossimImageHandlerFactory; // let's turn off tiff error reporting TIFFSetErrorHandler(0); TIFFSetWarningHandler(0); } return theInstance; }
// load TIFF int16 image int16_t *read_tiff_int16_gray(const char *fname, int *nx, int *ny) { int16_t *data; TIFFSetWarningHandler(NULL); //suppress warnings TIFF *tif = TIFFOpen(fname, "r"); if (!tif) { fprintf(stderr, "Unable to read TIFF file %s\n", fname); return NULL; } data = readTIFF(tif, nx, ny); TIFFClose(tif); return data; }