1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
|
/* SPDX-License-Identifier: GPL-2.0-or-later
* Copyright 2001-2002 NaN Holding BV. All rights reserved. */
#pragma once
/** \file
* \ingroup bke
*/
#include "BLI_utildefines.h"
#include "BLI_rect.h"
#ifdef __cplusplus
extern "C" {
#endif
struct Depsgraph;
struct ID;
struct ImBuf;
struct Image;
struct ImageFormatData;
struct ImagePool;
struct ImageTile;
struct ImbFormatOptions;
struct ListBase;
struct Main;
struct Object;
struct RenderResult;
struct ReportList;
struct Scene;
struct StampData;
struct anim;
#define IMA_MAX_SPACE 64
#define IMA_UDIM_MAX 2000
void BKE_image_free_packedfiles(struct Image *image);
void BKE_image_free_views(struct Image *image);
void BKE_image_free_buffers(struct Image *image);
/**
* Simply free the image data from memory,
* on display the image can load again (except for render buffers).
*/
void BKE_image_free_buffers_ex(struct Image *image, bool do_lock);
void BKE_image_free_gputextures(struct Image *ima);
/**
* Free (or release) any data used by this image (does not free the image itself).
* \note Call from library.
*/
void BKE_image_free_data(struct Image *image);
typedef void(StampCallback)(void *data, const char *propname, char *propvalue, int len);
void BKE_render_result_stamp_info(struct Scene *scene,
struct Object *camera,
struct RenderResult *rr,
bool allocate_only);
/**
* Fills in the static stamp data (i.e. everything except things that can change per frame).
* The caller is responsible for freeing the allocated memory.
*/
struct StampData *BKE_stamp_info_from_scene_static(const struct Scene *scene);
/**
* Check whether the given metadata field name translates to a known field of a stamp.
*/
bool BKE_stamp_is_known_field(const char *field_name);
void BKE_imbuf_stamp_info(struct RenderResult *rr, struct ImBuf *ibuf);
void BKE_stamp_info_from_imbuf(struct RenderResult *rr, struct ImBuf *ibuf);
void BKE_stamp_info_callback(void *data,
struct StampData *stamp_data,
StampCallback callback,
bool noskip);
void BKE_render_result_stamp_data(struct RenderResult *rr, const char *key, const char *value);
struct StampData *BKE_stamp_data_copy(const struct StampData *stamp_data);
void BKE_stamp_data_free(struct StampData *stamp_data);
void BKE_image_stamp_buf(struct Scene *scene,
struct Object *camera,
const struct StampData *stamp_data_template,
unsigned char *rect,
float *rectf,
int width,
int height,
int channels);
bool BKE_imbuf_alpha_test(struct ImBuf *ibuf);
int BKE_imbuf_write_stamp(struct Scene *scene,
struct RenderResult *rr,
struct ImBuf *ibuf,
const char *name,
const struct ImageFormatData *imf);
/**
* \note imf->planes is ignored here, its assumed the image channels are already set.
*/
int BKE_imbuf_write(struct ImBuf *ibuf, const char *name, const struct ImageFormatData *imf);
/**
* Same as #BKE_imbuf_write() but crappy workaround not to permanently modify _some_,
* values in the imbuf.
*/
int BKE_imbuf_write_as(struct ImBuf *ibuf,
const char *name,
struct ImageFormatData *imf,
bool save_copy);
/**
* Used by sequencer too.
*/
struct anim *openanim(const char *name,
int flags,
int streamindex,
char colorspace[IMA_MAX_SPACE]);
struct anim *openanim_noload(const char *name,
int flags,
int streamindex,
char colorspace[IMA_MAX_SPACE]);
void BKE_image_tag_time(struct Image *ima);
/* ********************************** NEW IMAGE API *********************** */
/* ImageUser is in Texture, in Nodes, Background Image, Image Window, .... */
/* should be used in conjunction with an ID * to Image. */
struct ImageUser;
struct RenderData;
struct RenderPass;
struct RenderResult;
/* signals */
/* reload only frees, doesn't read until image_get_ibuf() called */
#define IMA_SIGNAL_RELOAD 0
#define IMA_SIGNAL_FREE 1
/* source changes, from image to sequence or movie, etc */
#define IMA_SIGNAL_SRC_CHANGE 5
/* image-user gets a new image, check settings */
#define IMA_SIGNAL_USER_NEW_IMAGE 6
#define IMA_SIGNAL_COLORMANAGE 7
/**
* Checks whether there's an image buffer for given image and user.
*/
bool BKE_image_has_ibuf(struct Image *ima, struct ImageUser *iuser);
/**
* Return image buffer for given image and user:
* - will lock render result if image type is render result and lock is not NULL
* - will return NULL if image is NULL or image type is render or composite result and lock is NULL
*
* References the result, #BKE_image_release_ibuf should be used to de-reference.
*/
struct ImBuf *BKE_image_acquire_ibuf(struct Image *ima, struct ImageUser *iuser, void **r_lock);
void BKE_image_release_ibuf(struct Image *ima, struct ImBuf *ibuf, void *lock);
struct ImagePool *BKE_image_pool_new(void);
void BKE_image_pool_free(struct ImagePool *pool);
struct ImBuf *BKE_image_pool_acquire_ibuf(struct Image *ima,
struct ImageUser *iuser,
struct ImagePool *pool);
void BKE_image_pool_release_ibuf(struct Image *ima, struct ImBuf *ibuf, struct ImagePool *pool);
/**
* Set an alpha mode based on file extension.
*/
char BKE_image_alpha_mode_from_extension_ex(const char *filepath);
void BKE_image_alpha_mode_from_extension(struct Image *image);
/**
* Returns a new image or NULL if it can't load.
*/
struct Image *BKE_image_load(struct Main *bmain, const char *filepath);
/**
* Returns existing Image when filename/type is same.
*
* Checks if image was already loaded, then returns same image otherwise creates new
* (does not load ibuf itself).
*/
struct Image *BKE_image_load_exists_ex(struct Main *bmain, const char *filepath, bool *r_exists);
struct Image *BKE_image_load_exists(struct Main *bmain, const char *filepath);
/**
* Adds new image block, creates ImBuf and initializes color.
*/
struct Image *BKE_image_add_generated(struct Main *bmain,
unsigned int width,
unsigned int height,
const char *name,
int depth,
int floatbuf,
short gen_type,
const float color[4],
bool stereo3d,
bool is_data,
bool tiled);
/**
* Create an image from ibuf. The reference-count of ibuf is increased,
* caller should take care to drop its reference by calling #IMB_freeImBuf if needed.
*/
struct Image *BKE_image_add_from_imbuf(struct Main *bmain, struct ImBuf *ibuf, const char *name);
/**
* For reload, refresh, pack.
*/
void BKE_imageuser_default(struct ImageUser *iuser);
void BKE_image_init_imageuser(struct Image *ima, struct ImageUser *iuser);
void BKE_image_signal(struct Main *bmain, struct Image *ima, struct ImageUser *iuser, int signal);
void BKE_image_walk_all_users(const struct Main *mainp,
void *customdata,
void callback(struct Image *ima,
struct ID *iuser_id,
struct ImageUser *iuser,
void *customdata));
/**
* Ensures an Image exists for viewing nodes or render
* forces existence of 1 Image for render-output or nodes, returns Image.
*
* \param name: Only for default, when making new one.
*/
struct Image *BKE_image_ensure_viewer(struct Main *bmain, int type, const char *name);
/**
* Ensures the view node cache is compatible with the scene views.
* Reset the image cache and views when the Viewer Nodes views don't match the scene views.
*/
void BKE_image_ensure_viewer_views(const struct RenderData *rd,
struct Image *ima,
struct ImageUser *iuser);
/**
* Called on frame change or before render.
*/
void BKE_image_user_frame_calc(struct Image *ima, struct ImageUser *iuser, int cfra);
int BKE_image_user_frame_get(const struct ImageUser *iuser, int cfra, bool *r_is_in_range);
void BKE_image_user_file_path(struct ImageUser *iuser, struct Image *ima, char *path);
void BKE_image_user_file_path_ex(struct ImageUser *iuser,
struct Image *ima,
char *path,
bool resolve_udim);
void BKE_image_editors_update_frame(const struct Main *bmain, int cfra);
/**
* Dependency graph update for image user users.
*/
bool BKE_image_user_id_has_animation(struct ID *id);
void BKE_image_user_id_eval_animation(struct Depsgraph *depsgraph, struct ID *id);
/**
* Sets index offset for multi-layer files and because rendered results use fake layer/passes,
* don't correct for wrong indices here.
*/
struct RenderPass *BKE_image_multilayer_index(struct RenderResult *rr, struct ImageUser *iuser);
/**
* Sets index offset for multi-view files.
*/
void BKE_image_multiview_index(struct Image *ima, struct ImageUser *iuser);
/**
* For multi-layer images as well as for render-viewer
* and because rendered results use fake layer/passes, don't correct for wrong indices here.
*/
bool BKE_image_is_multilayer(struct Image *ima);
bool BKE_image_is_multiview(struct Image *ima);
bool BKE_image_is_stereo(struct Image *ima);
struct RenderResult *BKE_image_acquire_renderresult(struct Scene *scene, struct Image *ima);
void BKE_image_release_renderresult(struct Scene *scene, struct Image *ima);
/**
* For multi-layer images as well as for single-layer.
*/
bool BKE_image_is_openexr(struct Image *ima);
/**
* For multiple slot render, call this before render.
*/
void BKE_image_backup_render(struct Scene *scene, struct Image *ima, bool free_current_slot);
/**
* For single-layer OpenEXR saving.
*/
bool BKE_image_save_openexr_multiview(struct Image *ima,
struct ImBuf *ibuf,
const char *filepath,
int flags);
/**
* Goes over all textures that use images.
*/
void BKE_image_free_all_textures(struct Main *bmain);
/**
* Operates on one image only!
* \param except_frame: This is weak, only works for sequences without offset.
*/
void BKE_image_free_anim_ibufs(struct Image *ima, int except_frame);
/**
* Does all images with type MOVIE or SEQUENCE.
*/
void BKE_image_all_free_anim_ibufs(struct Main *bmain, int cfra);
void BKE_image_free_all_gputextures(struct Main *bmain);
/**
* Same as above but only free animated images.
*/
void BKE_image_free_anim_gputextures(struct Main *bmain);
void BKE_image_free_old_gputextures(struct Main *bmain);
/**
* Pack image to memory.
*/
bool BKE_image_memorypack(struct Image *ima);
void BKE_image_packfiles(struct ReportList *reports, struct Image *ima, const char *basepath);
void BKE_image_packfiles_from_mem(struct ReportList *reports,
struct Image *ima,
char *data,
size_t data_len);
/**
* Prints memory statistics for images.
*/
void BKE_image_print_memlist(struct Main *bmain);
/**
* Merge source into `dest`, and free `source`.
*/
void BKE_image_merge(struct Main *bmain, struct Image *dest, struct Image *source);
/**
* Scale the image.
*/
bool BKE_image_scale(struct Image *image, int width, int height);
/**
* Check if texture has alpha (planes == 32 || planes == 16).
*/
bool BKE_image_has_alpha(struct Image *image);
/**
* Check if texture has GPU texture code.
*/
bool BKE_image_has_opengl_texture(struct Image *ima);
/**
* Get tile index for tiled images.
*/
void BKE_image_get_tile_label(struct Image *ima,
struct ImageTile *tile,
char *label,
int len_label);
/**
* Checks whether the given filepath refers to a UDIM tiled texture.
* If yes, the range from the lowest to the highest tile is returned.
*
* `filepath` may be modified to ensure a UDIM token is present.
* `tiles` may be filled even if the result ultimately is false!
*/
bool BKE_image_get_tile_info(char *filepath,
struct ListBase *tiles,
int *tile_start,
int *tile_range);
struct ImageTile *BKE_image_add_tile(struct Image *ima, int tile_number, const char *label);
bool BKE_image_remove_tile(struct Image *ima, struct ImageTile *tile);
void BKE_image_reassign_tile(struct Image *ima, struct ImageTile *tile, int new_tile_number);
void BKE_image_sort_tiles(struct Image *ima);
bool BKE_image_fill_tile(struct Image *ima,
struct ImageTile *tile,
int width,
int height,
const float color[4],
int gen_type,
int planes,
bool is_float);
typedef enum {
UDIM_TILE_FORMAT_NONE = 0,
UDIM_TILE_FORMAT_UDIM = 1,
UDIM_TILE_FORMAT_UVTILE = 2
} eUDIM_TILE_FORMAT;
/**
* Ensures that `filename` contains a UDIM token if we find a supported format pattern.
* \note This must only be the name component (without slashes).
*/
void BKE_image_ensure_tile_token(char *filename);
/**
* When provided with an absolute virtual filepath, check to see if at least
* one concrete file exists.
* Note: This function requires directory traversal and may be inefficient in time-critical,
* or iterative, code paths.
*/
bool BKE_image_tile_filepath_exists(const char *filepath);
/**
* Retrieves the UDIM token format and returns the pattern from the provided `filepath`.
* The returned pattern is typically passed to either `BKE_image_get_tile_number_from_filepath` or
* `BKE_image_set_filepath_from_tile_number`.
*/
char *BKE_image_get_tile_strformat(const char *filepath, eUDIM_TILE_FORMAT *r_tile_format);
bool BKE_image_get_tile_number_from_filepath(const char *filepath,
const char *pattern,
eUDIM_TILE_FORMAT tile_format,
int *r_tile_number);
void BKE_image_set_filepath_from_tile_number(char *filepath,
const char *pattern,
eUDIM_TILE_FORMAT tile_format,
int tile_number);
struct ImageTile *BKE_image_get_tile(struct Image *ima, int tile_number);
struct ImageTile *BKE_image_get_tile_from_iuser(struct Image *ima, const struct ImageUser *iuser);
int BKE_image_get_tile_from_pos(struct Image *ima,
const float uv[2],
float r_uv[2],
float r_ofs[2]);
/**
* Return the tile_number for the closest UDIM tile.
*/
int BKE_image_find_nearest_tile(const struct Image *image, const float co[2]);
void BKE_image_get_size(struct Image *image, struct ImageUser *iuser, int *r_width, int *r_height);
void BKE_image_get_size_fl(struct Image *image, struct ImageUser *iuser, float r_size[2]);
void BKE_image_get_aspect(struct Image *image, float *r_aspx, float *r_aspy);
/* image_gen.c */
void BKE_image_buf_fill_color(
unsigned char *rect, float *rect_float, int width, int height, const float color[4]);
void BKE_image_buf_fill_checker(unsigned char *rect, float *rect_float, int width, int height);
void BKE_image_buf_fill_checker_color(unsigned char *rect,
float *rect_float,
int width,
int height);
/* Cycles hookup */
unsigned char *BKE_image_get_pixels_for_frame(struct Image *image, int frame, int tile);
float *BKE_image_get_float_pixels_for_frame(struct Image *image, int frame, int tile);
/* Image modifications */
bool BKE_image_is_dirty(struct Image *image);
void BKE_image_mark_dirty(struct Image *image, struct ImBuf *ibuf);
bool BKE_image_buffer_format_writable(struct ImBuf *ibuf);
bool BKE_image_is_dirty_writable(struct Image *image, bool *r_is_writable);
/**
* Guess offset for the first frame in the sequence.
*/
int BKE_image_sequence_guess_offset(struct Image *image);
bool BKE_image_has_anim(struct Image *image);
bool BKE_image_has_packedfile(const struct Image *image);
bool BKE_image_has_filepath(struct Image *ima);
/**
* Checks the image buffer changes with time (not keyframed values).
*/
bool BKE_image_is_animated(struct Image *image);
/**
* Checks whether the image consists of multiple buffers.
*/
bool BKE_image_has_multiple_ibufs(struct Image *image);
void BKE_image_file_format_set(struct Image *image,
int ftype,
const struct ImbFormatOptions *options);
bool BKE_image_has_loaded_ibuf(struct Image *image);
/**
* References the result, #BKE_image_release_ibuf is to be called to de-reference.
* Use lock=NULL when calling #BKE_image_release_ibuf().
*/
struct ImBuf *BKE_image_get_ibuf_with_name(struct Image *image, const char *name);
/**
* References the result, #BKE_image_release_ibuf is to be called to de-reference.
* Use lock=NULL when calling #BKE_image_release_ibuf().
*
* TODO(sergey): This is actually "get first item from the cache", which is
* not so much predictable. But using first loaded image buffer
* was also malicious logic and all the areas which uses this
* function are to be re-considered.
*/
struct ImBuf *BKE_image_get_first_ibuf(struct Image *image);
/**
* Not to be use directly.
*/
struct GPUTexture *BKE_image_create_gpu_texture_from_ibuf(struct Image *image, struct ImBuf *ibuf);
/**
* Get the #GPUTexture for a given `Image`.
*
* `iuser` and `ibuf` are mutual exclusive parameters. The caller can pass the `ibuf` when already
* available. It is also required when requesting the #GPUTexture for a render result.
*/
struct GPUTexture *BKE_image_get_gpu_texture(struct Image *image,
struct ImageUser *iuser,
struct ImBuf *ibuf);
struct GPUTexture *BKE_image_get_gpu_tiles(struct Image *image,
struct ImageUser *iuser,
struct ImBuf *ibuf);
struct GPUTexture *BKE_image_get_gpu_tilemap(struct Image *image,
struct ImageUser *iuser,
struct ImBuf *ibuf);
/**
* Is the alpha of the `GPUTexture` for a given image/ibuf premultiplied.
*/
bool BKE_image_has_gpu_texture_premultiplied_alpha(struct Image *image, struct ImBuf *ibuf);
/**
* Partial update of texture for texture painting.
* This is often much quicker than fully updating the texture for high resolution images.
*/
void BKE_image_update_gputexture(
struct Image *ima, struct ImageUser *iuser, int x, int y, int w, int h);
/**
* Mark areas on the #GPUTexture that needs to be updated. The areas are marked in chunks.
* The next time the #GPUTexture is used these tiles will be refreshes. This saves time
* when writing to the same place multiple times This happens for during foreground rendering.
*/
void BKE_image_update_gputexture_delayed(struct Image *ima,
struct ImageTile *image_tile,
struct ImBuf *ibuf,
int x,
int y,
int w,
int h);
/**
* Called on entering and exiting texture paint mode,
* temporary disabling/enabling mipmapping on all images for quick texture
* updates with glTexSubImage2D. images that didn't change don't have to be re-uploaded to OpenGL.
*/
void BKE_image_paint_set_mipmap(struct Main *bmain, bool mipmap);
/**
* Delayed free of OpenGL buffers by main thread.
*/
void BKE_image_free_unused_gpu_textures(void);
struct RenderSlot *BKE_image_add_renderslot(struct Image *ima, const char *name);
bool BKE_image_remove_renderslot(struct Image *ima, struct ImageUser *iuser, int slot);
struct RenderSlot *BKE_image_get_renderslot(struct Image *ima, int index);
bool BKE_image_clear_renderslot(struct Image *ima, struct ImageUser *iuser, int slot);
/* --- image_partial_update.cc --- */
/** Image partial updates. */
struct PartialUpdateUser;
/**
* \brief Create a new PartialUpdateUser. An Object that contains data to use partial updates.
*/
struct PartialUpdateUser *BKE_image_partial_update_create(const struct Image *image);
/**
* \brief free a partial update user.
*/
void BKE_image_partial_update_free(struct PartialUpdateUser *user);
/* --- partial updater (image side) --- */
struct PartialUpdateRegister;
void BKE_image_partial_update_register_free(struct Image *image);
/** \brief Mark a region of the image to update. */
void BKE_image_partial_update_mark_region(struct Image *image,
const struct ImageTile *image_tile,
const struct ImBuf *image_buffer,
const rcti *updated_region);
/** \brief Mark the whole image to be updated. */
void BKE_image_partial_update_mark_full_update(struct Image *image);
#ifdef __cplusplus
}
#endif
|