# Reducing Texture Memory Usage by 2-channel Color Encoding

These single-material textures often do not exhibit large color variety and contain a limited range of hues, while using a full range of brightness resulting from highlights and dark (e.g., shadowed), regions within the material surface.

The method presented here follows these observations and aims to encode any given texture into two channels: one channel preserving full luminance information and the other one dedicated to hue/saturation encoding.

Texture Encoding Algorithm

Approximating this space with two channels effectively means that we have to find a surface (two-dimensional manifold) embedded within this unit cube that lies as close as possible to the set of texels from the source texture.

1. 重估颜色空间

sRGB颜色值转到线性颜色空间。

RGB值对亮度的贡献的非线性和不同的，因此我们要赋予RGB不同的权重。

2. 算出两个base的颜色向量

find_components() 求解。

3. 亮度编码

4. 饱和度编码

Decoding Algorithm

• 实现：
```// encode

//  读入图片

// 计算颜色平面和法线（返回的是法线）

vec3 est = estimate_image(src);

// gamma 处理

stamp_color_probe(src);

// 编码

BITMAP *encoded = encode_image(src,est);

// 两个基本的颜色坐标向量解码的时候需要用到，需要解出来传给decode端

vec3 base_a, base_b;

find_components(est,base_a,base_b);

// decode

// 解码

BITMAP *decoded = decode_image(encoded,base_a,base_b);

BITMAP *final = create_bitmap(src->w + decoded->w,src->h);```

vec3 estimate_image(BITMAP *src) ：

void stamp_color_probe(BITMAP *bmp)：

BITMAP *encode_image(BITMAP *src,vec3 n)：

BITMAP *decode_image(BITMAP *src,const vec3 &base_a,const vec3 &base_b)：