1 /*
2 * Copyright (C) 2004 Michael Niedermayer <michaelni@gmx.at>
3 *
4 * This file is part of FFmpeg.
5 *
6 * FFmpeg is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * FFmpeg is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with FFmpeg; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
29
30
32 int src_x,
int src_y,
int src_stride, slice_buffer * sb,
int add, uint8_t * dst8){
33 int y, x;
35 for(y=0; y<b_h; y++){
36 //FIXME ugly misuse of obmc_stride
37 const uint8_t *obmc1= obmc + y*obmc_stride;
38 const uint8_t *obmc2= obmc1+ (obmc_stride>>1);
39 const uint8_t *obmc3= obmc1+ obmc_stride*(obmc_stride>>1);
40 const uint8_t *
obmc4= obmc3+ (obmc_stride>>1);
42 for(x=0; x<b_w; x++){
43 int v= obmc1[x] *
block[3][x + y*src_stride]
44 +obmc2[x] *
block[2][x + y*src_stride]
45 +obmc3[x] *
block[1][x + y*src_stride]
47
51 }
53 v += dst[x + src_x];
55 if(v&(~255)) v= ~(v>>31);
56 dst8[x + y*src_stride] = v;
57 }else{
58 dst[x + src_x] -= v;
59 }
60 }
61 }
62 }
63
65 {
68
69 frame->width =
s->avctx->width ;
70 frame->height =
s->avctx->height;
71 if (edges_needed) {
74
76 } else
80 if (edges_needed) {
86 }
87 frame->width =
s->avctx->width;
88 frame->height =
s->avctx->height;
89 }
90
91 return 0;
92 }
93
95 int plane_index,
level, orientation;
96
97 for(plane_index=0; plane_index<3; plane_index++){
99 for(orientation=
level ? 1:0; orientation<4; orientation++){
100 memset(
s->plane[plane_index].band[
level][orientation].state,
MID_STATE,
sizeof(
s->plane[plane_index].band[
level][orientation].state));
101 }
102 }
103 }
104 memset(
s->header_state,
MID_STATE,
sizeof(
s->header_state));
105 memset(
s->block_state,
MID_STATE,
sizeof(
s->block_state));
106 }
107
111
114
116 s->block =
av_calloc(
w *
h,
sizeof(*
s->block) << (
s->block_max_depth*2));
119
120 return 0;
121 }
122
124 static const uint8_t
weight[64]={
125 8,7,6,5,4,3,2,1,
126 7,7,0,0,0,0,0,1,
127 6,0,6,0,0,0,2,0,
128 5,0,0,5,0,3,0,0,
129 4,0,0,0,4,0,0,0,
130 3,0,0,5,0,3,0,0,
131 2,0,6,0,0,0,2,0,
132 1,7,0,0,0,0,0,1,
133 };
134
135 static const uint8_t brane[256]={
136 0x00,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x11,0x12,0x12,0x12,0x12,0x12,0x12,0x12,
137 0x04,0x05,0xcc,0xcc,0xcc,0xcc,0xcc,0x41,0x15,0x16,0xcc,0xcc,0xcc,0xcc,0xcc,0x52,
138 0x04,0xcc,0x05,0xcc,0xcc,0xcc,0x41,0xcc,0x15,0xcc,0x16,0xcc,0xcc,0xcc,0x52,0xcc,
139 0x04,0xcc,0xcc,0x05,0xcc,0x41,0xcc,0xcc,0x15,0xcc,0xcc,0x16,0xcc,0x52,0xcc,0xcc,
140 0x04,0xcc,0xcc,0xcc,0x41,0xcc,0xcc,0xcc,0x15,0xcc,0xcc,0xcc,0x16,0xcc,0xcc,0xcc,
141 0x04,0xcc,0xcc,0x41,0xcc,0x05,0xcc,0xcc,0x15,0xcc,0xcc,0x52,0xcc,0x16,0xcc,0xcc,
142 0x04,0xcc,0x41,0xcc,0xcc,0xcc,0x05,0xcc,0x15,0xcc,0x52,0xcc,0xcc,0xcc,0x16,0xcc,
143 0x04,0x41,0xcc,0xcc,0xcc,0xcc,0xcc,0x05,0x15,0x52,0xcc,0xcc,0xcc,0xcc,0xcc,0x16,
144 0x44,0x45,0x45,0x45,0x45,0x45,0x45,0x45,0x55,0x56,0x56,0x56,0x56,0x56,0x56,0x56,
145 0x48,0x49,0xcc,0xcc,0xcc,0xcc,0xcc,0x85,0x59,0x5A,0xcc,0xcc,0xcc,0xcc,0xcc,0x96,
146 0x48,0xcc,0x49,0xcc,0xcc,0xcc,0x85,0xcc,0x59,0xcc,0x5A,0xcc,0xcc,0xcc,0x96,0xcc,
147 0x48,0xcc,0xcc,0x49,0xcc,0x85,0xcc,0xcc,0x59,0xcc,0xcc,0x5A,0xcc,0x96,0xcc,0xcc,
148 0x48,0xcc,0xcc,0xcc,0x49,0xcc,0xcc,0xcc,0x59,0xcc,0xcc,0xcc,0x96,0xcc,0xcc,0xcc,
149 0x48,0xcc,0xcc,0x85,0xcc,0x49,0xcc,0xcc,0x59,0xcc,0xcc,0x96,0xcc,0x5A,0xcc,0xcc,
150 0x48,0xcc,0x85,0xcc,0xcc,0xcc,0x49,0xcc,0x59,0xcc,0x96,0xcc,0xcc,0xcc,0x5A,0xcc,
151 0x48,0x85,0xcc,0xcc,0xcc,0xcc,0xcc,0x49,0x59,0x96,0xcc,0xcc,0xcc,0xcc,0xcc,0x5A,
152 };
153
154 static const uint8_t needs[16]={
155 0,1,0,0,
156 2,4,2,0,
157 0,1,0,0,
158 15
159 };
160
164 int16_t *tmpI= tmpIt;
165 uint8_t *tmp2= tmp2t[0];
166 const uint8_t *hpel[11];
168 r= brane[dx + 16*dy]&15;
169 l= brane[dx + 16*dy]>>4;
170
171 b= needs[l] | needs[
r];
174
177 for(x=0; x < b_w; x++){
186 int am=0;
189 tmpI[x]= am;
190 am= (am+16)>>5;
191 }else{
193 tmpI[x]= am;
194 am= (am+32)>>6;
195 }
196
197 if(am&(~255)) am= ~(am>>31);
198 tmp2[x]= am;
199 }
200 tmpI+= 64;
201 tmp2+= 64;
203 }
205 }
207 tmp2= tmp2t[1];
208
210 for(y=0; y < b_h; y++){
211 for(x=0; x < b_w+1; x++){
220 int am=0;
223 else
225
226 if(am&(~255)) am= ~(am>>31);
227 tmp2[x]= am;
228 }
230 tmp2+= 64;
231 }
233 }
235 tmp2= tmp2t[2];
236 tmpI= tmpIt;
238 for(y=0; y < b_h; y++){
239 for(x=0; x < b_w; x++){
248 int am=0;
251 else
253 if(am&(~255)) am= ~(am>>31);
254 tmp2[x]= am;
255 }
256 tmpI+= 64;
257 tmp2+= 64;
258 }
259 }
260
264
265 hpel[ 4]= tmp2t[1];
266 hpel[ 5]= tmp2t[2];
267 hpel[ 6]= tmp2t[1] + 1;
268
270 hpel[ 9]= hpel[1] + 64;
271 hpel[10]= hpel[8] + 1;
272
273 #define MC_STRIDE(x) (needs[x] ? 64 : stride)
274
276 int dxy = dx / 8 + dy / 8 * 4;
277 const uint8_t *
src1 = hpel[dxy ];
278 const uint8_t *
src2 = hpel[dxy + 1];
279 const uint8_t *src3 = hpel[dxy + 4];
280 const uint8_t *src4 = hpel[dxy + 5];
285 dx&=7;
286 dy&=7;
287 for(y=0; y < b_h; y++){
288 for(x=0; x < b_w; x++){
289 dst[x]= ((8-dx)*(8-dy)*
src1[x] + dx*(8-dy)*
src2[x]+
290 (8-dx)* dy *src3[x] + dx* dy *src4[x]+32)>>6;
291 }
294 src3+=stride3;
295 src4+=stride4;
297 }
298 }else{
299 const uint8_t *
src1= hpel[l];
300 const uint8_t *
src2= hpel[
r];
303 int a=
weight[((dx&7) + (8*(dy&7)))];
305 for(y=0; y < b_h; y++){
306 for(x=0; x < b_w; x++){
308 }
312 }
313 }
314 }
315
316 void ff_snow_pred_block(
SnowContext *
s, uint8_t *dst, uint8_t *
tmp, ptrdiff_t
stride,
int sx,
int sy,
int b_w,
int b_h,
const BlockNode *
block,
int plane_index,
int w,
int h){
318 int x, y;
319 const unsigned color =
block->color[plane_index];
320 const unsigned color4 =
color*0x01010101;
321 if(b_w==32){
322 for(y=0; y < b_h; y++){
323 *(uint32_t*)&dst[0 + y*
stride]= color4;
324 *(uint32_t*)&dst[4 + y*
stride]= color4;
325 *(uint32_t*)&dst[8 + y*
stride]= color4;
326 *(uint32_t*)&dst[12+ y*
stride]= color4;
327 *(uint32_t*)&dst[16+ y*
stride]= color4;
328 *(uint32_t*)&dst[20+ y*
stride]= color4;
329 *(uint32_t*)&dst[24+ y*
stride]= color4;
330 *(uint32_t*)&dst[28+ y*
stride]= color4;
331 }
332 }else if(b_w==16){
333 for(y=0; y < b_h; y++){
334 *(uint32_t*)&dst[0 + y*
stride]= color4;
335 *(uint32_t*)&dst[4 + y*
stride]= color4;
336 *(uint32_t*)&dst[8 + y*
stride]= color4;
337 *(uint32_t*)&dst[12+ y*
stride]= color4;
338 }
339 }else if(b_w==8){
340 for(y=0; y < b_h; y++){
341 *(uint32_t*)&dst[0 + y*
stride]= color4;
342 *(uint32_t*)&dst[4 + y*
stride]= color4;
343 }
344 }else if(b_w==4){
345 for(y=0; y < b_h; y++){
346 *(uint32_t*)&dst[0 + y*
stride]= color4;
347 }
348 }else{
349 for(y=0; y < b_h; y++){
350 for(x=0; x < b_w; x++){
352 }
353 }
354 }
355 }else{
356 const uint8_t *
src =
s->last_picture[
block->ref]->data[plane_index];
357 const int scale= plane_index ? (2*
s->mv_scale)>>
s->chroma_h_shift : 2*
s->mv_scale;
360 const int dx= mx&15;
361 const int dy= my&15;
362 const int tab_index= 3 - (b_w>>2) + (b_w>>4);
373 }
374
375 av_assert2(
s->chroma_h_shift ==
s->chroma_v_shift);
// only one mv_scale
376
377 av_assert2((tab_index>=0 && tab_index<4) || b_w==32);
378 if( (dx&3) || (dy&3)
379 || !(b_w == b_h || 2*b_w == b_h || b_w == 2*b_h)
380 || (b_w&(b_w-1))
381 || b_w == 1
382 || b_h == 1
383 || !
s->plane[plane_index].fast_mc )
385 else if(b_w==32){
386 int y;
387 for(y=0; y<b_h; y+=16){
390 }
391 }else if(b_w==b_h)
392 s->h264qpel.put_h264_qpel_pixels_tab[tab_index ][dy+(dx>>2)](dst,
src + 3 + 3*
stride,
stride);
393 else if(b_w==2*b_h){
394 s->h264qpel.put_h264_qpel_pixels_tab[tab_index+1][dy+(dx>>2)](dst ,
src + 3 + 3*
stride,
stride);
395 s->h264qpel.put_h264_qpel_pixels_tab[tab_index+1][dy+(dx>>2)](dst+b_h,
src + 3 + b_h + 3*
stride,
stride);
396 }else{
398 s->h264qpel.put_h264_qpel_pixels_tab[tab_index ][dy+(dx>>2)](dst ,
src + 3 + 3*
stride ,
stride);
400 }
401 }
402 }
403
404 #define mca(dx,dy,b_w)\
405 static void mc_block_hpel ## dx ## dy ## b_w(uint8_t *dst, const uint8_t *src, ptrdiff_t stride, int h){\
406 av_assert2(h==b_w);\
407 mc_block(NULL, dst, src-(HTAPS_MAX/2-1)-(HTAPS_MAX/2-1)*stride, stride, b_w, b_w, dx, dy);\
408 }
409
418
419 static
av_cold void snow_static_init(
void)
420 {
424 }
425
431
433 s->max_ref_frames=1;
//just make sure it's not an invalid value in case of no initial keyframe
434 s->spatial_decomposition_count = 1;
435
440
441 #define mcf(dx,dy)\
442 s->qdsp.put_qpel_pixels_tab [0][dy+dx/4]=\
443 s->qdsp.put_no_rnd_qpel_pixels_tab[0][dy+dx/4]=\
444 s->h264qpel.put_h264_qpel_pixels_tab[0][dy+dx/4];\
445 s->qdsp.put_qpel_pixels_tab [1][dy+dx/4]=\
446 s->qdsp.put_no_rnd_qpel_pixels_tab[1][dy+dx/4]=\
447 s->h264qpel.put_h264_qpel_pixels_tab[1][dy+dx/4];
448
465
466 #define mcfh(dx,dy)\
467 s->hdsp.put_pixels_tab [0][dy/4+dx/8]=\
468 s->hdsp.put_no_rnd_pixels_tab[0][dy/4+dx/8]=\
469 mc_block_hpel ## dx ## dy ## 16;\
470 s->hdsp.put_pixels_tab [1][dy/4+dx/8]=\
471 s->hdsp.put_no_rnd_pixels_tab[1][dy/4+dx/8]=\
472 mc_block_hpel ## dx ## dy ## 8;
473
478
479 // dec += FFMAX(s->chroma_h_shift, s->chroma_v_shift);
480
483
490
493 if (!
s->last_picture[
i])
495 }
496
499 if (!
s->mconly_picture || !
s->current_picture)
501
503
504 return 0;
505 }
506
509 int plane_index,
level, orientation;
510 int ret, emu_buf_size;
511
517 }
518
523 }
524
526 s->mconly_picture->format != avctx->
pix_fmt) {
529 }
530
531 for(plane_index=0; plane_index <
s->nb_planes; plane_index++){
532 int w=
s->avctx->width;
533 int h=
s->avctx->height;
534
535 if(plane_index){
538 }
539 s->plane[plane_index].width =
w;
540 s->plane[plane_index].height=
h;
541
543 for(orientation=
level ? 1 : 0; orientation<4; orientation++){
545
546 b->buf=
s->spatial_dwt_buffer;
548 b->stride=
s->plane[plane_index].width << (
s->spatial_decomposition_count -
level);
549 b->width = (
w + !(orientation&1))>>1;
550 b->height= (
h + !(orientation>1))>>1;
551
552 b->stride_line = 1 << (
s->spatial_decomposition_count -
level);
555
556 if(orientation&1){
558 b->buf_x_offset = (
w+1)>>1;
559 }
560 if(orientation>1){
561 b->buf +=
b->stride>>1;
562 b->buf_y_offset =
b->stride_line >> 1;
563 }
564 b->ibuf=
s->spatial_idwt_buffer + (
b->buf -
s->spatial_dwt_buffer);
565
567 b->parent= &
s->plane[plane_index].band[
level-1][orientation];
568 //FIXME avoid this realloc
571 sizeof(*
b->x_coeff));
574 }
577 }
578 }
579
580 return 0;
581 }
582
584 {
586
587 if(
s->last_picture[
s->max_ref_frames-1]->data[0]){
589 }
590 }
591
595
597
598 tmp=
s->last_picture[
s->max_ref_frames-1];
599 for(
i=
s->max_ref_frames-1;
i>0;
i--)
600 s->last_picture[
i] =
s->last_picture[
i-1];
601 s->last_picture[0] =
s->current_picture;
602 s->current_picture =
tmp;
603
606 }else{
608 for(
i=0;
i<
s->max_ref_frames &&
s->last_picture[
i]->data[0];
i++)
609 if(
i &&
s->last_picture[
i-1]->key_frame)
610 break;
612 if(
s->ref_frames==0){
615 }
616 }
619
620 s->current_picture->key_frame=
s->keyframe;
621
622 return 0;
623 }
624
626 {
627 int plane_index,
level, orientation,
i;
628
634
639
643
647 if(
s->last_picture[
i] &&
s->last_picture[
i]->data[0]) {
648 av_assert0(
s->last_picture[
i]->data[0] !=
s->current_picture->data[0]);
649 }
651 }
652
653 for(plane_index=0; plane_index <
MAX_PLANES; plane_index++){
655 for(orientation=
level ? 1 : 0; orientation<4; orientation++){
657
659 }
660 }
661 }
664 }