Blender  V3.3
Classes | Typedefs | Enumerations | Functions
paint_image_2d.c File Reference
#include <string.h>
#include "MEM_guardedalloc.h"
#include "DNA_brush_types.h"
#include "DNA_object_types.h"
#include "DNA_scene_types.h"
#include "DNA_space_types.h"
#include "BLI_bitmap.h"
#include "BLI_listbase.h"
#include "BLI_math_color_blend.h"
#include "BLI_stack.h"
#include "BLI_task.h"
#include "BKE_brush.h"
#include "BKE_colorband.h"
#include "BKE_context.h"
#include "BKE_image.h"
#include "BKE_paint.h"
#include "BKE_report.h"
#include "DEG_depsgraph.h"
#include "ED_paint.h"
#include "ED_screen.h"
#include "IMB_colormanagement.h"
#include "IMB_imbuf.h"
#include "IMB_imbuf_types.h"
#include "WM_api.h"
#include "WM_types.h"
#include "UI_view2d.h"
#include "paint_intern.h"

Go to the source code of this file.

Classes

struct  BrushPainterCache
 
struct  BrushPainter
 
struct  ImagePaintRegion
 
struct  ImagePaintTile
 
struct  ImagePaintState
 
struct  Paint2DForeachData
 

Typedefs

typedef struct BrushPainterCache BrushPainterCache
 
typedef struct BrushPainter BrushPainter
 
typedef struct ImagePaintRegion ImagePaintRegion
 
typedef enum ImagePaintTileState ImagePaintTileState
 
typedef struct ImagePaintTile ImagePaintTile
 
typedef struct ImagePaintState ImagePaintState
 
typedef struct Paint2DForeachData Paint2DForeachData
 

Enumerations

enum  ImagePaintTileState { PAINT2D_TILE_UNINITIALIZED = 0 , PAINT2D_TILE_MISSING , PAINT2D_TILE_READY }
 

Functions

static BrushPainterbrush_painter_2d_new (Scene *scene, Brush *brush, bool invert)
 
static void brush_painter_2d_require_imbuf (Brush *brush, ImagePaintTile *tile, bool use_float, bool use_color_correction, bool invert)
 
static void brush_painter_cache_2d_free (BrushPainterCache *cache)
 
static void brush_imbuf_tex_co (rctf *mapping, int x, int y, float texco[3])
 
static ushortbrush_painter_mask_ibuf_new (BrushPainter *painter, const int size)
 
static void brush_painter_mask_imbuf_update (BrushPainter *painter, ImagePaintTile *tile, const ushort *tex_mask_old, int origx, int origy, int w, int h, int xt, int yt, const int diameter)
 
static void brush_painter_mask_imbuf_partial_update (BrushPainter *painter, ImagePaintTile *tile, const float pos[2], const int diameter)
 
static ImBufbrush_painter_imbuf_new (BrushPainter *painter, ImagePaintTile *tile, const int size, float pressure, float distance)
 
static void brush_painter_imbuf_update (BrushPainter *painter, ImagePaintTile *tile, ImBuf *oldtexibuf, int origx, int origy, int w, int h, int xt, int yt)
 
static void brush_painter_imbuf_partial_update (BrushPainter *painter, ImagePaintTile *tile, const float pos[2], const int diameter)
 
static void brush_painter_2d_tex_mapping (ImagePaintState *s, ImagePaintTile *tile, const int diameter, const float pos[2], const float mouse[2], int mapmode, rctf *mapping)
 
static void brush_painter_2d_refresh_cache (ImagePaintState *s, BrushPainter *painter, ImagePaintTile *tile, const float pos[2], const float mouse[2], float pressure, float distance, float size)
 
static bool paint_2d_ensure_tile_canvas (ImagePaintState *s, int i)
 
static void paint_2d_ibuf_rgb_get (ImBuf *ibuf, int x, int y, float r_rgb[4])
 
static void paint_2d_ibuf_rgb_set (ImBuf *ibuf, int x, int y, const bool is_torus, const float rgb[4])
 
static void paint_2d_ibuf_tile_convert (ImBuf *ibuf, int *x, int *y, short paint_tile)
 
static float paint_2d_ibuf_add_if (ImBuf *ibuf, int x, int y, float *outrgb, short paint_tile, float w)
 
