Lagrange
All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Modules Pages
save_image.h
1/*
2 * Copyright 2023 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 <lagrange/fs/filesystem.h>
15#include <lagrange/image/ImageView.h>
16#include <lagrange/image_io/api.h>
17
18namespace lagrange {
19namespace image_io {
20
21// Save image. Returns true on success.
22LA_IMAGE_IO_API bool save_image(
23 const fs::path& path,
24 const unsigned char* data,
25 size_t width,
26 size_t height,
27 image::ImagePrecision precision,
28 image::ImageChannel channel);
29
30// Save image using stb. Supports png or jpeg. Only supports uint8 data.
31LA_IMAGE_IO_API bool save_image_stb(
32 const fs::path& path,
33 const unsigned char* data,
34 size_t width,
35 size_t height,
36 image::ImageChannel channel);
37
38// Note: #include <lagrange/image_io/exr.h> to use the full save_image_exr directly
39// Save exr image using tinyexr.
40LA_IMAGE_IO_API bool save_image_exr(
41 const fs::path& path,
42 const unsigned char* data,
43 size_t width,
44 size_t height,
45 image::ImagePrecision precision,
46 image::ImageChannel channel);
47
48// Save image to our custom binary format.
49LA_IMAGE_IO_API bool save_image_bin(
50 const fs::path& path,
51 const unsigned char* data,
52 size_t width,
53 size_t height,
54 image::ImagePrecision precision,
55 image::ImageChannel channel);
56
57// Save image from an ImageView.
58template <typename T>
59bool save_image(const fs::path& path, const image::ImageView<T>& img)
60{
61 auto buf = std::move(img.pack());
62 return save_image(
63 path,
64 buf.data(),
65 img.get_view_size()(0),
66 img.get_view_size()(1),
67 image::ImageTraits<T>::precision,
68 image::ImageTraits<T>::channel);
69}
70
71} // namespace image_io
72} // namespace lagrange
Main namespace for Lagrange.
Definition: AABBIGL.h:30