Image File Formats and Custom Format Creation

Jul 5, 2024

Image File Formats: JPEG vs. PNG and Creating a Custom Format

Key Differences between JPEG and PNG

  • JPEG does not support transparent backgrounds.
  • PNG supports transparency.

Issues with Online Image Searches

  • Searching for PNGs often results in incorrect file formats or low-quality JPEGs.

Objective

  • Create a new image file format using Rust.
  • The new format will be called profile.

Development Steps

Converting PNG to Profile

  1. Function Creation: Function to translate PNG's RGB values to hex values.
    • Hex is chosen for its shorter length (6 chars) compared to RGB (10 chars).
    • Store pixel colors as hex strings in the new format.
    • Add new lines to indicate rows of pixels in the file.
  2. File Storage: Write the hex strings to a file with a .profile extension.
    • Initial output: Bunch of colors in one row.
    • Update: Add new lines to handle rows properly.
  3. Problems & Solutions:
    • Size Issue: Profile formats were ~3.3 times larger than PNG (sometimes up to 98 times).
    • Compression not explored but considered.

Viewing the Profile File

  1. Rendering the Image:
    • Read the file and extract hex values to color each pixel on a canvas.
    • Initial Errors: Troubles with incorrect characters and wrong extensions.
    • Fixed by setting the alpha value for RGB.
  2. Windows Integration: Ensure Windows can run the program to open profile images.
    • Multiple libraries and tools tried for displaying images.
    • Successful implementation found after extensive search.

Final Implementation

  • Utility Function: To turn a PNG into a profile: cargo run compile [path-to-image]
  • Open Profile Images: cargo run [path-to-image] or set profile.exe as default to open profiles.

Summary

  • The project is experimental and meant for fun—not efficiency or practicality.
  • Available on GitHub for those interested.

Acknowledgements

  • Thanks to all patrons and YouTube members for their support.
  • End of the video note: See you in the next one!