Mobile Development 11 min read

How to Cut Mobile Texture Memory by 75% with Macro‑Block Compression

This article presents a macro‑block based texture compression technique that removes hollow (alpha‑zero) regions from textures, dramatically reduces memory usage on mobile devices, and restores the original visual quality during rendering, even after video encoding.

Kuaishou Large Model
Kuaishou Large Model
Kuaishou Large Model
How to Cut Mobile Texture Memory by 75% with Macro‑Block Compression

Abstract

When rendering special effects on mobile devices, large amounts of sequence‑frame textures are used, and memory optimization is a persistent challenge. This method removes hollow (alpha‑zero) regions from textures, rearranges the remaining data in macro‑blocks, and restores the original image during rendering, achieving lossless‑perceived quality while reducing memory consumption by up to 75%.

Texture Compression Method

The approach consists of two main steps: texture compression and texture restoration. During compression, effective (non‑transparent) macro‑blocks are identified and packed into a smaller texture, while an index map records the original positions. During restoration, the index map is used to retrieve each macro‑block and place it back at its correct location for rendering.

1. Texture Compression

The macro‑block size must be chosen carefully. Too small a block enlarges the index map, increasing memory; too large a block reduces the compression ratio because fewer effective pixels remain per block. Experiments on a 1024×1024 source image show that a 32‑pixel block size (32×32 blocks) offers a good trade‑off.

During compression, the source image is scanned from the top‑left corner; each effective macro‑block is copied to a new compact texture, and its new coordinates are stored in the R (horizontal) and G (vertical) channels of a 32×32 index texture.

2. Texture Restoration

In a typical OpenGL pipeline, a rectangle is drawn with texture coordinates ranging from 0 to 1. When using the compressed textures, the shader first reads the R and G values from the index map to locate the corresponding macro‑block in the compact texture, then offsets the original texture coordinates accordingly to sample the correct color.

3. Edge Protection

Bilinear sampling can cause colors from neighboring macro‑blocks to bleed at block edges, producing visible stripes. Adding a one‑pixel border around each macro‑block (internal or external padding) prevents this artifact. Vertical padding alone is sufficient because macro‑blocks are stored contiguously in the horizontal direction.

4. Index Map Additional Storage

To avoid precision errors when determining macro‑block positions in shaders, the macro‑block coordinates are also stored in the B and A channels of the index texture. The shader can then read these channels directly, eliminating the need for floating‑point calculations and removing sampling artifacts.

5. Compatibility with Video Codec

Sequence‑frame textures are often encoded as video. The method was tested with H.264 encoding; internal padding (32‑pixel blocks) performed better than external padding (34‑pixel blocks) because H.264 macro‑blocks (8 or 16 pixels) align well with the internal padding size, preserving visual quality after encoding.

Application Example

A short‑video effect featuring colorful butterflies was used to demonstrate the technique. The original sequence consisted of 50 frames at 720×1280 resolution. After applying the compression method, the memory footprint of the texture data dropped to roughly one‑quarter of the original size.

On an iPhone SE 2, loading the original effect increased memory usage from 475 MB to 585 MB, while the compressed effect raised it only to 527 MB, saving more than 50 % of memory. Frame rate remained stable at 30 FPS, indicating negligible performance overhead.

Visual quality comparisons show that the compressed textures are virtually indistinguishable from the originals when examined at normal viewing distances, confirming the method’s effectiveness for memory‑critical mobile graphics.

Conclusion

The macro‑block texture compression technique efficiently removes hollow regions, reduces memory consumption dramatically, and restores textures without perceptible quality loss, making it suitable for mobile special‑effect rendering, sequence‑frame stickers, and scenarios requiring video‑codec compatibility. Future work includes simplifying the preparation pipeline and automating the process for broader adoption.

Memory Optimizationtexture compressionVideo EncodingOpenGLmobile graphicsmacro block
Kuaishou Large Model
Written by

Kuaishou Large Model

Official Kuaishou Account

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.