comparison pnmenc.c @ 10466:64ffd3bcd73e libavcodec

Split PAM encoder off into its own file.
author diego
date Wed, 28 Oct 2009 06:41:58 +0000
parents 267588850827
children 8a4984c5cacc
comparison
equal deleted inserted replaced
10465:267588850827 10466:64ffd3bcd73e
109 } 109 }
110 } 110 }
111 return s->bytestream - s->bytestream_start; 111 return s->bytestream - s->bytestream_start;
112 } 112 }
113 113
114 static int pam_encode_frame(AVCodecContext *avctx, unsigned char *outbuf,
115 int buf_size, void *data)
116 {
117 PNMContext *s = avctx->priv_data;
118 AVFrame *pict = data;
119 AVFrame * const p = (AVFrame*)&s->picture;
120 int i, h, w, n, linesize, depth, maxval;
121 const char *tuple_type;
122 uint8_t *ptr;
123
124 if (buf_size < avpicture_get_size(avctx->pix_fmt, avctx->width, avctx->height) + 200) {
125 av_log(avctx, AV_LOG_ERROR, "encoded frame too large\n");
126 return -1;
127 }
128
129 *p = *pict;
130 p->pict_type = FF_I_TYPE;
131 p->key_frame = 1;
132
133 s->bytestream_start =
134 s->bytestream = outbuf;
135 s->bytestream_end = outbuf+buf_size;
136
137 h = avctx->height;
138 w = avctx->width;
139 switch (avctx->pix_fmt) {
140 case PIX_FMT_MONOWHITE:
141 n = (w + 7) >> 3;
142 depth = 1;
143 maxval = 1;
144 tuple_type = "BLACKANDWHITE";
145 break;
146 case PIX_FMT_GRAY8:
147 n = w;
148 depth = 1;
149 maxval = 255;
150 tuple_type = "GRAYSCALE";
151 break;
152 case PIX_FMT_RGB24:
153 n = w * 3;
154 depth = 3;
155 maxval = 255;
156 tuple_type = "RGB";
157 break;
158 case PIX_FMT_RGB32:
159 n = w * 4;
160 depth = 4;
161 maxval = 255;
162 tuple_type = "RGB_ALPHA";
163 break;
164 default:
165 return -1;
166 }
167 snprintf(s->bytestream, s->bytestream_end - s->bytestream,
168 "P7\nWIDTH %d\nHEIGHT %d\nDEPTH %d\nMAXVAL %d\nTUPLETYPE %s\nENDHDR\n",
169 w, h, depth, maxval, tuple_type);
170 s->bytestream += strlen(s->bytestream);
171
172 ptr = p->data[0];
173 linesize = p->linesize[0];
174
175 if (avctx->pix_fmt == PIX_FMT_RGB32) {
176 int j;
177 unsigned int v;
178
179 for (i = 0; i < h; i++) {
180 for (j = 0; j < w; j++) {
181 v = ((uint32_t *)ptr)[j];
182 bytestream_put_be24(&s->bytestream, v);
183 *s->bytestream++ = v >> 24;
184 }
185 ptr += linesize;
186 }
187 } else {
188 for (i = 0; i < h; i++) {
189 memcpy(s->bytestream, ptr, n);
190 s->bytestream += n;
191 ptr += linesize;
192 }
193 }
194 return s->bytestream - s->bytestream_start;
195 }
196
197 114
198 #if CONFIG_PGM_ENCODER 115 #if CONFIG_PGM_ENCODER
199 AVCodec pgm_encoder = { 116 AVCodec pgm_encoder = {
200 "pgm", 117 "pgm",
201 CODEC_TYPE_VIDEO, 118 CODEC_TYPE_VIDEO,
244 pnm_encode_frame, 161 pnm_encode_frame,
245 .pix_fmts = (const enum PixelFormat[]){PIX_FMT_MONOWHITE, PIX_FMT_NONE}, 162 .pix_fmts = (const enum PixelFormat[]){PIX_FMT_MONOWHITE, PIX_FMT_NONE},
246 .long_name = NULL_IF_CONFIG_SMALL("PBM (Portable BitMap) image"), 163 .long_name = NULL_IF_CONFIG_SMALL("PBM (Portable BitMap) image"),
247 }; 164 };
248 #endif 165 #endif
249
250 #if CONFIG_PAM_ENCODER
251 AVCodec pam_encoder = {
252 "pam",
253 CODEC_TYPE_VIDEO,
254 CODEC_ID_PAM,
255 sizeof(PNMContext),
256 ff_pnm_init,
257 pam_encode_frame,
258 .pix_fmts = (const enum PixelFormat[]){PIX_FMT_RGB24, PIX_FMT_RGB32, PIX_FMT_GRAY8, PIX_FMT_MONOWHITE, PIX_FMT_NONE},
259 .long_name = NULL_IF_CONFIG_SMALL("PAM (Portable AnyMap) image"),
260 };
261 #endif