This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"errors" | |
"fmt" | |
"os" | |
"github.com/samuel/go-thrift/parser" | |
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"image" | |
"image/color" | |
"image/jpeg" | |
"image/png" | |
"log" | |
"math" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func (b *MosaicBuilder) Build() error { | |
b.logger.Println("Load parts paths ...") | |
partsPaths, err := b.getPartsPaths() | |
if err != nil { | |
return err | |
} | |
b.logger.Println("Load parts map ...") | |
partsMap, err := b.getPartsMap(partsPaths) | |
if err != nil { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func getClosestPart(mp *map[PixelColor]image.Image, pix color.Color) image.Image { | |
c := color.RGBAModel.Convert(pix).(color.RGBA) | |
key := [3]uint8{c.R, c.G, c.B} | |
if part, ok := (*mp)[key]; ok { | |
return part | |
} | |
var minD *float64 | |
var prt *image.Image |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func (b *MosaicBuilder) Build() error { | |
b.logger.Println("Load parts paths ...") | |
partsPaths, err := b.getPartsPaths() | |
if err != nil { | |
return err | |
} | |
b.logger.Println("Load parts map ...") | |
partsMap, err := b.getPartsMap(partsPaths) | |
if err != nil { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func (b *MosaicBuilder) getPartsMap(parts []string) (map[PixelColor]image.Image, error) { | |
partsMap := make(map[PixelColor]image.Image, len(parts)) | |
for _, path := range parts { | |
src, err := b.loadImage(path) | |
if err == nil { | |
partsMap[calculateModalAverageColour(src)] = src | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type PixelColor [3]uint8 | |
func calculateModalAverageColour(img image.Image) PixelColor { | |
imgSize := img.Bounds().Size() | |
var redTotal, greenTotal, blueTotal, pixelsCount int64 | |
for x := 0; x < imgSize.X; x++ { | |
for y := 0; y < imgSize.Y; y++ { | |
cc := color.RGBAModel.Convert(img.At(x, y)).(color.RGBA) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func (b *MosaicBuilder) loadImage(path string) (image.Image, error) { | |
infile, err := os.Open(path) | |
defer func(infile *os.File) { | |
_ = infile.Close() | |
}(infile) | |
if err != nil { | |
return nil, err | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"log" | |
"os" | |
) | |
type MosaicBuilder struct { | |
logger *log.Logger | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import random | |
def max_(a, b): | |
div_b = (b * 2 // a * 2) | |
div_a = (a * 2 // b * 2) | |
return ( | |
b * (div_b % (div_b - 1)) + a * (div_a % (div_a - 1)) | |
) // ((a // b) * (b // a) + 1) |
NewerOlder