Author Topic: Greyscale on Nspire/CAS  (Read 7140 times)

0 Members and 1 Guest are viewing this topic.

Offline Chirlian

  • LV2 Member (Next: 40)
  • **
  • Posts: 22
  • Rating: +0/-0
    • View Profile
Greyscale on Nspire/CAS
« on: March 24, 2015, 07:09:58 pm »
Am looking for any info about the greyscale that the clickpad/touchpad nspires are using with their b/w lcd. Not much what I find. A greyscale prog I could find, but it works only with Ndless. So how can someone use the greyscale in progs without info about the relation of r/g/b values to grescale 0-15? Ok, not really useful to search longer, I am writing such a program in Lua that shows this values and the related grey by a simple grafik. Am sure that a used coder would do it in shortest time, however, it's a good start for first steps in Lua. But: is there anywhere the info about the r/g/b values of the greyscale?

Offline Adriweb

  • Editor
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1708
  • Rating: +229/-17
    • View Profile
    • TI-Planet.org
Re: Greyscale on Nspire/CAS
« Reply #1 on: March 24, 2015, 08:17:51 pm »
RGB stands for Red Green Blue. More info here: https://en.wikipedia.org/wiki/RGB_color_model
So, to get grey, assign the same value for the 3 colors. They range from 0 to 255 (0xff in hexadecimal)

Grey gradient:
Code: [Select]
function on.paint(gc)
    for i=0,255 do
        gc:setColorRGB(i,i,i)
        gc:drawLine(i, 0, i, 200) -- using the same variable for the position because I'm lazy
    end
end



More info about Nspire-Lua on https://wiki.inspired-lua.org for an API doc, and http://compasstech.com.au/TNS_Authoring/Scripting/ for tutorials
My calculator programs
TI-Planet.org co-admin.
TI-Nspire Lua programming : Tutorials  |  API Documentation

Offline Chirlian

  • LV2 Member (Next: 40)
  • **
  • Posts: 22
  • Rating: +0/-0
    • View Profile
Re: Greyscale on Nspire/CAS
« Reply #2 on: March 24, 2015, 08:56:47 pm »
Hi,
thanks for this info, but that is already clear for me (as radio/tv technician it should :-) ). My question is: to which of the 16 gray stages are which r/g/b values related? Up to now I see that this 16 greys are not spreaded over the 8 bit (would mean all 16 bit are a quant to next grey stage) but at about 176 I see the grafik starting to get a little lighter. And this seems to be spreaded over red and green, but blue seems not affected (am just trying this,may be it's not correct). So I am still looking which grey needs which r/g/(b) value. Should be a simple question but also at this lua pages (and TI pages) I didn't find any info about this.

Offline Chirlian

  • LV2 Member (Next: 40)
  • **
  • Posts: 22
  • Rating: +0/-0
    • View Profile
Re: Greyscale on Nspire/CAS
« Reply #3 on: March 24, 2015, 09:28:47 pm »
Hi,
now everything (about this theme) is clear to me. I was experimenting with the single colors of r/g/b (because at b/w lcd they ever must show any grey). But your hint with setting them synchron makes is simple. Starting at 0, then 16 and 32 for all 3 colors I can't see any change on my clickpad display. Then at higher values I can see getting the grafik lighter. Theoretically the change must be at 64, 80, 96 and so on, but it's difficult to see this exactly. However, my question is answered, thank you! So it's very simple to get every grey value as wanted.

Offline Jens_K

  • LV4 Regular (Next: 200)
  • ****
  • Posts: 187
  • Rating: +52/-0
    • View Profile
Re: Greyscale on Nspire/CAS
« Reply #4 on: May 06, 2015, 03:19:04 pm »
Hi,
even though it seems like your problem was solved, I think I can still give some more useful information about this topic:
I messed around with the grayscaling of the emulator and found out that the Nspire (at least the emulator) apparently uses the commonly used RGB-channel weighting of 0.299*R + 0.587*G + 0.114*B. You can see that on the attached screenshot (even though the emulator seems to mess up certain RGB-values like 0,129,0). Based on this and the fact that the Nspire can display 16 different shades of gray, I assume that the Nspire calculates the displayed shade like this:
Code: [Select]
shade = floor((0.299 * R + 0.587 * G + 0.114 * B) / 16)I can't test if that's the case myself because I don't own a grayscale Nspire, but this would explain your confusion with single colors of r/g/b.  ;)
Sorry for nonsense.

Projects:



Offline Chirlian

  • LV2 Member (Next: 40)
  • **
  • Posts: 22
  • Rating: +0/-0
    • View Profile
Re: Greyscale on Nspire/CAS
« Reply #5 on: May 06, 2015, 05:41:28 pm »
Hi Jens,
I will try this on my Clickpad to see, if I get a linear greyscale by this formula. In practice I did simply set the rgb channels synchron to 0/16/32/64 and so on to get the 16 greyshades that the clickpad can show. I will look, if that is as linear as using your formular.
greeting
klaus

Offline Jens_K

  • LV4 Regular (Next: 200)
  • ****
  • Posts: 187
  • Rating: +52/-0
    • View Profile
Re: Greyscale on Nspire/CAS
« Reply #6 on: May 06, 2015, 07:37:27 pm »
Well I think you got me wrong here; the best way to get certain shades of gray is to set R,G and B to the same value. The formula would just explain how the Nspire transforms colors to gray shades. E.g. if you'd gc:setColorRGB(150,100,255), then, according to the formula,
Code: [Select]
floor((0.299*150+0.587*100+0.114*255)/16)=8the Nspire would display the 8th shade.
« Last Edit: May 06, 2015, 10:30:34 pm by Jens_K »
Sorry for nonsense.

Projects: