31 LOG_ERROR <<
"Image file '" <<
filepath.string() <<
"' is a directory, cannot use as image.";
47 metadata.
width = spec.width;
48 metadata.
height = spec.height;
52 size_t channel_size = spec.format.basesize();
54 bool is_float =
false;
57 if (spec.format.is_floating_point()) {
61 for (
size_t channel = 0; channel < spec.channelformats.size(); channel++) {
62 channel_size =
max(channel_size, spec.channelformats[channel].basesize());
63 if (spec.channelformats[channel].is_floating_point()) {
69 if (spec.format == TypeDesc::HALF) {
82 else if (spec.format == TypeDesc::USHORT) {
97template<TypeDesc::BASETYPE FileFormat,
typename StorageType>
100 const bool associate_alpha,
103 const size_t width = metadata.
width;
104 const size_t height = metadata.
height;
105 const int components = metadata.
channels;
108 StorageType *readpixels = pixels;
110 if (components > 4) {
111 tmppixels.resize(width * height * components);
112 readpixels = &tmppixels[0];
115 const size_t scanlinesize = width * components *
sizeof(StorageType);
121 (
uchar *)readpixels + (height - 1) * scanlinesize,
126 if (components > 4) {
127 const size_t dimensions = width * height;
128 for (
size_t i = dimensions - 1, pixel = 0; pixel < dimensions; pixel++,
i--) {
129 pixels[
i * 4 + 3] = tmppixels[
i * components + 3];
130 pixels[
i * 4 + 2] = tmppixels[
i * components + 2];
131 pixels[
i * 4 + 1] = tmppixels[
i * components + 1];
132 pixels[
i * 4 + 0] = tmppixels[
i * components + 0];
138 const bool cmyk = strcmp(
in->format_name(),
"jpeg") == 0 && components == 4;
142 const size_t num_pixels = width * height;
143 for (
size_t i = num_pixels - 1, pixel = 0; pixel < num_pixels; pixel++,
i--) {
151 pixels[
i * 4 + 3] = one;
155 if (components == 4 && associate_alpha) {
156 const size_t dimensions = width * height;
157 for (
size_t i = dimensions - 1, pixel = 0; pixel < dimensions; pixel++,
i--) {
158 const StorageType alpha = pixels[
i * 4 + 3];
169 const bool associate_alpha)
184 ImageSpec spec = ImageSpec();
185 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) {
226 metadata,
in, do_associate_alpha, (uint16_t *)pixels);
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() override
OIIOImageLoader(const string &filepath)
bool load_metadata(const ImageDeviceFeatures &features, ImageMetaData &metadata) override
string name() const override
T util_image_cast_from_float(const float value)
T util_image_multiply_native(T a, T b)
float util_image_cast_to_float(T value)
#define CCL_NAMESPACE_END
static void oiio_load_pixels(const ImageMetaData &metadata, const unique_ptr< ImageInput > &in, const bool associate_alpha, StorageType *pixels)
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_EMPTY
@ IMAGE_DATA_TYPE_NANOVDB_FLOAT
@ IMAGE_DATA_TYPE_NANOVDB_FLOAT3
@ IMAGE_DATA_TYPE_NANOVDB_FLOAT4
@ IMAGE_DATA_TYPE_NANOVDB_FPN