예제 #1
0
        private int PackWinDC(byte[] bufOut, ref int sizeDepack, int topBottom, bool razDiff, int modeLigne, bool optimSpeed)
        {
            int xFin = 0;
            int xDeb = BitmapCpc.NbCol;
            int yDeb = BitmapCpc.NbLig;
            int yFin = 0;
            int lStart = 0, lEnd = BitmapCpc.NbLig, xStart = 0, xEnd = BitmapCpc.NbCol;

            if (razDiff)
            {
                Array.Clear(BufPrec, 0, BufPrec.Length);
            }

            // Copier l'image cpc dans le buffer de travail
            img.bitmapCpc.CreeBmpCpc(img.BmpLock, null);

            if (chkZoneVert.Checked)
            {
                xStart = topBottom < 1 ? 0 : BitmapCpc.NbCol >> 1;
                xEnd   = topBottom == 0 ? BitmapCpc.NbCol >> 1 : BitmapCpc.NbCol;
            }
            else
            {
                lStart = topBottom < 1 ? 0 : BitmapCpc.NbLig >> 1;
                lEnd   = topBottom == 0 ? BitmapCpc.NbLig >> 1 : BitmapCpc.NbLig;
            }
            // Recherche les "coordonnées" de l'image différente par rapport à la précédente
            for (int l = lStart; l < lEnd; l += modeLigne)
            {
                int adr = BitmapCpc.GetAdrCpc(l << 1);
                for (int oct = xStart; oct < xEnd; oct++)
                {
                    if (img.bitmapCpc.bmpCpc[adr + oct] != BufPrec[adr + oct])
                    {
                        xDeb = Math.Min(xDeb, oct);
                        xFin = Math.Max(xFin, oct);
                        yDeb = Math.Min(yDeb, l);
                        yFin = Math.Max(yFin, l);
                        BufPrec[adr + oct] = img.bitmapCpc.bmpCpc[adr + oct];
                    }
                }
            }

            int tailleX = xFin > xDeb ? xFin - xDeb + 1 : 0;
            int tailleY = (yFin + 1 - yDeb) / modeLigne;
            int length  = tailleX * tailleY;

            if (length > 0)
            {
                Array.Clear(bLigne, 0, bLigne.Length);
                int pos = 0, AdrEcr;
                bLigne[pos++] = (byte)tailleX;
                bLigne[pos++] = (byte)tailleY;
                if (!optimSpeed)
                {
                    AdrEcr        = 0xC000 + xDeb + (yDeb >> 3) * BitmapCpc.NbCol + (yDeb & 7) * 0x800;
                    bLigne[pos++] = (byte)(AdrEcr & 0xFF);
                    bLigne[pos++] = (byte)(AdrEcr >> 8);
                }
                if (chkCol.Checked)
                {
                    // passage en mode "colonne par colonne"
                    for (int x = xDeb; x <= xFin; x++)
                    {
                        for (int l = 0; l < tailleY * modeLigne; l += modeLigne)
                        {
                            int offsetEcr = ((l + yDeb) >> 3) * BitmapCpc.NbCol + ((l + yDeb) & 7) * 0x800 + x;
                            if (optimSpeed)
                            {
                                AdrEcr        = 0xC000 + offsetEcr;
                                bLigne[pos++] = (byte)(AdrEcr & 0xFF);
                                bLigne[pos++] = (byte)(AdrEcr >> 8);
                            }
                            bLigne[pos++] = BufPrec[offsetEcr];
                        }
                    }
                }
                else
                {
                    // Passage en mode "ligne à ligne"
                    for (int l = yDeb; l <= yFin; l += modeLigne)
                    {
                        int offsetEcr = (l >> 3) * BitmapCpc.NbCol + (l & 7) * 0x800 + xDeb;
                        if (optimSpeed)
                        {
                            AdrEcr        = 0xC000 + offsetEcr;
                            bLigne[pos++] = (byte)(AdrEcr & 0xFF);
                            bLigne[pos++] = (byte)(AdrEcr >> 8);
                        }
                        Array.Copy(BufPrec, offsetEcr, bLigne, pos, tailleX);
                        pos += tailleX;
                    }
                }
                int lpack = PackDepack.Pack(bLigne, pos, bufOut, 0);
                sizeDepack = length + 4;
                return(lpack);
            }
            else
            {
                return(0);
            }
        }
예제 #2
0
        public byte[] GetCpcScr(Param param, bool spriteMode = false)
        {
            int maxSize = (BitmapCpc.TailleX >> 3) + ((BitmapCpc.TailleY - 2) >> 4) * (BitmapCpc.TailleX >> 3) + ((BitmapCpc.TailleY - 2) & 14) * 0x400;

            if (spriteMode)
            {
                maxSize = (BitmapCpc.TailleX * BitmapCpc.TailleY) >> 4;
            }
            else
            if (maxSize >= 0x4000)
            {
                maxSize += 0x3800;
            }

            byte[] ret = new byte[maxSize];
            Array.Clear(ret, 0, ret.Length);
            int posRet = 0;

            for (int y = 0; y < BitmapCpc.TailleY; y += 2)
            {
                int adrCPC = BitmapCpc.GetAdrCpc(y);
                int tx     = BitmapCpc.CalcTx(y);
                for (int x = 0; x < BitmapCpc.TailleX; x += 8)
                {
                    byte pen = 0, octet = 0;
                    for (int p = 0; p < 8; p++)
                    {
                        if ((p % tx) == 0)
                        {
                            RvbColor col = BmpLock.GetPixelColor(x + p, y);
                            if (BitmapCpc.cpcPlus)
                            {
                                for (pen = 0; pen < 16; pen++)
                                {
                                    if ((col.v >> 4) == (BitmapCpc.Palette[pen] >> 8) && (col.r >> 4) == ((BitmapCpc.Palette[pen] >> 4) & 0x0F) && (col.b >> 4) == (BitmapCpc.Palette[pen] & 0x0F))
                                    {
                                        break;
                                    }
                                }
                            }
                            else
                            {
                                for (pen = 0; pen < 16; pen++)
                                {
                                    RvbColor fixedCol = BitmapCpc.RgbCPC[BitmapCpc.Palette[pen]];
                                    if (fixedCol.r == col.r && fixedCol.b == col.b && fixedCol.v == col.v)
                                    {
                                        break;
                                    }
                                }
                            }
                            octet |= (byte)(tabOctetMode[pen] >> (p / tx));
                        }
                    }
                    if (!spriteMode)
                    {
                        posRet = BitmapCpc.GetAdrCpc(y) + (x >> 3);
                    }

                    ret[posRet++] = octet;
                }
            }
            return(ret);
        }