LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 03-20-2007, 10:11 PM   #1
guitara
LQ Newbie
 
Registered: Mar 2006
Distribution: Debian, Ubuntu, Kanotix
Posts: 21

Rep: Reputation: 15
Read pixel in Linux


What's the best (meaning easiest way, and the fastest way) to read a pixel when running an x server? Under windows, I was able to drive a gui, watch the screen to react to events (much like the game botters do) using pixelchecksums and getpixelcolors. In my case, I have to watch and automate a java app, that I don't have the source to as part of my job. It's a crippled third party vendor app, and we're forced to use it -- you know the rest of the story with those :-). At any rate, under windows "reading" the screen was easy, but under X11, I don't find the same thing. I considered using everything from python to java. My windows code was actually C++, and later autohotkey. I've looked at xmacro, andriod, expect, etc, but none really give you that low level access I'm after (they use the XTEST extension which states it's not to be used to automate guis). After alot of searching this led to using Xlib directly. Is this the best way? And are there other wrappers for Xlib besides the orginal C? I know of python-xlib wrapper as well, but that's it.
 
Old 03-21-2007, 08:32 AM   #2
Nick_Battle
Member
 
Registered: Dec 2006
Location: Bracknell, UK
Distribution: SUSE 13.1
Posts: 159

Rep: Reputation: 32
I believe Xlib will do the job, yes. You need to be careful of the window coordinates though. If you literally want a pixel from the screen (an absolute position relative to the (say) 1024x768 background) you will be looking at the "root" window; if you want a pixel from an application window, and you know which window!, then you may want to give window-relative coordinates, which have the 0,0 origin inside the Window Manager's title bar.

If you're grabbing large areas of the screen, don't do it a pixel at a time (too much comms with the server). Xlib has functions to grab an area I think.

All the common C/C++ GUI toolkits wrap Xlib, AFAIK - eg. Qt, GTK. The KDE toolkit builds on Qt.

I had a brief look to see whether Qt provides an API to read a pixel, but I could only find a method in the class that handles graphical images. http://doc.trolltech.com/3.3/classes.html

HTH,
-nick
 
Old 03-21-2007, 09:16 AM   #3
Quigi
Member
 
Registered: Mar 2003
Location: Cambridge, MA, USA
Distribution: Ubuntu (Dapper and Heron)
Posts: 377

Rep: Reputation: 31
Back when I was doing such hacks, I found the frame buffer very easy to use. One call (IIRC, fb_open under Solaris), and you get a struct with a pointer to the video memory, and other useful info.
No messing with X and toolkits here -- but you may need to do that if you care where a particular window lies on your screen.

A completely different approach: Provide an instrumented environment (Drawable etc.) to your java app. I'm not sure how easy it will be to architect, but if you can intercept, e.g., calls to draw and have them do what you need (instead of painting pixels), that might be more efficient than polling pixels off the screen.
 
Old 03-21-2007, 07:09 PM   #4
guitara
LQ Newbie
 
Registered: Mar 2006
Distribution: Debian, Ubuntu, Kanotix
Posts: 21

Original Poster
Rep: Reputation: 15
Thanks! Can you enlighten me a little more with the framebuffer approach? And could someone provide a link with an up to date API that can do it with XLIB? I too looked for it in GTK and came up short. Yes, I am looking to grab a small chunk of pixels in a few locations. I'll let everyone know if I find anything - glad I'm on the right track with using XLib
 
Old 03-22-2007, 04:14 AM   #5
Nick_Battle
Member
 
Registered: Dec 2006
Location: Bracknell, UK
Distribution: SUSE 13.1
Posts: 159

Rep: Reputation: 32
Here's an Xlib link:
http://www.ac3.edu.au/SGI_Developer/...b_PG/sgi_html/

Sounds like XGetImage will help.

I think the frame buffer approach and Xlib are quite different. I don't know much about using a frame buffer, but as I understand it, this accesses the hardware "directly" on the machine, whereas the X protocol is designed to operate a display (or many displays) that may be physically remote from where the program is. That makes X slower, but potentially more flexible. Though this isn't likely to be a big issue - most Linux X programs assume run on the same machine as the display.
 
Old 03-22-2007, 08:15 AM   #6
Quigi
Member
 
Registered: Mar 2003
Location: Cambridge, MA, USA
Distribution: Ubuntu (Dapper and Heron)
Posts: 377

Rep: Reputation: 31
guitara,
I googled a bit, and it seems a frame buffer in Linux is much more complicated than in Solaris.

In Solaris, you get a pointer p and you can read or write the pixel (x,y) as p[x+linesize*y]. Real easy.

In Linux, things seem geared toward efficiency; people are concerned with leveraging hardware acceleration, picosecond timing of the CRT signal, sound, graphical input devices, image formats, ...

Sorry, you may need to do your own research. I bet there's a simple API somewhere, but I didn't find it right away.

Last edited by Quigi; 03-22-2007 at 09:04 AM.
 
Old 03-22-2007, 06:12 PM   #7
guitara
LQ Newbie
 
Registered: Mar 2006
Distribution: Debian, Ubuntu, Kanotix
Posts: 21

Original Poster
Rep: Reputation: 15
thanks - that's along the lines of what i was looking for. A toolkit for this would be nice, but as such it's a nice reference. I also found this - which may or may not work out. It's a X virtual frame buffer. FUN FUN!
http://www.xfree86.org/4.0.1/Xvfb.1.html
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Dead Pixel Question Daedra Slackware 1 10-18-2006 06:58 AM
pixel pipelines? tnelson42345 Linux - Hardware 1 11-12-2005 12:25 PM
Question(s) about bits per pixel kornerr Linux - General 4 08-21-2005 02:06 AM
Pixel Stretching, and panning shamgar03 Linux - Laptop and Netbook 10 06-23-2005 12:13 AM
C function for plotting a pixel in Linux ( like putpixel of bgi)? chandan Programming 4 01-23-2004 09:16 AM


All times are GMT -5. The time now is 09:50 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration