[Bf-blender-cvs] [5c62468e4b3] temp-udim-images: Support UDIMs in Image Space operators
Lukas Stockner
noreply at git.blender.org
Mon Jun 11 09:41:12 CEST 2018
Commit: 5c62468e4b393218a915ebc317138e09ad2d0e71
Author: Lukas Stockner
Date: Sun Jun 10 23:23:12 2018 +0200
Branches: temp-udim-images
https://developer.blender.org/rB5c62468e4b393218a915ebc317138e09ad2d0e71
Support UDIMs in Image Space operators
===================================================================
M source/blender/editors/include/ED_image.h
M source/blender/editors/space_image/image_draw.c
M source/blender/editors/space_image/image_edit.c
M source/blender/editors/space_image/image_ops.c
M source/blender/editors/space_image/space_image.c
M source/blender/makesdna/DNA_color_types.h
M source/blender/makesrna/intern/rna_space.c
===================================================================
diff --git a/source/blender/editors/include/ED_image.h b/source/blender/editors/include/ED_image.h
index ce12c2fcd7a..ae2d416ccc7 100644
--- a/source/blender/editors/include/ED_image.h
+++ b/source/blender/editors/include/ED_image.h
@@ -48,7 +48,7 @@ struct Mask *ED_space_image_get_mask(struct SpaceImage *sima);
void ED_space_image_set_mask(struct bContext *C, struct SpaceImage *sima, struct Mask *mask);
bool ED_space_image_color_sample(struct SpaceImage *sima, struct ARegion *ar, int mval[2], float r_col[3]);
-struct ImBuf *ED_space_image_acquire_buffer(struct SpaceImage *sima, void **r_lock);
+struct ImBuf *ED_space_image_acquire_buffer(struct SpaceImage *sima, void **r_lock, int tile);
void ED_space_image_release_buffer(struct SpaceImage *sima, struct ImBuf *ibuf, void *lock);
bool ED_space_image_has_buffer(struct SpaceImage *sima);
diff --git a/source/blender/editors/space_image/image_draw.c b/source/blender/editors/space_image/image_draw.c
index bd008e4b392..28dc108a4d8 100644
--- a/source/blender/editors/space_image/image_draw.c
+++ b/source/blender/editors/space_image/image_draw.c
@@ -585,9 +585,13 @@ void draw_image_sample_line(SpaceImage *sima)
immUniformArray4fv("colors", (float *)(float[][4]){{1.0f, 1.0f, 1.0f, 1.0f}, {0.0f, 0.0f, 0.0f, 1.0f}}, 2);
immUniform1f("dash_width", 2.0f);
+ float co[2][2];
+ add_v2_v2v2(co[0], hist->co[0], hist->draw_offset);
+ add_v2_v2v2(co[1], hist->co[1], hist->draw_offset);
+
immBegin(GWN_PRIM_LINES, 2);
- immVertex2fv(shdr_dashed_pos, hist->co[0]);
- immVertex2fv(shdr_dashed_pos, hist->co[1]);
+ immVertex2fv(shdr_dashed_pos, co[0]);
+ immVertex2fv(shdr_dashed_pos, co[1]);
immEnd();
immUnbindProgram();
@@ -766,7 +770,7 @@ void draw_image_main(const bContext *C, ARegion *ar)
BKE_image_multiview_index(ima, &sima->iuser);
}
- ibuf = ED_space_image_acquire_buffer(sima, &lock);
+ ibuf = ED_space_image_acquire_buffer(sima, &lock, 0);
/* draw the image or grid */
if (ibuf == NULL) {
@@ -795,9 +799,7 @@ void draw_image_main(const bContext *C, ARegion *ar)
if (ima && ima->source == IMA_SRC_UDIM) {
for (int t = 1; t < ima->num_tiles; t++) {
- sima->iuser.tile = t;
-
- ibuf = ED_space_image_acquire_buffer(sima, &lock);
+ ibuf = ED_space_image_acquire_buffer(sima, &lock, t);
if (ibuf) {
int x_pos = t%10;
int y_pos = t/10;
@@ -805,7 +807,6 @@ void draw_image_main(const bContext *C, ARegion *ar)
}
ED_space_image_release_buffer(sima, ibuf, lock);
}
- sima->iuser.tile = 0;
draw_image_udim_grid(ar, sima, zoomx, zoomy, false);
}
diff --git a/source/blender/editors/space_image/image_edit.c b/source/blender/editors/space_image/image_edit.c
index 0911bea3be4..1d4397361be 100644
--- a/source/blender/editors/space_image/image_edit.c
+++ b/source/blender/editors/space_image/image_edit.c
@@ -104,7 +104,7 @@ void ED_space_image_set_mask(bContext *C, SpaceImage *sima, Mask *mask)
}
}
-ImBuf *ED_space_image_acquire_buffer(SpaceImage *sima, void **r_lock)
+ImBuf *ED_space_image_acquire_buffer(SpaceImage *sima, void **r_lock, int tile)
{
ImBuf *ibuf;
@@ -114,7 +114,9 @@ ImBuf *ED_space_image_acquire_buffer(SpaceImage *sima, void **r_lock)
return BIF_render_spare_imbuf();
else
#endif
+ sima->iuser.tile = tile;
ibuf = BKE_image_acquire_ibuf(sima->image, &sima->iuser, r_lock);
+ sima->iuser.tile = 0;
if (ibuf) {
if (ibuf->rect || ibuf->rect_float)
@@ -141,7 +143,7 @@ bool ED_space_image_has_buffer(SpaceImage *sima)
void *lock;
bool has_buffer;
- ibuf = ED_space_image_acquire_buffer(sima, &lock);
+ ibuf = ED_space_image_acquire_buffer(sima, &lock, 0);
has_buffer = (ibuf != NULL);
ED_space_image_release_buffer(sima, ibuf, lock);
@@ -154,7 +156,8 @@ void ED_space_image_get_size(SpaceImage *sima, int *width, int *height)
ImBuf *ibuf;
void *lock;
- ibuf = ED_space_image_acquire_buffer(sima, &lock);
+ /* TODO(lukas): Support UDIMs with different sizes */
+ ibuf = ED_space_image_acquire_buffer(sima, &lock, 0);
if (ibuf && ibuf->x > 0 && ibuf->y > 0) {
*width = ibuf->x;
diff --git a/source/blender/editors/space_image/image_ops.c b/source/blender/editors/space_image/image_ops.c
index e1a4dcfe7ab..735d8f74444 100644
--- a/source/blender/editors/space_image/image_ops.c
+++ b/source/blender/editors/space_image/image_ops.c
@@ -226,7 +226,8 @@ static int space_image_file_exists_poll(bContext *C)
bool ret = false;
char name[FILE_MAX];
- ibuf = ED_space_image_acquire_buffer(sima, &lock);
+ /* TODO(lukas): Saving UDIMs */
+ ibuf = ED_space_image_acquire_buffer(sima, &lock, 0);
if (ibuf) {
BLI_strncpy(name, ibuf->name, FILE_MAX);
BLI_path_abs(name, BKE_main_blendfile_path(bmain));
@@ -1695,7 +1696,8 @@ static int save_image_options_init(Main *bmain, SaveImageOptions *simopts, Space
const bool guess_path, const bool save_as_render)
{
void *lock;
- ImBuf *ibuf = ED_space_image_acquire_buffer(sima, &lock);
+ /* TODO(lukas): Saving UDIMs */
+ ImBuf *ibuf = ED_space_image_acquire_buffer(sima, &lock, 0);
if (ibuf) {
Image *ima = sima->image;
@@ -1880,7 +1882,8 @@ static bool save_image_doit(bContext *C, SpaceImage *sima, wmOperator *op, SaveI
{
Image *ima = ED_space_image(sima);
void *lock;
- ImBuf *ibuf = ED_space_image_acquire_buffer(sima, &lock);
+ /* TODO(lukas): Saving UDIMs */
+ ImBuf *ibuf = ED_space_image_acquire_buffer(sima, &lock, 0);
Scene *scene;
RenderResult *rr = NULL;
bool ok = false;
@@ -2979,12 +2982,34 @@ static void image_sample_draw(const bContext *C, ARegion *ar, void *arg_info)
}
}
+static int image_get_position(SpaceImage *sima, ARegion *ar, const int mval[2], float *fx, float *fy)
+{
+ UI_view2d_region_to_view(&ar->v2d, mval[0], mval[1], fx, fy);
+
+ /* If the image has tiles, shift the positions accordingly. */
+
+ Image *image = ED_space_image(sima);
+ if (!image || image->source != IMA_SRC_UDIM) {
+ return 0;
+ }
+
+ /* Determine the tile in which the sample lies. */
+ int ix = (int) *fx, iy = max_ii(0, (int) *fy);
+ CLAMP(ix, 0, 9);
+
+ *fx -= ix;
+ *fy -= iy;
+ return 10*iy + ix;
+}
+
/* Returns color in linear space, matching ED_space_node_color_sample(). */
bool ED_space_image_color_sample(SpaceImage *sima, ARegion *ar, int mval[2], float r_col[3])
{
- void *lock;
- ImBuf *ibuf = ED_space_image_acquire_buffer(sima, &lock);
float fx, fy;
+ int tile = image_get_position(sima, ar, mval, &fx, &fy);
+
+ void *lock;
+ ImBuf *ibuf = ED_space_image_acquire_buffer(sima, &lock, tile);
bool ret = false;
if (ibuf == NULL) {
@@ -2992,8 +3017,6 @@ bool ED_space_image_color_sample(SpaceImage *sima, ARegion *ar, int mval[2], flo
return false;
}
- UI_view2d_region_to_view(&ar->v2d, mval[0], mval[1], &fx, &fy);
-
if (fx >= 0.0f && fy >= 0.0f && fx < 1.0f && fy < 1.0f) {
const float *fp;
unsigned char *cp;
@@ -3023,10 +3046,14 @@ static void image_sample_apply(bContext *C, wmOperator *op, const wmEvent *event
{
SpaceImage *sima = CTX_wm_space_image(C);
ARegion *ar = CTX_wm_region(C);
+ Image *image = ED_space_image(sima);
+
+ float fx, fy;
+ int tile = image_get_position(sima, ar, event->mval, &fx, &fy);
+
void *lock;
- ImBuf *ibuf = ED_space_image_acquire_buffer(sima, &lock);
+ ImBuf *ibuf = ED_space_image_acquire_buffer(sima, &lock, tile);
ImageSampleInfo *info = op->customdata;
- float fx, fy;
Scene *scene = CTX_data_scene(C);
CurveMapping *curve_mapping = scene->view_settings.curve_mapping;
@@ -3036,13 +3063,10 @@ static void image_sample_apply(bContext *C, wmOperator *op, const wmEvent *event
return;
}
- UI_view2d_region_to_view(&ar->v2d, event->mval[0], event->mval[1], &fx, &fy);
-
if (fx >= 0.0f && fy >= 0.0f && fx < 1.0f && fy < 1.0f) {
const float *fp;
unsigned char *cp;
int x = (int)(fx * ibuf->x), y = (int)(fy * ibuf->y);
- Image *image = ED_space_image(sima);
CLAMP(x, 0, ibuf->x - 1);
CLAMP(y, 0, ibuf->y - 1);
@@ -3250,12 +3274,29 @@ static int image_sample_line_exec(bContext *C, wmOperator *op)
int x_end = RNA_int_get(op->ptr, "xend");
int y_end = RNA_int_get(op->ptr, "yend");
+ float x1f, y1f, x2f, y2f;
+ UI_view2d_region_to_view(&ar->v2d, x_start, y_start, &x1f, &y1f);
+ UI_view2d_region_to_view(&ar->v2d, x_end, y_end, &x2f, &y2f);
+
+ /* If the image has tiles, shift the positions accordingly. */
+ Image *image = ED_space_image(sima);
+ int tile = 0, ix = 0, iy = 0;
+ if (image && image->source == IMA_SRC_UDIM) {
+ ix = (int) x1f;
+ iy = (int) y1f;
+ CLAMP(ix, 0, 9);
+
+ x1f -= ix;
+ x2f -= ix;
+ y1f -= iy;
+ y2f -= iy;
+ tile = 10*iy + ix;
+ }
+
void *lock;
- ImBuf *ibuf = ED_space_image_acquire_buffer(sima, &lock);
+ ImBuf *ibuf = ED_space_image_acquire_buffer(sima, &lock, tile);
Histogram *hist = &sima->sample_line_hist;
- float x1f, y1f, x2f, y2f;
-
if (ibuf == NULL) {
ED_space_image_release_buffer(sima, ibuf, lock);
return OPERATOR_CANCELLED;
@@ -3266,13 +3307,12 @@ static int image_sample_line_exec(bContext *C, wmOperator *op)
return OPERATOR_CANCELLED;
}
- UI_view2d_region_to_view(&ar->v2d, x_start, y_start, &x1f, &y1f);
- UI_view2d_region_to_view(&ar->v2d, x_end, y_end, &x2f, &y2f);
-
hist->co[0][0] = x1f;
hist->co[0][1] = y1f;
hist->co[1][0] = x2f;
hist->co[1][1] = y2f;
+ hist->draw_offset[0] = ix;
+ hist->draw_offset[1] = iy;
/* enable line drawing */
hist->flag |= HISTO_FLAG_SAMPLELINE;
diff --git a/source/blender/editors/space_image/space_image.c b/source/blender/editors/space_image/space_image.c
index c143ebbcd67..5450f305a87 100644
--- a/source/blender/editors/space_image/space_image.c
+++ b/source/blender/editors/space_image/space_image.c
@@ -926,7 +926,8 @@ static void image_tools_region_draw(const bContext *C, ARegion *ar)
SpaceImage *sima = CTX_wm_space_image(C);
Scene *scene = CTX_data_scene(C);
void *lock;
- ImBuf *ibuf = ED_space_image_acquire_buffer(sima, &lock);
+ /* TODO(lukas): Support tiles in scopes? */
+ ImBuf *ibuf = ED_space_image_acquire_buffer(sima, &lock, 0);
/* XXX performance regression if name of scopes category changes! */
PanelCategoryStack *category = UI_panel_category_active_find(ar, "Scopes");
diff --git a/source/blender/m
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list