static void sampleImageAtLocation(ImBuf *ibuf, float x, float y, PixelSampler sampler, bool make_linear_rgb, float color[4]) { if (ibuf->rect_float) { switch (sampler) { case COM_PS_NEAREST: nearest_interpolation_color(ibuf, NULL, color, x, y); break; case COM_PS_BILINEAR: bilinear_interpolation_color(ibuf, NULL, color, x, y); break; case COM_PS_BICUBIC: bicubic_interpolation_color(ibuf, NULL, color, x, y); break; } } else { unsigned char byte_color[4]; switch (sampler) { case COM_PS_NEAREST: nearest_interpolation_color(ibuf, byte_color, NULL, x, y); break; case COM_PS_BILINEAR: bilinear_interpolation_color(ibuf, byte_color, NULL, x, y); break; case COM_PS_BICUBIC: bicubic_interpolation_color(ibuf, byte_color, NULL, x, y); break; } rgba_uchar_to_float(color, byte_color); if (make_linear_rgb) { IMB_colormanagement_colorspace_to_scene_linear_v4(color, false, ibuf->rect_colorspace); } } }
static void sample_apply(bContext *C, wmOperator *op, const wmEvent *event) { Main *bmain = CTX_data_main(C); Scene *scene = CTX_data_scene(C); SpaceSeq *sseq = (SpaceSeq *) CTX_wm_space_data(C); ARegion *ar = CTX_wm_region(C); ImBuf *ibuf = sequencer_ibuf_get(bmain, scene, sseq, CFRA, 0); ImageSampleInfo *info = op->customdata; float fx, fy; if (ibuf == NULL) { IMB_freeImBuf(ibuf); info->draw = 0; return; } UI_view2d_region_to_view(&ar->v2d, event->mval[0], event->mval[1], &fx, &fy); fx += (float) ibuf->x / 2.0f; fy += (float) ibuf->y / 2.0f; if (fx >= 0.0f && fy >= 0.0f && fx < ibuf->x && fy < ibuf->y) { const float *fp; unsigned char *cp; int x = (int) fx, y = (int) fy; info->x = x; info->y = y; info->draw = 1; info->channels = ibuf->channels; info->colp = NULL; info->colfp = NULL; if (ibuf->rect) { cp = (unsigned char *)(ibuf->rect + y * ibuf->x + x); info->col[0] = cp[0]; info->col[1] = cp[1]; info->col[2] = cp[2]; info->col[3] = cp[3]; info->colp = info->col; info->colf[0] = (float)cp[0] / 255.0f; info->colf[1] = (float)cp[1] / 255.0f; info->colf[2] = (float)cp[2] / 255.0f; info->colf[3] = (float)cp[3] / 255.0f; info->colfp = info->colf; copy_v4_v4(info->linearcol, info->colf); IMB_colormanagement_colorspace_to_scene_linear_v4(info->linearcol, false, ibuf->rect_colorspace); info->color_manage = true; } if (ibuf->rect_float) { fp = (ibuf->rect_float + (ibuf->channels) * (y * ibuf->x + x)); info->colf[0] = fp[0]; info->colf[1] = fp[1]; info->colf[2] = fp[2]; info->colf[3] = fp[3]; info->colfp = info->colf; /* sequencer's image buffers are in non-linear space, need to make them linear */ copy_v4_v4(info->linearcol, info->colf); BKE_sequencer_pixel_from_sequencer_space_v4(scene, info->linearcol); info->color_manage = true; } } else { info->draw = 0; } IMB_freeImBuf(ibuf); ED_area_tag_redraw(CTX_wm_area(C)); }
static void sample_apply(bContext *C, wmOperator *op, const wmEvent *event) { SpaceNode *snode = CTX_wm_space_node(C); ARegion *ar = CTX_wm_region(C); ImageSampleInfo *info = op->customdata; void *lock; Image *ima; ImBuf *ibuf; float fx, fy, bufx, bufy; ima = BKE_image_verify_viewer(IMA_TYPE_COMPOSITE, "Viewer Node"); ibuf = BKE_image_acquire_ibuf(ima, NULL, &lock); if (!ibuf) { info->draw = 0; return; } if (!ibuf->rect) { IMB_rect_from_float(ibuf); } /* map the mouse coords to the backdrop image space */ bufx = ibuf->x * snode->zoom; bufy = ibuf->y * snode->zoom; fx = (bufx > 0.0f ? ((float)event->mval[0] - 0.5f * ar->winx - snode->xof) / bufx + 0.5f : 0.0f); fy = (bufy > 0.0f ? ((float)event->mval[1] - 0.5f * ar->winy - snode->yof) / bufy + 0.5f : 0.0f); if (fx >= 0.0f && fy >= 0.0f && fx < 1.0f && fy < 1.0f) { float *fp; unsigned char *cp; int x = (int)(fx * ibuf->x), y = (int)(fy * ibuf->y); CLAMP(x, 0, ibuf->x - 1); CLAMP(y, 0, ibuf->y - 1); info->x = x; info->y = y; info->draw = 1; info->channels = ibuf->channels; info->zp = NULL; info->zfp = NULL; if (ibuf->rect) { cp = (unsigned char *)(ibuf->rect + y * ibuf->x + x); info->col[0] = cp[0]; info->col[1] = cp[1]; info->col[2] = cp[2]; info->col[3] = cp[3]; info->colf[0] = (float)cp[0] / 255.0f; info->colf[1] = (float)cp[1] / 255.0f; info->colf[2] = (float)cp[2] / 255.0f; info->colf[3] = (float)cp[3] / 255.0f; copy_v4_v4(info->linearcol, info->colf); IMB_colormanagement_colorspace_to_scene_linear_v4(info->linearcol, false, ibuf->rect_colorspace); info->color_manage = TRUE; } if (ibuf->rect_float) { fp = (ibuf->rect_float + (ibuf->channels) * (y * ibuf->x + x)); info->colf[0] = fp[0]; info->colf[1] = fp[1]; info->colf[2] = fp[2]; info->colf[3] = fp[3]; info->color_manage = TRUE; } if (ibuf->zbuf) { info->z = ibuf->zbuf[y * ibuf->x + x]; info->zp = &info->z; } if (ibuf->zbuf_float) { info->zf = ibuf->zbuf_float[y * ibuf->x + x]; info->zfp = &info->zf; } ED_node_sample_set(info->colf); } else { info->draw = 0; ED_node_sample_set(NULL); } BKE_image_release_ibuf(ima, ibuf, lock); ED_area_tag_redraw(CTX_wm_area(C)); }