// Calcul automatique matrice 4x4 en mode 1 static public void CnvTrame(DirectBitmap source, Param prm, ImageCpc dest, List <TrameM1> lstTrame, Param p) { p.modeVirtuel = 1; ConvertPasse1(source, dest, p); RechercheCMax(4, p.lockState, p); for (int y = 0; y < BitmapCpc.TailleY; y += 8) { for (int x = 0; x < BitmapCpc.TailleX; x += 8) { TrameM1 locTrame = new TrameM1(); for (int maty = 0; maty < 4; maty++) { for (int matx = 0; matx < 4; matx++) { RvbColor pix = source.GetPixelColor(x + (matx << 1), y + (maty << 1)); int oldDist = 0x7FFFFFFF; int choix = 0; for (int i = 0; i < 4; i++) { RvbColor c = dest.bitmapCpc.GetColorPal(i); int dist = (c.r - pix.r) * (c.r - pix.r) * prm.coefR + (c.v - pix.v) * (c.v - pix.v) * prm.coefV + (c.b - pix.b) * (c.b - pix.b) * prm.coefB; if (dist < oldDist) { choix = i; oldDist = dist; if (dist == 0) { i = 4; } } } locTrame.SetPix(matx, maty, choix); } } bool found = false; foreach (TrameM1 t in lstTrame) { if (t.IsSame(locTrame, 4)) { found = true; break; } } if (!found) { lstTrame.Add(locTrame); } } } }
public bool IsSame(TrameM1 t, int deltaErr = 0) { int nbErr = 0; for (int y = 0; y < 4; y++) { for (int x = 0; x < 4; x++) { if (trame[x, y] != t.GetPix(x, y)) { if (++nbErr > deltaErr) { return(false); } } } } nbFound++; return(true); }