| 3412 | |
| 3413 | |
| 3414 | void PixelSearch(Var *output_var_x, Var *output_var_y |
| 3415 | , int aLeft, int aTop, int aRight, int aBottom, COLORREF aColorRGB |
| 3416 | , int aVariation, bool aIsPixelGetColor, ResultToken &aResultToken) |
| 3417 | // Author: The fast-mode PixelSearch was created by Aurelian Maga. |
| 3418 | { |
| 3419 | // For maintainability, get RGB/BGR conversion out of the way early. |
| 3420 | COLORREF aColorBGR = rgb_to_bgr(aColorRGB); |
| 3421 | |
| 3422 | // Many of the following sections are similar to those in ImageSearch(), so they should be |
| 3423 | // maintained together. |
| 3424 | |
| 3425 | if (!aIsPixelGetColor) |
| 3426 | { |
| 3427 | output_var_x->Assign(); // Init to empty string regardless of whether we succeed here. |
| 3428 | output_var_y->Assign(); // Same. |
| 3429 | } |
| 3430 | |
| 3431 | POINT origin = {0}; |
| 3432 | CoordToScreen(origin, COORD_MODE_PIXEL); |
| 3433 | aLeft += origin.x; |
| 3434 | aTop += origin.y; |
| 3435 | aRight += origin.x; |
| 3436 | aBottom += origin.y; |
| 3437 | |
| 3438 | bool right_to_left = aLeft > aRight; |
| 3439 | bool bottom_to_top = aTop > aBottom; |
| 3440 | |
| 3441 | int left = aLeft; |
| 3442 | int top = aTop; |
| 3443 | int right = aRight; |
| 3444 | int bottom = aBottom; |
| 3445 | if (right_to_left) |
| 3446 | { |
| 3447 | left = aRight; |
| 3448 | right = aLeft; |
| 3449 | } |
| 3450 | if (bottom_to_top) |
| 3451 | { |
| 3452 | top = aBottom; |
| 3453 | bottom = aTop; |
| 3454 | } |
| 3455 | |
| 3456 | if (aVariation < 0) |
| 3457 | aVariation = 0; |
| 3458 | if (aVariation > 255) |
| 3459 | aVariation = 255; |
| 3460 | |
| 3461 | // Allow colors to vary within the spectrum of intensity, rather than having them |
| 3462 | // wrap around (which doesn't seem to make much sense). For example, if the user specified |
| 3463 | // a variation of 5, but the red component of aColorBGR is only 0x01, we don't want red_low to go |
| 3464 | // below zero, which would cause it to wrap around to a very intense red color: |
| 3465 | COLORREF pixel; // Used much further down. |
| 3466 | BYTE red, green, blue; // Used much further down. |
| 3467 | BYTE search_red, search_green, search_blue; |
| 3468 | BYTE red_low, green_low, blue_low, red_high, green_high, blue_high; |
| 3469 | if (aVariation > 0) |
| 3470 | { |
| 3471 | search_red = GetRValue(aColorBGR); |
no test coverage detected