static void SetPixCol1(BitmapCpc dest) { int choix = 0; for (int y = 0; y < tailleY; y += 2) { for (int x = 0; x < tailleX; x += Tx) { int oldDist = 0x7FFFFFFF; int totR = 0, totV = 0, totB = 0; bitmap.GetPixel(x, y, ref totR, ref totV, ref totB); bitmap.AddGetPixel(x, y + 1, ref totR, ref totV, ref totB); totR >>= 1; totV >>= 1; totB >>= 1; for (int i = 0; i < MaxCol; i++) { int Dist = CalcDist(tabCol[i], totR, totV, totB); if (Dist < oldDist) { choix = i; oldDist = Dist; if (Dist == 0) { break; } } } dest.SetPixelCpc(x, y, choix); } } }
static void SetPixCol0(BitmapCpc dest) { for (int y = 0; y < tailleY; y += 2) { for (int x = 0; x < tailleX; x += Tx) { int oldDist = 0x7FFFFFFF; int p = bitmap.GetPixel(x, y); int choix = 0; for (int i = 0; i < MaxCol; i++) { int Dist = CalcDist(p, tabCol[i].GetColor); if (Dist < oldDist) { choix = i; oldDist = Dist; if (Dist == 0) { break; } } } dest.SetPixelCpc(x, y, choix); } } }
static void SetPixCol2(BitmapCpc dest) { int choix0 = 0, choix1 = 0; for (int y = 0; y < tailleY; y += 4) { int ynorm = y + 2 < tailleY ? y + 2 : y + 1; for (int x = 0; x < tailleX; x += Tx << 1) { int xnorm = x + Tx < tailleX ? x + Tx : x + 1; int OldDist = 0x7FFFFFFF; int totR = 0, totV = 0, totB = 0; bitmap.GetPixel(x, y, ref totR, ref totV, ref totB); bitmap.AddGetPixel(x, ynorm, ref totR, ref totV, ref totB); bitmap.AddGetPixel(xnorm, y, ref totR, ref totV, ref totB); bitmap.AddGetPixel(xnorm, ynorm, ref totR, ref totV, ref totB); totR >>= 1; totV >>= 1; totB >>= 1; for (int i1 = 0; i1 < MaxCol; i1++) { for (int i2 = 0; i2 < MaxCol; i2++) { int sr = tabCol[i1].red + tabCol[i2].red; int sv = tabCol[i1].green + tabCol[i2].green; int sb = tabCol[i1].blue + tabCol[i2].blue; int Dist = CalcDist(sr, sv, sb, totR, totV, totB); if (Dist < OldDist) { choix0 = i1; choix1 = i2; OldDist = Dist; if (Dist == 0) { i1 = i2 = MaxCol; } } } } dest.SetPixelCpc(x, y, choix0); dest.SetPixelCpc(xnorm, y, choix1); dest.SetPixelCpc(x, ynorm, choix1); dest.SetPixelCpc(xnorm, ynorm, choix0); } } }
static void SetPixColBigPixelM0(BitmapCpc dest) { int index = 0, pos = 0, choix0 = 0; for (int y = 0; y < tailleY; y += 8) { for (int x = 0; x < tailleX; x += 8) { int OldDist = 0x7FFFFFFF; int totR = 0, totV = 0, totB = 0; for (int i1 = 0; i1 < 4; i1++) { for (int i2 = 0; i2 < 4; i2++) { bitmap.AddGetPixel(x + 2 * i2 < tailleX ? x + 2 * i2 : x + 1, y + 2 * i1 < tailleY ? y + 2 * i1 : y + 1, ref totR, ref totV, ref totB); } } pos = 0; for (int i1 = 0; i1 < 16; i1++) { int Dist = CalcDist(tabCol[i1].red << 4, tabCol[i1].green << 4, tabCol[i1].blue << 4, totR, totV, totB); pos++; if (Dist < OldDist) { choix0 = i1; OldDist = Dist; if (Dist == 0) { i1 = 16; } } } resultTri[index++] = choix0; for (int i1 = 0; i1 < 4; i1++) { for (int i2 = 0; i2 < 4; i2++) { dest.SetPixelCpc(x + 2 * i2 < tailleX ? x + 2 * i2 : x + 1, y + 2 * i1 < tailleY ? y + 2 * i1 : y + 1, choix0); } } } } }
static void SetPixColTriangle(BitmapCpc dest) { int[,] matTri = new int[4, 4] { { 0, 0, 0, 1 }, { 0, 1, 1, 0 }, { 0, 1, 1, 0 }, { 1, 0, 0, 0 } }; int index = 0, pos = 0, nb1 = 0; for (int i1 = 0; i1 < 4; i1++) { for (int i2 = 0; i2 < 4; i2++) { if (matTri[i1, i2] == 1) { nb1++; } } } for (int i1 = 0; i1 < 4; i1++) { for (int i2 = 0; i2 < 4; i2++) { int sr = tabCol[i1].red * (16 - nb1) + tabCol[i2].red * nb1; int sv = tabCol[i1].green * (16 - nb1) + tabCol[i2].green * nb1; int sb = tabCol[i1].blue * (16 - nb1) + tabCol[i2].blue * nb1; tabMelange[pos++] = new RvbColor(sr, sv, sb); } } int choix0 = 0, choix1 = 0; for (int y = 0; y < tailleY; y += 8) { for (int x = 0; x < tailleX; x += 8) { int OldDist = 0x7FFFFFFF; int totR = 0, totV = 0, totB = 0; for (int i1 = 0; i1 < 4; i1++) { for (int i2 = 0; i2 < 4; i2++) { bitmap.AddGetPixel(x + 2 * i2 < tailleX ? x + 2 * i2 : x + 1, y + 2 * i1 < tailleY ? y + 2 * i1 : y + 1, ref totR, ref totV, ref totB); } } pos = 0; for (int i1 = 0; i1 < 4; i1++) { for (int i2 = 0; i2 < 4; i2++) { int Dist = CalcDist(tabMelange[pos].red, tabMelange[pos].green, tabMelange[pos].blue, totR, totV, totB); pos++; if (Dist < OldDist) { choix0 = i1; choix1 = i2; OldDist = Dist; if (Dist == 0) { i1 = i2 = 4; } } } } resultTri[index++] = choix0 + (choix1 << 2); for (int i1 = 0; i1 < 4; i1++) { for (int i2 = 0; i2 < 4; i2++) { dest.SetPixelCpc(x + 2 * i2 < tailleX ? x + 2 * i2 : x + 1, y + 2 * i1 < tailleY ? y + 2 * i1 : y + 1, matTri[i1, i2] == 0 ? choix0 : choix1); } } } } }
static void SetPixCol3(BitmapCpc dest) { int pos = 0; for (int i1 = 0; i1 < MaxCol; i1++) { for (int i2 = 0; i2 < MaxCol; i2++) { for (int i3 = 0; i3 < MaxCol; i3++) { for (int i4 = 0; i4 < MaxCol; i4++) { int sr = tabCol[i1].red + tabCol[i2].red + tabCol[i3].red + tabCol[i4].red; int sv = tabCol[i1].green + tabCol[i2].green + tabCol[i3].green + tabCol[i4].green; int sb = tabCol[i1].blue + tabCol[i2].blue + tabCol[i3].blue + tabCol[i4].blue; tabMelange[pos++] = new RvbColor(sr, sv, sb); } } } } int choix0 = 0, choix2 = 0, choix3 = 0, choix1 = 0; for (int y = 0; y < tailleY; y += 4) { int ynorm = y + 2 < tailleY ? y + 2 : y + 1; for (int x = 0; x < tailleX; x += Tx << 1) { int xnorm = x + Tx < tailleX ? x + Tx : x + 1; int OldDist = 0x7FFFFFFF; int totR = 0, totV = 0, totB = 0; bitmap.GetPixel(x, y, ref totR, ref totV, ref totB); bitmap.AddGetPixel(x, ynorm, ref totR, ref totV, ref totB); bitmap.AddGetPixel(xnorm, y, ref totR, ref totV, ref totB); bitmap.AddGetPixel(xnorm, ynorm, ref totR, ref totV, ref totB); pos = 0; for (int i1 = 0; i1 < MaxCol; i1++) { for (int i2 = 0; i2 < MaxCol; i2++) { for (int i3 = 0; i3 < MaxCol; i3++) { for (int i4 = 0; i4 < MaxCol; i4++) { int Dist = CalcDist(tabMelange[pos].red, tabMelange[pos].green, tabMelange[pos].blue, totR, totV, totB); pos++; if (Dist < OldDist) { choix0 = i1; choix1 = i2; choix2 = i3; choix3 = i4; OldDist = Dist; if (Dist == 0) { i1 = i2 = i3 = i4 = MaxCol; } } } } } } dest.SetPixelCpc(x, y, choix0); dest.SetPixelCpc(x, ynorm, choix2); dest.SetPixelCpc(xnorm, y, choix3); dest.SetPixelCpc(xnorm, ynorm, choix1); } } }