1
0
mirror of https://github.com/FFmpeg/FFmpeg.git synced 2024-11-26 19:01:44 +02:00
Commit Graph

97 Commits

Author SHA1 Message Date
Andreas Rheinhardt
42f6dfc42e avcodec/jpeg2000: Simplify exp2fi for numbers used here
The call to ff_exp2fi() here always uses arguments in the normal
range, so that the branches in ff_exp2fi() are unnecessary.
This is so because JPEG2000 itself only supports up to
128 bits per component per pixel (we only support far less);
furthermore, expn is always 0..31 for the decoder and also
sane for the encoder, so that the difference between these
two values is always in the normal range of -126..128.

Reviewed-by: Tomas Härdin <git@haerdin.se>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2024-02-20 00:09:05 +01:00
Andreas Rheinhardt
1ea3650823 Replace all occurences of av_mallocz_array() by av_calloc()
They do the same.

Reviewed-by: Paul B Mahol <onemda@gmail.com>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2021-09-20 01:03:52 +02:00
Andreas Rheinhardt
faa62773cb avcodec/jpeg2000: Make ff_tag_tree_size() static
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2021-09-08 22:59:14 +02:00
Andreas Rheinhardt
3c26773ae2 avcodec/jpeg2000dec: Make decoder init-threadsafe
The JPEG-2000 decoder and encoder share common luts; the decoder
initializes them once, guarded by a dedicated AVOnce, whereas
the encoder initializes them always during init. This means that
the decoder is not init-threadsafe; in fact there is a potential
data race because these luts can be initialized while an active
decoder/encoder is using them.

Fix this and make the decoder init-threadsafe by making the
initialization function guard initialization itself with a dedicated
AVOnce.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2021-05-12 06:00:14 +02:00
Gautam Ramakrishnan
341064d68a libavcodec/jpeg2000: fix tag tree reset
The implementation of the tag tree did not
set the correct reset value for the encoder.
This lead to inefficent tag tree being encoded.
This patch fixes the implementation of the
ff_tag_tree_zero() function.

Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2020-08-30 16:18:37 +02:00
Gautam Ramakrishnan
f0e33119e4 libavcodec/j2kenc: Support for multiple layers
This patch allows setting a compression ratio and to
set multiple layers. The user has to input a compression
ratio for each layer.
The per layer compression ration can be set as follows:
-layer_rates "r1,r2,...rn"
for to create 'n' layers.

Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2020-08-30 16:18:37 +02:00
Gautam Ramakrishnan
3c06045a8b libavcodec/j2kenc: Fix tag tree coding
The implementation of tag tree encoding was incorrect.
However, this error was not visible as the current j2k
encoder encodes only 1 layer.
This patch fixes tag tree coding for JPEG2000 such tag
tree coding would work for multi layer encoding.

Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2020-08-30 16:18:37 +02:00
Gautam Ramakrishnan
87567fc398 libavcodec/jpeg2000: Make tag tree functions non static
This patch makes the tag_tree_zero() and tag_tree_size()
functions non static and callable from other files.

Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2020-08-30 16:18:37 +02:00
Gautam Ramakrishnan
579ac96a04 libavcodec/jpeg2000.c: Precinct size check removed
This patch removes a check which throws an error if
the log2 precinct width/height is 0. The standard allows
the first component to have 0 as the log2 width/height.
However, to ensure proper intialization of coding style,
an extra check has been added.

Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2020-06-30 20:35:23 +02:00
Gautam Ramakrishnan
995d937827 libavcodec/jpeg2000: fix precinct coordinate calculation
The calculation of precinct boundaries has been
fixed. The precinct boundaries were calculated
as an offset to the band boundary, but must
instead be calculated as an offset from the
reslevel. This patch fixes #4669 and #4679.

Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2020-04-11 18:15:58 +02:00
Michael Niedermayer
06ef186fa1 avcodec/jpeg2000: Check stepsize before using it
Fixes: value 1.87633e+10 is outside the range of representable values of type 'int'
Fixes: Undefined behavior
Fixes: 14246/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_JPEG2000_fuzzer-5758393601490944

Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2019-04-25 14:49:51 +02:00
Michael Niedermayer
6887e41243 avcodec/jpeg2000: Check sum of sizes of band->prec before allocating
Fixes: OOM
Fixes: 4810/clusterfuzz-testcase-minimized-6034253235093504

Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2018-01-15 19:55:22 +01:00
Michael Niedermayer
42274db1c6 avcodec/jpeg2000dec: Allocate lengthinc and data_start arrays as needed
Decreases memory requirements
Fixes: OOM
Fixes: 4525/clusterfuzz-testcase-minimized-6400713073623040

Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2017-12-21 19:48:41 +01:00
Michael Niedermayer
b5587fd2c6 avcodec/jpeg2000: Only allocate Jpeg2000Pass for the encoder
Reduces memory needed.
Fixes: OOM
Fixes: 4427/clusterfuzz-testcase-minimized-5106919271301120

Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2017-12-01 23:12:07 +01:00
Michael Niedermayer
3d5822d9cf avcodec/jpeg2000: Dynamically allocate codeblock data
Fixes: OOM
Fixes: 3541/clusterfuzz-testcase-minimized-6469958596820992

