Mercurial > libavcodec.hg
comparison pnm.c @ 4068:186e51891c8c libavcodec
PGM 16-bit gray support
author | kostya |
---|---|
date | Tue, 24 Oct 2006 05:00:14 +0000 |
parents | c8c591fe26f8 |
children | e893c1438b36 |
comparison
equal
deleted
inserted
replaced
4067:8ab58b7bc06b | 4068:186e51891c8c |
---|---|
68 return 0; | 68 return 0; |
69 } | 69 } |
70 | 70 |
71 static int pnm_decode_header(AVCodecContext *avctx, PNMContext * const s){ | 71 static int pnm_decode_header(AVCodecContext *avctx, PNMContext * const s){ |
72 char buf1[32], tuple_type[32]; | 72 char buf1[32], tuple_type[32]; |
73 int h, w, depth, maxval;; | 73 int h, w, depth, maxval; |
74 | 74 |
75 pnm_get(s, buf1, sizeof(buf1)); | 75 pnm_get(s, buf1, sizeof(buf1)); |
76 if (!strcmp(buf1, "P4")) { | 76 if (!strcmp(buf1, "P4")) { |
77 avctx->pix_fmt = PIX_FMT_MONOWHITE; | 77 avctx->pix_fmt = PIX_FMT_MONOWHITE; |
78 } else if (!strcmp(buf1, "P5")) { | 78 } else if (!strcmp(buf1, "P5")) { |
140 avctx->height = atoi(buf1); | 140 avctx->height = atoi(buf1); |
141 if(avcodec_check_dimensions(avctx, avctx->width, avctx->height)) | 141 if(avcodec_check_dimensions(avctx, avctx->width, avctx->height)) |
142 return -1; | 142 return -1; |
143 if (avctx->pix_fmt != PIX_FMT_MONOWHITE) { | 143 if (avctx->pix_fmt != PIX_FMT_MONOWHITE) { |
144 pnm_get(s, buf1, sizeof(buf1)); | 144 pnm_get(s, buf1, sizeof(buf1)); |
145 } | 145 if(atoi(buf1) == 65535 && avctx->pix_fmt == PIX_FMT_GRAY8) |
146 | 146 avctx->pix_fmt = PIX_FMT_GRAY16BE; |
147 } | |
147 /* more check if YUV420 */ | 148 /* more check if YUV420 */ |
148 if (avctx->pix_fmt == PIX_FMT_YUV420P) { | 149 if (avctx->pix_fmt == PIX_FMT_YUV420P) { |
149 if ((avctx->width & 1) != 0) | 150 if ((avctx->width & 1) != 0) |
150 return -1; | 151 return -1; |
151 h = (avctx->height * 2); | 152 h = (avctx->height * 2); |
191 case PIX_FMT_RGB24: | 192 case PIX_FMT_RGB24: |
192 n = avctx->width * 3; | 193 n = avctx->width * 3; |
193 goto do_read; | 194 goto do_read; |
194 case PIX_FMT_GRAY8: | 195 case PIX_FMT_GRAY8: |
195 n = avctx->width; | 196 n = avctx->width; |
197 goto do_read; | |
198 case PIX_FMT_GRAY16BE: | |
199 n = avctx->width * 2; | |
196 goto do_read; | 200 goto do_read; |
197 case PIX_FMT_MONOWHITE: | 201 case PIX_FMT_MONOWHITE: |
198 case PIX_FMT_MONOBLACK: | 202 case PIX_FMT_MONOBLACK: |
199 n = (avctx->width + 7) >> 3; | 203 n = (avctx->width + 7) >> 3; |
200 do_read: | 204 do_read: |
290 break; | 294 break; |
291 case PIX_FMT_GRAY8: | 295 case PIX_FMT_GRAY8: |
292 c = '5'; | 296 c = '5'; |
293 n = avctx->width; | 297 n = avctx->width; |
294 break; | 298 break; |
299 case PIX_FMT_GRAY16BE: | |
300 c = '5'; | |
301 n = avctx->width * 2; | |
302 break; | |
295 case PIX_FMT_RGB24: | 303 case PIX_FMT_RGB24: |
296 c = '6'; | 304 c = '6'; |
297 n = avctx->width * 3; | 305 n = avctx->width * 3; |
298 break; | 306 break; |
299 case PIX_FMT_YUV420P: | 307 case PIX_FMT_YUV420P: |
308 "P%c\n%d %d\n", | 316 "P%c\n%d %d\n", |
309 c, avctx->width, h1); | 317 c, avctx->width, h1); |
310 s->bytestream += strlen(s->bytestream); | 318 s->bytestream += strlen(s->bytestream); |
311 if (avctx->pix_fmt != PIX_FMT_MONOWHITE) { | 319 if (avctx->pix_fmt != PIX_FMT_MONOWHITE) { |
312 snprintf(s->bytestream, s->bytestream_end - s->bytestream, | 320 snprintf(s->bytestream, s->bytestream_end - s->bytestream, |
313 "%d\n", 255); | 321 "%d\n", (avctx->pix_fmt != PIX_FMT_GRAY16BE) ? 255 : 65535); |
314 s->bytestream += strlen(s->bytestream); | 322 s->bytestream += strlen(s->bytestream); |
315 } | 323 } |
316 | 324 |
317 ptr = p->data[0]; | 325 ptr = p->data[0]; |
318 linesize = p->linesize[0]; | 326 linesize = p->linesize[0]; |
535 sizeof(PNMContext), | 543 sizeof(PNMContext), |
536 common_init, | 544 common_init, |
537 pnm_encode_frame, | 545 pnm_encode_frame, |
538 NULL, //encode_end, | 546 NULL, //encode_end, |
539 pnm_decode_frame, | 547 pnm_decode_frame, |
540 .pix_fmts= (enum PixelFormat[]){PIX_FMT_GRAY8, -1}, | 548 .pix_fmts= (enum PixelFormat[]){PIX_FMT_GRAY8, PIX_FMT_GRAY16BE, -1}, |
541 }; | 549 }; |
542 #endif // CONFIG_PGM_ENCODER | 550 #endif // CONFIG_PGM_ENCODER |
543 | 551 |
544 #ifdef CONFIG_PGMYUV_ENCODER | 552 #ifdef CONFIG_PGMYUV_ENCODER |
545 AVCodec pgmyuv_encoder = { | 553 AVCodec pgmyuv_encoder = { |