static void paint_2d_lift_soften (ImagePaintState *s, ImagePaintTile *tile, ImBuf *ibuf, ImBuf *ibufb, const int *pos, const short paint_tile)
 
static void paint_2d_set_region (ImagePaintRegion *region, int destx, int desty, int srcx, int srcy, int width, int height)
 
static int paint_2d_torus_split_region (ImagePaintRegion region[4], ImBuf *dbuf, ImBuf *sbuf, short paint_tile)
 
static void paint_2d_lift_smear (ImBuf *ibuf, ImBuf *ibufb, int *pos, short paint_tile)
 
static ImBufpaint_2d_lift_clone (ImBuf *ibuf, ImBuf *ibufb, const int *pos)
 
static void paint_2d_convert_brushco (ImBuf *ibufb, const float pos[2], int ipos[2])
 
static void paint_2d_do_making_brush (ImagePaintState *s, ImagePaintTile *tile, ImagePaintRegion *region, ImBuf *frombuf, float mask_max, short blend, int tilex, int tiley, int tilew, int tileh)
 
static void paint_2d_op_foreach_do (void *__restrict data_v, const int iter, const TaskParallelTLS *__restrict UNUSED(tls))
 
static int paint_2d_op (void *state, ImagePaintTile *tile, const float lastpos[2], const float pos[2])
 
static int paint_2d_canvas_set (ImagePaintState *s)
 
static void paint_2d_canvas_free (ImagePaintState *s)
 
static void paint_2d_transform_mouse (View2D *v2d, const float in[2], float out[2])
 
static bool is_inside_tile (const int size[2], const float pos[2], const float brush[2])
 
static void paint_2d_uv_to_coord (ImagePaintTile *tile, const float uv[2], float coord[2])
 
void paint_2d_stroke (void *ps, const float prev_mval[2], const float mval[2], const bool eraser, float pressure, float distance, float base_size)
 
voidpaint_2d_new_stroke (bContext *C, wmOperator *op, int mode)
 
void paint_2d_redraw (const bContext *C, void *ps, bool final)
 
void paint_2d_stroke_done (void *ps)
 
static void paint_2d_fill_add_pixel_byte (const int x_px, const int y_px, ImBuf *ibuf, BLI_Stack *stack, BLI_bitmap *touched, const float color[4], float threshold_sq)
 
static void paint_2d_fill_add_pixel_float (const int x_px, const int y_px, ImBuf *ibuf, BLI_Stack *stack, BLI_bitmap *touched, const float color[4], float threshold_sq)
 
static ImageUserpaint_2d_get_tile_iuser (ImagePaintState *s, int tile_number)
 
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)
 
void paint_2d_gradient_fill (const bContext *C, Brush *br, const float mouse_init[2], const float mouse_final[2], void *ps)
 

Typedef Documentation

◆ BrushPainter

typedef struct BrushPainter BrushPainter

◆ BrushPainterCache

◆ ImagePaintRegion

◆ ImagePaintState

◆ ImagePaintTile

◆ ImagePaintTileState

◆ Paint2DForeachData

Enumeration Type Documentation

◆ ImagePaintTileState

Enumerator
PAINT2D_TILE_UNINITIALIZED 
PAINT2D_TILE_MISSING 
PAINT2D_TILE_READY 

Definition at line 94 of file paint_image_2d.c.

Function Documentation

◆ brush_imbuf_tex_co()

static void brush_imbuf_tex_co ( rctf mapping,
int  x,
int  y,
float  texco[3] 
)
static

◆ brush_painter_2d_new()

static BrushPainter* brush_painter_2d_new ( Scene scene,
Brush brush,
bool  invert 
)
static

◆ brush_painter_2d_refresh_cache()

static void brush_painter_2d_refresh_cache ( ImagePaintState s,
BrushPainter painter,
ImagePaintTile tile,
const float  pos[2],
const float  mouse[2],
float  pressure,
float  distance,
float  size 
)
static

◆ brush_painter_2d_require_imbuf()

static void brush_painter_2d_require_imbuf ( Brush brush,
ImagePaintTile tile,
bool  use_float,
bool  use_color_correction,
bool  invert 
)
static

