> For the complete documentation index, see [llms.txt](https://book.bsdcn.org/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://book.bsdcn.org/man/man5/pbm.5.md).

# pbm.5

`pbm` — 可移植位图文件格式

## 名称

`pbm`

## 描述

可移植位图格式是一种最大公约数式的单色文件格式。它最初被设计用于在今天我们常用的那种简单网络邮件程序之间，在不同类型的机器上合理地邮寄位图。现在它作为一大类位图转换过滤器的通用语言。其定义如下：

* 用于标识文件类型的 “魔数”。pbm 文件的魔数是两个字符 “P1”。
* 空白字符（空格、TAB、CR、LF）。
* 宽度，以十进制 ASCII 字符格式表示。
* 空白字符。
* 高度，同样以十进制 ASCII 格式表示。
* 空白字符。
* 宽度 × 高度个位，每个为 ‘1’ 或 ‘0’，从位图的左上角开始，按照正常的英文阅读顺序排列。
* 字符 ‘1’ 表示黑色，‘0’ 表示白色。
* 位部分中的空白字符将被忽略。
* 从 “#” 到下一个行尾的字符将被忽略（注释）。
* 任何行都不应超过 70 个字符。

以下是此格式的一个小位图示例：

```sh
P1
# feep.pbm
24 7
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 1 1 1 1 0 0 1 1 1 1 0 0 1 1 1 1 0 0 1 1 1 1 0
0 1 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 1 0 0 1 0
0 1 1 1 0 0 0 1 1 1 0 0 0 1 1 1 0 0 0 1 1 1 1 0
0 1 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0
0 1 0 0 0 0 0 1 1 1 1 0 0 1 1 1 1 0 0 1 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
```

读取此格式的程序应尽可能宽容，接受任何看起来稍微像位图的内容。

该格式还有一种变体，可在编译时设置 RAWBITS 选项来启用。此变体在以下方面有所不同：

* “魔数” 是 “P4” 而不是 “P1”。
* 位以每字节 8 个的方式存储，高位在前，低位在后。
* 位部分中不允许有空白字符，并且高度之后只允许单个空白字符（通常是换行符）。
* 文件小 8 倍，读写速度快许多倍。

## 作者

版权所有 (C) 1989, 1991，Jef Poskanzer。


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://book.bsdcn.org/man/man5/pbm.5.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
