Multi-thread image printing method, printing controller, medium and product
By using a multi-threaded image printing method, the image is divided into multiple data frames for parallel processing. Combined with buffer sorting and real-time monitoring of buffer usage, the problem of low efficiency in single-threaded processing is solved, and efficient image printing processing is achieved.
Patent Information
- Application Number
- CN202511468329.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-10-15
- Publication Date
- 2025-11-11
AI Technical Summary
In existing technologies, the single-threaded processing method of image printing controllers results in excessively long compression processing time for large-size images, making it difficult to meet the needs of fast printing and leading to low printing efficiency.
A multi-threaded image printing method is adopted, which divides the original image into multiple data frames with sequence numbers and complexity. The corresponding compression algorithm is selected according to the complexity, and multiple parallel worker threads are used for processing. The data allocation rate is dynamically adjusted by sorting the buffer area and monitoring the buffer usage of the printing device in real time.
It significantly improves image data processing efficiency, ensures data order and print quality, avoids device buffer overflow, and achieves efficient printing processing.
Smart Images

Figure CN120929030A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of data processing, and more particularly to a multi-threaded image printing method, a print controller, a medium, and a product. Background Technology
[0002] With the rapid development of the digital age, image printing technology has been widely used in office, advertising, and printing fields. In the process of large-format image printing, data processing and transmission control of the original image are necessary to ensure print quality and efficiency. The print controller, as the core component connecting the computer and printing equipment, plays a crucial role in the image data processing process.
[0003] In related technologies, print controllers typically employ a single-threaded processing method to compress the original image. Specifically, the print controller divides the original image into multiple image blocks, and then uses a uniform compression algorithm to compress each image block sequentially. After compression, the print controller transmits the compressed data to the printing device for printing.
[0004] However, due to the use of a single-threaded processing method, image blocks can only be compressed one by one in sequence. When processing large images, the overall compression processing time is long, which makes it difficult to meet the needs of fast printing and results in low printing efficiency. Summary of the Invention
[0005] This application provides a multi-threaded image printing method, a print controller, a medium, and a product for improving printing processing efficiency.
[0006] Firstly, this application provides a multi-threaded image printing method applied to a print controller. The method includes: dividing the original image to be processed into multiple data frames based on preset image segmentation rules, with different data frames corresponding to different sequence numbers and different complexities. The sequence number is used to indicate the positional order of the data frame in the original image, and the complexity is used to indicate the compression difficulty of the data frame; determining the compression algorithm corresponding to each of the multiple data frames based on the complexity; allocating the multiple data frames to multiple parallel working threads to obtain multiple compressed data packets with the same sequence number as the corresponding data frame, and the working threads performing compression operations according to the compression algorithm corresponding to the data frame; passing the multiple compressed data packets to a buffer to obtain an ordered compressed data stream, and the buffer performing an ascending sorting operation based on the sequence number of the compressed data packets; sending the ordered compressed data stream sequentially to the printing device and monitoring the buffer occupancy of the printing device in real time; when the buffer occupancy exceeds the buffer occupancy threshold, reducing the rate of allocating data frames to the multiple parallel working threads until the buffer occupancy is reduced to the buffer occupancy threshold.
[0007] By employing the above technical solution, the print controller segments the original image to be processed into multiple data frames with sequence numbers and complexity levels. Based on the complexity, it selects the corresponding compression algorithm for each data frame, achieving differentiated processing for regions of varying image complexity. The print controller uses multiple parallel threads to process the data frames simultaneously, significantly improving image data processing efficiency. The print controller sorts the compressed data packets in ascending order of sequence number through a buffer, ensuring data ordering. Simultaneously, the print controller monitors the print device's buffer usage in real time and dynamically adjusts the data allocation rate to prevent buffer overflow. This adaptive multi-threaded processing method based on data characteristics ensures print quality while improving processing efficiency, alleviating the inefficiency of traditional single-threaded processing methods.
[0008] In conjunction with some embodiments of the first aspect, in some embodiments, based on preset image segmentation rules, the original image to be processed is segmented into multiple data frames, specifically including: dividing the original image into macroblocks of a preset size, calculating image feature parameters for each macroblock, the size of the macroblock being M×N pixels, and the image feature parameters including image entropy value and / or edge density; generating an image complexity distribution map based on the image feature parameters, the image complexity distribution map including high-complexity region images and low-complexity region images; segmenting the high-complexity region images using a first preset size to obtain a first set of data frames, the first preset size being P×Q pixels; segmenting the low-complexity region images using a second preset size to obtain a second set of data frames, the second preset size being R×S pixels, where P×Q is less than R×S; and assigning sequence numbers to the first set of data frames and the second set of data frames sequentially based on the original image.
[0009] By employing the above technical solution, the print controller initially divides the original image based on macroblocks of a preset size, calculates the image feature parameters of each macroblock to generate an image complexity distribution map, and achieves accurate assessment of the image content complexity. For high-complexity regions, a smaller segmentation size (P×Q) is used, while for low-complexity regions, a larger segmentation size (R×S) is used. This differentiated segmentation strategy ensures the processing accuracy of complex regions while avoiding over-segmentation of simple regions. By assigning sequence numbers to the segmented data frames, the positional order of the data is ensured.
[0010] In conjunction with some embodiments of the first aspect, in some embodiments, an image complexity distribution map is generated based on image feature parameters. The image complexity distribution map includes high-complexity region images and low-complexity region images. Specifically, this includes: inputting the image feature parameters of the macroblock into a complexity prediction model to obtain the predicted complexity of the macroblock; determining the high-complexity region images and low-complexity region images based on the predicted complexity; and obtaining the image complexity distribution map based on the high-complexity region images and low-complexity region images.
[0011] By adopting the above technical solution, the print controller inputs the image feature parameters of macroblocks into the complexity prediction model, achieving intelligent prediction of image region complexity. Based on the predicted complexity of macroblocks, high and low complexity regions are identified, and an image complexity distribution map is generated for subsequent differential processing. This machine learning-based complexity prediction method is more accurate and intelligent than the traditional fixed threshold judgment method, better adapting to the characteristics of different types of images, improving the accuracy and adaptability of complexity assessment, and laying the foundation for efficient differential processing.
[0012] In conjunction with some embodiments of the first aspect, in some embodiments, the compression algorithm corresponding to each of the multiple data frames is determined according to the complexity, specifically including: obtaining the printing mode at the current moment, the printing mode including quality priority mode, speed priority mode and equalization mode; determining the compression parameter matrix based on the printing mode, the compression parameter matrix including compression quality parameters and compression rate parameters; and determining the compression algorithm corresponding to each of the multiple data frames according to the compression parameter matrix and the complexity of the data frames.
[0013] By employing the above technical solution, the print controller acquires the current printing mode (quality-first, speed-first, or balanced mode) and determines a compression parameter matrix containing compression quality and compression rate parameters based on the printing mode, thus achieving dynamic adjustment of the compression process. The print controller combines the complexity of the data frame with the compression parameter matrix to determine the compression algorithm, enabling optimization of the compression process according to user needs and image features. This adaptive compression scheme based on printing mode not only meets the printing requirements of different scenarios but also balances the relationship between compression quality and processing speed, improving the system's flexibility and practicality, and better adapting to the needs of different application scenarios.
[0014] In conjunction with some embodiments of the first aspect, in some embodiments, based on complexity, the compression algorithms corresponding to multiple data frames are determined respectively. Specifically, this includes: matching the complexity with a complexity range in a preset complexity range-compression algorithm mapping table, which includes multiple complexity ranges, with different complexity ranges corresponding to different compression algorithms; if the complexity falls into a low complexity range, the data frame is determined to correspond to a lossless compression algorithm; if the complexity falls into a medium complexity range, the data frame is determined to correspond to a hybrid compression algorithm; if the complexity falls into a high complexity range, the data frame is determined to correspond to a lossy compression algorithm.
[0015] By adopting the above technical solution, the printing controller uses a preset complexity range-compression algorithm mapping table to associate different complexity ranges with corresponding compression algorithms, achieving intelligent selection of compression algorithms. Lossless compression algorithms are used for low complexity ranges, hybrid compression algorithms for medium complexity ranges, and lossy compression algorithms for high complexity ranges. This differentiated compression strategy fully considers the characteristics of the image content. By automatically selecting the compression algorithm based on the complexity range, the quality loss or inefficiency caused by using a fixed compression algorithm is avoided, improving the targeting and effectiveness of the compression process and achieving an optimal balance between compression quality and efficiency.
[0016] In conjunction with some embodiments of the first aspect, in some embodiments, after the step of allocating multiple data frames to multiple parallel working threads to obtain multiple compressed data packets with the same sequence number as the corresponding data frames, the method further includes: obtaining the data processing capability of each working thread, wherein the data processing capability is used to represent the average processing time of high-complexity data frames, the average processing time of medium-complexity data frames, and the average processing time of low-complexity data frames; dividing the multiple parallel working threads into high-complexity data frame working threads, medium-complexity data frame working threads, and low-complexity data frame working threads according to the data processing capability; and allocating data frames to the corresponding working threads according to the complexity range.
[0017] By adopting the above technical solution, this approach assesses the data processing capabilities of each worker thread by obtaining the average processing time for data frames of varying complexity, and classifies worker threads into different types accordingly. Worker threads are then assigned to the corresponding type based on data frame complexity, achieving specialized division of labor. This thread classification and task allocation scheme based on processing capability fully utilizes the processing characteristics of different threads, avoids the uneven processing efficiency caused by traditional random allocation methods, improves the overall efficiency of multi-threaded processing, and optimizes the utilization of computing resources.
[0018] In conjunction with some embodiments of the first aspect, in some embodiments, after the step of sequentially sending the ordered compressed data stream to the printing device, the method further includes: detecting the transmission status of the ordered compressed data stream; when an abnormal transmission status is detected, executing an abnormal handling process, the abnormal handling process including stopping the task processing of the working thread, suspending the segmentation operation of the original image, and storing the transmission progress information; when the transmission status is detected to have returned to normal, executing a recovery process, the recovery process including determining the transmission interruption position based on the transmission progress information, retransmitting the ordered compressed data stream that was not successfully transmitted at the transmission interruption position, resuming the segmentation operation of the original image, and executing the task processing of the working thread.
[0019] By adopting the above technical solution, the print controller monitors the transmission status of the ordered compressed data stream in real time. When an abnormal transmission status is detected, it executes an exception handling process that stops the worker thread, suspends the segmentation operation of the original image, and stores the transmission progress information. After the transmission status is detected to be normal, it executes a recovery process that includes determining the transmission interruption location based on the transmission progress information, retransmitting the ordered compressed data stream that was not successfully transmitted at the transmission interruption location, resuming the segmentation operation of the original image, and executing the worker thread's task processing. This complete exception handling mechanism can effectively cope with various abnormal situations during transmission, ensuring the reliability and continuity of data transmission.
[0020] In a second aspect, embodiments of this application provide a print controller, which includes: one or more processors and a memory; the memory is coupled to the one or more processors, and the memory is used to store computer program code, the computer program code including computer instructions, and the one or more processors call the computer instructions to cause the print controller to perform the method described in the first aspect and any possible implementation thereof.
[0021] Thirdly, embodiments of this application provide a computer program product containing instructions that, when the computer program product is run on a print controller, cause the print controller to perform the method described in the first aspect and any possible implementation thereof.
[0022] Fourthly, embodiments of this application provide a computer-readable storage medium including instructions that, when executed on a print controller, cause the print controller to perform the method described in the first aspect and any possible implementation thereof.
[0023] Understandably, the printer controller provided in the second aspect, the computer program product provided in the third aspect, and the computer storage medium provided in the fourth aspect are all used to execute the methods provided in the embodiments of this application. Therefore, the beneficial effects they can achieve can be referred to the beneficial effects in the corresponding methods, and will not be repeated here.
[0024] One or more technical solutions provided in the embodiments of this application have at least the following technical effects or advantages: 1. By adopting the above technical solution, the print controller segments the original image to be processed into multiple data frames with sequence numbers and complexity levels. Based on the complexity, it selects the corresponding compression algorithm for each data frame, achieving differentiated processing for regions of different image complexity. The print controller uses multiple parallel threads to process data frames simultaneously, significantly improving the processing efficiency of image data. The print controller sorts the compressed data packets according to their sequence numbers in ascending order through a buffer, ensuring data orderliness. Simultaneously, the print controller monitors the print device's buffer usage in real time and dynamically adjusts the data allocation rate to avoid buffer overflow. This adaptive multi-threaded processing method based on data characteristics ensures print quality while improving processing efficiency, alleviating the inefficiency problem of traditional single-threaded processing methods.
[0025] 2. By adopting the above technical solution, the print controller inputs the image feature parameters of macroblocks into the complexity prediction model, realizing intelligent prediction of image region complexity. Based on the predicted complexity of macroblocks, high and low complexity regions are identified, and an image complexity distribution map is generated to facilitate subsequent differential processing. This machine learning-based complexity prediction method is more accurate and intelligent than the traditional fixed threshold judgment method, and can better adapt to the characteristics of different types of images, improving the accuracy and adaptability of complexity assessment, and laying the foundation for efficient differential processing.
[0026] 3. By adopting the above technical solution, the print controller obtains the current printing mode (quality-first, speed-first, or balanced mode) and determines a compression parameter matrix containing compression quality and compression rate parameters based on the printing mode, thus achieving dynamic adjustment of the compression process. The print controller combines the complexity of the data frame and the compression parameter matrix to determine the compression algorithm, enabling the compression process to be optimized according to user needs and image features. This adaptive compression scheme based on printing mode not only meets the printing needs of different scenarios but also balances the relationship between compression quality and processing speed, improving the system's flexibility and practicality, and better adapting to different application scenarios. Attached Figure Description
[0027] Figure 1 This is a flowchart illustrating a multi-threaded image printing method in an embodiment of this application; Figure 2 This is another flowchart illustrating the multi-threaded image printing method in this application embodiment; Figure 3 This is a schematic diagram of the physical device structure of a printing controller in an embodiment of this application. Detailed Implementation
[0028] The terminology used in the following embodiments of this application is for the purpose of describing particular embodiments only and is not intended to be limiting of this application. As used in the specification of this application, the singular expressions “a,” “an,” “the,” “the,” and “this” are intended to include the plural expressions as well, unless the context clearly indicates otherwise. It should also be understood that the term “and / or” as used in this application refers to any or all possible combinations including one or more of the listed items.
[0029] Hereinafter, the terms "first" and "second" are used for descriptive purposes only and should not be construed as implying or suggesting relative importance or implicitly indicating the number of indicated technical features. Thus, a feature defined as "first" or "second" may explicitly or implicitly include one or more of that feature, and in the description of the embodiments of this application, unless otherwise stated, "multiple" means two or more.
[0030] The following describes the process of the method provided in this implementation. Please refer to [link / reference]. Figure 1 This is a flowchart illustrating a multi-threaded image printing method in an embodiment of this application.
[0031] S101. Based on the preset image segmentation rules, the original image to be processed is segmented into multiple data frames. Different data frames correspond to different sequence numbers and different complexities. The sequence number is used to indicate the position order of the data frame in the original image, and the complexity is used to indicate the compression difficulty of the data frame. Here, the original image refers to image data that has not yet been processed, such as an image to be printed sent from a computer to a print controller; the preset image segmentation rules refer to a set of pre-defined rules for determining how to divide the original image, including parameters such as segmentation size and segmentation direction; the data frame refers to the image data block obtained after dividing the original image; the sequence number is used to indicate the relative position number of the data frame in the original image, such as sequential numbering from left to right and from top to bottom; and the complexity is used to indicate the complexity of the image content in the data frame, which can be calculated through feature parameters such as image entropy value and edge density.
[0032] Specifically, first, the print controller calculates the segmentation parameters of the original image according to preset image segmentation rules, including the size and number of segmentation blocks. Preset image segmentation rules can be divided into the following two types: (1) Fixed-size segmentation method: For example, an original image of 2048×1536 pixels, when segmented into 512×512 pixels, will yield 12 data frames (4 columns × 3 rows). Starting from the top left corner, these data frames are numbered 0-11 in order from left to right and from top to bottom.
[0033] (2) Content-adaptive segmentation method: The segmentation size is dynamically adjusted according to the complexity of the image content. For example, the blue sky part (simple content) in the photo may be segmented into a large block of 1024×1024, while the details of the building part (complex content) may be segmented into a small block of 256×256.
[0034] Then, the print controller divides the original image into multiple data frames of equal or unequal size according to preset image segmentation rules. For each data frame, the print controller calculates its image feature parameters and evaluates its complexity accordingly. At the same time, the print controller assigns a unique sequence number to each data frame based on its position in the original image.
[0035] Optionally, under normal circumstances, based on preset image segmentation rules, the original image to be processed can be segmented into multiple data frames in the following ways, which are not limited here: Divide the original image into macroblocks of a preset size, calculate the image feature parameters of each macroblock, the size of the macroblock is M×N pixels, and the image feature parameters include image entropy value and / or edge density; Based on the image feature parameters, generate an image complexity distribution map, which includes high-complexity region images and low-complexity region images; Segment the high-complexity region images using a first preset size to obtain a first set of data frames, the first preset size being P×Q pixels; Segment the low-complexity region images using a second preset size to obtain a second set of data frames, the second preset size being R×S pixels, where P×Q is less than R×S; Based on the original image, assign sequence numbers to the first set of data frames and the second set of data frames in sequence.
[0036] Suppose we have an original image of 1600×1200 pixels, which shows a person standing in front of a blue sky and white clouds. The process of dividing the original image into multiple data frames is as follows.
[0037] (1) Macroblock partitioning stage: The size of the macroblock is set to M×N as 200×200 pixels, and the entire original image is divided into 48 macroblocks (8 columns × 6 rows). (2) Feature calculation stage (the image feature parameters of each macroblock are calculated): The upper part of the sky region: image entropy value ≈ 2.1 (low), edge density ≈ 0.05 (very few edges); The area where the person is located has an image entropy value of approximately 6.8 (relatively high) and an edge density of approximately 0.45 (rich edges). Complexity distribution determination stage (based on the calculation results, the image is divided into): Highly complex areas: the figure and its surroundings, accounting for approximately 40% of the image; Low-complexity areas: the sky and background areas, accounting for approximately 60% of the image; (4) Differentiated segmentation: For highly complex areas (character parts): use the first preset size P×Q=100×100 pixels, this area generates approximately 96 small data frames; For low-complexity areas (sky portion): using the second preset size R×S=400×400 pixels, this area generates approximately 6 large data frames; (5) Serial number allocation (starting from the top left corner, serial numbers are allocated in order from left to right and from top to bottom): Big data frame (sky portion) sequence number: 0-5; Small data frame (person part) serial number: 6-101.
[0038] The advantage of this segmentation method is that simple areas such as the sky are segmented with large sizes to reduce the number of data frames, while complex areas such as people are segmented with small sizes to ensure detail quality. A total of about 102 data frames are generated. Compared with uniform segmentation (for example, segmenting all areas with 100×100 will produce 192 data frames), this method ensures the image quality of complex areas while improving the processing efficiency of simple areas.
[0039] Optionally, in general, an image complexity distribution map is generated based on image feature parameters. The image complexity distribution map includes high-complexity region images and low-complexity region images. This can be achieved in the following ways, without limitation: input the image feature parameters of the macroblock into the complexity prediction model to obtain the predicted complexity of the macroblock; determine the high-complexity region images and low-complexity region images based on the predicted complexity; and obtain the image complexity distribution map based on the high-complexity region images and low-complexity region images.
[0040] Training process of complexity prediction model: (1) Data preparation: Label each macroblock with "high / low complexity" manually or with tools, and then extract the image features of each macroblock (such as texture, edge, color difference, etc.) to form a training dataset and a validation dataset of "feature + label".
[0041] (2) Select a basic model: Use a simple machine learning model (such as decision tree, support vector machine) or a lightweight neural network as the basic framework for complexity prediction.
[0042] (3) Training and optimization: Input the training dataset into the model and let the model learn the correspondence between "features + labels"; continuously adjust the parameters during the process to reduce prediction errors until the model can stably judge the complexity of new macroblocks.
[0043] (4) Validation test: Use the validation dataset to test the model and confirm that the prediction is accurate in order to complete the training.
[0044] S102. Based on the complexity, determine the compression algorithm corresponding to each of the multiple data frames; Optionally, under normal circumstances, the compression algorithm corresponding to each of the multiple data frames can be determined according to the complexity in the following ways, which are not limited here: obtain the printing mode at the current moment, which includes quality-first mode, speed-first mode, and equalization mode; determine the compression parameter matrix based on the printing mode, which includes compression quality parameters and compression rate parameters; and determine the compression algorithm corresponding to each of the multiple data frames according to the compression parameter matrix and the complexity of the data frames.
[0045] Among them, the print mode represents the print task processing strategy selected by the user, which is used to balance print quality and print speed; the quality-first mode is the processing mode that pursues the best print quality; the speed-first mode is the processing mode that pursues the fastest print speed; the balanced mode is the processing mode that seeks a balance between print quality and print speed; the compression parameter matrix is a parameter configuration table generated according to the print mode; the compression quality parameter is used to control the degree of quality loss during the compression process; and the compression rate parameter is used to control the processing speed during the compression process.
[0046] Specifically, the print controller reads the current print mode. For quality-first mode, the compression parameter matrix is set to a higher compression quality parameter and a lower compression rate parameter; for speed-first mode, the compression parameter matrix is set to the opposite: a lower compression quality parameter and a higher compression rate parameter; for balanced mode, the compression parameter matrix is set to a moderate compression quality parameter and compression rate parameter. The print controller comprehensively evaluates the compression parameter matrix and the complexity of the data frame to select an appropriate compression algorithm. For example, in quality-first mode, even for highly complex data frames, it tends to choose a compression algorithm with higher fidelity, while in speed-first mode, it prioritizes compression algorithms with faster processing speed.
[0047] Optionally, in general, determining the compression algorithm corresponding to multiple data frames based on complexity can be achieved in the following way, without limitation: matching the complexity with the complexity range in a preset complexity range-compression algorithm mapping table. The complexity range-compression algorithm mapping table includes multiple complexity ranges, and different complexity ranges correspond to different compression algorithms. If the complexity falls into the low complexity range, the data frame is determined to correspond to a lossless compression algorithm; if the complexity falls into the medium complexity range, the data frame is determined to correspond to a hybrid compression algorithm; if the complexity falls into the high complexity range, the data frame is determined to correspond to a lossy compression algorithm.
[0048] Here, complexity intervals refer to different ranges divided according to complexity, such as low complexity interval [0, 0.3], medium complexity interval [0.3, 0.7], and high complexity interval [0.7, 1.0]. The preset complexity interval-compression algorithm mapping table refers to a pre-established correspondence table between complexity intervals and compression algorithms. Lossless compression algorithms are algorithms that do not lose image information during the compression process, such as RLE and LZW. Lossy compression algorithms are algorithms that lose some image information during the compression process, such as JPEG. Hybrid compression algorithms are composite algorithms that combine lossless and lossy characteristics.
[0049] Specifically, the print controller accesses a preset complexity range-compression algorithm mapping table, which defines in detail the compression algorithm selection strategies corresponding to different complexity ranges. For low-complexity data frames (such as solid color blocks, simple graphics, etc.), a lossless compression algorithm is selected to ensure image quality; for high-complexity data frames (such as photos, complex textures, etc.), a lossy compression algorithm is selected to improve compression efficiency; for data frames of moderate complexity, a hybrid compression algorithm is selected to balance quality and efficiency. Furthermore, the complexity range-compression algorithm mapping table can also contain specific parameter configurations for each compression algorithm, such as compression ratio and quality factor, to achieve more precise compression control.
[0050] S103. Distribute multiple data frames to multiple parallel working threads to obtain multiple compressed data packets with the same sequence number as the corresponding data frames. The working threads perform compression operations according to the compression algorithm corresponding to the data frames. Here, a worker thread represents a parallel computing unit that performs data processing tasks; a compressed data packet refers to a data set obtained after data frames have been compressed.
[0051] Specifically, the print controller can allocate data frames to worker threads in the following ways.
[0052] (1) Average allocation method: Assuming there are N worker threads and M data frames, each worker thread is allocated M / N data frames on average. For example, if there are 4 worker threads and 12 data frames, each thread processes 3 data frames. Specifically, the first worker thread processes data frames with sequence numbers 1, 5, and 9; the second worker thread processes data frames with sequence numbers 2, 6, and 10; the third worker thread processes data frames with sequence numbers 3, 7, and 11; and the fourth worker thread processes data frames with sequence numbers 4, 8, and 12.
[0053] (2) Dynamic allocation method: The print controller maintains a global task queue, and all data frames are stored in the queue in sequence according to their sequence numbers. After completing the current task, each worker thread immediately retrieves the next data frame to be processed from the queue.
[0054] Other implementations of distributing multiple data frames to multiple parallel worker threads are not limited here.
[0055] After the worker threads call the corresponding compression algorithm to compress the data frames, they obtain compressed data packets with the same sequence number as the corresponding data frames. Continuing the previous example, the first worker thread outputs compressed data packets with sequence numbers 1, 5, and 9; the second worker thread outputs compressed data packets with sequence numbers 2, 6, and 10; the third worker thread outputs compressed data packets with sequence numbers 3, 7, and 11; and the fourth worker thread outputs compressed data packets with sequence numbers 4, 8, and 12.
[0056] S104. Multiple compressed data packets are passed into the buffer to obtain an ordered compressed data stream. The buffer performs a sorting operation from smallest to largest based on the sequence number of the compressed data packets. Among them, the buffer area refers to the memory space used for temporary storage of data, which can be a circular buffer or a queue structure; the ordered compressed data stream refers to the continuous data sequence formed by sorting multiple compressed data packets according to their sequence numbers; the sorting operation represents the process of rearranging the compressed data packets according to their sequence numbers.
[0057] Specifically, first, the print controller allocates a buffer for compressed data packets and writes the compressed data packets into the buffer. The buffer uses a double-buffering mechanism, including a write buffer and a read buffer. The write buffer is responsible for receiving new compressed data packets, and the read buffer is responsible for sending data to the print device. When the write buffer receives a sufficient number of compressed data packets, the buffer management module executes a quicksort algorithm based on the sequence number of the compressed data packets, rearranging the compressed data packets into an ordered compressed data stream. After sorting, the write buffer and the read buffer switch roles.
[0058] S105. Send the ordered compressed data stream to the printing device in sequence, and monitor the buffer usage of the printing device in real time; Among them, printing device refers to the hardware device that performs the actual printing task, such as inkjet printer, laser printer, etc.; buffer usage refers to the amount of storage space used in the receiving buffer of the printing device.
[0059] Specifically, first, the print controller checks if the printing device is in a data-receiving state. Then, the print controller reads the ordered compressed data stream from the buffer according to its sequence number and sends it to the printing device through the data interface. During transmission, the print controller obtains the usage status of the printing device's buffer through real-time querying or interruption, and records the ratio of the amount of data sent to the total capacity of the printing device's buffer as the buffer occupancy.
[0060] S106. When the cache usage exceeds the cache usage threshold, reduce the rate at which data frames are allocated to multiple parallel worker threads until the cache usage is reduced to the cache usage threshold.
[0061] Among them, the cache usage threshold represents a pre-set maximum percentage of cache usage, which is used to trigger the flow control mechanism; the data frame allocation rate refers to the frequency at which worker threads allocate new data frames.
[0062] Specifically, the print controller acquires the print device's buffer occupancy at fixed time intervals (e.g., 10ms) and compares it with a preset buffer occupancy threshold (e.g., 80%). If the buffer occupancy exceeds the threshold, the print controller immediately initiates a flow control mechanism: first, it calculates the percentage reduction in the rate, and then correspondingly reduces the frequency of allocating new data frames to worker threads, employing either linear or stepped deceleration strategies. Simultaneously, the print controller continues to monitor the buffer occupancy trend. Once the buffer occupancy drops below the threshold and remains stable for a period, the print controller gradually restores the data frame allocation rate until it returns to normal processing speed.
[0063] By employing the above technical solution, the print controller segments the original image to be processed into multiple data frames with sequence numbers and complexity levels. Based on the complexity, it selects the corresponding compression algorithm for each data frame, achieving differentiated processing for regions of varying image complexity. The print controller uses multiple parallel threads to process the data frames simultaneously, significantly improving image data processing efficiency. The print controller sorts the compressed data packets in ascending order of sequence number through a buffer, ensuring data ordering. Simultaneously, the print controller monitors the print device's buffer usage in real time and dynamically adjusts the data allocation rate to prevent buffer overflow. This adaptive multi-threaded processing method based on data characteristics ensures print quality while improving processing efficiency, alleviating the inefficiency of traditional single-threaded processing methods.
[0064] The following provides a more detailed description of the process of the method provided in this implementation. Please refer to [link / reference]. Figure 2 This is another flowchart illustrating the multi-threaded image printing method in this application embodiment.
[0065] S201. Based on the preset image segmentation rules, the original image to be processed is segmented into multiple data frames. Different data frames correspond to different sequence numbers and different complexities. The sequence number is used to indicate the position order of the data frame in the original image, and the complexity is used to indicate the compression difficulty of the data frame.
[0066] For details, please refer to step S101, which will not be repeated here.
[0067] S202. Based on the complexity, determine the compression algorithm corresponding to each of the multiple data frames.
[0068] For details, please refer to step S102, which will not be repeated here.
[0069] S203. Distribute multiple data frames to multiple parallel working threads to obtain multiple compressed data packets with the same sequence number as the corresponding data frames. The working threads perform compression operations according to the compression algorithm corresponding to the data frames.
[0070] For details, please refer to step S103, which will not be repeated here.
[0071] S204. Obtain the data processing capability of each worker thread. The data processing capability is used to represent the average processing time of high-complexity data frames, the average processing time of medium-complexity data frames, and the average processing time of low-complexity data frames.
[0072] Among them, data processing capability refers to the efficiency index of worker threads in processing data frames of different complexities; the average processing time of high-complexity data frames represents the average time required to process a high-complexity data frame; the average processing time of medium-complexity data frames represents the average time required to process a medium-complexity data frame; and the average processing time of low-complexity data frames represents the average time required to process a low-complexity data frame.
[0073] Specifically, the print controller allocates data frames to each worker thread, including high-complexity, medium-complexity, and low-complexity data frames. The print controller records the time each worker thread takes to process these data frames and calculates the average time for that worker thread to process data frames of different complexities. For example, a worker thread might take an average of 100ms to process a high-complexity data frame, 60ms to process a medium-complexity data frame, and 30ms to process a low-complexity data frame. Through this performance testing method, the print controller obtains the data processing capability of each worker thread.
[0074] S205. Based on data processing capabilities, the multiple parallel working threads are divided into high-complexity data frame working threads, medium-complexity data frame working threads, and low-complexity data frame working threads.
[0075] Among them, the high-complexity data frame worker thread refers to a worker thread that is dedicated to processing high-complexity data frames; the medium-complexity data frame worker thread refers to a worker thread that is dedicated to processing medium-complexity data frames; and the low-complexity data frame worker thread refers to a worker thread that is dedicated to processing low-complexity data frames.
[0076] Specifically, after acquiring the data processing capabilities of each worker thread, the print controller begins to classify and categorize the worker threads. The print controller compares and analyzes the processing time for each worker thread across three levels of data complexity to determine which level of data complexity each worker thread is best suited for. For example, if a worker thread has a shorter average processing time for high-complexity data frames compared to other threads, it is classified as a high-complexity data frame worker thread. In this way, the print controller divides all worker threads into three categories: high-complexity data frame worker threads, medium-complexity data frame worker threads, and low-complexity data frame worker threads, forming dedicated processing queues.
[0077] S206. Based on the complexity range, allocate the data frame to the corresponding worker thread.
[0078] Here, complexity range represents the range of data frame complexity, such as high, medium, and low ranges; data frame allocation represents the process of assigning data frames to corresponding types of worker threads; corresponding worker threads refer to dedicated worker threads that match the complexity of the data frames.
[0079] Specifically, after classifying and dividing the worker threads, the print controller begins the data frame allocation process. First, the print controller determines the complexity range of each data frame. Then, it assigns the data frame to the corresponding type of worker thread. For example, a data frame with a complexity of 0.8 belongs to the high complexity range and is assigned to a high complexity data frame worker thread; a data frame with a complexity of 0.5 belongs to the medium complexity range and is assigned to a medium complexity data frame worker thread; and a data frame with a complexity of 0.2 belongs to the low complexity range and is assigned to a low complexity data frame worker thread. This specialized allocation method ensures that each data frame is processed by the most suitable worker thread.
[0080] S207. Multiple compressed data packets are passed to the buffer to obtain an ordered compressed data stream. The buffer performs an ascending sorting operation based on the sequence number of the compressed data packets.
[0081] For details, please refer to step S104, which will not be repeated here.
[0082] S208. The ordered compressed data stream is sent sequentially to the printing device.
[0083] For details, please refer to step S105, which will not be repeated here.
[0084] S209. Detect the transmission status of the ordered compressed data stream.
[0085] Among them, transmission status refers to the operating status during data transmission, including normal transmission, transmission timeout, data loss, connection disconnection, etc.; detection refers to the process of real-time monitoring and judgment of transmission status.
[0086] Specifically, the print controller detects transmission status in the following ways: 1) It sets a transmission timeout timer to monitor whether the transmission time of each data packet exceeds a preset transmission time threshold; 2) It checks the transmission acknowledgment information of the data packets to determine if any data packets are lost; 3) It monitors the connection status with the printing device to detect whether a connection interruption has occurred. For example, the print controller checks the transmission status every 100ms. If a data packet does not receive a transmission acknowledgment within 500ms, it is determined to be a transmission anomaly.
[0087] S210. When an abnormal transmission status is detected, an abnormality handling process is executed. The abnormality handling process includes stopping the task processing of the working thread, suspending the segmentation operation of the original image, and storing the transmission progress information.
[0088] Among them, "transmission status is abnormal" means that a transmission failure has been detected; "abnormal handling process" refers to a series of processing operations to deal with transmission abnormalities; "stop working thread task processing" means to suspend the data compression operation of all working threads; "stop original image segmentation operation" means to stop further segmentation of the original image; "store transmission progress information" means to record the current transmission position, data sent, and other status information.
[0089] Specifically, first, the print controller sends a stop signal to all worker threads, requiring them to stop receiving new tasks after completing the data frame they are currently processing. Simultaneously, the print controller pauses the segmentation operation of the original image to prevent the generation of new data frames. Then, the print controller records detailed transmission progress information, including: the sequence number of the last successfully transmitted data packet, information on data packets awaiting transmission in the buffer, and information on the data frames currently being processed.
[0090] S211. When the transmission status is detected to have returned to normal, the recovery process is executed. The recovery process includes determining the transmission interruption location based on the transmission progress information, retransmitting the ordered compressed data stream that was not successfully transmitted at the transmission interruption location, restoring the segmentation operation of the original image, and executing the task processing of the worker thread.
[0091] Among them, "transmission status restored to normal" means that the abnormal situation has been resolved; "recovery process" refers to a series of operations to restart data transmission; "transmission interruption position" refers to the sequence number position when data transmission was interrupted; "unsuccessfully sent ordered compressed data stream" refers to data packets that failed to be transmitted after the data transmission was interrupted; "restoring the original image segmentation operation" means restarting the segmentation of the original image; and "executing the task processing of the worker thread" means restarting the data compression work of the worker thread.
[0092] Specifically, first, the print controller reads the previously stored transmission progress information to determine the location of the transmission interruption. For example, if the transmission was interrupted at data packet with sequence number 100, the data is retransmitted starting from sequence number 101. Then, the print controller checks all data packets in the buffer with sequence numbers greater than 100 and retransmits these failed transmission packets in order. Simultaneously, the print controller resumes the segmentation operation of the original image and continues to generate new data frames. Finally, the print controller sends a recovery signal to each worker thread to restart the data compression processing. This orderly recovery mechanism ensures the continuity and integrity of data transmission.
[0093] S212. Monitor the cache usage of the printing device in real time. When the cache usage exceeds the cache usage threshold, reduce the rate at which data frames are allocated to multiple parallel working threads until the cache usage is reduced to the cache usage threshold.
[0094] For details, please refer to steps S105 and S106, which will not be repeated here.
[0095] The printing controller in the embodiments of this invention is described below from the perspective of hardware processing. Please refer to [link / reference needed]. Figure 3 This is a schematic diagram of the physical device structure of a printing controller in an embodiment of this application.
[0096] It should be noted that, Figure 3 The structure of the print controller shown is merely an example and should not impose any limitation on the functionality and scope of use of the embodiments of the present invention.
[0097] like Figure 3 As shown, the print controller includes a CPU 301, which can perform various appropriate actions and processes based on a program stored in the read-only memory ROM 302 or a program loaded from the storage section 308 into the random access memory RAM 303, such as performing the methods described in the above embodiments. The RAM 303 also stores various programs and data required for system operation. The CPU 301, ROM 302, and RAM 303 are interconnected via a bus 304. An I / O interface 305 is also connected to the bus 304.
[0098] The following components are connected to I / O interface 305: input section 306 including audio input devices, push-button switches, etc.; output section 307 including a liquid crystal display (LCD) and audio output devices, indicator lights, etc.; storage section 308 including a hard disk, etc.; and communication section 309 including a network interface card such as a LAN (Local Area Network) card, modem, etc. Communication section 309 performs communication processing via a network such as the Internet. Drive 310 is also connected to I / O interface 305 as needed. Removable media 311, such as a disk, optical disk, magneto-optical disk, semiconductor memory, etc., are installed on drive 310 as needed so that computer programs read from them can be installed into storage section 308 as needed.
[0099] In particular, according to embodiments of the present invention, the processes described above with reference to the flowcharts can be implemented as computer software programs. For example, embodiments of the present invention include a computer program product comprising a computer program carried on a computer-readable medium, the computer program containing computer programs for performing the methods shown in the flowcharts. In such embodiments, the computer program can be downloaded and installed from a network via communication section 309, and / or installed from removable medium 311. When the computer program is executed by CPU 301, it performs the various functions defined in the present invention.
[0100] It should be noted that specific examples of computer-readable storage media may include, but are not limited to: electrical connections having one or more wires, portable computer disks, hard disks, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM), flash memory, optical fiber, portable compact disc read-only memory (CD-ROM), optical storage devices, magnetic storage devices, or any suitable combination thereof. In this invention, a computer-readable storage medium can be any tangible medium containing or storing a program that can be used by or in conjunction with an instruction execution system, apparatus, or device.
[0101] The flowcharts and block diagrams in the accompanying drawings illustrate the architecture, functionality, and operation of possible implementations of systems, methods, and computer program products according to various embodiments of the present invention. Each block in a flowchart or block diagram may represent a module, program segment, or portion of code, which contains one or more executable instructions for implementing a specified logical function. It should also be noted that in some alternative implementations, the functions indicated in the blocks may occur in a different order than those shown in the drawings.
[0102] Specifically, the print controller in this embodiment includes a processor and a memory. The memory stores a computer program, and when the computer program is executed by the processor, it implements the multi-threaded image printing method provided in the above embodiment.
[0103] In another aspect, the present invention also provides a computer-readable storage medium, which may be included in the print controller described in the above embodiments; or it may exist independently and not assembled into the print controller. The storage medium carries one or more computer programs that, when executed by a processor of the print controller, cause the print controller to implement the multi-threaded image printing method provided in the above embodiments.
[0104] The above-described embodiments are only used to illustrate the technical solutions of this application, and are not intended to limit it. Although this application has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some of the technical features. Such modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the scope of the technical solutions of the embodiments of this application.
[0105] As used in the above embodiments, depending on the context, the term "when..." can be interpreted as meaning "if...", "after...", "in response to determining...", or "in response to detecting...". Similarly, depending on the context, the phrase "when determining..." or "if (the stated condition or event) is interpreted as meaning "if determining...", "in response to determining...", "when (the stated condition or event) is detected", or "in response to detecting (the stated condition or event)".
[0106] Those skilled in the art will understand that all or part of the processes in the methods of the above embodiments can be implemented by a computer program instructing related hardware. This program can be stored in a computer-readable storage medium, and when executed, it can include the processes described in the above method embodiments. The aforementioned storage medium includes various media capable of storing program code, such as ROM or random access memory (RAM), magnetic disks, or optical disks.
Claims
1. A multi-threaded image printing method, characterized in that, Applied to a print controller, the method includes: Based on preset image segmentation rules, the original image to be processed is segmented into multiple data frames. Different data frames correspond to different sequence numbers and different complexities. The sequence number is used to indicate the position order of the data frame in the original image, and the complexity is used to indicate the compression difficulty of the data frame. Based on the complexity, determine the compression algorithm corresponding to each of the multiple data frames; The multiple data frames are allocated to multiple parallel working threads to obtain multiple compressed data packets with the same sequence number as the corresponding data frames. The working threads perform compression operations according to the compression algorithm corresponding to the data frames. The multiple compressed data packets are passed to the buffer to obtain an ordered compressed data stream. The buffer performs an ascending sorting operation based on the sequence number of the compressed data packets. The ordered compressed data stream is sent sequentially to the printing device, and the buffer usage of the printing device is monitored in real time. When the cache usage exceeds the cache usage threshold, the rate at which the data frames are allocated to the multiple parallel worker threads is reduced until the cache usage is reduced to the cache usage threshold.
2. The method according to claim 1, characterized in that, The process of segmenting the original image to be processed into multiple data frames based on preset image segmentation rules specifically includes: The original image is divided into macroblocks of a preset size, and the image feature parameters of each macroblock are calculated. The size of the macroblock is M×N pixels, and the image feature parameters include image entropy value and / or edge density. Based on the image feature parameters, an image complexity distribution map is generated, which includes high-complexity region images and low-complexity region images; The image of the highly complex region is segmented using a first preset size to obtain a first set of data frames, wherein the first preset size is P×Q pixels; The low-complexity region image is segmented using a second preset size to obtain a second set of data frames. The second preset size is R×S pixels, and P×Q is smaller than R×S. Based on the original image, sequence numbers are assigned sequentially to the first group of data frames and the second group of data frames.
3. The method according to claim 2, characterized in that, Based on the image feature parameters, an image complexity distribution map is generated, which includes high-complexity region images and low-complexity region images, specifically including: The image feature parameters of the macroblock are input into the complexity prediction model to obtain the predicted complexity of the macroblock. Based on the predicted complexity, the high-complexity region image and the low-complexity region image are determined; Based on the high-complexity region image and the low-complexity region image, the image complexity distribution map is obtained.
4. The method according to claim 1, characterized in that, The step of determining the compression algorithm corresponding to each of the multiple data frames based on the complexity specifically includes: Obtain the current printing mode, which includes quality-priority mode, speed-priority mode, and balanced mode; Based on the printing mode, a compression parameter matrix is determined, which includes compression quality parameters and compression rate parameters; Based on the compression parameter matrix and the complexity of the data frames, the compression algorithms corresponding to the multiple data frames are determined respectively.
5. The method according to claim 1, characterized in that, The step of determining the compression algorithm corresponding to each of the multiple data frames based on the complexity specifically includes: The complexity is matched with a complexity range in a preset complexity range-compression algorithm mapping table, which includes multiple complexity ranges, and different complexity ranges correspond to different compression algorithms. If the complexity falls into the low complexity range, the lossless compression algorithm corresponding to the data frame is determined. If the complexity falls into the medium complexity range, the data frame is determined to correspond to a hybrid compression algorithm; If the complexity falls into the high complexity range, the data frame is determined to correspond to a lossy compression algorithm.
6. The method according to claim 5, characterized in that, After the step of allocating the plurality of data frames to a plurality of parallel worker threads to obtain a plurality of compressed data packets with the same sequence number as the corresponding data frames, the method further includes: Obtain the data processing capability of each worker thread, which is used to represent the average processing time of high-complexity data frames, the average processing time of medium-complexity data frames, and the average processing time of low-complexity data frames. Based on the data processing capabilities, the multiple parallel working threads are divided into high-complexity data frame working threads, medium-complexity data frame working threads, and low-complexity data frame working threads. Based on the range of complexity, the data frame is allocated to the corresponding worker thread.
7. The method according to claim 1, characterized in that, After the step of sequentially sending the ordered compressed data stream to the printing device, the method further includes: Detect the transmission status of the ordered compressed data stream; When an abnormal transmission status is detected, an abnormality handling process is executed. The abnormality handling process includes stopping the task processing of the working thread, suspending the segmentation operation of the original image, and storing the transmission progress information. When the transmission status is detected to have returned to normal, a recovery process is executed. The recovery process includes determining the transmission interruption location based on the transmission progress information, retransmitting the ordered compressed data stream that was not successfully transmitted at the transmission interruption location, restoring the segmentation operation of the original image, and executing the task processing of the worker thread.
8. A printer controller, characterized in that, The print controller includes: one or more processors and a memory; the memory is coupled to the one or more processors, the memory being used to store computer program code, the computer program code including computer instructions, and the one or more processors invoking the computer instructions to cause the print controller to perform the method as described in any one of claims 1-7.
9. A computer-readable storage medium comprising instructions, characterized in that, When the instruction is executed on the print controller, it causes the print controller to perform the method as described in any one of claims 1-7.
10. A computer program product, characterized in that, When the computer program product is run on the print controller, the print controller performs the method as described in any one of claims 1-7.
Citation Information
Patent Citations
Temporal image buffer for an image processor using a compressed raw image
CN101218603A
Network printing method and network printer
CN102799399A
Data transmission method and device, electronic device and storage medium
CN115065732A
Image coding and decoding method, device and system
CN116708800A
Multi-thread picture compression method and device and storage medium
CN120676162A