Commit 628369b6 authored by Yann Boucher's avatar Yann Boucher
Browse files

Fixed issue with the palette of GIF files

parent 1f8cf700
Pipeline #79778 passed with stages
in 17 seconds
{
"data": "x = 200, y = 9\n23bo37bo47bo37bo37bo$21bobo35bobo45bobo35bobo35bobo$11b2o6b2o12b2o14b2o6b2o12b2o24b2o6b2o12b2o14b2o6b2o12b2o14b2o6b2o12b2o$10bo3bo4b2o12b2o13bo3bo4b2o12b2o23bo3bo4b2o12b2o13bo3bo4b2o12b2o13bo3bo4b2o12b2o$o8bo5bo3b2o16b2o8bo5bo3b2o26b2o8bo5bo3b2o16b2o8bo5bo3b2o16b2o8bo5bo3b2o16bo$o8bo3bob2o4bobo13b2o8bo3bob2o4bobo23b2o8bo3bob2o4bobo13b2o8bo3bob2o4bobo13b2o8bo3bob2o4bobo13bo$9bo5bo7bo23bo5bo7bo33bo5bo7bo23bo5bo7bo23bo5bo7bo$10bo3bo33bo3bo43bo3bo33bo3bo33bo3bo$11b2o36b2o46b2o36b2o36b2o!",
"height": 220,
"left": 0,
"model": "Game of Life",
"title": "gosper-glider",
"top": 104,
"width": 200
}
This diff is collapsed.
{
"alphabet": [
{
"color": [
255,
255,
0
],
"name": "0"
},
{
"color": [
255,
215,
135
],
"name": "1"
},
{
"color": [
255,
170,
0
],
"name": "2"
},
{
"color": [
255,
0,
0
],
"name": "3"
},
{
"color": [
0,
255,
0
],
"name": "4"
},
{
"color": [
170,
255,
255
],
"name": "5"
},
{
"color": [
85,
0,
127
],
"name": "6"
}
],
"author": "Eugene",
"date": "Fri Jun 11 2021",
"desc": "",
"neighborhood_data": {
"radius": 1
},
"neighborhood_name": "Moore",
"title": "Griffeath++",
"transition_data": {
"rule_string": "i, (i+1)%7:[3..*] -> (i+1)%7"
},
"transition_name": "Totalistic rulestring"
}
...@@ -216,19 +216,19 @@ void MainWindow::save_as_gif() ...@@ -216,19 +216,19 @@ void MainWindow::save_as_gif()
const unsigned delay = 100/ui->simSpeedSlider->value(); // hundredths of second const unsigned delay = 100/ui->simSpeedSlider->value(); // hundredths of second
const Alphabet& alph = ui->grid_view->alphabet(); const Alphabet& alph = ui->grid_view->alphabet();
unsigned state_count = alph.taille(); unsigned state_count = alph.taille();
unsigned palette_depth = 0; unsigned palette_depth = 1;
while (state_count >>= 1) ++palette_depth; // log2 while (state_count >>= 1) ++palette_depth; // log2
QString filename = QFileDialog::getSaveFileName(this, tr("Save GIF"),"",tr("GIF (*.gif)")); QString filename = QFileDialog::getSaveFileName(this, tr("Save GIF"),"",tr("GIF (*.gif)"));
if (filename.isEmpty()) if (filename.isEmpty())
return; return;
std::vector<uint8_t> palette; std::vector<uint8_t> palette((1 << palette_depth)*3);
for (unsigned i = 0; i < alph.taille(); ++i) for (unsigned i = 0; i < alph.taille(); ++i)
{ {
palette.push_back(alph.getState(i).getColor().getRed()); palette[3*i+0] = (alph.getState(i).getColor().getRed());
palette.push_back(alph.getState(i).getColor().getGreen()); palette[3*i+1] = (alph.getState(i).getColor().getGreen());
palette.push_back(alph.getState(i).getColor().getBlue()); palette[3*i+2] = (alph.getState(i).getColor().getBlue());
} }
ge_GIF* gif = ge_new_gif(filename.toStdString().c_str(), width, height, palette.data(), palette_depth, 0); ge_GIF* gif = ge_new_gif(filename.toStdString().c_str(), width, height, palette.data(), palette_depth, 0);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment