summaryrefslogtreecommitdiff
path: root/vendor/github.com/dsoprea/go-photoshop-info-format
diff options
context:
space:
mode:
authorLibravatar kim <89579420+NyaaaWhatsUpDoc@users.noreply.github.com>2024-08-02 11:46:41 +0000
committerLibravatar GitHub <noreply@github.com>2024-08-02 12:46:41 +0100
commit94e87610c4ce9bbb1c614a61bab29c1422fed11b (patch)
tree2e06b8ce64212140e796f6077ba841b6cc678501 /vendor/github.com/dsoprea/go-photoshop-info-format
parent[feature] Allow import of following and blocks via CSV (#3150) (diff)
downloadgotosocial-94e87610c4ce9bbb1c614a61bab29c1422fed11b.tar.xz
[chore] add back exif-terminator and use only for jpeg,png,webp (#3161)
* add back exif-terminator and use only for jpeg,png,webp * fix arguments passed to terminateExif() * pull in latest exif-terminator * fix test * update processed img --------- Co-authored-by: tobi <tobi.smethurst@protonmail.com>
Diffstat (limited to 'vendor/github.com/dsoprea/go-photoshop-info-format')
-rw-r--r--vendor/github.com/dsoprea/go-photoshop-info-format/.MODULE_ROOT0
-rw-r--r--vendor/github.com/dsoprea/go-photoshop-info-format/LICENSE21
-rw-r--r--vendor/github.com/dsoprea/go-photoshop-info-format/README.md3
-rw-r--r--vendor/github.com/dsoprea/go-photoshop-info-format/info.go119
-rw-r--r--vendor/github.com/dsoprea/go-photoshop-info-format/testing_common.go70
5 files changed, 213 insertions, 0 deletions
diff --git a/vendor/github.com/dsoprea/go-photoshop-info-format/.MODULE_ROOT b/vendor/github.com/dsoprea/go-photoshop-info-format/.MODULE_ROOT
new file mode 100644
index 000000000..e69de29bb
--- /dev/null
+++ b/vendor/github.com/dsoprea/go-photoshop-info-format/.MODULE_ROOT
diff --git a/vendor/github.com/dsoprea/go-photoshop-info-format/LICENSE b/vendor/github.com/dsoprea/go-photoshop-info-format/LICENSE
new file mode 100644
index 000000000..d92c04268
--- /dev/null
+++ b/vendor/github.com/dsoprea/go-photoshop-info-format/LICENSE
@@ -0,0 +1,21 @@
+MIT License
+
+Copyright (c) 2020 Dustin Oprea
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+SOFTWARE.
diff --git a/vendor/github.com/dsoprea/go-photoshop-info-format/README.md b/vendor/github.com/dsoprea/go-photoshop-info-format/README.md
new file mode 100644
index 000000000..6219ba020
--- /dev/null
+++ b/vendor/github.com/dsoprea/go-photoshop-info-format/README.md
@@ -0,0 +1,3 @@
+# Overview
+
+This is a minimal Photoshop format implementation to allow IPTC data to be extracted from a JPEG image. This project primarily services [go-jpeg-image-structure](https://github.com/dsoprea/go-jpeg-image-structure).
diff --git a/vendor/github.com/dsoprea/go-photoshop-info-format/info.go b/vendor/github.com/dsoprea/go-photoshop-info-format/info.go
new file mode 100644
index 000000000..7f17fa6c0
--- /dev/null
+++ b/vendor/github.com/dsoprea/go-photoshop-info-format/info.go
@@ -0,0 +1,119 @@
+package photoshopinfo
+
+import (
+ "fmt"
+ "io"
+
+ "encoding/binary"
+
+ "github.com/dsoprea/go-logging"
+)
+
+var (
+ defaultByteOrder = binary.BigEndian
+)
+
+// Photoshop30InfoRecord is the data for one parsed Photoshop-info record.
+type Photoshop30InfoRecord struct {
+ // RecordType is the record-type.
+ RecordType string
+
+ // ImageResourceId is the image resource-ID.
+ ImageResourceId uint16
+
+ // Name is the name of the record. It is optional and will be an empty-
+ // string if not present.
+ Name string
+
+ // Data is the raw record data.
+ Data []byte
+}
+
+// String returns a descriptive string.
+func (pir Photoshop30InfoRecord) String() string {
+ return fmt.Sprintf("RECORD-TYPE=[%s] IMAGE-RESOURCE-ID=[0x%04x] NAME=[%s] DATA-SIZE=(%d)", pir.RecordType, pir.ImageResourceId, pir.Name, len(pir.Data))
+}
+
+// ReadPhotoshop30InfoRecord parses a single photoshop-info record.
+func ReadPhotoshop30InfoRecord(r io.Reader) (pir Photoshop30InfoRecord, err error) {
+ defer func() {
+ if state := recover(); state != nil {
+ err = log.Wrap(state.(error))
+ }
+ }()
+
+ recordType := make([]byte, 4)
+ _, err = io.ReadFull(r, recordType)
+ if err != nil {
+ if err == io.EOF {
+ return pir, err
+ }
+
+ log.Panic(err)
+ }
+
+ // TODO(dustin): Move BigEndian to constant/config.
+
+ irId := uint16(0)
+ err = binary.Read(r, defaultByteOrder, &irId)
+ log.PanicIf(err)
+
+ nameSize := uint8(0)
+ err = binary.Read(r, defaultByteOrder, &nameSize)
+ log.PanicIf(err)
+
+ // Add an extra byte if the two length+data size is odd to make the total
+ // bytes read even.
+ doAddPadding := (1+nameSize)%2 == 1
+ if doAddPadding == true {
+ nameSize++
+ }
+
+ name := make([]byte, nameSize)
+ _, err = io.ReadFull(r, name)
+ log.PanicIf(err)
+
+ // If the last byte is padding, truncate it.
+ if doAddPadding == true {
+ name = name[:nameSize-1]
+ }
+
+ dataSize := uint32(0)
+ err = binary.Read(r, defaultByteOrder, &dataSize)
+ log.PanicIf(err)
+
+ data := make([]byte, dataSize+dataSize%2)
+ _, err = io.ReadFull(r, data)
+ log.PanicIf(err)
+
+ data = data[:dataSize]
+
+ pir = Photoshop30InfoRecord{
+ RecordType: string(recordType),
+ ImageResourceId: irId,
+ Name: string(name),
+ Data: data,
+ }
+
+ return pir, nil
+}
+
+// ReadPhotoshop30Info parses a sequence of photoship-info records from the stream.
+func ReadPhotoshop30Info(r io.Reader) (pirIndex map[uint16]Photoshop30InfoRecord, err error) {
+ pirIndex = make(map[uint16]Photoshop30InfoRecord)
+
+ for {
+ pir, err := ReadPhotoshop30InfoRecord(r)
+ if err != nil {
+ if err == io.EOF {
+ break
+ }
+
+ log.Panic(err)
+ }
+
+ pirIndex[pir.ImageResourceId] = pir
+ }
+
+ return pirIndex, nil
+}
diff --git a/vendor/github.com/dsoprea/go-photoshop-info-format/testing_common.go b/vendor/github.com/dsoprea/go-photoshop-info-format/testing_common.go
new file mode 100644
index 000000000..1bc03139a
--- /dev/null
+++ b/vendor/github.com/dsoprea/go-photoshop-info-format/testing_common.go
@@ -0,0 +1,70 @@
+package photoshopinfo
+
+import (
+ "os"
+ "path"
+
+ "github.com/dsoprea/go-logging"
+)
+
+var (
+ testDataRelFilepath = "photoshop.data"
+)
+
+var (
+ moduleRootPath = ""
+ assetsPath = ""
+)
+
+func GetModuleRootPath() string {
+ if moduleRootPath == "" {
+ moduleRootPath = os.Getenv("PHOTOSHOPINFO_MODULE_ROOT_PATH")
+ if moduleRootPath != "" {
+ return moduleRootPath
+ }
+
+ currentWd, err := os.Getwd()
+ log.PanicIf(err)
+
+ currentPath := currentWd
+ visited := make([]string, 0)
+
+ for {
+ tryStampFilepath := path.Join(currentPath, ".MODULE_ROOT")
+
+ _, err := os.Stat(tryStampFilepath)
+ if err != nil && os.IsNotExist(err) != true {
+ log.Panic(err)
+ } else if err == nil {
+ break
+ }
+
+ visited = append(visited, tryStampFilepath)
+
+ currentPath = path.Dir(currentPath)
+ if currentPath == "/" {
+ log.Panicf("could not find module-root: %v", visited)
+ }
+ }
+
+ moduleRootPath = currentPath
+ }
+
+ return moduleRootPath
+}
+
+func GetTestAssetsPath() string {
+ if assetsPath == "" {
+ moduleRootPath := GetModuleRootPath()
+ assetsPath = path.Join(moduleRootPath, "assets")
+ }
+
+ return assetsPath
+}
+
+func GetTestDataFilepath() string {
+ assetsPath := GetTestAssetsPath()
+ filepath := path.Join(assetsPath, testDataRelFilepath)
+
+ return filepath
+}