virtual void update() { // Rebuild the lookup table in case the prarameters have changed. updateLUT(); unsigned char *pixel = (unsigned char *) in; unsigned char *dest = (unsigned char *) out; if (fabs(m_sat-1) < 0.001) { // Calculating the saturation is expensive. So first check whether // we really need to do it. // Keeping the if/else outside of the loop gives a little speed gain. // Worth the duplicate code, as only 4 lines so far :) for (unsigned int i = 0; i < size; i++) { *dest++ = m_lutR[*pixel++]; *dest++ = m_lutG[*pixel++]; *dest++ = m_lutB[*pixel++]; *dest++ = m_lutA[*pixel++]; } } else { double luma; for (unsigned int i = 0; i < size; i++) { luma = 0.2126 * m_lutR[*(pixel+0)] + 0.7152 * m_lutG[*(pixel+1)] + 0.0722 * m_lutB[*(pixel+2)]; *dest++ = CLAMP0255(luma + m_sat*(m_lutR[*pixel++]-luma)); *dest++ = CLAMP0255(luma + m_sat*(m_lutG[*pixel++]-luma)); *dest++ = CLAMP0255(luma + m_sat*(m_lutB[*pixel++]-luma)); *dest++ = m_lutA[*pixel++]; } } }
SOPSat(unsigned int, unsigned int) { register_param(rSlope, "rSlope", "Slope of the red color component"); register_param(gSlope, "gSlope", "Slope of the green color component"); register_param(bSlope, "bSlope", "Slope of the blue color component"); register_param(aSlope, "aSlope", "Slope of the alpha component"); register_param(rOffset, "rOffset", "Offset of the red color component"); register_param(gOffset, "gOffset", "Offset of the green color component"); register_param(bOffset, "bOffset", "Offset of the blue color component"); register_param(aOffset, "aOffset", "Offset of the alpha component"); register_param(rPower, "rPower", "Power (Gamma) of the red color component"); register_param(gPower, "gPower", "Power (Gamma) of the green color component"); register_param(bPower, "bPower", "Power (Gamma) of the blue color component"); register_param(aPower, "aPower", "Power (Gamma) of the alpha component"); register_param(saturation, "saturation", "Overall saturation"); rSlope = 1; gSlope = 1; bSlope = 1; aSlope = 1; rOffset = 0; gOffset = 0; bOffset = 0; aOffset = 0; rPower = 1; gPower = 1; bPower = 1; aPower = 1; saturation = 200; // Pre-build the lookup table. // For 1080p, rendering a 5-second video took // * 37 s without the LUT // * 7 s with the LUT // * 5 s without any effect applied (plain rendering). // So the LUT brings about 15x speedup. m_lutR = (unsigned char *) malloc(256*sizeof(char)); m_lutG = (unsigned char *) malloc(256*sizeof(char)); m_lutB = (unsigned char *) malloc(256*sizeof(char)); m_lutA = (unsigned char *) malloc(256*sizeof(char)); updateLUT(); }
static ssize_t kgamma_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) { int lut, color, posn; if (!count) return -EINVAL; sscanf(buf, "%u %u %u", &lut, &color, &posn); if (lut > 0xff) return count; if (posn > 0xff) return count; if (color > 2) return count; updateLUT(lut, color, posn); lut_updated = true; return count; }