diff --git a/cmd/ovm/animate.go b/cmd/ovm/animate.go new file mode 100644 index 0000000000..4de52f33cb --- /dev/null +++ b/cmd/ovm/animate.go @@ -0,0 +1,65 @@ +package main + +import ( + "image" + "image/color" + "image/draw" + "image/gif" +) + +func MakeGif(images []image.Image, delay int) gif.GIF { + // Alloc slice with 0 elems but capacity of all images + frames := make([]*image.Paletted, 0, len(images)+1) + delays := make([]int, 0, len(images)+1) + disposals := make([]byte, 0, len(images)+1) + + for _, png := range images { + // Images are in reverse order so we need to prepend them + frames = append([]*image.Paletted{renderToPalette(png)}, frames...) + delays = append(delays, delay) + disposals = append(disposals, gif.DisposalBackground) + } + + // Add out background to revert to when changing frames + frames = append([]*image.Paletted{makeBlank()}, frames...) + delays = append([]int{0}, delays...) + disposals = append([]byte{gif.DisposalNone}, disposals...) + + return gif.GIF{ + Image: frames, + Delay: delays, + LoopCount: 10, + Disposal: disposals, + BackgroundIndex: 0, + } +} + +func makeBlank() *image.Paletted { + var palette color.Palette = color.Palette{ + image.Transparent, + } + img := image.NewPaletted(image.Rect(0, 0, 4025, 2048), palette) + draw.Draw(img, img.Bounds(), &image.Uniform{color.RGBA{0, 0, 0, 0}}, img.Bounds().Min, draw.Src) + return img +} + +func renderToPalette(img image.Image) *image.Paletted { + var palette color.Palette = color.Palette{ + image.Transparent, + // color.RGBA{255, 255, 255, 255}, + color.RGBA{88, 166, 255, 255}, + color.RGBA{63, 185, 80, 255}, + color.RGBA{248, 81, 73, 255}, + color.RGBA{163, 113, 247, 255}, + color.RGBA{134, 94, 201, 255}, + } + // Some days the images are off by a column so we are just hard coding the fix for now + // TODO(prince-chrismc) Make this more generic + sp := img.Bounds().Min + width := img.Bounds().Dx() + sp.X = width - 4025 + + paletted := image.NewPaletted(image.Rect(0, 0, 4025, 2048), palette) + draw.Draw(paletted, image.Rect(0, 0, 4025, 2048), img, sp, draw.Src) + return paletted +} diff --git a/cmd/ovm/dry_run.go b/cmd/ovm/dry_run.go index e618521a45..c4b4a1b523 100644 --- a/cmd/ovm/dry_run.go +++ b/cmd/ovm/dry_run.go @@ -8,7 +8,6 @@ import ( "image/png" "os" - "github.com/prince-chrismc/conan-center-index-pending-review/v2/internal/charts" "github.com/wcharczuk/go-chart/v2" ) @@ -37,7 +36,7 @@ func SaveToDisk(barGraph chart.StackedBarChart, images []image.Image) error { } images = append([]image.Image{img}, images...) - jif := charts.MakeGif(images, delay) + jif := MakeGif(images, delay) g, _ := os.Create("ovm.gif") defer g.Close() diff --git a/cmd/ovm/opened_versus_merged.go b/cmd/ovm/opened_versus_merged.go index b6a602166b..be4948a8a6 100644 --- a/cmd/ovm/opened_versus_merged.go +++ b/cmd/ovm/opened_versus_merged.go @@ -92,7 +92,7 @@ func OpenVersusMerged(token string, dryRun bool) error { } images = append([]image.Image{img}, images...) - jif := charts.MakeGif(images, delay) + jif := MakeGif(images, delay) var b3 bytes.Buffer err = gif.EncodeAll(&b3, &jif) diff --git a/internal/charts/animate.go b/internal/charts/animate.go deleted file mode 100644 index bdabc29fe3..0000000000 --- a/internal/charts/animate.go +++ /dev/null @@ -1,46 +0,0 @@ -package charts - -import ( - "image" - "image/color" - "image/draw" - "image/gif" -) - -func MakeGif(images []image.Image, delay int) gif.GIF { - // Alloc slice with 0 elems but capacity of all images - frames := make([]*image.Paletted, 0, len(images)) - delays := make([]int, 0, len(images)) - - for _, png := range images { - frames = append([]*image.Paletted{renderToPalette(png)}, frames...) - delays = append(delays, delay) - } - - return gif.GIF{ - Image: frames, - Delay: delays, - LoopCount: 10, - } -} - -func renderToPalette(img image.Image) *image.Paletted { - var palette color.Palette = color.Palette{ - image.Transparent, - color.RGBA{88, 166, 255, 255}, - color.RGBA{63, 185, 80, 255}, - color.RGBA{248, 81, 73, 255}, - color.RGBA{163, 113, 247, 255}, - color.RGBA{134, 94, 201, 255}, - } - - // Some days the images are off by a column so we are just hard coding the fix for now - // TODO(prince-chrismc) Make this more generic - sp := img.Bounds().Min - width := img.Bounds().Dx() - sp.X = width - 4025 - - paletted := image.NewPaletted(img.Bounds(), palette) - draw.Draw(paletted, img.Bounds(), img, sp, draw.Over) - return paletted -}