Blender V5.3
cineon_dpx.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2006 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9#include "logImageCore.h"
10#include <cstdio>
11#include <cstring>
12
14#include "IMB_filetype.hh"
15#include "IMB_imbuf.hh"
16#include "IMB_imbuf_types.hh"
17
18#include "BKE_global.hh"
19
20#include "MEM_guardedalloc.h"
21
22namespace blender {
23
24static ImBuf *imb_load_dpx_cineon(const uchar *mem,
25 size_t size,
26 ImBufFlags flags,
27 ImFileColorSpace &r_colorspace)
28{
29 ImBuf *ibuf;
31 int width, height, depth;
32
33 logImageSetVerbose((G.debug & G_DEBUG) ? 1 : 0);
34
35 image = logImageOpenFromMemory(mem, size);
36
37 if (image == nullptr) {
38 printf("Cineon: error opening image.\n");
39 return nullptr;
40 }
41
42 logImageGetSize(image, &width, &height, &depth);
43
44 ibuf = IMB_allocImBuf(width, height, ImBufFlags::FloatData | flags);
45 if (ibuf == nullptr) {
47 return nullptr;
48 }
49
50 if (!flag_is_set(flags, ImBufFlags::Test)) {
51 if (logImageGetDataRGBA(image, ibuf->float_data_for_write(), 1) != 0) {
53 IMB_freeImBuf(ibuf);
54 return nullptr;
55 }
56 IMB_flipy(ibuf);
57 }
58
60 ibuf->ftype = IMB_FTYPE_CINEON;
61
62 if (flag_is_set(flags, ImBufFlags::AlphaDetect)) {
64 }
65
66 r_colorspace.is_hdr_float = true;
67
68 return ibuf;
69}
70
71static int imb_save_dpx_cineon(ImBuf *ibuf, const char *filepath)
72{
73 LogImageFile *logImage;
74 float *fbuf;
75 float *fbuf_ptr;
76 const uchar *rect_ptr;
77 int x, y, rvalue;
78
79 logImageSetVerbose((G.debug & G_DEBUG) ? 1 : 0);
80
82 printf("Cineon: only RGB/RGBA is supported, file: '%s'\n", filepath);
83 return 0;
84 }
85
86 const bool has_alpha = ibuf->color_mode == ImColorMode::RGBA;
87 logImage = logImageCreate(filepath, ibuf->x, ibuf->y, "Blender");
88
89 if (logImage == nullptr) {
90 printf("Cineon: error creating file.\n");
91 return 0;
92 }
93
94 if (ibuf->float_data() != nullptr) {
95 fbuf = MEM_new_array_uninitialized<float>(4 * size_t(ibuf->x) * size_t(ibuf->y),
96 "fbuf in imb_save_dpx_cineon");
97
98 for (y = 0; y < ibuf->y; y++) {
99 float *dst_ptr = fbuf + (4 * (size_t(ibuf->y - y - 1) * size_t(ibuf->x)));
100 const float *src_ptr = ibuf->float_data() + (4 * (size_t(y) * size_t(ibuf->x)));
101
102 memcpy(dst_ptr, src_ptr, 4 * ibuf->x * sizeof(float));
103 }
104
105 rvalue = (logImageSetDataRGBA(logImage, fbuf, 1) == 0);
106
107 MEM_delete(fbuf);
108 }
109 else {
110 if (ibuf->byte_data()) {
112 }
113
114 fbuf = MEM_new_array_uninitialized<float>(4 * size_t(ibuf->x) * size_t(ibuf->y),
115 "fbuf in imb_save_dpx_cineon");
116 if (fbuf == nullptr) {
117 printf("Cineon: error allocating memory.\n");
118 logImageClose(logImage);
119 return 0;
120 }
121 const uint8_t *byte_data = ibuf->byte_data();
122 for (y = 0; y < ibuf->y; y++) {
123 fbuf_ptr = fbuf + (4 * (size_t(ibuf->y - y - 1) * size_t(ibuf->x)));
124 rect_ptr = byte_data + (4 * (size_t(y) * size_t(ibuf->x)));
125 for (x = 0; x < ibuf->x; x++) {
126 fbuf_ptr[0] = float(rect_ptr[0]) / 255.0f;
127 fbuf_ptr[1] = float(rect_ptr[1]) / 255.0f;
128 fbuf_ptr[2] = float(rect_ptr[2]) / 255.0f;
129 fbuf_ptr[3] = has_alpha ? (float(rect_ptr[3]) / 255.0f) : 1.0f;
130 fbuf_ptr += 4;
131 rect_ptr += 4;
132 }
133 }
134 rvalue = (logImageSetDataRGBA(logImage, fbuf, 0) == 0);
135 MEM_delete(fbuf);
136 }
137
138 logImageClose(logImage);
139 return rvalue;
140}
141
142bool imb_save_cineon(ImBuf *buf, const char *filepath, ImBufFlags /*flags*/)
143{
144 return imb_save_dpx_cineon(buf, filepath);
145}
146
147bool imb_is_a_cineon(const uchar *mem, size_t size)
148{
149 return logImageIsCineon(mem, size);
150}
151
153 size_t size,
154 ImBufFlags flags,
155 ImFileColorSpace &r_colorspace)
156{
157 if (!imb_is_a_cineon(mem, size)) {
158 return nullptr;
159 }
160 return imb_load_dpx_cineon(mem, size, flags, r_colorspace);
161}
162
163} // namespace blender
Read Blender memory allocation and freeing.
#define ELEM(...)
BMesh Iterators.
void * MEM_new_array_uninitialized(size_t len, size_t size, const char *str) ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1
void logImageClose(LogImageFile *logImage)
int logImageIsCineon(const void *buffer, const uint size)
void logImageGetSize(const LogImageFile *logImage, int *width, int *height, int *depth)
void logImageSetVerbose(int verbosity)
Global G
Definition blender.cc:57
ImBuf * imb_load_cineon(const uchar *mem, size_t size, ImBufFlags flags, ImFileColorSpace &r_colorspace)
LogImageFile * logImageOpenFromMemory(const uchar *buffer, uint size)
void IMB_freeImBuf(ImBuf *ibuf)
unsigned char uchar
Definition BKE_text.h:58
static ImBuf * imb_load_dpx_cineon(const uchar *mem, size_t size, ImBufFlags flags, ImFileColorSpace &r_colorspace)
Definition cineon_dpx.cc:24
unsigned char uint8_t
Definition BKE_text.h:79
LogImageFile * logImageCreate(const char *filepath, int width, int height, const char *creator)
void IMB_flipy(ImBuf *ibuf)
int logImageSetDataRGBA(LogImageFile *logImage, const float *data, int dataIsLinearRGB)
static int imb_save_dpx_cineon(ImBuf *ibuf, const char *filepath)
Definition cineon_dpx.cc:71
ImBuf * IMB_allocImBuf(unsigned int x, unsigned int y, ImBufFlags flags)
void IMB_byte_from_float(ImBuf *ibuf)
bool imb_is_a_cineon(const uchar *mem, size_t size)
int logImageGetDataRGBA(LogImageFile *logImage, float *data, int dataIsLinearRGB)
bool imb_save_cineon(ImBuf *buf, const char *filepath, ImBufFlags)
KERNEL_FEATURE_LIGHT_PASSES KERNEL_FEATURE_PATH_GUIDING float
const uint8_t * byte_data() const
const float * float_data() const
ImColorMode color_mode
eImbFileType ftype
float * float_data_for_write()
Definition allocimbuf.cc:79