1 // Copyright (c) the JPEG XL Project Authors. All rights reserved.
2 //
3 // Use of this source code is governed by a BSD-style
4 // license that can be found in the LICENSE file.
5 
6 #ifndef LIB_JXL_ENC_COEFF_ORDER_H_
7 #define LIB_JXL_ENC_COEFF_ORDER_H_
8 
9 #include <stddef.h>
10 #include <stdint.h>
11 
12 #include "lib/jxl/ac_strategy.h"
13 #include "lib/jxl/aux_out_fwd.h"
14 #include "lib/jxl/base/compiler_specific.h"
15 #include "lib/jxl/base/status.h"
16 #include "lib/jxl/coeff_order.h"
17 #include "lib/jxl/coeff_order_fwd.h"
18 #include "lib/jxl/common.h"
19 #include "lib/jxl/dct_util.h"
20 #include "lib/jxl/dec_bit_reader.h"
21 #include "lib/jxl/enc_bit_writer.h"
22 #include "lib/jxl/enc_params.h"
23 
24 namespace jxl {
25 
26 // Orders that are actually used in part of image. `rect` is in block units.
27 uint32_t ComputeUsedOrders(SpeedTier speed, const AcStrategyImage& ac_strategy,
28                            const Rect& rect);
29 
30 // Modify zig-zag order, so that DCT bands with more zeros go later.
31 // Order of DCT bands with same number of zeros is untouched, so
32 // permutation will be cheaper to encode.
33 void ComputeCoeffOrder(SpeedTier speed, const ACImage& acs,
34                        const AcStrategyImage& ac_strategy,
35                        const FrameDimensions& frame_dim, uint32_t& used_orders,
36                        coeff_order_t* JXL_RESTRICT order);
37 
38 void EncodeCoeffOrders(uint16_t used_orders,
39                        const coeff_order_t* JXL_RESTRICT order,
40                        BitWriter* writer, size_t layer,
41                        AuxOut* JXL_RESTRICT aux_out);
42 
43 // Encoding/decoding of a single permutation. `size`: number of elements in the
44 // permutation. `skip`: number of elements to skip from the *beginning* of the
45 // permutation.
46 void EncodePermutation(const coeff_order_t* JXL_RESTRICT order, size_t skip,
47                        size_t size, BitWriter* writer, int layer,
48                        AuxOut* aux_out);
49 
50 }  // namespace jxl
51 
52 #endif  // LIB_JXL_ENC_COEFF_ORDER_H_
53