Blender V4.5
writeimage.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2001-2002 NaN Holding BV. All rights reserved.
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9#include <cerrno>
10#include <cstdio>
11#include <cstdlib>
12
13#include "BLI_path_utils.hh" /* For assertions. */
14
16#include "IMB_filetype.hh"
17#include "IMB_imbuf.hh"
18#include "IMB_imbuf_types.hh"
19
20bool IMB_save_image(ImBuf *ibuf, const char *filepath, const int flags)
21{
22 errno = 0;
23
24 BLI_assert(!BLI_path_is_rel(filepath));
25
26 if (ibuf == nullptr) {
27 return false;
28 }
29 ibuf->flags = flags;
30
31 const ImFileType *type = IMB_file_type_from_ibuf(ibuf);
32 if (type == nullptr || type->save == nullptr) {
33 fprintf(stderr, "Couldn't save picture.\n");
34 return false;
35 }
36
37 /* If writing byte image from float buffer, create a byte buffer for writing.
38 *
39 * For color managed image writing, IMB_colormanagement_imbuf_for_write should
40 * have already created this byte buffer. This is a basic fallback for other
41 * cases where we do not have a specific desired output colorspace. */
42 if (!(type->flag & IM_FTYPE_FLOAT)) {
43 if (ibuf->byte_buffer.data == nullptr && ibuf->float_buffer.data) {
46 }
47 }
48
49 return type->save(ibuf, filepath, flags);
50}
#define BLI_assert(a)
Definition BLI_assert.h:46
bool BLI_path_is_rel(const char *path) ATTR_NONNULL(1) ATTR_WARN_UNUSED_RESULT
@ COLOR_ROLE_DEFAULT_BYTE
#define IM_FTYPE_FLOAT
void IMB_byte_from_float(ImBuf *ibuf)
const ColorSpace * colormanage_colorspace_get_roled(const int role)
const ImFileType * IMB_file_type_from_ibuf(const ImBuf *ibuf)
Definition filetype.cc:232
const ColorSpace * colorspace
ImBufFloatBuffer float_buffer
ImBufByteBuffer byte_buffer
bool(* save)(ImBuf *ibuf, const char *filepath, int flags)
bool IMB_save_image(ImBuf *ibuf, const char *filepath, const int flags)
Definition writeimage.cc:20