From 9cc8d50a046f4029df60a279dd86074b77c0da4a Mon Sep 17 00:00:00 2001 From: jim man Date: Thu, 29 Jul 2021 12:46:24 +0200 Subject: cleanup: editor_image : Remove unused draw functions These functions are unused currently.. Reviewed By: deadpin, jbakker Differential Revision: https://developer.blender.org/D11968 --- source/blender/editors/space_image/image_draw.c | 475 ---------------------- source/blender/editors/space_image/image_intern.h | 2 - 2 files changed, 477 deletions(-) (limited to 'source/blender/editors/space_image') diff --git a/source/blender/editors/space_image/image_draw.c b/source/blender/editors/space_image/image_draw.c index dc693b25107..92ceb00d5c0 100644 --- a/source/blender/editors/space_image/image_draw.c +++ b/source/blender/editors/space_image/image_draw.c @@ -460,258 +460,6 @@ void ED_image_draw_info(Scene *scene, BLF_draw_ascii(blf_mono_font, str, sizeof(str)); } } - -/* image drawing */ -static void sima_draw_zbuf_pixels( - float x1, float y1, int rectx, int recty, const int *rect, float zoomx, float zoomy) -{ - const float red[4] = {1.0f, 0.0f, 0.0f, 0.0f}; - - /* Very slow! */ - float *rectf = MEM_mallocN(rectx * recty * sizeof(float), "temp"); - for (int a = rectx * recty - 1; a >= 0; a--) { - /* zbuffer values are signed, so we need to shift color range */ - rectf[a] = rect[a] * 0.5f + 0.5f; - } - - IMMDrawPixelsTexState state = immDrawPixelsTexSetup(GPU_SHADER_2D_IMAGE_SHUFFLE_COLOR); - GPU_shader_uniform_vector( - state.shader, GPU_shader_get_uniform(state.shader, "shuffle"), 4, 1, red); - - immDrawPixelsTex(&state, x1, y1, rectx, recty, GPU_R16F, false, rectf, zoomx, zoomy, NULL); - - MEM_freeN(rectf); -} - -static void sima_draw_zbuffloat_pixels(Scene *scene, - float x1, - float y1, - int rectx, - int recty, - const float *rect_float, - float zoomx, - float zoomy) -{ - float bias, scale, *rectf, clip_end; - int a; - const float red[4] = {1.0f, 0.0f, 0.0f, 0.0f}; - - if (scene->camera && scene->camera->type == OB_CAMERA) { - bias = ((Camera *)scene->camera->data)->clip_start; - clip_end = ((Camera *)scene->camera->data)->clip_end; - scale = 1.0f / (clip_end - bias); - } - else { - bias = 0.1f; - scale = 0.01f; - clip_end = 100.0f; - } - - rectf = MEM_mallocN(rectx * recty * sizeof(float), "temp"); - for (a = rectx * recty - 1; a >= 0; a--) { - if (rect_float[a] > clip_end) { - rectf[a] = 0.0f; - } - else if (rect_float[a] < bias) { - rectf[a] = 1.0f; - } - else { - rectf[a] = 1.0f - (rect_float[a] - bias) * scale; - rectf[a] *= rectf[a]; - } - } - - IMMDrawPixelsTexState state = immDrawPixelsTexSetup(GPU_SHADER_2D_IMAGE_SHUFFLE_COLOR); - GPU_shader_uniform_vector( - state.shader, GPU_shader_get_uniform(state.shader, "shuffle"), 4, 1, red); - - immDrawPixelsTex(&state, x1, y1, rectx, recty, GPU_R16F, false, rectf, zoomx, zoomy, NULL); - - MEM_freeN(rectf); -} - -static void draw_udim_label(ARegion *region, float fx, float fy, const char *label) -{ - if (label == NULL || !label[0]) { - return; - } - - /* find window pixel coordinates of origin */ - int x, y; - UI_view2d_view_to_region(®ion->v2d, fx, fy, &x, &y); - - GPU_blend(GPU_BLEND_ALPHA); - - int textwidth = BLF_width(blf_mono_font, label, strlen(label)) + 10; - float stepx = BLI_rcti_size_x(®ion->v2d.mask) / BLI_rctf_size_x(®ion->v2d.cur); - float opacity; - if (textwidth < 0.5f * (stepx - 10)) { - opacity = 1.0f; - } - else if (textwidth < (stepx - 10)) { - opacity = 2.0f - 2.0f * (textwidth / (stepx - 10)); - } - else { - opacity = 0.0f; - } - BLF_color4ub(blf_mono_font, 220, 220, 220, 150 * opacity); - BLF_position(blf_mono_font, (int)(x + 10), (int)(y + 10), 0); - BLF_draw_ascii(blf_mono_font, label, strlen(label)); - - GPU_blend(GPU_BLEND_NONE); -} - -static void draw_image_buffer(const bContext *C, - SpaceImage *sima, - ARegion *region, - Scene *scene, - ImBuf *ibuf, - float fx, - float fy, - float zoomx, - float zoomy) -{ - /* Image are still drawn in display space. */ - GPUFrameBuffer *fb = GPU_framebuffer_active_get(); - GPU_framebuffer_bind_no_srgb(fb); - - int x, y; - int sima_flag = sima->flag & ED_space_image_get_display_channel_mask(ibuf); - - /* find window pixel coordinates of origin */ - UI_view2d_view_to_region(®ion->v2d, fx, fy, &x, &y); - - /* this part is generic image display */ - if (sima_flag & SI_SHOW_ZBUF && (ibuf->zbuf || ibuf->zbuf_float || (ibuf->channels == 1))) { - if (ibuf->zbuf) { - sima_draw_zbuf_pixels(x, y, ibuf->x, ibuf->y, ibuf->zbuf, zoomx, zoomy); - } - else if (ibuf->zbuf_float) { - sima_draw_zbuffloat_pixels(scene, x, y, ibuf->x, ibuf->y, ibuf->zbuf_float, zoomx, zoomy); - } - else if (ibuf->channels == 1) { - sima_draw_zbuffloat_pixels(scene, x, y, ibuf->x, ibuf->y, ibuf->rect_float, zoomx, zoomy); - } - } - else { - int clip_max_x, clip_max_y; - UI_view2d_view_to_region( - ®ion->v2d, region->v2d.cur.xmax, region->v2d.cur.ymax, &clip_max_x, &clip_max_y); - - if (sima_flag & SI_USE_ALPHA) { - imm_draw_box_checker_2d(x, y, x + ibuf->x * zoomx, y + ibuf->y * zoomy); - - GPU_blend(GPU_BLEND_ALPHA); - } - - /* If RGBA display with color management */ - if ((sima_flag & (SI_SHOW_R | SI_SHOW_G | SI_SHOW_B | SI_SHOW_ALPHA)) == 0) { - - ED_draw_imbuf_ctx_clipping(C, ibuf, x, y, false, 0, 0, clip_max_x, clip_max_y, zoomx, zoomy); - } - else { - float shuffle[4] = {0.0f, 0.0f, 0.0f, 0.0f}; - uchar *display_buffer; - void *cache_handle; - ColorManagedViewSettings *view_settings; - ColorManagedDisplaySettings *display_settings; - - if (sima_flag & SI_SHOW_R) { - shuffle[0] = 1.0f; - } - else if (sima_flag & SI_SHOW_G) { - shuffle[1] = 1.0f; - } - else if (sima_flag & SI_SHOW_B) { - shuffle[2] = 1.0f; - } - else if (sima_flag & SI_SHOW_ALPHA) { - shuffle[3] = 1.0f; - } - - IMMDrawPixelsTexState state = immDrawPixelsTexSetup(GPU_SHADER_2D_IMAGE_SHUFFLE_COLOR); - GPU_shader_uniform_vector( - state.shader, GPU_shader_get_uniform(state.shader, "shuffle"), 4, 1, shuffle); - - IMB_colormanagement_display_settings_from_ctx(C, &view_settings, &display_settings); - display_buffer = IMB_display_buffer_acquire( - ibuf, view_settings, display_settings, &cache_handle); - - if (display_buffer) { - immDrawPixelsTex_clipping(&state, - x, - y, - ibuf->x, - ibuf->y, - GPU_RGBA8, - false, - display_buffer, - 0, - 0, - clip_max_x, - clip_max_y, - zoomx, - zoomy, - NULL); - } - - IMB_display_buffer_release(cache_handle); - } - - if (sima_flag & SI_USE_ALPHA) { - GPU_blend(GPU_BLEND_NONE); - } - } - - GPU_framebuffer_bind(fb); -} - -static void draw_image_buffer_repeated(const bContext *C, - SpaceImage *sima, - ARegion *region, - Scene *scene, - ImBuf *ibuf, - float zoomx, - float zoomy) -{ - const double time_current = PIL_check_seconds_timer(); - - const int xmax = ceil(region->v2d.cur.xmax); - const int ymax = ceil(region->v2d.cur.ymax); - const int xmin = floor(region->v2d.cur.xmin); - const int ymin = floor(region->v2d.cur.ymin); - - for (int x = xmin; x < xmax; x++) { - for (int y = ymin; y < ymax; y++) { - draw_image_buffer(C, sima, region, scene, ibuf, x, y, zoomx, zoomy); - - /* only draw until running out of time */ - if ((PIL_check_seconds_timer() - time_current) > 0.25) { - return; - } - } - } -} - -/* draw uv edit */ - -/* draw grease pencil */ -void draw_image_grease_pencil(bContext *C, bool onlyv2d) -{ - /* draw in View2D space? */ - if (onlyv2d) { - /* draw grease-pencil ('image' strokes) */ - ED_annotation_draw_2dimage(C); - } - else { - /* assume that UI_view2d_restore(C) has been called... */ - // SpaceImage *sima = (SpaceImage *)CTX_wm_space_data(C); - - /* draw grease-pencil ('screen' strokes) */ - ED_annotation_draw_view2d(C, 0); - } -} - void draw_image_sample_line(SpaceImage *sima) { if (sima->sample_line_hist.flag & HISTO_FLAG_SAMPLELINE) { @@ -742,229 +490,6 @@ void draw_image_sample_line(SpaceImage *sima) } } -static void draw_udim_tile_grid(uint pos_attr, - uint color_attr, - ARegion *region, - int x, - int y, - float stepx, - float stepy, - const float color[3]) -{ - float x1, y1; - UI_view2d_view_to_region_fl(®ion->v2d, x, y, &x1, &y1); - const int gridpos[5][2] = {{0, 0}, {0, 1}, {1, 1}, {1, 0}, {0, 0}}; - for (int i = 0; i < 4; i++) { - immAttr3fv(color_attr, color); - immVertex2f(pos_attr, x1 + gridpos[i][0] * stepx, y1 + gridpos[i][1] * stepy); - immAttr3fv(color_attr, color); - immVertex2f(pos_attr, x1 + gridpos[i + 1][0] * stepx, y1 + gridpos[i + 1][1] * stepy); - } -} - -static void draw_udim_tile_grids(ARegion *region, SpaceImage *sima, Image *ima) -{ - int num_tiles; - if (ima != NULL) { - num_tiles = BLI_listbase_count(&ima->tiles); - - if (ima->source != IMA_SRC_TILED) { - return; - } - } - else { - num_tiles = sima->tile_grid_shape[0] * sima->tile_grid_shape[1]; - } - - float stepx = BLI_rcti_size_x(®ion->v2d.mask) / BLI_rctf_size_x(®ion->v2d.cur); - float stepy = BLI_rcti_size_y(®ion->v2d.mask) / BLI_rctf_size_y(®ion->v2d.cur); - - GPUVertFormat *format = immVertexFormat(); - uint pos = GPU_vertformat_attr_add(format, "pos", GPU_COMP_F32, 2, GPU_FETCH_FLOAT); - uint color = GPU_vertformat_attr_add(format, "color", GPU_COMP_F32, 3, GPU_FETCH_FLOAT); - - immBindBuiltinProgram(GPU_SHADER_2D_FLAT_COLOR); - immBegin(GPU_PRIM_LINES, 8 * num_tiles); - - float theme_color[3], selected_color[3]; - UI_GetThemeColorShade3fv(TH_GRID, 60.0f, theme_color); - UI_GetThemeColor3fv(TH_FACE_SELECT, selected_color); - - if (ima != NULL) { - ImageTile *cur_tile = BLI_findlink(&ima->tiles, ima->active_tile_index); - - LISTBASE_FOREACH (ImageTile *, tile, &ima->tiles) { - if (tile != cur_tile) { - int x = (tile->tile_number - 1001) % 10; - int y = (tile->tile_number - 1001) / 10; - draw_udim_tile_grid(pos, color, region, x, y, stepx, stepy, theme_color); - } - } - - if (cur_tile != NULL) { - int cur_x = (cur_tile->tile_number - 1001) % 10; - int cur_y = (cur_tile->tile_number - 1001) / 10; - draw_udim_tile_grid(pos, color, region, cur_x, cur_y, stepx, stepy, selected_color); - } - } - else { - for (int y = 0; y < sima->tile_grid_shape[1]; y++) { - for (int x = 0; x < sima->tile_grid_shape[0]; x++) { - draw_udim_tile_grid(pos, color, region, x, y, stepx, stepy, theme_color); - } - } - } - - immEnd(); - immUnbindProgram(); -} - -/* draw main image region */ - -void draw_image_main(const bContext *C, ARegion *region) -{ - SpaceImage *sima = CTX_wm_space_image(C); - Scene *scene = CTX_data_scene(C); - Image *ima; - ImBuf *ibuf; - float zoomx, zoomy; - bool show_viewer, show_stereo3d, show_multilayer; - void *lock; - - /* XXX can we do this in refresh? */ -#if 0 - what_image(sima); - - if (sima->image) { - ED_image_get_aspect(sima->image, &xuser_asp, &yuser_asp); - - /* UGLY hack? until now iusers worked fine... but for flipbook viewer we need this */ - if (sima->image->type == IMA_TYPE_COMPOSITE) { - ImageUser *iuser = ntree_get_active_iuser(scene->nodetree); - if (iuser) { - BKE_image_user_calc_imanr(iuser, scene->r.cfra, 0); - sima->iuser = *iuser; - } - } - /* and we check for spare */ - ibuf = ED_space_image_buffer(sima); - } -#endif - - /* retrieve the image and information about it */ - ima = ED_space_image(sima); - ED_space_image_get_zoom(sima, region, &zoomx, &zoomy); - - /* Tag image as in active use for garbage collector. */ - if (ima) { - BKE_image_tag_time(ima); - } - - show_viewer = (ima && ima->source == IMA_SRC_VIEWER) != 0; - show_stereo3d = (ima && BKE_image_is_stereo(ima) && (sima->iuser.flag & IMA_SHOW_STEREO)); - show_multilayer = ima && BKE_image_is_multilayer(ima); - - if (show_viewer) { - /* use locked draw for drawing viewer image buffer since the compositor - * is running in separated thread and compositor could free this buffers. - * other images are not modifying in such a way so they does not require - * lock (sergey) - */ - BLI_thread_lock(LOCK_DRAW_IMAGE); - } - - if (show_stereo3d) { - if (show_multilayer) { - /* Update multi-index and pass for the current eye. */ - BKE_image_multilayer_index(ima->rr, &sima->iuser); - } - else { - BKE_image_multiview_index(ima, &sima->iuser); - } - } - - ibuf = ED_space_image_acquire_buffer(sima, &lock, 0); - - int main_w = 0; - int main_h = 0; - - /* draw the image or grid */ - if (ibuf == NULL) { - if (ima != NULL) { - LISTBASE_FOREACH (ImageTile *, tile, &ima->tiles) { - int x = (tile->tile_number - 1001) % 10; - int y = (tile->tile_number - 1001) / 10; - ED_region_grid_draw(region, zoomx, zoomy, x, y); - } - } - else { - for (int y = 0; y < sima->tile_grid_shape[1]; y++) { - for (int x = 0; x < sima->tile_grid_shape[0]; x++) { - ED_region_grid_draw(region, zoomx, zoomy, x, y); - } - } - } - } - else { - if (sima->flag & SI_DRAW_TILE) { - draw_image_buffer_repeated(C, sima, region, scene, ibuf, zoomx, zoomy); - } - else { - main_w = ibuf->x; - main_h = ibuf->y; - - draw_image_buffer(C, sima, region, scene, ibuf, 0.0f, 0.0f, zoomx, zoomy); - if (ima->source == IMA_SRC_TILED) { - ImageTile *tile = BKE_image_get_tile(ima, 0); - char label[sizeof(tile->label)]; - BKE_image_get_tile_label(ima, tile, label, sizeof(label)); - draw_udim_label(region, 0.0f, 0.0f, label); - } - } - - if (sima->flag & SI_DRAW_METADATA) { - int x, y; - rctf frame; - - BLI_rctf_init(&frame, 0.0f, ibuf->x, 0.0f, ibuf->y); - UI_view2d_view_to_region(®ion->v2d, 0.0f, 0.0f, &x, &y); - - ED_region_image_metadata_draw(x, y, ibuf, &frame, zoomx, zoomy); - } - } - - ED_space_image_release_buffer(sima, ibuf, lock); - - if (ima != NULL && ima->source == IMA_SRC_TILED) { - LISTBASE_FOREACH (ImageTile *, tile, &ima->tiles) { - if (tile->tile_number == 1001) { - continue; - } - - ibuf = ED_space_image_acquire_buffer(sima, &lock, tile->tile_number); - if (ibuf != NULL) { - int x_pos = (tile->tile_number - 1001) % 10; - int y_pos = (tile->tile_number - 1001) / 10; - char label[sizeof(tile->label)]; - BKE_image_get_tile_label(ima, tile, label, sizeof(label)); - - float tile_zoomx = (zoomx * main_w) / ibuf->x; - float tile_zoomy = (zoomy * main_h) / ibuf->y; - draw_image_buffer(C, sima, region, scene, ibuf, x_pos, y_pos, tile_zoomx, tile_zoomy); - draw_udim_label(region, x_pos, y_pos, label); - } - ED_space_image_release_buffer(sima, ibuf, lock); - } - } - - draw_udim_tile_grids(region, sima, ima); - draw_image_main_helpers(C, region); - - if (show_viewer) { - BLI_thread_unlock(LOCK_DRAW_IMAGE); - } -} - void draw_image_main_helpers(const bContext *C, ARegion *region) { SpaceImage *sima = CTX_wm_space_image(C); diff --git a/source/blender/editors/space_image/image_intern.h b/source/blender/editors/space_image/image_intern.h index d302f099772..6af0f3a416b 100644 --- a/source/blender/editors/space_image/image_intern.h +++ b/source/blender/editors/space_image/image_intern.h @@ -36,10 +36,8 @@ struct wmOperatorType; extern const char *image_context_dir[]; /* doc access */ /* image_draw.c */ -void draw_image_main(const struct bContext *C, struct ARegion *region); void draw_image_main_helpers(const struct bContext *C, struct ARegion *region); void draw_image_cache(const struct bContext *C, struct ARegion *region); -void draw_image_grease_pencil(struct bContext *C, bool onlyv2d); void draw_image_sample_line(struct SpaceImage *sima); /* image_ops.c */ -- cgit v1.2.3