当前位置: 首页>>代码示例>>C++>>正文


C++ TIFFGetField函数代码示例

本文整理汇总了C++中TIFFGetField函数的典型用法代码示例。如果您正苦于以下问题:C++ TIFFGetField函数的具体用法?C++ TIFFGetField怎么用?C++ TIFFGetField使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了TIFFGetField函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: TIFFNewScanlineSize

/*
 * Return the number of bytes to read/write in a call to
 * one of the scanline-oriented i/o routines.  Note that
 * this number may be 1/samples-per-pixel if data is
 * stored as separate planes.
 * The ScanlineSize in case of YCbCrSubsampling is defined as the
 * strip size divided by the strip height, i.e. the size of a pack of vertical
 * subsampling lines divided by vertical subsampling. It should thus make
 * sense when multiplied by a multiple of vertical subsampling.
 * Some stuff depends on this newer version of TIFFScanlineSize
 * TODO: resolve this
 */
tsize_t
TIFFNewScanlineSize(TIFF* tif)
{
	TIFFDirectory *td = &tif->tif_dir;
	tsize_t scanline;

	if (td->td_planarconfig == PLANARCONFIG_CONTIG) {
		if (td->td_photometric == PHOTOMETRIC_YCBCR
		    && !isUpSampled(tif)) {
			uint16 ycbcrsubsampling[2];

			TIFFGetField(tif, TIFFTAG_YCBCRSUBSAMPLING,
				     ycbcrsubsampling + 0,
				     ycbcrsubsampling + 1);

			if (ycbcrsubsampling[0]*ycbcrsubsampling[1] == 0) {
				TIFFErrorExt(tif->tif_clientdata, tif->tif_name,
					     "Invalid YCbCr subsampling");
				return 0;
			}

			return((tsize_t) ((((td->td_imagewidth+ycbcrsubsampling[0]-1)
					    /ycbcrsubsampling[0])
					   *(ycbcrsubsampling[0]*ycbcrsubsampling[1]+2)
					   *td->td_bitspersample+7)
					  /8)/ycbcrsubsampling[1]);

		} else {
			scanline = multiply(tif, td->td_imagewidth,
					    td->td_samplesperpixel,
					    "TIFFScanlineSize");
		}
	} else
		scanline = td->td_imagewidth;
	return ((tsize_t) TIFFhowmany8(multiply(tif, scanline,
						td->td_bitspersample,
						"TIFFScanlineSize")));
}
开发者ID:GDXN,项目名称:fitsliberator,代码行数:50,代码来源:tif_strip.c

示例2: check_icc_header

/*  checks ICC header */
int check_icc_header (const char * filename ) {
  /* load file */
  TIFF* tif = TIFFOpen(filename, "r+");
  if (NULL == tif) {
    fprintf( stderr, "file '%s' could not be opened\n", filename);
    exit (FIXIT_TIFF_READ_PERMISSION_ERROR);
  };
  /* find date-tag and fix it */
  char *iccprofile=NULL;
  uint32 count=0;
  int returncode = 0;
  int found=TIFFGetField(tif, TIFFTAG_ICCPROFILE, &count, &iccprofile);
  if (1==found) { /* there exists a datetime field */
    unsigned long errsize=1024;
    char errmsg[errsize];
    returncode =  parse_icc(count, iccprofile, errsize, errmsg);
  } else if (0 == found) {
    if (FLAGGED == flag_be_verbose) printf ("no ICC profile found!\n");
  }
  TIFFClose(tif);
  if (0 == returncode) return FIXIT_TIFF_IS_VALID;
  else return FIXIT_TIFF_IS_INVALID;
}
开发者ID:SLUB-digitalpreservation,项目名称:fixit_tiff,代码行数:24,代码来源:check_icc_header.c

示例3: TIFFWritePerSampleShorts

/*
 * Setup a directory entry that references a
 * samples/pixel array of SHORT values and
 * (potentially) write the associated indirect
 * values.
 */
static int
TIFFWritePerSampleShorts(TIFF* tif, ttag_t tag, TIFFDirEntry* dir)
{
	uint16 buf[10], v;
	uint16* w = buf;
	int i, status, samples = tif->tif_dir.td_samplesperpixel;

	if (samples > NITEMS(buf)) {
		w = (uint16*) _TIFFmalloc(samples * sizeof (uint16));
		if (w == NULL) {
			TIFFError(tif->tif_name,
			    "No space to write per-sample shorts");
			return (0);
		}
	}
	TIFFGetField(tif, tag, &v);
	for (i = 0; i < samples; i++)
		w[i] = v;
	status = TIFFWriteShortArray(tif, TIFF_SHORT, tag, dir, samples, w);
	if (w != buf)
		_TIFFfree((char*) w);
	return (status);
}
开发者ID:AlexHayton,项目名称:decoda,代码行数:29,代码来源:tif_dirwrite.c

示例4: TIFFVStripSize

/*
 * Compute the # bytes in a variable height, row-aligned strip.
 */
tsize_t
TIFFVStripSize(TIFF* tif, uint32 nrows)
{
	TIFFDirectory *td = &tif->tif_dir;

	if (nrows == (uint32) -1)
		nrows = td->td_imagelength;
#ifdef YCBCR_SUPPORT
	if (td->td_planarconfig == PLANARCONFIG_CONTIG &&
	    td->td_photometric == PHOTOMETRIC_YCBCR &&
	    !isUpSampled(tif)) {
		/*
		 * Packed YCbCr data contain one Cb+Cr for every
		 * HorizontalSampling*VerticalSampling Y values.
		 * Must also roundup width and height when calculating
		 * since images that are not a multiple of the
		 * horizontal/vertical subsampling area include
		 * YCbCr data for the extended image.
		 */
                uint16 ycbcrsubsampling[2];
                tsize_t w, scanline, samplingarea;

                TIFFGetField( tif, TIFFTAG_YCBCRSUBSAMPLING, 
                              ycbcrsubsampling + 0, 
                              ycbcrsubsampling + 1 );

		w = TIFFroundup(td->td_imagewidth, ycbcrsubsampling[0]);
		scanline = TIFFhowmany(w*td->td_bitspersample, 8);
		samplingarea = ycbcrsubsampling[0]*ycbcrsubsampling[1];
		nrows = TIFFroundup(nrows, ycbcrsubsampling[1]);
		/* NB: don't need TIFFhowmany here 'cuz everything is rounded */
		return ((tsize_t)
		    (nrows*scanline + 2*(nrows*scanline / samplingarea)));
	} else
#endif
		return ((tsize_t)(nrows * TIFFScanlineSize(tif)));
}
开发者ID:OS2World,项目名称:LIB-SDL,代码行数:40,代码来源:tif_strip.c

