• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2019 The libgav1 Authors
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef LIBGAV1_SRC_UTILS_CONSTANTS_H_
18 #define LIBGAV1_SRC_UTILS_CONSTANTS_H_
19 
20 #include <cstdint>
21 #include <cstdlib>
22 
23 #include "src/utils/bit_mask_set.h"
24 
25 namespace libgav1 {
26 
27 // Returns the number of elements between begin (inclusive) and end (inclusive).
EnumRangeLength(int begin,int end)28 constexpr int EnumRangeLength(int begin, int end) { return end - begin + 1; }
29 
30 enum {
31 // Maximum number of threads that the library will ever create.
32 #if defined(LIBGAV1_MAX_THREADS) && LIBGAV1_MAX_THREADS > 0
33   kMaxThreads = LIBGAV1_MAX_THREADS
34 #else
35   kMaxThreads = 128
36 #endif
37 };  // anonymous enum
38 
39 enum {
40   kInvalidMvValue = -32768,
41   kCdfMaxProbability = 32768,
42   kBlockWidthCount = 5,
43   kMaxSegments = 8,
44   kMinQuantizer = 0,
45   kMinLossyQuantizer = 1,
46   kMaxQuantizer = 255,
47   // Quantizer matrix is used only when level < 15.
48   kNumQuantizerLevelsForQuantizerMatrix = 15,
49   kFrameLfCount = 4,
50   kMaxLoopFilterValue = 63,
51   kNum4x4In64x64 = 256,
52   kMaxAngleDelta = 3,
53   kDirectionalIntraModes = 8,
54   kMaxSuperBlockSizeLog2 = 7,
55   kMinSuperBlockSizeLog2 = 6,
56   kGlobalMotionReadControl = 3,
57   kSuperResScaleNumerator = 8,
58   kBooleanSymbolCount = 2,
59   kRestorationTypeSymbolCount = 3,
60   kSgrProjParamsBits = 4,
61   kSgrProjPrecisionBits = 7,
62   // Padding on left and right side of a restoration block.
63   // 3 is enough, but padding to 4 is more efficient, and makes the temporary
64   // source buffer 8-pixel aligned.
65   kRestorationHorizontalBorder = 4,
66   // Padding on top and bottom side of a restoration block.
67   kRestorationVerticalBorder = 2,
68   kCdefBorder = 2,             // Padding on each side of a cdef block.
69   kConvolveBorderLeftTop = 3,  // Left/top padding of a convolve block.
70   // Right/bottom padding of a convolve block. This needs to be 4 at minimum,
71   // but was increased to simplify the SIMD loads in
72   // ConvolveCompoundScale2D_NEON() and ConvolveScale2D_NEON().
73   kConvolveBorderRight = 8,
74   kConvolveScaleBorderRight = 15,
75   kConvolveBorderBottom = 4,
76   kSubPixelTaps = 8,
77   kWienerFilterBits = 7,
78   kWienerFilterTaps = 7,
79   kMaxPaletteSize = 8,
80   kMinPaletteSize = 2,
81   kMaxPaletteSquare = 64,
82   kBorderPixels = 64,
83   // The final blending process for film grain needs room to overwrite and read
84   // with SIMD instructions. The maximum overwrite is 7 pixels, but the border
85   // is required to be a multiple of 32 by YuvBuffer::Realloc, so that
86   // subsampled chroma borders are 16-aligned.
87   kBorderPixelsFilmGrain = 32,
88   // These constants are the minimum left, right, top, and bottom border sizes
89   // in pixels as an extension of the frame boundary. The minimum border sizes
90   // are derived from the following requirements:
91   // - Warp_C() may read up to 13 pixels before or after a row.
92   // - Warp_NEON() may read up to 13 pixels before a row. It may read up to 14
93   //   pixels after a row, but the value of the last read pixel is not used.
94   // - Warp_C() and Warp_NEON() may read up to 13 pixels above the top row and
95   //   13 pixels below the bottom row.
96   kMinLeftBorderPixels = 13,
97   kMinRightBorderPixels = 13,
98   kMinTopBorderPixels = 13,
99   kMinBottomBorderPixels = 13,
100   kWarpedModelPrecisionBits = 16,
101   kMaxRefMvStackSize = 8,
102   kMaxLeastSquaresSamples = 8,
103   kMaxTemporalMvCandidates = 19,
104   // The SIMD implementations of motion vection projection functions always
105   // process 2 or 4 elements together, so we pad the corresponding buffers to
106   // size 20.
107   kMaxTemporalMvCandidatesWithPadding = 20,
108   kMaxSuperBlockSizeInPixels = 128,
109   kMaxScaledSuperBlockSizeInPixels = 128 * 2,
110   kMaxSuperBlockSizeSquareInPixels = 128 * 128,
111   kNum4x4InLoopFilterUnit = 16,
112   kNum4x4InLoopRestorationUnit = 16,
113   kProjectionMvClamp = (1 << 14) - 1,  // == 16383
114   kProjectionMvMaxHorizontalOffset = 8,
115   kCdefUnitSize = 64,
116   kCdefUnitSizeWithBorders = kCdefUnitSize + 2 * kCdefBorder,
117   kRestorationUnitOffset = 8,
118   // Loop restoration's processing unit size is fixed as 64x64.
119   kRestorationUnitHeight = 64,
120   kRestorationUnitWidth = 256,
121   kRestorationUnitHeightWithBorders =
122       kRestorationUnitHeight + 2 * kRestorationVerticalBorder,
123   kRestorationUnitWidthWithBorders =
124       kRestorationUnitWidth + 2 * kRestorationHorizontalBorder,
125   kSuperResFilterBits = 6,
126   kSuperResFilterShifts = 1 << kSuperResFilterBits,
127   kSuperResFilterTaps = 8,
128   kSuperResScaleBits = 14,
129   kSuperResExtraBits = kSuperResScaleBits - kSuperResFilterBits,
130   kSuperResScaleMask = (1 << 14) - 1,
131   kSuperResHorizontalBorder = 4,
132   kSuperResVerticalBorder = 1,
133   // The SIMD implementations of superres calculate up to 15 extra upscaled
134   // pixels which will over-read up to 15 downscaled pixels in the end of each
135   // row. Set the padding to 16 for alignment purposes.
136   kSuperResHorizontalPadding = 16,
137   // TODO(chengchen): consider merging these constants:
138   // kFilterBits, kWienerFilterBits, and kSgrProjPrecisionBits, which are all 7,
139   // They are designed to match AV1 convolution, which increases coeff
140   // values up to 7 bits. We could consider to combine them and use kFilterBits
141   // only.
142   kFilterBits = 7,
143   // Sub pixel is used in AV1 to represent a pixel location that is not at
144   // integer position. Sub pixel is in 1/16 (1 << kSubPixelBits) unit of
145   // integer pixel. Sub pixel values are interpolated using adjacent integer
146   // pixel values. The interpolation is a filtering process.
147   kSubPixelBits = 4,
148   kSubPixelMask = (1 << kSubPixelBits) - 1,
149   // Precision bits when computing inter prediction locations.
150   kScaleSubPixelBits = 10,
151   kWarpParamRoundingBits = 6,
152   // Number of fractional bits of lookup in divisor lookup table.
153   kDivisorLookupBits = 8,
154   // Number of fractional bits of entries in divisor lookup table.
155   kDivisorLookupPrecisionBits = 14,
156   // Number of phases used in warped filtering.
157   kWarpedPixelPrecisionShifts = 1 << 6,
158   kResidualPaddingVertical = 4,
159   kWedgeMaskMasterSize = 64,
160   kMaxFrameDistance = 31,
161   kReferenceFrameScalePrecision = 14,
162   kNumWienerCoefficients = 3,
163   kLoopFilterMaxModeDeltas = 2,
164   kMaxCdefStrengths = 8,
165   kCdefLargeValue = 0x4000,  // Used to indicate where CDEF is not available.
166   kMaxTileColumns = 64,
167   kMaxTileRows = 64,
168   kMaxOperatingPoints = 32,
169   // There can be a maximum of 4 spatial layers and 8 temporal layers.
170   kMaxLayers = 32,
171   // The cache line size should ideally be queried at run time. 64 is a common
172   // cache line size of x86 CPUs. Web searches showed the cache line size of ARM
173   // CPUs is 32 or 64 bytes. So aligning to 64-byte boundary will work for all
174   // CPUs that we care about, even though it is excessive for some ARM
175   // CPUs.
176   //
177   // On Linux, the cache line size can be looked up with the command:
178   //   getconf LEVEL1_DCACHE_LINESIZE
179   kCacheLineSize = 64,
180 };  // anonymous enum
181 
182 enum FrameType : uint8_t {
183   kFrameKey,
184   kFrameInter,
185   kFrameIntraOnly,
186   kFrameSwitch
187 };
188 
189 enum Plane : uint8_t { kPlaneY, kPlaneU, kPlaneV };
190 enum : uint8_t { kMaxPlanesMonochrome = kPlaneY + 1, kMaxPlanes = kPlaneV + 1 };
191 
192 // The plane types, called luma and chroma in the spec.
193 enum PlaneType : uint8_t { kPlaneTypeY, kPlaneTypeUV, kNumPlaneTypes };
194 
195 enum ReferenceFrameType : int8_t {
196   kReferenceFrameNone = -1,
197   kReferenceFrameIntra,
198   kReferenceFrameLast,
199   kReferenceFrameLast2,
200   kReferenceFrameLast3,
201   kReferenceFrameGolden,
202   kReferenceFrameBackward,
203   kReferenceFrameAlternate2,
204   kReferenceFrameAlternate,
205   kNumReferenceFrameTypes,
206   kNumInterReferenceFrameTypes =
207       EnumRangeLength(kReferenceFrameLast, kReferenceFrameAlternate),
208   kNumForwardReferenceTypes =
209       EnumRangeLength(kReferenceFrameLast, kReferenceFrameGolden),
210   kNumBackwardReferenceTypes =
211       EnumRangeLength(kReferenceFrameBackward, kReferenceFrameAlternate)
212 };
213 
214 enum {
215   // Unidirectional compound reference pairs that are signaled explicitly:
216   // {kReferenceFrameLast, kReferenceFrameLast2},
217   // {kReferenceFrameLast, kReferenceFrameLast3},
218   // {kReferenceFrameLast, kReferenceFrameGolden},
219   // {kReferenceFrameBackward, kReferenceFrameAlternate}
220   kExplicitUnidirectionalCompoundReferences = 4,
221   // Other unidirectional compound reference pairs:
222   // {kReferenceFrameLast2, kReferenceFrameLast3},
223   // {kReferenceFrameLast2, kReferenceFrameGolden},
224   // {kReferenceFrameLast3, kReferenceFrameGolden},
225   // {kReferenceFrameBackward, kReferenceFrameAlternate2},
226   // {kReferenceFrameAlternate2, kReferenceFrameAlternate}
227   kUnidirectionalCompoundReferences =
228       kExplicitUnidirectionalCompoundReferences + 5,
229 };  // anonymous enum
230 
231 enum BlockSize : uint8_t {
232   kBlock4x4,
233   kBlock4x8,
234   kBlock4x16,
235   kBlock8x4,
236   kBlock8x8,
237   kBlock8x16,
238   kBlock8x32,
239   kBlock16x4,
240   kBlock16x8,
241   kBlock16x16,
242   kBlock16x32,
243   kBlock16x64,
244   kBlock32x8,
245   kBlock32x16,
246   kBlock32x32,
247   kBlock32x64,
248   kBlock64x16,
249   kBlock64x32,
250   kBlock64x64,
251   kBlock64x128,
252   kBlock128x64,
253   kBlock128x128,
254   kMaxBlockSizes,
255   kBlockInvalid
256 };
257 
258 //  Partition types.  R: Recursive
259 //
260 //  None          Horizontal    Vertical      Split
261 //  +-------+     +-------+     +---+---+     +---+---+
262 //  |       |     |       |     |   |   |     | R | R |
263 //  |       |     +-------+     |   |   |     +---+---+
264 //  |       |     |       |     |   |   |     | R | R |
265 //  +-------+     +-------+     +---+---+     +---+---+
266 //
267 //  Horizontal    Horizontal    Vertical      Vertical
268 //  with top      with bottom   with left     with right
269 //  split         split         split         split
270 //  +---+---+     +-------+     +---+---+     +---+---+
271 //  |   |   |     |       |     |   |   |     |   |   |
272 //  +---+---+     +---+---+     +---+   |     |   +---+
273 //  |       |     |   |   |     |   |   |     |   |   |
274 //  +-------+     +---+---+     +---+---+     +---+---+
275 //
276 //  Horizontal4   Vertical4
277 //  +-----+       +-+-+-+
278 //  +-----+       | | | |
279 //  +-----+       | | | |
280 //  +-----+       +-+-+-+
281 enum Partition : uint8_t {
282   kPartitionNone,
283   kPartitionHorizontal,
284   kPartitionVertical,
285   kPartitionSplit,
286   kPartitionHorizontalWithTopSplit,
287   kPartitionHorizontalWithBottomSplit,
288   kPartitionVerticalWithLeftSplit,
289   kPartitionVerticalWithRightSplit,
290   kPartitionHorizontal4,
291   kPartitionVertical4
292 };
293 enum : uint8_t { kMaxPartitionTypes = kPartitionVertical4 + 1 };
294 
295 enum PredictionMode : uint8_t {
296   // Intra prediction modes.
297   kPredictionModeDc,
298   kPredictionModeVertical,
299   kPredictionModeHorizontal,
300   kPredictionModeD45,
301   kPredictionModeD135,
302   kPredictionModeD113,
303   kPredictionModeD157,
304   kPredictionModeD203,
305   kPredictionModeD67,
306   kPredictionModeSmooth,
307   kPredictionModeSmoothVertical,
308   kPredictionModeSmoothHorizontal,
309   kPredictionModePaeth,
310   kPredictionModeChromaFromLuma,
311   // Single inter prediction modes.
312   kPredictionModeNearestMv,
313   kPredictionModeNearMv,
314   kPredictionModeGlobalMv,
315   kPredictionModeNewMv,
316   // Compound inter prediction modes.
317   kPredictionModeNearestNearestMv,
318   kPredictionModeNearNearMv,
319   kPredictionModeNearestNewMv,
320   kPredictionModeNewNearestMv,
321   kPredictionModeNearNewMv,
322   kPredictionModeNewNearMv,
323   kPredictionModeGlobalGlobalMv,
324   kPredictionModeNewNewMv,
325   kNumPredictionModes,
326   kNumCompoundInterPredictionModes =
327       EnumRangeLength(kPredictionModeNearestNearestMv, kPredictionModeNewNewMv),
328   kIntraPredictionModesY =
329       EnumRangeLength(kPredictionModeDc, kPredictionModePaeth),
330   kIntraPredictionModesUV =
331       EnumRangeLength(kPredictionModeDc, kPredictionModeChromaFromLuma),
332   kPredictionModeInvalid = 255
333 };
334 
335 enum InterIntraMode : uint8_t {
336   kInterIntraModeDc,
337   kInterIntraModeVertical,
338   kInterIntraModeHorizontal,
339   kInterIntraModeSmooth,
340   kNumInterIntraModes
341 };
342 
343 enum MotionMode : uint8_t {
344   kMotionModeSimple,
345   kMotionModeObmc,  // Overlapped block motion compensation.
346   kMotionModeLocalWarp,
347   kNumMotionModes
348 };
349 
350 enum TxMode : uint8_t {
351   kTxModeOnly4x4,
352   kTxModeLargest,
353   kTxModeSelect,
354   kNumTxModes
355 };
356 
357 // These enums are named as kType1Type2 where Type1 is the transform type for
358 // the rows and Type2 is the transform type for the columns.
359 enum TransformType : uint8_t {
360   kTransformTypeDctDct,
361   kTransformTypeAdstDct,
362   kTransformTypeDctAdst,
363   kTransformTypeAdstAdst,
364   kTransformTypeFlipadstDct,
365   kTransformTypeDctFlipadst,
366   kTransformTypeFlipadstFlipadst,
367   kTransformTypeAdstFlipadst,
368   kTransformTypeFlipadstAdst,
369   kTransformTypeIdentityIdentity,
370   kTransformTypeIdentityDct,
371   kTransformTypeDctIdentity,
372   kTransformTypeIdentityAdst,
373   kTransformTypeAdstIdentity,
374   kTransformTypeIdentityFlipadst,
375   kTransformTypeFlipadstIdentity,
376   kNumTransformTypes
377 };
378 
379 constexpr BitMaskSet kTransformFlipColumnsMask(kTransformTypeFlipadstDct,
380                                                kTransformTypeFlipadstAdst,
381                                                kTransformTypeFlipadstIdentity,
382                                                kTransformTypeFlipadstFlipadst);
383 constexpr BitMaskSet kTransformFlipRowsMask(kTransformTypeDctFlipadst,
384                                             kTransformTypeAdstFlipadst,
385                                             kTransformTypeIdentityFlipadst,
386                                             kTransformTypeFlipadstFlipadst);
387 
388 enum TransformSize : uint8_t {
389   kTransformSize4x4,
390   kTransformSize4x8,
391   kTransformSize4x16,
392   kTransformSize8x4,
393   kTransformSize8x8,
394   kTransformSize8x16,
395   kTransformSize8x32,
396   kTransformSize16x4,
397   kTransformSize16x8,
398   kTransformSize16x16,
399   kTransformSize16x32,
400   kTransformSize16x64,
401   kTransformSize32x8,
402   kTransformSize32x16,
403   kTransformSize32x32,
404   kTransformSize32x64,
405   kTransformSize64x16,
406   kTransformSize64x32,
407   kTransformSize64x64,
408   kNumTransformSizes
409 };
410 
411 enum TransformSet : uint8_t {
412   // DCT Only (1).
413   kTransformSetDctOnly,
414   // 2D-DCT and 2D-ADST without flip (4) + Identity (1) + 1D Horizontal/Vertical
415   // DCT (2) = Total (7).
416   kTransformSetIntra1,
417   // 2D-DCT and 2D-ADST without flip (4) + Identity (1) = Total (5).
418   kTransformSetIntra2,
419   // All transforms = Total (16).
420   kTransformSetInter1,
421   // 2D-DCT and 2D-ADST with flip (9) + Identity (1) + 1D Horizontal/Vertical
422   // DCT (2) = Total (12).
423   kTransformSetInter2,
424   // DCT (1) + Identity (1) = Total (2).
425   kTransformSetInter3,
426   kNumTransformSets
427 };
428 
429 enum TransformClass : uint8_t {
430   kTransformClass2D,
431   kTransformClassHorizontal,
432   kTransformClassVertical,
433   kNumTransformClasses
434 };
435 
436 enum FilterIntraPredictor : uint8_t {
437   kFilterIntraPredictorDc,
438   kFilterIntraPredictorVertical,
439   kFilterIntraPredictorHorizontal,
440   kFilterIntraPredictorD157,
441   kFilterIntraPredictorPaeth,
442   kNumFilterIntraPredictors
443 };
444 
445 enum ObmcDirection : uint8_t {
446   kObmcDirectionVertical,
447   kObmcDirectionHorizontal,
448   kNumObmcDirections
449 };
450 
451 // In AV1 the name of the filter refers to the direction of filter application.
452 // Horizontal refers to the column edge and vertical the row edge.
453 enum LoopFilterType : uint8_t {
454   kLoopFilterTypeVertical,
455   kLoopFilterTypeHorizontal,
456   kNumLoopFilterTypes
457 };
458 
459 enum LoopFilterTransformSizeId : uint8_t {
460   kLoopFilterTransformSizeId4x4,
461   kLoopFilterTransformSizeId8x8,
462   kLoopFilterTransformSizeId16x16,
463   kNumLoopFilterTransformSizeIds
464 };
465 
466 enum LoopRestorationType : uint8_t {
467   kLoopRestorationTypeNone,
468   kLoopRestorationTypeSwitchable,
469   kLoopRestorationTypeWiener,
470   kLoopRestorationTypeSgrProj,  // self guided projection filter.
471   kNumLoopRestorationTypes
472 };
473 
474 enum CompoundReferenceType : uint8_t {
475   kCompoundReferenceUnidirectional,
476   kCompoundReferenceBidirectional,
477   kNumCompoundReferenceTypes
478 };
479 
480 enum CompoundPredictionType : uint8_t {
481   kCompoundPredictionTypeWedge,
482   kCompoundPredictionTypeDiffWeighted,
483   kCompoundPredictionTypeAverage,
484   kCompoundPredictionTypeIntra,
485   kCompoundPredictionTypeDistance,
486   kNumCompoundPredictionTypes,
487   // Number of compound prediction types that are explicitly signaled in the
488   // bitstream (in the compound_type syntax element).
489   kNumExplicitCompoundPredictionTypes = 2
490 };
491 
492 enum InterpolationFilter : uint8_t {
493   kInterpolationFilterEightTap,
494   kInterpolationFilterEightTapSmooth,
495   kInterpolationFilterEightTapSharp,
496   kInterpolationFilterBilinear,
497   kInterpolationFilterSwitchable,
498   kNumInterpolationFilters,
499   // Number of interpolation filters that can be explicitly signaled in the
500   // compressed headers (when the uncompressed headers allow switchable
501   // interpolation filters) of the bitstream.
502   kNumExplicitInterpolationFilters = EnumRangeLength(
503       kInterpolationFilterEightTap, kInterpolationFilterEightTapSharp)
504 };
505 
506 enum MvJointType : uint8_t {
507   kMvJointTypeZero,
508   kMvJointTypeHorizontalNonZeroVerticalZero,
509   kMvJointTypeHorizontalZeroVerticalNonZero,
510   kMvJointTypeNonZero,
511   kNumMvJointTypes
512 };
513 
514 enum ObuType : int8_t {
515   kObuInvalid = -1,
516   kObuSequenceHeader = 1,
517   kObuTemporalDelimiter = 2,
518   kObuFrameHeader = 3,
519   kObuTileGroup = 4,
520   kObuMetadata = 5,
521   kObuFrame = 6,
522   kObuRedundantFrameHeader = 7,
523   kObuTileList = 8,
524   kObuPadding = 15,
525 };
526 
527 constexpr BitMaskSet kPredictionModeSmoothMask(kPredictionModeSmooth,
528                                                kPredictionModeSmoothHorizontal,
529                                                kPredictionModeSmoothVertical);
530 
531 //------------------------------------------------------------------------------
532 // ToString()
533 //
534 // These functions are meant to be used only in debug logging and within tests.
535 // They are defined inline to avoid including the strings in the release
536 // library when logging is disabled; unreferenced functions will not be added to
537 // any object file in that case.
538 
ToString(const BlockSize size)539 inline const char* ToString(const BlockSize size) {
540   switch (size) {
541     case kBlock4x4:
542       return "kBlock4x4";
543     case kBlock4x8:
544       return "kBlock4x8";
545     case kBlock4x16:
546       return "kBlock4x16";
547     case kBlock8x4:
548       return "kBlock8x4";
549     case kBlock8x8:
550       return "kBlock8x8";
551     case kBlock8x16:
552       return "kBlock8x16";
553     case kBlock8x32:
554       return "kBlock8x32";
555     case kBlock16x4:
556       return "kBlock16x4";
557     case kBlock16x8:
558       return "kBlock16x8";
559     case kBlock16x16:
560       return "kBlock16x16";
561     case kBlock16x32:
562       return "kBlock16x32";
563     case kBlock16x64:
564       return "kBlock16x64";
565     case kBlock32x8:
566       return "kBlock32x8";
567     case kBlock32x16:
568       return "kBlock32x16";
569     case kBlock32x32:
570       return "kBlock32x32";
571     case kBlock32x64:
572       return "kBlock32x64";
573     case kBlock64x16:
574       return "kBlock64x16";
575     case kBlock64x32:
576       return "kBlock64x32";
577     case kBlock64x64:
578       return "kBlock64x64";
579     case kBlock64x128:
580       return "kBlock64x128";
581     case kBlock128x64:
582       return "kBlock128x64";
583     case kBlock128x128:
584       return "kBlock128x128";
585     case kMaxBlockSizes:
586       return "kMaxBlockSizes";
587     case kBlockInvalid:
588       return "kBlockInvalid";
589   }
590   abort();
591 }
592 
ToString(const InterIntraMode mode)593 inline const char* ToString(const InterIntraMode mode) {
594   switch (mode) {
595     case kInterIntraModeDc:
596       return "kInterIntraModeDc";
597     case kInterIntraModeVertical:
598       return "kInterIntraModeVertical";
599     case kInterIntraModeHorizontal:
600       return "kInterIntraModeHorizontal";
601     case kInterIntraModeSmooth:
602       return "kInterIntraModeSmooth";
603     case kNumInterIntraModes:
604       return "kNumInterIntraModes";
605   }
606   abort();
607 }
608 
ToString(const ObmcDirection direction)609 inline const char* ToString(const ObmcDirection direction) {
610   switch (direction) {
611     case kObmcDirectionVertical:
612       return "kObmcDirectionVertical";
613     case kObmcDirectionHorizontal:
614       return "kObmcDirectionHorizontal";
615     case kNumObmcDirections:
616       return "kNumObmcDirections";
617   }
618   abort();
619 }
620 
ToString(const LoopRestorationType type)621 inline const char* ToString(const LoopRestorationType type) {
622   switch (type) {
623     case kLoopRestorationTypeNone:
624       return "kLoopRestorationTypeNone";
625     case kLoopRestorationTypeSwitchable:
626       return "kLoopRestorationTypeSwitchable";
627     case kLoopRestorationTypeWiener:
628       return "kLoopRestorationTypeWiener";
629     case kLoopRestorationTypeSgrProj:
630       return "kLoopRestorationTypeSgrProj";
631     case kNumLoopRestorationTypes:
632       return "kNumLoopRestorationTypes";
633   }
634   abort();
635 }
636 
ToString(const TransformSize size)637 inline const char* ToString(const TransformSize size) {
638   switch (size) {
639     case kTransformSize4x4:
640       return "kTransformSize4x4";
641     case kTransformSize4x8:
642       return "kTransformSize4x8";
643     case kTransformSize4x16:
644       return "kTransformSize4x16";
645     case kTransformSize8x4:
646       return "kTransformSize8x4";
647     case kTransformSize8x8:
648       return "kTransformSize8x8";
649     case kTransformSize8x16:
650       return "kTransformSize8x16";
651     case kTransformSize8x32:
652       return "kTransformSize8x32";
653     case kTransformSize16x4:
654       return "kTransformSize16x4";
655     case kTransformSize16x8:
656       return "kTransformSize16x8";
657     case kTransformSize16x16:
658       return "kTransformSize16x16";
659     case kTransformSize16x32:
660       return "kTransformSize16x32";
661     case kTransformSize16x64:
662       return "kTransformSize16x64";
663     case kTransformSize32x8:
664       return "kTransformSize32x8";
665     case kTransformSize32x16:
666       return "kTransformSize32x16";
667     case kTransformSize32x32:
668       return "kTransformSize32x32";
669     case kTransformSize32x64:
670       return "kTransformSize32x64";
671     case kTransformSize64x16:
672       return "kTransformSize64x16";
673     case kTransformSize64x32:
674       return "kTransformSize64x32";
675     case kTransformSize64x64:
676       return "kTransformSize64x64";
677     case kNumTransformSizes:
678       return "kNumTransformSizes";
679   }
680   abort();
681 }
682 
ToString(const TransformType type)683 inline const char* ToString(const TransformType type) {
684   switch (type) {
685     case kTransformTypeDctDct:
686       return "kTransformTypeDctDct";
687     case kTransformTypeAdstDct:
688       return "kTransformTypeAdstDct";
689     case kTransformTypeDctAdst:
690       return "kTransformTypeDctAdst";
691     case kTransformTypeAdstAdst:
692       return "kTransformTypeAdstAdst";
693     case kTransformTypeFlipadstDct:
694       return "kTransformTypeFlipadstDct";
695     case kTransformTypeDctFlipadst:
696       return "kTransformTypeDctFlipadst";
697     case kTransformTypeFlipadstFlipadst:
698       return "kTransformTypeFlipadstFlipadst";
699     case kTransformTypeAdstFlipadst:
700       return "kTransformTypeAdstFlipadst";
701     case kTransformTypeFlipadstAdst:
702       return "kTransformTypeFlipadstAdst";
703     case kTransformTypeIdentityIdentity:
704       return "kTransformTypeIdentityIdentity";
705     case kTransformTypeIdentityDct:
706       return "kTransformTypeIdentityDct";
707     case kTransformTypeDctIdentity:
708       return "kTransformTypeDctIdentity";
709     case kTransformTypeIdentityAdst:
710       return "kTransformTypeIdentityAdst";
711     case kTransformTypeAdstIdentity:
712       return "kTransformTypeAdstIdentity";
713     case kTransformTypeIdentityFlipadst:
714       return "kTransformTypeIdentityFlipadst";
715     case kTransformTypeFlipadstIdentity:
716       return "kTransformTypeFlipadstIdentity";
717     // case to quiet compiler
718     case kNumTransformTypes:
719       return "kNumTransformTypes";
720   }
721   abort();
722 }
723 
724 //------------------------------------------------------------------------------
725 
726 extern const uint8_t k4x4WidthLog2[kMaxBlockSizes];
727 
728 extern const uint8_t k4x4HeightLog2[kMaxBlockSizes];
729 
730 extern const uint8_t kNum4x4BlocksWide[kMaxBlockSizes];
731 
732 extern const uint8_t kNum4x4BlocksHigh[kMaxBlockSizes];
733 
734 extern const uint8_t kBlockWidthPixels[kMaxBlockSizes];
735 
736 extern const uint8_t kBlockHeightPixels[kMaxBlockSizes];
737 
738 extern const BlockSize kSubSize[kMaxPartitionTypes][kMaxBlockSizes];
739 
740 extern const BlockSize kPlaneResidualSize[kMaxBlockSizes][2][2];
741 
742 extern const int16_t kProjectionMvDivisionLookup[kMaxFrameDistance + 1];
743 
744 extern const uint8_t kTransformWidth[kNumTransformSizes];
745 
746 extern const uint8_t kTransformHeight[kNumTransformSizes];
747 
748 extern const uint8_t kTransformWidth4x4[kNumTransformSizes];
749 
750 extern const uint8_t kTransformHeight4x4[kNumTransformSizes];
751 
752 extern const uint8_t kTransformWidthLog2[kNumTransformSizes];
753 
754 extern const uint8_t kTransformHeightLog2[kNumTransformSizes];
755 
756 extern const TransformSize kSplitTransformSize[kNumTransformSizes];
757 
758 // Square transform of size min(w,h).
759 extern const TransformSize kTransformSizeSquareMin[kNumTransformSizes];
760 
761 // Square transform of size max(w,h).
762 extern const TransformSize kTransformSizeSquareMax[kNumTransformSizes];
763 
764 extern const uint8_t kNumTransformTypesInSet[kNumTransformSets];
765 
766 extern const uint8_t kSgrProjParams[1 << kSgrProjParamsBits][4];
767 
768 extern const int8_t kSgrProjMultiplierMin[2];
769 
770 extern const int8_t kSgrProjMultiplierMax[2];
771 
772 extern const int8_t kWienerTapsMin[3];
773 
774 extern const int8_t kWienerTapsMax[3];
775 
776 extern const uint8_t kUpscaleFilterUnsigned[kSuperResFilterShifts]
777                                            [kSuperResFilterTaps];
778 
779 // An int8_t version of the kWarpedFilters array.
780 // Note: The array could be removed with a performance penalty.
781 extern const int8_t kWarpedFilters8[3 * kWarpedPixelPrecisionShifts + 1][8];
782 
783 extern const int16_t kWarpedFilters[3 * kWarpedPixelPrecisionShifts + 1][8];
784 
785 extern const int8_t kHalfSubPixelFilters[6][16][8];
786 
787 extern const uint8_t kAbsHalfSubPixelFilters[6][16][8];
788 
789 extern const int16_t kDirectionalIntraPredictorDerivative[44];
790 
791 extern const uint8_t kDeblockFilterLevelIndex[kMaxPlanes][kNumLoopFilterTypes];
792 
793 }  // namespace libgav1
794 
795 #endif  // LIBGAV1_SRC_UTILS_CONSTANTS_H_
796