implement cache line for image editor
It works exactly the same as a cache line in movie clip editor.
This commit is contained in:
@@ -133,6 +133,15 @@ static int imagecache_hashcmp(const void *a_v, const void *b_v)
|
||||
return a->index - b->index;
|
||||
}
|
||||
|
||||
static void imagecache_keydata(void *userkey, int *framenr, int *proxy, int *render_flags)
|
||||
{
|
||||
ImageCacheKey *key = (ImageCacheKey *)userkey;
|
||||
|
||||
*framenr = IMA_INDEX_FRAME(key->index);
|
||||
*proxy = IMB_PROXY_NONE;
|
||||
*render_flags = 0;
|
||||
}
|
||||
|
||||
static void imagecache_put(Image *image, int index, ImBuf *ibuf)
|
||||
{
|
||||
ImageCacheKey key;
|
||||
@@ -143,6 +152,7 @@ static void imagecache_put(Image *image, int index, ImBuf *ibuf)
|
||||
|
||||
image->cache = IMB_moviecache_create("Image Datablock Cache", sizeof(ImageCacheKey),
|
||||
imagecache_hashhash, imagecache_hashcmp);
|
||||
IMB_moviecache_set_getdata_callback(image->cache, imagecache_keydata);
|
||||
}
|
||||
|
||||
key.index = index;
|
||||
|
@@ -178,6 +178,12 @@ int ED_operator_posemode(struct bContext *C);
|
||||
int ED_operator_mask(struct bContext *C);
|
||||
|
||||
|
||||
/* Cache display helpers */
|
||||
|
||||
void ED_region_cache_draw_background(const struct ARegion *ar);
|
||||
void ED_region_cache_draw_curfra_label(const int framenr, const float x, const float y);
|
||||
void ED_region_cache_draw_cached_segments(const struct ARegion *ar, const int num_segments, const int *points, const int sfra, const int efra);
|
||||
|
||||
/* default keymaps, bitflags */
|
||||
#define ED_KEYMAP_UI 1
|
||||
#define ED_KEYMAP_VIEW2D 2
|
||||
|
@@ -2007,3 +2007,49 @@ void ED_region_visible_rect(ARegion *ar, rcti *rect)
|
||||
BLI_rcti_translate(rect, -ar->winrct.xmin, -ar->winrct.ymin);
|
||||
}
|
||||
|
||||
/* Cache display helpers */
|
||||
|
||||
void ED_region_cache_draw_background(const ARegion *ar)
|
||||
{
|
||||
glColor4ub(128, 128, 255, 64);
|
||||
glRecti(0, 0, ar->winx, 8 * UI_DPI_FAC);
|
||||
}
|
||||
|
||||
void ED_region_cache_draw_curfra_label(const int framenr, const float x, const float y)
|
||||
{
|
||||
uiStyle *style = UI_GetStyle();
|
||||
int fontid = style->widget.uifont_id;
|
||||
char numstr[32];
|
||||
float font_dims[2] = {0.0f, 0.0f};
|
||||
|
||||
/* frame number */
|
||||
BLF_size(fontid, 11.0f * U.pixelsize, U.dpi);
|
||||
BLI_snprintf(numstr, sizeof(numstr), "%d", framenr);
|
||||
|
||||
BLF_width_and_height(fontid, numstr, sizeof(numstr), &font_dims[0], &font_dims[1]);
|
||||
|
||||
glRecti(x, y, x + font_dims[0] + 6.0f, y + font_dims[1] + 4.0f);
|
||||
|
||||
UI_ThemeColor(TH_TEXT);
|
||||
BLF_position(fontid, x + 2.0f, y + 2.0f, 0.0f);
|
||||
BLF_draw(fontid, numstr, sizeof(numstr));
|
||||
}
|
||||
|
||||
void ED_region_cache_draw_cached_segments(const ARegion *ar, const int num_segments, const int *points, const int sfra, const int efra)
|
||||
{
|
||||
if (num_segments) {
|
||||
int a;
|
||||
|
||||
glColor4ub(128, 128, 255, 128);
|
||||
|
||||
for (a = 0; a < num_segments; a++) {
|
||||
float x1, x2;
|
||||
|
||||
x1 = (float)(points[a * 2] - sfra) / (efra - sfra + 1) * ar->winx;
|
||||
x2 = (float)(points[a * 2 + 1] - sfra + 1) / (efra - sfra + 1) * ar->winx;
|
||||
|
||||
glRecti(x1, 0, x2, 8 * UI_DPI_FAC);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -76,26 +76,6 @@
|
||||
|
||||
/*********************** main area drawing *************************/
|
||||
|
||||
void clip_draw_curfra_label(const int framenr, const float x, const float y)
|
||||
{
|
||||
uiStyle *style = UI_GetStyle();
|
||||
int fontid = style->widget.uifont_id;
|
||||
char numstr[32];
|
||||
float font_dims[2] = {0.0f, 0.0f};
|
||||
|
||||
/* frame number */
|
||||
BLF_size(fontid, 11.0f * U.pixelsize, U.dpi);
|
||||
BLI_snprintf(numstr, sizeof(numstr), "%d", framenr);
|
||||
|
||||
BLF_width_and_height(fontid, numstr, sizeof(numstr), &font_dims[0], &font_dims[1]);
|
||||
|
||||
glRecti(x, y, x + font_dims[0] + 6.0f, y + font_dims[1] + 4.0f);
|
||||
|
||||
UI_ThemeColor(TH_TEXT);
|
||||
BLF_position(fontid, x + 2.0f, y + 2.0f, 0.0f);
|
||||
BLF_draw(fontid, numstr, sizeof(numstr));
|
||||
}
|
||||
|
||||
static void draw_keyframe(int frame, int cfra, int sfra, float framelen, int width)
|
||||
{
|
||||
int height = (frame == cfra) ? 22 : 10;
|
||||
@@ -183,23 +163,11 @@ static void draw_movieclip_cache(SpaceClip *sc, ARegion *ar, MovieClip *clip, Sc
|
||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
|
||||
/* cache background */
|
||||
glColor4ub(128, 128, 255, 64);
|
||||
glRecti(0, 0, ar->winx, 8 * UI_DPI_FAC);
|
||||
ED_region_cache_draw_background(ar);
|
||||
|
||||
/* cached segments -- could be usefu lto debug caching strategies */
|
||||
BKE_movieclip_get_cache_segments(clip, &sc->user, &totseg, &points);
|
||||
if (totseg) {
|
||||
glColor4ub(128, 128, 255, 128);
|
||||
|
||||
for (a = 0; a < totseg; a++) {
|
||||
float x1, x2;
|
||||
|
||||
x1 = (points[a * 2] - sfra) / (efra - sfra + 1) * ar->winx;
|
||||
x2 = (points[a * 2 + 1] - sfra + 1) / (efra - sfra + 1) * ar->winx;
|
||||
|
||||
glRecti(x1, 0, x2, 8 * UI_DPI_FAC);
|
||||
}
|
||||
}
|
||||
ED_region_cache_draw_cached_segments(ar, totseg, points, sfra, efra);
|
||||
|
||||
/* track */
|
||||
if (act_track || act_plane_track) {
|
||||
@@ -271,7 +239,7 @@ static void draw_movieclip_cache(SpaceClip *sc, ARegion *ar, MovieClip *clip, Sc
|
||||
UI_ThemeColor(TH_CFRAME);
|
||||
glRecti(x, 0, x + ceilf(framelen), 8 * UI_DPI_FAC);
|
||||
|
||||
clip_draw_curfra_label(sc->user.framenr, x, 8.0f * UI_DPI_FAC);
|
||||
ED_region_cache_draw_curfra_label(sc->user.framenr, x, 8.0f * UI_DPI_FAC);
|
||||
|
||||
/* solver keyframes */
|
||||
glColor4ub(175, 255, 0, 255);
|
||||
|
@@ -72,7 +72,6 @@ void CLIP_OT_dopesheet_view_all(struct wmOperatorType *ot);
|
||||
/* clip_draw.c */
|
||||
void clip_draw_main(const struct bContext *C, struct SpaceClip *sc, struct ARegion *ar);
|
||||
void clip_draw_grease_pencil(struct bContext *C, int onlyv2d);
|
||||
void clip_draw_curfra_label(const int framenr, const float x, const float y);
|
||||
void clip_draw_cache_and_notes(const bContext *C, SpaceClip *sc, ARegion *ar);
|
||||
|
||||
/* clip_editor.c */
|
||||
|
@@ -319,7 +319,7 @@ void clip_draw_cfra(SpaceClip *sc, ARegion *ar, Scene *scene)
|
||||
UI_view2d_getscale(v2d, &xscale, &yscale);
|
||||
glScalef(1.0f / xscale, 1.0f, 1.0f);
|
||||
|
||||
clip_draw_curfra_label(sc->user.framenr, (float)sc->user.framenr * xscale, 18);
|
||||
ED_region_cache_draw_curfra_label(sc->user.framenr, (float)sc->user.framenr * xscale, 18);
|
||||
|
||||
/* restore view transform */
|
||||
glScalef(xscale, 1.0, 1.0);
|
||||
|
@@ -40,6 +40,7 @@
|
||||
#include "DNA_scene_types.h"
|
||||
#include "DNA_screen_types.h"
|
||||
#include "DNA_brush_types.h"
|
||||
#include "DNA_mask_types.h"
|
||||
|
||||
#include "PIL_time.h"
|
||||
|
||||
@@ -52,6 +53,7 @@
|
||||
#include "IMB_imbuf.h"
|
||||
#include "IMB_imbuf_types.h"
|
||||
#include "IMB_colormanagement.h"
|
||||
#include "IMB_moviecache.h"
|
||||
|
||||
#include "BKE_context.h"
|
||||
#include "BKE_global.h"
|
||||
@@ -65,6 +67,7 @@
|
||||
|
||||
#include "ED_gpencil.h"
|
||||
#include "ED_image.h"
|
||||
#include "ED_mask.h"
|
||||
#include "ED_screen.h"
|
||||
|
||||
#include "UI_interface.h"
|
||||
@@ -884,3 +887,48 @@ void draw_image_main(const bContext *C, ARegion *ar)
|
||||
if (ima && show_render)
|
||||
draw_render_info(scene, ima, ar, zoomx, zoomy);
|
||||
}
|
||||
|
||||
void draw_image_cache(const bContext *C, ARegion *ar)
|
||||
{
|
||||
SpaceImage *sima = CTX_wm_space_image(C);
|
||||
Scene *scene = CTX_data_scene(C);
|
||||
Image *image = ED_space_image(sima);
|
||||
float x, cfra = CFRA, sfra = SFRA, efra = EFRA, framelen = ar->winx / (efra - sfra + 1);
|
||||
Mask *mask = NULL;
|
||||
|
||||
if (sima->mode == SI_MODE_MASK) {
|
||||
mask = ED_space_image_get_mask(sima);
|
||||
}
|
||||
|
||||
if (image == NULL && mask == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
glEnable(GL_BLEND);
|
||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
|
||||
/* Draw cache background. */
|
||||
ED_region_cache_draw_background(ar);
|
||||
|
||||
/* Draw cached segments. */
|
||||
if (image != NULL && image->cache != NULL && ELEM(image->source, IMA_SRC_SEQUENCE, IMA_SRC_MOVIE)) {
|
||||
int num_segments = 0;
|
||||
int *points = NULL;
|
||||
|
||||
IMB_moviecache_get_cache_segments(image->cache, IMB_PROXY_NONE, 0, &num_segments, &points);
|
||||
ED_region_cache_draw_cached_segments(ar, num_segments, points, sfra + sima->iuser.offset, efra + sima->iuser.offset);
|
||||
}
|
||||
|
||||
glDisable(GL_BLEND);
|
||||
|
||||
/* Draw current frame. */
|
||||
x = (cfra - sfra) / (efra - sfra + 1) * ar->winx;
|
||||
|
||||
UI_ThemeColor(TH_CFRAME);
|
||||
glRecti(x, 0, x + ceilf(framelen), 8 * UI_DPI_FAC);
|
||||
ED_region_cache_draw_curfra_label(cfra, x, 8.0f * UI_DPI_FAC);
|
||||
|
||||
if (mask != NULL) {
|
||||
ED_mask_draw_frames(mask, ar, cfra, sfra, efra);
|
||||
}
|
||||
}
|
||||
|
@@ -53,6 +53,7 @@ extern const char *image_context_dir[]; /* doc access */
|
||||
|
||||
/* image_draw.c */
|
||||
void draw_image_main(const struct bContext *C, struct ARegion *ar);
|
||||
void draw_image_cache(const struct bContext *C, struct ARegion *ar);
|
||||
void draw_image_grease_pencil(struct bContext *C, bool onlyv2d);
|
||||
void draw_image_sample_line(struct SpaceImage *sima);
|
||||
|
||||
|
@@ -739,13 +739,13 @@ static void image_main_area_draw(const bContext *C, ARegion *ar)
|
||||
true, false,
|
||||
NULL, C);
|
||||
|
||||
ED_mask_draw_frames(mask, ar, CFRA, mask->sfra, mask->efra);
|
||||
|
||||
UI_view2d_view_ortho(v2d);
|
||||
draw_image_cursor(ar, sima->cursor);
|
||||
UI_view2d_view_restore(C);
|
||||
}
|
||||
|
||||
draw_image_cache(C, ar);
|
||||
|
||||
/* scrollers? */
|
||||
#if 0
|
||||
scrollers = UI_view2d_scrollers_calc(C, v2d, V2D_UNIT_VALUES, V2D_GRID_CLAMP, V2D_ARG_DUMMY, V2D_ARG_DUMMY);
|
||||
|
Reference in New Issue
Block a user