Blender  V3.3
paint_image.cc
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later
2  * Copyright 2001-2002 NaN Holding BV. All rights reserved. */
3 
9 #include <cfloat>
10 #include <cmath>
11 #include <cstdio>
12 #include <cstring>
13 
14 #include "MEM_guardedalloc.h"
15 
16 #include "BLI_blenlib.h"
17 #include "BLI_math.h"
18 #include "BLI_utildefines.h"
19 
20 #include "BLT_translation.h"
21 
22 #include "IMB_imbuf.h"
23 #include "IMB_imbuf_types.h"
24 
25 #include "DNA_brush_types.h"
26 #include "DNA_material_types.h"
27 #include "DNA_mesh_types.h"
28 #include "DNA_node_types.h"
29 #include "DNA_object_types.h"
30 
31 #include "BKE_brush.h"
32 #include "BKE_colorband.h"
33 #include "BKE_context.h"
34 #include "BKE_image.h"
35 #include "BKE_main.h"
36 #include "BKE_material.h"
37 #include "BKE_mesh.h"
38 #include "BKE_node.h"
39 #include "BKE_paint.h"
40 #include "BKE_undo_system.h"
41 
42 #include "NOD_texture.h"
43 
44 #include "DEG_depsgraph.h"
45 
46 #include "UI_interface.h"
47 #include "UI_view2d.h"
48 
49 #include "ED_image.h"
50 #include "ED_object.h"
51 #include "ED_paint.h"
52 #include "ED_screen.h"
53 #include "ED_view3d.h"
54 
55 #include "WM_api.h"
56 #include "WM_message.h"
57 #include "WM_toolsystem.h"
58 #include "WM_types.h"
59 
60 #include "RNA_access.h"
61 #include "RNA_define.h"
62 
63 #include "GPU_immediate.h"
64 #include "GPU_state.h"
65 
66 #include "IMB_colormanagement.h"
67 
68 #include "paint_intern.h"
69 
70 extern "C" {
71 
78 
80 {
81  return &imapaintpartial;
82 }
83 
85 {
86  imapaintpartial = *ippr;
87 }
88 
89 /* Image paint Partial Redraw & Dirty Region. */
90 
92 {
94 }
95 
97  ImBuf *ibuf, int x, int y, int w, int h, int *tx, int *ty, int *tw, int *th)
98 {
99  int srcx = 0, srcy = 0;
100 
101  IMB_rectclip(ibuf, nullptr, &x, &y, &srcx, &srcy, &w, &h);
102 
103  *tw = ((x + w - 1) >> ED_IMAGE_UNDO_TILE_BITS);
104  *th = ((y + h - 1) >> ED_IMAGE_UNDO_TILE_BITS);
105  *tx = (x >> ED_IMAGE_UNDO_TILE_BITS);
106  *ty = (y >> ED_IMAGE_UNDO_TILE_BITS);
107 }
108 
110  Image *ima, ImBuf *ibuf, ImageUser *iuser, int x, int y, int w, int h, bool find_old)
111 {
112  ImBuf *tmpibuf = nullptr;
113  int tilex, tiley, tilew, tileh, tx, ty;
114  int srcx = 0, srcy = 0;
115 
116  IMB_rectclip(ibuf, nullptr, &x, &y, &srcx, &srcy, &w, &h);
117 
118  if (w == 0 || h == 0) {
119  return;
120  }
121 
122  rcti rect_to_merge;
123  BLI_rcti_init(&rect_to_merge, x, x + w, y, y + h);
125 
126  imapaint_region_tiles(ibuf, x, y, w, h, &tilex, &tiley, &tilew, &tileh);
127 
129 
130  for (ty = tiley; ty <= tileh; ty++) {
131  for (tx = tilex; tx <= tilew; tx++) {
133  undo_tiles, ima, ibuf, &tmpibuf, iuser, tx, ty, nullptr, nullptr, false, find_old);
134  }
135  }
136 
137  BKE_image_mark_dirty(ima, ibuf);
138 
139  if (tmpibuf) {
140  IMB_freeImBuf(tmpibuf);
141  }
142 }
143 
145  SpaceImage *sima, Image *image, ImBuf *ibuf, ImageUser *iuser, short texpaint)
146 {
148  return;
149  }
150 
151  if (ibuf->mipmap[0]) {
152  ibuf->userflags |= IB_MIPMAP_INVALID;
153  }
154 
160 
161  /* TODO: should set_tpage create ->rect? */
162  if (texpaint || (sima && sima->lock)) {
165  /* Testing with partial update in uv editor too */
168  }
169 }
170 
172 {
173  int i, j;
174  BlurKernel *kernel = MEM_new<BlurKernel>("BlurKernel");
175 
176  float radius;
177  int side;
178  eBlurKernelType type = static_cast<eBlurKernelType>(br->blur_mode);
179 
180  if (proj) {
181  radius = 0.5f;
182 
183  side = kernel->side = 2;
184  kernel->side_squared = kernel->side * kernel->side;
185  kernel->wdata = static_cast<float *>(
186  MEM_mallocN(sizeof(float) * kernel->side_squared, "blur kernel data"));
187  kernel->pixel_len = radius;
188  }
189  else {
190  if (br->blur_kernel_radius <= 0) {
191  br->blur_kernel_radius = 1;
192  }
193 
194  radius = br->blur_kernel_radius;
195 
196  side = kernel->side = radius * 2 + 1;
197  kernel->side_squared = kernel->side * kernel->side;
198  kernel->wdata = static_cast<float *>(
199  MEM_mallocN(sizeof(float) * kernel->side_squared, "blur kernel data"));
200  kernel->pixel_len = br->blur_kernel_radius;
201  }
202 
203  switch (type) {
204  case KERNEL_BOX:
205  for (i = 0; i < kernel->side_squared; i++) {
206  kernel->wdata[i] = 1.0;
207  }
208  break;
209 
210  case KERNEL_GAUSSIAN: {
211  /* at 3.0 standard deviations distance, kernel is about zero */
212  float standard_dev = radius / 3.0f;
213 
214  /* make the necessary adjustment to the value for use in the normal distribution formula */
215  standard_dev = -standard_dev * standard_dev * 2;
216 
217  for (i = 0; i < side; i++) {
218  for (j = 0; j < side; j++) {
219  float idist = radius - i;
220  float jdist = radius - j;
221  float value = exp((idist * idist + jdist * jdist) / standard_dev);
222 
223  kernel->wdata[i + j * side] = value;
224  }
225  }
226 
227  break;
228  }
229 
230  default:
231  printf("unidentified kernel type, aborting\n");
233  MEM_delete(kernel);
234  return nullptr;
235  }
236 
237  return kernel;
238 }
239 
241 {
242  if (kernel->wdata) {
243  MEM_freeN(kernel->wdata);
244  }
245 }
246 
247 /************************ image paint poll ************************/
248 
250 {
252  ToolSettings *settings = scene->toolsettings;
253 
254  return BKE_paint_brush(&settings->imapaint.paint);
255 }
256 
257 static bool image_paint_poll_ex(bContext *C, bool check_tool)
258 {
259  Object *obact;
260 
261  if (!image_paint_brush(C)) {
262  return false;
263  }
264 
265  obact = CTX_data_active_object(C);
266  if ((obact && obact->mode & OB_MODE_TEXTURE_PAINT) && CTX_wm_region_view3d(C)) {
267  if (!check_tool || WM_toolsystem_active_tool_is_brush(C)) {
268  return true;
269  }
270  }
271  else {
273 
274  if (sima) {
275  if (sima->image != nullptr &&
276  (ID_IS_LINKED(sima->image) || ID_IS_OVERRIDE_LIBRARY(sima->image))) {
277  return false;
278  }
279  if (sima->mode == SI_MODE_PAINT) {
280  const ARegion *region = CTX_wm_region(C);
281  if (region->regiontype == RGN_TYPE_WINDOW) {
282  return true;
283  }
284  }
285  }
286  }
287 
288  return false;
289 }
290 
292 {
293  return image_paint_poll_ex(C, true);
294 }
295 
297 {
298  return image_paint_poll_ex(C, false);
299 }
300 
302 {
303  Brush *brush = image_paint_brush(C);
304 
306  if (brush && (brush->imagepaint_tool == PAINT_TOOL_CLONE)) {
307  if (brush->clone.image) {
308  return true;
309  }
310  }
311  }
312 
313  return false;
314 }
315 
316 /************************ paint operator ************************/
318 {
319  return ((brush->flag & BRUSH_AIRBRUSH) || (brush->flag & BRUSH_DRAG_DOT) ||
320  (brush->flag & BRUSH_ANCHORED) ||
322  (brush->imagepaint_tool == PAINT_TOOL_FILL) ||
323  (brush->flag & BRUSH_USE_GRADIENT) ||
324  (brush->mtex.tex && !ELEM(brush->mtex.brush_map_mode,
327  MTEX_MAP_MODE_3D)) ?
328  false :
329  true);
330 }
331 
333  struct Brush *br,
334  bool color_correction,
335  bool invert,
336  float distance,
337  float pressure,
338  float color[3],
339  struct ColorManagedDisplay *display)
340 {
341  if (invert) {
343  }
344  else {
345  if (br->flag & BRUSH_USE_GRADIENT) {
346  float color_gr[4];
347  switch (br->gradient_stroke_mode) {
349  BKE_colorband_evaluate(br->gradient, pressure, color_gr);
350  break;
352  float coord = fmod(distance / br->gradient_spacing, 1.0);
353  BKE_colorband_evaluate(br->gradient, coord, color_gr);
354  break;
355  }
358  break;
359  }
360  }
361  /* Gradient / Color-band colors are not considered #PROP_COLOR_GAMMA.
362  * Brush colors are expected to be in sRGB though. */
364  }
365  else {
367  }
368  }
369  if (color_correction) {
371  }
372 }
373 
375 {
376  /* init mtex nodes */
377  if (brush) {
378  MTex *mtex = &brush->mtex;
379  if (mtex->tex && mtex->tex->nodetree) {
380  /* has internal flag to detect it only does it once */
382  }
383  mtex = &brush->mask_mtex;
384  if (mtex->tex && mtex->tex->nodetree) {
386  }
387  }
388 }
389 
391 {
392  if (brush) {
393  MTex *mtex = &brush->mtex;
394  if (mtex->tex && mtex->tex->nodetree) {
396  }
397  mtex = &brush->mask_mtex;
398  if (mtex->tex && mtex->tex->nodetree) {
400  }
401  }
402 }
403 
404 bool get_imapaint_zoom(bContext *C, float *zoomx, float *zoomy)
405 {
407  if (area && area->spacetype == SPACE_IMAGE) {
408  SpaceImage *sima = static_cast<SpaceImage *>(area->spacedata.first);
409  if (sima->mode == SI_MODE_PAINT) {
410  ARegion *region = CTX_wm_region(C);
411  ED_space_image_get_zoom(sima, region, zoomx, zoomy);
412  return true;
413  }
414  }
415 
416  *zoomx = *zoomy = 1;
417 
418  return false;
419 }
420 
421 /************************ cursor drawing *******************************/
422 
423 static void toggle_paint_cursor(Scene *scene, bool enable)
424 {
425  ToolSettings *settings = scene->toolsettings;
426  Paint *p = &settings->imapaint.paint;
427 
428  if (p->paint_cursor && !enable) {
429  WM_paint_cursor_end(static_cast<wmPaintCursor *>(p->paint_cursor));
430  p->paint_cursor = nullptr;
432  }
433  else if (enable) {
435  }
436 }
437 
439 {
440  ToolSettings *settings = scene->toolsettings;
441  ImagePaintSettings *imapaint = &settings->imapaint;
442  bool enabled = false;
443 
444  LISTBASE_FOREACH (wmWindow *, win, &wm->windows) {
445  bScreen *screen = WM_window_get_active_screen(win);
446 
447  LISTBASE_FOREACH (ScrArea *, area, &screen->areabase) {
448  if (area->spacetype == SPACE_IMAGE) {
449  if (((SpaceImage *)area->spacedata.first)->mode == SI_MODE_PAINT) {
450  enabled = true;
451  }
452  }
453  }
454  }
455 
456  if (enabled) {
458 
460  }
461  else {
463  }
464 }
465 
466 /************************ grab clone operator ************************/
467 
468 struct GrabClone {
469  float startoffset[2];
471 };
472 
474 {
475  Brush *brush = image_paint_brush(C);
476  float delta[2];
477 
478  RNA_float_get_array(op->ptr, "delta", delta);
479  add_v2_v2(brush->clone.offset, delta);
481 }
482 
484 {
485  grab_clone_apply(C, op);
486 
487  return OPERATOR_FINISHED;
488 }
489 
490 static int grab_clone_invoke(bContext *C, wmOperator *op, const wmEvent *event)
491 {
492  Brush *brush = image_paint_brush(C);
493  GrabClone *cmv;
494 
495  cmv = MEM_new<GrabClone>("GrabClone");
496  copy_v2_v2(cmv->startoffset, brush->clone.offset);
497  cmv->startx = event->xy[0];
498  cmv->starty = event->xy[1];
499  op->customdata = cmv;
500 
502 
503  return OPERATOR_RUNNING_MODAL;
504 }
505 
506 static int grab_clone_modal(bContext *C, wmOperator *op, const wmEvent *event)
507 {
508  Brush *brush = image_paint_brush(C);
509  ARegion *region = CTX_wm_region(C);
510  GrabClone *cmv = static_cast<GrabClone *>(op->customdata);
511  float startfx, startfy, fx, fy, delta[2];
512  int xmin = region->winrct.xmin, ymin = region->winrct.ymin;
513 
514  switch (event->type) {
515  case LEFTMOUSE:
516  case MIDDLEMOUSE:
517  case RIGHTMOUSE: /* XXX hardcoded */
518  MEM_freeN(op->customdata);
519  return OPERATOR_FINISHED;
520  case MOUSEMOVE:
521  /* mouse moved, so move the clone image */
523  &region->v2d, cmv->startx - xmin, cmv->starty - ymin, &startfx, &startfy);
524  UI_view2d_region_to_view(&region->v2d, event->xy[0] - xmin, event->xy[1] - ymin, &fx, &fy);
525 
526  delta[0] = fx - startfx;
527  delta[1] = fy - startfy;
528  RNA_float_set_array(op->ptr, "delta", delta);
529 
530  copy_v2_v2(brush->clone.offset, cmv->startoffset);
531 
532  grab_clone_apply(C, op);
533  break;
534  }
535 
536  return OPERATOR_RUNNING_MODAL;
537 }
538 
540 {
541  GrabClone *cmv = static_cast<GrabClone *>(op->customdata);
542  MEM_delete(cmv);
543 }
544 
546 {
547  /* identifiers */
548  ot->name = "Grab Clone";
549  ot->idname = "PAINT_OT_grab_clone";
550  ot->description = "Move the clone source image";
551 
552  /* api callbacks */
558 
559  /* flags */
561 
562  /* properties */
564  "delta",
565  2,
566  nullptr,
567  -FLT_MAX,
568  FLT_MAX,
569  "Delta",
570  "Delta offset of clone image in 0.0 to 1.0 coordinates",
571  -1.0f,
572  1.0f);
573 }
574 
575 /******************** sample color operator ********************/
579  float initcolor[3];
581 };
582 
584 {
585  char msg[UI_MAX_DRAW_STR];
587 
588  if (area) {
589  BLI_snprintf(msg,
590  sizeof(msg),
591  TIP_("Sample color for %s"),
592  !data->sample_palette ?
593  TIP_("Brush. Use Left Click to sample for palette instead") :
594  TIP_("Palette. Use Left Click to sample more colors"));
596  }
597 }
598 
600 {
602  Brush *brush = BKE_paint_brush(paint);
604  ARegion *region = CTX_wm_region(C);
605  wmWindow *win = CTX_wm_window(C);
606  const bool show_cursor = ((paint->flags & PAINT_SHOW_BRUSH) != 0);
607  int location[2];
608  paint->flags &= ~PAINT_SHOW_BRUSH;
609 
610  /* force redraw without cursor */
611  WM_paint_cursor_tag_redraw(win, region);
613 
614  RNA_int_get_array(op->ptr, "location", location);
615  const bool use_palette = RNA_boolean_get(op->ptr, "palette");
616  const bool use_sample_texture = (mode == PAINT_MODE_TEXTURE_3D) &&
617  !RNA_boolean_get(op->ptr, "merged");
618 
619  paint_sample_color(C, region, location[0], location[1], use_sample_texture, use_palette);
620 
621  if (show_cursor) {
622  paint->flags |= PAINT_SHOW_BRUSH;
623  }
624 
626 
627  return OPERATOR_FINISHED;
628 }
629 
630 static int sample_color_invoke(bContext *C, wmOperator *op, const wmEvent *event)
631 {
634  Brush *brush = BKE_paint_brush(paint);
635  SampleColorData *data = MEM_new<SampleColorData>("sample color custom data");
636  ARegion *region = CTX_wm_region(C);
637  wmWindow *win = CTX_wm_window(C);
638 
639  data->launch_event = WM_userdef_event_type_from_keymap_type(event->type);
640  data->show_cursor = ((paint->flags & PAINT_SHOW_BRUSH) != 0);
641  copy_v3_v3(data->initcolor, BKE_brush_color_get(scene, brush));
642  data->sample_palette = false;
643  op->customdata = data;
644  paint->flags &= ~PAINT_SHOW_BRUSH;
645 
647 
649 
650  /* force redraw without cursor */
651  WM_paint_cursor_tag_redraw(win, region);
653 
654  RNA_int_set_array(op->ptr, "location", event->mval);
655 
657  const bool use_sample_texture = (mode == PAINT_MODE_TEXTURE_3D) &&
658  !RNA_boolean_get(op->ptr, "merged");
659 
660  paint_sample_color(C, region, event->mval[0], event->mval[1], use_sample_texture, false);
662 
664 
665  return OPERATOR_RUNNING_MODAL;
666 }
667 
668 static int sample_color_modal(bContext *C, wmOperator *op, const wmEvent *event)
669 {
671  SampleColorData *data = static_cast<SampleColorData *>(op->customdata);
673  Brush *brush = BKE_paint_brush(paint);
674 
675  if ((event->type == data->launch_event) && (event->val == KM_RELEASE)) {
676  if (data->show_cursor) {
677  paint->flags |= PAINT_SHOW_BRUSH;
678  }
679 
680  if (data->sample_palette) {
681  BKE_brush_color_set(scene, brush, data->initcolor);
682  RNA_boolean_set(op->ptr, "palette", true);
683  }
685  MEM_delete(data);
686  ED_workspace_status_text(C, nullptr);
687 
688  return OPERATOR_FINISHED;
689  }
690 
692  const bool use_sample_texture = (mode == PAINT_MODE_TEXTURE_3D) &&
693  !RNA_boolean_get(op->ptr, "merged");
694 
695  switch (event->type) {
696  case MOUSEMOVE: {
697  ARegion *region = CTX_wm_region(C);
698  RNA_int_set_array(op->ptr, "location", event->mval);
699  paint_sample_color(C, region, event->mval[0], event->mval[1], use_sample_texture, false);
701  break;
702  }
703 
704  case LEFTMOUSE:
705  if (event->val == KM_PRESS) {
706  ARegion *region = CTX_wm_region(C);
707  RNA_int_set_array(op->ptr, "location", event->mval);
708  paint_sample_color(C, region, event->mval[0], event->mval[1], use_sample_texture, true);
709  if (!data->sample_palette) {
710  data->sample_palette = true;
712  }
714  }
715  break;
716  }
717 
718  return OPERATOR_RUNNING_MODAL;
719 }
720 
722 {
724 }
725 
727 {
728  /* identifiers */
729  ot->name = "Sample Color";
730  ot->idname = "PAINT_OT_sample_color";
731  ot->description = "Use the mouse to sample a color in the image";
732 
733  /* api callbacks */
738 
739  /* flags */
741 
742  /* properties */
743  PropertyRNA *prop;
744 
745  prop = RNA_def_int_vector(
746  ot->srna, "location", 2, nullptr, 0, INT_MAX, "Location", "", 0, 16384);
748 
749  RNA_def_boolean(ot->srna, "merged", false, "Sample Merged", "Sample the output display color");
750  RNA_def_boolean(ot->srna, "palette", false, "Add to Palette", "");
751 }
752 
753 /******************** texture paint toggle operator ********************/
754 
756 {
757  Image *ima = nullptr;
759 
760  /* This has to stay here to regenerate the texture paint
761  * cache in case we are loading a file */
763 
764  ED_paint_proj_mesh_data_check(scene, ob, nullptr, nullptr, nullptr, nullptr);
765 
766  /* entering paint mode also sets image to editors */
767  if (imapaint->mode == IMAGEPAINT_MODE_MATERIAL) {
768  /* set the current material active paint slot on image editor */
769  Material *ma = BKE_object_material_get(ob, ob->actcol);
770 
771  if (ma && ma->texpaintslot) {
772  ima = ma->texpaintslot[ma->paint_active_slot].ima;
773  }
774  }
775  else if (imapaint->mode == IMAGEPAINT_MODE_IMAGE) {
776  ima = imapaint->canvas;
777  }
778 
779  if (ima) {
780  wmWindowManager *wm = static_cast<wmWindowManager *>(bmain->wm.first);
781  LISTBASE_FOREACH (wmWindow *, win, &wm->windows) {
782  const bScreen *screen = WM_window_get_active_screen(win);
783  LISTBASE_FOREACH (ScrArea *, area, &screen->areabase) {
784  SpaceLink *sl = static_cast<SpaceLink *>(area->spacedata.first);
785  if (sl->spacetype == SPACE_IMAGE) {
786  SpaceImage *sima = (SpaceImage *)sl;
787 
788  if (!sima->pin) {
789  ED_space_image_set(bmain, sima, ima, true);
790  }
791  }
792  }
793  }
794  }
795 
797 
799 
800  BKE_paint_toolslots_brush_validate(bmain, &imapaint->paint);
801 
802  if (U.glreslimit != 0) {
804  }
805  BKE_image_paint_set_mipmap(bmain, false);
806 
807  toggle_paint_cursor(scene, true);
808 
809  Mesh *me = BKE_mesh_from_object(ob);
810  BLI_assert(me != nullptr);
813 }
814 
816 {
817  Main *bmain = CTX_data_main(C);
821 }
822 
824 {
825  ob->mode &= ~OB_MODE_TEXTURE_PAINT;
826 
827  if (U.glreslimit != 0) {
829  }
830  BKE_image_paint_set_mipmap(bmain, true);
831  toggle_paint_cursor(scene, false);
832 
833  Mesh *me = BKE_mesh_from_object(ob);
834  BLI_assert(me != nullptr);
837 }
838 
840 {
841  Main *bmain = CTX_data_main(C);
845 }
846 
848 {
850  if (ob == nullptr || ob->type != OB_MESH) {
851  return false;
852  }
853  if (ob->data == nullptr || ID_IS_LINKED(ob->data) || ID_IS_OVERRIDE_LIBRARY(ob->data)) {
854  return false;
855  }
856 
857  return true;
858 }
859 
861 {
862  struct wmMsgBus *mbus = CTX_wm_message_bus(C);
863  Main *bmain = CTX_data_main(C);
866  const int mode_flag = OB_MODE_TEXTURE_PAINT;
867  const bool is_mode_set = (ob->mode & mode_flag) != 0;
868 
869  if (!is_mode_set) {
870  if (!ED_object_mode_compat_set(C, ob, static_cast<eObjectMode>(mode_flag), op->reports)) {
871  return OPERATOR_CANCELLED;
872  }
873  }
874 
875  if (ob->mode & mode_flag) {
877  }
878  else {
880  }
881 
882  WM_msg_publish_rna_prop(mbus, &ob->id, ob, Object, mode);
883 
885 
886  return OPERATOR_FINISHED;
887 }
888 
890 {
891  /* identifiers */
892  ot->name = "Texture Paint Toggle";
893  ot->idname = "PAINT_OT_texture_paint_toggle";
894  ot->description = "Toggle texture paint mode in 3D view";
895 
896  /* api callbacks */
899 
900  /* flags */
902 }
903 
905 {
908 
910  Brush *br = BKE_paint_brush(paint);
911 
912  if (ups->flag & UNIFIED_PAINT_COLOR) {
913  swap_v3_v3(ups->rgb, ups->secondary_rgb);
914  }
915  else if (br) {
916  swap_v3_v3(br->rgb, br->secondary_rgb);
917  }
918  else {
919  return OPERATOR_CANCELLED;
920  }
921 
923 
924  return OPERATOR_FINISHED;
925 }
926 
928 {
930  Brush *br = image_paint_brush(C);
932  return true;
933  }
934  }
935  else {
937  if (ob != nullptr) {
939  return true;
940  }
941  }
942  }
943  return false;
944 }
945 
947 {
948  /* identifiers */
949  ot->name = "Swap Colors";
950  ot->idname = "PAINT_OT_brush_colors_flip";
951  ot->description = "Swap primary and secondary brush colors";
952 
953  /* api callbacks */
956 
957  /* flags */
959 }
960 
962  float color[3],
963  wmOperator *op,
964  const int mouse[2])
965 {
967 
968  if (sima && sima->image) {
969  Image *ima = sima->image;
970 
972 
973  const float mouse_init[2] = {static_cast<float>(mouse[0]), static_cast<float>(mouse[1])};
974  paint_2d_bucket_fill(C, color, nullptr, mouse_init, nullptr, nullptr);
975 
977 
978  DEG_id_tag_update(&ima->id, 0);
979  }
980 }
981 
983 {
986  return true;
987  }
988  }
989 
990  return false;
991 }
992 
994 {
996 }
997 
999 {
1001 }
1002 
1004 {
1006 }
1007 
1009 {
1011 }
1012 }
const float * BKE_brush_secondary_color_get(const struct Scene *scene, const struct Brush *brush)
Definition: brush.cc:2216
const float * BKE_brush_color_get(const struct Scene *scene, const struct Brush *brush)
Definition: brush.cc:2210
void BKE_brush_color_set(struct Scene *scene, struct Brush *brush, const float color[3])
Definition: brush.cc:2222
bool BKE_colorband_evaluate(const struct ColorBand *coba, float in, float out[4])
struct ScrArea * CTX_wm_area(const bContext *C)
Definition: context.c:738
struct Scene * CTX_data_scene(const bContext *C)
Definition: context.c:1090
struct Object * CTX_data_active_object(const bContext *C)
Definition: context.c:1353
struct wmMsgBus * CTX_wm_message_bus(const bContext *C)
Definition: context.c:770
struct ARegion * CTX_wm_region(const bContext *C)
Definition: context.c:749
struct SpaceImage * CTX_wm_space_image(const bContext *C)
Definition: context.c:824
struct Main * CTX_data_main(const bContext *C)
Definition: context.c:1074
struct RegionView3D * CTX_wm_region_view3d(const bContext *C)
Definition: context.c:793
struct wmWindow * CTX_wm_window(const bContext *C)
Definition: context.c:723
void BKE_image_paint_set_mipmap(struct Main *bmain, bool mipmap)
Definition: image_gpu.cc:866
void BKE_image_mark_dirty(struct Image *image, struct ImBuf *ibuf)
void BKE_image_free_all_gputextures(struct Main *bmain)
Definition: image_gpu.cc:521
void BKE_image_update_gputexture(struct Image *ima, struct ImageUser *iuser, int x, int y, int w, int h)
Definition: image_gpu.cc:838
General operations, lookup, etc. for materials.
struct Material * BKE_object_material_get(struct Object *ob, short act)
Definition: material.c:687
void BKE_texpaint_slots_refresh_object(struct Scene *scene, struct Object *ob)
Definition: material.c:1564
struct Mesh * BKE_mesh_from_object(struct Object *ob)
Definition: mesh.cc:1365
bool BKE_paint_select_elem_test(struct Object *ob)
Definition: paint.c:994
ePaintMode BKE_paintmode_get_active_from_context(const struct bContext *C)
struct Brush * BKE_paint_brush(struct Paint *paint)
Definition: paint.c:607
void BKE_paint_init(struct Main *bmain, struct Scene *sce, ePaintMode mode, const char col[3])
Definition: paint.c:1130
struct Paint * BKE_paint_get_active_from_context(const struct bContext *C)
bool BKE_paint_select_vert_test(struct Object *ob)
Definition: paint.c:987
const char PAINT_CURSOR_TEXTURE_PAINT[3]
Definition: paint.c:223
bool BKE_paint_select_face_test(struct Object *ob)
Definition: paint.c:980
void BKE_paint_toolslots_brush_validate(struct Main *bmain, struct Paint *paint)
ePaintMode
Definition: BKE_paint.h:67
@ PAINT_MODE_TEXTURE_3D
Definition: BKE_paint.h:73
@ PAINT_MODE_TEXTURE_2D
Definition: BKE_paint.h:75
#define BLI_assert(a)
Definition: BLI_assert.h:46
#define LISTBASE_FOREACH(type, var, list)
Definition: BLI_listbase.h:336
MINLINE void copy_v2_v2(float r[2], const float a[2])
MINLINE void copy_v3_v3(float r[3], const float a[3])
MINLINE void add_v2_v2(float r[2], const float a[2])
MINLINE void swap_v3_v3(float a[3], float b[3])
BLI_INLINE int BLI_rcti_size_y(const struct rcti *rct)
Definition: BLI_rect.h:190
void BLI_rcti_init_minmax(struct rcti *rect)
Definition: rct.c:477
void BLI_rcti_init(struct rcti *rect, int xmin, int xmax, int ymin, int ymax)
Definition: rct.c:417
BLI_INLINE int BLI_rcti_size_x(const struct rcti *rct)
Definition: BLI_rect.h:186
bool BLI_rcti_is_empty(const struct rcti *rect)
void BLI_rcti_do_minmax_rcti(struct rcti *rect, const struct rcti *other)
size_t BLI_snprintf(char *__restrict dst, size_t maxncpy, const char *__restrict format,...) ATTR_NONNULL(1
#define UNUSED(x)
#define ELEM(...)
#define TIP_(msgid)
void DEG_id_tag_update(struct ID *id, int flag)
@ ID_RECALC_COPY_ON_WRITE
Definition: DNA_ID.h:834
#define ID_IS_LINKED(_id)
Definition: DNA_ID.h:566
#define ID_IS_OVERRIDE_LIBRARY(_id)
Definition: DNA_ID.h:588
eBlurKernelType
@ KERNEL_BOX
@ KERNEL_GAUSSIAN
@ BRUSH_DRAG_DOT
@ BRUSH_ANCHORED
@ BRUSH_USE_GRADIENT
@ BRUSH_AIRBRUSH
@ BRUSH_GRADIENT_SPACING_CLAMP
@ BRUSH_GRADIENT_PRESSURE
@ BRUSH_GRADIENT_SPACING_REPEAT
@ PAINT_TOOL_CLONE
@ PAINT_TOOL_SMEAR
@ PAINT_TOOL_SOFTEN
@ PAINT_TOOL_FILL
@ PAINT_TOOL_DRAW
eObjectMode
@ OB_MODE_SCULPT
@ OB_MODE_TEXTURE_PAINT
@ OB_MODE_VERTEX_PAINT
Object is a sort of wrapper for general info.
@ OB_MESH
@ UNIFIED_PAINT_COLOR
#define IMAGEPAINT_MODE_IMAGE
#define IMAGEPAINT_MODE_MATERIAL
@ PAINT_SHOW_BRUSH
@ RGN_TYPE_WINDOW
@ SPACE_IMAGE
@ SI_MODE_PAINT
#define MTEX_MAP_MODE_3D
#define MTEX_MAP_MODE_STENCIL
#define MTEX_MAP_MODE_TILED
@ OPERATOR_CANCELLED
@ OPERATOR_FINISHED
@ OPERATOR_RUNNING_MODAL
void ED_space_image_get_zoom(struct SpaceImage *sima, const struct ARegion *region, float *r_zoomx, float *r_zoomy)
void ED_space_image_set(struct Main *bmain, struct SpaceImage *sima, struct Image *ima, bool automatic)
Definition: image_edit.c:45
void ED_paint_cursor_start(struct Paint *p, bool(*poll)(struct bContext *C))
bool ED_object_mode_compat_set(struct bContext *C, struct Object *ob, eObjectMode mode, struct ReportList *reports)
Definition: object_modes.c:161
void ED_image_undo_push_begin(const char *name, int paint_mode)
Definition: image_undo.cc:1095
struct PaintTileMap * ED_image_paint_tile_map_get(void)
Definition: image_undo.cc:1061
void ED_image_undo_push_end(void)
Definition: image_undo.cc:1133
void * ED_image_paint_tile_push(PaintTileMap *paint_tile_map, struct Image *image, struct ImBuf *ibuf, struct ImBuf **tmpibuf, struct ImageUser *iuser, int x_tile, int y_tile, unsigned short **r_mask, bool **r_valid, bool use_thread_lock, bool find_prev)
Definition: image_undo.cc:192
bool ED_paint_proj_mesh_data_check(struct Scene *scene, struct Object *ob, bool *uvs, bool *mat, bool *tex, bool *stencil)
#define ED_IMAGE_UNDO_TILE_BITS
Definition: ED_paint.h:104
void ED_region_tag_redraw(struct ARegion *region)
Definition: area.c:655
void ED_workspace_status_text(struct bContext *C, const char *str)
Definition: area.c:816
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum const void *lists _GL_VOID_RET _GL_VOID const GLdouble *equation _GL_VOID_RET _GL_VOID GLdouble GLdouble blue _GL_VOID_RET _GL_VOID GLfloat GLfloat blue _GL_VOID_RET _GL_VOID GLint GLint blue _GL_VOID_RET _GL_VOID GLshort GLshort blue _GL_VOID_RET _GL_VOID GLubyte GLubyte blue _GL_VOID_RET _GL_VOID GLuint GLuint blue _GL_VOID_RET _GL_VOID GLushort GLushort blue _GL_VOID_RET _GL_VOID GLbyte GLbyte GLbyte alpha _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble alpha _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat alpha _GL_VOID_RET _GL_VOID GLint GLint GLint alpha _GL_VOID_RET _GL_VOID GLshort GLshort GLshort alpha _GL_VOID_RET _GL_VOID GLubyte GLubyte GLubyte alpha _GL_VOID_RET _GL_VOID GLuint GLuint GLuint alpha _GL_VOID_RET _GL_VOID GLushort GLushort GLushort alpha _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLint y
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum type
void IMB_partial_display_buffer_update_delayed(struct ImBuf *ibuf, int xmin, int ymin, int xmax, int ymax)
void IMB_colormanagement_display_to_scene_linear_v3(float pixel[3], struct ColorManagedDisplay *display)
BLI_INLINE void IMB_colormanagement_scene_linear_to_srgb_v3(float srgb[3], const float scene_linear[3])
void IMB_rectclip(struct ImBuf *dbuf, const struct ImBuf *sbuf, int *destx, int *desty, int *srcx, int *srcy, int *width, int *height)
Contains defines and structs used throughout the imbuf module.
@ IB_MIPMAP_INVALID
Read Guarded memory(de)allocation.
Group Output data from inside of a node group A color picker Mix two input colors RGB to Convert a color s luminance to a grayscale value Generate a normal vector and a dot product Bright Control the brightness and contrast of the input color Vector Map an input vectors to used to fine tune the interpolation of the input Camera Retrieve information about the camera and how it relates to the current shading point s position Clamp a value between a minimum and a maximum Vector Perform vector math operation Invert a color
void ntreeTexEndExecTree(struct bNodeTreeExec *exec)
struct bNodeTreeExec * ntreeTexBeginExecTree(struct bNodeTree *ntree)
PropertyFlag
Definition: RNA_types.h:183
@ PROP_SKIP_SAVE
Definition: RNA_types.h:218
@ PROP_HIDDEN
Definition: RNA_types.h:216
#define C
Definition: RandGen.cpp:25
#define UI_MAX_DRAW_STR
Definition: UI_interface.h:91
void UI_view2d_region_to_view(const struct View2D *v2d, float x, float y, float *r_view_x, float *r_view_y) ATTR_NONNULL()
@ KM_PRESS
Definition: WM_types.h:267
@ KM_RELEASE
Definition: WM_types.h:268
@ OPTYPE_BLOCKING
Definition: WM_types.h:150
@ OPTYPE_UNDO
Definition: WM_types.h:148
@ OPTYPE_REGISTER
Definition: WM_types.h:146
#define NC_BRUSH
Definition: WM_types.h:335
#define ND_MODE
Definition: WM_types.h:393
#define NC_SCENE
Definition: WM_types.h:328
#define NA_EDITED
Definition: WM_types.h:523
unsigned int U
Definition: btGjkEpa3.h:78
SIMD_FORCE_INLINE const btScalar & w() const
Return the w value.
Definition: btQuadWord.h:119
Scene scene
SyclQueue void void size_t num_bytes SyclQueue void const char void *memory_device_pointer KernelContext int kernel
depth_tx normal_tx diffuse_light_tx specular_light_tx volume_light_tx environment_tx ambient_occlusion_tx aov_value_tx in_weight_img image(1, GPU_R32F, Qualifier::WRITE, ImageType::FLOAT_2D_ARRAY, "out_weight_img") .image(3
void IMB_freeImBuf(ImBuf *UNUSED(ibuf))
bool enabled
CCL_NAMESPACE_BEGIN ccl_device float invert(float color, float factor)
Definition: invert.h:8
void(* MEM_freeN)(void *vmemh)
Definition: mallocn.c:27
void *(* MEM_mallocN)(size_t len, const char *str)
Definition: mallocn.c:33
ccl_device_inline float3 exp(float3 v)
Definition: math_float3.h:392
static void area(int d1, int d2, int e1, int e2, float weights[2])
T distance(const T &a, const T &b)
void paint_cursor_delete_textures(void)
Definition: paint_cursor.c:88
void paint_delete_blur_kernel(BlurKernel *kernel)
Definition: paint_image.cc:240
static bool image_paint_2d_clone_poll(bContext *C)
Definition: paint_image.cc:301
bool ED_image_tools_paint_poll(bContext *C)
Definition: paint_image.cc:291
static int texture_paint_toggle_exec(bContext *C, wmOperator *op)
Definition: paint_image.cc:860
BlurKernel * paint_new_blur_kernel(Brush *br, bool proj)
Definition: paint_image.cc:171
static bool image_paint_poll_ex(bContext *C, bool check_tool)
Definition: paint_image.cc:257
void ED_imapaint_bucket_fill(struct bContext *C, float color[3], wmOperator *op, const int mouse[2])
Definition: paint_image.cc:961
static bool texture_paint_poll(bContext *C)
Definition: paint_image.cc:982
bool vert_paint_poll(bContext *C)
static int grab_clone_exec(bContext *C, wmOperator *op)
Definition: paint_image.cc:483
void imapaint_image_update(SpaceImage *sima, Image *image, ImBuf *ibuf, ImageUser *iuser, short texpaint)
Definition: paint_image.cc:144
ImagePaintPartialRedraw * get_imapaintpartial(void)
Definition: paint_image.cc:79
void paint_brush_init_tex(Brush *brush)
Definition: paint_image.cc:374
static bool texture_paint_toggle_poll(bContext *C)
Definition: paint_image.cc:847
void ED_imapaint_dirty_region(Image *ima, ImBuf *ibuf, ImageUser *iuser, int x, int y, int w, int h, bool find_old)
Definition: paint_image.cc:109
void ED_object_texture_paint_mode_exit_ex(Main *bmain, Scene *scene, Object *ob)
Definition: paint_image.cc:823
static int sample_color_exec(bContext *C, wmOperator *op)
Definition: paint_image.cc:599
static Brush * image_paint_brush(bContext *C)
Definition: paint_image.cc:249
static int grab_clone_modal(bContext *C, wmOperator *op, const wmEvent *event)
Definition: paint_image.cc:506
void ED_object_texture_paint_mode_exit(bContext *C)
Definition: paint_image.cc:839
bool facemask_paint_poll(bContext *C)
Definition: paint_image.cc:998
bool image_texture_paint_poll(bContext *C)
Definition: paint_image.cc:993
void ED_imapaint_clear_partial_redraw(void)
Definition: paint_image.cc:91
void ED_object_texture_paint_mode_enter_ex(Main *bmain, Scene *scene, Object *ob)
Definition: paint_image.cc:755
void PAINT_OT_sample_color(wmOperatorType *ot)
Definition: paint_image.cc:726
void set_imapaintpartial(struct ImagePaintPartialRedraw *ippr)
Definition: paint_image.cc:84
static void sample_color_update_header(SampleColorData *data, bContext *C)
Definition: paint_image.cc:583
static ImagePaintPartialRedraw imapaintpartial
Definition: paint_image.cc:77
void PAINT_OT_texture_paint_toggle(wmOperatorType *ot)
Definition: paint_image.cc:889
void ED_space_image_paint_update(Main *bmain, wmWindowManager *wm, Scene *scene)
Definition: paint_image.cc:438
bool mask_paint_poll(bContext *C)
static int brush_colors_flip_exec(bContext *C, wmOperator *UNUSED(op))
Definition: paint_image.cc:904
bool paint_use_opacity_masking(Brush *brush)
Definition: paint_image.cc:317
void paint_brush_color_get(struct Scene *scene, struct Brush *br, bool color_correction, bool invert, float distance, float pressure, float color[3], struct ColorManagedDisplay *display)
Definition: paint_image.cc:332
static int grab_clone_invoke(bContext *C, wmOperator *op, const wmEvent *event)
Definition: paint_image.cc:490
static void toggle_paint_cursor(Scene *scene, bool enable)
Definition: paint_image.cc:423
static void grab_clone_cancel(bContext *UNUSED(C), wmOperator *op)
Definition: paint_image.cc:539
void ED_object_texture_paint_mode_enter(bContext *C)
Definition: paint_image.cc:815
static void grab_clone_apply(bContext *C, wmOperator *op)
Definition: paint_image.cc:473
void PAINT_OT_brush_colors_flip(wmOperatorType *ot)
Definition: paint_image.cc:946
bool get_imapaint_zoom(bContext *C, float *zoomx, float *zoomy)
Definition: paint_image.cc:404
static bool brush_colors_flip_poll(bContext *C)
Definition: paint_image.cc:927
void PAINT_OT_grab_clone(wmOperatorType *ot)
Definition: paint_image.cc:545
void paint_brush_exit_tex(Brush *brush)
Definition: paint_image.cc:390
static int sample_color_modal(bContext *C, wmOperator *op, const wmEvent *event)
Definition: paint_image.cc:668
static bool sample_color_poll(bContext *C)
Definition: paint_image.cc:721
void imapaint_region_tiles(ImBuf *ibuf, int x, int y, int w, int h, int *tx, int *ty, int *tw, int *th)
Definition: paint_image.cc:96
static bool image_paint_poll_ignore_tool(bContext *C)
Definition: paint_image.cc:296
static int sample_color_invoke(bContext *C, wmOperator *op, const wmEvent *event)
Definition: paint_image.cc:630
void paint_2d_bucket_fill(const bContext *C, const float color[3], Brush *br, const float mouse_init[2], const float mouse_final[2], void *ps)
bool vertex_paint_poll_ignore_tool(struct bContext *C)
void paint_sample_color(struct bContext *C, struct ARegion *region, int x, int y, bool texpaint_proj, bool palette)
Definition: paint_utils.c:374
void RNA_int_set_array(PointerRNA *ptr, const char *name, const int *values)
Definition: rna_access.c:4945
void RNA_int_get_array(PointerRNA *ptr, const char *name, int *values)
Definition: rna_access.c:4933
void RNA_boolean_set(PointerRNA *ptr, const char *name, bool value)
Definition: rna_access.c:4874
void RNA_float_get_array(PointerRNA *ptr, const char *name, float *values)
Definition: rna_access.c:4980
bool RNA_boolean_get(PointerRNA *ptr, const char *name)
Definition: rna_access.c:4863
void RNA_float_set_array(PointerRNA *ptr, const char *name, const float *values)
Definition: rna_access.c:4992
PropertyRNA * RNA_def_boolean(StructOrFunctionRNA *cont_, const char *identifier, bool default_value, const char *ui_name, const char *ui_description)
Definition: rna_define.c:3493
PropertyRNA * RNA_def_float_vector(StructOrFunctionRNA *cont_, const char *identifier, int len, const float *default_value, float hardmin, float hardmax, const char *ui_name, const char *ui_description, float softmin, float softmax)
Definition: rna_define.c:3862
PropertyRNA * RNA_def_int_vector(StructOrFunctionRNA *cont_, const char *identifier, int len, const int *default_value, int hardmin, int hardmax, const char *ui_name, const char *ui_description, int softmin, int softmax)
Definition: rna_define.c:3623
void RNA_def_property_flag(PropertyRNA *prop, PropertyFlag flag)
Definition: rna_define.c:1490
short regiontype
struct Image * image
float offset[2]
struct ColorBand * gradient
int blur_kernel_radius
struct BrushClone clone
struct MTex mtex
float rgb[3]
char imagepaint_tool
char gradient_stroke_mode
struct MTex mask_mtex
int gradient_spacing
float secondary_rgb[3]
int blur_mode
float startoffset[2]
Definition: paint_image.cc:469
struct ImBuf * mipmap[IMB_MIPMAP_LEVELS]
int userflags
struct Image * canvas
void * first
Definition: DNA_listBase.h:31
char brush_map_mode
struct Tex * tex
Definition: BKE_main.h:121
ListBase wm
Definition: BKE_main.h:197
short paint_active_slot
struct TexPaintSlot * texpaintslot
void * data
void * paint_cursor
float initcolor[3]
Definition: paint_image.cc:579
struct ToolSettings * toolsettings
struct Image * image
struct Image * ima
struct bNodeTree * nodetree
struct ImagePaintSettings imapaint
struct UnifiedPaintSettings unified_paint_settings
struct bNodeTreeExec * execdata
ListBase areabase
int ymin
Definition: DNA_vec_types.h:64
int ymax
Definition: DNA_vec_types.h:64
int xmin
Definition: DNA_vec_types.h:63
int xmax
Definition: DNA_vec_types.h:63
short val
Definition: WM_types.h:680
int xy[2]
Definition: WM_types.h:682
int mval[2]
Definition: WM_types.h:684
short type
Definition: WM_types.h:678
int(* invoke)(struct bContext *, struct wmOperator *, const struct wmEvent *) ATTR_WARN_UNUSED_RESULT
Definition: WM_types.h:919
const char * name
Definition: WM_types.h:888
int(* modal)(struct bContext *, struct wmOperator *, const struct wmEvent *) ATTR_WARN_UNUSED_RESULT
Definition: WM_types.h:935
const char * idname
Definition: WM_types.h:890
bool(* poll)(struct bContext *) ATTR_WARN_UNUSED_RESULT
Definition: WM_types.h:943
void(* cancel)(struct bContext *, struct wmOperator *)
Definition: WM_types.h:927
struct StructRNA * srna
Definition: WM_types.h:969
const char * description
Definition: WM_types.h:893
int(* exec)(struct bContext *, struct wmOperator *) ATTR_WARN_UNUSED_RESULT
Definition: WM_types.h:903
struct ReportList * reports
struct wmOperatorType * type
struct PointerRNA * ptr
void WM_cursor_modal_set(wmWindow *win, int val)
Definition: wm_cursors.c:191
void WM_cursor_modal_restore(wmWindow *win)
Definition: wm_cursors.c:200
@ WM_CURSOR_EYEDROPPER
Definition: wm_cursors.h:35
void WM_redraw_windows(bContext *C)
Definition: wm_draw.c:1380
void WM_paint_cursor_tag_redraw(wmWindow *win, ARegion *UNUSED(region))
Definition: wm_draw.c:1294
int WM_userdef_event_type_from_keymap_type(int kmitype)
wmEventHandler_Op * WM_event_add_modal_handler(bContext *C, wmOperator *op)
void WM_main_add_notifier(unsigned int type, void *reference)
void WM_event_add_notifier(const bContext *C, uint type, void *reference)
@ RIGHTMOUSE
@ MOUSEMOVE
@ LEFTMOUSE
@ MIDDLEMOUSE
wmOperatorType * ot
Definition: wm_files.c:3479
#define WM_msg_publish_rna_prop(mbus, id_, data_, type_, prop_)
bool WM_paint_cursor_end(wmPaintCursor *handle)
bool WM_toolsystem_active_tool_is_brush(const bContext *C)
void WM_toolsystem_update_from_context_view3d(bContext *C)
bScreen * WM_window_get_active_screen(const wmWindow *win)
Definition: wm_window.c:2300