π
<-

ndless get_pixel

C, C++, ASM...

ndless get_pixel

Unread postby parisse » 31 May 2020, 08:04

Is it possible to get the color of a pixel using ndless? I can only see writing functions in ngc.h
User avatar
parisseVIP++
Niveau 12: CP (Calculatrice sur Pattes)
Niveau 12: CP (Calculatrice sur Pattes)
Level up: 89.4%
 
Posts: 3721
Joined: 13 Dec 2013, 16:35
Gender: Not specified
Calculator(s):
MyCalcs profile

Re: ndless get_pixel

Unread postby Ti64CLi++ » 31 May 2020, 10:25

You could try to get it by accessing the LCD address
Image
User avatar
Ti64CLi++Modo
Niveau 16: CC2 (Commandeur des Calculatrices)
Niveau 16: CC2 (Commandeur des Calculatrices)
Level up: 32.5%
 
Posts: 3446
Images: 75
Joined: 04 Jul 2014, 14:40
Location: Clermont-Ferrand 63
Gender: Male
Calculator(s):
MyCalcs profile
Class: ENS Rennes
GitHub: Ti64CLi

Re: ndless get_pixel

Unread postby critor » 31 May 2020, 11:07

Each pixel is encoded on 2 bytes in RGB-565.
Image
User avatar
critorAdmin
Niveau 19: CU (Créateur Universel)
Niveau 19: CU (Créateur Universel)
Level up: 51.3%
 
Posts: 42240
Images: 16685
Joined: 25 Oct 2008, 00:00
Location: Montpellier
Gender: Male
Calculator(s):
MyCalcs profile
YouTube: critor3000
Twitter: critor2000
GitHub: critor

Re: ndless get_pixel

Unread postby Noury » 31 May 2020, 12:13

TI64CLI++ and critor are right.
But be careful, the pixel address depends on the Nspire model. There are two LCD layouts.
User avatar
NouryVIP++
Niveau 11: LV (Légende Vivante)
Niveau 11: LV (Légende Vivante)
Level up: 66.3%
 
Posts: 325
Joined: 07 Sep 2018, 09:19
Location: Sceaux, France 92
Gender: Male
Calculator(s):
MyCalcs profile

Re: ndless get_pixel

Unread postby parisse » 31 May 2020, 18:52

I tried
Code: Select all
int os_get_pixel(int x,int y){
  unsigned short * addr=(unsigned short *) 0xC0000010;
  int r=addr[y*SCREEN_WIDTH+x];
  return r;
}

But that does not work (tried on a nspire cx). I filled a rectangle (0,0,100,100) with red, then get_pixel(2,30) does not return the same value as get_pixel(2,31), 27113 then 0.
User avatar
parisseVIP++
Niveau 12: CP (Calculatrice sur Pattes)
Niveau 12: CP (Calculatrice sur Pattes)
Level up: 89.4%
 
Posts: 3721
Joined: 13 Dec 2013, 16:35
Gender: Not specified
Calculator(s):
MyCalcs profile

Re: ndless get_pixel

Unread postby Noury » 31 May 2020, 19:25

Last time I've written to LCD (using assembly language), I have used:
@pixel=0xC0000010 + ((num col * 480) + (num lig * 2))
0xC0000010 is Frame Base Address
It was with a CX CAS

I think older Nspire have an LCD rotated (90°). Not sure which way.
User avatar
NouryVIP++
Niveau 11: LV (Légende Vivante)
Niveau 11: LV (Légende Vivante)
Level up: 66.3%
 
Posts: 325
Joined: 07 Sep 2018, 09:19
Location: Sceaux, France 92
Gender: Male
Calculator(s):
MyCalcs profile

Re: ndless get_pixel

Unread postby parisse » 31 May 2020, 19:47

Perhaps reading in the LCD does not work. But I found another way, inspired by ngc.c of the SDK, using the offscreen buffer, like this
Code: Select all
Gc nspire_gc=0;

