forked from bartvdbraak/blender
Fix [#22610] Alpha problem with textureswhen Brightness > 1 or Contrast < 1
* Enabled premultiplication for packed images * Added pack/unpack operator to image template * Moved brightness/contrast corrections to after de-premultiplication in image texture sampling
This commit is contained in:
parent
a8f6a198a6
commit
3173232bfa
@ -1715,7 +1715,10 @@ static ImBuf *image_load_image_file(Image *ima, ImageUser *iuser, int cfra)
|
||||
|
||||
/* is there a PackedFile with this image ? */
|
||||
if (ima->packedfile) {
|
||||
ibuf = IMB_ibImageFromMemory((unsigned char*)ima->packedfile->data, ima->packedfile->size, IB_rect|IB_multilayer);
|
||||
flag = IB_rect|IB_multilayer;
|
||||
if(ima->flag & IMA_DO_PREMUL) flag |= IB_premul;
|
||||
|
||||
ibuf = IMB_ibImageFromMemory((unsigned char*)ima->packedfile->data, ima->packedfile->size, flag);
|
||||
}
|
||||
else {
|
||||
flag= IB_rect|IB_multilayer|IB_metadata;
|
||||
|
@ -841,6 +841,16 @@ void uiTemplateImage(uiLayout *layout, bContext *C, PointerRNA *ptr, char *propn
|
||||
|
||||
if(ima->source != IMA_SRC_GENERATED) {
|
||||
row= uiLayoutRow(layout, 1);
|
||||
split = uiLayoutSplit(row, 0.0, 0);
|
||||
if (ima->packedfile)
|
||||
uiItemO(split, "", ICON_PACKAGE, "image.unpack");
|
||||
else
|
||||
uiItemO(split, "", ICON_UGLYPACKAGE, "image.pack");
|
||||
|
||||
split = uiLayoutSplit(row, 0.0, 0);
|
||||
row= uiLayoutRow(split, 1);
|
||||
uiLayoutSetEnabled(row, ima->packedfile==NULL);
|
||||
|
||||
uiItemR(row, &imaptr, "filepath", 0, "", 0);
|
||||
uiItemO(row, "", ICON_FILE_REFRESH, "image.reload");
|
||||
}
|
||||
|
@ -25,6 +25,7 @@
|
||||
* ***** END GPL LICENSE BLOCK *****
|
||||
*/
|
||||
|
||||
#include <stddef.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
@ -1285,6 +1286,8 @@ static int pack_exec(bContext *C, wmOperator *op)
|
||||
else
|
||||
ima->packedfile= newPackedFile(op->reports, ima->name);
|
||||
|
||||
WM_event_add_notifier(C, NC_IMAGE|NA_EDITED, ima);
|
||||
|
||||
return OPERATOR_FINISHED;
|
||||
}
|
||||
|
||||
@ -1315,12 +1318,12 @@ void IMAGE_OT_pack(wmOperatorType *ot)
|
||||
{
|
||||
/* identifiers */
|
||||
ot->name= "Pack";
|
||||
ot->description= "Pack an image as embedded data into the .blend file";
|
||||
ot->idname= "IMAGE_OT_pack";
|
||||
|
||||
/* api callbacks */
|
||||
ot->exec= pack_exec;
|
||||
ot->invoke= pack_invoke;
|
||||
ot->poll= space_image_buffer_exists_poll;
|
||||
|
||||
/* flags */
|
||||
ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
|
||||
@ -1331,12 +1334,14 @@ void IMAGE_OT_pack(wmOperatorType *ot)
|
||||
|
||||
/********************* unpack operator *********************/
|
||||
|
||||
void unpack_menu(bContext *C, char *opname, char *abs_name, char *folder, PackedFile *pf)
|
||||
void unpack_menu(bContext *C, char *opname, Image *ima, char *folder, PackedFile *pf)
|
||||
{
|
||||
PointerRNA props_ptr;
|
||||
uiPopupMenu *pup;
|
||||
uiLayout *layout;
|
||||
char line[FILE_MAXDIR + FILE_MAXFILE + 100];
|
||||
char local_name[FILE_MAXDIR + FILE_MAX], fi[FILE_MAX];
|
||||
char *abs_name = ima->name;
|
||||
|
||||
strcpy(local_name, abs_name);
|
||||
BLI_splitdirstring(local_name, fi);
|
||||
@ -1351,17 +1356,33 @@ void unpack_menu(bContext *C, char *opname, char *abs_name, char *folder, Packed
|
||||
switch(checkPackedFile(local_name, pf)) {
|
||||
case PF_NOFILE:
|
||||
sprintf(line, "Create %s", local_name);
|
||||
uiItemEnumO(layout, opname, line, 0, "method", PF_WRITE_LOCAL);
|
||||
props_ptr= uiItemFullO(layout, opname, line, 0, NULL, WM_OP_EXEC_DEFAULT, UI_ITEM_O_RETURN_PROPS);
|
||||
RNA_enum_set(&props_ptr, "method", PF_WRITE_LOCAL);
|
||||
RNA_string_set(&props_ptr, "image", ima->id.name+2);
|
||||
|
||||
break;
|
||||
case PF_EQUAL:
|
||||
sprintf(line, "Use %s (identical)", local_name);
|
||||
uiItemEnumO(layout, opname, line, 0, "method", PF_USE_LOCAL);
|
||||
//uiItemEnumO(layout, opname, line, 0, "method", PF_USE_LOCAL);
|
||||
props_ptr= uiItemFullO(layout, opname, line, 0, NULL, WM_OP_EXEC_DEFAULT, UI_ITEM_O_RETURN_PROPS);
|
||||
RNA_enum_set(&props_ptr, "method", PF_USE_LOCAL);
|
||||
RNA_string_set(&props_ptr, "image", ima->id.name+2);
|
||||
|
||||
break;
|
||||
case PF_DIFFERS:
|
||||
sprintf(line, "Use %s (differs)", local_name);
|
||||
uiItemEnumO(layout, opname, line, 0, "method", PF_USE_LOCAL);
|
||||
//uiItemEnumO(layout, opname, line, 0, "method", PF_USE_LOCAL);
|
||||
props_ptr= uiItemFullO(layout, opname, line, 0, NULL, WM_OP_EXEC_DEFAULT, UI_ITEM_O_RETURN_PROPS);
|
||||
RNA_enum_set(&props_ptr, "method", PF_USE_LOCAL);
|
||||
RNA_string_set(&props_ptr, "image", ima->id.name);
|
||||
|
||||
sprintf(line, "Overwrite %s", local_name);
|
||||
uiItemEnumO(layout, opname, line, 0, "method", PF_WRITE_LOCAL);
|
||||
//uiItemEnumO(layout, opname, line, 0, "method", PF_WRITE_LOCAL);
|
||||
props_ptr= uiItemFullO(layout, opname, line, 0, NULL, WM_OP_EXEC_DEFAULT, UI_ITEM_O_RETURN_PROPS);
|
||||
RNA_enum_set(&props_ptr, "method", PF_WRITE_LOCAL);
|
||||
RNA_string_set(&props_ptr, "image", ima->id.name+2);
|
||||
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -1369,17 +1390,30 @@ void unpack_menu(bContext *C, char *opname, char *abs_name, char *folder, Packed
|
||||
switch(checkPackedFile(abs_name, pf)) {
|
||||
case PF_NOFILE:
|
||||
sprintf(line, "Create %s", abs_name);
|
||||
uiItemEnumO(layout, opname, line, 0, "method", PF_WRITE_ORIGINAL);
|
||||
//uiItemEnumO(layout, opname, line, 0, "method", PF_WRITE_ORIGINAL);
|
||||
props_ptr= uiItemFullO(layout, opname, line, 0, NULL, WM_OP_EXEC_DEFAULT, UI_ITEM_O_RETURN_PROPS);
|
||||
RNA_enum_set(&props_ptr, "method", PF_WRITE_ORIGINAL);
|
||||
RNA_string_set(&props_ptr, "image", ima->id.name+2);
|
||||
break;
|
||||
case PF_EQUAL:
|
||||
sprintf(line, "Use %s (identical)", abs_name);
|
||||
uiItemEnumO(layout, opname, line, 0, "method", PF_USE_ORIGINAL);
|
||||
//uiItemEnumO(layout, opname, line, 0, "method", PF_USE_ORIGINAL);
|
||||
props_ptr= uiItemFullO(layout, opname, line, 0, NULL, WM_OP_EXEC_DEFAULT, UI_ITEM_O_RETURN_PROPS);
|
||||
RNA_enum_set(&props_ptr, "method", PF_USE_ORIGINAL);
|
||||
RNA_string_set(&props_ptr, "image", ima->id.name+2);
|
||||
break;
|
||||
case PF_DIFFERS:
|
||||
sprintf(line, "Use %s (differs)", local_name);
|
||||
uiItemEnumO(layout, opname, line, 0, "method", PF_USE_ORIGINAL);
|
||||
//uiItemEnumO(layout, opname, line, 0, "method", PF_USE_ORIGINAL);
|
||||
props_ptr= uiItemFullO(layout, opname, line, 0, NULL, WM_OP_EXEC_DEFAULT, UI_ITEM_O_RETURN_PROPS);
|
||||
RNA_enum_set(&props_ptr, "method", PF_USE_ORIGINAL);
|
||||
RNA_string_set(&props_ptr, "image", ima->id.name+2);
|
||||
|
||||
sprintf(line, "Overwrite %s", local_name);
|
||||
uiItemEnumO(layout, opname, line, 0, "method", PF_WRITE_ORIGINAL);
|
||||
//uiItemEnumO(layout, opname, line, 0, "method", PF_WRITE_ORIGINAL);
|
||||
props_ptr= uiItemFullO(layout, opname, line, 0, NULL, WM_OP_EXEC_DEFAULT, UI_ITEM_O_RETURN_PROPS);
|
||||
RNA_enum_set(&props_ptr, "method", PF_WRITE_ORIGINAL);
|
||||
RNA_string_set(&props_ptr, "image", ima->id.name+2);
|
||||
break;
|
||||
}
|
||||
|
||||
@ -1391,6 +1425,14 @@ static int unpack_exec(bContext *C, wmOperator *op)
|
||||
Image *ima= CTX_data_edit_image(C);
|
||||
int method= RNA_enum_get(op->ptr, "method");
|
||||
|
||||
/* find the suppplied image by name */
|
||||
if (RNA_property_is_set(op->ptr, "image")) {
|
||||
char imaname[22];
|
||||
RNA_string_get(op->ptr, "image", imaname);
|
||||
ima = BLI_findstring(&CTX_data_main(C)->image, imaname, offsetof(ID, name) + 2);
|
||||
if (!ima) ima = CTX_data_edit_image(C);
|
||||
}
|
||||
|
||||
if(!ima || !ima->packedfile)
|
||||
return OPERATOR_CANCELLED;
|
||||
|
||||
@ -1401,8 +1443,10 @@ static int unpack_exec(bContext *C, wmOperator *op)
|
||||
|
||||
if(G.fileflags & G_AUTOPACK)
|
||||
BKE_report(op->reports, RPT_WARNING, "AutoPack is enabled, so image will be packed again on file save.");
|
||||
|
||||
|
||||
unpackImage(op->reports, ima, method);
|
||||
|
||||
WM_event_add_notifier(C, NC_IMAGE|NA_EDITED, ima);
|
||||
|
||||
return OPERATOR_FINISHED;
|
||||
}
|
||||
@ -1411,6 +1455,9 @@ static int unpack_invoke(bContext *C, wmOperator *op, wmEvent *event)
|
||||
{
|
||||
Image *ima= CTX_data_edit_image(C);
|
||||
|
||||
if(RNA_property_is_set(op->ptr, "image"))
|
||||
return unpack_exec(C, op);
|
||||
|
||||
if(!ima || !ima->packedfile)
|
||||
return OPERATOR_CANCELLED;
|
||||
|
||||
@ -1422,7 +1469,7 @@ static int unpack_invoke(bContext *C, wmOperator *op, wmEvent *event)
|
||||
if(G.fileflags & G_AUTOPACK)
|
||||
BKE_report(op->reports, RPT_WARNING, "AutoPack is enabled, so image will be packed again on file save.");
|
||||
|
||||
unpack_menu(C, "IMAGE_OT_unpack", ima->name, "textures", ima->packedfile);
|
||||
unpack_menu(C, "IMAGE_OT_unpack", ima, "textures", ima->packedfile);
|
||||
|
||||
return OPERATOR_FINISHED;
|
||||
}
|
||||
@ -1431,18 +1478,19 @@ void IMAGE_OT_unpack(wmOperatorType *ot)
|
||||
{
|
||||
/* identifiers */
|
||||
ot->name= "Unpack";
|
||||
ot->description= "Save an image packed in the .blend file to disk";
|
||||
ot->idname= "IMAGE_OT_unpack";
|
||||
|
||||
/* api callbacks */
|
||||
ot->exec= unpack_exec;
|
||||
ot->invoke= unpack_invoke;
|
||||
ot->poll= space_image_buffer_exists_poll;
|
||||
|
||||
/* flags */
|
||||
ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
|
||||
|
||||
/* properties */
|
||||
RNA_def_enum(ot->srna, "method", unpack_method_items, PF_USE_LOCAL, "Method", "How to unpack.");
|
||||
RNA_def_string(ot->srna, "image", "", 21, "Image Name", "Image datablock name to unpack.");
|
||||
}
|
||||
|
||||
/******************** sample image operator ********************/
|
||||
|
@ -236,8 +236,6 @@ int imagewrap(Tex *tex, Image *ima, ImBuf *ibuf, float *texvec, TexResult *texre
|
||||
}
|
||||
}
|
||||
|
||||
BRICONTRGB;
|
||||
|
||||
if(texres->talpha) texres->tin= texres->ta;
|
||||
else if(tex->imaflag & TEX_CALCALPHA) {
|
||||
texres->ta= texres->tin= MAX3(texres->tr, texres->tg, texres->tb);
|
||||
@ -254,6 +252,8 @@ int imagewrap(Tex *tex, Image *ima, ImBuf *ibuf, float *texvec, TexResult *texre
|
||||
texres->tb*= fx;
|
||||
}
|
||||
|
||||
BRICONTRGB;
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
@ -1318,8 +1318,6 @@ static int imagewraposa_aniso(Tex *tex, Image *ima, ImBuf *ibuf, float *texvec,
|
||||
}
|
||||
}
|
||||
|
||||
BRICONTRGB;
|
||||
|
||||
if (tex->imaflag & TEX_CALCALPHA)
|
||||
texres->ta = texres->tin = texres->ta * MAX3(texres->tr, texres->tg, texres->tb);
|
||||
else
|
||||
@ -1348,6 +1346,8 @@ static int imagewraposa_aniso(Tex *tex, Image *ima, ImBuf *ibuf, float *texvec,
|
||||
texres->tb *= fx;
|
||||
}
|
||||
|
||||
BRICONTRGB;
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
@ -1705,8 +1705,6 @@ int imagewraposa(Tex *tex, Image *ima, ImBuf *ibuf, float *texvec, float *DXT, f
|
||||
boxsample(ibuf, fx-minx, fy-miny, fx+minx, fy+miny, texres, imaprepeat, imapextend, 0);
|
||||
}
|
||||
|
||||
BRICONTRGB;
|
||||
|
||||
if(tex->imaflag & TEX_CALCALPHA) {
|
||||
texres->ta= texres->tin= texres->ta*MAX3(texres->tr, texres->tg, texres->tb);
|
||||
}
|
||||
@ -1733,6 +1731,8 @@ int imagewraposa(Tex *tex, Image *ima, ImBuf *ibuf, float *texvec, float *DXT, f
|
||||
texres->tb*= fx;
|
||||
}
|
||||
|
||||
BRICONTRGB;
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user