Compression (OCR GCSE Computer Science): Revision Notes
📚 Revision Notes
Compression
The Need for Compression
- Compression is used to reduce the size of files, making them easier to store and transfer.
- Large files, such as images, videos, and software, can take up significant storage and require a long time to upload/download.
- Compression is necessary to improve transfer speed, save storage space, and make file sharing more efficient.
Types of Compression
Lossy Compression
- Lossy compression permanently removes some data from the file to reduce its size.
- It is commonly used for media files like images, audio, and video (e.g., JPEG, MP3, MP4).
Advantages:
-
Significantly reduces file size, making it ideal for online streaming and storage. Disadvantages:
-
Some data and quality are lost, meaning the original cannot be perfectly restored.
-
Quality reduction may be noticeable, such as in blurry images or reduced audio clarity.
Effect on file: The file becomes much smaller, but the quality decreases depending on the compression level.
Lossless Compression
- Lossless compression reduces file size without losing any data.
- Used for files where it is essential to maintain original quality, such as text files, ZIP files, and some image formats (e.g., PNG).
Advantages:
-
No loss of data, so the file can be restored to its original state.
-
Ideal for compressing important documents and high-quality images. Disadvantages:
-
Less reduction in file size compared to lossy compression.
Effect on file: The file size is reduced, but quality is preserved.
Common Scenarios for Compression
- Media files: Images, videos, and music are compressed to reduce file size and speed up sharing over the internet.
- Documents: Text and data files (e.g., ZIP archives) are compressed using lossless compression to save space without losing information.
- Websites: Images and files on websites are often compressed to help them load faster, improving the user's experience.
Bitmap Images and File Size
- Bitmap images are made up of tiny squares called pixels. Each pixel stores a specific colour using a binary code.
- The colour depth of an image refers to how many bits are used to store each pixel's colour. More bits = more possible colours:
- 1 bit can store 2 colours.
- 2 bits can store 4 colours.
- 3 bits can store 8 colours.
- 4 bits can store 16 colours.
- Resolution refers to the number of pixels in an image. Higher resolution = more detail but a larger file size.
Image Terminology
- Pixel: The smallest unit of an image, representing one colour. Each pixel is stored as a binary value.
- Colour Depth: The number of bits used to represent the colour of a pixel. More bits allow more colours but increase file size (e.g., 4 bits = 16 colours, 8 bits = 256 colours).
- Resolution: The density of pixels in an image, usually measured in dots per inch (DPI). Higher DPI = more pixels, higher quality, and larger file size.
- Metadata: Extra information stored with an image, such as its resolution, colour depth, file format, and camera settings (e.g., exposure, ISO, aperture).
Effect of Colour Depth and Resolution on File Size
- Larger colour depth and higher resolution result in better image quality, but also larger file sizes.
- Smaller colour depth and lower resolution create smaller file sizes, but the image quality decreases.
Calculating Image File Size
- File size formula: Multiply the image's resolution by its colour depth (in bits).
- To convert bits to bytes, divide by 8. For example, a 100x100 pixel image with 8-bit colour depth would have a size of:
- Size = 100 x 100 x 8 bits = 80,000 bits
- Divide by 8 to get 10,000 bytes (or 10 KB).
infoNote
Key Points to Remember
- Compression reduces file size to save storage and improve transfer speeds.
- Lossy compression removes some data permanently, reducing quality but saving significant space (e.g., JPEG, MP3).
- Lossless compression reduces size without losing data, preserving quality (e.g., ZIP, PNG).
- Bitmap images use pixels, and their file size depends on colour depth (bits per pixel) and resolution (pixel density).
- Higher colour depth and resolution improve quality but increase file size.