Blender V4.3
format_dpx.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
12#include "IMB_filetype.hh"
13#include "IMB_imbuf_types.hh"
14
15OIIO_NAMESPACE_USING
16using namespace blender::imbuf;
17
18bool imb_is_a_dpx(const uchar *mem, size_t size)
19{
20 return imb_oiio_check(mem, size, "dpx");
21}
22
23ImBuf *imb_load_dpx(const uchar *mem, size_t size, int flags, char colorspace[IM_MAX_SPACE])
24{
25 ImageSpec config, spec;
26
27 ReadContext ctx{mem, size, "dpx", IMB_FTYPE_DPX, flags};
28
30
31 ImBuf *ibuf = imb_oiio_read(ctx, config, colorspace, spec);
32 if (ibuf) {
33 if (flags & IB_alphamode_detect) {
35 }
36 }
37
38 return ibuf;
39}
40
41bool imb_save_dpx(ImBuf *ibuf, const char *filepath, int flags)
42{
43 int bits_per_sample = 8;
44 if (ibuf->foptions.flag & CINEON_10BIT) {
45 bits_per_sample = 10;
46 }
47 else if (ibuf->foptions.flag & CINEON_12BIT) {
48 bits_per_sample = 12;
49 }
50 else if (ibuf->foptions.flag & CINEON_16BIT) {
51 bits_per_sample = 16;
52 }
53
54 const int file_channels = ibuf->planes >> 3;
55 const TypeDesc data_format = bits_per_sample == 8 ? TypeDesc::UINT8 : TypeDesc::UINT16;
56
57 WriteContext ctx = imb_create_write_context("dpx", ibuf, flags);
58 ImageSpec file_spec = imb_create_write_spec(ctx, file_channels, data_format);
59
60 const float max_value = powf(2, bits_per_sample) - 1.0f;
61 file_spec.attribute("oiio:BitsPerSample", bits_per_sample);
62 file_spec.attribute("dpx:WhiteLevel", 685.0f / 1023.0f * max_value);
63 file_spec.attribute("dpx:BlackLevel", 95.0f / 1023.0f * max_value);
64 file_spec.attribute("dpx:HighData", max_value);
65 file_spec.attribute("dpx:LowData", 0);
66 file_spec.attribute("dpx:LowQuantity", 0.0f);
67
68 if (ibuf->foptions.flag & CINEON_LOG) {
69 /* VERIFY: This matches previous code but seems odd. Needs a comment if confirmed. */
70 file_spec.attribute("dpx:Transfer", "Printing density");
71 file_spec.attribute("dpx:HighQuantity", 2.048f);
72 }
73 else {
74 file_spec.attribute("dpx:Transfer", "Linear");
75 file_spec.attribute("dpx:HighQuantity", max_value);
76 }
77
78 if (ELEM(bits_per_sample, 8, 16)) {
79 file_spec.attribute("dpx:Packing", "Packed");
80 }
81 else {
82 file_spec.attribute("dpx:Packing", "Filled, method A");
83 }
84
85 return imb_oiio_write(ctx, filepath, file_spec);
86}
unsigned char uchar
#define ELEM(...)
@ COLOR_ROLE_DEFAULT_FLOAT
#define IM_MAX_SPACE
Definition IMB_imbuf.hh:49
Contains defines and structs used throughout the imbuf module.
@ IB_alphamode_premul
@ IB_alphamode_detect
static DBVT_INLINE btScalar size(const btDbvtVolume &a)
Definition btDbvt.cpp:52
#define powf(x, y)
bool imb_is_a_dpx(const uchar *mem, size_t size)
Definition format_dpx.cc:18
bool imb_save_dpx(ImBuf *ibuf, const char *filepath, int flags)
Definition format_dpx.cc:41
ImBuf * imb_load_dpx(const uchar *mem, size_t size, int flags, char colorspace[IM_MAX_SPACE])
Definition format_dpx.cc:23
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