-
Notifications
You must be signed in to change notification settings - Fork 6
/
export_handler.go
234 lines (218 loc) · 5.83 KB
/
export_handler.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
package main
import (
"os"
"strconv"
"strings"
"github.com/disintegration/imaging"
"github.com/jeromelesaux/martine/common"
"github.com/jeromelesaux/martine/config"
"github.com/jeromelesaux/martine/constants"
"github.com/jeromelesaux/martine/export/compression"
"github.com/jeromelesaux/martine/log"
)
// nolint: funlen, gocognit
func ExportHandler() (*config.MartineConfig, constants.Size) {
var size constants.Size
cfg := config.NewMartineConfig(*picturePath, *output)
size = constants.NewSizeMode(uint8(*mode), *overscan)
if !*reverse {
emptySize := constants.Size{}
if size == emptySize && *height == -1 && *width == -1 && !*deltaMode {
log.GetLogger().Error("mode %d not defined and no custom width or height\n", *mode)
usage()
}
if *height != -1 {
cfg.CustomDimension = true
cfg.Win = true
size.Height = *height
if *width != -1 {
size.Width = *width
} else {
size.Width = 0
}
}
if *width != -1 {
cfg.Win = true
cfg.CustomDimension = true
size.Width = *width
if *height != -1 {
size.Height = *height
} else {
size.Height = 0
}
}
if size.Width > constants.WidthMax {
log.GetLogger().Error("Max width allowed is (%d) your choice (%d), Quiting...\n", size.Width, constants.WidthMax)
os.Exit(-1)
}
if size.Height > constants.HeightMax {
log.GetLogger().Error("Max height allowed is (%d) your choice (%d), Quiting...\n", size.Height, constants.HeightMax)
os.Exit(-1)
}
}
var resizeAlgo imaging.ResampleFilter
switch *resizeAlgorithm {
case 1:
resizeAlgo = imaging.NearestNeighbor
case 2:
resizeAlgo = imaging.CatmullRom
case 3:
resizeAlgo = imaging.Lanczos
case 4:
resizeAlgo = imaging.Linear
case 5:
resizeAlgo = imaging.Box
case 6:
resizeAlgo = imaging.Hermite
case 7:
resizeAlgo = imaging.BSpline
case 8:
resizeAlgo = imaging.Hamming
case 9:
resizeAlgo = imaging.Hann
case 10:
resizeAlgo = imaging.Gaussian
case 11:
resizeAlgo = imaging.Blackman
case 12:
resizeAlgo = imaging.Bartlett
case 13:
resizeAlgo = imaging.Welch
case 14:
resizeAlgo = imaging.Cosine
case 15:
resizeAlgo = imaging.MitchellNetravali
default:
resizeAlgo = imaging.NearestNeighbor
}
cfg.FilloutGif = *filloutGif
cfg.ExtendedDsk = *extendedDsk
cfg.TileMode = *tileMode
cfg.RollMode = *rollMode
cfg.RollIteration = *iterations
cfg.NoAmsdosHeader = *noAmsdosHeader
cfg.CpcPlus = *plusMode
cfg.TileIterationX = *tileIterationX
cfg.TileIterationY = *tileIterationY
cfg.Compression = compression.ToCompressMethod(*compress)
cfg.RotationMode = *rotateMode
cfg.Rotation3DMode = *rotate3dMode
cfg.Rotation3DType = *rotate3dType
cfg.Rotation3DX0 = *rotate3dX0
cfg.Rotation3DY0 = *rotate3dY0
cfg.M4Host = *m4Host
cfg.M4RemotePath = *m4RemotePath
cfg.M4Autoexec = *m4Autoexec
cfg.ResizingAlgo = resizeAlgo
cfg.DitheringMultiplier = *ditheringMultiplier
cfg.DitheringWithQuantification = *withQuantization
cfg.PalettePath = *palettePath
cfg.InkPath = *inkPath
cfg.KitPath = *kitPath
cfg.RotationRlaBit = *rla
cfg.RotationSraBit = *sra
cfg.RotationSlaBit = *sla
cfg.RotationRraBit = *rra
cfg.RotationKeephighBit = *keephigh
cfg.RotationKeeplowBit = *keeplow
cfg.RotationLosthighBit = *losthigh
cfg.RotationLostlowBit = *lostlow
cfg.RotationIterations = *iterations
cfg.Flash = *flash
cfg.Sna = *sna
cfg.SpriteHard = *spriteHard
cfg.SplitRaster = *splitRasters
cfg.ZigZag = *zigzag
cfg.Animate = *doAnimation
cfg.Reducer = *reducer
cfg.Json = *jsonOutput
cfg.Ascii = *txtOutput
cfg.OneLine = *oneLine
cfg.OneRow = *oneRow
cfg.ExportAsGoFile = *exportGoFiles
if *scanlineSequence != "" {
sequence := strings.Split(*scanlineSequence, ",")
for _, v := range sequence {
line, err := strconv.Atoi(v)
if err != nil {
log.GetLogger().Error("Bad scanline sequence (%s) error:%v\n", *scanlineSequence, err)
os.Exit(-1)
}
cfg.ScanlineSequence = append(cfg.ScanlineSequence, line)
}
modulo := size.Height % len(cfg.ScanlineSequence)
if modulo != 0 {
log.GetLogger().Error("height modulo scanlinesequence is not equal to 0 %d lines and the output image lines is %d\n", len(cfg.ScanlineSequence), size.Height)
os.Exit(-1)
}
}
if err := cfg.ImportInkSwap(*inkSwap); err != nil {
log.GetLogger().Error("Cannot parse inkswap option with error [%s]\n", err)
os.Exit(-1)
}
if *lineWidth != "" {
if err := cfg.SetLineWith(*lineWidth); err != nil {
log.GetLogger().Error("Cannot parse linewidth option with error [%s]\n", err)
os.Exit(-1)
}
}
if *maskSprite != "" {
v, err := common.ParseHexadecimal8(*maskSprite)
if err == nil {
cfg.MaskSprite = v
}
if cfg.MaskSprite != 0 {
if *maskOrOperation {
cfg.MaskOrOperation = true
}
if *maskAdOperation {
cfg.MaskAndOperation = true
}
if cfg.MaskAndOperation && cfg.MaskOrOperation {
log.GetLogger().Error("Or and And operations are setted, will only apply And operation.\n")
cfg.MaskOrOperation = false
}
if !cfg.MaskAndOperation && !cfg.MaskOrOperation {
log.GetLogger().Error("Or and And operations are not setted, will only apply And operation.\n")
cfg.MaskAndOperation = true
}
log.GetLogger().Info("Applying sprite mask value [#%X] [%.8b] AND = %t, OR =%t\n",
cfg.MaskSprite,
cfg.MaskSprite,
cfg.MaskAndOperation,
cfg.MaskOrOperation)
}
}
if cfg.CpcPlus {
cfg.Kit = true
cfg.Pal = false
}
cfg.Overscan = *overscan
if cfg.Overscan {
cfg.Scr = false
cfg.Kit = true
}
if cfg.M4Host != "" {
cfg.M4 = true
}
if *egx1 {
cfg.EgxFormat = config.Egx1Mode
}
if *egx2 {
cfg.EgxFormat = config.Egx2Mode
}
if *mode != -1 {
cfg.EgxMode1 = uint8(*mode)
}
if *mode2 != -1 {
cfg.EgxMode2 = uint8(*mode2)
}
if *saturationPal > 0 || *brightnessPal > 0 {
cfg.CpcPlus = true
cfg.Saturation = *saturationPal
cfg.Brightness = *brightnessPal
}
cfg.DeltaMode = *deltaMode
cfg.Dsk = *dsk
return cfg, size
}