Esempio n. 1
0
        public Bitmap CreateImageFromCpc(int length, Param par, bool isSprite = false)
        {
            if (!isSprite)
            {
                if (bmpCpc[0] == 'M' && bmpCpc[1] == 'J' && bmpCpc[2] == 'H')
                {
                    DepactOCP();
                }
                else
                if (bmpCpc[0] == 'P' && bmpCpc[1] == 'K' && (bmpCpc[2] == 'O' || bmpCpc[2] == 'V' || bmpCpc[2] == 'S'))
                {
                    DepactPK();
                }
                else
                {
                    if (!InitDatas())
                    {
                        if (length == 16384)
                        {
                            nbCol = 80;
                            nbLig = 200;
                        }
                        else
                        if (length < 32000)
                        {
                            int l = PackDepack.Depack(bmpCpc, 0, bufTmp);
                            Array.Copy(bufTmp, bmpCpc, l);
                            if (!InitDatas())
                            {
                                cpcPlus = false;
                                nbCol   = maxColsCpc;
                                nbLig   = maxLignesCpc;
                                SetPalette(bmpCpc, 0x600, cpcPlus);
                            }
                        }
                        else
                        {
                            if (length > 0x4000)
                            {
                                nbCol = maxColsCpc;
                                nbLig = maxLignesCpc;
                            }
                        }
                    }
                }
            }
            par.cpcPlus = cpcPlus;
            // Rendu dans un bitmap PC
            DirectBitmap loc = new DirectBitmap(nbCol << 3, nbLig * 2);

            for (int y = 0; y < nbLig << 1; y += 2)
            {
                int mode    = (modeVirtuel >= 5 ? 1 : modeVirtuel >= 3 ? (y & 2) == 0 ? modeVirtuel - 2 : modeVirtuel - 3 : modeVirtuel);
                int adrCPC  = isSprite ? nbCol * (y >> 1) : GetAdrCpc(y);
                int xBitmap = 0;
                for (int x = 0; x < nbCol; x++)
                {
                    byte octet = bmpCpc[adrCPC + x];
                    switch (mode)
                    {
                    case 0:
                        loc.SetHorLineDouble(xBitmap, y, 4, GetPalCPC(Palette[(octet >> 7) + ((octet & 0x20) >> 3) + ((octet & 0x08) >> 2) + ((octet & 0x02) << 2)]));
                        loc.SetHorLineDouble(xBitmap + 4, y, 4, GetPalCPC(Palette[((octet & 0x40) >> 6) + ((octet & 0x10) >> 2) + ((octet & 0x04) >> 1) + ((octet & 0x01) << 3)]));
                        xBitmap += 8;
                        break;

                    case 1:
                        loc.SetHorLineDouble(xBitmap, y, 2, GetPalCPC(Palette[((octet >> 7) & 1) + ((octet >> 2) & 2)]));
                        loc.SetHorLineDouble(xBitmap + 2, y, 2, GetPalCPC(Palette[((octet >> 6) & 1) + ((octet >> 1) & 2)]));
                        loc.SetHorLineDouble(xBitmap + 4, y, 2, GetPalCPC(Palette[((octet >> 5) & 1) + ((octet >> 0) & 2)]));
                        loc.SetHorLineDouble(xBitmap + 6, y, 2, GetPalCPC(Palette[((octet >> 4) & 1) + ((octet << 1) & 2)]));
                        xBitmap += 8;
                        break;

                    case 2:
                        for (int i = 8; i-- > 0;)
                        {
                            loc.SetPixel(xBitmap, y, GetPalCPC(Palette[(octet >> i) & 1]));
                            loc.SetPixel(xBitmap++, y + 1, GetPalCPC(Palette[(octet >> i) & 1]));
                        }

                        break;
                    }
                }
            }
            return(loc.Bitmap);
        }
Esempio n. 2
0
        private void ToolModeCopy(MouseEventArgs e)
        {
            int yReel = ((e.Y / zoom) & 0xFFE) * zoom;
            int tx    = BitmapCpc.CalcTx(yReel);
            int xReel = ((e.X / zoom) & -tx) * zoom;

            if (e.Button == MouseButtons.Left && xReel >= 0 && yReel >= 0)
            {
                if (imgMotif != null)
                {
                    for (int y = 0; y < imgMotif.Height; y += 2)
                    {
                        tx = BitmapCpc.CalcTx(y + yReel);
                        for (int x = 0; x < imgMotif.Width; x += tx)
                        {
                            if (x + xReel < BitmapCpc.NbCol << 3 && y + yReel < BitmapCpc.NbLig << 1)
                            {
                                int c = imgMotif.GetPixel(x, y);
                                undo.MemoUndoRedo(x + xReel, y + yReel, BmpLock.GetPixel(x + xReel, y + yReel), c, doDraw);
                                BmpLock.SetHorLineDouble(x + xReel, y + yReel, tx, c);
                                doDraw = true;
                            }
                        }
                    }
                    imgCopy.CopyBits(BmpLock);
                    Render();
                }
                else
                {
                    if (!setCopyRect)
                    {
                        setCopyRect = true;
                        copyRectx   = xReel;
                        copyRecty   = yReel;
                        copyRecth   = copyRectw = 0;
                    }
                    else
                    {
                        Graphics g = Graphics.FromImage(pictureBox.Image);
                        if (copyRecth != 0 || copyRectw != 0)
                        {
                            XorDrawing.DrawXorRectangle(g, (Bitmap)pictureBox.Image, copyRectx, copyRecty, copyRectx + copyRectw, copyRecty + copyRecth);
                        }
                        copyRectw = xReel - copyRectx;
                        copyRecth = yReel - copyRecty;
                        XorDrawing.DrawXorRectangle(g, (Bitmap)pictureBox.Image, copyRectx, copyRecty, copyRectx + copyRectw, copyRecty + copyRecth);
                        pictureBox.Refresh();
                    }
                }
            }
            else
            {
                if (setCopyRect)
                {
                    setCopyRect = false;
                    if (copyRectw != 0 && copyRecth != 0)
                    {
                        Graphics g = Graphics.FromImage(pictureBox.Image);
                        XorDrawing.DrawXorRectangle(g, (Bitmap)pictureBox.Image, copyRectx, copyRecty, copyRectx + copyRectw, copyRecty + copyRecth);
                        imgMotif = new DirectBitmap(Math.Abs(copyRectw / zoom), Math.Abs(copyRecth / zoom));
                        for (int x = 0; x < imgMotif.Width; x++)
                        {
                            for (int y = 0; y < imgMotif.Height; y++)
                            {
                                imgMotif.SetPixel(x, y, BmpLock.GetPixel(offsetX + x + copyRectx / zoom, offsetY + y + copyRecty / zoom));
                            }
                        }

                        if (zoom != 1)
                        {
                            zoom = 1;
                            DoZoom();
                        }
                        imgCopy          = new DirectBitmap(BmpLock.Width, BmpLock.Height);
                        pictureBox.Image = imgCopy.Bitmap;
                    }
                }
                if (doDraw)
                {
                    doDraw = false;
                    undo.EndUndoRedo();
                }
                DrawCopy(e);
                pictureBox.Refresh();
            }
        }