2012-07-25 10:15:24 +00:00
|
|
|
/*
|
|
|
|
|
* 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.
|
|
|
|
|
*/
|
|
|
|
|
|
2019-02-18 08:08:12 +11:00
|
|
|
/** \file
|
|
|
|
|
* \ingroup spimage
|
2012-07-25 10:15:24 +00:00
|
|
|
*/
|
|
|
|
|
|
2014-07-21 12:02:05 +02:00
|
|
|
#include "DNA_brush_types.h"
|
2012-07-25 10:39:54 +00:00
|
|
|
#include "DNA_mask_types.h"
|
2012-07-25 10:15:24 +00:00
|
|
|
#include "DNA_object_types.h"
|
|
|
|
|
#include "DNA_scene_types.h"
|
|
|
|
|
|
2018-06-14 22:46:30 +02:00
|
|
|
#include "BLI_listbase.h"
|
2020-03-19 09:33:03 +01:00
|
|
|
#include "BLI_rect.h"
|
2012-07-25 10:15:24 +00:00
|
|
|
|
2015-01-12 14:21:23 +01:00
|
|
|
#include "BKE_colortools.h"
|
2012-07-25 10:39:54 +00:00
|
|
|
#include "BKE_context.h"
|
2018-11-07 18:00:24 +01:00
|
|
|
#include "BKE_editmesh.h"
|
2012-07-25 10:15:24 +00:00
|
|
|
#include "BKE_global.h"
|
2012-07-25 10:39:54 +00:00
|
|
|
#include "BKE_image.h"
|
2020-02-10 12:58:59 +01:00
|
|
|
#include "BKE_lib_id.h"
|
2018-05-31 18:23:20 +02:00
|
|
|
#include "BKE_main.h"
|
2012-07-25 10:15:24 +00:00
|
|
|
|
|
|
|
|
#include "IMB_imbuf_types.h"
|
|
|
|
|
|
2018-02-06 17:28:00 +11:00
|
|
|
#include "DEG_depsgraph.h"
|
|
|
|
|
|
2012-07-25 10:15:24 +00:00
|
|
|
#include "ED_image.h" /* own include */
|
|
|
|
|
#include "ED_mesh.h"
|
|
|
|
|
#include "ED_screen.h"
|
|
|
|
|
#include "ED_uvedit.h"
|
|
|
|
|
|
2012-07-25 20:39:49 +00:00
|
|
|
#include "UI_view2d.h"
|
|
|
|
|
|
2012-07-25 10:15:24 +00:00
|
|
|
#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;
|
|
|
|
|
}
|
|
|
|
|
|
2019-03-11 12:44:14 +01:00
|
|
|
void ED_space_image_set(Main *bmain, SpaceImage *sima, Object *obedit, Image *ima, bool automatic)
|
2012-07-25 10:15:24 +00:00
|
|
|
{
|
2019-03-11 12:44:14 +01:00
|
|
|
/* Automatically pin image when manually assigned, otherwise it follows object. */
|
|
|
|
|
if (!automatic && sima->image != ima && sima->mode == SI_MODE_UV) {
|
|
|
|
|
sima->pin = true;
|
|
|
|
|
}
|
|
|
|
|
|
2012-07-25 10:15:24 +00:00
|
|
|
/* 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;
|
|
|
|
|
|
2012-07-25 11:25:10 +00:00
|
|
|
if (ima == NULL || ima->type == IMA_TYPE_R_RESULT || ima->type == IMA_TYPE_COMPOSITE) {
|
|
|
|
|
if (sima->mode == SI_MODE_PAINT) {
|
|
|
|
|
sima->mode = SI_MODE_VIEW;
|
|
|
|
|
}
|
|
|
|
|
}
|
2012-07-25 10:15:24 +00:00
|
|
|
|
2019-03-26 21:16:47 +11:00
|
|
|
if (sima->image) {
|
2018-06-11 15:40:37 +02:00
|
|
|
BKE_image_signal(bmain, sima->image, &sima->iuser, IMA_SIGNAL_USER_NEW_IMAGE);
|
2019-03-26 21:16:47 +11:00
|
|
|
}
|
2012-07-25 10:15:24 +00:00
|
|
|
|
2012-12-18 08:41:38 +00:00
|
|
|
id_us_ensure_real((ID *)sima->image);
|
2012-07-25 10:15:24 +00:00
|
|
|
|
2019-03-26 21:16:47 +11:00
|
|
|
if (obedit) {
|
2012-07-25 10:15:24 +00:00
|
|
|
WM_main_add_notifier(NC_GEOM | ND_DATA, obedit->data);
|
2019-03-26 21:16:47 +11:00
|
|
|
}
|
2012-07-25 10:15:24 +00:00
|
|
|
|
|
|
|
|
WM_main_add_notifier(NC_SPACE | ND_SPACE_IMAGE, NULL);
|
|
|
|
|
}
|
|
|
|
|
|
2019-03-11 12:44:14 +01:00
|
|
|
void ED_space_image_auto_set(const bContext *C, SpaceImage *sima)
|
|
|
|
|
{
|
|
|
|
|
if (sima->mode != SI_MODE_UV || sima->pin) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-03-11 12:44:14 +01:00
|
|
|
/* Track image assigned to active face in edit mode. */
|
|
|
|
|
Object *ob = CTX_data_active_object(C);
|
|
|
|
|
if (!(ob && (ob->mode & OB_MODE_EDIT) && ED_space_image_show_uvedit(sima, ob))) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-03-11 12:44:14 +01:00
|
|
|
BMEditMesh *em = BKE_editmesh_from_object(ob);
|
|
|
|
|
BMesh *bm = em->bm;
|
|
|
|
|
BMFace *efa = BM_mesh_active_face_get(bm, true, false);
|
|
|
|
|
if (efa == NULL) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-03-11 12:44:14 +01:00
|
|
|
Image *ima = NULL;
|
|
|
|
|
ED_object_get_active_image(ob, efa->mat_nr + 1, &ima, NULL, NULL, NULL);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-03-11 12:44:14 +01:00
|
|
|
if (ima != sima->image) {
|
|
|
|
|
sima->image = ima;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-03-11 12:44:14 +01:00
|
|
|
if (sima->image) {
|
|
|
|
|
Main *bmain = CTX_data_main(C);
|
|
|
|
|
BKE_image_signal(bmain, sima->image, &sima->iuser, IMA_SIGNAL_USER_NEW_IMAGE);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-07-25 10:39:54 +00:00
|
|
|
Mask *ED_space_image_get_mask(SpaceImage *sima)
|
|
|
|
|
{
|
|
|
|
|
return sima->mask_info.mask;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ED_space_image_set_mask(bContext *C, SpaceImage *sima, Mask *mask)
|
|
|
|
|
{
|
|
|
|
|
sima->mask_info.mask = mask;
|
|
|
|
|
|
2012-07-31 17:31:34 +00:00
|
|
|
/* weak, but same as image/space */
|
2012-12-18 08:41:38 +00:00
|
|
|
id_us_ensure_real((ID *)sima->mask_info.mask);
|
2012-07-31 17:31:34 +00:00
|
|
|
|
2012-07-25 10:39:54 +00:00
|
|
|
if (C) {
|
|
|
|
|
WM_event_add_notifier(C, NC_MASK | NA_SELECTED, mask);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
Add support for tiled images and the UDIM naming scheme
This patch contains the work that I did during my week at the Code Quest - adding support for tiled images to Blender.
With this patch, images now contain a list of tiles. By default, this just contains one tile, but if the source type is set to Tiled, the user can add additional tiles. When acquiring an ImBuf, the tile to be loaded is specified in the ImageUser.
Therefore, code that is not yet aware of tiles will just access the default tile as usual.
The filenames of the additional tiles are derived from the original filename according to the UDIM naming scheme - the filename contains an index that is calculated as (1001 + 10*<y coordinate of the tile> + <x coordinate of the tile>), where the x coordinate never goes above 9.
Internally, the various tiles are stored in a cache just like sequences. When acquired for the first time, the code will try to load the corresponding file from disk. Alternatively, a new operator can be used to initialize the tile similar to the New Image operator.
The following features are supported so far:
- Automatic detection and loading of all tiles when opening the first tile (1001)
- Saving all tiles
- Adding and removing tiles
- Filling tiles with generated images
- Drawing all tiles in the Image Editor
- Viewing a tiled grid even if no image is selected
- Rendering tiled images in Eevee
- Rendering tiled images in Cycles (in SVM mode)
- Automatically skipping loading of unused tiles in Cycles
- 2D texture painting (also across tiles)
- 3D texture painting (also across tiles, only limitation: individual faces can not cross tile borders)
- Assigning custom labels to individual tiles (drawn in the Image Editor instead of the ID)
- Different resolutions between tiles
There still are some missing features that will be added later (see T72390):
- Workbench engine support
- Packing/Unpacking support
- Baking support
- Cycles OSL support
- many other Blender features that rely on images
Thanks to Brecht for the review and to all who tested the intermediate versions!
Differential Revision: https://developer.blender.org/D3509
2019-12-12 16:06:08 +01:00
|
|
|
ImBuf *ED_space_image_acquire_buffer(SpaceImage *sima, void **r_lock, int tile)
|
2012-07-25 10:15:24 +00:00
|
|
|
{
|
|
|
|
|
ImBuf *ibuf;
|
|
|
|
|
|
|
|
|
|
if (sima && sima->image) {
|
|
|
|
|
#if 0
|
2019-05-31 23:21:16 +10:00
|
|
|
if (sima->image->type == IMA_TYPE_R_RESULT && BIF_show_render_spare()) {
|
2012-07-25 10:15:24 +00:00
|
|
|
return BIF_render_spare_imbuf();
|
2019-05-31 23:21:16 +10:00
|
|
|
}
|
2012-07-25 10:15:24 +00:00
|
|
|
else
|
|
|
|
|
#endif
|
2019-05-31 23:21:16 +10:00
|
|
|
{
|
Add support for tiled images and the UDIM naming scheme
This patch contains the work that I did during my week at the Code Quest - adding support for tiled images to Blender.
With this patch, images now contain a list of tiles. By default, this just contains one tile, but if the source type is set to Tiled, the user can add additional tiles. When acquiring an ImBuf, the tile to be loaded is specified in the ImageUser.
Therefore, code that is not yet aware of tiles will just access the default tile as usual.
The filenames of the additional tiles are derived from the original filename according to the UDIM naming scheme - the filename contains an index that is calculated as (1001 + 10*<y coordinate of the tile> + <x coordinate of the tile>), where the x coordinate never goes above 9.
Internally, the various tiles are stored in a cache just like sequences. When acquired for the first time, the code will try to load the corresponding file from disk. Alternatively, a new operator can be used to initialize the tile similar to the New Image operator.
The following features are supported so far:
- Automatic detection and loading of all tiles when opening the first tile (1001)
- Saving all tiles
- Adding and removing tiles
- Filling tiles with generated images
- Drawing all tiles in the Image Editor
- Viewing a tiled grid even if no image is selected
- Rendering tiled images in Eevee
- Rendering tiled images in Cycles (in SVM mode)
- Automatically skipping loading of unused tiles in Cycles
- 2D texture painting (also across tiles)
- 3D texture painting (also across tiles, only limitation: individual faces can not cross tile borders)
- Assigning custom labels to individual tiles (drawn in the Image Editor instead of the ID)
- Different resolutions between tiles
There still are some missing features that will be added later (see T72390):
- Workbench engine support
- Packing/Unpacking support
- Baking support
- Cycles OSL support
- many other Blender features that rely on images
Thanks to Brecht for the review and to all who tested the intermediate versions!
Differential Revision: https://developer.blender.org/D3509
2019-12-12 16:06:08 +01:00
|
|
|
sima->iuser.tile = tile;
|
2019-05-31 23:21:16 +10:00
|
|
|
ibuf = BKE_image_acquire_ibuf(sima->image, &sima->iuser, r_lock);
|
Add support for tiled images and the UDIM naming scheme
This patch contains the work that I did during my week at the Code Quest - adding support for tiled images to Blender.
With this patch, images now contain a list of tiles. By default, this just contains one tile, but if the source type is set to Tiled, the user can add additional tiles. When acquiring an ImBuf, the tile to be loaded is specified in the ImageUser.
Therefore, code that is not yet aware of tiles will just access the default tile as usual.
The filenames of the additional tiles are derived from the original filename according to the UDIM naming scheme - the filename contains an index that is calculated as (1001 + 10*<y coordinate of the tile> + <x coordinate of the tile>), where the x coordinate never goes above 9.
Internally, the various tiles are stored in a cache just like sequences. When acquired for the first time, the code will try to load the corresponding file from disk. Alternatively, a new operator can be used to initialize the tile similar to the New Image operator.
The following features are supported so far:
- Automatic detection and loading of all tiles when opening the first tile (1001)
- Saving all tiles
- Adding and removing tiles
- Filling tiles with generated images
- Drawing all tiles in the Image Editor
- Viewing a tiled grid even if no image is selected
- Rendering tiled images in Eevee
- Rendering tiled images in Cycles (in SVM mode)
- Automatically skipping loading of unused tiles in Cycles
- 2D texture painting (also across tiles)
- 3D texture painting (also across tiles, only limitation: individual faces can not cross tile borders)
- Assigning custom labels to individual tiles (drawn in the Image Editor instead of the ID)
- Different resolutions between tiles
There still are some missing features that will be added later (see T72390):
- Workbench engine support
- Packing/Unpacking support
- Baking support
- Cycles OSL support
- many other Blender features that rely on images
Thanks to Brecht for the review and to all who tested the intermediate versions!
Differential Revision: https://developer.blender.org/D3509
2019-12-12 16:06:08 +01:00
|
|
|
sima->iuser.tile = 0;
|
2019-05-31 23:21:16 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-11-15 15:59:58 +00:00
|
|
|
if (ibuf) {
|
2019-03-26 21:16:47 +11:00
|
|
|
if (ibuf->rect || ibuf->rect_float) {
|
2012-11-15 15:59:58 +00:00
|
|
|
return ibuf;
|
2019-03-26 21:16:47 +11:00
|
|
|
}
|
2016-02-01 17:10:40 +01:00
|
|
|
BKE_image_release_ibuf(sima->image, ibuf, *r_lock);
|
|
|
|
|
*r_lock = NULL;
|
2012-11-15 15:59:58 +00:00
|
|
|
}
|
2012-07-25 10:15:24 +00:00
|
|
|
}
|
2019-03-26 21:16:47 +11:00
|
|
|
else {
|
2015-05-08 07:25:39 +10:00
|
|
|
*r_lock = NULL;
|
2019-03-26 21:16:47 +11:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-07-25 10:15:24 +00:00
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
2012-11-15 15:59:58 +00:00
|
|
|
void ED_space_image_release_buffer(SpaceImage *sima, ImBuf *ibuf, void *lock)
|
2012-07-25 10:15:24 +00:00
|
|
|
{
|
2019-03-26 21:16:47 +11:00
|
|
|
if (sima && sima->image) {
|
2012-11-15 15:59:58 +00:00
|
|
|
BKE_image_release_ibuf(sima->image, ibuf, lock);
|
2019-03-26 21:16:47 +11:00
|
|
|
}
|
2012-07-25 10:15:24 +00:00
|
|
|
}
|
|
|
|
|
|
2020-03-23 13:51:55 +01:00
|
|
|
/* Get the SpaceImage flag that is valid for the given ibuf. */
|
|
|
|
|
int ED_space_image_get_display_channel_mask(ImBuf *ibuf)
|
|
|
|
|
{
|
|
|
|
|
int result = (SI_USE_ALPHA | SI_SHOW_ALPHA | SI_SHOW_ZBUF | SI_SHOW_R | SI_SHOW_G | SI_SHOW_B);
|
|
|
|
|
if (!ibuf) {
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const bool color = ibuf->channels >= 3;
|
|
|
|
|
const bool alpha = ibuf->channels == 4;
|
|
|
|
|
const bool zbuf = ibuf->zbuf || ibuf->zbuf_float || (ibuf->channels == 1);
|
|
|
|
|
|
|
|
|
|
if (!alpha) {
|
|
|
|
|
result &= ~(SI_USE_ALPHA | SI_SHOW_ALPHA);
|
|
|
|
|
}
|
|
|
|
|
if (!zbuf) {
|
2020-06-18 12:21:38 +10:00
|
|
|
result &= ~SI_SHOW_ZBUF;
|
2020-03-23 13:51:55 +01:00
|
|
|
}
|
|
|
|
|
if (!color) {
|
|
|
|
|
result &= ~(SI_SHOW_R | SI_SHOW_G | SI_SHOW_B);
|
|
|
|
|
}
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
2014-01-28 03:52:21 +11:00
|
|
|
bool ED_space_image_has_buffer(SpaceImage *sima)
|
2012-07-25 10:15:24 +00:00
|
|
|
{
|
|
|
|
|
ImBuf *ibuf;
|
|
|
|
|
void *lock;
|
2014-01-28 03:52:21 +11:00
|
|
|
bool has_buffer;
|
2012-07-25 10:15:24 +00:00
|
|
|
|
Add support for tiled images and the UDIM naming scheme
This patch contains the work that I did during my week at the Code Quest - adding support for tiled images to Blender.
With this patch, images now contain a list of tiles. By default, this just contains one tile, but if the source type is set to Tiled, the user can add additional tiles. When acquiring an ImBuf, the tile to be loaded is specified in the ImageUser.
Therefore, code that is not yet aware of tiles will just access the default tile as usual.
The filenames of the additional tiles are derived from the original filename according to the UDIM naming scheme - the filename contains an index that is calculated as (1001 + 10*<y coordinate of the tile> + <x coordinate of the tile>), where the x coordinate never goes above 9.
Internally, the various tiles are stored in a cache just like sequences. When acquired for the first time, the code will try to load the corresponding file from disk. Alternatively, a new operator can be used to initialize the tile similar to the New Image operator.
The following features are supported so far:
- Automatic detection and loading of all tiles when opening the first tile (1001)
- Saving all tiles
- Adding and removing tiles
- Filling tiles with generated images
- Drawing all tiles in the Image Editor
- Viewing a tiled grid even if no image is selected
- Rendering tiled images in Eevee
- Rendering tiled images in Cycles (in SVM mode)
- Automatically skipping loading of unused tiles in Cycles
- 2D texture painting (also across tiles)
- 3D texture painting (also across tiles, only limitation: individual faces can not cross tile borders)
- Assigning custom labels to individual tiles (drawn in the Image Editor instead of the ID)
- Different resolutions between tiles
There still are some missing features that will be added later (see T72390):
- Workbench engine support
- Packing/Unpacking support
- Baking support
- Cycles OSL support
- many other Blender features that rely on images
Thanks to Brecht for the review and to all who tested the intermediate versions!
Differential Revision: https://developer.blender.org/D3509
2019-12-12 16:06:08 +01:00
|
|
|
ibuf = ED_space_image_acquire_buffer(sima, &lock, 0);
|
2012-07-25 10:15:24 +00:00
|
|
|
has_buffer = (ibuf != NULL);
|
2012-11-15 15:59:58 +00:00
|
|
|
ED_space_image_release_buffer(sima, ibuf, lock);
|
2012-07-25 10:15:24 +00:00
|
|
|
|
|
|
|
|
return has_buffer;
|
|
|
|
|
}
|
|
|
|
|
|
2020-03-25 17:58:58 +11:00
|
|
|
void ED_space_image_get_size(SpaceImage *sima, int *r_width, int *r_height)
|
2012-07-25 10:15:24 +00:00
|
|
|
{
|
|
|
|
|
Scene *scene = sima->iuser.scene;
|
|
|
|
|
ImBuf *ibuf;
|
|
|
|
|
void *lock;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
Add support for tiled images and the UDIM naming scheme
This patch contains the work that I did during my week at the Code Quest - adding support for tiled images to Blender.
With this patch, images now contain a list of tiles. By default, this just contains one tile, but if the source type is set to Tiled, the user can add additional tiles. When acquiring an ImBuf, the tile to be loaded is specified in the ImageUser.
Therefore, code that is not yet aware of tiles will just access the default tile as usual.
The filenames of the additional tiles are derived from the original filename according to the UDIM naming scheme - the filename contains an index that is calculated as (1001 + 10*<y coordinate of the tile> + <x coordinate of the tile>), where the x coordinate never goes above 9.
Internally, the various tiles are stored in a cache just like sequences. When acquired for the first time, the code will try to load the corresponding file from disk. Alternatively, a new operator can be used to initialize the tile similar to the New Image operator.
The following features are supported so far:
- Automatic detection and loading of all tiles when opening the first tile (1001)
- Saving all tiles
- Adding and removing tiles
- Filling tiles with generated images
- Drawing all tiles in the Image Editor
- Viewing a tiled grid even if no image is selected
- Rendering tiled images in Eevee
- Rendering tiled images in Cycles (in SVM mode)
- Automatically skipping loading of unused tiles in Cycles
- 2D texture painting (also across tiles)
- 3D texture painting (also across tiles, only limitation: individual faces can not cross tile borders)
- Assigning custom labels to individual tiles (drawn in the Image Editor instead of the ID)
- Different resolutions between tiles
There still are some missing features that will be added later (see T72390):
- Workbench engine support
- Packing/Unpacking support
- Baking support
- Cycles OSL support
- many other Blender features that rely on images
Thanks to Brecht for the review and to all who tested the intermediate versions!
Differential Revision: https://developer.blender.org/D3509
2019-12-12 16:06:08 +01:00
|
|
|
/* TODO(lukas): Support tiled images with different sizes */
|
|
|
|
|
ibuf = ED_space_image_acquire_buffer(sima, &lock, 0);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-07-25 10:15:24 +00:00
|
|
|
if (ibuf && ibuf->x > 0 && ibuf->y > 0) {
|
2020-03-25 17:58:58 +11:00
|
|
|
*r_width = ibuf->x;
|
|
|
|
|
*r_height = ibuf->y;
|
2012-07-25 10:15:24 +00:00
|
|
|
}
|
|
|
|
|
else if (sima->image && sima->image->type == IMA_TYPE_R_RESULT && scene) {
|
|
|
|
|
/* not very important, just nice */
|
2020-03-25 17:58:58 +11:00
|
|
|
*r_width = (scene->r.xsch * scene->r.size) / 100;
|
|
|
|
|
*r_height = (scene->r.ysch * scene->r.size) / 100;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-07-25 10:15:24 +00:00
|
|
|
if ((scene->r.mode & R_BORDER) && (scene->r.mode & R_CROP)) {
|
2020-03-25 17:58:58 +11:00
|
|
|
*r_width *= BLI_rctf_size_x(&scene->r.border);
|
|
|
|
|
*r_height *= BLI_rctf_size_y(&scene->r.border);
|
2012-07-25 10:15:24 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
/* I know a bit weak... but preview uses not actual image size */
|
2020-03-25 17:58:58 +11:00
|
|
|
// XXX else if (image_preview_active(sima, r_width, r_height));
|
2012-07-25 10:15:24 +00:00
|
|
|
else {
|
2020-03-25 17:58:58 +11:00
|
|
|
*r_width = IMG_SIZE_FALLBACK;
|
|
|
|
|
*r_height = IMG_SIZE_FALLBACK;
|
2012-07-25 10:15:24 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-11-15 15:59:58 +00:00
|
|
|
ED_space_image_release_buffer(sima, ibuf, lock);
|
2012-07-25 10:15:24 +00:00
|
|
|
}
|
|
|
|
|
|
2020-03-25 17:58:58 +11:00
|
|
|
void ED_space_image_get_size_fl(SpaceImage *sima, float r_size[2])
|
2012-07-26 11:47:47 +00:00
|
|
|
{
|
|
|
|
|
int size_i[2];
|
|
|
|
|
ED_space_image_get_size(sima, &size_i[0], &size_i[1]);
|
2020-03-25 17:58:58 +11:00
|
|
|
r_size[0] = size_i[0];
|
|
|
|
|
r_size[1] = size_i[1];
|
2012-07-26 11:47:47 +00:00
|
|
|
}
|
|
|
|
|
|
2020-03-25 17:58:58 +11:00
|
|
|
void ED_space_image_get_aspect(SpaceImage *sima, float *r_aspx, float *r_aspy)
|
2012-09-13 05:29:38 +00:00
|
|
|
{
|
|
|
|
|
Image *ima = sima->image;
|
2012-12-14 09:19:13 +00:00
|
|
|
if ((ima == NULL) || (ima->aspx == 0.0f || ima->aspy == 0.0f)) {
|
2020-03-25 17:58:58 +11:00
|
|
|
*r_aspx = *r_aspy = 1.0;
|
2012-09-13 05:29:38 +00:00
|
|
|
}
|
|
|
|
|
else {
|
2020-03-25 17:58:58 +11:00
|
|
|
BKE_image_get_aspect(ima, r_aspx, r_aspy);
|
2012-07-25 10:15:24 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-04 19:32:59 +10:00
|
|
|
void ED_space_image_get_zoom(SpaceImage *sima,
|
|
|
|
|
const ARegion *region,
|
|
|
|
|
float *r_zoomx,
|
|
|
|
|
float *r_zoomy)
|
2012-07-25 10:15:24 +00:00
|
|
|
{
|
|
|
|
|
int width, height;
|
|
|
|
|
|
2012-07-25 16:30:53 +00:00
|
|
|
ED_space_image_get_size(sima, &width, &height);
|
2012-07-25 10:15:24 +00:00
|
|
|
|
2020-03-25 17:58:58 +11:00
|
|
|
*r_zoomx = (float)(BLI_rcti_size_x(®ion->winrct) + 1) /
|
|
|
|
|
(float)(BLI_rctf_size_x(®ion->v2d.cur) * width);
|
|
|
|
|
*r_zoomy = (float)(BLI_rcti_size_y(®ion->winrct) + 1) /
|
|
|
|
|
(float)(BLI_rctf_size_y(®ion->v2d.cur) * height);
|
2012-07-25 10:15:24 +00:00
|
|
|
}
|
|
|
|
|
|
2020-03-25 17:58:58 +11:00
|
|
|
void ED_space_image_get_uv_aspect(SpaceImage *sima, float *r_aspx, float *r_aspy)
|
2012-07-25 10:15:24 +00:00
|
|
|
{
|
|
|
|
|
int w, h;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2020-03-25 17:58:58 +11:00
|
|
|
ED_space_image_get_aspect(sima, r_aspx, r_aspy);
|
2012-07-25 16:30:53 +00:00
|
|
|
ED_space_image_get_size(sima, &w, &h);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2020-03-25 17:58:58 +11:00
|
|
|
*r_aspx *= (float)w;
|
|
|
|
|
*r_aspy *= (float)h;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2020-03-25 17:58:58 +11:00
|
|
|
if (*r_aspx < *r_aspy) {
|
|
|
|
|
*r_aspy = *r_aspy / *r_aspx;
|
|
|
|
|
*r_aspx = 1.0f;
|
2012-07-25 10:15:24 +00:00
|
|
|
}
|
|
|
|
|
else {
|
2020-03-25 17:58:58 +11:00
|
|
|
*r_aspx = *r_aspx / *r_aspy;
|
|
|
|
|
*r_aspy = 1.0f;
|
2012-07-25 10:15:24 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-03-25 17:58:58 +11:00
|
|
|
void ED_image_get_uv_aspect(Image *ima, ImageUser *iuser, float *r_aspx, float *r_aspy)
|
2012-07-25 10:15:24 +00:00
|
|
|
{
|
2012-09-13 13:29:10 +00:00
|
|
|
if (ima) {
|
|
|
|
|
int w, h;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2020-03-25 17:58:58 +11:00
|
|
|
BKE_image_get_aspect(ima, r_aspx, r_aspy);
|
2012-09-13 13:29:10 +00:00
|
|
|
BKE_image_get_size(ima, iuser, &w, &h);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2020-03-25 17:58:58 +11:00
|
|
|
*r_aspx *= (float)w;
|
|
|
|
|
*r_aspy *= (float)h;
|
2012-09-13 13:29:10 +00:00
|
|
|
}
|
|
|
|
|
else {
|
2020-03-25 17:58:58 +11:00
|
|
|
*r_aspx = 1.0f;
|
|
|
|
|
*r_aspy = 1.0f;
|
2012-09-13 13:29:10 +00:00
|
|
|
}
|
2012-07-25 10:15:24 +00:00
|
|
|
}
|
|
|
|
|
|
2012-07-27 15:15:55 +00:00
|
|
|
/* takes event->mval */
|
2020-05-04 19:32:59 +10:00
|
|
|
void ED_image_mouse_pos(SpaceImage *sima, const ARegion *region, const int mval[2], float co[2])
|
2012-07-25 20:39:49 +00:00
|
|
|
{
|
|
|
|
|
int sx, sy, width, height;
|
|
|
|
|
float zoomx, zoomy;
|
|
|
|
|
|
2020-03-06 16:56:42 +01:00
|
|
|
ED_space_image_get_zoom(sima, region, &zoomx, &zoomy);
|
2012-07-25 20:39:49 +00:00
|
|
|
ED_space_image_get_size(sima, &width, &height);
|
|
|
|
|
|
2020-03-06 16:56:42 +01:00
|
|
|
UI_view2d_view_to_region(®ion->v2d, 0.0f, 0.0f, &sx, &sy);
|
2012-07-25 20:39:49 +00:00
|
|
|
|
2012-07-27 15:15:55 +00:00
|
|
|
co[0] = ((mval[0] - sx) / zoomx) / width;
|
|
|
|
|
co[1] = ((mval[1] - sy) / zoomy) / height;
|
2012-07-25 20:39:49 +00:00
|
|
|
}
|
|
|
|
|
|
2019-10-01 20:19:44 +10:00
|
|
|
void ED_image_view_center_to_point(SpaceImage *sima, float x, float y)
|
|
|
|
|
{
|
|
|
|
|
int width, height;
|
|
|
|
|
float aspx, aspy;
|
|
|
|
|
|
|
|
|
|
ED_space_image_get_size(sima, &width, &height);
|
|
|
|
|
ED_space_image_get_aspect(sima, &aspx, &aspy);
|
|
|
|
|
|
|
|
|
|
sima->xof = (x - 0.5f) * width * aspx;
|
|
|
|
|
sima->yof = (y - 0.5f) * height * aspy;
|
|
|
|
|
}
|
|
|
|
|
|
2020-03-25 17:58:58 +11:00
|
|
|
void ED_image_point_pos(
|
2020-05-04 19:32:59 +10:00
|
|
|
SpaceImage *sima, const ARegion *region, float x, float y, float *r_x, float *r_y)
|
2012-07-26 09:54:52 +00:00
|
|
|
{
|
|
|
|
|
int sx, sy, width, height;
|
|
|
|
|
float zoomx, zoomy;
|
|
|
|
|
|
2020-03-06 16:56:42 +01:00
|
|
|
ED_space_image_get_zoom(sima, region, &zoomx, &zoomy);
|
2012-07-26 09:54:52 +00:00
|
|
|
ED_space_image_get_size(sima, &width, &height);
|
|
|
|
|
|
2020-03-06 16:56:42 +01:00
|
|
|
UI_view2d_view_to_region(®ion->v2d, 0.0f, 0.0f, &sx, &sy);
|
2012-07-26 09:54:52 +00:00
|
|
|
|
2020-03-25 17:58:58 +11:00
|
|
|
*r_x = ((x - sx) / zoomx) / width;
|
|
|
|
|
*r_y = ((y - sy) / zoomy) / height;
|
2012-07-26 09:54:52 +00:00
|
|
|
}
|
|
|
|
|
|
2020-03-06 16:56:42 +01:00
|
|
|
void ED_image_point_pos__reverse(SpaceImage *sima,
|
2020-05-04 19:32:59 +10:00
|
|
|
const ARegion *region,
|
2020-03-06 16:56:42 +01:00
|
|
|
const float co[2],
|
|
|
|
|
float r_co[2])
|
2012-07-26 09:54:52 +00:00
|
|
|
{
|
|
|
|
|
float zoomx, zoomy;
|
|
|
|
|
int width, height;
|
|
|
|
|
int sx, sy;
|
|
|
|
|
|
2020-03-06 16:56:42 +01:00
|
|
|
UI_view2d_view_to_region(®ion->v2d, 0.0f, 0.0f, &sx, &sy);
|
2012-07-26 09:54:52 +00:00
|
|
|
ED_space_image_get_size(sima, &width, &height);
|
2020-03-06 16:56:42 +01:00
|
|
|
ED_space_image_get_zoom(sima, region, &zoomx, &zoomy);
|
2012-07-26 09:54:52 +00:00
|
|
|
|
|
|
|
|
r_co[0] = (co[0] * width * zoomx) + (float)sx;
|
|
|
|
|
r_co[1] = (co[1] * height * zoomy) + (float)sy;
|
|
|
|
|
}
|
|
|
|
|
|
2015-11-16 07:13:40 +11:00
|
|
|
/**
|
|
|
|
|
* This is more a user-level functionality, for going to next/prev used slot,
|
|
|
|
|
* Stepping onto the last unused slot too.
|
|
|
|
|
*/
|
|
|
|
|
bool ED_image_slot_cycle(struct Image *image, int direction)
|
|
|
|
|
{
|
|
|
|
|
const int cur = image->render_slot;
|
|
|
|
|
int i, slot;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2015-11-16 07:13:40 +11:00
|
|
|
BLI_assert(ELEM(direction, -1, 1));
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-06-14 22:46:30 +02:00
|
|
|
int num_slots = BLI_listbase_count(&image->renderslots);
|
|
|
|
|
for (i = 1; i < num_slots; i++) {
|
|
|
|
|
slot = (cur + ((direction == -1) ? -i : i)) % num_slots;
|
2019-03-26 21:16:47 +11:00
|
|
|
if (slot < 0) {
|
|
|
|
|
slot += num_slots;
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-06-19 16:07:10 +02:00
|
|
|
RenderSlot *render_slot = BKE_image_get_renderslot(image, slot);
|
|
|
|
|
if ((render_slot && render_slot->render) || slot == image->last_render_slot) {
|
2015-11-16 07:13:40 +11:00
|
|
|
image->render_slot = slot;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2020-08-04 19:55:54 +10:00
|
|
|
if (num_slots == 1) {
|
|
|
|
|
image->render_slot = 0;
|
|
|
|
|
}
|
|
|
|
|
else if (i == num_slots) {
|
2015-11-16 07:13:40 +11:00
|
|
|
image->render_slot = ((cur == 1) ? 0 : 1);
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2020-12-18 09:15:55 +01:00
|
|
|
if ((cur != image->render_slot)) {
|
|
|
|
|
image->gpuflag |= IMA_GPU_REFRESH;
|
|
|
|
|
}
|
2015-11-16 07:13:40 +11:00
|
|
|
return (cur != image->render_slot);
|
|
|
|
|
}
|
|
|
|
|
|
2015-01-12 14:21:23 +01:00
|
|
|
void ED_space_image_scopes_update(const struct bContext *C,
|
|
|
|
|
struct SpaceImage *sima,
|
|
|
|
|
struct ImBuf *ibuf,
|
|
|
|
|
bool use_view_settings)
|
|
|
|
|
{
|
|
|
|
|
Scene *scene = CTX_data_scene(C);
|
|
|
|
|
Object *ob = CTX_data_active_object(C);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2015-01-12 14:21:23 +01:00
|
|
|
/* scope update can be expensive, don't update during paint modes */
|
2019-03-26 21:16:47 +11:00
|
|
|
if (sima->mode == SI_MODE_PAINT) {
|
2015-01-12 14:21:23 +01:00
|
|
|
return;
|
2019-03-26 21:16:47 +11:00
|
|
|
}
|
|
|
|
|
if (ob && ((ob->mode & (OB_MODE_TEXTURE_PAINT | OB_MODE_EDIT)) != 0)) {
|
2015-01-12 14:21:23 +01:00
|
|
|
return;
|
2019-03-26 21:16:47 +11:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-03-10 11:29:45 +05:00
|
|
|
/* We also don't update scopes of render result during render. */
|
|
|
|
|
if (G.is_rendering) {
|
|
|
|
|
const Image *image = sima->image;
|
|
|
|
|
if (image != NULL && (image->type == IMA_TYPE_R_RESULT || image->type == IMA_TYPE_COMPOSITE)) {
|
|
|
|
|
return;
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
2016-03-10 11:29:45 +05:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-08-07 03:21:55 +10:00
|
|
|
BKE_scopes_update(&sima->scopes,
|
|
|
|
|
ibuf,
|
|
|
|
|
use_view_settings ? &scene->view_settings : NULL,
|
|
|
|
|
&scene->display_settings);
|
2015-01-12 14:21:23 +01:00
|
|
|
}
|
|
|
|
|
|
2014-01-28 03:52:21 +11:00
|
|
|
bool ED_space_image_show_render(SpaceImage *sima)
|
2012-07-25 10:15:24 +00:00
|
|
|
{
|
|
|
|
|
return (sima->image && ELEM(sima->image->type, IMA_TYPE_R_RESULT, IMA_TYPE_COMPOSITE));
|
|
|
|
|
}
|
|
|
|
|
|
2014-01-28 03:52:21 +11:00
|
|
|
bool ED_space_image_show_paint(SpaceImage *sima)
|
2012-07-25 10:15:24 +00:00
|
|
|
{
|
2019-03-26 21:16:47 +11:00
|
|
|
if (ED_space_image_show_render(sima)) {
|
2014-07-21 12:02:05 +02:00
|
|
|
return false;
|
2019-03-26 21:16:47 +11:00
|
|
|
}
|
2012-07-25 10:15:24 +00:00
|
|
|
|
2012-07-25 11:25:10 +00:00
|
|
|
return (sima->mode == SI_MODE_PAINT);
|
2012-07-25 10:15:24 +00:00
|
|
|
}
|
|
|
|
|
|
2014-01-28 03:52:21 +11:00
|
|
|
bool ED_space_image_show_uvedit(SpaceImage *sima, Object *obedit)
|
2012-07-25 10:15:24 +00:00
|
|
|
{
|
2018-10-19 20:10:14 +11:00
|
|
|
if (sima) {
|
|
|
|
|
if (ED_space_image_show_render(sima)) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
if (sima->mode != SI_MODE_UV) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
2012-07-25 10:15:24 +00:00
|
|
|
|
|
|
|
|
if (obedit && obedit->type == OB_MESH) {
|
2013-04-16 05:59:48 +00:00
|
|
|
struct BMEditMesh *em = BKE_editmesh_from_object(obedit);
|
2014-07-21 12:02:05 +02:00
|
|
|
bool ret;
|
2012-07-25 10:15:24 +00:00
|
|
|
|
2017-05-25 15:11:00 +10:00
|
|
|
ret = EDBM_uv_check(em);
|
2012-07-25 10:15:24 +00:00
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
2014-07-21 12:02:05 +02:00
|
|
|
return false;
|
2012-07-25 10:15:24 +00:00
|
|
|
}
|
|
|
|
|
|
2012-07-25 10:39:54 +00:00
|
|
|
/* matches clip function */
|
2020-09-02 12:44:37 +10:00
|
|
|
bool ED_space_image_check_show_maskedit(SpaceImage *sima, Object *obedit)
|
2012-07-25 10:39:54 +00:00
|
|
|
{
|
2012-07-31 14:16:27 +00:00
|
|
|
/* check editmode - this is reserved for UV editing */
|
2020-09-02 12:44:37 +10:00
|
|
|
if (obedit && ED_space_image_show_uvedit(sima, obedit)) {
|
2014-04-01 11:34:00 +11:00
|
|
|
return false;
|
2012-07-31 14:16:27 +00:00
|
|
|
}
|
|
|
|
|
|
2012-07-25 12:15:22 +00:00
|
|
|
return (sima->mode == SI_MODE_MASK);
|
2012-07-25 10:39:54 +00:00
|
|
|
}
|
|
|
|
|
|
2018-07-02 11:47:00 +02:00
|
|
|
bool ED_space_image_maskedit_poll(bContext *C)
|
2012-07-25 10:39:54 +00:00
|
|
|
{
|
|
|
|
|
SpaceImage *sima = CTX_wm_space_image(C);
|
2018-04-05 18:20:27 +02:00
|
|
|
|
2012-08-03 22:33:45 +00:00
|
|
|
if (sima) {
|
2017-11-23 13:51:49 -02:00
|
|
|
ViewLayer *view_layer = CTX_data_view_layer(C);
|
2020-09-02 12:44:37 +10:00
|
|
|
Object *obedit = OBEDIT_FROM_VIEW_LAYER(view_layer);
|
|
|
|
|
return ED_space_image_check_show_maskedit(sima, obedit);
|
2012-07-25 10:39:54 +00:00
|
|
|
}
|
|
|
|
|
|
2014-04-01 11:34:00 +11:00
|
|
|
return false;
|
2012-07-25 10:39:54 +00:00
|
|
|
}
|
|
|
|
|
|
2014-07-21 12:02:05 +02:00
|
|
|
bool ED_space_image_paint_curve(const bContext *C)
|
|
|
|
|
{
|
|
|
|
|
SpaceImage *sima = CTX_wm_space_image(C);
|
|
|
|
|
|
|
|
|
|
if (sima && sima->mode == SI_MODE_PAINT) {
|
|
|
|
|
Brush *br = CTX_data_tool_settings(C)->imapaint.paint.brush;
|
|
|
|
|
|
2019-03-26 21:16:47 +11:00
|
|
|
if (br && (br->flag & BRUSH_CURVE)) {
|
2014-07-21 12:02:05 +02:00
|
|
|
return true;
|
2019-03-26 21:16:47 +11:00
|
|
|
}
|
2014-07-21 12:02:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2018-07-02 11:47:00 +02:00
|
|
|
bool ED_space_image_maskedit_mask_poll(bContext *C)
|
2012-07-25 10:39:54 +00:00
|
|
|
{
|
|
|
|
|
if (ED_space_image_maskedit_poll(C)) {
|
2012-08-03 22:33:45 +00:00
|
|
|
SpaceImage *sima = CTX_wm_space_image(C);
|
|
|
|
|
return sima->mask_info.mask != NULL;
|
2012-07-25 10:39:54 +00:00
|
|
|
}
|
|
|
|
|
|
2014-04-01 11:34:00 +11:00
|
|
|
return false;
|
2012-07-25 10:39:54 +00:00
|
|
|
}
|
2019-10-01 20:19:44 +10:00
|
|
|
|
|
|
|
|
bool ED_space_image_cursor_poll(bContext *C)
|
|
|
|
|
{
|
|
|
|
|
return ED_operator_uvedit_space_image(C) || ED_space_image_maskedit_poll(C) ||
|
|
|
|
|
ED_space_image_paint_curve(C);
|
|
|
|
|
}
|