Rename png_ functions conflicting with chrome.

Part of the work required to ship XFA with chrome.

BUG=pdfium:396
R=dsinclair@chromium.org

Review URL: https://codereview.chromium.org/1763493002 .
diff --git a/BUILD.gn b/BUILD.gn
index 831fe2d..3f99c28 100644
--- a/BUILD.gn
+++ b/BUILD.gn
@@ -16,7 +16,6 @@
   defines = [
     "OPJ_STATIC",
     "PNG_PREFIX",
-    "PNGPREFIX_H",
     "PNG_USE_READ_MACROS",
     "V8_DEPRECATION_WARNINGS",
     "_CRT_SECURE_NO_WARNINGS",
diff --git a/pdfium.gyp b/pdfium.gyp
index 6bc8709..14d18e1 100644
--- a/pdfium.gyp
+++ b/pdfium.gyp
@@ -22,7 +22,6 @@
     'defines' : [
       'OPJ_STATIC',
       'PNG_PREFIX',
-      'PNGPREFIX_H',
       'PNG_USE_READ_MACROS',
       'V8_DEPRECATION_WARNINGS',
       '_CRT_SECURE_NO_WARNINGS',
diff --git a/samples/BUILD.gn b/samples/BUILD.gn
index e365208..9ff1bea 100644
--- a/samples/BUILD.gn
+++ b/samples/BUILD.gn
@@ -17,24 +17,23 @@
 config("pdfium_samples_config") {
   defines = [
     "PNG_PREFIX",
-    "PNGPREFIX_H",
     "PNG_USE_READ_MACROS",
   ]
   include_dirs = [ ".." ]
   if (pdf_enable_v8) {
-    defines += [ "PDF_ENABLE_V8", ]
+    defines += [ "PDF_ENABLE_V8" ]
   }
   if (pdf_enable_xfa) {
-    defines += [ "PDF_ENABLE_XFA", ]
+    defines += [ "PDF_ENABLE_XFA" ]
   }
 }
 
 executable("pdfium_test") {
   testonly = true
   sources = [
-    "pdfium_test.cc",
     "image_diff_png.cc",
     "image_diff_png.h",
+    "pdfium_test.cc",
   ]
   deps = [
     "//build/config/sanitizers:deps",
diff --git a/samples/samples.gyp b/samples/samples.gyp
index da9ce74..6f262d5 100644
--- a/samples/samples.gyp
+++ b/samples/samples.gyp
@@ -10,7 +10,6 @@
   'target_defaults': {
     'defines' : [
       'PNG_PREFIX',
-      'PNGPREFIX_H',
       'PNG_USE_READ_MACROS',
     ],
     'include_dirs': [
diff --git a/testing/libfuzzer/BUILD.gn b/testing/libfuzzer/BUILD.gn
index 46cf058..d5ccb7f 100644
--- a/testing/libfuzzer/BUILD.gn
+++ b/testing/libfuzzer/BUILD.gn
@@ -7,7 +7,6 @@
 config("libfuzzer_config") {
   defines = [
     "PNG_PREFIX",
-    "PNGPREFIX_H",
     "PNG_USE_READ_MACROS",
   ]
   include_dirs = [ "../.." ]
diff --git a/testing/libfuzzer/fuzzers.gyp b/testing/libfuzzer/fuzzers.gyp
index a65fe1b..bdd9086 100644
--- a/testing/libfuzzer/fuzzers.gyp
+++ b/testing/libfuzzer/fuzzers.gyp
@@ -10,7 +10,6 @@
   'target_defaults': {
     'defines' : [
       'PNG_PREFIX',
-      'PNGPREFIX_H',
       'PNG_USE_READ_MACROS',
     ],
     'include_dirs': [
diff --git a/third_party/BUILD.gn b/third_party/BUILD.gn
index 92fbcaa..ec6f8cb 100644
--- a/third_party/BUILD.gn
+++ b/third_party/BUILD.gn
@@ -298,6 +298,7 @@
     "libpng16/pnglibconf.h",
     "libpng16/pngmem.c",
     "libpng16/pngpread.c",
+    "libpng16/pngprefix.h",
     "libpng16/pngpriv.h",
     "libpng16/pngread.c",
     "libpng16/pngrio.c",
@@ -320,10 +321,10 @@
       "//build/config/compiler:no_chromium_code",
       "//third_party/pdfium:pdfium_config",
     ]
-    deps = [ "//third_party:jpeg" ]
+    deps = [
+      "//third_party:jpeg",
+    ]
     sources = [
-      "libtiff/tiffiop.h",
-      "libtiff/tiffvers.h",
       "libtiff/tif_aux.c",
       "libtiff/tif_close.c",
       "libtiff/tif_codec.c",
@@ -359,6 +360,8 @@
       "libtiff/tif_warning.c",
       "libtiff/tif_write.c",
       "libtiff/tif_zip.c",
+      "libtiff/tiffiop.h",
+      "libtiff/tiffvers.h",
     ]
   }
 }
diff --git a/third_party/libpng16/README.pdfium b/third_party/libpng16/README.pdfium
index d60bc6f..b0e6805 100644
--- a/third_party/libpng16/README.pdfium
+++ b/third_party/libpng16/README.pdfium
@@ -10,6 +10,7 @@
 Local Modifications:
 
 pnglibconf.h: a copy of libpng's scripts/pnglibconf.h.prebuilt.
+pngprefix.h: manually-created redefinitions to avoid conflicts with chome.
 0000-build-config.patch: Local build configuration changes.
 0001-disable-arm-neon.diff: Disable ARM NEON optimizations.
 0002-static-png-gt.patch: Unconditionally use static png_gt() in png.c to avoid compilation warning.
diff --git a/third_party/libpng16/pngprefix.h b/third_party/libpng16/pngprefix.h
new file mode 100644
index 0000000..8eab668
--- /dev/null
+++ b/third_party/libpng16/pngprefix.h
@@ -0,0 +1,17 @@
+// Copyright 2016 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef PNGPREFIX_H
+#define PNGPREFIX_H
+
+// The purpose of this file is to rename conflicting functions
+// when this version of libpng and chromium's version of it are
+// both simultaneously present.
+
+#define png_get_uint_32 PDFIUM_png_get_uint_32
+#define png_get_uint_16 PDFIUM_png_get_uint_16
+#define png_get_int_32 PDFIUM_png_get_int_32
+#define png_get_int_16 PDFIUM_png_get_int_16
+
+#endif  // PNGPREFIX_H
diff --git a/third_party/third_party.gyp b/third_party/third_party.gyp
index 6746230..d58c9a7 100644
--- a/third_party/third_party.gyp
+++ b/third_party/third_party.gyp
@@ -10,7 +10,6 @@
     'defines': [
       'OPJ_STATIC',
       'PNG_PREFIX',
-      'PNGPREFIX_H',
       'PNG_USE_READ_MACROS',
       '_CRT_SECURE_NO_WARNINGS',
     ],
@@ -280,6 +279,7 @@
         'libpng16/pnglibconf.h',
         'libpng16/pngmem.c',
         'libpng16/pngpread.c',
+        'libpng16/pngprefix.h',
         'libpng16/pngpriv.h',
         'libpng16/pngread.c',
         'libpng16/pngrio.c',