tiff

package module
v0.0.0-...-f6e011e Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 3, 2020 License: BSD-3-Clause Imports: 15 Imported by: 1

README

tiff

GoDoc

This is a Go package to read and write TIFF or TIFF-like files.

This package is still experimental. Some features are missing, especially in the case of the encoder.

Features

Category Feature Decode Encode
Format Classic TIFF Yes Yes
BigTIFF Yes Yes
Metadata TIFF tags Yes Yes
Exif tags Yes Yes
GPS tags Yes -
Lossless Compression LZW Yes Yes
Deflate Yes Yes
zstd Yes Yes
Lossless JPEG - -
Lossy Compression Lossy JPEG 8-bit YCbCr -
Bit depth 1-bit - -
8-bit Yes Yes
16-bit Yes Yes
Planar Configuration Contig Yes Yes
Separate (planar) - -
Segmented Images Strip Yes Yes
Tile Yes -

Documentation

Overview

Package tiff implements structures and functionality to encode and decode TIFF-like files.

To iterate through images in a multi-page TIFF and read image data:

r, err := tiff.NewReader(f)
if err != nil {
	// handle error
}
iter := r.Iter()
for iter.Next() {
	im := iter.Image()
	width, height := im.WidthHeight()
	samplesPerPixel := im.SamplesPerPixel()
	if width * height * samplesPerPixel == 0 {
		continue
	}
	switch im.DataType() {
	case tiff.Uint8:
		buf := make([]uint8, width*height*samplesPerPixel)
		err = im.DecodeImage(buf)
	case tiff.Uint16:
		buf := make([]uint16, width*height*samplesPerPixel)
		err = im.DecodeImage(buf)
	}
}
if err := iter.Err(); err != nil {
	// handle error
}

To read SubIFDs:

if im.SubImage != nil {
	for _, subim := range im.SubImage {
		// access subim
	}
}

To read any TIFF tag, EXIF tag or GPS tag:

bisPerSample, ok := im.Tag[tiff.TagBitsPerSample].UintSlice()
make, ok := im.Tag[tiff.TagMake].String()
model, ok := im.Tag[tiff.TagModel].String()

exposure, ok := im.Exif.Tag[tiff.TagExposureTime].Rational()
exposureSecond := float64(exposure[0]) / float64(exposure[1])
lensModel, ok := im.Exif.Tag[tiff.TagLensModel].String()

To encode a TIFF image with one or multiple pages:

enc, err := tiff.NewEncoder(f)
if err != nil {
	// handle error
}
// Default:
// enc.SetByteOrder(binary.LittleEndian)
// enc.SetVersion(tiff.VersionClassicTIFF)
im := enc.NewImage()
im.SetWidthHeight(400, 300)
im.SetPixelFormat(tiff.PhotometricRGB, 3, []uint16{8, 8, 8})
im.SetCompression(tiff.CompressionNone)

im.SetTag(tiff.TagImageDescription, tiff.TagTypeASCII, "your image description")
im.SetTag(tiff.TagDateTime, tiff.TagTypeASCII, "")
im.SetTag(tiff.TagXResolution, tiff.TagTypeRational, [2]uint32{})
im.SetTag(tiff.TagYResolution, tiff.TagTypeRational, [2]uint32{})
im.SetTag(tiff.TagResolutionUnit, , tiff.TagTypeShort, 1)
im.SetExifTag(tiff.ExifTagExposureTime, tiff.TagTypeRational, [2]uint32{})
err = im.EncodeImage(buf)

// To write another image
im = w.NewImage()
// ...
err = im.EncodeImage(buf)

w.Close()

To encode a TIFF image with sub-images (SubIFDs).

im := w.NewImage()
// ...
// AddSubImage needs to be performed before calling EncodeImage()
subim1 := im.AddSubImage()
subim1.SetWidthHeight()
// ...
err = im.EncodeImage(buf)
err = subim1.EncodeImage(buf)

w.Close()

Index

Constants

