maroontree 0.1.1

AV1 & AV2 tiny still-image (AVIF) encoder
Documentation
/*
 * // Copyright (c) Radzivon Bartoshyk 6/2026. All rights reserved.
 * //
 * // 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.
 * //
 * // 3.  Neither the name of the copyright holder nor the names of its
 * // contributors may be used to endorse or promote products derived from
 * // this software without specific prior written permission.
 * //
 * // 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.
 */

pub(crate) static BLK_SKIP: [u16; 2] = [1097, 0];

pub(crate) static C_SKIP: [[u16; 2]; 13] = [
    [919, 0],
    [26876, 0],
    [20656, 0],
    [10833, 0],
    [12479, 0],
    [5295, 0],
    [281, 0],
    [25114, 0],
    [13295, 0],
    [2784, 0],
    [22807, 0],
    [2526, 0],
    [651, 0],
];

pub(crate) static EOB_BIN16: [[u16; 5]; 2] = [
    [31928, 31729, 30788, 27873, 0],
    [29521, 27818, 23080, 18205, 0],
];

pub(crate) static EOB_HI: [[[u16; 2]; 11]; 2] = [
    [
        [16384, 0],
        [16384, 0],
        [15807, 0],
        [15545, 0],
        [25147, 0],
        [16384, 0],
        [16384, 0],
        [16384, 0],
        [16384, 0],
        [16384, 0],
        [16384, 0],
    ],
    [
        [16384, 0],
        [16384, 0],
        [13699, 0],
        [10243, 0],
        [19391, 0],
        [16384, 0],
        [16384, 0],
        [16384, 0],
        [16384, 0],
        [16384, 0],
        [16384, 0],
    ],
];

pub(crate) static EOB_BASE: [[[u16; 3]; 4]; 2] = [
    [
        [14931, 3713, 0],
        [3168, 1322, 0],
        [1924, 890, 0],
        [7842, 3820, 0],
    ],
    [
        [11403, 2742, 0],
        [2256, 345, 0],
        [1110, 147, 0],
        [3138, 887, 0],
    ],
];

pub(crate) static BASE_TOK: [[[u16; 4]; 41]; 2] = [
    [
        [28734, 23838, 20041, 0],
        [14686, 3027, 891, 0],
        [20172, 6644, 2275, 0],
        [23322, 11650, 5763, 0],
        [26460, 17627, 11489, 0],
        [30305, 26411, 22985, 0],
        [12101, 2222, 839, 0],
        [19725, 6645, 2634, 0],
        [24617, 14011, 7990, 0],
        [27513, 19929, 14136, 0],
        [29948, 25562, 21607, 0],
        [24576, 16384, 8192, 0],
        [24576, 16384, 8192, 0],
        [24576, 16384, 8192, 0],
        [24576, 16384, 8192, 0],
        [24576, 16384, 8192, 0],
        [24576, 16384, 8192, 0],
        [24576, 16384, 8192, 0],
        [24576, 16384, 8192, 0],
        [24576, 16384, 8192, 0],
        [24576, 16384, 8192, 0],
        [17032, 5215, 2164, 0],
        [21558, 8974, 3981, 0],
        [26821, 18894, 13067, 0],
        [28553, 23445, 18877, 0],
        [29935, 26306, 22709, 0],
        [13163, 2375, 1186, 0],
        [19245, 6516, 2520, 0],
        [24322, 14146, 8256, 0],
        [28950, 22425, 16794, 0],
        [31287, 28651, 25972, 0],
        [10119, 1466, 578, 0],
        [17939, 5641, 2319, 0],
        [24455, 15066, 9464, 0],
        [29746, 24467, 19982, 0],
        [31232, 28356, 25584, 0],
        [10414, 2994, 1396, 0],
        [18045, 7296, 3554, 0],
        [26095, 19023, 14106, 0],
        [30700, 27002, 23446, 0],
        [24576, 16384, 8192, 0],
    ],
    [
        [26466, 16324, 11007, 0],
        [9728, 1230, 293, 0],
        [17572, 4316, 1272, 0],
        [22748, 9822, 4254, 0],
        [26235, 15906, 9267, 0],
        [29230, 22952, 17692, 0],
        [8324, 893, 243, 0],
        [16887, 3844, 1133, 0],
        [22846, 9895, 4302, 0],
        [26241, 15802, 9077, 0],
        [28654, 21465, 15548, 0],
        [24576, 16384, 8192, 0],
        [24576, 16384, 8192, 0],
        [24576, 16384, 8192, 0],
        [24576, 16384, 8192, 0],
        [24576, 16384, 8192, 0],
        [24576, 16384, 8192, 0],
        [24576, 16384, 8192, 0],
        [24576, 16384, 8192, 0],
        [24576, 16384, 8192, 0],
        [24576, 16384, 8192, 0],
        [12567, 1998, 559, 0],
        [18014, 4697, 1510, 0],
        [24390, 12582, 6251, 0],
        [26852, 17469, 10790, 0],
        [28500, 21185, 14867, 0],
        [8407, 743, 187, 0],
        [14095, 2663, 825, 0],
        [22572, 10524, 5192, 0],
        [27273, 18419, 12351, 0],
        [30092, 25353, 21270, 0],
        [8090, 810, 183, 0],
        [14139, 2862, 937, 0],
        [23404, 12044, 6453, 0],
        [28127, 20450, 14674, 0],
        [30010, 25381, 21189, 0],
        [7335, 926, 299, 0],
        [13973, 3479, 1357, 0],
        [25124, 15184, 9176, 0],
        [29360, 23754, 17721, 0],
        [24576, 16384, 8192, 0],
    ],
];

