| 1 | /***************************************************************************** |
| 2 | * Copyright (C) 2014 x265 project |
| 3 | * |
| 4 | * Authors: Steve Borho <steve@borho.org> |
| 5 | * |
| 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. |
| 10 | * |
| 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. |
| 15 | * |
| 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. |
| 19 | * |
| 20 | * This program is also available under a commercial proprietary license. |
| 21 | * For more information, contact us at license @ x265.com. |
| 22 | *****************************************************************************/ |
| 23 | |
| 24 | #ifndef X265_SCALINGLIST_H |
| 25 | #define X265_SCALINGLIST_H |
| 26 | |
| 27 | #include "common.h" |
| 28 | |
| 29 | namespace x265 { |
| 30 | // private namespace |
| 31 | |
| 32 | class ScalingList |
| 33 | { |
| 34 | public: |
| 35 | |
| 36 | enum { NUM_SIZES = 4 }; // 4x4, 8x8, 16x16, 32x32 |
| 37 | enum { NUM_LISTS = 6 }; // number of quantization matrix lists (YUV * inter/intra) |
| 38 | enum { NUM_REM = 6 }; // number of remainders of QP/6 |
| 39 | enum { MAX_MATRIX_COEF_NUM = 64 }; // max coefficient number per quantization matrix |
| 40 | enum { MAX_MATRIX_SIZE_NUM = 8 }; // max size number for quantization matrix |
| 41 | |
| 42 | static const int s_numCoefPerSize[NUM_SIZES]; |
| 43 | static const int32_t s_invQuantScales[NUM_REM]; |
| 44 | static const int32_t s_quantScales[NUM_REM]; |
| 45 | |
| 46 | int32_t m_scalingListDC[NUM_SIZES][NUM_LISTS]; // the DC value of the matrix coefficient for 16x16 |
| 47 | int32_t* m_scalingListCoef[NUM_SIZES][NUM_LISTS]; // quantization matrix |
| 48 | |
| 49 | int32_t* m_quantCoef[NUM_SIZES][NUM_LISTS][NUM_REM]; // array of quantization matrix coefficient 4x4 |
| 50 | int32_t* m_dequantCoef[NUM_SIZES][NUM_LISTS][NUM_REM]; // array of dequantization matrix coefficient 4x4 |
| 51 | |
| 52 | bool m_bEnabled; |
| 53 | bool m_bDataPresent; // non-default scaling lists must be signaled |
| 54 | |
| 55 | ScalingList(); |
| 56 | ~ScalingList(); |
| 57 | |
| 58 | bool init(); |
| 59 | void setDefaultScalingList(); |
| 60 | bool parseScalingList(const char* filename); |
| 61 | void setupQuantMatrices(); |
| 62 | |
| 63 | /* used during SPS coding */ |
| 64 | int checkPredMode(int sizeId, int listId) const; |
| 65 | |
| 66 | protected: |
| 67 | |
| 68 | static const int SCALING_LIST_DC = 16; // default DC value |
| 69 | |
| 70 | const int32_t* getScalingListDefaultAddress(int sizeId, int listId) const; |
| 71 | void processDefaultMarix(int sizeId, int listId); |
| 72 | bool checkDefaultScalingList() const; |
| 73 | |
| 74 | void processScalingListEnc(int32_t *coeff, int32_t *quantcoeff, int32_t quantScales, int height, int width, int ratio, int stride, int32_t dc); |
| 75 | void processScalingListDec(int32_t *coeff, int32_t *dequantcoeff, int32_t invQuantScales, int height, int width, int ratio, int stride, int32_t dc); |
| 76 | }; |
| 77 | |
| 78 | } |
| 79 | |
| 80 | #endif // ifndef X265_SCALINGLIST_H |