Commit Graph

3292 Commits

Author SHA1 Message Date
James Zern
de9fa5074e ConvertWRGBToYUV: use relative pointer offsets
avoids int rollover when working with large input

BUG=webp:312

Change-Id: I693cbb295df9cf94aa89294b19c0496bdbe84d18
2016-11-04 00:35:04 -07:00
James Zern
deb1b83199 ImportYUVAFromRGBA: use relative pointer offsets
avoids int rollover when working with large input

BUG=webp:312

Change-Id: I3d7b689be8d5751248a82d1021243d80d3f67203
2016-11-04 00:34:58 -07:00
James Zern
cac9a36a23 gifdec,Remap: avoid out of bounds colormap read
make this function return success/failure.
an empty map or out of bounds read is treated as an error.

BUG=webp:316

Change-Id: Ic8651836915ea4dd8e0dc81ca8d5d3f247be1ff8
2016-11-02 15:01:10 -07:00
James Zern
4595e01fd0 Revert "gifdec,Remap: avoid out of bounds colormap read"
This reverts commit f048d38d38.

the 'len' in Remap refers to the src[] not the colormap; this change
breaks valid files

BUG=webp:316

Change-Id: I1ed40075c2194df91d345cb6f29619b1f5cc96fc
2016-11-01 21:03:56 -07:00
James Zern
fb52d4432a gifdec: make some constants unsigned
fixes implicit type conversion when dealing with color types

Change-Id: Ie4f25e14d8bb2748050db4fca25147164fc6adb4
2016-10-31 17:51:27 -07:00
James Zern
f048d38d38 gifdec,Remap: avoid out of bounds colormap read
sanitize the requested length to be read against the reported size of
the table

BUG=webp:316

Change-Id: I1c471e93ab696a9d21a0142cf1987ffcf8f55dd2
2016-10-31 12:56:04 -07:00
Pascal Massimino
31b1e34342 fix SSIM metric ... by ignoring too-dark area
Roughly, if both the source and the reference areas are
darker too dark (R/G/B <= ~6), they are ignored.

One caveat: SSIM calculation won't work for U/V planes,
which are 128-centered and not related to luminance.
But WebPPlaneDistortion() enforces the conversion to RGB,
if needed.

Change-Id: I586c2579c475583b8c90c5baefd766b1d5aea591
2016-10-20 15:17:55 +02:00
Pascal Massimino
2f51b614b0 introduce WebPPlaneDistortion to compute plane distortion
Make WebPPictureDistortion() only compute distortion on A/R/G/B planes, not Y/U/V(A).
(not just for SSIM, but PSNR too).

This is to avoid problems with using SSIM on U/V channels.
If Y/U/V distortion is needed, one can always use WebPPlaneDistortion() individually.

Change-Id: If8bc9c3ac12a8d2220f03224694fc389b16b7da9
2016-10-19 09:12:13 +02:00
James Zern
0104d730bf configure: fix NEON flag detection under gcc 6
use a compile check on a separate file to avoid assuming using
arm_neon.h is safe to use without flags when just the file itself is
self-contained with GCC target pragmas.

BUG=webp:313

Change-Id: I48f92ae3e6e4a9468ea5b937c80a89ee40b2dcfd
2016-10-14 06:24:08 +00:00
Pascal Massimino
265abbe9b2 Merge "additional fix for stride type as size_t" 2016-10-13 20:38:07 +00:00
Pascal Massimino
f7601aa686 Merge "Introduce a generic WebPGetImageReader(type) function" 2016-10-13 07:21:59 +00:00
Pascal Massimino
ce8733209d Introduce a generic WebPGetImageReader(type) function
Also introduce an always-failing 'reader' for unknown formats.
So we don't have to check reader==NULL, code is more regular.

-> We can get read of specific ReadPNG(), ReadJPEG(), ... declaration and use.

