yuv/
internals.rs

1/*
2 * Copyright (c) Radzivon Bartoshyk, 10/2024. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without modification,
5 * are permitted provided that the following conditions are met:
6 *
7 * 1.  Redistributions of source code must retain the above copyright notice, this
8 * list of conditions and the following disclaimer.
9 *
10 * 2.  Redistributions in binary form must reproduce the above copyright notice,
11 * this list of conditions and the following disclaimer in the documentation
12 * and/or other materials provided with the distribution.
13 *
14 * 3.  Neither the name of the copyright holder nor the names of its
15 * contributors may be used to endorse or promote products derived from
16 * this software without specific prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
22 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
24 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
25 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
26 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 */
29use crate::yuv_support::{CbCrForwardTransform, CbCrInverseTransform, YuvChromaRange};
30
31#[allow(dead_code)]
32#[derive(Debug, Copy, Clone, Ord, PartialOrd, Eq, PartialEq)]
33pub(crate) struct ProcessedOffset {
34    pub(crate) cx: usize,
35    pub(crate) ux: usize,
36}
37
38pub(crate) trait WideRowInversionHandler<V, K> {
39    fn handle_row(
40        &self,
41        y_plane: &[V],
42        u_plane: &[V],
43        v_plane: &[V],
44        rgba: &mut [V],
45        width: u32,
46        chroma: YuvChromaRange,
47        transform: &CbCrInverseTransform<K>,
48    ) -> ProcessedOffset;
49}
50
51pub(crate) trait WideRowAlphaInversionHandler<V, T, K> {
52    fn handle_row(
53        &self,
54        y_plane: &[V],
55        u_plane: &[V],
56        v_plane: &[V],
57        a_plane: &[V],
58        rgba: &mut [T],
59        width: u32,
60        chroma: YuvChromaRange,
61        transform: &CbCrInverseTransform<K>,
62        use_premultiplied_alpha: bool,
63    ) -> ProcessedOffset;
64}
65
66#[cfg(feature = "nightly_f16")]
67pub(crate) trait WideDRowInversionHandler<V, T, K> {
68    fn handle_row(
69        &self,
70        y_plane: &[V],
71        u_plane: &[V],
72        v_plane: &[V],
73        rgba: &mut [T],
74        width: u32,
75        chroma: YuvChromaRange,
76        transform: &CbCrInverseTransform<K>,
77    ) -> ProcessedOffset;
78}
79
80#[cfg(feature = "nightly_f16")]
81pub(crate) trait WideDAlphaRowInversionHandler<V, T, K> {
82    fn handle_row(
83        &self,
84        y_plane: &[V],
85        u_plane: &[V],
86        v_plane: &[V],
87        a_plane: &[V],
88        rgba: &mut [T],
89        width: u32,
90        chroma: YuvChromaRange,
91        transform: &CbCrInverseTransform<K>,
92    ) -> ProcessedOffset;
93}
94
95pub(crate) trait WideRow420InversionHandler<V, K> {
96    fn handle_row(
97        &self,
98        y0_plane: &[V],
99        y1_plane: &[V],
100        u_plane: &[V],
101        v_plane: &[V],
102        rgba0: &mut [V],
103        rgba1: &mut [V],
104        width: u32,
105        chroma: YuvChromaRange,
106        transform: &CbCrInverseTransform<K>,
107    ) -> ProcessedOffset;
108}
109
110pub(crate) trait RowBiPlanarInversionHandler<V, K> {
111    fn handle_row(
112        &self,
113        y_plane: &[V],
114        uv_plane: &[V],
115        rgba: &mut [V],
116        width: u32,
117        chroma: YuvChromaRange,
118        transform: &CbCrInverseTransform<K>,
119    ) -> ProcessedOffset;
120}
121
122pub(crate) trait RowDBiPlanarInversionHandler<V, T, K> {
123    fn handle_row(
124        &self,
125        y_plane: &[V],
126        uv_plane: &[V],
127        rgba: &mut [T],
128        width: u32,
129        chroma: YuvChromaRange,
130        transform: &CbCrInverseTransform<K>,
131    ) -> ProcessedOffset;
132}
133
134pub(crate) trait RowBiPlanarInversion420Handler<V, K> {
135    fn handle_row(
136        &self,
137        y_plane0: &[V],
138        y_plane1: &[V],
139        uv_plane: &[V],
140        rgba0: &mut [V],
141        rgba1: &mut [V],
142        width: u32,
143        chroma: YuvChromaRange,
144        transform: &CbCrInverseTransform<K>,
145    ) -> ProcessedOffset;
146}
147
148pub(crate) trait WideRowForwardHandler<V, K> {
149    fn handle_row(
150        &self,
151        y_plane: &mut [V],
152        u_plane: &mut [V],
153        v_plane: &mut [V],
154        rgba: &[V],
155        width: u32,
156        chroma: YuvChromaRange,
157        transform: &CbCrForwardTransform<K>,
158    ) -> ProcessedOffset;
159}
160
161pub(crate) trait WideRowForward420Handler<V, K> {
162    fn handle_row(
163        &self,
164        y_plane0: &mut [V],
165        y_plane1: &mut [V],
166        u_plane: &mut [V],
167        v_plane: &mut [V],
168        rgba0: &[V],
169        rgba1: &[V],
170        width: u32,
171        chroma: YuvChromaRange,
172        transform: &CbCrForwardTransform<K>,
173    ) -> ProcessedOffset;
174}
175
176pub(crate) trait WideRowForwardBiPlanar420Handler<V, K> {
177    fn handle_rows(
178        &self,
179        rgba0: &[V],
180        rgba1: &[V],
181        y_plane0: &mut [V],
182        y_plane1: &mut [V],
183        uv_plane: &mut [V],
184        width: u32,
185        chroma: YuvChromaRange,
186        transform: &CbCrForwardTransform<K>,
187    ) -> ProcessedOffset;
188}
189
190pub(crate) trait WideRowForwardBiPlanarHandler<V, K> {
191    fn handle_row(
192        &self,
193        rgba: &[V],
194        y_plane: &mut [V],
195        uv_plane: &mut [V],
196        width: u32,
197        chroma: YuvChromaRange,
198        transform: &CbCrForwardTransform<K>,
199    ) -> ProcessedOffset;
200}