an introduction of ppm files

本文深入探讨了PPM图像文件格式的定义、特性和应用,包括其简单RGB颜色描述方式、魔法数字、像素布局以及读写操作。还介绍了与PPM格式相关的工具和转换方法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

PPM is the portable pixel map format. It is a simple RGB color image description. The definition is as follows:

  • A "magic number" for identifying the file type. A PPM file's magic number is the two characters "P3".
  • Whitespace (blanks, TABs, CRs, LFs).
  • A width, formatted as ASCII characters in decimal.
  • Whitespace.
  • A height, again in ASCII decimal.
  • Whitespace.
  • The maximum color-component value, again in ASCII decimal.
  • Whitespace.
  • Width * height pixels, each three ASCII decimal values between 0 and the specified maximum value, starting at the top-left corner of the pixmap, proceeding in normal English reading order. The three values for each pixel represent red, green, and blue, respectively; a value of 0 means that color is off, and the maximum value means that color is maxed out.
Characters from a "#" to the next end-of-line are ignored (comments). No line should be longer than 70 characters.

There is also a variant on the format, available by setting the RAWBITS option at compile time. This variant is different in the following ways:

  • The "magic number" is "P6" instead of "P3".
  • The pixel values are stored as plain bytes, instead of ASCII decimal.
  • No whitespace is allowed in the pixel section, and only a single character of whitespace (typically a newline) is allowed after the MAXVAL.
The files are smaller and many times faster to read and write. Note that this raw format can only be used for MAXVAL less than or equal to 255. If you use the PPM library and try to write a file with a larger MAXVAL, it will automatically fall back on the slower but more general plain format.

EXAMPLE:

        P3
        # feep.ppm
        4 4
        15
         0  0  0  0  0  0    0  0  0   15  0 15
         0  0  0  0 15  7    0  0  0    0  0  0
         0  0  0  0  0  0    0 15  7    0  0  0
        15  0 15  0  0  0    0  0  0    0  0  0
      

PPM files are:

  • ASCII or BINARY
  • RGB color
  • 2D
  • No compression
  • 1 image

Reference:

Programs to view a PPM file include:

  • The AVS module read_any_image can read a PPM file.
  • GIMP
  • The ImageVision program imgview can display a PPM file.
  • XV

Routines to read or write a PPM file:

Programs to convert a PPM file to another format:

  • GIMP can read a PPM file and write out a copy in a variety of formats.
  • PPMA_2_BMP converts an ASCII PPM file to BMP format.
  • XV can read a PPM file and write out a copy in BMP, FIT, GIF, JPG, PBM/PGM, RGB or TIF format.

Programs to convert a file to PPM format:

  • BMP_2_PPMA
  • GIMP can read a file in a variety of formats, and write it out as a PPM file.
  • XV can read a file in a BMP, FIT, GIF, JPG, PBM/PGM, RGB or TIF format, and write it out as a PPM file.

Files you may copy:

Back to the data home page.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值