def _CheckPNGFormat(input_api, output_api):
  """Checks that .png files have a format that will be considered valid by our
  test runners. If a file ends with .png, then it must be of the form
  NAME_expected(_(skia|skiapaths))?(_(win|mac|linux))?.pdf.#.png
  The expected format used by _CheckPngNames() in testing/corpus/PRESUBMIT.py
  must be the same as this one.
  """
  expected_pattern = input_api.re.compile(
      r'.+_expected(_(skia|skiapaths))?(_(win|mac|linux))?\.pdf\.\d+.png')
  results = []
  for f in input_api.AffectedFiles(include_deletes=False):
    if not f.LocalPath().endswith('.png'):
      continue
    if expected_pattern.match(f.LocalPath()):
      continue
    results.append(output_api.PresubmitError(
        'PNG file %s does not have the correct format' % f.LocalPath()))
  return results