Adds support for decoding codeblock data larger than 8kb
Reduces decoder memory consumption

Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2017-11-22 13:06:50 +01:00
Michael Niedermayer
64e034da95 avcodec/jpeg2000: Check that codsty->log2_prec_widths/heights has been initialized
Fixes: OOM
Fixes: 2225/clusterfuzz-testcase-minimized-5505632079708160

Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2017-09-30 23:35:45 +02:00
Clément Bœsch
8ef57a0d61 Merge commit '41ed7ab45fc693f7d7fc35664c0233f4c32d69bb'
* commit '41ed7ab45fc693f7d7fc35664c0233f4c32d69bb':
  cosmetics: Fix spelling mistakes

Merged-by: Clément Bœsch <u@pkh.me>
2016-06-21 21:55:34 +02:00
Vittorio Giovara
41ed7ab45f cosmetics: Fix spelling mistakes
Signed-off-by: Diego Biurrun <diego@biurrun.de>
2016-05-04 18:16:21 +02:00
Ganesh Ajjanagadde
83a04f103d lavc: move exp2fi to ff_exp2fi in internal.h
Reviewed-by: Michael Niedermayer <michael@niedermayer.cc>
Signed-off-by: Ganesh Ajjanagadde <gajjanagadde@gmail.com>
2015-12-16 07:57:26 -05:00
Ganesh Ajjanagadde
42868ca569 avcodec/jpeg2000: replace naive pow call with smarter exp2fi
pow is a very wasteful function for this purpose. A low hanging fruit
would be simply to replace with exp2f, and that does yield some speedup.
However, there are 2 drawbacks of this:
1. It does not exploit the integer nature of the argument.
2. (minor) Some platforms lack a proper exp2f routine, making benefits available
only to non broken libm.
3. exp2f does not solve the same issue that plagues pow, namely terrible
worst case performance. This is a fundamental issue known as the
"table-maker's dilemma" recognized by Prof. Kahan himself and
subsequently elaborated and researched by many others. All this is clear from benchmarks below.

This exploits the IEEE-754 format to get very good performance even in
the worst case for integer powers of 2. This solves all the issues noted
above. Function tested with clang usan over [-1000, 1000] (beyond range of
relevance for this, which is [-255, 255]), patch itself with FATE.

Benchmarks obtained on x86-64, Haswell, GNU-Linux via 10^5 iterations of
the pow call, START/STOP, and command ffplay ~/samples/jpeg2000/chiens_dcinema2K.mxf.
Low number of runs also given to prove the point about worst case:

pow:
 216270 decicycles in pow,       1 runs,      0 skips
 110175 decicycles in pow,       2 runs,      0 skips
  56085 decicycles in pow,       4 runs,      0 skips
  29013 decicycles in pow,       8 runs,      0 skips
  15472 decicycles in pow,      16 runs,      0 skips
   8689 decicycles in pow,      32 runs,      0 skips
   5295 decicycles in pow,      64 runs,      0 skips
   3599 decicycles in pow,     128 runs,      0 skips
   2748 decicycles in pow,     256 runs,      0 skips
   2304 decicycles in pow,     511 runs,      1 skips
   2072 decicycles in pow,    1022 runs,      2 skips
   1963 decicycles in pow,    2044 runs,      4 skips
   1894 decicycles in pow,    4091 runs,      5 skips
   1860 decicycles in pow,    8184 runs,      8 skips

