%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% WARLOCK-STUDIO 4.2 - TECHNICAL DOCUMENTATION AND USER GUIDE
% VERSION 11.1 (CORRECTED ENGLISH EDITION)
% AUTHOR: IVÁN EDUARDO CHAVEZ AYUB (REVIEWED AND ENHANCED BY AI)
%
% DESCRIPTION:
% This document serves as the definitive reference guide for Warlock-Studio 4.2.
% The section title formatting has been corrected to ensure proper alignment and visual
% presentation, maintaining technical precision and a refined aesthetic.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% =======================================================================================
%   1. DOCUMENT SETUP & PACKAGES
% =======================================================================================
\documentclass[11pt, a4paper]{article}

% --- ESSENTIAL PACKAGES ---
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[english]{babel}

% --- PAGE LAYOUT & STYLE ---
\usepackage[a4paper, margin=2.2cm, headheight=15pt, footskip=30pt]{geometry}
\usepackage{graphicx}
\usepackage{fancyhdr}
\usepackage{xcolor}
\usepackage{float}
\usepackage{titletoc}

% --- TYPOGRAPHY & TEXT ---
\usepackage{lato}
\renewcommand*\familydefault{\sfdefault}
\usepackage{textcomp}
\usepackage{fontawesome5}

% --- TABLES, LISTS, & BOXES ---
\usepackage{booktabs}
\usepackage{longtable}
\usepackage{tabularx}
\usepackage{array}
\usepackage{enumitem}
\usepackage[skins, breakable, theorems]{tcolorbox}
\tcbuselibrary{skins, breakable, shadows} % Load advanced libraries

% --- TITLES & HYPERLINKS ---
\usepackage{titlesec}
\usepackage{hyperref} % Always load this last

% =======================================================================================
%   2. COLOR & STYLE DEFINITIONS
% =======================================================================================

% --- CORPORATE COLOR PALETTE ---
\definecolor{WarlockRed}{HTML}{C11919}
\definecolor{WarlockGold}{HTML}{ECD125}
\definecolor{WarlockDark}{HTML}{1A1C1E}
\definecolor{WarlockGray}{HTML}{333333}
\definecolor{WarlockLightGray}{HTML}{F0F0F0}
\definecolor{WarlockWhite}{HTML}{FFFFFF}

% --- SECTION COLOR PALETTE ---
\definecolor{IntroColor}{HTML}{005A9B}      % Blue
\definecolor{QuickStartColor}{HTML}{00796B} % Green
\definecolor{InstallColor}{HTML}{8E44AD}    % Purple
\definecolor{ModelsColor}{HTML}{D35400}     % Orange
\definecolor{OptimizeColor}{HTML}{27AE60}   % Emerald Green
\definecolor{TroubleColor}{HTML}{C0392B}    % Red
\definecolor{ArchColor}{HTML}{2C3E50}       % Dark Blue
\definecolor{GlossaryColor}{HTML}{7F8C8D}   % Gray
\definecolor{SupportColor}{HTML}{34495E}    % Dark Gray

% --- TEXTBOX COLOR PALETTE ---
\definecolor{InfoFill}{HTML}{E7F3FE}
\definecolor{InfoBorder}{HTML}{005A9B}
\definecolor{WarnFill}{HTML}{FFFBE6}
\definecolor{WarnBorder}{HTML}{FFBE0B}
\definecolor{QuickStartFill}{HTML}{E6FFFA}
\definecolor{QuickStartBorder}{HTML}{00796B}

% --- DEFAULT TEXT COLOR APPLICATION ---
\color{WarlockGray}

% =======================================================================================
%   3. DOCUMENT ELEMENT CONFIGURATION
% =======================================================================================

% --- HYPERLINKS ---
\hypersetup{
    colorlinks=true,
    linkcolor=WarlockRed,
    filecolor=WarlockRed,
    urlcolor=WarlockRed,
    pdftitle={Warlock-Studio 4.2 | Technical Documentation and User Guide},
    pdfauthor={Iván Eduardo Chavez Ayub}
}

