static void vectorscope_put_cross(unsigned char r, unsigned char g, unsigned char b, char *tgt, int w, int h, int size) { float rgb[3], yuv[3]; char *p; int x = 0; int y = 0; rgb[0] = (float)r / 255.0f; rgb[1] = (float)g / 255.0f; rgb[2] = (float)b / 255.0f; rgb_to_yuv_normalized(rgb, yuv); p = tgt + 4 * (w * (int) ((yuv[2] * (h - 3) + 1)) + (int) ((yuv[1] * (w - 3) + 1))); if (r == 0 && g == 0 && b == 0) { r = 255; } for (y = -size; y <= size; y++) { for (x = -size; x <= size; x++) { char *q = p + 4 * (y * w + x); q[0] = r; q[1] = g; q[2] = b; q[3] = 255; } } }
static ImBuf *make_vectorscope_view_from_ibuf_float(ImBuf *ibuf) { ImBuf *rval = IMB_allocImBuf(515, 515, 32, IB_rect); int x, y; float *src = ibuf->rect_float; char *tgt = (char *) rval->rect; float rgb[3], yuv[3]; int w = 515; int h = 515; float scope_gamma = 0.2; unsigned char wtable[256]; for (x = 0; x < 256; x++) { wtable[x] = (unsigned char) (pow(((float) x + 1) / 256, scope_gamma) * 255); } for (x = 0; x <= 255; x++) { vectorscope_put_cross(255, 0, 255 - x, tgt, w, h, 1); vectorscope_put_cross(255, x, 0, tgt, w, h, 1); vectorscope_put_cross(255 - x, 255, 0, tgt, w, h, 1); vectorscope_put_cross(0, 255, x, tgt, w, h, 1); vectorscope_put_cross(0, 255 - x, 255, tgt, w, h, 1); vectorscope_put_cross(x, 0, 255, tgt, w, h, 1); } for (y = 0; y < ibuf->y; y++) { for (x = 0; x < ibuf->x; x++) { float *src1 = src + 4 * (ibuf->x * y + x); char *p; memcpy(rgb, src1, 3 * sizeof(float)); CLAMP(rgb[0], 0.0f, 1.0f); CLAMP(rgb[1], 0.0f, 1.0f); CLAMP(rgb[2], 0.0f, 1.0f); rgb_to_yuv_normalized(rgb, yuv); p = tgt + 4 * (w * (int) ((yuv[2] * (h - 3) + 1)) + (int) ((yuv[1] * (w - 3) + 1))); scope_put_pixel(wtable, (unsigned char *)p); } } vectorscope_put_cross(0, 0, 0, tgt, w, h, 3); return rval; }