Skip to content

Commit

Permalink
Added verbose mode
Browse files Browse the repository at this point in the history
Replaced hacky Sprintf/concat constructs with just Printf
  • Loading branch information
SamusAranX committed Sep 18, 2021
1 parent d9debc0 commit 17c8477
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 18 deletions.
4 changes: 2 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
)

const (
version = "0.2"
version = "0.2.1"
)

func main() {
Expand All @@ -39,7 +39,7 @@ func main() {
os.Exit(1)
}

r := remapper.NewMapper(opts.MemoryHog)
r := remapper.NewMapper(opts.MemoryHog, opts.Verbose)

err = r.RemapFrames(opts.InputDir, opts.InputPattern, opts.OutputDir, opts.StartIndex)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion options.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ type CommandLineOpts struct {
InputPattern string `short:"p" long:"pattern" description:"Input file name glob pattern (optional)"`

StartIndex int `short:"s" long:"start-index" default:"0" description:"Starting index"`

MemoryHog bool `short:"M" long:"memory-hog" description:"Hog Mode (will attempt to keep all new frames in memory)"`
Verbose bool `short:"V" long:"verbose" description:"Outputs more status messages"`

Version bool `short:"v" long:"version" description:"Show version and exit"`
}
43 changes: 28 additions & 15 deletions remapper/remapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,15 @@ type Remapper struct {
inputFrames []string

frameWidth, frameHeight int
hogMode bool
hogMode, verbose bool
}

func NewMapper(hogMode bool) Remapper {
func NewMapper(hogMode, verbose bool) Remapper {
r := Remapper{
frameWidth: -1,
frameHeight: -1,
hogMode: hogMode,
verbose: verbose,
}
return r
}
Expand Down Expand Up @@ -127,13 +128,13 @@ func (r *Remapper) hogCheck() error {
func (r *Remapper) RemapFrames(inputDir, inputPattern, outputDir string, startFrame int) error {
r.loadFilesWithPattern(inputDir, inputPattern)

fmt.Println("preflight check")
fmt.Println("Preflight check")
err := r.preflightCheck()
if err != nil {
return err
}

fmt.Println("hog check")
fmt.Println("Hog check")
err = r.hogCheck()
if err != nil {
// This is the one non-critical error here, so we merely print it instead of panicking
Expand All @@ -142,12 +143,20 @@ func (r *Remapper) RemapFrames(inputDir, inputPattern, outputDir string, startFr

inputFrameCache := make([]image.Image, len(r.inputFrames))

numDigits := len(strconv.Itoa(r.frameWidth))

// there will be as many new frames as pixels the input frames are wide
for frameX := startFrame; frameX < r.frameWidth; frameX++ {
// new frames are as high as the input frames
// but as wide as the total number of input frames
img := image.NewRGBA(image.Rect(0, 0, len(r.inputFrames), r.frameHeight))

fmt.Printf("Building frame %0[3]*[1]d/%0[3]*[2]d…\n", frameX+1, r.frameWidth, numDigits)

if r.hogMode && frameX == 0 {
fmt.Println("(Subsequent frames will be processed much faster)")
}

percent := -1

// loop through input frames and fill new frames with 1px-wide pixel columns
Expand Down Expand Up @@ -185,21 +194,25 @@ func (r *Remapper) RemapFrames(inputDir, inputPattern, outputDir string, startFr
newPercent := int(math.Floor(float64(dstX) / float64(len(r.inputFrames)) * 100))
if newPercent >= percent+1 {
percent = newPercent
fmt.Printf("%03d%% (%d/%d)\n",
newPercent,
dstX,
len(r.inputFrames))
if r.verbose {
fmt.Printf("%03[1]d%% (%0[4]*[2]d/%0[4]*[3]d)\n",
newPercent,
dstX, len(r.inputFrames),
numDigits)
}
}
}

fmt.Printf("%03d%% (%d/%d)\n",
100,
len(r.inputFrames),
len(r.inputFrames))
if r.verbose {
fmt.Printf("%03[1]d%% (%0[4]*[2]d/%0[4]*[3]d)\n",
100,
len(r.inputFrames), len(r.inputFrames),
numDigits)
}

formatStr := fmt.Sprintf("frame%%0%dd.png", len(strconv.Itoa(r.frameWidth)))
newFileName := filepath.Join(outputDir, fmt.Sprintf(formatStr, frameX))
newFrameFile, err := os.Create(newFileName)
newFileName := fmt.Sprintf("frame%0[2]*[1]d.png", frameX, numDigits)
newFilePath := filepath.Join(outputDir, newFileName)
newFrameFile, err := os.Create(newFilePath)
if err != nil {
return err
}
Expand Down

0 comments on commit 17c8477

Please sign in to comment.