Mercurial > libavcodec.hg
annotate pnmenc.c @ 10894:4b2227257766 libavcodec
Support lowres 3 when decoding MPEG video.
Patch by Anatoliy Nenashev, nenashev_as mail ru
author | cehoyos |
---|---|
date | Sat, 16 Jan 2010 10:41:52 +0000 |
parents | 64ffd3bcd73e |
children | 8a4984c5cacc |
rev | line source |
---|---|
2344 | 1 /* |
2 * PNM 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 | 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 | 8 * modify it under the terms of the GNU Lesser General Public |
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 | 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 | 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
15 * Lesser General Public License for more details. | |
16 * | |
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 | 20 */ |
10459
a6bb56636f90
whitespace cosmetics: K&R coding style, prettyprinting
diego
parents:
10458
diff
changeset
|
21 |
2344 | 22 #include "avcodec.h" |
5089 | 23 #include "bytestream.h" |
4978 | 24 #include "pnm.h" |
2967 | 25 |
2344 | 26 |
10459
a6bb56636f90
whitespace cosmetics: K&R coding style, prettyprinting
diego
parents:
10458
diff
changeset
|
27 static int pnm_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 | 33 int i, h, h1, c, n, linesize; |
34 uint8_t *ptr, *ptr1, *ptr2; | |
35 | |
10459
a6bb56636f90
whitespace cosmetics: K&R coding style, prettyprinting
diego
parents:
10458
diff
changeset
|
36 if (buf_size < avpicture_get_size(avctx->pix_fmt, avctx->width, avctx->height) + 200) { |
2422 | 37 av_log(avctx, AV_LOG_ERROR, "encoded frame too large\n"); |
38 return -1; | |
39 } | |
40 | |
10459
a6bb56636f90
whitespace cosmetics: K&R coding style, prettyprinting
diego
parents:
10458
diff
changeset
|
41 *p = *pict; |
a6bb56636f90
whitespace cosmetics: K&R coding style, prettyprinting
diego
parents:
10458
diff
changeset
|
42 p->pict_type = FF_I_TYPE; |
a6bb56636f90
whitespace cosmetics: K&R coding style, prettyprinting
diego
parents:
10458
diff
changeset
|
43 p->key_frame = 1; |
2967 | 44 |
10459
a6bb56636f90
whitespace cosmetics: K&R coding style, prettyprinting
diego
parents:
10458
diff
changeset
|
45 s->bytestream_start = |
a6bb56636f90
whitespace cosmetics: K&R coding style, prettyprinting
diego
parents:
10458
diff
changeset
|
46 s->bytestream = outbuf; |
a6bb56636f90
whitespace cosmetics: K&R coding style, prettyprinting
diego
parents:
10458
diff
changeset
|
47 s->bytestream_end = outbuf + buf_size; |
2344 | 48 |
10459
a6bb56636f90
whitespace cosmetics: K&R coding style, prettyprinting
diego
parents:
10458
diff
changeset
|
49 h = avctx->height; |
2344 | 50 h1 = h; |
10459
a6bb56636f90
whitespace cosmetics: K&R coding style, prettyprinting
diego
parents:
10458
diff
changeset
|
51 switch (avctx->pix_fmt) { |
2344 | 52 case PIX_FMT_MONOWHITE: |
10459
a6bb56636f90
whitespace cosmetics: K&R coding style, prettyprinting
diego
parents:
10458
diff
changeset
|
53 c = '4'; |
a6bb56636f90
whitespace cosmetics: K&R coding style, prettyprinting
diego
parents:
10458
diff
changeset
|
54 n = (avctx->width + 7) >> 3; |
2344 | 55 break; |
56 case PIX_FMT_GRAY8: | |
10459
a6bb56636f90
whitespace cosmetics: K&R coding style, prettyprinting
diego
parents:
10458
diff
changeset
|
57 c = '5'; |
a6bb56636f90
whitespace cosmetics: K&R coding style, prettyprinting
diego
parents:
10458
diff
changeset
|
58 n = avctx->width; |
2344 | 59 break; |
4068 | 60 case PIX_FMT_GRAY16BE: |
10459
a6bb56636f90
whitespace cosmetics: K&R coding style, prettyprinting
diego
parents:
10458
diff
changeset
|
61 c = '5'; |
a6bb56636f90
whitespace cosmetics: K&R coding style, prettyprinting
diego
parents:
10458
diff
changeset
|
62 n = avctx->width * 2; |
4068 | 63 break; |
2344 | 64 case PIX_FMT_RGB24: |
10459
a6bb56636f90
whitespace cosmetics: K&R coding style, prettyprinting
diego
parents:
10458
diff
changeset
|
65 c = '6'; |
a6bb56636f90
whitespace cosmetics: K&R coding style, prettyprinting
diego
parents:
10458
diff
changeset
|
66 n = avctx->width * 3; |
2344 | 67 break; |
9002 | 68 case PIX_FMT_RGB48BE: |
10459
a6bb56636f90
whitespace cosmetics: K&R coding style, prettyprinting
diego
parents:
10458
diff
changeset
|
69 c = '6'; |
a6bb56636f90
whitespace cosmetics: K&R coding style, prettyprinting
diego
parents:
10458
diff
changeset
|
70 n = avctx->width * 6; |
9002 | 71 break; |
2344 | 72 case PIX_FMT_YUV420P: |
10459
a6bb56636f90
whitespace cosmetics: K&R coding style, prettyprinting
diego
parents:
10458
diff
changeset
|
73 c = '5'; |
a6bb56636f90
whitespace cosmetics: K&R coding style, prettyprinting
diego
parents:
10458
diff
changeset
|
74 n = avctx->width; |
2344 | 75 h1 = (h * 3) / 2; |
76 break; | |
77 default: | |
78 return -1; | |
79 } | |
2967 | 80 snprintf(s->bytestream, s->bytestream_end - s->bytestream, |
10459
a6bb56636f90
whitespace cosmetics: K&R coding style, prettyprinting
diego
parents:
10458
diff
changeset
|
81 "P%c\n%d %d\n", c, avctx->width, h1); |
2344 | 82 s->bytestream += strlen(s->bytestream); |
83 if (avctx->pix_fmt != PIX_FMT_MONOWHITE) { | |
2967 | 84 snprintf(s->bytestream, s->bytestream_end - s->bytestream, |
9002 | 85 "%d\n", (avctx->pix_fmt != PIX_FMT_GRAY16BE && avctx->pix_fmt != PIX_FMT_RGB48BE) ? 255 : 65535); |
2344 | 86 s->bytestream += strlen(s->bytestream); |
87 } | |
88 | |
10459
a6bb56636f90
whitespace cosmetics: K&R coding style, prettyprinting
diego
parents:
10458
diff
changeset
|
89 ptr = p->data[0]; |
2344 | 90 linesize = p->linesize[0]; |
10459
a6bb56636f90
whitespace cosmetics: K&R coding style, prettyprinting
diego
parents:
10458
diff
changeset
|
91 for (i = 0; i < h; i++) { |
2344 | 92 memcpy(s->bytestream, ptr, n); |
93 s->bytestream += n; | |
10459
a6bb56636f90
whitespace cosmetics: K&R coding style, prettyprinting
diego
parents:
10458
diff
changeset
|
94 ptr += linesize; |
2344 | 95 } |
2967 | 96 |
2344 | 97 if (avctx->pix_fmt == PIX_FMT_YUV420P) { |
98 h >>= 1; | |
99 n >>= 1; | |
100 ptr1 = p->data[1]; | |
101 ptr2 = p->data[2]; | |
10459
a6bb56636f90
whitespace cosmetics: K&R coding style, prettyprinting
diego
parents:
10458
diff
changeset
|
102 for (i = 0; i < h; i++) { |
2344 | 103 memcpy(s->bytestream, ptr1, n); |
104 s->bytestream += n; | |
105 memcpy(s->bytestream, ptr2, n); | |
106 s->bytestream += n; | |
107 ptr1 += p->linesize[1]; | |
108 ptr2 += p->linesize[2]; | |
109 } | |
110 } | |
111 return s->bytestream - s->bytestream_start; | |
112 } | |
113 | |
2348 | 114 |
8590 | 115 #if CONFIG_PGM_ENCODER |
2344 | 116 AVCodec pgm_encoder = { |
117 "pgm", | |
118 CODEC_TYPE_VIDEO, | |
119 CODEC_ID_PGM, | |
120 sizeof(PNMContext), | |
10460
059265d3cc65
Move PNM init/end functions to the PNM common code.
diego
parents:
10459
diff
changeset
|
121 ff_pnm_init, |
2344 | 122 pnm_encode_frame, |
10459
a6bb56636f90
whitespace cosmetics: K&R coding style, prettyprinting
diego
parents:
10458
diff
changeset
|
123 .pix_fmts = (const enum PixelFormat[]){PIX_FMT_GRAY8, PIX_FMT_GRAY16BE, PIX_FMT_NONE}, |
a6bb56636f90
whitespace cosmetics: K&R coding style, prettyprinting
diego
parents:
10458
diff
changeset
|
124 .long_name = NULL_IF_CONFIG_SMALL("PGM (Portable GrayMap) image"), |
2344 | 125 }; |
10459
a6bb56636f90
whitespace cosmetics: K&R coding style, prettyprinting
diego
parents:
10458
diff
changeset
|
126 #endif |
2344 | 127 |
8590 | 128 #if CONFIG_PGMYUV_ENCODER |
2344 | 129 AVCodec pgmyuv_encoder = { |
130 "pgmyuv", | |
131 CODEC_TYPE_VIDEO, | |
132 CODEC_ID_PGMYUV, | |
133 sizeof(PNMContext), | |
10460
059265d3cc65
Move PNM init/end functions to the PNM common code.
diego
parents:
10459
diff
changeset
|
134 ff_pnm_init, |
2344 | 135 pnm_encode_frame, |
10459
a6bb56636f90
whitespace cosmetics: K&R coding style, prettyprinting
diego
parents:
10458
diff
changeset
|
136 .pix_fmts = (const enum PixelFormat[]){PIX_FMT_YUV420P, PIX_FMT_NONE}, |
a6bb56636f90
whitespace cosmetics: K&R coding style, prettyprinting
diego
parents:
10458
diff
changeset
|
137 .long_name = NULL_IF_CONFIG_SMALL("PGMYUV (Portable GrayMap YUV) image"), |
2344 | 138 }; |
10459
a6bb56636f90
whitespace cosmetics: K&R coding style, prettyprinting
diego
parents:
10458
diff
changeset
|
139 #endif |
2344 | 140 |
8590 | 141 #if CONFIG_PPM_ENCODER |
2344 | 142 AVCodec ppm_encoder = { |
143 "ppm", | |
144 CODEC_TYPE_VIDEO, | |
145 CODEC_ID_PPM, | |
146 sizeof(PNMContext), | |
10460
059265d3cc65
Move PNM init/end functions to the PNM common code.
diego
parents:
10459
diff
changeset
|
147 ff_pnm_init, |
2344 | 148 pnm_encode_frame, |
10459
a6bb56636f90
whitespace cosmetics: K&R coding style, prettyprinting
diego
parents:
10458
diff
changeset
|
149 .pix_fmts = (const enum PixelFormat[]){PIX_FMT_RGB24, PIX_FMT_RGB48BE, PIX_FMT_NONE}, |
a6bb56636f90
whitespace cosmetics: K&R coding style, prettyprinting
diego
parents:
10458
diff
changeset
|
150 .long_name = NULL_IF_CONFIG_SMALL("PPM (Portable PixelMap) image"), |
2344 | 151 }; |
10459
a6bb56636f90
whitespace cosmetics: K&R coding style, prettyprinting
diego
parents:
10458
diff
changeset
|
152 #endif |
2344 | 153 |
8590 | 154 #if CONFIG_PBM_ENCODER |
2344 | 155 AVCodec pbm_encoder = { |
156 "pbm", | |
157 CODEC_TYPE_VIDEO, | |
158 CODEC_ID_PBM, | |
159 sizeof(PNMContext), | |
10460
059265d3cc65
Move PNM init/end functions to the PNM common code.
diego
parents:
10459
diff
changeset
|
160 ff_pnm_init, |
2344 | 161 pnm_encode_frame, |
10459
a6bb56636f90
whitespace cosmetics: K&R coding style, prettyprinting
diego
parents:
10458
diff
changeset
|
162 .pix_fmts = (const enum PixelFormat[]){PIX_FMT_MONOWHITE, PIX_FMT_NONE}, |
a6bb56636f90
whitespace cosmetics: K&R coding style, prettyprinting
diego
parents:
10458
diff
changeset
|
163 .long_name = NULL_IF_CONFIG_SMALL("PBM (Portable BitMap) image"), |
2344 | 164 }; |
10459
a6bb56636f90
whitespace cosmetics: K&R coding style, prettyprinting
diego
parents:
10458
diff
changeset
|
165 #endif |