View Source
const (
	NewFiletypeImage        = 0x0 // full resolution version
	NewFiletypeReducedImage = 0x1 // reduced resolution version
	NewFiletypePage         = 0x2 // one page of many
	NewFiletypeMask         = 0x4 // transparency mask

	CompressionNone       = 1     // Baseline. None
	CompressionCCITTRLE   = 2     // CCITT modified Huffman RLE
	CompressionCCITTG3    = 3     // CCITT T.4 (Group 3)
	CompressionCCITTG4    = 4     // CCITT T.6 (Group 4)
	CompressionLZW        = 5     // LZW
	CompressionJPEGOld    = 6     // Old-style JPEG
	CompressionJPEG       = 7     // JPEG
	CompressionDeflate    = 8     // Deflate compression
	CompressionDeflateOld = 32946 // Non-standard. Deflate compression
	CompressionPackBits   = 32773 // Baseline. PackBits compression
	CompressionLossyJPEG  = 34892 // Lossy JPEG
	CompressionLZMA       = 34925 // LZMA2
	CompressionZstd       = 50000 // ZSTD: WARNING not registered in Adobe-maintained registry
	CompressionWebP       = 50001 // WEBP: WARNING not registered in Adobe-maintained registry

	PhotometricWhiteIsZero = 0     // WhiteIsZero
	PhotometricBlackIsZero = 1     // BlackIsZero
	PhotometricRGB         = 2     // RGB
	PhotometricPalette     = 3     // Palette color
	PhotometricMask        = 4     // Transparency mask
	PhotometricSeparated   = 5     // Separated (usually CMYK)
	PhotometricYCbCr       = 6     // YCbCr
	PhotometricCIELab      = 8     // 1976 CIE L*a*b*
	PhotometricICCLab      = 9     // ICC L*a*b*
	PhotometricITULab      = 10    // ITU L*a*b*
	PhotometricCFA         = 32803 // Color filter array
	PhotometricLogL        = 32844 // CIE Log2(L)
	PhotometricLogLuv      = 32845 // CIE Log2(L) (u',v')
	PhotometricLinearRaw   = 34925 // LinearRaw (or de-mosaiced CFA data)

	PlanarConfigContig   = 1 // The component values for each pixel are stored contiguously, e.g, RGBRGB...RGB
	PlanarConfigSeparate = 2 // The components are stored in separate component planes, e.g., RR..RGG..GBB..B
)
View Source
const (
	// Baseline & Extended TIFF
	TagNewSubfileType         TagID = 254   // Baseline. A general indication of the kind of data contained in this subfile.
	TagSubfileType            TagID = 255   // Baseline. A general indication of the kind of data contained in this subfile.
	TagImageWidth             TagID = 256   // Baseline. The number of columns in the image, i.e., the number of pixels per row.
	TagImageLength            TagID = 257   // Baseline. The number of rows of pixels in the image.
	TagBitsPerSample          TagID = 258   // Baseline. Number of bits per component.
	TagCompression            TagID = 259   // Baseline. Compression scheme used on the image data.
	TagPhotometric            TagID = 262   // Baseline. The color space of the image data.
	TagThreshholding          TagID = 263   // Baseline. For black and white TIFF files that represent shades of gray, the technique used to convert from gray to black and white pixels.
	TagCellWidth              TagID = 264   // Baseline. The width of the dithering or halftoning matrix used to create a dithered or halftoned bilevel file.
	TagCellLength             TagID = 265   // Baseline. The length of the dithering or halftoning matrix used to create a dithered or halftoned bilevel file.
	TagFillOrder              TagID = 266   // Baseline. The logical order of bits within a byte.
	TagDocumentName           TagID = 269   // Extended. The name of the document from which this image was scanned.
	TagImageDescription       TagID = 270   // Baseline. A string that describes the subject of the image.
	TagMake                   TagID = 271   // Baseline. The scanner manufacturer.
	TagModel                  TagID = 272   // Baseline. The scanner model name or number.
	TagStripOffsets           TagID = 273   // Baseline. For each strip, the byte offset of that strip.
	TagOrientation            TagID = 274   // Baseline. The orientation of the image with respect to the rows and columns.
	TagSamplesPerPixel        TagID = 277   // Baseline. The number of components per pixel.
	TagRowsPerStrip           TagID = 278   // Baseline. The number of rows per strip.
	TagStripByteCounts        TagID = 279   // Baseline. For each strip, the number of bytes in the strip after compression.
	TagMinSampleValue         TagID = 280   // Baseline. The minimum component value used.
	TagMaxSampleValue         TagID = 281   // Baseline. The maximum component value used.
	TagXResolution            TagID = 282   // Baseline. The number of pixels per ResolutionUnit in the ImageWidth direction.
	TagYResolution            TagID = 283   // Baseline. The number of pixels per ResolutionUnit in the ImageLength direction.
	TagPlanarConfig           TagID = 284   // Baseline. How the components of each pixel are stored.
	TagPageName               TagID = 285   // Extended. The name of the page from which this image was scanned.
	TagXPosition              TagID = 286   // Extended. X position of the image.
	TagYPosition              TagID = 287   // Extended. Y position of the image.
	TagFreeOffsets            TagID = 288   // Baseline. For each string of contiguous unused bytes in a TIFF file, the byte offset of the string.
	TagFreeByteCounts         TagID = 289   // Baseline. For each string of contiguous unused bytes in a TIFF file, the number of bytes in the string.
	TagGrayResponseUnit       TagID = 290   // Baseline. The precision of the information contained in the GrayResponseCurve.
	TagGrayResponseCurve      TagID = 291   // Baseline. For grayscale data, the optical density of each possible pixel value.
	TagT4Options              TagID = 292   // Extended. Options for Group 3 Fax compression
	TagT6Options              TagID = 293   // Extended. Options for Group 4 Fax compression
	TagResolutionUnit         TagID = 296   // Baseline. The unit of measurement for XResolution and YResolution.
	TagPageNumber             TagID = 297   // Extended. The page number of the page from which this image was scanned.
	TagTransferFunction       TagID = 301   // Extended. Describes a transfer function for the image in tabular style.
	TagSoftware               TagID = 305   // Baseline. Name and version number of the software package(s) used to create the image.
	TagDateTime               TagID = 306   // Baseline. Date and time of image creation.
	TagArtist                 TagID = 315   // Baseline. Person who created the image.
	TagHostComputer           TagID = 316   // Baseline. The computer and/or operating system in use at the time of image creation.
	TagPredictor              TagID = 317   // Extended. A mathematical operator that is applied to the image data before an encoding scheme is applied.
	TagWhitePoint             TagID = 318   // Extended. The chromaticity of the white point of the image.
	TagPrimaryChromaticities  TagID = 319   // Extended. The chromaticities of the primaries of the image.
	TagColorMap               TagID = 320   // Baseline & Supplement1. A color map for palette color images.
	TagHalftoneHints          TagID = 321   // Extended. Conveys to the halftone function the range of gray levels within a colorimetrically-specified image that should retain tonal detail.
	TagTileWidth              TagID = 322   // Extended. The tile width in pixels. This is the number of columns in each tile.
	TagTileLength             TagID = 323   // Extended. The tile length (height) in pixels. This is the number of rows in each tile.
	TagTileOffsets            TagID = 324   // Extended. For each tile, the byte offset of that tile, as compressed and stored on disk.
	TagTileByteCounts         TagID = 325   // Extended. For each tile, the number of (compressed) bytes in that tile.
	TagBadFaxLines            TagID = 326   // Extended. Used in the TIFF-F standard, denotes the number of 'bad' scan lines encountered by the facsimile device.
	TagCleanFaxData           TagID = 327   // Extended. Used in the TIFF-F standard, indicates if 'bad' lines encountered during reception are stored in the data, or if 'bad' lines have been replaced by the receiver.
	TagConsecutiveBadFaxLines TagID = 328   // Extended. Used in the TIFF-F standard, denotes the maximum number of consecutive 'bad' scanlines received.
	TagSubIFDs                TagID = 330   // Supplement1. Offset to child IFDs.
	TagInkSet                 TagID = 332   // Extended. The set of inks used in a separated (Photometric = 5) image.
	TagInkNames               TagID = 333   // Extended. The name of each ink used in a separated image.
	TagNumberOfInks           TagID = 334   // Extended. The number of inks.
	TagDotRange               TagID = 336   // Extended. The component values that correspond to a 0% dot and 100% dot.
	TagTargetPrinter          TagID = 337   // Extended. A description of the printing environment for which this separation is intended.
	TagExtraSamples           TagID = 338   // Baseline. Description of extra components.
	TagSampleFormat           TagID = 339   // Extended. Specifies how to interpret each data sample in a pixel.
	TagSMinSampleValue        TagID = 340   // Extended. Specifies the minimum sample value.
	TagSMaxSampleValue        TagID = 341   // Extended. Specifies the maximum sample value.
	TagTransferRange          TagID = 342   // Extended. Expands the range of the TransferFunction.
	TagClipPath               TagID = 343   // Supplement1. Mirrors the essentials of PostScript's path creation functionality.
	TagXClipPathUnits         TagID = 344   // Supplement1. The number of units that span the width of the image, in terms of integer ClipPath coordinates.
	TagYClipPathUnits         TagID = 345   // Supplement1. The number of units that span the height of the image, in terms of integer ClipPath coordinates.
	TagIndexed                TagID = 346   // Supplement1. Aims to broaden the support for indexed images to include support for any color space.
	TagJPEGTables             TagID = 347   // Supplement1. JPEG quantization and/or Huffman tables.
	TagOPIProxy               TagID = 351   // Supplement1. OPI-related.
	TagGlobalParametersIFD    TagID = 400   // Extended. Used in the TIFF-FX standard to point to an IFD containing tags that are globally applicable to the complete TIFF file.
	TagProfileType            TagID = 401   // Extended. Used in the TIFF-FX standard, denotes the type of data stored in this file or IFD.
	TagFaxProfile             TagID = 402   // Extended. Used in the TIFF-FX standard, denotes the 'profile' that applies to this file.
	TagCodingMethods          TagID = 403   // Extended. Used in the TIFF-FX standard, indicates which coding methods are used in the file.
	TagVersionYear            TagID = 404   // Extended. Used in the TIFF-FX standard, denotes the year of the standard specified by the FaxProfile field.
	TagModeNumber             TagID = 405   // Extended. Used in the TIFF-FX standard, denotes the mode of the standard specified by the FaxProfile field.
	TagDecode                 TagID = 433   // Extended. Used in the TIFF-F and TIFF-FX standards, holds information about the ITULAB (Photometric = 10) encoding.
	TagDefaultImageColor      TagID = 434   // Extended. Defined in the Mixed Raster Content part of RFC 2301, is the default color needed in areas where no image is available.
	TagJPEGProc               TagID = 512   // Extended. Old-style JPEG compression field. TechNote2 invalidates this part of the specification. But it is still quite widely used.
	TagJPEGIFOffset           TagID = 513   // Extended. Old-style JPEG compression field. TechNote2 invalidates this part of the specification. But it is still quite widely used.
	TagJPEGIFByteCount        TagID = 514   // Extended. Old-style JPEG compression field. TechNote2 invalidates this part of the specification. But it is still quite widely used.
	TagJPEGRestartInterval    TagID = 515   // Extended. Old-style JPEG compression field. TechNote2 invalidates this part of the specification. But it is still quite widely used.
	TagJPEGLosslessPredictors TagID = 517   // Extended. Old-style JPEG compression field. TechNote2 invalidates this part of the specification. But it is still quite widely used.
	TagJPEGPointTransforms    TagID = 518   // Extended. Old-style JPEG compression field. TechNote2 invalidates this part of the specification. But it is still quite widely used.
	TagJPEGQTables            TagID = 519   // Extended. Old-style JPEG compression field. TechNote2 invalidates this part of the specification. But it is still quite widely used.
	TagJPEGDCTables           TagID = 520   // Extended. Old-style JPEG compression field. TechNote2 invalidates this part of the specification. But it is still quite widely used.
	TagJPEGACTables           TagID = 521   // Extended. Old-style JPEG compression field. TechNote2 invalidates this part of the specification. But it is still quite widely used.
	TagYCbCrCoefficients      TagID = 529   // Extended. The transformation from RGB to YCbCr image data.
	TagYCbCrSubSampling       TagID = 530   // Extended. Specifies the subsampling factors used for the chrominance components of a YCbCr image.
	TagYCbCrPositioning       TagID = 531   // Extended. Specifies the positioning of subsampled chrominance components relative to luminance samples.
	TagReferenceBlackWhite    TagID = 532   // Extended. Specifies a pair of headroom and footroom image data values (codes) for each pixel component.
	TagStripRowCounts         TagID = 559   // Extended. Defined in the Mixed Raster Content part of RFC 2301, used to replace RowsPerStrip for IFDs with variable-sized strips.
	TagXMP                    TagID = 700   // Extended. XML packet containing XMP metadata
	TagImageID                TagID = 32781 // Supplement1. OPI-related.
	TagCopyright              TagID = 33432 // Baseline. Copyright notice.
	TagImageLayer             TagID = 34732 // Extended. Defined in the Mixed Raster Content part of RFC 2301, used to denote the particular function of this Image in the mixed raster scheme.

	// From libtiff
	TagColorResponseUnit TagID = 300
	TagT82Options        TagID = 435

	// TIFF/EP
	TagCFARepeatPatternDim      TagID = 33421
	TagCFAPattern               TagID = 33422
	TagSelfTimeMode             TagID = 34859
	TagFocalPlaneXResolution    TagID = 37390
	TagFocalPlaneYResolution    TagID = 37391
	TagFocalPlaneResolutionUnit TagID = 37392
	TagImageNumber              TagID = 37393
	TagSecurityClassification   TagID = 37394
	TagImageHistory             TagID = 37395
	TagExposureIndex            TagID = 37397
	TagTIFFEPStandardID         TagID = 37398
	TagSensingMethod            TagID = 37399

	// EXIF Private IFDs
	TagExifIFD             TagID = 34665
	TagGPSIFD              TagID = 34853
	TagInteroperabilityIFD TagID = 40965

	// EXIF Tags
	ExifTagExposureTime             ExifTagID = 33434
	ExifTagFNumber                  ExifTagID = 33437
	ExifTagExposureProgram          ExifTagID = 34850
	ExifTagSpectralSensitivity      ExifTagID = 34852
	ExifTagISOSpeedRatings          ExifTagID = 34855
	ExifTagOECF                     ExifTagID = 34856
	ExifTagSensitivityType          ExifTagID = 34864
	ExifTagRecommendedExposureIndex ExifTagID = 34866
	ExifTagExifVersion              ExifTagID = 36864
	ExifTagDateTimeOriginal         ExifTagID = 36867
	ExifTagDateTimeDigitized        ExifTagID = 36868
	ExifTagComponentsConfiguration  ExifTagID = 37121
	ExifTagCompressedBitsPerPixel   ExifTagID = 37122
	ExifTagShutterSpeedValue        ExifTagID = 37377
	ExifTagApertureValue            ExifTagID = 37378
	ExifTagBrightnessValue          ExifTagID = 37379
	ExifTagExposureBiasValue        ExifTagID = 37380
	ExifTagMaxApertureValue         ExifTagID = 37381
	ExifTagSubjectDistance          ExifTagID = 37382
	ExifTagMeteringMode             ExifTagID = 37383
	ExifTagLightSource              ExifTagID = 37384
	ExifTagFlash                    ExifTagID = 37385
	ExifTagFocalLength              ExifTagID = 37386
	ExifTagSubjectArea              ExifTagID = 37396
	ExifTagMakerNote                ExifTagID = 37500
	ExifTagUserComment              ExifTagID = 37510
	ExifTagSubsecTime               ExifTagID = 37520
	ExifTagSubsecTimeOriginal       ExifTagID = 37521
	ExifTagSubsecTimeDigitized      ExifTagID = 37522
	ExifTagFlashpixVersion          ExifTagID = 40960
	ExifTagColorSpace               ExifTagID = 40961
	ExifTagPixelXDimension          ExifTagID = 40962
	ExifTagPixelYDimension          ExifTagID = 40963
	ExifTagRelatedSoundFile         ExifTagID = 40964
	ExifTagFlashEnergy              ExifTagID = 41483
	ExifTagSpatialFrequencyResponse ExifTagID = 41484
	ExifTagFocalPlaneXResolution    ExifTagID = 41486
	ExifTagFocalPlaneYResolution    ExifTagID = 41487
	ExifTagFocalPlaneResolutionUnit ExifTagID = 41488
	ExifTagSubjectLocation          ExifTagID = 41492
	ExifTagExposureIndex            ExifTagID = 41493
	ExifTagSensingMethod            ExifTagID = 41495
	ExifTagFileSource               ExifTagID = 41728
	ExifTagSceneType                ExifTagID = 41729
	ExifTagCFAPattern               ExifTagID = 41730
	ExifTagCustomRendered           ExifTagID = 41985
	ExifTagExposureMode             ExifTagID = 41986
	ExifTagWhiteBalance             ExifTagID = 41987
	ExifTagDigitalZoomRatio         ExifTagID = 41988
	ExifTagFocalLengthIn35mmFilm    ExifTagID = 41989
	ExifTagSceneCaptureType         ExifTagID = 41990
	ExifTagGainControl              ExifTagID = 41991
	ExifTagContrast                 ExifTagID = 41992
	ExifTagSaturation               ExifTagID = 41993
	ExifTagSharpness                ExifTagID = 41994
	ExifTagDeviceSettingDescription ExifTagID = 41995
	ExifTagSubjectDistanceRange     ExifTagID = 41996
	ExifTagImageUniqueID            ExifTagID = 42016
	ExifTagCameraOwnerName          ExifTagID = 42032
	ExifTagBodySerialNumber         ExifTagID = 42033
	ExifTagLensSpecification        ExifTagID = 42034
	ExifTagLensMake                 ExifTagID = 42035
	ExifTagLensModel                ExifTagID = 42036
	ExifTagLensSerialNumber         ExifTagID = 42037

	// DNG 1.0
	TagDNGVersion             TagID = 50706
	TagDNGBackwardVersion     TagID = 50707
	TagUniqueCameraModel      TagID = 50708
	TagLocalizedCameraModel   TagID = 50709
	TagCFAPlaneColor          TagID = 50710
	TagCFALayout              TagID = 50711
	TagLinearizationTable     TagID = 50712
	TagBlackLevelRepeatDim    TagID = 50713
	TagBlackLevel             TagID = 50714
	TagBlackLevelDeltaH       TagID = 50715
	TagBlackLevelDeltaV       TagID = 50716
	TagWhiteLevel             TagID = 50717
	TagDefaultScale           TagID = 50718
	TagBestQualityScale       TagID = 50780
	TagDefaultCropOrigin      TagID = 50719
	TagDefaultCropSize        TagID = 50720
	TagCalibrationIlluminant1 TagID = 50778
	TagCalibrationIlluminant2 TagID = 50779
	TagColorMatrix1           TagID = 50721
	TagColorMatrix2           TagID = 50722
	TagCameraCalibration1     TagID = 50723
	TagCameraCalibration2     TagID = 50724
	TagReductionMatrix1       TagID = 50725
	TagReductionMatrix2       TagID = 50726
	TagAnalogBalance          TagID = 50727
	TagAsShotNeutral          TagID = 50728
	TagAsShotWhiteXY          TagID = 50729
	TagBaselineExposure       TagID = 50730
	TagBaselineNoise          TagID = 50731
	TagBaselineSharpness      TagID = 50732
	TagBayerGreenSplit        TagID = 50733
	TagLinearResponseLimit    TagID = 50734
	TagCameraSerialNumber     TagID = 50735
	TagLensInfo               TagID = 50736
	TagChromaBlurRadius       TagID = 50737
	TagAntiAliasStrength      TagID = 50738
	TagDNGPrivateData         TagID = 50740
	TagMakerNoteSafety        TagID = 50741

	// DNG 1.1
	TagShadowScale             TagID = 50739
	TagRawDataUniqueID         TagID = 50781
	TagOriginalRawFileName     TagID = 50827
	TagOriginalRawFileData     TagID = 50828
	TagActiveArea              TagID = 50829
	TagMaskedAreas             TagID = 50830
	TagAsShotICCProfile        TagID = 50831
	TagAsShotPreProfileMatrix  TagID = 50832
	TagCurrentICCProfile       TagID = 50833
	TagCurrentPreProfileMatrix TagID = 50834

	// DNG 1.2
	TagColorimetricReference       TagID = 50879
	TagCameraCalibrationSignature  TagID = 50931
	TagProfileCalibrationSignature TagID = 50932
	TagExtraCameraProfiles         TagID = 50933
	TagAsShotProfileName           TagID = 50934
	TagNoiseReductionApplied       TagID = 50935
	TagProfileName                 TagID = 50936
	TagProfileHueSatMapDims        TagID = 50937
	TagProfileHueSatMapData1       TagID = 50938
	TagProfileHueSatMapData2       TagID = 50939
	TagProfileToneCurve            TagID = 50940
	TagProfileEmbedPolicy          TagID = 50941
	TagProfileCopyright            TagID = 50942
	TagForwardMatrix1              TagID = 50964
	TagForwardMatrix2              TagID = 50965
	TagPreviewApplicationName      TagID = 50966
	TagPreviewApplicationVersion   TagID = 50967
	TagPreviewSettingsName         TagID = 50968
	TagPreviewSettingsDigest       TagID = 50969
	TagPreviewColorSpace           TagID = 50970
	TagPreviewDateTime             TagID = 50971
	TagRawImageDigest              TagID = 50972
	TagOriginalRawFileDigest       TagID = 50973
	TagSubTileBlockSize            TagID = 50974
	TagRowInterleaveFactor         TagID = 50975
	TagProfileLookTableDims        TagID = 50981
	TagProfileLookTableData        TagID = 50982

	// DNG 1.3
	TagOpcodeList1  TagID = 51008
	TagOpcodeList2  TagID = 51009
	TagOpcodeList3  TagID = 51022
	TagNoiseProfile TagID = 51041

	// DNG 1.4
	TagDefaultUserCrop              TagID = 51125
	TagDefaultBlackRender           TagID = 51110
	TagBaselineExposureOffset       TagID = 51109
	TagProfileLookTableEncoding     TagID = 51108
	TagProfileHueSatMapEncoding     TagID = 51107
	TagOriginalDefaultFinalSize     TagID = 51089
	TagOriginalBestQualityFinalSize TagID = 51090
	TagOriginalDefaultCropSize      TagID = 51091
	TagNewRawImageDigest            TagID = 51111
	TagRawToPreviewGain             TagID = 51112

	// DNG (Adobe DNG SDK)
	TagCacheBlob    TagID = 51113
	TagCacheVersion TagID = 51114
)

