~ubuntu-branches/ubuntu/oneiric/kdeplasma-addons/oneiric

« back to all changes in this revision

Viewing changes to wallpapers/mandelbrot/mix.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Jonathan Thomas
  • Date: 2010-05-25 09:50:14 UTC
  • mto: (0.4.3 experimental)
  • mto: This revision was merged to the branch mainline in revision 68.
  • Revision ID: james.westby@ubuntu.com-20100525095014-e3cebfkdenjrx3xg
Tags: upstream-4.4.80
ImportĀ upstreamĀ versionĀ 4.4.80

Show diffs side-by-side

added added

removed removed

Lines of Context:
45
45
    return result_rgb;
46
46
  }
47
47
}
 
48
 
 
49
unsigned char qreal_to_uchar_color_channel(qreal t)
 
50
{
 
51
  qreal t_scaled = qreal(255)*t;
 
52
  qreal floor_t_scaled = std::floor(t_scaled);
 
53
  qreal probability_to_add_one = t_scaled - floor_t_scaled;
 
54
  // note: qrand() is thread-safe, std::rand() isn't.
 
55
  qreal result = floor_t_scaled + (qrand() < int(qreal(RAND_MAX)*probability_to_add_one) ? qreal(1) : qreal(0));
 
56
  int result_int_clamped = (int) CLAMP(result, qreal(0), qreal(255));
 
57
  return (unsigned char) result_int_clamped;
 
58
}