LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Slackware (http://www.linuxquestions.org/questions/slackware-14/)
-   -   Extracting color of a pixel with Slackware (http://www.linuxquestions.org/questions/slackware-14/extracting-color-of-a-pixel-with-slackware-4175481145/)

waddles 10-17-2013 05:21 AM

Extracting color of a pixel with Slackware
 
I have a need to extract the color of a screen pixel usibg shell script. I have found programs/commands like xdotool, grabc, that are supposed to do that but these are not in the full install of Slackware. I keep running into these when I search the web so they must be a sort of default.
I finally found a "mouse" command (v.13.37) that described several protocols but none for my Logitech trackball. This command apparently can get bits back and these could be converted to x,y coordinates for the mouse from their dx and dy bits.
Has anyone used the "mouse" command to extract the coordinates of the mouse? Does anyone know a way to find the color of a screen pixel given the coordinates in Slackware?
If not I may have to create a file of the screen with xwd then use cursor positioning.

wildwizard 10-17-2013 05:42 AM

Are you trying to find the pixel colour from the screen in X or from a console screen?

There are so many different ways to return the value but you need to give a starting point as different graphics modes have different routines.

qweasd 10-17-2013 03:07 PM

Do you use a compositor? (Transparent windows, etc.) If you don't, this is easy.
Code:

import -window root -crop 1x1+100+200 foo.txt
Here you put in coordinates for 100 and 200. This gives you something like
Code:

# ImageMagick pixel enumeration: 1,1,65535,srgb
0,0: (15420,15420,15420)  #3C3C3C3C3C3C  srgb(60,60,60)

which you can awk into submission.

If you DO use a compositor, neither import nor xwd can see the transparency
(here they fill it with black), so you may have to use a different program.
GIMP works, but I don't know the batch mode curse to take a screenshot.
scrot may also work, but it doesn't come with Slackware.

waddles 10-18-2013 01:49 AM

@wildwizard: by console mode I presume U are defining it as the console mode as the system monitor as presented by the XFCE menu or do U mean as like U get on boot up? Actually I need to cover all bases so yes to console mode and to x screen.

@qweasd: I must not be referring to a compositor as I have no idea what that is. As for transparency I have a difficult time understanding what is meant. GIMP's transparency concept, for example, seems to work in reverse of of what I expect it should.
What I am looking for is an X-windows like command where I put in pixel position measured from the top left corner in x,y (maybe like XGetPointerMapping or XChangePointerControl) and be at a location where in the same command or another I could then extract that pixel's color (maybe with XQueryColor). I just now looked at those Xcommands in "XWindowSystem" so they are probably not what I am after in bash/bournesh, but maybe they give a sense of what I am after.

qweasd 10-18-2013 01:41 PM

This tells me you probably don't have a compositor (what window manager do you use?). So this will probably work:
Code:

$ function pixel_color () { import -window root -crop 1x1+$1+$2 -depth 8 txt:- | grep '^0' | sed 's/.*\(\#......\).*/\1/' ; }
$ pixel_color 10 10
#295682


waddles 10-18-2013 04:12 PM

I am using XFCE tho I have access to several other window managers.
I will try that and see how it goes.
I tried it with position 20 20 and get: #5E98E3
Am I correct in thinking this is: red=5E green=98 blue=E3? Why do I get a double beep?
I need to investigate tput as I just ran into its "initc" which may also do this (me tput stupid).

qweasd 10-18-2013 11:22 PM

xfce comes with a compositor. If you have "effects" enabled, import will likely lie when you query blended and semi-transparent things. If you don't, it should do just fine.


All times are GMT -5. The time now is 11:33 AM.