// Generated by scripts/generate-av1-intra-mode-tables.py. Do not edit.
// AV1 normative mode defaults; each call returns fresh mutable CDF rows.
// Official default tables: https://raw.githubusercontent.com/AOMediaCodec/av1-spec/master/10.additional.tables.md
// Official Intra_Mode_Context mapping: https://raw.githubusercontent.com/AOMediaCodec/av1-spec/master/09.parsing.process.md
// Source: https://github.com/mgvs/go-av1/tree/main/cdf
// _refs/go-av1/cdf/tables_gen.go SHA-256: 583c969851ff9f5fc42369ab77adf80944ce1c049636d0e2dbb7d435daebcdd4
// _refs/go-av1/cdf/tables_angle_gen.go SHA-256: e817a2a2816d1c189e1c54e67c8edd2218b5c0a261043c6611ca663b428acb52
//
// BSD 2-Clause License
//
// Copyright (c) 2026, Oleksandr Zhabotynskyi
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// 1. Redistributions of source code must retain the above copyright notice, this
//    list of conditions and the following disclaimer.
//
// 2. Redistributions in binary form must reproduce the above copyright notice,
//    this list of conditions and the following disclaimer in the documentation
//    and/or other materials provided with the distribution.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

///|
// Indexed by above/left Intra_Mode_Context; 13 modes plus adaptation count.
fn av1_intra_y_mode_cdfs() -> Array[Array[Array[Int]]] {
  [
    [
      [
        15588, 17027, 19338, 20218, 20682, 21110, 21825, 23244, 24189, 28165, 29093,
        30466, 32768, 0,
      ],
      [
        12016, 18066, 19516, 20303, 20719, 21444, 21888, 23032, 24434, 28658, 30172,
        31409, 32768, 0,
      ],
      [
        10052, 10771, 22296, 22788, 23055, 23239, 24133, 25620, 26160, 29336, 29929,
        31567, 32768, 0,
      ],
      [
        14091, 15406, 16442, 18808, 19136, 19546, 19998, 22096, 24746, 29585, 30958,
        32462, 32768, 0,
      ],
      [
        12122, 13265, 15603, 16501, 18609, 20033, 22391, 25583, 26437, 30261, 31073,
        32475, 32768, 0,
      ],
    ],
    [
      [
        10023, 19585, 20848, 21440, 21832, 22760, 23089, 24023, 25381, 29014, 30482,
        31436, 32768, 0,
      ],
      [
        5983, 24099, 24560, 24886, 25066, 25795, 25913, 26423, 27610, 29905, 31276,
        31794, 32768, 0,
      ],
      [
        7444, 12781, 20177, 20728, 21077, 21607, 22170, 23405, 24469, 27915, 29090,
        30492, 32768, 0,
      ],
      [
        8537, 14689, 15432, 17087, 17408, 18172, 18408, 19825, 24649, 29153, 31096,
        32210, 32768, 0,
      ],
      [
        7543, 14231, 15496, 16195, 17905, 20717, 21984, 24516, 26001, 29675, 30981,
        31994, 32768, 0,
      ],
    ],
    [
      [
        12613, 13591, 21383, 22004, 22312, 22577, 23401, 25055, 25729, 29538, 30305,
        32077, 32768, 0,
      ],
      [
        9687, 13470, 18506, 19230, 19604, 20147, 20695, 22062, 23219, 27743, 29211,
        30907, 32768, 0,
      ],
      [
        6183, 6505, 26024, 26252, 26366, 26434, 27082, 28354, 28555, 30467, 30794,
        32086, 32768, 0,
      ],
      [
        10718, 11734, 14954, 17224, 17565, 17924, 18561, 21523, 23878, 28975, 30287,
        32252, 32768, 0,
      ],
      [
        9194, 9858, 16501, 17263, 18424, 19171, 21563, 25961, 26561, 30072, 30737,
        32463, 32768, 0,
      ],
    ],
    [
      [
        12602, 14399, 15488, 18381, 18778, 19315, 19724, 21419, 25060, 29696, 30917,
        32409, 32768, 0,
      ],
      [
        8203, 13821, 14524, 17105, 17439, 18131, 18404, 19468, 25225, 29485, 31158,
        32342, 32768, 0,
      ],
      [
        8451, 9731, 15004, 17643, 18012, 18425, 19070, 21538, 24605, 29118, 30078,
        32018, 32768, 0,
      ],
      [
        7714, 9048, 9516, 16667, 16817, 16994, 17153, 18767, 26743, 30389, 31536,
        32528, 32768, 0,
      ],
      [
        8843, 10280, 11496, 15317, 16652, 17943, 19108, 22718, 25769, 29953, 30983,
        32485, 32768, 0,
      ],
    ],
    [
      [
        12578, 13671, 15979, 16834, 19075, 20913, 22989, 25449, 26219, 30214, 31150,
        32477, 32768, 0,
      ],
      [
        9563, 13626, 15080, 15892, 17756, 20863, 22207, 24236, 25380, 29653, 31143,
        32277, 32768, 0,
      ],
      [
        8356, 8901, 17616, 18256, 19350, 20106, 22598, 25947, 26466, 29900, 30523,
        32261, 32768, 0,
      ],
      [
        10835, 11815, 13124, 16042, 17018, 18039, 18947, 22753, 24615, 29489, 30883,
        32482, 32768, 0,
      ],
      [
        7618, 8288, 9859, 10509, 15386, 18657, 22903, 28776, 29180, 31355, 31802,
        32593, 32768, 0,
      ],
    ],
  ]
}

///|
// Indexed by the raw YMode. CfL adds a fourteenth UV symbol.
fn av1_intra_uv_mode_cdfs(cfl_allowed : Bool) -> Array[Array[Int]] {
  if cfl_allowed {
    [
      [
        10407, 11208, 12900, 13181, 13823, 14175, 14899, 15656, 15986, 20086, 20995,
        22455, 24212, 32768, 0,
      ],
      [
        4532, 19780, 20057, 20215, 20428, 21071, 21199, 21451, 22099, 24228, 24693,
        27032, 29472, 32768, 0,
      ],
      [
        5273, 5379, 20177, 20270, 20385, 20439, 20949, 21695, 21774, 23138, 24256,
        24703, 26679, 32768, 0,
      ],
      [
        6740, 7167, 7662, 14152, 14536, 14785, 15034, 16741, 18371, 21520, 22206,
        23389, 24182, 32768, 0,
      ],
      [
        4987, 5368, 5928, 6068, 19114, 20315, 21857, 22253, 22411, 24911, 25380,
        26027, 26376, 32768, 0,
      ],
      [
        5370, 6889, 7247, 7393, 9498, 21114, 21402, 21753, 21981, 24780, 25386, 26517,
        27176, 32768, 0,
      ],
      [
        4816, 4961, 7204, 7326, 8765, 8930, 20169, 20682, 20803, 23188, 23763, 24455,
        24940, 32768, 0,
      ],
      [
        6608, 6740, 8529, 9049, 9257, 9356, 9735, 18827, 19059, 22336, 23204, 23964,
        24793, 32768, 0,
      ],
      [
        5998, 7419, 7781, 8933, 9255, 9549, 9753, 10417, 18898, 22494, 23139, 24764,
        25989, 32768, 0,
      ],
      [
        10660, 11298, 12550, 12957, 13322, 13624, 14040, 15004, 15534, 20714, 21789,
        23443, 24861, 32768, 0,
      ],
      [
        10522, 11530, 12552, 12963, 13378, 13779, 14245, 15235, 15902, 20102, 22696,
        23774, 25838, 32768, 0,
      ],
      [
        10099, 10691, 12639, 13049, 13386, 13665, 14125, 15163, 15636, 19676, 20474,
        23519, 25208, 32768, 0,
      ],
      [
        3144, 5087, 7382, 7504, 7593, 7690, 7801, 8064, 8232, 9248, 9875, 10521,
        29048, 32768, 0,
      ],
    ]
  } else {
    [
      [
        22631, 24152, 25378, 25661, 25986, 26520, 27055, 27923, 28244, 30059, 30941,
        31961, 32768, 0,
      ],
      [
        9513, 26881, 26973, 27046, 27118, 27664, 27739, 27824, 28359, 29505, 29800,
        31796, 32768, 0,
      ],
      [
        9845, 9915, 28663, 28704, 28757, 28780, 29198, 29822, 29854, 30764, 31777,
        32029, 32768, 0,
      ],
      [
        13639, 13897, 14171, 25331, 25606, 25727, 25953, 27148, 28577, 30612, 31355,
        32493, 32768, 0,
      ],
      [
        9764, 9835, 9930, 9954, 25386, 27053, 27958, 28148, 28243, 31101, 31744,
        32363, 32768, 0,
      ],
      [
        11825, 13589, 13677, 13720, 15048, 29213, 29301, 29458, 29711, 31161, 31441,
        32550, 32768, 0,
      ],
      [
        14175, 14399, 16608, 16821, 17718, 17775, 28551, 30200, 30245, 31837, 32342,
        32667, 32768, 0,
      ],
      [
        12885, 13038, 14978, 15590, 15673, 15748, 16176, 29128, 29267, 30643, 31961,
        32461, 32768, 0,
      ],
      [
        12026, 13661, 13874, 15305, 15490, 15726, 15995, 16273, 28443, 30388, 30767,
        32416, 32768, 0,
      ],
      [
        19052, 19840, 20579, 20916, 21150, 21467, 21885, 22719, 23174, 28861, 30379,
        32175, 32768, 0,
      ],
      [
        18627, 19649, 20974, 21219, 21492, 21816, 22199, 23119, 23527, 27053, 31397,
        32148, 32768, 0,
      ],
      [
        17026, 19004, 19997, 20339, 20586, 21103, 21349, 21907, 22482, 25896, 26541,
        31819, 32768, 0,
      ],
      [
        12124, 13759, 14959, 14992, 15007, 15051, 15078, 15166, 15255, 15753, 16039,
        16606, 32768, 0,
      ],
    ]
  }
}

///|
// Shared by Y and UV; indexed by directional mode minus V_PRED.
fn av1_intra_angle_cdfs() -> Array[Array[Int]] {
  [
    [2180, 5032, 7567, 22776, 26989, 30217, 32768, 0],
    [2301, 5608, 8801, 23487, 26974, 30330, 32768, 0],
    [3780, 11018, 13699, 19354, 23083, 31286, 32768, 0],
    [4581, 11226, 15147, 17138, 21834, 28397, 32768, 0],
    [1737, 10927, 14509, 19588, 22745, 28823, 32768, 0],
    [2664, 10176, 12485, 17650, 21600, 30495, 32768, 0],
    [2240, 11096, 15453, 20341, 22561, 28917, 32768, 0],
    [3605, 10428, 12459, 17676, 21244, 30655, 32768, 0],
  ]
}

///|
// Input is one of the thirteen AV1 intra modes, numbered 0 through 12.
fn av1_intra_mode_context(mode : Int) -> Int {
  let contexts : Array[Int] = [0, 1, 2, 3, 4, 4, 4, 4, 3, 0, 1, 2, 0]
  contexts[mode]
}