Skip to content

Instantly share code, notes, and snippets.

@ensc
Created November 1, 2016 10:24
Show Gist options
  • Save ensc/1d6cfcce945ba6dd94c711bbec17f1e9 to your computer and use it in GitHub Desktop.
Save ensc/1d6cfcce945ba6dd94c711bbec17f1e9 to your computer and use it in GitHub Desktop.
####
#### Usage:
#### SRC_URI = "<uri>;name=bootsplash[;rotate=<rot>][;convert=<conv>]
#### name=bootsplash ... mandatory parameter to mark URI as
#### a bootsplash image
#### rotate=<rot> ... rotate image by <rot> degree
#### convert=<conv> ... apply <conv> conversion
#### linux-logo ... convert to ASCII PPM with <=224 colors
#### barebox ... convert to PNG
####
#### There will be used the ${CONVERT} program which is assumed
#### to be compatible with the 'convert' from the ImageMagick
#### (http://www.imagemagick.org/) suite.
####
BOOTSPLASH ?= "${WORKDIR}/bootsplash"
CONVERT ?= "convert.im6"
def _find_bootsplash(d):
fetch = bb.fetch2.Fetch([], d)
for url in fetch.urls:
urldata = fetch.ud[url]
parm = urldata.parm
if parm.get('name') == 'bootsplash':
return urldata
raise Exception("no bootsplash")
def get_bootsplash_deps(d):
uri = _find_bootsplash(d)
parm = uri.parm
convert = parm.get('convert')
rotate = parm.get('rotate')
if (rotate is not None) or (convert is not None):
return "imagemagick-native:do_populate_sysroot"
else:
return ""
get_bootsplash_convert[vardeps] += "SRC_URI BOOTSPLASH"
def get_bootsplash_convert(d):
uri = _find_bootsplash(d)
parm = uri.parm
convert = parm.get('convert')
rotate = parm.get('rotate')
if not uri.localpath:
# happens in early parsing stage; skip further processing
return None
opts=[]
fmt=""
if rotate is not None:
opts.extend(['-rotate', '%s' % rotate])
if convert is None:
pass
elif convert == 'linux-logo':
opts.extend(['-compress', 'none', '-colors', '224'])
fmt = 'ppm:'
elif convert == 'barebox':
fmt = 'png:'
else:
raise Exception("unsupported '%s' conversion" % convert)
if not opts:
opts = [ "-s", uri.localpath, d.getVar('BOOTSPLASH', False) ]
prog = "ln"
else:
opts.extend([uri.localpath, fmt + d.getVar('BOOTSPLASH', False) ])
prog = '${CONVERT}'
import pipes
opts = map(lambda x: pipes.quote(x), opts)
return "%s %s" % (prog, ' '.join(opts))
LOGO_CONVERT_CMD = "${@get_bootsplash_convert(d)}"
LOGO_DEPENDS = "${@get_bootsplash_deps(d)}"
do_unpack[depends] += "${LOGO_DEPENDS}"
do_logo_preprocess() {
set -x
${LOGO_CONVERT_CMD}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment