π
<-

Format ti_picture

TI's micropython + modules

Format ti_picture

Unread postby Maxam » 17 Sep 2020, 19:35

Hello,

Je cherche à comprendre le format des images de la bib ti_picture, mais je n'y comprend rien, ou alors ça fait trop longtemps que je n'ai pas jouer avec des pixels :)

Voila un petit bout de code pour tester, c'est censé afficher deux lignes verticales, je vous laisse admirer par vous même

Code: Select all
def setPixel(img,x,y,color):
    pixel=(y*318)+(x*3)
    img[pixel]=color[2]
    img[pixel+1]=color[1]
    img[pixel+2]=color[0]
def test():
  clear()
  img=newImage(318,212,(0,0,0))
  color=(255,255,255)
  for y in range(0,212):
    setPixel(img,6,y,color)
    setPixel(img,8,y,color)
  showImage(img,318,212,0,0)
User avatar
Maxam
Niveau 7: EP (Espèce Protégée: geek)
Niveau 7: EP (Espèce Protégée: geek)
Level up: 39.8%
 
Posts: 36
Joined: 27 Aug 2020, 07:58
Gender: Not specified
Calculator(s):
MyCalcs profile

Re: Format ti_picture

Unread postby critor » 17 Sep 2020, 20:02

Avec un newImage(318, 212, ...) on obtient une liste de 202248 éléments, soit 318*212*3.
Donc le format semblerait évident, du RGB-888.

Après je constate comme toi, impossible d'obtenir un affichage correct avec showImage(...). Sur le logiciel ça ne m'affiche même rien du tout.

Peut-être pour ça aussi que le module ti_picture n'est pas (encore ?...) au menu, si il ne marche pas...
Image
User avatar
critorAdmin
Niveau 19: CU (Créateur Universel)
Niveau 19: CU (Créateur Universel)
Level up: 51.3%
 
Posts: 42242
Images: 16691
Joined: 25 Oct 2008, 00:00
Location: Montpellier
Gender: Male
Calculator(s):
MyCalcs profile
YouTube: critor3000
Twitter: critor2000
GitHub: critor

Re: Format ti_picture

Unread postby Maxam » 17 Sep 2020, 20:08

critor wrote:Avec un newImage(318, 212, ...) on obtient une liste de 202248 éléments, soit 318*212*3.
Donc le format semblerait évident, du RGB-888.

Oui, j'en ai tenu compte dans mon setPixel et d'après mes essais c'est bien du 888.

critor wrote:Après je constate comme toi, impossible d'obtenir un affichage correct avec showImage(...). Sur le logiciel ça ne m'affiche même rien du tout.
Peut-être pour ça aussi que le module ti_picture n'est pas (encore ?...) au menu, si il ne marche pas...


Il faut faire un clear() (de ti_draw) avant sinon la machine ne passe pas en mode graphique. Ensuite showImage affiche (dans le logiciel) mais c'est n'importe quoi.
User avatar
Maxam
Niveau 7: EP (Espèce Protégée: geek)
Niveau 7: EP (Espèce Protégée: geek)
Level up: 39.8%
 
Posts: 36
Joined: 27 Aug 2020, 07:58
Gender: Not specified
Calculator(s):
MyCalcs profile

Re: Format ti_picture

Unread postby Ti64CLi++ » 17 Sep 2020, 20:10

Le module ti_picture marche de la même manière que ti_image non ?
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: Format ti_picture

Unread postby critor » 17 Sep 2020, 20:18

@Ti64CLi++ Absolument pas.

Maxam wrote:Il faut faire un clear() (de ti_draw) avant sinon la machine ne passe pas en mode graphique. Ensuite showImage affiche (dans le logiciel) mais c'est n'importe quoi.

Merci pour la précision. Alors dans ce cas ça me semble marcher parfaitement : :)
Image

C'est simplement ta fonction setPixel() qui est à corriger, 1ère ligne :
Code: Select all
def setPixel(img,x,y,color):
    pixel=(y*318+x)*3
    img[pixel]=color[2]
    img[pixel+1]=color[1]
    img[pixel+2]=color[0]
Image
User avatar
critorAdmin
Niveau 19: CU (Créateur Universel)
Niveau 19: CU (Créateur Universel)
Level up: 51.3%
 
Posts: 42242
Images: 16691
Joined: 25 Oct 2008, 00:00
Location: Montpellier
Gender: Male
Calculator(s):
MyCalcs profile
YouTube: critor3000
Twitter: critor2000
GitHub: critor

Re: Format ti_picture

Unread postby Ti64CLi++ » 17 Sep 2020, 20:23

La fonction showImage marche comme tel : showImage(var_img, w, h, x, y)

Ici, les paramètres w et h doivent respectivement valoir la largeur et la hauteur de votre image, donc si vous créez une image de dimension 10x10, il faudra mettre 10, 10.
Ensuite, les paramètres x et y sont bien évidemment la position.

Voilà un code qui marche par exemple :
Code: Select all
from ti_draw import clear
from ti_picture import newImage, showImage

clear()

img = newImage(50, 50, (255, 0, 0))
showImage(img, 50, 50, 0, 0)

for i in range(len(img) / 3):
  img[3 * i] = 0
  img[3 * i + 2] = 255

showImage(img, 50, 50, 70, 80)


Après rien n'empêche de mettre des valeurs inférieures à la taille pour w et h, l'image sera juste rognée ;)
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: Format ti_picture

Unread postby Maxam » 17 Sep 2020, 20:23

critor wrote:@Ti64CLi++ Absolument pas.

C'est simplement ta fonction setPixel() qui est à corriger, 1ère ligne :


Oui mais non, les lignes devraient être blanches :)
User avatar
Maxam
Niveau 7: EP (Espèce Protégée: geek)
Niveau 7: EP (Espèce Protégée: geek)
Level up: 39.8%
 
Posts: 36
Joined: 27 Aug 2020, 07:58
Gender: Not specified
Calculator(s):
MyCalcs profile

Re: Format ti_picture

Unread postby critor » 17 Sep 2020, 20:25

@Ti64Cli++
Je ne comprends pas où tu veux en venir. Tu décris exactement ce qui est déjà dans le code initial depuis le début...

@Maxam
J'ai juste testé avec un exemple à moi, et ça donne bien exactement ce que j'ai codé.
Code: Select all
def test():
  clear()
  img=newImage(318,212,(0,0,0))
  for y in range(0,212):
    setPixel(img,6,y,(255,0,0))
    setPixel(img,8,y,(0,255,0))
    setPixel(img,10,y,(0,0,255))
  showImage(img,318,212,0,0)
Retente avec la correction que je t'ai donnée et ça marchera. :)
Image
User avatar
critorAdmin
Niveau 19: CU (Créateur Universel)
Niveau 19: CU (Créateur Universel)
Level up: 51.3%
 
Posts: 42242
Images: 16691
Joined: 25 Oct 2008, 00:00
Location: Montpellier
Gender: Male
Calculator(s):
MyCalcs profile
YouTube: critor3000
Twitter: critor2000
GitHub: critor

Re: Format ti_picture

Unread postby Maxam » 17 Sep 2020, 20:28

Ti64CLi++ wrote:La fonction showImage marche comme tel : showImage(var_img, w, h, x, y)


Oui, c'est bien que ce j'utilise:

Code: Select all
img=newImage(318,212,(0,0,0))
showImage(img,318,212,0,0)
User avatar
Maxam
Niveau 7: EP (Espèce Protégée: geek)
Niveau 7: EP (Espèce Protégée: geek)
Level up: 39.8%
 
Posts: 36
Joined: 27 Aug 2020, 07:58
Gender: Not specified
Calculator(s):
MyCalcs profile

Re: Format ti_picture

Unread postby Ti64CLi++ » 17 Sep 2020, 20:31

Désolé, j'avais mal compris le problème :?

Comme dit critor, pour pallier à ton problème, il suffit de remplacer pixel = (y*318)+(x*3) par pixel = (y*318+x)*3 ;)
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

Next

Return to Python

Who is online

Users browsing this forum: ClaudeBot [spider] and 0 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.
1146 utilisateurs:
>1106 invités
>34 membres
>6 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)