Jump to content

_PixelFindAll()


Wolvereness
 Share

Recommended Posts

Okay, here is my script. If anyone has any improvements that can make it faster (very slow right now). It is pixel search but returns all pixels found in this format:

$Array[0][0] = Number of pixels found

$Array[0][1] = Color used to search (hexidecimal 6 places)

$Array[n>0][0] = The X axis of the nth number

$Array[n>0][1] = The Y axis of the nth number

The use of $shade is the max difference of the added up differences in the RGB colors...

Func _PixelFindAll($i_PosLeft, $i_PosTop, $i_Width, $i_Height, $i_Color, $i_Shade = 0, $i_Step = 1)
    If $i_PosLeft <> Abs(Int($i_PosLeft)) Or $i_PosTop <> Abs(Int($i_PosTop)) Or $i_Width <> Abs(Int($i_Width)) Or $i_Height <> Abs(Int($i_Height)) Or $i_Color <> Abs(Int($i_Color)) Or $i_Shade < 0 Or $i_Shade <> Abs(Int($i_Shade)) Or $i_Step = 0 Or $i_Step <> Abs(Int($i_Step)) Or $i_Color > 0xFFFFFF Or $i_PosLeft + $i_Width > @DesktopWidth Or $i_PosTop + $i_Height > @DesktopHeight Then
        Local $ai_Return[1][1]
        $ai_Return[0][0] = 0
        SetError(1)
        Return $ai_Return
    EndIf
    Local $ai_Return[$i_Width * $i_Height + 1][2]
    Local $ai_Original[3]
    Local $i_Count
    Local $i_Count_X
    Local $i_Count_Y
    Local $i_Found
    $ai_Return[0][0] = 0
    $ai_Return[0][1] = $i_Color
    $ai_Original[0] = BitAND(BitShift($i_Color, 16), 0xff)
    $ai_Original[1] = BitAND(BitShift($i_Color, 8), 0xff)
    $ai_Original[2] = BitAND($i_Color, 0xff)
    If $i_Width / $i_Step <> Int($i_Width / $i_Step) Then
        Do
            $i_Width = $i_Width - 1
        Until $i_Width / $i_Step = Int($i_Width / $i_Step) Or $i_Width = 0
    EndIf
    If $i_Height / $i_Step <> Int($i_Height / $i_Step) Then
        Do
            $i_Height = $i_Height - 1
        Until $i_Height / $i_Step = Int($i_Height / $i_Step) Or $i_Height = 0
    EndIf
    If $i_Width = 0 And $i_Height = 0 Then
        Local $ai_Return[1][1]
        $ai_Return[0][0] = 0
        SetError(1)
        Return $ai_Return
    EndIf
    For $i_Count_X = $i_PosLeft To $i_PosLeft + $i_Width - 1 Step $i_Step
        For $i_Count_Y = $i_PosTop To $i_PosTop + $i_Height - 1 Step $i_Step
            $i_Found = PixelGetColor($i_Count_X, $i_Count_Y)
            If Abs(BitAND(BitShift($i_Found, 16), 0xff) - $ai_Original[0]) + Abs(BitAND(BitShift($i_Found, 8), 0xff) - $ai_Original[1]) + Abs(BitAND($i_Found, 0xff) - $ai_Original[2]) <= $i_Shade Then
                $i_Count = $ai_Return[0][0] + 1
                $ai_Return[0][0] = $i_Count
                $ai_Return[$i_Count][0] = $i_Count_X
                $ai_Return[$i_Count][1] = $i_Count_Y
            EndIf
        Next
    Next
    $i_Count = $ai_Return[0][0]
    ReDim $ai_Return[$i_Count + 1][2]
    Return $ai_Return
EndFunc  ;==>_PixelFindAll
/Edit: LAST VERSION - FULLY WORKING Edited by Wolvereness

Offering any help to anyone (to my capabilities of course)Want to say thanks? Click here! [quote name='Albert Einstein']Only two things are infinite, the universe and human stupidity, and I'm not sure about the former.[/quote][quote name='Wolvereness' date='7:35PM Central, Jan 11, 2005']I'm NEVER wrong, I call it something else[/quote]

Link to comment
Share on other sites

Why do you return the users parameter directly back to them?

"I thoroughly disapprove of duels. If a man should challenge me, I would take him kindly and forgivingly by the hand and lead him to a quiet place and kill him." - Mark TwainPatient: "It hurts when I do $var_"Doctor: "Don't do $var_" - Lar.
Link to comment
Share on other sites

Why do you return the users parameter directly back to them?

<{POST_SNAPBACK}>

