public static IIDConvertor GetConvertor( MapInfo info ) { IIDConvertor convertor = null; if ( info.IDConvertor == null ) { Console.WriteLine( "Error: The source contains an invalid idconvertor reference." ); return null; } else { try { convertor = (IIDConvertor)info.IDConvertor.GetConstructor( Type.EmptyTypes ).Invoke( null ); } catch { Console.WriteLine( "Warning: The source contains an valid idconvertor reference, but it could not be instantiated." ); return null; } Console.WriteLine( "Using convertor \"{0}\".", convertor.ToString() ); } return convertor; }
public static void WriteTestPNGs( int[] colorbuffer, int[] idbuffer, int[] borderbuffer, PngLevel pngLevel, MapInfo info ) { Console.Write( "Writing buffer check PNGs..."); if ((pngLevel & PngLevel.Shading)>0) { Console.Write("Colorbuffer... "); Visualiser.CreateImage32(colorbuffer, info.Size).Save("test-Shading.png", ImageFormat.Png); } if ((pngLevel & PngLevel.IDs)>0) { Console.Write("IDbuffer... "); Visualiser.CreateImage32(idbuffer, info.Size).Save("test-IDs.png", ImageFormat.Png); } if ((pngLevel & PngLevel.Borders)>0) { Console.Write("Borderbuffer... "); Visualiser.CreateImage32(borderbuffer, info.Size).Save("test-Borders.png", ImageFormat.Png); } Console.WriteLine( "Done!" ); }
private static void DoExport( Lightmap map, Rectangle region, PngLevel pngLevel, IDMap idmap, string sourcefile, string target ) { Console.WriteLine( "Decoding image..." ); RawImage rawimg = map.DecodeImage( region ); int[] shadebuffer, idbuffer, borderbuffer; new IOShader( Boot.DefaultConvertor ).MultiShade32( rawimg, out shadebuffer, out idbuffer, out borderbuffer ); // We don't use the lightmap version as a source: this can lead to errors. // Use the idmap as source. For lightmap2 and lightmap3, this needs to be scaled down. // -- NOTE: if this is changed, don't forget to turn on the id converting in the IOShader.Multishade above! ushort[] tmpbuffer = null; if ( map.Zoom == 0 ) { tmpbuffer = idmap.ExportBitmapBuffer( rawimg.Bounds ); } else { Console.WriteLine( "Scaling idmap..." ); tmpbuffer = MapToolsLib.Utils.ScaleIDBuffer( idmap.ExportBitmapGrid( map.CoordMap.ZoomedToActual( rawimg.Bounds ) ), map.Zoom ); } // Convert it to the map format for ( int i=0; i<idbuffer.Length; ++i ) { if ( tmpbuffer[i] >= Province.Count ) tmpbuffer[i] = Province.TerraIncognitaID; idbuffer[i] = Boot.DefaultConvertor.ConvertID( tmpbuffer[i] ); } if ( pngLevel != PngLevel.None ) { string basetarget = Path.ChangeExtension( Path.GetFileNameWithoutExtension( target ) + "-###", Path.GetExtension( target ) ); if ((pngLevel & PngLevel.Shading) > 0) { target = basetarget.Replace("###", Boot.ShadingLayerName); Console.WriteLine("Exporting to \"{0}\"...", Path.GetFileName(target)); Visualiser.CreateImage32(shadebuffer, rawimg.Size).Save(target, ImageFormat.Png); } if ((pngLevel & PngLevel.IDs) > 0) { target = basetarget.Replace("###", Boot.IDLayerName); Console.WriteLine("Exporting to \"{0}\"...", Path.GetFileName(target)); Visualiser.CreateImage32(idbuffer, rawimg.Size).Save(target, ImageFormat.Png); } if ((pngLevel & PngLevel.Borders) > 0) { target = basetarget.Replace("###", Boot.BorderLayerName); Console.WriteLine("Exporting to \"{0}\"...", Path.GetFileName(target)); Visualiser.CreateImage32(borderbuffer, rawimg.Size).Save(target, ImageFormat.Png); } } else { Console.WriteLine( "Exporting to \"{0}\"...", Path.GetFileName( target ) ); PSD.File psd = new PSD.File( rawimg.Size ); Bitmap img = new MapInfo( map.Zoom, rawimg.Location, rawimg.Size, sourcefile, Path.GetFileName( target ), Boot.DefaultConvertor ).AsBitmap(); PSD.Layer l = psd.Layers.Add( new PSD.Layer( Boot.MapInfoLayerName, 0, 0, img ) ); l.Opacity = 255; l.Visible = false; l.ProtectTransparancy = true; img = Visualiser.CreateImage32( shadebuffer, rawimg.Size ); l = psd.Layers.Add( new PSD.Layer( Boot.ShadingLayerName, 0, 0, img ) ); l.Opacity = 254; l.Visible = true; l.ProtectTransparancy = false; img = Visualiser.CreateImage32( idbuffer, rawimg.Size ); l = psd.Layers.Add( new PSD.Layer( Boot.IDLayerName, 0, 0, img ) ); l.Opacity = 254; l.Mode = PSD.LayerMode.Overlay; l.Visible = true; l.ProtectTransparancy = false; img = Visualiser.CreateImage32( borderbuffer, rawimg.Size, true ); l = psd.Layers.Add( new PSD.Layer( Boot.BorderLayerName, 0, 0, img ) ); l.Opacity = 254; l.Visible = true; l.ProtectTransparancy = false; // -- Write the psd FileStream stream = null; try { stream = new FileStream( target, FileMode.Create, FileAccess.Write, FileShare.None ); psd.WriteTo( new BinaryWriter( stream ) ); } finally { if ( stream != null ) stream.Close(); } } }