30 unique_ptr<ImageInput> in(ImageInput::create(
filepath.string()));
37 if (!in->open(
filepath.string(), spec)) {
41 metadata.
width = spec.width;
42 metadata.
height = spec.height;
43 metadata.
depth = spec.depth;
47 size_t channel_size = spec.format.basesize();
49 bool is_float =
false;
52 if (spec.format.is_floating_point()) {
56 for (
size_t channel = 0; channel < spec.channelformats.size(); channel++) {
57 channel_size =
max(channel_size, spec.channelformats[channel].basesize());
58 if (spec.channelformats[channel].is_floating_point()) {
64 if (spec.format == TypeDesc::HALF) {
77 else if (spec.format == TypeDesc::USHORT) {
94 const unique_ptr<ImageInput> &in,
95 const bool associate_alpha,
98 const size_t width = metadata.
width;
99 const size_t height = metadata.
height;
100 const int depth = metadata.
depth;
101 const int components = metadata.
channels;
104 StorageType *readpixels = pixels;
106 if (components > 4) {
107 tmppixels.resize(width * height * components);
108 readpixels = &tmppixels[0];
112 size_t scanlinesize = width * components *
sizeof(StorageType);
118 (
uchar *)readpixels + (height - 1) * scanlinesize,
124 in->read_image(0, 0, 0, components, FileFormat, (
uchar *)readpixels);
127 if (components > 4) {
128 size_t dimensions = width * height;
129 for (
size_t i = dimensions - 1, pixel = 0; pixel < dimensions; pixel++, i--) {
130 pixels[i * 4 + 3] = tmppixels[i * components + 3];
131 pixels[i * 4 + 2] = tmppixels[i * components + 2];
132 pixels[i * 4 + 1] = tmppixels[i * components + 1];
133 pixels[i * 4 + 0] = tmppixels[i * components + 0];
139 const bool cmyk = strcmp(in->format_name(),
"jpeg") == 0 && components == 4;
143 const size_t num_pixels = width * height * depth;
144 for (
size_t i = num_pixels - 1, pixel = 0; pixel < num_pixels; pixel++, i--) {
152 pixels[i * 4 + 3] = one;
156 if (components == 4 && associate_alpha) {
157 size_t dimensions = width * height;
158 for (
size_t i = dimensions - 1, pixel = 0; pixel < dimensions; pixel++, i--) {
159 const StorageType alpha = pixels[i * 4 + 3];
170 const bool associate_alpha)
172 unique_ptr<ImageInput> in =
NULL;
180 in = unique_ptr<ImageInput>(ImageInput::create(
filepath.string()));
185 ImageSpec spec = ImageSpec();
186 ImageSpec config = ImageSpec();
191 config.attribute(
"oiio:UnassociatedAlpha", 1);
193 if (!in->open(
filepath.string(), spec, config)) {
197 bool do_associate_alpha =
false;
198 if (associate_alpha) {
199 do_associate_alpha = spec.get_int_attribute(
"oiio:UnassociatedAlpha", 0);
201 if (!do_associate_alpha && spec.alpha_channel != -1) {
204 if (strcmp(in->format_name(),
"targa") == 0) {
205 do_associate_alpha = spec.get_int_attribute(
"targa:alpha_type", -1) != 4;
208 if (strcmp(in->format_name(),
"dds") == 0) {
209 do_associate_alpha =
true;
213 if (strcmp(in->format_name(),
"psd") == 0) {
214 do_associate_alpha =
true;
219 switch (metadata.
type) {
227 metadata, in, do_associate_alpha, (
uint16_t *)pixels);
@ IMAGE_DATA_TYPE_NANOVDB_FP16
@ IMAGE_DATA_TYPE_USHORT4
@ IMAGE_DATA_TYPE_NANOVDB_FLOAT
@ IMAGE_DATA_TYPE_NANOVDB_FLOAT3
@ IMAGE_DATA_TYPE_NANOVDB_FPN