An image encoding apparatus comprising:
- a quantization unit configured to quantize transform coefficients in a block in an image, using a first quantization matrix;
- and
- an encoding unit configured to encode the first quantization matrix,
- wherein in a case where a first mode is used to encode the first quantization matrix, the encoding unit encodes, into a scaling list data syntax structure, (i) information indicating that the first quantization matrix is the same as a second quantization matrix to be referenced and (ii) information for specifying the second quantization matrix,
- wherein in a case where a second mode is used to encode the first quantization matrix, the encoding unit encodes, into the scaling list data syntax structure, the information for specifying the second quantization matrix, and encodes information used to derive a first one-dimensional matrix comprising of a plurality of elements comprising:
- (a) a first element which is a 1st element in a predetermined scan order and which is an element of a difference value between an element at a 1st row and a 1st column of the first quantization matrix and an element at a 1st row and a 1st column of the second quantization matrix;
- (b) a second element which is a 2nd element in the predetermined scan order and which is an element of a difference value between an element at a 2nd row and a 1st column of the first quantization matrix and an element at a 2nd row and a 1st column of the second quantization matrix;
- (c) a third element which is a 3rd element in the predetermined scan order and which is an element of a difference value between an element at a 1st row and a 2nd column of the first quantization matrix and an element at a 1st row and a 2nd column of the second quantization matrix, and
- wherein in a case where a third mode is used to encode the first quantization matrix, the encoding unit encodes a difference value of two consecutive elements in the predetermined scan order within the first quantization matrix so that the encoding unit;
- (a) encodes, into the scaling list data syntax structure, a difference value between (i) the element, corresponding to a 1st element in the predetermined scan order, at the 1st row and the 1st column of the first quantization matrix and (ii) a predetermined value and;
- (b) encodes, into the scaling list data syntax structure, a difference value between (i) the element, corresponding to a 2nd element in the predetermined scan order, at the 2nd row and the 1st column of the first quantization matrix and (ii) the element at the 1st row and the 1st column of the first quantization matrix;
- (c) encodes, into the scaling list data syntax structure, a difference value between (i) the element, corresponding to a 3rd element in the predetermined scan order, at the 1st row and the 2nd column of the first quantization matrix and (ii) the element at the 2nd row and the 1st column of the first quantization matrix;
- and
- (d) encodes, into the scaling list data syntax structure, a difference value between (i) an element, corresponding to a 4th element in the predetermined scan order, at the 3rd row and the 1st column of the first quantization matrix and (ii) the element at the 1st row and the 2nd column of the first quantization matrix,
- wherein the decoding unit is capable of using, as the second quantization matrix, a quantization matrix all elements of which are set as 16,
- wherein a code amount of information representing that the first mode is used is less than a code amount of information representing that the second mode is used,
- wherein the code amount of information representing that the first mode is used is not greater than a code amount of information representing that the third mode is used,
- wherein a size of the second quantization matrix can only be 2×2, 4×4, or 8×8, And
- wherein in a case where a size of the first quantization matrix to be encoded is 4×4, the size of the second quantization matrix is 4×4.