exp2f:
 134140 decicycles in pow,       1 runs,      0 skips
  68110 decicycles in pow,       2 runs,      0 skips
  34530 decicycles in pow,       4 runs,      0 skips
  17677 decicycles in pow,       8 runs,      0 skips
   9175 decicycles in pow,      16 runs,      0 skips
   4931 decicycles in pow,      32 runs,      0 skips
   2808 decicycles in pow,      64 runs,      0 skips
   1747 decicycles in pow,     128 runs,      0 skips
   1208 decicycles in pow,     256 runs,      0 skips
    952 decicycles in pow,     512 runs,      0 skips
    822 decicycles in pow,    1024 runs,      0 skips
    765 decicycles in pow,    2047 runs,      1 skips
    722 decicycles in pow,    4094 runs,      2 skips
    693 decicycles in pow,    8190 runs,      2 skips

exp2fi:
   2740 decicycles in pow,       1 runs,      0 skips
   1530 decicycles in pow,       2 runs,      0 skips
    955 decicycles in pow,       4 runs,      0 skips
    622 decicycles in pow,       8 runs,      0 skips
    477 decicycles in pow,      16 runs,      0 skips
    368 decicycles in pow,      32 runs,      0 skips
    317 decicycles in pow,      64 runs,      0 skips
    291 decicycles in pow,     128 runs,      0 skips
    277 decicycles in pow,     256 runs,      0 skips
    268 decicycles in pow,     512 runs,      0 skips
    265 decicycles in pow,    1024 runs,      0 skips
    263 decicycles in pow,    2048 runs,      0 skips
    263 decicycles in pow,    4095 runs,      1 skips
    260 decicycles in pow,    8191 runs,      1 skips

Reviewed-by: Michael Niedermayer <michael@niedermayer.cc>
Signed-off-by: Ganesh Ajjanagadde <gajjanagadde@gmail.com>
2015-12-08 22:00:05 -05:00
Michael Niedermayer
0afdfbe116 avcodec/jpeg2000: fix type of arguments of tag_tree_size
Fixes: out of array read
Fixes: 36b8096fefab16c4c9326a508053e95c/signal_sigsegv_1d9ce18_3233_1a55196b018106dfabeace071a432d9e.r3d

Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2015-12-03 02:28:00 +01:00
Michael Niedermayer
0eb7de1973 avcodec/jpeg2000: Change coord to 32bit to support larger than 32k width or height
Fixes: 03e0abe721b1174856d41a1eb5d6a896/signal_sigabrt_7ffff6ae7cc9_3813_e71bf3541abed3ccba031cd5ba0269a4.avi

Found-by: Mateusz "j00ru" Jurczyk and Gynvael Coldwind
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2015-11-15 22:11:05 +01:00
Michael Niedermayer
a1a8cbcb35 avcodec/jpeg2000: Check comp coords to be within the supported size
Fixes assertion failure
Fixes: 03e0abe721b1174856d41a1eb5d6a896/signal_sigabrt_7ffff6ae7cc9_3813_e71bf3541abed3ccba031cd5ba0269a4.avi

This fix is choosen to be simple to backport, better solution
for master is planed

Found-by: Mateusz "j00ru" Jurczyk and Gynvael Coldwind
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2015-11-15 20:53:22 +01:00
Michael Niedermayer
016fd413f9 avcodec/jpeg2000: Use av_image_check_size() in ff_jpeg2000_init_component()
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2015-11-15 20:53:22 +01:00
Hendrik Leppkes
b2a72e8ab9 Merge commit '570fcaf3326aef9313b10863e2f6e6ae664d9dae'
* commit '570fcaf3326aef9313b10863e2f6e6ae664d9dae':
  jpeg2000: Factor out prec init

Merged-by: Hendrik Leppkes <h.leppkes@gmail.com>
2015-09-16 14:04:46 +02:00
Hendrik Leppkes
2fc552b629 Merge commit '95a41311ac3a44773cc4dc407408aca35b1f8e26'
* commit '95a41311ac3a44773cc4dc407408aca35b1f8e26':
  jpeg2000: Factor out band stepsize initialization

