40 if (!in->open(
filepath.string(), spec)) {
44 metadata.
width = spec.width;
45 metadata.
height = spec.height;
46 metadata.
depth = spec.depth;
50 size_t channel_size = spec.format.basesize();
52 bool is_float =
false;
55 if (spec.format.is_floating_point()) {
59 for (
size_t channel = 0; channel < spec.channelformats.size(); channel++) {
60 channel_size =
max(channel_size, spec.channelformats[channel].basesize());
61 if (spec.channelformats[channel].is_floating_point()) {
94 template<TypeDesc::BASETYPE FileFormat,
typename StorageType>
96 const unique_ptr<ImageInput> &in,
97 const bool associate_alpha,
102 const int depth = metadata.
depth;
103 const int components = metadata.
channels;
106 StorageType *readpixels = pixels;
108 if (components > 4) {
110 readpixels = &tmppixels[0];
114 size_t scanlinesize =
width * components *
sizeof(StorageType);
115 in->read_image(FileFormat,
122 in->read_image(FileFormat, (
uchar *)readpixels);
125 if (components > 4) {
127 for (
size_t i = dimensions - 1, pixel = 0; pixel < dimensions; pixel++, i--) {
128 pixels[i * 4 + 3] = tmppixels[i * components + 3];
129 pixels[i * 4 + 2] = tmppixels[i * components + 2];
130 pixels[i * 4 + 1] = tmppixels[i * components + 1];
131 pixels[i * 4 + 0] = tmppixels[i * components + 0];
137 const bool cmyk = strcmp(in->format_name(),
"jpeg") == 0 && components == 4;
139 const StorageType one = util_image_cast_from_float<StorageType>(1.0f);
147 pixels[i * 4 + 0] = util_image_cast_from_float<StorageType>((1.0f -
c) * (1.0f - k));
148 pixels[i * 4 + 1] = util_image_cast_from_float<StorageType>((1.0f - m) * (1.0f - k));
149 pixels[i * 4 + 2] = util_image_cast_from_float<StorageType>((1.0f -
y) * (1.0f - k));
150 pixels[i * 4 + 3] = one;
154 if (components == 4 && associate_alpha) {
156 for (
size_t i = dimensions - 1, pixel = 0; pixel < dimensions; pixel++, i--) {
157 const StorageType alpha = pixels[i * 4 + 3];
168 const bool associate_alpha)
170 unique_ptr<ImageInput> in =
NULL;
183 ImageSpec spec = ImageSpec();
184 ImageSpec config = ImageSpec();
190 config.attribute(
"oiio:UnassociatedAlpha", 1);
192 if (!in->open(
filepath.string(), spec, config)) {
196 bool do_associate_alpha =
false;
197 if (associate_alpha) {
198 do_associate_alpha = spec.get_int_attribute(
"oiio:UnassociatedAlpha", 0);
200 if (!do_associate_alpha && spec.alpha_channel != -1) {
203 if (strcmp(in->format_name(),
"targa") == 0) {
204 do_associate_alpha = spec.get_int_attribute(
"targa:alpha_type", -1) != 4;
207 if (strcmp(in->format_name(),
"dds") == 0) {
208 do_associate_alpha =
true;
212 if (strcmp(in->format_name(),
"psd") == 0) {
213 do_associate_alpha =
true;
218 switch (metadata.
type) {
221 oiio_load_pixels<TypeDesc::UINT8, uchar>(metadata, in, do_associate_alpha, (
uchar *)pixels);
225 oiio_load_pixels<TypeDesc::USHORT, uint16_t>(
226 metadata, in, do_associate_alpha, (
uint16_t *)pixels);
230 oiio_load_pixels<TypeDesc::HALF, half>(metadata, in, do_associate_alpha, (
half *)pixels);
234 oiio_load_pixels<TypeDesc::FLOAT, float>(metadata, in, do_associate_alpha, (
float *)pixels);
_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
_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
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
#define CCL_NAMESPACE_END
T util_image_multiply_native(T a, T b)
float util_image_cast_to_float(T value)
static void oiio_load_pixels(const ImageMetaData &metadata, const unique_ptr< ImageInput > &in, const bool associate_alpha, StorageType *pixels)
ccl_gpu_kernel_postfix ccl_global float int num_pixels
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.
bool path_is_directory(const string &path)
bool path_exists(const string &path)
string path_filename(const string &path)
@ IMAGE_DATA_TYPE_NANOVDB_FP16
@ IMAGE_DATA_TYPE_USHORT4
@ IMAGE_DATA_TYPE_NANOVDB_FLOAT
@ IMAGE_DATA_TYPE_NANOVDB_FLOAT3
@ IMAGE_DATA_TYPE_NANOVDB_FPN