[Ffmpeg-devel] [PATCH] TIFF encoder (Google SoC qualification task)

Baptiste Coudurier baptiste.coudurier
Thu Mar 22 17:25:40 CET 2007


Hi

Kamil Nowosad wrote:
> Writing a TIFF encoder is one of your SoC qualification tasks, and I am
> now submitting what i have yet done.
> 
> Apart from libavcodec, I have also updated the libavformat, so that it
> is possible to include many images in one TIFF file.
> Each image is divided into strips [of size ~8kB] and then compressed
> using zlib or [when configured without zlib] packbits compression.
> 
> My TiffEncoderContext is small. I don't really need [yet] more than this
> one field [file_offset]. Is it ok, or should I extend the structure?

Write encoder in separate tiffenc.c.

> It supports now only rgb24 pixel format, but i'm going to change that
> until the deadline.

It's fine to begin with.

> Are there any features that you find especially important to be
> implemented here? I can also improve the decoder. I think I could add
> the multiple_imares_per_one_file support.
> 
> I'm waiting for your suggestions.
> 
> [...]
>
> +static void tiff_put_short(uint8_t **p, uint16_t v)
> +{
> +    *(*p)++ = v;
> +    *(*p)++ = v >> 8;
> +}
> +
> +static void tiff_put_long(uint8_t **p, uint32_t v)
> +{
> +    *(*p)++ = v;
> +    *(*p)++ = v >> 8;
> +    *(*p)++ = v >> 16;
> +    *(*p)++ = v >> 24;
> +} 
> +

see bytestream.h

> +static void tiff_add_ifd_entry(uint8_t **ptr, uint16_t tag, uint16_t type, uint32_t count, uint32_t value)
> +{
> +    tiff_put_short(ptr, tag);
> +    tiff_put_short(ptr, type);
> +    tiff_put_long(ptr, count);
> +    tiff_put_long(ptr, value);
> +}
> +
> +static int tiff_pack_bits(uint8_t *dst, int *dst_len, uint8_t *src, int src_len)
> +{
> +#define MIN(a, b) ((a)<(b) ? (a):(b))

FFMIN

> [...]
> +}
> +
> +static int encode_frame(AVCodecContext *avctx, unsigned char *buf, int buf_size, void *data)
> +{
> +    /* encoding scheme:
> +     *
> +     * *offset of the IFD
> +     * *image data [divided into strips]
> +     * *strip offsets
> +     * *strip sizes
> +     * *bpp info
> +     * *IFD, sorted by tag [excluding the offset of the next IFD 
> +     *  - it will be filled while encoding the next frame or writing the format footer]
> +     */

put comments outside functions in doxygen compatible format.

> [...]
> +   
> +    switch(avctx->pix_fmt){   
> +	case PIX_FMT_RGB24: break;
> +	default: av_log(avctx, AV_LOG_ERROR, "only RGB24 pix_fmt supported\n");
> +		 return -1;
> +    }
> +
> +#define CURR_OFFSET (buf - buf_start + s->file_offset)
> +    buf_start = buf;
> +    buf_end = buf + buf_size;
> +    
> +    entry_point = buf;
> +    buf += 4; // a place for next IFD offset [later overwritten]
> +
> +    /* compute the number of strips */
> +    if (avctx->width == 0 || avctx->height == 0){
> +	num_of_strips = 0;
> +	lines_per_strip = 0;
> +    }
> +    else{
> +	lines_per_strip = (8192 + avctx->width * 3 - 1)/(avctx->width * 3); // =ceil(height/num_of_strips)
> +	num_of_strips = (avctx->height + lines_per_strip - 1)/lines_per_strip;
> +    }

FFmpeg indentation style is 4 spaces.

-- 
Baptiste COUDURIER                              GnuPG Key Id: 0x5C1ABAAA
SMARTJOG S.A.                                    http://www.smartjog.com
Key fingerprint                 8D77134D20CC9220201FC5DB0AC9325C5C1ABAAA
Phone: +33 1 49966312




More information about the ffmpeg-devel mailing list