QA: Use pngfix to find broken PNG files

Acked-by: Alexander Berntsen <bernalex@gentoo.org>
Acked-by: Brian Dolbec <dolsen@gentoo.org>
Reviewed-by: Justin Lecher <jlec@gentoo.org>
Reviewed-by: Sergei Trofimovich <slyfox@gentoo.org>
diff --git a/bin/misc-functions.sh b/bin/misc-functions.sh
index 5ccf7c2..4e0f1fc 100755
--- a/bin/misc-functions.sh
+++ b/bin/misc-functions.sh
@@ -1,5 +1,5 @@
 #!/bin/bash
-# Copyright 1999-2013 Gentoo Foundation
+# Copyright 1999-2014 Gentoo Foundation
 # Distributed under the terms of the GNU General Public License v2
 #
 # Miscellaneous shell functions that make use of the ebuild env but don't need
@@ -860,6 +860,33 @@
 
 		[[ ${abort} == yes ]] && die "multilib-strict check failed!"
 	fi
+
+	local pngfix=$(type -P pngfix)
+	if [[ -n ${pngfix} ]] ; then
+		local pngout=()
+		local next
+
+		while read -r -a pngout ; do
+			local error
+
+			case "${pngout[1]}" in
+				CHK)
+					error='invalid checksum'
+					;;
+				TFB)
+					error='broken IDAT window length'
+					;;
+			esac
+
+			if [[ -n ${error} ]] ; then
+				if [[ -z ${next} ]] ; then
+					eqawarn "QA Notice: broken .png files found:"
+					next=1
+				fi
+				eqawarn "   ${pngout[@]:7}: ${error}"
+			fi
+		done < <(find "${ED}" -type f -name '*.png' -exec "${pngfix}" {} +)
+	fi
 }
 
 install_qa_check_prefix() {