Path: csiph.com!eternal-september.org!feeder.eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail From: Andreas Leitgeb Newsgroups: comp.lang.java.programmer Subject: Re: Game color question, with max 256 colors Date: Sun, 2 Jun 2019 14:16:06 -0000 (UTC) Organization: A noiseless patient Spider Lines: 40 Message-ID: References: Reply-To: avl@logic.at Injection-Date: Sun, 2 Jun 2019 14:16:06 -0000 (UTC) Injection-Info: reader02.eternal-september.org; posting-host="252c2dfa75f62a4d76b9073d1801dcf0"; logging-data="13464"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+xF04Mkwi87IyMfwYohE6i" User-Agent: slrn/1.0.3 (Linux) Cancel-Lock: sha1:ocyVl0g2J8sljYrlJ17tSNVT8Xg= Xref: csiph.com comp.lang.java.programmer:38979 Graeme Geldenhuys wrote: > Is there anybody here that can figure this out? > public class Color { > public static int get(int a, int b, int c, int d) { > return (get(d) << 24) + (get(c) << 16) + (get(b) << 8) + (get(a)); > } This method encodes 4 unsigned 1-byte values in an int. Probably these 4 values are the 4 separate colors to be used for rendering the sprite. Encoding 4 values into one means that the caller only needs to pass one value for all four colors. In a serious application, one would use a class to hold the four independent color attributes. > public static int get(int d) { > if (d < 0) return 255; > int r = d / 100 % 10; > int g = d / 10 % 10; > int b = d % 10; > return r * 36 + g * 6 + b; > } > } This method converts values from a "fake base-6" representation into a binary representation of a "6-shades of each red,green,blue colorcube." E.g.: 555: 5 red, 5 green, 5 blue - decimal value 5*36 + 5*6 + 5 = 215 432: 4 red, 3 green, 2 blue - decimal value 4*36 + 3*6 + 2 = 164 -1 is a special case here, and is encoded as 255, which likely gets a special treatment lateron. Maybe it means transparent, but I don't know, without looking up the relevant part of the source to see how screen.render(...) unpacks and uses the values. That the digits would mean red,green,blue in this order is just a guess, based on how colors are usually specified. > screen.render(... , Color.get(-1, 555, 555, 555), 0); > https://www.twitch.tv/videos/38122415