Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
F
firmware
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
TilCreator
firmware
Commits
a9518740
Commit
a9518740
authored
5 years ago
by
TilCreator
Browse files
Options
Downloads
Patches
Plain Diff
Fix code style
parent
8653530c
Branches
TilCreator/firmware-master
Branches containing commit
No related tags found
No related merge requests found
Pipeline
#3710
passed
5 years ago
Stage: build
Stage: test
Changes
1
Pipelines
2
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
tools/image_to_pixels.py
+41
-20
41 additions, 20 deletions
tools/image_to_pixels.py
with
41 additions
and
20 deletions
tools/image_to_pixels.py
+
41
−
20
View file @
a9518740
...
@@ -3,12 +3,30 @@ from copy import deepcopy
...
@@ -3,12 +3,30 @@ from copy import deepcopy
import
argparse
import
argparse
parser
=
argparse
.
ArgumentParser
(
description
=
'
Converts images to card10 parsable images
'
)
parser
=
argparse
.
ArgumentParser
(
parser
.
add_argument
(
'
--ignore_alpha
'
,
'
-a
'
,
dest
=
'
alpha
'
,
action
=
'
store_false
'
,
help
=
'
Ignore alpha
'
)
description
=
"
Converts images to card10 parsable images
"
parser
.
add_argument
(
'
--use_exact_alpha
'
,
'
-e
'
,
dest
=
'
exact_alpha
'
,
action
=
'
store_true
'
,
help
=
'
Use exact alpha
'
)
)
parser
.
add_argument
(
'
--debug
'
,
'
-d
'
,
dest
=
'
debug
'
,
action
=
'
store_true
'
,
help
=
'
Debug
'
)
parser
.
add_argument
(
parser
.
add_argument
(
'
--background
'
,
'
-b
'
,
type
=
lambda
hexCode
:
tuple
([
int
(
hexCode
.
lstrip
(
'
#
'
)[
i
:
i
+
2
],
16
)
for
i
in
(
0
,
2
,
4
)]),
default
=
'
000000
'
,
help
=
'
Background color in rgb hex
'
)
"
--ignore_alpha
"
,
"
-a
"
,
dest
=
"
alpha
"
,
action
=
"
store_false
"
,
help
=
"
Ignore alpha
"
parser
.
add_argument
(
'
images
'
,
nargs
=
'
*
'
,
default
=
[],
help
=
'
path to images
'
)
)
parser
.
add_argument
(
"
--use_exact_alpha
"
,
"
-e
"
,
dest
=
"
exact_alpha
"
,
action
=
"
store_true
"
,
help
=
"
Use exact alpha
"
,
)
parser
.
add_argument
(
"
--debug
"
,
"
-d
"
,
dest
=
"
debug
"
,
action
=
"
store_true
"
,
help
=
"
Debug
"
)
parser
.
add_argument
(
"
--background
"
,
"
-b
"
,
type
=
lambda
hexCode
:
tuple
(
[
int
(
hexCode
.
lstrip
(
"
#
"
)[
i
:
i
+
2
],
16
)
for
i
in
(
0
,
2
,
4
)]
),
default
=
"
000000
"
,
help
=
"
Background color in rgb hex
"
,
)
parser
.
add_argument
(
"
images
"
,
nargs
=
"
*
"
,
default
=
[],
help
=
"
path to images
"
)
a
=
parser
.
parse_args
()
a
=
parser
.
parse_args
()
...
@@ -16,12 +34,12 @@ if a.debug:
...
@@ -16,12 +34,12 @@ if a.debug:
print
(
a
)
print
(
a
)
for
path
in
a
.
images
:
for
path
in
a
.
images
:
img
=
Image
.
open
(
path
,
'
r
'
)
img
=
Image
.
open
(
path
,
"
r
"
)
mask
=
deepcopy
(
img
)
mask
=
deepcopy
(
img
)
mask_p
=
mask
.
load
()
mask_p
=
mask
.
load
()
bg
=
Image
.
new
(
'
RGB
'
,
img
.
size
,
a
.
background
)
bg
=
Image
.
new
(
"
RGB
"
,
img
.
size
,
a
.
background
)
bg
.
paste
(
img
,
None
,
img
)
bg
.
paste
(
img
,
None
,
img
)
img
=
bg
img
=
bg
...
@@ -32,12 +50,15 @@ for path in a.images:
...
@@ -32,12 +50,15 @@ for path in a.images:
elif
not
a
.
exact_alpha
:
elif
not
a
.
exact_alpha
:
mask_p
[
x
,
y
]
=
(
*
mask_p
[
x
,
y
][:
3
],
(
mask_p
[
x
,
y
][
3
]
//
255
)
*
255
)
mask_p
[
x
,
y
]
=
(
*
mask_p
[
x
,
y
][:
3
],
(
mask_p
[
x
,
y
][
3
]
//
255
)
*
255
)
else
:
else
:
mask_p
[
x
,
y
]
=
(
*
mask_p
[
x
,
y
][:
3
],
min
((
mask_p
[
x
,
y
][
3
]
//
1
)
*
255
,
255
))
mask_p
[
x
,
y
]
=
(
*
mask_p
[
x
,
y
][:
3
],
min
((
mask_p
[
x
,
y
][
3
]
//
1
)
*
255
,
255
),
)
if
a
.
debug
:
if
a
.
debug
:
# mask.show()
# mask.show()
img
.
show
()
img
.
show
()
show_img
=
Image
.
new
(
'
RGBA
'
,
img
.
size
,
(
0
,
0
,
0
,
0
))
show_img
=
Image
.
new
(
"
RGBA
"
,
img
.
size
,
(
0
,
0
,
0
,
0
))
show_img
.
paste
(
img
,
None
,
mask
)
show_img
.
paste
(
img
,
None
,
mask
)
# show_img.show()
# show_img.show()
...
@@ -48,10 +69,10 @@ for path in a.images:
...
@@ -48,10 +69,10 @@ for path in a.images:
for
y
in
range
(
img
.
size
[
1
]):
for
y
in
range
(
img
.
size
[
1
]):
for
x
in
range
(
img
.
size
[
0
]):
for
x
in
range
(
img
.
size
[
0
]):
if
mask_p
[
x
,
y
][
3
]
>
0
:
if
mask_p
[
x
,
y
][
3
]
>
0
:
msb
=
(
img_p
[
x
,
y
][
0
]
&
0xF8
)
|
(
img_p
[
x
,
y
][
1
]
>>
5
)
;
msb
=
(
img_p
[
x
,
y
][
0
]
&
0xF8
)
|
(
img_p
[
x
,
y
][
1
]
>>
5
)
lsb
=
((
img_p
[
x
,
y
][
1
]
&
0x1C
)
<<
3
)
|
(
img_p
[
x
,
y
][
2
]
>>
3
)
;
lsb
=
((
img_p
[
x
,
y
][
1
]
&
0x1C
)
<<
3
)
|
(
img_p
[
x
,
y
][
2
]
>>
3
)
data
.
extend
(
x
.
to_bytes
(
length
=
1
,
byteorder
=
'
big
'
))
data
.
extend
(
x
.
to_bytes
(
length
=
1
,
byteorder
=
"
big
"
))
data
.
extend
(
y
.
to_bytes
(
length
=
1
,
byteorder
=
'
big
'
))
data
.
extend
(
y
.
to_bytes
(
length
=
1
,
byteorder
=
"
big
"
))
data
.
extend
(
lsb
.
to_bytes
(
length
=
1
,
byteorder
=
'
big
'
))
data
.
extend
(
lsb
.
to_bytes
(
length
=
1
,
byteorder
=
"
big
"
))
data
.
extend
(
msb
.
to_bytes
(
length
=
1
,
byteorder
=
'
big
'
))
data
.
extend
(
msb
.
to_bytes
(
length
=
1
,
byteorder
=
"
big
"
))
print
(
path
[
path
.
rfind
(
'
/
'
)
+
1
:
path
.
rfind
(
'
.
'
)],
'
=
'
,
data
)
print
(
path
[
path
.
rfind
(
"
/
"
)
+
1
:
path
.
rfind
(
"
.
"
)],
"
=
"
,
data
)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment