IPB

Bienvenue invité ( Connexion | Inscription )

 
Reply to this topicStart new topic
> Récupérer la valeur RVB d'un pixel
Options
Ne0
posté 23 Oct 2007, 18:13
Message #1


Macbidouilleur de bronze !
**

Groupe : Membres
Messages : 325
Inscrit : 22 Mar 2003
Lieu : Marseille
Membre no 6 788



Bonsoir à tous,

Quelqu'un saurait t il comment faire (en cocoa) pour récupérer les composantes RVB d'un pixel affiché à l'écran (de coordonnées données)?

Merci d'avance.


--------------------
Go to the top of the page
 
+Quote Post
schlum
posté 23 Oct 2007, 20:14
Message #2


Terminaltor
Moderating Machine
*****

Groupe : Admin
Messages : 24 449
Inscrit : 25 Oct 2002
Lieu : Jeumont (59)
Membre no 4 319



Moi je sais, mais c'est du Carbon, pas du Cocoa...

CODE
CGDirectDisplayID display = kCGDirectMainDisplay;
char pixC[4];
void *pix = CGDisplayAddressForPosition(display,i,j);
memcpy(pixC,pix,4);
NSLog(@"R: %3d; G: %3d; B: %3d",pixC[2],pixC[1],pixC[0]);


bits 1-8 -> composante "bleu"
bits 9-16 -> composante "vert"
bits 17-24 -> composante "rouge"
bits 25-32 -> inutilisé


--------------------
          I think therefore I Mac          
Go to the top of the page
 
+Quote Post
Phili
posté 23 Oct 2007, 21:25
Message #3


Adepte de Macbidouille
*

Groupe : Membres
Messages : 244
Inscrit : 10 May 2002
Membre no 2 433



En fait,

CGDisplayAddressForPosition : n'est pas du Carbon mais du langage quartz pour être plus précis du CoreGraphic.

Il se trouve dans : ApplicationServices.framework et non dans le carbon.framework ;-)

Dans le cas d'un NSView sans écran complet et si on veut faire du cocoa pur :

NSPoint realPoint = NSMakePoint(posX+6,posY+6);

[self lockFocus];
NSColor *color = NSReadPixel(realPoint);
[self unlockFocus];


Le [self lockFocus]; est important sinon plantage.


Philippe.

Ce message a été modifié par Phili - 23 Oct 2007, 21:30.


--------------------
Développeur d'iMathGeo.

Site web : Site d'iMathGeo
Go to the top of the page
 
+Quote Post
schlum
posté 23 Oct 2007, 21:45
Message #4


Terminaltor
Moderating Machine
*****

Groupe : Admin
Messages : 24 449
Inscrit : 25 Oct 2002
Lieu : Jeumont (59)
Membre no 4 319



CITATION(Phili @ 23 Oct 2007, 22:25) [snapback]2400687[/snapback]

En fait,

CGDisplayAddressForPosition : n'est pas du Carbon mais du langage quartz pour être plus précis du CoreGraphic.

Il se trouve dans : ApplicationServices.framework et non dans le carbon.framework ;-)

Dans le cas d'un NSView sans écran complet et si on veut faire du cocoa pur :

NSPoint realPoint = NSMakePoint(posX+6,posY+6);

[self lockFocus];
NSColor *color = NSReadPixel(realPoint);
[self unlockFocus];


Le [self lockFocus]; est important sinon plantage.


Philippe.


Avec un "s" (CoreGraphics)

C'est vrai que j'ai un peu tendance à appeler Carbon tout ce qui n'est pas Cocoa tongue.gif
Mais là pour une fois c'est vrai laugh.gif

Extrait de Carbon.h :
CODE
#ifndef __APPLICATIONSERVICES__
#include <ApplicationServices/ApplicationServices.h>
#endif

C'est donc bien une partie de Carbon wink.gif


--------------------
          I think therefore I Mac          
Go to the top of the page
 
