Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <Imlib2.h>
- #include <math.h>
- #include <stdio.h>
- static int u, v;
- int compute(int w, int h)
- {
- u = cosf(60.f * 3.14159f / 180.f) * h;
- v = sinf(60.f * 3.14159f / 180.f) * h;
- }
- int collide(int x, int y, int w, int h)
- {
- int t = x - w/2;
- return
- h - y < sqrtf(h*h - t*t) && // circle bound
- h - y > v * t / u && // bottom-right bound
- h - y > -v * t / u ; // bottom-left bound
- }
- int main(int argc, char **argv)
- {
- Imlib_Image img;
- Imlib_Image cropped_img;
- DATA32 *data;
- int w, h;
- int i, j;
- if (argc != 3)
- return 1;
- img = imlib_load_image(argv[1]);
- if (!img)
- return 2;
- imlib_context_set_image(img);
- imlib_image_set_has_alpha(1);
- data = imlib_image_get_data();
- w = imlib_image_get_width();
- h = imlib_image_get_height();
- compute(w, h);
- for (i=0; i<h; i++)
- {
- for (j=0; j<w; j++)
- {
- if (!collide(j, i, w, h))
- *data = 0; // Fully transparent black
- data++;
- }
- }
- cropped_img = imlib_create_cropped_image(w/2 - u, 0, 2*u, h);
- imlib_free_image_and_decache();
- imlib_context_set_image(cropped_img);
- imlib_save_image(argv[2]);
- imlib_free_image_and_decache();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement