Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int is_not_painted_rect(struct Png *image, int width_pixel, int x, int y, int Red, int Green, int
- Blue) {
- png_byte *row = image->row_pointers[y];
- png_byte *ptr = &(row[x * width_pixel]);
- if ((ptr[0] == Red) && (ptr[1] == Green) && (ptr[2] == Blue)) {
- return 0;
- }
- return 1;
- }
- //проверка, является ли четырёхугольник по координатам прямоугольником
- int check_X_Y(struct Png *image, int x0, int y0, int *x1, int *y1, int *x2, int *y2, int *x3, int
- *y3, int *x4, int *y4, int width_pixel, int red0, int green0, int blue0) {
- int x1t = 0, y1t = 0, x2t = 0, y2t = 0, x3t = 0, y3t = 0, x4t = 0, y4t = 0;
- int flag = 0;
- png_byte *row = image->row_pointers[y0];
- for (int x = x0; x < image->width; x++) {
- png_byte *ptr = &(row[x * width_pixel]);
- if (ptr[0] == red0 && ptr[1] == green0 && ptr[2] == blue0) {
- if (flag == 0) {
- x1t = x, y1t = y0;
- flag++;
- }
- } else {
- if (x != (x0 + 1)) {
- x2t = x - 1, y2t = y0;
- flag++;
- break;
- } else {
- return 0;
- }
- }
- }
- for (int y = y0; y < image->height; y++) {
- png_byte *row = image->row_pointers[y];
- png_byte *ptr = &(row[x0 * width_pixel]);
- if (ptr[0] != red0 || ptr[1] != green0 || ptr[2] != blue0) {
- if (y != (y0 + 1) && flag == 2) {
- y3t = y - 1, x3t = x0;
- flag++;
- }
- }
- }
- for (int y = y0; y < image->height; y++) {
- png_byte *row = image->row_pointers[y];
- png_byte *ptr = &(row[x1t * width_pixel]);
- if (ptr[0] != red0 || ptr[1] != green0 || ptr[2] != blue0) {
- if (y != (y0 + 1) && flag == 3) {
- y4t = y - 1, x4t = x2t;
- flag++;
- }
- }
- }
- if (y4t != y3t)
- return 0;
- row = image->row_pointers[y3t];
- for (int x = x3t; x < x4t; x++) {
- png_byte *ptr = &(row[x * width_pixel]);
- if (ptr[0] != red0 || ptr[1] != green0 || ptr[2] != blue0) {
- return 0;
- }
- }
- *x1 = x1t, *y1 = y1t;
- *x2 = x2t, *y2 = y2t;
- *x3 = x3t, *y3 = y3t;
- *x4 = x4t, *y4 = y4t;
- return 1;
- }
- //перекраска прямоугольника
- void pouring_rectangle(struct Png *image, int width_pixel, int x, int y, int Red, int Green, int
- Blue, int Red_l, int Green_l, int Blue_l) {
- png_byte *row;
- png_byte *ptr;
- if (check(image, x, y)) {
- row = image->row_pointers[y];
- ptr = &(row[x * width_pixel]);
- if ((ptr[0] == Red_l) && (ptr[1] == Green_l) && (ptr[2] == Blue_l)) {
- return;
- }
- } else return;
- if ((ptr[0] == Red) && (ptr[1] == Green) && (ptr[2] == Blue)) {
- paint_pixel(image, x, y, width_pixel, Red_l, Green_l, Blue_l);
- pouring_rectangle(image, width_pixel, x + 1, y, Red, Green, Blue, Red_l, Green_l, Blue_l);
- pouring_rectangle(image, width_pixel, x - 1, y, Red, Green, Blue, Red_l, Green_l, Blue_l);
- pouring_rectangle(image, width_pixel, x, y + 1, Red, Green, Blue, Red_l, Green_l, Blue_l);
- pouring_rectangle(image, width_pixel, x, y - 1, Red, Green, Blue, Red_l, Green_l, Blue_l);
- }
- }
- // поиск прямоугольника макс площади
- int is_rectangle(struct Png *image, int width_pixel, int red0, int green0, int blue0, int red1, int
- green1, int blue1) {
- int x1, y1, x2, y2, x3, y3, x4, y4;
- int square, square_max = 0;
- int x1_max, y1_max, x2_max, y2_max, x3_max, y3_max, x4_max, y4_max;
- for (int y = 0; y < image2->height; y++) {
- png_byte *row = image2->row_pointers[y];
- for (int x = 0; x < image2->width; x++) {
- png_byte *ptr = &(row[x * width_pixel]);
- if (ptr[0] == red0 && ptr[1] == green0 && ptr[2] == blue0) {
- if (check_X_Y(image, x, y, &x1, &y1, &x2, &y2, &x3, &y3, &x4, &y4,
- width_pixel, red0, green0, blue0)) {
- int square = sqrt((x2 - x1) * (x2 - x1)) * sqrt((y3 - y1) * (y3 - y1));
- if (square > square_max) {
- square_max = square;
- x1_max = x1, y1_max = y1, x2_max = x2, y2_max = y2, x3_max = x3, y3_max =
- y3, x4_max = x4, y4_max = y4;
- }
- }
- }
- }
- }
- pouring_rectangle(image, width_pixel, x1_max, y1_max, red0, green0, blue0, red1, green1, blue1);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement