The OpenNET Project / Index page

[ новости /+++ | форум | теги | ]



Индекс форумов
Составление сообщения

Исходное сообщение
"Смещение контура матрицы. Алгоритм  (развлекательная задача)"
Отправлено Аноним, 23-Фев-21 14:54 

> Но вроде бы какой-то алго выстроился у меня.

на

https://github.com/hankking11/ImageManip/blob/master/ppm.c

первае что в бошку пришло, и что важно - это работает и есть аптимизираванныи реализации хоть под канкретный камень


//This function takes in a ppmPic structure
//and returns a ppmPic structure representing an
//inverted version of the original picture (inverts the colors)
ppmPic *
invertppmPic(ppmPic *a)
    {
    int i;
    int j;                                  //j is the row number
    for (j = 0; j < a->rows; j++)
        {                                   //This for loop inverts each row one at a time
        i = 0;
                                            //i is the column number
        while(i < a->cols)
            {                               //This while loop inverts one row (row j)
            a->pixels[j][i].red = a->colors - a->pixels[j][i].red;
            a->pixels[j][i].green = a->colors - a->pixels[j][i].green;
            a->pixels[j][i].blue = a->colors - a->pixels[j][i].blue;
            i++;
            }
        }
    return a;
    }

//This function takes in a ppmPic structure
//and returns a ppmPic structure representing a
//horizontally flipped version of the original picture
ppmPic *
swapppmPic(ppmPic *a)
    {
    int i;                                  
    Pixel temp;
    int j;                          //j is the row number
    for (j = 0; j < a->rows; j++)
        {                           //This for loop swaps each row, one at a time
        i = 0;                      //i is the column number
        while(i < a->cols / 2)      //integer division is used, so the middle row is not
            {                       //swapped with itself if there's an odd number of cols
            temp = a->pixels[j][i]; //This while loop swaps one row (row j)
            a->pixels[j][i] = a->pixels[j][a->cols - i - 1];
            a->pixels[j][a->cols - i - 1] = temp;
            i++;
            }
        }
    return a;
    }

//This function takes in a ppmPic structure
//and returns a ppmPic structure representing an
//upside-down version of the original picture
ppmPic *
flipppmPic(ppmPic *a)
    {
    int i;                           // integer division is used, so the middle row
    Pixel temp;                      //is not swapped with itself if there is an
    int j;                           //odd number of rows. (in the for loop
    for (j = 0; j < a->rows / 2; j++)   //condition)
        {                           //This for loop switches the top half to the bottom half
        i = 0;                      //i is the column number
        while(i < a->cols)
            {                       //This while loop switches an upper half row with
            temp = a->pixels[j][i]; //a corresponding lower half row
            a->pixels[j][i] = a->pixels[a->rows - 1 - j][i];
            a->pixels[a->rows - 1 - j][i] = temp;
            i++;
            }
        }
    return a;
    }

 

Ваше сообщение
Имя*:
EMail:
Для отправки новых сообщений в текущей нити на email укажите знак ! перед адресом, например, !user@host.ru (!! - не показывать email).
Более тонкая настройка отправки ответов производится в профиле зарегистрированного участника форума.
Заголовок*:
Сообщение*:
  Введите код, изображенный на картинке: КОД
 
При общении не допускается: неуважительное отношение к собеседнику, хамство, унизительное обращение, ненормативная лексика, переход на личности, агрессивное поведение, обесценивание собеседника, провоцирование флейма голословными и заведомо ложными заявлениями. Не отвечайте на сообщения, явно нарушающие правила - удаляются не только сами нарушения, но и все ответы на них. Лог модерирования.



Партнёры:
PostgresPro
Inferno Solutions
Hosting by Hoster.ru
Хостинг:

Закладки на сайте
Проследить за страницей
Created 1996-2024 by Maxim Chirkov
Добавить, Поддержать, Вебмастеру