Skip to content

Commit

Permalink
Revert "Run all image decoding through a central place"
Browse files Browse the repository at this point in the history
This reverts commit 9ee1376.
  • Loading branch information
turt2live committed Sep 5, 2023
1 parent 773e691 commit b9ab418
Show file tree
Hide file tree
Showing 13 changed files with 21 additions and 62 deletions.
4 changes: 0 additions & 4 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ jobs:
go-version: '1.20'
- name: "Install libheif"
run: "chmod +x ./.github/workflows/build-libheif.sh && ./.github/workflows/build-libheif.sh"
- name: "Install other dependencies"
run: "sudo apt-get install -y libjpeg-turbo-dev"
- run: './build.sh' # verify the thing compiles
static:
name: 'Go Static (1.20)'
Expand All @@ -25,8 +23,6 @@ jobs:
go-version: '1.20'
- name: "Install libheif"
run: "chmod +x ./.github/workflows/build-libheif.sh && ./.github/workflows/build-libheif.sh"
- name: "Install other dependencies"
run: "sudo apt-get install -y libjpeg-turbo-dev"
- name: "Prepare: compile assets"
run: "GOBIN=$PWD/bin go install -v ./cmd/compile_assets"
- name: "Run: compile assets"
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
FROM golang:1.20-alpine AS builder

# Install build dependencies
RUN apk add --no-cache git musl-dev dos2unix build-base libde265-dev libheif-dev libjpeg-turbo-dev
RUN apk add --no-cache git musl-dev dos2unix build-base libde265-dev libheif-dev

WORKDIR /opt
COPY . /opt
Expand Down
4 changes: 2 additions & 2 deletions api/unstable/info.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"strings"
"time"

"github.com/disintegration/imaging"
"github.com/getsentry/sentry-go"
"github.com/sirupsen/logrus"
"github.com/turt2live/matrix-media-repo/api/_apimeta"
Expand All @@ -19,7 +20,6 @@ import (
"github.com/turt2live/matrix-media-repo/thumbnailing"
"github.com/turt2live/matrix-media-repo/thumbnailing/i"
"github.com/turt2live/matrix-media-repo/util"
"github.com/turt2live/matrix-media-repo/util/idec"
)

