Пример #1
0
        static public int Convert(DirectBitmap source, ImageCpc dest, Param p, bool noInfo = false)
        {
            System.Array.Clear(coulTrouvee, 0, coulTrouvee.GetLength(0) * coulTrouvee.GetLength(1));
            double c = p.pctContrast / 100.0;

            for (int i = 0; i < 256; i++)
            {
                tblContrast[i] = MinMaxByte(((((i / 255.0) - 0.5) * c) + 0.5) * 255.0);
            }

            ConvertPasse1(source, dest, p);
            int nbCol = 0;

            for (int i = 0; i < coulTrouvee.GetLength(0); i++)
            {
                bool memoCol = false;
                for (int y = 0; y < 272; y++)
                {
                    if (!memoCol && coulTrouvee[i, y] > 0)
                    {
                        nbCol++;
                        memoCol = true;
                    }
                }
            }

            int colSplit = 0;

            Passe2(source, dest, p, ref colSplit);
            if (!noInfo)
            {
                dest.main.SetInfo("Conversion terminée, nombre de couleurs dans l'image:" + nbCol);
                if (colSplit > 0)
                {
                    dest.main.SetInfo("Couleurs générées avec split : " + colSplit);
                }
            }

            dest.bitmapCpc.isCalc = true;
            return(nbCol);
        }
Пример #2
0
        public Main()
        {
            InitializeComponent();
            imgCpc       = new ImageCpc(this, Convert);
            anim         = new Animation(this);
            paramInterne = new ParamInterne(this);
            paramInterne.InitValues();
            ChangeLanguage("FR");
            int i = 1;

            foreach (KeyValuePair <string, double[, ]> dith in Dither.dicMat)
            {
                methode.Items.Insert(i++, dith.Key);
            }

            SetModes();

            nbCols.Value          = BitmapCpc.TailleX >> 3;
            nbLignes.Value        = BitmapCpc.TailleY >> 1;
            methode.SelectedIndex = 0;
            param.pctContrast     = param.pctLumi = param.pctSat = param.pctRed = param.pctGreen = param.pctBlue = 100;
            param.withCode        = withCode.Checked;
            param.withPalette     = withPalette.Checked;
            Version version = Assembly.GetExecutingAssembly().GetName().Version;

            lblInfoVersion.Text = "V " + version.ToString() + " - " + new DateTime(2000, 1, 1).AddDays(version.Build).ToShortDateString();
            radioUserSize_CheckedChanged(null, null);
            string configDetault = "ConvImgCpc.xml";

            if (File.Exists(configDetault))
            {
                ReadParam(configDetault);
            }

            anim.Show();
            imgCpc.Show();
            Show();
            CheckVersion(version);
        }
Пример #3
0
        // #### A revoir...
        static public void GenereAfficheStd(StreamWriter sw, ImageCpc img, int mode, int[] palette, bool overscan)
        {
            sw.WriteLine("	DI");
            if (BitmapCpc.cpcPlus)
            {
                GenereInitPlus(sw);
            }
            else
            {
                GenereInitOld(sw);
            }

            GenereFormatEcran(sw);
            sw.WriteLine("	LD	HL,ImageCmp");
            sw.WriteLine("	LD	DE,#"+ (overscan ? "0200" : "C000"));
            sw.WriteLine("	CALL	DepkLzw");
            GenereTspace(sw, false);

            sw.WriteLine("	LD	BC,#BC0C");
            sw.WriteLine("	LD	A,#30");
            sw.WriteLine("	OUT	(C),C");
            sw.WriteLine("	INC	B");
            sw.WriteLine("	OUT	(C),A");
            sw.WriteLine("	EI");
            sw.WriteLine("	RET");

            GenereDepack(sw);

            if (BitmapCpc.cpcPlus)
            {
                GenerePalettePlus(sw, img);
            }
            else
            {
                GenerePaletteOld(sw, img);
            }
        }
Пример #4
0
        //
        // 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;
            }
        }