Merged-by: Hendrik Leppkes <h.leppkes@gmail.com>
2015-09-16 14:01:58 +02:00
Hendrik Leppkes
054ce2d6ab Merge commit '7fb93eae43cc89bd7c1c275344e1cdbadab7155b'
* commit '7fb93eae43cc89bd7c1c275344e1cdbadab7155b':
  jpeg2000: Factor out band initialization

Merged-by: Hendrik Leppkes <h.leppkes@gmail.com>
2015-09-16 13:58:30 +02:00
Luca Barbato
570fcaf332 jpeg2000: Factor out prec init
Makes debugging a little simpler.
2015-09-14 14:50:19 +02:00
Luca Barbato
95a41311ac jpeg2000: Factor out band stepsize initialization 2015-09-14 14:48:59 +02:00
Luca Barbato
7fb93eae43 jpeg2000: Factor out band initialization 2015-09-14 14:36:18 +02:00
Ganesh Ajjanagadde
36f7a37895 avcodec/jpeg2000: comment out unused variable
Fixes -Wunused-const-variable from
http://fate.ffmpeg.org/report.cgi?time=20150820031140&slot=arm64-darwin-clang-apple-5.1

Signed-off-by: Ganesh Ajjanagadde <gajjanagadde@gmail.com>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2015-08-21 13:01:44 +02:00
Michael Niedermayer
29d147c94d Merge commit '059a934806d61f7af9ab3fd9f74994b838ea5eba'
* commit '059a934806d61f7af9ab3fd9f74994b838ea5eba':
  lavc: Consistently prefix input buffer defines

Conflicts:
	doc/examples/decoding_encoding.c
	libavcodec/4xm.c
	libavcodec/aac_adtstoasc_bsf.c
	libavcodec/aacdec.c
	libavcodec/aacenc.c
	libavcodec/ac3dec.h
	libavcodec/asvenc.c
	libavcodec/avcodec.h
	libavcodec/avpacket.c
	libavcodec/dvdec.c
	libavcodec/ffv1enc.c
	libavcodec/g2meet.c
	libavcodec/gif.c
	libavcodec/h264.c
	libavcodec/h264_mp4toannexb_bsf.c
	libavcodec/huffyuvdec.c
	libavcodec/huffyuvenc.c
	libavcodec/jpeglsenc.c
	libavcodec/libxvid.c
	libavcodec/mdec.c
	libavcodec/motionpixels.c
	libavcodec/mpeg4videodec.c
	libavcodec/mpegvideo.c
	libavcodec/noise_bsf.c
	libavcodec/nuv.c
	libavcodec/nvenc.c
	libavcodec/options.c
	libavcodec/parser.c
	libavcodec/pngenc.c
	libavcodec/proresenc_kostya.c
	libavcodec/qsvdec.c
	libavcodec/svq1enc.c
	libavcodec/tiffenc.c
	libavcodec/truemotion2.c
	libavcodec/utils.c
	libavcodec/utvideoenc.c
	libavcodec/vc1dec.c
	libavcodec/wmalosslessdec.c
	libavformat/adxdec.c
	libavformat/aiffdec.c
	libavformat/apc.c
	libavformat/apetag.c
	libavformat/avidec.c
	libavformat/bink.c
	libavformat/cafdec.c
	libavformat/flvdec.c
	libavformat/id3v2.c
	libavformat/isom.c
	libavformat/matroskadec.c
	libavformat/mov.c
	libavformat/mpc.c
	libavformat/mpc8.c
	libavformat/mpegts.c
	libavformat/mvi.c
	libavformat/mxfdec.c
	libavformat/mxg.c
	libavformat/nutdec.c
	libavformat/oggdec.c
	libavformat/oggparsecelt.c
	libavformat/oggparseflac.c
	libavformat/oggparseopus.c
	libavformat/oggparsespeex.c
	libavformat/omadec.c
	libavformat/rawdec.c
	libavformat/riffdec.c
	libavformat/rl2.c
	libavformat/rmdec.c
	libavformat/rtpdec_latm.c
	libavformat/rtpdec_mpeg4.c
	libavformat/rtpdec_qdm2.c
	libavformat/rtpdec_svq3.c
	libavformat/sierravmd.c
	libavformat/smacker.c
	libavformat/smush.c
	libavformat/spdifenc.c
	libavformat/takdec.c
	libavformat/tta.c
	libavformat/utils.c
	libavformat/vqf.c
	libavformat/westwood_vqa.c
	libavformat/xmv.c
	libavformat/xwma.c
	libavformat/yop.c

