public evaluatePalette ( byte alpha, bool d3d9 ) : void | ||
alpha | byte | |
d3d9 | bool | |
return | void |
/*static uint computeAlphaError8( ColorBlock & rgba, AlphaBlockDXT5 * block, int bestError = INT_MAX) * { * int totalError = 0; * * for (uint i = 0; i < 16; i++) * { * byte alpha = rgba.color[i].a; * * totalError += alphaDistance(alpha, nearestAlpha8(alpha, block.alpha0, block.alpha1)); * * if (totalError > bestError) * { * // early out * return totalError; * } * } * * return totalError; * }*/ static float computeAlphaError(AlphaBlock4x4 src, AlphaBlockDXT5 dst, float bestError = float.MaxValue) { byte[] alphas = new byte[8]; dst.evaluatePalette(alphas, false); // @@ Use target decoder. float totalError = 0; for (uint i = 0; i < 16; i++) { byte alpha = src.alpha[i]; uint minDist = int.MaxValue; for (uint p = 0; p < 8; p++) { uint dist = alphaDistance(alpha, alphas[p]); minDist = Math.Min(dist, minDist); } totalError += minDist * src.weights[i]; if (totalError > bestError) { // early out return(totalError); } } return(totalError); }
static uint computeAlphaIndices(AlphaBlock4x4 src, AlphaBlockDXT5 block) { byte[] alphas = new byte[8]; block.evaluatePalette(alphas, false); // @@ Use target decoder. uint totalError = 0; for (uint i = 0; i < 16; i++) { byte alpha = src.alpha[i]; uint besterror = 256 * 256; uint best = 8; for (uint p = 0; p < 8; p++) { int d = alphas[p] - alpha; uint error = (uint)(d * d); if (error < besterror) { besterror = error; best = p; } } //nvDebugCheck(best < 8); totalError += besterror; block.setIndex(i, best); } return(totalError); }
static float computeAlphaError_RGBM(ColorSet src, ColorBlock RGB, AlphaBlockDXT5 dst, float bestError = float.MaxValue) { byte[] alphas = new byte[8]; dst.evaluatePalette(alphas, /*d3d9=*/ false); // @@ Use target decoder. float totalError = 0; for (uint i = 0; i < 16; i++) { float R = src.color[i].x; float G = src.color[i].y; float B = src.color[i].z; float r = (float)(RGB.color[i].r) / 255.0f; float g = (float)(RGB.color[i].g) / 255.0f; float b = (float)(RGB.color[i].b) / 255.0f; float minDist = float.MaxValue; for (uint p = 0; p < 8; p++) { // Compute M. float M = (float)(alphas[p]) / 255.0f * (1 - threshold) + threshold; // Decode color. float fr = r * M; float fg = g * M; float fb = b * M; // Measure error. float error = Mathf.Pow(R - fr, 2) + Mathf.Pow(G - fg, 2) + Mathf.Pow(B - fb, 2); minDist = Mathf.Min(error, minDist); } totalError += minDist * src.weights[i]; if (totalError > bestError) { // early out return(totalError); } } return(totalError); }
static void computeAlphaIndices_RGBM(ColorSet src, ColorBlock RGB, AlphaBlockDXT5 dst) { byte[] alphas = new byte[8]; dst.evaluatePalette(alphas, /*d3d9=*/ false); // @@ Use target decoder. for (uint i = 0; i < 16; i++) { float R = src.color[i].x; float G = src.color[i].y; float B = src.color[i].z; float r = (float)(RGB.color[i].r) / 255.0f; float g = (float)(RGB.color[i].g) / 255.0f; float b = (float)(RGB.color[i].b) / 255.0f; float minDist = float.MaxValue; uint bestIndex = 8; for (uint p = 0; p < 8; p++) { // Compute M. float M = (float)(alphas[p]) / 255.0f * (1 - threshold) + threshold; // Decode color. float fr = r * M; float fg = g * M; float fb = b * M; // Measure error. float error = Mathf.Pow(R - fr, 2) + Mathf.Pow(G - fg, 2) + Mathf.Pow(B - fb, 2); if (error < minDist) { minDist = error; bestIndex = p; } } dst.setIndex(i, bestIndex); } }
static void computeAlphaIndices(AlphaBlock4x4 src, AlphaBlockDXT5 dst) { byte[] alphas = new byte[8]; dst.evaluatePalette(alphas, /*d3d9=*/ false); // @@ Use target decoder. for (uint i = 0; i < 16; i++) { byte alpha = src.alpha[i]; uint minDist = int.MaxValue; uint bestIndex = 8; for (uint p = 0; p < 8; p++) { uint dist = alphaDistance(alpha, alphas[p]); if (dist < minDist) { minDist = dist; bestIndex = p; } } dst.setIndex(i, bestIndex); } }
static void computeAlphaIndices_RGBM(ColorSet src, ColorBlock RGB, AlphaBlockDXT5 dst) { byte[] alphas = new byte[8]; dst.evaluatePalette(alphas, /*d3d9=*/false); // @@ Use target decoder. for (uint i = 0; i < 16; i++) { float R = src.color[i].x; float G = src.color[i].y; float B = src.color[i].z; float r = (float)(RGB.color[i].r) / 255.0f; float g = (float)(RGB.color[i].g) / 255.0f; float b = (float)(RGB.color[i].b) / 255.0f; float minDist = float.MaxValue; uint bestIndex = 8; for (uint p = 0; p < 8; p++) { // Compute M. float M = (float)(alphas[p]) / 255.0f * (1 - threshold) + threshold; // Decode color. float fr = r * M; float fg = g * M; float fb = b * M; // Measure error. float error = Mathf.Pow(R - fr, 2) + Mathf.Pow(G - fg, 2) + Mathf.Pow(B - fb, 2); if (error < minDist) { minDist = error; bestIndex = p; } } dst.setIndex(i, bestIndex); } }
static void computeAlphaIndices(AlphaBlock4x4 src, AlphaBlockDXT5 dst) { byte[] alphas = new byte[8]; dst.evaluatePalette(alphas, /*d3d9=*/false); // @@ Use target decoder. for (uint i = 0; i < 16; i++) { byte alpha = src.alpha[i]; uint minDist = int.MaxValue; uint bestIndex = 8; for (uint p = 0; p < 8; p++) { uint dist = alphaDistance(alpha, alphas[p]); if (dist < minDist) { minDist = dist; bestIndex = p; } } dst.setIndex(i, bestIndex); } }
static float computeAlphaError_RGBM(ColorSet src, ColorBlock RGB, AlphaBlockDXT5 dst, float bestError = float.MaxValue) { byte[] alphas = new byte[8]; dst.evaluatePalette(alphas, /*d3d9=*/false); // @@ Use target decoder. float totalError = 0; for (uint i = 0; i < 16; i++) { float R = src.color[i].x; float G = src.color[i].y; float B = src.color[i].z; float r = (float)(RGB.color[i].r) / 255.0f; float g = (float)(RGB.color[i].g) / 255.0f; float b = (float)(RGB.color[i].b) / 255.0f; float minDist = float.MaxValue; for (uint p = 0; p < 8; p++) { // Compute M. float M = (float)(alphas[p]) / 255.0f * (1 - threshold) + threshold; // Decode color. float fr = r * M; float fg = g * M; float fb = b * M; // Measure error. float error = Mathf.Pow(R - fr, 2) + Mathf.Pow(G - fg, 2) + Mathf.Pow(B - fb, 2); minDist = Mathf.Min(error, minDist); } totalError += minDist * src.weights[i]; if (totalError > bestError) { // early out return totalError; } } return totalError; }
/*static uint computeAlphaError8( ColorBlock & rgba, AlphaBlockDXT5 * block, int bestError = INT_MAX) { int totalError = 0; for (uint i = 0; i < 16; i++) { byte alpha = rgba.color[i].a; totalError += alphaDistance(alpha, nearestAlpha8(alpha, block.alpha0, block.alpha1)); if (totalError > bestError) { // early out return totalError; } } return totalError; }*/ static float computeAlphaError(AlphaBlock4x4 src, AlphaBlockDXT5 dst, float bestError = float.MaxValue) { byte[] alphas = new byte[8]; dst.evaluatePalette(alphas, false); // @@ Use target decoder. float totalError = 0; for (uint i = 0; i < 16; i++) { byte alpha = src.alpha[i]; uint minDist = int.MaxValue; for (uint p = 0; p < 8; p++) { uint dist = alphaDistance(alpha, alphas[p]); minDist = Math.Min(dist, minDist); } totalError += minDist * src.weights[i]; if (totalError > bestError) { // early out return totalError; } } return totalError; }