Most image formats like PNG, JPEG, BMP, and WebP store images the same way:
each pixel position maps to a color value in linear order. This has been the standard approach for decades.
A few days ago, I wondered what would happen if we inverted the logic completely.
Instead of storing pixels in order and assigning each one a color, what if we grouped pixels by color first?
That idea became C2PM, which stands for Color-to-Pixel Map.
It is an experimental format where each unique color is mapped to the list of pixel positions where it appears.
This turns an image into an inverted index, similar to how search engines map words to documents.
C2PM is open-source and available here:
https://github.com/yukeshj2006/C2PM-Color-to-Pixel-Map-Image-Format
Advantages of this inverted approach:
Instant lookup of any color
Since the format stores a direct mapping from a color to its pixel positions, you can retrieve all pixels of a specific color immediately without scanning the entire image.
This is useful for segmentation, mask generation, recoloring, and sprite editing.Efficient palette and recoloring operations
Traditional raster formats require scanning every pixel.
With C2PM, transforming one color requires modifying only its associated index list.Great for pixel art and low-color images
Many game assets, sprites, and icons rely on limited palettes.
C2PM performs especially well on these because of the small number of unique colors.Useful for computer vision experiments
Since C2PM already groups pixels by color, it acts like a basic segmentation map.
It is handy for quick region extraction and analyzing color-based clustering.Simple and educational design
C2PM has a clean binary structure suitable for learning how file formats work internally.
It teaches concepts like indexing, data serialization, and memory layout.
How C2PM stores data:
The layout is straightforward.
The header contains four fields: a magic identifier, width, height, and the number of unique colors.
For each unique color, the file stores its RGB values, the number of pixel indices associated with it, and the list of those indices.
The format is fully lossless and preserves all original colors.
Current limitations:
• C2PM v1 does not use compression.
• It can produce large files for images with many colors.
• Random-access writes make decoding slower for very large images.
• It is intended as a prototype rather than a replacement for production image formats.
Roadmap for future versions:
• Add RLE to compress pixel index lists
• Add a hash table for faster color insertion and lookup
• Introduce optional lossy modes
• Build a simple C2PM viewer
• Publish a more formal specification
Why this project matters:
As a student who enjoys games, graphics, and system-level thinking, creating C2PM taught me more than any tutorial ever could.
It helped me understand how formats work, how data structures influence performance, and how ideas evolve when implemented in real code.
Even though C2PM is experimental, it is my first step into creating original concepts instead of only using existing ones.
I hope it inspires others to explore alternative representations and experiment with how we store data.
If you have ideas, feedback, or suggestions, I would love to hear them.
Top comments (0)