Hello
I would be thankful if You could tell me how this function works. Maybe You used some descriptions which are on some websites? Can You share me these description? I understand only what map and mean functions do.
Thank You
int ColorLUT::generate(ColorModel *model, const Frame8 &frame, const RectA ®ion) { Fpoint meanVal; float angle, pangle, pslope, meanSat; float yi, istep, s, xsat, sat; int result; m_hpixels = (HuePixel *)maxMalloc(sizeof(HuePixel)*CL_HPIXEL_MAX_SIZE, &m_hpixelSize); if (m_hpixels==NULL) return -1; // not enough memory m_hpixelSize /= sizeof(HuePixel); map(frame, region); mean(&meanVal); angle = atan2(meanVal.m_y, meanVal.m_x); Fpoint uvec(cos(angle), sin(angle)); Line hueLine(tan(angle), 0.0); pangle = angle + PI/2; // perpendicular angle pslope = tan(pangle); // perpendicular slope Line pLine(pslope, meanVal.m_y - pslope*meanVal.m_x); // perpendicular line through mean // upper hue line istep = fabs(m_iterateStep/uvec.m_x); yi = iterate(hueLine, istep); yi += fabs(m_hueTol*yi); // extend model->m_hue[0].m_yi = yi; model->m_hue[0].m_slope = hueLine.m_slope; // lower hue line yi = iterate(hueLine, -istep); yi -= fabs(m_hueTol*yi); // extend model->m_hue[1].m_yi = yi; model->m_hue[1].m_slope = hueLine.m_slope; // inner sat line s = sign(uvec.m_y); istep = s*fabs(m_iterateStep/cos(pangle)); yi = iterate(pLine, -istep); yi -= s*fabs(m_satTol*(yi-pLine.m_yi)); // extend xsat = yi/(hueLine.m_slope-pslope); // x value where inner sat line crosses hue line Fpoint minsatVec(xsat, xsat*hueLine.m_slope); // vector going to inner sat line sat = dot(uvec, minsatVec); // length of line meanSat = dot(uvec, meanVal); if (sat < m_minSat) // if it's too short, we need to extend { minsatVec.m_x = uvec.m_x*m_minSat; minsatVec.m_y = uvec.m_y*m_minSat; yi = minsatVec.m_y - pslope*minsatVec.m_x; } model->m_sat[0].m_yi = yi; model->m_sat[0].m_slope = pslope; // outer sat line yi = iterate(pLine, istep); yi += s*fabs(m_maxSatRatio*m_satTol*(yi-pLine.m_yi)); // extend model->m_sat[1].m_yi = yi; model->m_sat[1].m_slope = pslope; // swap if outer sat line is greater than inner sat line // Arbitrary convention, but we need it to be consistent to test membership (checkBounds) if (model->m_sat[1].m_yi>model->m_sat[0].m_yi) { Line tmp = model->m_sat[0]; model->m_sat[0] = model->m_sat[1]; model->m_sat[1] = tmp; } free(m_hpixels); // calculate goodness result = (meanSat-m_minSat)*100/64 + 10; // 64 because it's half of our range if (result<0) result = 0; if (result>100) result = 100; return result; }