comparison raw.c @ 3160:25f6245381be libavcodec

PAL8 support (fixed BLUR8.AVI) cleanup
author michael
date Fri, 03 Mar 2006 21:33:06 +0000
parents 16eff725382f
children 78963e63a45c
comparison
equal deleted inserted replaced
3159:e1157712c1d5 3160:25f6245381be
24 24
25 #include "avcodec.h" 25 #include "avcodec.h"
26 26
27 typedef struct RawVideoContext { 27 typedef struct RawVideoContext {
28 unsigned char * buffer; /* block of memory for holding one frame */ 28 unsigned char * buffer; /* block of memory for holding one frame */
29 unsigned char * p; /* current position in buffer */
30 int length; /* number of bytes in buffer */ 29 int length; /* number of bytes in buffer */
31 AVFrame pic; ///< AVCodecContext.coded_frame 30 AVFrame pic; ///< AVCodecContext.coded_frame
32 } RawVideoContext; 31 } RawVideoContext;
33 32
34 typedef struct PixelFormatTag { 33 typedef struct PixelFormatTag {
84 83
85 if (avctx->codec_tag) 84 if (avctx->codec_tag)
86 avctx->pix_fmt = findPixelFormat(avctx->codec_tag); 85 avctx->pix_fmt = findPixelFormat(avctx->codec_tag);
87 else if (avctx->bits_per_sample){ 86 else if (avctx->bits_per_sample){
88 switch(avctx->bits_per_sample){ 87 switch(avctx->bits_per_sample){
88 case 8: avctx->pix_fmt= PIX_FMT_PAL8 ; break;
89 case 15: avctx->pix_fmt= PIX_FMT_RGB555; break; 89 case 15: avctx->pix_fmt= PIX_FMT_RGB555; break;
90 case 16: avctx->pix_fmt= PIX_FMT_RGB565; break; 90 case 16: avctx->pix_fmt= PIX_FMT_RGB565; break;
91 case 24: avctx->pix_fmt= PIX_FMT_BGR24 ; break; 91 case 24: avctx->pix_fmt= PIX_FMT_BGR24 ; break;
92 case 32: avctx->pix_fmt= PIX_FMT_RGBA32; break; 92 case 32: avctx->pix_fmt= PIX_FMT_RGBA32; break;
93 } 93 }
94 } 94 }
95 95
96 context->length = avpicture_get_size(avctx->pix_fmt, avctx->width, avctx->height); 96 context->length = avpicture_get_size(avctx->pix_fmt, avctx->width, avctx->height);
97 context->buffer = av_malloc(context->length); 97 context->buffer = av_malloc(context->length);
98 context->p = context->buffer;
99 context->pic.pict_type = FF_I_TYPE; 98 context->pic.pict_type = FF_I_TYPE;
100 context->pic.key_frame = 1; 99 context->pic.key_frame = 1;
101 100
102 avctx->coded_frame= &context->pic; 101 avctx->coded_frame= &context->pic;
103 102
106 105
107 return 0; 106 return 0;
108 } 107 }
109 108
110 static void flip(AVCodecContext *avctx, AVPicture * picture){ 109 static void flip(AVCodecContext *avctx, AVPicture * picture){
111 if(!avctx->codec_tag && avctx->bits_per_sample && picture->linesize[1]==0){ 110 if(!avctx->codec_tag && avctx->bits_per_sample && picture->linesize[2]==0){
112 picture->data[0] += picture->linesize[0] * (avctx->height-1); 111 picture->data[0] += picture->linesize[0] * (avctx->height-1);
113 picture->linesize[0] *= -1; 112 picture->linesize[0] *= -1;
114 } 113 }
115 } 114 }
116 115
117 static int raw_decode(AVCodecContext *avctx, 116 static int raw_decode(AVCodecContext *avctx,
118 void *data, int *data_size, 117 void *data, int *data_size,
119 uint8_t *buf, int buf_size) 118 uint8_t *buf, int buf_size)
120 { 119 {
121 RawVideoContext *context = avctx->priv_data; 120 RawVideoContext *context = avctx->priv_data;
122 int bytesNeeded;
123 121
124 AVFrame * frame = (AVFrame *) data; 122 AVFrame * frame = (AVFrame *) data;
125 AVPicture * picture = (AVPicture *) data; 123 AVPicture * picture = (AVPicture *) data;
126 124
127 frame->interlaced_frame = avctx->coded_frame->interlaced_frame; 125 frame->interlaced_frame = avctx->coded_frame->interlaced_frame;
128 frame->top_field_first = avctx->coded_frame->top_field_first; 126 frame->top_field_first = avctx->coded_frame->top_field_first;
129 127
130 /* Early out without copy if packet size == frame size */ 128 if(buf_size < context->length - (avctx->pix_fmt==PIX_FMT_PAL8 ? 256*4 : 0))
131 if (buf_size == context->length && context->p == context->buffer) { 129 return -1;
132 avpicture_fill(picture, buf, avctx->pix_fmt, avctx->width, avctx->height); 130
133 flip(avctx, picture); 131 avpicture_fill(picture, buf, avctx->pix_fmt, avctx->width, avctx->height);
134 *data_size = sizeof(AVPicture); 132 if(avctx->pix_fmt==PIX_FMT_PAL8 && buf_size < context->length){
135 return buf_size; 133 frame->data[1]= context->buffer;
134 }
135 if (avctx->palctrl && avctx->palctrl->palette_changed) {
136 memcpy(frame->data[1], avctx->palctrl->palette, AVPALETTE_SIZE);
137 avctx->palctrl->palette_changed = 0;
136 } 138 }
137 139
138 bytesNeeded = context->length - (context->p - context->buffer);
139 if (buf_size < bytesNeeded) {
140 memcpy(context->p, buf, buf_size);
141 context->p += buf_size;
142 return buf_size;
143 }
144
145 memcpy(context->p, buf, bytesNeeded);
146 context->p = context->buffer;
147 avpicture_fill(picture, context->buffer, avctx->pix_fmt, avctx->width, avctx->height);
148 flip(avctx, picture); 140 flip(avctx, picture);
149 *data_size = sizeof(AVPicture); 141 *data_size = sizeof(AVPicture);
150 return bytesNeeded; 142 return buf_size;
151 } 143 }
152 144
153 static int raw_close_decoder(AVCodecContext *avctx) 145 static int raw_close_decoder(AVCodecContext *avctx)
154 { 146 {
155 RawVideoContext *context = avctx->priv_data; 147 RawVideoContext *context = avctx->priv_data;