Exemple #1
0
func ParseField(br tiff.BReader, tsp tiff.TagSpace, ftsp tiff.FieldTypeSpace) (out tiff.Field, err error) {
	if ftsp == nil {
		ftsp = tiff.DefaultFieldTypeSpace
	}
	if tsp == nil {
		tsp = tiff.DefaultTagSpace
	}
	f := &field{ftsp: ftsp, tsp: tsp}
	if f.entry, err = ParseEntry(br); err != nil {
		return
	}
	fv := &fieldValue{order: br.ByteOrder()}
	valSize := int64(f.Count()) * int64(f.Type().Size())
	valOffBytes := f.entry.ValueOffset()
	if valSize > 8 {
		fv.value = make([]byte, valSize)
		offset := int64(br.ByteOrder().Uint64(valOffBytes[:])) // Hope this does not go negative
		if err = br.BReadSection(&fv.value, offset, valSize); err != nil {
			return
		}
	} else {
		fv.value = valOffBytes[:]
	}
	f.value = fv
	return f, nil
}
Exemple #2
0
func ParseBigTIFF(ordr [2]byte, vers uint16, br tiff.BReader, tsp tiff.TagSpace, ftsp tiff.FieldTypeSpace) (out tiff.TIFF, err error) {
	if tsp == nil {
		tsp = tiff.DefaultTagSpace
	}
	if ftsp == nil {
		ftsp = tiff.DefaultFieldTypeSpace
	}

	var restOfHdr [12]byte

	if _, err = io.ReadFull(br, restOfHdr[:]); err != nil {
		return nil, fmt.Errorf("bigtiff: unable to read the rest of the header: %v", err)
	}

	offsetSize := br.ByteOrder().Uint16(restOfHdr[:2])
	if offsetSize > 8 {
		return nil, fmt.Errorf("bigtiff: unsupported offset size %d", offsetSize)
	}

	// Skip restOfHdr[2:4] since it is a constant that is normally always 0x0000 and has no use yet.

	firstOffset := br.ByteOrder().Uint64(restOfHdr[4:])
	// Check the offset to the first IFD (ensure it is past the end of the header)
	if firstOffset < 16 {
		return nil, fmt.Errorf("bigtiff: invalid offset to first IFD, %d < 16", firstOffset)
	}

	t := &BigTIFF{ordr: ordr, vers: vers, offsetSize: offsetSize, firstOff: firstOffset, r: br}

	// Locate and decode IFDs
	for nextOffset := firstOffset; nextOffset != 0; {
		var ifd tiff.IFD
		if ifd, err = ParseIFD(br, nextOffset, tsp, ftsp); err != nil {
			return nil, err
		}
		t.ifds = append(t.ifds, ifd)
		nextOffset = ifd.NextOffset()
	}
	return t, nil
}