[FFmpeg-devel] [PATCH] libavcodec/exr.c : A new exr lossy compression technique B44 is added

Michael Niedermayer michaelni at gmx.at
Thu Mar 26 13:11:33 CET 2015


On Thu, Mar 26, 2015 at 01:57:28PM +0530, greeshma wrote:
> Greeshma
> 
> 
> On Wed, Mar 25, 2015 at 10:32 PM, Michael Niedermayer <michaelni at gmx.at>
> wrote:
> 
> > On Tue, Mar 24, 2015 at 04:07:01PM +0530, greeshma wrote:
> > > The patch is made and FATE tests are done.It accepted, will submit with
> > the
> > > copyrights  and signature.The code is written based on openEXR algorithm
> > of
> > > B44 lossy compression and modified according to the FFmpeg code.
> > >
> > >
> > > From 9670e283f38b71c06457c976f3f2040c8d38bbd9 Mon Sep 17 00:00:00 2001
> > > From: greeshmab <greeshmabalabadra at gmail.com>
> > > Date: Tue, 24 Mar 2015 12:36:21 +0530
> > > Subject: [PATCH] A new exr lossy compression technique B44 is added
> > >
> > > ---
> > >  libavcodec/exr.c | 121
> > > +++++++++++++++++++++++++++++++++++++++++++++++++++++++
> > >  1 file changed, 121 insertions(+)
> > >
> > > diff --git a/libavcodec/exr.c b/libavcodec/exr.c
> > > index 6251fb7..b7114be 100644
> > > --- a/libavcodec/exr.c
> > > +++ b/libavcodec/exr.c
> > > @@ -770,6 +770,124 @@ static int piz_uncompress(EXRContext *s, const
> > > uint8_t *src, int ssize,
> > >      return 0;
> > >  }
> > >
> > > +
> > > +static void B44_unpack14 ( GetByteContext *gb, uint16_t out[16]){
> > > +    uint16_t shift;
> > > +    const uint8_t *r = gb->buffer;
> > > +    av_assert0(r[2] != 0xfc);
> > > +    out[0] = (r[0] << 8) | r[1];
> > > +    shift = (r[2] >> 2);
> > > +    out[ 1] = out[ 0] + ((r[ 5] >> 2) << shift);
> > > +    out[ 2] = out[ 1] + ((r[ 8] >> 2) << shift);
> > > +    out[ 3] = out[ 2] + ((r[11] >> 2) << shift);
> > > +    out[ 4] = out[ 0] + (((r[ 2] << 4) | (r[ 3] >> 4)) << shift);
> > > +    out[ 5] = out[ 4] + (((r[ 5] << 4) | (r[ 6] >> 4)) << shift);
> > > +    out[ 6] = out[ 5] + (((r[ 8] << 4) | (r[ 9] >> 4)) << shift);
> > > +    out[ 7] = out[ 6] + (((r[11] << 4) | (r[12] >> 4)) << shift);
> > > +    out[ 8] = out[ 4] + (((r[ 3] << 2) | (r[ 4] >> 6)) << shift);
> > > +    out[ 9] = out[ 8] + (((r[ 6] << 2) | (r[ 7] >> 6)) << shift);
> > > +    out[10] = out[ 9] + (((r[ 9] << 2) | (r[10] >> 6)) << shift);
> > > +    out[11] = out[10] + (((r[12] << 2) | (r[13] >> 6)) << shift);
> > > +    out[12] = out[ 8] + (r[ 4]  << shift);
> > > +    out[13] = out[12] + (r[ 7]  << shift);
> > > +    out[14] = out[13] + (r[10]  << shift);
> > > +    out[15] = out[14] + (r[13]  << shift);
> > > +    for (int i = 0; i < 16; ++i) {              //if any out value
> > exceeds
> > > 16bits
> > > +        if (out[i] & 0x8000)
> >
> > the patch is corrupted by linebreaks, please make sure you attach
> > the patch if you do not use "git send-email -1"
> >
> 
> The linebreaks are modified.

does not apply

Applying: exr lossy compression B44(based on OpenEXR code) Signed-off-by: Greeshma <greeshmabalabadra at gmail.com>
ffmpeg/.git/rebase-apply/patch:98: trailing whitespace.
                    }
fatal: corrupt patch at line 133
Repository lacks necessary blobs to fall back on 3-way merge.
Cannot fall back to three-way merge.
Patch failed at 0001 exr lossy compression B44(based on OpenEXR code) Signed-off-by: Greeshma <greeshmabalabadra at gmail.com>
When you have resolved this problem run "git am --resolved".
If you would prefer to skip this patch, instead run "git am --skip".
To restore the original branch and stop patching run "git am --abort".


> 
> >
> > also, if the code is based on some other implementtaton this should
> > be mentioned in the commit message, you can edit the last commit
> > message with git commit --amend
> >
> > The commit message is changed accordingly
> 
> 
> > also it may be needed to add a copyright statement if code has been
> > used from elsewhere
> >
> > The code is not entirely taken from openEXR.I have just used the algorithm
> they used to compress and wrote unpack technique accordingly.Does this
> require copyright statement for openEXR?

if the code is a clean reimplementation of the algorithm then it is
not required, otherwise it is. IANAL


> 
> The patch is attached.PFA.
> 
> Thanks.
> 
> Thanks
> >
> > [...]
> > --
> > Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
> >
> > You can kill me, but you cannot change the truth.
> >
> > _______________________________________________
> > ffmpeg-devel mailing list
> > ffmpeg-devel at ffmpeg.org
> > http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
> >
> >

>  exr.c |  117 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 117 insertions(+)
> 50ea6668605fe929c255be202a1e092eb9714e9f  0001-exr-lossy-compression-B44-based-on-OpenEXR-code.patch
> From 9ab93eb32d4ee7a8cacc5ce98239dd12bc75bf42 Mon Sep 17 00:00:00 2001
> From: greeshmab <greeshmabalabadra at gmail.com>
> Date: Tue, 24 Mar 2015 12:36:21 +0530
> Subject: [PATCH] exr lossy compression B44(based on OpenEXR code)
>  Signed-off-by: Greeshma <greeshmabalabadra at gmail.com>
> 
> ---
>  libavcodec/exr.c | 121 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 121 insertions(+)
> 
> diff --git a/libavcodec/exr.c b/libavcodec/exr.c
> index 6251fb7..d184fb9 100644
> --- a/libavcodec/exr.c
> +++ b/libavcodec/exr.c
> @@ -770,6 +770,124 @@ static int piz_uncompress(EXRContext *s, const uint8_t *src, int ssize,
>      return 0;
>  }
>  
> +
> +
> +static void B44_unpack14 ( GetByteContext *gb, uint16_t out[16]){
> +    uint16_t shift;
> +    const uint8_t *r = gb->buffer;
> +    av_assert0(r[2] != 0xfc);
> +    out[0] = (r[0] << 8) | r[1];
> +    shift = (r[2] >> 2);
> +    out[ 1] = out[ 0] + ((r[ 5] >> 2) << shift);
> +    out[ 2] = out[ 1] + ((r[ 8] >> 2) << shift);
> +    out[ 3] = out[ 2] + ((r[11] >> 2) << shift);
> +    out[ 4] = out[ 0] + (((r[ 2] << 4) | (r[ 3] >> 4)) << shift);
> +    out[ 5] = out[ 4] + (((r[ 5] << 4) | (r[ 6] >> 4)) << shift);
> +    out[ 6] = out[ 5] + (((r[ 8] << 4) | (r[ 9] >> 4)) << shift);
> +    out[ 7] = out[ 6] + (((r[11] << 4) | (r[12] >> 4)) << shift);
> +    out[ 8] = out[ 4] + (((r[ 3] << 2) | (r[ 4] >> 6)) << shift);
> +    out[ 9] = out[ 8] + (((r[ 6] << 2) | (r[ 7] >> 6)) << shift);
> +    out[10] = out[ 9] + (((r[ 9] << 2) | (r[10] >> 6)) << shift);
> +    out[11] = out[10] + (((r[12] << 2) | (r[13] >> 6)) << shift);
> +    out[12] = out[ 8] + (r[ 4]  << shift);
> +    out[13] = out[12] + (r[ 7]  << shift);
> +    out[14] = out[13] + (r[10]  << shift);
> +    out[15] = out[14] + (r[13]  << shift);
> +    for (int i = 0; i < 16; ++i) {              //if any out value exceeds 16bits
> +        if (out[i] & 0x8000)
> +            out[i] &= 0x7fff;
> +        else
> +            out[i] = ~out[i];
> +    }
> +}
> +
> +
> +static void B44_unpack3 ( GetByteContext *gb, uint16_t out[16]){
> +    const uint8_t *r = gb->buffer;                                       //pixels have the same value
> +    av_assert0(r[2] == 0xfc);
> +    out[0] = (r[0] << 8) | r[1];
> +    if (out[0] & 0x8000)
> +        out[0] &= 0x7fff;
> +    else
> +        out[0] = ~out[0];
> +    for (int i = 1; i < 16; ++i)
> +        out[i] = out[0];
> +}
> +
> +
> +
> +static int b44_uncompress(EXRContext *s, const uint8_t *src,int ssize, int dsize, EXRThreadData *td)
> +
> +{
> +    GetByteContext gb;
> +    unsigned long  dest_len = dsize;
> +    uint8_t *out;
> +    int i, j;
> +    uint16_t *tmp = (uint16_t *)td->tmp;
> +    out = td->uncompressed_data;
> +    bytestream2_init(&gb, src, ssize);
> +    if (uncompress(td->tmp, &dest_len, src, ssize) != Z_OK || dest_len != dsize)
> +        return AVERROR_INVALIDDATA;
> +    for (i = 0; i < s->nb_channels; i++) {
> +        EXRChannel *channel = &s->channels[i];
> +        int size = channel->pixel_type;
> +        int inSize = ssize;
> +        if (channel->pixel_type != EXR_HALF) {              // UINT or FLOAT channel.
> +            int n = s->xdelta * s->ydelta * size * sizeof (*tmp);
> +            memcpy (tmp, gb.buffer, n);
> +            gb.buffer += n;
> +            inSize -= n;
> +            continue;
> +        } else {                                            //EXR_HALF Channel
> +            for (int y=0; y < s->ydelta; y +=4 ) {
> +                uint16_t *row0 = tmp + y * s->xdelta;
> +                uint16_t *row1 = row0 + s->xdelta;
> +                uint16_t *row2 = row1 + s->xdelta;
> +                uint16_t *row3 = row2 + s->xdelta;
> +                for (int x = 0; x < s->xdelta; x += 4) {
> +                    uint16_t out[16];
> +                    int num = (x + 3 < s->xdelta)? 4 * sizeof (*out) : (s->xdelta - x) * sizeof (*out);
> +                    if (gb.buffer[2] == 0xfc) {
> +                        B44_unpack3 (&gb, out);

> +                        gb.buffer += 3;

please use the functions from libavcodec/bytestream.h instead of
directly accessing the fields or dont use GetByteContext

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

Good people do not need laws to tell them to act responsibly, while bad
people will find a way around the laws. -- Plato
-------------- 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/20150326/9f3b4345/attachment.asc>


More information about the ffmpeg-devel mailing list