Color& Color::offsetHSL( float h, float s, float l ) { auto hsl = getHSL(); hsl.h += h; hsl.s += s; hsl.l += l; setHSL( hsl.h, hsl.s, hsl.l ); return *this; }
void Image::emotion(int x, int y, float degree){ int imageWidth = m_width; int imageHeight = m_height; long pixelCount = imageHeight * imageWidth; long tapPixelIndex = getIndexOfPoint(x, y); int step = m_channels; struct HSL baseHSL; struct RGB baseRGB; setRGB(m_imageData[tapPixelIndex*step + 0], m_imageData[tapPixelIndex*step + 1], m_imageData[tapPixelIndex*step + 2], &baseRGB); rgb2HSL(&baseRGB, &baseHSL); struct HSL hsl; struct RGB rgb; for (long index = 0; index < pixelCount; index++) { long arrayIndex = index*step; int red = m_imageData[arrayIndex + 0]; int green = m_imageData[arrayIndex + 1]; int blue = m_imageData[arrayIndex + 2]; setRGB(red, green, blue, &rgb); rgb2HSL(&rgb, &hsl); float rate = analogicalRateWithBaseHSL(&baseHSL, &hsl, degree); if (rate < 0) { setHSL(0, 0, hsl.Lummiance, &hsl); hsl2RGB(&hsl, &rgb); m_imageData[arrayIndex + 0] = rgb.Red; m_imageData[arrayIndex + 1] = rgb.Green; m_imageData[arrayIndex + 2] = rgb.Blue; }else if(rate > 0.001f){ int newSa = rate * hsl.Saturation; setHSL(hsl.Hue, newSa, hsl.Lummiance, &hsl); hsl2RGB(&hsl, &rgb); m_imageData[arrayIndex + 0] = rgb.Red; m_imageData[arrayIndex + 1] = rgb.Green; m_imageData[arrayIndex + 2] = rgb.Blue; } } }