示例5: _declspec

_declspec (dllexport) uint32_t getTiffTags( int * compression, 
                                            char * hostComputer, 
                                            int32_t * imageWidth, 
                                            int32_t * imageLength, 
                                            char * software, 
                                            int* bitness, 
                                            int* samples_per_pixel, 
                                            int32_t* scanlineSize,
                                            int32_t* stripSize,
                                            TIFF* tif) {
  TIFFGetField(tif, TIFFTAG_COMPRESSION, compression);
  TIFFGetField(tif, TIFFTAG_HOSTCOMPUTER, hostComputer);
  TIFFGetField(tif, TIFFTAG_SOFTWARE, software);
  TIFFGetField(tif, TIFFTAG_IMAGEWIDTH, imageWidth);
  TIFFGetField(tif, TIFFTAG_IMAGELENGTH, imageLength);
  TIFFGetField(tif, TIFFTAG_BITSPERSAMPLE, bitness);
  TIFFGetField(tif, TIFFTAG_SAMPLESPERPIXEL, samples_per_pixel);
  uint32_t tifPages = countTiffPages(tif);
  *scanlineSize = TIFFScanlineSize(tif);
  *stripSize = TIFFStripSize(tif);
  return tifPages;
}
开发者ID:sandlerr,项目名称:imagerecon,代码行数:22,代码来源:labviewdll.cpp

示例6: TIFFSetWarningHandler

