comparison pnm.c @ 2967:ef2149182f1c libavcodec

COSMETICS: Remove all trailing whitespace.
author diego
date Sat, 17 Dec 2005 18:14:38 +0000
parents 95bac7109ff0
children 0b546eab515d
comparison
equal deleted inserted replaced
2966:564788471dd4 2967:ef2149182f1c
24 uint8_t *bytestream_start; 24 uint8_t *bytestream_start;
25 uint8_t *bytestream_end; 25 uint8_t *bytestream_end;
26 AVFrame picture; 26 AVFrame picture;
27 } PNMContext; 27 } PNMContext;
28 28
29 static inline int pnm_space(int c) 29 static inline int pnm_space(int c)
30 { 30 {
31 return (c == ' ' || c == '\n' || c == '\r' || c == '\t'); 31 return (c == ' ' || c == '\n' || c == '\r' || c == '\t');
32 } 32 }
33 33
34 static void pnm_get(PNMContext *sc, char *str, int buf_size) 34 static void pnm_get(PNMContext *sc, char *str, int buf_size)
35 { 35 {
36 char *s; 36 char *s;
37 int c; 37 int c;
38 38
39 /* skip spaces and comments */ 39 /* skip spaces and comments */
40 for(;;) { 40 for(;;) {
41 c = *sc->bytestream++; 41 c = *sc->bytestream++;
42 if (c == '#') { 42 if (c == '#') {
43 do { 43 do {
45 } while (c != '\n' && sc->bytestream < sc->bytestream_end); 45 } while (c != '\n' && sc->bytestream < sc->bytestream_end);
46 } else if (!pnm_space(c)) { 46 } else if (!pnm_space(c)) {
47 break; 47 break;
48 } 48 }
49 } 49 }
50 50
51 s = str; 51 s = str;
52 while (sc->bytestream < sc->bytestream_end && !pnm_space(c)) { 52 while (sc->bytestream < sc->bytestream_end && !pnm_space(c)) {
53 if ((s - str) < buf_size - 1) 53 if ((s - str) < buf_size - 1)
54 *s++ = c; 54 *s++ = c;
55 c = *sc->bytestream++; 55 c = *sc->bytestream++;
72 72
73 pnm_get(s, buf1, sizeof(buf1)); 73 pnm_get(s, buf1, sizeof(buf1));
74 if (!strcmp(buf1, "P4")) { 74 if (!strcmp(buf1, "P4")) {
75 avctx->pix_fmt = PIX_FMT_MONOWHITE; 75 avctx->pix_fmt = PIX_FMT_MONOWHITE;
76 } else if (!strcmp(buf1, "P5")) { 76 } else if (!strcmp(buf1, "P5")) {
77 if (avctx->codec_id == CODEC_ID_PGMYUV) 77 if (avctx->codec_id == CODEC_ID_PGMYUV)
78 avctx->pix_fmt = PIX_FMT_YUV420P; 78 avctx->pix_fmt = PIX_FMT_YUV420P;
79 else 79 else
80 avctx->pix_fmt = PIX_FMT_GRAY8; 80 avctx->pix_fmt = PIX_FMT_GRAY8;
81 } else if (!strcmp(buf1, "P6")) { 81 } else if (!strcmp(buf1, "P6")) {
82 avctx->pix_fmt = PIX_FMT_RGB24; 82 avctx->pix_fmt = PIX_FMT_RGB24;
109 } 109 }
110 } 110 }
111 /* check that all tags are present */ 111 /* check that all tags are present */
112 if (w <= 0 || h <= 0 || maxval <= 0 || depth <= 0 || tuple_type[0] == '\0' || avcodec_check_dimensions(avctx, w, h)) 112 if (w <= 0 || h <= 0 || maxval <= 0 || depth <= 0 || tuple_type[0] == '\0' || avcodec_check_dimensions(avctx, w, h))
113 return -1; 113 return -1;
114 114
115 avctx->width = w; 115 avctx->width = w;
116 avctx->height = h; 116 avctx->height = h;
117 if (depth == 1) { 117 if (depth == 1) {
118 if (maxval == 1) 118 if (maxval == 1)
119 avctx->pix_fmt = PIX_FMT_MONOWHITE; 119 avctx->pix_fmt = PIX_FMT_MONOWHITE;
120 else 120 else
121 avctx->pix_fmt = PIX_FMT_GRAY8; 121 avctx->pix_fmt = PIX_FMT_GRAY8;
122 } else if (depth == 3) { 122 } else if (depth == 3) {
123 avctx->pix_fmt = PIX_FMT_RGB24; 123 avctx->pix_fmt = PIX_FMT_RGB24;
124 } else if (depth == 4) { 124 } else if (depth == 4) {
125 avctx->pix_fmt = PIX_FMT_RGBA32; 125 avctx->pix_fmt = PIX_FMT_RGBA32;
153 avctx->height = h; 153 avctx->height = h;
154 } 154 }
155 return 0; 155 return 0;
156 } 156 }
157 157
158 static int pnm_decode_frame(AVCodecContext *avctx, 158 static int pnm_decode_frame(AVCodecContext *avctx,
159 void *data, int *data_size, 159 void *data, int *data_size,
160 uint8_t *buf, int buf_size) 160 uint8_t *buf, int buf_size)
161 { 161 {
162 PNMContext * const s = avctx->priv_data; 162 PNMContext * const s = avctx->priv_data;
163 AVFrame *picture = data; 163 AVFrame *picture = data;
166 unsigned char *ptr; 166 unsigned char *ptr;
167 167
168 s->bytestream_start= 168 s->bytestream_start=
169 s->bytestream= buf; 169 s->bytestream= buf;
170 s->bytestream_end= buf + buf_size; 170 s->bytestream_end= buf + buf_size;
171 171
172 if(pnm_decode_header(avctx, s) < 0) 172 if(pnm_decode_header(avctx, s) < 0)
173 return -1; 173 return -1;
174 174
175 if(p->data[0]) 175 if(p->data[0])
176 avctx->release_buffer(avctx, p); 176 avctx->release_buffer(avctx, p);
177 177
178 p->reference= 0; 178 p->reference= 0;
179 if(avctx->get_buffer(avctx, p) < 0){ 179 if(avctx->get_buffer(avctx, p) < 0){
180 av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); 180 av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
181 return -1; 181 return -1;
182 } 182 }
183 p->pict_type= FF_I_TYPE; 183 p->pict_type= FF_I_TYPE;
184 p->key_frame= 1; 184 p->key_frame= 1;
185 185
186 switch(avctx->pix_fmt) { 186 switch(avctx->pix_fmt) {
187 default: 187 default:
188 return -1; 188 return -1;
189 case PIX_FMT_RGB24: 189 case PIX_FMT_RGB24:
190 n = avctx->width * 3; 190 n = avctx->width * 3;
272 } 272 }
273 273
274 *p = *pict; 274 *p = *pict;
275 p->pict_type= FF_I_TYPE; 275 p->pict_type= FF_I_TYPE;
276 p->key_frame= 1; 276 p->key_frame= 1;
277 277
278 s->bytestream_start= 278 s->bytestream_start=
279 s->bytestream= outbuf; 279 s->bytestream= outbuf;
280 s->bytestream_end= outbuf+buf_size; 280 s->bytestream_end= outbuf+buf_size;
281 281
282 h = avctx->height; 282 h = avctx->height;
300 h1 = (h * 3) / 2; 300 h1 = (h * 3) / 2;
301 break; 301 break;
302 default: 302 default:
303 return -1; 303 return -1;
304 } 304 }
305 snprintf(s->bytestream, s->bytestream_end - s->bytestream, 305 snprintf(s->bytestream, s->bytestream_end - s->bytestream,
306 "P%c\n%d %d\n", 306 "P%c\n%d %d\n",
307 c, avctx->width, h1); 307 c, avctx->width, h1);
308 s->bytestream += strlen(s->bytestream); 308 s->bytestream += strlen(s->bytestream);
309 if (avctx->pix_fmt != PIX_FMT_MONOWHITE) { 309 if (avctx->pix_fmt != PIX_FMT_MONOWHITE) {
310 snprintf(s->bytestream, s->bytestream_end - s->bytestream, 310 snprintf(s->bytestream, s->bytestream_end - s->bytestream,
311 "%d\n", 255); 311 "%d\n", 255);
312 s->bytestream += strlen(s->bytestream); 312 s->bytestream += strlen(s->bytestream);
313 } 313 }
314 314
315 ptr = p->data[0]; 315 ptr = p->data[0];
317 for(i=0;i<h;i++) { 317 for(i=0;i<h;i++) {
318 memcpy(s->bytestream, ptr, n); 318 memcpy(s->bytestream, ptr, n);
319 s->bytestream += n; 319 s->bytestream += n;
320 ptr += linesize; 320 ptr += linesize;
321 } 321 }
322 322
323 if (avctx->pix_fmt == PIX_FMT_YUV420P) { 323 if (avctx->pix_fmt == PIX_FMT_YUV420P) {
324 h >>= 1; 324 h >>= 1;
325 n >>= 1; 325 n >>= 1;
326 ptr1 = p->data[1]; 326 ptr1 = p->data[1];
327 ptr2 = p->data[2]; 327 ptr2 = p->data[2];
351 } 351 }
352 352
353 *p = *pict; 353 *p = *pict;
354 p->pict_type= FF_I_TYPE; 354 p->pict_type= FF_I_TYPE;
355 p->key_frame= 1; 355 p->key_frame= 1;
356 356
357 s->bytestream_start= 357 s->bytestream_start=
358 s->bytestream= outbuf; 358 s->bytestream= outbuf;
359 s->bytestream_end= outbuf+buf_size; 359 s->bytestream_end= outbuf+buf_size;
360 360
361 h = avctx->height; 361 h = avctx->height;
386 tuple_type = "RGB_ALPHA"; 386 tuple_type = "RGB_ALPHA";
387 break; 387 break;
388 default: 388 default:
389 return -1; 389 return -1;
390 } 390 }
391 snprintf(s->bytestream, s->bytestream_end - s->bytestream, 391 snprintf(s->bytestream, s->bytestream_end - s->bytestream,
392 "P7\nWIDTH %d\nHEIGHT %d\nDEPTH %d\nMAXVAL %d\nTUPLETYPE %s\nENDHDR\n", 392 "P7\nWIDTH %d\nHEIGHT %d\nDEPTH %d\nMAXVAL %d\nTUPLETYPE %s\nENDHDR\n",
393 w, h, depth, maxval, tuple_type); 393 w, h, depth, maxval, tuple_type);
394 s->bytestream += strlen(s->bytestream); 394 s->bytestream += strlen(s->bytestream);
395 395
396 ptr = p->data[0]; 396 ptr = p->data[0];
397 linesize = p->linesize[0]; 397 linesize = p->linesize[0];
398 398
399 if (avctx->pix_fmt == PIX_FMT_RGBA32) { 399 if (avctx->pix_fmt == PIX_FMT_RGBA32) {
400 int j; 400 int j;
401 unsigned int v; 401 unsigned int v;
402 402
403 for(i=0;i<h;i++) { 403 for(i=0;i<h;i++) {
454 } 454 }
455 #endif 455 #endif
456 456
457 static int pnm_parse(AVCodecParserContext *s, 457 static int pnm_parse(AVCodecParserContext *s,
458 AVCodecContext *avctx, 458 AVCodecContext *avctx,
459 uint8_t **poutbuf, int *poutbuf_size, 459 uint8_t **poutbuf, int *poutbuf_size,
460 const uint8_t *buf, int buf_size) 460 const uint8_t *buf, int buf_size)
461 { 461 {
462 ParseContext *pc = s->priv_data; 462 ParseContext *pc = s->priv_data;
463 PNMContext pnmctx; 463 PNMContext pnmctx;
464 int next; 464 int next;
495 goto retry; 495 goto retry;
496 } 496 }
497 #endif 497 #endif
498 next= END_NOT_FOUND; 498 next= END_NOT_FOUND;
499 }else{ 499 }else{
500 next= pnmctx.bytestream - pnmctx.bytestream_start 500 next= pnmctx.bytestream - pnmctx.bytestream_start
501 + avpicture_get_size(avctx->pix_fmt, avctx->width, avctx->height); 501 + avpicture_get_size(avctx->pix_fmt, avctx->width, avctx->height);
502 if(pnmctx.bytestream_start!=buf) 502 if(pnmctx.bytestream_start!=buf)
503 next-= pc->index; 503 next-= pc->index;
504 if(next > buf_size) 504 if(next > buf_size)
505 next= END_NOT_FOUND; 505 next= END_NOT_FOUND;
506 } 506 }
507 507
508 if(ff_combine_frame(pc, next, (uint8_t **)&buf, &buf_size)<0){ 508 if(ff_combine_frame(pc, next, (uint8_t **)&buf, &buf_size)<0){
509 *poutbuf = NULL; 509 *poutbuf = NULL;
510 *poutbuf_size = 0; 510 *poutbuf_size = 0;
511 return buf_size; 511 return buf_size;
512 } 512 }
531 sizeof(PNMContext), 531 sizeof(PNMContext),
532 common_init, 532 common_init,
533 pnm_encode_frame, 533 pnm_encode_frame,
534 NULL, //encode_end, 534 NULL, //encode_end,
535 pnm_decode_frame, 535 pnm_decode_frame,
536 .pix_fmts= (enum PixelFormat[]){PIX_FMT_GRAY8, -1}, 536 .pix_fmts= (enum PixelFormat[]){PIX_FMT_GRAY8, -1},
537 }; 537 };
538 #endif // CONFIG_PGM_ENCODER 538 #endif // CONFIG_PGM_ENCODER
539 539
540 #ifdef CONFIG_PGMYUV_ENCODER 540 #ifdef CONFIG_PGMYUV_ENCODER
541 AVCodec pgmyuv_encoder = { 541 AVCodec pgmyuv_encoder = {
545 sizeof(PNMContext), 545 sizeof(PNMContext),
546 common_init, 546 common_init,
547 pnm_encode_frame, 547 pnm_encode_frame,
548 NULL, //encode_end, 548 NULL, //encode_end,
549 pnm_decode_frame, 549 pnm_decode_frame,
550 .pix_fmts= (enum PixelFormat[]){PIX_FMT_YUV420P, -1}, 550 .pix_fmts= (enum PixelFormat[]){PIX_FMT_YUV420P, -1},
551 }; 551 };
552 #endif // CONFIG_PGMYUV_ENCODER 552 #endif // CONFIG_PGMYUV_ENCODER
553 553
554 #ifdef CONFIG_PPM_ENCODER 554 #ifdef CONFIG_PPM_ENCODER
555 AVCodec ppm_encoder = { 555 AVCodec ppm_encoder = {
559 sizeof(PNMContext), 559 sizeof(PNMContext),
560 common_init, 560 common_init,
561 pnm_encode_frame, 561 pnm_encode_frame,
562 NULL, //encode_end, 562 NULL, //encode_end,
563 pnm_decode_frame, 563 pnm_decode_frame,
564 .pix_fmts= (enum PixelFormat[]){PIX_FMT_RGB24, -1}, 564 .pix_fmts= (enum PixelFormat[]){PIX_FMT_RGB24, -1},
565 }; 565 };
566 #endif // CONFIG_PPM_ENCODER 566 #endif // CONFIG_PPM_ENCODER
567 567
568 #ifdef CONFIG_PBM_ENCODER 568 #ifdef CONFIG_PBM_ENCODER
569 AVCodec pbm_encoder = { 569 AVCodec pbm_encoder = {
573 sizeof(PNMContext), 573 sizeof(PNMContext),
574 common_init, 574 common_init,
575 pnm_encode_frame, 575 pnm_encode_frame,
576 NULL, //encode_end, 576 NULL, //encode_end,
577 pnm_decode_frame, 577 pnm_decode_frame,
578 .pix_fmts= (enum PixelFormat[]){PIX_FMT_MONOWHITE, -1}, 578 .pix_fmts= (enum PixelFormat[]){PIX_FMT_MONOWHITE, -1},
579 }; 579 };
580 #endif // CONFIG_PBM_ENCODER 580 #endif // CONFIG_PBM_ENCODER
581 581
582 #ifdef CONFIG_PAM_ENCODER 582 #ifdef CONFIG_PAM_ENCODER
583 AVCodec pam_encoder = { 583 AVCodec pam_encoder = {
587 sizeof(PNMContext), 587 sizeof(PNMContext),
588 common_init, 588 common_init,
589 pam_encode_frame, 589 pam_encode_frame,
590 NULL, //encode_end, 590 NULL, //encode_end,
591 pnm_decode_frame, 591 pnm_decode_frame,
592 .pix_fmts= (enum PixelFormat[]){PIX_FMT_RGB24, PIX_FMT_RGBA32, PIX_FMT_GRAY8, PIX_FMT_MONOWHITE, -1}, 592 .pix_fmts= (enum PixelFormat[]){PIX_FMT_RGB24, PIX_FMT_RGBA32, PIX_FMT_GRAY8, PIX_FMT_MONOWHITE, -1},
593 }; 593 };
594 #endif // CONFIG_PAM_ENCODER 594 #endif // CONFIG_PAM_ENCODER