added image-editor operators:
authorM.G. Kishalmi <lmg@kishalmi.net>
Wed, 23 Feb 2011 12:02:43 +0000 (12:02 +0000)
committerM.G. Kishalmi <lmg@kishalmi.net>
Wed, 23 Feb 2011 12:02:43 +0000 (12:02 +0000)
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.

release/scripts/ui/space_image.py
source/blender/editors/space_image/image_intern.h
source/blender/editors/space_image/image_ops.c
source/blender/editors/space_image/space_image.c

index 9687bcfaadf73453b2ff55d7b9694d1aa7707c69..09229fb81054998e55803067c648d97d20772c8e 100644 (file)
@@ -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"
 
index 5111d3c41e7b13011dd15653a86e0c172c1f5c08..f3804fbc453cc66be8204154e430a54e5c768c8b 100644 (file)
@@ -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);
index d5d20d034d5ba4bb9749cc4963c2b48ec2eb00d7..374acda5b09e02fef988684600ade250ec868976 100644 (file)
@@ -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 ********************/
index 132076954b3b15cf9baf394df67bb586c44be6f6..cc81d7ac97531c66377e6aa7ca93979fd51ee405 100644 (file)
@@ -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);