[FFmpeg-cvslog] exr: zip decompression
Reimar Döffinger
Reimar.Doeffinger at gmx.de
Sun Jul 15 12:59:42 CEST 2012
On Wed, Jul 11, 2012 at 11:00:34PM +0200, Paul B Mahol wrote:
> +static void predictor(uint8_t *src, int size)
> +{
> + uint8_t *t = src + 1;
> + uint8_t *stop = src + size;
> +
> + while (t < stop) {
> + int d = (int)t[-1] + (int)t[0] - 128;
> + t[0] = d;
> + ++t;
The casts are double pointless: First by the C standard
int is used for the calculations anyway, and then it doesn't
matter since the result type is uint8_t anyway.
The whole thing could be reduced to
*t++ += t[-1] - 128;
Also the - could be replaced by + or ^, no idea if that is relevantly
better.
Smaller aside: Some compilers can also optimize ordinary for-loops easier,
so I at least stopped writing loops like that unless I can see it
make a real difference.
> + const int8_t *t1 = src;
> + const int8_t *t2 = src + (size + 1) / 2;
> + int8_t *s = dst;
> + int8_t *stop = s + size;
> +
> + while (1) {
> + if (s < stop)
> + *(s++) = *(t1++);
> + else
> + break;
> +
> + if (s < stop)
> + *(s++) = *(t2++);
> + else
> + break;
> + }
Personally I find the () confusing, because almost nobody uses them for
this case...
I think it would be smaller and clearer as
while (s < stop) {
*s++ = *t1++;
if (s >= stop)
break;
*s++ = *t2++;
}
> @@ -478,17 +582,23 @@ static int decode_frame(AVCodecContext *avctx,
> static av_cold int decode_init(AVCodecContext *avctx)
> {
> EXRContext *s = avctx->priv_data;
> +
> avcodec_get_frame_defaults(&s->picture);
> avctx->coded_frame = &s->picture;
> +
> return 0;
> }
>
> static av_cold int decode_end(AVCodecContext *avctx)
> {
> EXRContext *s = avctx->priv_data;
> +
Not a big deal but please try to avoid the unrelated cosmetics
in the same patch.
More information about the ffmpeg-cvslog
mailing list