Add build files for libjpeg-turbo.
This change adds a GYP file, header files, and a README file used for building libjpeg-turbo. (This GYP file builds libjpeg-turbo only on Windows and Mac since Linux uses the system libjpeg.)

BUG=48789
TEST=build libjpeg-turbo on Windows and Mac.
Review URL: http://codereview.chromium.org/4298001

git-svn-id: http://src.chromium.org/svn/trunk/deps/third_party/libjpeg_turbo@66929 4ff67af0-8c30-449e-8e8b-ad334ec8d88c
diff --git a/README.chromium b/README.chromium
new file mode 100644
index 0000000..a0ba717
--- /dev/null
+++ b/README.chromium
@@ -0,0 +1,17 @@
+Name: libjpeg-turbo
+URL: http://sourceforge.net/projects/libjpeg-turbo/
+License File: LICENSE.txt
+
+This consists of three components:
+* A partial copy of libjpeg-turbo-1.0.1;
+* A build file (libjpeg.gyp), and;
+* Patched header files used by Chromium.
+
+This libjpeg-turbo can replace our libjpeg-6b without any modifications in the
+Chromium code.
+
+Same as our copy of libjpeg-6b, this libjpeg-turbo also added a new file
+jpeglibmangler.h and included it from jpeglib.h that changes the names of all
+externally visible functions to chromium_* so that we can avoid conflicts that
+arise when system libraries attempt to use our libjpeg. The 'google.patch' file
+represents our changes from the original libjpeg-turbo-1.0.1.
diff --git a/google.patch b/google.patch
new file mode 100644
index 0000000..4600a11
--- /dev/null
+++ b/google.patch
@@ -0,0 +1,162 @@
+Index: jmorecfg.h
+===================================================================
+--- jmorecfg.h	(revision 64575)
++++ jmorecfg.h	(working copy)
+@@ -159,8 +159,10 @@
+ /* INT32 must hold at least signed 32-bit values. */
+ 
+ #ifndef XMD_H			/* X11/xmd.h correctly defines INT32 */
++#ifndef _BASETSD_H_		/* basetsd.h correctly defines INT32 */
+ typedef long INT32;
+ #endif
++#endif
+ 
+ /* Datatype used for image dimensions.  The JPEG standard only supports
+  * images up to 64K*64K due to 16-bit fields in SOF markers.  Therefore
+@@ -210,11 +212,13 @@
+  * explicit coding is needed; see uses of the NEED_FAR_POINTERS symbol.
+  */
+ 
++#ifndef FAR
+ #ifdef NEED_FAR_POINTERS
+ #define FAR  far
+ #else
+ #define FAR
+ #endif
++#endif
+ 
+ 
+ /*
+Index: jpeglib.h
+===================================================================
+--- jpeglib.h	(revision 64575)
++++ jpeglib.h	(working copy)
+@@ -18,6 +18,10 @@
+ extern "C" {
+ #endif
+ 
++/* Begin chromium edits */
++#include "jpeglibmangler.h"
++/* End chromium edits */
++
+ /*
+  * First we include the configuration files that record how this
+  * installation of the JPEG library is set up.  jconfig.h can be
+Index: jpeglibmangler.h
+===================================================================
+--- jpeglibmangler.h	(revision 0)
++++ jpeglibmangler.h	(revision 0)
+@@ -0,0 +1,113 @@
++// Copyright (c) 2009 The Chromium 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 THIRD_PARTY_LIBJPEG_TURBO_JPEGLIBMANGLER_H_
++#define THIRD_PARTY_LIBJPEG_TURBO_JPEGLIBMANGLER_H_
++
++// Mangle all externally visible function names so we can build our own libjpeg
++// without system libraries trying to use it.
++
++#define jpeg_make_c_derived_tbl chromium_jpeg_make_c_derived_tbl
++#define jpeg_gen_optimal_table chromium_jpeg_gen_optimal_table
++#define jpeg_make_d_derived_tbl chromium_jpeg_make_d_derived_tbl
++#define jpeg_fill_bit_buffer chromium_jpeg_fill_bit_buffer
++#define jpeg_huff_decode chromium_jpeg_huff_decode
++#define jpeg_fdct_islow chromium_jpeg_fdct_islow
++#define jpeg_fdct_ifast chromium_jpeg_fdct_ifast
++#define jpeg_fdct_float chromium_jpeg_fdct_float
++#define jpeg_idct_islow chromium_jpeg_idct_islow
++#define jpeg_idct_ifast chromium_jpeg_idct_ifast
++#define jpeg_idct_float chromium_jpeg_idct_float
++#define jpeg_idct_4x4 chromium_jpeg_idct_4x4
++#define jpeg_idct_2x2 chromium_jpeg_idct_2x2
++#define jpeg_idct_1x1 chromium_jpeg_idct_1x1
++#define jinit_compress_master chromium_jinit_compress_master
++#define jinit_c_master_control chromium_jinit_c_master_control
++#define jinit_c_main_controller chromium_jinit_c_main_controller
++#define jinit_c_prep_controller chromium_jinit_c_prep_controller
++#define jinit_c_coef_controller chromium_jinit_c_coef_controller
++#define jinit_color_converter chromium_jinit_color_converter
++#define jinit_downsampler chromium_jinit_downsampler
++#define jinit_forward_dct chromium_jinit_forward_dct
++#define jinit_huff_encoder chromium_jinit_huff_encoder
++#define jinit_phuff_encoder chromium_jinit_phuff_encoder
++#define jinit_marker_writer chromium_jinit_marker_writer
++#define jinit_master_decompress chromium_jinit_master_decompress
++#define jinit_d_main_controller chromium_jinit_d_main_controller
++#define jinit_d_coef_controller chromium_jinit_d_coef_controller
++#define jinit_d_post_controller chromium_jinit_d_post_controller
++#define jinit_input_controller chromium_jinit_input_controller
++#define jinit_marker_reader chromium_jinit_marker_reader
++#define jinit_huff_decoder chromium_jinit_huff_decoder
++#define jinit_phuff_decoder chromium_jinit_phuff_decoder
++#define jinit_inverse_dct chromium_jinit_inverse_dct
++#define jinit_upsampler chromium_jinit_upsampler
++#define jinit_color_deconverter chromium_jinit_color_deconverter
++#define jinit_1pass_quantizer chromium_jinit_1pass_quantizer
++#define jinit_2pass_quantizer chromium_jinit_2pass_quantizer
++#define jinit_merged_upsampler chromium_jinit_merged_upsampler
++#define jinit_memory_mgr chromium_jinit_memory_mgr
++#define jdiv_round_up chromium_jdiv_round_up
++#define jround_up chromium_jround_up
++#define jcopy_sample_rows chromium_jcopy_sample_rows
++#define jcopy_block_row chromium_jcopy_block_row
++#define jzero_far chromium_jzero_far
++#define jpeg_std_error chromium_jpeg_std_error
++#define jpeg_CreateCompress chromium_jpeg_CreateCompress
++#define jpeg_CreateDecompress chromium_jpeg_CreateDecompress
++#define jpeg_destroy_compress chromium_jpeg_destroy_compress
++#define jpeg_destroy_decompress chromium_jpeg_destroy_decompress
++#define jpeg_stdio_dest chromium_jpeg_stdio_dest
++#define jpeg_stdio_src chromium_jpeg_stdio_src
++#define jpeg_set_defaults chromium_jpeg_set_defaults
++#define jpeg_set_colorspace chromium_jpeg_set_colorspace
++#define jpeg_default_colorspace chromium_jpeg_default_colorspace
++#define jpeg_set_quality chromium_jpeg_set_quality
++#define jpeg_set_linear_quality chromium_jpeg_set_linear_quality
++#define jpeg_add_quant_table chromium_jpeg_add_quant_table
++#define jpeg_quality_scaling chromium_jpeg_quality_scaling
++#define jpeg_simple_progression chromium_jpeg_simple_progression
++#define jpeg_suppress_tables chromium_jpeg_suppress_tables
++#define jpeg_alloc_quant_table chromium_jpeg_alloc_quant_table
++#define jpeg_alloc_huff_table chromium_jpeg_alloc_huff_table
++#define jpeg_start_compress chromium_jpeg_start_compress
++#define jpeg_write_scanlines chromium_jpeg_write_scanlines
++#define jpeg_finish_compress chromium_jpeg_finish_compress
++#define jpeg_write_raw_data chromium_jpeg_write_raw_data
++#define jpeg_write_marker chromium_jpeg_write_marker
++#define jpeg_write_m_header chromium_jpeg_write_m_header
++#define jpeg_write_m_byte chromium_jpeg_write_m_byte
++#define jpeg_write_tables chromium_jpeg_write_tables
++#define jpeg_read_header chromium_jpeg_read_header
++#define jpeg_start_decompress chromium_jpeg_start_decompress
++#define jpeg_read_scanlines chromium_jpeg_read_scanlines
++#define jpeg_finish_decompress chromium_jpeg_finish_decompress
++#define jpeg_read_raw_data chromium_jpeg_read_raw_data
++#define jpeg_has_multiple_scans chromium_jpeg_has_multiple_scans
++#define jpeg_start_output chromium_jpeg_start_output
++#define jpeg_finish_output chromium_jpeg_finish_output
++#define jpeg_input_complete chromium_jpeg_input_complete
++#define jpeg_new_colormap chromium_jpeg_new_colormap
++#define jpeg_consume_input chromium_jpeg_consume_input
++#define jpeg_calc_output_dimensions chromium_jpeg_calc_output_dimensions
++#define jpeg_save_markers chromium_jpeg_save_markers
++#define jpeg_set_marker_processor chromium_jpeg_set_marker_processor
++#define jpeg_read_coefficients chromium_jpeg_read_coefficients
++#define jpeg_write_coefficients chromium_jpeg_write_coefficients
++#define jpeg_copy_critical_parameters chromium_jpeg_copy_critical_parameters
++#define jpeg_abort_compress chromium_jpeg_abort_compress
++#define jpeg_abort_decompress chromium_jpeg_abort_decompress
++#define jpeg_abort chromium_jpeg_abort
++#define jpeg_destroy chromium_jpeg_destroy
++#define jpeg_resync_to_restart chromium_jpeg_resync_to_restart
++#define jpeg_get_small chromium_jpeg_get_small
++#define jpeg_free_small chromium_jpeg_free_small
++#define jpeg_get_large chromium_jpeg_get_large
++#define jpeg_free_large chromium_jpeg_free_large
++#define jpeg_mem_available chromium_jpeg_mem_available
++#define jpeg_open_backing_store chromium_jpeg_open_backing_store
++#define jpeg_mem_init chromium_jpeg_mem_init
++#define jpeg_mem_term chromium_jpeg_mem_term
++
++#endif  // THIRD_PARTY_LIBJPEG_TURBO_JPEGLIBMANGLER_H_
diff --git a/jconfig.h b/jconfig.h
new file mode 100644
index 0000000..e7f0c63
--- /dev/null
+++ b/jconfig.h
@@ -0,0 +1,103 @@
+/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* ***** BEGIN LICENSE BLOCK *****
+ * Version: MPL 1.1/GPL 2.0/LGPL 2.1
+ *
+ * The contents of this file are subject to the Mozilla Public License Version
+ * 1.1 (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+ * for the specific language governing rights and limitations under the
+ * License.
+ *
+ * The Original Code is mozilla.org code.
+ *
+ * The Initial Developer of the Original Code is
+ * Netscape Communications Corporation.
+ * Portions created by the Initial Developer are Copyright (C) 1998
+ * the Initial Developer. All Rights Reserved.
+ *
+ * Contributor(s):
+ *
+ * Alternatively, the contents of this file may be used under the terms of
+ * either the GNU General Public License Version 2 or later (the "GPL"), or
+ * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
+ * in which case the provisions of the GPL or the LGPL are applicable instead
+ * of those above. If you wish to allow use of your version of this file only
+ * under the terms of either the GPL or the LGPL, and not to allow others to
+ * use your version of this file under the terms of the MPL, indicate your
+ * decision by deleting the provisions above and replace them with the notice
+ * and other provisions required by the GPL or the LGPL. If you do not delete
+ * the provisions above, a recipient may use your version of this file under
+ * the terms of any one of the MPL, the GPL or the LGPL.
+ *
+ * ***** END LICENSE BLOCK ***** */
+
+/*
+ * jconfig.h to configure the IJG JPEG library for the Mozilla/Netscape
+ * environment.  Note that there are also Mozilla mods in jmorecfg.h.
+ */
+
+/* We assume an ANSI C or C++ compilation environment */
+#define HAVE_PROTOTYPES 
+#define HAVE_UNSIGNED_CHAR 
+#define HAVE_UNSIGNED_SHORT 
+/* #define void char */
+/* #define const */
+#ifndef HAVE_STDDEF_H 
+#define HAVE_STDDEF_H 
+#endif /* HAVE_STDDEF_H */
+#ifndef HAVE_STDLIB_H
+#define HAVE_STDLIB_H 
+#endif /* HAVE_STDLIB_H */
+#undef NEED_BSD_STRINGS
+#undef NEED_SYS_TYPES_H
+#undef NEED_FAR_POINTERS
+#undef NEED_SHORT_EXTERNAL_NAMES
+/* Define this if you get warnings about undefined structures. */
+#undef INCOMPLETE_TYPES_BROKEN
+
+/* With this setting, the IJG code will work regardless of whether
+ * type "char" is signed or unsigned.
+ */
+#undef CHAR_IS_UNSIGNED
+
+
+/* defines that need not be visible to callers of the IJG library */
+
+#ifdef JPEG_INTERNALS
+
+/* If right shift of "long" quantities is unsigned on your machine,
+ * you'll have to define this.  Fortunately few people should need it.
+ */
+#undef RIGHT_SHIFT_IS_UNSIGNED
+
+#ifdef XP_MAC                   /* Macintosh */
+
+#define ALIGN_TYPE long         /* for sane memory alignment */
+#define NO_GETENV               /* we do have the function, but it's dead */
+
+#endif /* XP_MAC */
+
+#endif /* JPEG_INTERNALS */
+
+
+/* these defines are not interesting for building just the IJG library,
+ * but we leave 'em here anyway.
+ */
+#ifdef JPEG_CJPEG_DJPEG
+
+#define BMP_SUPPORTED		/* BMP image file format */
+#define GIF_SUPPORTED		/* GIF image file format */
+#define PPM_SUPPORTED		/* PBMPLUS PPM/PGM image file format */
+#undef RLE_SUPPORTED		/* Utah RLE image file format */
+#define TARGA_SUPPORTED		/* Targa image file format */
+
+#undef TWO_FILE_COMMANDLINE
+#undef NEED_SIGNAL_CATCHER
+#undef DONT_USE_B_MODE
+#undef PROGRESS_REPORT
+
+#endif /* JPEG_CJPEG_DJPEG */
diff --git a/jmorecfg.h b/jmorecfg.h
index 0e7fb72..bb12f0d 100644
--- a/jmorecfg.h
+++ b/jmorecfg.h
@@ -159,8 +159,10 @@
 /* INT32 must hold at least signed 32-bit values. */
 
 #ifndef XMD_H			/* X11/xmd.h correctly defines INT32 */
