Exemple #1
0
        public void Reset(bool force = false)
        {
            if (!bitmapCpc.isCalc || force)
            {
                int startImg = force ? 0 : selImage;
                int endImg   = force ? maxImage : selImage;
                for (int i = startImg; i < endImg; i++)
                {
                    selImage = i;
                    int col = System.Drawing.SystemColors.Control.ToArgb();
                    for (int y = 0; y < tabBmpLock[i].Height; y += 2)
                    {
                        int startX = y < BitmapCpc.TailleY ? BitmapCpc.TailleX : 0;
                        tabBmpLock[i].SetHorLineDouble(0, y, startX, GetPalCPC(BitmapCpc.Palette[0]));
                        tabBmpLock[i].SetHorLineDouble(startX, y, tabBmpLock[i].Width - startX, col);
                    }
                }
            }
            int tx     = BitmapCpc.CalcTx();
            int maxPen = BitmapCpc.MaxPen(2);

            for (int i = 0; i < 16; i++)
            {
                colors[i].Visible = lockColors[i].Visible = i < maxPen;
            }

            ToolModeDraw(null);
        }
Exemple #2
0
        static public void GenerePaletteOld(StreamWriter sw, ImageCpc img)
        {
            sw.WriteLine("Palette:");
            string line = "\tDB\t";

            for (int i = 0; i < 17; i++)
            {
                line += "#" + ((int)BitmapCpc.CpcVGA[BitmapCpc.Palette[i < BitmapCpc.MaxPen() ? i : 0]]).ToString("X2") + ",";
            }

            line += "#" + ((BitmapCpc.modeVirtuel == 7 ? 1 : BitmapCpc.modeVirtuel & 3) | 0x8C).ToString("X2");
            sw.WriteLine(line);
        }
Exemple #3
0
        static public void GenerePalettePlus(StreamWriter sw, ImageCpc img)
        {
            sw.WriteLine("UnlockAsic:");
            sw.WriteLine("	DB	#FF,#00,#FF,#77,#B3,#51,#A8,#D4,#62,#39,#9C,#46,#2B,#15,#8A,#CD,#EE");
            sw.WriteLine("Palette:");
            string line = "\tDB\t#" + ((BitmapCpc.modeVirtuel == 7 ? 1 : BitmapCpc.modeVirtuel & 3) | 0x8C).ToString("X2");

            for (int i = 0; i < 17; i++)
            {
                int c = BitmapCpc.Palette[i < BitmapCpc.MaxPen() ? i : 0];
                line += ",#" + ((byte)(((c >> 4) & 0x0F) | (c << 4))).ToString("X2") + ",#" + ((byte)(c >> 8)).ToString("X2");
            }
            sw.WriteLine(line);
        }
