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

« back to all changes in this revision

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

  • Committer: Package Import Robot
  • Author(s): Sebastian Dröge
  • Date: 2013-09-24 17:07:00 UTC
  • mfrom: (1.1.17) (7.1.9 experimental)
  • Revision ID: package-import@ubuntu.com-20130924170700-4dg62s3pwl0pdakz
Tags: 1.2.0-1
* New upstream stable release:
  + debian/control:
    - Build depend on GStreamer and gst-plugins-base >= 1.2.0.

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
 
22
22
#include "avcodec.h"
23
23
#include "bytestream.h"
 
24
#include "internal.h"
24
25
#include "pnm.h"
25
26
 
26
27
 
27
 
static int pam_encode_frame(AVCodecContext *avctx, unsigned char *outbuf,
28
 
                            int buf_size, void *data)
 
28
static int pam_encode_frame(AVCodecContext *avctx, AVPacket *pkt,
 
29
                            const AVFrame *pict, int *got_packet)
29
30
{
30
31
    PNMContext *s     = avctx->priv_data;
31
 
    AVFrame *pict     = data;
32
 
    AVFrame * const p = (AVFrame*)&s->picture;
33
 
    int i, h, w, n, linesize, depth, maxval;
 
32
    AVFrame * const p = &s->picture;
 
33
    int i, h, w, n, linesize, depth, maxval, ret;
34
34
    const char *tuple_type;
35
35
    uint8_t *ptr;
36
36
 
37
 
    if (buf_size < avpicture_get_size(avctx->pix_fmt, avctx->width, avctx->height) + 200) {
 
37
    if ((ret = ff_alloc_packet(pkt, avpicture_get_size(avctx->pix_fmt,
 
38
                                                       avctx->width,
 
39
                                                       avctx->height) + 200)) < 0) {
38
40
        av_log(avctx, AV_LOG_ERROR, "encoded frame too large\n");
39
 
        return -1;
 
41
        return ret;
40
42
    }
41
43
 
42
44
    *p           = *pict;
44
46
    p->key_frame = 1;
45
47
 
46
48
    s->bytestream_start =
47
 
    s->bytestream       = outbuf;
48
 
    s->bytestream_end   = outbuf+buf_size;
 
49
    s->bytestream       = pkt->data;
 
50
    s->bytestream_end   = pkt->data + pkt->size;
49
51
 
50
52
    h = avctx->height;
51
53
    w = avctx->width;
52
54
    switch (avctx->pix_fmt) {
53
 
    case PIX_FMT_MONOWHITE:
 
55
    case AV_PIX_FMT_MONOWHITE:
54
56
        n          = (w + 7) >> 3;
55
57
        depth      = 1;
56
58
        maxval     = 1;
57
59
        tuple_type = "BLACKANDWHITE";
58
60
        break;
59
 
    case PIX_FMT_GRAY8:
 
61
    case AV_PIX_FMT_GRAY8:
60
62
        n          = w;
61
63
        depth      = 1;
62
64
        maxval     = 255;
63
65
        tuple_type = "GRAYSCALE";
64
66
        break;
65
 
    case PIX_FMT_RGB24:
 
67
    case AV_PIX_FMT_RGB24:
66
68
        n          = w * 3;
67
69
        depth      = 3;
68
70
        maxval     = 255;
69
71
        tuple_type = "RGB";
70
72
        break;
71
 
    case PIX_FMT_RGB32:
 
73
    case AV_PIX_FMT_RGB32:
72
74
        n          = w * 4;
73
75
        depth      = 4;
74
76
        maxval     = 255;
78
80
        return -1;
79
81
    }
80
82
    snprintf(s->bytestream, s->bytestream_end - s->bytestream,
81
 
             "P7\nWIDTH %d\nHEIGHT %d\nDEPTH %d\nMAXVAL %d\nTUPLETYPE %s\nENDHDR\n",
 
83
             "P7\nWIDTH %d\nHEIGHT %d\nDEPTH %d\nMAXVAL %d\nTUPLTYPE %s\nENDHDR\n",
82
84
             w, h, depth, maxval, tuple_type);
83
85
    s->bytestream += strlen(s->bytestream);
84
86
 
85
87
    ptr      = p->data[0];
86
88
    linesize = p->linesize[0];
87
89
 
88
 
    if (avctx->pix_fmt == PIX_FMT_RGB32) {
 
90
    if (avctx->pix_fmt == AV_PIX_FMT_RGB32) {
89
91
        int j;
90
92
        unsigned int v;
91
93
 
104
106
            ptr           += linesize;
105
107
        }
106
108
    }
107
 
    return s->bytestream - s->bytestream_start;
 
109
 
 
110
    pkt->size   = s->bytestream - s->bytestream_start;
 
111
    pkt->flags |= AV_PKT_FLAG_KEY;
 
112
    *got_packet = 1;
 
113
    return 0;
108
114
}
109
115
 
110
116
 
111
117
AVCodec ff_pam_encoder = {
112
118
    .name           = "pam",
113
119
    .type           = AVMEDIA_TYPE_VIDEO,
114
 
    .id             = CODEC_ID_PAM,
 
120
    .id             = AV_CODEC_ID_PAM,
115
121
    .priv_data_size = sizeof(PNMContext),
116
122
    .init           = ff_pnm_init,
117
 
    .encode         = pam_encode_frame,
118
 
    .pix_fmts  = (const enum PixelFormat[]){PIX_FMT_RGB24, PIX_FMT_RGB32, PIX_FMT_GRAY8, PIX_FMT_MONOWHITE, PIX_FMT_NONE},
119
 
    .long_name = NULL_IF_CONFIG_SMALL("PAM (Portable AnyMap) image"),
 
123
    .encode2        = pam_encode_frame,
 
124
    .pix_fmts       = (const enum AVPixelFormat[]){
 
125
        AV_PIX_FMT_RGB24, AV_PIX_FMT_RGB32, AV_PIX_FMT_GRAY8, AV_PIX_FMT_MONOWHITE,
 
126
        AV_PIX_FMT_NONE
 
127
    },
 
128
    .long_name      = NULL_IF_CONFIG_SMALL("PAM (Portable AnyMap) image"),
120
129
};