PNG Image Encoding
This repository contains a PNG image encoder implemented in C. It takes a BMP image as input and encodes it using PNG-like encoding, producing a compressed output file.
The encoder performs the following steps:
- Image Loading: Loads a BMP image from the specified input file.
- Filtering: Applies various filtering techniques to the image scanlines.
- Encoding: Encodes the filtered image data.
- File Output: Writes the encoded data to the specified output file, including a header and the encoded image data.
The repository has the following structure:
include/: Contains header files, including encoder.h, which defines the image and encoder structures and function prototypes.src/: Contains the source code files.png_encoder.c: Implements the PNG encoding logic.main.c: Contains the main function that parses command-line arguments, loads the image, performs the encoding, and saves the output.utils/: Contains utility functions.bitstream.c: Implements bitstream reading and writing functions.image.c: Implements image loading and saving functions.
Makefile: Defines the build process for the project.README.md: This file, providing an overview of the project.
To build the encoder, you need a C compiler (e.g., GCC) and the make build tool.
- Clone the repository.
- Navigate to the repository's root directory.
- Run the
makecommand.
makeThis will create an executable file named png-encoder in the bin directory.
To use the encoder, run the png-encoder executable with the following command-line arguments:
bin/png-encoder <input_file> <output_file> [level=0-9]<input_file>: The path to the input BMP image file.<output_file>: The path to the output file where the encoded data will be written.level: The PNG compression level (0-9, default: 6).
Example:
bin/png-encoder input.bmp output.png level=9The output file format is as follows:
- Header: "PNGL" (4 bytes)
- Image Dimensions:
- Width (4 bytes)
- Height (4 bytes)
- Channels (1 byte)
- Compression Level (1 byte)
- Filtered Data: The filtered image data, with each scanline prefixed by its filter type.
- Standard C library