Gc * get_gc(){
  if (!nspire_gc){
    nspire_gc=gui_gc_global_GC();
    gui_gc_setRegion(nspire_gc, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
    gui_gc_begin(nspire_gc);
  }
  return &nspire_gc;
}

int os_get_pixel(int x,int y){
  if (x<0 || x>=SCREEN_WIDTH || y<0 || y>=SCREEN_HEIGHT)
    return -1;
  get_gc();
  char ** off_buff = ((((char *****)nspire_gc)[9])[0])[0x8];
  int res = *(unsigned short *) (off_buff[y+nspire_statusarea] + 2*x);
  return res;
}
User avatar
parisseVIP++
Niveau 12: CP (Calculatrice sur Pattes)
Niveau 12: CP (Calculatrice sur Pattes)
Level up: 89.4%
 
Posts: 3721
Joined: 13 Dec 2013, 16:35
Gender: Not specified
Calculator(s):
MyCalcs profile

Re: ndless get_pixel

Unread postby Vogtinator » 31 May 2020, 21:21

parisse wrote:I tried
Code: Select all
int os_get_pixel(int x,int y){
  unsigned short * addr=(unsigned short *) 0xC0000010;
  int r=addr[y*SCREEN_WIDTH+x];
  return r;
}

But that does not work (tried on a nspire cx). I filled a rectangle (0,0,100,100) with red, then get_pixel(2,30) does not return the same value as get_pixel(2,31), 27113 then 0.


You forgot one level of indirection. 0xC0000010 has a pointer to the framebuffer, so it has to be

Code: Select all
int os_get_pixel(int x,int y){
  unsigned short * addr=*(unsigned short **) 0xC0000010;
  int r=addr[y*SCREEN_WIDTH+x];
  return r;
}


Though I wonder what this is for.
User avatar
VogtinatorPremium
Niveau 9: IC (Compteur Infatigable)
Niveau 9: IC (Compteur Infatigable)
Level up: 1.6%
 
Posts: 217
Joined: 29 Mar 2014, 15:55
Gender: Male
Calculator(s):
MyCalcs profile

Re: ndless get_pixel

Unread postby parisse » 01 Jun 2020, 14:30

I see, thanks. I will keep the gc code since it works...
User avatar
parisseVIP++
Niveau 12: CP (Calculatrice sur Pattes)
Niveau 12: CP (Calculatrice sur Pattes)
Level up: 89.4%
 
Posts: 3721
Joined: 13 Dec 2013, 16:35
Gender: Not specified
Calculator(s):
MyCalcs profile


Return to Native: Ndless, Linux, ...

Who is online

Users browsing this forum: ClaudeBot [spider] and 6 guests

-
Search
-
Social TI-Planet
-
Featured topics
Comparaisons des meilleurs prix pour acheter sa calculatrice !
"1 calculatrice pour tous", le programme solidaire de Texas Instruments. Reçois gratuitement et sans aucune obligation d'achat, 5 calculatrices couleur programmables en Python à donner aux élèves les plus nécessiteux de ton lycée. Tu peux recevoir au choix 5 TI-82 Advanced Edition Python ou bien 5 TI-83 Premium CE Edition Python.
Enseignant(e), reçois gratuitement 1 exemplaire de test de la TI-82 Advanced Edition Python. À demander d'ici le 31 décembre 2024.
Aidez la communauté à documenter les révisions matérielles en listant vos calculatrices graphiques !
1234
-
Donations / Premium
For more contests, prizes, reviews, helping us pay the server and domains...
Donate
Discover the the advantages of a donor account !
JoinRejoignez the donors and/or premium!les donateurs et/ou premium !


Partner and ad
Notre partenaire Jarrety Calculatrices à acheter chez Calcuso
-
Stats.
1193 utilisateurs:
>1150 invités
>36 membres
>7 robots
Record simultané (sur 6 mois):
6892 utilisateurs (le 07/06/2017)
-
Other interesting websites
Texas Instruments Education
Global | France
 (English / Français)
Banque de programmes TI
ticalc.org
 (English)
La communauté TI-82
tout82.free.fr
 (Français)