diff options
author | M.G. Kishalmi <lmg@kishalmi.net> | 2011-02-23 15:02:43 +0300 |
---|---|---|
committer | M.G. Kishalmi <lmg@kishalmi.net> | 2011-02-23 15:02:43 +0300 |
commit | f0f3d9a2fff6316b62634256e0cd46f508fb68a2 (patch) | |
tree | 332e0a743ca838cfbe334045cb0066707539faf4 | |
parent | d7c29a0310f3709395a6de2a1ace6da395770aa6 (diff) |
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.
-rw-r--r-- | release/scripts/ui/space_image.py | 30 | ||||
-rw-r--r-- | source/blender/editors/space_image/image_intern.h | 2 | ||||
-rw-r--r-- | source/blender/editors/space_image/image_ops.c | 68 | ||||
-rw-r--r-- | source/blender/editors/space_image/space_image.c | 2 |
4 files changed, 98 insertions, 4 deletions
diff --git a/release/scripts/ui/space_image.py b/release/scripts/ui/space_image.py index 9687bcfaadf..09229fb8105 100644 --- a/release/scripts/ui/space_image.py +++ b/release/scripts/ui/space_image.py @@ -128,6 +128,10 @@ class IMAGE_MT_image(bpy.types.Menu): layout.operator("image.external_edit", "Edit Externally") + layout.separator() + + layout.menu("IMAGE_MT_image_invert") + if not show_render: layout.separator() @@ -147,6 +151,32 @@ class IMAGE_MT_image(bpy.types.Menu): 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): bl_label = "Show/Hide Faces" diff --git a/source/blender/editors/space_image/image_intern.h b/source/blender/editors/space_image/image_intern.h index 5111d3c41e7..f3804fbc453 100644 --- a/source/blender/editors/space_image/image_intern.h +++ b/source/blender/editors/space_image/image_intern.h @@ -79,6 +79,8 @@ void IMAGE_OT_save_sequence(struct wmOperatorType *ot); void IMAGE_OT_pack(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_sample(struct wmOperatorType *ot); diff --git a/source/blender/editors/space_image/image_ops.c b/source/blender/editors/space_image/image_ops.c index d5d20d034d5..374acda5b09 100644 --- a/source/blender/editors/space_image/image_ops.c +++ b/source/blender/editors/space_image/image_ops.c @@ -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."); } +/********************* 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 *********************/ static int pack_test(bContext *C, wmOperator *op) @@ -1499,10 +1563,6 @@ void IMAGE_OT_unpack(wmOperatorType *ot) /* 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, "id", "", 21, "Image Name", "Image datablock name to unpack."); /* XXX, weark!, will fail with library, name collisions */ } /******************** sample image operator ********************/ diff --git a/source/blender/editors/space_image/space_image.c b/source/blender/editors/space_image/space_image.c index 132076954b3..cc81d7ac975 100644 --- a/source/blender/editors/space_image/space_image.c +++ b/source/blender/editors/space_image/space_image.c @@ -478,6 +478,8 @@ static void image_operatortypes(void) WM_operatortype_append(IMAGE_OT_save_sequence); WM_operatortype_append(IMAGE_OT_pack); WM_operatortype_append(IMAGE_OT_unpack); + + WM_operatortype_append(IMAGE_OT_invert); WM_operatortype_append(IMAGE_OT_cycle_render_slot); |