132
132
AVFrame current_picture, last_picture;
133
133
GetBitContext pre_gb; ///< ac/dc prefix
134
134
GetBitContext gb;
135
const uint8_t *bytestream;
136
const uint16_t *wordstream;
280
static inline void mcdc(uint16_t *dst, uint16_t *src, int log2w, int h, int stride, int scale, int dc){
280
static inline void mcdc(uint16_t *dst, uint16_t *src, int log2w, int h, int stride, int scale, unsigned dc){
328
328
assert(code>=0 && code<=6);
331
src += f->mv[ *f->bytestream++ ];
331
src += f->mv[bytestream2_get_byte(&f->g)];
332
332
if(start > src || src > end){
333
333
av_log(f->avctx, AV_LOG_ERROR, "mv out of pic\n");
345
345
}else if(code == 3 && f->version<2){
346
346
mcdc(dst, src, log2w, h, stride, 1, 0);
347
347
}else if(code == 4){
348
src += f->mv[ *f->bytestream++ ];
348
src += f->mv[bytestream2_get_byte(&f->g)];
349
349
if(start > src || src > end){
350
350
av_log(f->avctx, AV_LOG_ERROR, "mv out of pic\n");
353
mcdc(dst, src, log2w, h, stride, 1, av_le2ne16(*f->wordstream++));
353
mcdc(dst, src, log2w, h, stride, 1, bytestream2_get_le16(&f->g2));
354
354
}else if(code == 5){
355
mcdc(dst, src, log2w, h, stride, 0, av_le2ne16(*f->wordstream++));
355
mcdc(dst, src, log2w, h, stride, 0, bytestream2_get_le16(&f->g2));
356
356
}else if(code == 6){
358
dst[0] = av_le2ne16(*f->wordstream++);
359
dst[1] = av_le2ne16(*f->wordstream++);
358
dst[0] = bytestream2_get_le16(&f->g2);
359
dst[1] = bytestream2_get_le16(&f->g2);
361
dst[0 ] = av_le2ne16(*f->wordstream++);
362
dst[stride] = av_le2ne16(*f->wordstream++);
361
dst[0 ] = bytestream2_get_le16(&f->g2);
362
dst[stride] = bytestream2_get_le16(&f->g2);
371
371
uint16_t *src= (uint16_t*)f->last_picture.data[0];
372
372
uint16_t *dst= (uint16_t*)f->current_picture.data[0];
373
373
const int stride= f->current_picture.linesize[0]>>1;
374
unsigned int bitstream_size, bytestream_size, wordstream_size, extra;
374
unsigned int bitstream_size, bytestream_size, wordstream_size, extra, bytestream_offset, wordstream_offset;
376
376
if(f->version>1){
399
399
if (!f->bitstream_buffer)
400
400
return AVERROR(ENOMEM);
401
401
f->dsp.bswap_buf(f->bitstream_buffer, (const uint32_t*)(buf + extra), bitstream_size/4);
402
memset((uint8_t*)f->bitstream_buffer + bitstream_size, 0, FF_INPUT_BUFFER_PADDING_SIZE);
402
403
init_get_bits(&f->gb, f->bitstream_buffer, 8*bitstream_size);
404
f->wordstream= (const uint16_t*)(buf + extra + bitstream_size);
405
f->bytestream= buf + extra + bitstream_size + wordstream_size;
405
wordstream_offset = extra + bitstream_size;
406
bytestream_offset = extra + bitstream_size + wordstream_size;
407
bytestream2_init(&f->g2, buf + wordstream_offset, length - wordstream_offset);
408
bytestream2_init(&f->g, buf + bytestream_offset, length - bytestream_offset);
417
if( bitstream_size != (get_bits_count(&f->gb)+31)/32*4
418
|| (((const char*)f->wordstream - (const char*)buf + 2)&~2) != extra + bitstream_size + wordstream_size
419
|| (((const char*)f->bytestream - (const char*)buf + 3)&~3) != extra + bitstream_size + wordstream_size + bytestream_size)
420
av_log(f->avctx, AV_LOG_ERROR, " %d %td %td bytes left\n",
421
bitstream_size - (get_bits_count(&f->gb)+31)/32*4,
422
-(((const char*)f->bytestream - (const char*)buf + 3)&~3) + (extra + bitstream_size + wordstream_size + bytestream_size),
423
-(((const char*)f->wordstream - (const char*)buf + 2)&~2) + (extra + bitstream_size + wordstream_size)
604
init_vlc(&f->pre_vlc, ACDC_VLC_BITS, 257,
598
if (init_vlc(&f->pre_vlc, ACDC_VLC_BITS, 257,
619
614
int x, y, x2, y2;
620
615
const int width= f->avctx->width;
621
616
const int height= f->avctx->height;
617
const int mbs = (FFALIGN(width, 16) >> 4) * (FFALIGN(height, 16) >> 4);
622
618
uint16_t *dst= (uint16_t*)f->current_picture.data[0];
623
619
const int stride= f->current_picture.linesize[0]>>1;
622
if(length < mbs * 8) {
623
av_log(f->avctx, AV_LOG_ERROR, "packet size too small\n");
624
return AVERROR_INVALIDDATA;
626
bytestream2_init(&g3, buf, length);
625
628
for(y=0; y<height; y+=16){
626
629
for(x=0; x<width; x+=16){
627
630
unsigned int color[4], bits;
628
631
memset(color, 0, sizeof(color));
629
632
//warning following is purely guessed ...
630
color[0]= bytestream_get_le16(&buf);
631
color[1]= bytestream_get_le16(&buf);
633
color[0]= bytestream2_get_le16u(&g3);
634
color[1]= bytestream2_get_le16u(&g3);
633
636
if(color[0]&0x8000) av_log(NULL, AV_LOG_ERROR, "unk bit 1\n");
634
637
if(color[1]&0x8000) av_log(NULL, AV_LOG_ERROR, "unk bit 2\n");
636
639
color[2]= mix(color[0], color[1]);
637
640
color[3]= mix(color[1], color[0]);
639
bits= bytestream_get_le32(&buf);
642
bits= bytestream2_get_le32u(&g3);
640
643
for(y2=0; y2<16; y2++){
641
644
for(x2=0; x2<16; x2++){
642
645
int index= 2*(x2>>2) + 8*(y2>>2);
656
659
const int width= f->avctx->width;
657
660
const int height= f->avctx->height;
658
uint16_t *dst= (uint16_t*)f->current_picture.data[0];
659
const int stride= f->current_picture.linesize[0]>>1;
660
661
const unsigned int bitstream_size= AV_RL32(buf);
661
const int token_count av_unused = AV_RL32(buf + bitstream_size + 8);
662
unsigned int prestream_size= 4*AV_RL32(buf + bitstream_size + 4);
663
const uint8_t *prestream= buf + bitstream_size + 12;
662
int token_count av_unused;
663
unsigned int prestream_size;
664
const uint8_t *prestream;
666
if (length < bitstream_size + 12) {
667
av_log(f->avctx, AV_LOG_ERROR, "packet size too small\n");
668
return AVERROR_INVALIDDATA;
671
token_count = AV_RL32(buf + bitstream_size + 8);
672
prestream_size = 4 * AV_RL32(buf + bitstream_size + 4);
673
prestream = buf + bitstream_size + 12;
665
675
if(prestream_size + bitstream_size + 12 != length
666
676
|| bitstream_size > (1<<26)
679
689
if (!f->bitstream_buffer)
680
690
return AVERROR(ENOMEM);
681
691
f->dsp.bswap_buf(f->bitstream_buffer, (const uint32_t*)prestream, prestream_size/4);
692
memset((uint8_t*)f->bitstream_buffer + prestream_size, 0, FF_INPUT_BUFFER_PADDING_SIZE);
682
693
init_get_bits(&f->pre_gb, f->bitstream_buffer, 8*prestream_size);
684
695
f->last_dc= 0*128*8*8;
785
795
if(frame_4cc == AV_RL32("ifr2")){
786
796
p->pict_type= AV_PICTURE_TYPE_I;
787
if(decode_i2_frame(f, buf-4, frame_size) < 0)
797
if(decode_i2_frame(f, buf-4, frame_size + 4) < 0)
789
799
}else if(frame_4cc == AV_RL32("ifrm")){
790
800
p->pict_type= AV_PICTURE_TYPE_I;
868
878
AVCodec ff_fourxm_decoder = {
872
sizeof(FourXContext),
880
.type = AVMEDIA_TYPE_VIDEO,
882
.priv_data_size = sizeof(FourXContext),
885
.decode = decode_frame,
886
.capabilities = CODEC_CAP_DR1,
878
887
.long_name = NULL_IF_CONFIG_SMALL("4X Movie"),