Debian Codegraph @

src/color_convert.rs

raw symbols SCIP
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 #![allow(
10 clippy::many_single_char_names,
11 clippy::similar_names,
12 clippy::cast_possible_truncation,
13 clippy::cast_sign_loss,
14 clippy::cast_possible_wrap,
15 clippy::too_many_arguments,
16 clippy::doc_markdown
17 )]
18
19 //! Color space conversion routines
20 //!
21 //! This files exposes functions to convert one colorspace to another in a jpeg
22 //! image
23 //!
24 //! Currently supported conversions are
25 //!
26 //! - `YCbCr` to `RGB,RGBA,GRAYSCALE,RGBX`.
27 //!
28 //!
29 //! Hey there, if your reading this it means you probably need something, so let me help you.
30 //!
31 //! There are 3 supported cpu extensions here.
32 //! 1. Scalar
33 //! 2. SSE
34 //! 3. AVX
35 //!
36 //! There are two types of the color convert functions
37 //!
38 //! 1. Acts on 16 pixels.
39 //! 2. Acts on 8 pixels.
40 //!
41 //! The reason for this is because when implementing the AVX part it occurred to me that we can actually
42 //! do better and process 2 MCU's if we change IDCT return type to be `i16's`, since a lot of
43 //! CPU's these days support AVX extensions, it becomes nice if we optimize for that path ,
44 //! therefore AVX routines can process 16 pixels directly and SSE and Scalar just compensate.
45 //!
46 //! By compensating, I mean I wrote the 16 pixels version operating on the 8 pixel version twice.
47 //!
48 //! Therefore if your looking to optimize some routines, probably start there.
49
50 pub use scalarrust-analyzer cargo zune-jpeg 0.5.15 color_convert/scalar/::ycbcr_to_grayscalerust-analyzer cargo zune-jpeg 0.5.15 color_convert/scalar/ycbcr_to_grayscale().;
51 use zune_corerust-analyzer cargo zune-core 0.5.1 crate/::colorspacerust-analyzer cargo zune-core 0.5.1 colorspace/::ColorSpacerust-analyzer cargo zune-core 0.5.1 colorspace/ColorSpace#;
52 use zune_corerust-analyzer cargo zune-core 0.5.1 crate/::optionsrust-analyzer cargo zune-core 0.5.1 options/::DecoderOptionsrust-analyzer cargo zune-core 0.5.1 options/decoder/DecoderOptions#;
53
54 #[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
55 #[cfg(feature = "x86")]
56 pub use craterust-analyzer cargo zune-jpeg 0.5.15 crate/::color_convertrust-analyzer cargo zune-jpeg 0.5.15 color_convert/::avxrust-analyzer cargo zune-jpeg 0.5.15 color_convert/avx/::{ycbcr_to_rgb_avx2rust-analyzer cargo zune-jpeg 0.5.15 color_convert/avx/ycbcr_to_rgb_avx2()., ycbcr_to_rgba_avx2rust-analyzer cargo zune-jpeg 0.5.15 color_convert/avx/ycbcr_to_rgba_avx2().};
57 use craterust-analyzer cargo zune-jpeg 0.5.15 crate/::decoderrust-analyzer cargo zune-jpeg 0.5.15 decoder/::ColorConvert16Ptrrust-analyzer cargo zune-jpeg 0.5.15 decoder/ColorConvert16Ptr#;
58
59 mod avxrust-analyzer cargo zune-jpeg 0.5.15 color_convert/avx/;
60 mod neon64;
61 mod scalarrust-analyzer cargo zune-jpeg 0.5.15 color_convert/scalar/;
62
63 #[allow(unused_variables)]
64 pub fn choose_ycbcr_to_rgb_convert_funcrust-analyzer cargo zune-jpeg 0.5.15 color_convert/choose_ycbcr_to_rgb_convert_func().(
65 type_need: ColorSpacerust-analyzer cargo zune-core 0.5.1 colorspace/ColorSpace#, options: &DecoderOptionsrust-analyzer cargo zune-core 0.5.1 options/decoder/DecoderOptions#
66 ) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<ColorConvert16Ptrrust-analyzer cargo zune-jpeg 0.5.15 decoder/ColorConvert16Ptr#> {
67 #[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
68 #[cfg(feature = "x86")]
69 {
70 use zune_corerust-analyzer cargo zune-core 0.5.1 crate/::logrust-analyzer cargo log 0.4.29 crate/::debugrust-analyzer cargo log 0.4.29 macros/debug!;
71 if options.use_avx2rust-analyzer cargo zune-core 0.5.1 options/decoder/impl#[DecoderOptions]use_avx2().() {
72 debugrust-analyzer cargo log 0.4.29 macros/debug!!("Using AVX optimised color conversion functions");
73
74 // I believe avx2 means sse4 is also available
75 // match colorspace
76 match type_need {
77 ColorSpacerust-analyzer cargo zune-core 0.5.1 colorspace/ColorSpace#::RGBrust-analyzer cargo zune-core 0.5.1 colorspace/ColorSpace#RGB# => return Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(ycbcr_to_rgb_avx2rust-analyzer cargo zune-jpeg 0.5.15 color_convert/avx/ycbcr_to_rgb_avx2().),
78 ColorSpacerust-analyzer cargo zune-core 0.5.1 colorspace/ColorSpace#::RGBArust-analyzer cargo zune-core 0.5.1 colorspace/ColorSpace#RGBA# => return Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(ycbcr_to_rgba_avx2rust-analyzer cargo zune-jpeg 0.5.15 color_convert/avx/ycbcr_to_rgba_avx2().),
79 _ => () // fall through to scalar, which has more types
80 };
81 }
82 }
83 #[cfg(all(feature = "neon", target_arch = "aarch64"))]
84 {
85 if options.use_neon() {
86 use craterust-analyzer cargo zune-jpeg 0.5.15 crate/::color_convertrust-analyzer cargo zune-jpeg 0.5.15 color_convert/::neon64::{ycbcr_to_rgb_neon, ycbcr_to_rgba_neon};
87 match type_need {
88 ColorSpacerust-analyzer cargo zune-core 0.5.1 colorspace/ColorSpace#::RGBrust-analyzer cargo zune-core 0.5.1 colorspace/ColorSpace#RGB# => return Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(ycbcr_to_rgb_neon),
89 ColorSpacerust-analyzer cargo zune-core 0.5.1 colorspace/ColorSpace#::RGBArust-analyzer cargo zune-core 0.5.1 colorspace/ColorSpace#RGBA# => return Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(ycbcr_to_rgba_neon),
90 _ => () // fall through to scalar, which has more types
91 };
92 }
93 }
94 // when there is no x86 or we haven't returned by here, resort to scalar
95 return match type_need {
96 ColorSpacerust-analyzer cargo zune-core 0.5.1 colorspace/ColorSpace#::RGBrust-analyzer cargo zune-core 0.5.1 colorspace/ColorSpace#RGB# => Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(scalarrust-analyzer cargo zune-jpeg 0.5.15 color_convert/scalar/::ycbcr_to_rgb_inner_16_scalarrust-analyzer cargo zune-jpeg 0.5.15 color_convert/scalar/ycbcr_to_rgb_inner_16_scalar().::<false>),
97 ColorSpacerust-analyzer cargo zune-core 0.5.1 colorspace/ColorSpace#::RGBArust-analyzer cargo zune-core 0.5.1 colorspace/ColorSpace#RGBA# => Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(scalarrust-analyzer cargo zune-jpeg 0.5.15 color_convert/scalar/::ycbcr_to_rgba_inner_16_scalarrust-analyzer cargo zune-jpeg 0.5.15 color_convert/scalar/ycbcr_to_rgba_inner_16_scalar().::<false>),
98 ColorSpacerust-analyzer cargo zune-core 0.5.1 colorspace/ColorSpace#::BGRArust-analyzer cargo zune-core 0.5.1 colorspace/ColorSpace#BGRA# => Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(scalarrust-analyzer cargo zune-jpeg 0.5.15 color_convert/scalar/::ycbcr_to_rgba_inner_16_scalarrust-analyzer cargo zune-jpeg 0.5.15 color_convert/scalar/ycbcr_to_rgba_inner_16_scalar().::<true>),
99 ColorSpacerust-analyzer cargo zune-core 0.5.1 colorspace/ColorSpace#::BGRrust-analyzer cargo zune-core 0.5.1 colorspace/ColorSpace#BGR# => Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(scalarrust-analyzer cargo zune-jpeg 0.5.15 color_convert/scalar/::ycbcr_to_rgb_inner_16_scalarrust-analyzer cargo zune-jpeg 0.5.15 color_convert/scalar/ycbcr_to_rgb_inner_16_scalar().::<true>),
100 _ => Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#
101 };
102 }