Fixes for alpha mode do_versions code

Before this change only old flag "Premultiply" was used to
detect alpha mode, which is not enough actually.

Now the logic here is:

- If "Premultiply" was enabled it is likely float image with
  straight alpha, which shall be premultiplied before usage.

  In this case image/sequence Alpha Mode is set to Straight.

- Otherwise use default alpha mode for image format based on
  an extension. This could fail in some cases like TIFF, but
  this wasn't handled fully correct in older blender anyway.

Initial discovered issue was that EXR images saved in older
Blender versions were set to Straight alpha mode, which is
obviously a straight way to lots of headache.
This commit is contained in:
2013-02-19 08:37:08 +00:00
parent c68d5325d0
commit e5a135e0b2
5 changed files with 47 additions and 2 deletions

View File

@@ -152,6 +152,9 @@ void BKE_image_pool_free(struct ImagePool *pool);
struct ImBuf *BKE_image_pool_acquire_ibuf(struct Image *ima, struct ImageUser *iuser, struct ImagePool *pool);
void BKE_image_pool_release_ibuf(struct Image *ima, struct ImBuf *ibuf, struct ImagePool *pool);
/* set an alpha mode based on file extension */
void BKE_image_alpha_mode_from_extension(struct Image *image);
/* returns a new image or NULL if it can't load */
struct Image *BKE_image_load(struct Main *bmain, const char *filepath);
/* returns existing Image when filename/type is same (frame optional) */

View File

@@ -356,6 +356,8 @@ typedef struct SeqLoadInfo {
typedef struct Sequence *(*SeqLoadFunc)(struct bContext *, ListBase *, struct SeqLoadInfo *);
struct Sequence *BKE_sequence_alloc(ListBase *lb, int cfra, int machine);
void BKE_sequence_alpha_mode_from_extension(struct Sequence *seq);
void BKE_sequence_init_colorspace(struct Sequence *seq);
struct Sequence *BKE_sequencer_add_image_strip(struct bContext *C, ListBase *seqbasep, struct SeqLoadInfo *seq_load);

View File

@@ -571,6 +571,20 @@ static void image_init_color_management(Image *ima)
}
}
void BKE_image_alpha_mode_from_extension(Image *image)
{
if (BLI_testextensie(image->name, ".exr") ||
BLI_testextensie(image->name, ".cin") ||
BLI_testextensie(image->name, ".dpx") ||
BLI_testextensie(image->name, ".hdr"))
{
image->alpha_mode = IMA_ALPHA_PREMUL;
}
else {
image->alpha_mode = IMA_ALPHA_STRAIGHT;
}
}
Image *BKE_image_load(Main *bmain, const char *filepath)
{
Image *ima;

View File

@@ -3955,6 +3955,24 @@ Sequence *BKE_sequence_alloc(ListBase *lb, int cfra, int machine)
return seq;
}
void BKE_sequence_alpha_mode_from_extension(Sequence *seq)
{
if (seq->strip && seq->strip->stripdata) {
char *name = seq->strip->stripdata->name;
if (BLI_testextensie(name, ".exr") ||
BLI_testextensie(name, ".cin") ||
BLI_testextensie(name, ".dpx") ||
BLI_testextensie(name, ".hdr"))
{
seq->alpha_mode = IMA_ALPHA_PREMUL;
}
else {
seq->alpha_mode = IMA_ALPHA_STRAIGHT;
}
}
}
void BKE_sequence_init_colorspace(Sequence *seq)
{
if (seq->strip && seq->strip->stripdata) {

View File

@@ -8653,8 +8653,12 @@ static void do_versions(FileData *fd, Library *lib, Main *main)
SEQ_BEGIN (scene->ed, seq)
{
if (seq->flag & SEQ_MAKE_PREMUL)
if (seq->flag & SEQ_MAKE_PREMUL) {
seq->alpha_mode = SEQ_ALPHA_STRAIGHT;
}
else {
BKE_sequence_alpha_mode_from_extension(seq);
}
}
SEQ_END
@@ -8680,8 +8684,12 @@ static void do_versions(FileData *fd, Library *lib, Main *main)
}
for (image = main->image.first; image; image = image->id.next) {
if (image->flag & IMA_DO_PREMUL)
if (image->flag & IMA_DO_PREMUL) {
image->alpha_mode = IMA_ALPHA_STRAIGHT;
}
else {
BKE_image_alpha_mode_from_extension(image);
}
image->flag &= ~IMA_DONE_TAG;
}