return SHRR(sy, 4) + SHRR(su, 8) + SHRR(sv, 10);
}
+// FIXME is this correct?
+inline int color_dist_lab_srgb(const color_t &a, const color_t &b)
+{
+ // undo sRGB
+ float ar = powf(a.r / 31.0f, 2.4f);
+ float ag = powf(a.g / 63.0f, 2.4f);
+ float ab = powf(a.b / 31.0f, 2.4f);
+ float br = powf(b.r / 31.0f, 2.4f);
+ float bg = powf(b.g / 63.0f, 2.4f);
+ float bb = powf(b.b / 31.0f, 2.4f);
+ // convert to CIE XYZ
+ float aX = 0.4124f * ar + 0.3576f * ag + 0.1805f * ab;
+ float aY = 0.2126f * ar + 0.7152f * ag + 0.0722f * ab;
+ float aZ = 0.0193f * ar + 0.1192f * ag + 0.9505f * ab;
+ float bX = 0.4124f * br + 0.3576f * bg + 0.1805f * bb;
+ float bY = 0.2126f * br + 0.7152f * bg + 0.0722f * bb;
+ float bZ = 0.0193f * br + 0.1192f * bg + 0.9505f * bb;
+ // convert to CIE Lab
+ float Xn = 0.3127f;
+ float Yn = 0.3290f;
+ float Zn = 0.3583f;
+ float aL = 116 * cbrtf(aY / Yn) - 16;
+ float aA = 500 * (cbrtf(aX / Xn) - cbrtf(aY / Yn));
+ float aB = 200 * (cbrtf(aY / Yn) - cbrtf(aZ / Zn));
+ float bL = 116 * cbrtf(bY / Yn) - 16;
+ float bA = 500 * (cbrtf(bX / Xn) - cbrtf(bY / Yn));
+ float bB = 200 * (cbrtf(bY / Yn) - cbrtf(bZ / Zn));
+ // euclidean distance
+ return 100 * ((aL - bL) * (aL - bL) + (aA - bA) * (aA - bA) + (aB - bB) * (aB - bB));
+}
+
inline int color_dist_normalmap(const color_t &a, const color_t &b)
{
float ca[3], cb[3];
RGB,
YUV,
SRGB,
+ LAB,
AVG,
NORMALMAP
};
case SRGB:
s2tc_encode_block<color_dist_srgb>(out, rgba, iw, w, h, dxt, nrandom);
break;
+ case LAB:
+ s2tc_encode_block<color_dist_lab_srgb>(out, rgba, iw, w, h, dxt, nrandom);
+ break;
case AVG:
s2tc_encode_block<color_dist_avg>(out, rgba, iw, w, h, dxt, nrandom);
break;
" [-o outfile.dds]\n"
" [-t {DXT1|DXT3|DXT5}]\n"
" [-r randomcount]\n"
- " [-c {RGB|YUV|SRGB|AVG|NORMALMAP}]\n",
+ " [-c {RGB|YUV|SRGB|LAB|AVG|NORMALMAP}]\n",
me);
return 1;
}
cd = YUV;
else if(!strcasecmp(optarg, "SRGB"))
cd = SRGB;
+ else if(!strcasecmp(optarg, "LAB"))
+ cd = LAB;
else if(!strcasecmp(optarg, "AVG"))
cd = AVG;
else if(!strcasecmp(optarg, "NORMALMAP"))
echo >&3 "<tr><th>Picture</th>"
echo >&3 "<th>Original</th>"
echo >&3 "<th>nvcompress</th>"
+ echo >&3 "<th>rand64-L*a*b*</th>"
+ echo >&3 "<th>norand-L*a*b*</th>"
echo >&3 "<th>rand64-sRGB</th>"
echo >&3 "<th>norand-sRGB</th>"
+ echo >&3 "<th>rand64-YUV</th>"
+ echo >&3 "<th>norand-YUV</th>"
echo >&3 "<th>rand64</th>"
echo >&3 "<th>norand</th>"
echo >&3 "<th>rand64-avg</th>"
}
html_start
-for i in dxtfail base_concrete1a disabled floor_tile3a lift02 panel_ceil1a sunset amelia rms; do
+for i in amelia dxtfail base_concrete1a disabled floor_tile3a lift02 panel_ceil1a sunset rms; do
html_rowstart "$i"
html "$i".tga
nvcompress "$i".tga "$i".dds
html "$i".dds
+ t "$i".tga "$i"-rand64-lab.dds ./s2tc -c LAB -r 64
+ t "$i".tga "$i"-nogray-lab.dds ./s2tc -c LAB -r 0
t "$i".tga "$i"-rand64-srgb.dds ./s2tc -c SRGB -r 64
t "$i".tga "$i"-nogray-srgb.dds ./s2tc -c SRGB -r 0
+ t "$i".tga "$i"-rand64-yuv.dds ./s2tc -c YUV -r 64
+ t "$i".tga "$i"-nogray-yuv.dds ./s2tc -c YUV -r 0
t "$i".tga "$i"-rand64.dds ./s2tc -c RGB -r 64
t "$i".tga "$i"-norand.dds ./s2tc -c RGB -r 0
t "$i".tga "$i"-rand64-avg.dds ./s2tc -c AVG -r 64