ptr[0] = size >> 8;
ptr[1] = size;
}
+
+ if( s->avctx->pix_fmt == PIX_FMT_YUV420P
+ ||s->avctx->pix_fmt == PIX_FMT_YUV422P
+ ||s->avctx->pix_fmt == PIX_FMT_YUV444P){
+ put_marker(p, COM);
+ flush_put_bits(p);
+ ptr = pbBufPtr(p);
+ put_bits(p, 16, 0); /* patched later */
+ put_string(p, "CS=ITU601", 1);
+ size = strlen("CS=ITU601")+3;
+ ptr[0] = size >> 8;
+ ptr[1] = size;
+ }
}
void mjpeg_picture_header(MpegEncContext *s)
mjpeg_picture_header(s);
s->header_bits= put_bits_count(&s->pb);
-
+
if(avctx->pix_fmt == PIX_FMT_RGBA32){
int x, y, i;
const int linesize= p->linesize[0];
- uint16_t buffer[2048][4];
+ uint16_t (*buffer)[4]= (void *) s->rd_scratchpad;
int left[3], top[3], topleft[3];
for(i=0; i<3; i++){
const int modified_predictor= y ? predictor : 1;
uint8_t *ptr = p->data[0] + (linesize * y);
+ if(s->pb.buf_end - s->pb.buf - (put_bits_count(&s->pb)>>3) < width*3*4){
+ av_log(s->avctx, AV_LOG_ERROR, "encoded frame too large\n");
+ return -1;
+ }
+
for(i=0; i<3; i++){
top[i]= left[i]= topleft[i]= buffer[0][i];
}
const int mb_height = (height + s->mjpeg_vsample[0] - 1) / s->mjpeg_vsample[0];
for(mb_y = 0; mb_y < mb_height; mb_y++) {
+ if(s->pb.buf_end - s->pb.buf - (put_bits_count(&s->pb)>>3) < mb_width * 4 * 3 * s->mjpeg_hsample[0] * s->mjpeg_vsample[0]){
+ av_log(s->avctx, AV_LOG_ERROR, "encoded frame too large\n");
+ return -1;
+ }
for(mb_x = 0; mb_x < mb_width; mb_x++) {
if(mb_x==0 || mb_y==0){
for(i=0;i<3;i++) {
int last_dc[MAX_COMPONENTS]; /* last DEQUANTIZED dc (XXX: am I right to do that ?) */
AVFrame picture; /* picture structure */
int linesize[MAX_COMPONENTS]; ///< linesize << interlaced
- uint8_t *qscale_table;
+ int8_t *qscale_table;
DCTELEM block[64] __align8;
ScanTable scantable;
void (*idct_put)(uint8_t *dest/*align 8*/, int line_size, DCTELEM *block/*align 16*/);
int restart_count;
int buggy_avid;
+ int cs_itu601;
int interlace_polarity;
int mjpb_skiptosod;
static int mjpeg_decode_dht(MJpegDecodeContext *s);
static int build_vlc(VLC *vlc, const uint8_t *bits_table, const uint8_t *val_table,
- int nb_codes)
+ int nb_codes, int use_static)
{
uint8_t huff_size[256];
uint16_t huff_code[256];
memset(huff_size, 0, sizeof(huff_size));
build_huffman_codes(huff_size, huff_code, bits_table, val_table);
- return init_vlc(vlc, 9, nb_codes, huff_size, 1, 1, huff_code, 2, 2);
+ return init_vlc(vlc, 9, nb_codes, huff_size, 1, 1, huff_code, 2, 2, use_static);
}
static int mjpeg_decode_init(AVCodecContext *avctx)
s->first_picture = 1;
s->org_height = avctx->coded_height;
- build_vlc(&s->vlcs[0][0], bits_dc_luminance, val_dc_luminance, 12);
- build_vlc(&s->vlcs[0][1], bits_dc_chrominance, val_dc_chrominance, 12);
- build_vlc(&s->vlcs[1][0], bits_ac_luminance, val_ac_luminance, 251);
- build_vlc(&s->vlcs[1][1], bits_ac_chrominance, val_ac_chrominance, 251);
+ build_vlc(&s->vlcs[0][0], bits_dc_luminance, val_dc_luminance, 12, 0);
+ build_vlc(&s->vlcs[0][1], bits_dc_chrominance, val_dc_chrominance, 12, 0);
+ build_vlc(&s->vlcs[1][0], bits_ac_luminance, val_ac_luminance, 251, 0);
+ build_vlc(&s->vlcs[1][1], bits_ac_chrominance, val_ac_chrominance, 251, 0);
if (avctx->flags & CODEC_FLAG_EXTERN_HUFF)
{
free_vlc(&s->vlcs[class][index]);
dprintf("class=%d index=%d nb_codes=%d\n",
class, index, code_max + 1);
- if(build_vlc(&s->vlcs[class][index], bits_table, val_table, code_max + 1) < 0){
+ if(build_vlc(&s->vlcs[class][index], bits_table, val_table, code_max + 1, 0) < 0){
return -1;
}
}
}
height = get_bits(&s->gb, 16);
width = get_bits(&s->gb, 16);
+
dprintf("sof0: picture: %dx%d\n", width, height);
+ if(avcodec_check_dimensions(s->avctx, width, height))
+ return -1;
nb_components = get_bits(&s->gb, 8);
if (nb_components <= 0 ||
if(s->rgb){
s->avctx->pix_fmt = PIX_FMT_RGBA32;
}else if(s->nb_components==3)
- s->avctx->pix_fmt = PIX_FMT_YUV444P;
+ s->avctx->pix_fmt = s->cs_itu601 ? PIX_FMT_YUV444P : PIX_FMT_YUVJ444P;
else
s->avctx->pix_fmt = PIX_FMT_GRAY8;
break;
case 0x21:
- s->avctx->pix_fmt = PIX_FMT_YUV422P;
+ s->avctx->pix_fmt = s->cs_itu601 ? PIX_FMT_YUV422P : PIX_FMT_YUVJ422P;
break;
default:
case 0x22:
- s->avctx->pix_fmt = PIX_FMT_YUV420P;
+ s->avctx->pix_fmt = s->cs_itu601 ? PIX_FMT_YUV420P : PIX_FMT_YUVJ420P;
break;
}
static int ljpeg_decode_rgb_scan(MJpegDecodeContext *s, int predictor, int point_transform){
int i, mb_x, mb_y;
- uint16_t buffer[2048][4];
+ uint16_t buffer[32768][4];
int left[3], top[3], topleft[3];
const int linesize= s->linesize[0];
const int mask= (1<<s->bits)-1;
+ if((unsigned)s->mb_width > 32768) //dynamic alloc
+ return -1;
+
for(i=0; i<3; i++){
buffer[0][i]= 1 << (s->bits + point_transform - 1);
}
// if (s->first_picture)
// printf("mjpeg: workarounding buggy AVID\n");
}
+ else if(!strcmp(cbuf, "CS=ITU601")){
+ s->cs_itu601= 1;
+ }
av_free(cbuf);
}
int start_code;
AVFrame *picture = data;
- /* no supplementary picture */
- if (buf_size == 0)
- return 0;
-
buf_ptr = buf;
buf_end = buf + buf_size;
while (buf_ptr < buf_end) {
uint32_t dqt_offs, dht_offs, sof_offs, sos_offs, second_field_offs;
uint32_t field_size, sod_offs;
- /* no supplementary picture */
- if (buf_size == 0)
- return 0;
-
buf_ptr = buf;
buf_end = buf + buf_size;
uint8_t *buf_ptr, *buf_end, *recoded;
int i = 0, j = 0;
- /* no supplementary picture */
- if (buf_size == 0)
- return 0;
-
if (!avctx->width || !avctx->height)
return -1;
s->v_max = 2;
s->qscale_table = av_mallocz((s->width+15)/16);
- avctx->pix_fmt = PIX_FMT_YUV420P;
+ avctx->pix_fmt = s->cs_itu601 ? PIX_FMT_YUV420P : PIX_FMT_YUVJ420;
s->interlaced = 0;
s->picture.reference = 0;