Table Of Contents

Previous topic

8.4. Inputs/Outputs (I/O) in C++

Next topic

8.6. STL: the (C++) standard template library

Download

8.5. Structure and format of the image and shapes files

8.5.1. Structure of an Image file

8.5.1.1. Description

Image files are ASCII files holding the description of one image.

8.5.1.2. Syntax

For more informations about the grammar below, heed toward this wikipedia page

The complete syntax used in these text files can be described like so:

image  ::=  'IMAGE' data 'IMAGE_END'
data   ::=  'WIDTH' <value>
            'HEIGHT' <value>
            'PIXELS' pixels
pixels ::=  pixel pixels | pixel
pixel  ::=  <value>

Note

This type of grammar is a standard. For example, the first line means:

An ‘image’ is composed of the word IMAGE followed by ‘data’ and finally the token IMAGE_END.

To know what ‘data’ means, one just has to go to the next line.

8.5.2. Structure of a Shape file

8.5.2.1. Description

A shape file is a structured ASCII file holding the description of graphical shapes.

  • each individual description of a shape is flanked by 2 keywords SHAPE and SHAPE_END.
  • between these 2 keywords, the description of the shape itself is given by:
    • its type (TYPE,)
    • the geometrical data of the shape, dependent on the type of the shape.

8.5.2.2. Syntax

For more informations about the grammar below, heed toward this wikipedia page

The complete syntax used in these text files can be described like so:

shapes    ::=  shape | shape shapes | comment shapes
shape     ::=  'SHAPE' <number> 'TYPE'  type_name data 'SHAPE_END'
comment   ::=  'COMMENT' ... 'COMMENT_END'
type_name ::=  'SQUARE' | 'RECTANGLE' | 'CIRCLE' | 'ELLIPSE' | 'POLYGON'
data      ::=  envelope | list
envelope  ::=  'ORIGIN' <x> <y> 'WIDTH'  <width> 'HEIGHT' <height>
list      ::=  'NB_POINTS' <number> points
points    ::=  point points | point
point     ::=  'POINT' <x> <y>