[Ffmpeg-devel] [PATCH] Targa encoder
Michael Niedermayer
michaelni
Fri Mar 16 03:46:55 CET 2007
Hi
On Fri, Mar 16, 2007 at 09:38:48AM +0900, Bobby Bingham wrote:
> Michael Niedermayer wrote:
> >Hi
> >
> >On Thu, Mar 15, 2007 at 05:57:43PM +0900, Bobby Bingham wrote:
> >>Diego Biurrun wrote:
> >>>On Thu, Mar 15, 2007 at 12:19:41PM +0900, Bobby Bingham wrote:
> >>>>Attached is an updated patch. It adds support for 15 bpp output, as
> >>>>well as RLE compression. It always tries RLE for a frame, and falls
> >>>>back to uncompressed if RLE didn't help or made the size bigger.
> >
> >ive already approved the previous patch and this patch does not fix
> >any critical issues instead it adds several more features which should
> >be in seperate patches
> >or in other words
> >* the original patch should be applied
> >* the quicktime issue is a bug which should be investigated though
> > this is not critical, QT is likely just broken like always but still
> > it would be interresting to figure out where the problem is exactly
> >* 15bpp and RLE support is very welcome but please in a seperate patch
> >
>
> Alright. Here are separate patches for separate features.
:)
> The first
> adds 15-bit support.
looks ok
> The second is cosmetic, and moves the actual
> encoding of the image data to its own function.
looks ok
> The third adds RLE
> encoding support.
[...]
> +
> +/**
> + * RLE compress the image, with maximum size of out_size
> + * @param outbuf Output buffer
> + * @param out_size Maximum output size
> + * @param pic Image to compress
> + * @param bpp Bytes per pixel
> + * @param w Image width
> + * @param h Image height
> + * @return Size of output in bytes, or -1 if larger than out_size
> + */
> +static int targa_encode_rle(uint8_t *outbuf, int out_size, AVFrame *pic,
> + int bpp, int w, int h)
> +{
> + int count, x, y;
> + uint8_t *ptr, *line, *out;
> +
> + out = outbuf;
> + line = pic->data[0];
> +
> + for(y = 0; y < h; y ++) {
> + ptr = line;
> +
> + for(x = 0; x < w; x += count) {
> + /* see if we can encode the next set of pixels with RLE */
> + if((count = count_pixels(ptr, w-x, bpp, 1)) > 1) {
> + *out++ = 0x80 | (count - 1);
> + memcpy(out, ptr, bpp);
> + out += bpp;
> +
> + if(out > outbuf + out_size) return -1;
writing first and checking later is not a good idea unless you know te buffer
is large enough ...
> + } else {
> + /* fall back on uncompressed */
> + count = count_pixels(ptr, w-x, bpp, 0);
> + *out++ = count - 1;
> +
> + if(out + bpp*count > outbuf + out_size) return -1;
> + memcpy(out, ptr, bpp * count);
> + out += bpp * count;
> + }
> + ptr += count * bpp;
> + }
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
[...]
--
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
Freedom in capitalist society always remains about the same as it was in
ancient Greek republics: Freedom for slave owners. -- Vladimir Lenin
-------------- 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/0255b6e5/attachment.pgp>
More information about the ffmpeg-devel
mailing list