Advertisement
GeeckoDev

camembert

Sep 3rd, 2012
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.34 KB | None | 0 0
  1. #include <Imlib2.h>
  2. #include <math.h>
  3. #include <stdio.h>
  4.  
  5. static int u, v;
  6.  
  7. int compute(int w, int h)
  8. {
  9.     u = cosf(60.f * 3.14159f / 180.f) * h;
  10.     v = sinf(60.f * 3.14159f / 180.f) * h;
  11. }
  12.  
  13. int collide(int x, int y, int w, int h)
  14. {
  15.     int t = x - w/2;
  16.  
  17.     return
  18.         h - y < sqrtf(h*h - t*t)    && // circle bound
  19.         h - y >  v * t / u          && // bottom-right bound
  20.         h - y > -v * t / u           ; // bottom-left bound
  21. }
  22.  
  23. int main(int argc, char **argv)
  24. {
  25.     Imlib_Image img;
  26.     Imlib_Image cropped_img;
  27.     DATA32 *data;
  28.     int w, h;
  29.     int i, j;
  30.  
  31.     if (argc != 3)
  32.         return 1;
  33.  
  34.     img = imlib_load_image(argv[1]);
  35.  
  36.     if (!img)
  37.         return 2;
  38.  
  39.     imlib_context_set_image(img);
  40.     imlib_image_set_has_alpha(1);
  41.  
  42.     data = imlib_image_get_data();
  43.     w = imlib_image_get_width();
  44.     h = imlib_image_get_height();
  45.  
  46.     compute(w, h);
  47.  
  48.     for (i=0; i<h; i++)
  49.     {
  50.         for (j=0; j<w; j++)
  51.         {
  52.             if (!collide(j, i, w, h))
  53.                 *data = 0; // Fully transparent black
  54.  
  55.             data++;
  56.         }
  57.     }
  58.  
  59.     cropped_img = imlib_create_cropped_image(w/2 - u, 0, 2*u, h);
  60.     imlib_free_image_and_decache();
  61.  
  62.     imlib_context_set_image(cropped_img);
  63.     imlib_save_image(argv[2]);
  64.     imlib_free_image_and_decache();
  65.  
  66.     return 0;
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement