~ppsspp/ppsspp/ffmpeg

« back to all changes in this revision

Viewing changes to libavcodec/pnmenc.c

  • Committer: Henrik Rydgård
  • Date: 2014-01-03 10:44:32 UTC
  • Revision ID: git-v1:87c6c126784b1718bfa448ecf2e6a9fef781eb4e
Update our ffmpeg snapshot to a clone of the official repository.

This is because Maxim's at3plus support has been officially merged!

Show diffs side-by-side

added added

removed removed

Lines of Context:
22
22
#include "libavutil/pixdesc.h"
23
23
#include "avcodec.h"
24
24
#include "internal.h"
25
 
#include "pnm.h"
26
 
 
27
25
 
28
26
static int pnm_encode_frame(AVCodecContext *avctx, AVPacket *pkt,
29
27
                            const AVFrame *p, int *got_packet)
30
28
{
31
 
    PNMContext *s     = avctx->priv_data;
 
29
    uint8_t *bytestream, *bytestream_start, *bytestream_end;
32
30
    int i, h, h1, c, n, linesize, ret;
33
31
    uint8_t *ptr, *ptr1, *ptr2;
34
32
 
37
35
                                                       avctx->height) + 200)) < 0)
38
36
        return ret;
39
37
 
40
 
    s->bytestream_start =
41
 
    s->bytestream       = pkt->data;
42
 
    s->bytestream_end   = pkt->data + pkt->size;
 
38
    bytestream_start =
 
39
    bytestream       = pkt->data;
 
40
    bytestream_end   = pkt->data + pkt->size;
43
41
 
44
42
    h  = avctx->height;
45
43
    h1 = h;
81
79
    default:
82
80
        return -1;
83
81
    }