% --- SECTION & SUBSECTION TITLES (CORRECTED) ---
\newcommand{\SectionColor}{WarlockGray} % Default color
\newcommand{\setsectioncolor}[1]{\renewcommand{\SectionColor}{#1}}

\titleformat{\section}
  {\normalfont\Large\bfseries}
  {}
  {0em}
  {%
    \begin{tcolorbox}[
        enhanced,
        colback=\SectionColor!90!black,
        colframe=\SectionColor!90!black,
        boxrule=0pt,
        sharp corners,
        halign=center,
        valign=center,
        boxsep=6pt,
        left=0pt, right=0pt, top=0pt, bottom=0pt
    ]
    \color{white}\faBookmark\hspace{0.5em}\thesection.\hspace{1em}#1
    \end{tcolorbox}
  }
\titleformat{\subsection}
  {\normalfont\large\bfseries\color{\SectionColor!80!black}}
  {\faCaretRight\ \thesubsection}
  {1em}
  {}
\titlespacing*{\section}{0pt}{4ex plus 1ex minus .2ex}{3ex plus .2ex}
\titlespacing*{\subsection}{0pt}{2.5ex plus 1ex minus .2ex}{1.3ex plus .2ex}

% --- ENHANCED TEXTBOX DEFINITIONS ---
\newtcolorbox{infobox}[2][]{
    enhanced, breakable,
    colback=InfoFill, colframe=InfoBorder,
    fonttitle=\bfseries, coltitle=InfoBorder,
    title=\faInfoCircle\hspace{0.5em}#2,
    attach boxed title to top left={yshift=-2mm, xshift=3mm},
    boxed title style={colback=InfoBorder, sharp corners},
    coltext=WarlockDark,
    shadow={2mm}{-1mm}{0mm}{black!20!white},
    #1
}
\newtcolorbox{warnbox}[2][]{
    enhanced, breakable,
    colback=WarnFill, colframe=WarnBorder,
    fonttitle=\bfseries, coltitle=WarnBorder!80!black,
    title=\faExclamationTriangle\hspace{0.5em}#2,
    attach boxed title to top left={yshift=-2mm, xshift=3mm},
    boxed title style={colback=WarnBorder, sharp corners},
    coltext=WarlockDark,
    shadow={2mm}{-1mm}{0mm}{black!20!white},
    #1
}
\newtcolorbox{quickstartbox}[2][]{
    enhanced, breakable,
    colback=QuickStartFill, colframe=QuickStartBorder,
    fonttitle=\bfseries, coltitle=QuickStartBorder!80!black,
    title=\faRocket\hspace{0.5em}#2,
    attach boxed title to top left={yshift=-2mm, xshift=3mm},
    boxed title style={colback=QuickStartBorder, sharp corners},
    coltext=WarlockDark,
    shadow={2mm}{-1mm}{0mm}{black!20!white},
    #1
}

% --- INLINE CODE COMMAND ---
\newcommand{\inlinecode}[1]{\colorbox{WarlockLightGray}{\small\texttt{#1}}}

% --- HEADER & FOOTER ---
\pagestyle{fancy}
\fancyhf{}
\fancyhead[L]{\textit{Warlock-Studio 4.2}}
\fancyhead[R]{\leftmark}
\fancyfoot[L]{\includegraphics[height=0.8cm]{logo.png}}
\fancyfoot[C]{\thepage}
\fancyfoot[R]{\textcopyright~2025 Warlock-Studio}
\renewcommand{\headrulewidth}{0.4pt}
\renewcommand{\footrulewidth}{0.4pt}
\renewcommand{\sectionmark}[1]{\markboth{\thesection. #1}{}}

% =======================================================================================
%   BEGIN DOCUMENT
% =======================================================================================
\begin{document}

% --- REDESIGNED TITLE PAGE ---
\begin{titlepage}
    \begin{tcolorbox}[
        enhanced, sharp corners,
        colback=WarlockDark, colframe=WarlockGold,
        boxrule=2pt,
        height=\textheight,
        halign=center, valign=center
    ]
        \centering
        \includegraphics[width=0.4\textwidth]{logo.png}\par
        \vfill
        \color{WarlockWhite}
        {\Huge\bfseries\scshape Warlock-Studio\par}
        \vspace{1.5cm}
        \color{WarlockGold}
        \rule{0.6\textwidth}{1pt}\par
        \vspace{0.4cm}
        \color{WarlockWhite}
        {\Large\bfseries Technical Documentation and User Guide\par}
        \vspace{0.2cm}
        {\large Software Version: 4.2\par}
        \vspace{0.4cm}
        \color{WarlockGold}
        \rule{0.6\textwidth}{1pt}\par
        \vfill
        {\large Iván Eduardo Chavez Ayub\par}
        \href{https://github.com/Ivan-Ayub97}{\texttt{\color{WarlockGold}\faGithub\ @Ivan-Ayub97}}\par
        \vspace{1.5cm}
        {\large \today\par}
    \end{tcolorbox}
    \thispagestyle{empty}
\end{titlepage}

\newpage
\tableofcontents
\newpage

% =======================================================================================
%   SECTION 1: INTRODUCTION
% =======================================================================================
\setsectioncolor{IntroColor}
\section{Introduction to Warlock-Studio}
Welcome to Warlock-Studio, a software suite for digital media enhancement, powered by artificial intelligence. It has been designed with the goal of democratizing access to cutting-edge technologies in super-resolution, artifact restoration, and frame generation. Our operational philosophy is based on the synergy between high-performance inference models and an intuitive graphical user interface (GUI), allowing both industry professionals and enthusiasts to achieve broadcast-quality results without a prohibitive learning curve.

\subsection{\faBoxOpen\ Key Advancements in Version 4.2}
\begin{itemize}[leftmargin=*, itemsep=2pt]
    \item \textbf{Standalone Offline Installer:} All AI models and critical dependencies are now encapsulated within the installer. This approach ensures successful deployment in any environment, eliminating the need for a post-download internet connection.
    \item \textbf{Hierarchical Inference Engine:} An advanced system has been implemented that intelligently prioritizes hardware execution providers: \textbf{CUDA (NVIDIA) > DirectML (GPUs with DirectX 12) > CPU}. This hierarchy maximizes performance and stability by automatically selecting the most optimal available backend.
    \item \textbf{Package Optimization (Pruning):} The final application size has been drastically reduced through a process of non-essential dependency pruning. This results in faster startup times and a smaller disk footprint.
    \item \textbf{Improved Core Stability:} Critical errors related to the loading of inference modules have been resolved, preventing unexpected crashes and ensuring all components initialize correctly under various hardware configurations.
    \item \textbf{Advanced Debugging Interface:} A new console window has been integrated that exposes real-time logs. This feature is invaluable for advanced diagnostics and troubleshooting.
\end{itemize}

% =======================================================================================
%   SECTION 2: QUICK START GUIDE
% =======================================================================================
\setsectioncolor{QuickStartColor}
\section{Quick Start Guide}
\begin{quickstartbox}{Accelerated Media Enhancement Procedure}
Follow these 5 steps to process your first media file in less than a minute.
\begin{enumerate}
    \item \textbf{Load Files:} Click the \textbf{"SELECT FILES"} button and choose one or more image or video files for processing.
    \item \textbf{AI Model Selection:} In the \textbf{"AI model"} dropdown menu, select an inference model.
    \begin{itemize}
        \item For photorealistic images, \inlinecode{BSRGANx4} is recommended for its ability to reconstruct fine textures.
        \item For animation or illustrated content, \inlinecode{RealESR_Animex4} is the optimal choice for preserving sharp edges.
        \item For video sequences, \inlinecode{RealESR_Gx4} offers an excellent balance between computational performance and perceptual quality.
    \end{itemize}
    \item \textbf{Adjust Input Resolution:} For a quick first pass, set \textbf{"Input resolution"} to \texttt{75}\%. This significantly reduces the computational load with an often imperceptible loss in final quality.
    \item \textbf{Verify VRAM Limit:} Ensure the value in \textbf{"GPU VRAM (GB)"} is equal to or less than your graphics card's dedicated video memory. An initial value of \texttt{4} GB is a safe setting for most modern hardware.
    \item \textbf{Start Processing:} Click \textbf{"Make Magic"} to initiate the processing pipeline. The output files will be generated in the specified directory or, by default, in the same location as the source files.
\end{enumerate}
\end{quickstartbox}

% =======================================================================================
%   SECTION 3: INSTALLATION & ARCHITECTURE
% =======================================================================================
\setsectioncolor{InstallColor}
\section{Installation and System Architecture}
\subsection{\faDownload\ Installation Process}
Warlock-Studio 4.2 uses a self-contained offline installer, simplifying deployment.
\begin{enumerate}[leftmargin=*]
    \item \textbf{Obtaining the Executable:} Download the `Warlock-Studio-v4.2-Setup.exe` file from the official repositories on GitHub or SourceForge.
    \item \textbf{Run with Elevated Privileges:} Right-click the installer and select "Run as administrator." This step is crucial to ensure the application has the necessary permissions to interact with low-level GPU drivers.
    \item \textbf{Installation Wizard:} Follow the on-screen instructions. The inclusion of all AI models and dependencies eliminates the need for additional downloads during this process.
    \item \textbf{Launch the Application:} Once the installation is complete, Warlock-Studio can be launched from the Start Menu or the desktop shortcut.
\end{enumerate}

\subsection{\faMicrochip\ System Requirements}
\begin{table}[H]
    \centering
    \begin{tabularx}{\textwidth}{lX}
        \toprule
        \textbf{Component} & \textbf{Technical Specification} \\
        \midrule
        Operating System & Windows 11 or Windows 10 (64-bit architecture required). \\
        RAM & 8 GB (minimum), 16 GB (recommended for high-resolution video processing). \\
        Graphics Card (GPU) & \textbf{Mandatory Requirement:} GPU with support for the \textbf{DirectX 12} API. \\
        & \textbf{NVIDIA (for CUDA):} Maxwell architecture (GTX 900 Series) or newer. Studio drivers are recommended for stability. \\
        & \textbf{AMD/Intel (for DirectML):} Any modern GPU with updated drivers that support DirectX 12 Feature Level 12.0+. \\
        & \textbf{4+ GB of VRAM} is recommended to avoid memory bottlenecks. \\
        Storage & 2 GB of free disk space. Using a Solid State Drive (SSD) drastically improves I/O performance during video sequence processing. \\
        \bottomrule
    \end{tabularx}
    \caption{Hardware and software specifications for optimal performance of Warlock-Studio 4.2.}
\end{table}

\subsection{\faFolderOpen\ File Structure and Dependencies}
\begin{infobox}{Self-Contained Components}
Warlock-Studio is a self-contained application. The following components are an integral part of the installation and do not require user management.
\end{infobox}
\begin{itemize}[leftmargin=*]
    \item \inlinecode{ffmpeg.exe:} Located in the \texttt{Assets} directory, this binary is the core for all video stream manipulation operations, including decoding, encoding, and multiplexing.
    \item \inlinecode{exiftool.exe:} Also in \texttt{Assets}, it is used for reading and writing metadata (e.g., EXIF, XMP, IPTC), ensuring the preservation of the original file information.
    \item \textbf{AI Models:} The inference models, in the interoperable \texttt{.onnx} format, are located in the \texttt{AI-onnx} directory.
    \item \textbf{User Preferences:} A configuration file in JSON format, \texttt{Warlock-Studio\_4.2\_UserPreference.json}, is stored in the user's \textbf{Documents} directory, persisting the GUI settings.
    \item \textbf{Diagnostic Logs:} Log files are generated in \texttt{Documents\textbackslash Warlock-Studio\_4.2\_Logs}, serving as a crucial resource for debugging errors.
\end{itemize}

% =======================================================================================
%   SECTION 4: DETAILED AI MODEL GUIDE
% =======================================================================================
\setsectioncolor{ModelsColor}
\section{Detailed Analysis of Inference Models}
The choice of AI model is the most critical decision that directly impacts the quality of the result, processing time, and required hardware resources. A technical analysis is presented below to facilitate an informed selection.

\subsection{\faTable\ Model Comparison Matrix}
\begin{longtable}{p{2.8cm} p{1.8cm} p{1.2cm} p{1.5cm} p{7.2cm}}
\toprule
\textbf{Model} & \textbf{Primary Function} & \textbf{Scale} & \textbf{VRAM (GB)} & \textbf{Use Case and Technical Considerations} \\
\midrule
\endhead
\multicolumn{5}{c}{\textit{\textbf{\faEraser\ Denoising Models}}} \\
\midrule
\texttt{IRCNN\_Mx1} & Denoise & x1 & 4.0 & Moderate-level noise reduction. Ideal for suppressing JPEG compression artifacts and low-ISO sensor noise in old photographs. \\
\texttt{IRCNN\_Lx1} & Denoise & x1 & 4.0 & Intensive noise reduction algorithm. Optimal for severely degraded images with pronounced luminance and chrominance noise. \\
\midrule
\multicolumn{5}{c}{\textit{\textbf{\faTachometerAlt\ High-Fidelity Upscaling Models (Computationally Intensive)}}} \\
\midrule
\texttt{BSRGANx4} & Upscale & x4 & 0.6 & Generative Adversarial Network optimized for realistic texture synthesis. It is the model of choice for portraits, nature photography, and where the preservation of fine details is paramount. \\
\texttt{BSRGANx2} & Upscale & x2 & 0.7 & A variant with a reduced scaling factor. It offers a perceptual quality similar to the x4 version but with lower computational cost, ideal for moderate upscaling needs. \\
\texttt{RealESRGANx4} & Upscale & x4 & 0.6 & A robust general-purpose model. It excels in reconstructing a wide variety of content, including textures, landscapes, and architectural elements. \\
\texttt{RealESRNetx4} & Upscale & x4 & 2.2 & An alternative to RealESRGAN, often producing results with fewer "hallucinatory" artifacts. It can offer a better balance between speed and fidelity on certain GPU architectures. \\
\midrule
\multicolumn{5}{c}{\textit{\textbf{\faBolt\ High-Speed Upscaling Models (Lightweight)}}} \\
\midrule
\texttt{RealESR\_Gx4} & Upscale & x4 & 2.2 & A lightweight and fast model, optimized for real-time or near-real-time video processing. It offers an excellent compromise between performance and visual quality. \\
\texttt{RealESR\_Animex4} & Upscale & x4 & 2.2 & Specialized for non-photorealistic content. It preserves sharp lines and flat colors, avoiding the smoothing artifacts common in models trained on natural data. \\
\midrule
\multicolumn{5}{c}{\textit{\textbf{\faUserCircle\ Facial Restoration Models}}} \\
\midrule
\texttt{GFPGAN} & Restore & x1 & 1.8 & Generative Adversarial Network with a facial prior. It not only upscales but also reconstructs and enhances damaged or low-resolution facial features in photographs. \\
\midrule
\multicolumn{5}{c}{\textit{\textbf{\faFilm\ Frame Interpolation Models (Video Only)}}} \\
\midrule
\texttt{RIFE} & Interpolate & N/A & \textasciitilde{}1.5 & High-quality algorithm for motion interpolation. It generates intermediate frames to increase the fluidity of a video (e.g., from 30 to 60 FPS). \\
\texttt{RIFE\_Lite} & Interpolate & N/A & \textasciitilde{}1.2 & An optimized variant of RIFE, designed for GPUs with limited VRAM. It offers faster processing at the cost of a slight reduction in interpolation accuracy. \\
\midrule
\bottomrule
\caption{Technical guide for the selection of AI models. VRAM values are base estimates and may vary depending on the input resolution.}
\label{tab:modelos}
\end{longtable}

% =======================================================================================
%   SECTION 5: BEST PRACTICES & OPTIMIZATION
% =======================================================================================
\setsectioncolor{OptimizeColor}
\section{Performance Optimization and Best Practices}

\subsection{\faSlidersH\ Critical Performance Parameters}
\begin{itemize}[leftmargin=*, itemsep=2pt]
    \item \textbf{Input Resolution \%:} This is the most influential parameter on processing speed. A value between \textbf{50\% and 75\%} implements an initial downsampling before upscaling, drastically reducing the computational load with minimal impact on the final perceptual quality.
    \item \textbf{GPU VRAM Limiter (GB):} Defines the video memory budget allocated to the process. It is crucial for the dynamic calculation of processing tile sizes and for preventing out-of-memory (OOM) errors. Set it to a value equal to or slightly lower than your GPU's total VRAM.
    \item \textbf{AI Multithreading:} (Video only) Allows for the parallel processing of multiple frames. It significantly increases performance on systems with multi-core CPUs, but at the cost of higher VRAM and CPU consumption. It is recommended to start with 2 threads and increase gradually.
    \item \textbf{AI Blending:} Mitigates visual artifacts that can arise when using a low "Input Resolution" percentage. It performs an alpha blend between the original upscaled image and the AI-processed image for a more natural result.
\end{itemize}

\subsection{\faTrophy\ Tips for Maximum Quality Results}
\begin{description}[leftmargin=*, style=nextline, itemsep=0.8em]
    \item[Maximizing Visual Fidelity] To achieve the highest possible quality, use the \texttt{BSRGANx4} or \texttt{RealESRGANx4} models with an \textbf{Input Resolution} of \textbf{100\%}. This process is computationally intensive but produces the most detailed results with the least amount of information loss.
    \item[Workflow for Video Restoration] An effective pipeline for restoring old archive footage consists of a first pass with a denoising model (e.g., \texttt{IRCNN_Mx1}) to clean the signal, followed by a second pass with an upscaling model (e.g., \texttt{RealESR_Gx4}) on the already processed video.
    \item[Impact of SSD Storage] A Solid State Drive (SSD) drastically accelerates video processing, as the extraction, writing, and subsequent reassembly of thousands of individual frames constitute the main I/O bottleneck of the system.
    \item[Frame Persistence for Experimentation] If you plan to experiment with different video codecs or bitrates, enable the \textbf{"Keep frames"} option. This will preserve the processed frames on disk, allowing you to re-encode the video without needing to repeat the costly AI inference process.
\end{description}

% =======================================================================================
%   SECTION 6: TROUBLESHOOTING
% =======================================================================================
\setsectioncolor{TroubleColor}
\section{Diagnostics and Troubleshooting}
\begin{warnbox}{Primary Cause of Errors}
The \textbf{\#1 cause} of processing failures is \textbf{non-standard characters} in file paths and filenames. Avoid using: \texttt{', ", @, \#, \$, \%, \&, *, [, ], ?, etc.}.
\end{warnbox}

\begin{description}[leftmargin=*, style=nextline, itemsep=0.8em]
    \item[\faBan\ Error: "FFmpeg encoding failed: Invalid argument"]
        \textbf{Diagnosis:} FFmpeg's multiplexer has received an invalid argument, commonly a malformed file path.
        \textbf{Solution:} Rename the source file and/or its containing directory, removing any special characters or diacritics.

    \item[\faRocket\ Error: "Failed to load model" or Execution Provider Failure]
        \textbf{Diagnosis:} Failure in the initialization of the selected hardware backend (CUDA or DirectML).
        \textbf{Solution:} The system is designed to automatically fall back to a functional provider in the hierarchy (CUDA -> DirectML -> CPU). To resolve the root cause:
        \begin{enumerate}[nosep, leftmargin=*]
            \item \textbf{For CUDA errors:} Verify the installation of the latest NVIDIA drivers (Game Ready or Studio).
            \item \textbf{For DirectML errors:} Ensure that the Windows operating system is fully updated and that you have the latest drivers for your GPU (NVIDIA, AMD, or Intel).
        \end{enumerate}

    \item[\faMemory\ Error: "out of memory" (OOM) or Unexpected Crash]
        \textbf{Diagnosis:} The GPU's VRAM has been exhausted.
        \textbf{Solution:}
        \begin{enumerate}[nosep, leftmargin=*]
            \item Lower the \textbf{VRAM Limiter} to a value equal to or less than your GPU's physical VRAM.
            \item Decrease the \textbf{Input Resolution \%} to 75\% or less.
            \item For videos, reduce the number of \textbf{AI Multithreading} threads.
            \item The application will attempt an automatic recovery from this error by reducing the processing tile size and retrying the operation.
        \end{enumerate}

    \item[\faTachometerAlt\ Error: "cannot convert float NaN to integer"]
        \textbf{Diagnosis:} GPU driver timeout (TDR - Timeout Detection and Recovery), often caused by hardware overload or overheating.
        \textbf{Solution:} Restart the process \textbf{without deleting the generated frames folder}. The application will detect the existing frames and resume the task from the point of failure.
\end{description}

% =======================================================================================
%   SECTION 7: ADVANCED TECHNICAL ARCHITECTURE
% =======================================================================================
\setsectioncolor{ArchColor}
\section{Software Architecture Analysis}

\subsection{\faCogs\ Inference Engine and Hardware Abstraction}
Warlock-Studio is built upon a multi-layered inference engine powered by \textbf{ONNX Runtime}. This system abstracts the underlying hardware and prioritizes Execution Providers to maximize performance:
\begin{enumerate}[leftmargin=*]
    \item \textbf{CUDA (\texttt{CUDAExecutionProvider}):} The highest performance option, leveraging the parallel computing architecture of NVIDIA GPUs.
    \item \textbf{DirectML (\texttt{DmlExecutionProvider}):} If CUDA is not available, the system falls back to DirectML. This Microsoft API translates neural network operations into native \textbf{DirectX 12} calls, ensuring broad hardware compatibility (NVIDIA, AMD, Intel).
    \item \textbf{CPU (\texttt{CPUExecutionProvider}):} This is the last resort provider. If no GPU acceleration is viable, the application runs the model on the CPU, guaranteeing universal functionality at the cost of significantly lower performance.
\end{enumerate}

\subsection{\faThLarge\ Dynamic Tiling and Memory Management}
To process high-resolution images and videos that would exceed available VRAM, the application implements a "tiling" system. Each frame is subdivided into fragments (tiles) of a size dynamically calculated based on the user-configured \textbf{VRAM Limiter}. If an out-of-memory (OOM) error occurs, the system can autonomously reduce the tile size and retry the operation, providing a robust recovery mechanism.

\subsection{\faSyncAlt\ Resume and Checkpointing Functionality}
If a video process is interrupted (either by the user or by an error), the frames already processed and written to disk are preserved. Upon restarting the same task, the \inlinecode{check\_video\_upscaling\_resume} function detects these partial files and resumes the processing pipeline from the last pending frame, saving a significant amount of computation time.

\subsection{\faBolt\ Asynchronous Frame Writing}
During video upscaling, the frames processed by the GPU are placed in a queue managed by a separate writer thread. This decouples the GPU processing (very fast) from the disk I/O operations (slower), allowing the GPU to begin processing the next batch of frames without waiting for the previous batch to be physically written to disk.

% =======================================================================================
%   SECTION 8: TECHNICAL GLOSSARY
% =======================================================================================
\setsectioncolor{GlossaryColor}
\section{Glossary}
\begin{description}[leftmargin=*, style=nextline, itemsep=0.8em]
    \item[ONNX Runtime] (Open Neural Network Exchange) A high-performance, cross-platform inference engine for AI models. It allows Warlock-Studio to run models in a hardware-agnostic manner.
    \item[CUDA] (Compute Unified Device Architecture) A parallel computing platform and programming model API created by NVIDIA. It enables general-purpose acceleration on NVIDIA GPUs.
    \item[DirectML] (Direct Machine Learning) A low-level Microsoft API that uses DirectX 12 to provide GPU-accelerated AI on a wide range of DX12-compatible hardware.
    \item[VRAM] (Video RAM) High-speed random-access memory dedicated to a graphics card, used to store textures, framebuffers, and other data critical for rendering and computation on the GPU.
    \item[Tiling] A technique of dividing a large image into smaller "tiles" to be processed individually. It is an essential mechanism for handling resolutions that exceed available VRAM.
    \item[Codec] (Coder-Decoder) A software or hardware algorithm/device that compresses and decompresses digital video data. Examples of software codecs are x264 (H.264) and x265 (HEVC). Hardware codecs (NVENC, AMF, QSV) use dedicated encoders on the GPU to accelerate this process.
\end{description}

% =======================================================================================
%   SECTION 9: SUPPORT & CONTRIBUTIONS
% =======================================================================================
\setsectioncolor{SupportColor}
\section{Support and Community}
\begin{itemize}[leftmargin=*]
    \item \textbf{\faBug\ Reporting Issues:} If you encounter a reproducible bug, please open an "Issue" on the GitHub repository. It is essential to attach the \texttt{error\_log.txt} file for effective diagnosis.
    \item \textbf{\faCodeBranch\ Code Contributions:} Contributions to the source code are welcome. It is recommended to follow the standard workflow: fork the repository, create a new branch for the feature or fix, and submit a "Pull Request" for review.
    \item \textbf{\faEnvelope\ Direct Contact:} For general inquiries or technical support that does not constitute a software bug, you can contact the author at \href{mailto:negroayub97@gmail.com}{\texttt{negroayub97@gmail.com}}.
\end{itemize}
\vspace{1cm}
\centering
\textbf{Thank you for using Warlock-Studio.}

% =======================================================================================
%   END OF DOCUMENT
% =======================================================================================
\end{document}