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-18 21:52:20 +0300
committerBrecht Van Lommel <brechtvanlommel@gmail.com>2019-05-19 15:36:42 +0300
commit7aaa7aa9dd79b8c6e37f351fd67a93ba07fbb883 (patch)
tree6d64084b9b104ad3d9f2bbff2b3d0404ec356862 /intern/cycles/render/image.cpp
parent3b23b5c638feae0ad6319440771b83a64a1f9ebe (diff)
Images: change alpha settings to support channel packing
This also replaces the Use Alpha setting. We now have these alpha modes: * Straight: store RGB and alpha channels separately with alpha acting as a mask, also known as unassociated alpha. * Premultiplied: transparent RGB pixels are multiplied by the alpha channel. The natural format for renders. * Channel Packed: different images are packed in the RGB and alpha channels, and they should not influence each other. Channel packing is commonly used by game engines to save memory. * None: ignore alpha channel from the file and make image fully opaque. Cycles OSL does not correctly support Channel Packed and None yet, we are missing fine control over the OpenImageIO texture cache to do that. Fixes T53672
Diffstat (limited to 'intern/cycles/render/image.cpp')
-rw-r--r--intern/cycles/render/image.cpp30
1 files changed, 16 insertions, 14 deletions
diff --git a/intern/cycles/render/image.cpp b/intern/cycles/render/image.cpp
index 6301b416724..160e7d9ff1e 100644
--- a/intern/cycles/render/image.cpp
+++ b/intern/cycles/render/image.cpp
@@ -299,12 +299,12 @@ static bool image_equals(ImageManager::Image *image,
void *builtin_data,
InterpolationType interpolation,
ExtensionType extension,
- bool use_alpha,
+ ImageAlphaType alpha_type,
ustring colorspace)
{
return image->filename == filename && image->builtin_data == builtin_data &&
image->interpolation == interpolation && image->extension == extension &&
- image->use_alpha == use_alpha && image->colorspace == colorspace;
+ image->alpha_type == alpha_type && image->colorspace == colorspace;
}
int ImageManager::add_image(const string &filename,
@@ -313,7 +313,7 @@ int ImageManager::add_image(const string &filename,
float frame,
InterpolationType interpolation,
ExtensionType extension,
- bool use_alpha,
+ ImageAlphaType alpha_type,
ustring colorspace,
ImageMetaData &metadata)
{
@@ -338,14 +338,15 @@ int ImageManager::add_image(const string &filename,
/* Fnd existing image. */
for (slot = 0; slot < images[type].size(); slot++) {
img = images[type][slot];
- if (img && image_equals(
- img, filename, builtin_data, interpolation, extension, use_alpha, colorspace)) {
+ if (img &&
+ image_equals(
+ img, filename, builtin_data, interpolation, extension, alpha_type, colorspace)) {
if (img->frame != frame) {
img->frame = frame;
img->need_load = true;
}
- if (img->use_alpha != use_alpha) {
- img->use_alpha = use_alpha;
+ if (img->alpha_type != alpha_type) {
+ img->alpha_type = alpha_type;
img->need_load = true;
}
if (img->colorspace != colorspace) {
@@ -399,7 +400,7 @@ int ImageManager::add_image(const string &filename,
img->interpolation = interpolation;
img->extension = extension;
img->users = 1;
- img->use_alpha = use_alpha;
+ img->alpha_type = alpha_type;
img->colorspace = colorspace;
img->mem = NULL;
@@ -445,7 +446,7 @@ void ImageManager::remove_image(const string &filename,
void *builtin_data,
InterpolationType interpolation,
ExtensionType extension,
- bool use_alpha,
+ ImageAlphaType alpha_type,
ustring colorspace)
{
size_t slot;
@@ -457,7 +458,7 @@ void ImageManager::remove_image(const string &filename,
builtin_data,
interpolation,
extension,
- use_alpha,
+ alpha_type,
colorspace)) {
remove_image(type_index_to_flattened_slot(slot, (ImageDataType)type));
return;
@@ -474,7 +475,7 @@ void ImageManager::tag_reload_image(const string &filename,
void *builtin_data,
InterpolationType interpolation,
ExtensionType extension,
- bool use_alpha,
+ ImageAlphaType alpha_type,
ustring colorspace)
{
for (size_t type = 0; type < IMAGE_DATA_NUM_TYPES; type++) {
@@ -484,7 +485,7 @@ void ImageManager::tag_reload_image(const string &filename,
builtin_data,
interpolation,
extension,
- use_alpha,
+ alpha_type,
colorspace)) {
images[type][slot]->need_load = true;
break;
@@ -516,7 +517,8 @@ bool ImageManager::file_load_image_generic(Image *img, unique_ptr<ImageInput> *i
/* 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->use_alpha == false);
+ img->alpha_type == IMAGE_ALPHA_IGNORE ||
+ img->alpha_type == IMAGE_ALPHA_CHANNEL_PACKED);
if (!associate_alpha) {
config.attribute("oiio:UnassociatedAlpha", 1);
@@ -692,7 +694,7 @@ bool ImageManager::file_load_image(Image *img,
}
/* Disable alpha if requested by the user. */
- if (img->use_alpha == false) {
+ if (img->alpha_type == IMAGE_ALPHA_IGNORE) {
for (size_t i = num_pixels - 1, pixel = 0; pixel < num_pixels; pixel++, i--) {
pixels[i * 4 + 3] = one;
}