type mediaInfoHashes struct {
Expand Down Expand Up @@ -115,7 +115,7 @@ func MediaInfo(r *http.Request, rctx rcontext.RequestContext, user _apimeta.User
}

if strings.HasPrefix(response.ContentType, "image/") {
img, err := idec.Decode(stream)
img, err := imaging.Decode(stream)
if err == nil {
response.Width = img.Bounds().Max.X
response.Height = img.Bounds().Max.Y
Expand Down
4 changes: 2 additions & 2 deletions cmd/plugin_antispam_ocr/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"encoding/base64"
"encoding/json"
"fmt"
"image"
"io"
"math"
"net/http"
Expand All @@ -19,7 +20,6 @@ import (
"github.com/turt2live/matrix-media-repo/plugins/plugin_common"
"github.com/turt2live/matrix-media-repo/plugins/plugin_interfaces"
"github.com/turt2live/matrix-media-repo/util"
"github.com/turt2live/matrix-media-repo/util/idec"
)

type AntispamOCR struct {
Expand Down Expand Up @@ -84,7 +84,7 @@ func (a *AntispamOCR) CheckForSpam(b64 string, filename string, contentType stri
return false, nil
}

img, err := idec.Decode(bytes.NewBuffer(b))
img, _, err := image.Decode(bytes.NewBuffer(b))
if err != nil {
return false, err
}
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ require (
github.com/t2bot/pgo-fleet/embedded v1.0.1
github.com/testcontainers/testcontainers-go v0.23.0
github.com/testcontainers/testcontainers-go/modules/postgres v0.23.0
github.com/viam-labs/go-libjpeg v0.3.2-0.20230621193101-e6b235025092
golang.org/x/sync v0.3.0
golang.org/x/term v0.12.0
)
Expand Down Expand Up @@ -117,6 +116,7 @@ require (
github.com/prometheus/common v0.44.0 // indirect
github.com/prometheus/procfs v0.11.1 // indirect
github.com/rs/xid v1.5.0 // indirect
github.com/smartystreets/assertions v1.0.0 // indirect
golang.org/x/exp v0.0.0-20230817173708-d852ddb80c63 // indirect
golang.org/x/mod v0.12.0 // indirect
golang.org/x/sys v0.12.0 // indirect
Expand Down
6 changes: 2 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,8 @@ github.com/sebest/xff v0.0.0-20210106013422-671bd2870b3a/go.mod h1:wozgYq9WEBQBa
github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ=
github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ=
github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc=
github.com/smartystreets/assertions v1.2.0 h1:42S6lae5dvLc7BrLu/0ugRtcFVjoJNMC/N3yZFZkDFs=
github.com/smartystreets/assertions v1.0.0 h1:UVQPSSmc3qtTi+zPPkCXvZX9VvW/xT/NsRvKfwY81a8=
github.com/smartystreets/assertions v1.0.0/go.mod h1:kHHU4qYBaI3q23Pp3VPrmWhuIUrLW/7eUrw0BU5VaoM=
github.com/smartystreets/goconvey v1.6.4 h1:fv0U8FUIMPNf1L9lnHLvLhgicrIVChEkdzIKYqbNC9s=
github.com/smartystreets/goconvey v1.6.4/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9QV7WQ/tjFTllLA=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
Expand Down Expand Up @@ -407,8 +408,6 @@ github.com/testcontainers/testcontainers-go v0.23.0 h1:ERYTSikX01QczBLPZpqsETTBO
github.com/testcontainers/testcontainers-go v0.23.0/go.mod h1:3gzuZfb7T9qfcH2pHpV4RLlWrPjeWNQah6XlYQ32c4I=
github.com/testcontainers/testcontainers-go/modules/postgres v0.23.0 h1:OEGUC1YTN1RyS4xqsHmlyYkBWm9lMJcswoV4JSHJQOM=
github.com/testcontainers/testcontainers-go/modules/postgres v0.23.0/go.mod h1:YnqIhPwhjqVbJBuvSRJS6pa9Cy1PDRJcrM6T63Uw2ms=
github.com/viam-labs/go-libjpeg v0.3.2-0.20230621193101-e6b235025092 h1:DsILjTWWpYH9jl+AsxqkSdbocxkrHxCwCBgHnYTsnfs=
github.com/viam-labs/go-libjpeg v0.3.2-0.20230621193101-e6b235025092/go.mod h1:BCaeb3/txASzLy3XwzuzqFMs+u0cEf+wdiQQL3TxQVo=
github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k=
Expand All @@ -420,7 +419,6 @@ go.opentelemetry.io/otel/sdk v1.12.0/go.mod h1:WYcvtgquYvgODEvxOry5owO2y9MyciW7J
go.opentelemetry.io/otel/sdk/metric v0.35.0/go.mod h1:eDyp1GxSiwV98kr7w4pzrszQh/eze9MqBqPd2bCPmyE=
go.opentelemetry.io/otel/trace v1.12.0/go.mod h1:pHlgBynn6s25qJ2szD+Bv+iwKJttjHSI3lUAyf0GNuQ=
go.uber.org/goleak v1.2.0/go.mod h1:XJYK+MuIchqpmGmUSAzotztawfKvYLUIgg7guXrwVUo=
go.viam.com/test v1.1.0 h1:KXf8crEwt0bHn5iMsjmXg0vPio/yzKGrfd20sWhe/t4=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
Expand Down
5 changes: 2 additions & 3 deletions pipelines/_steps/upload/blurhash_async.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"github.com/disintegration/imaging"
"github.com/turt2live/matrix-media-repo/common/rcontext"
"github.com/turt2live/matrix-media-repo/database"
"github.com/turt2live/matrix-media-repo/util/idec"
"github.com/turt2live/matrix-media-repo/util/readers"
)

Expand All @@ -32,7 +31,7 @@ func CalculateBlurhashAsync(ctx rcontext.RequestContext, reader io.Reader, sizeB
// Same goes for pixel size
var c image.Config
br := readers.NewBufferReadsReader(reader)
c, err = idec.DecodeConfig(br)
c, _, err = image.DecodeConfig(br)
if err != nil {
return
}
Expand All @@ -42,7 +41,7 @@ func CalculateBlurhashAsync(ctx rcontext.RequestContext, reader io.Reader, sizeB
reader = br.GetRewoundReader()

var img image.Image
img, err = idec.Decode(reader)
img, err = imaging.Decode(reader)
if err != nil {
ctx.Log.Debug("Skipping blurhash on this upload due to error: ", err)
return
Expand Down
3 changes: 1 addition & 2 deletions test/test_internals/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (

"github.com/disintegration/imaging"
"github.com/stretchr/testify/assert"
"github.com/turt2live/matrix-media-repo/util/idec"
)

var evenColor = color.RGBA{R: 255, G: 0, B: 0, A: 255}
Expand Down Expand Up @@ -46,7 +45,7 @@ func MakeTestImage(width int, height int) (string, io.Reader, error) {
}

func AssertIsTestImage(t *testing.T, i io.Reader) {
img, err := idec.Decode(i)
img, _, err := image.Decode(i)
assert.NoError(t, err, "Error decoding image")
width := img.Bounds().Max.X
height := img.Bounds().Max.Y
Expand Down
6 changes: 3 additions & 3 deletions thumbnailing/i/heif.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ package i

import (
"errors"
"image"
"io"

_ "github.com/strukturag/libheif/go/heif"
"github.com/turt2live/matrix-media-repo/common/rcontext"
"github.com/turt2live/matrix-media-repo/thumbnailing/m"
"github.com/turt2live/matrix-media-repo/util"
"github.com/turt2live/matrix-media-repo/util/idec"
)

type heifGenerator struct {
Expand All @@ -27,15 +27,15 @@ func (d heifGenerator) matches(img io.Reader, contentType string) bool {
}

func (d heifGenerator) GetOriginDimensions(b io.Reader, contentType string, ctx rcontext.RequestContext) (bool, int, int, error) {
cfg, err := idec.DecodeConfig(b)
cfg, _, err := image.DecodeConfig(b)
if err != nil {
return false, 0, 0, err
}
return true, cfg.Width, cfg.Height, nil
}

func (d heifGenerator) GenerateThumbnail(b io.Reader, contentType string, width int, height int, method string, animated bool, ctx rcontext.RequestContext) (*m.Thumbnail, error) {
src, err := idec.Decode(b)
src, _, err := image.Decode(b)
if err != nil {
return nil, errors.New("heif: error decoding thumbnail: " + err.Error())
}
Expand Down
4 changes: 2 additions & 2 deletions thumbnailing/i/jpg.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ import (
_ "image/jpeg"
"io"

"github.com/disintegration/imaging"
"github.com/turt2live/matrix-media-repo/common/rcontext"
"github.com/turt2live/matrix-media-repo/thumbnailing/m"
"github.com/turt2live/matrix-media-repo/thumbnailing/u"
"github.com/turt2live/matrix-media-repo/util"
"github.com/turt2live/matrix-media-repo/util/idec"
"github.com/turt2live/matrix-media-repo/util/readers"
)

Expand Down Expand Up @@ -38,7 +38,7 @@ func (d jpgGenerator) GenerateThumbnail(b io.Reader, contentType string, width i
orientation := u.ExtractExifOrientation(br)
b = br.GetRewoundReader()

src, err := idec.Decode(b)
src, err := imaging.Decode(b)
if err != nil {
return nil, errors.New("jpg: error decoding thumbnail: " + err.Error())
}
Expand Down
5 changes: 2 additions & 3 deletions thumbnailing/i/mp3.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import (
"github.com/turt2live/matrix-media-repo/common/rcontext"
"github.com/turt2live/matrix-media-repo/thumbnailing/m"
"github.com/turt2live/matrix-media-repo/thumbnailing/u"
"github.com/turt2live/matrix-media-repo/util/idec"
"github.com/turt2live/matrix-media-repo/util/readers"
)

Expand Down Expand Up @@ -104,7 +103,7 @@ func (d mp3Generator) GenerateFromStream(audio beep.StreamSeekCloser, format bee
sq := int(math.Round(float64(height) * 0.66))
var artworkImg image.Image
if meta != nil && meta.Picture() != nil {
artwork, _ := idec.Decode(bytes.NewBuffer(meta.Picture().Data))
artwork, _, _ := image.Decode(bytes.NewBuffer(meta.Picture().Data))
if artwork != nil {
artworkImg, _ = u.MakeThumbnail(artwork, "crop", sq, sq)
}
Expand All @@ -128,7 +127,7 @@ func (d mp3Generator) GenerateFromStream(audio beep.StreamSeekCloser, format bee
f, _ := os.OpenFile(path.Join(config.Runtime.AssetsPath, "default-artwork.png"), os.O_RDONLY, 0640)
if f != nil {
defer f.Close()
tmp, _ := idec.Decode(f)
tmp, _, _ := image.Decode(f)
if tmp != nil {
artworkImg, _ = u.MakeThumbnail(tmp, "crop", ax, ay)
}
Expand Down
6 changes: 3 additions & 3 deletions thumbnailing/i/png.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ import (
_ "image/png"
"io"

"github.com/disintegration/imaging"
"github.com/turt2live/matrix-media-repo/common/rcontext"
"github.com/turt2live/matrix-media-repo/thumbnailing/m"
"github.com/turt2live/matrix-media-repo/thumbnailing/u"
"github.com/turt2live/matrix-media-repo/util/idec"
)

type pngGenerator struct {
Expand All @@ -28,15 +28,15 @@ func (d pngGenerator) matches(img io.Reader, contentType string) bool {
}

func (d pngGenerator) GetOriginDimensions(b io.Reader, contentType string, ctx rcontext.RequestContext) (bool, int, int, error) {
i, err := idec.DecodeConfig(b)
i, _, err := image.DecodeConfig(b)
if err != nil {
return false, 0, 0, err
}
return true, i.Width, i.Height, nil
}

func (d pngGenerator) GenerateThumbnail(b io.Reader, contentType string, width int, height int, method string, animated bool, ctx rcontext.RequestContext) (*m.Thumbnail, error) {
src, err := idec.Decode(b)
src, err := imaging.Decode(b)
if err != nil {
return nil, errors.New("png: error decoding thumbnail: " + err.Error())
}
Expand Down
32 changes: 0 additions & 32 deletions util/idec/decode.go

This file was deleted.

0 comments on commit b9ab418

Please sign in to comment.