◆ brush_painter_2d_tex_mapping()

static void brush_painter_2d_tex_mapping ( ImagePaintState s,
ImagePaintTile tile,
const int  diameter,
const float  pos[2],
const float  mouse[2],
int  mapmode,
rctf mapping 
)
static

◆ brush_painter_cache_2d_free()

static void brush_painter_cache_2d_free ( BrushPainterCache cache)
static

◆ brush_painter_imbuf_new()

static ImBuf* brush_painter_imbuf_new ( BrushPainter painter,
ImagePaintTile tile,
const int  size,
float  pressure,
float  distance 
)
static

◆ brush_painter_imbuf_partial_update()

static void brush_painter_imbuf_partial_update ( BrushPainter painter,
ImagePaintTile tile,
const float  pos[2],
const int  diameter 
)
static

◆ brush_painter_imbuf_update()

static void brush_painter_imbuf_update ( BrushPainter painter,
ImagePaintTile tile,
ImBuf oldtexibuf,
int  origx,
int  origy,
int  w,
int  h,
int  xt,
int  yt 
)
static

◆ brush_painter_mask_ibuf_new()

static ushort* brush_painter_mask_ibuf_new ( BrushPainter painter,
const int  size 
)
static

◆ brush_painter_mask_imbuf_partial_update()

static void brush_painter_mask_imbuf_partial_update ( BrushPainter painter,
ImagePaintTile tile,
const float  pos[2],
const int  diameter 
)
static

Update the brush mask image by trying to reuse the cached texture result. This can be considerably faster for brushes that change size due to pressure or textures that stick to the surface where only part of the pixels are new

Definition at line 286 of file paint_image_2d.c.

References brush_painter_mask_imbuf_update(), floorf, IMB_rectclip(), MEM_freeN, MEM_mallocN, min_ii(), NULL, pos, BrushPainterCache::tex_mask, BrushPainterCache::tex_mask_old, BrushPainterCache::tex_mask_old_h, BrushPainterCache::tex_mask_old_w, tile, w(), ImBuf::x, x2, ImBuf::y, and y1.

Referenced by brush_painter_2d_refresh_cache().

◆ brush_painter_mask_imbuf_update()

static void brush_painter_mask_imbuf_update ( BrushPainter painter,
ImagePaintTile tile,
const ushort tex_mask_old,
int  origx,
int  origy,
int  w,
int  h,
int  xt,
int  yt,
const int  diameter 
)
static

◆ is_inside_tile()

static bool is_inside_tile ( const int  size[2],
const float  pos[2],
const float  brush[2] 
)
static

Definition at line 1440 of file paint_image_2d.c.

References pos, and size().

Referenced by paint_2d_stroke().

◆ paint_2d_bucket_fill()

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 
)

◆ paint_2d_canvas_free()

static void paint_2d_canvas_free ( ImagePaintState s)
static

◆ paint_2d_canvas_set()

static int paint_2d_canvas_set ( ImagePaintState s)
static

◆ paint_2d_convert_brushco()

static void paint_2d_convert_brushco ( ImBuf ibufb,
const float  pos[2],
int  ipos[2] 
)
static

Definition at line 1179 of file paint_image_2d.c.

References floorf, pos, ImBuf::x, and ImBuf::y.

Referenced by paint_2d_op().

◆ paint_2d_do_making_brush()

static void paint_2d_do_making_brush ( ImagePaintState s,
ImagePaintTile tile,
ImagePaintRegion region,
ImBuf frombuf,
float  mask_max,
short  blend,
int  tilex,
int  tiley,
int  tilew,
int  tileh 
)
static

◆ paint_2d_ensure_tile_canvas()

static bool paint_2d_ensure_tile_canvas ( ImagePaintState s,
int  i 
)
static

◆ paint_2d_fill_add_pixel_byte()

static void paint_2d_fill_add_pixel_byte ( const int  x_px,
const int  y_px,
ImBuf ibuf,
BLI_Stack stack,
BLI_bitmap touched,
const float  color[4],
float  threshold_sq 
)
static

◆ paint_2d_fill_add_pixel_float()

static void paint_2d_fill_add_pixel_float ( const int  x_px,
const int  y_px,
ImBuf ibuf,
BLI_Stack stack,
BLI_bitmap touched,
const float  color[4],
float  threshold_sq 
)
static

