move ED_image functions into their own file.
authorCampbell Barton <ideasman42@gmail.com>
Wed, 25 Jul 2012 10:15:24 +0000 (10:15 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Wed, 25 Jul 2012 10:15:24 +0000 (10:15 +0000)
source/blender/editors/include/ED_image.h
source/blender/editors/space_image/CMakeLists.txt
source/blender/editors/space_image/image_buttons.c
source/blender/editors/space_image/image_edit.c [new file with mode: 0644]
source/blender/editors/space_image/image_ops.c
source/blender/editors/space_image/space_image.c

index b95615ce3650ed6cd3dd5fd2615370d1ea3a5d6f..0387463bc7289b36acc433278bb3be8a6f4d5cfb 100644 (file)
@@ -39,7 +39,7 @@ struct ToolSettings;
 struct uiBlock;
 struct wmWindowManager;
 
-/* space_image.c, exported for transform */
+/* image_edit.c, exported for transform */
 struct Image *ED_space_image(struct SpaceImage *sima);
 void ED_space_image_set(struct SpaceImage *sima, struct Scene *scene, struct Object *obedit, struct Image *ima);
 
index f397f2387d743fdfa3621e96addaa56d3cf687ff..3e3c6adcf8c8f31b3a12affb7fdc59557f9c8859 100644 (file)
@@ -40,6 +40,7 @@ set(INC_SYS
 set(SRC
        image_buttons.c
        image_draw.c
+       image_edit.c
        image_ops.c
        space_image.c
 
index 7d358bcfb8b394df304283c8689b7797fc73af76..0acead3808e7a8602827fa3722a66a8f55f89b59 100644 (file)
@@ -27,8 +27,6 @@
  *  \ingroup spimage
  */
 
-
-
 #include <string.h>
 #include <stdio.h>
 
diff --git a/source/blender/editors/space_image/image_edit.c b/source/blender/editors/space_image/image_edit.c
new file mode 100644 (file)
index 0000000..725c76d
--- /dev/null
@@ -0,0 +1,298 @@
+/*
+ * ***** BEGIN GPL LICENSE BLOCK *****
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * The Original Code is Copyright (C) 2008 Blender Foundation.
+ * All rights reserved.
+ *
+ *
+ * Contributor(s): Blender Foundation
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+/** \file blender/editors/space_image/image_editor.c
+ *  \ingroup spimage
+ */
+
+#include "DNA_object_types.h"
+#include "DNA_scene_types.h"
+
+#include "BLI_math.h"
+
+#include "BKE_image.h"
+#include "BKE_global.h"
+#include "BKE_main.h"
+#include "BKE_tessmesh.h"
+
+#include "IMB_imbuf_types.h"
+
+#include "ED_image.h"  /* own include */
+#include "ED_mesh.h"
+#include "ED_screen.h"
+#include "ED_uvedit.h"
+
+#include "WM_api.h"
+#include "WM_types.h"
+
+/* note; image_panel_properties() uses pointer to sima->image directly */
+Image *ED_space_image(SpaceImage *sima)
+{
+       return sima->image;
+}
+
+/* called to assign images to UV faces */
+void ED_space_image_set(SpaceImage *sima, Scene *scene, Object *obedit, Image *ima)
+{
+       /* context may be NULL, so use global */
+       ED_uvedit_assign_image(G.main, scene, obedit, ima, sima->image);
+
+       /* change the space ima after because uvedit_face_visible_test uses the space ima
+        * to check if the face is displayed in UV-localview */
+       sima->image = ima;
+
+       if (ima == NULL || ima->type == IMA_TYPE_R_RESULT || ima->type == IMA_TYPE_COMPOSITE)
+               sima->flag &= ~SI_DRAWTOOL;
+
+       if (sima->image)
+               BKE_image_signal(sima->image, &sima->iuser, IMA_SIGNAL_USER_NEW_IMAGE);
+
+       if (sima->image && sima->image->id.us == 0)
+               sima->image->id.us = 1;
+
+       if (obedit)
+               WM_main_add_notifier(NC_GEOM | ND_DATA, obedit->data);
+
+       WM_main_add_notifier(NC_SPACE | ND_SPACE_IMAGE, NULL);
+}
+
+ImBuf *ED_space_image_acquire_buffer(SpaceImage *sima, void **lock_r)
+{
+       ImBuf *ibuf;
+
+       if (sima && sima->image) {
+#if 0
+               if (sima->image->type == IMA_TYPE_R_RESULT && BIF_show_render_spare())
+                       return BIF_render_spare_imbuf();
+               else
+#endif
+               ibuf = BKE_image_acquire_ibuf(sima->image, &sima->iuser, lock_r);
+
+               if (ibuf && (ibuf->rect || ibuf->rect_float))
+                       return ibuf;
+       }
+
+       return NULL;
+}
+
+void ED_space_image_release_buffer(SpaceImage *sima, void *lock)
+{
+       if (sima && sima->image)
+               BKE_image_release_ibuf(sima->image, lock);
+}
+
+int ED_space_image_has_buffer(SpaceImage *sima)
+{
+       ImBuf *ibuf;
+       void *lock;
+       int has_buffer;
+
+       ibuf = ED_space_image_acquire_buffer(sima, &lock);
+       has_buffer = (ibuf != NULL);
+       ED_space_image_release_buffer(sima, lock);
+
+       return has_buffer;
+}
+
+void ED_image_size(Image *ima, int *width, int *height)
+{
+       ImBuf *ibuf = NULL;
+       void *lock;
+
+       if (ima)
+               ibuf = BKE_image_acquire_ibuf(ima, NULL, &lock);
+
+       if (ibuf && ibuf->x > 0 && ibuf->y > 0) {
+               *width = ibuf->x;
+               *height = ibuf->y;
+       }
+       else {
+               *width = 256;
+               *height = 256;
+       }
+
+       if (ima)
+               BKE_image_release_ibuf(ima, lock);
+}
+
+void ED_space_image_size(SpaceImage *sima, int *width, int *height)
+{
+       Scene *scene = sima->iuser.scene;
+       ImBuf *ibuf;
+       void *lock;
+
+       ibuf = ED_space_image_acquire_buffer(sima, &lock);
+
+       if (ibuf && ibuf->x > 0 && ibuf->y > 0) {
+               *width = ibuf->x;
+               *height = ibuf->y;
+       }
+       else if (sima->image && sima->image->type == IMA_TYPE_R_RESULT && scene) {
+               /* not very important, just nice */
+               *width = (scene->r.xsch * scene->r.size) / 100;
+               *height = (scene->r.ysch * scene->r.size) / 100;
+
+               if ((scene->r.mode & R_BORDER) && (scene->r.mode & R_CROP)) {
+                       *width *= (scene->r.border.xmax - scene->r.border.xmin);
+                       *height *= (scene->r.border.ymax - scene->r.border.ymin);
+               }
+
+       }
+       /* I know a bit weak... but preview uses not actual image size */
+       // XXX else if (image_preview_active(sima, width, height));
+       else {
+               *width = 256;
+               *height = 256;
+       }
+
+       ED_space_image_release_buffer(sima, lock);
+}
+
+void ED_image_aspect(Image *ima, float *aspx, float *aspy)
+{
+       *aspx = *aspy = 1.0;
+
+       if ((ima == NULL) || (ima->type == IMA_TYPE_R_RESULT) || (ima->type == IMA_TYPE_COMPOSITE) ||
+           (ima->aspx == 0.0f || ima->aspy == 0.0f))
+       {
+               return;
+       }
+
+       /* x is always 1 */
+       *aspy = ima->aspy / ima->aspx;
+}
+
+void ED_space_image_aspect(SpaceImage *sima, float *aspx, float *aspy)
+{
+       ED_image_aspect(ED_space_image(sima), aspx, aspy);
+}
+
+void ED_space_image_zoom(SpaceImage *sima, ARegion *ar, float *zoomx, float *zoomy)
+{
+       int width, height;
+
+       ED_space_image_size(sima, &width, &height);
+
+       *zoomx = (float)(ar->winrct.xmax - ar->winrct.xmin + 1) / (float)((ar->v2d.cur.xmax - ar->v2d.cur.xmin) * width);
+       *zoomy = (float)(ar->winrct.ymax - ar->winrct.ymin + 1) / (float)((ar->v2d.cur.ymax - ar->v2d.cur.ymin) * height);
+}
+
+void ED_space_image_uv_aspect(SpaceImage *sima, float *aspx, float *aspy)
+{
+       int w, h;
+
+       ED_space_image_aspect(sima, aspx, aspy);
+       ED_space_image_size(sima, &w, &h);
+
+       *aspx *= (float)w;
+       *aspy *= (float)h;
+
+       if (*aspx < *aspy) {
+               *aspy = *aspy / *aspx;
+               *aspx = 1.0f;
+       }
+       else {
+               *aspx = *aspx / *aspy;
+               *aspy = 1.0f;
+       }
+}
+
+void ED_image_uv_aspect(Image *ima, float *aspx, float *aspy)
+{
+       int w, h;
+
+       ED_image_aspect(ima, aspx, aspy);
+       ED_image_size(ima, &w, &h);
+
+       *aspx *= (float)w;
+       *aspy *= (float)h;
+}
+
+int ED_space_image_show_render(SpaceImage *sima)
+{
+       return (sima->image && ELEM(sima->image->type, IMA_TYPE_R_RESULT, IMA_TYPE_COMPOSITE));
+}
+
+int ED_space_image_show_paint(SpaceImage *sima)
+{
+       if (ED_space_image_show_render(sima))
+               return 0;
+
+       return (sima->flag & SI_DRAWTOOL);
+}
+
+int ED_space_image_show_uvedit(SpaceImage *sima, Object *obedit)
+{
+       if (sima && (ED_space_image_show_render(sima) || ED_space_image_show_paint(sima)))
+               return 0;
+
+       if (obedit && obedit->type == OB_MESH) {
+               struct BMEditMesh *em = BMEdit_FromObject(obedit);
+               int ret;
+
+               ret = EDBM_mtexpoly_check(em);
+
+               return ret;
+       }
+
+       return 0;
+}
+
+int ED_space_image_show_uvshadow(SpaceImage *sima, Object *obedit)
+{
+       if (ED_space_image_show_render(sima))
+               return 0;
+
+       if (ED_space_image_show_paint(sima))
+               if (obedit && obedit->type == OB_MESH) {
+                       struct BMEditMesh *em = BMEdit_FromObject(obedit);
+                       int ret;
+
+                       ret = EDBM_mtexpoly_check(em);
+
+                       return ret;
+               }
+
+       return 0;
+}
+
+/******************** TODO ********************/
+
+/* XXX notifier? */
+
+/* goes over all ImageUsers, and sets frame numbers if auto-refresh is set */
+
+static void image_update_frame(struct Image *UNUSED(ima), struct ImageUser *iuser, void *customdata)
+{
+       int cfra = *(int *)customdata;
+
+       BKE_image_user_check_frame_calc(iuser, cfra, 0);
+}
+
+void ED_image_update_frame(const Main *mainp, int cfra)
+{
+       BKE_image_walk_all_users(mainp, &cfra, image_update_frame);
+}
index 7d1328ca2667a207944d1196c5552ba2e7f4ca8e..9dfaac76dab17cb8fbcdd587b185c44e59187e85 100644 (file)
@@ -2422,22 +2422,3 @@ void IMAGE_OT_cycle_render_slot(wmOperatorType *ot)
 
        RNA_def_boolean(ot->srna, "reverse", 0, "Cycle in Reverse", "");
 }
-
-/******************** TODO ********************/
-
-/* XXX notifier? */
-
-/* goes over all ImageUsers, and sets frame numbers if auto-refresh is set */
-
-static void image_update_frame(struct Image *UNUSED(ima), struct ImageUser *iuser, void *customdata)
-{
-       int cfra = *(int*)customdata;
-
-       BKE_image_user_check_frame_calc(iuser, cfra, 0);
-}
-
-void ED_image_update_frame(const Main *mainp, int cfra)
-{
-       BKE_image_walk_all_users(mainp, &cfra, image_update_frame);
-}
-
index 6a6658af4aade0d330675c03a480ab65e88742f5..5b8db3bac1de7c4d7d089c1afd9dab29cc5dbb5f 100644 (file)
  *  \ingroup spimage
  */
 
-
-#include <string.h>
-#include <stdio.h>
-
 #include "DNA_mesh_types.h"
 #include "DNA_mask_types.h"
 #include "DNA_meshdata_types.h"
 
 #include "BLI_blenlib.h"
 #include "BLI_math.h"
-#include "BLI_rand.h"
-#include "BLI_utildefines.h"
 
 #include "BKE_colortools.h"
 #include "BKE_context.h"
 #include "BKE_image.h"
-#include "BKE_global.h"
-#include "BKE_main.h"
-#include "BKE_mesh.h"
 #include "BKE_scene.h"
 #include "BKE_screen.h"
 #include "BKE_tessmesh.h"
 
 /**************************** common state *****************************/
 
-/* note; image_panel_properties() uses pointer to sima->image directly */
-Image *ED_space_image(SpaceImage *sima)
-{
-       return sima->image;
-}
-
-/* called to assign images to UV faces */
-void ED_space_image_set(SpaceImage *sima, Scene *scene, Object *obedit, Image *ima)
-{
-       /* context may be NULL, so use global */
-       ED_uvedit_assign_image(G.main, scene, obedit, ima, sima->image);
-       
-       /* change the space ima after because uvedit_face_visible_test uses the space ima
-        * to check if the face is displayed in UV-localview */
-       sima->image = ima;
-       
-       if (ima == NULL || ima->type == IMA_TYPE_R_RESULT || ima->type == IMA_TYPE_COMPOSITE)
-               sima->flag &= ~SI_DRAWTOOL;
-       
-       if (sima->image)
-               BKE_image_signal(sima->image, &sima->iuser, IMA_SIGNAL_USER_NEW_IMAGE);
-       
-       if (sima->image && sima->image->id.us == 0)
-               sima->image->id.us = 1;
-       
-       if (obedit)
-               WM_main_add_notifier(NC_GEOM | ND_DATA, obedit->data);
-
-       WM_main_add_notifier(NC_SPACE | ND_SPACE_IMAGE, NULL);
-}
-
-ImBuf *ED_space_image_acquire_buffer(SpaceImage *sima, void **lock_r)
-{
-       ImBuf *ibuf;
-       
-       if (sima && sima->image) {
-#if 0
-               if (sima->image->type == IMA_TYPE_R_RESULT && BIF_show_render_spare())
-                       return BIF_render_spare_imbuf();
-               else
-#endif
-               ibuf = BKE_image_acquire_ibuf(sima->image, &sima->iuser, lock_r);
-               
-               if (ibuf && (ibuf->rect || ibuf->rect_float))
-                       return ibuf;
-       }
-       
-       return NULL;
-}
-
-void ED_space_image_release_buffer(SpaceImage *sima, void *lock)
-{
-       if (sima && sima->image)
-               BKE_image_release_ibuf(sima->image, lock);
-}
-
-int ED_space_image_has_buffer(SpaceImage *sima)
-{
-       ImBuf *ibuf;
-       void *lock;
-       int has_buffer;
-       
-       ibuf = ED_space_image_acquire_buffer(sima, &lock);
-       has_buffer = (ibuf != NULL);
-       ED_space_image_release_buffer(sima, lock);
-       
-       return has_buffer;
-}
-
-void ED_image_size(Image *ima, int *width, int *height)
-{
-       ImBuf *ibuf = NULL;
-       void *lock;
-       
-       if (ima)
-               ibuf = BKE_image_acquire_ibuf(ima, NULL, &lock);
-       
-       if (ibuf && ibuf->x > 0 && ibuf->y > 0) {
-               *width = ibuf->x;
-               *height = ibuf->y;
-       }
-       else {
-               *width = 256;
-               *height = 256;
-       }
-       
-       if (ima)
-               BKE_image_release_ibuf(ima, lock);
-}
-
-void ED_space_image_size(SpaceImage *sima, int *width, int *height)
-{
-       Scene *scene = sima->iuser.scene;
-       ImBuf *ibuf;
-       void *lock;
-       
-       ibuf = ED_space_image_acquire_buffer(sima, &lock);
-       
-       if (ibuf && ibuf->x > 0 && ibuf->y > 0) {
-               *width = ibuf->x;
-               *height = ibuf->y;
-       }
-       else if (sima->image && sima->image->type == IMA_TYPE_R_RESULT && scene) {
-               /* not very important, just nice */
-               *width = (scene->r.xsch * scene->r.size) / 100;
-               *height = (scene->r.ysch * scene->r.size) / 100;
-
-               if ((scene->r.mode & R_BORDER) && (scene->r.mode & R_CROP)) {
-                       *width *= (scene->r.border.xmax - scene->r.border.xmin);
-                       *height *= (scene->r.border.ymax - scene->r.border.ymin);
-               }
-
-       }
-       /* I know a bit weak... but preview uses not actual image size */
-       // XXX else if (image_preview_active(sima, width, height));
-       else {
-               *width = 256;
-               *height = 256;
-       }
-       
-       ED_space_image_release_buffer(sima, lock);
-}
-
-void ED_image_aspect(Image *ima, float *aspx, float *aspy)
-{
-       *aspx = *aspy = 1.0;
-       
-       if ((ima == NULL) || (ima->type == IMA_TYPE_R_RESULT) || (ima->type == IMA_TYPE_COMPOSITE) ||
-           (ima->aspx == 0.0f || ima->aspy == 0.0f))
-       {
-               return;
-       }
-       
-       /* x is always 1 */
-       *aspy = ima->aspy / ima->aspx;
-}
-
-void ED_space_image_aspect(SpaceImage *sima, float *aspx, float *aspy)
-{
-       ED_image_aspect(ED_space_image(sima), aspx, aspy);
-}
-
-void ED_space_image_zoom(SpaceImage *sima, ARegion *ar, float *zoomx, float *zoomy)
-{
-       int width, height;
-       
-       ED_space_image_size(sima, &width, &height);
-       
-       *zoomx = (float)(ar->winrct.xmax - ar->winrct.xmin + 1) / (float)((ar->v2d.cur.xmax - ar->v2d.cur.xmin) * width);
-       *zoomy = (float)(ar->winrct.ymax - ar->winrct.ymin + 1) / (float)((ar->v2d.cur.ymax - ar->v2d.cur.ymin) * height);
-}
-
-void ED_space_image_uv_aspect(SpaceImage *sima, float *aspx, float *aspy)
-{
-       int w, h;
-       
-       ED_space_image_aspect(sima, aspx, aspy);
-       ED_space_image_size(sima, &w, &h);
-
-       *aspx *= (float)w;
-       *aspy *= (float)h;
-       
-       if (*aspx < *aspy) {
-               *aspy = *aspy / *aspx;
-               *aspx = 1.0f;
-       }
-       else {
-               *aspx = *aspx / *aspy;
-               *aspy = 1.0f;
-       }
-}
-
-void ED_image_uv_aspect(Image *ima, float *aspx, float *aspy)
-{
-       int w, h;
-       
-       ED_image_aspect(ima, aspx, aspy);
-       ED_image_size(ima, &w, &h);
-       
-       *aspx *= (float)w;
-       *aspy *= (float)h;
-}
-
-int ED_space_image_show_render(SpaceImage *sima)
-{
-       return (sima->image && ELEM(sima->image->type, IMA_TYPE_R_RESULT, IMA_TYPE_COMPOSITE));
-}
-
-int ED_space_image_show_paint(SpaceImage *sima)
-{
-       if (ED_space_image_show_render(sima))
-               return 0;
-       
-       return (sima->flag & SI_DRAWTOOL);
-}
-
-int ED_space_image_show_uvedit(SpaceImage *sima, Object *obedit)
-{
-       if (sima && (ED_space_image_show_render(sima) || ED_space_image_show_paint(sima)))
-               return 0;
-
-       if (obedit && obedit->type == OB_MESH) {
-               struct BMEditMesh *em = BMEdit_FromObject(obedit);
-               int ret;
-               
-               ret = EDBM_mtexpoly_check(em);
-               
-               return ret;
-       }
-       
-       return 0;
-}
-
-int ED_space_image_show_uvshadow(SpaceImage *sima, Object *obedit)
-{
-       if (ED_space_image_show_render(sima))
-               return 0;
-       
-       if (ED_space_image_show_paint(sima))
-               if (obedit && obedit->type == OB_MESH) {
-                       struct BMEditMesh *em = BMEdit_FromObject(obedit);
-                       int ret;
-                       
-                       ret = EDBM_mtexpoly_check(em);
-                       
-                       return ret;
-               }
-       
-       return 0;
-}
-
-
 static void image_scopes_tag_refresh(ScrArea *sa)
 {
        SpaceImage *sima = (SpaceImage *)sa->spacedata.first;