forked from bartvdbraak/blender
added image-editor operators:
Invert Image Colors (RGB) -- Invert Red Channel Invert Green Channel Invert Blue Channel Invert Alpha Channel mostly because of the recent changes in normalmap channels, so users can adopt old bakes quickly. though they might aswell prove useful in other situations.
This commit is contained in:
parent
d7c29a0310
commit
f0f3d9a2ff
@ -128,6 +128,10 @@ class IMAGE_MT_image(bpy.types.Menu):
|
|||||||
|
|
||||||
layout.operator("image.external_edit", "Edit Externally")
|
layout.operator("image.external_edit", "Edit Externally")
|
||||||
|
|
||||||
|
layout.separator()
|
||||||
|
|
||||||
|
layout.menu("IMAGE_MT_image_invert")
|
||||||
|
|
||||||
if not show_render:
|
if not show_render:
|
||||||
layout.separator()
|
layout.separator()
|
||||||
|
|
||||||
@ -147,6 +151,32 @@ class IMAGE_MT_image(bpy.types.Menu):
|
|||||||
layout.prop(sima, "use_image_paint")
|
layout.prop(sima, "use_image_paint")
|
||||||
|
|
||||||
|
|
||||||
|
class IMAGE_MT_image_invert(bpy.types.Menu):
|
||||||
|
bl_label = "Invert"
|
||||||
|
|
||||||
|
def draw(self, context):
|
||||||
|
layout = self.layout
|
||||||
|
|
||||||
|
op = layout.operator("image.invert", text="Invert Image Colors");
|
||||||
|
op.inv_r = True;
|
||||||
|
op.inv_g = True;
|
||||||
|
op.inv_b = True;
|
||||||
|
|
||||||
|
layout.separator()
|
||||||
|
|
||||||
|
op = layout.operator("image.invert", text="Invert Red Channel");
|
||||||
|
op.inv_r = True;
|
||||||
|
|
||||||
|
op = layout.operator("image.invert", text="Invert Green Channel");
|
||||||
|
op.inv_g = True;
|
||||||
|
|
||||||
|
op = layout.operator("image.invert", text="Invert Blue Channel");
|
||||||
|
op.inv_b = True;
|
||||||
|
|
||||||
|
op = layout.operator("image.invert", text="Invert Alpha Channel");
|
||||||
|
op.inv_a = True;
|
||||||
|
|
||||||
|
|
||||||
class IMAGE_MT_uvs_showhide(bpy.types.Menu):
|
class IMAGE_MT_uvs_showhide(bpy.types.Menu):
|
||||||
bl_label = "Show/Hide Faces"
|
bl_label = "Show/Hide Faces"
|
||||||
|
|
||||||
|
@ -79,6 +79,8 @@ void IMAGE_OT_save_sequence(struct wmOperatorType *ot);
|
|||||||
void IMAGE_OT_pack(struct wmOperatorType *ot);
|
void IMAGE_OT_pack(struct wmOperatorType *ot);
|
||||||
void IMAGE_OT_unpack(struct wmOperatorType *ot);
|
void IMAGE_OT_unpack(struct wmOperatorType *ot);
|
||||||
|
|
||||||
|
void IMAGE_OT_invert(struct wmOperatorType *ot);
|
||||||
|
|
||||||
void IMAGE_OT_cycle_render_slot(struct wmOperatorType *ot);
|
void IMAGE_OT_cycle_render_slot(struct wmOperatorType *ot);
|
||||||
|
|
||||||
void IMAGE_OT_sample(struct wmOperatorType *ot);
|
void IMAGE_OT_sample(struct wmOperatorType *ot);
|
||||||
|
@ -1345,6 +1345,70 @@ void IMAGE_OT_new(wmOperatorType *ot)
|
|||||||
RNA_def_boolean(ot->srna, "float", 0, "32 bit Float", "Create image with 32 bit floating point bit depth.");
|
RNA_def_boolean(ot->srna, "float", 0, "32 bit Float", "Create image with 32 bit floating point bit depth.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/********************* invert operators *********************/
|
||||||
|
|
||||||
|
static int image_invert_exec(bContext *C, wmOperator *op) {
|
||||||
|
Image *ima= CTX_data_edit_image(C);
|
||||||
|
ImBuf *ibuf= BKE_image_get_ibuf(ima, NULL);
|
||||||
|
|
||||||
|
// flags indicate if this channel should be inverted
|
||||||
|
short r,g,b,a;
|
||||||
|
int i;
|
||||||
|
|
||||||
|
r = RNA_boolean_get(op->ptr, "inv_r");
|
||||||
|
g = RNA_boolean_get(op->ptr, "inv_g");
|
||||||
|
b = RNA_boolean_get(op->ptr, "inv_b");
|
||||||
|
a = RNA_boolean_get(op->ptr, "inv_a");
|
||||||
|
|
||||||
|
/* TODO: make this into an IMB_invert_channels(ibuf,r,g,b,a) method!? */
|
||||||
|
if (ibuf->rect_float) {
|
||||||
|
|
||||||
|
float *fp = (float *) ibuf->rect_float;
|
||||||
|
for( i = ibuf->x * ibuf->y; i > 0; i--, fp+=4 ) {
|
||||||
|
if( r ) fp[0] = 1.0f - fp[0];
|
||||||
|
if( g ) fp[1] = 1.0f - fp[1];
|
||||||
|
if( b ) fp[2] = 1.0f - fp[2];
|
||||||
|
if( a ) fp[3] = 1.0f - fp[3];
|
||||||
|
}
|
||||||
|
IMB_rect_from_float(ibuf);
|
||||||
|
}
|
||||||
|
else if(ibuf->rect) {
|
||||||
|
|
||||||
|
char *cp = (char *) ibuf->rect;
|
||||||
|
for( i = ibuf->x * ibuf->y; i > 0; i--, cp+=4 ) {
|
||||||
|
if( r ) cp[0] = 255 - cp[0];
|
||||||
|
if( g ) cp[1] = 255 - cp[1];
|
||||||
|
if( b ) cp[2] = 255 - cp[2];
|
||||||
|
if( a ) cp[3] = 255 - cp[3];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
return OPERATOR_CANCELLED;
|
||||||
|
|
||||||
|
WM_event_add_notifier(C, NC_IMAGE|NA_EDITED, ima);
|
||||||
|
|
||||||
|
return OPERATOR_FINISHED;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void IMAGE_OT_invert(wmOperatorType *ot) {
|
||||||
|
/* identifiers */
|
||||||
|
ot->name= "Invert Channels";
|
||||||
|
ot->idname= "IMAGE_OT_invert";
|
||||||
|
|
||||||
|
/* api callbacks */
|
||||||
|
ot->exec= image_invert_exec;
|
||||||
|
|
||||||
|
/* properties */
|
||||||
|
RNA_def_boolean(ot->srna, "inv_r", 0, "Red", "Invert Red Channel");
|
||||||
|
RNA_def_boolean(ot->srna, "inv_g", 0, "Green", "Invert Green Channel");
|
||||||
|
RNA_def_boolean(ot->srna, "inv_b", 0, "Blue", "Invert Blue Channel");
|
||||||
|
RNA_def_boolean(ot->srna, "inv_a", 0, "Alpha", "Invert Alpha Channel");
|
||||||
|
|
||||||
|
/* flags */
|
||||||
|
ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
|
||||||
|
}
|
||||||
|
|
||||||
/********************* pack operator *********************/
|
/********************* pack operator *********************/
|
||||||
|
|
||||||
static int pack_test(bContext *C, wmOperator *op)
|
static int pack_test(bContext *C, wmOperator *op)
|
||||||
@ -1499,10 +1563,6 @@ void IMAGE_OT_unpack(wmOperatorType *ot)
|
|||||||
|
|
||||||
/* flags */
|
/* flags */
|
||||||
ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
|
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, "id", "", 21, "Image Name", "Image datablock name to unpack."); /* XXX, weark!, will fail with library, name collisions */
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/******************** sample image operator ********************/
|
/******************** sample image operator ********************/
|
||||||
|
@ -479,6 +479,8 @@ static void image_operatortypes(void)
|
|||||||
WM_operatortype_append(IMAGE_OT_pack);
|
WM_operatortype_append(IMAGE_OT_pack);
|
||||||
WM_operatortype_append(IMAGE_OT_unpack);
|
WM_operatortype_append(IMAGE_OT_unpack);
|
||||||
|
|
||||||
|
WM_operatortype_append(IMAGE_OT_invert);
|
||||||
|
|
||||||
WM_operatortype_append(IMAGE_OT_cycle_render_slot);
|
WM_operatortype_append(IMAGE_OT_cycle_render_slot);
|
||||||
|
|
||||||
WM_operatortype_append(IMAGE_OT_sample);
|
WM_operatortype_append(IMAGE_OT_sample);
|
||||||
|
Loading…
Reference in New Issue
Block a user