mirror of
				https://github.com/stevenrobertson/cuburn.git
				synced 2025-11-03 18:00:55 -05:00 
			
		
		
		
	Add gamma linearization (may be incorrect)
This commit is contained in:
		@ -4,8 +4,10 @@ from cuburn.code.util import *
 | 
				
			|||||||
class ColorClip(HunkOCode):
 | 
					class ColorClip(HunkOCode):
 | 
				
			||||||
    defs = """
 | 
					    defs = """
 | 
				
			||||||
__global__
 | 
					__global__
 | 
				
			||||||
void colorclip(float4 *pixbuf, float gamma, float vibrancy, float highpow) {
 | 
					void colorclip(float4 *pixbuf, float gamma, float vibrancy, float highpow,
 | 
				
			||||||
    // TODO: test if over an edge of the framebuffer
 | 
					               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;
 | 
					    int i = blockDim.x * blockIdx.x + threadIdx.x;
 | 
				
			||||||
    float4 pix = pixbuf[i];
 | 
					    float4 pix = pixbuf[i];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -13,8 +15,12 @@ void colorclip(float4 *pixbuf, float gamma, float vibrancy, float highpow) {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    float4 opix = pix;
 | 
					    float4 opix = pix;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // TODO: linearized bottom range
 | 
					    float alpha = pow(pix.w, gamma);
 | 
				
			||||||
    float alpha = powf(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 ls = vibrancy * alpha / pix.w;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    float maxc = fmaxf(pix.x, fmaxf(pix.y, pix.z));
 | 
					    float maxc = fmaxf(pix.x, fmaxf(pix.y, pix.z));
 | 
				
			||||||
 | 
				
			|||||||
@ -308,16 +308,18 @@ class _AnimRenderer(object):
 | 
				
			|||||||
                     self.stream)
 | 
					                     self.stream)
 | 
				
			||||||
        self.stream.synchronize()
 | 
					        self.stream.synchronize()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        f = np.float32
 | 
				
			||||||
        n = np.float32(self.ncps)
 | 
					        n = f(self.ncps)
 | 
				
			||||||
        gam = np.float32(n / gam)
 | 
					        gam = f(n / gam)
 | 
				
			||||||
        vib = np.float32(vib / n)
 | 
					        vib = f(vib / n)
 | 
				
			||||||
        hipow = np.float32(hipow / 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
 | 
					        # TODO: get block size from colorclip class? It actually does not
 | 
				
			||||||
        # depend on that being the case
 | 
					        # depend on that being the case
 | 
				
			||||||
        color_fun = a.mod.get_function("colorclip")
 | 
					        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),
 | 
					                  block=(256, 1, 1), grid=(self.nbins / 256, 1),
 | 
				
			||||||
                  stream=self.stream)
 | 
					                  stream=self.stream)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user