From 89cfa38cfc57c0f9e22417a5779cd938d5876beb Mon Sep 17 00:00:00 2001 From: Dustin Oprea Date: Mon, 30 Apr 2018 01:33:13 -0400 Subject: [PATCH] exif: Reorganized. No-op changes. --- exif.go | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/exif.go b/exif.go index cb37422..87577bd 100644 --- a/exif.go +++ b/exif.go @@ -4,6 +4,7 @@ import ( "os" "errors" "bytes" + "fmt" "io/ioutil" "encoding/binary" @@ -16,8 +17,18 @@ const ( // data. RootIfdExifOffset = uint32(0x0008) - // ExifAddressableAreaStart is the start of where all offsets are relative to. + // ExifAddressableAreaStart is the position that all offsets are relative + // to. It's actually only about halfway through the header (technically + // unallocatable space). ExifAddressableAreaStart = uint32(0x6) + + // ExifDefaultFirstIfdOffset is essentially the number of bytes in addition + // to `ExifAddressableAreaStart` that you have to move in order to escape + // the rest of the header and get to the earliest point where we can put + // stuff (which has to be the first IFD). This is the size of the header + // sequence containing the two-character byte-order, two-character fixed- + // bytes, and the four bytes describing the first-IFD offset. + ExifDefaultFirstIfdOffset = uint32(2 + 2 + 4) ) var ( @@ -94,6 +105,11 @@ type ExifHeader struct { FirstIfdOffset uint32 } +func (eh ExifHeader) String() string { + return fmt.Sprintf("ExifHeader", eh.ByteOrder, eh.FirstIfdOffset) +} + + func (e *Exif) ParseExifHeader(data []byte) (eh ExifHeader, err error) { defer func() { if state := recover(); state != nil { @@ -188,6 +204,8 @@ func BuildExifHeader(byteOrder binary.ByteOrder, firstIfdOffset uint32) (headerB _, err = b.Write(ExifHeaderPrefixBytes) log.PanicIf(err) + // NOTE: This is the point in the data that all offsets are relative to. + if byteOrder == binary.BigEndian { _, err := b.WriteString("MM") log.PanicIf(err)