- w = width;
- while(left>0) {
-
- put_bits(&p, 9, 0x0100); /* clear code */
-
- for(i=(left<GIF_CHUNKS)?left:GIF_CHUNKS;i;i--) {
- put_bits(&p, 9, *ptr++);
- if (--w == 0) {
- w = width;
- buf += linesize;
- ptr = buf;
- }
- }
-
- if(left<=GIF_CHUNKS) {
- put_bits(&p, 9, 0x101); /* end of stream */
- flush_put_bits(&p);
- }
- if(put_bits_ptr(&p) - p.buf > 0) {
- bytestream_put_byte(bytestream, put_bits_ptr(&p) - p.buf); /* byte count of the packet */
- bytestream_put_buffer(bytestream, p.buf, put_bits_ptr(&p) - p.buf); /* the actual buffer */
- p.buf_ptr = p.buf; /* dequeue the bytes off the bitstream */
- }
- left-=GIF_CHUNKS;
+ for (height = avctx->height; height--;) {
+ len += ff_lzw_encode(s->lzw, ptr, avctx->width);
+ ptr += linesize;
+ }
+ len += ff_lzw_encode_flush(s->lzw, flush_put_bits);
+
+ ptr = s->buf;
+ while (len > 0) {
+ int size = FFMIN(255, len);
+ bytestream_put_byte(bytestream, size);
+ if (end - *bytestream < size)
+ return -1;
+ bytestream_put_buffer(bytestream, ptr, size);
+ ptr += size;
+ len -= size;