+ }
+ if(run_mode){
+ while(run_count >= 1<<log2_run[run_index]){
+ run_count -= 1<<log2_run[run_index];
+ run_index++;
+ put_bits(&s->pb, 1, 1);
+ }
+
+ if(run_count)
+ put_bits(&s->pb, 1, 1);
+ }
+ s->run_index= run_index;
+
+ return 0;
+}
+
+static void encode_plane(FFV1Context *s, uint8_t *src, int w, int h, int stride, int plane_index){
+ int x,y,i;
+ const int ring_size= s->avctx->context_model ? 3 : 2;
+ int_fast16_t sample_buffer[ring_size][w+6], *sample[ring_size];
+ s->run_index=0;
+
+ memset(sample_buffer, 0, sizeof(sample_buffer));
+
+ for(y=0; y<h; y++){
+ for(i=0; i<ring_size; i++)
+ sample[i]= sample_buffer[(h+i-y)%ring_size]+3;
+
+ sample[0][-1]= sample[1][0 ];
+ sample[1][ w]= sample[1][w-1];
+//{START_TIMER
+ for(x=0; x<w; x++){
+ sample[0][x]= src[x + stride*y];
+ }
+ encode_line(s, w, sample, plane_index, 8);
+//STOP_TIMER("encode line")}
+ }
+}
+
+static void encode_rgb_frame(FFV1Context *s, uint32_t *src, int w, int h, int stride){
+ int x, y, p, i;
+ const int ring_size= s->avctx->context_model ? 3 : 2;
+ int_fast16_t sample_buffer[3][ring_size][w+6], *sample[3][ring_size];
+ s->run_index=0;
+
+ memset(sample_buffer, 0, sizeof(sample_buffer));
+
+ for(y=0; y<h; y++){
+ for(i=0; i<ring_size; i++)
+ for(p=0; p<3; p++)
+ sample[p][i]= sample_buffer[p][(h+i-y)%ring_size]+3;