Change-Id: I290759705420878f00c7223c726d4ad404afd9c4
2016-10-12 21:00:27 -07:00
James Zern
2a2773ea29 imageio/*dec,Read*: add input parameter checks
Change-Id: I5e069d6ea4da9d8c71be03ef99aad679dd1aad21
2016-10-12 20:49:30 -07:00
Pascal Massimino
9f5c8eca79 additional fix for stride type as size_t
- remove the inclusion of format_constants.h
 - use incremental update of pointer, instead of arithmetic

(follow-up to e2affacc35)

Change-Id: I48420c8defc8d47339f54bc00e9da9617f08ab32
2016-10-12 18:23:04 +00:00
Pascal Massimino
4eb5df28d1 remove unused stride fields from VP8Iterator
Change-Id: I242aaa746dc53c456eb8f1a71a5a2378f26fa843
2016-10-10 18:08:47 +02:00
Vincent Rabaud
11bc423ae5 MIN_LENGTH cleanups.
No change in logic so no change in speed or compression.

Change-Id: I744161978c7d058c9b58450f330cba11731530c6
2016-10-10 15:37:45 +02:00
Pascal Massimino
273d035a44 Merge "fix a typo in WebPPictureYUVAToARGB's doc" 2016-10-10 13:30:20 +00:00
Pascal Massimino
4db82a178f Merge "fix potential overflow when width * height * 4 >= (1<<32)" 2016-10-10 13:03:50 +00:00
Pascal Massimino
e2affacc35 fix potential overflow when width * height * 4 >= (1<<32)
Mostly: avoid doing calculation like: ptr + j * stride
when stride is 'int'. Rather use size_t, or pointer increments (ptr += stride)
when possible.

BUG=webp:314

Change-Id: I81c684b515dd1ec4f601f32d50a6e821c4e46e20
2016-10-10 13:55:46 +02:00
Pascal Massimino
dc789ada44 fix a typo in WebPPictureYUVAToARGB's doc
method -> colorspace

Change-Id: I5c9a2ccc909c967a936758dde2cfce92eb95462a
2016-10-10 04:50:10 -07:00
Vincent Rabaud
539f5a688f Fix non-included header in config.c.
When compiling as experimental, WEBP_EXPERIMENTAL_FEATURES
would not be defined because the header defining it would
not be included.
Hence runtime errors in debug mode when running:
./cwebp -lossles whatever
...
Error! Cannot encode picture as WebP
Error code: 4 (INVALID_CONFIGURATION: configuration is invalid)

(detail: WebPConfig would have a random value set for
delta_palettization as config.c does not consider
it to exist.)

Change-Id: I41761cffe81a971130ed514b195a73d1c6dac1b7
2016-10-10 13:39:17 +02:00
Pascal Massimino
aaf2a6a698 systematically call WebPDemuxReleaseIterator() on dec->prev_iter_
Change-Id: I4a767134dcc52a7ee7c3bc5deb91012eaf7b6512
2016-10-07 17:30:58 -07:00
James Zern
20ef99159e Merge "imageio_util: add ImgIoUtilCheckSizeArgumentsOverflow" 2016-10-08 00:18:48 +00:00
James Zern
bc86b7a8a1 imageio_util: add ImgIoUtilCheckSizeArgumentsOverflow
and use it to validate decoder allocations. fixes a crash in jpegdec at
least.

BUG=webp:312

Change-Id: Ia940590098f29510add6aad10a8dfe9e9ea46bf4
2016-10-07 14:41:48 -07:00
James Zern
806f6279ae gif2webp: fix crash with NULL extension data
DGifGetExtension() may successfully return, but the data pointer should
still be validated

BUG=webp:310

Change-Id: I6cfe617871fef2fe07887e5f48bb20f7ab7cfb35
2016-10-07 11:21:18 -07:00
hui su
68ae5b671f Add libwebp/src/mux/animi.h
Change-Id: I80ca2070d419acf6e8355a295ee965d2df5a4d8f
2016-10-05 10:33:29 -07:00
Vincent Rabaud
28ce304344 Remove some errors when compiling the code as C++.
This fixes some cases from
https://bugs.chromium.org/p/webp/issues/detail?id=137

Change-Id: I58f3a617bf973dbe4c5794004a01e2aea39ba53a
2016-10-05 09:39:08 +02:00
hui su
b34abcb8b1 Favor keeping the areas locally similar in spatial prediction mode selection
About 0.1% compression improvement.

Change-Id: If106ab209cc2671ef282b726e09ff2971c3e4abf
2016-10-04 16:28:24 -07:00
Pascal Massimino
ba843a92e7 fix some SSIM calculations
* prevent 64bit overflow by controlling the 32b->64b conversions
  and preventively descaling by 8bit before the final multiply
* adjust the threshold constants C1 and C2 to de-emphasis the dark
  areas
* use a hat-like filter instead of box-filtering to avoid blockiness
  during averaging

SSIM distortion calc is actually *faster* now in SSE2, because of the
unrolling during the function rewrite.
The C-version is quite slower because still un-optimized.

Change-Id: I96e2715827f79d26faae354cc28c7406c6800c90
2016-10-04 01:09:07 -07:00
James Zern
51b71fd295 Merge "vwebp: ensure setenv() is available in stdlib.h" 2016-10-01 02:56:54 +00:00
Pascal Massimino
fb01743a53 get_disto: fix the r/g/b order for luma calculation
Change-Id: I62be556f6254031e8c1f1a572cfdc4ea2641483b
2016-09-30 16:04:17 +02:00
James Zern
bfab894739 vwebp: ensure setenv() is available in stdlib.h
quiets a -Wimplicit-function-declaration with some configurations of gcc
(-std=c99).
_POSIX_C_SOURCE is preferred over _BSD_SOURCE with newer versions of
glibc

Change-Id: I378bffb13ba52ff5c4bad1433090dcc387e5d507
2016-09-30 00:27:06 -07:00
Pascal Massimino
9310d19258 vwebp: handle window resizing properly
The image is scaled to fit the whole viewport.
Avoid some oddities with offsets, etc.

removes some TODO.

Change-Id: I52fae9ca80a2feed234f32261c7f6358d7594e21
2016-09-29 07:30:03 +02:00
Vincent Rabaud
f79450ca02 Speedup ApplyMap.
If a small hash map can be used, use it to avoid binary search.
This fist hash function that is tried works with the previous
use case of having indexed data in green.

Change-Id: I2f91cec5f3ca7e9c393fd829e69e09bab74f4e7c
2016-09-28 17:18:08 +02:00
Pascal Massimino
cfdda7c6bf Merge "prevent 32b overflow for very large canvas_width / height" 2016-09-28 15:09:58 +00:00
Pascal Massimino
e36396ba75 Merge "get_disto: new option to compute SSIM map and convert to gray" 2016-09-28 15:08:58 +00:00
Vincent Rabaud
18a9a0ab57 Add an API to import a color-mapped image.
Change-Id: I71421a1a706a74d184a24dc9276b55005d7457b5
2016-09-28 14:23:23 +02:00
Vincent Rabaud
30d43706d3 Speed-up Combined entropy for palettized histograms.
Change-Id: Ie9bdebb26c726e5b44c2dbcc84d453f85a03f419
2016-09-28 13:22:13 +02:00
Pascal Massimino
36aa087b6d get_disto: new option to compute SSIM map and convert to gray
using -ssim -o will trigger SSIM map calculation instead of add-diff map.

-gray converts the error map to intensity instead of having each channels' error separated.

Change-Id: I4bdb88880a252e5562aa4e0e3c2353ad93aef20e
2016-09-28 00:23:43 -07:00
Pascal Massimino
86a84b3598 2x faster SSE2 implementation of SSIMGet
Change-Id: I53705d7ddfa595389ff2d542e5088f96f948d351
2016-09-23 23:23:06 -07:00
James Zern
b8384b53d6 lower WEBP_MAX_ALLOCABLE_MEMORY default
restrict to 2^34 for 64-bit targets, < 2^32 for 32-bit

Change-Id: Iff4ce40ae2c3c7fc119f018c2128dbe8f744341f
2016-09-22 23:13:33 -07:00
Pascal Massimino
1c36440094 prevent 32b overflow for very large canvas_width / height
some multiplies here and there needed some extra checks
and error reporting. Even if width * height is guaranteed
to be < 2**32, we were multiplying by num_channels and
triggering a 32b overflow.
Some multiplies were not using size_t or uint64_t, additionally.

Change-Id: If2a35b94c8af204135f4b88a7fd63850aa381bbf
2016-09-23 05:19:32 +00:00
Pascal Massimino
eee0cce158 Merge "Small LZ77 speedups." 2016-09-22 12:50:13 +00:00
Vincent Rabaud
5f1caf2987 Small LZ77 speedups.
The most common conditions are re-ordered and cached.

iter_min was recently introduced to make sure enough iterations
are made in cases where there are many matches (mostly uniform regions).
Now that those are properly analyzed, it becomes useless.

Change-Id: Id3010ee4ec66b84d602fcb926f91eb9155ad27f4
2016-09-22 14:03:25 +02:00
Pascal Massimino
1effde7bcd fix anim_util.c compilation when HAVE_GIF is not defined.
Change-Id: I1a4f13a5799c020fb4b3ade3c7336f049443ab62
2016-09-22 13:43:36 +02:00
hui su
a2fe9bf404 Speedup TrellisQuantizeBlock().
-Skip examining quantized levels that are too high.
-Calculate last_pos_cost only when needed.

Encoding speed for m6 is increased by about 3%;
Compression performance is neutral.

Change-Id: I8af70b049587cca0375d9b3eb00479ec7c0c842a
2016-09-20 14:54:15 -07:00
Pascal Massimino
573cce270e smartYUV improvements
* switch to Rec709 transfer function in SmartYUV
* use Rec709 for Gray evaluation too.
* stop iterations if error is going up

See paragraph 1.2 and 3.2:
https://www.itu.int/dms_pubrec/itu-r/rec/bt/R-REC-BT.709-6-201506-I!!PDF-E.pdf

(digest: https://en.wikipedia.org/wiki/Rec._709#Transfer_characteristics)

suggested by pdknsk@gmail.com on the mailing list

Change-Id: I12b5f4d3e318dd5134984e1c0a4b244a620a57d7
2016-09-20 06:14:31 +00:00
Pascal Massimino
21e7537abe fix infinite loop in case of PARTITION0 overflow
max_i4_header_bits_ could drop to zero for difficult image and trigger
a loop. Surprisingly, StatLoop() didn't have this bug.

Change-Id: Idc0f9eadef30a2b2f02041b994f25def30901e36
2016-09-15 02:38:28 -07:00
Pascal Massimino
053a1565c8 Merge "Change the rule of picking UV mode in MBAnalyzeBestUVMode()" 2016-09-15 06:58:40 +00:00
hui su
1377ac2ec1 Change the rule of picking UV mode in MBAnalyzeBestUVMode()
Pick the mode with the smallest alpha.
It only affects m0, in which case the mode decision is not re-examined
later in VP8Decimate(). Tests on some natural content png images show
PSNR increase as well as visual quality improvement.

Change-Id: Iea997e718cd7477160fa05eb7cfb35f4cec2fa9a
2016-09-15 06:01:03 +00:00