Variables

This section is empty.

Functions

func DecodeASCII

func DecodeASCII(count int, data []byte, byteOrder binary.ByteOrder) ([]string, error)

func DecodeDouble

func DecodeDouble(count int, data []byte, byteOrder binary.ByteOrder) []float64

func DecodeFloat

func DecodeFloat(count int, data []byte, byteOrder binary.ByteOrder) []float32

func DecodeLong

func DecodeLong(count int, data []byte, byteOrder binary.ByteOrder) []uint32

func DecodeLong8

func DecodeLong8(count int, data []byte, byteOrder binary.ByteOrder) []uint64

func DecodeSByte

func DecodeSByte(count int, data []byte, byteOrder binary.ByteOrder) []int8

func DecodeSLong

func DecodeSLong(count int, data []byte, byteOrder binary.ByteOrder) []int32

func DecodeSLong8

func DecodeSLong8(count int, data []byte, byteOrder binary.ByteOrder) []int64

func DecodeSShort

func DecodeSShort(count int, data []byte, byteOrder binary.ByteOrder) []int16

func DecodeShort

func DecodeShort(count int, data []byte, byteOrder binary.ByteOrder) []uint16

Types

type DataType

type DataType int
const (
	InvalidDataType DataType = iota
	Uint8
	Uint16
)