Image *Read (IStream *file, const Image::ReadOptions& options)
{
    int                   nrow;
    int                   result = 0;
    long                  LineSize;
    TIFF                  *tif;
    Image                 *image ;
    uint16                BitsPerSample;
    uint16                BytesPerSample = 1;
    uint16                PhotometricInterpretation;
    uint16                SamplePerPixel;
    uint16                Orientation;
    uint32                RowsPerStrip;
    unsigned int          width;
    unsigned int          height;

    // TODO - TIFF files probably have some gamma info in them by default, but we're currently ignorant about that.
    // Until that is fixed, use whatever the user has chosen as default.
    GammaCurvePtr gamma;
    if (options.gammacorrect && options.defaultGamma)
        gamma = TranscodingGammaCurve::Get(options.workingGamma, options.defaultGamma);

    // [CLi] TIFF is specified to use associated (= premultiplied) alpha, so that's the preferred mode to use for the image container unless the user overrides
    // (e.g. to handle a non-compliant file).
    bool premul = true;
    if (options.premultiplyOverride)
        premul = options.premultiply;

    // Rather than have libTIFF complain about tags it doesn't understand,
    // we just suppress all the warnings.
    TIFFSetWarningHandler(SuppressTIFFWarnings);
    TIFFSetErrorHandler(SuppressTIFFWarnings);

    // Open and do initial processing
    tif = TIFFClientOpen("Dummy File Name", "r", file,
        Tiff_Read, Tiff_Write, Tiff_Seek, Tiff_Close,
        Tiff_Size, Tiff_Map, Tiff_Unmap);
    if (!tif)
        return (NULL) ;

    // Get basic information about the image
    int ExtraSamples, ExtraSampleInfo;
    TIFFGetField(tif, TIFFTAG_IMAGEWIDTH, &width);
    TIFFGetField(tif, TIFFTAG_IMAGELENGTH, &height);
    TIFFGetField(tif, TIFFTAG_BITSPERSAMPLE, &BitsPerSample);
    TIFFGetField(tif, TIFFTAG_ROWSPERSTRIP, &RowsPerStrip);
    TIFFGetField(tif, TIFFTAG_PHOTOMETRIC, &PhotometricInterpretation);
    TIFFGetField(tif, TIFFTAG_ORIENTATION, &Orientation);
    TIFFGetFieldDefaulted(tif, TIFFTAG_SAMPLESPERPIXEL, &SamplePerPixel);
    TIFFGetFieldDefaulted(tif, TIFFTAG_EXTRASAMPLES, &ExtraSamples, &ExtraSampleInfo);

    // don't support more than 16 bits per sample
    if (BitsPerSample == 16)
    {
        BytesPerSample = 2 ;
        options.warnings.push_back ("Warning: reading 16 bits/sample TIFF file; components crunched to 8");
    }

    LineSize = TIFFScanlineSize(tif);
    assert (SamplePerPixel == (int) (LineSize / width) / BytesPerSample);
    // SamplePerPixel = (int)(LineSize / width);

#if 0
    // For now we are ignoring the orientation of the image...
    switch (Orientation)
    {
    case ORIENTATION_TOPLEFT:
        break;
    case ORIENTATION_TOPRIGHT:
        break;
    case ORIENTATION_BOTRIGHT:
        break;
    case ORIENTATION_BOTLEFT:
        break;
    case ORIENTATION_LEFTTOP:
        break;
    case ORIENTATION_RIGHTTOP:
        break;
    case ORIENTATION_RIGHTBOT:
        break;
    case ORIENTATION_LEFTBOT:
        break;
    default:
        break;
    }
#endif

    //PhotometricInterpretation = 2 image is RGB
    //PhotometricInterpretation = 3 image have a color palette
    if (PhotometricInterpretation == PHOTOMETRIC_PALETTE && (TIFFIsTiled(tif) == 0))
    {
        uint16 *red, *green, *blue;

        //load the palette
        int cmap_len = (1 << BitsPerSample);

        TIFFGetField(tif, TIFFTAG_COLORMAP, &red, &green, &blue);

        vector<Image::RGBMapEntry> colormap ;
        Image::RGBMapEntry entry;
//.........这里部分代码省略.........
开发者ID:SteveShaw,项目名称:povray,代码行数:101,代码来源:tiff.cpp

示例7: main

int
main(int argc, char* argv[])
{
    uint16 bitspersample, shortv;
    uint32 imagewidth, imagelength;
    uint16 config = PLANARCONFIG_CONTIG;
    uint32 rowsperstrip = (uint32) -1;
    uint16 photometric = PHOTOMETRIC_RGB;
    uint16 *rmap, *gmap, *bmap;
    uint32 row;
    int cmap = -1;
    TIFF *in, *out;
    int c;
    extern int optind;
    extern char* optarg;

    while ((c = getopt(argc, argv, "C:c:p:r:")) != -1)
        switch (c) {
        case 'C':		/* force colormap interpretation */
            cmap = atoi(optarg);
            break;
        case 'c':		/* compression scheme */
            if (!processCompressOptions(optarg))
                usage();
            break;
        case 'p':		/* planar configuration */
            if (streq(optarg, "separate"))
                config = PLANARCONFIG_SEPARATE;
            else if (streq(optarg, "contig"))
                config = PLANARCONFIG_CONTIG;
            else
                usage();
            break;
        case 'r':		/* rows/strip */
            rowsperstrip = atoi(optarg);
            break;
        case '?':
            usage();
            /*NOTREACHED*/
        }
    if (argc - optind != 2)
        usage();
    in = TIFFOpen(argv[optind], "r");
    if (in == NULL)
        return (-1);
    if (!TIFFGetField(in, TIFFTAG_PHOTOMETRIC, &shortv) ||
            shortv != PHOTOMETRIC_PALETTE) {
        fprintf(stderr, "%s: Expecting a palette image.\n",
                argv[optind]);
        return (-1);
    }
    if (!TIFFGetField(in, TIFFTAG_COLORMAP, &rmap, &gmap, &bmap)) {
        fprintf(stderr,
                "%s: No colormap (not a valid palette image).\n",
                argv[optind]);
        return (-1);
    }
    bitspersample = 0;
    TIFFGetField(in, TIFFTAG_BITSPERSAMPLE, &bitspersample);
    if (bitspersample != 8) {
        fprintf(stderr, "%s: Sorry, can only handle 8-bit images.\n",
                argv[optind]);
        return (-1);
    }
    out = TIFFOpen(argv[optind+1], "w");
    if (out == NULL)
        return (-2);
    cpTags(in, out);
    TIFFGetField(in, TIFFTAG_IMAGEWIDTH, &imagewidth);
    TIFFGetField(in, TIFFTAG_IMAGELENGTH, &imagelength);
    if (compression != (uint16)-1)
        TIFFSetField(out, TIFFTAG_COMPRESSION, compression);
    else
        TIFFGetField(in, TIFFTAG_COMPRESSION, &compression);
    switch (compression) {
    case COMPRESSION_JPEG:
        if (jpegcolormode == JPEGCOLORMODE_RGB)
            photometric = PHOTOMETRIC_YCBCR;
        else
            photometric = PHOTOMETRIC_RGB;
        TIFFSetField(out, TIFFTAG_JPEGQUALITY, quality);
        TIFFSetField(out, TIFFTAG_JPEGCOLORMODE, jpegcolormode);
        break;
    case COMPRESSION_LZW:
    case COMPRESSION_DEFLATE:
        if (predictor != 0)
            TIFFSetField(out, TIFFTAG_PREDICTOR, predictor);
        break;
    }
    TIFFSetField(out, TIFFTAG_PHOTOMETRIC, photometric);
    TIFFSetField(out, TIFFTAG_SAMPLESPERPIXEL, 3);
    TIFFSetField(out, TIFFTAG_PLANARCONFIG, config);
    TIFFSetField(out, TIFFTAG_ROWSPERSTRIP,
                 rowsperstrip = TIFFDefaultStripSize(out, rowsperstrip));
    (void) TIFFGetField(in, TIFFTAG_PLANARCONFIG, &shortv);
    if (cmap == -1)
        cmap = checkcmap(1<<bitspersample, rmap, gmap, bmap);
    if (cmap == 16) {
        /*
         * Convert 16-bit colormap to 8-bit.
//.........这里部分代码省略.........
开发者ID:carolemieux,项目名称:daikon,代码行数:101,代码来源:pal2rgb.c

示例8: main


//.........这里部分代码省略.........
    TIFFSetField(faxTIFF, TIFFTAG_IMAGEWIDTH,	xsize);
    TIFFSetField(faxTIFF, TIFFTAG_SAMPLESPERPIXEL,	1);
    TIFFSetField(faxTIFF, TIFFTAG_BITSPERSAMPLE,	1);
    TIFFSetField(faxTIFF, TIFFTAG_FILLORDER,	fillorder_in);
    TIFFSetField(faxTIFF, TIFFTAG_PLANARCONFIG,	PLANARCONFIG_CONTIG);
    TIFFSetField(faxTIFF, TIFFTAG_PHOTOMETRIC,	photometric_in);
    TIFFSetField(faxTIFF, TIFFTAG_YRESOLUTION,	resY);
    TIFFSetField(faxTIFF, TIFFTAG_RESOLUTIONUNIT,	RESUNIT_INCH);

    /* NB: this must be done after directory info is setup */
    TIFFSetField(faxTIFF, TIFFTAG_COMPRESSION, compression_in);
    if (compression_in == COMPRESSION_CCITTFAX3)
        TIFFSetField(faxTIFF, TIFFTAG_GROUP3OPTIONS, group3options_in);
    else if (compression_in == COMPRESSION_CCITTFAX4)
        TIFFSetField(faxTIFF, TIFFTAG_GROUP4OPTIONS, group4options_in);
    for (pn = 0; optind < argc; pn++, optind++) {
        in = fopen(argv[optind], "r" BINMODE);
        if (in == NULL) {
            fprintf(stderr,
                    "%s: %s: Can not open\n", argv[0], argv[optind]);
            continue;
        }
#if defined(_WIN32) && defined(USE_WIN32_FILEIO)
        TIFFSetClientdata(faxTIFF, (thandle_t)_get_osfhandle(fileno(in)));
#else
        TIFFSetClientdata(faxTIFF, (thandle_t)fileno(in));
#endif
        TIFFSetFileName(faxTIFF, (const char*)argv[optind]);
        TIFFSetField(out, TIFFTAG_IMAGEWIDTH, xsize);
        TIFFSetField(out, TIFFTAG_BITSPERSAMPLE, 1);
        TIFFSetField(out, TIFFTAG_COMPRESSION, compression_out);
        TIFFSetField(out, TIFFTAG_PHOTOMETRIC, photometric_out);
        TIFFSetField(out, TIFFTAG_ORIENTATION, ORIENTATION_TOPLEFT);
        TIFFSetField(out, TIFFTAG_SAMPLESPERPIXEL, 1);
        switch (compression_out) {
        /* g3 */
        case COMPRESSION_CCITTFAX3:
            TIFFSetField(out, TIFFTAG_GROUP3OPTIONS,
                         group3options_out);
            TIFFSetField(out, TIFFTAG_FAXMODE, mode);
            rowsperstrip =
                (defrowsperstrip)?defrowsperstrip:(uint32)-1L;
            break;

        /* g4 */
        case COMPRESSION_CCITTFAX4:
            TIFFSetField(out, TIFFTAG_GROUP4OPTIONS,
                         group4options_out);
            TIFFSetField(out, TIFFTAG_FAXMODE, mode);
            rowsperstrip =
                (defrowsperstrip)?defrowsperstrip:(uint32)-1L;
            break;

        default:
            rowsperstrip = (defrowsperstrip) ?
                           defrowsperstrip : TIFFDefaultStripSize(out, 0);
        }
        TIFFSetField(out, TIFFTAG_ROWSPERSTRIP, rowsperstrip);
        TIFFSetField(out, TIFFTAG_PLANARCONFIG, PLANARCONFIG_CONTIG);
        TIFFSetField(out, TIFFTAG_FILLORDER, fillorder_out);
        TIFFSetField(out, TIFFTAG_SOFTWARE, "fax2tiff");
        TIFFSetField(out, TIFFTAG_XRESOLUTION, 204.0);
        if (!stretch) {
            TIFFGetField(faxTIFF, TIFFTAG_YRESOLUTION, &resY);
            TIFFSetField(out, TIFFTAG_YRESOLUTION, resY);
        } else
            TIFFSetField(out, TIFFTAG_YRESOLUTION, 196.);
        TIFFSetField(out, TIFFTAG_RESOLUTIONUNIT, RESUNIT_INCH);
        TIFFSetField(out, TIFFTAG_PAGENUMBER, pn, npages);

        if (!verbose)
            whandler = TIFFSetWarningHandler(NULL);
        rows = copyFaxFile(faxTIFF, out);
        fclose(in);
        if (!verbose)
            (void) TIFFSetWarningHandler(whandler);

        TIFFSetField(out, TIFFTAG_IMAGELENGTH, rows);

        if (verbose) {
            fprintf(stderr, "%s:\n", argv[optind]);
            fprintf(stderr, "%d rows in input\n", rows);
            fprintf(stderr, "%ld total bad rows\n",
                    (long) badfaxlines);
            fprintf(stderr, "%d max consecutive bad rows\n", badfaxrun);
        }
        if (compression_out == COMPRESSION_CCITTFAX3 &&
                mode == FAXMODE_CLASSF) {
            TIFFSetField(out, TIFFTAG_BADFAXLINES, badfaxlines);
            TIFFSetField(out, TIFFTAG_CLEANFAXDATA, badfaxlines ?
                         CLEANFAXDATA_REGENERATED : CLEANFAXDATA_CLEAN);
            TIFFSetField(out, TIFFTAG_CONSECUTIVEBADFAXLINES, badfaxrun);
        }
        TIFFWriteDirectory(out);
    }
    TIFFClose(out);
    _TIFFfree(rowbuf);
    _TIFFfree(refbuf);
    return (EXIT_SUCCESS);
}
开发者ID:CyberIntelMafia,项目名称:clamav-devel,代码行数:101,代码来源:fax2tiff.c

示例9: TIFFPrintDirectory


//.........这里部分代码省略.........
		case THRESHHOLD_ERRORDIFFUSE:
			fprintf(fd, "error diffused\n");
			break;
		default:
			fprintf(fd, "%u (0x%x)\n",
			    td->td_threshholding, td->td_threshholding);
			break;
		}
	}
	if (TIFFFieldSet(tif,FIELD_FILLORDER)) {
		fprintf(fd, "  FillOrder: ");
		switch (td->td_fillorder) {
		case FILLORDER_MSB2LSB:
			fprintf(fd, "msb-to-lsb\n");
			break;
		case FILLORDER_LSB2MSB:
			fprintf(fd, "lsb-to-msb\n");
			break;
		default:
			fprintf(fd, "%u (0x%x)\n",
			    td->td_fillorder, td->td_fillorder);
			break;
		}
	}
	if (TIFFFieldSet(tif,FIELD_YCBCRSUBSAMPLING))
        {
            /*
             * For hacky reasons (see tif_jpeg.c - JPEGFixupTestSubsampling),
             * we need to fetch this rather than trust what is in our
             * structures.
             */
            uint16 subsampling[2];

            TIFFGetField( tif, TIFFTAG_YCBCRSUBSAMPLING, 
                          subsampling + 0, subsampling + 1 );
		fprintf(fd, "  YCbCr Subsampling: %u, %u\n",
                        subsampling[0], subsampling[1] );
        }
	if (TIFFFieldSet(tif,FIELD_YCBCRPOSITIONING)) {
		fprintf(fd, "  YCbCr Positioning: ");
		switch (td->td_ycbcrpositioning) {
		case YCBCRPOSITION_CENTERED:
			fprintf(fd, "centered\n");
			break;
		case YCBCRPOSITION_COSITED:
			fprintf(fd, "cosited\n");
			break;
		default:
			fprintf(fd, "%u (0x%x)\n",
			    td->td_ycbcrpositioning, td->td_ycbcrpositioning);
			break;
		}
	}
	if (TIFFFieldSet(tif,FIELD_HALFTONEHINTS))
		fprintf(fd, "  Halftone Hints: light %u dark %u\n",
		    td->td_halftonehints[0], td->td_halftonehints[1]);
	if (TIFFFieldSet(tif,FIELD_ORIENTATION)) {
		fprintf(fd, "  Orientation: ");
		if (td->td_orientation < NORIENTNAMES)
			fprintf(fd, "%s\n", orientNames[td->td_orientation]);
		else
			fprintf(fd, "%u (0x%x)\n",
			    td->td_orientation, td->td_orientation);
	}
	if (TIFFFieldSet(tif,FIELD_SAMPLESPERPIXEL))
		fprintf(fd, "  Samples/Pixel: %u\n", td->td_samplesperpixel);
开发者ID:pottootje1982,项目名称:singalong,代码行数:67,代码来源:tif_print.c

示例10: tracker_extract_get_metadata

G_MODULE_EXPORT gboolean
tracker_extract_get_metadata (TrackerExtractInfo *info)
{
	TIFF *image;
	TrackerXmpData *xd = NULL;
	TrackerIptcData *id = NULL;
	TrackerExifData *ed = NULL;
	MergeData md = { 0 };
	TiffData td = { 0 };
	gchar *filename, *uri;
	gchar *date;
	glong exif_offset;
	GPtrArray *keywords;
	guint i;
	GFile *file;
	TrackerSparqlBuilder *metadata, *preupdate;
	const gchar *graph, *urn;
	int fd;

#ifdef HAVE_LIBIPTCDATA
	gchar *iptc_offset;
	guint32 iptc_size;
#endif

#ifdef HAVE_EXEMPI
	gchar *xmp_offset;
	guint32 size;
#endif /* HAVE_EXEMPI */

	file = tracker_extract_info_get_file (info);
	filename = g_file_get_path (file);

	preupdate = tracker_extract_info_get_preupdate_builder (info);
	metadata = tracker_extract_info_get_metadata_builder (info);
	graph = tracker_extract_info_get_graph (info);
	urn = tracker_extract_info_get_urn (info);

	fd = tracker_file_open_fd (filename);

	if (fd == -1) {
		g_warning ("Could not open tiff file '%s': %s\n",
		           filename,
		           g_strerror (errno));
		g_free (filename);
		return FALSE;
	}	

	if ((image = TIFFFdOpen (fd, filename, "r")) == NULL){
		g_warning ("Could not open image:'%s'\n", filename);
		g_free (filename);
		close (fd);
		return FALSE;
	}

	tracker_sparql_builder_predicate (metadata, "a");
	tracker_sparql_builder_object (metadata, "nfo:Image");
	tracker_sparql_builder_object (metadata, "nmm:Photo");

	uri = g_file_get_uri (file);

#ifdef HAVE_LIBIPTCDATA
	if (TIFFGetField (image, 
	                  TIFFTAG_RICHTIFFIPTC, 
	                  &iptc_size, 
	                  &iptc_offset)) {
		if (TIFFIsByteSwapped(image) != 0) {
			TIFFSwabArrayOfLong((uint32*) iptc_offset, 
			                    (unsigned long) iptc_size);
		}
		id = tracker_iptc_new (iptc_offset, 4 * iptc_size, uri);
	}
#endif /* HAVE_LIBIPTCDATA */

	if (!id) {
		id = g_new0 (TrackerIptcData, 1);
	}

	/* FIXME There are problems between XMP data embedded with different tools
	   due to bugs in the original spec (type) */
#ifdef HAVE_EXEMPI
	if (TIFFGetField (image, TIFFTAG_XMLPACKET, &size, &xmp_offset)) {
		xd = tracker_xmp_new (xmp_offset, size, uri);
	}
#endif /* HAVE_EXEMPI */

	if (!xd) {
		xd = g_new0 (TrackerXmpData, 1);
	}

	ed = g_new0 (TrackerExifData, 1);

	/* Get Tiff specifics */
	td.width = tag_to_string (image, TIFFTAG_IMAGEWIDTH, TAG_TYPE_UINT32);
	td.length = tag_to_string (image, TIFFTAG_IMAGELENGTH, TAG_TYPE_UINT32);
	td.artist = tag_to_string (image, TIFFTAG_ARTIST, TAG_TYPE_STRING);
	td.copyright = tag_to_string (image, TIFFTAG_COPYRIGHT, TAG_TYPE_STRING);

	date = tag_to_string (image, TIFFTAG_DATETIME, TAG_TYPE_STRING);
	td.date = tracker_date_guess (date);
	g_free (date);
//.........这里部分代码省略.........
开发者ID:Haititi,项目名称:tracker,代码行数:101,代码来源:tracker-extract-tiff.c

示例11: TIFFWriteNormalTag

/*
 * Process tags that are not special cased.
 */
static int
TIFFWriteNormalTag(TIFF* tif, TIFFDirEntry* dir, const TIFFFieldInfo* fip)
{
	u_short wc = (u_short) fip->field_writecount;
	uint32 wc2;

	dir->tdir_tag = (uint16) fip->field_tag;
	dir->tdir_type = (u_short) fip->field_type;
	dir->tdir_count = wc;
#define	WRITEF(x,y)	x(tif, fip->field_type, fip->field_tag, dir, wc, y)
	switch (fip->field_type) {
	case TIFF_SHORT:
	case TIFF_SSHORT:
		if (wc > 1) {
			uint16* wp;
			if (wc == (u_short) TIFF_VARIABLE
			    || fip->field_passcount)
				TIFFGetField(tif, fip->field_tag, &wc, &wp);
			else
				TIFFGetField(tif, fip->field_tag, &wp);
			if (!WRITEF(TIFFWriteShortArray, wp))
				return (0);
		} else {
			if (fip->field_passcount) {
				uint16* wp;
				TIFFGetField(tif, fip->field_tag, &wc, &wp);
				if (!WRITEF(TIFFWriteShortArray, wp))
					return 0;
			} else {
				uint16 sv;
				TIFFGetField(tif, fip->field_tag, &sv);
				dir->tdir_offset =
					TIFFInsertData(tif, dir->tdir_type, sv);
			}
		}
		break;
	case TIFF_LONG:
	case TIFF_SLONG:
	case TIFF_IFD:
		if (wc > 1) {
			uint32* lp;
			if (wc == (u_short) TIFF_VARIABLE
			    || fip->field_passcount)
				TIFFGetField(tif, fip->field_tag, &wc, &lp);
			else
				TIFFGetField(tif, fip->field_tag, &lp);
			if (!WRITEF(TIFFWriteLongArray, lp))
				return (0);
		} else {
			if (fip->field_passcount) {
				uint32* lp;
				TIFFGetField(tif, fip->field_tag, &wc, &lp);
				if (!WRITEF(TIFFWriteLongArray, lp))
					return 0;
			} else {
				/* XXX handle LONG->SHORT conversion */
				TIFFGetField(tif, fip->field_tag,
					     &dir->tdir_offset);
			}
		}
		break;
	case TIFF_RATIONAL:
	case TIFF_SRATIONAL:
		if (wc > 1) {
			float* fp;
			if (wc == (u_short) TIFF_VARIABLE
			    || fip->field_passcount)
				TIFFGetField(tif, fip->field_tag, &wc, &fp);
			else
				TIFFGetField(tif, fip->field_tag, &fp);
			if (!WRITEF(TIFFWriteRationalArray, fp))
				return (0);
		} else {
			if (fip->field_passcount) {
				float* fp;
				TIFFGetField(tif, fip->field_tag, &wc, &fp);
				if (!WRITEF(TIFFWriteRationalArray, fp))
					return 0;
			} else {
				float fv;
				TIFFGetField(tif, fip->field_tag, &fv);
				if (!WRITEF(TIFFWriteRationalArray, &fv))
					return (0);
			}
		}
		break;
	case TIFF_FLOAT:
		if (wc > 1) {
			float* fp;
			if (wc == (u_short) TIFF_VARIABLE
			    || fip->field_passcount)
				TIFFGetField(tif, fip->field_tag, &wc, &fp);
			else
				TIFFGetField(tif, fip->field_tag, &fp);
			if (!WRITEF(TIFFWriteFloatArray, fp))
				return (0);
		} else {
//.........这里部分代码省略.........
开发者ID:AlexHayton,项目名称:decoda,代码行数:101,代码来源:tif_dirwrite.c

示例12: TIFFOpen

ImageIO::errorType ImageIO::loadTIFF(const char * filename)
{
#ifdef ENABLE_TIFF
  TIFF * tiff = TIFFOpen(filename, "r");
  if (!tiff)
    return IO_ERROR;

  // read the dimensions
  uint32 tiff_width, tiff_height;
  uint16 tiff_samplesPerPixel;
  uint16 tiff_bits;
  TIFFGetField(tiff, TIFFTAG_IMAGEWIDTH, &tiff_width);
  TIFFGetField(tiff, TIFFTAG_IMAGELENGTH, &tiff_height);
  TIFFGetField(tiff, TIFFTAG_SAMPLESPERPIXEL, &tiff_samplesPerPixel);
  TIFFGetField(tiff, TIFFTAG_BITSPERSAMPLE, &tiff_bits);

  //printf("tiff_width: %d tiff_height: %d tiff_samplesPerPixel: %d tiff_bits: %d\n", tiff_width, tiff_height, tiff_samplesPerPixel, tiff_bits);

  if ((tiff_samplesPerPixel != IMAGE_IO_RGB) && (tiff_samplesPerPixel != IMAGE_IO_RGB_ALPHA))
  {
    printf("Error in loadTIFF: Sorry, cannot handle %d-channel images.\n", tiff_samplesPerPixel);
    TIFFClose(tiff);
    return OTHER_ERROR;
  }

  if (tiff_bits != BITS_PER_CHANNEL_8)
  {
    printf("Error in loadTIFF: Sorry, cannot handle %d-bit images.\n", tiff_bits);
    TIFFClose(tiff);
    return OTHER_ERROR;
  }

  width = tiff_width;
  height = tiff_height;
  bytesPerPixel = tiff_samplesPerPixel;

  uint32 * tiff_pixels = (uint32*) _TIFFmalloc(tiff_width * tiff_height * sizeof(uint32));
  if (!tiff_pixels)
  {
    TIFFClose(tiff);
    return MEMORY_ERROR;
  }

  printf("Loading TIFF image from file %s: resolution: %d x %d, %d-bit.\n", filename, width, height, 8 * bytesPerPixel);
 
  int stopOnError = 1;
  if (!TIFFReadRGBAImage(tiff, tiff_width, tiff_height, tiff_pixels, stopOnError))
  { 
    _TIFFfree(tiff_pixels);
    TIFFClose(tiff);
    printf("Error in loadTIFF: Unknown error when calling TIFFReadRGBAImage.\n");
    return IO_ERROR;
  }

  pixels = (unsigned char*) malloc (sizeof(unsigned char) * width * height * bytesPerPixel);

  // write tiff_pixels into the pixels array
  int counter = 0;
  for(unsigned int row=0; row < height; row++)
  {
    for(unsigned int column=0; column < width; column++)
    {
      // read the uint32 pixel
      uint32 tiff_pixel = tiff_pixels[row * tiff_width + column];

      // write R,G,B,A in place into pixels
      pixels[counter] = TIFFGetR(tiff_pixel);
      counter++;

      if (bytesPerPixel < 3) 
        continue;

      pixels[counter] = TIFFGetG(tiff_pixel);
      counter++;
      pixels[counter] = TIFFGetB(tiff_pixel);
      counter++;

      if (bytesPerPixel < 4) 
        continue;

      // alpha channel
      pixels[counter] = TIFFGetA(tiff_pixel);
      counter++;
    }
  }

  _TIFFfree(tiff_pixels);
  TIFFClose(tiff);

  return OK;

#else
  return INVALID_FILE_FORMAT;
#endif
}
开发者ID:RainVector,项目名称:VegaFEM,代码行数:95,代码来源:imageIO.cpp

示例13: main

int main(int argc, char *argv[]) {
  TIFF *image;
  // Open the TIFF file
  if((image = TIFFOpen(argv[1], "r")) == NULL){
    printf("Could not open file\n");
    exit(42);
  }
  uint16 bps, spp;
  TIFFGetField(image, TIFFTAG_BITSPERSAMPLE, &bps);
  TIFFGetField(image, TIFFTAG_SAMPLESPERPIXEL, &spp);
  printf("BPS=%u SPP=%u\n", bps, spp);
/*
  uint16 photo, fillorder;
  TIFFGetField(image, TIFFTAG_PHOTOMETRIC, &photo);
  if(!TIFFGetField(image, TIFFTAG_FILLORDER, &fillorder)) {
    printf("FillOrder undefined, assume MSB2LSB\n");
    fillorder = FILLORDER_MSB2LSB;
  }
  printf("photo=%u order=%u\n", photo, fillorder);
*/
  uint16 minsv, maxsv;
  if(!TIFFGetField(image, TIFFTAG_MINSAMPLEVALUE, &minsv)) {
    printf("MinSamplerateValue undefined, assume 0\n");
    minsv = 0;
  }
  if(!TIFFGetField(image, TIFFTAG_MAXSAMPLEVALUE, &maxsv)) {
    printf("MaxSamplerateValue undefined, assume 65535\n");
    maxsv = 65535;
  }
  printf("SampleRateValue Min=%u Max=%u\n", minsv, maxsv);
/*
  tsize_t stripSize = TIFFStripSize (image);
  int stripMax = TIFFNumberOfStrips (image);
  printf("strip size=%d max=%d\n", (int)stripSize, stripMax);
*/
  unsigned int histsize = maxsv-minsv+1;
  uint16 * hist = (uint16*)malloc(histsize * bps/8);
  bzero(hist, histsize * bps/8);
  tsize_t lsize = TIFFScanlineSize(image);
  //unsigned char * buf = (unsigned char*)malloc(bufsize);
  //unsigned int bufsize = stripSize; // * stripMax;
  tdata_t buf = _TIFFmalloc(lsize);
  uint32 imlen;
  TIFFGetField(image, TIFFTAG_IMAGELENGTH, &imlen);
  printf("ImageLength=%d ScanlineSize=%d\n", imlen, lsize);
  for(uint32 i = 0; i < imlen; i++) {
    int readsz = TIFFReadScanline(image, buf, i);
    for(uint32 j = 0; j < lsize*8/bps; j++) {
       uint16 raw = ((uint16*)buf)[j];
       if(raw<minsv || raw>maxsv) { printf(" minsv-maxsv error: %u\n", raw); exit(1); }
       hist[raw-minsv]++;
    }
  }
  for(uint16 i=minsv; i<=maxsv; i++) {
    printf("HIST %u: %u (%.2lf%%)\n", i, hist[i], hist[i]*100./(lsize*imlen/2));
  }
  uint16 minh=0, maxh=65535;
  for(uint16 i=minsv+minr; i<=maxsv; i++) {
    if(hist[i]>minc) { minh=i; break; }
  }
  for(uint16 i=maxsv-maxr; i>=minsv; i--) {
    if(hist[i]>maxc) { maxh=i; break; }
  }
  printf("RANGE %u %u\n", minh, maxh);
}
开发者ID:shurshur,项目名称:ov3wms,代码行数:65,代码来源:hist.cpp

示例14: main

int
main(int argc, char* argv[])
{
	uint32 rowsperstrip = (uint32) -1;
	TIFF *in, *out;
	uint32 w, h;
	uint16 samplesperpixel;
	uint16 bitspersample;
	uint16 config;
	uint16 photometric;
	uint16* red;
	uint16* green;
	uint16* blue;
	tsize_t rowsize;
	register uint32 row;
	register tsample_t s;
	unsigned char *inbuf, *outbuf;
	char thing[1024];
	int c;
	extern int optind;
	extern char *optarg;

	while ((c = getopt(argc, argv, "c:r:R:G:B:")) != -1)
		switch (c) {
		case 'c':		/* compression scheme */
			if (!processCompressOptions(optarg))
				usage();
			break;
		case 'r':		/* rows/strip */
			rowsperstrip = atoi(optarg);
			break;
		case 'R':
			RED = PCT(atoi(optarg));
			break;
		case 'G':
			GREEN = PCT(atoi(optarg));
			break;
		case 'B':
			BLUE = PCT(atoi(optarg));
			break;
		case '?':
			usage();
			/*NOTREACHED*/
		}
	if (argc - optind < 2)
		usage();
	in = TIFFOpen(argv[optind], "r");
	if (in == NULL)
		return (-1);
	photometric = 0;
	TIFFGetField(in, TIFFTAG_PHOTOMETRIC, &photometric);
	if (photometric != PHOTOMETRIC_RGB && photometric != PHOTOMETRIC_PALETTE ) {
		fprintf(stderr,
	    "%s: Bad photometric; can only handle RGB and Palette images.\n",
		    argv[optind]);
		return (-1);
	}
	TIFFGetField(in, TIFFTAG_SAMPLESPERPIXEL, &samplesperpixel);
	if (samplesperpixel != 1 && samplesperpixel != 3) {
		fprintf(stderr, "%s: Bad samples/pixel %u.\n",
		    argv[optind], samplesperpixel);
		return (-1);
	}
	TIFFGetField(in, TIFFTAG_BITSPERSAMPLE, &bitspersample);
	if (bitspersample != 8) {
		fprintf(stderr,
		    " %s: Sorry, only handle 8-bit samples.\n", argv[optind]);
		return (-1);
	}
	TIFFGetField(in, TIFFTAG_IMAGEWIDTH, &w);
	TIFFGetField(in, TIFFTAG_IMAGELENGTH, &h);
	TIFFGetField(in, TIFFTAG_PLANARCONFIG, &config);

	out = TIFFOpen(argv[optind+1], "w");
	if (out == NULL)
		return (-1);
	cpTags(in, out);
	TIFFSetField(out, TIFFTAG_BITSPERSAMPLE, 8);
	TIFFSetField(out, TIFFTAG_SAMPLESPERPIXEL, 1);
	TIFFSetField(out, TIFFTAG_PLANARCONFIG, PLANARCONFIG_CONTIG);
	if (compression != (uint16) -1) {
		TIFFSetField(out, TIFFTAG_COMPRESSION, compression);
		switch (compression) {
		case COMPRESSION_JPEG:
			TIFFSetField(out, TIFFTAG_JPEGQUALITY, quality);
			TIFFSetField(out, TIFFTAG_JPEGCOLORMODE, jpegcolormode);
			break;
		case COMPRESSION_LZW:
		case COMPRESSION_DEFLATE:
			if (predictor != 0)
				TIFFSetField(out, TIFFTAG_PREDICTOR, predictor);
			break;
		}
	}
	TIFFSetField(out, TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_MINISBLACK);
	sprintf(thing, "B&W version of %s", argv[optind]);
	TIFFSetField(out, TIFFTAG_IMAGEDESCRIPTION, thing);
	TIFFSetField(out, TIFFTAG_SOFTWARE, "tiff2bw");
	outbuf = (unsigned char *)_TIFFmalloc(TIFFScanlineSize(out));
	TIFFSetField(out, TIFFTAG_ROWSPERSTRIP,
//.........这里部分代码省略.........
开发者ID:Starlink,项目名称:tkimg,代码行数:101,代码来源:tiff2bw.c

示例15: cpTiff

static int cpTiff(TIFF* in, TIFF* out,
                  const uint16_t iLayer, const uint16_t nLayer)
{
	uint16_t samplesperpixel;
	uint16_t orientation;
	uint32_t width, length, rowsperstrip;

    // Image size and memory layout.
	CopyField(TIFFTAG_IMAGEWIDTH, width);
	CopyField(TIFFTAG_IMAGELENGTH, length);
    {
		/*
		 * RowsPerStrip is left unspecified: use either the
		 * value from the input image or, if nothing is defined,
		 * use the library default.
		 */
		if (!TIFFGetField(in, TIFFTAG_ROWSPERSTRIP, &rowsperstrip)) {
			rowsperstrip = TIFFDefaultStripSize(out, rowsperstrip);
		}
		if (rowsperstrip > length && rowsperstrip != (uint32_t)-1) {
			rowsperstrip = length;
        }
		TIFFSetField(out, TIFFTAG_ROWSPERSTRIP, rowsperstrip);
	}
    CopyField(TIFFTAG_SAMPLESPERPIXEL, samplesperpixel);
	if (samplesperpixel <= 4)
		CopyTag(TIFFTAG_TRANSFERFUNCTION, 4, TIFF_SHORT);

    // Image orientation (per page).
	TIFFGetFieldDefaulted(in, TIFFTAG_ORIENTATION, &orientation);
	switch (orientation) {
		case ORIENTATION_BOTRIGHT:
		case ORIENTATION_RIGHTBOT:	/* XXX */
			TIFFWarning(TIFFFileName(in), "using bottom-left orientation");
			orientation = ORIENTATION_BOTLEFT;
		/* fall thru... */
		case ORIENTATION_LEFTBOT:	/* XXX */
		case ORIENTATION_BOTLEFT:
			break;
		case ORIENTATION_TOPRIGHT:
		case ORIENTATION_RIGHTTOP:	/* XXX */
		default:
			TIFFWarning(TIFFFileName(in), "using top-left orientation");
			orientation = ORIENTATION_TOPLEFT;
		/* fall thru... */
		case ORIENTATION_LEFTTOP:	/* XXX */
		case ORIENTATION_TOPLEFT:
			break;
	}
	TIFFSetField(out, TIFFTAG_ORIENTATION, orientation);

    // Colormap profile.
	{
		uint32_t len32;
		void** data;
		if (TIFFGetField(in, TIFFTAG_ICCPROFILE, &len32, &data))
			TIFFSetField(out, TIFFTAG_ICCPROFILE, len32, data);
	}
	{
		uint16_t ninks;
		const char* inknames;
		if (TIFFGetField(in, TIFFTAG_NUMBEROFINKS, &ninks)) {
			TIFFSetField(out, TIFFTAG_NUMBEROFINKS, ninks);
			if (TIFFGetField(in, TIFFTAG_INKNAMES, &inknames)) {
				int inknameslen = strlen(inknames) + 1;
				const char* cp = inknames;
				while (ninks > 1) {
					cp = strchr(cp, '\0');
                    cp++;
                    inknameslen += (strlen(cp) + 1);
					ninks--;
				}
				TIFFSetField(out, TIFFTAG_INKNAMES, inknameslen, inknames);
			}
		}
	}

    // Page number.
	TIFFSetField(out, TIFFTAG_PAGENUMBER, iLayer, nLayer);

    // Rest of the tags, directly copy them.
	for (struct defTagList *t = tags; t < &tags[NTAGS]; t++)
		CopyTag(t->tag, t->count,t->type);

	return cpData(in, out, length);
}
开发者ID:liuyenting,项目名称:python-tiff-transpose,代码行数:86,代码来源:tiff.cpp


注:本文中的TIFFGetField函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。