zune_jpeg/upsampler.rs
1/*
2 * Copyright (c) 2023.
3 *
4 * This software is free software;
5 *
6 * You can redistribute it or modify it under terms of the MIT, Apache License or Zlib license
7 */
8
9//! Up-sampling routines
10//!
11//! The main upsampling method is a bi-linear interpolation or a "triangle
12//! filter " or libjpeg turbo `fancy_upsampling` which is a good compromise
13//! between speed and visual quality
14//!
15//! # The filter
16//! Each output pixel is made from `(3*A+B)/4` where A is the original
17//! pixel closer to the output and B is the one further.
18//!
19//! ```text
20//!+---+---+
21//! | A | B |
22//! +---+---+
23//! +-+-+-+-+
24//! | |P| | |
25//! +-+-+-+-+
26//! ```
27//!
28//! # Horizontal Bi-linear filter
29//! ```text
30//! |---+-----------+---+
31//! | | | |
32//! | A | |p1 | p2| | B |
33//! | | | |
34//! |---+-----------+---+
35//!
36//! ```
37//! For a horizontal bi-linear it's trivial to implement,
38//!
39//! `A` becomes the input closest to the output.
40//!
41//! `B` varies depending on output.
42//! - For odd positions, input is the `next` pixel after A
43//! - For even positions, input is the `previous` value before A.
44//!
45//! We iterate in a classic 1-D sliding window with a window of 3.
46//! For our sliding window approach, `A` is the 1st and `B` is either the 0th term or 2nd term
47//! depending on position we are writing.(see scalar code).
48//!
49//! For vector code see module sse for explanation.
50//!
51//! # Vertical bi-linear.
52//! Vertical up-sampling is a bit trickier.
53//!
54//! ```text
55//! +----+----+
56//! | A1 | A2 |
57//! +----+----+
58//! +----+----+
59//! | p1 | p2 |
60//! +----+-+--+
61//! +----+-+--+
62//! | p3 | p4 |
63//! +----+-+--+
64//! +----+----+
65//! | B1 | B2 |
66//! +----+----+
67//! ```
68//!
69//! For `p1`
70//! - `A1` is given a weight of `3` and `B1` is given a weight of 1.
71//!
72//! For `p3`
73//! - `B1` is given a weight of `3` and `A1` is given a weight of 1
74//!
75//! # Horizontal vertical downsampling/chroma quartering.
76//!
77//! Carry out a vertical filter in the first pass, then a horizontal filter in the second pass.
78use crate::components::UpSampler;
79
80mod scalar;
81
82// choose best possible implementation for this platform
83pub fn choose_horizontal_samp_function(_use_unsafe: bool) -> UpSampler {
84 return scalar::upsample_horizontal;
85}
86
87pub fn choose_hv_samp_function(_use_unsafe: bool) -> UpSampler {
88 return scalar::upsample_hv;
89}
90
91pub fn choose_v_samp_function(_use_unsafe: bool) -> UpSampler {
92 return scalar::upsample_vertical;
93}
94
95/// Upsample nothing
96
97pub fn upsample_no_op(
98 _input: &[i16], _in_ref: &[i16], _in_near: &[i16], _scratch_space: &mut [i16],
99 _output: &mut [i16]
100) {
101}