public AxROMMapper(IImageReader reader, IMemoryBus cpuBus, IMemoryBus ppuBus) : base(reader, cpuBus, ppuBus) { if (this.Reader.ChrRomSize != 0) { throw new ArgumentOutOfRangeException("AxROM expects CHR RAM!"); } if (this.Reader.PrgRomSize > AxROMMapper.MaxPrgSize) { throw new ArgumentOutOfRangeException("AxROM supports a maximum of 256KB of PRG ROM!"); } // 1 32KB bank of PRG ROM at CPU 0x8000 base.MapCpuRange(this, 0x8000, 0xFFFF); // 8K bank of CHR ROM at PPU 0x0000 base.MapPpuRange(this, 0x0000, 0x1FFF); // Load data from ROM this.prgRom = new byte[this.Reader.PrgRomSize]; this.prgRomBanks = this.Reader.PrgRomSize / AxROMMapper.PrgRomBankSize; this.Reader.GetPrgRom(0, this.prgRom, 0, this.Reader.PrgRomSize); // First bank of PRG ROM is initially mapped at 0x8000 this.prgRomBankMask = (UInt32)((((this.prgRomBanks - 1) & 0x07) % this.prgRomBanks) << 15);; }
public ImageConverter(string sourcePath, string convertTo, string outputPath) { _imageReader = ImageReaderFactory.GetInstance().GetImageReader(sourcePath); _imageWriter = ImageWriterFactory.GetInstance() .GetImageWriter((ImageWriteFormat)Enum.Parse(typeof(ImageWriteFormat), convertTo, true), outputPath); }
public static void Run() { IImageReader reader = null; List <string> images = new List <string> { "image1.gif", "image2.jpg" }; List <DecodedImage> decodedImages = new List <DecodedImage>(); foreach (var image in images) { string imageType = image.Split('.')[1]; switch (imageType) { case "gif": reader = new GifReader(image); break; case "jpg": reader = new JpgReader(image); break; } decodedImages.Add(reader.Decode()); } }
public void LoadFromFile(string path, IImageReader reader) { using (var fs = new FileStream(path, FileMode.Open)) { reader.LoadFromStream(fs, this); } }
public void DataProviderTesting() { byte[][] images = new byte[][] { new byte[] { 0, 1, 2, 3, 4, 5 }, new byte[] { 6, 7, 8, 9, 0, 1 } }; byte[] labels = new byte[] { 0, 1 }; IImageReader imageReader = Mock.Of <IImageReader>(e => e.Height == 2 && e.Width == 3 && e.Data == images); ILabelReader labelReader = Mock.Of <ILabelReader>(e => e.Data == labels); DataProvider provider = new DataProvider(imageReader, labelReader); PatternCollection result = provider.Load(); Assert.AreEqual(2, result.Count); Assert.AreEqual(2, result.Height); Assert.AreEqual(3, result.Width); CollectionAssert.AreEqual(images[0], result[0].Image); Assert.AreEqual(labels[0], result[0].Label); CollectionAssert.AreEqual(images[1], result[1].Image); Assert.AreEqual(labels[1], result[1].Label); }
internal MMC1Mapper(IImageReader reader, IMemoryBus cpuBus, IMemoryBus ppuBus) : base(reader, cpuBus, ppuBus) { if (this.Reader.PrgRamSize > MMC1Mapper.PrgRamMaxSize) { throw new ArgumentOutOfRangeException("MMC1 supports a maximum of 32KB of PRG RAM"); } if (this.Reader.PrgRomSize > MMC1Mapper.PrgRomMaxSize) { throw new ArgumentOutOfRangeException("MMC1 supports a maximum of 512KB of PRG ROM"); } if (this.Reader.ChrRomSize > MMC1Mapper.ChrRomMaxSize) { throw new ArgumentOutOfRangeException("MMC1 supports a maximum of 128KB of CHR ROM"); } // Initialize ROM int prgRomSize = this.Reader.PrgRomSize; int prgRamSize = (this.Reader.PrgRamSize != 0) ? this.Reader.PrgRamSize : 0x2000; int chrRomSize = (this.Reader.ChrRomSize != 0) ? this.Reader.ChrRomSize : 0x2000; this.prgRomBanks = prgRomSize / MMC1Mapper.PrgRomBankSize; this.chrRomBanks = chrRomSize / MMC1Mapper.ChrRomBankSize; this.prgRam = new byte[prgRamSize]; this.prgRom = new byte[prgRomSize]; this.chrRom = new byte[chrRomSize]; // Read PRG ROM this.Reader.GetPrgRom(0, this.prgRom, 0, prgRomSize); if (this.Reader.ChrRomSize != 0) { // Read CHR ROM this.Reader.GetChrRom(0, this.chrRom, 0, chrRomSize); } else { // We're using CHR RAM - initialize the masks for the fixed banks this.chrRomLoBankMask = 0x0000; this.chrRomHiBankMask = 0x1000; } this.shiftRegister = 0x10; // 8K bank of PRG RAM at CPU 0x6000 this.MapCpuRange(this, 0x6000, 0x7FFF); // 2 16K banks of PRG ROM at CPU 0x8000 and 0xC000 this.MapCpuRange(this, 0x8000, 0xFFFF); // 2 4K banks of CHR ROM at PPU 0x0000 and 0x1000 this.MapPpuRange(this, 0x0000, 0x1FFF); // Initial state varies, but the last bank of PRG ROM seems to always be mapped // at 0xC000 - see http://forums.nesdev.com/viewtopic.php?t=6766 this.prgRomHiBankMask = (UInt32)(this.prgRomBanks - 1) << 14; }
public void RegisterImageReader(ImageFileFormat fileFormat, IImageReader readerImplementation) { if(_readers.ContainsKey(fileFormat)) throw new ArgumentException("Reader for the image format already registered!", "fileFormat"); _readers.Add(fileFormat, readerImplementation); ReadableFileFormats.Add(fileFormat); }
public static string GetFileFilter(this IImageReader self) { if (self.FormatFilter.IsNullOrEmpty()) { return("All files (*.*)|*.*"); } return($"{self.FormatDescription} ({self.FormatFilter})|{self.FormatFilter}"); }
// This loads the image protected override void LocalLoadImage() { // Leave when already loaded if (this.IsImageLoaded) { return; } lock (this) { // Load file data if (bitmap != null) { bitmap.Dispose(); } bitmap = null; MemoryStream filedata = datareader.LoadFile(filepathname); //mxd if (filedata != null) { // Get a reader for the data IImageReader reader = ImageDataFormat.GetImageReader(filedata, probableformat, General.Map.Data.Palette); if (!(reader is UnknownImageReader)) { // Load the image filedata.Seek(0, SeekOrigin.Begin); try { bitmap = reader.ReadAsBitmap(filedata); } catch (InvalidDataException) { // Data cannot be read! bitmap = null; } } // Not loaded? if (bitmap == null) { General.ErrorLogger.Add(ErrorType.Error, "Image file \"" + filepathname + "\" data format could not be read, while loading texture \"" + this.Name + "\""); loadfailed = true; } else { // Get width and height from image width = bitmap.Size.Width; height = bitmap.Size.Height; } filedata.Dispose(); } // Pass on to base base.LocalLoadImage(); } }
internal MMC3Mapper(IImageReader reader, IMemoryBus cpuBus, IMemoryBus ppuBus, IProcessorInterrupt irq) : base(reader, cpuBus, ppuBus) { if (this.Reader.PrgRamSize > MMC3Mapper.PrgRamMaxSize) { throw new ArgumentOutOfRangeException("MMC3 supports a maximum of 8KB of PRG RAM"); } if (this.Reader.PrgRomSize > MMC3Mapper.PrgRomMaxSize) { throw new ArgumentOutOfRangeException("MMC3 supports a maximum of 512KB of PRG ROM"); } if (this.Reader.ChrRomSize > MMC3Mapper.ChrRomMaxSize) { throw new ArgumentOutOfRangeException("MMC3 supports a maximum of 256KB of CHR ROM"); } this.irq = irq; // Initialize ROM int prgRomSize = this.Reader.PrgRomSize; int prgRamSize = (this.Reader.PrgRamSize != 0) ? this.Reader.PrgRamSize : 0x2000; int chrRomSize = (this.Reader.ChrRomSize != 0) ? this.Reader.ChrRomSize : 0x2000; this.prgRomBanks = this.Reader.PrgRomSize / MMC3Mapper.PrgRomBankSize; this.chrRomBanks = (this.Reader.ChrRomSize != 0) ? (this.Reader.ChrRomSize / MMC3Mapper.ChrRomBankSize) : 8; this.prgRam = new byte[prgRamSize]; this.prgRom = new byte[prgRomSize]; this.chrRom = new byte[chrRomSize]; // Read PRG ROM this.Reader.GetPrgRom(0, this.prgRom, 0, prgRomSize); if (this.Reader.ChrRomSize != 0) { // Read CHR ROM this.Reader.GetChrRom(0, this.chrRom, 0, chrRomSize); } // 8K bank of PRG RAM at CPU 0x6000 this.MapCpuRange(this, 0x6000, 0x7FFF); // 2 16K banks of PRG ROM at CPU 0x8000 and 0xC000 this.MapCpuRange(this, 0x8000, 0xFFFF); // 2 2K banks and 4 1K banks of CHR ROM between PPU 0x0000 and 0x1000 this.MapPpuRange(this, 0x0000, 0x1FFF); // Initial state is undefined, except that the last bank of PRG ROM will be mapped from 0xE000 - 0xFFFF this.prgRomBank3Mask = (UInt32)(this.prgRomBanks - 1) << 13; // Set initial nametable mirroring from ROM data as a hack to fix some homebrew that doesn't properly // initialize the mapper base.SetNametableMirroring(this.Reader.Mirroring); }
public FileSystemImageManager(IOptions <ImageManagerOptions> options, ILogger <FileSystemImageManager> logger, IImageReader imageReader, IImageProcessor imageProcessor, IImageWriter imageWriter) { this.options = options.Value; this.logger = logger; reader = imageReader; processor = imageProcessor; writer = imageWriter; }
// This loads the image protected override LocalLoadResult LocalLoadImage() { Bitmap bitmap = null; string error = null; // Get the lump data stream string flatlocation = string.Empty; //mxd Stream lumpdata = General.Map.Data.GetFlatData(Name, hasLongName, ref flatlocation); if (lumpdata != null) { // Copy lump data to memory byte[] membytes = new byte[(int)lumpdata.Length]; lock (lumpdata) //mxd { lumpdata.Seek(0, SeekOrigin.Begin); lumpdata.Read(membytes, 0, (int)lumpdata.Length); } MemoryStream mem = new MemoryStream(membytes); mem.Seek(0, SeekOrigin.Begin); // Get a reader for the data IImageReader reader = ImageDataFormat.GetImageReader(mem, ImageDataFormat.DOOMFLAT, General.Map.Data.Palette); if (reader is UnknownImageReader) { // Data is in an unknown format! error = "Flat lump \"" + Path.Combine(flatlocation, Name) + "\" data format could not be read. Does this lump contain valid picture data at all?"; bitmap = null; } else { // Read data as bitmap mem.Seek(0, SeekOrigin.Begin); bitmap = reader.ReadAsBitmap(mem); } // Done mem.Dispose(); } else { // Missing a patch lump! error = "Missing flat lump \"" + Name + "\". Did you forget to include required resources?"; } return(new LocalLoadResult(bitmap, error, () => { scale.x = General.Map.Config.DefaultFlatScale; scale.y = General.Map.Config.DefaultFlatScale; })); }
protected MapperBase(IImageReader reader, IMemoryBus cpuBus, IMemoryBus ppuBus) { this.Reader = reader; this.CpuBus = cpuBus; this.PpuBus = ppuBus; this.cpuMappings = new List <IMemoryMapping>(); this.cpuMirrorings = new List <IMemoryMirroring>(); this.ppuMappings = new List <IMemoryMapping>(); this.ppuMirrorings = new List <IMemoryMirroring>(); }
internal DirectoryReader(ILogger logger, string directoryName, string extension, IImageReader reader) { _logger = LogManager.GetCurrentClassLogger(); _directoryName = directoryName; _extension = extension; _reader = reader; ClassName = nameof(DirectoryReader); Title = ClassName; _logger?.InfoLog($"Instantiated.", ClassName); }
// This loads the image protected override LocalLoadResult LocalLoadImage() { // Get the patch data stream Bitmap bitmap = null; string error = null; string patchlocation = string.Empty; //mxd Stream patchdata = General.Map.Data.GetTextureData(lumpname, hasLongName, ref patchlocation); if (patchdata != null) { // Copy patch data to memory byte[] membytes = new byte[(int)patchdata.Length]; lock (patchdata) //mxd { patchdata.Seek(0, SeekOrigin.Begin); patchdata.Read(membytes, 0, (int)patchdata.Length); } MemoryStream mem = new MemoryStream(membytes); mem.Seek(0, SeekOrigin.Begin); // Get a reader for the data IImageReader reader = ImageDataFormat.GetImageReader(mem, ImageDataFormat.DOOMPICTURE, General.Map.Data.Palette); if (!(reader is UnknownImageReader)) { // Load the image mem.Seek(0, SeekOrigin.Begin); try { bitmap = reader.ReadAsBitmap(mem); } catch (InvalidDataException) { // Data cannot be read! bitmap = null; } } // Not loaded? if (bitmap == null) { error = "Image lump \"" + Path.Combine(patchlocation, lumpname) + "\" data format could not be read, while loading texture \"" + this.Name + "\". Does this lump contain valid picture data at all?"; } // Done mem.Dispose(); } else { error = "Image lump \"" + lumpname + "\" could not be found, while loading texture \"" + this.Name + "\". Did you forget to include required resources?"; } return(new LocalLoadResult(bitmap, error)); }
internal Volume(string dir, IImageReader imgReader) { //TODO: remove coupling with IImage //TODO: throw exception for different sizes img in list var imgList = imgReader.GetImageListInDir(dir); foreach (var imgPath in imgList) { _data.Add(new Image(imgPath,imgReader)); Width = imgReader.Width(imgPath); Height = imgReader.Heigth(imgPath); } Depth = imgList.Count; }
// This loads the image protected override LocalLoadResult LocalLoadImage() { Bitmap bitmap = null; string error = null; // Get the lump data stream Stream lumpdata = General.Map.Data.GetColormapData(Name); if (lumpdata != null) { // Copy lump data to memory lumpdata.Seek(0, SeekOrigin.Begin); byte[] membytes = new byte[(int)lumpdata.Length]; lumpdata.Read(membytes, 0, (int)lumpdata.Length); MemoryStream mem = new MemoryStream(membytes); mem.Seek(0, SeekOrigin.Begin); // Get a reader for the data IImageReader reader = ImageDataFormat.GetImageReader(mem, ImageDataFormat.DOOMCOLORMAP, General.Map.Data.Palette); if (reader is UnknownImageReader) { // Data is in an unknown format! error = "Colormap lump \"" + Name + "\" data format could not be read. Does this lump contain valid colormap data at all?"; bitmap = null; } else { // Read data as bitmap mem.Seek(0, SeekOrigin.Begin); if (bitmap != null) { bitmap.Dispose(); } bitmap = reader.ReadAsBitmap(mem); } // Done mem.Dispose(); } else { // Missing a patch lump! error = "Missing colormap lump \"" + Name + "\". Did you forget to include required resources?"; } return(new LocalLoadResult(bitmap, error, () => { scale.x = General.Map.Config.DefaultFlatScale; scale.y = General.Map.Config.DefaultFlatScale; })); }
// This loads the image protected override LocalLoadResult LocalLoadImage() { // Get the lump data stream Bitmap bitmap = null; string error = null; string spritelocation = string.Empty; //mxd Stream lumpdata = General.Map.Data.GetSpriteData(Name, ref spritelocation); if (lumpdata != null) { // Get a reader for the data IImageReader reader = ImageDataFormat.GetImageReader(lumpdata, ImageDataFormat.DOOMPICTURE, General.Map.Data.Palette); if (reader is UnknownImageReader) { // Data is in an unknown format! error = "Sprite lump \"" + Path.Combine(spritelocation, Name) + "\" data format could not be read. Does this lump contain valid picture data at all?"; bitmap = null; } else { // Read data as bitmap lumpdata.Seek(0, SeekOrigin.Begin); if (bitmap != null) { bitmap.Dispose(); } bitmap = reader.ReadAsBitmap(lumpdata, out offsetx, out offsety); } // Done lumpdata.Close(); } else { // Missing a patch lump! error = "Missing sprite lump \"" + Name + "\". Forgot to include required resources?"; } return(new LocalLoadResult(bitmap, error, () => { scale.x = 1.0f; scale.y = 1.0f; // Make offset corrections if the offset was not given if ((offsetx == int.MinValue) || (offsety == int.MinValue)) { offsetx = (int)((width * scale.x) * 0.5f); offsety = (int)(height * scale.y); } })); }
public void Setup() { _bmpImageReader = new BmpImageReader(); _2PosibleMatchBlocksTxtFileName = _basePath + "TxtMatrices\\" + _2PosibleMatchBlocksTxtFileName; _lenna256anTxtFileName = _basePath + "TxtMatrices\\" + _lenna256anTxtFileName; _testBmpPath = _basePath + _testBmpPath; _one3X4MatchBlockBmpPath = _basePath + _one3X4MatchBlockBmpPath; _2PossibleMatchBlocksBmpPath = _basePath + _2PossibleMatchBlocksBmpPath; _lenna256anBmpPath = _basePath + _lenna256anBmpPath; _peppers512 = _basePath + _peppers512; _gz2DlzEncoderFacade = new Gz2DlzEncoderFacade(); }
private IImageReader GetReader() { IImageReader reader; foreach (IImageReaderFactory factory in this.ImageReaderFactories) { reader = factory.CreateImageReader(this.imageStream); if (reader.IsValidImage) { return(reader); } } return(null); }
internal UxROMMapper(IImageReader reader, IMemoryBus cpuBus, IMemoryBus ppuBus, UxRomVariant variant = UxRomVariant.UxROM) : base(reader, cpuBus, ppuBus) { if (this.Reader.ChrRomSize != 0 && this.Reader.ChrRomSize != 8 * 1024) { throw new ArgumentOutOfRangeException("UxROM expects 0 or 8KB of CHR ROM!"); } if (this.Reader.PrgRomSize > UxROMMapper.MaxPrgSize) { throw new ArgumentOutOfRangeException("UxROM supports a maximum of 4MB of PRG ROM!"); } // 2 16KB banks of PRG ROM at CPU 0x8000 and 0xC000 base.MapCpuRange(this, 0x8000, 0xFFFF); // 8K bank of CHR ROM at PPU 0x0000 base.MapPpuRange(this, 0x0000, 0x1FFF); // Load data from ROM this.prgRom = new byte[this.Reader.PrgRomSize]; this.prgRomBanks = this.Reader.PrgRomSize / UxROMMapper.PrgRomBankSize; if (this.Reader.ChrRomSize > 0) { this.Reader.GetChrRom(0, this.chrRom, 0, this.Reader.ChrRomSize); } this.Reader.GetPrgRom(0, this.prgRom, 0, this.Reader.PrgRomSize); base.SetNametableMirroring(this.Reader.Mirroring); // High bank of PRG ROM is always mapped at 0xC000 this.prgRomHiBankMask = (UInt32)(this.prgRomBanks - 1) << 14; switch (variant) { case UxRomVariant.UxROM: this.bankSwitchRegisterAddrRangeStart = 0x8000; this.bankSwitchRegisterAddrRangeEnd = 0xFFFF; break; case UxRomVariant.Camerica71: this.bankSwitchRegisterAddrRangeStart = 0xC000; this.bankSwitchRegisterAddrRangeEnd = 0xFFFF; break; } }
public void Execute(IPresentation presentation, Action <IImageReader> OnReadSeccessfull) { IImageReader imageReader = Factory.CreateImageLoader(); var image = imageReader.Read(); if (image != null) { presentation.AddImage(imageReader.ImageName, image); string savePath = Path.Combine(Resource.GetImageFolderPath(), imageReader.ImageName); File.Copy(imageReader.ImagePath, savePath, true); OnReadSeccessfull(imageReader); } }
public void GifReaderObject_Success() { DecodedImage decodedImage; IImageReader reader = null; string image = "anil.gif"; string format = image.Substring(image.IndexOf('.') + 1); if (format.Equals("gif")) { reader = new GifReader(image); } Assert.NotNull(reader); Assert.IsType <GifReader>(reader); }
public void AnalyzeFolder(string foldername) { foreach (var filename in GetSupportedFiles(foldername)) { IImageReader reader = ImageReaderFactory.CreateReader(filename); CdromImage image = reader.ReadImage(filename); WriteImageInfo(image, filename + ".txt"); _cdromImages.Add(filename, image); } var writer = new BinImageWriter(); foreach (var filename in _cdromImages.Keys) { writer.WriteImage(_cdromImages[filename], filename + ".new"); } }
public List <IPresentation> ReadAll() { Console.WriteLine("Loading Presentations"); List <IPresentation> presentations = new List <IPresentation>(); string root = Directory.GetCurrentDirectory(); string AllPresentationFolder = Path.Combine(root, Resource.PRESENTATION_FOLDER_NAME); if (Directory.Exists(AllPresentationFolder)) { foreach (var presentationFolder in Resource.GetDirectories(AllPresentationFolder)) { IPresentation presentation = new T(); List <string> extensions = new List <string>() { "json" }; foreach (var file in Resource.GetFilesAtFolder(presentationFolder, extensions)) { presentation = LoadJSON <T>(file); presentations.Add(presentation); } if (presentation != null) { IImageReader imageReader = Factory.CreateImageLoader(); string imageFolder = Path.Combine(presentationFolder, Resource.IMAGE_FOLDER_NAME); presentation.SetImages(imageReader.ReadAll(imageFolder)); } } Console.WriteLine("Finished Loading Presentations: " + presentations.Count); return(presentations); } return(null); }
// This loads the image protected override LocalLoadResult LocalLoadImage() { // Load file data Bitmap bitmap = null; string error = null; MemoryStream filedata = null; try { filedata = new MemoryStream(File.ReadAllBytes(filepathname)); } catch (IOException) { error = "Image file \"" + filepathname + "\" could not be read, while loading image \"" + this.Name + "\". Consider reloading resources."; } if (filedata != null) { // Get a reader for the data IImageReader reader = ImageDataFormat.GetImageReader(filedata, probableformat, General.Map.Data.Palette); if (!(reader is UnknownImageReader)) { // Load the image filedata.Seek(0, SeekOrigin.Begin); try { bitmap = reader.ReadAsBitmap(filedata); } catch (InvalidDataException) { // Data cannot be read! bitmap = null; } } // Not loaded? if (bitmap == null) { error = "Image file \"" + filepathname + "\" data format could not be read, while loading image \"" + this.Name + "\". Is this a valid picture file at all?"; } filedata.Dispose(); } return(new LocalLoadResult(bitmap, error)); }
public static void InitiateConversion(string originalPath, string destinationPath, string outputFormat) { string originalTypeStr = GetExtension(originalPath); ImageType originalType; ImageType finalType; try { originalType = (ImageType)Enum.Parse(typeof(ImageType), originalTypeStr, true); finalType = (ImageType)Enum.Parse(typeof(ImageType), outputFormat, true); } catch (Exception) { throw new InvalidOperationException("Unsupported Image Type"); } IFactory <IImageReader> readerFactory = new ReaderFactory(); IFactory <IImageWriter> writerFactory = new WriterFactory(); IImageReader reader = readerFactory.Create(originalType); IImageWriter writer = writerFactory.Create(finalType); var image = reader.Read(originalPath); Converter converter = new Converter(writer); converter.Convert(image, destinationPath); Bitmap pic = new Bitmap(image.Header.Width, image.Header.Height, System.Drawing.Imaging.PixelFormat.Format24bppRgb); for (int i = 0; i < image.Header.Height; i++) { for (int j = 0; j < image.Header.Width; j++) { Color c = Color.FromArgb(image.Bitmap[i, j].R, image.Bitmap[i, j].G, image.Bitmap[i, j].B); pic.SetPixel(j, i, c); } } pic.Save("testcow.bmp"); string GetExtension(string path) { return(path.Substring(path.LastIndexOf('.') + 1)); } }
public FileSystemImageProvider(ImageModel imageModel, IEnumerable <string> filePaths, bool infitlyLoopOverFiles) { _infitlyLoopOverFiles = infitlyLoopOverFiles; _filePathsEnumerator = filePaths.GetEnumerator(); switch (imageModel.ImageBitDepth) { case ImageBitDepth.Bpp8: _imageReader = new BitmapImageReader(imageModel); break; case ImageBitDepth.Bpp12: _imageReader = new RawImageReader(imageModel); break; default: throw new ArgumentOutOfRangeException(); } }
public void LoadRom(string fileName) { if (this.imageStream != null) { this.imageStream.Close(); this.imageStream.Dispose(); } this.imageStream = File.OpenRead(fileName); this.reader = this.GetReader(); if (reader == null) { throw new InvalidOperationException("Not a valid ROM!"); } Trace.WriteLine("Loaded ROM: {0}".FormatCurrentCulture(fileName)); Trace.WriteLine(" PRG ROM: {0} bytes".FormatCurrentCulture(this.reader.PrgRomSize)); Trace.WriteLine(" PRG RAM: {0} bytes".FormatCurrentCulture(this.reader.PrgRamSize)); Trace.WriteLine(" CHR ROM: {0} bytes".FormatCurrentCulture(this.reader.ChrRomSize)); Trace.WriteLine(" Mapper ID: {0}".FormatCurrentCulture(this.reader.Mapper)); IMapperFactory mapperFactory = this.MapperFactories.FirstOrDefault(f => f.Metadata.MapperId == this.reader.Mapper)?.Value; if (mapperFactory == null) { throw new InvalidOperationException(String.Format(CultureInfo.CurrentCulture, "No mapper available with ID '{0}'!", this.reader.Mapper)); } if (this.currentMapper != null) { // Dispose the old mapper to unhook it from the memory buses this.currentMapper.Dispose(); this.currentMapper = null; } this.currentMapper = mapperFactory.CreateInstance(this.reader, this.cpuBus, this.ppuBus, this.irq); Trace.WriteLine(" Mapper name: {0}".FormatCurrentCulture(this.currentMapper.Name)); }
// This loads the image protected override LocalLoadResult LocalLoadImage() { // Load file data Bitmap bitmap = null; string error = null; MemoryStream filedata = datareader.LoadFile(filepathname); //mxd isBadForLongTextureNames = false; if (filedata != null) { // Get a reader for the data IImageReader reader = ImageDataFormat.GetImageReader(filedata, probableformat, General.Map.Data.Palette); if (!(reader is UnknownImageReader)) { // Load the image filedata.Seek(0, SeekOrigin.Begin); try { bitmap = reader.ReadAsBitmap(filedata); } catch (InvalidDataException) { // Data cannot be read! bitmap = null; } } // Not loaded? if (bitmap == null) { error = "Image file \"" + filepathname + "\" data format could not be read, while loading texture \"" + this.Name + "\""; } filedata.Dispose(); } return(new LocalLoadResult(bitmap, error)); }
static void Main(string[] args) { ILoggerFactory fileLoggerFactory = new FileLoggerFactory(); ILoggerFactory databaseLoggerFactory = new DatabaseLoggerFactory(); //针对抽象工厂接口编程 ILogger fileLogger = fileLoggerFactory.CreateLogger(); ILogger databaseLogger = databaseLoggerFactory.CreateLogger(); fileLogger.Log(); databaseLogger.Log(); IImageReaderFactory gifReaderFactory = new GifReaderFactory(); IImageReaderFactory jpgReaderFactory = new JPGReaderFactory(); IImageReaderFactory bmpReaderFactory = new BMPReaderFactory(); IImageReader gifReader = gifReaderFactory.GetImageReader(); IImageReader jpgReader = jpgReaderFactory.GetImageReader(); IImageReader bmpReader = bmpReaderFactory.GetImageReader(); gifReader.Load(@"E:\Media\Images\壁纸\ (1).jpg"); jpgReader.Load(@"E:\Media\Images\壁纸\ (1).jpg"); bmpReader.Load(@"E:\Media\Images\壁纸\ (1).jpg"); Console.ReadKey(); }
internal CNROMMapper(IImageReader reader, IMemoryBus cpuBus, IMemoryBus ppuBus) : base(reader, cpuBus, ppuBus) { if (this.Reader.PrgRomSize != 16 * 1024 && this.Reader.PrgRomSize != 32 * 1024) { throw new ArgumentOutOfRangeException("CNROM expects 16 or 32KB of PRG ROM!"); } if (this.Reader.ChrRomSize > CNROMMapper.MaxChrSize) { throw new ArgumentOutOfRangeException("CNROM supports a maximum of 2MB of CHR ROM!"); } // 2 16KB banks of PRG ROM at CPU 0x8000 and 0xC000 base.MapCpuRange(this, 0x8000, 0xFFFF); // 8K bank of CHR ROM at PPU 0x0000 base.MapPpuRange(this, 0x0000, 0x1FFF); // Load data from ROM this.chrRom = new byte[this.Reader.ChrRomSize]; this.chrRomBanks = this.Reader.ChrRomSize / CNROMMapper.ChrRomBankSize; this.Reader.GetChrRom(0, this.chrRom, 0, this.Reader.ChrRomSize); this.Reader.GetPrgRom(0, this.prgRom, 0, 0x4000); if (this.Reader.PrgRomSize == 0x4000) { this.Reader.GetPrgRom(0, this.prgRom, 0x4000, 0x4000); } else { this.Reader.GetPrgRom(0x4000, this.prgRom, 0x4000, 0x4000); } base.SetNametableMirroring(this.Reader.Mirroring); }
public Image(string imgPath, IImageReader imageReader) { _data = imageReader.GetBitmapFromFile(imgPath); Width = imageReader.Width(imgPath); Height = imageReader.Heigth(imgPath); }