-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
78 lines (63 loc) · 1.48 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
package main
import (
"fmt"
"log"
"os"
)
func main() {
println("starting")
dal := NewDAL()
defer dal.Shutdown()
makeOutputDirectory()
rows := dal.FindThumnails()
defer rows.Close()
var width int
var height int
var bitspercomponent int
var bitsperpixel int
var bytesperrow int
var bitmapdata_location int64
var bitmapdata_length int64
thumbnails := make([]*Thumbnail, 0)
for rows.Next() {
err := rows.Scan(&width, &height, &bitspercomponent, &bitsperpixel, &bytesperrow, &bitmapdata_location, &bitmapdata_length)
if err != nil {
log.Fatal(err)
}
thumbnail := NewThumbnail(
width,
height,
bitspercomponent,
bitsperpixel,
bytesperrow,
bitmapdata_location,
bitmapdata_length,
dal.DataFile,
)
thumbnails = append(thumbnails, thumbnail)
}
total := len(thumbnails)
var successCount int
for i, thumb := range thumbnails {
filename := fmt.Sprintf("%s/out-%d.png", getOutputDir(), i)
if err := thumb.CreateImage(filename); err != nil {
log.Printf("Image creation failed: %s", err.Error())
} else {
successCount += 1
log.Printf("Successfully created %d of %d thumbnails", successCount, total)
}
}
}
func makeOutputDirectory() {
log.Printf("Outputting to %s", getOutputDir())
if err := os.Mkdir(getOutputDir(), os.ModeDir|os.ModePerm); err != nil {
log.Fatal(err.Error())
}
}
func getOutputDir() string {
cwd, err := os.Getwd()
if err != nil {
log.Fatal(err.Error())
}
return fmt.Sprintf("%s/osx-thumbnails-output", cwd)
}