<commit_before>﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Imaging;
using System.Globalization;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;

namespace PixelPet.Commands {
	internal class SerializeTilesetIndexed : CliCommand {
		public SerializeTilesetIndexed()
			: base("Serialize-Tileset-Indexed") { }

		public override void Run(Workbench workbench, Cli cli) {
			cli.Log("Serializing tileset...");

			if (workbench.Palette.Count == 0) {
				cli.Log("WARNING: No palette loaded.");
			}

			int palSize = 16;
			int bpp = 4;        // bits per pixel

			int ppb = 8 / bpp;  // pixels per byte
			int pi = 0;         // pixel index in current byte
			int b = 0;          // current byte

			workbench.Stream.SetLength(0);

			bool foundUnmatchedColor = false;

			int t = 0;
			int lastPal = 0;
			foreach (Tile tile in workbench.Tileset.Tiles) {
				if (!tile.IsIndexed) {
					int palIndex = tile.IndexTileAny(workbench.Palette, palSize, lastPal);
					if (palIndex != -1) {
						lastPal = palIndex;
					} else {
						// Couldn't index this tile with any of the palettes.
						// Index it separately.
						lastPal = 0;
						tile.IndexTile();

						if (!foundUnmatchedColor) {
							cli.Log("WARNING: Could not match tile " + t + " to a palette.");
							foundUnmatchedColor = true;
						}
					}
				}<commit_msg>SerializeTilesetIndexed: Change palette size and bits per pixel to parameters.<commit_after>﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Imaging;
using System.Globalization;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;

namespace PixelPet.Commands {
	internal class SerializeTilesetIndexed : CliCommand {
		public SerializeTilesetIndexed()
			: base("Serialize-Tileset-Indexed", new Parameter[] {
				new Parameter("palette-size",   "ps",  false, new ParameterValue("count", "16")),
				new Parameter("bits-per-pixel", "bpp", false, new ParameterValue("count", "4")),
			}) { }

		public override void Run(Workbench workbench, Cli cli) {
			cli.Log("Serializing tileset...");

			if (workbench.Palette.Count == 0) {
				cli.Log("WARNING: No palette loaded.");
			}

			int palSize = FindNamedParameter("--palette-size").Values[0].ToInt32();
			int bpp     = FindNamedParameter("--bits-per-pixel").Values[0].ToInt32();

			int ppb = 8 / bpp;  // pixels per byte
			int pi = 0;         // pixel index in current byte
			int b = 0;          // current byte

			workbench.Stream.SetLength(0);

			bool foundUnmatchedColor = false;

			int t = 0;
			int lastPal = 0;
			foreach (Tile tile in workbench.Tileset.Tiles) {
				if (!tile.IsIndexed) {
					int palIndex = tile.IndexTileAny(workbench.Palette, palSize, lastPal);
					if (palIndex != -1) {
						lastPal = palIndex;
					} else {
						// Couldn't index this tile with any of the palettes.
						// Index it separately.
						lastPal = 0;
						tile.IndexTile();

						if (!foundUnmatchedColor) {
							cli.Log("WARNING: Could not match tile " + t + " to a palette.");
							foundUnmatchedColor = true;
						}
					}
				}
{'fraction_non_alphanumeric': 0.12160454832596336, 'fraction_numerical': 0.009475679090334808, 'mean_word_length': 2.8811274509803924, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4255908', 'n_tokens_mistral': 1237, 'n_tokens_neox': 983, 'n_words': 274}