Convert PNG images to HolyC data structures for drawing in TempleOS
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

54 lines
962 B

#ifndef PXBLOT_HC
#define PXBLOT_HC
class PxData {
I32 width;
I32 height;
U8 *body;
};
public U0 PxBlot(CDC *dc, PxData *data, I64 x, I64 y) {
// Cull
if (x >= dc->width_internal || y >= dc->height ||
x+data->width < 0 || y+data->height < 0) {
return;
}
// Clip X
I64 minX = 0;
if (x < 0) {
minX = -x;
x = 0;
}
I64 maxX = data->width;
if (maxX+x >= dc->width_internal) {
maxX -= maxX+x - dc->width_internal;
}
// Clip Y
I64 minY = 0;
if (y < 0) {
minY = -y;
y = 0;
}
I64 maxY = data->height;
if (maxY+y >= dc->height) {
maxY -= maxY+y - dc->height;
}
// Draw
I64 d = dc->body + y*dc->width_internal + x;
y = 0;
I64 dy, dx;
for (dy=minY; dy<maxY; y++, dy++) {
U8 *dst = d + y*dc->width_internal;
for (dx=minX; dx<maxX; dx++, dst++) {
U8 color = data->body[dy*data->width+dx];
if (color != TRANSPARENT) {
*dst = color;
}
}
}
}
#endif