42 metadata.
width = spec.width;
43 metadata.
height = spec.height;
44 metadata.
depth = spec.depth;
48 size_t channel_size = spec.format.basesize();
50 bool is_float =
false;
53 if (spec.format.is_floating_point()) {
57 for (
size_t channel = 0; channel < spec.channelformats.size(); channel++) {
58 channel_size =
max(channel_size, spec.channelformats[channel].basesize());
59 if (spec.channelformats[channel].is_floating_point()) {
65 if (spec.format == TypeDesc::HALF) {
78 else if (spec.format == TypeDesc::USHORT) {
96 const bool associate_alpha,
99 const size_t width = metadata.
width;
100 const size_t height = metadata.
height;
101 const int depth = metadata.
depth;
102 const int components = metadata.
channels;
105 StorageType *readpixels = pixels;
107 if (components > 4) {
108 tmppixels.resize(width * height * components);
109 readpixels = &tmppixels[0];
113 const size_t scanlinesize = width * components *
sizeof(StorageType);
119 (
uchar *)readpixels + (height - 1) * scanlinesize,
125 in->read_image(0, 0, 0, components, FileFormat, (
uchar *)readpixels);
128 if (components > 4) {
129 const size_t dimensions = width * height;
130 for (
size_t i = dimensions - 1, pixel = 0; pixel < dimensions; pixel++,
i--) {
131 pixels[
i * 4 + 3] = tmppixels[
i * components + 3];
132 pixels[
i * 4 + 2] = tmppixels[
i * components + 2];
133 pixels[
i * 4 + 1] = tmppixels[
i * components + 1];
134 pixels[
i * 4 + 0] = tmppixels[
i * components + 0];
140 const bool cmyk = strcmp(
in->format_name(),
"jpeg") == 0 && components == 4;
144 const size_t num_pixels = width * height * depth;
145 for (
size_t i = num_pixels - 1, pixel = 0; pixel < num_pixels; pixel++,
i--) {
153 pixels[
i * 4 + 3] = one;
157 if (components == 4 && associate_alpha) {
158 const size_t dimensions = width * height;
159 for (
size_t i = dimensions - 1, pixel = 0; pixel < dimensions; pixel++,
i--) {
160 const StorageType alpha = pixels[
i * 4 + 3];
171 const bool associate_alpha)
186 ImageSpec spec = ImageSpec();
187 ImageSpec config = ImageSpec();
192 config.attribute(
"oiio:UnassociatedAlpha", 1);
194 if (!
in->open(
filepath.string(), spec, config)) {
198 bool do_associate_alpha =
false;
199 if (associate_alpha) {
200 do_associate_alpha = spec.get_int_attribute(
"oiio:UnassociatedAlpha", 0);
202 if (!do_associate_alpha && spec.alpha_channel != -1) {
205 if (strcmp(
in->format_name(),
"targa") == 0) {
206 do_associate_alpha = spec.get_int_attribute(
"targa:alpha_type", -1) != 4;
209 if (strcmp(
in->format_name(),
"dds") == 0) {
210 do_associate_alpha =
true;
214 if (strcmp(
in->format_name(),
"psd") == 0) {
215 do_associate_alpha =
true;
220 switch (metadata.
type) {
228 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