Skip to main content
10 events
when toggle format what by license comment
Nov 1, 2018 at 7:53 comment added Peter Taylor @Viezevingertjes, I tried to explain that in the first paragraph. If you sum 256 values in the range 0x00 to 0xff the result will be in the range 0x0000 to 0xffff. So if you mask with 0xff00ff and add 256 values then the top 16 bits of the result will contain the sums of the bits masked by 0xff0000 and the bottom 16 bits of the result will contain the sums of the bits masked by 0x0000ff. If that's a clearer explanation then I can edit it in, or feel free to do so yourself.
Nov 1, 2018 at 7:02 comment added Viezevingertjes @PeterTaylor I stand corrected, it indeed works to access the values like that as long as it's 32bpp, another thing learned in the wonderful world of pointers. Yet i seem to have a hard time on understanding how the bitwise operations result in a average R,G,B though. Any chance you could shine a light on that?
Oct 31, 2018 at 21:14 comment added Peter Taylor @Viezevingertjes, no magic required. It's just reinterpreting the memory layout. Nowadays it could probably be done better with Span<T>.
Oct 31, 2018 at 21:11 comment added Viezevingertjes @PeterTaylor Defining it as something different and forcing a cast, doesnt magically merge 4 values [B, G, R, A], right?
Oct 31, 2018 at 20:41 comment added Peter Taylor @Viezevingertjes, uint* p...
Oct 31, 2018 at 20:01 comment added Viezevingertjes p[idx] = 1 byte = 8 bits, 0-255 so R, G or B, not all three, why would those bitmasks work exactly? Not trying to be a dick, would be interested in how this theoretically would work but not seeying this work in C# as-is.
Oct 31, 2018 at 19:57 comment added Peter Taylor @Viezevingertjes, I don't understand your objection. What does p[idx] contain if not a pixel's value?
Oct 31, 2018 at 19:43 comment added Viezevingertjes This makes no sense anyway right? 'p' would be the BGR addresses, so it makes no sense to apply bitmasks over the same p[idx] value unless i'm missing something? Maybe that's how java does it in memory, but surely C# doesnt return uint* in that case.
Mar 14, 2017 at 11:45 comment added Heslacher You need to change to totals[0] += sumRR00BB & 0xffff; and totals[2] += sumRR00BB >> 16; because the color components are stored BGR instead of RGB.
Mar 14, 2017 at 9:00 history answered Peter Taylor CC BY-SA 3.0