84
 
    snprintf(s->bytestream, s->bytestream_end - s->bytestream,
 
82
    snprintf(bytestream, bytestream_end - bytestream,
85
83
             "P%c\n%d %d\n", c, avctx->width, h1);
86
 
    s->bytestream += strlen(s->bytestream);
 
84
    bytestream += strlen(bytestream);
87
85
    if (avctx->pix_fmt != AV_PIX_FMT_MONOWHITE) {
88
86
        int maxdepth = (1 << (av_pix_fmt_desc_get(avctx->pix_fmt)->comp[0].depth_minus1 + 1)) - 1;
89
 
        snprintf(s->bytestream, s->bytestream_end - s->bytestream,
 
87
        snprintf(bytestream, bytestream_end - bytestream,
90
88
                 "%d\n", maxdepth);
91
 
        s->bytestream += strlen(s->bytestream);
 
89
        bytestream += strlen(bytestream);
92
90
    }
93
91
 
94
92
    ptr      = p->data[0];
95
93
    linesize = p->linesize[0];
96
94
    for (i = 0; i < h; i++) {
97
 
        memcpy(s->bytestream, ptr, n);
98
 
        s->bytestream += n;
99
 
        ptr           += linesize;
 
95
        memcpy(bytestream, ptr, n);
 
96
        bytestream += n;
 
97
        ptr        += linesize;
100
98
    }
101
99
 
102
100
    if (avctx->pix_fmt == AV_PIX_FMT_YUV420P || avctx->pix_fmt == AV_PIX_FMT_YUV420P16BE) {
105
103
        ptr1 = p->data[1];
106
104
        ptr2 = p->data[2];
107
105
        for (i = 0; i < h; i++) {
108
 
            memcpy(s->bytestream, ptr1, n);
109
 
            s->bytestream += n;
110
 
            memcpy(s->bytestream, ptr2, n);
111
 
            s->bytestream += n;
 
106
            memcpy(bytestream, ptr1, n);
 
107
            bytestream += n;
 
108
            memcpy(bytestream, ptr2, n);
 
109
            bytestream += n;
112
110
                ptr1 += p->linesize[1];
113
111
                ptr2 += p->linesize[2];
114
112
        }
115
113
    }
116
 
    pkt->size   = s->bytestream - s->bytestream_start;
 
114
    pkt->size   = bytestream - bytestream_start;
117
115
    pkt->flags |= AV_PKT_FLAG_KEY;
118
116
    *got_packet = 1;
119
117
 
120
118
    return 0;
121
119
}
122
120
 
 
121
static av_cold int pnm_encode_init(AVCodecContext *avctx)
 
122
{
 
123
    avctx->coded_frame = av_frame_alloc();
 
124
    if (!avctx->coded_frame)
 
125
        return AVERROR(ENOMEM);
 
126
 
 
127
    avctx->coded_frame->pict_type = AV_PICTURE_TYPE_I;
 
128
    avctx->coded_frame->key_frame = 1;
 
129
 
 
130
    return 0;
 
131
}
 
132
 
 
133
static av_cold int pnm_encode_close(AVCodecContext *avctx)
 
134
{
 
135
    av_frame_free(&avctx->coded_frame);
 
136
    return 0;
 
137
}
123
138
 
124
139
#if CONFIG_PGM_ENCODER
125
140
AVCodec ff_pgm_encoder = {
127
142
    .long_name      = NULL_IF_CONFIG_SMALL("PGM (Portable GrayMap) image"),
128
143
    .type           = AVMEDIA_TYPE_VIDEO,
129
144
    .id             = AV_CODEC_ID_PGM,
130
 
    .priv_data_size = sizeof(PNMContext),
 
145
    .init           = pnm_encode_init,
 
146
    .close          = pnm_encode_close,
131
147
    .encode2        = pnm_encode_frame,
132
148
    .pix_fmts       = (const enum AVPixelFormat[]){
133
149
        AV_PIX_FMT_GRAY8, AV_PIX_FMT_GRAY16BE, AV_PIX_FMT_NONE
141
157
    .long_name      = NULL_IF_CONFIG_SMALL("PGMYUV (Portable GrayMap YUV) image"),
142
158
    .type           = AVMEDIA_TYPE_VIDEO,
143
159
    .id             = AV_CODEC_ID_PGMYUV,
144
 
    .priv_data_size = sizeof(PNMContext),
 
160
    .init           = pnm_encode_init,
 
161
    .close          = pnm_encode_close,
145
162
    .encode2        = pnm_encode_frame,
146
163
    .pix_fmts       = (const enum AVPixelFormat[]){
147
164
        AV_PIX_FMT_YUV420P, AV_PIX_FMT_YUV420P16BE, AV_PIX_FMT_NONE
155
172
    .long_name      = NULL_IF_CONFIG_SMALL("PPM (Portable PixelMap) image"),
156
173
    .type           = AVMEDIA_TYPE_VIDEO,
157
174
    .id             = AV_CODEC_ID_PPM,
158
 
    .priv_data_size = sizeof(PNMContext),
 
175
    .init           = pnm_encode_init,
 
176
    .close          = pnm_encode_close,
159
177
    .encode2        = pnm_encode_frame,
160
178
    .pix_fmts       = (const enum AVPixelFormat[]){
161
179
        AV_PIX_FMT_RGB24, AV_PIX_FMT_RGB48BE, AV_PIX_FMT_NONE
169
187
    .long_name      = NULL_IF_CONFIG_SMALL("PBM (Portable BitMap) image"),
170
188
    .type           = AVMEDIA_TYPE_VIDEO,
171
189
    .id             = AV_CODEC_ID_PBM,
172
 
    .priv_data_size = sizeof(PNMContext),
 
190
    .init           = pnm_encode_init,
 
191
    .close          = pnm_encode_close,
173
192
    .encode2        = pnm_encode_frame,
174
193
    .pix_fmts       = (const enum AVPixelFormat[]){ AV_PIX_FMT_MONOWHITE,
175
194
                                                  AV_PIX_FMT_NONE },