Thanks to visit codestin.com
Credit goes to github.com

Skip to content

WillKirkmanM/png

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PNG Encoding with Paeth Filtering & Predicting

PNG Image Encoding

PNG Image Encoder

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.

Functionality

The encoder performs the following steps:

  1. Image Loading: Loads a BMP image from the specified input file.
  2. Filtering: Applies various filtering techniques to the image scanlines.
  3. Encoding: Encodes the filtered image data.
  4. File Output: Writes the encoded data to the specified output file, including a header and the encoded image data.

Repository Structure

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.

Building the Encoder

To build the encoder, you need a C compiler (e.g., GCC) and the make build tool.

  1. Clone the repository.
  2. Navigate to the repository's root directory.
  3. Run the make command.
make

This will create an executable file named png-encoder in the bin directory.

Usage

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=9

File Format

The output file format is as follows:

  1. Header: "PNGL" (4 bytes)
  2. Image Dimensions:
    • Width (4 bytes)
    • Height (4 bytes)
    • Channels (1 byte)
    • Compression Level (1 byte)
  3. Filtered Data: The filtered image data, with each scanline prefixed by its filter type.

Dependencies

  • Standard C library

About

PNG Encoding with Paeth Filtering & Predicting

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published