public static Palette Read( string path, int count = 6 ) { try { using( BinaryReader br = new BinaryReader( new FileStream( path, FileMode.Open ) ) ) { Palette res = new Palette( new ushort[ count, 16 ] ); res.m_colors = new Color[ count, 16 ]; for( int i = 0; i < count; ++i ) for( int j = 0; j < 16; ++j ) { res.m_pal[ i, j ] = br.ReadUInt16( ); int b = ( res.m_pal[ i, j ] >> 10 ) & 31; int g = ( res.m_pal[ i, j ] >> 5 ) & 31; int r = ( res.m_pal[ i, j ] ) & 31; res.m_colors[ i, j ] = Color.FromArgb( 255 * r / 31, 255 * g / 31, 255 * b / 31 ); } return res; } } catch( Exception ) { return new Palette( new ushort[ count, 16 ] ); } }
public static Palette FromBlown( string path, int count = 6 ) { try { using( BinaryReader br = new BinaryReader( new FileStream( path, FileMode.Open ) ) ) { Palette res = new Palette( new ushort[ count, 16 ] ); res.m_colors = new Color[ count, 16 ]; for( int i = 0; i < count; ++i ) for( int j = 0; j < 16; ++j ) { byte r = br.ReadByte( ); byte g = br.ReadByte( ); byte b = br.ReadByte( ); br.ReadByte( ); res.m_colors[ i, j ] = Color.FromArgb( r, g, b ); res.m_pal[ i, j ] = (ushort)( ( ( b / 255 * 31 ) << 10 ) | ( ( g / 255 * 31 ) << 5 ) | ( r / 255 * 31 ) ); } return res; } } catch( Exception ) { return new Palette( new ushort[ count, 16 ] ); } }
private void Initialize() { this.Templates = ManifestReader.Initialize(); Dictionary<string, TileTemplate> lookup = new Dictionary<string, TileTemplate>(); foreach (TileTemplate[] templates in this.Templates.Values) { foreach (TileTemplate template in templates) { lookup[template.ID] = template; } } this.TileTemplateLookup = lookup; this.palette = new Palette(this.Templates.Keys.ToArray()); this.paletteHost.Children.Add(this.palette); this.GridToggle(); /* try { string keys = "^! '\"` ,-./" + "0123456789:;<=>?" + "*ABCDEFGHIJKLMNO" + "PQRSTUVWXYZ(&) "; int keyIndex = 0; BitmapImage bmp = ImageLoader.LoadImage("C:\\Users\\Blake\\Desktop\\font.png"); int[] pixels = ImageLoader.GetPixels(bmp); int index = 0; bool isWhite; List<string> letters = new List<string>(); for (int cy = 0; cy < bmp.PixelHeight; cy += 8) { for (int cx = 0; cx < bmp.PixelWidth; cx += 8) { List<string> output = new List<string>(); char key = keys[keyIndex++]; if (key != ' ') { output.Add("chars['" + key + "'] = ["); for (int x = 0; x < 8; ++x) { if (x > 0) output.Add(","); output.Add("["); for (int y = 0; y < 8; ++y) { if (y > 0) output.Add(","); index = (128 * (y + cy) + x + cx); isWhite = pixels[index] == -1; output.Add(isWhite ? "1" : "0"); } output.Add("]"); } output.Add("]"); if (key == 'L') { string foo = string.Join("", output); } letters.Add(string.Join("", output)); } } } string finalOutput = string.Join("\n", letters); System.IO.File.WriteAllText("C:\\users\\blake\\desktop\\fonts.txt", finalOutput); } catch (Exception) { } finally { }//*/ }
public Bitmap ToBitmap( TileSet[ ] tileSets, Palette[ ] palettes ) { if( tileSets[ 0 ] == null ) tileSets[ 0 ] = tileSets[ 1 ]; if( tileSets[ 1 ] == null ) tileSets[ 1 ] = tileSets[ 0 ]; if( tileSets[ 1 ] == null ) return null; if( palettes[ 0 ] == null ) palettes[ 0 ] = palettes[ 1 ]; if( palettes[ 1 ] == null ) palettes[ 1 ] = palettes[ 0 ]; if( palettes[ 1 ] == null ) return null; Bitmap res = new Bitmap( 16, 16 ); for( int x = 0; x < 2; ++x ) for( int y = 0; y < 2; ++y ) { ushort tileIdx = (ushort)( m_bottom[ y, x ] & 1023 ); bool vflip = ( ( m_bottom[ y, x ] >> 11 ) & 1 ) == 1; bool hflip = ( ( m_bottom[ y, x ] >> 10 ) & 1 ) == 1; byte palIdx = (byte)( ( m_bottom[ y, x ] >> 12 ) & 15 ); Tile btmTile = tileSets[ tileIdx / 512 ].m_blocks[ tileIdx % 512 ]; for( int i = 0; i < 8; i += 2 ) for( int j = 0; j < 8; ++j ) { int xi1 = hflip ? 7 - i : i; int xi2 = hflip ? xi1 - 1 : xi1 + 1; int yi = vflip ? 7 - j : j; byte curCol = btmTile.m_tile[ ( 8 * j + i ) / 2 ]; if( palIdx >= 12 ) continue; res.SetPixel( x * 8 + xi1, y * 8 + yi, palettes[ palIdx / 6 ][ palIdx % 6, curCol & 15 ] ); res.SetPixel( x * 8 + xi2, y * 8 + yi, palettes[ palIdx / 6 ][ palIdx % 6, curCol >> 4 ] ); } } for( int x = 0; x < 2; ++x ) for( int y = 0; y < 2; ++y ) { ushort tileIdx = (ushort)( m_top[ y, x ] & 1023 ); bool vflip = ( ( m_top[ y, x ] >> 11 ) & 1 ) == 1; bool hflip = ( ( m_top[ y, x ] >> 10 ) & 1 ) == 1; byte palIdx = (byte)( ( m_top[ y, x ] >> 12 ) & 15 ); Tile btmTile = tileSets[ tileIdx / 512 ].m_blocks[ tileIdx % 512 ]; for( int i = 0; i < 8; i += 2 ) for( int j = 0; j < 8; ++j ) { int xi1 = hflip ? 7 - i : i; int xi2 = hflip ? xi1 - 1 : xi1 + 1; int yi = vflip ? 7 - j : j; byte curCol = btmTile.m_tile[ ( 8 * j + i ) / 2 ]; if( palIdx >= 12 ) continue; if( ( curCol & 15 ) != 0 ) res.SetPixel( x * 8 + xi1, y * 8 + yi, palettes[ palIdx / 6 ][ palIdx % 6, curCol & 15 ] ); if( ( curCol >> 4 ) != 0 ) res.SetPixel( x * 8 + xi2, y * 8 + yi, palettes[ palIdx / 6 ][ palIdx % 6, curCol >> 4 ] ); } } return res; }