annotate pamenc.c @ 11279:08fdccf61a03 libavcodec

Fix doxy and assert().
author michael
date Wed, 24 Feb 2010 22:05:51 +0000
parents 64ffd3bcd73e
children 8a4984c5cacc
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2344
f09680c5e8f4 move p*m from image/lavf -> image2/lavc
michael
parents:
diff changeset
1 /*
10466
64ffd3bcd73e Split PAM encoder off into its own file.
diego
parents: 10465
diff changeset
2 * PAM image format
8629
04423b2f6e0b cosmetics: Remove pointless period after copyright statement non-sentences.
diego
parents: 8590
diff changeset
3 * Copyright (c) 2002, 2003 Fabrice Bellard
2344
f09680c5e8f4 move p*m from image/lavf -> image2/lavc
michael
parents:
diff changeset
4 *
3947
c8c591fe26f8 Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 3455
diff changeset
5 * This file is part of FFmpeg.
c8c591fe26f8 Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 3455
diff changeset
6 *
c8c591fe26f8 Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 3455
diff changeset
7 * FFmpeg is free software; you can redistribute it and/or
2344
f09680c5e8f4 move p*m from image/lavf -> image2/lavc
michael
parents:
diff changeset
8 * modify it under the terms of the GNU Lesser General Public
f09680c5e8f4 move p*m from image/lavf -> image2/lavc
michael
parents:
diff changeset
9 * License as published by the Free Software Foundation; either
3947
c8c591fe26f8 Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 3455
diff changeset
10 * version 2.1 of the License, or (at your option) any later version.
2344
f09680c5e8f4 move p*m from image/lavf -> image2/lavc
michael
parents:
diff changeset
11 *
3947
c8c591fe26f8 Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 3455
diff changeset
12 * FFmpeg is distributed in the hope that it will be useful,
2344
f09680c5e8f4 move p*m from image/lavf -> image2/lavc
michael
parents:
diff changeset
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
f09680c5e8f4 move p*m from image/lavf -> image2/lavc
michael
parents:
diff changeset
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
f09680c5e8f4 move p*m from image/lavf -> image2/lavc
michael
parents:
diff changeset
15 * Lesser General Public License for more details.
f09680c5e8f4 move p*m from image/lavf -> image2/lavc
michael
parents:
diff changeset
16 *
f09680c5e8f4 move p*m from image/lavf -> image2/lavc
michael
parents:
diff changeset
17 * You should have received a copy of the GNU Lesser General Public
3947
c8c591fe26f8 Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 3455
diff changeset
18 * License along with FFmpeg; if not, write to the Free Software
3036
0b546eab515d Update licensing information: The FSF changed postal address.
diego
parents: 2967
diff changeset
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
2344
f09680c5e8f4 move p*m from image/lavf -> image2/lavc
michael
parents:
diff changeset
20 */
10459
a6bb56636f90 whitespace cosmetics: K&R coding style, prettyprinting
diego
parents: 10458
diff changeset
21
2344
f09680c5e8f4 move p*m from image/lavf -> image2/lavc
michael
parents:
diff changeset
22 #include "avcodec.h"
5089
bff60ecc02f9 Use AV_xx throughout libavcodec
ramiro
parents: 4985
diff changeset
23 #include "bytestream.h"
4978
95934eef9589 move pnm parser in its own file
aurel
parents: 4931
diff changeset
24 #include "pnm.h"
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2864
diff changeset
25
2344
f09680c5e8f4 move p*m from image/lavf -> image2/lavc
michael
parents:
diff changeset
26
10459
a6bb56636f90 whitespace cosmetics: K&R coding style, prettyprinting
diego
parents: 10458
diff changeset
27 static int pam_encode_frame(AVCodecContext *avctx, unsigned char *outbuf,
a6bb56636f90 whitespace cosmetics: K&R coding style, prettyprinting
diego
parents: 10458
diff changeset
28 int buf_size, void *data)
a6bb56636f90 whitespace cosmetics: K&R coding style, prettyprinting
diego
parents: 10458
diff changeset
29 {
a6bb56636f90 whitespace cosmetics: K&R coding style, prettyprinting
diego
parents: 10458
diff changeset
30 PNMContext *s = avctx->priv_data;
a6bb56636f90 whitespace cosmetics: K&R coding style, prettyprinting
diego
parents: 10458
diff changeset
31 AVFrame *pict = data;
a6bb56636f90 whitespace cosmetics: K&R coding style, prettyprinting
diego
parents: 10458
diff changeset
32 AVFrame * const p = (AVFrame*)&s->picture;
2344
f09680c5e8f4 move p*m from image/lavf -> image2/lavc
michael
parents:
diff changeset
33 int i, h, w, n, linesize, depth, maxval;
f09680c5e8f4 move p*m from image/lavf -> image2/lavc
michael
parents:
diff changeset
34 const char *tuple_type;
f09680c5e8f4 move p*m from image/lavf -> image2/lavc
michael
parents:
diff changeset
35 uint8_t *ptr;
f09680c5e8f4 move p*m from image/lavf -> image2/lavc
michael
parents:
diff changeset
36
10459
a6bb56636f90 whitespace cosmetics: K&R coding style, prettyprinting
diego
parents: 10458
diff changeset
37 if (buf_size < avpicture_get_size(avctx->pix_fmt, avctx->width, avctx->height) + 200) {
2422
18b8b2dcc037 various security fixes and precautionary checks
michael
parents: 2349
diff changeset
38 av_log(avctx, AV_LOG_ERROR, "encoded frame too large\n");
18b8b2dcc037 various security fixes and precautionary checks
michael
parents: 2349
diff changeset
39 return -1;
18b8b2dcc037 various security fixes and precautionary checks
michael
parents: 2349
diff changeset
40 }
18b8b2dcc037 various security fixes and precautionary checks
michael
parents: 2349
diff changeset
41
10459
a6bb56636f90 whitespace cosmetics: K&R coding style, prettyprinting
diego
parents: 10458
diff changeset
42 *p = *pict;
a6bb56636f90 whitespace cosmetics: K&R coding style, prettyprinting
diego
parents: 10458
diff changeset
43 p->pict_type = FF_I_TYPE;
a6bb56636f90 whitespace cosmetics: K&R coding style, prettyprinting
diego
parents: 10458
diff changeset
44 p->key_frame = 1;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2864
diff changeset
45
10459
a6bb56636f90 whitespace cosmetics: K&R coding style, prettyprinting
diego
parents: 10458
diff changeset
46 s->bytestream_start =
a6bb56636f90 whitespace cosmetics: K&R coding style, prettyprinting
diego
parents: 10458
diff changeset
47 s->bytestream = outbuf;
a6bb56636f90 whitespace cosmetics: K&R coding style, prettyprinting
diego
parents: 10458
diff changeset
48 s->bytestream_end = outbuf+buf_size;
2344
f09680c5e8f4 move p*m from image/lavf -> image2/lavc
michael
parents:
diff changeset
49
f09680c5e8f4 move p*m from image/lavf -> image2/lavc
michael
parents:
diff changeset
50 h = avctx->height;
f09680c5e8f4 move p*m from image/lavf -> image2/lavc
michael
parents:
diff changeset
51 w = avctx->width;
10459
a6bb56636f90 whitespace cosmetics: K&R coding style, prettyprinting
diego
parents: 10458
diff changeset
52 switch (avctx->pix_fmt) {
2344
f09680c5e8f4 move p*m from image/lavf -> image2/lavc
michael
parents:
diff changeset
53 case PIX_FMT_MONOWHITE:
10459
a6bb56636f90 whitespace cosmetics: K&R coding style, prettyprinting
diego
parents: 10458
diff changeset
54 n = (w + 7) >> 3;
a6bb56636f90 whitespace cosmetics: K&R coding style, prettyprinting
diego
parents: 10458
diff changeset
55 depth = 1;
a6bb56636f90 whitespace cosmetics: K&R coding style, prettyprinting
diego
parents: 10458
diff changeset
56 maxval = 1;
2344
f09680c5e8f4 move p*m from image/lavf -> image2/lavc
michael
parents:
diff changeset
57 tuple_type = "BLACKANDWHITE";
f09680c5e8f4 move p*m from image/lavf -> image2/lavc
michael
parents:
diff changeset
58 break;
f09680c5e8f4 move p*m from image/lavf -> image2/lavc
michael
parents:
diff changeset
59 case PIX_FMT_GRAY8:
10459
a6bb56636f90 whitespace cosmetics: K&R coding style, prettyprinting
diego
parents: 10458
diff changeset
60 n = w;
a6bb56636f90 whitespace cosmetics: K&R coding style, prettyprinting
diego
parents: 10458
diff changeset
61 depth = 1;
a6bb56636f90 whitespace cosmetics: K&R coding style, prettyprinting
diego
parents: 10458
diff changeset
62 maxval = 255;
2344
f09680c5e8f4 move p*m from image/lavf -> image2/lavc
michael
parents:
diff changeset
63 tuple_type = "GRAYSCALE";
f09680c5e8f4 move p*m from image/lavf -> image2/lavc
michael
parents:
diff changeset
64 break;
f09680c5e8f4 move p*m from image/lavf -> image2/lavc
michael
parents:
diff changeset
65 case PIX_FMT_RGB24:
10459
a6bb56636f90 whitespace cosmetics: K&R coding style, prettyprinting
diego
parents: 10458
diff changeset
66 n = w * 3;
a6bb56636f90 whitespace cosmetics: K&R coding style, prettyprinting
diego
parents: 10458
diff changeset
67 depth = 3;
a6bb56636f90 whitespace cosmetics: K&R coding style, prettyprinting
diego
parents: 10458
diff changeset
68 maxval = 255;
2344
f09680c5e8f4 move p*m from image/lavf -> image2/lavc
michael
parents:
diff changeset
69 tuple_type = "RGB";
f09680c5e8f4 move p*m from image/lavf -> image2/lavc
michael
parents:
diff changeset
70 break;
4494
ce643a22f049 Replace deprecated PIX_FMT names by the newer variants.
diego
parents: 4152
diff changeset
71 case PIX_FMT_RGB32:
10459
a6bb56636f90 whitespace cosmetics: K&R coding style, prettyprinting
diego
parents: 10458
diff changeset
72 n = w * 4;
a6bb56636f90 whitespace cosmetics: K&R coding style, prettyprinting
diego
parents: 10458
diff changeset
73 depth = 4;
a6bb56636f90 whitespace cosmetics: K&R coding style, prettyprinting
diego
parents: 10458
diff changeset
74 maxval = 255;
2344
f09680c5e8f4 move p*m from image/lavf -> image2/lavc
michael
parents:
diff changeset
75 tuple_type = "RGB_ALPHA";
f09680c5e8f4 move p*m from image/lavf -> image2/lavc
michael
parents:
diff changeset
76 break;
f09680c5e8f4 move p*m from image/lavf -> image2/lavc
michael
parents:
diff changeset
77 default:
f09680c5e8f4 move p*m from image/lavf -> image2/lavc
michael
parents:
diff changeset
78 return -1;
f09680c5e8f4 move p*m from image/lavf -> image2/lavc
michael
parents:
diff changeset
79 }
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2864
diff changeset
80 snprintf(s->bytestream, s->bytestream_end - s->bytestream,
2344
f09680c5e8f4 move p*m from image/lavf -> image2/lavc
michael
parents:
diff changeset
81 "P7\nWIDTH %d\nHEIGHT %d\nDEPTH %d\nMAXVAL %d\nTUPLETYPE %s\nENDHDR\n",
f09680c5e8f4 move p*m from image/lavf -> image2/lavc
michael
parents:
diff changeset
82 w, h, depth, maxval, tuple_type);
f09680c5e8f4 move p*m from image/lavf -> image2/lavc
michael
parents:
diff changeset
83 s->bytestream += strlen(s->bytestream);
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2864
diff changeset
84
10459
a6bb56636f90 whitespace cosmetics: K&R coding style, prettyprinting
diego
parents: 10458
diff changeset
85 ptr = p->data[0];
2344
f09680c5e8f4 move p*m from image/lavf -> image2/lavc
michael
parents:
diff changeset
86 linesize = p->linesize[0];
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2864
diff changeset
87
4494
ce643a22f049 Replace deprecated PIX_FMT names by the newer variants.
diego
parents: 4152
diff changeset
88 if (avctx->pix_fmt == PIX_FMT_RGB32) {
2344
f09680c5e8f4 move p*m from image/lavf -> image2/lavc
michael
parents:
diff changeset
89 int j;
f09680c5e8f4 move p*m from image/lavf -> image2/lavc
michael
parents:
diff changeset
90 unsigned int v;
f09680c5e8f4 move p*m from image/lavf -> image2/lavc
michael
parents:
diff changeset
91
10459
a6bb56636f90 whitespace cosmetics: K&R coding style, prettyprinting
diego
parents: 10458
diff changeset
92 for (i = 0; i < h; i++) {
a6bb56636f90 whitespace cosmetics: K&R coding style, prettyprinting
diego
parents: 10458
diff changeset
93 for (j = 0; j < w; j++) {
2344
f09680c5e8f4 move p*m from image/lavf -> image2/lavc
michael
parents:
diff changeset
94 v = ((uint32_t *)ptr)[j];
5089
bff60ecc02f9 Use AV_xx throughout libavcodec
ramiro
parents: 4985
diff changeset
95 bytestream_put_be24(&s->bytestream, v);
2344
f09680c5e8f4 move p*m from image/lavf -> image2/lavc
michael
parents:
diff changeset
96 *s->bytestream++ = v >> 24;
f09680c5e8f4 move p*m from image/lavf -> image2/lavc
michael
parents:
diff changeset
97 }
f09680c5e8f4 move p*m from image/lavf -> image2/lavc
michael
parents:
diff changeset
98 ptr += linesize;
f09680c5e8f4 move p*m from image/lavf -> image2/lavc
michael
parents:
diff changeset
99 }
f09680c5e8f4 move p*m from image/lavf -> image2/lavc
michael
parents:
diff changeset
100 } else {
10459
a6bb56636f90 whitespace cosmetics: K&R coding style, prettyprinting
diego
parents: 10458
diff changeset
101 for (i = 0; i < h; i++) {
2344
f09680c5e8f4 move p*m from image/lavf -> image2/lavc
michael
parents:
diff changeset
102 memcpy(s->bytestream, ptr, n);
f09680c5e8f4 move p*m from image/lavf -> image2/lavc
michael
parents:
diff changeset
103 s->bytestream += n;
10459
a6bb56636f90 whitespace cosmetics: K&R coding style, prettyprinting
diego
parents: 10458
diff changeset
104 ptr += linesize;
2344
f09680c5e8f4 move p*m from image/lavf -> image2/lavc
michael
parents:
diff changeset
105 }
f09680c5e8f4 move p*m from image/lavf -> image2/lavc
michael
parents:
diff changeset
106 }
f09680c5e8f4 move p*m from image/lavf -> image2/lavc
michael
parents:
diff changeset
107 return s->bytestream - s->bytestream_start;
f09680c5e8f4 move p*m from image/lavf -> image2/lavc
michael
parents:
diff changeset
108 }
f09680c5e8f4 move p*m from image/lavf -> image2/lavc
michael
parents:
diff changeset
109
2348
d02fb928ca44 pnm parser
michael
parents: 2344
diff changeset
110
2344
f09680c5e8f4 move p*m from image/lavf -> image2/lavc
michael
parents:
diff changeset
111 AVCodec pam_encoder = {
f09680c5e8f4 move p*m from image/lavf -> image2/lavc
michael
parents:
diff changeset
112 "pam",
f09680c5e8f4 move p*m from image/lavf -> image2/lavc
michael
parents:
diff changeset
113 CODEC_TYPE_VIDEO,
f09680c5e8f4 move p*m from image/lavf -> image2/lavc
michael
parents:
diff changeset
114 CODEC_ID_PAM,
f09680c5e8f4 move p*m from image/lavf -> image2/lavc
michael
parents:
diff changeset
115 sizeof(PNMContext),
10460
059265d3cc65 Move PNM init/end functions to the PNM common code.
diego
parents: 10459
diff changeset
116 ff_pnm_init,
2344
f09680c5e8f4 move p*m from image/lavf -> image2/lavc
michael
parents:
diff changeset
117 pam_encode_frame,
10459
a6bb56636f90 whitespace cosmetics: K&R coding style, prettyprinting
diego
parents: 10458
diff changeset
118 .pix_fmts = (const enum PixelFormat[]){PIX_FMT_RGB24, PIX_FMT_RGB32, PIX_FMT_GRAY8, PIX_FMT_MONOWHITE, PIX_FMT_NONE},
a6bb56636f90 whitespace cosmetics: K&R coding style, prettyprinting
diego
parents: 10458
diff changeset
119 .long_name = NULL_IF_CONFIG_SMALL("PAM (Portable AnyMap) image"),
2344
f09680c5e8f4 move p*m from image/lavf -> image2/lavc
michael
parents:
diff changeset
120 };