private void ToolModeDraw(MouseEventArgs e) { int incY = BitmapCpc.modeVirtuel >= 8 ? 8 : 2; int yReel = e != null ? (offsetY + (e.Y / zoom)) & -incY : 0; int tx = BitmapCpc.CalcTx(yReel); drawColor.BackColor = Color.FromArgb(bitmapCpc.GetColorPal(drawCol % (BitmapCpc.modeVirtuel == 6 ? 16 : 1 << tx)).GetColorArgb); undrawColor.BackColor = Color.FromArgb(bitmapCpc.GetColorPal(undrawCol % (BitmapCpc.modeVirtuel == 6 ? 16 : 1 << tx)).GetColorArgb); drawColor.Width = undrawColor.Width = 35 * Math.Min(tx, 4); drawColor.Refresh(); undrawColor.Refresh(); if (e == null || e.Button == MouseButtons.None) { if (doDraw) { doDraw = false; undo.EndUndoRedo(); } } else { int pen = e.Button == MouseButtons.Left ? drawCol : undrawCol; for (int y = 0; y < penWidth * incY; y += 2) { tx = BitmapCpc.CalcTx(yReel); int nbCol = BitmapCpc.modeVirtuel == 6 ? 16 : 1 << tx; int realColor = GetPalCPC(BitmapCpc.Palette[pen % nbCol]); int yStart = zoom * (yReel - offsetY); for (int x = 0; x < penWidth * tx; x += tx) { int xReel = (x + offsetX + (e.X / zoom)) & -tx; if (xReel >= 0 && yReel >= 0 && xReel < BitmapCpc.TailleX && yReel < BitmapCpc.TailleY) { undo.MemoUndoRedo(xReel, yReel, BmpLock.GetPixel(xReel, yReel), realColor, doDraw); doDraw = true; BmpLock.SetHorLineDouble(xReel, yReel, tx, realColor); if (zoom != 1) { for (int yz = yStart; yz < Math.Min(tmpLock.Height, yStart + (zoom << 1)); yz += 2) { if (yz >= 0) { tmpLock.SetHorLineDouble(zoom * (xReel - offsetX), yz, zoom * tx, realColor); } } } } } yReel += 2; } Render(); } }
public void SauvePng(string fileName, Param param) { if (BitmapCpc.modeVirtuel == 6) { string singleName = Path.GetDirectoryName(fileName) + "\\" + Path.GetFileNameWithoutExtension(fileName); DirectBitmap bmpRaster = new DirectBitmap(BmpLock.Bitmap.Width >> 1, BmpLock.Bitmap.Height >> 1); //DirectBitmap bmp4Cols = new DirectBitmap(BmpLock.Bitmap.Width >> 1, BmpLock.Bitmap.Height >> 1); RvbColor c2 = new RvbColor(0); int posx = 0; for (int y = 0; y < bmpRaster.Height; y++) { bool memoC = false; for (int x = 0; x < bmpRaster.Width; x++) { RvbColor c = BmpLock.GetPixelColor(x << 1, y << 1); for (int i = 0; i < 16; i++) { RvbColor p = BitmapCpc.RgbCPC[colMode5[y, i]]; if (p.r == c.r && p.v == c.v && p.b == c.b) { if (i > 2) { //c = BitmapCpc.RgbCPC[colMode5[y, 3]]; c2 = p; int start = memoC ? x & 0xFF8 : 0; memoC = true; for (int r = start; r < x; r++) { bmpRaster.SetPixel(r, y, c2); } // posx = 0; } break; } } //bmp4Cols.SetPixel(x, y, c); bmpRaster.SetPixel(x, y, c2); posx++; } } bmpRaster.Bitmap.Save(singleName + "_Rasters" + ".png", System.Drawing.Imaging.ImageFormat.Png); bitmapCpc.CreeBmpCpcForceMode1(BmpLock); SauveImage.SauveScr(singleName + ".scr", bitmapCpc, this, param, false); } else { BmpLock.Bitmap.Save(fileName, System.Drawing.Imaging.ImageFormat.Png); } main.SetInfo("Sauvegarde image PNG ok."); }
public void Render(bool forceDrawZoom = false) { UpdatePalette(); modeCaptureSprites.Visible = BitmapCpc.modeVirtuel == 11; modeEdition.Visible = BitmapCpc.modeVirtuel != 11; if (chkDoRedo.Checked && modeEdition.Checked) { Enabled = false; List <MemoPoint> lst = undo.lstUndoRedo; foreach (MemoPoint p in lst) { int Tx = BitmapCpc.CalcTx(p.posy); BmpLock.SetHorLineDouble(p.posx, p.posy, Tx, p.newColor); } forceDrawZoom = true; bpUndo.Enabled = undo.CanUndo; bpRedo.Enabled = undo.CanRedo; Enabled = true; } if (zoom != 1) { if (tmpLock == null) { tmpLock = new DirectBitmap(imgOrigine.Width, imgOrigine.Height); } if (forceDrawZoom) { for (int y = 0; y < imgOrigine.Height; y += 2) { int ySrc = Math.Min(offsetY + (y / zoom), BitmapCpc.TailleY - 1); for (int x = 0; x < imgOrigine.Width; x += zoom) { tmpLock.SetHorLineDouble(x, y, Math.Min(zoom, imgOrigine.Width - x - 1), BmpLock.GetPixel(offsetX + (x / zoom), ySrc)); } } } pictureBox.Image = tmpLock.Bitmap; } else { pictureBox.Image = imgCopy != null ? imgCopy.Bitmap : BmpLock.Bitmap; tmpLock = null; } pictureBox.Refresh(); if (fenetreRendu != null) { fenetreRendu.Picture.Refresh(); } }
private byte[] MakeSprite() { byte[] ret = new byte[(BitmapCpc.TailleX * BitmapCpc.TailleY) >> 4]; Array.Clear(ret, 0, ret.Length); for (int y = 0; y < BitmapCpc.TailleY; y += 2) { 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; } } } if (pen > 15) { pen = 0; // Pb peut survenir si la palette n'est pas la même pour chaque image d'une animation... } octet |= (byte)(tabOctetMode[pen % 16] >> (p / tx)); } } ret[(x >> 3) + (y >> 1) * (BitmapCpc.TailleX >> 3)] = octet; } } return(ret); }
private void bpRedo_Click(object sender, System.EventArgs e) { Enabled = false; List <MemoPoint> lst = undo.Redo(); foreach (MemoPoint p in lst) { int tx = BitmapCpc.CalcTx(p.posy); BmpLock.SetHorLineDouble(p.posx, p.posy, tx, p.newColor); } if (imgCopy != null) { imgCopy.CopyBits(BmpLock); } Render(true); bpUndo.Enabled = undo.CanUndo; bpRedo.Enabled = undo.CanRedo; Enabled = true; }
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); }
public void SetPixelCpc(int xPos, int yPos, int col, int tx) { BmpLock.SetHorLineDouble(xPos, yPos, tx, GetPalCPC(BitmapCpc.modeVirtuel == 5 || BitmapCpc.modeVirtuel == 6 ? colMode5[yPos >> 1, col] : BitmapCpc.Palette[col])); }
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(); } }