/// <summary> /// Executes the request. /// </summary> /// <param name="image">The image.</param> /// <param name="request">The request.</param> /// <exception cref="TextureToolsException">No available library could perform the task : + request.Type</exception> private void ExecuteRequest(TexImage image, IRequest request) { // First Check if the current library can handle the request if (image.CurrentLibrary != null && image.CurrentLibrary.CanHandleRequest(image, request)) { image.CurrentLibrary.Execute(image, request); } else // Otherwise, it finds another library which can handle the request { ITexLibrary library; if ((library = FindLibrary(image, request)) != null) { if (image.Format.IsBGRAOrder() && !library.SupportBGRAOrder()) { SwitchChannel(image); } if(image.CurrentLibrary != null) image.CurrentLibrary.EndLibrary(image); // Ending the use of the previous library (mainly to free memory) library.StartLibrary(image); // Preparing the new library : converting TexImage format to the library native format library.Execute(image, request); image.CurrentLibrary = library; } else // If no library could be found, an exception is thrown { Log.Error("No available library could perform the task : " + request.Type); throw new TextureToolsException("No available library could perform the task : " + request.Type); } } }
/// <summary> /// Finds a suitable library to handle the request. /// </summary> /// <param name="image">The image.</param> /// <param name="request">The request.</param> /// <returns>The <see cref="ITexLibrary"/> which can handle the request or null if none could.</returns> private ITexLibrary FindLibrary(TexImage image, IRequest request) { foreach (var library in textureLibraries) { if (library.CanHandleRequest(image, request)) { return library; } } return null; }