Describe how a simple black and white (binary) bitemapped image is encoded in memory. Your answer should detail the representation of individual pixels and the overall image structure. Consider the roles of bits, bytes, and the relationship between pixel data and the image dimensions.
A bitemapped image is represented as a grid of pixels, where each pixel's color is determined by a binary value – typically 0 for black and 1 for white. This means each pixel requires only one bit of storage. The image is stored in memory as a sequence of these bits.
The most common way to store these bits is using bytes. A byte consists of 8 bits. Therefore, 8 bits can represent 28 = 256 different values. For a simple black and white image, we can use 1 bit per pixel, which means we can store 256 pixels per byte.
The image dimensions (width and height) are crucial for determining the total number of pixels and, consequently, the total amount of memory required. The image data is typically stored row by row, or in a flattened format (row-major or column-major order). Each byte in memory corresponds to a set of pixels in the image. The number of bytes needed is calculated as: (width in pixels * height in pixels) / 8. If the width and height are not both divisible by 8, padding bytes may be added to the end of rows to ensure a complete byte.
For example, a 10x10 black and white image would have 100 pixels. This requires 100 bits. Since 8 bits make a byte, this is equal to 100/8 = 12.5 bytes. Therefore, we would need 13 bytes to store the image, with the last byte being partially filled.
2.
Describe, in detail, how a vector graphic is encoded in a file format like SVG. Your answer should cover the key data structures and the purpose of each. Consider the representation of shapes, colours, and transformations.
A vector graphic is encoded as a set of mathematical instructions that describe the shapes within the image. Unlike raster graphics which store pixel data, vector graphics store geometric primitives like lines, curves, and polygons. SVG (Scalable Vector Graphics) is a common file format for vector graphics. The encoding involves a series of XML tags that define these primitives and their properties.
Key Data Structures and Encoding Elements:
Root Element: This is the root element of the SVG document, containing all other elements. It defines the viewport and the coordinate system.
Element: This is the most versatile element for defining shapes. It uses a series of commands to draw lines, curves (e.g., Bezier curves), and other complex paths. Each command is represented by a letter followed by numerical parameters. For example:
M (Move To): Moves the current point to a specified coordinate.
L (Line To): Draws a straight line from the current point to a specified coordinate.
C (Cubic Bezier Curve): Draws a cubic Bezier curve to a specified coordinate, using two control points.
Q (Quadratic Bezier Curve): Draws a quadratic Bezier curve to a specified coordinate, using one control point.
Z (Close Path): Closes the current path by drawing a straight line from the current point back to the starting point.
Element: Defines a rectangle with attributes like x, y, width, and height.
Element: Defines a circle with attributes like cx, cy, and r (radius).
Element: Defines an ellipse with attributes like cx, cy, rx, and ry (radii).
Element: Defines text with attributes like x, y, font-family, font-size, and fill (colour).
Element: A grouping element that allows you to apply transformations (e.g., rotation, scaling, translation) to a group of elements. This is crucial for manipulating the entire graphic as a unit.
Attributes: Attributes like fill (colour of the shape), stroke (colour of the outline), stroke-width (thickness of the outline), and transform (for applying transformations) are used to define the appearance of the shapes.
Colour Representation: Colours are typically represented using:
Hexadecimal Colour Codes: e.g., #FF0000 (red).
RGB Values: e.g., rgb(255, 0, 0) (red).
CSS Colour Names: e.g., red, blue, green.
Transformations: Transformations are applied using the transform attribute. These transformations can be combined using the transform attribute which accepts a string of transformation commands. Common transformations include:
translate(x, y): Moves the graphic by x and y pixels.
rotate(angle): Rotates the graphic by the specified angle (in degrees).
scale(x, y): Scales the graphic by x and y factors.
3.
Consider a digital image. Define resolution in the context of digital images and explain how changing the pixel density (pixels per unit area) affects the perceived detail and file size of the image.
Resolution in the context of digital images refers to the number of pixels in an image, typically expressed as width x height (e.g., 1920x1080). It essentially determines the level of detail that can be represented in the image.
Changing the pixel density (pixels per unit area, often expressed as DPI or PPI) directly impacts the perceived detail and file size of the image.
Increasing the pixel density (higher DPI/PPI): This means more pixels are packed into the same area. The image will appear sharper and more detailed, especially when viewed at a larger size. However, it also increases the file size because more data needs to be stored to represent each pixel.
Decreasing the pixel density (lower DPI/PPI): This means fewer pixels are packed into the same area. The image will appear less sharp and less detailed, especially when viewed at a larger size. The file size will be smaller because less data is required.
The relationship between resolution and file size is not always linear. Image compression techniques (e.g., JPEG) can significantly reduce file size, even with a high resolution. However, these techniques often involve some loss of detail.