37 VLOG(1) <<
"File '" <<
filepath.string() <<
"' does not exist.";
41 VLOG(1) <<
"File '" <<
filepath.string() <<
"' is a directory, can't use as image.";
45 unique_ptr<ImageInput> in(ImageInput::create(
filepath.string()));
52 if (!in->open(
filepath.string(), spec)) {
56 metadata.
width = spec.width;
57 metadata.
height = spec.height;
58 metadata.
depth = spec.depth;
62 size_t channel_size = spec.format.basesize();
64 bool is_float =
false;
67 if (spec.format.is_floating_point()) {
71 for (
size_t channel = 0; channel < spec.channelformats.size(); channel++) {
72 channel_size =
max(channel_size, spec.channelformats[channel].basesize());
73 if (spec.channelformats[channel].is_floating_point()) {
106 template<TypeDesc::BASETYPE FileFormat,
typename StorageType>
108 const unique_ptr<ImageInput> &in,
113 const int depth = metadata.
depth;
114 const int components = metadata.
channels;
117 StorageType *readpixels = pixels;
119 if (components > 4) {
120 tmppixels.resize(((
size_t)
width) *
height * components);
121 readpixels = &tmppixels[0];
125 size_t scanlinesize = ((size_t)
width) * components *
sizeof(StorageType);
126 in->read_image(FileFormat,
133 in->read_image(FileFormat, (
uchar *)readpixels);
136 if (components > 4) {
138 for (
size_t i = dimensions - 1, pixel = 0; pixel < dimensions; pixel++, i--) {
139 pixels[i * 4 + 3] = tmppixels[i * components + 3];
140 pixels[i * 4 + 2] = tmppixels[i * components + 2];
141 pixels[i * 4 + 1] = tmppixels[i * components + 1];
142 pixels[i * 4 + 0] = tmppixels[i * components + 0];
148 const bool cmyk = strcmp(in->format_name(),
"jpeg") == 0 && components == 4;
150 const StorageType one = util_image_cast_from_float<StorageType>(1.0f);
152 const size_t num_pixels = ((size_t)
width) *
height * depth;
153 for (
size_t i = num_pixels - 1, pixel = 0; pixel < num_pixels; pixel++, i--) {
158 pixels[i * 4 + 0] = util_image_cast_from_float<StorageType>((1.0f -
c) * (1.0f - k));
159 pixels[i * 4 + 1] = util_image_cast_from_float<StorageType>((1.0f - m) * (1.0f - k));
160 pixels[i * 4 + 2] = util_image_cast_from_float<StorageType>((1.0f -
y) * (1.0f - k));
161 pixels[i * 4 + 3] = one;
169 const bool associate_alpha)
171 unique_ptr<ImageInput> in =
NULL;
179 in = unique_ptr<ImageInput>(ImageInput::create(
filepath.string()));
184 ImageSpec spec = ImageSpec();
185 ImageSpec config = ImageSpec();
187 if (!associate_alpha) {
188 config.attribute(
"oiio:UnassociatedAlpha", 1);
191 if (!in->open(
filepath.string(), spec, config)) {
195 switch (metadata.
type) {
198 oiio_load_pixels<TypeDesc::UINT8, uchar>(metadata, in, (
uchar *)pixels);
202 oiio_load_pixels<TypeDesc::USHORT, uint16_t>(metadata, in, (
uint16_t *)pixels);
206 oiio_load_pixels<TypeDesc::HALF, half>(metadata, in, (
half *)pixels);
210 oiio_load_pixels<TypeDesc::FLOAT, float>(metadata, in, (
float *)pixels);
_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
_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 y
ustring osl_filepath() const override
bool equals(const ImageLoader &other) const override
bool load_pixels(const ImageMetaData &metadata, void *pixels, const size_t pixels_size, const bool associate_alpha) override
OIIOImageLoader(const string &filepath)
bool load_metadata(const ImageDeviceFeatures &features, ImageMetaData &metadata) override
string name() const override
static void oiio_load_pixels(const ImageMetaData &metadata, const unique_ptr< ImageInput > &in, StorageType *pixels)
#define CCL_NAMESPACE_END
float util_image_cast_to_float(T value)
bool path_is_directory(const string &path)
bool path_exists(const string &path)
string path_filename(const string &path)
@ IMAGE_DATA_TYPE_USHORT4
@ IMAGE_DATA_TYPE_NANOVDB_FLOAT
@ IMAGE_DATA_TYPE_NANOVDB_FLOAT3