On Fri, Apr 26, 2013 at 8:40 PM, Jason Ekstrand <ja...@jlekstrand.net> wrote:
> I think you forgot reply-all. I add wayland-devel again. Blast. Sorry about that. Thanks! >> There is, actually: >> >> expanded = (base << 7) | (base >> 1); >> >> ie: repeat the bit pattern down into the lower bits. Examples: >> >> 11111111 -> (111111110000000) | (1111111) -> 111111111111111 >> 0000000 -> (0000000000000000) | (0000000) -> 000000000000000 >> 1000000 -> (1000000000000000) | (100000) -> 100000001000000 >> 1011001 -> (10110010000000) | (101100) -> 1011001101100 >> >> And so forth. It's the same scheme you use when doing color >> channel expansion. I haven't seen a rigorous mathematical proof that >> it's correct, but I'd be surprised if someone more so inclined than I >> hasn't come up with one. > > Wow, I've never seen that one before. And yes, it is provably exactly > correct (up to a little integer round-off because of the implicit right > shift by 1). I guess I learned a new trick today; that's really cool! AFAIK folks in graphics hardware have been using that trick at the hardware level to do color channel expansion (ie: turning RGB565 into RGB888 or the like) since at least the 90s, but like a lot of the more clever bit manipulation tricks it's not that widely disseminated. I actually came up with it independently back in the 90s and was pretty proud of myself before a co-worker I was explaining it shot me down with "oh, *that*, yeah, that's what my raytracer does.". :) I meant to mention in my original reply that although most physical hardware (especially historical hardware) is linearly mapped signed byte or unsigned byte axis values, I think a protocol that's going to be relatively future proof needs to handle higher precision and convert well to float. Most games are going to want the sticks to map cleanly to either digital up/down/left/right buttons or to [-1.0 .. 1.0] ranges, and both of those are easy translations from the [-32k .. 32k] range. Todd. -- Todd Showalter, President, Electron Jump Games, Inc. _______________________________________________ wayland-devel mailing list wayland-devel@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/wayland-devel