Пример #5
0
        static public int SauveScr(string fileName, BitmapCpc bitmapCpc, ImageCpc img, Param param, bool compact, string version = null, int[,] colMode5 = null)
        {
            byte[] bufPack  = new byte[0x8000];
            bool   overscan = (BitmapCpc.NbLig * BitmapCpc.NbCol > 0x3F00);

            if (param.withPalette && version == null)
            {
                if (param.cpcPlus)
                {
                    ModePal[0] = (byte)(BitmapCpc.modeVirtuel | 0x8C);
                    int k = 1;
                    for (int i = 0; i < 16; i++)
                    {
                        ModePal[k++] = (byte)(((BitmapCpc.Palette[i] >> 4) & 0x0F) | (BitmapCpc.Palette[i] << 4));
                        ModePal[k++] = (byte)(BitmapCpc.Palette[i] >> 8);
                    }
                }
                else
                {
                    ModePal[0] = (byte)BitmapCpc.modeVirtuel;
                    for (int i = 0; i < 16; i++)
                    {
                        ModePal[1 + i] = (byte)BitmapCpc.Palette[i];
                    }
                }
            }

            byte[] imgCpc = bitmapCpc.bmpCpc;
            if (!overscan)
            {
                Buffer.BlockCopy(ModePal, 0, imgCpc, 0x17D0, ModePal.Length);
                if (param.withCode && version == null)
                {
                    if (param.cpcPlus)
                    {
                        Buffer.BlockCopy(CodeP0, 0, imgCpc, 0x07D0, CodeP0.Length);
                        Buffer.BlockCopy(CodeP1, 0, imgCpc, 0x0FD0, CodeP1.Length);
                        Buffer.BlockCopy(CodeP3, 0, imgCpc, 0x1FD0, CodeP3.Length);
                    }
                    else
                    {
                        Buffer.BlockCopy(CodeStd, 0, imgCpc, 0x07D0, CodeStd.Length);
                    }

                    if (BitmapCpc.modeVirtuel == 3 || BitmapCpc.modeVirtuel == 4)
                    {
                        Buffer.BlockCopy(codeEgx0, 0, imgCpc, 0x37D0, codeEgx0.Length);
                        Buffer.BlockCopy(codeEgx1, 0, imgCpc, 0x2FD0, codeEgx1.Length);
                        imgCpc[0x07F2] = 0xD0;
                        imgCpc[0x07F3] = 0xF7;                          //	CALL 0xF7D0
                        imgCpc[0x37FA] = 0xEF;                          //	Call 0xEFD0
                    }
                }
            }
            else
            {
                if (BitmapCpc.NbLig * BitmapCpc.NbCol > 0x4000)
                {
                    Buffer.BlockCopy(ModePal, 0, imgCpc, 0x600, ModePal.Length);
                    if (param.withCode && version == null)
                    {
                        if (param.cpcPlus)
                        {
                            Buffer.BlockCopy(CodeOvP, 0, imgCpc, 0x621, CodeOvP.Length);
                        }
                        else
                        {
                            Buffer.BlockCopy(CodeOv, 0, imgCpc, 0x611, CodeOv.Length);
                        }

                        if (BitmapCpc.modeVirtuel == 3 || BitmapCpc.modeVirtuel == 4)
                        {
                            Buffer.BlockCopy(codeEgx0, 0, imgCpc, 0x1600, codeEgx0.Length);
                            Buffer.BlockCopy(codeEgx1, 0, imgCpc, 0x1640, codeEgx1.Length);
                            if (param.cpcPlus)
                            {
                                imgCpc[0x669] = 0xCD;
                                imgCpc[0x66A] = 0x00;
                                imgCpc[0x66B] = 0x18;                                           // CALL	#1800
                            }
                            else
                            {
                                imgCpc[0x631] = 0x00;
                                imgCpc[0x632] = 0x18;                                           // CALL	#1800
                            }
                            imgCpc[0x1629] = 0x40;
                            imgCpc[0x162A] = 0x18;                              //	CALL	#1840
                        }
                    }
                }
            }

            short     startAdr = (short)(overscan ? 0x200 : 0xC000);
            short     exec     = (short)(overscan ? param.cpcPlus ? 0x821 : 0x811 : 0xC7D0);
            CpcAmsdos entete;
            int       lg = BitmapCpc.BitmapSize;

            if (compact)
            {
                lg = PackDepack.Pack(bitmapCpc.bmpCpc, lg, bufPack, 0) + 1;                 // Prendre 1 octet de marge ?
                if (param.withCode && version == null)
                {
                    Buffer.BlockCopy(codeDepack, 0, bufPack, lg, codeDepack.Length);
                    bufPack[lg + 4]  = (byte)(startAdr & 0xFF);
                    bufPack[lg + 5]  = (byte)(startAdr >> 8);
                    startAdr         = (short)(0xA657 - (lg + codeDepack.Length));
                    bufPack[lg + 1]  = (byte)(startAdr & 0xFF);
                    bufPack[lg + 2]  = (byte)(startAdr >> 8);
                    bufPack[lg + 32] = (byte)(exec & 0xFF);
                    bufPack[lg + 33] = (byte)(exec >> 8);
                    lg  += codeDepack.Length;
                    exec = (short)(0xA657 - codeDepack.Length);
                }
                else
                {
                    startAdr = (short)(0xA657 - lg);
                    exec     = 0;
                }
            }
            if (version != null)
            {
                // Sauvegarde source assembleur
                StreamWriter sw  = SaveAsm.OpenAsm(fileName, version);
                int          org = 0xA500 - lg - (BitmapCpc.modeVirtuel == 5 ? 600 : 0);
                sw.WriteLine("	ORG	#"+ org.ToString("X4"));
                sw.WriteLine("	Nolist");
                sw.WriteLine("ImageCmp:");
                SaveAsm.GenereDatas(sw, bufPack, lg, 16);
                sw.WriteLine("	List");
                if (param.withCode)
                {
                    sw.WriteLine("	RUN	$");
                    sw.WriteLine("_StartDepack:");
                    if (BitmapCpc.modeVirtuel == 3 || BitmapCpc.modeVirtuel == 4)
                    {
                        SaveAsm.GenereAfficheModeEgx(sw, BitmapCpc.Palette, overscan);
                    }
                    else
                    {
                        SaveAsm.GenereFormatEcran(sw);
                        if (BitmapCpc.modeVirtuel == 5)
                        {
                            SaveAsm.GenereAfficheModeX(sw, colMode5, overscan);
                        }
                        else
                        {
                            SaveAsm.GenereAfficheStd(sw, img, BitmapCpc.modeVirtuel, BitmapCpc.Palette, overscan);
                        }
                    }
                }
                SaveAsm.CloseAsm(sw);
            }
            else
            {
                entete = CpcSystem.CreeEntete(fileName, startAdr, (short)lg, exec);
                BinaryWriter fp = new BinaryWriter(new FileStream(fileName, FileMode.Create));
                fp.Write(CpcSystem.AmsdosToByte(entete));
                fp.Write(compact ? bufPack : bitmapCpc.bmpCpc, 0, lg);
                fp.Close();
            }
            return(lg);
        }