Revision b74fb935 libavcodec/4xm.c

View differences:

libavcodec/4xm.c
575 575
    return ptr;
576 576
}
577 577

  
578
static int mix(int c0, int c1){
579
    int blue = 2*(c0&0x001F) + (c1&0x001F);
580
    int green= (2*(c0&0x03E0) + (c1&0x03E0))>>5;
581
    int red  = 2*(c0>>10) + (c1>>10);
582
    return red/3*1024 + green/3*32 + blue/3;
583
}
584

  
585
static int decode_i2_frame(FourXContext *f, uint8_t *buf, int length){
586
    int x, y, x2, y2;
587
    const int width= f->avctx->width;
588
    const int height= f->avctx->height;
589
    uint16_t *dst= (uint16_t*)f->current_picture.data[0];
590
    const int stride= f->current_picture.linesize[0]>>1;
591

  
592
    for(y=0; y<height; y+=16){
593
        for(x=0; x<width; x+=16){
594
            unsigned int color[4], bits;
595
            memset(color, 0, sizeof(color));
596
//warning following is purely guessed ...
597
            color[0]= AV_RN16(buf); buf+=2; //FIXME use bytestream
598
            color[1]= AV_RN16(buf); buf+=2;
599

  
600
            if(color[0]&0x8000) av_log(NULL, AV_LOG_ERROR, "unk bit 1\n");
601
            if(color[1]&0x8000) av_log(NULL, AV_LOG_ERROR, "unk bit 2\n");
602

  
603
            color[2]= mix(color[0], color[1]);
604
            color[3]= mix(color[1], color[0]);
605

  
606
            bits= AV_RL32(buf); buf+= 4;
607
            for(y2=0; y2<16; y2++){
608
                for(x2=0; x2<16; x2++){
609
                    int index= 2*(x2>>2) + 8*(y2>>2);
610
                    dst[y2*stride+x2]= color[(bits>>index)&3];
611
                }
612
            }
613
            dst+=16;
614
        }
615
        dst += 16*stride - width;
616
    }
617

  
618
    return 0;
619
}
620

  
578 621
static int decode_i_frame(FourXContext *f, uint8_t *buf, int length){
579 622
    int x, y;
580 623
    const int width= f->avctx->width;
......
702 745
        return -1;
703 746
    }
704 747

  
705
    if(frame_4cc == ff_get_fourcc("ifrm") || frame_4cc == ff_get_fourcc("ifr2")){
748
    if(frame_4cc == ff_get_fourcc("ifr2")){
749
        p->pict_type= I_TYPE;
750
        if(decode_i2_frame(f, buf-4, frame_size) < 0)
751
            return -1;
752
    }else if(frame_4cc == ff_get_fourcc("ifrm")){
706 753
        p->pict_type= I_TYPE;
707 754
        if(decode_i_frame(f, buf, frame_size) < 0)
708 755
            return -1;

Also available in: Unified diff