draws simple or filled circle */
| 1451 | |
| 1452 | /* draws simple or filled circle */ |
| 1453 | static void |
| 1454 | Circle( Mat& img, Point center, int radius, const void* color, int fill ) |
| 1455 | { |
| 1456 | Size size = img.size(); |
| 1457 | size_t step = img.step; |
| 1458 | int pix_size = (int)img.elemSize(); |
| 1459 | uchar* ptr = img.data; |
| 1460 | int err = 0, dx = radius, dy = 0, plus = 1, minus = (radius << 1) - 1; |
| 1461 | int inside = center.x >= radius && center.x < size.width - radius && |
| 1462 | center.y >= radius && center.y < size.height - radius; |
| 1463 | |
| 1464 | #define ICV_PUT_POINT( ptr, x ) \ |
| 1465 | memcpy( ptr + (x)*pix_size, color, pix_size ); |
| 1466 | |
| 1467 | while( dx >= dy ) |
| 1468 | { |
| 1469 | int mask; |
| 1470 | int y11 = center.y - dy, y12 = center.y + dy, y21 = center.y - dx, y22 = center.y + dx; |
| 1471 | int x11 = center.x - dx, x12 = center.x + dx, x21 = center.x - dy, x22 = center.x + dy; |
| 1472 | |
| 1473 | if( inside ) |
| 1474 | { |
| 1475 | uchar *tptr0 = ptr + y11 * step; |
| 1476 | uchar *tptr1 = ptr + y12 * step; |
| 1477 | |
| 1478 | if( !fill ) |
| 1479 | { |
| 1480 | ICV_PUT_POINT( tptr0, x11 ); |
| 1481 | ICV_PUT_POINT( tptr1, x11 ); |
| 1482 | ICV_PUT_POINT( tptr0, x12 ); |
| 1483 | ICV_PUT_POINT( tptr1, x12 ); |
| 1484 | } |
| 1485 | else |
| 1486 | { |
| 1487 | ICV_HLINE( tptr0, x11, x12, color, pix_size ); |
| 1488 | ICV_HLINE( tptr1, x11, x12, color, pix_size ); |
| 1489 | } |
| 1490 | |
| 1491 | tptr0 = ptr + y21 * step; |
| 1492 | tptr1 = ptr + y22 * step; |
| 1493 | |
| 1494 | if( !fill ) |
| 1495 | { |
| 1496 | ICV_PUT_POINT( tptr0, x21 ); |
| 1497 | ICV_PUT_POINT( tptr1, x21 ); |
| 1498 | ICV_PUT_POINT( tptr0, x22 ); |
| 1499 | ICV_PUT_POINT( tptr1, x22 ); |
| 1500 | } |
| 1501 | else |
| 1502 | { |
| 1503 | ICV_HLINE( tptr0, x21, x22, color, pix_size ); |
| 1504 | ICV_HLINE( tptr1, x21, x22, color, pix_size ); |
| 1505 | } |
| 1506 | } |
| 1507 | else if( x11 < size.width && x12 >= 0 && y21 < size.height && y22 >= 0 ) |
| 1508 | { |
| 1509 | if( fill ) |
| 1510 | { |