Advertisement
LilChicha174

Untitled

Apr 24th, 2022
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 4.20 KB | None | 0 0
  1. struct Png{
  2.     int width, height;
  3.     png_byte color_type;
  4.     png_byte bit_depth;
  5.  
  6.     png_structp png_ptr;
  7.     png_infop info_ptr;
  8.     png_byte **row_pointers;
  9. };
  10.  
  11. void print_info(struct Png *image){
  12.     printf("Ширина в пикселях: %d\n", image->width);
  13.     printf("Высота в пикселях: %d\n", image->height);
  14.     printf("Тип цвета: %u\n", image->color_type);
  15.     printf("Глубина цвета: %u бит\n", image->bit_depth);
  16. }
  17.  
  18. void draw_Circle(struct Png *image, int x0, int y0, int line_fat, int width_pixel, int Red, int Green, int Blue) {
  19.     int x = 0;
  20.     int radius = line_fat / 2;
  21.     int y = radius;
  22.     int start = y0 - radius;
  23.     int end = y0 + radius;
  24.     int delta = 1 - 2 * radius;
  25.     int error;
  26.     while(y >= 0) {
  27.         png_byte *row = image->row_pointers[y0 + y];
  28.         png_byte *ptr = &(row[(x0 + x) * width_pixel]);
  29.         ptr[0] = Red;
  30.         ptr[1] = Green;
  31.         ptr[2] = Blue;
  32.  
  33.         png_byte *row1 = image->row_pointers[y0 - y];
  34.         png_byte *ptr1 = &(row1[(x0 + x) * width_pixel]);
  35.         ptr1[0] = Red;
  36.         ptr1[1] = Green;
  37.         ptr1[2] = Blue;
  38.  
  39.         png_byte *row2 = image->row_pointers[y0 + y];
  40.         png_byte *ptr2 = &(row2[(x0 - x) * width_pixel]);
  41.         ptr2[0] = Red;
  42.         ptr2[1] = Green;
  43.         ptr2[2] = Blue;
  44.  
  45.         png_byte *row3 = image->row_pointers[y0 - y];
  46.         png_byte *ptr3 = &(row3[(x0 - x) * width_pixel]);
  47.         ptr3[0] = Red;
  48.         ptr3[1] = Green;
  49.         ptr3[2] = Blue;
  50.         error = 2 * (delta + y) - 1;
  51.         while(start <= y0) {
  52.             for (int i = abs(x - x0); i < (x + x0); i++) {
  53.                 png_byte *row4 = image->row_pointers[start];
  54.                 png_byte *ptr4 = &(row4[i * width_pixel]);
  55.                 ptr4[0] = Red;
  56.                 ptr4[1] = Green;
  57.                 ptr4[2] = Blue;
  58.  
  59.                 png_byte *row5 = image->row_pointers[end];
  60.                 png_byte *ptr5 = &(row5[i * width_pixel]);
  61.                 ptr5[0] = Red;
  62.                 ptr5[1] = Green;
  63.                 ptr5[2] = Blue;
  64.             }
  65.             if(error > 0) {
  66.                 start++;
  67.                 end--;
  68.             }
  69.             break;
  70.         }
  71.         if(delta < 0 && error <= 0) {
  72.             ++x;
  73.             delta += 2 * x + 1;
  74.             continue;
  75.         }
  76.         error = 2 * (delta - x) - 1;
  77.         if(delta > 0 && error > 0) {
  78.             --y;
  79.             delta += 1 - 2 * y;
  80.             continue;
  81.         }
  82.         ++x;
  83.         delta += 2 * (x - y);
  84.         --y;
  85.     }
  86. }
  87.  
  88. void paint_line(struct Png *image, int width_pixel, int x0, int y0, int x1, int y1, int line_fat, int Red, int Green, int Blue){
  89.     int A, B, sign;
  90.     A = y1 - y0;
  91.     B = x0 - x1;
  92.     if (abs(A) > abs(B)) sign = 1;
  93.     else sign = -1;
  94.     int signa, signb;
  95.     if (A < 0) signa = -1;
  96.     else signa = 1;
  97.     if (B < 0) signb = -1;
  98.     else signb = 1;
  99.     int f = 0;
  100.     png_byte *row = image->row_pointers[y0];
  101.     png_byte *ptr = &(row[x0 * width_pixel]);
  102.     ptr[0] = Red;
  103.     ptr[1] = Green;
  104.     ptr[2] = Blue;
  105.     draw_Circle(image, x0, y0, line_fat, width_pixel, Red, Green, Blue);
  106.     int x = x0, y = y0;
  107.     if (sign == -1){
  108.         do {
  109.             f += A * signa;
  110.             if (f > 0)
  111.             {
  112.                 f -= B * signb;
  113.                 y += signa;
  114.             }
  115.             x -= signb;
  116.             png_byte *row1 = image->row_pointers[y];
  117.             png_byte *ptr1 = &(row1[x * width_pixel]);
  118.             ptr1[0] = Red;
  119.             ptr1[1] = Green;
  120.             ptr1[2] = Blue;
  121.             draw_Circle(image, x, y, line_fat, width_pixel, Red, Green, Blue);
  122.         } while (x != x1 || y != y1);
  123.     }
  124.     else
  125.     {
  126.         do {
  127.             f += B * signb;
  128.             if (f > 0) {
  129.                 f -= A * signa;
  130.                 x -= signb;
  131.             }
  132.             y += signa;
  133.             png_byte *row2 = image->row_pointers[y];
  134.             png_byte *ptr2 = &(row2[x * width_pixel]);
  135.             ptr2[0] = Red;
  136.             ptr2[1] = Green;
  137.             ptr2[2] = Blue;
  138.             draw_Circle(image, x, y, line_fat, width_pixel, Red, Green, Blue);
  139.         } while (x != x1 || y != y1);
  140.     }
  141. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement