make a working API

This commit is contained in:
Neo Anderson committed 2020-02-15 09:32:44 -08:00
1 parent 2b5a5b3d38
commit f9ef6427f9
2 files changed
+37 -5

No files matched your search

+2 -5
View File
@@ -1,12 +1,9 @@
package karaoke
import (
"fmt"
"bytes"
"image"
"image/png"
"io/ioutil"
"log"
"os"
)
const (
@@ -71,7 +68,7 @@ func ScreenshotAtTime(cdgBytes []byte, timeInSec int) []byte {
/** @Return raw PNG buffer **/
func snap() []byte {
buf := new(bytes.Buffer)
png.Encode(out_file, internal_rgba_context)
png.Encode(buf, internal_rgba_context)
return buf.Bytes()
}
+35
View File
@@ -0,0 +1,35 @@
package main
import (
"io/ioutil"
"log"
"os"
".."
)
func main() {
//load data
cdg_file_data, err := ioutil.ReadFile("../cdg/SC-SBI-REMIX - Billy Idol - Rebel Yell.cdg")
if err != nil {
log.Fatal("Couldn't read .cdg file")
}
png := karaoke.ScreenshotAtTime(cdg_file_data, 3)
file, err := os.OpenFile(
"screenshot.png",
os.O_WRONLY|os.O_TRUNC|os.O_CREATE,
0666,
)
if err != nil {
log.Fatal(err)
}
defer file.Close()
bytesWritten, err := file.Write(png)
if err != nil {
log.Fatal(err)
}
log.Printf("Wrote %d bytes to %s\n", bytesWritten, "screenshot.png")
}