Jump to content
Macro Express Forums

Pixel Question


patgenn123

Recommended Posts

This forum issue was never resolved and it falls in line with the question I have.

 

http://pgmacros.invisionzone.com/index.php...68&hl=pixel

 

Floyd mentioned something about scanning the whole screen and taking some time to do it searching for the pixel color.

 

It was never answered and I can't find anything else that could help me.

 

Instead of scanning the whole screen, is there a way of splitting the screen into 4 parts and scanning for example, the top right quadrant instead(looking for the pixel value)?

 

Just need some direction on this...

 

Thanks!

 

-P

Link to comment
Share on other sites

Scanning each pixel would be way to slow. I have some macros that scan small areas of the screen and although it's quick doing the entire screen would take time.

 

Here's something I've considered before when faced with a similar problem but never tried. I was thinking one could use a screen shot from a print screen and save it to a file which you could read back in as a string. The uncompressed BMP file format is pretty simple so if the color was unique it would be fairly simple to find your color. The tenth byte contains the offset or start of actual data so you could trim that out and then do an "If Variable Contains" to find the byte(s). This would at least speed up the screen polls. If one was really clever one could decode the BMP file and find the position of that pixel on the screen but that might take some work to perfect. But one could do a reverse engineering of it by looking at the actual position on screen versus the position in the BMP file data and come up with what I think would be a pretty simple formula. Otherwise one could just wait until you knew it appeared and then scan the screen.

 

As far as scanning the screen pixel by pixel you could definitely break it into a quadrant. Just some simple math with your repeats can accomplish this. In fact you could start at a most likely point and work your way out to cut down the time. For instance start at a given XY and then in your repeats have integers vars that represent the perimeters of your search. Each time you would increment/decrement once each of these and do one side at a time. in a square spiral pattern. A little bit of a brain teaser but not too difficult.

 

Also you might consider the spacing of your samples. I doubt your object is one pixel in size so looking at every pixel would be a waste. Let's say what you are looking for is an icon 32X32. Then in your repeats increment by 32 and 32. On my screens I have 1680X1050 for a total of 1764000 pixels to scan. If I scanned with 32P increments the total number of pixels to process is only 1664! That's more than 1/1000 of the number of iterations. That doesn't land you in the center but most mouse clicks don't care. If you need to find the center you can do a simple bracketing technique to find the edge.

Link to comment
Share on other sites

Cory,

 

Hello this is Pat. Remember me?

 

Ah yes, I'm sure you do. If you recall, I am thinking about writing a book called "I'm still an idiot when it comes to computers. Umm.. can you explain that in layman's terms?" That's the title of my made up book I am thinking about writing.

 

Now, come again?

 

-P

Link to comment
Share on other sites

I'm not knowledgable about decompiling image files, But I'll take a stab at the looping idea...

 

