c0a4fab3bcbaf88ef417dd6f4299d8795065555d
1 /*****************************************************************************
2 * Copyright (C) 2013 x265 project
4 * Authors: Steve Borho <steve@borho.org>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program 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
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111, USA.
20 * This program is also available under a commercial proprietary license.
21 * For more information, contact us at license @ x265.com.
22 *****************************************************************************/
25 #include "primitives.h"
30 void BitCost::setQP(unsigned int qp
)
34 ScopedLock
s(s_costCalcLock
);
36 // Now that we have acquired the lock, check again if another thread calculated
37 // this row while we were blocked
40 x265_emms(); // just to be safe
43 s_costs
[qp
] = new uint16_t[4 * BC_MAX_MV
+ 1] + 2 * BC_MAX_MV
;
44 double lambda
= x265_lambda_tab
[qp
];
46 // estimate same cost for negative and positive MVD
47 for (int i
= 0; i
<= 2 * BC_MAX_MV
; i
++)
48 s_costs
[qp
][i
] = s_costs
[qp
][-i
] = (uint16_t)X265_MIN(s_bitsizes
[i
] * lambda
+ 0.5f
, (1 << 16) - 1);
56 * Class static data and methods
59 uint16_t *BitCost::s_costs
[BC_MAX_QP
];
61 float *BitCost::s_bitsizes
;
63 Lock
BitCost::s_costCalcLock
;
65 void BitCost::CalculateLogs()
69 s_bitsizes
= new float[2 * BC_MAX_MV
+ 1];
70 s_bitsizes
[0] = 0.718f
;
71 float log2_2
= 2.0f
/ log(2.0f
); // 2 x 1/log(2)
72 for (int i
= 1; i
<= 2 * BC_MAX_MV
; i
++)
73 s_bitsizes
[i
] = log((float)(i
+ 1)) * log2_2
+ 1.718f
;
77 void BitCost::destroy()
79 for (int i
= 0; i
< BC_MAX_QP
; i
++)
83 delete [] (s_costs
[i
] - 2 * BC_MAX_MV
);