Merged-by: Michael Niedermayer <michael@niedermayer.cc>
2015-07-27 23:15:19 +02:00
Michael Niedermayer
96e73fa649 avcodec/jpeg2000dec: Merge i_stepsize/2 decoder special case into dequant
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
2015-06-28 15:26:31 +02:00
Michael Niedermayer
317be53ca6 avcodec/jpeg2000: Support 32 decomposition levels
Fixes Ticket4680

Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
2015-06-28 03:16:06 +02:00
Michael Niedermayer
c72a831931 avcodec/jpeg2000dec: Support progression order changes
Fixes Ticket4657

Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
2015-06-26 21:00:10 +02:00
Michael Niedermayer
f1e173049e avcodec/jpeg2000: Remove CBLK limit
This also reduces the amount of memory needed
Fixes Ticket4672

The new code seems slightly faster as well, probably due to better cache usage

Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
2015-06-26 01:00:17 +02:00
Michael Niedermayer
67fc898243 avcodec/jpeg2000: Improve right bottom precinct positions
Fixes Ticket4656

Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
2015-06-25 00:23:31 +02:00
Michael Niedermayer
4e926fb969 avcodec/jpeg2000: Move L band scaling from the 9/7f wavelet to quantization stage
This reduces the number of operations
Its not done for 9/7i as that would overflow thanks to JPEG2000 allowing
32 decomposition levels

Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
2015-06-22 03:01:24 +02:00
Michael Niedermayer
6c7b1597c7 avcodec/jpeg2000: Move H band scaling from wavelet into quantization code
This reduces the number of operations done and is equivalent except for
rounding

Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
2015-06-22 02:00:57 +02:00
Michael Niedermayer
1c495b0bf6 avcodec/jpeg2000: Move gainb handling into the quantization code
thats how the specification defines it, this also improves numerical
accuracy of the integer wavelet implementation. It otherwise should
be equivalent, in case of overflows this can be reverted.

Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
2015-06-22 01:36:05 +02:00
Michael Niedermayer
ec5164aa31 avcodec/jpeg2000: Fix regression with multiple tiles
Fixes Ticket 4624

Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
2015-06-14 22:59:50 +02:00
Michael Niedermayer
a206c13289 avcodec/jpeg2000: Change codeblock coords to same origin as bands
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
2015-06-14 22:59:50 +02:00
Michael Niedermayer
d9841e53e2 avcodec/jpeg2000: Change precinct coords to same origin as bands
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
2015-06-14 22:59:42 +02:00
Michael Niedermayer
59c107292c avcodec/jpeg2000: Fix band coords
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
2015-06-14 21:58:38 +02:00
James Almer
9f815bc2c2 avcodec/jpeg200dsp: add ff_rct_int_{sse2,avx2}
Reviewed-by: Michael Niedermayer <michaelni@gmx.at>
Signed-off-by: James Almer <jamrial@gmail.com>
2015-06-13 16:53:31 -03:00
James Almer
7912a6830d avcodec/jpeg200dsp: add ff_ict_float_{sse,avx}
Original intrinsics version by Nicolas Bertrand.

Reviewed-by: Michael Niedermayer <michaelni@gmx.at>
Signed-off-by: James Almer <jamrial@gmail.com>
2015-06-13 16:53:27 -03:00
Michael Niedermayer
dc73c7adc0 avcodec/jpeg2000dec: Fix Selective arithmetic coding bypass and Multiple codeword segments
These 2 are highly related so they are in the same commit
Fixes part of Ticket4605
Fixes p0_04.j2k

Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
2015-06-12 03:12:54 +02:00
Michael Niedermayer
dbbb31e5bb avcodec/jpeg2000: remove unused variable
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
2015-06-09 18:48:39 +02:00
Michael Niedermayer
44327cbc9a avcodec/jpeg2000: Disable special case for JPEG2000_QSTY_SI
The code gave apparently completely wrong values

Fixes Ticket2872

Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
2015-06-09 16:44:32 +02:00
Michael Niedermayer
074159ed70 avcodec/jpeg2000dec: Fix subsampled decoding
Fixes part of Ticket3619

Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
2015-06-09 01:02:05 +02:00