Upgrade libjpeg-turbo to 09efc26aff7983f4377a1743a197ca3d74796d7d

Test: make
Change-Id: I81d381e5dcef8a1169021ca75ddf2cb6d505affd
diff --git a/.gitattributes b/.gitattributes
new file mode 100644
index 0000000..2948038
--- /dev/null
+++ b/.gitattributes
@@ -0,0 +1,5 @@
+/.travis.yml export-ignore
+/appveyor.yml export-ignore
+/ci export-ignore
+/.gitattributes export-ignore
+/.github export-ignore
diff --git a/.github/CONTRIBUTING.md b/.github/CONTRIBUTING.md
new file mode 100644
index 0000000..d554dd0
--- /dev/null
+++ b/.github/CONTRIBUTING.md
@@ -0,0 +1,95 @@
+Contributing to libjpeg-turbo
+=============================
+
+libjpeg-turbo is a stable and mature product with a worldwide reach, it is an
+ISO/ITU-T reference implementation of the JPEG standard, and its maintainer
+does not earn a salary for maintaining it.  Thus, not every code contribution
+can or will be accepted into the libjpeg-turbo code base.  In order to maximize
+the chances that a code contribution is acceptable, please adhere to the
+following guidelines:
+
+1. If the code contribution is a bug fix, then please ensure that enough
+information is provided so that the maintainer can readily reproduce and
+document the bug.  That information should include:
+    - A clear and concise description of the bug
+    - The steps and (if applicable) images necessary to reproduce the bug
+    - The compilers, operating systems, and CPUs with which the bug was
+      observed
+    - The versions of libjpeg-turbo with which the bug was observed
+    - If the bug is a regression, the specific commit that introduced the bug
+      (use `git bisect` to determine this)
+
+2. If the code contribution will implement a major new feature, then please
+contact the project maintainer (through a
+[GitHub issue](https://github.com/libjpeg-turbo/libjpeg-turbo/issues/new),
+[direct e-mail](https://libjpeg-turbo.org/About/Contact), or the
+[libjpeg-turbo-devel mailing list](https://libjpeg-turbo.org/About/MailingLists))
+prior to implementing the feature.  In general, major new features that are
+potentially disruptive to the quality of libjpeg-turbo are unlikely to be
+accepted unless:
+    - The new feature is within the existing scope of libjpeg-turbo.
+    - The new feature has been thoroughly regression tested and benchmarked on
+      all of the supported platforms that are potentially affected by it.
+    - The new feature has been documented clearly and concisely in the change
+      log and (if applicable) the libjpeg and TurboJPEG API documentation and
+      man pages.
+    - The code implementing the new feature is formatted consistently with the
+      rest of the libjpeg-turbo code base (use
+      [checkstyle](https://github.com/libjpeg-turbo/checkstyle) to validate
+      this.)
+    - The new feature does not introduce new members into the exposed libjpeg
+      API structures (doing so would break backward ABI compatibility.)
+    - The new feature does not alter existing libjpeg-turbo usage or
+      development workflows.
+    - The code implementing the new feature is elegant, easily maintainable,
+      and causes the least possible amount of disruption to the libjpeg-turbo
+      code base.
+    - The new feature is based on the dev branch of the libjpeg-turbo
+      repository.
+
+    ... OR ...
+
+    - Your organization is prepared to pay for the labor necessary to ensure
+      all of the above.  Even the most well-written patches can still require
+      a significant amount of labor to clean up, test, and integrate.  (See
+      above RE: the maintainer not earning a salary.)
+
+    Specific types of features that *will not* be accepted:
+
+    - Features that extend the scope of libjpeg-turbo to support image formats
+      other than DCT-based JPEG and JFIF
+    - Features that extend the scope of libjpeg-turbo to support image
+      processing algorithms that are not necessary for JPEG compression or
+      decompression
+    - Extensions to the JPEG format that have not been approved by the
+      appropriate standards bodies
+    - Non-trivial performance enhancements that have less than a 5% overall
+      impact on performance
+
+3. If the code contribution is a build system enhancement, then please be
+prepared to justify the enhancement.  In general, build system enhancements
+are unlikely to be accepted unless:
+    - The enhancement is potentially beneficial to a significant number of
+      upstream libjpeg-turbo users/developers.  (If the enhancement is only
+      beneficial to a downstream project, then it does not belong here.)
+    - The enhancement has been tested with the following CMake versions:
+        - The earliest version of CMake that libjpeg-turbo currently supports
+          (refer to CMakeLists.txt)
+        - The most recent major version of CMake
+        - (if applicable) The earliest version of CMake with which the
+          enhancement can be used
+    - The enhancement has been tested on all of the major platforms (Mac,
+      Linux, Windows/Visual C++, Windows/MinGW) that are potentially affected
+      by it.
+    - The enhancement does not introduce new build system requirements or CMake
+      variables unless absolutely necessary.
+    - The enhancement does not alter existing libjpeg-turbo development
+      workflows.
+
+    Specific types of build system enhancements that *will not* be accepted:
+
+    - Enhancements that allow libjpeg-turbo to be built from a subdirectory
+      of a downstream repository.  These enhancements are not maintainable in
+      the upstream libjpeg-turbo build system.  Use the CMake
+      `ExternalProject_Add()` function instead.
+    - Enhancements that introduce new (non-CMake-based) build systems
diff --git a/.github/ISSUE_TEMPLATE/bug-report.md b/.github/ISSUE_TEMPLATE/bug-report.md
new file mode 100644
index 0000000..a2a5feb
--- /dev/null
+++ b/.github/ISSUE_TEMPLATE/bug-report.md
@@ -0,0 +1,40 @@
+---
+name: Bug Report
+about: Inform the libjpeg-turbo maintainer about unexpected, reproducible behavior
+title: ''
+labels: bug
+assignees: dcommander
+
+---
+
+**Have you searched the existing issues (both open and closed) in the libjpeg-turbo issue tracker to ensure that this bug report is not a duplicate?**
+
+
+**Does this bug report describe one of the [two known and unsolvable issues with the JPEG format](https://libjpeg-turbo.org/pmwiki/uploads/About/TwoIssueswiththeJPEGStandard.pdf)?**
+
+
+**Clear and concise description of the bug:**
+
+
+**Steps to reproduce the bug (using *only* libjpeg-turbo):**
+
+
+**Image(s) needed in order to reproduce the bug (if applicable):**
+
+
+**Expected behavior:**
+
+
+**Observed behavior:**
+
+
+**Platform(s) (compiler version, operating system version, CPU) on which the bug was observed:**
+
+
+**libjpeg-turbo release(s), commit(s), or branch(es) in which the bug was observed (always test the tip of the master branch or the latest [stable pre-release](https://libjpeg-turbo.org/DeveloperInfo/PreReleases) to verify that the bug hasn't already been fixed):**
+
+
+**If the bug is a regression, the specific commit that introduced the regression (use `git bisect` to determine this):**
+
+
+**Additional information:**
diff --git a/.github/ISSUE_TEMPLATE/feature-request.md b/.github/ISSUE_TEMPLATE/feature-request.md
new file mode 100644
index 0000000..eac443a
--- /dev/null
+++ b/.github/ISSUE_TEMPLATE/feature-request.md
@@ -0,0 +1,8 @@
+---
+name: Feature Request
+about: Suggest new libjpeg-turbo functionality
+title: ''
+labels: enhancement
+assignees: dcommander
+
+---
diff --git a/.travis.yml b/.travis.yml
new file mode 100644
index 0000000..35a7907
--- /dev/null
+++ b/.travis.yml
@@ -0,0 +1,156 @@
+language: c
+
+branches:
+  except:
+    - /^[0-9]+\.[0-9]+\.[0-9]+/
+    - /^jpeg-.*/
+
+matrix:
+  include:
+    - os: linux
+      env: BUILD_OFFICIAL=1
+      sudo: required
+      services:
+        - docker
+    - os: osx
+      env: BUILD_OFFICIAL=1
+      osx_image: xcode8.3
+    - os: linux
+      compiler: clang
+      env:
+        CMAKE_BUILD_TYPE=RelWithDebInfo
+        CFLAGS_RELWITHDEBINFO="-O1 -g -fsanitize=address,undefined -fno-omit-frame-pointer"
+        CMAKE_FLAGS="-DENABLE_SHARED=0"
+        ASAN_OPTIONS="detect_leaks=1 symbolize=1"
+        CTEST_OUTPUT_ON_FAILURE=1
+      addons:
+        apt:
+          packages:
+            - nasm
+    - os: linux
+      compiler: gcc
+      env:
+        CMAKE_FLAGS="-DWITH_12BIT=1"
+        CTEST_OUTPUT_ON_FAILURE=1
+    - os: linux
+      compiler: gcc
+      env:
+        CMAKE_FLAGS="-DWITH_JPEG7=1"
+        CTEST_OUTPUT_ON_FAILURE=1
+      addons:
+        apt:
+          packages:
+            - nasm
+    - os: linux
+      compiler: gcc
+      env:
+        CMAKE_FLAGS="-DWITH_JPEG8=1"
+        CTEST_OUTPUT_ON_FAILURE=1
+      addons:
+        apt:
+          packages:
+            - nasm
+    - os: linux
+      compiler: clang
+      env:
+        CMAKE_BUILD_TYPE=RelWithDebInfo
+        CFLAGS_RELWITHDEBINFO="-O3 -g -fsanitize=memory -fPIE"
+        CMAKE_FLAGS="-DWITH_SIMD=0"
+        CTEST_OUTPUT_ON_FAILURE=1
+
+addons:
+  homebrew:
+    brewfile: true
+    update: true
+
+cache:
+  directories:
+    - $HOME/Library/Caches/Homebrew
+
+before_cache:
+  - if [ "${TRAVIS_OS_NAME}" = "osx" ]; then brew cleanup; fi
+
+before_install:
+  - if [ "$TRAVIS_OS_NAME" = "osx" ]; then
+      git clone --depth=1 https://github.com/libjpeg-turbo/gas-preprocessor.git ~/src/gas-preprocessor &&
+      ln -fs /Applications/Xcode.app /Applications/Xcode72.app;
+    fi
+  - if [ "${BUILD_OFFICIAL:-}" != "" ]; then
+      if [ "$TRAVIS_OS_NAME" = "linux" ]; then
+        docker pull dcommander/buildljt;
+      fi &&
+      git clone --depth=1 https://github.com/libjpeg-turbo/buildscripts.git -b $TRAVIS_BRANCH ~/src/buildscripts &&
+      if [ -n "$encrypted_f92e8533f6f1_iv" ]; then
+        openssl aes-256-cbc -K $encrypted_f92e8533f6f1_key -iv $encrypted_f92e8533f6f1_iv -in ci/keys.enc -out ci/keys -d &&
+        tar xf ci/keys &&
+        rm ci/keys &&
+        mv ci/gpgsign ~/src/buildscripts &&
+        gpg --batch --import ci/sign_ljt &&
+        rm ci/sign_ljt;
+      fi
+    fi
+
+script:
+  - if [ "${BUILD_OFFICIAL:-}" != "" ]; then
+      mkdir -p ~/src/ljt.nightly &&
+      if [ "$TRAVIS_OS_NAME" = "linux" ]; then
+        mkdir $HOME/rpmkeys &&
+        wget --no-check-certificate "http://www.libjpeg-turbo.org/key/LJTPR-GPG-KEY" -O $HOME/rpmkeys/LJTPR-GPG-KEY &&
+        docker run -v $HOME/src/ljt.nightly:/root/src/ljt.nightly -v $HOME/src/buildscripts:/root/src/buildscripts -v $TRAVIS_BUILD_DIR:/root/src/libjpeg-turbo -v $HOME/.gnupg:/root/.gnupg -v $HOME/rpmkeys:/rpmkeys -t dcommander/buildljt:latest bash -c "rpm --import /rpmkeys/LJTPR-GPG-KEY && ~/src/buildscripts/buildljt -d /root/src/libjpeg-turbo -v" &&
+        sudo chown -R travis:travis ~/src/ljt.nightly &&
+        mv ~/src/ljt.nightly/latest/log-$TRAVIS_OS_NAME.txt ~/src/ljt.nightly/latest/files/;
+      else
+        PATH=$PATH:~/src/gas-preprocessor ~/src/buildscripts/buildljt -d $TRAVIS_BUILD_DIR -v &&
+        mv ~/src/ljt.nightly/latest/log-$TRAVIS_OS_NAME.txt ~/src/ljt.nightly/latest/files/;
+      fi
+    fi
+  - if [ "${BUILD_OFFICIAL:-}" == "" ]; then
+      mkdir build &&
+      pushd build &&
+      cmake -G"Unix Makefiles" -DCMAKE_BUILD_TYPE=$CMAKE_BUILD_TYPE "-DCMAKE_C_FLAGS_RELWITHDEBINFO=$CFLAGS_RELWITHDEBINFO" $CMAKE_FLAGS .. &&
+      export NUMCPUS=`grep -c '^processor' /proc/cpuinfo` &&
+      make -j$NUMCPUS --load-average=$NUMCPUS &&
+      make test &&
+      if [[ ! "${CMAKE_FLAGS[0]}" =~ "WITH_12BIT" &&
+            ! "${CMAKE_FLAGS[0]}" =~ "WITH_SIMD" ]]; then
+        JSIMD_FORCESSE2=1 make test &&
+        cmake -DFLOATTEST=32bit .. &&
+        JSIMD_FORCENONE=1 make test;
+      fi &&
+      popd;
+    fi
+
+after_failure:
+  - if [ "${BUILD_OFFICIAL:-}" == "" ]; then
+      if [ -f $TRAVIS_BUILD_DIR/build/config.log ]; then
+        cat $TRAVIS_BUILD_DIR/build/config.log;
+      fi
+    fi
+
+deploy:
+  - provider: s3
+    bucket: libjpeg-turbo-pr
+    access_key_id:
+      secure: bmFEt4H90/oR/LiN9XI+G26Pd6hiyrTw3+Vg3lS4ynwAYk33weApaVM8CyzQTgIhGSPzFStqVm9fTrb3RmrYP/PnNS+/surOeWLkH2DMRxvc0qmetBuNx1+vAN7FUkY8MO/u5uE9WXHAdp4e64pXcLXEbKmh+wgDm72b35WmMxErtHsGbpqy+j47rQkY4BJGi7XQzjjafaamfm4PzitsjkYYsgX8KLI16jyJEIirvyDHCPTn9wKR/jSjelDl+xTlgZGuCqmLCBW8f6JgycIspWjcYfO4WpWvkbnnI2sl3rCMPvOYc4wHe8SwzG0l4tM1PblZZDRcU7vjE15PmNf1Xfq9Vx3RpgBJv+UBNL/Vn0rKdpUCeEcfC12hxrske8DWpV6waBiDivjQJreE+YRXqa5YBhV/EdkoKYCqafnJvRASlOko9evje8F9KXTNsIGTT1HPmU9QM9WoJwLs/Xa3t09EmA2IjhcuAvvUmwCTuBBQVAlDjExiTT3Zhc9IYZDD92JgpAYLgridtzR87ElOxKhTkR4PowdI6UiLYArPjMFTjoz5Rivb9qNpbLaQC8HCYgLWxpWtUTzlW/9rM8izHpF8ySFHjO6E2aA9OJFc0tcbEGwAs2jLGD01OduU+DbBfsIkW0EgfXCPbD3FVgHsn3tkuzgO/bg20SM7uuCEYKQ=
+    secret_access_key:
+      secure: mrkOpEtqd2dEmi/qNJyX9vkME+6xgVBnXaRETKF7jT+flcQCQ0ayQkRkMV7lzGqq44XFg+n6Cpfn6oW0gH9RNdcC8YQvFP+kgzPx6nw6V/M31Vz6ySapJf59HBzVevf0NJkr0/1JoWsp1iq4IoN10WPzsCXZB55Io3Cf7DgpR+yiyBlWOctDfNdjJ97Juw3ENE80MHDf0fVqdUOIknQka1p68yAGkjar9kc2Oe7o94RzzmoqEn8tuFumiBQjIcuVRALsKqz+eIxBNgkL3BF9shVyRjOWLAeBhMPVFxZs5Dgd4ECbvU0i33gfmje3d6qqcw78N2lZaLefoVvWol3pOzVO133ewOSY9/lmpqEiRUU2ohEe8T4aSoS7posBW42itUTO4Y5w+eVOnHsm4sRQaI+/AXWTe7GPel+P8Qbe8Ya10A5gnpoag7o3raRDcHx+/qaZw1Af/u4XiAOYz3be3U90Qc+YMc/kS5i8BH0GXBbSfaWQ00CwRFlZQ3n1xUqmjC2CmjZTki3W/p7mEt0DjhcH9ZIXscK603sCC+mF6pEd9019k5fG/8fr2Y4Ptai9kd3BxZJCX9/jSoMfWOBbgkA5bRgHU0xrAj+p49qD6Ej9Xr8GE3+uebz3sEuhSFRnCKwKoOHOemfgevfO2y/jQXP677WPf3xQX7bVDfTFSHU=
+    acl: public_read
+    local-dir: $HOME/src/ljt.nightly/latest/files
+    upload-dir: $TRAVIS_BRANCH/$TRAVIS_OS_NAME
+    on:
+      repo: libjpeg-turbo/libjpeg-turbo
+      branch: master
+      condition: -n "$BUILD_OFFICIAL"
+  - provider: s3
+    bucket: libjpeg-turbo-pr
+    access_key_id:
+      secure: bmFEt4H90/oR/LiN9XI+G26Pd6hiyrTw3+Vg3lS4ynwAYk33weApaVM8CyzQTgIhGSPzFStqVm9fTrb3RmrYP/PnNS+/surOeWLkH2DMRxvc0qmetBuNx1+vAN7FUkY8MO/u5uE9WXHAdp4e64pXcLXEbKmh+wgDm72b35WmMxErtHsGbpqy+j47rQkY4BJGi7XQzjjafaamfm4PzitsjkYYsgX8KLI16jyJEIirvyDHCPTn9wKR/jSjelDl+xTlgZGuCqmLCBW8f6JgycIspWjcYfO4WpWvkbnnI2sl3rCMPvOYc4wHe8SwzG0l4tM1PblZZDRcU7vjE15PmNf1Xfq9Vx3RpgBJv+UBNL/Vn0rKdpUCeEcfC12hxrske8DWpV6waBiDivjQJreE+YRXqa5YBhV/EdkoKYCqafnJvRASlOko9evje8F9KXTNsIGTT1HPmU9QM9WoJwLs/Xa3t09EmA2IjhcuAvvUmwCTuBBQVAlDjExiTT3Zhc9IYZDD92JgpAYLgridtzR87ElOxKhTkR4PowdI6UiLYArPjMFTjoz5Rivb9qNpbLaQC8HCYgLWxpWtUTzlW/9rM8izHpF8ySFHjO6E2aA9OJFc0tcbEGwAs2jLGD01OduU+DbBfsIkW0EgfXCPbD3FVgHsn3tkuzgO/bg20SM7uuCEYKQ=
+    secret_access_key:
+      secure: mrkOpEtqd2dEmi/qNJyX9vkME+6xgVBnXaRETKF7jT+flcQCQ0ayQkRkMV7lzGqq44XFg+n6Cpfn6oW0gH9RNdcC8YQvFP+kgzPx6nw6V/M31Vz6ySapJf59HBzVevf0NJkr0/1JoWsp1iq4IoN10WPzsCXZB55Io3Cf7DgpR+yiyBlWOctDfNdjJ97Juw3ENE80MHDf0fVqdUOIknQka1p68yAGkjar9kc2Oe7o94RzzmoqEn8tuFumiBQjIcuVRALsKqz+eIxBNgkL3BF9shVyRjOWLAeBhMPVFxZs5Dgd4ECbvU0i33gfmje3d6qqcw78N2lZaLefoVvWol3pOzVO133ewOSY9/lmpqEiRUU2ohEe8T4aSoS7posBW42itUTO4Y5w+eVOnHsm4sRQaI+/AXWTe7GPel+P8Qbe8Ya10A5gnpoag7o3raRDcHx+/qaZw1Af/u4XiAOYz3be3U90Qc+YMc/kS5i8BH0GXBbSfaWQ00CwRFlZQ3n1xUqmjC2CmjZTki3W/p7mEt0DjhcH9ZIXscK603sCC+mF6pEd9019k5fG/8fr2Y4Ptai9kd3BxZJCX9/jSoMfWOBbgkA5bRgHU0xrAj+p49qD6Ej9Xr8GE3+uebz3sEuhSFRnCKwKoOHOemfgevfO2y/jQXP677WPf3xQX7bVDfTFSHU=
+    acl: public_read
+    local-dir: $HOME/src/ljt.nightly/latest/files
+    upload-dir: $TRAVIS_BRANCH/$TRAVIS_OS_NAME
+    on:
+      repo: libjpeg-turbo/libjpeg-turbo
+      branch: dev
+      condition: -n "$BUILD_OFFICIAL"
diff --git a/Android.bp b/Android.bp
new file mode 100644
index 0000000..408ee3c
--- /dev/null
+++ b/Android.bp
@@ -0,0 +1,303 @@
+// Set up common variables for usage across the libjpeg-turbo modules
+
+cc_defaults {
+    name: "libjpeg-defaults",
+    cflags: [
+        "-DWITH_SIMD",
+        "-DNO_GETENV",
+
+        "-O3",
+        "-fstrict-aliasing",
+
+        "-Werror",
+        "-Wno-sign-compare",
+        "-Wno-unused-parameter",
+    ],
+    srcs: [
+        "jaricom.c",
+        "jcapimin.c",
+        "jcapistd.c",
+        "jcarith.c",
+        "jccoefct.c",
+        "jccolor.c",
+        "jcdctmgr.c",
+        "jchuff.c",
+        "jcicc.c",
+        "jcinit.c",
+        "jcmainct.c",
+        "jcmarker.c",
+        "jcmaster.c",
+        "jcomapi.c",
+        "jcparam.c",
+        "jcphuff.c",
+        "jcprepct.c",
+        "jcsample.c",
+        "jctrans.c",
+        "jdapimin.c",
+        "jdapistd.c",
+        "jdarith.c",
+        "jdatadst.c",
+        "jdatasrc.c",
+        "jdcoefct.c",
+        "jdcolor.c",
+        "jddctmgr.c",
+        "jdhuff.c",
+        "jdicc.c",
+        "jdinput.c",
+        "jdmainct.c",
+        "jdmarker.c",
+        "jdmaster.c",
+        "jdmerge.c",
+        "jdphuff.c",
+        "jdpostct.c",
+        "jdsample.c",
+        "jdtrans.c",
+        "jerror.c",
+        "jfdctflt.c",
+        "jfdctfst.c",
+        "jfdctint.c",
+        "jidctflt.c",
+        "jidctfst.c",
+        "jidctint.c",
+        "jidctred.c",
+        "jmemmgr.c",
+        "jmemnobs.c",
+        "jpeg_nbits_table.c",
+        "jquant1.c",
+        "jquant2.c",
+        "jutils.c",
+    ],
+
+    arch: {
+        arm: {
+            // By default, the build system generates ARM target binaries in
+            // thumb mode, where each instruction is 16 bits wide.  Defining
+            // this variable as arm forces the build system to generate object
+            // files in 32-bit arm mode.  This is the same setting previously
+            // used by libjpeg and it provides a small performance benefit.
+            instruction_set: "arm",
+            // ARM v7 NEON
+            srcs: [
+                "simd/arm/aarch32/jchuff-neon.c",
+                "simd/arm/aarch32/jsimd.c",
+                "simd/arm/jccolor-neon.c",
+                "simd/arm/jcgray-neon.c",
+                "simd/arm/jcphuff-neon.c",
+                "simd/arm/jcsample-neon.c",
+                "simd/arm/jdcolor-neon.c",
+                "simd/arm/jdmerge-neon.c",
+                "simd/arm/jdsample-neon.c",
+                "simd/arm/jfdctfst-neon.c",
+                "simd/arm/jfdctint-neon.c",
+                "simd/arm/jidctfst-neon.c",
+                "simd/arm/jidctint-neon.c",
+                "simd/arm/jidctred-neon.c",
+                "simd/arm/jquanti-neon.c",
+            ],
+            cflags: ["-DNEON_INTRINSICS"],
+            local_include_dirs: ["simd/arm"],
+        },
+        arm64: {
+            // ARM v8 64-bit NEON
+            srcs: [
+                "simd/arm/aarch64/jchuff-neon.c",
+                "simd/arm/aarch64/jsimd.c",
+                "simd/arm/jccolor-neon.c",
+                "simd/arm/jcgray-neon.c",
+                "simd/arm/jcphuff-neon.c",
+                "simd/arm/jcsample-neon.c",
+                "simd/arm/jdcolor-neon.c",
+                "simd/arm/jdmerge-neon.c",
+                "simd/arm/jdsample-neon.c",
+                "simd/arm/jfdctfst-neon.c",
+                "simd/arm/jfdctint-neon.c",
+                "simd/arm/jidctfst-neon.c",
+                "simd/arm/jidctint-neon.c",
+                "simd/arm/jidctred-neon.c",
+                "simd/arm/jquanti-neon.c",
+            ],
+            cflags: ["-DNEON_INTRINSICS"],
+            local_include_dirs: ["simd/arm"],
+        },
+        x86: {
+            // x86 MMX and SSE2
+            srcs: [
+                "simd/i386/jccolor-avx2.asm",
+                "simd/i386/jccolor-mmx.asm",
+                "simd/i386/jccolor-sse2.asm",
+                "simd/i386/jcgray-avx2.asm",
+                "simd/i386/jcgray-mmx.asm",
+                "simd/i386/jcgray-sse2.asm",
+                "simd/i386/jchuff-sse2.asm",
+                "simd/i386/jcphuff-sse2.asm",
+                "simd/i386/jcsample-avx2.asm",
+                "simd/i386/jcsample-mmx.asm",
+                "simd/i386/jcsample-sse2.asm",
+                "simd/i386/jdcolor-avx2.asm",
+                "simd/i386/jdcolor-mmx.asm",
+                "simd/i386/jdcolor-sse2.asm",
+                "simd/i386/jdmerge-avx2.asm",
+                "simd/i386/jdmerge-mmx.asm",
+                "simd/i386/jdmerge-sse2.asm",
+                "simd/i386/jdsample-avx2.asm",
+                "simd/i386/jdsample-mmx.asm",
+                "simd/i386/jdsample-sse2.asm",
+                "simd/i386/jfdctflt-3dn.asm",
+                "simd/i386/jfdctflt-sse.asm",
+                "simd/i386/jfdctfst-mmx.asm",
+                "simd/i386/jfdctfst-sse2.asm",
+                "simd/i386/jfdctint-avx2.asm",
+                "simd/i386/jfdctint-mmx.asm",
+                "simd/i386/jfdctint-sse2.asm",
+                "simd/i386/jidctflt-3dn.asm",
+                "simd/i386/jidctflt-sse.asm",
+                "simd/i386/jidctflt-sse2.asm",
+                "simd/i386/jidctfst-mmx.asm",
+                "simd/i386/jidctfst-sse2.asm",
+                "simd/i386/jidctint-avx2.asm",
+                "simd/i386/jidctint-mmx.asm",
+                "simd/i386/jidctint-sse2.asm",
+                "simd/i386/jidctred-mmx.asm",
+                "simd/i386/jidctred-sse2.asm",
+                "simd/i386/jquant-3dn.asm",
+                "simd/i386/jquant-mmx.asm",
+                "simd/i386/jquant-sse.asm",
+                "simd/i386/jquantf-sse2.asm",
+                "simd/i386/jquanti-avx2.asm",
+                "simd/i386/jquanti-sse2.asm",
+                "simd/i386/jsimd.c",
+                "simd/i386/jsimdcpu.asm",
+            ],
+            asflags: [
+                "-DPIC",
+                "-D__x86__",
+            ],
+            local_include_dirs: ["simd/nasm"],
+        },
+        x86_64: {
+            // x86-64 SSE2
+            srcs: [
+                "simd/x86_64/jccolor-avx2.asm",
+                "simd/x86_64/jccolor-sse2.asm",
+                "simd/x86_64/jcgray-avx2.asm",
+                "simd/x86_64/jcgray-sse2.asm",
+                "simd/x86_64/jchuff-sse2.asm",
+                "simd/x86_64/jcphuff-sse2.asm",
+                "simd/x86_64/jcsample-avx2.asm",
+                "simd/x86_64/jcsample-sse2.asm",
+                "simd/x86_64/jdcolor-avx2.asm",
+                "simd/x86_64/jdcolor-sse2.asm",
+                "simd/x86_64/jdmerge-avx2.asm",
+                "simd/x86_64/jdmerge-sse2.asm",
+                "simd/x86_64/jdsample-avx2.asm",
+                "simd/x86_64/jdsample-sse2.asm",
+                "simd/x86_64/jfdctflt-sse.asm",
+                "simd/x86_64/jfdctfst-sse2.asm",
+                "simd/x86_64/jfdctint-avx2.asm",
+                "simd/x86_64/jfdctint-sse2.asm",
+                "simd/x86_64/jidctflt-sse2.asm",
+                "simd/x86_64/jidctfst-sse2.asm",
+                "simd/x86_64/jidctint-avx2.asm",
+                "simd/x86_64/jidctint-sse2.asm",
+                "simd/x86_64/jidctred-sse2.asm",
+                "simd/x86_64/jquantf-sse2.asm",
+                "simd/x86_64/jquanti-avx2.asm",
+                "simd/x86_64/jquanti-sse2.asm",
+                "simd/x86_64/jsimd.c",
+                "simd/x86_64/jsimdcpu.asm",
+            ],
+            asflags: [
+                "-DPIC",
+                "-D__x86_64__",
+            ],
+            local_include_dirs: ["simd/nasm"],
+        },
+    },
+
+    target: {
+        linux: {
+            asflags: [
+                "-DELF",
+            ],
+        },
+        darwin: {
+            asflags: [
+                "-DMACHO",
+            ],
+        },
+        windows_x86: {
+            asflags: [
+                "-DWIN32",
+            ],
+        },
+        windows_x86_64: {
+            asflags: [
+                "-DWIN64",
+            ],
+        },
+    },
+}
+
+// Build as a shared library.
+cc_library {
+    name: "libjpeg",
+    host_supported: true,
+    vendor_available: true,
+    product_available: true,
+    vndk: {
+        enabled: true,
+    },
+    defaults: ["libjpeg-defaults"],
+    export_include_dirs: ["."],
+    target: {
+        windows: {
+            enabled: true,
+        },
+    },
+}
+
+// Build static library against the NDK
+cc_library_static {
+    name: "libjpeg_static_ndk",
+    defaults: ["libjpeg-defaults"],
+    export_include_dirs: ["."],
+    sdk_version: "17",
+}
+
+// Definition for TJBench
+cc_binary {
+    name: "tjbench",
+
+    whole_static_libs: ["libjpeg"],
+
+    multilib: {
+        lib32: {
+            stem: "tj32",
+        },
+        lib64: {
+            stem: "tj64",
+        },
+    },
+
+    compile_multilib: "both",
+
+    cflags: [
+        "-DBMP_SUPPORTED",
+        "-DPPM_SUPPORTED",
+        "-Werror",
+        "-Wno-unused-parameter",
+    ],
+
+    srcs: [
+        "jdatadst-tj.c",
+        "jdatasrc-tj.c",
+        "rdbmp.c",
+        "rdppm.c",
+        "tjbench.c",
+        "tjutil.c",
+        "transupp.c",
+        "turbojpeg.c",
+        "wrbmp.c",
+        "wrppm.c",
+    ],
+}
diff --git a/METADATA b/METADATA
new file mode 100644
index 0000000..6eaebaf
--- /dev/null
+++ b/METADATA
@@ -0,0 +1,15 @@
+name: "libjpeg-turbo"
+description: "libjpeg-turbo is a JPEG image codec."
+third_party {
+  url {
+    type: GIT
+    value: "https://chromium.googlesource.com/chromium/deps/libjpeg_turbo"
+  }
+  version: "09efc26aff7983f4377a1743a197ca3d74796d7d"
+  license_type: NOTICE
+  last_upgrade_date {
+    year: 2020
+    month: 12
+    day: 29
+  }
+}
diff --git a/MODULE_LICENSE_BSD b/MODULE_LICENSE_BSD
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/MODULE_LICENSE_BSD
diff --git a/NOTICE b/NOTICE
new file mode 120000
index 0000000..f0c4298
--- /dev/null
+++ b/NOTICE
@@ -0,0 +1 @@
+LICENSE.md
\ No newline at end of file
diff --git a/OWNERS.android b/OWNERS.android
new file mode 100644
index 0000000..3fbf06e
--- /dev/null
+++ b/OWNERS.android
@@ -0,0 +1,4 @@
+# Upstream maintainer who should review any functional changes:
+scroggo@google.com
+# AOSP maintainers:
+include platform/system/core:/janitors/OWNERS
diff --git a/README.android b/README.android
new file mode 100644
index 0000000..b2003e8
--- /dev/null
+++ b/README.android
@@ -0,0 +1,15 @@
+# Android differences from upstream chromium
+
+Android builds with `C_ARITH_CODING_SUPPORTED` and `D_ARITH_CODING_SUPPORTED`,
+added in
+https://android-review.googlesource.com/c/platform/external/libjpeg-turbo/+/291407/
+to support a variant of jpeg files using arithmetic (instead of Huffman)
+encoding. This variant isn't often used because of a lack of support in many
+viewers (e.g. Chromium), but Android really values backwards compatibility, and
+this might break some users. Android probably only needs to keep
+`D_ARITH_CODING_SUPPORTED`, but vendor code might also be encoding by setting
+jpeg_compress_struct.arith_code to true, so we enable both to ensure full
+backwards compatibility since it's not really costing us anything.
+We `#define` these in jconfig.h rather than in Android.bp so that they're
+correctly exported to any *users* (in particular, jerror.h only conditionally
+defines the corresponding error codes if these `#define`s are present).
diff --git a/TEST_MAPPING b/TEST_MAPPING
new file mode 100644
index 0000000..10bd0ee
--- /dev/null
+++ b/TEST_MAPPING
@@ -0,0 +1,7 @@
+{
+  "presubmit": [
+    {
+      "name": "CtsGraphicsTestCases"
+    }
+  ]
+}
diff --git a/jconfig.h b/jconfig.h
index f63fb52..7d89c0e 100644
--- a/jconfig.h
+++ b/jconfig.h
@@ -10,10 +10,10 @@
 #define LIBJPEG_TURBO_VERSION_NUMBER 2000090
 
 /* Support arithmetic encoding */
-/* #define C_ARITH_CODING_SUPPORTED 1 */
+#define C_ARITH_CODING_SUPPORTED 1
 
 /* Support arithmetic decoding */
-/* #define D_ARITH_CODING_SUPPORTED 1 */
+#define D_ARITH_CODING_SUPPORTED 1
 
 /* Support in-memory source/destination managers */
 #define MEM_SRCDST_SUPPORTED 1
diff --git a/simd/CMakeLists.txt b/simd/CMakeLists.txt
old mode 100644
new mode 100755
diff --git a/tjbenchtest.in b/tjbenchtest.in
old mode 100644
new mode 100755
diff --git a/tjbenchtest.java.in b/tjbenchtest.java.in
old mode 100644
new mode 100755
diff --git a/turbojpeg-mapfile b/turbojpeg-mapfile
old mode 100644
new mode 100755
diff --git a/turbojpeg-mapfile.jni b/turbojpeg-mapfile.jni
old mode 100644
new mode 100755