Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrecht Van Lommel <brechtvanlommel@gmail.com>2019-05-26 13:16:58 +0300
committerBrecht Van Lommel <brechtvanlommel@gmail.com>2019-05-26 13:21:57 +0300
commit909b0ac16c26786f864a84e14ec7714c3308d8f0 (patch)
tree3b8d9839a0aa38d748ffc2ad8d0269328b45e043 /intern/cycles
parentf18373a9ab1ae1534f311af92e03b9c6db1a0cc8 (diff)
Fix Cycles packed images not handling channel packed alpha correctly
Diffstat (limited to 'intern/cycles')
-rw-r--r--intern/cycles/blender/blender_session.cpp20
-rw-r--r--intern/cycles/blender/blender_session.h2
-rw-r--r--intern/cycles/render/image.cpp18
-rw-r--r--intern/cycles/render/image.h2
4 files changed, 27 insertions, 15 deletions
diff --git a/intern/cycles/blender/blender_session.cpp b/intern/cycles/blender/blender_session.cpp
index 11b6a38c195..bb7c750078f 100644
--- a/intern/cycles/blender/blender_session.cpp
+++ b/intern/cycles/blender/blender_session.cpp
@@ -147,9 +147,9 @@ void BlenderSession::create_session()
scene->image_manager->builtin_image_info_cb = function_bind(
&BlenderSession::builtin_image_info, this, _1, _2, _3);
scene->image_manager->builtin_image_pixels_cb = function_bind(
- &BlenderSession::builtin_image_pixels, this, _1, _2, _3, _4, _5);
+ &BlenderSession::builtin_image_pixels, this, _1, _2, _3, _4, _5, _6);
scene->image_manager->builtin_image_float_pixels_cb = function_bind(
- &BlenderSession::builtin_image_float_pixels, this, _1, _2, _3, _4, _5);
+ &BlenderSession::builtin_image_float_pixels, this, _1, _2, _3, _4, _5, _6);
session->scene = scene;
@@ -1223,6 +1223,7 @@ bool BlenderSession::builtin_image_pixels(const string &builtin_name,
void *builtin_data,
unsigned char *pixels,
const size_t pixels_size,
+ const bool associate_alpha,
const bool free_cache)
{
if (!builtin_data) {
@@ -1272,12 +1273,14 @@ bool BlenderSession::builtin_image_pixels(const string &builtin_name,
b_image.buffers_free();
}
- /* Premultiply, byte images are always straight for Blender. */
- unsigned char *cp = pixels;
- for (size_t i = 0; i < num_pixels; i++, cp += channels) {
- cp[0] = (cp[0] * cp[3]) >> 8;
- cp[1] = (cp[1] * cp[3]) >> 8;
- cp[2] = (cp[2] * cp[3]) >> 8;
+ if (associate_alpha) {
+ /* Premultiply, byte images are always straight for Blender. */
+ unsigned char *cp = pixels;
+ for (size_t i = 0; i < num_pixels; i++, cp += channels) {
+ cp[0] = (cp[0] * cp[3]) >> 8;
+ cp[1] = (cp[1] * cp[3]) >> 8;
+ cp[2] = (cp[2] * cp[3]) >> 8;
+ }
}
return true;
}
@@ -1286,6 +1289,7 @@ bool BlenderSession::builtin_image_float_pixels(const string &builtin_name,
void *builtin_data,
float *pixels,
const size_t pixels_size,
+ const bool,
const bool free_cache)
{
if (!builtin_data) {
diff --git a/intern/cycles/blender/blender_session.h b/intern/cycles/blender/blender_session.h
index f0107d4e0b1..b93273e32ae 100644
--- a/intern/cycles/blender/blender_session.h
+++ b/intern/cycles/blender/blender_session.h
@@ -162,11 +162,13 @@ class BlenderSession {
void *builtin_data,
unsigned char *pixels,
const size_t pixels_size,
+ const bool associate_alpha,
const bool free_cache);
bool builtin_image_float_pixels(const string &builtin_name,
void *builtin_data,
float *pixels,
const size_t pixels_size,
+ const bool associate_alpha,
const bool free_cache);
void builtin_images_load();
diff --git a/intern/cycles/render/image.cpp b/intern/cycles/render/image.cpp
index 160e7d9ff1e..03ecc9bce52 100644
--- a/intern/cycles/render/image.cpp
+++ b/intern/cycles/render/image.cpp
@@ -494,6 +494,14 @@ void ImageManager::tag_reload_image(const string &filename,
}
}
+static bool image_associate_alpha(ImageManager::Image *img)
+{
+ /* For typical RGBA images we let OIIO convert to associated alpha,
+ * but some types we want to leave the RGB channels untouched. */
+ return !(ColorSpaceManager::colorspace_is_data(img->colorspace) ||
+ img->alpha_type == IMAGE_ALPHA_IGNORE || img->alpha_type == IMAGE_ALPHA_CHANNEL_PACKED);
+}
+
bool ImageManager::file_load_image_generic(Image *img, unique_ptr<ImageInput> *in)
{
if (img->filename == "")
@@ -514,13 +522,7 @@ bool ImageManager::file_load_image_generic(Image *img, unique_ptr<ImageInput> *i
ImageSpec spec = ImageSpec();
ImageSpec config = ImageSpec();
- /* For typical RGBA images we let OIIO convert to associated alpha,
- * but some types we want to leave the RGB channels untouched. */
- const bool associate_alpha = !(ColorSpaceManager::colorspace_is_data(img->colorspace) ||
- img->alpha_type == IMAGE_ALPHA_IGNORE ||
- img->alpha_type == IMAGE_ALPHA_CHANNEL_PACKED);
-
- if (!associate_alpha) {
+ if (!image_associate_alpha(img)) {
config.attribute("oiio:UnassociatedAlpha", 1);
}
@@ -630,6 +632,7 @@ bool ImageManager::file_load_image(Image *img,
img->builtin_data,
(float *)&pixels[0],
num_pixels * components,
+ image_associate_alpha(img),
img->metadata.builtin_free_cache);
}
else if (FileFormat == TypeDesc::UINT8) {
@@ -637,6 +640,7 @@ bool ImageManager::file_load_image(Image *img,
img->builtin_data,
(uchar *)&pixels[0],
num_pixels * components,
+ image_associate_alpha(img),
img->metadata.builtin_free_cache);
}
else {
diff --git a/intern/cycles/render/image.h b/intern/cycles/render/image.h
index ed2780f8471..459cd8c056c 100644
--- a/intern/cycles/render/image.h
+++ b/intern/cycles/render/image.h
@@ -132,12 +132,14 @@ class ImageManager {
void *data,
unsigned char *pixels,
const size_t pixels_size,
+ const bool associate_alpha,
const bool free_cache)>
builtin_image_pixels_cb;
function<bool(const string &filename,
void *data,
float *pixels,
const size_t pixels_size,
+ const bool associate_alpha,
const bool free_cache)>
builtin_image_float_pixels_cb;