Reputation: 16711
I was wondering how can I grab a color from a pixel as an RGB integer with conversion if needed. Also, how can I determine if a pixel is lighter or darker than another pixel by using the differences.
Upvotes: 1
Views: 1465
Reputation: 308121
Simple:
rgb_int = rgb_tuple[0] << 16 | rgb_tuple[1] << 8 | rgb_tuple[2]
Testing for lighter or darker is trickier. You should work with a single grayscale value for the lightness, then they are directly comparable. There are different ways to convert RGB to grayscale, this is the oldest and simplest:
gray = r * 0.299 + g * 0.587 + b * 0.114
Upvotes: 2