public override bool HandleExport(ExportSpriteInfo Info, TextBox EditOutput, DocumentInfo DocInfo) { System.Windows.Forms.SaveFileDialog saveDlg = new System.Windows.Forms.SaveFileDialog(); saveDlg.Title = "Export Sprites to Image"; saveDlg.Filter = Core.MainForm.FilterString(RetroDevStudio.Types.Constants.FILEFILTER_IMAGE_FILES); if (saveDlg.ShowDialog() != System.Windows.Forms.DialogResult.OK) { return(false); } GR.Image.MemoryImage targetImg = new GR.Image.MemoryImage(Info.Project.Sprites[0].Tile.Width * 4, ((Info.Project.TotalNumberOfSprites + 3) / 4) * Info.Project.Sprites[0].Tile.Height, Info.Project.Sprites[0].Tile.Image.PixelFormat); PaletteManager.ApplyPalette(targetImg); List <int> exportIndices = Info.ExportIndices; foreach (int i in exportIndices) { Info.Project.Sprites[i].Tile.Image.DrawTo(targetImg, (i % 4) * Info.Project.Sprites[i].Tile.Width, (i / 4) * Info.Project.Sprites[i].Tile.Height); } System.Drawing.Bitmap bmpTarget = targetImg.GetAsBitmap(); bmpTarget.Save(saveDlg.FileName, System.Drawing.Imaging.ImageFormat.Png); return(true); }
private void RenderFullImage(Tiny64.Machine machine, GR.Image.MemoryImage img) { // render image bool vicActive = ((machine.Memory.VIC.ReadByte(0x11) & 0x10) != 0); if (vicActive) { int vicBank = (machine.Memory.CIA2.ReadByte(0) & 0x03) ^ 0x03; int screenPos = ((machine.Memory.VIC.ReadByte(0x18) & 0xf0) >> 4) * 1024 + vicBank * 16384; int localCharDataPos = (machine.Memory.VIC.ReadByte(0x18) & 0x0e) * 1024; int charDataPos = localCharDataPos + vicBank * 16384; byte bgColor = (byte)(machine.Memory.VIC.ReadByte(0x21) & 0x0f); GR.Memory.ByteBuffer charData = null; if (((vicBank == 0) || (vicBank == 2)) && (localCharDataPos == 0x1000)) { // use default upper case chars charData = new GR.Memory.ByteBuffer(); charData.Append(Machine.Memory.CharacterROM, 0, 2048); } else if (((vicBank == 0) || (vicBank == 2)) && (localCharDataPos == 0x2000)) { // use default lower case chars charData = new GR.Memory.ByteBuffer(); charData.Append(Machine.Memory.CharacterROM, 2048, 2048); } else { // use RAM charData = new GR.Memory.ByteBuffer(machine.Memory.RAM); charData = charData.SubBuffer(charDataPos, 2048); } for (int y = 0; y < 25; ++y) { for (int x = 0; x < 40; ++x) { byte charIndex = machine.Memory.RAM[screenPos + x + y * 40]; byte charColor = machine.Memory.ColorRAM[x + y * 40]; //CharacterDisplayer.DisplayHiResChar( charData.SubBuffer( charIndex * 8, 8 ), bgColor, charColor, img, x * 8, y * 8 ); } } /* * DataObject dataObj = new DataObject(); * * GR.Memory.ByteBuffer dibData = img.CreateHDIBAsBuffer(); * * System.IO.MemoryStream ms = dibData.MemoryStream(); * * // WTF - SetData requires streams, NOT global data (HGLOBAL) * dataObj.SetData( "DeviceIndependentBitmap", ms ); * Clipboard.SetDataObject( dataObj, true );*/ } }
public UndoGraphicScreenSizeChange(GraphicScreenProject Project, GraphicScreenEditor Editor, int Width, int Height) { this.Width = Width; this.Height = Height; this.Editor = Editor; this.Project = Project; ChangedSection = Project.Image.GetImage(0, 0, Width, Height) as GR.Image.MemoryImage; }
public GraphicTile(int Width, int Height, GraphicTileMode Mode, ColorSettings Color) { this.Width = Width; this.Height = Height; this.Mode = Mode; Colors = Color; Data = new ByteBuffer((uint)Lookup.NumBytes(Width, Height, Mode)); Image = new GR.Image.MemoryImage(Width, Height, GR.Drawing.PixelFormat.Format32bppRgb); }
public int Add(object Object, GR.Image.MemoryImage Image) { ImageListItem item = new ImageListItem(Container); item.Value = Object; item.MemoryImage = Image; base.Add(item); Container.ItemsModified(); return(base.Count - 1); }
public static void ApplyPalette(GR.Image.MemoryImage Image) { for (int i = 0; i < 17; ++i) { Image.SetPaletteColor(i, (byte)((Types.ConstantData.Palette.ColorValues[i] & 0x00ff0000) >> 16), (byte)((Types.ConstantData.Palette.ColorValues[i] & 0x0000ff00) >> 8), (byte)(Types.ConstantData.Palette.ColorValues[i] & 0xff)); } }
public GraphicTile(GraphicTile OtherTile) { Width = OtherTile.Width; Height = OtherTile.Height; Mode = OtherTile.Mode; Colors = OtherTile.Colors; CustomColor = OtherTile.CustomColor; TransparentColorIndex = OtherTile.TransparentColorIndex; Data = new ByteBuffer(OtherTile.Data); Image = new GR.Image.MemoryImage(OtherTile.Image); }
public UndoGraphicScreenImageChange(GraphicScreenProject Project, GraphicScreenEditor Editor, int X, int Y, int Width, int Height) { this.X = X; this.Y = Y; this.Width = Width; this.Height = Height; this.Editor = Editor; this.Project = Project; ChangedSection = Project.Image.GetImage(X, Y, Width, Height); }
private void OpenImage(GR.Image.FastImage newImage) { if (newImage == null) { return; } m_OriginalImage = new GR.Image.MemoryImage(newImage.Width, newImage.Height, newImage.PixelFormat); m_ImportImage = new GR.Image.MemoryImage(newImage.Width, newImage.Height, System.Drawing.Imaging.PixelFormat.Format8bppIndexed); for (int j = 0; j < 17; ++j) { m_ImportImage.SetPaletteColor(j, (byte)((Types.ConstantData.Palette.ColorValues[j] & 0x00ff0000) >> 16), (byte)((Types.ConstantData.Palette.ColorValues[j] & 0x0000ff00) >> 8), (byte)(Types.ConstantData.Palette.ColorValues[j] & 0xff)); } for (int i = 0; i < newImage.PaletteEntryCount; ++i) { m_OriginalImage.SetPaletteColor(i, newImage.PaletteRed(i), newImage.PaletteGreen(i), newImage.PaletteBlue(i)); } newImage.DrawTo(m_OriginalImage, 0, 0); newImage.Dispose(); if (m_OriginalImage.PixelFormat != picOriginal.DisplayPage.PixelFormat) { picOriginal.DisplayPage.Create(picOriginal.ClientSize.Width, picOriginal.ClientSize.Height, m_OriginalImage.PixelFormat); for (int i = 0; i < newImage.PaletteEntryCount; ++i) { picOriginal.DisplayPage.SetPaletteColor(i, newImage.PaletteRed(i), newImage.PaletteGreen(i), newImage.PaletteBlue(i)); } } picOriginal.DisplayPage.Box(0, 0, picOriginal.DisplayPage.Width, picOriginal.DisplayPage.Height, 0); // determine optimal zoom size m_Zoom = 1024; while ((m_OriginalImage.Width * 1024 / m_Zoom < 64) && (m_OriginalImage.Height * 1024 / m_Zoom < 64)) { m_Zoom /= 2; } picOriginal.SetImageSize(picOriginal.ClientSize.Width * m_Zoom / 1024, picOriginal.ClientSize.Height * m_Zoom / 1024); picPreview.SetImageSize(picPreview.ClientSize.Width * m_Zoom / 1024, picPreview.ClientSize.Height * m_Zoom / 1024); picOriginal.DisplayPage.DrawFromMemoryImage(m_OriginalImage, 0, 0); m_OrigSize.Width = m_OriginalImage.Width; m_OrigSize.Height = m_OriginalImage.Height; RecalcImport(); }
public GameObject(GameObject OtherObject) { TemplateIndex = OtherObject.TemplateIndex; X = OtherObject.X; Y = OtherObject.Y; Color = OtherObject.Color; Speed = OtherObject.Speed; MoveBorderLeft = OtherObject.MoveBorderLeft; MoveBorderRight = OtherObject.MoveBorderRight; MoveBorderBottom = OtherObject.MoveBorderBottom; MoveBorderTop = OtherObject.MoveBorderTop; OptionalValue = OtherObject.OptionalValue; Optional = OtherObject.Optional; SpriteImage = new GR.Image.MemoryImage(OtherObject.SpriteImage); }
public override bool HandleExport(ExportCharsetScreenInfo Info, TextBox EditOutput, DocumentInfo DocInfo) { int neededWidth = Info.Charscreen.ScreenWidth * 8; int neededHeight = Info.Charscreen.ScreenHeight * 8; GR.Image.MemoryImage targetImg = new GR.Image.MemoryImage(neededWidth, neededHeight, GR.Drawing.PixelFormat.Format32bppRgb); Info.Image.DrawTo(targetImg, 0, 0); System.Drawing.Bitmap bmpTarget = targetImg.GetAsBitmap(); Clipboard.SetImage(bmpTarget); bmpTarget.Dispose(); return(true); }
public override bool HandleExport(ExportCharsetInfo Info, TextBox EditOutput, DocumentInfo DocInfo) { GR.Image.MemoryImage targetImg = new GR.Image.MemoryImage(128, 128, Info.Charset.Characters[0].Tile.Image.PixelFormat); PaletteManager.ApplyPalette(targetImg); List <int> exportIndices = Info.ExportIndices; foreach (int i in exportIndices) { Info.Charset.Characters[i].Tile.Image.DrawTo(targetImg, (i % 16) * 8, (i / 16) * 8); } System.Drawing.Bitmap bmpTarget = targetImg.GetAsBitmap(); Clipboard.SetImage(bmpTarget); bmpTarget.Dispose(); return(true); }
public override bool HandleExport(ExportSpriteInfo Info, TextBox EditOutput, DocumentInfo DocInfo) { GR.Image.MemoryImage targetImg = new GR.Image.MemoryImage(Info.Project.Sprites[0].Tile.Width * 4, ((Info.Project.TotalNumberOfSprites + 3) / 4) * Info.Project.Sprites[0].Tile.Height, Info.Project.Sprites[0].Tile.Image.PixelFormat); PaletteManager.ApplyPalette(targetImg); List <int> exportIndices = Info.ExportIndices; foreach (int i in exportIndices) { Info.Project.Sprites[i].Tile.Image.DrawTo(targetImg, (i % 4) * Info.Project.Sprites[i].Tile.Width, (i / 4) * Info.Project.Sprites[i].Tile.Height); } var bmpTarget = targetImg.GetAsBitmap(); Clipboard.SetImage(bmpTarget); bmpTarget.Dispose(); return(true); }
public override bool HandleExport(ExportCharsetScreenInfo Info, TextBox EditOutput, DocumentInfo DocInfo) { System.Windows.Forms.SaveFileDialog saveDlg = new System.Windows.Forms.SaveFileDialog(); saveDlg.Title = "Export Screen to Image"; saveDlg.Filter = "PNG File|*.png"; if (saveDlg.ShowDialog() != DialogResult.OK) { return(false); } int neededWidth = Info.Charscreen.ScreenWidth * 8; int neededHeight = Info.Charscreen.ScreenHeight * 8; GR.Image.MemoryImage targetImg = new GR.Image.MemoryImage(neededWidth, neededHeight, GR.Drawing.PixelFormat.Format32bppRgb); Info.Image.DrawTo(targetImg, 0, 0); System.Drawing.Bitmap bmpTarget = targetImg.GetAsBitmap(); bmpTarget.Save(saveDlg.FileName, System.Drawing.Imaging.ImageFormat.Png); return(true); }
private void btnExportCharsetToImage_Click(object sender, EventArgs e) { System.Windows.Forms.SaveFileDialog saveDlg = new System.Windows.Forms.SaveFileDialog(); saveDlg.Title = "Export Characters to Image"; saveDlg.Filter = Core.MainForm.FilterString(C64Studio.Types.Constants.FILEFILTER_IMAGE_FILES); if (saveDlg.ShowDialog() != System.Windows.Forms.DialogResult.OK) { return; } GR.Image.MemoryImage targetImg = new GR.Image.MemoryImage(128, 128, m_Charset.Characters[0].Image.PixelFormat); CustomRenderer.PaletteManager.ApplyPalette(targetImg); List <int> exportIndices = ListOfExportIndices(); foreach (int i in exportIndices) { m_Charset.Characters[i].Image.DrawTo(targetImg, (i % 16) * 8, (i / 16) * 8); } System.Drawing.Bitmap bmpTarget = targetImg.GetAsBitmap(); bmpTarget.Save(saveDlg.FileName, System.Drawing.Imaging.ImageFormat.Png); }
GR.Image.MemoryImage Assignment(CubeInfo cube_info, GR.Image.IImage pCD) { var format = GR.Drawing.PixelFormat.Format8bppIndexed; if (m_Colors <= 2) { format = GR.Drawing.PixelFormat.Format1bppIndexed; } /* * else if ( m_Colors <= 4 ) * { * format = System.Drawing.Imaging.PixelFormat.Format2bppIndexed; * }*/ else if (m_Colors <= 16) { format = GR.Drawing.PixelFormat.Format4bppIndexed; } var pImage = new GR.Image.MemoryImage(pCD.Width, pCD.Height, format); var pal = new RetroDevStudio.Palette(m_Colors); byte index; int count, i; NodeInfo node_info; uint dither, id; // Allocate image colormap. cube_info.colormap = new PixelPacket[256]; cube_info.colors = 0; DefineColormap(cube_info, cube_info.root); // Create a reduced color image. dither = cube_info.quantize_info.dither; for (int y = 0; y < pCD.Height; y++) { //indexes=GetIndexes(image); for (int x = 0; x < pCD.Width; x += count) { // Identify the deepest node containing the pixel's color. count = 1; uint pixel = pCD.GetPixel(x, y); int r = (byte)((pixel & 0xff0000) >> 16), g = (byte)((pixel & 0xff00) >> 8), b = (byte)(pixel & 0xff); node_info = cube_info.root; for (index = MaxTreeDepth - 1; (int)index > 0; index--) { id = (uint)(((Downscale(r) >> index) & 0x01) << 2 | ((Downscale(g) >> index) & 0x01) << 1 | ((Downscale(b) >> index) & 0x01)); if ((node_info.census & (1 << (byte)id)) == 0) { break; } node_info = node_info.child[id]; } // Find closest color among siblings and their children. cube_info.color.red = (byte)r; cube_info.color.green = (byte)g; cube_info.color.blue = (byte)b; cube_info.distance = 3.0 * (MaxRGB() + 1) * (MaxRGB() + 1); ClosestColor(cube_info, node_info.parent); index = (byte)cube_info.color_number; for (i = 0; i < count; i++) { if (cube_info.quantize_info.measure_error == 0) { pImage.SetPixel(x, y, index); } } } } for (i = 0; i < cube_info.colors; i++) { pal.ColorValues[i] = (uint)(0xff000000 | (uint)(cube_info.colormap[i].red << 16) | (uint)(cube_info.colormap[i].green << 8) | (uint)cube_info.colormap[i].blue); pImage.SetPaletteColor(i, cube_info.colormap[i].red, cube_info.colormap[i].green, cube_info.colormap[i].blue); } return(pImage); }
public CharData() { Image = new GR.Image.MemoryImage(8, 8, System.Drawing.Imaging.PixelFormat.Format8bppIndexed); AllColorImage = new GR.Image.MemoryImage(8 * 16, 8, System.Drawing.Imaging.PixelFormat.Format8bppIndexed); }
public SpriteData() { Image = new GR.Image.MemoryImage(24, 21, System.Drawing.Imaging.PixelFormat.Format8bppIndexed); }
public static GR.Image.MemoryImage BitmapFromKoala(GR.Memory.ByteBuffer koala) { byte fullValue; byte value; byte currentColor; int xCooBase = 0; int yCooBase = 0; GR.Image.MemoryImage Image = new GR.Image.MemoryImage(320, 200, System.Drawing.Imaging.PixelFormat.Format8bppIndexed); // Set the palette to the C64 one C64Studio.CustomRenderer.PaletteManager.ApplyPalette(Image); if (koala.Length >= 10002) { // Last Byte is Background Color and global Byte backgroundColor = koala.ByteAt(10002); for (int y = 0; y < 1000; y++) { // koala has 3 colors which can be selected for ech "cell" (8x8 pixel) byte lowerNibbleColor = (byte)(((((koala.ByteAt(y + 8002)) << 4) & 0xFF) >> 4)); byte upperNibbleColor = (byte)(koala.ByteAt(y + 8002) >> 4); byte colorRamColor = koala.ByteAt(y + 9002); for (int x = 0; x < 8; x++) { fullValue = koala.ByteAt((8 * y) + x + 2); for (int z = 0; z < 4; z++) { value = (byte)(((fullValue << (z * 2)) & 0xFF) >> 6); switch (value) { case 0: currentColor = backgroundColor; break; case 1: currentColor = upperNibbleColor; break; case 2: currentColor = lowerNibbleColor; break; default: currentColor = colorRamColor; break; } Image.SetPixel(((xCooBase * 4) * 2 + (z * 2)), yCooBase * 8 + x, currentColor); // koala is doublepixel, so we repeat it for the right neighbour Image.SetPixel(((xCooBase * 4) * 2 + (z * 2) + 1), yCooBase * 8 + x, currentColor); } } xCooBase++; if (xCooBase == 40) { xCooBase = 0; yCooBase++; } } } return(Image); }
public bool CopyToClipboard() { if (Entries.Count == 0) { return(false); } GR.Memory.ByteBuffer dataSelection = new GR.Memory.ByteBuffer(); dataSelection.AppendI32(Entries.Count); dataSelection.AppendI32(ColumnBased ? 1 : 0); dataSelection.AppendI32(Colors.BackgroundColor); dataSelection.AppendI32(Colors.MultiColor1); dataSelection.AppendI32(Colors.MultiColor2); dataSelection.AppendI32(Colors.BGColor4); dataSelection.AppendI32(Colors.Palettes.Count); for (int j = 0; j < Colors.Palettes.Count; ++j) { var pal = Colors.Palettes[j]; dataSelection.AppendI32(pal.NumColors); for (int i = 0; i < pal.NumColors; ++i) { dataSelection.AppendU32(pal.ColorValues[i]); } } int prevIndex = Entries[0].Index; foreach (var entry in Entries) { // delta in indices dataSelection.AppendI32(entry.Index - prevIndex); prevIndex = entry.Index; dataSelection.AppendI32((int)entry.Tile.Mode); dataSelection.AppendI32(entry.Tile.CustomColor); dataSelection.AppendI32(entry.Tile.Colors.ActivePalette); dataSelection.AppendI32(entry.Tile.Width); dataSelection.AppendI32(entry.Tile.Height); dataSelection.AppendU32(entry.Tile.Data.Length); dataSelection.Append(entry.Tile.Data); dataSelection.AppendI32(entry.Index); } DataObject dataObj = new DataObject(); dataObj.SetData("C64Studio.ImageList", false, dataSelection.MemoryStream()); // add as one image var fullImage = new GR.Image.MemoryImage(Entries.Count * Entries[0].Tile.Width, Entries[0].Tile.Height, System.Drawing.Imaging.PixelFormat.Format32bppRgb); int curX = 0; foreach (var entry in Entries) { entry.Tile.Image.DrawTo(fullImage, curX, 0); curX += entry.Tile.Width; } GR.Memory.ByteBuffer dibData2 = fullImage.CreateHDIBAsBuffer(); System.IO.MemoryStream ms2 = dibData2.MemoryStream(); dataObj.SetData("DeviceIndependentBitmap", ms2); Clipboard.SetDataObject(dataObj, true); return(true); }