THere is an ME function called "Get Pixel Color" (let's apprev it with "GPC") where you put in the coordinates of the pixel you want to evaluate.

As an example, lets say my computer screen is 1000 pixels wide and 800 pixel high (i.e. resolution is 1000x800).

If I have my "GPC" command (cmd) set to look in a "Specific Coordinate Relative to Screen" and I use the values X=1, Y=1, then it would return the color value of the pixel in the top/left of the screen. At X=1, Y=800, it's on the bottom left corner. X=1000, Y=800 is the bottom right. X= 500, Y=400, is approximately the middle of the screen. Note that the GPC cmd returns the color value by placing it in an Integer Variable. Let's put it in N1. Note also, that you can dynamically assign the "X" and "Y" using ADDITIONAL integer Variables. Let's make X=%N24% and Y=%N25%.

 

There's a specific color you want to look for... Let's use the example "16777215," which the ME Mouse Locator tool is telling me is the background color of this text field I'm typing into.... Let assign N2=16777215.

 

At this point we have

N1 is the color that the GPC cmd is assessing.

N2 is the target color to compare it to.

N24 is the X coordinate of the GPC location and N25 is the Y coord.

 

We’ll create a macro that systematically checks each of the pixels one at a time, going left-to-right on the top row, then drops to the second row and repeats left-to-right until we get to the bottom-right corner. We’ll do this by creating a loop within a loop. The first loop will increment X by “1” until it gets to “1000,” then start over. This will be imbedded in another loop that increments Y by “1” until it gets to “800” then the entire screen will have been searched, pixel-by-pixel. (For now we’ll just do the loop—then we’ll add the GPC assessment.

So the code is:

Set N24=1

Set N25=1

Loop until N25 = 800

N25 = N25+1

//this part gets played 800 times, once for each row.

Loop until N24=1000

N24 = N24+1

//This part gets played 800,000 times, once for each pixel.

Repeat Loop

Repeat Loop

 

===============

Note: The loop thing has to make sense before the following will makes any sense…

================

 

There’re two more important parts. 1. We have to compare each pixel (i.e. N1) with the target color (i.e. N2). We’ll use the GPC cmd to capture each pixel. 2. We need to do a mouse click or some other command, then to stop (break) the loop if we find the desired color. We’ll do this with an “IF” statement.

 

So the code is

 

Set N2=16777215

Set N24=1

Set N25=1

Loop until N25 = 800

N25 = N25+1

Loop until N24=1000

GPC at coordinate N24,N25 and save to N1

IF N1=N2

THEN click the mouse or some other command…

BREAK from loop //macro ends

ELSE

N24 = N24+1

Repeat Loop

Repeat Loop

 

I think the point Cory was making is that if the thing you’re looking for is only one pixel in size, you’ll need to assess each of the (in our example) 800,000 pixels. HOWEVER, if it’s the size of an icon, then the target patch of color might be 10x10 pixels in size. If that’s the case, you could safely skip, only assessing every fifth pixel, and not have to worry about accidently “jumping” over it and missing the taget. If the color patch is 5x5 pixels, then assessing every 4th pixel should be safe.

Having “N=N+1” increments by one, so “N=N+5” increments by 5. If incrementing by 5, you'd only have to assess 1000/5=200 pixels by 800/5=160 pixels for a total of 32000 pixels (which is only 4% as many).

 

If any of you gurus see any errors or can clarify, then please do so….

 

 

===========

Question for the gurus: If you where looping until N24=1000, but then were to increment such that N24 never actually equaled exactly “1000,” Would the loop still terminate once N>1000????

 

-steve

Link to comment
Share on other sites

Pooh. THe code was supposed to be indented... I'll add dashes to represent indentation...

So the code is

 

Set N2=16777215

Set N24=1

Set N25=1

Loop until N25 = 800

--N25 = N25+1

--Loop until N24=1000

--GPC at coordinate N24,N25 and save to N1

----IF N1=N2

--------THEN click the mouse or some other command…

--------BREAK from loop //macro ends

----ELSE

--------N24 = N24+1

--Repeat Loop

Repeat Loop

 

SOo the main loop has no dashes;

The secondary inner loop has two dashes;

THe Logic statements inside the secondary loop have four;

And the commands to be executed IF this or ELSE that have eight.

Link to comment
Share on other sites

I have a generic macro which I call, supplying a pixel colour, a timeout in seconds, and any number of pairs of coordinates specifying a left-hand top and a right-hand bottom. Upon return, if the supplied number of seconds = 0, then we failed to find the pixel; otherwise we succeeded.

 

I can probably let you have a copy if you think it would be useful to you.

Link to comment
Share on other sites

Cory, Steve K, Paul,

 

You guys are great! I am starting to get it. Somewhat. I am computer nitwit. Learning a little at a time.

 

If any of you have an example, that would help me a lot. I have my screen resolution of 1280x1024.

 

Sometimes, the pixel is moved around in the top right quadrant. What I am looking to do is the top half of the top right quadrant and find that pixel color.

 

I would really only need to find it in top half of the quadrant. This would reduce it to 1/8th of the screen. That should reduce the pixel scan a bunch.

 

I am sure a lot of people are in the dark regarding pixel color and how they work(including myself).

 

So based on this, am I correct to say that:

 

If splitting the pixel box into quadrants, then the top right quadrant is:

 

(640,1) Left Top

(1280,1) Right, Top

(640, 512) Bottom, Left

(1280, 512) Bottom right

 

Correct?

 

Going further splitting the quadrant in another half, the top half(splitting it across the middle)would be this:

 

(640, 1) Top right

(640, 256) Bottom right

(1280, 1) Top right

(1280, 256) bottom right

 

 

Is this correct?

 

 

Thank You!

 

Pat

Link to comment
Share on other sites

Open the ME editor and go to the Tools menu... One of the items is the "Mouse Locator" tool.

This will give you the numbers you need as X,Y.

I mis-wrote on my last post... I see now that the top/left pixel is actually 0,0 rather than 1,1. Sorry about that..

 

An interesting thing I was thinking about last night... THe coordinate plain from algregra lists the BOTTOM/left as the 0,0 point. Computers always use the TOP/left though... I guess because that's the direction we read in for English.

 

I'm curious, what is it that you're 'looking for' on the screen?

 

-steve

Link to comment
Share on other sites

Here's a simple loop that I made when I was trying to figure out a problem posed on another post. I never figured out the problem, but the loop is a simple loop with a logic statement that let's you 'break' the loop.... Paste the code into a macro that is triggered by a hotkey such as ##looper. Then open WOrd or Note Pad and type the hotkey...

 

<TBOX4:T:1:CenterCenter000278000200:000:Macro StartedDo you have and active text window ready?><REP3:08:000002:000001:0001:1:01:T1><TEXTTYPE:The loop runs once more...<ENTER>><IFMESS3:00000:2:2:"If Message" boxIf you want the loop to STOP, click OK.000027:000468><EXITREP><ENDIF><ENDREP><TBOX4:T:1:CenterCenter000278000200:000:Macro Complete.Done!>

 

Hope this helps. -steve

Link to comment
Share on other sites

Of course I remember you Pat! And I realize you're a newb but this is easier than you think. I looked at the data format for BMP and it's even easier than I thought. The header is really simple and has everything you need to find your pixel. Forget the "Get Pixel Color" I think I'm going to try this next time. The header has several bits of info like size and most importantly color depth. You already know the size so you can figure out the pixel position with a little math. The good thing about this is that it all happens at light speed. Now I've never done this before but you can bet I will next time. I think I'll do an example on my website as this could be really valuable for all. But basically the 10th byte shows the beginning of the pixel data. If you know that and the size of your screen it's easy to divine the position. I did a quick 'look see' and created a 100X100 yellow block. Viewing the file in hex the 10th byte is 36hex (54 decimal). Now the BMP is 24bit so each pixel is 3 bytes (24/8). So 36-38 is "00 FF FF". FFFF in hex is 65535 decimal which is, drum roll please, yellow! After that it's just a repeating pattern of that data. Since it's uncompressed the formula is simple. First we do a Set Integer to Position in Text. If it's zero, skip it. If not take that number and subtract the offset then, in this case divide by 3. This is how many pixels in it is. Now divide by the width of your screen and this number is the row (Y) and the remainder is the column (X). Might need to add one in here at some point for rounding but this is super simple. When I get some more time I'll make an example on my website.

Link to comment
Share on other sites

Thanks Cory. Thanks Steve. Thanks Paul.

 

Whatever idea you have would be great. This noob/ignoramus(when it comes to computers, of course) would be grateful.

 

Let me give you an idea of what I am doing.

 

I am using a database. For some unknown reason, the list of icons on the MENU bar keeps moving around. Only God knows why it does this. I know how to use pixel command to click on it IF it stayed in the same place, but for some reason it moves along the menu bar, but only in that 1/8 top right corner!!!!

 

Everytime I open the database and have the mouse click on the icon, sometimes it's there and sometimes it moves over a space right or left of the prior location.

 

Yes, it does have unique colors in the icon graphic so just scanning the top 1/8th of the screen/window would suffice to find the unique pixel color.

 

I ONLY have to do it ONCE when the program opens.

 

I feel if i ask someone for a complete macro, it would be cheating on a test. I don't want to take up anyone's time to write this completely, but if someone could at least start the script for me, I could experiment and still ask questions as I go along.

 

Thank you all!

 

Pat

Link to comment
Share on other sites

Hey! I figured it out? Isn't that amazing? Sometimes I even scare myself.

 

 

Here it is:

 

<REP3:01:001050:000001:01280:1:08:><DIS:<NMVAR:01:08:1:0000008:2:0000001><MMS2:8N,46><GETPXM:8><GETPX:1:S:001067:000046><IFVAR2:5:01:1:N8><LCLK><MSTOP><ENDIF><ENDREP><DIS:<IFMOUSE:13><DIS:<BREAK>

 

This macro runs along a straight line(46) (for a portion of the screen)until it hits the pixel color!

 

Hey, even blind squirell's find the nut sometime!

 

-P

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...