+Quote Post
Phili
posté 23 Oct 2007, 22:20
Message #5


Adepte de Macbidouille
*

Groupe : Membres
Messages : 244
Inscrit : 10 May 2002
Membre no 2 433



wink.gif

Philippe.


--------------------
Développeur d'iMathGeo.

Site web : Site d'iMathGeo
Go to the top of the page
 
+Quote Post
Ne0
posté 1 Nov 2007, 19:19
Message #6


Macbidouilleur de bronze !
**

Groupe : Membres
Messages : 325
Inscrit : 22 Mar 2003
Lieu : Marseille
Membre no 6 788



CITATION(schlum @ 23 Oct 2007, 20:14) [snapback]2400566[/snapback]

Moi je sais, mais c'est du Carbon, pas du Cocoa...

CODE
CGDirectDisplayID display = kCGDirectMainDisplay;
char pixC[4];
void *pix = CGDisplayAddressForPosition(display,i,j);
memcpy(pixC,pix,4);
NSLog(@"R: %3d; G: %3d; B: %3d",pixC[2],pixC[1],pixC[0]);


bits 1-8 -> composante "bleu"
bits 9-16 -> composante "vert"
bits 17-24 -> composante "rouge"
bits 25-32 -> inutilisé


Ok merci smile.gif

Par contre ya une ptite erreur, c'est plutôt :
CODE
NSLog(@"R: %3d; G: %3d; B: %3d",pixC[1],pixC[2],pixC[3]);


Et puis je comprend pas trop le void* , pourquoi ne pas mettre char * ?

Ce message a été modifié par Ne0 - 1 Nov 2007, 19:19.


--------------------
Go to the top of the page
 
+Quote Post
schlum
posté 2 Nov 2007, 01:16
Message #7


Terminaltor
Moderating Machine
*****

Groupe : Admin
Messages : 24 449
Inscrit : 25 Oct 2002
Lieu : Jeumont (59)
Membre no 4 319



Oui oui, c'est "char *" bien sûr, sinon l'index ne veut rien dire !

Par contre, pour l'ordre, j'avais fait des tests, et c'était bien 2, 1, 0 unsure.gif



--------------------
          I think therefore I Mac          
Go to the top of the page
 
+Quote Post
schlum
posté 23 Sep 2014, 10:42
Message #8


Terminaltor
Moderating Machine
*****

Groupe : Admin
Messages : 24 449
Inscrit : 25 Oct 2002
Lieu : Jeumont (59)
Membre no 4 319



Je uppe ce sujet, car CGDisplayAddressForPosition est manifestement deprecated depuis un bail, et renvoie maintenant NULL, d’où surprise quand j’en ai eu besoin à nouveau ^^

La nouvelle méthode :

Code
CGImageRef im = CGDisplayCreateImageForRect(kCGDirectMainDisplay,CGRectMake(i,j,1,1));    
CFDataRef px = CGDataProviderCopyData(CGImageGetDataProvider(im));
UInt8 pixC[3];
CFDataGetBytes(px,CFRangeMake(0,3), pixC);
NSLog(@"R: %3d; G: %3d; B: %3d",pixC[2],pixC[1],pixC[0]);
CFRelease(px);
CFRelease(im);


C’est malheureusement sensiblement plus lent (seulement ~ 1000 pixels/s ici), mais l’accès direct au raw framebuffer semble maintenant interdit ; il faut donc passer par la copie des données dans un buffer externe, via la création d’une CGImage (donc allocation, puis release).

J’ai essayé NSReadPixel aussi, mais ça me renvoie que des 0, peut-être que j’ai mal saisi quelque chose ^^


--------------------
          I think therefore I Mac          
Go to the top of the page
 
+Quote Post

Reply to this topicStart new topic
1 utilisateur(s) sur ce sujet (1 invité(s) et 0 utilisateur(s) anonyme(s))
0 membre(s) :

 



Nous sommes le : 25th April 2024 - 20:01