I understand+respect your opinion, but don't purposely give it just to make someone mad.

My opinion was that the space needed to be filled but with what I did not know. The best thing in my mind was the color they used as the user could easily recall it.

This is my choice isn't it?!

Edited by Wolvereness

Offering any help to anyone (to my capabilities of course)Want to say thanks? Click here! [quote name='Albert Einstein']Only two things are infinite, the universe and human stupidity, and I'm not sure about the former.[/quote][quote name='Wolvereness' date='7:35PM Central, Jan 11, 2005']I'm NEVER wrong, I call it something else[/quote]

Link to comment
Share on other sites

So?

Is shooting yourself in the foot a good choice?

Nopers.

Does removing that make it faster?

Yep. Not much, but yep.

EDIT:

Here's my try at it (couldn't get the line pixel search to work, so I decided to use this, probably not nearly as fast)

Func _PixelSearch($StartX, $StartY, $EndX, $EndY, $Color) 
   Local $aCoord, $Length, $Width, $Area,_
         $i, $x, $y, $CurrentElement = 1_
   
 ; Finding area of square to initiate array
   $Length = Abs($StartX - $EndX)
   $Width = Abs($StartY - $EndY)
   $Area = $Length * 2 + $Width * 2 
   Dim $aReturn[$Area + 1][2]

   For $x = $StartX to $EndX
      For $y = $StartY to $EndY
         If PixelGetColor( $x, $y) = $Color Then 
            $aReturn[$CurrentElement][0] = $x
            $aReturn[$CurrentElement][1] = $y
            $CurrentElement = $CurrentElement + 1
         EndIf
      Next
   Next

   ReDim $aReturn[$CurrentElement][2]
   $aReturn[0][0] = $CurrentElement
   Return $aReturn
EndFunc
Edited by Insolence
"I thoroughly disapprove of duels. If a man should challenge me, I would take him kindly and forgivingly by the hand and lead him to a quiet place and kill him." - Mark TwainPatient: "It hurts when I do $var_"Doctor: "Don't do $var_" - Lar.
Link to comment
Share on other sites

His point is that it would make it marginally faster. But even if they did use a formula, they could just put it in a variable and recall it later anyways.

And you need to chill out, why would you say "but don't purposely give it just to make someone mad" when he was just asking you why you have the piece of code in there?

Edited by ryeguy
Link to comment
Share on other sites

Thanks rye, that IS why I was asking... you still haven't given a reason.

I don't see a need for pixel variation, but it coudl be added fairly easily.

"I thoroughly disapprove of duels. If a man should challenge me, I would take him kindly and forgivingly by the hand and lead him to a quiet place and kill him." - Mark TwainPatient: "It hurts when I do $var_"Doctor: "Don't do $var_" - Lar.
Link to comment
Share on other sites

It does no harm, but it serves no purpose...

"I thoroughly disapprove of duels. If a man should challenge me, I would take him kindly and forgivingly by the hand and lead him to a quiet place and kill him." - Mark TwainPatient: "It hurts when I do $var_"Doctor: "Don't do $var_" - Lar.
Link to comment
Share on other sites

What are you talking about?

Who wants to use a big array like that to store a color, when you could just use 1 simple array? What is your problem? What you're doing is stupid, just admit it. You over-complicate things. My function does the same as yours (minus sanity checks and variation... which could easily be added) and is most likely faster.

It's much smaller and simpler... anyone can understand it. Why would you stem off of that and use a bunch of unneeded code?

"I thoroughly disapprove of duels. If a man should challenge me, I would take him kindly and forgivingly by the hand and lead him to a quiet place and kill him." - Mark TwainPatient: "It hurts when I do $var_"Doctor: "Don't do $var_" - Lar.
Link to comment
Share on other sites

Quite frankly, both of you are being whiny bitches about the whole thing and if you continue to argue over this, you're going to be on the negative side of the respect-o-meter with the forum veterans. Just something to think about before you go off on one another again.

Link to comment
Share on other sites

I did that for neatness... let me compare something:

$begin = TimerInit()
$var = _GetAllPixels ( 143, 45, 235, 56, 12895428 )
$dif = TimerDiff($begin)
MsgBox(0,"Time Difference",$dif)

$begin = TimerInit()
$var = _PixelFindAll ( 143, 45, 92, 11, 12895428 )
$dif = TimerDiff($begin)
MsgBox(0,"Time Difference",$dif)

Please correct me if I'm wrong in using your function... but mine is about 4 times faster.

EDIT-

Valik, I don't care what you or anyone else thinks. I'm only throwing insults because he is. I'm trying to find the best way to do this, I started with healthy debate and he got offended because he doesn't believe he's wrong.

If you don't mind settling this argument and saying who's right, I'd be more then happy to 'stop'.

Edited by Insolence
"I thoroughly disapprove of duels. If a man should challenge me, I would take him kindly and forgivingly by the hand and lead him to a quiet place and kill him." - Mark TwainPatient: "It hurts when I do $var_"Doctor: "Don't do $var_" - Lar.
Link to comment
Share on other sites

All I wanted was for him to leave my opinion alone and not spam up this topic. - Deleting my posts, hopefully he wont try to continue this.

Oh wait, he already did while I was writing...

However much I'd love to make his ignorance shine, I wont.

Edited by Wolvereness

Offering any help to anyone (to my capabilities of course)Want to say thanks? Click here! [quote name='Albert Einstein']Only two things are infinite, the universe and human stupidity, and I'm not sure about the former.[/quote][quote name='Wolvereness' date='7:35PM Central, Jan 11, 2005']I'm NEVER wrong, I call it something else[/quote]

Link to comment
Share on other sites

Wolverness you keep ignoring me. You gave no examples, mine's 4x faster.

EDIT -

Valik, right about what? Geez you got sand in certain places or what... you sure seem to love grabbing ahold of your internet penis and flaunting it whenever you can.

Edited by Insolence
"I thoroughly disapprove of duels. If a man should challenge me, I would take him kindly and forgivingly by the hand and lead him to a quiet place and kill him." - Mark TwainPatient: "It hurts when I do $var_"Doctor: "Don't do $var_" - Lar.
Link to comment
Share on other sites

I'm adding insolence to ignore list, right by guido.

Insolence, please do not post in this topic any more.

If you would do that, I will also ask you to delete your posts in this topic.

This is an option, but your choice reflects your matureness.

Offering any help to anyone (to my capabilities of course)Want to say thanks? Click here! [quote name='Albert Einstein']Only two things are infinite, the universe and human stupidity, and I'm not sure about the former.[/quote][quote name='Wolvereness' date='7:35PM Central, Jan 11, 2005']I'm NEVER wrong, I call it something else[/quote]

Link to comment
Share on other sites

Your choice to avoid my questions and get offended by simple questions reflects your matureness. Your unability to deal with me just shows how ignorant you are.

"I thoroughly disapprove of duels. If a man should challenge me, I would take him kindly and forgivingly by the hand and lead him to a quiet place and kill him." - Mark TwainPatient: "It hurts when I do $var_"Doctor: "Don't do $var_" - Lar.
Link to comment
Share on other sites

@Wolvereness

Nice UDF, thanks for sharing.

@Insolence

Please start your own thread, if you have a UDF to share.

@Both of you

This is Scripts and Scraps. Where good scripts are shared amongst the community and constructive opinions maybe given.

Let's try to minimize personal attacks.

Link to comment
Share on other sites

Believe me, I tried... I'm just trying to show him a different way of doing it and he refuses to do anything that isn't his way :idiot:

"I thoroughly disapprove of duels. If a man should challenge me, I would take him kindly and forgivingly by the hand and lead him to a quiet place and kill him." - Mark TwainPatient: "It hurts when I do $var_"Doctor: "Don't do $var_" - Lar.
Link to comment
Share on other sites

Believe me, I tried... I'm just trying to show him a different way of doing it and he refuses to do anything that isn't his way :idiot:

<{POST_SNAPBACK}>

Exactly, I will refuse to do it if it isn't my way. You can't force me to do or think anything. But if someone were to give me a suggestion to make it faster, that would be cool.

If you want to discuss something with MHz, take it to PMs.

@MHz, thankyou for taking your time to look at it and the compliment.

Offering any help to anyone (to my capabilities of course)Want to say thanks? Click here! [quote name='Albert Einstein']Only two things are infinite, the universe and human stupidity, and I'm not sure about the former.[/quote][quote name='Wolvereness' date='7:35PM Central, Jan 11, 2005']I'm NEVER wrong, I call it something else[/quote]

Link to comment
Share on other sites

I did give you a suggestion.

I'll give you more, don't immidiately convert it to Hex... maybe add a flag for it. Try to be simpler. Also I suggest using the Top Left, Bottom Right scheme, instead of the width height.

"I thoroughly disapprove of duels. If a man should challenge me, I would take him kindly and forgivingly by the hand and lead him to a quiet place and kill him." - Mark TwainPatient: "It hurts when I do $var_"Doctor: "Don't do $var_" - Lar.
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...