[Ffmpeg-devel] [PATCH] Targa encoder
Michael Niedermayer
michaelni
Fri Mar 16 13:52:59 CET 2007
Hi
On Fri, Mar 16, 2007 at 02:50:32PM +0900, Bobby Bingham wrote:
> Michael Niedermayer wrote:
> >this loop is not optimal
> >for example
> >0 1 1 0
> >would be encoded as 0 0 81 1 0 0 but should be encoded as 3 0 1 1 0
> >
>
> updated patch attached. gives a small size improvement for my test file.
>
> >
> >[...]
> --
> Bobby Bingham
> ??????????????????????????????????????????????????????????????????
> --- libavcodec/targaenc.c 2007-03-16 09:21:32.000000000 +0900
> +++ libavcodec/targaenc.c 2007-03-16 14:41:21.000000000 +0900
> @@ -21,6 +21,88 @@
> */
> #include "avcodec.h"
>
> +/**
> + * Count up to 127 consecutive pixels which are either all the same or
> + * all differ from the previous and next pixels.
> + * @param start Pointer to the first pixel
> + * @param len Maximum number of pixels
> + * @param bpp Bytes per pixel
> + * @param same 1 if searching for identical pixel values. 0 for differing
> + * @return Number of matching consecutive pixels found
> + */
> +static int count_pixels(uint8_t *start, int len, int bpp, int same)
> +{
> + uint8_t *pos;
> + int count = 1;
> +
> + if(len < 2) return len;
> +
> + for(pos = start + bpp; count < FFMIN(128, len); pos += bpp, count ++) {
if len= 1 the function will return 1 without the extra len<2 check
and len<1 should be impossible
> + if(same != !memcmp(pos-bpp, pos, bpp)) {
> + if(!same) {
> + /* if bpp == 1, then 0 1 1 0 is more efficiently encoded as a single
> + * raw block of pixels. for larger bpp, RLE is as good or better */
> + if(bpp == 1 && count > 1 && count + 1 < FFMIN(128, len) && *pos != *(pos+1))
> + continue;
i think count > 1 is always true
and the count + 1 < FFMIN(128, len) check also doesnt seem to change anything
> +
> + /* if RLE can encode the next block better than as a raw block,
> + * back up and leave _all_ the identical pixels for RLE */
> + count --;
> + }
> + break;
> + }
> + }
> +
> + return count;
> +}
wouldnt that encode 0 1 1 1 into 1 0 1 81 1?
instead of 0 0 82 1
[...]
--
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
I have often repented speaking, but never of holding my tongue.
-- Xenocrates
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
URL: <http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/attachments/20070316/02773588/attachment.pgp>
More information about the ffmpeg-devel
mailing list