Skip to content

Commit

Permalink
libgui|Image: Improved image colorization (adjust hue only)
Browse files Browse the repository at this point in the history
  • Loading branch information
skyjake committed Apr 1, 2016
1 parent 8a0f9c3 commit d84a542
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions doomsday/sdk/libgui/src/graphics/image.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -657,6 +657,9 @@ Image Image::colorized(Color const &color) const
{
QImage copy = toQImage().convertToFormat(QImage::Format_ARGB32);

QColor targetColor(color.x, color.y, color.z, 255);
int targetHue = targetColor.hue();

for(duint y = 0; y < height(); ++y)
{
duint32 *ptr = reinterpret_cast<duint32 *>(copy.bits() + y * copy.bytesPerLine());
Expand All @@ -669,13 +672,16 @@ Image Image::colorized(Color const &color) const

QColor rgba(r, g, b, a);

int value = rgba.value();
/*int value = rgba.value();
r = color.x * value >> 8;
g = color.y * value >> 8;
b = color.z * value >> 8;
a = color.w * a >> 8;
a = color.w * a >> 8;*/

QColor colorized;
colorized.setHsv(targetHue, rgba.saturation(), rgba.value(), color.w * a >> 8);

*ptr++ = qRgba(r, g, b, a);
*ptr++ = colorized.rgba();
}
}
return copy;
Expand Down

0 comments on commit d84a542

Please sign in to comment.