Blender V4.3
format_targa.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_tga(const uchar *mem, size_t size)
18{
19 return imb_oiio_check(mem, size, "tga");
20}
21
22ImBuf *imb_load_tga(const uchar *mem, size_t size, int flags, char colorspace[IM_MAX_SPACE])
23{
24 ImageSpec config, spec;
25 config.attribute("oiio:UnassociatedAlpha", 1);
26
27 ReadContext ctx{mem, size, "tga", IMB_FTYPE_TGA, flags};
28 return imb_oiio_read(ctx, config, colorspace, spec);
29}
30
31bool imb_save_tga(ImBuf *ibuf, const char *filepath, int flags)
32{
33 const int file_channels = ibuf->planes >> 3;
34 const TypeDesc data_format = TypeDesc::UINT8;
35
36 WriteContext ctx = imb_create_write_context("tga", ibuf, flags, false);
37 ImageSpec file_spec = imb_create_write_spec(ctx, file_channels, data_format);
38 file_spec.attribute("oiio:UnassociatedAlpha", 1);
39 file_spec.attribute("compression", (ibuf->foptions.flag & RAWTGA) ? "none" : "rle");
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_TGA
Contains defines and structs used throughout the imbuf module.
#define RAWTGA
static DBVT_INLINE btScalar size(const btDbvtVolume &a)
Definition btDbvt.cpp:52
bool imb_is_a_tga(const uchar *mem, size_t size)
bool imb_save_tga(ImBuf *ibuf, const char *filepath, int flags)
ImBuf * imb_load_tga(const uchar *mem, size_t size, int flags, char colorspace[IM_MAX_SPACE])
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
ImbFormatOptions foptions
unsigned char planes