## 3 Proposed Method
### Dynamic Bit-Level Encoding Algorithm (DEA)  
This part of the study introduces the novel dynamic encoding algorithm (DEA), developed to provide a flexible and universal solution for a variety of applications. To enhance clarity, the algorithm was divided into steps, which are illustrated in a flowchart presented in Figure 7. The phrase \"Do for each segment\" appears at the first step of the developed algorithm, accompanied by an asterisk indicating that the algorithm can also be applied to an entire image without segmentation. Furthermore, tests were performed both with and without segmentation to assess the algorithm's performance in each scenario. All operations within the algorithm were executed for either the entire image or its individual segments. The developed encoding algorithm is described in greater detail at the end of this section, along with a small example to enhance understanding. **Step 1:** Initially, the segmented or entire image is used as input, and the RGB values of each pixel within the data packet is extracted. For example, the red value ranges between 0 and 255. These values are planned to be converted into characters based on their corresponding ASCII codes; for instance, if the red value is 65, it is stored as \"A\", and if it is 99, it is stored as \"c\". Once all pixel values have been converted into characters, the algorithm calculates the frequency with which each character is immediately  
Figure 6: Segment data structure. Figure 7: Flowchart of the DEA (Do for each segment). followed by another. This process aims to identify recurring consecutive characters and their associated frequencies. For each character, the subsequent characters are sorted in descending order based on their frequency values. The aim of this approach is to enable a more straightforward analysis by identifying how often specific characters are followed by others. **Step 2:** The HCA is based on the fundamental principle of representing frequently occurring characters in a text with fewer bits, while less frequent characters are represented with longer bit sequences [23]. A critical aspect of the algorithm is calculating the number of palette entries, which ensures that characters frequently following a given character are assigned shorter bit lengths. Conversely, less frequent characters are allocated bit lengths that are efficient without being excessively long. This strategy optimizes the encoding process by balancing the bit-length allocation, thereby improving both compression efficiency and data representation. Therefore, it is crucial to divide the characters that follow each given character into two distinct groups. This approach constitutes a unique feature that distinguishes the developed encoding algorithm from prior studies in the literature. By dynamically determining the number of palette entries according to the specific characteristics of the input image, the proposed algorithm achieves a more efficient and versatile encoding solution, enhancing its adaptability and overall performance. Since RGB values range between 0 and 255, the characters that can follow any given character can have a maximum of 255 different possibilities. Therefore, the condition Group 1 + Group 2 \(\leq\) 255 must always be satisfied. Determining the optimal number of characters in Group 1 and Group 2 would require repeatedly executing the entire encoding process within a loop. However, this approach poses a significant risk of excessively long runtime. During the study, a specialized mathematical model was developed to calculate the optimal number of palette entries, eliminating the need to run the entire algorithm iteratively in a loop. While developing this equation, several variable parameters were considered, including the number of nodes in the Huffman tree and the bit lengths of characters at the leaf nodes. By incorporating these factors, the model ensures a balanced and efficient determination of palette entries, optimizing the encoding process.