Changeset View
Changeset View
Standalone View
Standalone View
source/blender/imbuf/intern/openexr/openexr_api.cpp
| Show First 20 Lines • Show All 318 Lines • ▼ Show 20 Lines | struct _RGBAZ { | ||||
| half g; | half g; | ||||
| half b; | half b; | ||||
| half a; | half a; | ||||
| half z; | half z; | ||||
| }; | }; | ||||
| using RGBAZ = _RGBAZ; | using RGBAZ = _RGBAZ; | ||||
| static half float_to_half_safe(const float value) | |||||
| { | |||||
| return half(clamp_f(value, -HALF_MAX, HALF_MAX)); | |||||
| } | |||||
| extern "C" { | extern "C" { | ||||
| /** | /** | ||||
| * Test presence of OpenEXR file. | * Test presence of OpenEXR file. | ||||
| * \param mem: pointer to loaded OpenEXR bitstream | * \param mem: pointer to loaded OpenEXR bitstream | ||||
| */ | */ | ||||
| bool imb_is_a_openexr(const unsigned char *mem, const size_t size) | bool imb_is_a_openexr(const unsigned char *mem, const size_t size) | ||||
| { | { | ||||
| ▲ Show 20 Lines • Show All 132 Lines • ▼ Show 20 Lines | try { | ||||
| } | } | ||||
| if (ibuf->rect_float) { | if (ibuf->rect_float) { | ||||
| float *from; | float *from; | ||||
| for (int i = ibuf->y - 1; i >= 0; i--) { | for (int i = ibuf->y - 1; i >= 0; i--) { | ||||
| from = ibuf->rect_float + channels * i * width; | from = ibuf->rect_float + channels * i * width; | ||||
| for (int j = ibuf->x; j > 0; j--) { | for (int j = ibuf->x; j > 0; j--) { | ||||
| to->r = from[0]; | to->r = float_to_half_safe(from[0]); | ||||
| to->g = (channels >= 2) ? from[1] : from[0]; | to->g = float_to_half_safe((channels >= 2) ? from[1] : from[0]); | ||||
| to->b = (channels >= 3) ? from[2] : from[0]; | to->b = float_to_half_safe((channels >= 3) ? from[2] : from[0]); | ||||
| to->a = (channels >= 4) ? from[3] : 1.0f; | to->a = float_to_half_safe((channels >= 4) ? from[3] : 1.0f); | ||||
| to++; | to++; | ||||
| from += channels; | from += channels; | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| else { | else { | ||||
| unsigned char *from; | unsigned char *from; | ||||
| ▲ Show 20 Lines • Show All 624 Lines • ▼ Show 20 Lines | if (data->channels.first) { | ||||
| } | } | ||||
| for (echan = (ExrChannel *)data->channels.first; echan; echan = echan->next) { | for (echan = (ExrChannel *)data->channels.first; echan; echan = echan->next) { | ||||
| /* Writing starts from last scanline, stride negative. */ | /* Writing starts from last scanline, stride negative. */ | ||||
| if (echan->use_half_float) { | if (echan->use_half_float) { | ||||
| float *rect = echan->rect; | float *rect = echan->rect; | ||||
| half *cur = current_rect_half; | half *cur = current_rect_half; | ||||
| for (size_t i = 0; i < num_pixels; i++, cur++) { | for (size_t i = 0; i < num_pixels; i++, cur++) { | ||||
| *cur = rect[i * echan->xstride]; | *cur = float_to_half_safe(rect[i * echan->xstride]); | ||||
| } | } | ||||
| half *rect_to_write = current_rect_half + (data->height - 1L) * data->width; | half *rect_to_write = current_rect_half + (data->height - 1L) * data->width; | ||||
| frameBuffer.insert( | frameBuffer.insert( | ||||
| echan->name, | echan->name, | ||||
| Slice(Imf::HALF, (char *)rect_to_write, sizeof(half), -data->width * sizeof(half))); | Slice(Imf::HALF, (char *)rect_to_write, sizeof(half), -data->width * sizeof(half))); | ||||
| current_rect_half += num_pixels; | current_rect_half += num_pixels; | ||||
| } | } | ||||
| else { | else { | ||||
| ▲ Show 20 Lines • Show All 982 Lines • Show Last 20 Lines | |||||