Untitled
unknown
c_cpp
3 years ago
1.4 kB
11
Indexable
void OverlayImageRect(RwRGBA *target, int targetWidth, RwRGBA *source, int sourceWidth, int offsetX, int offsetY, RwRect sourceRect) {
int width = sourceRect.w;
int height = sourceRect.h;
for (int y = offsetY; y < (offsetY + height); y++) {
int fY = y - offsetY + sourceRect.y;
for (int x = offsetX; x < (offsetX + width); x++) {
int fX = x - offsetX + sourceRect.x;
RwRGBA targetColor = target[y * targetWidth + x];
RwRGBA sourceColor = source[fY * sourceWidth + fX];
double opacity = sourceColor.alpha / 255.0f;
targetColor.red = (uint8_t)(targetColor.red * (1.0 - opacity) + opacity * sourceColor.red);
targetColor.green = (uint8_t)(targetColor.green * (1.0 - opacity) + opacity * sourceColor.green);
targetColor.blue = (uint8_t)(targetColor.blue * (1.0 - opacity) + opacity * sourceColor.blue);
targetColor.alpha = (uint8_t)(targetColor.alpha * (1.0 - opacity) + opacity * sourceColor.alpha);
target[y * targetWidth + x] = targetColor;
}
}
}
void ImageReplaceColor(RwRGBA *target, int width, int height, RwRGBA color) {
for (int y = 0; y < height; y++) {
for (int x = 0; x < width; x++) {
target[y * width + x].red = color.red;
target[y * width + x].green = color.green;
target[y * width + x].blue = color.blue;
}
}
}Editor is loading...