]> git.ipfire.org Git - thirdparty/tvheadend.git/commitdiff
configure: add on-the-fly pngquant support to save more space for bundle builds
authorJaroslav Kysela <perex@perex.cz>
Tue, 4 Apr 2017 19:47:50 +0000 (21:47 +0200)
committerJaroslav Kysela <perex@perex.cz>
Tue, 4 Apr 2017 19:47:50 +0000 (21:47 +0200)
Makefile
configure
support/mkbundle

index ea3d9a5f0ba597e9b27aeb8afe5630ec02114ba0..10d98cc7369c43b4857773f08f833da57ef5572a 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -164,7 +164,8 @@ vpath %.h $(ROOTDIR)
 # Other config
 #
 
-BUNDLE_FLAGS-${CONFIG_ZLIB} = -z
+BUNDLE_FLAGS-${CONFIG_ZLIB} += -z
+BUNDLE_FLAGS-${CONFIG_PNGQUANT} += -q
 BUNDLE_FLAGS = ${BUNDLE_FLAGS-yes}
 
 #
index 97385764b5eaf4833124c9ee007e9097f1ed2317..40f3c2cfa6589f88e6c9ede2f1c4e2e247743004 100755 (executable)
--- a/configure
+++ b/configure
@@ -58,6 +58,7 @@ OPTIONS=(
   "ccache:auto"
   "tvhcsa:auto"
   "bundle:no"
+  "pngquant:no"
   "dvbcsa:no"
   "dvben50221:auto"
   "kqueue:no"
index 1d41d01492d8b6b222050c32a921afbd83cca918..170ef9a915120c7124043a097d5534f5669df53b 100755 (executable)
@@ -25,6 +25,8 @@ optp.add_option('-z', '--gzip', action='store_true',
                 help='Compress the files with gzip')
 optp.add_option('-l', '--gzlevel', type='int', default=9,
                 help='Specify compression level if using gzip')
+optp.add_option('-q', '--pngquant', action='store_true',
+                help='Compress the png files with pngquant')
 optp.add_option('-o', '--output', default=None,
                 help='Specify output file (default /dev/stdout)')
 optp.add_option('-d', '--deps', default=None,
@@ -40,7 +42,15 @@ if opts.deps:
   depf = open(opts.deps, 'w')
   depf.write('%s: \\\n' % opts.output)
 
-# Build heirarchy
+# PNGquant
+pngquant_bin = '/usr/bin/pngquant'
+if opts.pngquant:
+  import distutils.spawn
+  import subprocess
+  import time
+  distutils.spawn.find_executable('pngquant')
+
+# Build hierarchy
 root  = os.path.abspath(os.path.join(os.path.dirname(sys.argv[0]), '..'))
 ents  = {}
 for path in args:
@@ -76,6 +86,25 @@ def output_file ( path, name, idx, next = -1 ):
   outf.write('static const uint8_t filebundle_data_%06d[] = {' % idx)
   o = -1
   d = open(p, 'rb').read()
+  if opts.pngquant and p.endswith('.png'):
+    fd = subprocess.PIPE
+    child = subprocess.Popen([pngquant_bin, '-Q80-95', '-'],
+                             stdin=fd, stdout=fd, stderr=fd)
+    child.stdin.write(d)
+    child.stdin.close()
+    d = b''
+    while 1:
+      rc = child.poll()
+      if rc is not None:
+        break
+      d2 = child.stdout.read(64*1024)
+      if not d2:
+        time.sleep(0.05)
+      d += d2
+    d += child.stdout.read()
+    if rc != 0: d = ''
+    if not d:
+      d = open(p, 'rb').read()
   if p.endswith('.gz'):
     t = BytesIO(d)
     z = gzip.GzipFile(filename=name, mode='r', fileobj=t)