Image processing method and related device
By using the method of parallel image processing by the main thread and child threads, the problem of lag in electronic devices when processing high-resolution or complex images is solved, achieving more efficient image processing and faster response speed.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- HONOR DEVICE CO LTD
- Filing Date
- 2024-10-30
- Publication Date
- 2026-05-01
AI Technical Summary
In the prior art, when electronic devices process high-resolution or complex images, the serial processing method results in excessively long image processing time, affecting the smoothness and responsiveness of the application.
The method of processing images in parallel using a main thread and multiple sub-threads divides the image into multiple sub-images and processes each sub-image in parallel. The main thread and sub-threads process their respective sub-images separately and finally stitch them together to form a complete image.
It improves image processing efficiency, shortens processing time, and enhances application smoothness and responsiveness.
Smart Images

Figure CN121961823A_ABST
Abstract
Description
Image processing methods and related devices Technical Field
[0001] This application relates to the field of terminals, and more particularly to an image processing method and related apparatus. Background Technology
[0002] With the development of terminal technology, users are using electronic devices for entertainment and daily tasks more and more frequently. During the use of electronic devices, image display is one of the key factors affecting user experience. The image processing performance of electronic devices is directly related to the smoothness and responsiveness of applications; therefore, how to improve the efficiency of image processing on electronic devices has become an urgent problem to be solved. Summary of the Invention
[0003] This application provides an image processing method and related apparatus, relating to the terminal field, which enables threads and one or more sub-threads to process sub-images in parallel, thereby improving the processing efficiency of image 1, greatly shortening the image processing time, and improving the smoothness and response speed of the application.
[0004] In a first aspect, this application provides an image processing method, comprising: an electronic device reading a first image through the main thread of a first application; the electronic device creating M sub-threads when a first preset condition is met; the electronic device dividing the first image into N sub-images; the electronic device processing the N sub-images in parallel through the main thread and the M sub-threads; and the electronic device obtaining a second image based on the processed N sub-images.
[0005] In one possible implementation, the first preset condition is one or more of the following: the process name of the first application is recorded in a whitelist, the size of the first image is greater than or equal to a first value, and the first image is the first frame image in the video stream.
[0006] In one possible implementation, when a first preset condition is met, the electronic device creates M sub-threads. Specifically, the electronic device determines whether the first preset condition is met based on the process name of the first application and the parameters of the first image. The parameters of the first image include one or more of the following: the length of the first image, the width of the first image, and the identifier of the first image. When it is determined that the first preset condition is met, the electronic device creates the M sub-threads.
[0007] In one possible implementation, each of the N sub-images includes parameters for that sub-image, wherein the parameters for each sub-image include its coordinates, length, and width. The electronic device processes the N sub-images in parallel using the main thread and the M sub-threads, specifically including: the electronic device processing the N-1 sub-images based on the parameters of the N-1 sub-images using the M sub-threads; and the electronic device processing the Nth sub-image based on the parameters of the Nth sub-image using the main thread.
[0008] In one possible implementation, the N sub-images include a first sub-image, and the M sub-threads include a first sub-thread. The electronic device processes the N-1 sub-images based on parameters of the N-1 sub-images through the M sub-threads, specifically including: the electronic device processes the first sub-image based on parameters of the first sub-image through the first sub-thread. The electronic device processes the Nth sub-image based on parameters of the Nth sub-image through the main thread, specifically including: when the electronic device processes the first sub-image through the first sub-thread, the electronic device processes the Nth sub-image based on parameters of the Nth sub-image through the main thread.
[0009] In one possible implementation, the N sub-images further include a second sub-image, and the M sub-threads further include a second sub-thread. The electronic device processes the N-1 sub-images based on the parameters of the N-1 sub-images through the M sub-threads, specifically further including: when the electronic device processes the first sub-image through the first sub-thread, the electronic device processes the second sub-image based on the parameters of the second sub-image through the second sub-thread.
[0010] In one possible implementation, M = N-1.
[0011] In one possible implementation, M is set to 3, or M is related to the number of processors in the electronic device.
[0012] In one possible implementation, the electronic device obtains a second image based on the processed N sub-images, specifically including:
[0013] The electronic device stitches together the processed N sub-images to obtain the second image.
[0014] In a second aspect, this application provides an electronic device comprising: one or more processors and a memory. The memory is coupled to the one or more processors and is used to store computer program code, the computer program code including computer instructions, which the one or more processors invoke to cause the electronic device to perform a method as described in any possible implementation of the first aspect.
[0015] Thirdly, this application provides a chip system applied to an electronic device, the chip system including one or more processors, the processors being configured to invoke computer instructions to cause the electronic device to perform a method as described in any possible implementation of the first aspect.
[0016] Fourthly, this application provides a computer-readable storage medium including instructions that, when executed on an electronic device, cause the electronic device to perform the method as described in any possible implementation of the first aspect.
[0017] Fifthly, this application provides a computer program product, including a computer program that, when executed by a processor, causes the electronic device to perform the method as described in any possible implementation of the first aspect. Attached Figure Description
[0018] Figure 1 is a schematic diagram of the hardware structure of an electronic device provided in an embodiment of this application;
[0019] Figure 2 is a schematic diagram illustrating the implementation principle of an electronic device displaying an image on a screen according to an embodiment of this application;
[0020] Figure 3A is a schematic diagram of the logic flow of an image processing method provided in an embodiment of this application;
[0021] Figure 3B is a comparative schematic diagram of two image processing flows provided in an embodiment of this application;
[0022] Figures 4A-4C are schematic diagrams of user interfaces for a set of application scenarios provided in the embodiments of this application;
[0023] Figure 5 is a flowchart illustrating an image processing method provided in an embodiment of this application;
[0024] Figure 6 is a schematic diagram of the software framework of an electronic device provided in an embodiment of this application;
[0025] Figure 7 is a schematic diagram of the module interaction of an image processing method provided in an embodiment of this application;
[0026] Figure 8 is a schematic diagram comparing the implementation effects of different image processing methods provided in this application. Detailed Implementation
[0027] The technical solutions in the embodiments of this application will be clearly and thoroughly described below with reference to the accompanying drawings. In the description of the embodiments of this application, unless otherwise stated, " / " means "or," for example, A / B can mean A or B; the word "and / or" in the text is merely a description of the relationship between related objects, indicating that three relationships can exist. For example, A and / or B can represent: A existing alone, A and B existing simultaneously, and B existing alone. Furthermore, in the description of the embodiments of this application, "multiple" refers to two or more than two.
[0028] 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.
[0029] Figure 1 is a schematic diagram of the hardware structure of an electronic device provided in an embodiment of this application.
[0030] In this embodiment of the application, the electronic device may also be referred to as electronic device 100.
[0031] In this embodiment of the application, the device type of electronic device 100 can be any of the following: mobile phone, tablet computer, handheld computer, desktop computer, laptop computer, ultra-mobile personal computer (UMPC), netbook, cellular phone, personal digital assistant (PDA), as well as smart home devices such as smart screens and smart speakers, wearable devices such as smart bracelets, smartwatches, and smart glasses, extended reality (XR) devices such as augmented reality (AR), virtual reality (VR), and mixed reality (MR), in-vehicle devices, or smart city devices.
[0032] As shown in Figure 1, the electronic device 100 may include a processor 101, a memory 102, a wireless communication module 103, a display screen 104, a sensor module 105, an audio module 106 (optional), and a speaker 107 (optional). These modules can be connected via a bus or other means; this embodiment uses a bus connection as an example.
[0033] It is understood that the structures illustrated in the embodiments of the present invention do not constitute a specific limitation on the electronic device 100. In other embodiments of this application, the electronic device 100 may also include more or fewer components than illustrated, or combine some components, or split some components, or have different component arrangements. The illustrated components may be implemented in hardware, software, or a combination of software and hardware.
[0034] Processor 101 may include one or more processor units, such as an application processor (AP), a modem processor, a graphics processing unit (GPU), an image signal processor (ISP), a controller, a video codec, a digital signal processor (DSP), a baseband processor, and / or a neural network processing unit (NPU). Different processing units may be independent devices or integrated into one or more processors.
[0035] The controller can generate operation control signals based on the instruction opcode and timing signals to complete the control of instruction fetching and execution.
[0036] The processor 101 may also include a memory for storing instructions and data. In some embodiments, the memory in the processor 101 is a cache memory. This memory can store instructions or data that the processor 101 has just used or that are used repeatedly. If the processor 101 needs to use the instruction or data again, it can directly retrieve it from the memory. This avoids repeated accesses, reduces the waiting time of the processor 101, and thus improves the efficiency of the system.
[0037] In some embodiments, the processor 101 may include one or more interfaces. Interfaces may include an integrated circuit (I2C) interface, an inter-integrated circuit sound (I2S) interface, a pulse code modulation (PCM) interface, a universal asynchronous receiver / transmitter (UART) interface, a mobile industry processor interface (MIPI), a general-purpose input / output (GPIO) interface, a subscriber identity module (SIM) interface, and / or a USB interface, etc.
[0038] The memory 102 is coupled to the processor 101 and is used to store various software programs and / or multiple sets of instructions. In specific implementations, the memory 102 may include volatile memory, such as random access memory (RAM); it may also include non-volatile memory, such as ROM, flash memory, hard disk drive (HDD), or solid-state drive (SSD); the memory 102 may also include combinations of the above types of memory. The memory 102 may store program code so that the processor 101 can call the program code stored in the memory 102 to implement the implementation method of the present application embodiment in the electronic device 100. The memory 102 may store an operating system, such as uCOS, VxWorks, RTLinux, or other embedded operating systems.
[0039] The wireless communication module 103 may include a Bluetooth communication module 103A (optional) and a WLAN communication module 103B. In some embodiments, the WLAN communication module 103B may be integrated with other communication modules (e.g., the Bluetooth communication module 103A). The WLAN communication module 103B and / or the Bluetooth communication module 103A can transmit signals to detect and scan devices near the electronic device 100, enabling the electronic device 100 to discover nearby devices using one or more wireless communication technologies, such as Bluetooth or WLAN, and to perform data transmission and reception based on the aforementioned wireless communication connection. The Bluetooth communication module 103A may provide a solution including one or more Bluetooth communication technologies, such as Basic Rate / Enhanced Data Rate (BR / EDR) or Bluetooth Low Energy (BLE). WLAN communication module 103B can provide WLAN communication solutions including one or more of the following: wireless fidelity direct (Wi-Fi direct), wireless fidelity local area networks (Wi-Fi LAN), or wireless fidelity software access point (Wi-Fi softAP). Wireless communication module 103 can receive electromagnetic waves via an antenna (not shown in Figure 1), frequency modulate and filter the electromagnetic wave signal, and send the processed signal to processor 101. Wireless communication module 103 can also receive signals to be transmitted from processor 101, frequency modulate and amplify them, and then convert them into electromagnetic waves for radiation via the antenna.
[0040] In some embodiments, the wireless communication module 103 may also provide wireless communication solutions applied to the electronic device 100, including global navigation satellite system (GNSS), frequency modulation (FM), near field communication (NFC), infrared (IR), and other wireless communication technologies.
[0041] The display screen 104 can be used to display images, videos, etc. The display screen 104 may include a display panel. The display panel may be a liquid crystal display (LCD), an organic light-emitting diode (OLED), an active-matrix organic light-emitting diode (AMOLED), a flexible light-emitting diode (FLED), a minimized LED, a microLED, a quantum dot light-emitting diode (QLED), etc. In some embodiments, the electronic device 100 may include one or N display screens 104, where N is a positive integer greater than 1.
[0042] The sensor module 105 may include a touch sensor 105A, etc. The touch sensor 105A can also be referred to as a "touch device". The touch sensor 105A can be disposed on the display screen 104, and the touch sensor 105A and the display screen 104 together form a touch screen, also called a "touchscreen". The touch sensor 105A can be used to detect touch operations applied to or near it. Optionally, the sensor module 105 may also include a gyroscope sensor (not shown in Figure 1), an accelerometer sensor (not shown in Figure 1), etc.
[0043] The audio module 106 can be used to convert digital audio information into analog audio signal output, and can also be used to convert analog audio input into digital audio signal. The audio module 106 can also be used to encode and decode audio signals. In some embodiments, the audio module 106 can also be disposed in the processor 101, or some functional modules of the audio module 106 can be disposed in the processor 101.
[0044] The speaker 107, also known as a "loudspeaker," is used to convert audio electrical signals into sound signals. The electronic device 100 can listen to music or make hands-free calls through the speaker 107.
[0045] To better illustrate the implementation of the image processing method provided in the embodiments of this application, the specific implementation principle of electronic devices displaying images on a screen is first introduced.
[0046] Figure 2 is a schematic diagram illustrating the implementation principle of an electronic device displaying an image on a screen according to an embodiment of this application.
[0047] As shown in Figure 2, when the electronic device 100 needs to display the interface 1 of the first application on the screen, the first application can read image 1 from the image resource storage module through the main thread. Then, the main thread can call the graphics rendering processing module to process the read image 1, such as performing color conversion, transparency processing, or scaling of the pixels in image 1. Next, the graphics rendering processing module can return image 2, obtained based on image 1, to the main thread. The main thread then sends image 2 to the image compositing module. The image compositing module can compose interface 1 based on image 2. Then, the image compositing module can write the data of interface 1 to the frame buffer, and the frame buffer can display the data of interface 1. The screen of the electronic device 100 can refresh and display interface 1, thus the electronic device 100 can present image 2 in interface 1 through the screen.
[0048] The image resource module can store one or more images arranged in a specified format, such as images arranged in RGB or RGBA formats (which can be called bitmap images). Here, R represents the red channel, B the blue channel, G the green channel, and A the alpha value. The color of each pixel in the image is represented by its corresponding RGB or RGBA value. For example, in an RGB format image, a pixel with an RGB value of (255, 0, 0) indicates that the pixel is red; in an RGBA format image, a pixel with an RGBA value of (255, 0, 0, 0.5) indicates that the pixel is red and has an alpha value of 0.5 (i.e., semi-transparent).
[0049] In some implementation scenarios, electronic device 100 typically uses a main thread to call the graphics rendering processing module to process image 1 as a whole.
[0050] For example, image 1 may include three regions: region 1, region 2, and region 3. When electronic device 100 processes image 1 through the graphics rendering module via the main thread, the main thread first processes region 1; after region 1 is processed, the main thread then processes region 2; and after region 2 is processed, the main thread then processes region 3. In other words, the main thread processes each region in image 1 sequentially. When all regions in image 1 have been processed, the main thread obtains image 2.
[0051] However, it is not difficult to see from the above process that since the main thread processes each region of the image serially, that is, the main thread can only process one region of an image at a time, when processing high-resolution or complex images, because each region has a large number of pixels or the number of regions in the image is large, the processing is more complicated. Therefore, this serial processing method is prone to causing the image processing time to be too long, which in turn leads to stuttering, frame drops and other issues, which greatly affects the smoothness and response speed of the application.
[0052] Therefore, this application provides an image processing method in which the electronic device 100 can divide image 1 into multiple sub-images and create one or more sub-threads in addition to the main thread. Then, the electronic device 100 can process the multiple sub-images in parallel through the main thread and the one or more created sub-threads to obtain image 2.
[0053] In this embodiment of the application, a sub-image can also be understood as an image block divided from the complete image 1. That is, each sub-image is a part of image 1, and the sub-images can be stitched together to form the complete image 1. The contents of each sub-image are different.
[0054] Figure 3A is a schematic diagram of the logic flow of an image processing method provided in an embodiment of this application.
[0055] As shown in Figure 3A, the main thread of the first application reads image 1 from the image resource storage module. Then, the main thread can call the UI module to check whether it meets the first preset condition. If it meets the first preset condition, the main thread can create a thread pool and create M child threads through the thread pool. This thread pool includes M child threads, so the electronic device 100 includes a total of M+1 threads. Among them, the M child threads can include child thread 1, child thread 2, etc. Furthermore, the main thread can divide image 1 into N sub-images through the UI module. Then, the main thread can distribute the N-1 sub-images to the M child threads. Each child thread can call the rendering interface provided by the graphics rendering processing module (e.g., the 2D vector graphics processing function library Skia, etc.) to process its own acquired sub-image. For example, child thread 1 can process sub-image 1, child thread 2 can process sub-image 2, and so on. At the same time, while the child threads are processing sub-images, the main thread can also call the rendering interface in parallel to process sub-image N. After each child thread has finished processing its own sub-image, each child thread can return the processing result to the main thread. The main thread stitches together the sub-images processed by each sub-thread and the sub-image N processed by the main thread (that is, the N sub-images stitched together by the main thread) to obtain image 2.
[0056] Next, the main thread can send image 2 to the image compositing module. The image compositing module can then compose interface 1 based on image 2. The image compositing module can then write the data of interface 1 to the frame buffer, which can then display the data of interface 1. The display screen of electronic device 100 can refresh and display interface 1, thereby allowing electronic device 100 to present image 2 from interface 1 on the display screen.
[0057] Thus, as can be seen from the above process, by implementing the image processing method provided in this application, the main thread and one or more sub-threads can process sub-images in parallel, thereby improving the processing efficiency of image 1, greatly shortening the image processing time, and improving the smoothness and response speed of the application.
[0058] Figure 3B is a comparative schematic diagram of two image processing flows provided in an embodiment of this application.
[0059] As shown in Figure 3B, for example, image 1 has a resolution of 1678x944, meaning its height is 944 pixels, its width is 1678 pixels, its top-left vertex coordinates are (x1, y1), and its bottom-right vertex coordinates are (x2, y2). Image 1 can include three regions: sub-image 1, sub-image 2, and sub-image 3. In the serial processing method, if the main thread does not create one or more sub-threads, the main thread processes the above three regions serially. That is, the main thread processes sub-image 1 first, then sub-image 2, and finally sub-image 3. When all three regions have been processed, the main thread obtains image 2.
[0060] In the image processing method provided in this application, the main thread can create two sub-threads, namely sub-thread 1 and sub-thread 2. Furthermore, the main thread can divide image 1 into three sub-images. The three threads can process their respective sub-images in parallel; that is, while sub-thread 1 processes sub-image 1 and sub-thread 2, the main thread can process sub-image 3 in parallel. Sub-thread 1 and sub-thread 2 can also process sub-images in parallel. When sub-thread 1 and sub-thread 2 finish processing their sub-images, they can return the processed sub-images 1 and 2 to the main thread. The main thread then stitches the processed sub-images 1, 2, and 3 together to obtain image 2.
[0061] As can be seen from Figure 3B, the image processing method provided in this application embodiment allows multiple threads to process image 1 in parallel. Compared with the serial processing method of the main thread, it can improve the processing efficiency of image 1, greatly shorten the image processing time, and improve the smoothness and response speed of the application.
[0062] Figures 4A-4C are schematic diagrams of user interfaces for a set of application scenarios provided in the embodiments of this application.
[0063] In one example, as shown in Figure 4A, the electronic device 100 can display a desktop 410. This desktop 410 displays a page containing application icons, including icons for multiple applications (e.g., weather app icon, stock app icon, calculator app icon, settings app icon, email app icon, desktop customization app icon 412, music app icon, video app icon 413, browser app icon, etc.). A status bar 411 is displayed in the upper portion of the desktop 410. This status bar 411 may include one or more indicators, such as one or more signal strength indicators for mobile communication signals (also known as cellular signals), battery status indicators, time indicators, Wi-Fi signal indicators, etc.
[0064] Electronic device 100 can receive a touch operation (e.g., a click) on the icon 412 of the desktop beautification application, and in response to the touch operation, electronic device 100 can display the desktop beautification interface 420.
[0065] As shown in Figure 4A, the desktop beautification interface 420 displayed by the electronic device 100 may include one or more page switching controls (e.g., a "wallpaper" page switching control, a "theme" page switching control, and a "my" page switching control, etc.). The desktop beautification interface 420 may also include a large-size image 421. Before displaying the desktop beautification interface 420, the electronic device 100 may implement the image processing method provided in this application on the large-size image 421, that is, to process the original image corresponding to the large-size image 421 in parallel through the main thread and one or more created main threads, thereby obtaining the large-size image 421 displayed on the screen of the electronic device 100. In this way, the image processing efficiency can be improved, the image processing time can be greatly shortened, and the smoothness and responsiveness of the application can be improved.
[0066] In another example, as shown in FIG4B, electronic device 100 can receive a touch operation (e.g., a click) on an icon 413 of a video application, and in response to the touch operation, electronic device 100 can display a video interface 430.
[0067] As shown in Figure 4B, the video interface 430 may include one or more page switching interfaces (e.g., "Following" page switching control, "Discover" page switching control, "Nearby" page switching control, etc.), and one or more video playback windows, such as video playback window 431, video playback window 432, etc. Video playback window 431 and video playback window 432 can be used to play videos. For the first frame image of the video stream displayed in video playback windows 431 and 432, the electronic device 100 can implement the image processing method provided in this application, that is, to process the original image corresponding to the first frame image in parallel through the main thread and one or more created main threads, thereby obtaining the first frame image of the video stream displayed on the screen of the electronic device 100. This can improve image processing efficiency, greatly shorten image processing time, and improve the smoothness and response speed of the application.
[0068] In another example, as shown in Figure 4C, electronic device 100 can receive a touch operation (e.g., swipe) applied to video interface 430. In response to this touch operation, electronic device 100 can display a video playback window in video interface 430. This video playback window 433 can be used to play video. For the first frame of the video stream displayed in video playback window 433, electronic device 100 can implement the image processing method provided in this application, that is, to process the original image corresponding to the first frame in parallel through the main thread and one or more created main threads, thereby obtaining the first frame of the video stream displayed on the screen of electronic device 100. This improves image processing efficiency, significantly shortens image processing time, and enhances the smoothness and responsiveness of the application.
[0069] Figure 5 is a flowchart illustrating an image processing method provided in an embodiment of this application.
[0070] As shown in Figure 5, the process of this image processing method may include:
[0071] S501: Electronic device 100 reads image 1 from image resource storage module through the main thread of the first application.
[0072] S502: Electronic device 100 determines whether the first preset condition is met.
[0073] Specifically, the electronic device 100 can determine whether the first preset condition is met based on the parameters of the first application. Wherein:
[0074] 1. The parameters of the first application may include one or more of the following: the process name of the first application (i.e., the application package name of the first application), the parameters of image 1, etc. The parameters of image 1 may include one or more of the following: the resolution of image 1 (including length and width information), the identifier of image 1, etc.
[0075] 2. The first preset condition may include one or more of the following: whether the process name of the first application is recorded in the whitelist, whether image 1 is a large image, whether image 1 is the first frame of the video stream in the video interface, etc.
[0076] The whitelist can be used to record the process names of one or more applications.
[0077] Image 1 is considered a large image if its length (or simply length) is greater than or equal to a specified value A1 and its width (or simply width) is greater than or equal to a specified value A2. Preferably, both specified values A1 and A2 are 512 pixels. In other words, an image is considered large when its length and width are both greater than or equal to 512 pixels (i.e., a resolution of 512x512).
[0078] The identifier for Image 1 can be used to indicate whether Image 1 is the first frame of the video stream in the video interface. When the value of the identifier is the first value, it can be used to indicate that Image 1 is the first frame of the video stream in the video interface; when the value of the identifier is the second value, it can be used to indicate that Image 1 is not the first frame of the video stream in the video interface.
[0079] Preferably, when the process name of the first application is recorded in the whitelist and image 1 is a large-size image, or when the process name of the first application is recorded in the whitelist and image 1 is the first frame image of the video stream in the video interface, the electronic device 100 can determine that the first preset condition is met.
[0080] S503: When the first preset condition is met, the electronic device 100 creates a thread pool and creates M child threads in the thread pool. The electronic device 100 includes M+1 threads, and the M+1 threads include M child threads and one main thread.
[0081] Preferably, the value of M can be fixed at 2, that is, including the main thread (i.e., the main thread of the first application mentioned above), there are a total of 3 threads processing image 1. In this way, the electronic device 100 can not only improve the efficiency of thread creation, but also, as experimental data has shown, regardless of how the number of other running processes or threads of the electronic device 100 changes, when M is 3, the electronic device 100 can guarantee the smooth progress of sub-image processing with a very high probability, unaffected by environmental changes.
[0082] In another example, electronic device 100 can also determine the number Q of currently idle processors and create child threads based on that number Q. Generally, M = Q - 3, meaning the number of threads is always kept at Q - 2. In this way, electronic device 100 can make great use of the processor's computing power and improve its processing efficiency.
[0083] In this embodiment of the application, there are no restrictions on the specific value of M.
[0084] S504: Electronic device 100 determines whether the thread pool has been created successfully.
[0085] Specifically, the main thread can call a specified function (e.g., pthread_pool) to create a thread pool. Then, the thread pool creates M child threads. When the thread pool is created successfully, the specified function (e.g., pthread_pool) can return a value S1 (e.g., 1 or 0) to the main thread, indicating successful thread pool creation; when the thread pool creation fails, the specified function (e.g., pthread_pool) can return a value S2 (e.g., 0 or 1) to the main thread, indicating that thread pool creation failed.
[0086] S505: When it is determined that the thread pool has been successfully created, the electronic device 100 divides image 1 into N sub-images.
[0087] Preferably, N can be the same as the number of threads, i.e., N = M + 1; or, N can be less than M + 1.
[0088] In one example, N can also be greater than M+1. However, when N is greater than M+1, M+1 threads process M+1 sub-images first. Only after one or more of the M+1 threads have finished processing the currently received sub-images can the remaining NM-1 sub-images be processed.
[0089] S506: Electronic device 100 processes sub-images in parallel using M+1 threads (including M sub-threads and one main thread). Each thread processes one sub-image, and different threads process different sub-images.
[0090] Specifically, the main thread can distribute N-1 sub-images to M sub-threads. Each sub-thread receives one sub-image and processes it; for example, sub-thread 1 receives sub-image 1, and sub-thread 2 receives sub-image 2. When all N-1 sub-threads have distributed the images, the main thread can process the Nth sub-image.
[0091] At this point, the child threads and the main thread are processing the sub-images in parallel. For example, while child thread 1 is processing sub-image 1 and child thread 2 is processing sub-image 2, the main thread can also process sub-image N in parallel. Simultaneously, each child thread is also processing its own sub-image in parallel; for example, while child thread 1 is processing sub-image 1, child thread 2 can also process sub-image 2.
[0092] S507: Electronic device 100 determines whether all sub-threads have successfully processed the sub-image.
[0093] Specifically, when a child thread calls the rendering interface provided by the graphics rendering processing module to process a child image, if the rendering interface successfully processes the child image, it can return a value S3 (e.g., 0 or 1) to the child thread, indicating that the rendering interface has successfully processed the child image, and the child thread has successfully processed the child image. If the rendering interface fails to process the child image, it can return a value S4 (e.g., 1 or 0) to the child thread, indicating that the rendering interface has failed to process the child image, and the child thread has failed to process the child image.
[0094] S508: When all sub-threads have successfully completed the processing of the sub-images, the electronic device 100 stitches together the processed N sub-images through the main thread to obtain image 2.
[0095] Specifically, the main thread can determine the processing status of the child threads based on a semaphore mechanism. When all child threads have successfully processed their respective sub-images, that is, image 1 has been processed, the main thread can stitch the processed sub-images together to obtain image 2. How the main thread determines the processing status of the child threads based on the semaphore mechanism will be described in detail in subsequent embodiments, and will not be repeated here.
[0096] S509: Electronic device 100 synthesizes interface 1 of the first application based on image 2, then writes the data of interface 1 into frame buffer, and then electronic device 100 sends the data of interface 1 to display through frame buffer.
[0097] It should be noted that most applications displaying their interfaces on a screen typically have three layers, each displaying one image. For example, interface 1 may include: a status bar layer (for displaying the status bar image), a bottom or side navigation bar layer (for displaying the navigation bar image), and a layer for image 2 (for displaying image 2). When the image compositing module in electronic device 100 receives the navigation bar image, status bar image, and image 2, it can composite these three images into interface 1. Then, the image compositing module in electronic device 100 writes the data of interface 1 into a frame buffer and refreshes the display of interface 1 on the screen based on the frame buffer. The navigation bar image and status bar image are obtained by system processes, while image 2 is obtained by the first application.
[0098] S510: When the electronic device 100 determines that the first preset condition is not met, or determines that the thread pool creation has failed, or determines that one or more sub-threads have failed to process the sub-image, the electronic device 100 processes image 1 through the main thread to obtain image 2.
[0099] Specifically, when a child thread fails to process a child image, that is, when the rendering interface corresponding to the child thread returns value S4, the child thread can send a child thread processing failure indication message to the main thread, indicating that the child thread failed to process the child image.
[0100] When electronic device 100 processes image 1 through the main thread, that is, electronic device 100 sequentially processes each region on image 1 through the main thread to obtain image 2, this description can be referred to the foregoing description.
[0101] After obtaining image 2, electronic device 100 can execute S509.
[0102] In this embodiment, sub-image processing can refer to color conversion, transparency processing, or scaling of pixels in the sub-image. In some application scenarios, when the electronic device 100 receives a compressed image (e.g., a jpeg or jpg image) from a server via the main thread of the first application, or when the compressed image is read from the hard drive into memory, the electronic device 100 can decode the compressed image through the above steps S501 to S510, that is, convert the compressed image into an image arranged in RGB or RGBA format. At this time, the compressed image is image 1, and sub-image processing is equivalent to decoding the sub-image.
[0103] Figure 6 is a schematic diagram of the software framework of an electronic device 100 provided in an embodiment of this application.
[0104] As shown in Figure 6, the device architecture of an electronic device can be divided into several layers. Each layer has a clear role and division of labor, and the layers communicate with each other through software interfaces. In some embodiments, the device architecture of the electronic device is divided into five layers, from top to bottom: application layer, application framework layer, Android runtime and system libraries, hardware abstraction layer, and kernel layer. Wherein:
[0105] The application layer includes a series of application packages, such as camera, calendar, notes, gallery, weather, and first app.
[0106] The application framework layer provides application programming interfaces (APIs) and a programming framework for applications in the application layer. The application framework layer includes predefined functions, which may include a window manager, content provider, resource manager, and notification manager. Specifically: The window manager manages window programs. It can obtain the screen area, determine if a status bar is present, lock the screen, and capture the screen. The content provider stores and retrieves data, making this data accessible to applications. This data may include videos, images, audio, made and received phone calls, browsing history and bookmarks, and phone books. The resource manager provides applications with various resources, such as localized strings, icons, images, layout files, and video files. The notification manager allows applications to display notifications in the status bar. These notifications can be used to convey informational messages and can disappear automatically after a short pause without user interaction. For example, a notification manager can be used to notify of download completion or message alerts. The notification manager can also display notifications as icons or scrollbar text in the system's top status bar, such as notifications from background applications, or as dialog windows on the screen. Examples include displaying text messages in the status bar, emitting alert sounds, vibrating electronic devices, and flashing indicator lights.
[0107] In this embodiment, the application framework layer may further include: an image resource storage module, a thread pool module, and a UI module. The UI module may include a parallel task creation and distribution module and a scene recognition module.
[0108] The image resource storage module can store the original image to be processed (e.g., image 1 as described above).
[0109] The thread pool module can be created from the main thread and includes M child threads. It is used to manage child threads, such as creating child threads, triggering child threads to process sub-images, destroying child threads, and maintaining the task execution order and lifecycle of each child thread.
[0110] The parallel task creation and distribution module can be located in the SkDrawBitmapTask class. It can be used to divide image 1 into N sub-images and encapsulate each sub-image into a callback function, waiting for the thread pool module to call it.
[0111] The scene recognition module is used to determine whether the first preset condition is met.
[0112] The Android Runtime consists of core libraries and a virtual machine. The Android runtime is responsible for the scheduling and management of the Android system.
[0113] The core library consists of two parts: one part is the functionalities that need to be called by the Java language, and the other part is the Android core library.
[0114] The application layer and application framework layer run in a virtual machine. The virtual machine executes the Java files of the application layer and application framework layer as binary files. The virtual machine is used to perform functions such as object lifecycle management, stack management, thread management, security and exception management, and garbage collection.
[0115] The system library can include multiple functional modules. For example, a surface manager, multiple rendering execution modules (M+1 or more), and a graphics rendering processing module (such as the 2D graphics engine Skia). The surface manager manages the display subsystem and provides fusion of 2D and 3D layers for multiple applications. The multiple rendering execution modules (M+1 or more) can call the rendering interfaces provided by the graphics rendering processing module. The graphics rendering processing module can be used for sub-image processing, and the 2D graphics engine Skia is a drawing engine for 2D graphics.
[0116] The Hardware Abstraction Layer (HAL) sits between the kernel layer and the application framework layer, acting as a bridge between them. The HAL may include an image compositing module, used to synthesize the interface 1 of the first application based on image 2.
[0117] The kernel layer includes multiple hardware drivers, such as audio drivers, sensor drivers, and display drivers. Among them, the display driver may include frame buffers.
[0118] In this embodiment of the application, Figure 6 is only used as an example to explain the application and does not constitute any limitation.
[0119] Figure 7 is a schematic diagram of the module interaction of an image processing method provided in an embodiment of this application.
[0120] As shown in Figure 7, the module interaction of this image processing method can specifically include:
[0121] S701: The main thread of the first application reads image 1.
[0122] Specifically, the main thread of the first application can read image 1 from the image resource storage module.
[0123] For example, the main thread of the first application can read image 1 based on a specified function. For instance, the main thread of the first application can read image 1 based on the functions of the Skcanvas class, SkBitmapDevice class, and SkDraw class. This application does not limit the method by which the main thread reads image 1.
[0124] S702: The main thread of the first application calls the scene recognition module and sends the parameters of the first application to the scene recognition module.
[0125] The parameters of the first application may include one or more of the following: the process name of the first application, parameters of image 1, etc. For a detailed explanation of the parameters of the first application, please refer to the description of S502 above.
[0126] S703: The scene recognition module determines whether the first preset condition is met based on the parameters of the first application.
[0127] For an explanation of this step, please refer to the description of S502 above.
[0128] S704: When it is determined that the first preset condition is met, the scene recognition module can send indication information 1 to the main thread of the first application. Indication information 1 is used to indicate that the first preset condition is met.
[0129] S705: The main thread of the first application determines that the first preset condition is met based on the indication information 1.
[0130] S706: The main thread of the first application creates a thread pool, and then creates M child threads through the thread pool.
[0131] For an explanation of the number of child threads M, please refer to the description in S503 above.
[0132] For example, the main thread of the first application can create a thread pool by calling a specified function (e.g., pthread_pool, etc.). This thread pool is contained within an object of the ThreadPool class. This application does not impose any restrictions on how the main thread of the first application creates the thread pool.
[0133] S707: The main thread of the first application determines whether the thread pool has been created successfully.
[0134] For instructions on this step, please refer to the description in S504.
[0135] S708: When it is determined that the thread pool has been successfully created, the main thread of the first application calls the parallel task creation and distribution module.
[0136] It should be noted that the thread pool includes M sub-threads, but the electronic device 100 at this time includes a total of M+1 threads. The M+1 threads include M sub-threads and one main thread. The M+1 threads can process sub-images in parallel.
[0137] S709: The parallel task creation and distribution module divides image 1 into N sub-images.
[0138] S710: The parallel task creation and distribution module sends the parameters of N sub-images back to the main thread of the first application.
[0139] Specifically, the parallel task creation and distribution module can divide image 1 into N sub-images using the SkdrawBitmapTask class. Each sub-image includes its own parameters (e.g., the coordinates of the top-left vertex, the size, width, and height of each sub-image). The parallel task creation and distribution module creates a rasterBlitter object for each sub-image, and then packages each rasterBlitter object and its corresponding sub-image parameters into a corresponding structure object `param`. This structure object can be passed back to the main thread of the first application, waiting for the corresponding thread to call it.
[0140] For example, the parallel task creation and distribution module can divide image 1 into three sub-images using the SkdrawBitmapTask class: sub-image 1, sub-image 2, and sub-image 3. Sub-image 1 includes the parameters of sub-image 1, sub-image 2 includes the parameters of sub-image 2, and sub-image 3 includes the parameters of sub-image 3. The parallel task creation and distribution module creates a rasterBlitter object 1 for sub-image 1, a rasterBlitter object 2 for sub-image 2, and a rasterBlitter object 3 for sub-image 2. Then, the parallel task creation and distribution module packages rasterBlitter object 1 plus the parameters of sub-image 1 into structure object 1 (param1), rasterBlitter object 2 plus the parameters of sub-image 2 into structure object 2 (param2), and rasterBlitter object 3 plus the parameters of sub-image 3 into structure object 3 (param3), and returns these three structure objects to the main thread. param1 can wait for a call from child thread 1, param2 can wait for a call from child thread 2, and param3 can wait for a call from the main thread.
[0141] The parameters of sub-image 1 include the coordinates of the top-left vertex, the size, width, and height of sub-image 1. The parameter descriptions for sub-image 2 and sub-image 3 can be found in sub-image 1.
[0142] S711: The main thread of the first application distributes the parameters of N-1 sub-images to M sub-threads.
[0143] Specifically, when the thread pool creates M child threads, each child thread holds its own `work` object. Each child thread can obtain the parameters of the sub-image through its respective `work` object. Simultaneously, each `work` object can be bound to a `param` structure object corresponding to the sub-image (this structure object contains the sub-image's parameters). The main thread of the first application can add N-1 `param` structure objects to the thread pool queue, waiting for child threads in the thread pool to call them through their respective `work` objects.
[0144] For example, based on the example given in S710, when child thread 1 and child thread 2 are created, child thread 1 can hold work1, and child thread 2 can hold work2. work1 can be bound to param1, and work2 can be bound to param2. Therefore, child thread 1 can obtain param1 (including the parameters of sub-image 1) through work1, while child thread 2 can obtain param2 (including the parameters of sub-image 2) through work2.
[0145] S712: Each sub-thread transmits the parameters of the corresponding sub-image to the corresponding rendering execution module in multiple rendering execution modules.
[0146] S713: Each rendering execution module can call the rendering interface provided by the graphics rendering processing module, and process the sub-images based on the parameters of each sub-image through the graphics rendering processing module.
[0147] Specifically, each rendering execution module processes one sub-image. Therefore, each sub-thread can send the parameters of the sub-image it has obtained to one of the multiple rendering execution modules. That is, each rendering module can configure a `rastrBlitter` object for the corresponding sub-image.
[0148] For example, based on the example given in S710, when child thread 1 obtains param1 through work1, child thread 1 can send param1 to rendering execution module 1; when child thread 2 obtains param2 through work2, child thread 2 can send param2 to rendering execution module 2.
[0149] Then, rendering execution module 1 can call the rendering interface provided by the graphics rendering processing module, and through the rendering interface, the graphics rendering processing module processes sub-image 1 based on param1. Rendering execution module 1 configures rasterBlitter object 1. Rendering execution module 2 can call the rendering interface provided by the graphics rendering processing module, and through the rendering interface, the graphics rendering processing module processes sub-image 2 based on param2. Rendering execution module 2 configures rasterBlitter object 2.
[0150] As a further example, the graphics rendering processing module provides a rendering interface through the function `SkRasterPipelineBlitter`. Each rendering execution module can encapsulate the rendering interface through the `Skscan` class and pass the parameters of the sub-image to the rendering interface through the function `fBlitRect(x,y,w,h)`. The rendering interface can trigger the graphics rendering processing module to process the sub-image based on the parameters of the sub-image through the `rasterBlitter` object. Here, in `fBlitRect(x,y,w,h)`, `x` represents the x-coordinate of the top-left vertex of the sub-image, `y` represents the y-coordinate of the top-left vertex of the sub-image, `w` represents the width of the sub-image, and `h` represents the height of the sub-image.
[0151] S714: After the rendering interface has finished processing the sub-images based on the graphics rendering processing module, the rendering interface can send the processed sub-images back to each sub-thread through the corresponding rendering execution module.
[0152] It should be noted that when the rendering interface successfully processes a sub-image, the rendering interface can return a value S3 (e.g., 0 or 1) to the sub-thread corresponding to that sub-image, indicating that the rendering interface has successfully processed the sub-image, and the sub-thread has successfully processed the sub-image.
[0153] Specifically, here is an explanation of how each sub-thread processes sub-images in parallel:
[0154] When a thread pool creates child threads, each child thread's `work` object can share a semaphore `workSem1` to control the state of each child thread. When a newly created thread pool has not yet received parameters from its child image, the thread pool calls the function `semwait(&workSem1)` to set the value of `workSem1` to 0, causing each child thread to enter a blocked state. While a child thread is in a blocked state, it does not consume CPU resources.
[0155] When the main thread detects that it has sent the structure object `param` corresponding to a sub-image to the queue in the thread pool, the thread pool calls the function `sempost(&workSem1)` to set the value of `workSem1` to 1. Simultaneously, the thread pool unblocks the corresponding child thread, which can then retrieve the structure object `param` through its held `work` object and process it using the rendering interface. However, once the thread pool detects that the value of `workSem1` is 1, it immediately calls the function `semwait(&workSem1)` to set the value of `workSem1` to 0, thus blocking other child threads that have not received the structure object `param`. Child threads that have received the structure object `param` can then process the sub-image in parallel. In this way, by setting the `workSem1` semaphore, multiple threads in the thread pool can execute sequentially, achieving parallel processing of sub-images.
[0156] For example, based on the S712 example, the thread pool can create two child threads: child thread 1 and child thread 2. Child thread 1 holds `work1` and child thread 2 holds `work2`, which can jointly hold a semaphore `workSem1` to control the state of each child thread. When child thread 1 and child thread 2 have not yet received parameters from the sub-image, the thread pool calls the function `semwait(&workSem1)` to set the value of `workSem1` to 0, causing each child thread to enter a blocked state. When a child thread is in a blocked state, it does not consume CPU resources.
[0157] Then, when the main thread detects that it has sent the param1 corresponding to sub-image 1 to the queue in the thread pool, the thread pool calls the function sempost(&workSem1) to set the value of workSem1 to 1. At the same time, the thread pool unblocks the corresponding sub-thread 1, which can then obtain param1 through the held work1 and call the rendering interface to process sub-image 1. However, once the thread pool detects that the value of workSem1 is 1, it immediately calls the function semwait(&workSem1) to set the value of workSem1 to 0, thus blocking sub-thread 2.
[0158] Next, when the main thread detects that it has sent the parameter 2 corresponding to sub-image 2 to the queue in the thread pool, the thread pool calls the function sempost(&workSem1) to set the value of workSem1 to 1. At the same time, the thread pool unblocks the corresponding sub-thread 2, and then immediately sets the value of workSem1 back to 0. Sub-thread 2 can then obtain parameter 2 through the held work2 and call the rendering interface to process sub-image 2. At this point, sub-thread 2 can execute in parallel with sub-thread 1.
[0159] S715: Each sub-thread sends the processed sub-images back to the main thread of the first application.
[0160] S716: The main thread of the first application transmits the parameters of the sub-image N to the corresponding rendering execution module N among multiple rendering execution modules.
[0161] It should be noted that after the main thread distributes sub-images 1 to N-1 to the child threads, the main thread immediately sends the parameters of sub-image N to the rendering execution module. The main thread and the child threads execute in parallel. The rendering execution module N can be configured with the rasterBlitter object N corresponding to sub-image N.
[0162] S717: Rendering execution module N among multiple rendering execution modules can call the rendering interface provided by the graphics rendering processing module, and process the sub-image N based on the parameters of the sub-image N through the graphics rendering processing module.
[0163] S718: After the graphics rendering processing module completes the processing of the sub-image N, the rendering interface can send the processed sub-image N back to the main thread through the rendering execution module N.
[0164] For an explanation of how the main thread processes the sub-image N through the rendering execution module N, please refer to the aforementioned description of the sub-thread.
[0165] S719: The main thread of the first application determines whether all child threads have successfully processed the sub-image.
[0166] Specifically, the main thread can determine whether all child threads have successfully processed the sub-image in the following way:
[0167] First, the work objects bound to each child thread can share a semaphore, workSem2, which is initially set to 0. When a child thread successfully processes a sub-image, the value of workSem2 is incremented by 1.
[0168] When the main thread finishes processing sub-image N, it will execute a for loop M times (i.e., the number of for loops equals the number of sub-threads). Each for loop can call the semwait(&workSem2) function to check the value of workSem2.
[0169] Each time the main thread executes the for loop, it calls the `semwait(&workSem2)` function to check the value of the semaphore `workSem2`. When the value of `workSem2` is 0, the main thread waits in the current for loop until it detects that the value of `workSem2` is 1 (i.e., a child thread has successfully processed a sub-image). At this point, the main thread releases its waiting state, exits the current for loop, and decrements the value of `workSem2` by 1. Then, the main thread executes the next for loop, repeating the process of checking the value of `workSem2` within the for loop.
[0170] In this way, when the M for loops have finished executing, that is, when the M child threads have finished executing, the main thread determines that all child threads have successfully processed the child image.
[0171] In one implementation, when the main thread processes sub-image N slowly, by the time it finishes processing sub-image N, T (T <= M) child threads have already finished processing their sub-images. At this point, the value of `workSem2` is T. When the main thread executes the `for` loop T times, each iteration immediately detects that the value of `workSem2` is greater than 0 using the `semwait(&workSem2)` function, immediately unblocks, exits the current `for` loop, enters the next `for` loop, and simultaneously decrements the value of `workSem2` by 1. In this case, the main thread executes the `for` loop T times quickly without waiting. That is, the main thread only enters a waiting state when the value of `workSem2` is 0, and exits the `for` loop as soon as the value of `workSem2` is greater than 0.
[0172] For example, based on the S714 example, child thread 1's `work1` and child thread 2's `work2` can jointly hold a semaphore `workSem2`. When the main thread finishes processing sub-image 3, it needs to execute a `for` loop twice. If, during the first `for` loop, the main thread detects that the value of `workSem2` is 0, meaning neither child thread 1 nor child thread 2 has successfully processed the sub-image, the main thread is in a waiting state during the first `for` loop. When child thread 1 successfully processes sub-image 1, the `semwait(&workSem2)` function detects that the value of `workSem2` is 1, the main thread releases its waiting state, exits the first `for` loop, and simultaneously decrements the value of `workSem2` by 1, setting it back to 0.
[0173] Then, when the main thread executes the second for loop, it detects that the value of `workSem2` is 0 using the `semwait(&workSem2)` function, meaning that child thread 2 has not successfully completed its processing, and the main thread waits. When child thread 2 successfully completes its processing of sub-image 2, the `semwait(&workSem2)` function detects that the value of `workSem2` is 1, the main thread releases its waiting state, and exits the second for loop. After the two for loops have completed, the main thread can be certain that both child thread 1 and child thread 2 have successfully processed their respective sub-images.
[0174] S720: After the main thread of the first application determines that all child threads have successfully processed the sub-images, the main thread stitches together the processed sub-images to obtain image 2.
[0175] S721: The main thread of the first application sends image 2 to the image compositing module.
[0176] S722: The image compositing module uses the interface 1 of the first application based on image 2 for image compositing.
[0177] S723: The image compositing module writes the data from interface 1 into the frame buffer of the display driver.
[0178] S724: Frame buffer sends data to display interface 1.
[0179] The descriptions of S721 to S724 can be found in S509.
[0180] S725: When the first preset condition is not met, or the thread pool creation fails, or one or more child threads fail to process the child image, the main thread of the first application processes image 1 and obtains image 2.
[0181] Specifically, when the scene recognition module determines that the first preset condition is not met based on the parameters of the first application, the scene recognition module sends instruction information 2 to the main thread to indicate that the first preset condition is not met. The main thread then processes image 1 and obtains image 2.
[0182] Specifically, when the main thread determines that the thread pool creation has failed, the main thread processes image 1 and obtains image 2.
[0183] Specifically, when one or more child threads fail to process a sub-image, that is, when the rendering interface corresponding to one or more child threads returns value S4, the child thread can indicate to the main thread that it failed to process the sub-image. The main thread then processes image 1 to obtain image 2.
[0184] After the main thread obtains image 2, it can execute S721 to S724.
[0185] In one embodiment, after all child threads in the thread pool have finished processing their respective sub-images, the thread pool can wait for a specified time T1. If, within the specified time T1, the thread pool receives sub-image parameters for another image (referred to as image 3), the thread pool triggers the child threads to execute the sub-image processing. If, within the specified time T1, the thread pool does not receive sub-image parameters for image 3, the thread pool can destroy all child threads. The processing of image 3 is the same as that of image 1, as described in the embodiments of Figures 5 and 7 above, and will not be repeated here.
[0186] Implementing the image processing method provided in this application can greatly improve the efficiency of image processing.
[0187] Figure 8 is a schematic diagram comparing the implementation effects of different image processing methods provided in this application.
[0188] As shown in Figure 8(a), by capturing the thread processing time through Trace, if the image processing method provided in this solution is not implemented, the time taken to process the entire image 1 with a size of 1798x944 (e.g., decoding) by only one main thread is 35.26 milliseconds.
[0189] As shown in Figure 8(b), by capturing the thread processing time through Trace, if the image processing method provided in this solution is implemented, and the image 1 with a size of 1798x944 is divided into three sub-images, namely sub-image 1 of 1798x315, sub-image 2 of 1798x315, and sub-image 3 of 1798x314, and sub-image 3 is processed by the main thread, sub-image 1 by sub-thread 1, and sub-image 2 by sub-thread 2, then the total processing time of image 1 (e.g., decoding) is only 11.84 milliseconds. It can be seen that compared with Figure 8(a), the efficiency of image processing is greatly improved.
[0190] This application also provides a computer-readable storage medium storing a computer program, which, when executed by a processor, can implement the steps in the above-described method embodiments.
[0191] This application also provides a computer program product, including a computer program that, when run on a processor, can implement the steps executed by the electronic device in the above-described method embodiments.
[0192] This application also provides a chip system, which includes a processing circuit interface circuit. The interface circuit receives instructions and transmits them to the processing circuit, which executes the instructions to cause the chip system to perform the steps executed by the electronic device in any of the method embodiments of this application. The chip system can be a single chip or a chip module composed of multiple chips.
[0193] The term "user interface (UI)" used in the specification and accompanying drawings of this application refers to the medium through which an application or operating system interacts and exchanges information with the user. It converts the internal form of information into a form acceptable to the user. The user interface of an application is source code written in a specific computer language such as Java or Extensible Markup Language (XML). This source code is parsed and rendered on the terminal device, ultimately presenting user-recognizable content, such as images, text, buttons, and other controls. Controls, also known as widgets, are the basic elements of the user interface. Typical controls include toolbars, menu bars, text boxes, buttons, scroll bars, images, and text. The attributes and content of controls in the interface are defined through tags or nodes, such as XML.<Te xtview> , <imgview> 、 <videoview>Nodes define the controls contained in the interface. A node corresponds to a control or property in the interface, and after parsing and rendering, the node is presented as the content visible to the user. In addition, many applications, such as hybrid applications, often contain web pages within their interfaces. A web page, also known as a webpage, can be understood as a special control embedded in the application interface. Web pages are source code written in a specific computer language, such as Hypertext Markup Language (HTML), Cascading Style Sheets (CSS), JavaScript (JS), etc. Web page source code can be loaded and displayed as user-readable content by a browser or a web page display component with browser-like functionality. The specific content contained in a webpage is also defined through tags or nodes in the webpage source code; for example, HTML uses tags or nodes to define the content. 、 、 <video> 、 <canvas>Used to define the elements and attributes of a webpage.
[0194] The most common form of user interface is the graphical user interface (GUI), which refers to a user interface related to computer operation displayed graphically. It can be an icon, window, control, or other interface element displayed on the screen of an electronic device. Controls can include visual interface elements such as icons, buttons, menus, tabs, text boxes, dialog boxes, status bars, navigation bars, and widgets.
[0195] In the above embodiments, implementation can be achieved entirely or partially through software, hardware, firmware, or any combination thereof. When implemented using software, it can be implemented entirely or partially in the form of a computer program product. The computer program product includes one or more computer instructions. When the computer program instructions are loaded and executed on a computer, all or part of the processes or functions described in the embodiments of this application are generated. The computer can be a general-purpose computer, a special-purpose computer, a computer network, or other programmable device. The computer instructions can be stored in a computer-readable storage medium or transmitted from one computer-readable storage medium to another. For example, the computer instructions can be transmitted from one website, computer, server, or data center to another website, computer, server, or data center via wired (e.g., coaxial cable, fiber optic, digital subscriber line) or wireless (e.g., infrared, wireless, microwave, etc.) means. The computer-readable storage medium can be any available medium that a computer can access or a data storage device such as a server or data center that integrates one or more available media. The available medium can be a magnetic medium (e.g., floppy disk, hard disk, magnetic tape), an optical medium (e.g., DVD), or a semiconductor medium (e.g., solid-state drive), etc.
[0196] 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.
[0197] 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.< / canvas> < / video> < / videoview> < / imgview>
Claims
1. An image processing method, characterized in that, include: The electronic device reads the first image through the main thread of the first application; when the first preset condition is met, the electronic device creates M sub-threads; The electronic device divides the first image into N sub-images; the electronic device processes the N sub-images in parallel through the main thread and the M sub-threads; the electronic device obtains the second image based on the processed N sub-images.
2. The method according to claim 1, characterized in that, The first preset condition is one or more of the following: the process name of the first application is recorded in the whitelist, the size of the first image is greater than or equal to the first value, and the first image is the first frame image in the video stream.
3. The method according to claim 1 or 2, characterized in that, When the first preset condition is met, the electronic device creates M sub-threads, specifically including: the electronic device determines whether the first preset condition is met based on the process name of the first application and the parameters of the first image; wherein, the parameters of the first image include one or more of the length of the first image, the width of the first image, and the identifier of the first image; when it is determined that the first preset condition is met, the electronic device creates the M sub-threads.
4. The method according to claim 1, characterized in that, Each of the N sub-images includes parameters for each sub-image, wherein the parameters for each sub-image include the coordinates, length, and width of each sub-image; the electronic device processes the N sub-images in parallel through the main thread and the M sub-threads, specifically including: the electronic device processes the N-1 sub-images based on the parameters of the N-1 sub-images through the M sub-threads; the electronic device processes the Nth sub-image based on the parameters of the Nth sub-image through the main thread.
5. The method according to claim 4, characterized in that, The N sub-images include a first sub-image, and the M sub-threads include a first sub-thread. The electronic device processes the N-1 sub-images based on the parameters of the N-1 sub-images through the M sub-threads, specifically including: the electronic device processes the first sub-image based on the parameters of the first sub-image through the first sub-thread; the electronic device processes the Nth sub-image based on the parameters of the Nth sub-image through the main thread, specifically including: when the electronic device processes the first sub-image through the first sub-thread, the electronic device processes the Nth sub-image based on the parameters of the Nth sub-image through the main thread.
6. The method according to claim 5, characterized in that, The N sub-images also include a second sub-image, and the M sub-threads also include a second sub-thread; the electronic device processes the N-1 sub-images based on the parameters of the N-1 sub-images through the M sub-threads, specifically further including: when the electronic device processes the first sub-image through the first sub-thread, the electronic device processes the second sub-image based on the parameters of the second sub-image through the second sub-thread.
7. The method according to claim 1, characterized in that, The M = N-1.
8. The method according to claim 1 or 7, characterized in that, The M is set to 3, or the M is related to the number of processors in the electronic device.
9. The method according to claim 1, characterized in that, The electronic device obtains a second image based on the processed N sub-images, specifically by stitching the processed N sub-images together to obtain the second image.
10. An electronic device, characterized in that, The electronic device includes: one or more processors and a memory; the memory is coupled to the one or more processors, 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 electronic device to perform the method as described in any one of claims 1-9.
11. A chip system, characterized in that, The chip system is applied to an electronic device, the chip system including one or more processors, the processors being used to invoke computer instructions to cause the electronic device to perform the method as described in any one of claims 1-9.
12. A computer-readable storage medium comprising instructions, characterized in that, When the instructions are executed on an electronic device, the electronic device causes the electronic device to perform the method as described in any one of claims 1-9.
13. A computer program product, characterized in that, Includes a computer program, which, when executed by a processor, causes the electronic device to perform the method as described in any one of claims 1-9.