Skip to content

Commit

Permalink
YCbCr everything
Browse files Browse the repository at this point in the history
  • Loading branch information
Wikidepia committed Jul 3, 2024
1 parent e9b5e27 commit 9dab306
Showing 1 changed file with 5 additions and 10 deletions.
15 changes: 5 additions & 10 deletions handlers/grid.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package handlers

import (
"image"
"image/draw"
"image/jpeg"
"math"
"net"
Expand Down Expand Up @@ -70,9 +69,9 @@ func avg(n []float64) float64 {

// GenerateGrid generates a grid of images
// based on https://blog.vjeux.com/2014/image/google-plus-layout-find-best-breaks.html
func GenerateGrid(images []*image.RGBA) (image.Image, error) {
func GenerateGrid(images []image.Image) (image.Image, error) {
var imagesWH [][]float64
images = append(images, image.NewRGBA(image.Rect(0, 0, 0, 0))) // Needed as for some reason the last image is not added
images = append(images, image.Rect(0, 0, 0, 0)) // Needed as for some reason the last image is not added
for _, image := range images {
imagesWH = append(imagesWH, []float64{float64(image.Bounds().Dx()), float64(image.Bounds().Dy())})
}
Expand Down Expand Up @@ -111,7 +110,7 @@ func GenerateGrid(images []*image.RGBA) (image.Image, error) {
canvasHeight += int(rowHeight)
}

canvas := image.NewRGBA(image.Rect(0, 0, canvasWidth, canvasHeight))
canvas := image.NewYCbCr(image.Rect(0, 0, canvasWidth, canvasHeight), image.YCbCrSubsampleRatio420)

oldRowHeight := 0
for i := 1; i < len(path); i++ {
Expand Down Expand Up @@ -158,7 +157,7 @@ func Grid() fiber.Handler {
mediaList = append(mediaList, item.Medias[i])
}

images := make([]*image.RGBA, len(mediaList))
images := make([]image.Image, len(mediaList))
var wg sync.WaitGroup

client := http.Client{Transport: transport, Timeout: timeout}
Expand All @@ -179,14 +178,10 @@ func Grid() fiber.Handler {
}
defer res.Body.Close()

imJPEG, err := jpeg.Decode(res.Body)
images[i], err = jpeg.Decode(res.Body)
if err != nil {
return
}

b := imJPEG.Bounds()
images[i] = image.NewRGBA(image.Rect(0, 0, b.Dx(), b.Dy()))
draw.Draw(images[i], images[i].Bounds(), imJPEG, b.Min, draw.Src)
}(i, media)
}
wg.Wait()
Expand Down

0 comments on commit 9dab306

Please sign in to comment.