Re: [FFmpeg-devel] [PATCH] lavc/tiff: add support for LZMA compression

2014-08-23 Thread Michael Niedermayer
On Sat, Aug 23, 2014 at 11:57:04AM -0300, James Almer wrote:
> On 23/08/14 8:37 AM, Hendrik Leppkes wrote:
> > On Sat, Aug 23, 2014 at 1:31 PM, Michael Niedermayer  
> > wrote:
> >> On Fri, Aug 22, 2014 at 11:39:57PM -0300, James Almer wrote:
> >>> Derived from deflate code.
> >>> Requires liblzma.
> >>>
> >>> Signed-off-by: James Almer 
> >>
> >> how can this be tested ?
> >> do you have a testcase / sample ?
> >>
> > 
> > This image should be lzma compressed:
> > https://www.flameeyes.eu/tmp/imgsrc001-lzma.tiff
> > 
> > - Hendrik
> 
> I get an assertion failure "width <= bytes_per_row" from this file in 
> tiff_unpack_strip(), before the lzma code even comes to play.
> libtiff seems to be able to handle it, though, so could open a ticket in 
> track 
> after this gets committed (Without this patch the decoder just aborts as soon 
> as it finds it's lzma).

applied

assert fixed

thanks

[...]
-- 
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

What does censorship reveal? It reveals fear. -- Julian Assange


signature.asc
Description: Digital signature
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH] lavc/tiff: add support for LZMA compression

2014-08-23 Thread James Almer
On 23/08/14 8:31 AM, Michael Niedermayer wrote:
> On Fri, Aug 22, 2014 at 11:39:57PM -0300, James Almer wrote:
>> Derived from deflate code.
>> Requires liblzma.
>>
>> Signed-off-by: James Almer 
> 
> how can this be tested ?
> do you have a testcase / sample ?

libtiff can create lzma compressed files. You can install xz-utils from most 
linux distros.

I nonetheless uploaded three files to the ftp (rgb, yuv420p and pal8 to 
test all code paths). They are called rgv-3c-8b_lzma.tif, yuv-3c-8b_lzma.tif 
and palette-1c-4b_lzma.tiff
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH] lavc/tiff: add support for LZMA compression

2014-08-23 Thread James Almer
On 23/08/14 8:37 AM, Hendrik Leppkes wrote:
> On Sat, Aug 23, 2014 at 1:31 PM, Michael Niedermayer  wrote:
>> On Fri, Aug 22, 2014 at 11:39:57PM -0300, James Almer wrote:
>>> Derived from deflate code.
>>> Requires liblzma.
>>>
>>> Signed-off-by: James Almer 
>>
>> how can this be tested ?
>> do you have a testcase / sample ?
>>
> 
> This image should be lzma compressed:
> https://www.flameeyes.eu/tmp/imgsrc001-lzma.tiff
> 
> - Hendrik

I get an assertion failure "width <= bytes_per_row" from this file in 
tiff_unpack_strip(), before the lzma code even comes to play.
libtiff seems to be able to handle it, though, so could open a ticket in track 
after this gets committed (Without this patch the decoder just aborts as soon 
as it finds it's lzma).
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH] lavc/tiff: add support for LZMA compression

2014-08-23 Thread Hendrik Leppkes
On Sat, Aug 23, 2014 at 1:31 PM, Michael Niedermayer  wrote:
> On Fri, Aug 22, 2014 at 11:39:57PM -0300, James Almer wrote:
>> Derived from deflate code.
>> Requires liblzma.
>>
>> Signed-off-by: James Almer 
>
> how can this be tested ?
> do you have a testcase / sample ?
>

This image should be lzma compressed:
https://www.flameeyes.eu/tmp/imgsrc001-lzma.tiff

- Hendrik
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH] lavc/tiff: add support for LZMA compression

2014-08-23 Thread Michael Niedermayer
On Fri, Aug 22, 2014 at 11:39:57PM -0300, James Almer wrote:
> Derived from deflate code.
> Requires liblzma.
> 
> Signed-off-by: James Almer 

how can this be tested ?
do you have a testcase / sample ?

[...]
-- 
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

The worst form of inequality is to try to make unequal things equal.
-- Aristotle


signature.asc
Description: Digital signature
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


[FFmpeg-devel] [PATCH] lavc/tiff: add support for LZMA compression

2014-08-22 Thread James Almer
Derived from deflate code.
Requires liblzma.

Signed-off-by: James Almer 
---
 Changelog |  1 +
 configure |  5 +++-
 libavcodec/tiff.c | 85 +--
 3 files changed, 88 insertions(+), 3 deletions(-)

diff --git a/Changelog b/Changelog
index 6260d0c..40d3c79 100644
--- a/Changelog
+++ b/Changelog
@@ -7,6 +7,7 @@ version :
 - large optimizations in dctdnoiz to make it usable
 - request icecast metadata by default
 - support for using metadata in stream specifiers in fftools
+- LZMA compression support in TIFF decoder
 
 
 version 2.3:
diff --git a/configure b/configure
index ffd0436..5af9d36 100755
--- a/configure
+++ b/configure
@@ -253,6 +253,7 @@ External library support:
native MPEG-4/Xvid encoder exists [no]
   --enable-libzmq  enable message passing via libzmq [no]
   --enable-libzvbi enable teletext support via libzvbi [no]