◆ paint_2d_get_tile_iuser()

static ImageUser* paint_2d_get_tile_iuser ( ImagePaintState s,
int  tile_number 
)
static

◆ paint_2d_gradient_fill()

void paint_2d_gradient_fill ( const bContext C,
Brush br,
const float  mouse_init[2],
const float  mouse_final[2],
void ps 
)

◆ paint_2d_ibuf_add_if()

static float paint_2d_ibuf_add_if ( ImBuf ibuf,
int  x,
int  y,
float outrgb,
short  paint_tile,
float  w 
)
static

◆ paint_2d_ibuf_rgb_get()

static void paint_2d_ibuf_rgb_get ( ImBuf ibuf,
int  x,
int  y,
float  r_rgb[4] 
)
static

◆ paint_2d_ibuf_rgb_set()

static void paint_2d_ibuf_rgb_set ( ImBuf ibuf,
int  x,
int  y,
const bool  is_torus,
const float  rgb[4] 
)
static

◆ paint_2d_ibuf_tile_convert()

static void paint_2d_ibuf_tile_convert ( ImBuf ibuf,
int *  x,
int *  y,
short  paint_tile 
)
static

Definition at line 887 of file paint_image_2d.c.

References PAINT_TILE_X, PAINT_TILE_Y, x, ImBuf::x, y, and ImBuf::y.

Referenced by paint_2d_ibuf_add_if(), and paint_2d_lift_soften().

◆ paint_2d_lift_clone()

static ImBuf* paint_2d_lift_clone ( ImBuf ibuf,
ImBuf ibufb,
const int *  pos 
)
static

◆ paint_2d_lift_smear()

static void paint_2d_lift_smear ( ImBuf ibuf,
ImBuf ibufb,
int *  pos,
short  paint_tile 
)
static

◆ paint_2d_lift_soften()

static void paint_2d_lift_soften ( ImagePaintState s,
ImagePaintTile tile,
ImBuf ibuf,
ImBuf ibufb,
const int *  pos,
const short  paint_tile 
)
static

◆ paint_2d_new_stroke()

void* paint_2d_new_stroke ( bContext C,
wmOperator op,
int  mode 
)

◆ paint_2d_op()

static int paint_2d_op ( void state,
ImagePaintTile tile,
const float  lastpos[2],
const float  pos[2] 
)
static

◆ paint_2d_op_foreach_do()

static void paint_2d_op_foreach_do ( void *__restrict  data_v,
const int  iter,
const TaskParallelTLS *__restrict   UNUSEDtls 
)
static

Definition at line 1249 of file paint_image_2d.c.

References data, and paint_2d_do_making_brush().

Referenced by paint_2d_op().

◆ paint_2d_redraw()

void paint_2d_redraw ( const bContext C,
void ps,
bool  final 
)

◆ paint_2d_set_region()

static void paint_2d_set_region ( ImagePaintRegion region,
int  destx,
int  desty,
int  srcx,
int  srcy,
int  width,
int  height 
)
static

◆ paint_2d_stroke()

void paint_2d_stroke ( void ps,
const float  prev_mval[2],
const float  mval[2],
const bool  eraser,
float  pressure,
float  distance,
float  base_size 
)

◆ paint_2d_stroke_done()

void paint_2d_stroke_done ( void ps)

◆ paint_2d_torus_split_region()

static int paint_2d_torus_split_region ( ImagePaintRegion  region[4],
ImBuf dbuf,
ImBuf sbuf,
short  paint_tile 
)
static

◆ paint_2d_transform_mouse()

static void paint_2d_transform_mouse ( View2D v2d,
const float  in[2],
float  out[2] 
)
static

Definition at line 1435 of file paint_image_2d.c.

References usdtokens::out(), and UI_view2d_region_to_view().

Referenced by paint_2d_bucket_fill(), and paint_2d_gradient_fill().

◆ paint_2d_uv_to_coord()

static void paint_2d_uv_to_coord ( ImagePaintTile tile,
const float  uv[2],
float  coord[2] 
)
static

Definition at line 1446 of file paint_image_2d.c.

References tile.

Referenced by paint_2d_stroke().