-
Notifications
You must be signed in to change notification settings - Fork 5
/
export_handler.go
246 lines (231 loc) · 5.88 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
235
236
237
238
239
240
241
242
243
244
245
246
package main
import (
"fmt"
"os"
"strconv"
"strings"
"github.com/disintegration/imaging"
"github.com/jeromelesaux/martine/common"
"github.com/jeromelesaux/martine/constants"
"github.com/jeromelesaux/martine/export"
)
func ExportHandler() (*export.MartineContext, constants.Size) {
var size constants.Size
exp := export.NewMartineContext(*picturePath, *output)
if !*reverse {
switch *mode {
case 0:
size = constants.Mode0
if *overscan {
size = constants.OverscanMode0
}
case 1:
size = constants.Mode1
if *overscan {
size = constants.OverscanMode1
}
case 2:
size = constants.Mode2
if *overscan {
size = constants.OverscanMode2
}
default:
if *height == -1 && *width == -1 && !*deltaMode {
fmt.Fprintf(os.Stderr, "mode %d not defined and no custom width or height\n", *mode)
usage()
}
}
if *height != -1 {
exp.CustomDimension = true
exp.Win = true
size.Height = *height
if *width != -1 {
size.Width = *width
} else {
size.Width = 0
}
}
if *width != -1 {
exp.Win = true
exp.CustomDimension = true
size.Width = *width
if *height != -1 {
size.Height = *height
} else {
size.Height = 0
}
}
if size.Width > constants.WidthMax {
fmt.Fprintf(os.Stderr, "Max width allowed is (%d) your choice (%d), Quiting...\n", size.Width, constants.WidthMax)
os.Exit(-1)
}
if size.Height > constants.HeightMax {
fmt.Fprintf(os.Stderr, "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
}
exp.FilloutGif = *filloutGif
exp.ExtendedDsk = *extendedDsk
exp.TileMode = *tileMode
exp.RollMode = *rollMode
exp.RollIteration = *iterations
exp.NoAmsdosHeader = *noAmsdosHeader
exp.CpcPlus = *plusMode
exp.TileIterationX = *tileIterationX
exp.TileIterationY = *tileIterationY
exp.Compression = *compress
exp.RotationMode = *rotateMode
exp.Rotation3DMode = *rotate3dMode
exp.Rotation3DType = *rotate3dType
exp.Rotation3DX0 = *rotate3dX0
exp.Rotation3DY0 = *rotate3dY0
exp.M4Host = *m4Host
exp.M4RemotePath = *m4RemotePath
exp.M4Autoexec = *m4Autoexec
exp.ResizingAlgo = resizeAlgo
exp.DitheringMultiplier = *ditheringMultiplier
exp.DitheringWithQuantification = *withQuantization
exp.PalettePath = *palettePath
exp.InkPath = *inkPath
exp.KitPath = *kitPath
exp.RotationRlaBit = *rla
exp.RotationSraBit = *sra
exp.RotationSlaBit = *sla
exp.RotationRraBit = *rra
exp.RotationKeephighBit = *keephigh
exp.RotationKeeplowBit = *keeplow
exp.RotationLosthighBit = *losthigh
exp.RotationLostlowBit = *lostlow
exp.RotationIterations = *iterations
exp.Flash = *flash
exp.Sna = *sna
exp.SpriteHard = *spriteHard
exp.SplitRaster = *splitRasters
exp.ZigZag = *zigzag
exp.Animate = *doAnimation
exp.Reducer = *reducer
exp.Json = *jsonOutput
exp.Ascii = *txtOutput
exp.OneLine = *oneLine
exp.OneRow = *oneRow
if *scanlineSequence != "" {
sequence := strings.Split(*scanlineSequence, ",")
for _, v := range sequence {
line, err := strconv.Atoi(v)
if err != nil {
fmt.Fprintf(os.Stderr, "Bad scanline sequence (%s) error:%v\n", *scanlineSequence, err)
os.Exit(-1)
}
exp.ScanlineSequence = append(exp.ScanlineSequence, line)
}
modulo := size.Height % len(exp.ScanlineSequence)
if modulo != 0 {
fmt.Fprintf(os.Stderr, "height modulo scanlinesequence is not equal to 0 %d lines and the output image lines is %d\n", len(exp.ScanlineSequence), size.Height)
os.Exit(-1)
}
}
if err := exp.ImportInkSwap(*inkSwap); err != nil {
fmt.Fprintf(os.Stderr, "Cannot parse inkswap option with error [%s]\n", err)
os.Exit(-1)
}
if *lineWidth != "" {
if err := exp.SetLineWith(*lineWidth); err != nil {
fmt.Fprintf(os.Stderr, "Cannot parse linewidth option with error [%s]\n", err)
os.Exit(-1)
}
}
if *maskSprite != "" {
v, err := common.ParseHexadecimal8(*maskSprite)
if err == nil {
exp.MaskSprite = uint8(v)
}
if exp.MaskSprite != 0 {
if *maskOrOperation {
exp.MaskOrOperation = true
}
if *maskAdOperation {
exp.MaskAndOperation = true
}
if exp.MaskAndOperation && exp.MaskOrOperation {
fmt.Fprintf(os.Stderr, "Or and And operations are setted, will only apply And operation.\n")
exp.MaskOrOperation = false
}
if !exp.MaskAndOperation && !exp.MaskOrOperation {
fmt.Fprintf(os.Stderr, "Or and And operations are not setted, will only apply And operation.\n")
exp.MaskAndOperation = true
}
fmt.Fprintf(os.Stdout, "Applying sprite mask value [#%X] [%.8b] AND = %t, OR =%t\n",
exp.MaskSprite,
exp.MaskSprite,
exp.MaskAndOperation,
exp.MaskOrOperation)
}
}
if exp.CpcPlus {
exp.Kit = true
exp.Pal = false
}
exp.Overscan = *overscan
if exp.Overscan {
exp.Scr = false
exp.Kit = true
}
if exp.M4Host != "" {
exp.M4 = true
}
if *egx1 {
exp.EgxFormat = export.Egx1Mode
}
if *egx2 {
exp.EgxFormat = export.Egx2Mode
}
if *mode != -1 {
exp.EgxMode1 = uint8(*mode)
}
if *mode2 != -1 {
exp.EgxMode2 = uint8(*mode2)
}
if *saturationPal > 0 || *brightnessPal > 0 {
exp.CpcPlus = true
exp.Saturation = *saturationPal
exp.Brightness = *brightnessPal
}
exp.DeltaMode = *deltaMode
exp.Dsk = *dsk
return exp, size
}