Ejemplo n.º 1
0
int IMG_isTIF(SDL_RWops* src)
{
	TIFF* tiff;
	TIFFErrorHandler prev_handler;

	/* Suppress output from libtiff */
	prev_handler = TIFFSetErrorHandler(NULL);
	
	/* Attempt to process the given file data */
	/* turn off memory mapped access with the m flag */
	tiff = TIFFClientOpen("SDL_image", "rm", (thandle_t)src, 
		tiff_read, tiff_write, tiff_seek, tiff_close, tiff_size, NULL, NULL);

	/* Reset the default error handler, since it can be useful for info */
	TIFFSetErrorHandler(prev_handler);

	/* If it's not a TIFF, then tiff will be NULL. */
	if(!tiff)
		return 0;

	/* Free up any dynamically allocated memory libtiff uses */
	TIFFClose(tiff);
	
	return 1;
}
Ejemplo n.º 2
0
int FileMatchTIF(Tcl_Channel chan,
		  CONST char *fileName,
		  Tcl_Obj *formatString,
		  int *widthPtr,
		  int *heightPtr,
		  Tcl_Interp *interp)
{
    TIFF *tif;
    TIFFErrorHandler prev_handler; /* Current TIFF error handler  */
    static TIFFErrorHandler temp_handler = tkTIFFErrorHandler;
                                   /* Temporary TIFF error handler
                                      (is used to avoid output of
                                       libtiff error messages to stderr) */

    prev_handler = TIFFSetErrorHandler(temp_handler);

    /* tif = TIFFFdOpen(f, fileName, "r"); */ /* this did not work */
    tif = TIFFOpen(fileName, "r");
    if (tif != NULL) {
        TIFFClose(tif);
        /* printf("FileMatchTIF: TIFF file found !"); */
        TIFFSetErrorHandler(prev_handler);
        return (TIF);
    } else {
        /* printf("FileMatchTIF: No TIF file found !"); */
        TIFFSetErrorHandler(prev_handler);
        return (0);
    }
}
Ejemplo n.º 3
0
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;
        }
