The program [initially] runs so much quicker than with the original pixelgetcolor code, but unfortunately I won't be able to use it if I can't get this issue fixed. I would be very grateful if you could offer any advice.

(Also, during the checkseatstatus function, I had to give the two uses of the CGDipSnapShot different names (originally they both used the variable "snap", now they have been changed to "snap1" and "snap2") even though they are used one after the other, because originally the second use was returning a result of zero each time the red colour component was read. NB: Parts of the code have been revised since I made those name changes- in case that may be relevant.)

Thank you!

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus

;------------------------------------------------------------------------

;------------------------------------------------------------------------

;------------------------CGdipSnapShot Functions-------------------------

;------------------------------------------------------------------------

;------------------------------------------------------------------------

;Average Colour Function

;Checks 100* pixels within the rectangle to find the average colour

;(*as long as dimensions are greater than 20, else it's one check per pixel per dimension <= 20)

AveCol(x,y,w,h)

{

blue := 0

green := 0

red := 0

snap := new CGdipSnapshot(x,y,w,h)

snap.TakeSnapShot

if (w > 20) then

{

loopw := 10

} else {

loopw := w

}

if (h > 20) then

{

looph := 10

} else {

looph := h

}

stepw := floor(w/10)

steph := floor(h/10)

count1 := 0

Loop %loopw%

{

count2 := 0

Loop %looph%

{

blue := blue + snap.Pixelsnap[count1,count2].b

green := green + snap.Pixelsnap[count1,count2].g

red := red + snap.Pixelsnap[count1,count2].r

count2 := count2 + steph

}

count1 := count1 + stepw

}

Blue := (blue/(loopw*looph))

Green := (green/(loopw*looph))

Red := (red/(loopw*looph))

;return Blue + Green + Red

return [Blue,Green,Red]

}

CheckBattery(Tablex,Tabley,Tablewidth,Tableheight)

{

Global head

x := Tablex + (0.919 * TableWidth)

y := Tabley + Head + (0.015 * (TableHeight-Head))

w := ((0.948 - 0.919) * TableWidth)

h := ((0.019 - 0.015) * (TableHeight-Head))

x1 := Tablex + (0.467 * TableWidth)

y1 := Tabley + Head + (0.947 * (TableHeight-Head))

colourcheck := AveCol(x,y,w,h)

blue := colourcheck[1]

green := colourcheck[2]

red := colourcheck[3]

if ((abs(blue-45)<25) and (abs(green-70)<25) and (abs(red-25)<15)) then

{

BatteryShown := 1

GreenShown := 1

} else {

BatteryShown := 0

GreenShown := 0

}

colourcheck := AveCol(x1,y1,1,1)

blue := colourcheck[1]

green := colourcheck[2]

red := colourcheck[3]

if ((abs(Blue-158)<20) and (abs(Green-223)<20) and (abs(Red-254)<20)) or ((abs(Blue-52)<10) and (abs(Green-39)<10) and (abs(Red-31)<10)) then

{

;Logo (or results page) showing, so Battery not showing

} else {

BatteryShown := 1

}

return [greenshown,batteryshown]

}

FeltColourCheck(x,y,w,h)

{

colourcheck := avecol(x,y,w,h)

blue := colourcheck[1]

green := colourcheck[2]

red := colourcheck[3]

tabcol := 0

if ((abs(blue-80)<40) and (abs(green-45)<40) and (abs(red-0)<30)) then

{

TabCol := 1

}

if ((abs(blue-40)<20) and (abs(green-40)<20) and (abs(red-40)<20) and (abs(blue-red)<5)) then

{

TabCol := 2

}

if ((abs(blue-130)<40) and (abs(green-70)<25) and (abs(red-50)<20)) then

{

TabCol := 3

}

if ((abs(blue-40)<20) and (abs(green-85)<25) and (abs(red-17)<30)) then

{

TabCol := 4

}

;msgbox %blue%, %green%, %red%

return tabcol

}

CheckSeatStatus(x,y,w,h,x1,y1,t)

{

Global head

fx := x + ((x1 - 0.033) * w)

fy := y + head + ((y1 - 0.013) * (h - head))

fw := (0.033 + 0.033) * w

fh := (0.013 + 0.013) * (h - head)

colourcheck := AveCol(fx,fy,fw,fh)

blue := colourcheck[1]

green := colourcheck[2]

red := colourcheck[3]

filled := 1

open := 0

balance := 0

if ((abs(blue-120)<45) and (abs(green-75)<25) and (abs(red-0)<22) and (t = 1)) then

{

filled := 0

}

if ((abs(blue-35)<20) and (abs(green-35)<20) and (abs(red-35)<20) and (abs(blue-red)<10) and (t = 2)) then

{

filled := 0

}

if ((abs(blue-115)<25) and (abs(green-70)<25) and (abs(red-50)<20) and (t = 3)) then

{

filled := 0

}

if ((abs(blue-40)<15) and (abs(green-75)<20) and (abs(red- 20)<10) and (t = 4)) then

{

filled := 0

}

if (filled = 0) then

{

;perfrom one more filled check, on the balance/writing under avatar, in case avatar colour is similar to background

qx := x + ((x1 - 0.025) * w)

qy := y + head + ((y1 + 0.055) * (h - head))

qw := (0.025 + 0.025) * w

qh := (0.060 - 0.055) * (h - head)

snap1 := new CGdipSnapshot(qx,qy,qw,qh)

snap1.TakeSnapShot

count1 := 0

Loop %qw%

{

count2 := 0

Loop %qh%

{

red := snap1.Pixelsnap[count1,count2].r

if (red > 100) then

balance := balance + 1

count2 := count2 + 1

}

count1 := count1 + 1

}

if (balance > 1) then

{

filled := 1

}

}

if (filled < 2) then

{

;check for Open seat

ox := x + ((x1 - 0.033) * w)

oy := y + head + ((y1 - 0.003) * (h - head))

ow := (0.033 + 0.033) * w

oh := (0.003 + 0.003) * (h - head)

snap2 := new CGdipSnapshot(ox,oy,ow,oh)

snap2.TakeSnapShot

count1 := 0

Loop %ow%

{

count2 := 0

Loop %oh%

{

red := snap2.Pixelsnap[count1,count2].r

if ((t = 1) and (red > 20)) then

{

open := open + 1

}

if ((t = 2) and (red > 48)) then

{

open := open + 1

}

if ((t = 3) and (red > 65)) then

{

open := open + 1

}

if ((t = 4) and (red > 37)) then

{

open := open + 1

}

count2 := count2 + 1

}

count1 := count1 + 1

}

}

return [filled,open]

}