Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
PyNutil
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Harry Carey
PyNutil
Commits
53cdbadd
Commit
53cdbadd
authored
1 year ago
by
Harry Carey
Browse files
Options
Downloads
Patches
Plain Diff
edits
parent
a90e2efe
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
messing_around_files/pyflat.py
+47
-47
47 additions, 47 deletions
messing_around_files/pyflat.py
with
47 additions
and
47 deletions
messing_around_files/pyflat.py
+
47
−
47
View file @
53cdbadd
"""
This is Gergely Csusc
'
s code from VisuAlign MediaWiki NITRC page,
this was a test, not used elsewhere in PyNutil
"""
import
sys
for
arg
in
sys
.
argv
:
if
arg
.
startswith
(
"
flat=
"
):
flatfile
=
arg
[
len
(
"
flat=
"
):]
if
arg
.
startswith
(
"
label=
"
):
labelfile
=
arg
[
len
(
"
label=
"
):]
if
arg
.
startswith
(
"
json=
"
):
jsonfile
=
arg
[
len
(
"
json=
"
):]
if
arg
.
startswith
(
"
output=
"
):
outfile
=
arg
[
len
(
"
output=
"
):]
if
"
flatfile
"
not
in
vars
():
print
(
"
flat=<some .flat file> parameter missing
"
)
sys
.
exit
()
if
"
outfile
"
not
in
vars
():
print
(
"
output=<new .png file> parameter missing
"
)
sys
.
exit
()
palette
=
False
if
"
labelfile
"
in
vars
():
import
re
palette
=
[]
with
open
(
labelfile
)
as
f
:
for
line
in
f
:
lbl
=
re
.
match
(
r
'
\s*\d+\s+(\d+)\s+(\d+)\s+(\d+)
'
,
line
)
if
lbl
:
palette
.
append
((
int
(
lbl
[
1
]),
int
(
lbl
[
2
]),
int
(
lbl
[
3
])))
print
(
f
"
{
len
(
palette
)
}
labels parsed
"
)
elif
"
jsonfile
"
in
vars
():
import
json
with
open
(
jsonfile
)
as
f
:
palette
=
[(
i
[
"
red
"
],
i
[
"
green
"
],
i
[
"
blue
"
])
for
i
in
json
.
load
(
f
)]
print
(
f
"
{
len
(
palette
)
}
labels loaded
"
)
import
struct
with
open
(
flatfile
,
"
rb
"
)
as
f
:
b
,
w
,
h
=
struct
.
unpack
(
"
>BII
"
,
f
.
read
(
9
))
data
=
struct
.
unpack
(
"
>
"
+
(
"
xBH
"
[
b
]
*
(
w
*
h
)),
f
.
read
(
b
*
w
*
h
))
print
(
f
"
{
b
}
bytes per pixel,
{
w
}
x
{
h
}
resolution
"
)
import
PIL.Image
image
=
PIL
.
Image
.
new
(
"
RGB
"
if
palette
else
"
L
"
,(
w
,
h
))
for
y
in
range
(
h
):
for
x
in
range
(
w
):
image
.
putpixel
((
x
,
y
),
palette
[
data
[
x
+
y
*
w
]]
if
palette
else
data
[
x
+
y
*
w
]
&
255
)
image
.
save
(
outfile
,
"
PNG
"
)
\ No newline at end of file
import
sys
for
arg
in
sys
.
argv
:
if
arg
.
startswith
(
"
flat=
"
):
flatfile
=
arg
[
len
(
"
flat=
"
):]
if
arg
.
startswith
(
"
label=
"
):
labelfile
=
arg
[
len
(
"
label=
"
):]
if
arg
.
startswith
(
"
json=
"
):
jsonfile
=
arg
[
len
(
"
json=
"
):]
if
arg
.
startswith
(
"
output=
"
):
outfile
=
arg
[
len
(
"
output=
"
):]
if
"
flatfile
"
not
in
vars
():
print
(
"
flat=<some .flat file> parameter missing
"
)
sys
.
exit
()
if
"
outfile
"
not
in
vars
():
print
(
"
output=<new .png file> parameter missing
"
)
sys
.
exit
()
palette
=
False
if
"
labelfile
"
in
vars
():
import
re
palette
=
[]
with
open
(
labelfile
)
as
f
:
for
line
in
f
:
lbl
=
re
.
match
(
r
'
\s*\d+\s+(\d+)\s+(\d+)\s+(\d+)
'
,
line
)
if
lbl
:
palette
.
append
((
int
(
lbl
[
1
]),
int
(
lbl
[
2
]),
int
(
lbl
[
3
])))
print
(
f
"
{
len
(
palette
)
}
labels parsed
"
)
elif
"
jsonfile
"
in
vars
():
import
json
with
open
(
jsonfile
)
as
f
:
palette
=
[(
i
[
"
red
"
],
i
[
"
green
"
],
i
[
"
blue
"
])
for
i
in
json
.
load
(
f
)]
print
(
f
"
{
len
(
palette
)
}
labels loaded
"
)
import
struct
with
open
(
flatfile
,
"
rb
"
)
as
f
:
b
,
w
,
h
=
struct
.
unpack
(
"
>BII
"
,
f
.
read
(
9
))
data
=
struct
.
unpack
(
"
>
"
+
(
"
xBH
"
[
b
]
*
(
w
*
h
)),
f
.
read
(
b
*
w
*
h
))
print
(
f
"
{
b
}
bytes per pixel,
{
w
}
x
{
h
}
resolution
"
)
import
PIL.Image
image
=
PIL
.
Image
.
new
(
"
RGB
"
if
palette
else
"
L
"
,(
w
,
h
))
for
y
in
range
(
h
):
for
x
in
range
(
w
):
image
.
putpixel
((
x
,
y
),
palette
[
data
[
x
+
y
*
w
]]
if
palette
else
data
[
x
+
y
*
w
]
&
255
)
image
.
save
(
outfile
,
"
PNG
"
)
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
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