From bc3f20e378b545e0dd6052285779342798280699 Mon Sep 17 00:00:00 2001 From: Roy Tam Date: Fri, 22 Feb 2019 21:51:15 +0800 Subject: [PATCH] libjpeg: update to libjpeg-turbo/libjpeg-turbo@0dd9a2c --- media/libjpeg/jcdctmgr.c | 2 +- media/libjpeg/jdapistd.c | 33 +++++++++++++++++++---- media/libjpeg/jdarith.c | 11 +++++--- media/libjpeg/jdcolor.c | 2 +- media/libjpeg/jdmerge.c | 2 +- media/libjpeg/jdmrg565.c | 18 ++++++------- media/libjpeg/jmemmgr.c | 4 ++- media/libjpeg/jmemnobs.c | 16 +++++++---- media/libjpeg/jversion.h | 6 ++--- media/libjpeg/simd/jchuff-sse2-64.asm | 16 +++++------ media/libjpeg/simd/jchuff-sse2.asm | 12 ++++----- media/libjpeg/simd/jsimd_arm.c | 1 + media/libjpeg/simd/jsimd_arm64.c | 1 + media/libjpeg/simd/jsimd_mips.c | 2 ++ media/libjpeg/simd/jsimd_mips_dspr2.S | 1 - media/libjpeg/simd/jsimd_mips_dspr2_asm.h | 2 -- media/libjpeg/simd/jsimd_powerpc.c | 24 +++++++++++++++++ 17 files changed, 106 insertions(+), 47 deletions(-) diff --git a/media/libjpeg/jcdctmgr.c b/media/libjpeg/jcdctmgr.c index aef8517f9c..6e3b19bcb3 100644 --- a/media/libjpeg/jcdctmgr.c +++ b/media/libjpeg/jcdctmgr.c @@ -216,7 +216,7 @@ compute_reciprocal (UINT16 divisor, DCTELEM *dtbl) #endif dtbl[DCTSIZE2 * 3] = (DCTELEM) r - sizeof(DCTELEM)*8; /* shift */ - if(r <= 16) return 0; + if (r <= 16) return 0; else return 1; } diff --git a/media/libjpeg/jdapistd.c b/media/libjpeg/jdapistd.c index 37afc8448b..105121df2b 100644 --- a/media/libjpeg/jdapistd.c +++ b/media/libjpeg/jdapistd.c @@ -4,7 +4,7 @@ * This file was part of the Independent JPEG Group's software: * Copyright (C) 1994-1996, Thomas G. Lane. * libjpeg-turbo Modifications: - * Copyright (C) 2010, 2015-2016, D. R. Commander. + * Copyright (C) 2010, 2015-2017, D. R. Commander. * Copyright (C) 2015, Google, Inc. * For conditions of distribution and use, see the accompanying README.ijg * file. @@ -190,7 +190,10 @@ jpeg_crop_scanline (j_decompress_ptr cinfo, JDIMENSION *xoffset, * single-pass decompression case, allowing us to use the same MCU column * width for all of the components. */ - align = cinfo->_min_DCT_scaled_size * cinfo->max_h_samp_factor; + if (cinfo->comps_in_scan == 1 && cinfo->num_components == 1) + align = cinfo->_min_DCT_scaled_size; + else + align = cinfo->_min_DCT_scaled_size * cinfo->max_h_samp_factor; /* Adjust xoffset to the nearest iMCU boundary <= the requested value */ input_xoffset = *xoffset; @@ -215,6 +218,9 @@ jpeg_crop_scanline (j_decompress_ptr cinfo, JDIMENSION *xoffset, for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components; ci++, compptr++) { + int hsf = (cinfo->comps_in_scan == 1 && cinfo->num_components == 1) ? + 1 : compptr->h_samp_factor; + /* Set downsampled_width to the new output width. */ orig_downsampled_width = compptr->downsampled_width; compptr->downsampled_width = @@ -228,11 +234,10 @@ jpeg_crop_scanline (j_decompress_ptr cinfo, JDIMENSION *xoffset, * values will be used in multi-scan decompressions. */ cinfo->master->first_MCU_col[ci] = - (JDIMENSION) (long) (*xoffset * compptr->h_samp_factor) / - (long) align; + (JDIMENSION) (long) (*xoffset * hsf) / (long) align; cinfo->master->last_MCU_col[ci] = (JDIMENSION) jdiv_round_up((long) ((*xoffset + cinfo->output_width) * - compptr->h_samp_factor), + hsf), (long) align) - 1; } @@ -293,6 +298,14 @@ noop_convert (j_decompress_ptr cinfo, JSAMPIMAGE input_buf, } +/* Dummy quantize function used by jpeg_skip_scanlines() */ +LOCAL(void) +noop_quantize (j_decompress_ptr cinfo, JSAMPARRAY input_buf, + JSAMPARRAY output_buf, int num_rows) +{ +} + + /* * In some cases, it is best to call jpeg_read_scanlines() and discard the * output, rather than skipping the scanlines, because this allows us to @@ -308,14 +321,22 @@ read_and_discard_scanlines (j_decompress_ptr cinfo, JDIMENSION num_lines) void (*color_convert) (j_decompress_ptr cinfo, JSAMPIMAGE input_buf, JDIMENSION input_row, JSAMPARRAY output_buf, int num_rows); + void (*color_quantize) (j_decompress_ptr cinfo, JSAMPARRAY input_buf, + JSAMPARRAY output_buf, int num_rows) = NULL; color_convert = cinfo->cconvert->color_convert; cinfo->cconvert->color_convert = noop_convert; + if (cinfo->cquantize && cinfo->cquantize->color_quantize) { + color_quantize = cinfo->cquantize->color_quantize; + cinfo->cquantize->color_quantize = noop_quantize; + } for (n = 0; n < num_lines; n++) jpeg_read_scanlines(cinfo, NULL, 1); cinfo->cconvert->color_convert = color_convert; + if (color_quantize) + cinfo->cquantize->color_quantize = color_quantize; } @@ -370,6 +391,8 @@ jpeg_skip_scanlines (j_decompress_ptr cinfo, JDIMENSION num_lines) /* Do not skip past the bottom of the image. */ if (cinfo->output_scanline + num_lines >= cinfo->output_height) { cinfo->output_scanline = cinfo->output_height; + (*cinfo->inputctl->finish_input_pass) (cinfo); + cinfo->inputctl->eoi_reached = TRUE; return cinfo->output_height - cinfo->output_scanline; } diff --git a/media/libjpeg/jdarith.c b/media/libjpeg/jdarith.c index df3540eef5..0f560f65a2 100644 --- a/media/libjpeg/jdarith.c +++ b/media/libjpeg/jdarith.c @@ -4,7 +4,7 @@ * This file was part of the Independent JPEG Group's software: * Developed 1997-2015 by Guido Vollbeding. * libjpeg-turbo Modifications: - * Copyright (C) 2015-2016, D. R. Commander. + * Copyright (C) 2015-2017, D. R. Commander. * For conditions of distribution and use, see the accompanying README.ijg * file. * @@ -21,6 +21,9 @@ #include "jpeglib.h" +#define NEG_1 ((unsigned int)-1) + + /* Expanded entropy decoder object for arithmetic decoding. */ typedef struct { @@ -303,7 +306,7 @@ decode_mcu_DC_first (j_decompress_ptr cinfo, JBLOCKROW *MCU_data) while (m >>= 1) if (arith_decode(cinfo, st)) v |= m; v += 1; if (sign) v = -v; - entropy->last_dc_val[ci] += v; + entropy->last_dc_val[ci] = (entropy->last_dc_val[ci] + v) & 0xffff; } /* Scale and output the DC coefficient (assumes jpeg_natural_order[0]=0) */ @@ -450,7 +453,7 @@ decode_mcu_AC_refine (j_decompress_ptr cinfo, JBLOCKROW *MCU_data) tbl = cinfo->cur_comp_info[0]->ac_tbl_no; p1 = 1 << cinfo->Al; /* 1 in the bit position being coded */ - m1 = (-1) << cinfo->Al; /* -1 in the bit position being coded */ + m1 = (NEG_1) << cinfo->Al; /* -1 in the bit position being coded */ /* Establish EOBx (previous stage end-of-block) index */ for (kex = cinfo->Se; kex > 0; kex--) @@ -561,7 +564,7 @@ decode_mcu (j_decompress_ptr cinfo, JBLOCKROW *MCU_data) while (m >>= 1) if (arith_decode(cinfo, st)) v |= m; v += 1; if (sign) v = -v; - entropy->last_dc_val[ci] += v; + entropy->last_dc_val[ci] = (entropy->last_dc_val[ci] + v) & 0xffff; } if (block) diff --git a/media/libjpeg/jdcolor.c b/media/libjpeg/jdcolor.c index ab8fa24925..05cbf4df1f 100644 --- a/media/libjpeg/jdcolor.c +++ b/media/libjpeg/jdcolor.c @@ -616,7 +616,7 @@ static const JLONG dither_matrix[4] = { static INLINE boolean is_big_endian(void) { int test_value = 1; - if(*(char *)&test_value != 1) + if (*(char *)&test_value != 1) return TRUE; return FALSE; } diff --git a/media/libjpeg/jdmerge.c b/media/libjpeg/jdmerge.c index 6276dd0950..ca6f16c252 100644 --- a/media/libjpeg/jdmerge.c +++ b/media/libjpeg/jdmerge.c @@ -503,7 +503,7 @@ static const JLONG dither_matrix[4] = { static INLINE boolean is_big_endian(void) { int test_value = 1; - if(*(char *)&test_value != 1) + if (*(char *)&test_value != 1) return TRUE; return FALSE; } diff --git a/media/libjpeg/jdmrg565.c b/media/libjpeg/jdmrg565.c index 18287b3735..a376340142 100644 --- a/media/libjpeg/jdmrg565.c +++ b/media/libjpeg/jdmrg565.c @@ -5,7 +5,7 @@ * Copyright (C) 1994-1996, Thomas G. Lane. * libjpeg-turbo Modifications: * Copyright (C) 2013, Linaro Limited. - * Copyright (C) 2014-2015, D. R. Commander. + * Copyright (C) 2014-2015, 2018, D. R. Commander. * For conditions of distribution and use, see the accompanying README.ijg * file. * @@ -304,20 +304,20 @@ h2v2_merged_upsample_565D_internal (j_decompress_ptr cinfo, rgb = PACK_SHORT_565(r, g, b); y = GETJSAMPLE(*inptr00++); - r = range_limit[DITHER_565_R(y + cred, d1)]; - g = range_limit[DITHER_565_G(y + cgreen, d1)]; - b = range_limit[DITHER_565_B(y + cblue, d1)]; - d1 = DITHER_ROTATE(d1); + r = range_limit[DITHER_565_R(y + cred, d0)]; + g = range_limit[DITHER_565_G(y + cgreen, d0)]; + b = range_limit[DITHER_565_B(y + cblue, d0)]; + d0 = DITHER_ROTATE(d0); rgb = PACK_TWO_PIXELS(rgb, PACK_SHORT_565(r, g, b)); WRITE_TWO_PIXELS(outptr0, rgb); outptr0 += 4; y = GETJSAMPLE(*inptr01++); - r = range_limit[DITHER_565_R(y + cred, d0)]; - g = range_limit[DITHER_565_G(y + cgreen, d0)]; - b = range_limit[DITHER_565_B(y + cblue, d0)]; - d0 = DITHER_ROTATE(d0); + r = range_limit[DITHER_565_R(y + cred, d1)]; + g = range_limit[DITHER_565_G(y + cgreen, d1)]; + b = range_limit[DITHER_565_B(y + cblue, d1)]; + d1 = DITHER_ROTATE(d1); rgb = PACK_SHORT_565(r, g, b); y = GETJSAMPLE(*inptr01++); diff --git a/media/libjpeg/jmemmgr.c b/media/libjpeg/jmemmgr.c index 2a8d8401f4..8dfb633dae 100644 --- a/media/libjpeg/jmemmgr.c +++ b/media/libjpeg/jmemmgr.c @@ -32,8 +32,10 @@ #include "jinclude.h" #include "jpeglib.h" #include "jmemsys.h" /* import the system-dependent declarations */ +#ifndef _WIN32 #include -#include /* some NDKs define SIZE_MAX in limits.h */ +#endif +#include #ifndef NO_GETENV #ifndef HAVE_STDLIB_H /* should declare getenv() */ diff --git a/media/libjpeg/jmemnobs.c b/media/libjpeg/jmemnobs.c index 5797198de8..ac12afa51b 100644 --- a/media/libjpeg/jmemnobs.c +++ b/media/libjpeg/jmemnobs.c @@ -3,8 +3,8 @@ * * This file was part of the Independent JPEG Group's software: * Copyright (C) 1992-1996, Thomas G. Lane. - * It was modified by The libjpeg-turbo Project to include only code and - * information relevant to libjpeg-turbo. + * libjpeg-turbo Modifications: + * Copyright (C) 2017, D. R. Commander. * For conditions of distribution and use, see the accompanying README.ijg * file. * @@ -15,7 +15,6 @@ * This is very portable in the sense that it'll compile on almost anything, * but you'd better have lots of main memory (or virtual memory) if you want * to process big images. - * Note that the max_memory_to_use option is ignored by this implementation. */ #define JPEG_INTERNALS @@ -66,14 +65,21 @@ jpeg_free_large (j_common_ptr cinfo, void *object, size_t sizeofobject) /* * This routine computes the total memory space available for allocation. - * Here we always say, "we got all you want bud!" */ GLOBAL(size_t) jpeg_mem_available (j_common_ptr cinfo, size_t min_bytes_needed, size_t max_bytes_needed, size_t already_allocated) { - return max_bytes_needed; + if (cinfo->mem->max_memory_to_use) { + if (cinfo->mem->max_memory_to_use > already_allocated) + return cinfo->mem->max_memory_to_use - already_allocated; + else + return 0; + } else { + /* Here we always say, "we got all you want bud!" */ + return max_bytes_needed; + } } diff --git a/media/libjpeg/jversion.h b/media/libjpeg/jversion.h index 6ce663d82a..7e44eaa3c5 100644 --- a/media/libjpeg/jversion.h +++ b/media/libjpeg/jversion.h @@ -4,7 +4,7 @@ * This file was part of the Independent JPEG Group's software: * Copyright (C) 1991-2012, Thomas G. Lane, Guido Vollbeding. * libjpeg-turbo Modifications: - * Copyright (C) 2010, 2012-2016, D. R. Commander. + * Copyright (C) 2010, 2012-2017, D. R. Commander. * For conditions of distribution and use, see the accompanying README.ijg * file. * @@ -35,7 +35,7 @@ * their code */ -#define JCOPYRIGHT "Copyright (C) 2009-2016 D. R. Commander\n" \ +#define JCOPYRIGHT "Copyright (C) 2009-2017 D. R. Commander\n" \ "Copyright (C) 2011-2016 Siarhei Siamashka\n" \ "Copyright (C) 2015-2016 Matthieu Darbois\n" \ "Copyright (C) 2015 Google, Inc.\n" \ @@ -46,4 +46,4 @@ "Copyright (C) 1999-2006 MIYASAKA Masaru\n" \ "Copyright (C) 1991-2016 Thomas G. Lane, Guido Vollbeding" \ -#define JCOPYRIGHT_SHORT "Copyright (C) 1991-2016 The libjpeg-turbo Project and many others" +#define JCOPYRIGHT_SHORT "Copyright (C) 1991-2017 The libjpeg-turbo Project and many others" diff --git a/media/libjpeg/simd/jchuff-sse2-64.asm b/media/libjpeg/simd/jchuff-sse2-64.asm index b1144d1cdd..0deb3e6fb4 100644 --- a/media/libjpeg/simd/jchuff-sse2-64.asm +++ b/media/libjpeg/simd/jchuff-sse2-64.asm @@ -195,11 +195,11 @@ EXTN(jsimd_huff_encode_one_block_sse2): lea rsp, [t2] collect_args %ifdef WIN64 - movaps XMMWORD [rsp-1*SIZEOF_XMMWORD], xmm8 - movaps XMMWORD [rsp-2*SIZEOF_XMMWORD], xmm9 - movaps XMMWORD [rsp-3*SIZEOF_XMMWORD], xmm10 - movaps XMMWORD [rsp-4*SIZEOF_XMMWORD], xmm11 sub rsp, 4*SIZEOF_XMMWORD + movaps XMMWORD [rsp+0*SIZEOF_XMMWORD], xmm8 + movaps XMMWORD [rsp+1*SIZEOF_XMMWORD], xmm9 + movaps XMMWORD [rsp+2*SIZEOF_XMMWORD], xmm10 + movaps XMMWORD [rsp+3*SIZEOF_XMMWORD], xmm11 %endif push rbx @@ -343,10 +343,10 @@ EXTN(jsimd_huff_encode_one_block_sse2): pop rbx %ifdef WIN64 - movaps xmm11, XMMWORD [rsp+0*SIZEOF_XMMWORD] - movaps xmm10, XMMWORD [rsp+1*SIZEOF_XMMWORD] - movaps xmm9, XMMWORD [rsp+2*SIZEOF_XMMWORD] - movaps xmm8, XMMWORD [rsp+3*SIZEOF_XMMWORD] + movaps xmm8, XMMWORD [rsp+0*SIZEOF_XMMWORD] + movaps xmm9, XMMWORD [rsp+1*SIZEOF_XMMWORD] + movaps xmm10, XMMWORD [rsp+2*SIZEOF_XMMWORD] + movaps xmm11, XMMWORD [rsp+3*SIZEOF_XMMWORD] add rsp, 4*SIZEOF_XMMWORD %endif uncollect_args diff --git a/media/libjpeg/simd/jchuff-sse2.asm b/media/libjpeg/simd/jchuff-sse2.asm index 36d1f2db66..b81db75b43 100644 --- a/media/libjpeg/simd/jchuff-sse2.asm +++ b/media/libjpeg/simd/jchuff-sse2.asm @@ -1,7 +1,7 @@ ; ; jchuff-sse2.asm - Huffman entropy encoding (SSE2) ; -; Copyright (C) 2009-2011, 2014-2016, D. R. Commander. +; Copyright (C) 2009-2011, 2014-2017, D. R. Commander. ; Copyright (C) 2015, Matthieu Darbois. ; ; Based on the x86 SIMD extension for IJG JPEG library @@ -288,13 +288,13 @@ EXTN(jsimd_huff_encode_one_block_sse2): .BLOOP: bsf ecx, edx ; r = __builtin_ctzl(index); - jz .ELOOP + jz near .ELOOP lea esi, [esi+ecx*2] ; k += r; shr edx, cl ; index >>= r; mov DWORD [esp+temp3], edx .BRLOOP: cmp ecx, 16 ; while (r > 15) { - jl .ERLOOP + jl near .ERLOOP sub ecx, 16 ; r -= 16; mov DWORD [esp+temp], ecx mov eax, INT [ebp + 240 * 4] ; code_0xf0 = actbl->ehufco[0xf0]; @@ -348,7 +348,7 @@ EXTN(jsimd_huff_encode_one_block_sse2): sub eax, esi shr eax, 1 bsf ecx, edx ; r = __builtin_ctzl(index); - jz .ELOOP2 + jz near .ELOOP2 shr edx, cl ; index >>= r; add ecx, eax lea esi, [esi+ecx*2] ; k += r; @@ -356,13 +356,13 @@ EXTN(jsimd_huff_encode_one_block_sse2): jmp .BRLOOP2 .BLOOP2: bsf ecx, edx ; r = __builtin_ctzl(index); - jz .ELOOP2 + jz near .ELOOP2 lea esi, [esi+ecx*2] ; k += r; shr edx, cl ; index >>= r; mov DWORD [esp+temp3], edx .BRLOOP2: cmp ecx, 16 ; while (r > 15) { - jl .ERLOOP2 + jl near .ERLOOP2 sub ecx, 16 ; r -= 16; mov DWORD [esp+temp], ecx mov eax, INT [ebp + 240 * 4] ; code_0xf0 = actbl->ehufco[0xf0]; diff --git a/media/libjpeg/simd/jsimd_arm.c b/media/libjpeg/simd/jsimd_arm.c index 61cd073e1b..0b955cdd09 100644 --- a/media/libjpeg/simd/jsimd_arm.c +++ b/media/libjpeg/simd/jsimd_arm.c @@ -2,6 +2,7 @@ * jsimd_arm.c * * Copyright 2009 Pierre Ossman for Cendio AB + * Copyright (C) 2011, Nokia Corporation and/or its subsidiary(-ies). * Copyright (C) 2009-2011, 2013-2014, 2016, D. R. Commander. * Copyright (C) 2015-2016, Matthieu Darbois. * diff --git a/media/libjpeg/simd/jsimd_arm64.c b/media/libjpeg/simd/jsimd_arm64.c index 09449bb6fd..f6e9736434 100644 --- a/media/libjpeg/simd/jsimd_arm64.c +++ b/media/libjpeg/simd/jsimd_arm64.c @@ -2,6 +2,7 @@ * jsimd_arm64.c * * Copyright 2009 Pierre Ossman for Cendio AB + * Copyright (C) 2011, Nokia Corporation and/or its subsidiary(-ies). * Copyright (C) 2009-2011, 2013-2014, 2016, D. R. Commander. * Copyright (C) 2015-2016, Matthieu Darbois. * diff --git a/media/libjpeg/simd/jsimd_mips.c b/media/libjpeg/simd/jsimd_mips.c index 63b8115d16..02e90cd9f0 100644 --- a/media/libjpeg/simd/jsimd_mips.c +++ b/media/libjpeg/simd/jsimd_mips.c @@ -63,6 +63,8 @@ parse_proc_cpuinfo(const char* search_string) LOCAL(void) init_simd (void) { + char *env = NULL; + if (simd_support != ~0U) return; diff --git a/media/libjpeg/simd/jsimd_mips_dspr2.S b/media/libjpeg/simd/jsimd_mips_dspr2.S index c8c286cb3e..c26dd5c536 100644 --- a/media/libjpeg/simd/jsimd_mips_dspr2.S +++ b/media/libjpeg/simd/jsimd_mips_dspr2.S @@ -4484,4 +4484,3 @@ LEAF_MIPS_DSPR2(jsimd_convsamp_float_mips_dspr2) END(jsimd_convsamp_float_mips_dspr2) /*****************************************************************************/ - diff --git a/media/libjpeg/simd/jsimd_mips_dspr2_asm.h b/media/libjpeg/simd/jsimd_mips_dspr2_asm.h index 64f9880482..499e34b7b6 100644 --- a/media/libjpeg/simd/jsimd_mips_dspr2_asm.h +++ b/media/libjpeg/simd/jsimd_mips_dspr2_asm.h @@ -281,5 +281,3 @@ LEAF_MIPS32R2(symbol) \ addiu sp, sp, \stack_offset .endif .endm - - diff --git a/media/libjpeg/simd/jsimd_powerpc.c b/media/libjpeg/simd/jsimd_powerpc.c index 42dc1e0868..47dd746f0d 100644 --- a/media/libjpeg/simd/jsimd_powerpc.c +++ b/media/libjpeg/simd/jsimd_powerpc.c @@ -14,6 +14,11 @@ * PowerPC architecture. */ +#ifdef __amigaos4__ +/* This must be defined first as it re-defines GLOBAL otherwise */ +#include +#endif + #define JPEG_INTERNALS #include "../jinclude.h" #include "../jpeglib.h" @@ -26,6 +31,12 @@ #include #include +#if defined(__OpenBSD__) +#include +#include +#include +#endif + static unsigned int simd_support = ~0; #if defined(__linux__) || defined(ANDROID) || defined(__ANDROID__) @@ -101,6 +112,12 @@ init_simd (void) char *env = NULL; #if !defined(__ALTIVEC__) && (defined(__linux__) || defined(ANDROID) || defined(__ANDROID__)) int bufsize = 1024; /* an initial guess for the line buffer size limit */ +#elif defined(__amigaos4__) + uint32 altivec = 0; +#elif defined(__OpenBSD__) + int mib[2] = { CTL_MACHDEP, CPU_ALTIVEC }; + int altivec; + size_t len = sizeof(altivec); #endif if (simd_support != ~0U) @@ -116,6 +133,13 @@ init_simd (void) if (bufsize > SOMEWHAT_SANE_PROC_CPUINFO_SIZE_LIMIT) break; } +#elif defined(__amigaos4__) + IExec->GetCPUInfoTags(GCIT_VectorUnit, &altivec, TAG_DONE); + if(altivec == VECTORTYPE_ALTIVEC) + simd_support |= JSIMD_ALTIVEC; +#elif defined(__OpenBSD__) + if (sysctl(mib, 2, &altivec, &len, NULL, 0) == 0 && altivec != 0) + simd_support |= JSIMD_ALTIVEC; #endif /* Force different settings through environment variables */