diff --git a/cuburn/code/filtering.py b/cuburn/code/filtering.py index bd1ae73..8746090 100644 --- a/cuburn/code/filtering.py +++ b/cuburn/code/filtering.py @@ -4,8 +4,10 @@ from cuburn.code.util import * class ColorClip(HunkOCode): defs = """ __global__ -void colorclip(float4 *pixbuf, float gamma, float vibrancy, float highpow) { - // TODO: test if over an edge of the framebuffer +void colorclip(float4 *pixbuf, float gamma, float vibrancy, float highpow, + float linrange, float lingam) { + // TODO: test if over an edge of the framebuffer - currently gutters are + // used and up to 256 pixels are ignored, which breaks when width<256 int i = blockDim.x * blockIdx.x + threadIdx.x; float4 pix = pixbuf[i]; @@ -13,8 +15,12 @@ void colorclip(float4 *pixbuf, float gamma, float vibrancy, float highpow) { float4 opix = pix; - // TODO: linearized bottom range - float alpha = powf(pix.w, gamma); + float alpha = pow(pix.w, gamma); + if (pix.w < linrange) { + float frac = pix.w / linrange; + alpha = (1.0f - frac) * pix.w * lingam / linrange + frac * alpha; + } + float ls = vibrancy * alpha / pix.w; float maxc = fmaxf(pix.x, fmaxf(pix.y, pix.z)); diff --git a/cuburn/render.py b/cuburn/render.py index 351315c..feea1fb 100644 --- a/cuburn/render.py +++ b/cuburn/render.py @@ -308,16 +308,18 @@ class _AnimRenderer(object): self.stream) self.stream.synchronize() - - n = np.float32(self.ncps) - gam = np.float32(n / gam) - vib = np.float32(vib / n) - hipow = np.float32(hipow / n) + f = np.float32 + n = f(self.ncps) + gam = f(n / gam) + vib = f(vib / n) + hipow = f(hipow / n) + lin = f(cen_cp.gam_lin_thresh) + lingam = f(math.pow(cen_cp.gam_lin_thresh, gam)) # TODO: get block size from colorclip class? It actually does not # depend on that being the case color_fun = a.mod.get_function("colorclip") - color_fun(self.d_out, gam, vib, hipow, + color_fun(self.d_out, gam, vib, hipow, lin, lingam, block=(256, 1, 1), grid=(self.nbins / 256, 1), stream=self.stream)