MCPcopy Create free account
hub / github.com/OpenXcom/OpenXcom / offset

Method offset

src/Engine/Surface.cpp:403–444  ·  view source on GitHub ↗

* 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. */

Source from the content-addressed store, hash-verified

401 * @param mul Shift multiplier.
402 */
403void 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.

Callers 6

getImageMethod · 0.45
blinkMethod · 0.45
recolorMethod · 0.45
mouseOverMethod · 0.45
drawMethod · 0.45
drawTrackMethod · 0.45

Calls

no outgoing calls

Tested by

no test coverage detected