+  --disable-lzma   disable lzma [autodetect]
   --enable-decklinkenable Blackmagick DeckLink output [no]
   --enable-openal  enable OpenAL 1.1 capture support [no]
   --enable-opencl  enable OpenCL code
@@ -1380,6 +1381,7 @@ EXTERNAL_LIBRARY_LIST="
 libxvid
 libzmq
 libzvbi
+lzma
 openal
 opencl
 opengl
@@ -2187,7 +2189,7 @@ svq3_decoder_suggest="zlib"
 tak_decoder_select="audiodsp"
 theora_decoder_select="vp3_decoder"
 thp_decoder_select="mjpeg_decoder"
-tiff_decoder_suggest="zlib"
+tiff_decoder_suggest="zlib lzma"
 tiff_encoder_suggest="zlib"
 truehd_decoder_select="mlp_parser"
 truemotion2_decoder_select="bswapdsp"
@@ -4758,6 +4760,7 @@ fi
 
 disabled  zlib || check_lib   zlib.h  zlibVersion -lz   || disable  zlib
 disabled bzlib || check_lib2 bzlib.h BZ2_bzlibVersion -lbz2 || disable bzlib
+disabled  lzma || check_lib2  lzma.h lzma_version_number -llzma || disable lzma
 
 check_lib math.h sin -lm && LIBM="-lm"
 disabled crystalhd || check_lib libcrystalhd/libcrystalhd_if.h 
DtsCrystalHDVersion -lcrystalhd || disable crystalhd
diff --git a/libavcodec/tiff.c b/libavcodec/tiff.c
index 2bb7c90..613ad3d 100644
--- a/libavcodec/tiff.c
+++ b/libavcodec/tiff.c
@@ -28,6 +28,9 @@
 #if CONFIG_ZLIB
 #include 
 #endif
+#if CONFIG_LZMA
+#include 
+#endif
 
 #include "libavutil/attributes.h"
 #include "libavutil/avstring.h"
@@ -378,6 +381,70 @@ static int tiff_unpack_zlib(TiffContext *s, AVFrame *p, 
uint8_t *dst, int stride
 }
 #endif
 
+#if CONFIG_LZMA
+static int tiff_uncompress_lzma(uint8_t *dst, uint64_t *len, const uint8_t 
*src,
+int size)
+{
+lzma_stream stream = LZMA_STREAM_INIT;
+lzma_ret ret;
+
+stream.next_in   = (uint8_t *)src;
+stream.avail_in  = size;
+stream.next_out  = dst;
+stream.avail_out = *len;
+ret  = lzma_stream_decoder(&stream, UINT64_MAX, 0);
+if (ret != LZMA_OK) {
+av_log(NULL, AV_LOG_ERROR, "LZMA init error: %d\n", ret);
+return ret;
+}
+ret = lzma_code(&stream, LZMA_RUN);
+lzma_end(&stream);
+*len = stream.total_out;
+return ret == LZMA_STREAM_END ? LZMA_OK : ret;
+}
+
+static int tiff_unpack_lzma(TiffContext *s, AVFrame *p, uint8_t *dst, int 
stride,
+const uint8_t *src, int size, int width, int lines,
+int strip_start, int is_yuv)
+{
+uint64_t outlen = width * lines;
+int ret, line;
+uint8_t *buf = av_malloc(outlen);
+if (!buf)
+return AVERROR(ENOMEM);
+if (s->fill_order) {
+if ((ret = deinvert_buffer(s, src, size)) < 0) {
+av_free(buf);
+return ret;
+}
+src = s->deinvert_buf;
+}
+ret = tiff_uncompress_lzma(buf, &outlen, src, size);
+if (ret != LZMA_OK) {
+av_log(s->avctx, AV_LOG_ERROR,
+   "Uncompressing failed (%"PRIu64" of %"PRIu64") with error 
%d\n", outlen,
+   (uint64_t)width * lines, ret);
+av_free(buf);
+return AVERROR_UNKNOWN;
+}
+src = buf;
+for (line = 0; line < lines; line++) {
+if (s->bpp < 8 && s->avctx->pix_fmt == AV_PIX_FMT_PAL8) {
+horizontal_fill(s->bpp, dst, 1, src, 0, width, 0);
+} else {
+memcpy(dst, src, width);
+}
+if (is_yuv) {
+unpack_yuv(s, p, dst, strip_start + line);
+line += s->subsampling[1] - 1;
+}
+dst += stride;
+src += width;
+}
+av_free(buf);
+return 0;
+}
+#endif
 
 static int tiff_unpack_fax(TiffContext *s, uint8_t *dst, int stride,
const uint8_t *src, int size, int width, int lines)
@@ -457,6 +524,16 @@ static int tiff_unpack_strip(TiffContext *s, AVFrame *p, 
uint8_t *dst, int strid
 return AVERROR(ENOSYS);
 #endif
 }
+if (s->compr == TIFF_LZMA) {
+#if CONFIG_LZMA
+return tiff_unpack_lzma(s, p, dst, stride, src, size, width, lines,
+strip_start,