public Bitmap makeObject(int index, ObjRec[] objects, Bitmap[][] objStrips, MapViewType drawType, int constantSubpal = -1) { var obj = objects[index]; int scaleInt16 = 16; var images = new Image[obj.getSize()]; for (int i = 0; i < obj.getSize(); i++) { int x = i % obj.w; int y = i / obj.w; int pali = (y >> 1) * (obj.w >> 1) + (x >> 1); var objStrip = constantSubpal == -1 ? objStrips[obj.getSubpallete(pali)] : objStrips[constantSubpal]; images[i] = objStrip[obj.indexes[i]]; } var mblock = UtilsGDI.GlueImages(images, obj.w, obj.h); using (Graphics g2 = Graphics.FromImage(mblock)) { if (drawType == MapViewType.ObjType) { g2.FillRectangle(new SolidBrush(CadObjectTypeColors[obj.getType()]), new Rectangle(0, 0, scaleInt16, scaleInt16)); g2.DrawString(String.Format("{0:X}", obj.getType()), new Font("Arial", 6), Brushes.White, new Point(0, 0)); } else if (drawType == MapViewType.ObjNumbers) { g2.FillRectangle(new SolidBrush(Color.FromArgb(192, 255, 255, 255)), new Rectangle(0, 0, scaleInt16, scaleInt16)); g2.DrawString(String.Format("{0:X}", index), new Font("Arial", 6), Brushes.Red, new Point(0, 0)); } } return(mblock); }
public Image[] makeBigBlocks(byte[] mapping, byte[] tiles, byte[] palette, int count, MapViewType curViewType = MapViewType.Tiles) { var result = new Image[count]; ushort[] m = Mapper.loadMapping(mapping); Color[] cpal = getPalette(palette); for (ushort i = 0; i < count; i++) { if (!ConfigScript.isBlockSize4x4()) { var b = getBlock(m, tiles, cpal, i); result[i] = UtilsGDI.ResizeBitmap(b, 32, 32); } else { var b = getBlock4X4(m, tiles, cpal, i); result[i] = UtilsGDI.ResizeBitmap(b, 32, 32); } if (curViewType == MapViewType.ObjNumbers) { result[i] = VideoHelper.addObjNumber(result[i], i); } } return(result); }
public void Execute(FormScript formScript) { formScript.writeLog(); formScript.writeLog("Script for find unused blocks at all screens"); var formMain = formScript.getFormMain(); //int scrNo = formMain.ScreenNo; //formScript.writeLog(String.Format("Current active screen: 0x{0:X}", scrNo)); int totalBlocksCount = formMain.bigBlocks.Length; formScript.writeLog(String.Format("Total big blocks count: {0}", totalBlocksCount)); int[] usedBlocks = new int[totalBlocksCount]; var screens = formMain.screens; //count all used blocks for (int scrNo = 0; scrNo < screens.Length; scrNo++) { var activeScreen = screens[scrNo]; for (int layerNo = 0; layerNo < activeScreen.layers.Length; layerNo++) { var data = activeScreen.layers[layerNo].data; for (int i = 0; i < data.Length; i++) { int blockNo = data[i]; usedBlocks[blockNo]++; } } } //print info about unused blocks var unusedBlocks = usedBlocks.Select((c, index) => new { Count = c, Index = index }).Where(c => c.Count == 0).Select(c => c.Index).ToArray(); formScript.writeLog("Unused blocks:", newLine: false); for (int i = 0; i < unusedBlocks.Length; i++) { formScript.writeLog(String.Format(" 0x{0:X}", unusedBlocks[i]), newLine: false); } int unusedBlocksCount = unusedBlocks.Length; if (unusedBlocksCount == 0) { formScript.writeLog(" not found", newLine: false); } formScript.writeLog(); formScript.writeLog(String.Format("Total unused blocks: {0}", unusedBlocksCount)); if (unusedBlocksCount > 0) { var unusedPictures = formMain.bigBlocks.Where((im, index) => unusedBlocks.Contains(index)).ToArray(); var glueImage = UtilsGDI.GlueImages(unusedPictures, unusedPictures.Length, 1); var fname = ConfigScript.ConfigDirectory + String.Format("unusedBlocks.png"); glueImage.Save(fname); formScript.writeLog(String.Format("Unused blocks image saved to file: {0}", fname)); } }
public Image[] makeBigBlocks(int videoNo, int bigBlockNo, BigBlock[] bigBlockIndexes, int palleteNo, MapViewType smallObjectsViewType = MapViewType.Tiles, MapViewType curViewType = MapViewType.Tiles, int hierarchyLevel = 0) { int blockCount = ConfigScript.getBigBlocksCount(hierarchyLevel); var bigBlocks = new Image[blockCount]; Image[] smallBlocksPack; if (hierarchyLevel == 0) { smallBlocksPack = makeObjects(videoNo, bigBlockNo, palleteNo, smallObjectsViewType); } else { var bigBlockIndexesPrev = ConfigScript.getBigBlocksRecursive(hierarchyLevel - 1, bigBlockNo); smallBlocksPack = makeBigBlocks(videoNo, bigBlockNo, bigBlockIndexesPrev, palleteNo, smallObjectsViewType, curViewType, hierarchyLevel - 1); } //tt version hardcode Image[][] smallBlocksAll = null; bool smallBlockHasSubpals = bigBlockIndexes == null ? true : bigBlockIndexes[0].smallBlocksWithPal(); if (!smallBlockHasSubpals) { smallBlocksAll = new Image[4][]; for (int i = 0; i < 4; i++) { smallBlocksAll[i] = makeObjects(videoNo, bigBlockNo, palleteNo, smallObjectsViewType, i); } } else { smallBlocksAll = new Image[4][] { smallBlocksPack, smallBlocksPack, smallBlocksPack, smallBlocksPack }; } for (int btileId = 0; btileId < blockCount; btileId++) { Image b; if (ConfigScript.isBuildScreenFromSmallBlocks()) { var sb = smallBlocksPack[btileId]; //scale for small blocks b = UtilsGDI.ResizeBitmap(sb, (int)(sb.Width * 2), (int)(sb.Height * 2)); } else { b = bigBlockIndexes[btileId].makeBigBlock(smallBlocksAll); } if (curViewType == MapViewType.ObjNumbers) { b = VideoHelper.addObjNumber(b, btileId); } bigBlocks[btileId] = b; } return(bigBlocks); }
public Bitmap getTilesRectangle(byte[] ppuData, Color[] palette) { var tiles = new Image[256]; for (int i = 0; i < tiles.Length; i++) { tiles[i] = getTile(ppuData, palette, i); } return(UtilsGDI.GlueImages(tiles, 16, 16)); }
public Image prepareImage(string imName) { //add scale? var bigBlocksImages = formMain.bigBlocks; int blockWidth = bigBlocksImages[0].Width; int blockHeight = bigBlocksImages[0].Height; int imWidthInBlocks = 16; int imHeightInBlocks = (int)(Math.Ceiling(bigBlocksImages.Length * 1.0 / imWidthInBlocks)); var bigBlockImage = UtilsGDI.GlueImages(bigBlocksImages, imWidthInBlocks, imHeightInBlocks); bigBlockImage.Save(imName); return(bigBlockImage); }
private void btExportPng_Click(object sender, EventArgs e) { if (sfExportDialog.ShowDialog() == DialogResult.OK) { var fname = sfExportDialog.FileName; var img = renderFrame(activeFrame, false); if (!showBack) { img = UtilsGDI.CropImage(img, UtilsGDI.FindBorderRect(img)); } img.Save(fname); } }
public Image[] makeBigBlocks(byte[] ppuData, byte[] tileData, byte[] pallette, int count, MapViewType curViewType = MapViewType.Tiles) { var result = new Image[count]; Color[] pal = getPalette(pallette); var tiles = new Image[256]; for (int i = 0; i < tiles.Length; i++) { tiles[i] = getTile(ppuData, pal, i); } /*var im = getTilesRectangle(ppuData, pal); * im.Save("chr.png");*/ for (int i = 0; i < count; i++) { //linear 2x2 tiles only for now int startIndex = i * 4; var tileImages = new[] { tiles[tileData[startIndex]], tiles[tileData[startIndex + 1]], tiles[tileData[startIndex + 2]], tiles[tileData[startIndex + 3]], }; var block = UtilsGDI.GlueImages(tileImages, 2, 2); result[i] = block; if (curViewType == MapViewType.ObjNumbers) { result[i] = VideoHelper.addObjNumber(result[i], i); } } return(result); }
public Bitmap makeObjectsStrip(int videoPageId, int tilesId, int palId, MapViewType drawType, int constantSubpal = -1) { var bitmaps = makeObjects(videoPageId, tilesId, palId, drawType, constantSubpal); return(UtilsGDI.GlueImages(bitmaps, bitmaps.Length, 1)); }
public Bitmap makeImageRectangle(byte[] videoChunk, byte[] pallete, int subPalIndex, bool withAlpha = false) { var images = Enumerable.Range(0, 256).Select(i => makeImage(i, videoChunk, pallete, subPalIndex, withAlpha)); return(UtilsGDI.GlueImages(images.ToArray(), 16, 16)); }