Lagrange
Loading...
Searching...
No Matches
Array3D.h
1/*
2 * Copyright 2025 Adobe. All rights reserved.
3 * This file is licensed to you under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License. You may obtain a copy
5 * of the License at http://www.apache.org/licenses/LICENSE-2.0
6 *
7 * Unless required by applicable law or agreed to in writing, software distributed under
8 * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9 * OF ANY KIND, either express or implied. See the License for the specific language
10 * governing permissions and limitations under the License.
11 */
12#pragma once
13
14#include <mdspan/mdarray.hpp>
15
16// Not sure we will keep mdspan, so this is an experimental API
17// The plan is to have a low-level API around a multi-dimensional view (equivalent to span<> in core
18// module), and multi-dimensional array (in Array3D.h). Then we can build a higher-level Image class
19// on top of that (equivalent to the Attribute<> class in core module).
20namespace lagrange::image::experimental {
21
24
25template <class T, typename Extent, typename Layout>
26using mdarray = MDSPAN_IMPL_STANDARD_NAMESPACE::Experimental::mdarray<T, Extent, Layout>;
27
28template <typename T>
29using Array3D = mdarray<
30 T,
31 MDSPAN_IMPL_STANDARD_NAMESPACE::dextents<size_t, 3>,
32 MDSPAN_IMPL_STANDARD_NAMESPACE::layout_stride>;
33
45template <typename T>
46Array3D<T> create_image(size_t width, size_t height, size_t num_channels)
47{
48 const MDSPAN_IMPL_STANDARD_NAMESPACE::dextents<size_t, 3> shape{width, height, num_channels};
49 const std::array<size_t, 3> strides{shape.extent(1) * shape.extent(2), shape.extent(2), 1};
50 const MDSPAN_IMPL_STANDARD_NAMESPACE::layout_stride::mapping mapping{shape, strides};
51 return Array3D<T>(mapping, std::vector<T>(width * height * num_channels));
52}
53
55
56} // namespace lagrange::image::experimental
Array3D< T > create_image(size_t width, size_t height, size_t num_channels)
Create an image with the given dimensions and number of channels.
Definition Array3D.h:46