public void saveFile(string fileName, FileFormat format, AmfFile file)
        {
            Stream fs = null;
            EndianBinaryWriter writer = null;
            try
            {
                debugLine("File format: " + format + ", file name: " + fileName);
                fs = Util.openStream(fileName, format, FileMode.Create);
                writer = Util.createEndianBinaryWriterForStream(fs);

                writeAmfFile(writer, file);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                if (writer != null)
                {
                    writer.Close();
                    if (format == FileFormat.COMPRESSED)
                    {
                        Util.compressFile(fileName);
                    }
                }
            }
        }
        private AmfFile readAmfFile(EndianBinaryReader reader)
        {
            validateFile(reader);

            ushort width = BitConverter.ToUInt16(reader.ReadBytes(2), 0);
            debugLine("width: " + width);
            ushort height = BitConverter.ToUInt16(reader.ReadBytes(2), 0);
            debugLine("width: " + height);
            AmfFile file = new AmfFile(width, height);
            readPixels(reader, width, height, file);

            return file;
        }
 public AmfAttributeMap(string filename)
 {
     L3dtFileManager.L3dtFileManager manager = new L3dtFileManager.L3dtFileManager();
     if (filename.EndsWith(".amf.gz"))
     {
         this.file = manager.loadAmfFile(filename, FileFormat.COMPRESSED);
     }
     else if (filename.EndsWith(".amf"))
     {
         this.file = manager.loadAmfFile(filename, FileFormat.UNCOMPRESSED);
     }
     else
     {
         throw new Exception("Not a AMF map file");
     }
 }
        private void readPixels(EndianBinaryReader reader, ushort width, ushort height, AmfFile file)
        {
            int totalPixels = width * height;
            uint xLocation = 1;
            uint yLocation = 1;
            for (int i = 0; i < totalPixels; i++)
            {
                byte landTypeId = reader.ReadByte();
                byte climateId = reader.ReadByte();
                file.addPixel(new AmfPixelInfo(xLocation, yLocation, landTypeId, climateId));

                xLocation++;
                if (xLocation > width)
                {
                    xLocation = 1;
                    yLocation++;
                }
            }

            debugLine("pixel count: " + file.pixels.Count());
        }
        private void writeAmfFile(EndianBinaryWriter writer, AmfFile file)
        {
            writer.Write(Util.StringToByteArray("L3DT", 4));
            ushort fileType = 520;
            writer.Write(fileType);

            writer.Write(file.width);
            writer.Write(file.height);

            foreach (AmfPixelInfo pixel in file.pixels)
            {
                writer.Write(pixel.landTypeId);
                writer.Write(pixel.climateId);
            }
        }
 public void saveAmfFile(string fileName, FileFormat format, AmfFile file)
 {
     amfManager.saveFile(fileName, format, file);
 }