📄 diff.cpp
字号:
/* gridsim2 (c) 2006 Kris Beevers This file is part of gridsim2. gridsim2 is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. gridsim2 is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with gridsim2; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA*/#include <inttypes.h>#include <assert.h>extern bool load_pgm(const char *file, uint8_t **grid, uint32_t *w, uint32_t *h);extern bool write_pgm(const char *file, const uint8_t *grid, uint32_t w, uint32_t h);inline uint8_t myabs(int i) { return i < 0 ? -i : i; }int main(int argc, char **argv){ assert(argc > 2); uint32_t gw, gh, mw, mh; uint8_t *grid, *map, *diff; assert(load_pgm(argv[1], &grid, &gw, &gh)); assert(load_pgm(argv[2], &map, &mw, &mh)); assert(mw == gw && mh == gh); diff = new uint8_t[gw*gh]; for(uint32_t i = 0; i < gw*gh; ++i) // diff[i] = (grid[i] != map[i]) ? 255 : 0; diff[i] = myabs(int(grid[i])-int(map[i])); write_pgm("diff.pgm", diff, gw, gh); return 0;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -