FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
flashdevelop/PluginCore/ScintillaNet/XPM.cs at development · SandersAlex/flashdevelop · GitHub
SandersAlex
flashdevelop
Repository navigation
Code
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
flashdevelop
/
PluginCore
/
ScintillaNet
/
XPM.cs
Copy path
More file actions
More file actions
Latest commit
History
History
History
62 lines (57 loc) · 2.27 KB
Breadcrumbs
flashdevelop
/
PluginCore
/
ScintillaNet
/
XPM.cs
Copy path
File metadata and controls
62 lines (57 loc) · 2.27 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
using
System
.
Collections
;
using
System
.
Drawing
;
using
System
.
Text
;
using
PluginCore
;
using
PluginCore
.
PluginCore
.
Utilities
;
namespace
ScintillaNet
{
public
class
XPM
{
/// <summary>
/// Converts Bitmap images to XPM data for use with ScintillaNet.
/// Warning: images with more than (around) 50 colors will generate incorrect XPM
/// tColor: specified transparent color in format: "#00FF00".
/// </summary>
static
public
string
ConvertToXPM
(
Bitmap
bmp
,
string
tColor
)
{
StringBuilder
sb
=
new
StringBuilder
(
)
;
ArrayList
colors
=
new
ArrayList
(
)
;
ArrayList
chars
=
new
ArrayList
(
)
;
OctreeQuantizer
quantizer
=
new
OctreeQuantizer
(
50
,
8
,
ColorTranslator
.
FromHtml
(
tColor
)
)
;
Bitmap
reducedBmp
=
quantizer
.
Quantize
(
bmp
)
;
int
width
=
reducedBmp
.
Width
;
int
height
=
reducedBmp
.
Height
;
int
index
;
sb
.
Append
(
"/* XPM */static char * xmp_data[] = {
\"
"
)
.
Append
(
width
)
.
Append
(
" "
)
.
Append
(
height
)
.
Append
(
" ? 1
\"
"
)
;
int
colorsIndex
=
sb
.
Length
;
string
col
;
char
c
;
for
(
int
y
=
0
;
y
<
height
;
y
++
)
{
sb
.
Append
(
",
\"
"
)
;
for
(
int
x
=
0
;
x
<
width
;
x
++
)
{
col
=
ColorTranslator
.
ToHtml
(
reducedBmp
.
GetPixel
(
x
,
y
)
)
;
index
=
colors
.
IndexOf
(
col
)
;
if
(
index
<
0
)
{
index
=
colors
.
Add
(
col
)
+
65
;
if
(
index
>
90
)
index
+=
6
;
c
=
Encoding
.
ASCII
.
GetChars
(
new
byte
[
]
{
(
byte
)
(
index
&
0xff
)
}
)
[
0
]
;
chars
.
Add
(
c
)
;
sb
.
Insert
(
colorsIndex
,
",
\"
"
+
c
+
" c "
+
col
+
"
\"
"
)
;
colorsIndex
+=
14
;
}
else
c
=
(
char
)
chars
[
index
]
;
sb
.
Append
(
c
)
;
}
sb
.
Append
(
"
\"
"
)
;
}
sb
.
Append
(
"};"
)
;
string
result
=
sb
.
ToString
(
)
;
int
p
=
result
.
IndexOfOrdinal
(
"?"
)
;
string
finalColor
=
result
.
Substring
(
0
,
p
)
+
colors
.
Count
+
result
.
Substring
(
p
+
1
)
.
Replace
(
tColor
.
ToUpper
(
)
,
"None"
)
;
return
finalColor
;
}
}
}
Back
|
FazBrowse Home
|
New Git URL