2 * This file is part of Libav.
4 * Libav is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * Libav is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with Libav; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22 #include "h264_parse.h"
24 int ff_h264_pred_weight_table(GetBitContext *gb, const SPS *sps,
25 const int *ref_count, int slice_type_nos,
26 H264PredWeightTable *pwt)
29 int luma_def, chroma_def;
32 pwt->use_weight_chroma = 0;
33 pwt->luma_log2_weight_denom = get_ue_golomb(gb);
34 if (sps->chroma_format_idc)
35 pwt->chroma_log2_weight_denom = get_ue_golomb(gb);
36 luma_def = 1 << pwt->luma_log2_weight_denom;
37 chroma_def = 1 << pwt->chroma_log2_weight_denom;
39 for (list = 0; list < 2; list++) {
40 pwt->luma_weight_flag[list] = 0;
41 pwt->chroma_weight_flag[list] = 0;
42 for (i = 0; i < ref_count[list]; i++) {
43 int luma_weight_flag, chroma_weight_flag;
45 luma_weight_flag = get_bits1(gb);
46 if (luma_weight_flag) {
47 pwt->luma_weight[i][list][0] = get_se_golomb(gb);
48 pwt->luma_weight[i][list][1] = get_se_golomb(gb);
49 if (pwt->luma_weight[i][list][0] != luma_def ||
50 pwt->luma_weight[i][list][1] != 0) {
52 pwt->luma_weight_flag[list] = 1;
55 pwt->luma_weight[i][list][0] = luma_def;
56 pwt->luma_weight[i][list][1] = 0;
59 if (sps->chroma_format_idc) {
60 chroma_weight_flag = get_bits1(gb);
61 if (chroma_weight_flag) {
63 for (j = 0; j < 2; j++) {
64 pwt->chroma_weight[i][list][j][0] = get_se_golomb(gb);
65 pwt->chroma_weight[i][list][j][1] = get_se_golomb(gb);
66 if (pwt->chroma_weight[i][list][j][0] != chroma_def ||
67 pwt->chroma_weight[i][list][j][1] != 0) {
68 pwt->use_weight_chroma = 1;
69 pwt->chroma_weight_flag[list] = 1;
74 for (j = 0; j < 2; j++) {
75 pwt->chroma_weight[i][list][j][0] = chroma_def;
76 pwt->chroma_weight[i][list][j][1] = 0;
81 if (slice_type_nos != AV_PICTURE_TYPE_B)
84 pwt->use_weight = pwt->use_weight || pwt->use_weight_chroma;