merge with trunk at r31523
[blender.git] / source / blender / editors / space_image / image_ops.c
index a8e231bfae9addbe04c7bc6bed6ac3be43a54603..818a6181626424a4162f4faf3dacfbf424318676 100644 (file)
@@ -33,6 +33,7 @@
 #include "MEM_guardedalloc.h"
 
 #include "DNA_object_types.h"
+#include "DNA_node_types.h"
 #include "DNA_packedFile_types.h"
 #include "DNA_scene_types.h"
 #include "DNA_meshdata_types.h"
@@ -41,7 +42,6 @@
 #include "BKE_context.h"
 #include "BKE_image.h"
 #include "BKE_global.h"
-#include "BKE_image.h"
 #include "BKE_library.h"
 #include "BKE_main.h"
 #include "BKE_node.h"
@@ -131,10 +131,15 @@ static int space_image_file_exists_poll(bContext *C)
                SpaceImage *sima= CTX_wm_space_image(C);
                ImBuf *ibuf;
                void *lock;
-               int poll;
-               
+               int poll= 0;
+               char name[FILE_MAX];
+
                ibuf= ED_space_image_acquire_buffer(sima, &lock);
-               poll= (ibuf && BLI_exists(ibuf->name) && BLI_is_writable(ibuf->name));
+               if(ibuf) {
+                       BLI_strncpy(name, ibuf->name, FILE_MAX);
+                       BLI_path_abs(name, G.sce);
+                       poll= (BLI_exists(name) && BLI_is_writable(name));
+               }
                ED_space_image_release_buffer(sima, lock);
 
                return poll;
@@ -646,9 +651,13 @@ static const EnumPropertyItem image_file_type_items[] = {
 #ifdef WITH_TIFF
                {R_TIFF, "TIFF", 0, "Tiff", ""},
 #endif
+#ifdef WITH_DDS
                {R_RADHDR, "RADIANCE_HDR", 0, "Radiance HDR", ""},
+#endif
+#ifdef WITH_CINEON
                {R_CINEON, "CINEON", 0, "Cineon", ""},
                {R_DPX, "DPX", 0, "DPX", ""},
+#endif
 #ifdef WITH_OPENEXR
                {R_OPENEXR, "OPENEXR", 0, "OpenEXR", ""},
        /* saving sequences of multilayer won't work, they copy buffers  */
@@ -734,7 +743,22 @@ static int open_exec(bContext *C, wmOperator *op)
 static int open_invoke(bContext *C, wmOperator *op, wmEvent *event)
 {
        SpaceImage *sima= CTX_wm_space_image(C);
-       char *path= (sima && sima->image)? sima->image->name: U.textudir;
+       char *path=U.textudir;
+       Image *ima= NULL;
+
+       if(sima) {
+                ima= sima->image;
+       }
+
+       if (ima==NULL) {
+                Tex *tex= CTX_data_pointer_get_type(C, "texture", &RNA_Texture).data;
+                if(tex && tex->type==TEX_IMAGE)
+                        ima= tex->ima;
+       }
+
+       if(ima)
+               path= ima->name;
+       
 
        if(!RNA_property_is_set(op->ptr, "relative_path"))
                RNA_boolean_set(op->ptr, "relative_path", U.flag & USER_RELPATHS);
@@ -1034,6 +1058,8 @@ static int save_exec(bContext *C, wmOperator *op)
        BLI_strncpy(name, ibuf->name, FILE_MAX);
        if(name[0]==0)
                BLI_strncpy(name, G.ima, FILE_MAX);
+       else
+               BLI_path_abs(name, G.sce);
        
        if(BLI_exists(name) && BLI_is_writable(name)) {
                rr= BKE_image_acquire_renderresult(scene, ima);
@@ -1241,7 +1267,7 @@ static int new_exec(bContext *C, wmOperator *op)
 void IMAGE_OT_new(wmOperatorType *ot)
 {
        PropertyRNA *prop;
-       float default_color[4]= {0.0f, 0.0f, 0.0f, 1.0f};
+       static float default_color[4]= {0.0f, 0.0f, 0.0f, 1.0f};
        
        /* identifiers */
        ot->name= "New";
@@ -2056,8 +2082,10 @@ void IMAGE_OT_cycle_render_slot(wmOperatorType *ot)
 
 void ED_image_update_frame(const bContext *C)
 {
-       Main *mainp = CTX_data_main(C);
+       Main *mainp= CTX_data_main(C);
        Scene *scene= CTX_data_scene(C);
+       wmWindowManager *wm= CTX_wm_manager(C);
+       wmWindow *win;
        Tex *tex;
        
        /* texture users */
@@ -2070,41 +2098,40 @@ void ED_image_update_frame(const bContext *C)
                }
        }
        
-#if 0
        /* image window, compo node users */
-       if(G.curscreen) {
-               ScrArea *sa;
-               for(sa= G.curscreen->areabase.first; sa; sa= sa->next) {
-                       if(sa->spacetype==SPACE_VIEW3D) {
-                               View3D *v3d= sa->spacedata.first;
-                               if(v3d->bgpic)
-                                       if(v3d->bgpic->iuser.flag & IMA_ANIM_ALWAYS)
-                                               BKE_image_user_calc_frame(&v3d->bgpic->iuser, scene->r.cfra, 0);
-                       }
-                       else if(sa->spacetype==SPACE_IMAGE) {
-                               SpaceImage *sima= sa->spacedata.first;
-                               if(sima->iuser.flag & IMA_ANIM_ALWAYS)
-                                       BKE_image_user_calc_frame(&sima->iuser, scene->r.cfra, 0);
-                       }
-                       else if(sa->spacetype==SPACE_NODE) {
-                               SpaceNode *snode= sa->spacedata.first;
-                               if((snode->treetype==NTREE_COMPOSIT) && (snode->nodetree)) {
-                                       bNode *node;
-                                       for(node= snode->nodetree->nodes.first; node; node= node->next) {
-                                               if(node->id && node->type==CMP_NODE_IMAGE) {
-                                                       Image *ima= (Image *)node->id;
-                                                       ImageUser *iuser= node->storage;
-                                                       if(ELEM(ima->source, IMA_SRC_MOVIE, IMA_SRC_SEQUENCE))
-                                                               if(iuser->flag & IMA_ANIM_ALWAYS)
-                                                                       BKE_image_user_calc_frame(iuser, scene->r.cfra, 0);
+       if(wm) {
+               for(win= wm->windows.first; win; win= win->next) {
+                       ScrArea *sa;
+                       for(sa= win->screen->areabase.first; sa; sa= sa->next) {
+                               if(sa->spacetype==SPACE_VIEW3D) {
+                                       View3D *v3d= sa->spacedata.first;
+                                       BGpic *bgpic;
+                                       for(bgpic= v3d->bgpicbase.first; bgpic; bgpic= bgpic->next)
+                                               if(bgpic->iuser.flag & IMA_ANIM_ALWAYS)
+                                                       BKE_image_user_calc_frame(&bgpic->iuser, scene->r.cfra, 0);
+                               }
+                               else if(sa->spacetype==SPACE_IMAGE) {
+                                       SpaceImage *sima= sa->spacedata.first;
+                                       if(sima->iuser.flag & IMA_ANIM_ALWAYS)
+                                               BKE_image_user_calc_frame(&sima->iuser, scene->r.cfra, 0);
+                               }
+                               else if(sa->spacetype==SPACE_NODE) {
+                                       SpaceNode *snode= sa->spacedata.first;
+                                       if((snode->treetype==NTREE_COMPOSIT) && (snode->nodetree)) {
+                                               bNode *node;
+                                               for(node= snode->nodetree->nodes.first; node; node= node->next) {
+                                                       if(node->id && node->type==CMP_NODE_IMAGE) {
+                                                               Image *ima= (Image *)node->id;
+                                                               ImageUser *iuser= node->storage;
+                                                               if(ELEM(ima->source, IMA_SRC_MOVIE, IMA_SRC_SEQUENCE))
+                                                                       if(iuser->flag & IMA_ANIM_ALWAYS)
+                                                                               BKE_image_user_calc_frame(iuser, scene->r.cfra, 0);
+                                                       }
                                                }
                                        }
                                }
                        }
                }
        }
-#endif
 }
 
-
-