room101/EFFECTS.CPP

78 lines
2.3 KiB
C++
Raw Permalink Normal View History

#include "effects.hpp"
/*******************************************************************************
** EffectTile
*******************************************************************************/
void
EffectTile(Picture* dst, Picture* src, int dx, int dy)
{
while (dx < 0) dx += src->width;
while (dy < 0) dy += src->height;
dx = (dx % src->width ) - src->width;
dy = (dy % src->height) - src->height;
for (int y = dy; y < dst->height; y += src->height)
{
for (int x = dx; x < dst->width; x += src->width)
{
PictureCopy(
PICTURE_COPY,
dst, x, y, x + src->width, y + src->height,
src, 0, 0, src->width, src->height,
0, 0, 0);
}
}
}
/*******************************************************************************
** EffectDownSample
*******************************************************************************/
void
EffectDownSample(Picture* dst, Picture* src)
{
PictureCreate(dst, src->width >> 1, src->height >> 1, 0, 0);
for (int y = 0; y < dst->height; y++)
{
Pixel* O = dst->pixels[y];
Pixel* A = src->pixels[(y << 1) + 0];
Pixel* B = src->pixels[(y << 1) + 1];
for (int x = 0; x < dst->width; x++)
{
*O++ = PIXEL_BLEND(PIXEL_BLEND(*A++, *B++), PIXEL_BLEND(*A++, *B++));
}
}
}
/*******************************************************************************
** EffectRipple
*******************************************************************************/
void
EffectRipple(Picture* dst, Picture* src, float wavelength, float amplitude, float offset)
{
int w = src->width;
int h = src->height;
assert(src != dst && dst->width == w && dst->height == h);
for (int y = 0; y < h; y++)
{
int x = Round(sin((y * wavelength + offset) * DTOR) * amplitude);
PictureCopy(PICTURE_COPY,
dst, x, y, x + w, y + 1,
src, 0, y, w, y + 1,
0, 0, 0);
PictureCopy(PICTURE_COPY,
dst, x - w, y, x, y + 1,
src, 0, y, w, y + 1,
0, 0, 0);
PictureCopy(PICTURE_COPY,
dst, x + w, y, x + w + w, y + 1,
src, 0, y, w, y + 1,
0, 0, 0);
}
}