Re: [FFmpeg-devel] [PATCH] avcodec/dxv: add support for "high" quality mode
On Mon, 16 Apr 2018 09:20:09 +0200 Hendrik Leppkes wrote: > On Mon, Apr 16, 2018 at 12:23 AM, Carl Eugen Hoyos wrote: > > 2018-04-15 9:41 GMT+02:00, Paul B Mahol : > >> On 4/14/18, Rostislav Pehlivanov wrote: > >>> On 14 April 2018 at 20:46, Paul B Mahol wrote: > >>> > Signed-off-by: Paul B Mahol > --- > libavcodec/dxv.c | 815 ++ > ++--- > 1 file changed, 780 insertions(+), 35 deletions(-) > > >>> > >>> LGTM > >> > >> Applied. Thanks. > > > > Thank you for working on formats like this one, I consider this > > highly important! > > > > Sorry for not testing your patch earlier... > > > > The committed change is not helpful afaict, if you cannot fix > > the colourspace issue (which I perfectly understand), please > > commit your original hack (with a note), this variant cannot > > help users. > > > > This is not the first decoder to output YCoCg, I have H.264 files with > that as well. Just because swscale cannot convert that doesn't mean we > should be doing anything but non-native output from a decoder. My > playback chain can support that just fine. > Feel free to contribute YCoCg conversion to swscale to resolve this > for "the users". +1 ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
Re: [FFmpeg-devel] [PATCH] avcodec/dxv: add support for "high" quality mode
On Mon, Apr 16, 2018 at 12:23 AM, Carl Eugen Hoyos wrote: > 2018-04-15 9:41 GMT+02:00, Paul B Mahol : >> On 4/14/18, Rostislav Pehlivanov wrote: >>> On 14 April 2018 at 20:46, Paul B Mahol wrote: >>> Signed-off-by: Paul B Mahol --- libavcodec/dxv.c | 815 ++ ++--- 1 file changed, 780 insertions(+), 35 deletions(-) >>> >>> LGTM >> >> Applied. Thanks. > > Thank you for working on formats like this one, I consider this > highly important! > > Sorry for not testing your patch earlier... > > The committed change is not helpful afaict, if you cannot fix > the colourspace issue (which I perfectly understand), please > commit your original hack (with a note), this variant cannot > help users. > This is not the first decoder to output YCoCg, I have H.264 files with that as well. Just because swscale cannot convert that doesn't mean we should be doing anything but non-native output from a decoder. My playback chain can support that just fine. Feel free to contribute YCoCg conversion to swscale to resolve this for "the users". - Hendrik ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
Re: [FFmpeg-devel] [PATCH] avcodec/dxv: add support for "high" quality mode
On 4/16/18, Carl Eugen Hoyos wrote: > 2018-04-15 9:41 GMT+02:00, Paul B Mahol : >> On 4/14/18, Rostislav Pehlivanov wrote: >>> On 14 April 2018 at 20:46, Paul B Mahol wrote: >>> Signed-off-by: Paul B Mahol --- libavcodec/dxv.c | 815 ++ ++--- 1 file changed, 780 insertions(+), 35 deletions(-) >>> >>> LGTM >> >> Applied. Thanks. > > Thank you for working on formats like this one, I consider this > highly important! > > Sorry for not testing your patch earlier... > > The committed change is not helpful afaict, if you cannot fix > the colourspace issue (which I perfectly understand), please > commit your original hack (with a note), this variant cannot > help users. > > Thank you, Carl Eugen Please, leave for the good of the world future. ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
Re: [FFmpeg-devel] [PATCH] avcodec/dxv: add support for "high" quality mode
2018-04-15 9:41 GMT+02:00, Paul B Mahol : > On 4/14/18, Rostislav Pehlivanov wrote: >> On 14 April 2018 at 20:46, Paul B Mahol wrote: >> >>> Signed-off-by: Paul B Mahol >>> --- >>> libavcodec/dxv.c | 815 ++ >>> ++--- >>> 1 file changed, 780 insertions(+), 35 deletions(-) >>> >> >> LGTM > > Applied. Thanks. Thank you for working on formats like this one, I consider this highly important! Sorry for not testing your patch earlier... The committed change is not helpful afaict, if you cannot fix the colourspace issue (which I perfectly understand), please commit your original hack (with a note), this variant cannot help users. Thank you, Carl Eugen ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
Re: [FFmpeg-devel] [PATCH] avcodec/dxv: add support for "high" quality mode
On 4/14/18, Rostislav Pehlivanov wrote: > On 14 April 2018 at 20:46, Paul B Mahol wrote: > >> Signed-off-by: Paul B Mahol >> --- >> libavcodec/dxv.c | 815 ++ >> ++--- >> 1 file changed, 780 insertions(+), 35 deletions(-) >> > > LGTM Applied. Thanks. ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
Re: [FFmpeg-devel] [PATCH] avcodec/dxv: add support for "high" quality mode
On 14 April 2018 at 20:46, Paul B Mahol wrote: > Signed-off-by: Paul B Mahol > --- > libavcodec/dxv.c | 815 ++ > ++--- > 1 file changed, 780 insertions(+), 35 deletions(-) > > diff --git a/libavcodec/dxv.c b/libavcodec/dxv.c > index 529e211258..101fe78481 100644 > --- a/libavcodec/dxv.c > +++ b/libavcodec/dxv.c > @@ -1,6 +1,7 @@ > /* > * Resolume DXV decoder > * Copyright (C) 2015 Vittorio Giovara > + * Copyright (C) 2018 Paul B Mahol > * > * This file is part of FFmpeg. > * > @@ -23,6 +24,7 @@ > > #include "libavutil/imgutils.h" > > +#include "mathops.h" > #include "avcodec.h" > #include "bytestream.h" > #include "internal.h" > @@ -34,50 +36,211 @@ typedef struct DXVContext { > TextureDSPContext texdsp; > GetByteContext gbc; > > -uint8_t *tex_data; // Compressed texture > -int tex_rat;// Compression ratio > -int tex_step; // Distance between blocks > -int64_t tex_size; // Texture size > +uint8_t *tex_data; // Compressed texture > +uint8_t *ctex_data; // Compressed texture > +int tex_rat; // Compression ratio > +int tex_step;// Distance between blocks > +int ctex_step; // Distance between blocks > +int64_t tex_size;// Texture size > +int64_t ctex_size; // Texture size > > /* Optimal number of slices for parallel decoding */ > int slice_count; > > +uint8_t *op_data[4]; // Opcodes > +int64_t op_size[4]; // Opcodes size > + > +int texture_block_w; > +int texture_block_h; > + > +int ctexture_block_w; > +int ctexture_block_h; > + > /* Pointer to the selected decompression function */ > int (*tex_funct)(uint8_t *dst, ptrdiff_t stride, const uint8_t > *block); > +int (*tex_funct_planar[2])(uint8_t *plane0, ptrdiff_t stride0, > + uint8_t *plane1, ptrdiff_t stride1, > + const uint8_t *block); > } DXVContext; > > +static void decompress_indices(uint8_t *dst, const uint8_t *src) > +{ > +int block, i; > + > +for (block = 0; block < 2; block++) { > +int tmp = AV_RL24(src); > + > +/* Unpack 8x3 bit from last 3 byte block */ > +for (i = 0; i < 8; i++) > +dst[i] = (tmp >> (i * 3)) & 0x7; > + > +src += 3; > +dst += 8; > +} > +} > + > +static int extract_component(int yo0, int yo1, int code) > +{ > +int yo; > + > +if (yo0 == yo1) { > +yo = yo0; > +} else if (code == 0) { > +yo = yo0; > +} else if (code == 1) { > +yo = yo1; > +} else { > +if (yo0 > yo1) { > +yo = (uint8_t) (((8 - code) * yo0 + > + (code - 1) * yo1) / 7); > +} else { > +if (code == 6) { > +yo = 0; > +} else if (code == 7) { > +yo = 255; > +} else { > +yo = (uint8_t) (((6 - code) * yo0 + > + (code - 1) * yo1) / 5); > +} > +} > +} > + > +return yo; > +} > + > +static int cocg_block(uint8_t *plane0, ptrdiff_t stride0, > + uint8_t *plane1, ptrdiff_t stride1, > + const uint8_t *block) > +{ > +uint8_t co_indices[16]; > +uint8_t cg_indices[16]; > +uint8_t co0 = *(block); > +uint8_t co1 = *(block + 1); > +uint8_t cg0 = *(block + 8); > +uint8_t cg1 = *(block + 9); > +int x, y; > + > +decompress_indices(co_indices, block + 2); > +decompress_indices(cg_indices, block + 10); > + > +for (y = 0; y < 4; y++) { > +for (x = 0; x < 4; x++) { > +int co_code = co_indices[x + y * 4]; > +int cg_code = cg_indices[x + y * 4]; > + > +plane0[x] = extract_component(cg0, cg1, cg_code); > +plane1[x] = extract_component(co0, co1, co_code); > +} > +plane0 += stride0; > +plane1 += stride1; > +} > + > +return 16; > +} > + > +static void yao_subblock(uint8_t *dst, uint8_t *yo_indices, > +ptrdiff_t stride, const uint8_t *block) > +{ > +uint8_t yo0 = *(block); > +uint8_t yo1 = *(block + 1); > +int x, y; > + > +decompress_indices(yo_indices, block + 2); > + > +for (y = 0; y < 4; y++) { > +for (x = 0; x < 4; x++) { > +int yo_code = yo_indices[x + y * 4]; > + > +dst[x] = extract_component(yo0, yo1, yo_code); > +} > +dst += stride; > +} > +} > + > +static int yo_block(uint8_t *dst, ptrdiff_t stride, > +uint8_t *unused0, ptrdiff_t unused1, > +const uint8_t *block) > +{ > +uint8_t yo_indices[16]; > + > +yao_subblock(dst, yo_indices, stride, block); > +yao_subblock(dst + 4, yo_indices, stride, block + 8); > +yao_subblock(dst + 8, yo_indices, stride, block + 16); > +yao_subblock(dst + 12, yo_indice
[FFmpeg-devel] [PATCH] avcodec/dxv: add support for "high" quality mode
Signed-off-by: Paul B Mahol --- libavcodec/dxv.c | 815 --- 1 file changed, 780 insertions(+), 35 deletions(-) diff --git a/libavcodec/dxv.c b/libavcodec/dxv.c index 529e211258..101fe78481 100644 --- a/libavcodec/dxv.c +++ b/libavcodec/dxv.c @@ -1,6 +1,7 @@ /* * Resolume DXV decoder * Copyright (C) 2015 Vittorio Giovara + * Copyright (C) 2018 Paul B Mahol * * This file is part of FFmpeg. * @@ -23,6 +24,7 @@ #include "libavutil/imgutils.h" +#include "mathops.h" #include "avcodec.h" #include "bytestream.h" #include "internal.h" @@ -34,50 +36,211 @@ typedef struct DXVContext { TextureDSPContext texdsp; GetByteContext gbc; -uint8_t *tex_data; // Compressed texture -int tex_rat;// Compression ratio -int tex_step; // Distance between blocks -int64_t tex_size; // Texture size +uint8_t *tex_data; // Compressed texture +uint8_t *ctex_data; // Compressed texture +int tex_rat; // Compression ratio +int tex_step;// Distance between blocks +int ctex_step; // Distance between blocks +int64_t tex_size;// Texture size +int64_t ctex_size; // Texture size /* Optimal number of slices for parallel decoding */ int slice_count; +uint8_t *op_data[4]; // Opcodes +int64_t op_size[4]; // Opcodes size + +int texture_block_w; +int texture_block_h; + +int ctexture_block_w; +int ctexture_block_h; + /* Pointer to the selected decompression function */ int (*tex_funct)(uint8_t *dst, ptrdiff_t stride, const uint8_t *block); +int (*tex_funct_planar[2])(uint8_t *plane0, ptrdiff_t stride0, + uint8_t *plane1, ptrdiff_t stride1, + const uint8_t *block); } DXVContext; +static void decompress_indices(uint8_t *dst, const uint8_t *src) +{ +int block, i; + +for (block = 0; block < 2; block++) { +int tmp = AV_RL24(src); + +/* Unpack 8x3 bit from last 3 byte block */ +for (i = 0; i < 8; i++) +dst[i] = (tmp >> (i * 3)) & 0x7; + +src += 3; +dst += 8; +} +} + +static int extract_component(int yo0, int yo1, int code) +{ +int yo; + +if (yo0 == yo1) { +yo = yo0; +} else if (code == 0) { +yo = yo0; +} else if (code == 1) { +yo = yo1; +} else { +if (yo0 > yo1) { +yo = (uint8_t) (((8 - code) * yo0 + + (code - 1) * yo1) / 7); +} else { +if (code == 6) { +yo = 0; +} else if (code == 7) { +yo = 255; +} else { +yo = (uint8_t) (((6 - code) * yo0 + + (code - 1) * yo1) / 5); +} +} +} + +return yo; +} + +static int cocg_block(uint8_t *plane0, ptrdiff_t stride0, + uint8_t *plane1, ptrdiff_t stride1, + const uint8_t *block) +{ +uint8_t co_indices[16]; +uint8_t cg_indices[16]; +uint8_t co0 = *(block); +uint8_t co1 = *(block + 1); +uint8_t cg0 = *(block + 8); +uint8_t cg1 = *(block + 9); +int x, y; + +decompress_indices(co_indices, block + 2); +decompress_indices(cg_indices, block + 10); + +for (y = 0; y < 4; y++) { +for (x = 0; x < 4; x++) { +int co_code = co_indices[x + y * 4]; +int cg_code = cg_indices[x + y * 4]; + +plane0[x] = extract_component(cg0, cg1, cg_code); +plane1[x] = extract_component(co0, co1, co_code); +} +plane0 += stride0; +plane1 += stride1; +} + +return 16; +} + +static void yao_subblock(uint8_t *dst, uint8_t *yo_indices, +ptrdiff_t stride, const uint8_t *block) +{ +uint8_t yo0 = *(block); +uint8_t yo1 = *(block + 1); +int x, y; + +decompress_indices(yo_indices, block + 2); + +for (y = 0; y < 4; y++) { +for (x = 0; x < 4; x++) { +int yo_code = yo_indices[x + y * 4]; + +dst[x] = extract_component(yo0, yo1, yo_code); +} +dst += stride; +} +} + +static int yo_block(uint8_t *dst, ptrdiff_t stride, +uint8_t *unused0, ptrdiff_t unused1, +const uint8_t *block) +{ +uint8_t yo_indices[16]; + +yao_subblock(dst, yo_indices, stride, block); +yao_subblock(dst + 4, yo_indices, stride, block + 8); +yao_subblock(dst + 8, yo_indices, stride, block + 16); +yao_subblock(dst + 12, yo_indices, stride, block + 24); + +return 32; +} + +static int yao_block(uint8_t *plane0, ptrdiff_t stride0, + uint8_t *plane3, ptrdiff_t stride1, + const uint8_t *block) +{ +uint8_t yo_indices[16]; +uint8_t a_indices[16]; + +yao_subblock(plane0, yo_indices, stride0, block); +yao_subblock(plane3, a_indices
Re: [FFmpeg-devel] [PATCH] avcodec/dxv: add support for "high" quality mode
On 4/14/18, Paul B Mahol wrote: > Signed-off-by: Paul B Mahol > --- > libavcodec/dxv.c | 815 > --- > 1 file changed, 780 insertions(+), 35 deletions(-) > Ignore this one. It introduces artifacts. ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
[FFmpeg-devel] [PATCH] avcodec/dxv: add support for "high" quality mode
Signed-off-by: Paul B Mahol --- libavcodec/dxv.c | 815 --- 1 file changed, 780 insertions(+), 35 deletions(-) diff --git a/libavcodec/dxv.c b/libavcodec/dxv.c index 529e211258..a0a3ff0595 100644 --- a/libavcodec/dxv.c +++ b/libavcodec/dxv.c @@ -1,6 +1,7 @@ /* * Resolume DXV decoder * Copyright (C) 2015 Vittorio Giovara + * Copyright (C) 2018 Paul B Mahol * * This file is part of FFmpeg. * @@ -23,6 +24,7 @@ #include "libavutil/imgutils.h" +#include "mathops.h" #include "avcodec.h" #include "bytestream.h" #include "internal.h" @@ -34,50 +36,211 @@ typedef struct DXVContext { TextureDSPContext texdsp; GetByteContext gbc; -uint8_t *tex_data; // Compressed texture -int tex_rat;// Compression ratio -int tex_step; // Distance between blocks -int64_t tex_size; // Texture size +uint8_t *tex_data; // Compressed texture +uint8_t *ctex_data; // Compressed texture +int tex_rat; // Compression ratio +int tex_step;// Distance between blocks +int ctex_step; // Distance between blocks +int64_t tex_size;// Texture size +int64_t ctex_size; // Texture size /* Optimal number of slices for parallel decoding */ int slice_count; +uint8_t *op_data[4]; // Opcodes +int64_t op_size[4]; // Opcodes size + +int texture_block_w; +int texture_block_h; + +int ctexture_block_w; +int ctexture_block_h; + /* Pointer to the selected decompression function */ int (*tex_funct)(uint8_t *dst, ptrdiff_t stride, const uint8_t *block); +int (*tex_funct_planar[2])(uint8_t *plane0, ptrdiff_t stride0, + uint8_t *plane1, ptrdiff_t stride1, + const uint8_t *block); } DXVContext; +static void decompress_indices(uint8_t *dst, const uint8_t *src) +{ +int block, i; + +for (block = 0; block < 2; block++) { +int tmp = AV_RL24(src); + +/* Unpack 8x3 bit from last 3 byte block */ +for (i = 0; i < 8; i++) +dst[i] = (tmp >> (i * 3)) & 0x7; + +src += 3; +dst += 8; +} +} + +static int extract_component(int yo0, int yo1, int code) +{ +int yo; + +if (yo0 == yo1) { +yo = yo0; +} else if (code == 0) { +yo = yo0; +} else if (code == 1) { +yo = yo1; +} else { +if (yo0 > yo1) { +yo = (uint8_t) (((8 - code) * yo0 + + (code - 1) * yo1) / 7); +} else { +if (code == 6) { +yo = 0; +} else if (code == 7) { +yo = 255; +} else { +yo = (uint8_t) (((6 - code) * yo0 + + (code - 1) * yo1) / 5); +} +} +} + +return yo; +} + +static int cocg_block(uint8_t *plane0, ptrdiff_t stride0, + uint8_t *plane1, ptrdiff_t stride1, + const uint8_t *block) +{ +uint8_t co_indices[16]; +uint8_t cg_indices[16]; +uint8_t co0 = *(block); +uint8_t co1 = *(block + 1); +uint8_t cg0 = *(block + 8); +uint8_t cg1 = *(block + 9); +int x, y; + +decompress_indices(co_indices, block + 2); +decompress_indices(cg_indices, block + 10); + +for (y = 0; y < 4; y++) { +for (x = 0; x < 4; x++) { +int co_code = co_indices[x + y * 4]; +int cg_code = cg_indices[x + y * 4]; + +plane0[x] = extract_component(cg0, cg1, cg_code); +plane1[x] = extract_component(co0, co1, co_code); +} +plane0 += stride0; +plane1 += stride1; +} + +return 16; +} + +static void yao_subblock(uint8_t *dst, uint8_t *yo_indices, +ptrdiff_t stride, const uint8_t *block) +{ +uint8_t yo0 = *(block); +uint8_t yo1 = *(block + 1); +int x, y; + +decompress_indices(yo_indices, block + 2); + +for (y = 0; y < 4; y++) { +for (x = 0; x < 4; x++) { +int yo_code = yo_indices[x + y * 4]; + +dst[x] = extract_component(yo0, yo1, yo_code); +} +dst += stride; +} +} + +static int yo_block(uint8_t *dst, ptrdiff_t stride, +uint8_t *unused0, ptrdiff_t unused1, +const uint8_t *block) +{ +uint8_t yo_indices[16]; + +yao_subblock(dst, yo_indices, stride, block); +yao_subblock(dst + 4, yo_indices, stride, block + 8); +yao_subblock(dst + 8, yo_indices, stride, block + 16); +yao_subblock(dst + 12, yo_indices, stride, block + 24); + +return 32; +} + +static int yao_block(uint8_t *plane0, ptrdiff_t stride0, + uint8_t *plane3, ptrdiff_t stride1, + const uint8_t *block) +{ +uint8_t yo_indices[16]; +uint8_t a_indices[16]; + +yao_subblock(plane0, yo_indices, stride0, block); +yao_subblock(plane3, a_indices
Re: [FFmpeg-devel] [PATCH] avcodec/dxv: add support for "high" quality mode
On 12 April 2018 at 17:00, Paul B Mahol wrote: > Signed-off-by: Paul B Mahol > --- > libavcodec/dxv.c | 1038 ++ > ++-- > 1 file changed, 1003 insertions(+), 35 deletions(-) > > diff --git a/libavcodec/dxv.c b/libavcodec/dxv.c > index 529e211258..af8038d377 100644 > --- a/libavcodec/dxv.c > +++ b/libavcodec/dxv.c > @@ -1,6 +1,7 @@ > /* > * Resolume DXV decoder > * Copyright (C) 2015 Vittorio Giovara > + * Copyright (C) 2018 Paul B Mahol > * > * This file is part of FFmpeg. > * > @@ -23,6 +24,7 @@ > > #include "libavutil/imgutils.h" > > +#include "mathops.h" > #include "avcodec.h" > #include "bytestream.h" > #include "internal.h" > @@ -34,50 +36,230 @@ typedef struct DXVContext { > TextureDSPContext texdsp; > GetByteContext gbc; > > -uint8_t *tex_data; // Compressed texture > -int tex_rat;// Compression ratio > -int tex_step; // Distance between blocks > -int64_t tex_size; // Texture size > +uint8_t *tex_data; // Compressed texture > +uint8_t *ctex_data; // Compressed texture > +int tex_rat; // Compression ratio > +int tex_step;// Distance between blocks > +int ctex_step; // Distance between blocks > +int64_t tex_size;// Texture size > +int64_t ctex_size; // Texture size > > /* Optimal number of slices for parallel decoding */ > int slice_count; > > +uint8_t *op_data[4]; // Opcodes > +int64_t op_size[4]; // Opcodes size > + > +int texture_block_w; > +int texture_block_h; > + > +int ctexture_block_w; > +int ctexture_block_h; > + > /* Pointer to the selected decompression function */ > int (*tex_funct)(uint8_t *dst, ptrdiff_t stride, const uint8_t > *block); > +int (*tex_funct_planar[2])(uint8_t *plane0, ptrdiff_t stride0, > + uint8_t *plane1, ptrdiff_t stride1, > + const uint8_t *block); > } DXVContext; > > +static void decompress_indices(uint8_t *dst, const uint8_t *src) > +{ > +int block, i; > + > +for (block = 0; block < 2; block++) { > +int tmp = AV_RL24(src); > + > +/* Unpack 8x3 bit from last 3 byte block */ > +for (i = 0; i < 8; i++) > +dst[i] = (tmp >> (i * 3)) & 0x7; > + > +src += 3; > +dst += 8; > +} > +} > + > +static int extract_component(int yo0, int yo1, int code) > +{ > +int yo; > + > +if (yo0 == yo1) { > +yo = yo0; > +} else if (code == 0) { > +yo = yo0; > +} else if (code == 1) { > +yo = yo1; > +} else { > +if (yo0 > yo1) { > +yo = (uint8_t) (((8 - code) * yo0 + > + (code - 1) * yo1) / 7); > +} else { > +if (code == 6) { > +yo = 0; > +} else if (code == 7) { > +yo = 255; > +} else { > +yo = (uint8_t) (((6 - code) * yo0 + > + (code - 1) * yo1) / 5); > +} > +} > +} > + > +return yo; > +} > + > +static int cocg_block(uint8_t *plane0, ptrdiff_t stride0, > + uint8_t *plane1, ptrdiff_t stride1, > + const uint8_t *block) > +{ > +uint8_t co_indices[16]; > +uint8_t cg_indices[16]; > +uint8_t co0 = *(block); > +uint8_t co1 = *(block + 1); > +uint8_t cg0 = *(block + 8); > +uint8_t cg1 = *(block + 9); > +int x, y; > + > +decompress_indices(co_indices, block + 2); > +decompress_indices(cg_indices, block + 10); > + > +for (y = 0; y < 4; y++) { > +for (x = 0; x < 4; x++) { > +int co_code = co_indices[x + y * 4]; > +int cg_code = cg_indices[x + y * 4]; > + > +plane0[x] = extract_component(cg0, cg1, cg_code); > +plane1[x] = extract_component(co0, co1, co_code); > +} > +plane0 += stride0; > +plane1 += stride1; > +} > + > +return 16; > +} > + > +static void yo_subblock(uint8_t *dst, uint8_t *yo_indices, > +ptrdiff_t stride, const uint8_t *block) > +{ > +uint8_t yo0 = *(block); > +uint8_t yo1 = *(block + 1); > +int x, y; > + > +decompress_indices(yo_indices, block + 2); > + > +for (y = 0; y < 4; y++) { > +for (x = 0; x < 4; x++) { > +int yo_code = yo_indices[x + y * 4]; > + > +dst[x] = extract_component(yo0, yo1, yo_code); > +} > +dst += stride; > +} > +} > + > +static int yo_block(uint8_t *dst, ptrdiff_t stride, > +uint8_t *unused0, ptrdiff_t unused1, > +const uint8_t *block) > +{ > +uint8_t yo_indices[16]; > + > +yo_subblock(dst, yo_indices, stride, block); > +yo_subblock(dst + 4, yo_indices, stride, block + 8); > +yo_subblock(dst + 8, yo_indices, stride, block + 16); > +yo_subblock(dst + 12, yo_indices, s
[FFmpeg-devel] [PATCH] avcodec/dxv: add support for "high" quality mode
Signed-off-by: Paul B Mahol --- libavcodec/dxv.c | 1038 -- 1 file changed, 1003 insertions(+), 35 deletions(-) diff --git a/libavcodec/dxv.c b/libavcodec/dxv.c index 529e211258..af8038d377 100644 --- a/libavcodec/dxv.c +++ b/libavcodec/dxv.c @@ -1,6 +1,7 @@ /* * Resolume DXV decoder * Copyright (C) 2015 Vittorio Giovara + * Copyright (C) 2018 Paul B Mahol * * This file is part of FFmpeg. * @@ -23,6 +24,7 @@ #include "libavutil/imgutils.h" +#include "mathops.h" #include "avcodec.h" #include "bytestream.h" #include "internal.h" @@ -34,50 +36,230 @@ typedef struct DXVContext { TextureDSPContext texdsp; GetByteContext gbc; -uint8_t *tex_data; // Compressed texture -int tex_rat;// Compression ratio -int tex_step; // Distance between blocks -int64_t tex_size; // Texture size +uint8_t *tex_data; // Compressed texture +uint8_t *ctex_data; // Compressed texture +int tex_rat; // Compression ratio +int tex_step;// Distance between blocks +int ctex_step; // Distance between blocks +int64_t tex_size;// Texture size +int64_t ctex_size; // Texture size /* Optimal number of slices for parallel decoding */ int slice_count; +uint8_t *op_data[4]; // Opcodes +int64_t op_size[4]; // Opcodes size + +int texture_block_w; +int texture_block_h; + +int ctexture_block_w; +int ctexture_block_h; + /* Pointer to the selected decompression function */ int (*tex_funct)(uint8_t *dst, ptrdiff_t stride, const uint8_t *block); +int (*tex_funct_planar[2])(uint8_t *plane0, ptrdiff_t stride0, + uint8_t *plane1, ptrdiff_t stride1, + const uint8_t *block); } DXVContext; +static void decompress_indices(uint8_t *dst, const uint8_t *src) +{ +int block, i; + +for (block = 0; block < 2; block++) { +int tmp = AV_RL24(src); + +/* Unpack 8x3 bit from last 3 byte block */ +for (i = 0; i < 8; i++) +dst[i] = (tmp >> (i * 3)) & 0x7; + +src += 3; +dst += 8; +} +} + +static int extract_component(int yo0, int yo1, int code) +{ +int yo; + +if (yo0 == yo1) { +yo = yo0; +} else if (code == 0) { +yo = yo0; +} else if (code == 1) { +yo = yo1; +} else { +if (yo0 > yo1) { +yo = (uint8_t) (((8 - code) * yo0 + + (code - 1) * yo1) / 7); +} else { +if (code == 6) { +yo = 0; +} else if (code == 7) { +yo = 255; +} else { +yo = (uint8_t) (((6 - code) * yo0 + + (code - 1) * yo1) / 5); +} +} +} + +return yo; +} + +static int cocg_block(uint8_t *plane0, ptrdiff_t stride0, + uint8_t *plane1, ptrdiff_t stride1, + const uint8_t *block) +{ +uint8_t co_indices[16]; +uint8_t cg_indices[16]; +uint8_t co0 = *(block); +uint8_t co1 = *(block + 1); +uint8_t cg0 = *(block + 8); +uint8_t cg1 = *(block + 9); +int x, y; + +decompress_indices(co_indices, block + 2); +decompress_indices(cg_indices, block + 10); + +for (y = 0; y < 4; y++) { +for (x = 0; x < 4; x++) { +int co_code = co_indices[x + y * 4]; +int cg_code = cg_indices[x + y * 4]; + +plane0[x] = extract_component(cg0, cg1, cg_code); +plane1[x] = extract_component(co0, co1, co_code); +} +plane0 += stride0; +plane1 += stride1; +} + +return 16; +} + +static void yo_subblock(uint8_t *dst, uint8_t *yo_indices, +ptrdiff_t stride, const uint8_t *block) +{ +uint8_t yo0 = *(block); +uint8_t yo1 = *(block + 1); +int x, y; + +decompress_indices(yo_indices, block + 2); + +for (y = 0; y < 4; y++) { +for (x = 0; x < 4; x++) { +int yo_code = yo_indices[x + y * 4]; + +dst[x] = extract_component(yo0, yo1, yo_code); +} +dst += stride; +} +} + +static int yo_block(uint8_t *dst, ptrdiff_t stride, +uint8_t *unused0, ptrdiff_t unused1, +const uint8_t *block) +{ +uint8_t yo_indices[16]; + +yo_subblock(dst, yo_indices, stride, block); +yo_subblock(dst + 4, yo_indices, stride, block + 8); +yo_subblock(dst + 8, yo_indices, stride, block + 16); +yo_subblock(dst + 12, yo_indices, stride, block + 24); + +return 32; +} + +static void a_subblock(uint8_t *dst, uint8_t *a_indices, + ptrdiff_t stride, const uint8_t *block) +{ +uint8_t a0 = *(block); +uint8_t a1 = *(block + 1); +int x, y; + +decompress_indices(a_indices, block + 2); + +for (y = 0; y < 4; y++) { +for (x = 0; x < 4; x++) { +
Re: [FFmpeg-devel] [PATCH] avcodec/dxv: add support for "high" quality mode
On Thu, 12 Apr 2018 15:49:30 +0200 Michael Niedermayer wrote: > On Thu, Apr 12, 2018 at 01:57:34PM +0100, Rostislav Pehlivanov wrote: > > On 12 April 2018 at 11:31, Paul B Mahol wrote: > > > > > Signed-off-by: Paul B Mahol > > > --- > > > libavcodec/dxv.c | 1006 ++ > > > ++-- > > > 1 file changed, 978 insertions(+), 28 deletions(-) > > > > > > > > > + > > > +static av_always_inline uint32_t yacocg2rgba(int yo, int co, int cg, int > > > a) > > > +{ > > > +int r, g, b; > > > + > > > +co = co - 127; > > > +cg = cg - 127; > > > + > > > +r = av_clip_uint8(yo + co - cg); > > > +g = av_clip_uint8(yo + cg); > > > +b = av_clip_uint8(yo - co - cg); > > > + > > > +return (a << 24) | (b << 16) | (g << 8) | (r); > > > +} > > > > > > Cinepak all over again? We're not doing and are never going to do > > no, its different. > The cinepak case was a volunteer who wanted to maintain the cinepak code, had > a patch that made the decoder several fold faster (in his practical use) and > possibly closer in output to the binary reference. That by doing colorspace > convertion to the vector quantizer data tables IIRC > > He was attacked > cinepak in ffmpeg is unmaintained since then and there has been no further > contribution from him since then either. > > This case here is very different, noone depends on this IIUC. > So i have no strong oppinion on this. > > The mention of cinepak as a "good" example is what makes me a bit upset. > I do not think we should be proud of how that cinepak case was handled. No, he posted a patch that was unacceptable for several reasons. These were pointed out. He then made a drama out of it, implying something about how FFmpeg will fade into irrelevance because Cinepak support is not the "best". And now you drag out this drama, for whatever reason. He also failed to provide explanations why this was supposed to be necessary. Keep in mind that he wanted to decode directly to obscure packed RGB formats and such. Also Cinepak is an obscure garbage codec, so it's not a big loss that it's a bit slower. Nobody complained about Cinepak support ever, except that one guy. ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
Re: [FFmpeg-devel] [PATCH] avcodec/dxv: add support for "high" quality mode
On Thu, 12 Apr 2018 13:57:34 +0100 Rostislav Pehlivanov wrote: > On 12 April 2018 at 11:31, Paul B Mahol wrote: > > > Signed-off-by: Paul B Mahol > > --- > > libavcodec/dxv.c | 1006 ++ > > ++-- > > 1 file changed, 978 insertions(+), 28 deletions(-) > > > > > > + > > +static av_always_inline uint32_t yacocg2rgba(int yo, int co, int cg, int > > a) > > +{ > > +int r, g, b; > > + > > +co = co - 127; > > +cg = cg - 127; > > + > > +r = av_clip_uint8(yo + co - cg); > > +g = av_clip_uint8(yo + cg); > > +b = av_clip_uint8(yo - co - cg); > > + > > +return (a << 24) | (b << 16) | (g << 8) | (r); > > +} > > > Cinepak all over again? We're not doing and are never going to do > conversion inside decoders. Output it as YCoCg by writing directly to the > data planes. We support it. It doesn't matter if it's perfectly mappable to > RGB, if you allow for 2 more bits of precision. +1 > On 12 April 2018 at 11:31, Paul B Mahol wrote: > > > Signed-off-by: Paul B Mahol > > --- > > libavcodec/dxv.c | 1006 ++ > > ++-- > > 1 file changed, 978 insertions(+), 28 deletions(-) > > > > diff --git a/libavcodec/dxv.c b/libavcodec/dxv.c > > index 529e211258..6308163735 100644 > > --- a/libavcodec/dxv.c > > +++ b/libavcodec/dxv.c > > @@ -1,6 +1,7 @@ > > /* > > * Resolume DXV decoder > > * Copyright (C) 2015 Vittorio Giovara > > + * Copyright (C) 2018 Paul B Mahol > > * > > * This file is part of FFmpeg. > > * > > @@ -23,6 +24,7 @@ > > > > #include "libavutil/imgutils.h" > > > > +#include "mathops.h" > > #include "avcodec.h" > > #include "bytestream.h" > > #include "internal.h" > > @@ -34,53 +36,250 @@ typedef struct DXVContext { > > TextureDSPContext texdsp; > > GetByteContext gbc; > > > > -uint8_t *tex_data; // Compressed texture > > -int tex_rat;// Compression ratio > > -int tex_step; // Distance between blocks > > -int64_t tex_size; // Texture size > > +uint8_t *tex_data; // Compressed texture > > +uint8_t *ctex_data; // Compressed texture > > +int tex_rat; // Compression ratio > > +int tex_step;// Distance between blocks > > +int ctex_step; // Distance between blocks > > +int64_t tex_size;// Texture size > > +int64_t ctex_size; // Texture size > > > > /* Optimal number of slices for parallel decoding */ > > int slice_count; > > > > +uint8_t *op_data[4]; // Opcodes > > +int64_t op_size[4]; // Opcodes size > > + > > +int texture_block_w; > > +int texture_block_h; > > + > > +int ctexture_block_w; > > +int ctexture_block_h; > > + > > /* Pointer to the selected decompression function */ > > int (*tex_funct)(uint8_t *dst, ptrdiff_t stride, const uint8_t > > *block); > > +int (*ctex_funct)(uint8_t *dst, ptrdiff_t stride, const uint8_t > > *block); > > } DXVContext; > > > > +static void decompress_indices(uint8_t *dst, const uint8_t *src) > > +{ > > +int block, i; > > + > > +for (block = 0; block < 2; block++) { > > +int tmp = AV_RL24(src); > > + > > +/* Unpack 8x3 bit from last 3 byte block */ > > +for (i = 0; i < 8; i++) > > +dst[i] = (tmp >> (i * 3)) & 0x7; > > + > > +src += 3; > > +dst += 8; > > +} > > +} > > + > > +static int extract_component(int yo0, int yo1, int code) > > +{ > > +int yo; > > + > > +if (yo0 == yo1) { > > +yo = yo0; > > +} else if (code == 0) { > > +yo = yo0; > > +} else if (code == 1) { > > +yo = yo1; > > +} else { > > +if (yo0 > yo1) { > > +yo = (uint8_t) (((8 - code) * yo0 + > > + (code - 1) * yo1) / 7); > > +} else { > > +if (code == 6) { > > +yo = 0; > > +} else if (code == 7) { > > +yo = 255; > > +} else { > > +yo = (uint8_t) (((6 - code) * yo0 + > > + (code - 1) * yo1) / 5); > > +} > > +} > > +} > > + > > +return yo; > > +} > > + > > +static av_always_inline uint32_t yacocg2rgba(int yo, int co, int cg, int > > a) > > +{ > > +int r, g, b; > > + > > +co = co - 127; > > +cg = cg - 127; > > + > > +r = av_clip_uint8(yo + co - cg); > > +g = av_clip_uint8(yo + cg); > > +b = av_clip_uint8(yo - co - cg); > > + > > +return (a << 24) | (b << 16) | (g << 8) | (r); > > +} > > + > > +static int cocg_block(uint8_t *dst, ptrdiff_t stride, > > + const uint8_t *block) > > +{ > > +uint8_t co_indices[16]; > > +uint8_t cg_indices[16]; > > +uint8_t co0 = *(block); > > +uint8_t co1 = *(block + 1); > > +uint8_t cg0 = *(block + 8); > > +uint8_t cg1 = *(block + 9); > > +int x, y; > > + > > +decompress_indices(co_indices, block + 2); > > +decompress_in
Re: [FFmpeg-devel] [PATCH] avcodec/dxv: add support for "high" quality mode
On Thu, Apr 12, 2018 at 02:42:11PM +0200, Paul B Mahol wrote: > Signed-off-by: Paul B Mahol > --- > libavcodec/dxv.c | 1032 > -- > 1 file changed, 1003 insertions(+), 29 deletions(-) > > diff --git a/libavcodec/dxv.c b/libavcodec/dxv.c > index 529e211258..cd7b693663 100644 > --- a/libavcodec/dxv.c > +++ b/libavcodec/dxv.c > @@ -1,6 +1,7 @@ > /* > * Resolume DXV decoder > * Copyright (C) 2015 Vittorio Giovara > + * Copyright (C) 2018 Paul B Mahol > * > * This file is part of FFmpeg. > * [...] > @@ -169,6 +368,728 @@ static int dxv_decompress_dxt1(AVCodecContext *avctx) > return 0; > } > > +typedef struct OpcodeTable { > +int16_t next; > +uint8_t val1; > +uint8_t val2; > +} OpcodeTable; > + > +static int fill_ltable(GetByteContext *gb, uint32_t *table, int *nb_elements) > +{ > +unsigned half = 512, bits = 1023, left = 1024, input, mask; > +int value, counter = 0, rshift = 10, lshift = 30; > + > +mask = bytestream2_get_le32(gb) >> 2; > +while (left) { > +if (bytestream2_get_bytes_left(gb) < 0 || counter >= 256) bytestream2_get_bytes_left returns unsigned so it cannot be negative [...] -- Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB "I am not trying to be anyone's saviour, I'm trying to think about the future and not be sad" - Elon Musk signature.asc Description: PGP signature ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
Re: [FFmpeg-devel] [PATCH] avcodec/dxv: add support for "high" quality mode
On Thu, Apr 12, 2018 at 01:57:34PM +0100, Rostislav Pehlivanov wrote: > On 12 April 2018 at 11:31, Paul B Mahol wrote: > > > Signed-off-by: Paul B Mahol > > --- > > libavcodec/dxv.c | 1006 ++ > > ++-- > > 1 file changed, 978 insertions(+), 28 deletions(-) > > > > > > + > > +static av_always_inline uint32_t yacocg2rgba(int yo, int co, int cg, int > > a) > > +{ > > +int r, g, b; > > + > > +co = co - 127; > > +cg = cg - 127; > > + > > +r = av_clip_uint8(yo + co - cg); > > +g = av_clip_uint8(yo + cg); > > +b = av_clip_uint8(yo - co - cg); > > + > > +return (a << 24) | (b << 16) | (g << 8) | (r); > > +} > > > Cinepak all over again? We're not doing and are never going to do no, its different. The cinepak case was a volunteer who wanted to maintain the cinepak code, had a patch that made the decoder several fold faster (in his practical use) and possibly closer in output to the binary reference. That by doing colorspace convertion to the vector quantizer data tables IIRC He was attacked cinepak in ffmpeg is unmaintained since then and there has been no further contribution from him since then either. This case here is very different, noone depends on this IIUC. So i have no strong oppinion on this. The mention of cinepak as a "good" example is what makes me a bit upset. I do not think we should be proud of how that cinepak case was handled. > conversion inside decoders. Output it as YCoCg by writing directly to the > data planes. We support it. It doesn't matter if it's perfectly mappable to > RGB, if you allow for 2 more bits of precision. Thanks [...] -- Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB The misfortune of the wise is better than the prosperity of the fool. -- Epicurus signature.asc Description: PGP signature ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
Re: [FFmpeg-devel] [PATCH] avcodec/dxv: add support for "high" quality mode
On 4/12/18, Rostislav Pehlivanov wrote: > On 12 April 2018 at 11:31, Paul B Mahol wrote: > >> Signed-off-by: Paul B Mahol >> --- >> libavcodec/dxv.c | 1006 ++ >> ++-- >> 1 file changed, 978 insertions(+), 28 deletions(-) >> >> >> + >> +static av_always_inline uint32_t yacocg2rgba(int yo, int co, int cg, int >> a) >> +{ >> +int r, g, b; >> + >> +co = co - 127; >> +cg = cg - 127; >> + >> +r = av_clip_uint8(yo + co - cg); >> +g = av_clip_uint8(yo + cg); >> +b = av_clip_uint8(yo - co - cg); >> + >> +return (a << 24) | (b << 16) | (g << 8) | (r); >> +} > > > Cinepak all over again? We're not doing and are never going to do > conversion inside decoders. Output it as YCoCg by writing directly to the > data planes. We support it. It doesn't matter if it's perfectly mappable to > RGB, if you allow for 2 more bits of precision. This is subsampled YCgCo, which is never going to be implemented in libswscale. And there is already code in texturedsp which deals with this, but it is for non-subsampled case. ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
Re: [FFmpeg-devel] [PATCH] avcodec/dxv: add support for "high" quality mode
On 12 April 2018 at 11:31, Paul B Mahol wrote: > Signed-off-by: Paul B Mahol > --- > libavcodec/dxv.c | 1006 ++ > ++-- > 1 file changed, 978 insertions(+), 28 deletions(-) > > > + > +static av_always_inline uint32_t yacocg2rgba(int yo, int co, int cg, int > a) > +{ > +int r, g, b; > + > +co = co - 127; > +cg = cg - 127; > + > +r = av_clip_uint8(yo + co - cg); > +g = av_clip_uint8(yo + cg); > +b = av_clip_uint8(yo - co - cg); > + > +return (a << 24) | (b << 16) | (g << 8) | (r); > +} Cinepak all over again? We're not doing and are never going to do conversion inside decoders. Output it as YCoCg by writing directly to the data planes. We support it. It doesn't matter if it's perfectly mappable to RGB, if you allow for 2 more bits of precision. On 12 April 2018 at 11:31, Paul B Mahol wrote: > Signed-off-by: Paul B Mahol > --- > libavcodec/dxv.c | 1006 ++ > ++-- > 1 file changed, 978 insertions(+), 28 deletions(-) > > diff --git a/libavcodec/dxv.c b/libavcodec/dxv.c > index 529e211258..6308163735 100644 > --- a/libavcodec/dxv.c > +++ b/libavcodec/dxv.c > @@ -1,6 +1,7 @@ > /* > * Resolume DXV decoder > * Copyright (C) 2015 Vittorio Giovara > + * Copyright (C) 2018 Paul B Mahol > * > * This file is part of FFmpeg. > * > @@ -23,6 +24,7 @@ > > #include "libavutil/imgutils.h" > > +#include "mathops.h" > #include "avcodec.h" > #include "bytestream.h" > #include "internal.h" > @@ -34,53 +36,250 @@ typedef struct DXVContext { > TextureDSPContext texdsp; > GetByteContext gbc; > > -uint8_t *tex_data; // Compressed texture > -int tex_rat;// Compression ratio > -int tex_step; // Distance between blocks > -int64_t tex_size; // Texture size > +uint8_t *tex_data; // Compressed texture > +uint8_t *ctex_data; // Compressed texture > +int tex_rat; // Compression ratio > +int tex_step;// Distance between blocks > +int ctex_step; // Distance between blocks > +int64_t tex_size;// Texture size > +int64_t ctex_size; // Texture size > > /* Optimal number of slices for parallel decoding */ > int slice_count; > > +uint8_t *op_data[4]; // Opcodes > +int64_t op_size[4]; // Opcodes size > + > +int texture_block_w; > +int texture_block_h; > + > +int ctexture_block_w; > +int ctexture_block_h; > + > /* Pointer to the selected decompression function */ > int (*tex_funct)(uint8_t *dst, ptrdiff_t stride, const uint8_t > *block); > +int (*ctex_funct)(uint8_t *dst, ptrdiff_t stride, const uint8_t > *block); > } DXVContext; > > +static void decompress_indices(uint8_t *dst, const uint8_t *src) > +{ > +int block, i; > + > +for (block = 0; block < 2; block++) { > +int tmp = AV_RL24(src); > + > +/* Unpack 8x3 bit from last 3 byte block */ > +for (i = 0; i < 8; i++) > +dst[i] = (tmp >> (i * 3)) & 0x7; > + > +src += 3; > +dst += 8; > +} > +} > + > +static int extract_component(int yo0, int yo1, int code) > +{ > +int yo; > + > +if (yo0 == yo1) { > +yo = yo0; > +} else if (code == 0) { > +yo = yo0; > +} else if (code == 1) { > +yo = yo1; > +} else { > +if (yo0 > yo1) { > +yo = (uint8_t) (((8 - code) * yo0 + > + (code - 1) * yo1) / 7); > +} else { > +if (code == 6) { > +yo = 0; > +} else if (code == 7) { > +yo = 255; > +} else { > +yo = (uint8_t) (((6 - code) * yo0 + > + (code - 1) * yo1) / 5); > +} > +} > +} > + > +return yo; > +} > + > +static av_always_inline uint32_t yacocg2rgba(int yo, int co, int cg, int > a) > +{ > +int r, g, b; > + > +co = co - 127; > +cg = cg - 127; > + > +r = av_clip_uint8(yo + co - cg); > +g = av_clip_uint8(yo + cg); > +b = av_clip_uint8(yo - co - cg); > + > +return (a << 24) | (b << 16) | (g << 8) | (r); > +} > + > +static int cocg_block(uint8_t *dst, ptrdiff_t stride, > + const uint8_t *block) > +{ > +uint8_t co_indices[16]; > +uint8_t cg_indices[16]; > +uint8_t co0 = *(block); > +uint8_t co1 = *(block + 1); > +uint8_t cg0 = *(block + 8); > +uint8_t cg1 = *(block + 9); > +int x, y; > + > +decompress_indices(co_indices, block + 2); > +decompress_indices(cg_indices, block + 10); > + > +for (y = 0; y < 4; y++) { > +for (x = 0; x < 4; x++) { > +int co_code = co_indices[x + y * 4]; > +int cg_code = cg_indices[x + y * 4]; > +uint8_t co, cg; > + > +co = extract_component(co0, co1, co_code); > +cg = extract_component(cg0, cg1, cg_code); > + > +dst[x * 8 + 1] = co; > +
[FFmpeg-devel] [PATCH] avcodec/dxv: add support for "high" quality mode
Signed-off-by: Paul B Mahol --- libavcodec/dxv.c | 1032 -- 1 file changed, 1003 insertions(+), 29 deletions(-) diff --git a/libavcodec/dxv.c b/libavcodec/dxv.c index 529e211258..cd7b693663 100644 --- a/libavcodec/dxv.c +++ b/libavcodec/dxv.c @@ -1,6 +1,7 @@ /* * Resolume DXV decoder * Copyright (C) 2015 Vittorio Giovara + * Copyright (C) 2018 Paul B Mahol * * This file is part of FFmpeg. * @@ -23,6 +24,7 @@ #include "libavutil/imgutils.h" +#include "mathops.h" #include "avcodec.h" #include "bytestream.h" #include "internal.h" @@ -34,53 +36,250 @@ typedef struct DXVContext { TextureDSPContext texdsp; GetByteContext gbc; -uint8_t *tex_data; // Compressed texture -int tex_rat;// Compression ratio -int tex_step; // Distance between blocks -int64_t tex_size; // Texture size +uint8_t *tex_data; // Compressed texture +uint8_t *ctex_data; // Compressed texture +int tex_rat; // Compression ratio +int tex_step;// Distance between blocks +int ctex_step; // Distance between blocks +int64_t tex_size;// Texture size +int64_t ctex_size; // Texture size /* Optimal number of slices for parallel decoding */ int slice_count; +uint8_t *op_data[4]; // Opcodes +int64_t op_size[4]; // Opcodes size + +int texture_block_w; +int texture_block_h; + +int ctexture_block_w; +int ctexture_block_h; + /* Pointer to the selected decompression function */ int (*tex_funct)(uint8_t *dst, ptrdiff_t stride, const uint8_t *block); +int (*ctex_funct)(uint8_t *dst, ptrdiff_t stride, const uint8_t *block); } DXVContext; +static void decompress_indices(uint8_t *dst, const uint8_t *src) +{ +int block, i; + +for (block = 0; block < 2; block++) { +int tmp = AV_RL24(src); + +/* Unpack 8x3 bit from last 3 byte block */ +for (i = 0; i < 8; i++) +dst[i] = (tmp >> (i * 3)) & 0x7; + +src += 3; +dst += 8; +} +} + +static int extract_component(int yo0, int yo1, int code) +{ +int yo; + +if (yo0 == yo1) { +yo = yo0; +} else if (code == 0) { +yo = yo0; +} else if (code == 1) { +yo = yo1; +} else { +if (yo0 > yo1) { +yo = (uint8_t) (((8 - code) * yo0 + + (code - 1) * yo1) / 7); +} else { +if (code == 6) { +yo = 0; +} else if (code == 7) { +yo = 255; +} else { +yo = (uint8_t) (((6 - code) * yo0 + + (code - 1) * yo1) / 5); +} +} +} + +return yo; +} + +static av_always_inline uint32_t yacocg2rgba(int yo, int co, int cg, int a) +{ +int r, g, b; + +co = co - 127; +cg = cg - 127; + +r = av_clip_uint8(yo + co - cg); +g = av_clip_uint8(yo + cg); +b = av_clip_uint8(yo - co - cg); + +return (a << 24) | (b << 16) | (g << 8) | (r); +} + +static int cocg_block(uint8_t *dst, ptrdiff_t stride, + const uint8_t *block) +{ +uint8_t co_indices[16]; +uint8_t cg_indices[16]; +uint8_t co0 = *(block); +uint8_t co1 = *(block + 1); +uint8_t cg0 = *(block + 8); +uint8_t cg1 = *(block + 9); +int x, y; + +decompress_indices(co_indices, block + 2); +decompress_indices(cg_indices, block + 10); + +for (y = 0; y < 4; y++) { +for (x = 0; x < 4; x++) { +int co_code = co_indices[x + y * 4]; +int cg_code = cg_indices[x + y * 4]; +uint8_t co, cg; + +co = extract_component(co0, co1, co_code); +cg = extract_component(cg0, cg1, cg_code); + +dst[x * 8 + 1] = co; +dst[x * 8 + 2] = cg; +dst[x * 8 + 5] = co; +dst[x * 8 + 6] = cg; +dst[x * 8 + stride + 1] = co; +dst[x * 8 + stride + 2] = cg; +dst[x * 8 + stride + 5] = co; +dst[x * 8 + stride + 6] = cg; +} +dst += 2 * stride; +} + +return 16; +} + +static void yo_subblock(uint8_t *dst, uint8_t *yo_indices, +ptrdiff_t stride, const uint8_t *block) +{ +uint8_t yo0 = *(block); +uint8_t yo1 = *(block + 1); +int x, y; + +decompress_indices(yo_indices, block + 2); + +for (y = 0; y < 4; y++) { +for (x = 0; x < 4; x++) { +int yo_code = yo_indices[x + y * 4]; +uint8_t yo; + +yo = extract_component(yo0, yo1, yo_code); + +AV_WL32(dst + x * 4, 255u << 24 | yo); +} +dst += stride; +} +} + +static int yo_block(uint8_t *dst, ptrdiff_t stride, +const uint8_t *block) +{ +uint8_t yo_indices[16]; + +yo_subblock(dst, yo_indices, stride, block); +yo_subblock(dst + 16, yo_indices, stride, block + 8); +yo_subblock(dst
[FFmpeg-devel] [PATCH] avcodec/dxv: add support for "high" quality mode
Signed-off-by: Paul B Mahol --- libavcodec/dxv.c | 1006 -- 1 file changed, 978 insertions(+), 28 deletions(-) diff --git a/libavcodec/dxv.c b/libavcodec/dxv.c index 529e211258..6308163735 100644 --- a/libavcodec/dxv.c +++ b/libavcodec/dxv.c @@ -1,6 +1,7 @@ /* * Resolume DXV decoder * Copyright (C) 2015 Vittorio Giovara + * Copyright (C) 2018 Paul B Mahol * * This file is part of FFmpeg. * @@ -23,6 +24,7 @@ #include "libavutil/imgutils.h" +#include "mathops.h" #include "avcodec.h" #include "bytestream.h" #include "internal.h" @@ -34,53 +36,250 @@ typedef struct DXVContext { TextureDSPContext texdsp; GetByteContext gbc; -uint8_t *tex_data; // Compressed texture -int tex_rat;// Compression ratio -int tex_step; // Distance between blocks -int64_t tex_size; // Texture size +uint8_t *tex_data; // Compressed texture +uint8_t *ctex_data; // Compressed texture +int tex_rat; // Compression ratio +int tex_step;// Distance between blocks +int ctex_step; // Distance between blocks +int64_t tex_size;// Texture size +int64_t ctex_size; // Texture size /* Optimal number of slices for parallel decoding */ int slice_count; +uint8_t *op_data[4]; // Opcodes +int64_t op_size[4]; // Opcodes size + +int texture_block_w; +int texture_block_h; + +int ctexture_block_w; +int ctexture_block_h; + /* Pointer to the selected decompression function */ int (*tex_funct)(uint8_t *dst, ptrdiff_t stride, const uint8_t *block); +int (*ctex_funct)(uint8_t *dst, ptrdiff_t stride, const uint8_t *block); } DXVContext; +static void decompress_indices(uint8_t *dst, const uint8_t *src) +{ +int block, i; + +for (block = 0; block < 2; block++) { +int tmp = AV_RL24(src); + +/* Unpack 8x3 bit from last 3 byte block */ +for (i = 0; i < 8; i++) +dst[i] = (tmp >> (i * 3)) & 0x7; + +src += 3; +dst += 8; +} +} + +static int extract_component(int yo0, int yo1, int code) +{ +int yo; + +if (yo0 == yo1) { +yo = yo0; +} else if (code == 0) { +yo = yo0; +} else if (code == 1) { +yo = yo1; +} else { +if (yo0 > yo1) { +yo = (uint8_t) (((8 - code) * yo0 + + (code - 1) * yo1) / 7); +} else { +if (code == 6) { +yo = 0; +} else if (code == 7) { +yo = 255; +} else { +yo = (uint8_t) (((6 - code) * yo0 + + (code - 1) * yo1) / 5); +} +} +} + +return yo; +} + +static av_always_inline uint32_t yacocg2rgba(int yo, int co, int cg, int a) +{ +int r, g, b; + +co = co - 127; +cg = cg - 127; + +r = av_clip_uint8(yo + co - cg); +g = av_clip_uint8(yo + cg); +b = av_clip_uint8(yo - co - cg); + +return (a << 24) | (b << 16) | (g << 8) | (r); +} + +static int cocg_block(uint8_t *dst, ptrdiff_t stride, + const uint8_t *block) +{ +uint8_t co_indices[16]; +uint8_t cg_indices[16]; +uint8_t co0 = *(block); +uint8_t co1 = *(block + 1); +uint8_t cg0 = *(block + 8); +uint8_t cg1 = *(block + 9); +int x, y; + +decompress_indices(co_indices, block + 2); +decompress_indices(cg_indices, block + 10); + +for (y = 0; y < 4; y++) { +for (x = 0; x < 4; x++) { +int co_code = co_indices[x + y * 4]; +int cg_code = cg_indices[x + y * 4]; +uint8_t co, cg; + +co = extract_component(co0, co1, co_code); +cg = extract_component(cg0, cg1, cg_code); + +dst[x * 8 + 1] = co; +dst[x * 8 + 2] = cg; +dst[x * 8 + 5] = co; +dst[x * 8 + 6] = cg; +dst[x * 8 + stride + 1] = co; +dst[x * 8 + stride + 2] = cg; +dst[x * 8 + stride + 5] = co; +dst[x * 8 + stride + 6] = cg; +} +dst += 2 * stride; +} + +return 16; +} + +static void yo_subblock(uint8_t *dst, uint8_t *yo_indices, +ptrdiff_t stride, const uint8_t *block) +{ +uint8_t yo0 = *(block); +uint8_t yo1 = *(block + 1); +int x, y; + +decompress_indices(yo_indices, block + 2); + +for (y = 0; y < 4; y++) { +for (x = 0; x < 4; x++) { +int yo_code = yo_indices[x + y * 4]; +uint8_t yo; + +yo = extract_component(yo0, yo1, yo_code); + +AV_WL32(dst + x * 4, 255u << 24 | yo); +} +dst += stride; +} +} + +static int yo_block(uint8_t *dst, ptrdiff_t stride, +const uint8_t *block) +{ +uint8_t yo_indices[16]; + +yo_subblock(dst, yo_indices, stride, block); +yo_subblock(dst + 16, yo_indices, stride, block + 8); +yo_subblock(dst +