|
|
@ -377,6 +377,42 @@ void Raster::drawImageWithKey(int startX, int startY, const Image* image, Rgba k |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
void Raster::drawImageAlphaTest(int startX, int startY, const Image* image, byte alpha) { |
|
|
|
/*越界部分不描画*/ |
|
|
|
int left = tmax<int>(startX, 0); |
|
|
|
int bottom = tmax<int>(startY, 0); |
|
|
|
|
|
|
|
int right = tmin<int>(startX + image->width(), _width); |
|
|
|
int top = tmin<int>(startY + image->height(), _height); |
|
|
|
|
|
|
|
for (int x = left; x < right; x++) { |
|
|
|
for (int y = bottom; y < top; y++) { |
|
|
|
Rgba color = image->pixelAt(x - left, y - bottom); |
|
|
|
if (color._a > alpha) { |
|
|
|
setPixel(x, y, color); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
void Raster::drawImageAlphaBlend(int startX, int startY, const Image* image, float alpha) { |
|
|
|
/*越界部分不描画*/ |
|
|
|
int left = tmax<int>(startX, 0); |
|
|
|
int bottom = tmax<int>(startY, 0); |
|
|
|
|
|
|
|
int right = tmin<int>(startX + image->width(), _width); |
|
|
|
int top = tmin<int>(startY + image->height(), _height); |
|
|
|
|
|
|
|
for (int x = left; x < right; x++) { |
|
|
|
for (int y = bottom; y < top; y++) { |
|
|
|
Rgba dstColor = image->pixelAt(x - left, y - bottom); |
|
|
|
Rgba srcColor = getPixel(x, y); |
|
|
|
Rgba color = colorLerp(srcColor, dstColor, dstColor._a / 255.0f * alpha); |
|
|
|
setPixel(x, y, color); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
int Raster::size() { |
|
|
|
return _width * _height * sizeof (Rgba); |
|
|
|
} |
|
|
@ -393,6 +429,10 @@ bool Raster::setPixel(int x, int y, Rgba color) { |
|
|
|
buffer[ ((_height - 1) - y) * _width + x] = color; |
|
|
|
} |
|
|
|
|
|
|
|
Rgba Raster::getPixel(int x, int y) { |
|
|
|
return buffer[ ((_height - 1) - y) * _width + x]; |
|
|
|
} |
|
|
|
|
|
|
|
bool Raster::isIn(int2 point) { |
|
|
|
if (point.x >= 0 && point.x <= _width && point.y >= 0 && point.y < _height) { |
|
|
|
return true; |
|
|
|