With the SDL and framebuffer setup in place we now dive into subdividing the image.
In this second part we build a basic quadtree system using a dynamic array (essentially a queue). Each quad is subdivided into four children and those are appended to the array.
What You’ll Learn
- How to define and manage quads covering image regions
- How to compute RGB histograms and calculate average color and error
- How to split image regions recursively using a dynamic array (via
stb_ds.h
) - Why naive non-prioritized subdivision can lead to wasted effort
- How visual structure begins to emerge even from simple logic
What’s Missing
This method uses no prioritization.
We pick the next quad from the array in order, regardless of whether it has high or low color variation. This means:
- We waste effort subdividing flat or unimportant regions
- High detail areas may not be refined early
- Rendering is “slower” (results appear not as fast) and less efficient
Still it creates a pleasing and abstract reveal of the image.
Project Code
You will find the complete source code here: quadtree-art
After building and running the project you will see your image rendered as large color block. Press any key to progressively split the image into smaller quads. Each quad is rendered with its average color. There is no prioritization yet, so the image is refined in order revealing detail bit by bit across the entire canvas.
External Resources
Acknowledgements
- Quads by Michael Fogleman - original idea
Next Up
In the final part we introduce a min-heap priority queue to guide the subdivision process by error and area. The result is much more coherent and satisfying.