Bool GLCD_checkBresenhamCorner(uint16_t h, uint16_t k, uint16_t r,
uint16_t which, uint16_t xC, uint16_t yC) {
int x = 0;
int y = r;
int p = (3 - (2 * r));
do {
switch (which) {
case 1: {//Testing if its outside the top left corner
if (xC <= h - x && yC <= k - y) {
return 0;
} else if (xC <= h - y && yC <= k - x) {
return 0;
}
break;
}
case 2: {//Testing if its outside the top right corner
if (xC >= h + y && yC <= k - x) {
return 0;
} else if (xC >= h + x && yC <= k - y) {
return 0;
}
break;
}
case 3: {//Testing if its outside the bottom right corner
if (xC >= h + x && yC >= k + y) {
return 0;
} else if (xC >= h + y && yC >= k + x) {
return 0;
}
break;
}
case 4: {//Testing if its outside the bottom left corner
if (xC <= h - y && yC >= k + x) {
return 0;
} else if (xC <= h - x && yC >= k + y) {
return 0;
}
break;
}
}
x++;
if (p < 0)
p += ((4 * x) + 6);
else {
y--;
p += ((4 * (x - y)) + 10);
}
} while (x <= y);
return 1;
}
void GLCD_displayBitmapInCirle(uint16_t x, uint16_t y, uint16_t w, uint16_t h,
uint16_t r, uint16_t * bitmap) {
uint16_t atx = 0, aty = 0;
uint16_t j = 0;
uint16_t k = 0;
uint16_t index = 0;
for (k = 0; k < h; k++) {
for (j = 0; j < w; j++) {
atx = x + j;
aty = y + k;
if (atx <= x + r && aty <= y + r) { //is it in the top left corner
if (GLCD_checkBresenhamCorner(x + r, y + r, r, 1, atx, aty)
== 1) {
GLCD_SetPixel_16bpp(atx, aty, bitmap[index]);
}
} else if (atx >= x + w - r && aty <= y + r) { //is it in the top right corner
if (GLCD_checkBresenhamCorner(x + w - r, y + r, r, 2, atx, aty)
== 1) {
GLCD_SetPixel_16bpp(atx, aty, bitmap[index]);
}
} else if (atx >= x + w - r && aty >= y + h - r) { //is it in the bottom right corner
if (GLCD_checkBresenhamCorner(x + w - r, y + h - r, r, 3, atx,
aty) == 1) {
GLCD_SetPixel_16bpp(atx, aty, bitmap[index]);
}
} else if (atx <= x + r && aty >= y + h - r) { //is it in the bottom left corner
if (GLCD_checkBresenhamCorner(x + r, y + h - r, r, 4, atx, aty)
== 1) {
GLCD_SetPixel_16bpp(atx, aty, bitmap[index]);
}
} else { //its not in a corner so draw it
GLCD_SetPixel_16bpp(atx, aty, bitmap[index]);
}
index++;
}
}
x++;
}
|