1cabdff1aSopenharmony_ci/*
2cabdff1aSopenharmony_ci * This file is part of FFmpeg.
3cabdff1aSopenharmony_ci *
4cabdff1aSopenharmony_ci * FFmpeg is free software; you can redistribute it and/or
5cabdff1aSopenharmony_ci * modify it under the terms of the GNU Lesser General Public
6cabdff1aSopenharmony_ci * License as published by the Free Software Foundation; either
7cabdff1aSopenharmony_ci * version 2.1 of the License, or (at your option) any later version.
8cabdff1aSopenharmony_ci *
9cabdff1aSopenharmony_ci * FFmpeg is distributed in the hope that it will be useful,
10cabdff1aSopenharmony_ci * but WITHOUT ANY WARRANTY; without even the implied warranty of
11cabdff1aSopenharmony_ci * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12cabdff1aSopenharmony_ci * Lesser General Public License for more details.
13cabdff1aSopenharmony_ci *
14cabdff1aSopenharmony_ci * You should have received a copy of the GNU Lesser General Public
15cabdff1aSopenharmony_ci * License along with FFmpeg; if not, write to the Free Software
16cabdff1aSopenharmony_ci * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17cabdff1aSopenharmony_ci */
18cabdff1aSopenharmony_ci
19cabdff1aSopenharmony_ci#ifndef AVCODEC_IDCTDSP_H
20cabdff1aSopenharmony_ci#define AVCODEC_IDCTDSP_H
21cabdff1aSopenharmony_ci
22cabdff1aSopenharmony_ci#include <stdint.h>
23cabdff1aSopenharmony_ci
24cabdff1aSopenharmony_ci#include "config.h"
25cabdff1aSopenharmony_ci
26cabdff1aSopenharmony_ci#include "avcodec.h"
27cabdff1aSopenharmony_ci
28cabdff1aSopenharmony_ci/**
29cabdff1aSopenharmony_ci * Scantable.
30cabdff1aSopenharmony_ci */
31cabdff1aSopenharmony_citypedef struct ScanTable {
32cabdff1aSopenharmony_ci    const uint8_t *scantable;
33cabdff1aSopenharmony_ci    uint8_t permutated[64];
34cabdff1aSopenharmony_ci    uint8_t raster_end[64];
35cabdff1aSopenharmony_ci} ScanTable;
36cabdff1aSopenharmony_ci
37cabdff1aSopenharmony_cienum idct_permutation_type {
38cabdff1aSopenharmony_ci    FF_IDCT_PERM_NONE,
39cabdff1aSopenharmony_ci    FF_IDCT_PERM_LIBMPEG2,
40cabdff1aSopenharmony_ci    FF_IDCT_PERM_SIMPLE,
41cabdff1aSopenharmony_ci    FF_IDCT_PERM_TRANSPOSE,
42cabdff1aSopenharmony_ci    FF_IDCT_PERM_PARTTRANS,
43cabdff1aSopenharmony_ci    FF_IDCT_PERM_SSE2,
44cabdff1aSopenharmony_ci};
45cabdff1aSopenharmony_ci
46cabdff1aSopenharmony_civoid ff_init_scantable(const uint8_t *permutation, ScanTable *st,
47cabdff1aSopenharmony_ci                       const uint8_t *src_scantable);
48cabdff1aSopenharmony_civoid ff_init_scantable_permutation(uint8_t *idct_permutation,
49cabdff1aSopenharmony_ci                                   enum idct_permutation_type perm_type);
50cabdff1aSopenharmony_ciint ff_init_scantable_permutation_x86(uint8_t *idct_permutation,
51cabdff1aSopenharmony_ci                                      enum idct_permutation_type perm_type);
52cabdff1aSopenharmony_ci
53cabdff1aSopenharmony_citypedef struct IDCTDSPContext {
54cabdff1aSopenharmony_ci    /* pixel ops : interface with DCT */
55cabdff1aSopenharmony_ci    void (*put_pixels_clamped)(const int16_t *block /* align 16 */,
56cabdff1aSopenharmony_ci                               uint8_t *av_restrict pixels /* align 8 */,
57cabdff1aSopenharmony_ci                               ptrdiff_t line_size);
58cabdff1aSopenharmony_ci    void (*put_signed_pixels_clamped)(const int16_t *block /* align 16 */,
59cabdff1aSopenharmony_ci                                      uint8_t *av_restrict pixels /* align 8 */,
60cabdff1aSopenharmony_ci                                      ptrdiff_t line_size);
61cabdff1aSopenharmony_ci    void (*add_pixels_clamped)(const int16_t *block /* align 16 */,
62cabdff1aSopenharmony_ci                               uint8_t *av_restrict pixels /* align 8 */,
63cabdff1aSopenharmony_ci                               ptrdiff_t line_size);
64cabdff1aSopenharmony_ci
65cabdff1aSopenharmony_ci    void (*idct)(int16_t *block /* align 16 */);
66cabdff1aSopenharmony_ci
67cabdff1aSopenharmony_ci    /**
68cabdff1aSopenharmony_ci     * block -> idct -> clip to unsigned 8 bit -> dest.
69cabdff1aSopenharmony_ci     * (-1392, 0, 0, ...) -> idct -> (-174, -174, ...) -> put -> (0, 0, ...)
70cabdff1aSopenharmony_ci     * @param line_size size in bytes of a horizontal line of dest
71cabdff1aSopenharmony_ci     */
72cabdff1aSopenharmony_ci    void (*idct_put)(uint8_t *dest /* align 8 */,
73cabdff1aSopenharmony_ci                     ptrdiff_t line_size, int16_t *block /* align 16 */);
74cabdff1aSopenharmony_ci
75cabdff1aSopenharmony_ci    /**
76cabdff1aSopenharmony_ci     * block -> idct -> add dest -> clip to unsigned 8 bit -> dest.
77cabdff1aSopenharmony_ci     * @param line_size size in bytes of a horizontal line of dest
78cabdff1aSopenharmony_ci     */
79cabdff1aSopenharmony_ci    void (*idct_add)(uint8_t *dest /* align 8 */,
80cabdff1aSopenharmony_ci                     ptrdiff_t line_size, int16_t *block /* align 16 */);
81cabdff1aSopenharmony_ci
82cabdff1aSopenharmony_ci    /**
83cabdff1aSopenharmony_ci     * IDCT input permutation.
84cabdff1aSopenharmony_ci     * Several optimized IDCTs need a permutated input (relative to the
85cabdff1aSopenharmony_ci     * normal order of the reference IDCT).
86cabdff1aSopenharmony_ci     * This permutation must be performed before the idct_put/add.
87cabdff1aSopenharmony_ci     * Note, normally this can be merged with the zigzag/alternate scan<br>
88cabdff1aSopenharmony_ci     * An example to avoid confusion:
89cabdff1aSopenharmony_ci     * - (->decode coeffs -> zigzag reorder -> dequant -> reference IDCT -> ...)
90cabdff1aSopenharmony_ci     * - (x -> reference DCT -> reference IDCT -> x)
91cabdff1aSopenharmony_ci     * - (x -> reference DCT -> simple_mmx_perm = idct_permutation
92cabdff1aSopenharmony_ci     *    -> simple_idct_mmx -> x)
93cabdff1aSopenharmony_ci     * - (-> decode coeffs -> zigzag reorder -> simple_mmx_perm -> dequant
94cabdff1aSopenharmony_ci     *    -> simple_idct_mmx -> ...)
95cabdff1aSopenharmony_ci     */
96cabdff1aSopenharmony_ci    uint8_t idct_permutation[64];
97cabdff1aSopenharmony_ci    enum idct_permutation_type perm_type;
98cabdff1aSopenharmony_ci
99cabdff1aSopenharmony_ci    int mpeg4_studio_profile;
100cabdff1aSopenharmony_ci} IDCTDSPContext;
101cabdff1aSopenharmony_ci
102cabdff1aSopenharmony_civoid ff_put_pixels_clamped_c(const int16_t *block, uint8_t *av_restrict pixels,
103cabdff1aSopenharmony_ci                             ptrdiff_t line_size);
104cabdff1aSopenharmony_civoid ff_add_pixels_clamped_c(const int16_t *block, uint8_t *av_restrict pixels,
105cabdff1aSopenharmony_ci                             ptrdiff_t line_size);
106cabdff1aSopenharmony_ci
107cabdff1aSopenharmony_civoid ff_idctdsp_init(IDCTDSPContext *c, AVCodecContext *avctx);
108cabdff1aSopenharmony_ci
109cabdff1aSopenharmony_civoid ff_idctdsp_init_aarch64(IDCTDSPContext *c, AVCodecContext *avctx,
110cabdff1aSopenharmony_ci                             unsigned high_bit_depth);
111cabdff1aSopenharmony_civoid ff_idctdsp_init_alpha(IDCTDSPContext *c, AVCodecContext *avctx,
112cabdff1aSopenharmony_ci                           unsigned high_bit_depth);
113cabdff1aSopenharmony_civoid ff_idctdsp_init_arm(IDCTDSPContext *c, AVCodecContext *avctx,
114cabdff1aSopenharmony_ci                         unsigned high_bit_depth);
115cabdff1aSopenharmony_civoid ff_idctdsp_init_ppc(IDCTDSPContext *c, AVCodecContext *avctx,
116cabdff1aSopenharmony_ci                         unsigned high_bit_depth);
117cabdff1aSopenharmony_civoid ff_idctdsp_init_x86(IDCTDSPContext *c, AVCodecContext *avctx,
118cabdff1aSopenharmony_ci                         unsigned high_bit_depth);
119cabdff1aSopenharmony_civoid ff_idctdsp_init_mips(IDCTDSPContext *c, AVCodecContext *avctx,
120cabdff1aSopenharmony_ci                          unsigned high_bit_depth);
121cabdff1aSopenharmony_civoid ff_idctdsp_init_loongarch(IDCTDSPContext *c, AVCodecContext *avctx,
122cabdff1aSopenharmony_ci                               unsigned high_bit_depth);
123cabdff1aSopenharmony_ci
124cabdff1aSopenharmony_ci#endif /* AVCODEC_IDCTDSP_H */
125