~ubuntu-branches/ubuntu/saucy/gst-libav1.0/saucy-proposed

« back to all changes in this revision

Viewing changes to gst-libs/ext/libav/libavcodec/ljpegenc.c

  • Committer: Package Import Robot
  • Author(s): Sebastian Dröge
  • Date: 2013-07-30 09:00:15 UTC
  • mfrom: (1.1.16) (7.1.7 experimental)
  • Revision ID: package-import@ubuntu.com-20130730090015-sc1ou2yssu7q5w4e
Tags: 1.1.3-1
* New upstream development snapshot:
  + debian/control:
    - Build depend on GStreamer and gst-plugins-base >= 1.1.3.

Show diffs side-by-side

added added

removed removed

Lines of Context:
32
32
 
33
33
#include "avcodec.h"
34
34
#include "dsputil.h"
 
35
#include "internal.h"
35
36
#include "mpegvideo.h"
36
37
#include "mjpeg.h"
37
38
#include "mjpegenc.h"
38
39
 
39
40
 
40
 
static int encode_picture_lossless(AVCodecContext *avctx, unsigned char *buf, int buf_size, void *data){
 
41
static int encode_picture_lossless(AVCodecContext *avctx, AVPacket *pkt,
 
42
                                   const AVFrame *pict, int *got_packet)
 
43
{
41
44
    MpegEncContext * const s = avctx->priv_data;
42
45
    MJpegContext * const m = s->mjpeg_ctx;
43
 
    AVFrame *pict = data;
44
46
    const int width= s->width;
45
47
    const int height= s->height;
46
 
    AVFrame * const p= (AVFrame*)&s->current_picture;
 
48
    AVFrame * const p = &s->current_picture.f;
47
49
    const int predictor= avctx->prediction_method+1;
48
 
 
49
 
    init_put_bits(&s->pb, buf, buf_size);
 
50
    const int mb_width  = (width  + s->mjpeg_hsample[0] - 1) / s->mjpeg_hsample[0];
 
51
    const int mb_height = (height + s->mjpeg_vsample[0] - 1) / s->mjpeg_vsample[0];
 
52
    int ret, max_pkt_size = FF_MIN_BUFFER_SIZE;
 
53
 
 
54
    if (avctx->pix_fmt == AV_PIX_FMT_BGRA)
 
55
        max_pkt_size += width * height * 3 * 4;
 
56
    else {
 
57
        max_pkt_size += mb_width * mb_height * 3 * 4
 
58
                        * s->mjpeg_hsample[0] * s->mjpeg_vsample[0];
 
59
    }
 
60
    if ((ret = ff_alloc_packet(pkt, max_pkt_size)) < 0) {
 
61
        av_log(avctx, AV_LOG_ERROR, "Error getting output packet of size %d.\n", max_pkt_size);
 
62
        return ret;
 
63
    }
 
64
 
 
65
    init_put_bits(&s->pb, pkt->data, pkt->size);
50
66
 
51
67
    *p = *pict;
52
68
    p->pict_type= AV_PICTURE_TYPE_I;
56
72
 
57
73
    s->header_bits= put_bits_count(&s->pb);
58
74
 
59
 
    if(avctx->pix_fmt == PIX_FMT_BGRA){
 
75
    if(avctx->pix_fmt == AV_PIX_FMT_BGRA){
60
76
        int x, y, i;
61
77
        const int linesize= p->linesize[0];
62
78
        uint16_t (*buffer)[4]= (void *) s->rd_scratchpad;
104
120
        }
105
121
    }else{
106
122
        int mb_x, mb_y, i;
107
 
        const int mb_width  = (width  + s->mjpeg_hsample[0] - 1) / s->mjpeg_hsample[0];
108
 
        const int mb_height = (height + s->mjpeg_vsample[0] - 1) / s->mjpeg_vsample[0];
109
123
 
110
124
        for(mb_y = 0; mb_y < mb_height; mb_y++) {
111
125
            if(s->pb.buf_end - s->pb.buf - (put_bits_count(&s->pb)>>3) < mb_width * 4 * 3 * s->mjpeg_hsample[0] * s->mjpeg_vsample[0]){
160
174
                                int pred;
161
175
 
162
176
                                ptr = p->data[i] + (linesize * (v * mb_y + y)) + (h * mb_x + x); //FIXME optimize this crap
163
 
//printf("%d %d %d %d %8X\n", mb_x, mb_y, x, y, ptr);
164
177
                                PREDICT(pred, ptr[-linesize-1], ptr[-linesize], ptr[-1], predictor);
165
178
 
166
179
                                if(i==0)
181
194
    s->picture_number++;
182
195
 
183
196
    flush_put_bits(&s->pb);
184
 
    return put_bits_ptr(&s->pb) - s->pb.buf;
 
197
    pkt->size   = put_bits_ptr(&s->pb) - s->pb.buf;
 
198
    pkt->flags |= AV_PKT_FLAG_KEY;
 
199
    *got_packet = 1;
 
200
 
 
201
    return 0;
185
202
//    return (put_bits_count(&f->pb)+7)/8;
186
203
}
187
204
 
189
206
AVCodec ff_ljpeg_encoder = { //FIXME avoid MPV_* lossless JPEG should not need them
190
207
    .name           = "ljpeg",
191
208
    .type           = AVMEDIA_TYPE_VIDEO,
192
 
    .id             = CODEC_ID_LJPEG,
 
209
    .id             = AV_CODEC_ID_LJPEG,
193
210
    .priv_data_size = sizeof(MpegEncContext),
194
 
    .init           = MPV_encode_init,
195
 
    .encode         = encode_picture_lossless,
196
 
    .close          = MPV_encode_end,
 
211
    .init           = ff_MPV_encode_init,
 
212
    .encode2        = encode_picture_lossless,
 
213
    .close          = ff_MPV_encode_end,
197
214
    .long_name      = NULL_IF_CONFIG_SMALL("Lossless JPEG"),
198
215
};