Refactor and improve imgdiag. am: 1f146b7db1
am: b43dca51d7

Change-Id: Ia3db976ecaf12772a17f302b4eb3db47c10abeb1