+#ifndef _BASETSD_H_		/* basetsd.h correctly defines INT32 */
 typedef long INT32;
 #endif
+#endif
 
 /* Datatype used for image dimensions.  The JPEG standard only supports
  * images up to 64K*64K due to 16-bit fields in SOF markers.  Therefore
@@ -210,11 +212,13 @@
  * explicit coding is needed; see uses of the NEED_FAR_POINTERS symbol.
  */
 
+#ifndef FAR
 #ifdef NEED_FAR_POINTERS
 #define FAR  far
 #else
 #define FAR
 #endif
+#endif
 
 
 /*
diff --git a/jpeglib.h b/jpeglib.h
index 7cc8039..e9768f7 100644
--- a/jpeglib.h
+++ b/jpeglib.h
@@ -18,6 +18,10 @@
 extern "C" {
 #endif
 
+/* Begin chromium edits */
+#include "jpeglibmangler.h"
+/* End chromium edits */
+
 /*
  * First we include the configuration files that record how this
  * installation of the JPEG library is set up.  jconfig.h can be
diff --git a/jpeglibmangler.h b/jpeglibmangler.h
new file mode 100644
index 0000000..aed411a
--- /dev/null
+++ b/jpeglibmangler.h
@@ -0,0 +1,113 @@
+// Copyright (c) 2009 The Chromium 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 THIRD_PARTY_LIBJPEG_TURBO_JPEGLIBMANGLER_H_
+#define THIRD_PARTY_LIBJPEG_TURBO_JPEGLIBMANGLER_H_
+
+// Mangle all externally visible function names so we can build our own libjpeg
+// without system libraries trying to use it.
+
+#define jpeg_make_c_derived_tbl chromium_jpeg_make_c_derived_tbl
+#define jpeg_gen_optimal_table chromium_jpeg_gen_optimal_table
+#define jpeg_make_d_derived_tbl chromium_jpeg_make_d_derived_tbl
+#define jpeg_fill_bit_buffer chromium_jpeg_fill_bit_buffer
+#define jpeg_huff_decode chromium_jpeg_huff_decode
+#define jpeg_fdct_islow chromium_jpeg_fdct_islow
+#define jpeg_fdct_ifast chromium_jpeg_fdct_ifast
+#define jpeg_fdct_float chromium_jpeg_fdct_float
+#define jpeg_idct_islow chromium_jpeg_idct_islow
+#define jpeg_idct_ifast chromium_jpeg_idct_ifast
+#define jpeg_idct_float chromium_jpeg_idct_float
+#define jpeg_idct_4x4 chromium_jpeg_idct_4x4
+#define jpeg_idct_2x2 chromium_jpeg_idct_2x2
+#define jpeg_idct_1x1 chromium_jpeg_idct_1x1
+#define jinit_compress_master chromium_jinit_compress_master
+#define jinit_c_master_control chromium_jinit_c_master_control
+#define jinit_c_main_controller chromium_jinit_c_main_controller
+#define jinit_c_prep_controller chromium_jinit_c_prep_controller
+#define jinit_c_coef_controller chromium_jinit_c_coef_controller
+#define jinit_color_converter chromium_jinit_color_converter
+#define jinit_downsampler chromium_jinit_downsampler
+#define jinit_forward_dct chromium_jinit_forward_dct
+#define jinit_huff_encoder chromium_jinit_huff_encoder
+#define jinit_phuff_encoder chromium_jinit_phuff_encoder
+#define jinit_marker_writer chromium_jinit_marker_writer
+#define jinit_master_decompress chromium_jinit_master_decompress
+#define jinit_d_main_controller chromium_jinit_d_main_controller
+#define jinit_d_coef_controller chromium_jinit_d_coef_controller
+#define jinit_d_post_controller chromium_jinit_d_post_controller
+#define jinit_input_controller chromium_jinit_input_controller
+#define jinit_marker_reader chromium_jinit_marker_reader
+#define jinit_huff_decoder chromium_jinit_huff_decoder
+#define jinit_phuff_decoder chromium_jinit_phuff_decoder
+#define jinit_inverse_dct chromium_jinit_inverse_dct
+#define jinit_upsampler chromium_jinit_upsampler
+#define jinit_color_deconverter chromium_jinit_color_deconverter
+#define jinit_1pass_quantizer chromium_jinit_1pass_quantizer
+#define jinit_2pass_quantizer chromium_jinit_2pass_quantizer
+#define jinit_merged_upsampler chromium_jinit_merged_upsampler
+#define jinit_memory_mgr chromium_jinit_memory_mgr
+#define jdiv_round_up chromium_jdiv_round_up
+#define jround_up chromium_jround_up
+#define jcopy_sample_rows chromium_jcopy_sample_rows
+#define jcopy_block_row chromium_jcopy_block_row
+#define jzero_far chromium_jzero_far
+#define jpeg_std_error chromium_jpeg_std_error
+#define jpeg_CreateCompress chromium_jpeg_CreateCompress
+#define jpeg_CreateDecompress chromium_jpeg_CreateDecompress
+#define jpeg_destroy_compress chromium_jpeg_destroy_compress
+#define jpeg_destroy_decompress chromium_jpeg_destroy_decompress
+#define jpeg_stdio_dest chromium_jpeg_stdio_dest
+#define jpeg_stdio_src chromium_jpeg_stdio_src
+#define jpeg_set_defaults chromium_jpeg_set_defaults
+#define jpeg_set_colorspace chromium_jpeg_set_colorspace
+#define jpeg_default_colorspace chromium_jpeg_default_colorspace
+#define jpeg_set_quality chromium_jpeg_set_quality
+#define jpeg_set_linear_quality chromium_jpeg_set_linear_quality
+#define jpeg_add_quant_table chromium_jpeg_add_quant_table
+#define jpeg_quality_scaling chromium_jpeg_quality_scaling
+#define jpeg_simple_progression chromium_jpeg_simple_progression
+#define jpeg_suppress_tables chromium_jpeg_suppress_tables
+#define jpeg_alloc_quant_table chromium_jpeg_alloc_quant_table
+#define jpeg_alloc_huff_table chromium_jpeg_alloc_huff_table
+#define jpeg_start_compress chromium_jpeg_start_compress
+#define jpeg_write_scanlines chromium_jpeg_write_scanlines
+#define jpeg_finish_compress chromium_jpeg_finish_compress
+#define jpeg_write_raw_data chromium_jpeg_write_raw_data
+#define jpeg_write_marker chromium_jpeg_write_marker
+#define jpeg_write_m_header chromium_jpeg_write_m_header
+#define jpeg_write_m_byte chromium_jpeg_write_m_byte
+#define jpeg_write_tables chromium_jpeg_write_tables
+#define jpeg_read_header chromium_jpeg_read_header
+#define jpeg_start_decompress chromium_jpeg_start_decompress
+#define jpeg_read_scanlines chromium_jpeg_read_scanlines
+#define jpeg_finish_decompress chromium_jpeg_finish_decompress
+#define jpeg_read_raw_data chromium_jpeg_read_raw_data
+#define jpeg_has_multiple_scans chromium_jpeg_has_multiple_scans
+#define jpeg_start_output chromium_jpeg_start_output
+#define jpeg_finish_output chromium_jpeg_finish_output
+#define jpeg_input_complete chromium_jpeg_input_complete
+#define jpeg_new_colormap chromium_jpeg_new_colormap
+#define jpeg_consume_input chromium_jpeg_consume_input
+#define jpeg_calc_output_dimensions chromium_jpeg_calc_output_dimensions
+#define jpeg_save_markers chromium_jpeg_save_markers
+#define jpeg_set_marker_processor chromium_jpeg_set_marker_processor
+#define jpeg_read_coefficients chromium_jpeg_read_coefficients
+#define jpeg_write_coefficients chromium_jpeg_write_coefficients
+#define jpeg_copy_critical_parameters chromium_jpeg_copy_critical_parameters
+#define jpeg_abort_compress chromium_jpeg_abort_compress
+#define jpeg_abort_decompress chromium_jpeg_abort_decompress
+#define jpeg_abort chromium_jpeg_abort
+#define jpeg_destroy chromium_jpeg_destroy
+#define jpeg_resync_to_restart chromium_jpeg_resync_to_restart
+#define jpeg_get_small chromium_jpeg_get_small
+#define jpeg_free_small chromium_jpeg_free_small
+#define jpeg_get_large chromium_jpeg_get_large
+#define jpeg_free_large chromium_jpeg_free_large
+#define jpeg_mem_available chromium_jpeg_mem_available
+#define jpeg_open_backing_store chromium_jpeg_open_backing_store
+#define jpeg_mem_init chromium_jpeg_mem_init
+#define jpeg_mem_term chromium_jpeg_mem_term
+
+#endif  // THIRD_PARTY_LIBJPEG_TURBO_JPEGLIBMANGLER_H_
diff --git a/libjpeg.gyp b/libjpeg.gyp
new file mode 100644
index 0000000..b5c06a4
--- /dev/null
+++ b/libjpeg.gyp
@@ -0,0 +1,356 @@
+# Copyright (c) 2010 The Chromium Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+{
+  'variables': {
+    'conditions': [
+      [ 'OS=="linux" or OS=="freebsd" or OS=="openbsd"', {
+        # Link to system .so since we already use it due to GTK.
+        'use_system_libjpeg%': 1,
+      }, {  # OS!="linux" and OS!="freebsd" and OS!="openbsd"
+        'use_system_libjpeg%': 0,
+      }],
+      [ 'OS=="win"', {
+        'object_suffix': 'obj',
+      }, {
+        'object_suffix': 'o',
+      }],
+      [ 'OS=="linux" or OS=="freebsd" or OS=="openbsd"', {
+        # This is a workaround for GYP issue 102.
+        # TODO(hbono): Delete this workaround when this issue is fixed.
+        'shared_generated_dir': '<(INTERMEDIATE_DIR)/third_party/libjpeg_turbo',
+      }, {
+        'shared_generated_dir': '<(SHARED_INTERMEDIATE_DIR)/third_party/libjpeg_turbo',
+      }],
+    ],
+  },
+  'conditions': [
+    [ 'use_system_libjpeg==0', {
+      'targets': [
+        {
+          'target_name': 'libjpeg',
+          'type': '<(library)',
+          'include_dirs': [
+            '.',
+          ],
+          'defines': [
+            'WITH_SIMD',
+          ],
+          'dependencies': [
+            'libjpeg_asm',
+          ],
+          'sources': [
+            'jconfig.h',
+            'jpeglib.h',
+            'jpeglibmangler.h',
+            'jcapimin.c',
+            'jcapistd.c',
+            'jccoefct.c',
+            'jccolor.c',
+            'jcdctmgr.c',
+            'jchuff.c',
+            'jchuff.h',
+            'jcinit.c',
+            'jcmainct.c',
+            'jcmarker.c',
+            'jcmaster.c',
+            'jcomapi.c',
+            'jcparam.c',
+            'jcphuff.c',
+            'jcprepct.c',
+            'jcsample.c',
+            'jdapimin.c',
+            'jdapistd.c',
+            'jdatadst.c',
+            'jdatasrc.c',
+            'jdcoefct.c',
+            'jdcolor.c',
+            'jdct.h',
+            'jddctmgr.c',
+            'jdhuff.c',
+            'jdhuff.h',
+            'jdinput.c',
+            'jdmainct.c',
+            'jdmarker.c',
+            'jdmaster.c',
+            'jdmerge.c',
+            'jdphuff.c',
+            'jdpostct.c',
+            'jdsample.c',
+            'jerror.c',
+            'jerror.h',
+            'jfdctflt.c',
+            'jfdctfst.c',
+            'jfdctint.c',
+            'jidctflt.c',
+            'jidctfst.c',
+            'jidctint.c',
+            'jidctred.c',
+            'jinclude.h',
+            'jmemmgr.c',
+            'jmemnobs.c',
+            'jmemsys.h',
+            'jmorecfg.h',
+            'jpegint.h',
+            'jquant1.c',
+            'jquant2.c',
+            'jutils.c',
+            'jversion.h',
+          ],
+          'direct_dependent_settings': {
+            'include_dirs': [
+              '.',
+            ],
+          },
+          'conditions': [
+            [ 'OS!="win"', {'product_name': 'jpeg_turbo'}],
+            # Add target-specific source files.
+            [ 'target_arch=="ia32"', {
+              'sources': [
+                'simd/jsimd_i386.c',
+                # Object files assembled by the 'libjpeg_asm' project.
+                '<(shared_generated_dir)/jsimdcpu.<(object_suffix)',
+                '<(shared_generated_dir)/jccolmmx.<(object_suffix)',
+                '<(shared_generated_dir)/jdcolmmx.<(object_suffix)',
+                '<(shared_generated_dir)/jcsammmx.<(object_suffix)',
+                '<(shared_generated_dir)/jdsammmx.<(object_suffix)',
+                '<(shared_generated_dir)/jdmermmx.<(object_suffix)',
+                '<(shared_generated_dir)/jcqntmmx.<(object_suffix)',
+                '<(shared_generated_dir)/jfmmxfst.<(object_suffix)',
+                '<(shared_generated_dir)/jfmmxint.<(object_suffix)',
+                '<(shared_generated_dir)/jimmxred.<(object_suffix)',
+                '<(shared_generated_dir)/jimmxint.<(object_suffix)',
+                '<(shared_generated_dir)/jimmxfst.<(object_suffix)',
+                '<(shared_generated_dir)/jcqnt3dn.<(object_suffix)',
+                '<(shared_generated_dir)/jf3dnflt.<(object_suffix)',
+                '<(shared_generated_dir)/ji3dnflt.<(object_suffix)',
+                '<(shared_generated_dir)/jcqntsse.<(object_suffix)',
+                '<(shared_generated_dir)/jfsseflt.<(object_suffix)',
+                '<(shared_generated_dir)/jisseflt.<(object_suffix)',
+                '<(shared_generated_dir)/jccolss2.<(object_suffix)',
+                '<(shared_generated_dir)/jdcolss2.<(object_suffix)',
+                '<(shared_generated_dir)/jcsamss2.<(object_suffix)',
+                '<(shared_generated_dir)/jdsamss2.<(object_suffix)',
+                '<(shared_generated_dir)/jdmerss2.<(object_suffix)',
+                '<(shared_generated_dir)/jcqnts2i.<(object_suffix)',
+                '<(shared_generated_dir)/jfss2fst.<(object_suffix)',
+                '<(shared_generated_dir)/jfss2int.<(object_suffix)',
+                '<(shared_generated_dir)/jiss2red.<(object_suffix)',
+                '<(shared_generated_dir)/jiss2int.<(object_suffix)',
+                '<(shared_generated_dir)/jiss2fst.<(object_suffix)',
+                '<(shared_generated_dir)/jcqnts2f.<(object_suffix)',
+                '<(shared_generated_dir)/jiss2flt.<(object_suffix)',
+              ],
+            }],
+            [ 'target_arch=="x64"', {
+              'sources': [
+                'simd/jsimd_x86_64.c',
+                # Object files assembled by the 'libjpeg_asm' project.
+                '<(shared_generated_dir)/jfsseflt-64.<(object_suffix)',
+                '<(shared_generated_dir)/jccolss2-64.<(object_suffix)',
+                '<(shared_generated_dir)/jdcolss2-64.<(object_suffix)',
+                '<(shared_generated_dir)/jcsamss2-64.<(object_suffix)',
+                '<(shared_generated_dir)/jdsamss2-64.<(object_suffix)',
+                '<(shared_generated_dir)/jdmerss2-64.<(object_suffix)',
+                '<(shared_generated_dir)/jcqnts2i-64.<(object_suffix)',
+                '<(shared_generated_dir)/jfss2fst-64.<(object_suffix)',
+                '<(shared_generated_dir)/jfss2int-64.<(object_suffix)',
+                '<(shared_generated_dir)/jiss2red-64.<(object_suffix)',
+                '<(shared_generated_dir)/jiss2int-64.<(object_suffix)',
+                '<(shared_generated_dir)/jiss2fst-64.<(object_suffix)',
+                '<(shared_generated_dir)/jcqnts2f-64.<(object_suffix)',
+                '<(shared_generated_dir)/jiss2flt-64.<(object_suffix)',
+              ],
+            }],
+          ],
+        },
+        {
+          # A project that assembles asm files and creates object files.
+          'target_name': 'libjpeg_asm',
+          'type': 'none',
+          'conditions': [
+            # Add platform-dependent source files.
+            [ 'target_arch=="ia32"', {
+              'sources': [
+                # The asm files for ia32.
+                'simd/jsimdcpu.asm',
+                'simd/jccolmmx.asm',
+                'simd/jdcolmmx.asm',
+                'simd/jcsammmx.asm',
+                'simd/jdsammmx.asm',
+                'simd/jdmermmx.asm',
+                'simd/jcqntmmx.asm',
+                'simd/jfmmxfst.asm',
+                'simd/jfmmxint.asm',
+                'simd/jimmxred.asm',
+                'simd/jimmxint.asm',
+                'simd/jimmxfst.asm',
+                'simd/jcqnt3dn.asm',
+                'simd/jf3dnflt.asm',
+                'simd/ji3dnflt.asm',
+                'simd/jcqntsse.asm',
+                'simd/jfsseflt.asm',
+                'simd/jisseflt.asm',
+                'simd/jccolss2.asm',
+                'simd/jdcolss2.asm',
+                'simd/jcsamss2.asm',
+                'simd/jdsamss2.asm',
+                'simd/jdmerss2.asm',
+                'simd/jcqnts2i.asm',
+                'simd/jfss2fst.asm',
+                'simd/jfss2int.asm',
+                'simd/jiss2red.asm',
+                'simd/jiss2int.asm',
+                'simd/jiss2fst.asm',
+                'simd/jcqnts2f.asm',
+                'simd/jiss2flt.asm',
+              ],
+            }],
+            [ 'target_arch=="x64"', {
+              'sources': [
+                # The asm files for x64.
+                'simd/jfsseflt-64.asm',
+                'simd/jccolss2-64.asm',
+                'simd/jdcolss2-64.asm',
+                'simd/jcsamss2-64.asm',
+                'simd/jdsamss2-64.asm',
+                'simd/jdmerss2-64.asm',
+                'simd/jcqnts2i-64.asm',
+                'simd/jfss2fst-64.asm',
+                'simd/jfss2int-64.asm',
+                'simd/jiss2red-64.asm',
+                'simd/jiss2int-64.asm',
+                'simd/jiss2fst-64.asm',
+                'simd/jcqnts2f-64.asm',
+                'simd/jiss2flt-64.asm',
+              ],
+            }],
+
+            # Build rules for an asm file.
+            # On Windows, we use the precompiled yasm binary. On Linux and Mac,
+            # we build yasm and use it as ffmpeg does.
+            [ 'OS=="win"', {
+              'variables': {
+                'yasm_path': '../yasm/binaries/win/yasm<(EXECUTABLE_SUFFIX)',
+              },
+              'rules': [
+                {
+                  'rule_name': 'assemble',
+                  'extension': 'asm',
+                  'inputs': [ '<(yasm_path)', ],
+                  'outputs': [
+                    '<(shared_generated_dir)/<(RULE_INPUT_ROOT).<(object_suffix)',
+                  ],
+                  'action': [
+                    '<(yasm_path)',
+                    '-fwin32',
+                    '-DWIN32',
+                    '-DMSVC',
+                    '-Iwin/',
+                    '-Isimd/',
+                    '-o', '<(shared_generated_dir)/<(RULE_INPUT_ROOT).<(object_suffix)',
+                    '<(RULE_INPUT_PATH)',
+                  ],
+                  'process_outputs_as_sources': 0,
+                  'message': 'Building <(RULE_INPUT_ROOT).<(object_suffix)',
+                },
+              ],
+            }],
+            [ 'OS=="mac"', {
+              'dependencies': [
+                '../yasm/yasm.gyp:yasm#host',
+              ],
+              'variables': {
+                'yasm_path': '<(PRODUCT_DIR)/yasm',
+              },
+              'rules': [
+                {
+                  'rule_name': 'assemble',
+                  'extension': 'asm',
+                  'inputs': [ '<(yasm_path)', ],
+                  'outputs': [
+                    '<(shared_generated_dir)/<(RULE_INPUT_ROOT).<(object_suffix)',
+                  ],
+                  'action': [
+                    '<(yasm_path)',
+                    '-fmacho',
+                    '-DMACHO',
+                    '-Imac/',
+                    '-Isimd/',
+                    '-o', '<(shared_generated_dir)/<(RULE_INPUT_ROOT).<(object_suffix)',
+                    '<(RULE_INPUT_PATH)',
+                  ],
+                  'process_outputs_as_sources': 0,
+                  'message': 'Building <(RULE_INPUT_ROOT).<(object_suffix)',
+                },
+              ],
+            }],
+            [ 'OS=="linux"', {
+              'dependencies': [
+                '../yasm/yasm.gyp:yasm#host',
+              ],
+              'variables': {
+                'yasm_path': '<(PRODUCT_DIR)/yasm',
+                'conditions': [
+                  [ 'target_arch=="ia32"', {
+                    'yasm_format': '-felf',
+                    'yasm_flag': '-D__X86__',
+                  }, {
+                    'yasm_format': '-felf64',
+                    'yasm_flag': '-D__x86_64__',
+                  }],
+                ],
+              },
+              'rules': [
+                {
+                  'rule_name': 'assemble',
+                  'extension': 'asm',
+                  'inputs': [ '<(yasm_path)', ],
+                  'outputs': [
+                    '<(shared_generated_dir)/<(RULE_INPUT_ROOT).<(object_suffix)',
+                  ],
+                  'action': [
+                    '<(yasm_path)',
+                    '<(yasm_format)',
+                    '-DELF',
+                    '<(yasm_flag)',
+                    '-Ilinux/',
+                    '-Isimd/',
+                    '-o', '<(shared_generated_dir)/<(RULE_INPUT_ROOT).<(object_suffix)',
+                    '<(RULE_INPUT_PATH)',
+                  ],
+                  'process_outputs_as_sources': 0,
+                  'message': 'Building <(RULE_INPUT_ROOT).<(object_suffix)',
+                },
+              ],
+            }],
+          ],
+        },
+      ],
+    }, { # else: use_system_libjpeg != 0
+      'targets': [
+        {
+          'target_name': 'libjpeg',
+          'type': 'settings',
+          'direct_dependent_settings': {
+            'defines': [
+              'USE_SYSTEM_LIBJPEG',
+            ],
+          },
+          'link_settings': {
+            'libraries': [
+              '-ljpeg',
+            ],
+          },
+        },
+      ],
+    }],
+  ],
+}
+
+# Local Variables:
+# tab-width:2
+# indent-tabs-mode:nil
+# End:
+# vim: set expandtab tabstop=2 shiftwidth=2:
diff --git a/linux/jsimdcfg.inc b/linux/jsimdcfg.inc
new file mode 100644
index 0000000..68e22e8
--- /dev/null
+++ b/linux/jsimdcfg.inc
@@ -0,0 +1,69 @@
+;
+; Automatically generated include file from jsimdcfg.inc.h
+;
+;
+; -- jpeglib.h
+;
+%define DCTSIZE 8
+%define DCTSIZE2 64
+;
+; -- jmorecfg.h
+;
+%define RGB_RED 0
+%define RGB_GREEN 1
+%define RGB_BLUE 2
+%define RGB_PIXELSIZE 3
+; Representation of a single sample (pixel element value).
+; On this SIMD implementation, this must be 'unsigned char'.
+;
+%define JSAMPLE byte ; unsigned char
+%define SIZEOF_JSAMPLE SIZEOF_BYTE ; sizeof(JSAMPLE)
+%define CENTERJSAMPLE 128
+; Representation of a DCT frequency coefficient.
+; On this SIMD implementation, this must be 'short'.
+;
+%define JCOEF word ; short
+%define SIZEOF_JCOEF SIZEOF_WORD ; sizeof(JCOEF)
+; Datatype used for image dimensions.
+; On this SIMD implementation, this must be 'unsigned int'.
+;
+%define JDIMENSION dword ; unsigned int
+%define SIZEOF_JDIMENSION SIZEOF_DWORD ; sizeof(JDIMENSION)
+%define JSAMPROW POINTER ; JSAMPLE * (jpeglib.h)
+%define JSAMPARRAY POINTER ; JSAMPROW * (jpeglib.h)
+%define JSAMPIMAGE POINTER ; JSAMPARRAY * (jpeglib.h)
+%define JCOEFPTR POINTER ; JCOEF * (jpeglib.h)
+%define SIZEOF_JSAMPROW SIZEOF_POINTER ; sizeof(JSAMPROW)
+%define SIZEOF_JSAMPARRAY SIZEOF_POINTER ; sizeof(JSAMPARRAY)
+%define SIZEOF_JSAMPIMAGE SIZEOF_POINTER ; sizeof(JSAMPIMAGE)
+%define SIZEOF_JCOEFPTR SIZEOF_POINTER ; sizeof(JCOEFPTR)
+;
+; -- jdct.h
+;
+; A forward DCT routine is given a pointer to a work area of type DCTELEM[];
+; the DCT is to be performed in-place in that buffer.
+; To maximize parallelism, Type DCTELEM is changed to short (originally, int).
+;
+%define DCTELEM word ; short
+%define SIZEOF_DCTELEM SIZEOF_WORD ; sizeof(DCTELEM)
+%define float FP32 ; float
+%define SIZEOF_FAST_FLOAT SIZEOF_FP32 ; sizeof(float)
+; To maximize parallelism, Type short is changed to short.
+;
+%define ISLOW_MULT_TYPE word ; must be short
+%define SIZEOF_ISLOW_MULT_TYPE SIZEOF_WORD ; sizeof(ISLOW_MULT_TYPE)
+%define IFAST_MULT_TYPE word ; must be short
+%define SIZEOF_IFAST_MULT_TYPE SIZEOF_WORD ; sizeof(IFAST_MULT_TYPE)
+%define IFAST_SCALE_BITS 2 ; fractional bits in scale factors
+%define FLOAT_MULT_TYPE FP32 ; must be float
+%define SIZEOF_FLOAT_MULT_TYPE SIZEOF_FP32 ; sizeof(FLOAT_MULT_TYPE)
+;
+; -- jsimd.h
+;
+%define JSIMD_NONE 0x00
+%define JSIMD_MMX 0x01
+%define JSIMD_3DNOW 0x02
+%define JSIMD_SSE 0x04
+%define JSIMD_SSE2 0x08
+; Short forms of external names for systems with brain-damaged linkers.
+;
diff --git a/mac/jsimdcfg.inc b/mac/jsimdcfg.inc
new file mode 100644
index 0000000..68e22e8
--- /dev/null
+++ b/mac/jsimdcfg.inc
@@ -0,0 +1,69 @@
+;
+; Automatically generated include file from jsimdcfg.inc.h
+;
+;
+; -- jpeglib.h
+;
+%define DCTSIZE 8
+%define DCTSIZE2 64
+;
+; -- jmorecfg.h
+;
+%define RGB_RED 0
+%define RGB_GREEN 1
+%define RGB_BLUE 2
+%define RGB_PIXELSIZE 3
+; Representation of a single sample (pixel element value).
+; On this SIMD implementation, this must be 'unsigned char'.
+;
+%define JSAMPLE byte ; unsigned char
+%define SIZEOF_JSAMPLE SIZEOF_BYTE ; sizeof(JSAMPLE)
+%define CENTERJSAMPLE 128
+; Representation of a DCT frequency coefficient.
+; On this SIMD implementation, this must be 'short'.
+;
+%define JCOEF word ; short
+%define SIZEOF_JCOEF SIZEOF_WORD ; sizeof(JCOEF)
+; Datatype used for image dimensions.
+; On this SIMD implementation, this must be 'unsigned int'.
+;
+%define JDIMENSION dword ; unsigned int
+%define SIZEOF_JDIMENSION SIZEOF_DWORD ; sizeof(JDIMENSION)
+%define JSAMPROW POINTER ; JSAMPLE * (jpeglib.h)
+%define JSAMPARRAY POINTER ; JSAMPROW * (jpeglib.h)
+%define JSAMPIMAGE POINTER ; JSAMPARRAY * (jpeglib.h)
+%define JCOEFPTR POINTER ; JCOEF * (jpeglib.h)
+%define SIZEOF_JSAMPROW SIZEOF_POINTER ; sizeof(JSAMPROW)
+%define SIZEOF_JSAMPARRAY SIZEOF_POINTER ; sizeof(JSAMPARRAY)
+%define SIZEOF_JSAMPIMAGE SIZEOF_POINTER ; sizeof(JSAMPIMAGE)
+%define SIZEOF_JCOEFPTR SIZEOF_POINTER ; sizeof(JCOEFPTR)
+;
+; -- jdct.h
+;
+; A forward DCT routine is given a pointer to a work area of type DCTELEM[];
+; the DCT is to be performed in-place in that buffer.
+; To maximize parallelism, Type DCTELEM is changed to short (originally, int).
+;
+%define DCTELEM word ; short
+%define SIZEOF_DCTELEM SIZEOF_WORD ; sizeof(DCTELEM)
+%define float FP32 ; float
+%define SIZEOF_FAST_FLOAT SIZEOF_FP32 ; sizeof(float)
+; To maximize parallelism, Type short is changed to short.
+;
+%define ISLOW_MULT_TYPE word ; must be short
+%define SIZEOF_ISLOW_MULT_TYPE SIZEOF_WORD ; sizeof(ISLOW_MULT_TYPE)
+%define IFAST_MULT_TYPE word ; must be short
+%define SIZEOF_IFAST_MULT_TYPE SIZEOF_WORD ; sizeof(IFAST_MULT_TYPE)
+%define IFAST_SCALE_BITS 2 ; fractional bits in scale factors
+%define FLOAT_MULT_TYPE FP32 ; must be float
+%define SIZEOF_FLOAT_MULT_TYPE SIZEOF_FP32 ; sizeof(FLOAT_MULT_TYPE)
+;
+; -- jsimd.h
+;
+%define JSIMD_NONE 0x00
+%define JSIMD_MMX 0x01
+%define JSIMD_3DNOW 0x02
+%define JSIMD_SSE 0x04
+%define JSIMD_SSE2 0x08
+; Short forms of external names for systems with brain-damaged linkers.
+;