[FFmpeg-devel] sgi without rle

Anne-Laure de Smit annelaure.desmit
Fri Sep 18 13:51:27 CEST 2009


Hi,

I modify the function encode_frame:

static int encode_frame(AVCodecContext *avctx, unsigned char *buf,
                        int buf_size, void *data) {
    SgiContext *s = avctx->priv_data;
    AVFrame * const p = &s->picture;
    uint8_t *offsettab, *lengthtab, *in_buf, *encode_buf;
    int x, y, z, length, tablesize;
    unsigned int width, height, depth, dimension;
    unsigned char *orig_buf = buf, *end_buf = buf + buf_size;

    *p = *(AVFrame*)data;
    p->pict_type = FF_I_TYPE;
    p->key_frame = 1;

    width = avctx->width;
    height = avctx->height;

    switch (avctx->pix_fmt) {
        case PIX_FMT_GRAY8:
            dimension = SGI_SINGLE_CHAN;
            depth = SGI_GRAYSCALE;
            break;
        case PIX_FMT_RGB24:
            dimension = SGI_MULTI_CHAN;
            depth = SGI_RGB;
            break;
        case PIX_FMT_RGBA:
            dimension = SGI_MULTI_CHAN;
            depth = SGI_RGBA;
            break;
        default:
            return AVERROR_INVALIDDATA;
    }

    tablesize = depth * height * 4;
    length = tablesize * 2 + SGI_HEADER_SIZE;

    if (buf_size < length) {
        av_log(avctx, AV_LOG_ERROR, "buf_size too small(need %d, got %d)\n",
length, buf_size);
        return -1;
    }

    /* Encode header. */
    bytestream_put_be16(&buf, SGI_MAGIC);
    bytestream_put_byte(&buf, 0); /* RLE */
    bytestream_put_byte(&buf, 1); /* bytes_per_channel */
    bytestream_put_be16(&buf, dimension);
    bytestream_put_be16(&buf, width);
    bytestream_put_be16(&buf, height);
    bytestream_put_be16(&buf, depth);

    /* The rest are constant in this implementation. */
    bytestream_put_be32(&buf, 0L); /* pixmin */
    bytestream_put_be32(&buf, 255L); /* pixmax */
    bytestream_put_be32(&buf, 0L); /* dummy */

    /* name */
    memset(buf, 0, SGI_HEADER_SIZE);
    buf += 80;

     /* colormap */
    bytestream_put_be32(&buf, 0L);

    /* The rest of the 512 byte header is unused. */
    buf += 404;
    offsettab = buf;

    /* Skip RLE offset table. */
    buf += tablesize;
    lengthtab = buf;

    /* Skip RLE length table. */
    buf += tablesize;

    /* Make an intermediate consecutive buffer. */
   // if ((encode_buf = av_malloc(width)) == NULL)
     //   return -1;

    for (z = 0; z < depth; z++) {
        in_buf = p->data[0] + p->linesize[0] * (height - 1) + z;

        for (y = 0; y < height; y++) {
            bytestream_put_be32(&offsettab, buf - orig_buf);

            for (x = 0; x < width; x++)
            {
                //encode_buf[x] = in_buf[depth * x];
                //*buf=encode_buf[x];
                bytestream_put_byte(&buf,in_buf[depth * x]);
                //buf++;
            }

           /* if((length = ff_rle_encode(buf, end_buf - buf - 1, encode_buf,
1, width, 0, 0, 0x80, 0)) < 1) {
                av_free(encode_buf);
                return -1;
            }*/
            length=width;
            //buf += length;
            //bytestream_put_byte(&buf, 0);
            bytestream_put_be32(&lengthtab, length );
            in_buf -= p->linesize[0];
        }
    }

   // av_free(encode_buf);
    /* total length */
    return buf - orig_buf;
}

but I have a problem in the frame.
Maybe you can see where is the problem.

Thank you very much for your help.

AL.

On Thu, Sep 17, 2009 at 11:40 PM, Vitor Sessak <vitor1001 at gmail.com> wrote:

> Anne-Laure de Smit wrote:
>
>> Hi,
>>
>> I want to modify sgienc.c for that image sgi are not compressed (without
>> rle). How can I do this?
>>
>
> First of all, look at sgidec.c to see in what compressed and uncompressed
> sgi images differs (and how uncompressed data is stored). Then, you need a
> way to specify through the command line if the user want compression or not.
> I suggest  "-compression_level" command line parameter that will set
> avctx->compression_level (as is done in tiffenc.c). Then, finally, in
> encode_frame(), just write the uncompressed data to the buffer if the
> avctx->compression_level is set to zero.
>
> -Vitor
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel at mplayerhq.hu
> https://lists.mplayerhq.hu/mailman/listinfo/ffmpeg-devel
>



More information about the ffmpeg-devel mailing list