* Shifts all the colors in the surface by a set amount. * This is a common method in 8bpp games to simulate color * effects for cheap. * @param off Amount to shift. * @param min Minimum color to shift to. * @param max Maximum color to shift to. * @param mul Shift multiplier. */
| 401 | * @param mul Shift multiplier. |
| 402 | */ |
| 403 | void Surface::offset(int off, int min, int max, int mul) |
| 404 | { |
| 405 | if (off == 0) |
| 406 | return; |
| 407 | |
| 408 | // Lock the surface |
| 409 | lock(); |
| 410 | |
| 411 | for (int x = 0, y = 0; x < getWidth() && y < getHeight();) |
| 412 | { |
| 413 | Uint8 pixel = getPixel(x, y); |
| 414 | int p; |
| 415 | if (off > 0) |
| 416 | { |
| 417 | p = pixel * mul + off; |
| 418 | } |
| 419 | else |
| 420 | { |
| 421 | p = (pixel + off) / mul; |
| 422 | } |
| 423 | if (min != -1 && p < min) |
| 424 | { |
| 425 | p = min; |
| 426 | } |
| 427 | else if (max != -1 && p > max) |
| 428 | { |
| 429 | p = max; |
| 430 | } |
| 431 | |
| 432 | if (pixel > 0) |
| 433 | { |
| 434 | setPixelIterative(&x, &y, p); |
| 435 | } |
| 436 | else |
| 437 | { |
| 438 | setPixelIterative(&x, &y, 0); |
| 439 | } |
| 440 | } |
| 441 | |
| 442 | // Unlock the surface |
| 443 | unlock(); |
| 444 | } |
| 445 | |
| 446 | /** |
| 447 | * Inverts all the colors in the surface according to a middle point. |