12 # define _USE_MATH_DEFINES
17 #include <OpenImageIO/imageio.h>
33 using std::unique_ptr;
37 template<
class T,
class Q>
40 if (components == 2) {
42 pixels[i * 4 + 3] = pixels[i * 2 + 1];
43 pixels[i * 4 + 2] = pixels[i * 2 + 0];
44 pixels[i * 4 + 1] = pixels[i * 2 + 0];
45 pixels[i * 4 + 0] = pixels[i * 2 + 0];
48 else if (components == 3) {
50 pixels[i * 4 + 3] = alpha;
51 pixels[i * 4 + 2] = pixels[i * 3 + 2];
52 pixels[i * 4 + 1] = pixels[i * 3 + 1];
53 pixels[i * 4 + 0] = pixels[i * 3 + 0];
56 else if (components == 1) {
58 pixels[i * 4 + 3] = alpha;
59 pixels[i * 4 + 2] = pixels[i];
60 pixels[i * 4 + 1] = pixels[i];
61 pixels[i * 4 + 0] = pixels[i];
67 ImageInput *in,
int width,
int height,
int components,
int flags,
bool is_alpha)
70 int scanlinesize =
width * components *
sizeof(
uchar);
76 if (!in->read_image(TypeDesc::UINT8,
81 std::cerr << __func__ <<
": ImageInput::read_image() failed:" << std::endl
82 << in->geterror() << std::endl;
91 catch (
const std::exception &exc) {
92 std::cerr << exc.what() << std::endl;
107 ImageInput *in,
int width,
int height,
int components,
int flags,
bool is_alpha)
110 int scanlinesize =
width * components *
sizeof(
float);
121 std::cerr << __func__ <<
": ImageInput::read_image() failed:" << std::endl
122 << in->geterror() << std::endl;
131 catch (
const std::exception &exc) {
132 std::cerr << exc.what() << std::endl;
152 const unsigned char magic[4] = {
'8',
'B',
'P',
'S'};
156 return memcmp(
magic, mem,
sizeof(
magic)) == 0;
162 std::cerr << __func__ <<
": Photoshop PSD-save: Create PSD in memory"
163 <<
" currently not supported" << std::endl;
174 struct ImBuf *ibuf =
nullptr;
176 bool is_float, is_alpha, is_half;
179 const bool is_colorspace_manually_set = (colorspace[0] !=
'\0');
190 std::cerr << __func__ <<
": ImageInput::create() failed:" << std::endl
191 << OIIO_NAMESPACE::geterror() << std::endl;
195 ImageSpec spec, config;
196 config.attribute(
"oiio:UnassociatedAlpha", (
int)1);
198 if (!in->open(filename, spec, config)) {
199 std::cerr << __func__ <<
": ImageInput::open() failed:" << std::endl
200 << in->geterror() << std::endl;
204 if (!is_colorspace_manually_set) {
205 string ics = spec.get_string_attribute(
"oiio:ColorSpace");
210 strcpy(colorspace, file_colorspace);
213 std::cerr << __func__ <<
": The embed colorspace (\"" << file_colorspace
214 <<
"\") not supported in existent OCIO configuration file. Fallback "
215 <<
"to system default colorspace (\"" << colorspace <<
"\")." << std::endl;
221 components = spec.nchannels;
222 is_alpha = spec.alpha_channel != -1;
223 basesize = spec.format.basesize();
224 is_float = basesize > 1;
228 if (!(components >= 1 && components <= 4)) {
251 ibuf->
ftype = IMB_FTYPE_PSD;
253 ibuf->
planes = (3 + (is_alpha ? 1 : 0)) * 4 << basesize;
259 catch (
const std::exception &exc) {
260 std::cerr << exc.what() << std::endl;
271 return openimageio_version();
typedef float(TangentPoint)[2]
char * BLI_strncpy(char *__restrict dst, const char *__restrict src, size_t maxncpy) ATTR_NONNULL()
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei height
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum const void *lists _GL_VOID_RET _GL_VOID const GLdouble *equation _GL_VOID_RET _GL_VOID GLdouble GLdouble blue _GL_VOID_RET _GL_VOID GLfloat GLfloat blue _GL_VOID_RET _GL_VOID GLint GLint blue _GL_VOID_RET _GL_VOID GLshort GLshort blue _GL_VOID_RET _GL_VOID GLubyte GLubyte blue _GL_VOID_RET _GL_VOID GLuint GLuint blue _GL_VOID_RET _GL_VOID GLushort GLushort blue _GL_VOID_RET _GL_VOID GLbyte GLbyte GLbyte alpha _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble alpha _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat alpha _GL_VOID_RET _GL_VOID GLint GLint GLint alpha _GL_VOID_RET _GL_VOID GLshort GLshort GLshort alpha _GL_VOID_RET _GL_VOID GLubyte GLubyte GLubyte alpha _GL_VOID_RET _GL_VOID GLuint GLuint GLuint alpha _GL_VOID_RET _GL_VOID GLushort GLushort GLushort alpha _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLint GLsizei width
Header file for allocimbuf.c.
@ COLOR_ROLE_DEFAULT_BYTE
struct ImBuf * IMB_allocImBuf(unsigned int x, unsigned int y, unsigned char planes, unsigned int flags)
bool IMB_ispic_type_matches(const char *filepath, int filetype)
Contains defines and structs used throughout the imbuf module.
Read Guarded memory(de)allocation.
bool imb_addencodedbufferImBuf(ImBuf *ibuf)
static DBVT_INLINE btScalar size(const btDbvtVolume &a)
void colorspace_set_default_role(char *colorspace, int size, int role)
ColorSpace * colormanage_colorspace_get_named(const char *name)
void IMB_freeImBuf(ImBuf *UNUSED(ibuf))
std::unique_ptr< IDProperty, IDPropertyDeleter > create(StringRefNull prop_name, int32_t value)
Allocate a new IDProperty of type IDP_INT, set its name and value.
int imb_save_photoshop(struct ImBuf *ibuf, const char *, int flags)
static ImBuf * imb_oiio_load_image_float(ImageInput *in, int width, int height, int components, int flags, bool is_alpha)
struct ImBuf * imb_load_photoshop(const char *filename, int flags, char colorspace[IM_MAX_SPACE])
bool imb_is_a_photoshop(const unsigned char *mem, size_t size)
int OIIO_getVersionHex(void)
static ImBuf * imb_oiio_load_image(ImageInput *in, int width, int height, int components, int flags, bool is_alpha)
static void fill_all_channels(T *pixels, int width, int height, int components, Q alpha)
static int magic(const Tex *tex, const float texvec[3], TexResult *texres)