type Decoder

type Decoder struct {
	Header *Header
	// contains filtered or unexported fields
}

Decoder of TIFF format.

func NewDecoder

func NewDecoder(r io.ReaderAt) (*Decoder, error)

NewDecoder returns a TIFF decoder.

func (*Decoder) DecodeExifIFD

func (d *Decoder) DecodeExifIFD(offset int64) (exif *ExifIFD, err error)

DecodeExifIFD decodes IFD at given offset and returns as ExifIFD.

func (*Decoder) DecodeGPSIFD

func (d *Decoder) DecodeGPSIFD(offset int64) (gps *GPSIFD, err error)

DecodeGPSIFD decodes IFD at given offset and returns as GPSIFD.

func (*Decoder) DecodeIFD

func (d *Decoder) DecodeIFD(offset int64) (im *Image, err error)

DecodeIFD decodes IFD at given offset and returns the IFD, without handling SubIFD, etc.

func (*Decoder) DecodeInteroperabilityIFD

func (d *Decoder) DecodeInteroperabilityIFD(offset int64) (interoperability *InteroperabilityIFD, err error)

DecodeInteroperabilityIFD decodes IFD at given offset and returns as InteroperabilityIFD.

func (*Decoder) Iter

func (d *Decoder) Iter() *Iter

