Check a specific pixel color value (returns True/False)
| 419 | |
| 420 | // Check a specific pixel color value (returns True/False) |
| 421 | bool Frame::CheckPixel(int row, int col, int red, int green, int blue, int alpha, int threshold) { |
| 422 | int col_pos = col * 4; // Find column array position |
| 423 | if (!image || row < 0 || row >= (height - 1) || |
| 424 | col_pos < 0 || col_pos >= (width - 1) ) { |
| 425 | // invalid row / col |
| 426 | return false; |
| 427 | } |
| 428 | // Check pixel color |
| 429 | const unsigned char* pixels = GetPixels(row); |
| 430 | if (pixels[col_pos + 0] >= (red - threshold) && pixels[col_pos + 0] <= (red + threshold) && |
| 431 | pixels[col_pos + 1] >= (green - threshold) && pixels[col_pos + 1] <= (green + threshold) && |
| 432 | pixels[col_pos + 2] >= (blue - threshold) && pixels[col_pos + 2] <= (blue + threshold) && |
| 433 | pixels[col_pos + 3] >= (alpha - threshold) && pixels[col_pos + 3] <= (alpha + threshold)) { |
| 434 | // Pixel color matches successfully |
| 435 | return true; |
| 436 | } else { |
| 437 | // Pixel color does not match |
| 438 | return false; |
| 439 | } |
| 440 | } |
| 441 | |
| 442 | // Set Pixel Aspect Ratio |
| 443 | void Frame::SetPixelRatio(int num, int den) |