Exemplo n.º 1
0
        static public int Convert(Bitmap source, BitmapCpc dest, Param p, bool triangle)
        {
            int[] CChoix = new int[16];
            Tx     = 4 >> (dest.ModeCPC == 3 ? 1 : dest.ModeCPC);
            MaxCol = 1 << Tx;
            for (int i = 0; i < 16; i++)
            {
                CChoix[i] = dest.Palette[i];
            }

            tailleX = dest.TailleX;
            tailleY = dest.TailleY;
            double   ratio = source.Width * tailleY / (double)(source.Height * tailleX);
            Bitmap   tmp   = new Bitmap(tailleX, tailleY);
            Graphics g     = Graphics.FromImage(tmp);

            switch (p.sizeMode)
            {
            case Param.SizeMode.KeepSmaller:
                if (ratio < 1)
                {
                    int newW = (int)(tailleX * ratio);
                    g.DrawImage(source, (tailleX - newW) >> 1, 0, newW, tailleY);
                }
                else
                {
                    int newH = (int)(tailleY / ratio);
                    g.DrawImage(source, 0, (tailleY - newH) >> 1, tailleX, newH);
                }
                bitmap = new LockBitmap(tmp);
                break;

            case Param.SizeMode.KeepLarger:
                if (ratio < 1)
                {
                    int newY = (int)(tailleY / ratio);
                    g.DrawImage(source, 0, (tailleY - newY) >> 1, tailleX, newY);
                }
                else
                {
                    int newX = (int)(tailleX * ratio);
                    g.DrawImage(source, (tailleX - newX) >> 1, 0, newX, tailleY);
                }
                bitmap = new LockBitmap(tmp);
                break;

            case Param.SizeMode.Fit:
                bitmap = new LockBitmap(new Bitmap(source, tailleX, tailleY));
                break;
            }
            bitmap.LockBits();
            int nbCol = ConvertPasse1(tailleX, tailleY, p.methode, p.matrice, p.pct, p.cpcPlus, p.newMethode, dest.ModeCPC, p.cpcPlus, p.reductPal1, p.reductPal2, p.newReduct, p.pctLumi, p.pctSat, p.pctContrast);

            //Bitmap b = bitmap.UnlockBits();
            //b.Save(@"C:\Users\deplanql\Desktop\Test.png",System.Drawing.Imaging.ImageFormat.Png);
            //bitmap.LockBits();
            RechercheCMax(CChoix, p.lockState, p.cpcPlus, p.sortPal);
            Passe2(dest, CChoix, p.cpcPlus, triangle ? 4 : p.pixMode);
            for (int i = 0; i < 16; i++)
            {
                dest.SetPalette(i, CChoix[i]);
            }

            bitmap.UnlockBits();
            return(nbCol);
        }