| 1 |
/* |
| 2 |
* Copyright (c) 2017, Intel Corporation |
| 3 |
* |
| 4 |
* Permission is hereby granted, free of charge, to any person obtaining a |
| 5 |
* copy of this software and associated documentation files (the "Software"), |
| 6 |
* to deal in the Software without restriction, including without limitation |
| 7 |
* the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 8 |
* and/or sell copies of the Software, and to permit persons to whom the |
| 9 |
* Software is furnished to do so, subject to the following conditions: |
| 10 |
* |
| 11 |
* The above copyright notice and this permission notice shall be included |
| 12 |
* in all copies or substantial portions of the Software. |
| 13 |
* |
| 14 |
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS |
| 15 |
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 16 |
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 17 |
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR |
| 18 |
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, |
| 19 |
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
| 20 |
* OTHER DEALINGS IN THE SOFTWARE. |
| 21 |
*/ |
| 22 |
//! |
| 23 |
//! \file codec_def_encode_jpeg.h |
| 24 |
//! \brief Defines encode JPEG types and macros shared by CodecHal, MHW, and DDI layer |
| 25 |
//! \details Applies to JPEG encode only. Should not contain any DDI specific code. |
| 26 |
//! |
| 27 |
|
| 28 |
#ifndef __CODEC_DEF_ENCODE_JPEG_H__ |
| 29 |
#define __CODEC_DEF_ENCODE_JPEG_H__ |
| 30 |
|
| 31 |
#include "codec_def_common_jpeg.h" |
| 32 |
#include "codec_def_common_encode.h" |
| 33 |
|
| 34 |
#define JPEG_MAX_NUM_QUANT_TABLE_INDEX 3 // Max 3 quant tables are allowed for encode |
| 35 |
#define JPEG_MAX_QUANT_TABLE 3 // MAx Number of Quantization tables that can be sent by the application |
| 36 |
#define JPEG_NUM_ENCODE_HUFF_BUFF 4 // Total number of Huffman tables that app can send for JPEG encode (2AC and 2DC tables allowed per frame) |
| 37 |
|
| 38 |
// Max supported resolution for JPEG encode is 16K X 16K |
| 39 |
#define ENCODE_JPEG_MAX_PIC_WIDTH 16384 |
| 40 |
#define ENCODE_JPEG_MAX_PIC_HEIGHT 16384 |
| 41 |
|
| 42 |
#define JPEG_MAX_NUM_HUFF_TABLES 2 // Max 2 sets of Huffman Tables are allowed (2AC and 2 DC) |
| 43 |
|
| 44 |
//! |
| 45 |
//! \struct CodecEncodeJpegQuantTable |
| 46 |
//! \brief Define JPEG Quant Table |
| 47 |
//! |
| 48 |
struct CodecEncodeJpegQuantTable |
| 49 |
{ |
| 50 |
struct |
| 51 |
{ |
| 52 |
uint32_t m_tableID; //!< Table ID |
| 53 |
uint32_t m_precision; //!< Precision |
| 54 |
uint16_t m_qm[JPEG_NUM_QUANTMATRIX]; //!< Quant Matrix |
| 55 |
} m_quantTable[JPEG_MAX_NUM_QUANT_TABLE_INDEX]; //!< Quant table array |
| 56 |
}; |
| 57 |
|
| 58 |
//! |
| 59 |
//! \struct CodecEncodeJpegHuffData |
| 60 |
//! \brief Define Huffman data for JPEG encode |
| 61 |
//! |
| 62 |
struct CodecEncodeJpegHuffData |
| 63 |
{ |
| 64 |
uint32_t m_tableClass; //!< table class |
| 65 |
uint32_t m_tableID; //!< table ID |
| 66 |
uint8_t m_bits[JPEG_NUM_HUFF_TABLE_AC_BITS]; //!< AC bits |
| 67 |
uint8_t m_huffVal[JPEG_NUM_HUFF_TABLE_AC_HUFFVAL]; //!< AC Huffman value |
| 68 |
}; |
| 69 |
|
| 70 |
//! |
| 71 |
//! \struct CodecEncodeJpegHuffmanDataArray |
| 72 |
//! \brief Define Huffman data array for JPEG encode |
| 73 |
//! |
| 74 |
struct CodecEncodeJpegHuffmanDataArray |
| 75 |
{ |
| 76 |
//!< huffmanData[0] --> Table for DC component of luma |
| 77 |
//!< huffmanData[1] --> Table for AC component of luma |
| 78 |
//!< huffmanData[2] --> Table for DC component of chroma |
| 79 |
//!< huffmanData[3] --> Table for AC component of chroma |
| 80 |
CodecEncodeJpegHuffData m_huffmanData[JPEG_NUM_ENCODE_HUFF_BUFF]; |
| 81 |
}; |
| 82 |
|
| 83 |
//! |
| 84 |
//! \enum CodecEncodeJpegInputSurfaceFormat |
| 85 |
//! \brief matches up with InputSurfaceFormats |
| 86 |
//! (converted from MOS format in ConvertMediaFormatToInputSurfaceFormat()) |
| 87 |
//! May want to unify enums instead of casting |
| 88 |
//! |
| 89 |
enum CodecEncodeJpegInputSurfaceFormat |
| 90 |
{ |
| 91 |
codechalJpegNV12 = 1, //!< NV12 surface format |
| 92 |
codechalJpegUYVY = 2, //!< UYVY surface format |
| 93 |
codechalJpegYUY2 = 3, //!< YUY2 surface format |
| 94 |
codechalJpegY8 = 4, //!< Y8 surface format |
| 95 |
codechalJpegRGB = 5 //!< RGB surface format |
| 96 |
}; |
| 97 |
|
| 98 |
//! |
| 99 |
//! \struct CodecEncodeJpegPictureParams |
| 100 |
//! \brief Picture Parameter Set for JPEG Encode |
| 101 |
//! |
| 102 |
struct CodecEncodeJpegPictureParams |
| 103 |
{ |
| 104 |
uint32_t m_profile : 2; //!< Profile. 0 -Baseline, 1 - Extended, 2 - Lossless, 3 - Hierarchical |
| 105 |
uint32_t m_progressive : 1; //!< Progressive flag. 1- Progressive, 0 - Sequential |
| 106 |
uint32_t m_huffman : 1; //!< Huffman flag. 1 - Huffman , 0 - Arithmetic |
| 107 |
uint32_t m_interleaved : 1; //!< Interleaved flag. 1 - Interleaved, 0 - NonInterleaved |
| 108 |
uint32_t m_differential : 1; //!< Differential flag. 1 - Differential, 0 - NonDifferential |
| 109 |
|
| 110 |
uint32_t m_picWidth; //!< Picture Width |
| 111 |
uint32_t m_picHeight; //!< Picture Height |
| 112 |
|
| 113 |
uint32_t m_inputSurfaceFormat; //!< Input surface format |
| 114 |
uint32_t m_sampleBitDepth; //!< Sample bit depth |
| 115 |
|
| 116 |
uint32_t m_numComponent; //!< Component Number |
| 117 |
uint8_t m_componentID[4]; //!< Component ID |
| 118 |
uint8_t m_quantTableSelector[4]; //!< Quant table selector |
| 119 |
|
| 120 |
uint32_t m_quality; //!< Quality |
| 121 |
|
| 122 |
uint32_t m_numScan; //!< Scan number |
| 123 |
uint32_t m_numQuantTable; //!< Quant table number |
| 124 |
uint32_t m_numCodingTable; //!< Coding table number |
| 125 |
|
| 126 |
uint32_t m_statusReportFeedbackNumber; //!< Status report feedback number |
| 127 |
|
| 128 |
}; |
| 129 |
|
| 130 |
//! |
| 131 |
//! \struct CodecEncodeJpegScanHeader |
| 132 |
//! \brief Scan Header structure for JPEG Encode |
| 133 |
//! |
| 134 |
struct CodecEncodeJpegScanHeader |
| 135 |
{ |
| 136 |
uint32_t m_restartInterval; //!< Restart Interval |
| 137 |
|
| 138 |
uint32_t m_numComponent; //!< Component number |
| 139 |
uint8_t m_componentSelector[4]; //!< Component selector |
| 140 |
uint8_t m_dcCodingTblSelector[4]; //!< DC coding table selector |
| 141 |
uint8_t m_acCodingTblSelector[4]; //!< AC coding table selector |
| 142 |
|
| 143 |
uint32_t FirstDCTCoeff; |
| 144 |
uint32_t LastDCTCoeff; |
| 145 |
uint32_t Ah; |
| 146 |
uint32_t Al; |
| 147 |
}; |
| 148 |
|
| 149 |
// matrix required to read in the quantization matrix |
| 150 |
static const uint8_t jpeg_qm_scan_8x8[64] = |
| 151 |
{ |
| 152 |
// Zig-Zag scan pattern |
| 153 |
0, 1, 8, 16, 9, 2, 3, 10, |
| 154 |
17, 24, 32, 25, 18, 11, 4, 5, |
| 155 |
12, 19, 26, 33, 40, 48, 41, 34, |
| 156 |
27, 20, 13, 6, 7, 14, 21, 28, |
| 157 |
35, 42, 49, 56, 57, 50, 43, 36, |
| 158 |
29, 22, 15, 23, 30, 37, 44, 51, |
| 159 |
58, 59, 52, 45, 38, 31, 39, 46, |
| 160 |
53, 60, 61, 54, 47, 55, 62, 63 |
| 161 |
}; |
| 162 |
|
| 163 |
#endif // __CODEC_DEF_ENCODE_JPEG_H__ |