28 # define _USE_MATH_DEFINES
33 #include <OpenImageIO/imageio.h>
49 using std::unique_ptr;
53 template<
class T,
class Q>
56 if (components == 2) {
58 pixels[i * 4 + 3] = pixels[i * 2 + 1];
59 pixels[i * 4 + 2] = pixels[i * 2 + 0];
60 pixels[i * 4 + 1] = pixels[i * 2 + 0];
61 pixels[i * 4 + 0] = pixels[i * 2 + 0];
64 else if (components == 3) {
66 pixels[i * 4 + 3] =
alpha;
67 pixels[i * 4 + 2] = pixels[i * 3 + 2];
68 pixels[i * 4 + 1] = pixels[i * 3 + 1];
69 pixels[i * 4 + 0] = pixels[i * 3 + 0];
72 else if (components == 1) {
74 pixels[i * 4 + 3] =
alpha;
75 pixels[i * 4 + 2] = pixels[i];
76 pixels[i * 4 + 1] = pixels[i];
77 pixels[i * 4 + 0] = pixels[i];
83 ImageInput *in,
int width,
int height,
int components,
int flags,
bool is_alpha)
86 int scanlinesize =
width * components *
sizeof(
uchar);
92 if (!in->read_image(TypeDesc::UINT8,
97 std::cerr << __func__ <<
": ImageInput::read_image() failed:" << std::endl
98 << in->geterror() << std::endl;
107 catch (
const std::exception &exc) {
108 std::cerr << exc.what() << std::endl;
123 ImageInput *in,
int width,
int height,
int components,
int flags,
bool is_alpha)
126 int scanlinesize =
width * components *
sizeof(
float);
132 if (!in->read_image(TypeDesc::FLOAT,
137 std::cerr << __func__ <<
": ImageInput::read_image() failed:" << std::endl
138 << in->geterror() << std::endl;
147 catch (
const std::exception &exc) {
148 std::cerr << exc.what() << std::endl;
168 const unsigned char magic[4] = {
'8',
'B',
'P',
'S'};
172 return memcmp(
magic, mem,
sizeof(
magic)) == 0;
178 std::cerr << __func__ <<
": Photoshop PSD-save: Create PSD in memory"
179 <<
" currently not supported" << std::endl;
190 struct ImBuf *ibuf =
nullptr;
192 bool is_float, is_alpha, is_half;
195 const bool is_colorspace_manually_set = (colorspace[0] !=
'\0');
204 unique_ptr<ImageInput> in(ImageInput::create(filename));
206 std::cerr << __func__ <<
": ImageInput::create() failed:" << std::endl
207 << OIIO_NAMESPACE::geterror() << std::endl;
211 ImageSpec spec, config;
212 config.attribute(
"oiio:UnassociatedAlpha", (
int)1);
214 if (!in->open(filename, spec, config)) {
215 std::cerr << __func__ <<
": ImageInput::open() failed:" << std::endl
216 << in->geterror() << std::endl;
220 if (!is_colorspace_manually_set) {
221 string ics = spec.get_string_attribute(
"oiio:ColorSpace");
226 strcpy(colorspace, file_colorspace);
229 std::cerr << __func__ <<
": The embed colorspace (\"" << file_colorspace
230 <<
"\") not supported in existent OCIO configuration file. Fallback "
231 <<
"to system default colorspace (\"" << colorspace <<
"\")." << std::endl;
237 components = spec.nchannels;
238 is_alpha = spec.alpha_channel != -1;
239 basesize = spec.format.basesize();
240 is_float = basesize > 1;
244 if (!(components >= 1 && components <= 4)) {
267 ibuf->
ftype = IMB_FTYPE_PSD;
269 ibuf->
planes = (3 + (is_alpha ? 1 : 0)) * 4 << basesize;
275 catch (
const std::exception &exc) {
276 std::cerr << exc.what() << std::endl;
287 return openimageio_version();
typedef float(TangentPoint)[2]
char * BLI_strncpy(char *__restrict dst, const char *__restrict src, const size_t maxncpy) ATTR_NONNULL()
_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
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei height
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)
void IMB_freeImBuf(struct ImBuf *ibuf)
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)
static CCL_NAMESPACE_BEGIN const double alpha
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)