pub(crate) static BR_TOK: [[[u16; 4]; 21]; 2] = [
    [
        [18470, 12050, 8594, 0],
        [20232, 13167, 8979, 0],
        [24056, 17717, 13265, 0],
        [26598, 21441, 17334, 0],
        [28026, 23842, 20230, 0],
        [28965, 25451, 22222, 0],
        [31072, 29451, 27897, 0],
        [18376, 12817, 10012, 0],
        [16790, 9550, 5950, 0],
        [20581, 13294, 8879, 0],
        [23592, 17128, 12509, 0],
        [25700, 20113, 15740, 0],
        [27112, 22326, 18296, 0],
        [30188, 27776, 25524, 0],
        [20632, 14719, 11342, 0],
        [18984, 12047, 8287, 0],
        [21932, 15147, 10868, 0],
        [24396, 18324, 13921, 0],
        [26245, 20989, 16768, 0],
        [27431, 22870, 19008, 0],
        [29734, 26908, 24306, 0],
    ],
    [
        [16801, 9863, 6482, 0],
        [19234, 12114, 8189, 0],
        [23264, 16676, 12233, 0],
        [25793, 20200, 15865, 0],
        [27404, 22677, 18748, 0],
        [28411, 24398, 20911, 0],
        [30262, 27834, 25550, 0],
        [9736, 3953, 1832, 0],
        [13228, 6064, 3049, 0],
        [17610, 9799, 5671, 0],
        [21360, 13903, 9118, 0],
        [23883, 17320, 12518, 0],
        [25660, 19915, 15352, 0],
        [28537, 24727, 21288, 0],
        [12945, 6278, 3612, 0],
        [13878, 6839, 3836, 0],
        [17108, 9277, 5335, 0],
        [20621, 12992, 8280, 0],
        [23040, 15994, 11119, 0],
        [24849, 18491, 13702, 0],
        [27328, 22598, 18583, 0],
    ],
];

pub(crate) static DC_SIGN: [[[u16; 2]; 3]; 2] = [
    [[16768, 0], [19712, 0], [13952, 0]],
    [[17536, 0], [19840, 0], [15488, 0]],
];

// ── Partition CDFs (icdf form) for frame-edge splitting in arbitrary-size
//    lossless frames. bl index: 64/32/16; ctx 0..3. Symbols: NONE=0, H=1, V=2,
//    SPLIT=3, ... (10-symbol). Edge superblocks split down to 8×8 leaves.
pub(crate) static PART_SPLIT_64: [[u16; 10]; 4] = [
    [12631, 11221, 9690, 3202, 2931, 2507, 2244, 1876, 1044, 0],
    [26036, 25278, 23271, 4824, 4518, 4253, 3799, 3138, 2664, 0],
    [26823, 25105, 24420, 4085, 3651, 3019, 2704, 2470, 530, 0],
    [31898, 31556, 31281, 1570, 1374, 1194, 1025, 887, 436, 0],
];
pub(crate) static PART_SPLIT_32: [[u16; 10]; 4] = [
    [14306, 11848, 9644, 5121, 4541, 3719, 3249, 2590, 1224, 0],
    [25079, 23708, 20712, 7776, 7108, 6586, 5817, 4727, 3716, 0],
    [26753, 23759, 22706, 8224, 7359, 6223, 5697, 5242, 721, 0],
    [31374, 30560, 29972, 4154, 3707, 3302, 2928, 2583, 869, 0],
];
pub(crate) static PART_SPLIT_16: [[u16; 10]; 4] = [
    [17171, 11839, 8197, 6062, 5104, 3947, 3167, 2197, 866, 0],
    [24843, 21725, 15983, 10298, 8797, 7725, 6117, 4067, 2934, 0],
    [27354, 19499, 17657, 12280, 10408, 8268, 7231, 6432, 651, 0],
    [30106, 26406, 24154, 11908, 9715, 7990, 6332, 4939, 1597, 0],
];

/// BL_8X8 partition (4-symbol: NONE/H/V/SPLIT), ctx 0..3.
pub(crate) static PART_8: [[u16; 4]; 4] = [
    [13636, 7258, 2376, 0],
    [18840, 12913, 4228, 0],
    [20246, 9089, 4139, 0],
    [22872, 13985, 6915, 0],
];