Iter returns an Image iterator.

type Encoder

type Encoder struct {
	Header *Header
	// contains filtered or unexported fields
}

func NewEncoder

func NewEncoder(w io.WriteSeeker) *Encoder

func (*Encoder) Close

func (enc *Encoder) Close() error

func (*Encoder) NewImage

func (enc *Encoder) NewImage() *Image

func (*Encoder) SetByteOrder

func (enc *Encoder) SetByteOrder(byteOrder binary.ByteOrder)

func (*Encoder) SetVersion

func (enc *Encoder) SetVersion(version Version)

type ExifIFD

type ExifIFD struct {
	Tag map[ExifTagID]*ExifTag

	// Filled by Encoder or Decoder
	Header     *Header // Header of the TIFF file
	Offset     int64   // Offset of this IFD
	OffsetNext int64   // Offset of the next IFD
}

func (*ExifIFD) TagID

func (dir *ExifIFD) TagID() []ExifTagID

type ExifTag

type ExifTag struct {
	ID    ExifTagID // Tag identifying code
	Type  TagType   // Data type of tag data
	Count int       // Number of values
	Data  []byte    // Tag data or offset to tag data

	// Filled by Encoder or Decoder
	Header      *Header // Header of the TIFF file
	OffsetEntry int64   // Offset of the tag in the TIFF file
	OffsetData  int64   // Offset of the data if the data are not in the IFD Entry
}

