#include <iostream>
#include <fstream>
#include <vector>
#include <iomanip>
using namespace std;
struct Pixel
{
unsigned char r;
unsigned char g;
unsigned char b;
};
int main()
{
// Размер изображения
const int WIDTH = 128;
const int HEIGHT = 128;
// Тут должен быть массив пикселей
// Заполни его своими RGB данными
vector<Pixel> image(WIDTH * HEIGHT);
// Пример:
// Белый фон
for (int i = 0; i < WIDTH * HEIGHT; i++)
{
image[i].r = 0xFF;
image[i].g = 0xFF;
image[i].b = 0xFF;
}
ofstream out("pikachu_rle.txt");
const char* channelNames[3] = {
"RED",
"GREEN",
"BLUE"
};
// 0 = R
// 1 = G
// 2 = B
for (int channel = 0; channel < 3; channel++)
{
out << "========== "
<< channelNames[channel]
<< " ==========\n";
for (int y = 0; y < HEIGHT; y++)
{
out << "Строка " << (y + 1) << ": ";
int x = 0;
while (x < WIDTH)
{
unsigned char value;
Pixel& p = image[y * WIDTH + x];
if (channel == 0)
value = p.r;
else if (channel == 1)
value = p.g;
else
value = p.b;
int count = 1;
while (x + count < WIDTH)
{
Pixel& next =
image[y * WIDTH + (x + count)];
unsigned char nextValue;
if (channel == 0)
nextValue = next.r;
else if (channel == 1)
nextValue = next.g;
else
nextValue = next.b;
if (nextValue != value)
break;
count++;
}
out << count
<< "x"
<< uppercase
<< hex
<< setw(2)
<< setfill('0')
<< (int)value;
x += count;
if (x < WIDTH)
out << " | ";
}
out << "\n";
}
out << "\n";
}
out.close();
cout << "Готово: pikachu_rle.txt\n";
return 0;
}