Blender V5.0
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 <cstdlib>
11
12#include "BLI_path_utils.hh" /* For assertions. */
13
15#include "IMB_filetype.hh"
16#include "IMB_imbuf.hh"
17#include "IMB_imbuf_types.hh"
18
19#include "CLG_log.h"
20
21static CLG_LogRef LOG = {"image.write"};
22
23bool IMB_save_image(ImBuf *ibuf, const char *filepath, const int flags)
24{
25 errno = 0;
26
27 BLI_assert(!BLI_path_is_rel(filepath));
28
29 if (ibuf == nullptr) {
30 return false;
31 }
32 ibuf->flags = flags;
33
34 const ImFileType *type = IMB_file_type_from_ibuf(ibuf);
35 if (type == nullptr || type->save == nullptr) {
36 CLOG_ERROR(&LOG, "Couldn't save image to \"%s\"", filepath);
37 return false;
38 }
39
40 /* If writing byte image from float buffer, create a byte buffer for writing.
41 *
42 * For color managed image writing, IMB_colormanagement_imbuf_for_write should
43 * have already created this byte buffer. This is a basic fallback for other
44 * cases where we do not have a specific desired output colorspace. */
45 if (!(type->flag & IM_FTYPE_FLOAT)) {
46 if (ibuf->byte_buffer.data == nullptr && ibuf->float_buffer.data) {
49 }
50 }
51
52 return type->save(ibuf, filepath, flags);
53}
#define BLI_assert(a)
Definition BLI_assert.h:46
bool BLI_path_is_rel(const char *path) ATTR_NONNULL(1) ATTR_WARN_UNUSED_RESULT
#define CLOG_ERROR(clg_ref,...)
Definition CLG_log.h:188
@ 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
#define LOG(level)
Definition log.h:97
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:23