Character rendering method based on modular cache, embedded device and storage medium
By establishing a modular cache library in embedded devices, the text to be rendered is split and retrieved, solving the problem of repetitive rendering calculations in embedded devices, thereby reducing CPU load and improving rendering efficiency.
Patent Information
- Application Number
- CN202511055954.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-07-30
- Publication Date
- 2025-11-21
AI Technical Summary
Existing text rendering methods for embedded devices require repeated calculations for each character, which leads to performance bottlenecks and low rendering efficiency, especially on resource-constrained devices.
A modular caching library is established, including sentence-level, phrase-level, and character-level modules. The text to be rendered is split according to the retrieval priority and the unretrieved text is rendered in batches. Encoding is used to improve search efficiency, the cache size and rendering mode are dynamically adjusted, and a probabilistic model is built to predict commonly used phrases and characters.
Significantly reduces CPU load, improves rendering efficiency, reduces redundant calculations, increases text display speed by 3-10 times, and reduces CPU usage by 60%.
Smart Images

Figure CN120994286A_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the field of character rendering, and particularly relates to a character rendering method based on modular caching, an embedded device and a storage medium. BACKGROUND
[0002] Currently, the UI system of an embedded device displays characters mainly through real-time rendering, that is, when displaying characters, pixel dot arrays or vector data corresponding to each character are acquired one by one, and then the data is mapped to a display buffer. A simple rendering method uses bitmap fonts, and each character corresponds to a fixed dot array image; high-quality display uses TrueType vector fonts, and character contour information is rendered into bitmap data through a font engine.
[0003] In the existing rendering method, rendering data needs to be recalculated for each character every time, and especially the vector font conversion process involves complex mathematical calculations, which causes a serious performance bottleneck on resource-limited embedded devices and low rendering efficiency. SUMMARY
[0004] Therefore, it is necessary to provide a character rendering method based on modular caching, an embedded device and a storage medium in view of the above technical problems.
[0005] In a first aspect, an embodiment of the present application provides a character rendering method based on modular caching, and the method comprises the following steps.
[0006] A character modular caching library is established, and the character modular caching library comprises a sentence-level module, a word group-level module and a character-level module; the sentence-level module is used to store rendered sentences; the word group-level module is used to store rendered word groups; and the character-level module is used to store rendered characters.
[0007] A text to be rendered is acquired, and the text to be rendered is split into sentences, word groups and characters to be rendered.
[0008] The sentences, word groups and characters to be rendered are searched in the sentence-level module, word group-level module and character-level module in turn according to a search priority.
[0009] The searched sentences, word groups and characters to be rendered are acquired, and characters not searched are batch-rendered.
[0010] In some embodiments, the sentence-level module is used to store rendered sentences and codes thereof; the word group-level module is used to store rendered word groups and codes thereof; and the character-level module is used to store rendered characters and codes thereof, and the searching of the sentences, word groups and characters to be rendered in the sentence-level module, word group-level module and character-level module in turn according to the search priority comprises the following steps.
[0011] respectively calculate the encodings of the sentence, the phrase, and the character to be rendered;
[0012] According to the search priority, search the corresponding encodings in the sentence level module, the phrase level module, and the character level module in sequence to determine whether the sentence, the phrase, and the character to be rendered exist.
[0013] In some embodiments, the method further comprises:
[0014] respectively calculate the encodings of the sentence, the phrase, and the character to be rendered based on the font file number, the font size, and the Hash calculated text content of the sentence, the phrase, and the character to be rendered.
[0015] In some embodiments, the splitting the text to be rendered into phrases comprises:
[0016] According to the usage frequency and the rendering time saving, calculate the scores of the phrases in different split form combinations respectively;
[0017] select the phrase in the split form combination with the highest score.
[0018] In some embodiments, the method further comprises:
[0019] According to the memory usage, the CPU load, and the rendering queue depth, calculate the resource score;
[0020] According to the resource score, select the corresponding rendering mode.
[0021] In some embodiments, the method further comprises:
[0022] According to the usage frequency, the recent access time, and the rendering cost, calculate the cache value score of the sentence level module, the phrase level module, and the character level module;
[0023] When the memory is less than the memory threshold, remove the modules with a cache value score lower than the score threshold.
[0024] In some embodiments, the method further comprises:
[0025] According to the memory usage, dynamically adjust the size of the character modular cache library.
[0026] In some embodiments, the method further comprises:
[0027] According to the sequence relationship of the phrases and the characters, construct a probability model;
[0028] Use the probability model to predict the phrases and the characters to be rendered, and add the phrases and the characters to be rendered to the character modular cache library.
[0029] In a second aspect, an embodiment of the present application provides an embedded device, comprising a memory and a processor, wherein the memory stores a computer program, and the processor executes the computer program to implement the steps of the method in the first aspect.
[0030] In a third aspect, an embodiment of the present application provides a computer readable storage medium, which stores a computer program, and the computer program is executed by a processor to implement the steps of the method in the first aspect.
[0031] Compared with the prior art, the above method, embedded device and storage medium establish a modularized cache library of characters, acquire a text to be rendered, split the text to be rendered into sentences, word groups and characters to be rendered, search the sentences, word groups and characters to be rendered in the sentence module, word group module and character module in sequence according to a search priority, acquire the searched sentences, word groups and characters to be rendered, and batch render the characters not searched. The present application stores the rendered sentences, word groups and characters in the modularized cache library of characters. When the sentences, word groups and characters to be rendered are already stored in the modularized cache library of characters, they can be directly acquired by searching, without being rendered again, thereby solving the problem of repeated rendering calculation in the embedded device, and achieving the technical effects of significantly reducing CPU load and improving rendering efficiency. BRIEF DESCRIPTION OF DRAWINGS
[0032] Figure 1 FIG. 1 is a structural schematic diagram of an embedded device in an embodiment;
[0033] Figure 2 FIG. 3 is a flowchart of a text rendering method based on modularized cache in an embodiment;
[0034] Figure 3 FIG. 5 is an architectural schematic diagram of a modularized cache library of characters in an embodiment;
[0035] Figure 4 FIG. 7 is a flowchart of a search method in an embodiment;
[0036] Figure 5 FIG. 9 is a flowchart of a splitting method in an embodiment;
[0037] Figure 6 FIG. 11 is a flowchart of a rendering mode selection method in an embodiment;
[0038] Figure 7 FIG. 13 is a flowchart of a module removal method in an embodiment;
[0039] Figure 8 FIG. 15 is a flowchart of a prediction method in an embodiment. DETAILED DESCRIPTION
[0040] In order to more clearly illustrate the technical solutions of the embodiments of the present application, the drawings required to be used in the embodiments description will be briefly introduced as follows. Obviously, the drawings in the following description only show some examples or embodiments of the present application, and for those skilled in the art, the present application can be applied to other similar scenarios without creative labor on the basis of these drawings. Unless the context clearly indicates otherwise or otherwise stated, the same reference numbers in the drawings represent the same structure or operation.
[0041] As shown in the present application and claims, unless the context clearly indicates otherwise or otherwise stated, the words "one", "a", "an", and / or "the" do not specifically refer to the singular, but can also include the plural. Generally speaking, the terms "comprising" and "including" only indicate the inclusion of the steps and elements explicitly identified, and these steps and elements do not constitute an exclusive list, and the method or device can also include other steps or elements.
[0042] Although the present application makes various references to certain modules in the apparatus according to the embodiments of the present application, however, any number of different modules can be used and run on a computing device and / or processor. The modules are only illustrative, and different aspects of the apparatus and method can use different modules.
[0043] It should be understood that when a unit or module is described as being "connected", "coupled" to other units, modules or blocks, it can mean that it is directly connected or coupled to the other units, modules or blocks, or it is in communication with the other units, modules or blocks, or there can be intermediate units, modules or blocks, unless the context clearly indicates otherwise. The term "and / or" used herein can include any and all combinations of one or more related listed items.
[0044] The text rendering method based on modular caching provided in the present application can be applied to an embedded device as shown in Figure 1 , for example. As shown in Figure 1As shown, the embedded device can include a processor 102 and a memory 104 for storing data, wherein the processor 102 can include, but is not limited to, a processing device such as a microprocessor MCU or a programmable logic device FPGA. The processor establishes a text modularization cache library, which includes a sentence-level module, a phrase-level module, and a character-level module; the sentence-level module is used to store rendered sentences; the phrase-level module is used to store rendered phrases; and the character-level module is used to store rendered characters. The text to be rendered is obtained, and the text to be rendered is split into sentences, phrases, and characters to be rendered. The sentences, phrases, and characters to be rendered are retrieved in the sentence-level module, phrase-level module, and character-level module in turn according to retrieval priorities. The retrieved sentences, phrases, and characters to be rendered are obtained, and the characters not retrieved are batch-rendered. The memory is used to store the text modularization cache library.
[0045] The above-mentioned embedded device can also include a transmission device 106 for communication functions and an input / output device 108. Those skilled in the art can understand that, Figure 1 The structure shown is only schematic and does not limit the structure of the above-mentioned embedded device. For example, the embedded device can also include more or fewer components than Figure 1 or have a different configuration than Figure 1 shown.
[0046] As shown in Figure 2 An embodiment of the present application provides a text rendering method based on modularization cache. The method is applied to an embedded device in Figure 2 for example, and includes the following steps:
[0047] S202: Establish a text modularization cache library.
[0048] As shown in Figure 3 The text modularization cache library includes a sentence-level module, a phrase-level module, and a character-level module; the sentence-level module is used to store rendered complete sentences and has a fixed expression; the phrase-level module is used to store rendered common phrases, usually 2-5 characters; and the character-level module is used to store rendered single character texts. The sentence-level module has a high priority, the phrase-level module has a medium priority, and the character-level module has a low priority.
[0049] In the actual rendering interface in this embodiment, many text contents often appear repeatedly, such as button text, titles, and the like. Therefore, a text modularization cache library is established to store sentences, phrases, and texts that are prone to appear.
[0050] S204: Obtain text to be rendered, and split the text to be rendered into sentences, phrases, and characters to be rendered.
[0051] S206: Retrieving the sentence, phrase and character to be rendered in the sentence level module, phrase level module and character level module in turn according to the retrieval priority.
[0052] Specifically, in the sentence level module, it is first searched whether there is a sentence to be rendered, if not, in the phrase level module, it is searched whether there is a phrase to be rendered, if not, in the character level module, it is searched whether there is a character to be rendered.
[0053] When the text needs to be rendered, the text content is first analyzed, which is split into appropriate modules, and then the character modular cache library is searched. If the rendered content is found, it is directly taken and used, and the time-consuming rendering calculation is skipped; only the first appearing content needs the complete rendering process, and the rendering result is stored in the character modular cache library for future use.
[0054] S208: Obtaining the retrieved sentence, phrase and character to be rendered, and batch rendering the characters not retrieved.
[0055] The retrieved sentence, phrase and character to be rendered can be directly used, all the characters to be rendered are organized into a rendering package, and the characters in the rendering package are rendered.
[0056] When rendering is needed, a single rendering instruction is executed, and all characters are directly mapped to the display buffer through memory copy, without word-by-word and pixel-by-pixel processing.
[0057] Memory mapping formula:
[0058] Display buffer address = base address + (y x screen width + x) x pixel byte number
[0059] Character mapping = memory copy (character cache address, display buffer address, block size)
[0060] Through the above mapping mode, the character display speed is improved by 3-10 times, especially when displaying a large amount of text, the effect is obvious, and the CPU occupancy is reduced by 60%.
[0061] Based on the steps S202-S208, the text modularization cache library is established, the text to be rendered is obtained, the text to be rendered is split into sentences, word groups and characters to be rendered, the sentences, word groups and characters to be rendered are searched in the sentence module, word group module and character module in sequence according to the search priority, the searched sentences, word groups and characters to be rendered are obtained, and the characters not searched are batch rendered. By establishing the text modularization cache library to store the rendered sentences, word groups and characters, when the sentences, word groups and characters to be rendered have been stored in the text modularization cache library, they can be directly obtained by searching without re-rendering, thereby solving the problem of repeated rendering calculation in the embedded device, realizing significant reduction of CPU load, avoiding repeated execution of time-consuming vector to bitmap conversion process, supporting reuse of rendering results among various display scenarios, and reducing redundant calculation.
[0062] In some embodiments, in order to quickly search the cache content, a unique code is needed to represent each text module. The sentence module is used to store the rendered sentences and the codes thereof; the word group module is used to store the rendered word groups and the codes thereof; and the character module is used to store the rendered characters and the codes thereof.
[0063] As shown in Figure 4 , the searching of the sentences, word groups and characters to be rendered in the sentence module, word group module and character module in sequence according to the search priority comprises:
[0064] S402: Calculate the codes of the sentences, word groups and characters to be rendered respectively.
[0065] Specifically, based on the font file number, font size and Hash calculated text content of the sentences, word groups and characters to be rendered, the codes of the sentences, word groups and characters to be rendered are calculated respectively, as shown in the following formula:
[0066] ModuleID = (FontID ×2 24 ) + (FontSize × 2 16 ) + Hash(TextContent)
[0067] Wherein, ModuleID represents the code, FontID represents the font file number, FontSize represents the font size, and TextContent represents the text content.
[0068] In the above formula, the font, font size and text content information are encoded into a numerical value, ensuring that the same characters with different fonts or sizes are regarded as different modules. The Hash function is used to process the text content part, so that the calculation is simple and efficient.
[0069] S404: According to the search priority, search in the sentence level module, phrase level module and character level module in turn to determine whether the sentence, phrase and character to be rendered exist.
[0070] In this embodiment, the efficiency of search can be improved by using encoding search.
[0071] In some embodiments, as shown in FIG. 6, the method further comprises: Figure 5 As shown in FIG. 5, splitting the text to be rendered into phrases comprises:
[0072] S502: Calculate the score of the phrase in different split form combinations according to the frequency of use and rendering time saving;
[0073] S504: Select the phrase in the split form combination with the highest score.
[0074] In this embodiment, the text to be displayed is intelligently analyzed and split into the best combination unit. For example, "thank you for using" can be split into ["thank you" + "for" + "using"], instead of being processed word by word.
[0075] Phrase combination score = frequency of use × 80% + rendering time saving × 20%
[0076] The frequency of use and rendering time saving are normalized. The higher the frequency of use and the more time saved after combination, the higher the score, and the phrase is preferentially selected.
[0077] In some embodiments, as shown in FIG. 6, the method further comprises: Figure 6
[0078] S602: Calculate the resource score according to the memory usage, CPU load and rendering queue depth;
[0079] S604: Select the corresponding rendering mode according to the resource score.
[0080] In this embodiment, the resource state of the embedded device is detected according to a period, and the resource score is calculated through three key indicators of memory usage, CPU load and rendering queue depth. The memory usage directly reflects the available memory situation, the CPU load represents the processing capacity margin, and the rendering queue depth reflects the system busy degree. Through this resource score, the appropriate rendering mode can be automatically selected.
[0081] In an example embodiment, the rendering mode includes a high-quality rendering mode, a balanced rendering mode and an energy-saving rendering mode. According to the resource score, the three rendering modes are switched. When the resource score is high, the high-quality rendering mode is used; when the resource score decreases, the mode is downgraded to a more energy-saving mode.
[0082] Each rendering mode is different in sub-pixel rendering, cache range and anti-aliasing level. For example, in the energy-saving rendering mode, sub-pixel rendering is turned off (to save memory), only single characters are cached (to reduce cache space), and 2-bit grayscale anti-aliasing is used (to reduce memory occupation). This gradient degradation ensures that basic text rendering display functions can still be maintained even in an extremely low resource state.
[0083] The calculation formula of the resource score is as follows:
[0084] ResourceScore = 0.4 x memory usage rate + 0.2 x CPU load + 0.2 x rendering queue depth
[0085] wherein ResourceScore represents the resource score, and the memory usage rate, load and rendering queue depth are normalized.
[0086] When ResourceScore < 0.6, the high-quality rendering mode is adopted, when 0.6 < ResourceScore < 0.8, the balanced rendering mode is adopted, and when ResourceScore > 0.8, the energy-saving rendering mode is adopted.
[0087] In some embodiments, as shown in FIG. 6, the method further comprises: Figure 7
[0088] S702: calculating cache value scores of the sentence-level module, the phrase-level module and the character-level module according to the usage frequency, the recent access time and the rendering cost;
[0089] S704: when the memory is less than the memory threshold, removing the modules whose cache value scores are lower than a score threshold.
[0090] The calculation formula of the cache value score is as follows:
[0091] CacheValueScore = W1 x usage frequency + W2 x recent access time + W3 x rendering cost
[0092] wherein W1, W2 and W3 represent corresponding weights, and the usage frequency, the recent access time and the rendering cost are normalized.
[0093] The cache value score is used to evaluate the value of each module, and comprehensively considers the usage frequency (hotness), the recent access time (temporal locality) and the rendering cost (the cost of regeneration). When the cache needs to be eliminated, the modules with lower value scores are preferentially removed.
[0094] In some embodiments, the method further comprises dynamically adjusting the size of the text modularization cache library according to the memory usage rate.
[0095] The calculation formula of the size of the word modular cache library is:
[0096] The size of the word modular cache library = basic cache size × (0.5 + 2.0 × (1.0 - memory usage rate))
[0097] When the memory is sufficient, the cache space is expanded to improve the hit rate; when the memory is tight, the cache is shrunk to release resources. This dynamic adjustment strategy ensures that the memory resources are reasonably allocated.
[0098] In some embodiments, as shown in Figure 8 the method further includes:
[0099] S802: constructing a probability model according to the sequence of the word groups and the characters;
[0100] S804: predicting the word groups and the characters to be rendered by using the probability model, and adding the word groups and the characters to be rendered to the character modular cache library.
[0101] According to the sequence of the word groups and the characters, the probability model is trained to predict the characters that are likely to appear next and to load them in advance when resources permit. For example, after rendering "hello", it is possible to predict that "world" or "please ask" and other common collocations are likely to appear next, and to add them to the cache in advance. This active preloading strategy can significantly improve the cache hit rate and reduce the rendering delay.
[0102] It should be understood that although each step in the above flowchart is displayed in sequence according to the arrow, these steps are not necessarily executed in sequence according to the arrow. Unless otherwise specified herein, the execution of these steps is not strictly limited in sequence, and these steps can be executed in other orders. Moreover, at least part of the steps in the above flowchart can include multiple steps or multiple stages, which are not necessarily executed at the same time, but can be executed at different times, and the execution sequence of these steps or stages is not necessarily sequential, but can be executed in rotation or alternation with at least part of other steps or steps or stages in other steps.
[0103] In an embodiment, the present embodiment provides a computer readable storage medium having a computer program stored thereon, wherein the computer program is executed by a processor to implement the steps in any of the above character rendering methods based on modular cache.
[0104] Those skilled in the art can understand that all or part of the processes in the above-mentioned embodiment methods can be completed by instructing the relevant hardware through a computer program. The computer program can be stored in a non-volatile computer readable storage medium, and when the computer program is executed, the processes of the above-mentioned embodiments of the methods can be included. Any reference to memory, storage, database or other medium used in each embodiment provided by the present application can include at least one of non-volatile and volatile memory. Non-volatile memory can include read-only memory (ROM), magnetic tape, floppy disk, flash memory or optical memory. Volatile memory can include random access memory (RAM) or external cache memory. As an illustration but not limitation, RAM can be in various forms, such as static random access memory (SRAM) or dynamic random access memory (DRAM).
[0105] Each technical feature of the above embodiments can be combined arbitrarily. In order to make the description simple, all possible combinations of each technical feature in the above embodiments are not described, but as long as the combination of the technical features does not exist, it should be considered as the scope of the present application.
[0106] The above embodiments only express several implementation manners of the present application, and the description is more specific and detailed, but it should not be understood as a limitation on the scope of the patent. It should be pointed out that for those skilled in the art, without departing from the concept of the present application, some modifications and improvements can be made, which are all within the protection scope of the present application. Therefore, the protection scope of the patent of the present application should be subject to the appended claims.
Claims
1. A text rendering method based on modular caching, characterized in that, The method includes: A modular text caching library is established, comprising sentence-level modules, phrase-level modules, and character-level modules; the sentence-level modules are used to store rendered sentences; the phrase-level modules are used to store rendered phrases; and the character-level modules are used to store rendered text. Obtain the text to be rendered, and split the text to be rendered into sentences, phrases, and characters to be rendered; The sentence, phrase, and text to be rendered are retrieved sequentially in the sentence-level module, phrase-level module, and character-level module according to the retrieval priority. The retrieved sentences, phrases, and text to be rendered are obtained, and the unretrieved text is rendered in batches.
2. The method according to claim 1, characterized in that, The sentence-level module is used to store rendered sentences and their codes; the phrase-level module is used to store rendered phrases and their codes; the character-level module is used to store rendered text and its codes. The step of retrieving the sentence, phrase, and text to be rendered sequentially from the sentence-level module, phrase-level module, and character-level module according to retrieval priority includes: Calculate the encoding of the sentence, phrase, and text to be rendered respectively; According to the search priority, the corresponding encoding is searched in the sentence-level module, phrase-level module, and character-level module in turn to determine whether the sentence, phrase, and text to be rendered exist.
3. The method according to claim 2, characterized in that, The calculation of the encoding of the sentence, phrase, and text to be rendered includes: Based on the font file number, font size, and hash-calculated text content of the sentence, phrase, and text to be rendered, the encoding of the sentence, phrase, and text to be rendered is calculated respectively.
4. The method according to claim 1, characterized in that, The text to be rendered is split into phrases, including: Based on usage frequency and rendering time savings, scores for word groups with different splitting methods are calculated. Choose the word group with the highest score in the splitting method.
5. The method according to claim 1, characterized in that, The method further includes: Resource scores are calculated based on memory usage, CPU load, and rendering queue depth. Select the corresponding rendering mode based on the resource score.
6. The method according to claim 1, characterized in that, The method further includes: The cache value scores of the sentence-level module, phrase-level module, and character-level module are calculated based on usage frequency, recent access time, and rendering cost. When memory is less than the memory threshold, remove modules whose cache value score is lower than the score threshold.
7. The method according to claim 1, characterized in that, The method further includes: The size of the text modular cache library is dynamically adjusted based on memory usage.
8. The method according to claim 1, characterized in that, The method further includes: Construct a probability model based on the order in which phrases and words appear; The probability model is used to predict the phrases and text to be rendered, and the phrases and text to be rendered are added to the text modular cache library.
9. An embedded device comprising a memory and a processor, the memory storing a computer program, characterized in that, When the processor executes the computer program, it implements the steps of the method according to any one of claims 1 to 8.
10. A computer-readable storage medium having a computer program stored thereon, characterized in that, When the computer program is executed by a processor, it implements the steps of the method according to any one of claims 1 to 8.