Exemple #4
0
        // Copier la palette dans le presse-papier
        private void bpCopyPal_Click(object sender, EventArgs e)
        {
            string palTxt = "";
            int    maxPen = BitmapCpc.MaxPen(2);

            for (int i = 0; i < maxPen; i++)
            {
                int    val    = BitmapCpc.Palette[i];
                string valStr = BitmapCpc.cpcPlus ? ("&" + val.ToString("X3")) : val.ToString();
                palTxt += valStr + (i < maxPen - 1 ? "," : "");
            }
            Clipboard.SetText(palTxt);
            MessageBox.Show("Palette copiée dans le presse-papier");
        }
        // Conversion "standard"
        static private void SetPixCol(DirectBitmap bitmap, Param prm, ImageCpc dest, int maxPen, RvbColor[,] tabCol)
        {
            int      incY = BitmapCpc.modeVirtuel >= 8 && BitmapCpc.modeVirtuel <= 10 ? 8 : 2;
            RvbColor pix;

            for (int y = 0; y < BitmapCpc.TailleY; y += incY)
            {
                int Tx = BitmapCpc.CalcTx(y);
                maxPen = BitmapCpc.MaxPen(y);
                for (int x = 0; x < BitmapCpc.TailleX; x += Tx)
                {
                    int oldDist = 0x7FFFFFFF;
                    int r = 0, v = 0, b = 0;
                    for (int j = 0; j < incY; j += 2)
                    {
                        pix = bitmap.GetPixelColor(x, y + j);
                        r  += pix.r;
                        v  += pix.v;
                        b  += pix.b;
                    }
                    r   = r / (incY >> 1);
                    v   = v / (incY >> 1);
                    b   = b / (incY >> 1);
                    pix = new RvbColor((byte)r, (byte)v, (byte)b);
                    int choix = 0;
                    for (int i = 0; i < maxPen; i++)
                    {
                        RvbColor c = tabCol[i, y >> 1];
                        if (c != null)
                        {
                            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 = maxPen;
                                }
                            }
                        }
                    }
                    for (int j = 0; j < incY; j += 2)
                    {
                        dest.SetPixelCpc(x, y + j, choix, Tx);
                    }
                }
            }
        }
 // Conversion avec trames précalculées en mode 1
 static private void SetPixTrameM1(DirectBitmap bitmap, Param prm, ImageCpc dest, int maxPen, RvbColor[,] tabCol)
 {
     for (int y = 0; y <= BitmapCpc.TailleY - 8; y += 8)
     {
         maxPen = BitmapCpc.MaxPen(y);
         for (int x = 0; x < BitmapCpc.TailleX; x += 8)
         {
             int choix = 0, oldDist = 0x7FFFFFFF;
             for (int i = 0; i < 16; i++)
             {
                 int dist = 0, r1 = 0, v1 = 0, b1 = 0, r2 = 0, v2 = 0, b2 = 0;
                 for (int ym = 0; ym < 4; ym++)
                 {
                     for (int xm = 0; xm < 4; xm++)
                     {
                         RvbColor pix = bitmap.GetPixelColor(x + (xm << 1), y + (ym << 1));
                         RvbColor c   = tabCol[BitmapCpc.trameM1[i, xm, ym], ym + (y >> 1)];
                         r1 += pix.r;
                         v1 += pix.v;
                         b1 += pix.b;
                         r2 += c.r;
                         v2 += c.v;
                         b2 += c.b;
                     }
                 }
                 dist = Math.Abs(r1 - r2) * prm.coefR + Math.Abs(v1 - v2) * prm.coefV + Math.Abs(b1 - b2) * prm.coefB;
                 if (dist < oldDist)
                 {
                     choix   = i;
                     oldDist = dist;
                     if (dist == 0)
                     {
                         i = 16;
                     }
                 }
             }
             for (int ym = 0; ym < 4; ym++)
             {
                 for (int xm = 0; xm < 4; xm++)
                 {
                     dest.SetPixelCpc(x + (xm << 1), y + (ym << 1), BitmapCpc.trameM1[choix, xm, ym], 2);
                 }
             }
         }
     }
 }
        //
        // Passe 2 : réduit l'image à MaxPen couleurs.
        //
        static private void Passe2(DirectBitmap source, ImageCpc dest, Param p, ref int colSplit)
        {
            RvbColor[,] tabCol = new RvbColor[16, 272];
            int[] MemoLockState = new int[16];
            int   i;
            int   Tx     = BitmapCpc.CalcTx();
            int   maxPen = BitmapCpc.MaxPen(2);

            for (i = 0; i < 16; i++)
            {
                MemoLockState[i] = p.lockState[i];
            }

            if (BitmapCpc.modeVirtuel == 3 || BitmapCpc.modeVirtuel == 4)
            {
                int newMax = BitmapCpc.MaxPen(0);
                RechercheCMax(newMax, MemoLockState, p);
                for (i = 0; i < newMax; i++)
                {
                    MemoLockState[i] = 1;
                }
            }
            if (BitmapCpc.modeVirtuel == 5 || BitmapCpc.modeVirtuel == 6)
            {
                if (BitmapCpc.modeVirtuel == 5)
                {
                    colSplit = RechercheCMaxModeX(dest.colMode5, MemoLockState, BitmapCpc.TailleY, p);
                }
                else
                {
                    colSplit = RechercheCMaxModeSplit(dest.colMode5, MemoLockState, BitmapCpc.TailleY, p);
                    maxPen   = 9;
                }
                // réduit l'image à MaxPen couleurs.
                for (int y = 0; y < BitmapCpc.TailleY >> 1; y++)
                {
                    for (i = 0; i < maxPen; i++)
                    {
                        tabCol[i, y] = p.cpcPlus ? new RvbColor((byte)((dest.colMode5[y, i] & 0x0F) * 17), (byte)(((dest.colMode5[y, i] & 0xF00) >> 8) * 17), (byte)(((dest.colMode5[y, i] & 0xF0) >> 4) * 17))
                                                        : BitmapCpc.RgbCPC[dest.colMode5[y, i] < 27 ? dest.colMode5[y, i] : 0];
                    }
                }
            }
            else
            {
                RechercheCMax(maxPen, MemoLockState, p);
                // réduit l'image à MaxPen couleurs.
                for (int y = 0; y < BitmapCpc.TailleY; y += 2)
                {
                    maxPen = BitmapCpc.MaxPen(y);
                    for (i = 0; i < maxPen; i++)
                    {
                        tabCol[i, y >> 1] = dest.bitmapCpc.GetColorPal(i);
                    }
                }
            }
            switch (BitmapCpc.modeVirtuel)
            {
            case 6:
                SetPixColSplit(source, p, dest, tabCol);
                break;

            case 7:
                SetPixTrameM1(source, p, dest, maxPen, tabCol);
                break;

            default:
                SetPixCol(source, p, dest, maxPen, tabCol);
                break;
            }
        }