Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
VideoLAN
x264
Commits
1ab01bbc
Commit
1ab01bbc
authored
Jun 20, 2005
by
Loren Merritt
Browse files
custom quant matrices
git-svn-id:
svn://svn.videolan.org/x264/trunk@266
df754926-b1dd-0310-bc7b-ec298dee348c
parent
2c4b31da
Changes
12
Hide whitespace changes
Inline
Side-by-side
Makefile
View file @
1ab01bbc
...
...
@@ -4,7 +4,7 @@ include config.mak
SRCS
=
common/mc.c common/predict.c common/pixel.c common/macroblock.c
\
common/frame.c common/dct.c common/cpu.c common/cabac.c
\
common/common.c common/mdate.c common/csp.c
\
common/common.c common/mdate.c common/csp.c
common/set.c
\
encoder/analyse.c encoder/me.c encoder/ratecontrol.c
\
encoder/set.c encoder/macroblock.c encoder/cabac.c
\
encoder/cavlc.c encoder/encoder.c encoder/eval.c
...
...
common/common.c
View file @
1ab01bbc
...
...
@@ -116,6 +116,14 @@ void x264_param_default( x264_param_t *param )
param
->
analyse
.
i_chroma_qp_offset
=
0
;
param
->
analyse
.
b_psnr
=
1
;
param
->
i_cqm_preset
=
X264_CQM_FLAT
;
memset
(
param
->
cqm_4iy
,
16
,
16
);
memset
(
param
->
cqm_4ic
,
16
,
16
);
memset
(
param
->
cqm_4py
,
16
,
16
);
memset
(
param
->
cqm_4pc
,
16
,
16
);
memset
(
param
->
cqm_8iy
,
16
,
64
);
memset
(
param
->
cqm_8py
,
16
,
64
);
param
->
b_aud
=
0
;
}
...
...
common/common.h
View file @
1ab01bbc
...
...
@@ -239,6 +239,11 @@ struct x264_t
x264_pps_t
*
pps
;
int
i_idr_pic_id
;
int
dequant4_mf
[
4
][
6
][
4
][
4
];
int
dequant8_mf
[
2
][
6
][
8
][
8
];
int
quant4_mf
[
4
][
6
][
4
][
4
];
int
quant8_mf
[
2
][
6
][
8
][
8
];
/* Slice header */
x264_slice_header_t
sh
;
...
...
common/macroblock.c
View file @
1ab01bbc
...
...
@@ -163,34 +163,35 @@ int x264_mb_transform_8x8_allowed( x264_t *h )
/****************************************************************************
* Scan and Quant functions
****************************************************************************/
void
x264_mb_dequant_2x2_dc
(
int16_t
dct
[
2
][
2
],
int
i_qscale
)
void
x264_mb_dequant_2x2_dc
(
int16_t
dct
[
2
][
2
],
int
dequant_mf
[
6
][
4
][
4
],
int
i_qscale
)
{
const
int
i_qbits
=
i_qscale
/
6
-
1
;
const
int
i_qbits
=
i_qscale
/
6
-
5
;
if
(
i_qbits
>=
0
)
{
const
int
i_dmf
=
dequant_mf
[
i_qscale
%
6
][
0
][
0
]
<<
i_qbits
;
dct
[
0
][
0
]
=
dct
[
0
][
0
]
*
i_dmf
;
dct
[
0
][
1
]
=
dct
[
0
][
1
]
*
i_dmf
;
dct
[
1
][
0
]
=
dct
[
1
][
0
]
*
i_dmf
;
dct
[
1
][
1
]
=
dct
[
1
][
1
]
*
i_dmf
;
dct
[
0
][
0
]
*
=
i_dmf
;
dct
[
0
][
1
]
*
=
i_dmf
;
dct
[
1
][
0
]
*
=
i_dmf
;
dct
[
1
][
1
]
*
=
i_dmf
;
}
else
{
const
int
i_dmf
=
dequant_mf
[
i_qscale
%
6
][
0
][
0
];
// chroma DC is truncated, not rounded
dct
[
0
][
0
]
=
(
dct
[
0
][
0
]
*
i_dmf
)
>>
1
;
dct
[
0
][
1
]
=
(
dct
[
0
][
1
]
*
i_dmf
)
>>
1
;
dct
[
1
][
0
]
=
(
dct
[
1
][
0
]
*
i_dmf
)
>>
1
;
dct
[
1
][
1
]
=
(
dct
[
1
][
1
]
*
i_dmf
)
>>
1
;
dct
[
0
][
0
]
=
(
dct
[
0
][
0
]
*
i_dmf
)
>>
(
-
i_qbits
)
;
dct
[
0
][
1
]
=
(
dct
[
0
][
1
]
*
i_dmf
)
>>
(
-
i_qbits
)
;
dct
[
1
][
0
]
=
(
dct
[
1
][
0
]
*
i_dmf
)
>>
(
-
i_qbits
)
;
dct
[
1
][
1
]
=
(
dct
[
1
][
1
]
*
i_dmf
)
>>
(
-
i_qbits
)
;
}
}
void
x264_mb_dequant_4x4_dc
(
int16_t
dct
[
4
][
4
],
int
i_qscale
)
void
x264_mb_dequant_4x4_dc
(
int16_t
dct
[
4
][
4
],
int
dequant_mf
[
6
][
4
][
4
],
int
i_qscale
)
{
const
int
i_qbits
=
i_qscale
/
6
-
2
;
int
x
,
y
;
const
int
i_qbits
=
i_qscale
/
6
-
6
;
int
y
;
if
(
i_qbits
>=
0
)
{
...
...
@@ -198,76 +199,89 @@ void x264_mb_dequant_4x4_dc( int16_t dct[4][4], int i_qscale )
for
(
y
=
0
;
y
<
4
;
y
++
)
{
for
(
x
=
0
;
x
<
4
;
x
++
)
{
dct
[
y
][
x
]
=
dct
[
y
][
x
]
*
i_dmf
;
}
dct
[
y
][
0
]
*=
i_dmf
;
dct
[
y
][
1
]
*=
i_dmf
;
dct
[
y
][
2
]
*
=
i_dmf
;
dct
[
y
][
3
]
*=
i_dmf
;
}
}
else
{
const
int
i_dmf
=
dequant_mf
[
i_qscale
%
6
][
0
][
0
];
const
int
f
=
-
i_qbits
;
//
1 << (-
1-
i_qbits
)
const
int
f
=
1
<<
(
-
i_qbits
-
1
);
for
(
y
=
0
;
y
<
4
;
y
++
)
{
for
(
x
=
0
;
x
<
4
;
x
++
)
{
dct
[
y
][
x
]
=
(
dct
[
y
][
x
]
*
i_dmf
+
f
)
>>
(
-
i_qbits
);
}
dct
[
y
][
0
]
=
(
dct
[
y
][
0
]
*
i_dmf
+
f
)
>>
(
-
i_qbits
);
dct
[
y
][
1
]
=
(
dct
[
y
][
1
]
*
i_dmf
+
f
)
>>
(
-
i_qbits
);
dct
[
y
][
2
]
=
(
dct
[
y
][
2
]
*
i_dmf
+
f
)
>>
(
-
i_qbits
);
dct
[
y
][
3
]
=
(
dct
[
y
][
3
]
*
i_dmf
+
f
)
>>
(
-
i_qbits
);
}
}
}
void
x264_mb_dequant_4x4
(
int16_t
dct
[
4
][
4
],
int
i_qscale
)
void
x264_mb_dequant_4x4
(
int16_t
dct
[
4
][
4
],
int
dequant_mf
[
6
][
4
][
4
],
int
i_qscale
)
{
const
int
i_mf
=
i_qscale
%
6
;
const
int
i_qbits
=
i_qscale
/
6
;
const
int
i_qbits
=
i_qscale
/
6
-
4
;
int
y
;
for
(
y
=
0
;
y
<
4
;
y
++
)
if
(
i_qbits
>=
0
)
{
for
(
y
=
0
;
y
<
4
;
y
++
)
{
dct
[
y
][
0
]
=
(
dct
[
y
][
0
]
*
dequant_mf
[
i_mf
][
y
][
0
]
)
<<
i_qbits
;
dct
[
y
][
1
]
=
(
dct
[
y
][
1
]
*
dequant_mf
[
i_mf
][
y
][
1
]
)
<<
i_qbits
;
dct
[
y
][
2
]
=
(
dct
[
y
][
2
]
*
dequant_mf
[
i_mf
][
y
][
2
]
)
<<
i_qbits
;
dct
[
y
][
3
]
=
(
dct
[
y
][
3
]
*
dequant_mf
[
i_mf
][
y
][
3
]
)
<<
i_qbits
;
}
}
else
{
dct
[
y
][
0
]
=
(
dct
[
y
][
0
]
*
dequant_mf
[
i_mf
][
y
][
0
]
)
<<
i_qbits
;
dct
[
y
][
1
]
=
(
dct
[
y
][
1
]
*
dequant_mf
[
i_mf
][
y
][
1
]
)
<<
i_qbits
;
dct
[
y
][
2
]
=
(
dct
[
y
][
2
]
*
dequant_mf
[
i_mf
][
y
][
2
]
)
<<
i_qbits
;
dct
[
y
][
3
]
=
(
dct
[
y
][
3
]
*
dequant_mf
[
i_mf
][
y
][
3
]
)
<<
i_qbits
;
const
int
f
=
1
<<
(
-
i_qbits
-
1
);
for
(
y
=
0
;
y
<
4
;
y
++
)
{
dct
[
y
][
0
]
=
(
dct
[
y
][
0
]
*
dequant_mf
[
i_mf
][
y
][
0
]
+
f
)
>>
(
-
i_qbits
);
dct
[
y
][
1
]
=
(
dct
[
y
][
1
]
*
dequant_mf
[
i_mf
][
y
][
1
]
+
f
)
>>
(
-
i_qbits
);
dct
[
y
][
2
]
=
(
dct
[
y
][
2
]
*
dequant_mf
[
i_mf
][
y
][
2
]
+
f
)
>>
(
-
i_qbits
);
dct
[
y
][
3
]
=
(
dct
[
y
][
3
]
*
dequant_mf
[
i_mf
][
y
][
3
]
+
f
)
>>
(
-
i_qbits
);
}
}
}
void
x264_mb_dequant_8x8
(
int16_t
dct
[
8
][
8
],
int
i_qscale
)
void
x264_mb_dequant_8x8
(
int16_t
dct
[
8
][
8
],
int
dequant_mf
[
6
][
8
][
8
],
int
i_qscale
)
{
const
int
i_mf
=
i_qscale
%
6
;
const
int
i_qbits
=
i_qscale
/
6
-
6
;
int
y
;
if
(
i_q
scale
>=
12
)
if
(
i_q
bits
>=
0
)
{
const
int
i_qbits
=
(
i_qscale
/
6
)
-
2
;
for
(
y
=
0
;
y
<
8
;
y
++
)
{
dct
[
y
][
0
]
=
(
dct
[
y
][
0
]
*
dequant
8
_mf
[
i_mf
][
y
][
0
]
)
<<
i_qbits
;
dct
[
y
][
1
]
=
(
dct
[
y
][
1
]
*
dequant
8
_mf
[
i_mf
][
y
][
1
]
)
<<
i_qbits
;
dct
[
y
][
2
]
=
(
dct
[
y
][
2
]
*
dequant
8
_mf
[
i_mf
][
y
][
2
]
)
<<
i_qbits
;
dct
[
y
][
3
]
=
(
dct
[
y
][
3
]
*
dequant
8
_mf
[
i_mf
][
y
][
3
]
)
<<
i_qbits
;
dct
[
y
][
4
]
=
(
dct
[
y
][
4
]
*
dequant
8
_mf
[
i_mf
][
y
][
4
]
)
<<
i_qbits
;
dct
[
y
][
5
]
=
(
dct
[
y
][
5
]
*
dequant
8
_mf
[
i_mf
][
y
][
5
]
)
<<
i_qbits
;
dct
[
y
][
6
]
=
(
dct
[
y
][
6
]
*
dequant
8
_mf
[
i_mf
][
y
][
6
]
)
<<
i_qbits
;
dct
[
y
][
7
]
=
(
dct
[
y
][
7
]
*
dequant
8
_mf
[
i_mf
][
y
][
7
]
)
<<
i_qbits
;
dct
[
y
][
0
]
=
(
dct
[
y
][
0
]
*
dequant_mf
[
i_mf
][
y
][
0
]
)
<<
i_qbits
;
dct
[
y
][
1
]
=
(
dct
[
y
][
1
]
*
dequant_mf
[
i_mf
][
y
][
1
]
)
<<
i_qbits
;
dct
[
y
][
2
]
=
(
dct
[
y
][
2
]
*
dequant_mf
[
i_mf
][
y
][
2
]
)
<<
i_qbits
;
dct
[
y
][
3
]
=
(
dct
[
y
][
3
]
*
dequant_mf
[
i_mf
][
y
][
3
]
)
<<
i_qbits
;
dct
[
y
][
4
]
=
(
dct
[
y
][
4
]
*
dequant_mf
[
i_mf
][
y
][
4
]
)
<<
i_qbits
;
dct
[
y
][
5
]
=
(
dct
[
y
][
5
]
*
dequant_mf
[
i_mf
][
y
][
5
]
)
<<
i_qbits
;
dct
[
y
][
6
]
=
(
dct
[
y
][
6
]
*
dequant_mf
[
i_mf
][
y
][
6
]
)
<<
i_qbits
;
dct
[
y
][
7
]
=
(
dct
[
y
][
7
]
*
dequant_mf
[
i_mf
][
y
][
7
]
)
<<
i_qbits
;
}
}
else
{
const
int
i_qbits
=
2
-
(
i_qscale
/
6
);
const
int
i_round
=
i_qbits
;
// 1<<(i_qbits-1)
const
int
f
=
1
<<
(
-
i_qbits
-
1
);
for
(
y
=
0
;
y
<
8
;
y
++
)
{
dct
[
y
][
0
]
=
(
dct
[
y
][
0
]
*
dequant
8
_mf
[
i_mf
][
y
][
0
]
+
i_round
)
>>
i_qbits
;
dct
[
y
][
1
]
=
(
dct
[
y
][
1
]
*
dequant
8
_mf
[
i_mf
][
y
][
1
]
+
i_round
)
>>
i_qbits
;
dct
[
y
][
2
]
=
(
dct
[
y
][
2
]
*
dequant
8
_mf
[
i_mf
][
y
][
2
]
+
i_round
)
>>
i_qbits
;
dct
[
y
][
3
]
=
(
dct
[
y
][
3
]
*
dequant
8
_mf
[
i_mf
][
y
][
3
]
+
i_round
)
>>
i_qbits
;
dct
[
y
][
4
]
=
(
dct
[
y
][
4
]
*
dequant
8
_mf
[
i_mf
][
y
][
4
]
+
i_round
)
>>
i_qbits
;
dct
[
y
][
5
]
=
(
dct
[
y
][
5
]
*
dequant
8
_mf
[
i_mf
][
y
][
5
]
+
i_round
)
>>
i_qbits
;
dct
[
y
][
6
]
=
(
dct
[
y
][
6
]
*
dequant
8
_mf
[
i_mf
][
y
][
6
]
+
i_round
)
>>
i_qbits
;
dct
[
y
][
7
]
=
(
dct
[
y
][
7
]
*
dequant
8
_mf
[
i_mf
][
y
][
7
]
+
i_round
)
>>
i_qbits
;
dct
[
y
][
0
]
=
(
dct
[
y
][
0
]
*
dequant_mf
[
i_mf
][
y
][
0
]
+
f
)
>>
(
-
i_qbits
)
;
dct
[
y
][
1
]
=
(
dct
[
y
][
1
]
*
dequant_mf
[
i_mf
][
y
][
1
]
+
f
)
>>
(
-
i_qbits
)
;
dct
[
y
][
2
]
=
(
dct
[
y
][
2
]
*
dequant_mf
[
i_mf
][
y
][
2
]
+
f
)
>>
(
-
i_qbits
)
;
dct
[
y
][
3
]
=
(
dct
[
y
][
3
]
*
dequant_mf
[
i_mf
][
y
][
3
]
+
f
)
>>
(
-
i_qbits
)
;
dct
[
y
][
4
]
=
(
dct
[
y
][
4
]
*
dequant_mf
[
i_mf
][
y
][
4
]
+
f
)
>>
(
-
i_qbits
)
;
dct
[
y
][
5
]
=
(
dct
[
y
][
5
]
*
dequant_mf
[
i_mf
][
y
][
5
]
+
f
)
>>
(
-
i_qbits
)
;
dct
[
y
][
6
]
=
(
dct
[
y
][
6
]
*
dequant_mf
[
i_mf
][
y
][
6
]
+
f
)
>>
(
-
i_qbits
)
;
dct
[
y
][
7
]
=
(
dct
[
y
][
7
]
*
dequant_mf
[
i_mf
][
y
][
7
]
+
f
)
>>
(
-
i_qbits
)
;
}
}
}
...
...
common/macroblock.h
View file @
1ab01bbc
...
...
@@ -157,6 +157,19 @@ static const int x264_mb_partition_count_table[17] =
4
,
2
,
2
,
1
};
static
const
int
x264_zigzag_scan4
[
16
]
=
{
0
,
1
,
4
,
8
,
5
,
2
,
3
,
6
,
9
,
12
,
13
,
10
,
7
,
11
,
14
,
15
};
static
const
int
x264_zigzag_scan8
[
64
]
=
{
0
,
1
,
8
,
16
,
9
,
2
,
3
,
10
,
17
,
24
,
32
,
25
,
18
,
11
,
4
,
5
,
12
,
19
,
26
,
33
,
40
,
48
,
41
,
34
,
27
,
20
,
13
,
6
,
7
,
14
,
21
,
28
,
35
,
42
,
49
,
56
,
57
,
50
,
43
,
36
,
29
,
22
,
15
,
23
,
30
,
37
,
44
,
51
,
58
,
59
,
52
,
45
,
38
,
31
,
39
,
46
,
53
,
60
,
61
,
54
,
47
,
55
,
62
,
63
};
void
x264_macroblock_cache_init
(
x264_t
*
h
);
void
x264_macroblock_slice_init
(
x264_t
*
h
);
void
x264_macroblock_cache_load
(
x264_t
*
h
,
int
i_mb_x
,
int
i_mb_y
);
...
...
@@ -165,10 +178,10 @@ void x264_macroblock_cache_end( x264_t *h );
void
x264_macroblock_bipred_init
(
x264_t
*
h
);
void
x264_mb_dequant_4x4_dc
(
int16_t
dct
[
4
][
4
],
int
i_qscale
);
void
x264_mb_dequant_2x2_dc
(
int16_t
dct
[
2
][
2
],
int
i_qscale
);
void
x264_mb_dequant_4x4
(
int16_t
dct
[
4
][
4
],
int
i_qscale
);
void
x264_mb_dequant_8x8
(
int16_t
dct
[
8
][
8
],
int
i_qscale
);
void
x264_mb_dequant_4x4_dc
(
int16_t
dct
[
4
][
4
],
int
dequant_mf
[
6
][
4
][
4
],
int
i_qscale
);
void
x264_mb_dequant_2x2_dc
(
int16_t
dct
[
2
][
2
],
int
dequant_mf
[
6
][
4
][
4
],
int
i_qscale
);
void
x264_mb_dequant_4x4
(
int16_t
dct
[
4
][
4
],
int
dequant_mf
[
6
][
4
][
4
],
int
i_qscale
);
void
x264_mb_dequant_8x8
(
int16_t
dct
[
8
][
8
],
int
dequant_mf
[
6
][
8
][
8
],
int
i_qscale
);
/* x264_mb_predict_mv_16x16:
* set mvp with predicted mv for D_16x16 block
...
...
common/set.c
0 → 100644
View file @
1ab01bbc
/*****************************************************************************
* set.c: h264 encoder library
*****************************************************************************
* Copyright (C) 2005 x264 project
*
* Authors: Loren Merritt <lorenm@u.washington.edu>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
*****************************************************************************/
#include
"common.h"
static
const
int
dequant4_scale
[
6
][
3
]
=
{
{
10
,
13
,
16
},
{
11
,
14
,
18
},
{
13
,
16
,
20
},
{
14
,
18
,
23
},
{
16
,
20
,
25
},
{
18
,
23
,
29
}
};
static
const
int
quant4_scale
[
6
][
3
]
=
{
{
13107
,
8066
,
5243
},
{
11916
,
7490
,
4660
},
{
10082
,
6554
,
4194
},
{
9362
,
5825
,
3647
},
{
8192
,
5243
,
3355
},
{
7282
,
4559
,
2893
},
};
static
const
int
quant8_scan
[
16
]
=
{
0
,
3
,
4
,
3
,
3
,
1
,
5
,
1
,
4
,
5
,
2
,
5
,
3
,
1
,
5
,
1
};
static
const
int
dequant8_scale
[
6
][
6
]
=
{
{
20
,
18
,
32
,
19
,
25
,
24
},
{
22
,
19
,
35
,
21
,
28
,
26
},
{
26
,
23
,
42
,
24
,
33
,
31
},
{
28
,
25
,
45
,
26
,
35
,
33
},
{
32
,
28
,
51
,
30
,
40
,
38
},
{
36
,
32
,
58
,
34
,
46
,
43
},
};
static
const
int
quant8_scale
[
6
][
6
]
=
{
{
13107
,
11428
,
20972
,
12222
,
16777
,
15481
},
{
11916
,
10826
,
19174
,
11058
,
14980
,
14290
},
{
10082
,
8943
,
15978
,
9675
,
12710
,
11985
},
{
9362
,
8228
,
14913
,
8931
,
11984
,
11259
},
{
8192
,
7346
,
13159
,
7740
,
10486
,
9777
},
{
7282
,
6428
,
11570
,
6830
,
9118
,
8640
}
};
void
x264_cqm_init
(
x264_t
*
h
)
{
int
def_quant4
[
6
][
16
];
int
def_quant8
[
6
][
64
];
int
def_dequant4
[
6
][
16
];
int
def_dequant8
[
6
][
64
];
int
q
,
i
,
i_list
;
for
(
q
=
0
;
q
<
6
;
q
++
)
{
for
(
i
=
0
;
i
<
16
;
i
++
)
{
int
j
=
(
i
&
1
)
+
((
i
>>
2
)
&
1
);
def_dequant4
[
q
][
i
]
=
dequant4_scale
[
q
][
j
];
def_quant4
[
q
][
i
]
=
quant4_scale
[
q
][
j
];
}
for
(
i
=
0
;
i
<
64
;
i
++
)
{
int
j
=
quant8_scan
[((
i
>>
1
)
&
12
)
|
(
i
&
3
)];
def_dequant8
[
q
][
i
]
=
dequant8_scale
[
q
][
j
];
def_quant8
[
q
][
i
]
=
quant8_scale
[
q
][
j
];
}
}
for
(
q
=
0
;
q
<
6
;
q
++
)
{
for
(
i_list
=
0
;
i_list
<
4
;
i_list
++
)
for
(
i
=
0
;
i
<
16
;
i
++
)
{
h
->
dequant4_mf
[
i_list
][
q
][
0
][
i
]
=
def_dequant4
[
q
][
i
]
*
h
->
pps
->
scaling_list
[
i_list
][
i
];
h
->
quant4_mf
[
i_list
][
q
][
0
][
i
]
=
def_quant4
[
q
][
i
]
*
16
/
h
->
pps
->
scaling_list
[
i_list
][
i
];
}
for
(
i_list
=
0
;
i_list
<
2
;
i_list
++
)
for
(
i
=
0
;
i
<
64
;
i
++
)
{
h
->
dequant8_mf
[
i_list
][
q
][
0
][
i
]
=
def_dequant8
[
q
][
i
]
*
h
->
pps
->
scaling_list
[
4
+
i_list
][
i
];
h
->
quant8_mf
[
i_list
][
q
][
0
][
i
]
=
def_quant8
[
q
][
i
]
*
16
/
h
->
pps
->
scaling_list
[
4
+
i_list
][
i
];
}
}
}
common/set.h
View file @
1ab01bbc
...
...
@@ -35,6 +35,19 @@ enum profile_e
PROFILE_HIGH444
=
144
};
enum
cqm4_e
{
CQM_4IY
=
0
,
CQM_4PY
=
1
,
CQM_4IC
=
2
,
CQM_4PC
=
3
};
enum
cqm8_e
{
CQM_8IY
=
0
,
CQM_8PY
=
1
};
typedef
struct
{
int
i_id
;
...
...
@@ -147,6 +160,60 @@ typedef struct
int
b_transform_8x8_mode
;
int
i_cqm_preset
;
const
uint8_t
*
scaling_list
[
6
];
/* could be 8, but we don't allow separate Cb/Cr lists */
}
x264_pps_t
;
/* default quant matrices */
static
const
uint8_t
x264_cqm_jvt4i
[
16
]
=
{
6
,
13
,
20
,
28
,
13
,
20
,
28
,
32
,
20
,
28
,
32
,
37
,
28
,
32
,
37
,
42
};
static
const
uint8_t
x264_cqm_jvt4p
[
16
]
=
{
10
,
14
,
20
,
24
,
14
,
20
,
24
,
27
,
20
,
24
,
27
,
30
,
24
,
27
,
30
,
34
};
static
const
uint8_t
x264_cqm_jvt8i
[
64
]
=
{
6
,
10
,
13
,
16
,
18
,
23
,
25
,
27
,
10
,
11
,
16
,
18
,
23
,
25
,
27
,
29
,
13
,
16
,
18
,
23
,
25
,
27
,
29
,
31
,
16
,
18
,
23
,
25
,
27
,
29
,
31
,
33
,
18
,
23
,
25
,
27
,
29
,
31
,
33
,
36
,
23
,
25
,
27
,
29
,
31
,
33
,
36
,
38
,
25
,
27
,
29
,
31
,
33
,
36
,
38
,
40
,
27
,
29
,
31
,
33
,
36
,
38
,
40
,
42
};
static
const
uint8_t
x264_cqm_jvt8p
[
64
]
=
{
9
,
13
,
15
,
17
,
19
,
21
,
22
,
24
,
13
,
13
,
17
,
19
,
21
,
22
,
24
,
25
,
15
,
17
,
19
,
21
,
22
,
24
,
25
,
27
,
17
,
19
,
21
,
22
,
24
,
25
,
27
,
28
,
19
,
21
,
22
,
24
,
25
,
27
,
28
,
30
,
21
,
22
,
24
,
25
,
27
,
28
,
30
,
32
,
22
,
24
,
25
,
27
,
28
,
30
,
32
,
33
,
24
,
25
,
27
,
28
,
30
,
32
,
33
,
35
};
static
const
uint8_t
x264_cqm_flat16
[
64
]
=
{
16
,
16
,
16
,
16
,
16
,
16
,
16
,
16
,
16
,
16
,
16
,
16
,
16
,
16
,
16
,
16
,
16
,
16
,
16
,
16
,
16
,
16
,
16
,
16
,
16
,
16
,
16
,
16
,
16
,
16
,
16
,
16
,
16
,
16
,
16
,
16
,
16
,
16
,
16
,
16
,
16
,
16
,
16
,
16
,
16
,
16
,
16
,
16
,
16
,
16
,
16
,
16
,
16
,
16
,
16
,
16
,
16
,
16
,
16
,
16
,
16
,
16
,
16
,
16
};
void
x264_cqm_init
(
x264_t
*
h
);
#endif
encoder/encoder.c
View file @
1ab01bbc
...
...
@@ -387,6 +387,7 @@ static int x264_validate_parameters( x264_t *h )
{
h
->
mb
.
b_lossless
=
1
;
h
->
param
.
analyse
.
b_transform_8x8
=
0
;
h
->
param
.
i_cqm_preset
=
X264_CQM_FLAT
;
h
->
param
.
rc
.
f_ip_factor
=
1
;
h
->
param
.
rc
.
f_pb_factor
=
1
;
h
->
param
.
analyse
.
b_psnr
=
0
;
...
...
@@ -414,6 +415,9 @@ static int x264_validate_parameters( x264_t *h )
if
(
h
->
param
.
i_threads
>
1
&&
h
->
param
.
i_cabac_init_idc
==
-
1
)
h
->
param
.
i_cabac_init_idc
=
0
;
if
(
h
->
param
.
i_cqm_preset
<
X264_CQM_FLAT
||
h
->
param
.
i_cqm_preset
>
X264_CQM_CUSTOM
)
h
->
param
.
i_cqm_preset
=
X264_CQM_FLAT
;
if
(
h
->
param
.
analyse
.
i_me_method
<
X264_ME_DIA
||
h
->
param
.
analyse
.
i_me_method
>
X264_ME_ESA
)
h
->
param
.
analyse
.
i_me_method
=
X264_ME_HEX
;
...
...
@@ -523,6 +527,8 @@ x264_t *x264_encoder_open ( x264_param_t *param )
h
->
pps
=
&
h
->
pps_array
[
0
];
x264_pps_init
(
h
->
pps
,
0
,
&
h
->
param
,
h
->
sps
);
x264_cqm_init
(
h
);
h
->
mb
.
i_mb_count
=
h
->
sps
->
i_mb_width
*
h
->
sps
->
i_mb_height
;
...
...
encoder/macroblock.c
View file @
1ab01bbc
...
...
@@ -45,7 +45,10 @@ static const uint8_t block_idx_xy[4][4] =
{
5
,
7
,
13
,
15
}
};
static
const
int
quant_mf
[
6
][
4
][
4
]
=
/* def_quant4_mf only for probe_skip; actual encoding uses matrices from set.c */
/* FIXME this seems to make better decisions with cqm=jvt, but could screw up
* with general custom matrices. */
static
const
int
def_quant4_mf
[
6
][
4
][
4
]
=
{
{
{
13107
,
8066
,
13107
,
8066
},
{
8066
,
5243
,
8066
,
5243
},
{
13107
,
8066
,
13107
,
8066
},
{
8066
,
5243
,
8066
,
5243
}
},
...
...
@@ -61,65 +64,6 @@ static const int quant_mf[6][4][4] =
{
7282
,
4559
,
7282
,
4559
},
{
4559
,
2893
,
4559
,
2893
}
}
};
const
int
quant8_mf
[
6
][
8
][
8
]
=
{
{
{
13107
,
12222
,
16777
,
12222
,
13107
,
12222
,
16777
,
12222
},
{
12222
,
11428
,
15481
,
11428
,
12222
,
11428
,
15481
,
11428
},
{
16777
,
15481
,
20972
,
15481
,
16777
,
15481
,
20972
,
15481
},
{
12222
,
11428
,
15481
,
11428
,
12222
,
11428
,
15481
,
11428
},
{
13107
,
12222
,
16777
,
12222
,
13107
,
12222
,
16777
,
12222
},
{
12222
,
11428
,
15481
,
11428
,
12222
,
11428
,
15481
,
11428
},
{
16777
,
15481
,
20972
,
15481
,
16777
,
15481
,
20972
,
15481
},
{
12222
,
11428
,
15481
,
11428
,
12222
,
11428
,
15481
,
11428
}
},
{
{
11916
,
11058
,
14980
,
11058
,
11916
,
11058
,
14980
,
11058
},
{
11058
,
10826
,
14290
,
10826
,
11058
,
10826
,
14290
,
10826
},
{
14980
,
14290
,
19174
,
14290
,
14980
,
14290
,
19174
,
14290
},
{
11058
,
10826
,
14290
,
10826
,
11058
,
10826
,
14290
,
10826
},
{
11916
,
11058
,
14980
,
11058
,
11916
,
11058
,
14980
,
11058
},
{
11058
,
10826
,
14290
,
10826
,
11058
,
10826
,
14290
,
10826
},
{
14980
,
14290
,
19174
,
14290
,
14980
,
14290
,
19174
,
14290
},
{
11058
,
10826
,
14290
,
10826
,
11058
,
10826
,
14290
,
10826
}
},
{
{
10082
,
9675
,
12710
,
9675
,
10082
,
9675
,
12710
,
9675
},
{
9675
,
8943
,
11985
,
8943
,
9675
,
8943
,
11985
,
8943
},
{
12710
,
11985
,
15978
,
11985
,
12710
,
11985
,
15978
,
11985
},
{
9675
,
8943
,
11985
,
8943
,
9675
,
8943
,
11985
,
8943
},
{
10082
,
9675
,
12710
,
9675
,
10082
,
9675
,
12710
,
9675
},
{
9675
,
8943
,
11985
,
8943
,
9675
,
8943
,
11985
,
8943
},
{
12710
,
11985
,
15978
,
11985
,
12710
,
11985
,
15978
,
11985
},
{
9675
,
8943
,
11985
,
8943
,
9675
,
8943
,
11985
,
8943
}
},
{
{
9362
,
8931
,
11984
,
8931
,
9362
,
8931
,
11984
,
8931
},
{
8931
,
8228
,
11259
,
8228
,
8931
,
8228
,
11259
,
8228
},
{
11984
,
11259
,
14913
,
11259
,
11984
,
11259
,
14913
,
11259
},
{
8931
,
8228
,
11259
,
8228
,
8931
,
8228
,
11259
,
8228
},
{
9362
,
8931
,
11984
,
8931
,
9362
,
8931
,
11984
,
8931
},
{
8931
,
8228
,
11259
,
8228
,
8931
,
8228
,
11259
,
8228
},
{
11984
,
11259
,
14913
,
11259
,
11984
,
11259
,
14913
,
11259
},
{
8931
,
8228
,
11259
,
8228
,
8931
,
8228
,
11259
,
8228
}
},
{
{
8192
,
7740
,
10486
,
7740
,
8192
,
7740
,
10486
,
7740
},
{
7740
,
7346
,
9777
,
7346
,
7740
,
7346
,
9777
,
7346
},
{
10486
,
9777
,
13159
,
9777
,
10486
,
9777
,
13159
,
9777
},
{
7740
,
7346
,
9777
,
7346
,
7740
,
7346
,
9777
,
7346
},
{
8192
,
7740
,
10486
,
7740
,
8192
,
7740
,
10486
,
7740
},
{
7740
,
7346
,
9777
,
7346
,
7740
,
7346
,
9777
,
7346
},
{
10486
,
9777
,
13159
,
9777
,
10486
,
9777
,
13159
,
9777
},
{
7740
,
7346
,
9777
,
7346
,
7740
,
7346
,
9777
,
7346
}
},
{
{
7282
,
6830
,
9118
,
6830
,
7282
,
6830
,
9118
,
6830
},
{
6830
,
6428
,
8640
,
6428
,
6830
,
6428
,
8640
,
6428
},
{
9118
,
8640
,
11570
,
8640
,
9118
,
8640
,
11570
,
8640
},
{
6830
,
6428
,
8640
,
6428
,
6830
,
6428
,
8640
,
6428
},
{
7282
,
6830
,
9118
,
6830
,
7282
,
6830
,
9118
,
6830
},
{
6830
,
6428
,
8640
,
6428
,
6830
,
6428
,
8640
,
6428
},
{
9118
,
8640
,
11570
,
8640
,
9118
,
8640
,
11570
,
8640
},
{
6830
,
6428
,
8640
,
6428
,
6830
,
6428
,
8640
,
6428
}
}
};
static
const
int
i_chroma_qp_table
[
52
]
=
{
0
,
1
,
2
,
3
,
4
,
5
,
6
,
7
,
8
,
9
,
...
...
@@ -200,7 +144,7 @@ static inline void sub_zigzag_4x4( int level[15], const uint8_t *p_src, uint8_t
}
#undef ZIG
static
void
quant_8x8
(
int16_t
dct
[
8
][
8
],
int
i_qscale
,
int
b_intra
)
static
void
quant_8x8
(
int16_t
dct
[
8
][
8
],
int
quant_mf
[
6
][
8
][
8
],
int
i_qscale
,
int
b_intra
)
{
const
int
i_qbits
=
16
+
i_qscale
/
6
;
const
int
i_mf
=
i_qscale
%
6
;
...
...
@@ -212,13 +156,13 @@ static void quant_8x8( int16_t dct[8][8], int i_qscale, int b_intra )
for
(
x
=
0
;
x
<
8
;
x
++
)
{
if
(
dct
[
y
][
x
]
>
0
)
dct
[
y
][
x
]
=
(
f
+
dct
[
y
][
x
]
*
quant
8
_mf
[
i_mf
][
y
][
x
]
)
>>
i_qbits
;
dct
[
y
][
x
]
=
(
f
+
dct
[
y
][
x
]
*
quant_mf
[
i_mf
][
y
][
x
]
)
>>
i_qbits
;
else
dct
[
y
][
x
]
=
-
(
(
f
-
dct
[
y
][
x
]
*
quant
8
_mf
[
i_mf
][
y
][
x
]
)
>>
i_qbits
);
dct
[
y
][
x
]
=
-
(
(
f
-
dct
[
y
][
x
]
*
quant_mf
[
i_mf
][
y
][
x
]
)
>>
i_qbits
);
}
}
}
static
void
quant_4x4
(
int16_t
dct
[
4
][
4
],
int
i_qscale
,
int
b_intra
)
static
void
quant_4x4
(
int16_t
dct
[
4
][
4
],
int
quant_mf
[
6
][
4
][
4
],