📄 gridstats.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>#include <stdio.h>extern double grid_density(const uint8_t *grid, uint32_t w, uint32_t h);extern bool load_pgm(const char *file, uint8_t **grid, uint32_t *w, uint32_t *h);extern double grid_entropy(const uint8_t *grid, uint32_t w, uint32_t h);int main(int argc, char **argv){ assert(argc > 1); uint32_t gw, gh; uint8_t *grid; assert(load_pgm(argv[1], &grid, &gw, &gh)); uint32_t g0 = 0; for(uint32_t i = 0; i < gw*gh; ++i) g0 += grid[i]; printf("d = %g\nH = %g\nsum = %d\n", grid_density(grid, gw, gh), grid_entropy(grid, gw, gh), g0); return 0;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -