Commit: 9ea1b88f0f01a617f452d5eaa44ecbebbaa95c4e
Author: Brecht Van Lommel
Date:   Thu Jul 14 20:16:34 2022 +0200
Branches: master
https://developer.blender.org/rB9ea1b88f0f01a617f452d5eaa44ecbebbaa95c4e

Cleanup: add utlity function to compute render resolution

Instead of duplicating logic many times.

===================================================================

M       source/blender/blenkernel/BKE_scene.h
M       source/blender/blenkernel/intern/image.cc
M       source/blender/blenkernel/intern/scene.cc
M       source/blender/compositor/operations/COM_CompositorOperation.cc
M       source/blender/compositor/operations/COM_RenderLayersProg.cc
M       source/blender/compositor/operations/COM_TextureOperation.cc
M       source/blender/compositor/operations/COM_ViewerOperation.cc
M       source/blender/editors/mask/mask_query.c
M       source/blender/editors/render/render_opengl.cc
M       source/blender/editors/render/render_view.cc
M       source/blender/editors/space_image/image_edit.c
M       source/blender/editors/space_image/image_ops.c
M       source/blender/editors/space_sequencer/sequencer_draw.c
M       source/blender/editors/space_sequencer/sequencer_view.c
M       source/blender/editors/space_view3d/view3d_edit.c
M       source/blender/io/gpencil/intern/gpencil_io_base.cc
M       source/blender/io/gpencil/intern/gpencil_io_base.hh
M       source/blender/render/intern/pipeline.c
M       source/blender/sequencer/intern/proxy.c
M       source/blender/sequencer/intern/render.c

===================================================================

diff --git a/source/blender/blenkernel/BKE_scene.h 
b/source/blender/blenkernel/BKE_scene.h
index a6402a1e8a1..61fc883fe7f 100644
--- a/source/blender/blenkernel/BKE_scene.h
+++ b/source/blender/blenkernel/BKE_scene.h
@@ -251,6 +251,10 @@ bool BKE_scene_check_rigidbody_active(const struct Scene 
*scene);
 int BKE_scene_num_threads(const struct Scene *scene);
 int BKE_render_num_threads(const struct RenderData *r);
 
+void BKE_render_resolution(const struct RenderData *r,
+                           const bool use_crop,
+                           int *r_width,
+                           int *r_height);
 int BKE_render_preview_pixel_size(const struct RenderData *r);
 
 /**********************************/
diff --git a/source/blender/blenkernel/intern/image.cc 
b/source/blender/blenkernel/intern/image.cc
index 6ec1c52c61a..f8b2d841028 100644
--- a/source/blender/blenkernel/intern/image.cc
+++ b/source/blender/blenkernel/intern/image.cc
@@ -5060,13 +5060,7 @@ void BKE_image_get_size(Image *image, ImageUser *iuser, 
int *r_width, int *r_hei
   }
   else if (image != nullptr && image->type == IMA_TYPE_R_RESULT && iuser != 
nullptr &&
            iuser->scene != nullptr) {
-    Scene *scene = iuser->scene;
-    *r_width = (scene->r.xsch * scene->r.size) / 100;
-    *r_height = (scene->r.ysch * scene->r.size) / 100;
-    if ((scene->r.mode & R_BORDER) && (scene->r.mode & R_CROP)) {
-      *r_width *= BLI_rctf_size_x(&scene->r.border);
-      *r_height *= BLI_rctf_size_y(&scene->r.border);
-    }
+    BKE_render_resolution(&iuser->scene->r, true, r_width, r_height);
   }
   else {
     *r_width = IMG_SIZE_FALLBACK;
diff --git a/source/blender/blenkernel/intern/scene.cc 
b/source/blender/blenkernel/intern/scene.cc
index 39157bc9890..e2da27fc840 100644
--- a/source/blender/blenkernel/intern/scene.cc
+++ b/source/blender/blenkernel/intern/scene.cc
@@ -2952,6 +2952,20 @@ int BKE_scene_num_threads(const Scene *scene)
   return BKE_render_num_threads(&scene->r);
 }
 
+void BKE_render_resolution(const struct RenderData *r,
+                           const bool use_crop,
+                           int *r_width,
+                           int *r_height)
+{
+  *r_width = (r->xsch * r->size) / 100;
+  *r_height = (r->ysch * r->size) / 100;
+
+  if (use_crop && (r->mode & R_BORDER) && (r->mode & R_CROP)) {
+    *r_width *= BLI_rctf_size_x(&r->border);
+    *r_height *= BLI_rctf_size_y(&r->border);
+  }
+}
+
 int BKE_render_preview_pixel_size(const RenderData *r)
 {
   if (r->preview_pixel_size == 0) {
diff --git a/source/blender/compositor/operations/COM_CompositorOperation.cc 
b/source/blender/compositor/operations/COM_CompositorOperation.cc
index e8b61ff229e..c0cc3fa1ba4 100644
--- a/source/blender/compositor/operations/COM_CompositorOperation.cc
+++ b/source/blender/compositor/operations/COM_CompositorOperation.cc
@@ -5,6 +5,7 @@
 
 #include "BKE_global.h"
 #include "BKE_image.h"
+#include "BKE_scene.h"
 
 #include "RE_pipeline.h"
 
@@ -164,8 +165,8 @@ void CompositorOperation::execute_region(rcti *rect, 
unsigned int /*tile_number*
      *                      Full frame
      */
 
-    int full_width = rd->xsch * rd->size / 100;
-    int full_height = rd->ysch * rd->size / 100;
+    int full_width, full_height;
+    BKE_render_resolution(rd, false, &full_width, &full_height);
 
     dx = rd->border.xmin * full_width - (full_width - this->get_width()) / 
2.0f;
     dy = rd->border.ymin * full_height - (full_height - this->get_height()) / 
2.0f;
@@ -214,8 +215,8 @@ void 
CompositorOperation::update_memory_buffer_partial(MemoryBuffer *UNUSED(outp
 
 void CompositorOperation::determine_canvas(const rcti &UNUSED(preferred_area), 
rcti &r_area)
 {
-  int width = rd_->xsch * rd_->size / 100;
-  int height = rd_->ysch * rd_->size / 100;
+  int width, height;
+  BKE_render_resolution(rd_, false, &width, &height);
 
   /* Check actual render resolution with cropping it may differ with cropped 
border.rendering
    * Fix for T31777 Border Crop gives black (easy). */
diff --git a/source/blender/compositor/operations/COM_RenderLayersProg.cc 
b/source/blender/compositor/operations/COM_RenderLayersProg.cc
index 522086658f8..40f2187b27b 100644
--- a/source/blender/compositor/operations/COM_RenderLayersProg.cc
+++ b/source/blender/compositor/operations/COM_RenderLayersProg.cc
@@ -109,8 +109,8 @@ void RenderLayersProg::execute_pixel_sampled(float 
output[4],
     /* see comment in execute_region describing coordinate mapping,
      * here it simply goes other way around
      */
-    int full_width = rd->xsch * rd->size / 100;
-    int full_height = rd->ysch * rd->size / 100;
+    int full_width, full_height;
+    BKE_render_resolution(rd, false, &full_width, &full_height);
 
     dx = rd->border.xmin * full_width - (full_width - this->get_width()) / 
2.0f;
     dy = rd->border.ymin * full_height - (full_height - this->get_height()) / 
2.0f;
diff --git a/source/blender/compositor/operations/COM_TextureOperation.cc 
b/source/blender/compositor/operations/COM_TextureOperation.cc
index 8b27c3aded4..c1c8db2ae3f 100644
--- a/source/blender/compositor/operations/COM_TextureOperation.cc
+++ b/source/blender/compositor/operations/COM_TextureOperation.cc
@@ -6,6 +6,7 @@
 
 #include "BKE_image.h"
 #include "BKE_node.h"
+#include "BKE_scene.h"
 
 #include "NOD_texture.h"
 
@@ -59,8 +60,8 @@ void TextureBaseOperation::determine_canvas(const rcti 
&preferred_area, rcti &r_
 {
   r_area = preferred_area;
   if (BLI_rcti_is_empty(&preferred_area)) {
-    int width = rd_->xsch * rd_->size / 100;
-    int height = rd_->ysch * rd_->size / 100;
+    int width, height;
+    BKE_render_resolution(rd_, false, &width, &height);
     r_area.xmax = preferred_area.xmin + width;
     r_area.ymax = preferred_area.ymin + height;
   }
diff --git a/source/blender/compositor/operations/COM_ViewerOperation.cc 
b/source/blender/compositor/operations/COM_ViewerOperation.cc
index 58392b8a638..aeadf8f255d 100644
--- a/source/blender/compositor/operations/COM_ViewerOperation.cc
+++ b/source/blender/compositor/operations/COM_ViewerOperation.cc
@@ -104,8 +104,8 @@ void ViewerOperation::execute_region(rcti *rect, unsigned 
int /*tile_number*/)
 
 void ViewerOperation::determine_canvas(const rcti &preferred_area, rcti 
&r_area)
 {
-  const int scene_render_width = rd_->xsch * rd_->size / 100;
-  const int scene_render_height = rd_->ysch * rd_->size / 100;
+  int scene_render_width, scene_render_height;
+  BKE_render_resolution(rd_, false, &scene_render_width, &scene_render_height);
 
   rcti local_preferred = preferred_area;
   local_preferred.xmax = local_preferred.xmin + scene_render_width;
diff --git a/source/blender/editors/mask/mask_query.c 
b/source/blender/editors/mask/mask_query.c
index 02e1524e23e..bb865e925d7 100644
--- a/source/blender/editors/mask/mask_query.c
+++ b/source/blender/editors/mask/mask_query.c
@@ -682,8 +682,7 @@ void ED_mask_get_size(ScrArea *area, int *width, int 
*height)
       }
       case SPACE_SEQ: {
         //              Scene *scene = CTX_data_scene(C);
-        //              *width = (scene->r.size * scene->r.xsch) / 100;
-        //              *height = (scene->r.size * scene->r.ysch) / 100;
+        //              BKE_render_resolution(&scene->r, false, width, height);
         break;
       }
       case SPACE_IMAGE: {
diff --git a/source/blender/editors/render/render_opengl.cc 
b/source/blender/editors/render/render_opengl.cc
index 7bd9812a178..77ad23f1e3f 100644
--- a/source/blender/editors/render/render_opengl.cc
+++ b/source/blender/editors/render/render_opengl.cc
@@ -758,8 +758,7 @@ static bool screen_opengl_render_init(bContext *C, 
wmOperator *op)
   WM_jobs_kill_all_except(wm, CTX_wm_screen(C));
 
   /* create offscreen buffer */
-  sizex = (scene->r.size * scene->r.xsch) / 100;
-  sizey = (scene->r.size * scene->r.ysch) / 100;
+  BKE_render_resolution(&scene->r, false, &sizex, &sizey);
 
   /* corrects render size with actual size, not every card supports 
non-power-of-two dimensions */
   DRW_opengl_context_enable(); /* Off-screen creation needs to be done in DRW 
context. */
diff --git a/source/blender/editors/render/render_view.cc 
b/source/blender/editors/render/render_view.cc
index a7ff2aad05a..9a16c910205 100644
--- a/source/blender/editors/render/render_view.cc
+++ b/source/blender/editors/render/render_view.cc
@@ -19,6 +19,7 @@
 #include "BKE_image.h"
 #include "BKE_main.h"
 #include "BKE_report.h"
+#include "BKE_scene.h"
 #include "BKE_screen.h"
 
 #include "BLT_translation.h"
@@ -130,8 +131,11 @@ ScrArea *render_view_open(bContext *C, int mx, int my, 
ReportList *reports)
   }
 
   if (U.render_display_type == USER_RENDER_DISPLAY_WINDOW) {
-    int sizex = 30 * UI_DPI_FAC + (scene->r.xsch * scene->r.size) / 100;
-    int sizey = 60 * UI_DPI_FAC + (scene->r.ysch * scene->r.size) / 100;
+    int sizex, sizey;
+    BKE_render_resolution(&scene->r, false, &sizex, &sizey);
+
+    sizex += 30 * UI_DPI_FAC;
+    sizey += 60 * UI_DPI_FAC;
 
     /* arbitrary... miniature image window views don't make much sense */
     if (sizex < 320) {
diff --git a/source/blender/editors/space_image/image_edit.c 
b/source/blender/editors/space_image/image_edit.c
index 950acd77f6a..0de50474ab8 100644
--- a/source/blender/editors/space_image/image_edit.c
+++ b/source/blender/editors/space_image/image_edit.c
@@ -20,6 +20,7 @@
 #include "BKE_image.h"
 #include "BKE_lib_id.h"
 #include "BKE_main.h"
+#include "BKE_scene.h"
 
 #include "IMB_imbuf_types.h"
 
@@ -212,13 +213,7 @@ void ED_space_image_get_size(SpaceImage *sima, int 
*r_width, int *r_height)
   }
   else if (sima->image && sima->image->type == IMA_TYPE_R_RESULT && scene) {
     /* not very important, just nice */
-    *r_width = (scene->r.xsch * scene->r.size) / 100;
-    *r_height = (scene->r.ysch * scene->r.size) / 100;
-
-    if ((scene->r.mode & R_BORDER) && (scene->r.mode & R_CROP)) {
-      *r_width *= BLI_rctf_size_x(&scene->r.border);
-      *r_height *= BLI_rctf_size_y(&scene->r.border);
-    }
+    BKE_render_resolution(&scene->r, true, r_width, r_height);
   }
   /* I know a bit weak... but preview uses not actual image size */
   // XXX else if (image_preview_active(sima, r_width, r_height));
diff --git a/source/blender/editors/space_im

@@ Diff output truncated at 10240 characters. @@

_______________________________________________
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to