Blender V4.3
format_bmp.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2023 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
10
11#include "IMB_filetype.hh"
12#include "IMB_imbuf_types.hh"
13
14OIIO_NAMESPACE_USING
15using namespace blender::imbuf;
16
17bool imb_is_a_bmp(const uchar *mem, size_t size)
18{
19 return imb_oiio_check(mem, size, "bmp");
20}
21
22ImBuf *imb_load_bmp(const uchar *mem, size_t size, int flags, char colorspace[IM_MAX_SPACE])
23{
24 ImageSpec config, spec;
25
26 /* Keep historical behavior - do not use a 1-channel format for a black-white image. */
27 config.attribute("bmp:monochrome_detect", 0);
28
29 ReadContext ctx{mem, size, "bmp", IMB_FTYPE_BMP, flags};
30 return imb_oiio_read(ctx, config, colorspace, spec);
31}
32
33bool imb_save_bmp(ImBuf *ibuf, const char *filepath, int flags)
34{
35 const int file_channels = ibuf->planes >> 3;
36 const TypeDesc data_format = TypeDesc::UINT8;
37
38 WriteContext ctx = imb_create_write_context("bmp", ibuf, flags, false);
39 ImageSpec file_spec = imb_create_write_spec(ctx, file_channels, data_format);
40
41 return imb_oiio_write(ctx, filepath, file_spec);
42}
unsigned char uchar
#define IM_MAX_SPACE
Definition IMB_imbuf.hh:49
@ IMB_FTYPE_BMP
Contains defines and structs used throughout the imbuf module.
static DBVT_INLINE btScalar size(const btDbvtVolume &a)
Definition btDbvt.cpp:52
bool imb_is_a_bmp(const uchar *mem, size_t size)
Definition format_bmp.cc:17
ImBuf * imb_load_bmp(const uchar *mem, size_t size, int flags, char colorspace[IM_MAX_SPACE])
Definition format_bmp.cc:22
bool imb_save_bmp(ImBuf *ibuf, const char *filepath, int flags)
Definition format_bmp.cc:33
bool imb_oiio_write(const WriteContext &ctx, const char *filepath, const ImageSpec &file_spec)
WriteContext imb_create_write_context(const char *file_format, ImBuf *ibuf, int flags, bool prefer_float)
ImBuf * imb_oiio_read(const ReadContext &ctx, const ImageSpec &config, char colorspace[IM_MAX_SPACE], ImageSpec &r_newspec)
bool imb_oiio_check(const uchar *mem, size_t mem_size, const char *file_format)
ImageSpec imb_create_write_spec(const WriteContext &ctx, int file_channels, TypeDesc data_format)
long long TypeDesc
unsigned char planes