3

So I've been starting DS programming, and I notice that to draw a pixel the color must be a RGB(0, 31, 0). Is there any way to change that to something like RGB(0, 255, 0)?

NDSgrammer
  • 43
  • 1
  • 4

2 Answers2

4

If you have a green-value g with a range of 0-255, you can convert it to NintendoDS's 0-31 range by using g*31/255. If you are asking us if you can actually do something to make your NintendoDS display a range of 0-255 for each channel the answer is no, but you could use dithering (search-engine it).

Bernd Elkemann
  • 23,242
  • 4
  • 37
  • 66
  • 2
    why would you need floor? they're integers – steabert Mar 06 '11 at 08:51
  • Don't forget that because zero is an acceptable value, there are 256 and 32 discrete levels, so you should be multiplying and dividing by 32 and 256, not 31 and 255. You can think of the conversion as involving only the five most significant bits. – Dave Mar 06 '11 at 09:05
  • 1
    Hm, actually the reason why I do *31/255 is so that I divide by the previous-maximum-value and multiply by the new-maximum-value; that should be correct. (in reverse-order so that integer arithmetic stays more accurate). – Bernd Elkemann Mar 06 '11 at 09:49
  • @Dave: There are that many distinct values, but these are values not indices. You really do want to multiply by 31 and divide by 255. 31 represents maximum to the DS, and 255 is how the OP wants to represent this. You can think of this as scaling down to the range [0,1], and then back up. – wnoise Mar 06 '11 at 10:21
  • Yeah, +1 eznme. Having thought about it, it's the right thing to do, treating black as a special case, then mapping the remaining 31. – Dave Mar 06 '11 at 10:37
3

5 bit rgb : 31 = 8 bit rgb : 255

so 8 bit rgb = (5 bit rgb * 255 / 31)

Example:

5 bit RGB = 12,3,21

8 bit R = (12 * 255) / 31 = 99
      G = (3 * 255) / 31  = 25
      B = (21 * 255) / 31 = 172

PS: I think you mean "5 bit RGB to 8 bit RGB" in your title.

BlackBear
  • 22,411
  • 10
  • 48
  • 86
  • Don't forget that because zero is an acceptable value, there are 256 and 32 discrete levels, so you should be multiplying and dividing by 256 and 32, not 255 and 31. You can think of the conversion as involving only the five most significant bits. – Dave Mar 06 '11 at 09:06
  • 1
    @Dave: I don't understand. (0*255)/31 = 0 (correct) and (31*255)/31 = 255 (correct too) – BlackBear Mar 06 '11 at 09:11
  • Thinking about it, your way works best for colour mapping, so +1 for you and eznme. My theory involved 32 and 256 discrete levels (which indeed there are) so each level would be exactly 8 from the next. But that means my theory would lose the blackness of 0, so would not be a good solution. – Dave Mar 06 '11 at 10:35