Ejemplo n.º 1
0
static av_cold int decode_init(AVCodecContext *avctx)
{
    HYuvContext *s = avctx->priv_data;

    ff_huffyuv_common_init(avctx);
    memset(s->vlc, 0, 3 * sizeof(VLC));

    avctx->coded_frame = &s->picture;
    s->interlaced = s->height > 288;

    s->bgr32 = 1;

    if (avctx->extradata_size) {
        if ((avctx->bits_per_coded_sample & 7) &&
            avctx->bits_per_coded_sample != 12)
            s->version = 1; // do such files exist at all?
        else
            s->version = 2;
    } else
        s->version = 0;

    if (s->version == 2) {
        int method, interlace;

        if (avctx->extradata_size < 4)
            return -1;

        method = ((uint8_t*)avctx->extradata)[0];
        s->decorrelate = method & 64 ? 1 : 0;
        s->predictor = method & 63;
        s->bitstream_bpp = ((uint8_t*)avctx->extradata)[1];
        if (s->bitstream_bpp == 0)
            s->bitstream_bpp = avctx->bits_per_coded_sample & ~7;
        interlace = (((uint8_t*)avctx->extradata)[2] & 0x30) >> 4;
        s->interlaced = (interlace == 1) ? 1 : (interlace == 2) ? 0 : s->interlaced;
        s->context = ((uint8_t*)avctx->extradata)[2] & 0x40 ? 1 : 0;

        if ( read_huffman_tables(s, ((uint8_t*)avctx->extradata) + 4,
                                 avctx->extradata_size - 4) < 0)
            return -1;
    }else{
Ejemplo n.º 2
0
static av_cold int decode_init(AVCodecContext *avctx)
{
    HYuvContext *s = avctx->priv_data;
    int ret;

    ret = av_image_check_size(avctx->width, avctx->height, 0, avctx);
    if (ret < 0)
        return ret;

    ff_huffyuvdsp_init(&s->hdsp, avctx->pix_fmt);
    ff_llviddsp_init(&s->llviddsp);
    memset(s->vlc, 0, 4 * sizeof(VLC));

    s->interlaced = avctx->height > 288;
    s->bgr32      = 1;

    if (avctx->extradata_size) {
        if ((avctx->bits_per_coded_sample & 7) &&
            avctx->bits_per_coded_sample != 12)
            s->version = 1; // do such files exist at all?
        else if (avctx->extradata_size > 3 && avctx->extradata[3] == 0)
            s->version = 2;
        else
            s->version = 3;
    } else
        s->version = 0;

    s->bps = 8;
    s->n = 1<<s->bps;
    s->vlc_n = FFMIN(s->n, MAX_VLC_N);
    s->chroma = 1;
    if (s->version >= 2) {
        int method, interlace;

        if (avctx->extradata_size < 4)
            return AVERROR_INVALIDDATA;

        method           = avctx->extradata[0];
        s->decorrelate   = method & 64 ? 1 : 0;
        s->predictor     = method & 63;
        if (s->version == 2) {
            s->bitstream_bpp = avctx->extradata[1];
            if (s->bitstream_bpp == 0)
                s->bitstream_bpp = avctx->bits_per_coded_sample & ~7;
        } else {
            s->bps = (avctx->extradata[1] >> 4) + 1;
            s->n = 1<<s->bps;
            s->vlc_n = FFMIN(s->n, MAX_VLC_N);
            s->chroma_h_shift = avctx->extradata[1] & 3;
            s->chroma_v_shift = (avctx->extradata[1] >> 2) & 3;
            s->yuv   = !!(avctx->extradata[2] & 1);
            s->chroma= !!(avctx->extradata[2] & 3);
            s->alpha = !!(avctx->extradata[2] & 4);
        }
        interlace     = (avctx->extradata[2] & 0x30) >> 4;
        s->interlaced = (interlace == 1) ? 1 : (interlace == 2) ? 0 : s->interlaced;
        s->context    = avctx->extradata[2] & 0x40 ? 1 : 0;

        if ((ret = read_huffman_tables(s, avctx->extradata + 4,
                                       avctx->extradata_size - 4)) < 0)
            goto error;
    } else {
Ejemplo n.º 3
0
static int decode_init(AVCodecContext *avctx)
{
    HYuvContext *s = avctx->priv_data;
    int width, height;

    s->avctx= avctx;
    s->flags= avctx->flags;
        
    dsputil_init(&s->dsp, avctx);
    
    width= s->width= avctx->width;
    height= s->height= avctx->height;
    avctx->coded_frame= &s->picture;

s->bgr32=1;
    assert(width && height);
//if(avctx->extradata)
//  printf("extradata:%X, extradata_size:%d\n", *(uint32_t*)avctx->extradata, avctx->extradata_size);
    if(avctx->extradata_size){
        if((avctx->bits_per_sample&7) && avctx->bits_per_sample != 12)
            s->version=1; // do such files exist at all?
        else
            s->version=2;
    }else
        s->version=0;
    
    if(s->version==2){
        int method;

        method= ((uint8_t*)avctx->extradata)[0];
        s->decorrelate= method&64 ? 1 : 0;
        s->predictor= method&63;
        s->bitstream_bpp= ((uint8_t*)avctx->extradata)[1];
        if(s->bitstream_bpp==0) 
            s->bitstream_bpp= avctx->bits_per_sample&~7;
            
        if(read_huffman_tables(s, ((uint8_t*)avctx->extradata)+4, avctx->extradata_size) < 0)
            return -1;
    }else{
        switch(avctx->bits_per_sample&7){
        case 1:
            s->predictor= LEFT;
            s->decorrelate= 0;
            break;
        case 2:
            s->predictor= LEFT;
            s->decorrelate= 1;
            break;
        case 3:
            s->predictor= PLANE;
            s->decorrelate= avctx->bits_per_sample >= 24;
            break;
        case 4:
            s->predictor= MEDIAN;
            s->decorrelate= 0;
            break;
        default:
            s->predictor= LEFT; //OLD
            s->decorrelate= 0;
            break;
        }
        s->bitstream_bpp= avctx->bits_per_sample & ~7;
        
        if(read_old_huffman_tables(s) < 0)
            return -1;
    }
    
    s->interlaced= height > 288;
    
    switch(s->bitstream_bpp){
    case 12:
        avctx->pix_fmt = PIX_FMT_YUV420P;
        break;
    case 16:
        if(s->yuy2){
            avctx->pix_fmt = PIX_FMT_YUV422;
        }else{
            avctx->pix_fmt = PIX_FMT_YUV422P;
        }
        break;
    case 24:
    case 32:
        if(s->bgr32){
            avctx->pix_fmt = PIX_FMT_RGBA32;
        }else{
            avctx->pix_fmt = PIX_FMT_BGR24;
        }
        break;
    default:
        assert(0);
    }
    
//    printf("pred:%d bpp:%d hbpp:%d il:%d\n", s->predictor, s->bitstream_bpp, avctx->bits_per_sample, s->interlaced);
    
    return 0;
}