Skip to content

Commit 23323f4

Browse files
committed
Aliased circle image generation on examples.
1 parent 2cef7c9 commit 23323f4

File tree

3 files changed

+61
-0
lines changed

3 files changed

+61
-0
lines changed
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/*
2+
* Copyright 2024 Nathanne Isip
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
#include <math.h>
18+
#include <mdif.h>
19+
#include <stdio.h>
20+
#include <stdlib.h>
21+
22+
void draw_circle(mdif_t* image, int centerX, int centerY, int radius) {
23+
int width = image->width;
24+
int height = image->height;
25+
26+
for (int y = 0; y < height; y++) {
27+
for (int x = 0; x < width; x++) {
28+
int dx = x - centerX;
29+
int dy = y - centerY;
30+
31+
if (dx * dx + dy * dy <= radius * radius) {
32+
image->red[y * width + x] = 255;
33+
image->green[y * width + x] = 255;
34+
image->blue[y * width + x] = 255;
35+
image->alpha[y * width + x] = 255;
36+
}
37+
}
38+
}
39+
}
40+
41+
int main() {
42+
mdif_t image, aliased;
43+
mdif_init(&image, 256, 256);
44+
45+
draw_circle(&image, 128, 128, 50);
46+
mdif_antialias(&image, &aliased);
47+
48+
if(mdif_write("circle_image.mdif", &image) != MDIF_ERROR_NONE) {
49+
fprintf(stderr, "Failed to write MDIF image to file.\r\n");
50+
mdif_free(&image);
51+
return EXIT_FAILURE;
52+
}
53+
54+
mdif_free(&image);
55+
mdif_free(&aliased);
56+
57+
printf("MDIF image with circle has been created successfully.\n");
58+
return 0;
59+
}

examples/aliased_circle/build.bat

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
g++ -o ..\..\dist\aliased_circle.exe -I..\..\src ..\..\src\mdif.cpp aliased_circle.cpp

examples/aliased_circle/build.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
g++ -o ../../dist/aliased_circle -I../../src ../../src/mdif.cpp aliased_circle.cpp

0 commit comments

Comments
 (0)