[FFmpeg-devel] [PATCH] lavf/tiff: add support for YUV deflate
Michael Niedermayer
michaelni at gmx.at
Tue Aug 19 12:07:14 CEST 2014
On Tue, Aug 19, 2014 at 01:54:58AM -0300, James Almer wrote:
> Signed-off-by: James Almer <jamrial at gmail.com>
> ---
> Seems to work great with yuv deflate tiff images created with our tiff encoder
>
> libavcodec/tiff.c | 71 +++++++++++++++++++++++++++----------------------------
> 1 file changed, 35 insertions(+), 36 deletions(-)
>
> diff --git a/libavcodec/tiff.c b/libavcodec/tiff.c
> index 73bf828..7acfe7b 100644
> --- a/libavcodec/tiff.c
> +++ b/libavcodec/tiff.c
> @@ -283,6 +283,34 @@ static int deinvert_buffer(TiffContext *s, const uint8_t *src, int size)
> return 0;
> }
>
> +static void unpack_yuv(TiffContext *s, AVFrame *p,
> + const uint8_t *src, int lnum)
> +{
> + int i, j, k;
> + int w = (s->width - 1) / s->subsampling[0] + 1;
> + uint8_t *pu = &p->data[1][lnum / s->subsampling[1] * p->linesize[1]];
> + uint8_t *pv = &p->data[2][lnum / s->subsampling[1] * p->linesize[2]];
> + if (s->width % s->subsampling[0] || s->height % s->subsampling[1]) {
> + for (i = 0; i < w; i++) {
> + for (j = 0; j < s->subsampling[1]; j++)
> + for (k = 0; k < s->subsampling[0]; k++)
> + p->data[0][FFMIN(lnum + j, s->height-1) * p->linesize[0] +
> + FFMIN(i * s->subsampling[0] + k, s->width-1)] = *src++;
> + *pu++ = *src++;
> + *pv++ = *src++;
> + }
> + }else{
> + for (i = 0; i < w; i++) {
> + for (j = 0; j < s->subsampling[1]; j++)
> + for (k = 0; k < s->subsampling[0]; k++)
> + p->data[0][(lnum + j) * p->linesize[0] +
> + i * s->subsampling[0] + k] = *src++;
> + *pu++ = *src++;
> + *pv++ = *src++;
> + }
> + }
> +}
> +
> #if CONFIG_ZLIB
> static int tiff_uncompress(uint8_t *dst, unsigned long *len, const uint8_t *src,
> int size)
> @@ -305,9 +333,9 @@ static int tiff_uncompress(uint8_t *dst, unsigned long *len, const uint8_t *src,
> return zret == Z_STREAM_END ? Z_OK : zret;
> }
>
> -static int tiff_unpack_zlib(TiffContext *s, uint8_t *dst, int stride,
> +static int tiff_unpack_zlib(TiffContext *s, AVFrame *p, uint8_t *dst, int stride,
> const uint8_t *src, int size,
> - int width, int lines)
> + int width, int lines, int strip_start)
> {
> uint8_t *zbuf;
> unsigned long outlen;
> @@ -338,6 +366,10 @@ static int tiff_unpack_zlib(TiffContext *s, uint8_t *dst, int stride,
> } else {
> memcpy(dst, src, width);
> }
> + if (s->photometric == TIFF_PHOTOMETRIC_YCBCR) {
> + unpack_yuv(s, p, dst, strip_start + line);
> + line += s->subsampling[1] - 1;
> + }
is photometric guranteed to match the pix_fmt ?
iam asking as i dont see that being ensured by the code but i might
be missing something
if they could mismatch, id assume it might crash
[...]
--
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
The real ebay dictionary, page 2
"100% positive feedback" - "All either got their money back or didnt complain"
"Best seller ever, very honest" - "Seller refunded buyer after failed scam"
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 181 bytes
Desc: Digital signature
URL: <https://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20140819/84ad9e7c/attachment.asc>
More information about the ffmpeg-devel
mailing list