blob: 556023334395ac472e9b2e88a14f65183efe590c (
plain)
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
|
; This is a test file for kate's PureBasic highlighting.
; BMP2x Converter by Sven Langenkamp
UseJPEGImageEncoder()
UsePNGImageEncoder()
Declare Convert(JPEG)
Enumeration 1
#JPEG
#PNG
EndEnumeration
; BEGIN section
; END
Global Count
Global file.s
Global filename.s
Global fileext.s
Global OutputFormat
Global JPEGQuality
Count = 0
OutputFormat = 1
JPEGQuality = -1
; MAIN PROGRAM------------------------------------------------------------------
;Request Options
PrintN("Output Format")
PrintN(" [1] JPEG")
PrintN(" [2] PNG")
Print ("> ")
OutputFormat = Int(Input())
Select OutputFormat
Case #JPEG:
fileext = ".jpg"
;Request JPEG Quality
PrintN("")
PrintN("JPEG Quality")
PrintN(" [0-10]")
Print ("> ")
JPEGQuality = Int(Input())
Case #PNG:
fileext = ".png"
EndSelect
;Convert all BMP files in the current directory
ExamineDirectory(0, "", "*.bmp")
While NextDirectoryEntry()
file = DirectoryEntryName()
filename = GetFilePart(file)
If LoadImage(0, file)
Select OutputFormat
Case #JPEG:
Convert(JPEGQuality)
Case #PNG:
Convert(-1)
EndSelect
Count = Count +1
EndIf
Wend
PrintN(Str(Count) + " files converted")
CloseConsole()
; PROCUDURES--------------------------------------------------------------------
Procedure Convert(JPEG)
Shared filename, fileext
If JPEG > -1
SaveImage(0, filename + fileext, #PB_ImagePlugin_JPEG, JPEG)
Else
SaveImage(0, filename + fileext, #PB_ImagePlugin_PNG)
EndIf
PrintN(file + " converted to " + filename + fileext)
EndProcedure
|