You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
glitch_img/main.go

59 lines
1.6 KiB

2 months ago
package main
import (
"fmt"
"os"
"strconv"
)
1 month ago
// TODO:
// - Flags instead of os.Args
// - Interactive UI
// - Check compatability with other image types (PNG etc)
// - better ffmpeg bindings (go package?)
const MAX_SIZE = 1000000
func main() {
if len(os.Args) < 6 {
fmt.Println("Usage: go run main.go <source-file> <number-of-copies> <shit-size> <iterations> <chance-to-random % (0-100)>")
2 months ago
return
}
sourceFile := os.Args[1]
2 months ago
numCopies, err := strconv.Atoi(os.Args[2])
if err != nil || numCopies <= 0 {
fmt.Println("Invalid number of copies. Must be a positive integer.")
return
}
shitSize, err := strconv.ParseInt(os.Args[3], 10, 64) // Parse shitSize as int64
if err != nil || shitSize <= 0 {
fmt.Println("Invalid shit size. Must be a positive integer.")
return
} else if shitSize > MAX_SIZE {
fmt.Printf("shitSize exceeds maximum size (%d)\n", MAX_SIZE)
return
2 months ago
}
iterations, err := strconv.ParseInt(os.Args[4], 10, 8)
check(err, "Cannot parse iterations. Must be a positive integer")
2 months ago
chanceToRandom, err := strconv.ParseInt(os.Args[5], 10, 32)
if err != nil || chanceToRandom < 0 {
fmt.Println("Invalid random chance value. Must be a positive integer (0-100).")
return
} else if chanceToRandom > 100 {
fmt.Println("Invalid random chance value. Must range between 0 to 100.")
return
}
fmt.Fprintf(os.Stdout, "Generating:\n %d copies of %s\n %d random bytes of data\n %d interations(s)\n Chance to random %d%%\n\n",
numCopies, sourceFile, shitSize, iterations, chanceToRandom)
makeOutputDir()
generateGlitchedSequence(sourceFile, numCopies, shitSize, iterations, int32(chanceToRandom))
ffmpegGenerateMP4()
clearOutputDir()
2 months ago
}