Ejemplo n.º 4
0
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;
}
Ejemplo n.º 5
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;
}
Ejemplo n.º 6
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);
}
Ejemplo n.º 7
0
Tiio::Reader *Tiio::makeTziReader() {
#ifdef _DEBUG
  TIFFSetErrorHandler(MyErrorHandler);
  TIFFSetWarningHandler(MyWarningHandler);
#endif
  return new TifReader(true);
}
Ejemplo n.º 8
0
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;
    }
}
Ejemplo n.º 9
0
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);
}
Ejemplo n.º 10
0
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
}
Ejemplo n.º 11
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__);
}
Ejemplo n.º 12
0
void tiff_reader<T>::init()
{
    TIFFSetWarningHandler(0);
    // Note - we intentially set the error handling to null
    // when opening the image for the first time to avoid
    // leaking in TiffOpen: https://github.com/mapnik/mapnik/issues/1783
    TIFFSetErrorHandler(0);

    TIFF* tif = open(stream_);

    if (!tif) throw image_reader_exception("Can't open tiff file");

    TIFFSetErrorHandler(on_error);

    char msg[1024];

    if (TIFFRGBAImageOK(tif,msg))
    {
        TIFFGetField(tif, TIFFTAG_IMAGEWIDTH, &width_);
        TIFFGetField(tif, TIFFTAG_IMAGELENGTH, &height_);
        if (TIFFIsTiled(tif))
        {
            TIFFGetField(tif, TIFFTAG_TILEWIDTH, &tile_width_);
            TIFFGetField(tif, TIFFTAG_TILELENGTH, &tile_height_);
            read_method_=tiled;
        }
        else if (TIFFGetField(tif,TIFFTAG_ROWSPERSTRIP,&rows_per_strip_)!=0)
        {
            read_method_=stripped;
        }
        //TIFFTAG_EXTRASAMPLES
        uint16 extrasamples;
        uint16* sampleinfo;
        TIFFGetFieldDefaulted(tif, TIFFTAG_EXTRASAMPLES,
                              &extrasamples, &sampleinfo);
        if (extrasamples == 1 &&
            sampleinfo[0] == EXTRASAMPLE_ASSOCALPHA)
        {
            premultiplied_alpha_ = true;
        }
    }
    else
    {
        throw image_reader_exception(msg);
    }
}
Ejemplo n.º 13
0
Tiio::Writer *Tiio::makeTifWriter() {
#ifdef _DEBUG
  TIFFSetErrorHandler(MyErrorHandler);
  TIFFSetWarningHandler(MyWarningHandler);
#endif

  return new TifWriter();
}
Ejemplo n.º 14
0
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();
}
Ejemplo n.º 15
0
Archivo: io-tiff.c Proyecto: hb/gtk
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);
}
Ejemplo n.º 16
0
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);
}
Ejemplo n.º 17
0
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;
}
Ejemplo n.º 18
0
/*
  Get information about tiff images

  This function gets informtion about tiff images and places it in and
  ImageInfo object.  See image_info.hpp for more information.
*/
ImageInfo* tiff_info(const char* filename) {
  TIFFErrorHandler saved_handler = TIFFSetErrorHandler(NULL);
  TIFF* tif = 0;
  tif = TIFFOpen(filename, "r");
  if (tif == 0) {
    TIFFSetErrorHandler(saved_handler);
    throw std::invalid_argument("Failed to open image header");
  }
  // Create this later so it isn't leaked if filename does
  // not exist or is not a TIFF file.
  ImageInfo* info = new ImageInfo();

  /*
    The tiff library seems very sensitive to type yet provides only a
    stupid non-type-checked interface.  The following seems to work well
    (notice that resolution is floating point).  KWM 6/6/01
   */
  try {
    unsigned short tmp;
    uint32 size;
    TIFFGetFieldDefaulted(tif, TIFFTAG_IMAGEWIDTH, &size);
    info->ncols((size_t)size);
    TIFFGetFieldDefaulted(tif, TIFFTAG_IMAGELENGTH, &size);
    info->nrows((size_t)size);
    TIFFGetFieldDefaulted(tif, TIFFTAG_BITSPERSAMPLE, &tmp);
    info->depth((size_t)tmp);
    float res;
    TIFFGetFieldDefaulted(tif, TIFFTAG_XRESOLUTION, &res);
    info->x_resolution(res);
    TIFFGetFieldDefaulted(tif, TIFFTAG_YRESOLUTION, &res);
    info->y_resolution(res);
    TIFFGetFieldDefaulted(tif, TIFFTAG_SAMPLESPERPIXEL, &tmp);
    info->ncolors((size_t)tmp);
    TIFFGetFieldDefaulted(tif, TIFFTAG_PHOTOMETRIC, &tmp);
    info->inverted(tmp == PHOTOMETRIC_MINISWHITE);
    
    TIFFClose(tif);
  } catch (std::exception e) {
    TIFFSetErrorHandler(saved_handler);
    delete info;
  }
  TIFFSetErrorHandler(saved_handler);
  return info;
}
Ejemplo n.º 19
0
TIFFImage *TIFFImage_new(void)
{
	TIFFImage *self = (TIFFImage *)calloc(1, sizeof(TIFFImage));
	TIFFImage_path_(self, "");
	TIFFImage_error_(self, "");
	self->byteArray = UArray_new();
	self->ownsBuffer = 1;
	TIFFSetErrorHandler(MyTIFFErrorHandler);
	return self;
}
Ejemplo n.º 20
0
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;
    }
}
Ejemplo n.º 21
0
static GwyContainer*
jpkscan_load(const gchar *filename,
             G_GNUC_UNUSED GwyRunType mode,
             GError **error)
{
    TIFFErrorHandler old_error, old_warning;
    GwyContainer *container;

    gwy_debug("Loading <%s>", filename);

    old_warning = TIFFSetWarningHandler(tiff_ignore);
    old_error = TIFFSetErrorHandler(tiff_error);

    container = jpkscan_load_tiff(filename, error);

    TIFFSetErrorHandler(old_error);
    TIFFSetErrorHandler(old_warning);

    return container;
}
Ejemplo n.º 22
0
//  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;
}
Ejemplo n.º 23
0
PSD
GdDecodeTIFF(char *path)
{
	TIFF 	*tif;
	int		w, h;
	PSD		pmd;
	MWBLITPARMS parms;
	static TIFFErrorHandler prev_handler = NULL;

	if (!prev_handler)
		prev_handler = TIFFSetErrorHandler(NULL);

	tif = TIFFOpen(path, "r");
	if (!tif)
		return NULL;

	TIFFGetField(tif, TIFFTAG_IMAGEWIDTH, &w);
	TIFFGetField(tif, TIFFTAG_IMAGELENGTH, &h);

	parms.data = NULL;
	pmd = GdCreatePixmap(&scrdev, w, h, MWIF_RGBA8888, NULL, 0);
	if (!pmd)
		goto err;

	/* Allocate extra image buffer*/
	if ((parms.data = malloc(h * pmd->pitch)) == NULL)
			goto err;

	TIFFReadRGBAImage(tif, w, h, (uint32 *)parms.data, 0);

	/* use conversion blit to flip upside down image*/
	parms.dstx = parms.dsty = parms.srcx = parms.srcy = 0;
	parms.width = w;
	parms.height = h;
	parms.src_pitch = parms.dst_pitch = pmd->pitch;
	parms.data_out = pmd->addr;
	convblit_flipy_8888(&parms);
	free(parms.data);

	TIFFClose(tif);
	return pmd;

err:
	EPRINTF("GdDecodeTIFF: image loading error\n");
	if (tif)
		TIFFClose(tif);
	if(parms.data)
		free(parms.data);
	if (pmd)
		GdFreePixmap(pmd);
	return NULL;		/* image error*/
}
Ejemplo n.º 24
0
ossimImageHandlerFactory* ossimImageHandlerFactory::instance()
{
   if(!theInstance)
   {
      theInstance = new ossimImageHandlerFactory;

      // let's turn off tiff error reporting
      TIFFSetErrorHandler(0);
      TIFFSetWarningHandler(0);
   }

   return theInstance;
}
Ejemplo n.º 25
0
void HILL_read_tiff(
    HILL_input_stream i,
    struct HILL_image_data *img
){
    TIFF *t;
    uint32_t width=0;
    uint32_t height=0;
    uint32_t bytes=0;
    
    TIFFSetErrorHandler(read_tiff_error_handler);
    TIFFSetWarningHandler(read_tiff_error_handler);

    t=TIFFClientOpen(
        "Memory",
        "r",
        (thandle_t)i,
        read_tiff_read,
        read_tiff_write,
        read_tiff_seek,
        read_tiff_close,
        read_tiff_size,
        NULL,
        NULL
    );
    if(t==NULL)
    {
        img->err=HILL_IMAGE_LIBRARY_ERROR;
        return;
    }

    TIFFGetField(t, TIFFTAG_IMAGEWIDTH, &width);
    TIFFGetField(t, TIFFTAG_IMAGELENGTH, &height);
    bytes=width*height*sizeof(uint32_t);

    img->w=width;
    img->h=height;
    img->fmt=HILL_RGBA8;
    img->data=malloc(bytes);

    if(TIFFReadRGBAImageOriented(t, width, height, (uint32_t *)img->data, ORIENTATION_TOPLEFT, 1) != 0)
    {
        img->err=HILL_IMAGE_NO_ERROR;
        TIFFClose(t);
    }
    else
    {
        img->err=HILL_IMAGE_NOT_SUPPORTED;
        free(img->data);
        TIFFClose(t);
    }
}
Ejemplo n.º 26
0
QFImageWriterLibTIFF::QFImageWriterLibTIFF(uint32_t compression, const QString& compression_name, bool noDouble, bool onefileperchannel):
    QFExporterImageSeries()
{
    tif.clear();
    frames=0;
    this->compression=compression;
    this->compression_name=compression_name;
    this->noDouble=noDouble;
    this->onefileperchannel=onefileperchannel;

    QString lf=ProgramOptions::getConfigValue("exporters_basicimages/libtiff/logfile", ProgramOptions::getInstance()->getConfigFileDirectory()+"/exporters_basicimages_libtiff.log").toString();
    if (ProgramOptions::getConfigValue("exporters_basicimages/libtiff/log", false).toBool()) {
        QMutexLocker lock(mutex);

        if (fLibTIFFLogFilename!=lf) {
            if (fLibTIFFLog) {
                FILE* f=fLibTIFFLog;
                fLibTIFFLog=NULL;
                fclose(f);
            }
            fLibTIFFLogFilename=lf;
            fLibTIFFLog=fopen(fLibTIFFLogFilename.toLocal8Bit().data(), "a");
        }
        TIFFSetWarningHandler(libTIFFWarningHandler);
        TIFFSetErrorHandler(libTIFFErrorHandler);
    } else {
        QMutexLocker lock(mutex);
        if (fLibTIFFLog) {
            FILE* f=fLibTIFFLog;
            fLibTIFFLog=NULL;
            fclose(f);
        }
        fLibTIFFLogFilename="";
        TIFFSetWarningHandler(0);
        TIFFSetErrorHandler(0);
    }
}
Ejemplo n.º 27
0
static gint
jpkscan_detect(const GwyFileDetectInfo *fileinfo, gboolean only_name)
{
    TIFFErrorHandler old_error, old_warning;
    TIFF *tiff;
    gdouble ulen, vlen;
    const gchar *name;
    gint score = 0;

    if (only_name)
        return score;

    if (fileinfo->buffer_len <= MAGIC_SIZE
        || memcmp(fileinfo->head, MAGIC, MAGIC_SIZE) != 0)
        return 0;

    old_warning = TIFFSetWarningHandler(tiff_ignore);
    old_error = TIFFSetErrorHandler(tiff_ignore);

    if ((tiff = TIFFOpen(fileinfo->name, "r"))
        && tiff_get_custom_double(tiff, JPK_TIFFTAG_Grid_uLength, &ulen)
        && tiff_get_custom_double(tiff, JPK_TIFFTAG_Grid_vLength, &vlen)
        && ulen > 0.0
        && vlen > 0.0
        && (tiff_get_custom_string(tiff, JPK_TIFFTAG_ChannelFancyName, &name)
            || tiff_get_custom_string(tiff, JPK_TIFFTAG_Channel, &name)))
        score = 100;

    if (tiff)
        TIFFClose(tiff);

    TIFFSetErrorHandler(old_error);
    TIFFSetErrorHandler(old_warning);

    return score;
}
Ejemplo n.º 28
0
int GetTiffPages(const char *pFileName)
{
#ifndef WITH_TIFF
  return NOT_IMPLEMENTED;
#else 
  if (!pFileName)
    return BAD_ARGS;

  TIFFSetErrorHandler(NULL);
  TIFFSetWarningHandler(NULL);

  scoped_tiff_handle pTIF(TIFFOpen(pFileName, "r"));
  if (!pTIF)
    return FILE_ERROR;
  const int nPages = TIFFNumberOfDirectories(pTIF);
  if (nPages < 0)
    return INTERNAL_ERROR;
  return nPages;
#endif // WITH_TIFF
}
Ejemplo n.º 29
0
static opj_image_t* readImageFromFileTIF(const char* filename, int nbFilenamePGX, const char *separator)
{
  opj_image_t* image_read = NULL;
  opj_cparameters_t parameters;
  (void)nbFilenamePGX;
  (void)separator;

  /* conformance test suite produce annoying warning/error:
   * TIFFReadDirectory: Warning, /.../data/baseline/conformance/jp2_1.tif: unknown field with tag 37724 (0x935c) encountered.
   * TIFFOpen: /.../data/baseline/nonregression/opj_jp2_1.tif: Cannot open.
   * On Win32 this open a message box by default, so remove it from the test suite:
   */
#ifdef OPJ_HAVE_LIBTIFF
  TIFFSetWarningHandler(NULL);
  TIFFSetErrorHandler(NULL);
#endif

  if ( strlen(separator) != 0 ) return NULL;

  /* set encoding parameters to default values */
  opj_set_default_encoder_parameters(&parameters);
  parameters.decod_format = TIF_DFMT;
  strcpy(parameters.infile, filename);

  /* Read the tif file corresponding to the component */
#ifdef OPJ_HAVE_LIBTIFF
  image_read = tiftoimage(filename, &parameters);
#endif
  if (!image_read)
    {
    fprintf(stderr, "Unable to load TIF file\n");
    return NULL;
    }

  /* \postconditions */
  assert( image_read->numcomps == 1 || image_read->numcomps == 3 );
  return image_read;
}
Ejemplo n.º 30
0
ImageCodecInfo *
gdip_getcodecinfo_tiff ()
{
	tiff_codec.Clsid = (CLSID) { 0x557cf405, 0x1a04, 0x11d3, { 0x9a, 0x73, 0x0, 0x0, 0xf8, 0x1e, 0xf3, 0x2e } };
	tiff_codec.FormatID = gdip_tif_image_format_guid;
	tiff_codec.CodecName = (const WCHAR*) tiff_codecname;
	tiff_codec.DllName = NULL;
	tiff_codec.FormatDescription = (const WCHAR*) tiff_format;
	tiff_codec.FilenameExtension = (const WCHAR*) tiff_extension;
	tiff_codec.MimeType = (const WCHAR*) tiff_mimetype;
	tiff_codec.Flags = ImageCodecFlagsEncoder | ImageCodecFlagsDecoder | ImageCodecFlagsSupportBitmap | ImageCodecFlagsBuiltin;
	tiff_codec.Version = 1;
	tiff_codec.SigCount = 2;
	tiff_codec.SigSize = 2;
	tiff_codec.SigPattern = tiff_sig_pattern;
	tiff_codec.SigMask = tiff_sig_mask;

	/* Mute the lib */
	TIFFSetErrorHandler(NULL);
	TIFFSetWarningHandler(NULL);
	
	return &tiff_codec;
}