讲解PPM Files、辅导Raster graphics、辅导JAVA/python,c++程序语言
- 首页 >> C/C++编程Working with PPM Files
Raster graphics (http://en.wikipedia.org/wiki/Raster_graphics), unless vector-graphics, rely and
operate on pixels where every pixel is typically made up of an RGB value.
Portable Pixel Map (PPM)
PPM images can eithr be stored in an ASCII or in a BINARY format, see here
(http://de.wikipedia.org/wiki/Portable_Pixmap) for details. For the implementation of the task you
may select one of these formats.
An example of an ASCII ppm image loaded with a text editor looks like:
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
Here the first line holds a unique image identifier (magic number), in particular, the ASCII
letters P3.
The PPM format allows for line comments that start with a # symbol.
The first three ASCII numbers following the magic number represent the image width,
height and the maximum color depth of every pixels color value.
The rest of the image is made up of ASCII numbers separated with whitespace characters -
three numbers in RED GREEN BLUE sequence per single pixel. Every single value is
between 0 and the maximum color depth (the maximum number for the latter is 255).
In order to implement the task using binary PPM images you’ll need to check the respective
file using a HEX editor (Windows: XVI32
(http://www.chmaas.handshake.de/delphi/freeware/xvi32/xvi32.htm), HxD (http://mh-nexus.de/de/hxd/),
FSHED (http://www.funduc.com/fshexedit.htm), etc.; Linux: ghex, dhex (http://www.dettus.net/dhex/),
bless (http://home.gna.org/bless/), wxhexeditor (http://www.wxhexeditor.org/), emacs, vi, etc.; MAC
OSX: Hex Fiend (http://ridiculousfish.com/hexfiend/), 0xED (http://www.suavetech.com/0xed/0xed.html),
etc.).
The structure of binary PPM images is the same as those of ASCII PPM images, however,
without comments and P6 (0x50 0x36) as magic number.
2019/1/4 Working with PPM Files
https://cis.technikum-wien.at/documents/bel/1/prg/semesterplan/tasks/imglib/ppm.html 2/2
A BINARY PPM image looks like:
P6 # unique identifier for BINARY PPM format
# some comment # an optional comment line
3 2 # image size: width and height
255 # color depth (0-255)
!@#$%^&*()_+|{}:"< # RGB pixel values in binary
TIP
In order to work with the binary format, it is highly recommended to install
and use a HEX editor.
Last updated 2015-11-05 10:09:35 CET