func (*ExifTag) GoString

func (t *ExifTag) GoString() string

type ExifTagID

type ExifTagID uint16

ExifTagID identifies the Exif tag field

func (ExifTagID) String

func (t ExifTagID) String() string

type FormatError

type FormatError string

A FormatError reports that the input is not a valid TIFF image.

var (
	ErrInvalidHeader FormatError = "invalid header"
)

func (FormatError) Error

func (e FormatError) Error() string

type GPSIFD

type GPSIFD struct {
	Tag map[GPSTagID]*GPSTag

	// Filled by Encoder or Decoder
	Header     *Header // Header of the TIFF file
	Offset     int64   // Offset of this IFD
	OffsetNext int64   // Offset of the next IFD
}

func (*GPSIFD) TagID

func (dir *GPSIFD) TagID() []GPSTagID

type GPSTag

type GPSTag struct {
	ID    GPSTagID // Tag identifying code
	Type  TagType  // Data type of tag data
	Count int      // Number of values
	Data  []byte   // Tag data or offset to tag data

	// Filled by Encoder or Decoder
	Header      *Header // Header of the TIFF file
	OffsetEntry int64   // Offset of the tag in the TIFF file
	OffsetData  int64   // Offset of the data if the data are not in the IFD Entry
}

type GPSTagID

type GPSTagID uint16

GPSTagID identifies the Exif tag field

func (GPSTagID) String

func (t GPSTagID) String() string
type Header struct {
	ByteOrder      binary.ByteOrder
	Version        Version
	OffsetFirstIFD int64
}

type Image

type Image struct {
	Tag map[TagID]*Tag

	SubImage         []*Image
	Exif             *ExifIFD
	GPS              *GPSIFD
	Interoperability *InteroperabilityIFD

	// Filled by Encoder or Decoder
	Header     *Header // Header of the TIFF file
	Offset     int64   // Offset of this IFD
	OffsetNext int64   // Offset of the next IFD
	// contains filtered or unexported fields
}

Image represents a Image File Directory (IFD).

func (*Image) BitDepth

func (im *Image) BitDepth() int

BitDepth returns bit depth of samples.

It returns 0, if valid BitsPerSample tag is not found, or if different components have different bit depth.

func (*Image) BitsPerSample

func (im *Image) BitsPerSample() []int

BitsPerSample returns the number of bits of each sample of a pixel.

func (*Image) Compression

func (im *Image) Compression() (compression int)

Compression returns the compression scheme used on the image data

func (*Image) DataType

func (im *Image) DataType() DataType

DataType returns the data type user should expect when decoding the image.

func (*Image) DecodeImage

func (im *Image) DecodeImage(buffer interface{}) error

DecodeImage decodes image data and copy data to buffer.

func (*Image) EncodeImage

func (im *Image) EncodeImage(buffer interface{}) error

func (*Image) EncodeTags

func (im *Image) EncodeTags(offset int64) ([]byte, error)

EncodeTags returns encoded tags with requested IFD offset.

func (*Image) NumStrips

func (im *Image) NumStrips() int

NumStrips returns the number of strips in the file, or 0 if the files in not organized in strips.

NumStrips finds the number of strips based on TagStripOffsets and TagStripByteCounts fields in metadata. It does not validate whether it is consistent with the number the image is supposed to have based on the size from TagImageLength and TagRowsPerStrip.

func (*Image) NumTiles

func (im *Image) NumTiles() int

NumTiles returns the number of tiles in the file, or 0 if the files in not organized in tiles.

NumTiles finds the number of tiles based on TagTileOffsets and TagTileByteCounts fields in metadata. It does not validate whether it is consistent with the number that the image is supposed to have based on from TagImageWidth, TagImageLength, TagTileWidth, TagTileLength

func (*Image) PlanarConfig

func (im *Image) PlanarConfig() int

PlanarConfig returns how the components of each pixel are stored.

func (*Image) RawStripReader

func (im *Image) RawStripReader(index int) *io.SectionReader

RawStripReader returns a Reader for reading the raw data of a strip, which may be compressed.

It panics when index >= im.NumStrips().

func (*Image) RawTileReader

func (im *Image) RawTileReader(index int) *io.SectionReader

RawTileReader returns a Reader for reading the raw data of a tile, which may be compressed.

It panics when index >= im.NumTiles().

func (*Image) SamplesPerPixel

func (im *Image) SamplesPerPixel() int

SamplesPerPixel returns the number of samples (color channels) per pixel.

func (*Image) SetCompression

func (im *Image) SetCompression(compression int)

func (*Image) SetPixelFormat

func (im *Image) SetPixelFormat(photometric int, samplePerPixel int, bitsPerSample []int)

func (*Image) SetRowsPerStrip

func (im *Image) SetRowsPerStrip(rowsPerStrip int)

func (*Image) SetTag

func (im *Image) SetTag(id TagID, tagType TagType, value interface{}) error

func (*Image) SetTileWidthHeight

func (im *Image) SetTileWidthHeight(tileWidth, tileHeight int)

func (*Image) SetWidthHeight

func (im *Image) SetWidthHeight(width int, height int)

func (*Image) StripReader

func (im *Image) StripReader(index int) (r io.ReadCloser, err error)

StripReader returns a Reader for reading the decompressed data of a strip.

It panics when index >= im.NumStrips().

func (*Image) TagID

func (im *Image) TagID() []TagID

TagID returns a sorted slice of TagIDs of the Image.

func (*Image) TileReader

func (im *Image) TileReader(index int) (r io.ReadCloser, err error)

TileReader returns a Reader for reading the decompressed data of a tile.

It panics when index >= im.NumTiles().

func (*Image) WidthHeight

func (im *Image) WidthHeight() (width int, height int)

WidthHeight returns the width and height of the image.

type InteroperabilityIFD

type InteroperabilityIFD struct {
	Tag map[InteroperabilityTagID]*InteroperabilityTag

	// Filled by Encoder or Decoder
	Header     *Header // Header of the TIFF file
	Offset     int64   // Offset of this IFD
	OffsetNext int64   // Offset of the next IFD
}

func (*InteroperabilityIFD) TagID

type InteroperabilityTag

type InteroperabilityTag struct {
	ID    InteroperabilityTagID // Tag identifying code
	Type  TagType               // Data type of tag data
	Count int                   // Number of values
	Data  []byte                // Tag data or offset to tag data

	// Filled by Encoder or Decoder
	Header      *Header // Header of the TIFF file
	OffsetEntry int64   // Offset of the tag in the TIFF file
	OffsetData  int64   // Offset of the data if the data are not in the IFD Entry
}

type InteroperabilityTagID

type InteroperabilityTagID uint16

InteroperabilityTagID identifies the Exif tag field

func (InteroperabilityTagID) String

func (t InteroperabilityTagID) String() string

type Iter

type Iter struct {
	// contains filtered or unexported fields
}

Iter is a iterator of Images in a TIFF file.

func (*Iter) All

func (it *Iter) All() ([]*Image, error)

All returns metadata of all remaining Images from the iterator.

func (*Iter) Err

func (it *Iter) Err() error

Err returns the error that terminited the iteration.

func (*Iter) Image

func (it *Iter) Image() *Image

Image returns the current image in the iteration. It should not be called before Next().

func (*Iter) Index

func (it *Iter) Index() int

Index returns the index of the current image in the file.

func (*Iter) Next

func (it *Iter) Next() bool

Next advances the iterator to the next Image.

type Rational

type Rational [2]uint32

func DecodeRational

func DecodeRational(count int, data []byte, byteOrder binary.ByteOrder) []Rational

func NewRational

func NewRational(a uint32, b uint32) Rational

func (Rational) String

func (r Rational) String() string

type SRational

type SRational [2]int32

func DecodeSRational

func DecodeSRational(count int, data []byte, byteOrder binary.ByteOrder) []SRational

func NewSRational

func NewSRational(a int32, b int32) SRational

func (SRational) String

func (r SRational) String() string

type Tag

type Tag struct {
	ID    TagID   // Tag identifying code
	Type  TagType // Data type of tag data
	Count int     // Number of values
	Data  []byte  // Tag data or offset to tag data

	// Filled by Encoder or Decoder
	Header      *Header // Header of the TIFF file
	OffsetEntry int64   // Offset of the tag in the TIFF file
	OffsetData  int64   // Offset of the data if the data are not in the IFD Entry
}

func NewTag

func NewTag(id TagID, tagType TagType, value interface{}, header *Header) (tag *Tag, err error)

func (*Tag) GoString

func (t *Tag) GoString() string

func (*Tag) String

func (t *Tag) String() (value string, ok bool)

func (*Tag) StringSlice

func (t *Tag) StringSlice() (value []string, ok bool)

func (*Tag) Uint

func (t *Tag) Uint() (value uint, ok bool)

Uint decodes Short, Long or Long8 tag value as uint, when the tag only has one value.

It returns (0, false) when the tags does not exist, has zero count or multiple values, or is of other data type.

func (*Tag) UintSlice

func (t *Tag) UintSlice() (value []uint, ok bool)

UintSlice decodes Short, Long or Long8 tag values as []uint.

It returns ([]uint{}, false) when the tags does not exist, has zero-count, or is of other data type.

type TagID

type TagID uint16

TagID identifies the field

func (TagID) String

func (t TagID) String() string

type TagType

type TagType uint16

TagType indicates data type of the field.

const (
	TagTypeByte      TagType = 1  // uint8
	TagTypeASCII     TagType = 2  // 8-bit byte that contains a 7-bit ASCII code; the last byte must be NUL (binary zero).
	TagTypeShort     TagType = 3  // uint16
	TagTypeLong      TagType = 4  // uint32
	TagTypeRational  TagType = 5  // Two Long's: the first represents the numerator of a fraction; the second, the denominator.
	TagTypeSByte     TagType = 6  // int8
	TagTypeUndefined TagType = 7  // An 8-bit byte that may contain anything, depending on the definition of the field.
	TagTypeSShort    TagType = 8  // int16
	TagTypeSLong     TagType = 9  // int32
	TagTypeSRational TagType = 10 // Two SLong's: the first represents the numerator of a fraction, the second the denominator.
	TagTypeFloat     TagType = 11 // float32
	TagTypeDouble    TagType = 12 // float64
	TagTypeIFD       TagType = 13 // uint32 (bigTIFF)
	TagTypeLong8     TagType = 16 // uint64 (bigTIFF)
	TagTypeSLong8    TagType = 17 // int64 (bigTIFF)
	TagTypeIFD8      TagType = 18 // uint16 IFD offset (bigTIFF)
)

Field data type

func (TagType) Size

func (t TagType) Size() int

func (TagType) String

func (t TagType) String() string

type UnsupportedError

type UnsupportedError string

An UnsupportedError reports that the input uses a valid but unimplemented feature.

func (UnsupportedError) Error

func (e UnsupportedError) Error() string

type Version

type Version uint16

Version indicates TIFF version.

const (
	VersionClassicTIFF Version = 42
	VersionBigTIFF     Version = 43
)

func (Version) String

func (v Version) String() string

Directories

Path Synopsis
examples
Package lzw implements the Lempel-Ziv-Welch compressed data format, described in T. A. Welch, “A Technique for High-Performance Data Compression”, Computer, 17(6) (June 1984), pp 8-19.
Package lzw implements the Lempel-Ziv-Welch compressed data format, described in T. A. Welch, “A Technique for High-Performance Data Compression”, Computer, 17(6) (June 1984), pp 8-19.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL