Add an extract command for doom graphics in the wad.
This commit is contained in:
parent
44285fbf59
commit
1ad6ec7297
2 changed files with 32 additions and 0 deletions
31
dcc/extract.py
Normal file
31
dcc/extract.py
Normal file
|
@ -0,0 +1,31 @@
|
||||||
|
from cliff.command import Command
|
||||||
|
import dcc.config
|
||||||
|
import omg
|
||||||
|
import numpy as np
|
||||||
|
import wand.color
|
||||||
|
import wand.image
|
||||||
|
|
||||||
|
class Extract(Command):
|
||||||
|
def get_parser(self, prog_name):
|
||||||
|
parser = super().get_parser(prog_name)
|
||||||
|
parser.add_argument('wad')
|
||||||
|
parser.add_argument('lump')
|
||||||
|
return parser
|
||||||
|
|
||||||
|
def take_action(self, parsed_args):
|
||||||
|
wads = sorted(dcc.config.PWADS.joinpath(parsed_args.wad).glob('*.wad', case_sensitive=False), reverse=True)
|
||||||
|
|
||||||
|
for w in wads:
|
||||||
|
try:
|
||||||
|
# TODO: handle anything other than graphics.
|
||||||
|
wad = omg.WadIO(w)
|
||||||
|
gl = omg.Graphic(wad.read(parsed_args.lump))
|
||||||
|
# With no arguments, convert() changes a paletted image to an RGB one.
|
||||||
|
with wand.image.Image.from_array(np.array(gl.to_Image().convert())) as img:
|
||||||
|
img.transparent_color(wand.color.Color("#ff00ff"), 0.0)
|
||||||
|
img.save(filename=dcc.config.OUTPUT.joinpath(parsed_args.wad).joinpath(parsed_args.lump + ".png"))
|
||||||
|
return
|
||||||
|
except Exception as e:
|
||||||
|
print("Wad {} likely has no lump {} (exception {}).".format(w, parsed_args.lump, e))
|
||||||
|
|
||||||
|
print("Lump {} not found in any wad in {}".format(parsed_args.lump, parsed_args.wad))
|
1
setup.py
1
setup.py
|
@ -28,6 +28,7 @@ setup(
|
||||||
'pb = dcc.pb:PB',
|
'pb = dcc.pb:PB',
|
||||||
'ss = dcc.ss:SS',
|
'ss = dcc.ss:SS',
|
||||||
'check = dcc.check:Check',
|
'check = dcc.check:Check',
|
||||||
|
'extract = dcc.extract:Extract',
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
zip_safe=False,
|
zip_safe=False,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue