Revision cbabccc3 libavcodec/ffv1.c

View differences:

libavcodec/ffv1.c
237 237
    uint8_t state_transition[256];
238 238
    int run_index;
239 239
    int colorspace;
240
    int_fast16_t *sample_buffer;
240 241

  
241 242
    DSPContext dsp;
242 243
}FFV1Context;
......
509 510
static void encode_plane(FFV1Context *s, uint8_t *src, int w, int h, int stride, int plane_index){
510 511
    int x,y,i;
511 512
    const int ring_size= s->avctx->context_model ? 3 : 2;
512
    int_fast16_t sample_buffer[ring_size][w+6], *sample[ring_size];
513
    int_fast16_t *sample[3];
513 514
    s->run_index=0;
514 515

  
515
    memset(sample_buffer, 0, sizeof(sample_buffer));
516
    memset(s->sample_buffer, 0, ring_size*(w+6)*sizeof(*s->sample_buffer));
516 517

  
517 518
    for(y=0; y<h; y++){
518 519
        for(i=0; i<ring_size; i++)
519
            sample[i]= sample_buffer[(h+i-y)%ring_size]+3;
520
            sample[i]= s->sample_buffer + (w+6)*((h+i-y)%ring_size) + 3;
520 521

  
521 522
        sample[0][-1]= sample[1][0  ];
522 523
        sample[1][ w]= sample[1][w-1];
......
539 540
static void encode_rgb_frame(FFV1Context *s, uint32_t *src, int w, int h, int stride){
540 541
    int x, y, p, i;
541 542
    const int ring_size= s->avctx->context_model ? 3 : 2;
542
    int_fast16_t sample_buffer[3][ring_size][w+6], *sample[3][ring_size];
543
    int_fast16_t *sample[3][3];
543 544
    s->run_index=0;
544 545

  
545
    memset(sample_buffer, 0, sizeof(sample_buffer));
546
    memset(s->sample_buffer, 0, ring_size*3*(w+6)*sizeof(*s->sample_buffer));
546 547

  
547 548
    for(y=0; y<h; y++){
548 549
        for(i=0; i<ring_size; i++)
549 550
            for(p=0; p<3; p++)
550
                sample[p][i]= sample_buffer[p][(h+i-y)%ring_size]+3;
551
                sample[p][i]= s->sample_buffer + p*ring_size*(w+6) + ((h+i-y)%ring_size)*(w+6) + 3;
551 552

  
552 553
        for(x=0; x<w; x++){
553 554
            int v= src[x + stride*y];
......
631 632

  
632 633
    assert(s->width && s->height);
633 634

  
635
    s->sample_buffer = av_malloc(6 * (s->width+6) * sizeof(*s->sample_buffer));
636
    if (!s->sample_buffer)
637
        return AVERROR(ENOMEM);
638

  
634 639
    return 0;
635 640
}
636 641

  
......
823 828
        av_freep(&p->vlc_state);
824 829
    }
825 830

  
831
    av_freep(&s->sample_buffer);
832

  
826 833
    return 0;
827 834
}
828 835

  
......
885 892

  
886 893
static void decode_plane(FFV1Context *s, uint8_t *src, int w, int h, int stride, int plane_index){
887 894
    int x, y;
888
    int_fast16_t sample_buffer[2][w+6];
889 895
    int_fast16_t *sample[2];
890
    sample[0]=sample_buffer[0]+3;
891
    sample[1]=sample_buffer[1]+3;
896
    sample[0]=s->sample_buffer    +3;
897
    sample[1]=s->sample_buffer+w+6+3;
892 898

  
893 899
    s->run_index=0;
894 900

  
895
    memset(sample_buffer, 0, sizeof(sample_buffer));
901
    memset(s->sample_buffer, 0, 2*(w+6)*sizeof(*s->sample_buffer));
896 902

  
897 903
    for(y=0; y<h; y++){
898 904
        int_fast16_t *temp= sample[0]; //FIXME try a normal buffer
......
921 927

  
922 928
static void decode_rgb_frame(FFV1Context *s, uint32_t *src, int w, int h, int stride){
923 929
    int x, y, p;
924
    int_fast16_t sample_buffer[3][2][w+6];
925 930
    int_fast16_t *sample[3][2];
926 931
    for(x=0; x<3; x++){
927
        sample[x][0] = sample_buffer[x][0]+3;
928
        sample[x][1] = sample_buffer[x][1]+3;
932
        sample[x][0] = s->sample_buffer +  x*2   *(w+6) + 3;
933
        sample[x][1] = s->sample_buffer + (x*2+1)*(w+6) + 3;
929 934
    }
930 935

  
931 936
    s->run_index=0;
932 937

  
933
    memset(sample_buffer, 0, sizeof(sample_buffer));
938
    memset(s->sample_buffer, 0, 6*(w+6)*sizeof(*s->sample_buffer));
934 939

  
935 940
    for(y=0; y<h; y++){
936 941
        for(p=0; p<3; p++){

Also available in: Unified diff