comparison snow.c @ 2998:733ceb1e079e libavcodec

mem corruption fix
author michael
date Fri, 30 Dec 2005 15:12:02 +0000
parents dfc271b90fe6
children bc83e7a080a5
comparison
equal deleted inserted replaced
2997:188f4ef688f2 2998:733ceb1e079e
587 #endif 587 #endif
588 #define QEXPSHIFT (7-FRAC_BITS+8) //FIXME try to change this to 0 588 #define QEXPSHIFT (7-FRAC_BITS+8) //FIXME try to change this to 0
589 static uint8_t qexp[QROOT]; 589 static uint8_t qexp[QROOT];
590 590
591 static inline int mirror(int v, int m){ 591 static inline int mirror(int v, int m){
592 if (v<0) return -v; 592 while((unsigned)v > (unsigned)m){
593 else if(v>m) return 2*m-v; 593 v=-v;
594 else return v; 594 if(v<0) v+= 2*m;
595 }
596 return v;
595 } 597 }
596 598
597 static inline void put_symbol(RangeCoder *c, uint8_t *state, int v, int is_signed){ 599 static inline void put_symbol(RangeCoder *c, uint8_t *state, int v, int is_signed){
598 int i; 600 int i;
599 601
1093 for(y=-2; y<height; y+=2){ 1095 for(y=-2; y<height; y+=2){
1094 DWTELEM *b2= buffer + mirror(y+1, height-1)*stride; 1096 DWTELEM *b2= buffer + mirror(y+1, height-1)*stride;
1095 DWTELEM *b3= buffer + mirror(y+2, height-1)*stride; 1097 DWTELEM *b3= buffer + mirror(y+2, height-1)*stride;
1096 1098
1097 {START_TIMER 1099 {START_TIMER
1098 if(b1 <= b3) horizontal_decompose53i(b2, width); 1100 if(y+1<(unsigned)height) horizontal_decompose53i(b2, width);
1099 if(y+2 < height) horizontal_decompose53i(b3, width); 1101 if(y+2<(unsigned)height) horizontal_decompose53i(b3, width);
1100 STOP_TIMER("horizontal_decompose53i")} 1102 STOP_TIMER("horizontal_decompose53i")}
1101 1103
1102 {START_TIMER 1104 {START_TIMER
1103 if(b1 <= b3) vertical_decompose53iH0(b1, b2, b3, width); 1105 if(y+1<(unsigned)height) vertical_decompose53iH0(b1, b2, b3, width);
1104 if(b0 <= b2) vertical_decompose53iL0(b0, b1, b2, width); 1106 if(y+0<(unsigned)height) vertical_decompose53iL0(b0, b1, b2, width);
1105 STOP_TIMER("vertical_decompose53i*")} 1107 STOP_TIMER("vertical_decompose53i*")}
1106 1108
1107 b0=b2; 1109 b0=b2;
1108 b1=b3; 1110 b1=b3;
1109 } 1111 }
1243 for(y=-4; y<height; y+=2){ 1245 for(y=-4; y<height; y+=2){
1244 DWTELEM *b4= buffer + mirror(y+3, height-1)*stride; 1246 DWTELEM *b4= buffer + mirror(y+3, height-1)*stride;
1245 DWTELEM *b5= buffer + mirror(y+4, height-1)*stride; 1247 DWTELEM *b5= buffer + mirror(y+4, height-1)*stride;
1246 1248
1247 {START_TIMER 1249 {START_TIMER
1248 if(b3 <= b5) horizontal_decompose97i(b4, width); 1250 if(y+3<(unsigned)height) horizontal_decompose97i(b4, width);
1249 if(y+4 < height) horizontal_decompose97i(b5, width); 1251 if(y+4<(unsigned)height) horizontal_decompose97i(b5, width);
1250 if(width>400){ 1252 if(width>400){
1251 STOP_TIMER("horizontal_decompose97i") 1253 STOP_TIMER("horizontal_decompose97i")
1252 }} 1254 }}
1253 1255
1254 {START_TIMER 1256 {START_TIMER
1255 if(b3 <= b5) vertical_decompose97iH0(b3, b4, b5, width); 1257 if(y+3<(unsigned)height) vertical_decompose97iH0(b3, b4, b5, width);
1256 if(b2 <= b4) vertical_decompose97iL0(b2, b3, b4, width); 1258 if(y+2<(unsigned)height) vertical_decompose97iL0(b2, b3, b4, width);
1257 if(b1 <= b3) vertical_decompose97iH1(b1, b2, b3, width); 1259 if(y+1<(unsigned)height) vertical_decompose97iH1(b1, b2, b3, width);
1258 if(b0 <= b2) vertical_decompose97iL1(b0, b1, b2, width); 1260 if(y+0<(unsigned)height) vertical_decompose97iL1(b0, b1, b2, width);
1259 1261
1260 if(width>400){ 1262 if(width>400){
1261 STOP_TIMER("vertical_decompose97i") 1263 STOP_TIMER("vertical_decompose97i")
1262 }} 1264 }}
1263 1265
1366 DWTELEM *b1= cs->b1; 1368 DWTELEM *b1= cs->b1;
1367 DWTELEM *b2= slice_buffer_get_line(sb, mirror2 * stride_line); 1369 DWTELEM *b2= slice_buffer_get_line(sb, mirror2 * stride_line);
1368 DWTELEM *b3= slice_buffer_get_line(sb, mirror3 * stride_line); 1370 DWTELEM *b3= slice_buffer_get_line(sb, mirror3 * stride_line);
1369 1371
1370 {START_TIMER 1372 {START_TIMER
1371 if(mirror1 <= mirror3) vertical_compose53iL0(b1, b2, b3, width); 1373 if(y+1<(unsigned)height) vertical_compose53iL0(b1, b2, b3, width);
1372 if(mirror0 <= mirror2) vertical_compose53iH0(b0, b1, b2, width); 1374 if(y+0<(unsigned)height) vertical_compose53iH0(b0, b1, b2, width);
1373 STOP_TIMER("vertical_compose53i*")} 1375 STOP_TIMER("vertical_compose53i*")}
1374 1376
1375 {START_TIMER 1377 {START_TIMER
1376 if(y-1 >= 0) horizontal_compose53i(b0, width); 1378 if(y-1<(unsigned)height) horizontal_compose53i(b0, width);
1377 if(mirror0 <= mirror2) horizontal_compose53i(b1, width); 1379 if(y+0<(unsigned)height) horizontal_compose53i(b1, width);
1378 STOP_TIMER("horizontal_compose53i")} 1380 STOP_TIMER("horizontal_compose53i")}
1379 1381
1380 cs->b0 = b2; 1382 cs->b0 = b2;
1381 cs->b1 = b3; 1383 cs->b1 = b3;
1382 cs->y += 2; 1384 cs->y += 2;
1388 DWTELEM *b1= cs->b1; 1390 DWTELEM *b1= cs->b1;
1389 DWTELEM *b2= buffer + mirror(y+1, height-1)*stride; 1391 DWTELEM *b2= buffer + mirror(y+1, height-1)*stride;
1390 DWTELEM *b3= buffer + mirror(y+2, height-1)*stride; 1392 DWTELEM *b3= buffer + mirror(y+2, height-1)*stride;
1391 1393
1392 {START_TIMER 1394 {START_TIMER
1393 if(b1 <= b3) vertical_compose53iL0(b1, b2, b3, width); 1395 if(y+1<(unsigned)height) vertical_compose53iL0(b1, b2, b3, width);
1394 if(b0 <= b2) vertical_compose53iH0(b0, b1, b2, width); 1396 if(y+0<(unsigned)height) vertical_compose53iH0(b0, b1, b2, width);
1395 STOP_TIMER("vertical_compose53i*")} 1397 STOP_TIMER("vertical_compose53i*")}
1396 1398
1397 {START_TIMER 1399 {START_TIMER
1398 if(y-1 >= 0) horizontal_compose53i(b0, width); 1400 if(y-1<(unsigned)height) horizontal_compose53i(b0, width);
1399 if(b0 <= b2) horizontal_compose53i(b1, width); 1401 if(y+0<(unsigned)height) horizontal_compose53i(b1, width);
1400 STOP_TIMER("horizontal_compose53i")} 1402 STOP_TIMER("horizontal_compose53i")}
1401 1403
1402 cs->b0 = b2; 1404 cs->b0 = b2;
1403 cs->b1 = b3; 1405 cs->b1 = b3;
1404 cs->y += 2; 1406 cs->y += 2;
1524 1526
1525 {START_TIMER 1527 {START_TIMER
1526 if(y>0 && y+4<height){ 1528 if(y>0 && y+4<height){
1527 vertical_compose97i(b0, b1, b2, b3, b4, b5, width); 1529 vertical_compose97i(b0, b1, b2, b3, b4, b5, width);
1528 }else{ 1530 }else{
1529 if(mirror3 <= mirror5) vertical_compose97iL1(b3, b4, b5, width); 1531 if(y+3<(unsigned)height) vertical_compose97iL1(b3, b4, b5, width);
1530 if(mirror2 <= mirror4) vertical_compose97iH1(b2, b3, b4, width); 1532 if(y+2<(unsigned)height) vertical_compose97iH1(b2, b3, b4, width);
1531 if(mirror1 <= mirror3) vertical_compose97iL0(b1, b2, b3, width); 1533 if(y+1<(unsigned)height) vertical_compose97iL0(b1, b2, b3, width);
1532 if(mirror0 <= mirror2) vertical_compose97iH0(b0, b1, b2, width); 1534 if(y+0<(unsigned)height) vertical_compose97iH0(b0, b1, b2, width);
1533 } 1535 }
1534 if(width>400){ 1536 if(width>400){
1535 STOP_TIMER("vertical_compose97i")}} 1537 STOP_TIMER("vertical_compose97i")}}
1536 1538
1537 {START_TIMER 1539 {START_TIMER
1538 if(y-1>= 0) horizontal_compose97i(b0, width); 1540 if(y-1<(unsigned)height) horizontal_compose97i(b0, width);
1539 if(mirror0 <= mirror2) horizontal_compose97i(b1, width); 1541 if(y+0<(unsigned)height) horizontal_compose97i(b1, width);
1540 if(width>400 && mirror0 <= mirror2){ 1542 if(width>400 && mirror0 <= mirror2){
1541 STOP_TIMER("horizontal_compose97i")}} 1543 STOP_TIMER("horizontal_compose97i")}}
1542 1544
1543 cs->b0=b2; 1545 cs->b0=b2;
1544 cs->b1=b3; 1546 cs->b1=b3;
1563 for(; x<width; x++) 1565 for(; x<width; x++)
1564 b5[x] += 169*2; 1566 b5[x] += 169*2;
1565 } 1567 }
1566 1568
1567 {START_TIMER 1569 {START_TIMER
1568 if(b3 <= b5) vertical_compose97iL1(b3, b4, b5, width); 1570 if(y+3<(unsigned)height) vertical_compose97iL1(b3, b4, b5, width);
1569 if(b2 <= b4) vertical_compose97iH1(b2, b3, b4, width); 1571 if(y+2<(unsigned)height) vertical_compose97iH1(b2, b3, b4, width);
1570 if(b1 <= b3) vertical_compose97iL0(b1, b2, b3, width); 1572 if(y+1<(unsigned)height) vertical_compose97iL0(b1, b2, b3, width);
1571 if(b0 <= b2) vertical_compose97iH0(b0, b1, b2, width); 1573 if(y+0<(unsigned)height) vertical_compose97iH0(b0, b1, b2, width);
1572 if(width>400){ 1574 if(width>400){
1573 STOP_TIMER("vertical_compose97i")}} 1575 STOP_TIMER("vertical_compose97i")}}
1574 1576
1575 {START_TIMER 1577 {START_TIMER
1576 if(y-1>= 0) horizontal_compose97i(b0, width); 1578 if(y-1<(unsigned)height) horizontal_compose97i(b0, width);
1577 if(b0 <= b2) horizontal_compose97i(b1, width); 1579 if(y+0<(unsigned)height) horizontal_compose97i(b1, width);
1578 if(width>400 && b0 <= b2){ 1580 if(width>400 && b0 <= b2){
1579 STOP_TIMER("horizontal_compose97i")}} 1581 STOP_TIMER("horizontal_compose97i")}}
1580 1582
1581 cs->b0=b2; 1583 cs->b0=b2;
1582 cs->b1=b3; 1584 cs->b1=b3;
3197 dia_change=0; 3199 dia_change=0;
3198 for(i=0; i<8; i++) 3200 for(i=0; i<8; i++)
3199 dia_change |= check_block(s, mb_x, mb_y, (int[2]){block->mx+square[i][0], block->my+square[i][1]}, 0, &best_rd); 3201 dia_change |= check_block(s, mb_x, mb_y, (int[2]){block->mx+square[i][0], block->my+square[i][1]}, 0, &best_rd);
3200 }while(dia_change); 3202 }while(dia_change);
3201 //FIXME or try the standard 2 pass qpel or similar 3203 //FIXME or try the standard 2 pass qpel or similar
3202 3204 #if 1
3203 for(i=0; i<3; i++){ 3205 for(i=0; i<3; i++){
3204 color[i]= get_dc(s, mb_x, mb_y, i); 3206 color[i]= get_dc(s, mb_x, mb_y, i);
3205 } 3207 }
3206 check_block(s, mb_x, mb_y, color, 1, &best_rd); 3208 check_block(s, mb_x, mb_y, color, 1, &best_rd);
3207 //FIXME RD style color selection 3209 //FIXME RD style color selection
3208 3210 #endif
3209 if(!same_block(block, &backup)){ 3211 if(!same_block(block, &backup)){
3210 if(tb != &null_block) tb ->type &= ~BLOCK_OPT; 3212 if(tb != &null_block) tb ->type &= ~BLOCK_OPT;
3211 if(lb != &null_block) lb ->type &= ~BLOCK_OPT; 3213 if(lb != &null_block) lb ->type &= ~BLOCK_OPT;
3212 if(rb != &null_block) rb ->type &= ~BLOCK_OPT; 3214 if(rb != &null_block) rb ->type &= ~BLOCK_OPT;
3213 if(bb != &null_block) bb ->type &= ~BLOCK_OPT; 3215 if(bb != &null_block) bb ->type &= ~BLOCK_OPT;