Disclosure of Invention
In order to solve the above problems in the prior art, the present invention provides a method and an apparatus for accelerating loading of a frame animation.
According to an aspect of the present invention, a frame animation loading acceleration method is provided. The method comprises the following steps:
synthesizing all frame pictures in the original frame animation into at least one synthesized picture through an editing tool, and exporting picture information files of all the frame pictures in the synthesized picture;
creating a corresponding number of threads based on the number of the composite graphs at a Natvie end, and loading each composite graph into a memory in the corresponding thread;
reading a picture information file, and associating each frame of picture loaded into the memory with the position in the memory one by one according to the sequence of all the frame pictures in the original frame animation based on the read information;
newly building a frame animation example at a Java end, and adding data of each frame of picture into the frame animation example according to the position in a memory associated with each frame of picture;
and playing the animation of the frame animation example.
Preferably, the information of the picture information file includes a position and a size of each frame of picture in the composite map for indexing each frame of picture in the composite map.
Preferably, when all the frame pictures in the original frame animation are combined into at least one combined picture, the frame pictures are combined in groups respectively, so that the size difference between the combined pictures is smaller than a predetermined value.
Preferably, when each composite graph is loaded to the memory in the corresponding thread, the composite graph is stored in the form of a byte array.
According to another aspect of the present invention, a frame animation loading acceleration apparatus is provided. The device includes:
the preprocessing unit synthesizes all the frame pictures in the frame animation into at least one synthesized picture through an editing tool and derives picture information files of all the frame pictures in the synthesized picture;
the loading unit is used for creating a corresponding number of threads based on the number of the composite graphs at the Natvie end and loading each composite graph into the memory in the corresponding thread;
the association unit is used for reading the picture information file, and associating each frame of picture loaded into the memory with the position in the memory one by one according to the sequence of all the frame pictures in the original frame animation based on the read information;
the instance creating unit is used for creating a frame animation instance at the Java end and adding the data of each frame of picture into the frame animation instance according to the position in the memory associated with each frame of picture;
and the playing unit plays the animation of the frame animation example.
Preferably, the information of the picture information file includes a position and a size of each frame of picture in the composite map for indexing each frame of picture in the composite map.
Preferably, when all the frame pictures in the original frame animation are combined into at least one combined picture, the frame pictures are combined in groups respectively, so that the size difference between the combined pictures is smaller than a predetermined value.
Preferably, when each composite graph is loaded to the memory in the corresponding thread, the composite graph is stored in the form of a byte array.
The invention realizes the accelerated loading of the frame animation pictures by adopting a preprocessing mode of synthesizing all pictures in the original frame animation and multithread loading, thereby greatly shortening the preparation time of the frame animation; meanwhile, the picture loading process is realized at the Native end, so that the risk of memory overflow in the picture loading process is reduced.
The method of the present invention has other features and advantages which will be apparent from or are set forth in detail in the accompanying drawings and the following detailed description, which are incorporated herein, and which together serve to explain certain principles of the invention.
Detailed Description
The invention will be described in more detail below with reference to the accompanying drawings. While the preferred embodiments of the present invention are shown in the drawings, it should be understood that the present invention may be embodied in various forms and should not be limited to the embodiments set forth herein.
FIG. 1 shows a flow diagram of a frame animation load acceleration method according to one embodiment of the invention.
In this embodiment, the frame animation loading acceleration method includes the following steps:
(1) and synthesizing all the frame pictures in the frame animation into at least one synthesized picture through an editing tool, and exporting picture information files of all the frame pictures in the synthesized picture.
For a frame animation with multiple picture frames, to reduce the number of times of reading pictures, all frame pictures are preprocessed first. The reason for reducing the number of pictures is to reduce the number of context switches of picture loading in software implementation.
In this embodiment, all the frame pictures in the frame animation are preprocessed to form a composite picture and a corresponding picture information file, and then uploaded to a server, and then loaded after a thread is created by a terminal in a subsequent step.
The preprocessing is to splice a certain number of frame pictures to form a composite picture through an editing tool, so that all the frame pictures in the frame animation are combined into at least one composite picture.
The thread concurrency (i.e., multithreading) can process multiple tasks simultaneously, i.e., the more threads, the more tasks that can be processed simultaneously, and the more pictures that can be read simultaneously in this embodiment. However, the more threads, the lower concurrency capability will be caused, so that each thread cannot obtain enough running time, and therefore blocking occurs and becomes irrevocable. Thus, the number of composite maps is limited to a reasonable number. This reasonable number is limited to no more than 3 sheets due to considerations of thread count and performance balance in software implementations.
In an exemplary embodiment, when all the frame pictures in the original frame animation are combined into at least one combined picture, the frame pictures are combined in groups respectively, and the size difference between the combined pictures is smaller than a preset value.
In consideration of thread concurrency efficiency, the size of the pictures formed by splicing should be guaranteed to be balanced as much as possible during picture splicing, that is, the size between the combined pictures is guaranteed to be smaller than a preset value. The predetermined value may be determined according to actual needs. For example, the target number is 3, the sizes of the three pictures should be ensured to be close to the same, and the situation that the size difference between the pictures is particularly large is avoided. During the picture splicing process, the information of each picture frame in the composite picture should be recorded.
In an exemplary embodiment, the editing tool is a texturepack.
In an exemplary embodiment, the information of the picture information file includes a position and a size of each picture frame in the composite map for indexing each frame picture in the composite map. The size of each picture frame in the composite image is in pixels, and the position coordinates are also in pixels.
In an exemplary embodiment, the picture information file is an xml file.
The following is an example of a picture information file for two frames of pictures in a composite picture:
the above parameters indicate that there are two frames of pictures in the synthesized synthetic map, pic1.png and pic2.png, respectively, where pic1.png is 1280 × 800 in size, and the position in the synthetic map is a rectangular region with the upper left coordinate (1,1) and the lower right coordinate (1280,800); png is 1280 × 800, and the position in the composite map is a rectangular area with the upper left coordinate (1,803) and the lower right coordinate (1280,800).
(2) And creating a corresponding number of threads based on the number of the composite graphs at a Natvie end, and loading each composite graph into a memory in the corresponding thread.
After the preprocessing is finished, the software is realized at a Java end and a Native end respectively, and the software can be realized in C/C + +.
At least one composite graph is synthesized in the preprocessing stage, the same number of threads are created at the Native end in the software implementation stage, and the corresponding composite graphs are read in each thread simultaneously to be loaded into the memory.
The whole reading process is process-consuming, namely if too many pictures are loaded, much time is consumed in the preparation and ending stages of data stream reading, and the actual reading and writing time is not long. And by synthesizing a limited number of synthesis maps, the number of pictures is reduced, thereby compressing the time of the read preparation phase.
The picture loading process is realized at the Native end, and Native codes are executed in a Native space, so that the memory of a Java virtual machine is not occupied, the use of the memory is not limited, and the risk of memory benefit cannot easily occur.
In an exemplary embodiment, when each composite graph is loaded to a memory in a corresponding thread, the composite graph is stored in a byte array. Preferably, each pixel point of the composite map is represented using 4 bytes.
For example, in the example picture information file described above, the data in the byte array for pic1.png are the top left (1,1) and bottom right (1280 × 4,800 × 4) array regions.
(3) And reading the picture information file, and associating each frame of picture loaded into the memory with the position in the memory one by one according to the sequence of all the frame pictures in the original frame animation based on the read information.
The positions of the composite images loaded in the threads in the memory are random, and if the frame images in each composite image are directly read, the sequence of the frame images is not necessarily consistent with the sequence of all the frame images in the original animation, so that each frame image in each composite image which is loaded into the memory needs to be associated with the position in the memory one by one. The position sequence in each associated memory is consistent with the arrangement sequence of all the frame pictures in the original animation, namely, the position of each frame picture in the memory in the composite picture is restored, and the subsequent display of each frame picture is realized according to the arrangement sequence.
(4) And (4) creating a frame animation example at the Java end, and adding the data of each frame of picture into the frame animation example according to the position in the memory associated with each frame of picture.
And creating a frame animation instance at the Java end, wherein the created frame animation instance is, for example, an animationDrawable, which is a basic class for realizing the frame animation and is used for managing each frame in the frame animation. And after the position of each frame of picture in the memory in the composite picture is restored, adding the data of each frame of picture into the frame animation example according to the position in the memory associated with each frame of picture.
(5) And transmitting the frame animation example to the terminal equipment, and displaying the current view class on the screen to play the animation.
The View displayed on the screen is View, and animation playing can be realized by calling a start () method of a frame animation example.
According to another embodiment of the present invention, a frame animation loading acceleration apparatus is provided.
The apparatus may include:
the preprocessing unit synthesizes all the frame pictures in the frame animation into at least one synthesized picture through an editing tool and derives picture information files of all the frame pictures in the synthesized picture;
the loading unit is used for creating a corresponding number of threads based on the number of the composite graphs at the Natvie end and loading each composite graph into the memory in the corresponding thread;
the association unit is used for reading the picture information file, and associating each frame of picture loaded into the memory with the position in the memory one by one according to the sequence of all the frame pictures in the original frame animation based on the read information;
the instance creating unit is used for creating a frame animation instance at the Java end and adding the data of each frame of picture into the frame animation instance according to the position in the memory associated with each frame of picture;
and the playing unit plays the animation of the frame animation example.
In one example, the information of the picture information file includes a position and a size of each frame picture in a composite map for indexing each frame picture in the composite map.
In one example, when all the frame pictures in the original frame animation are combined into at least one combined picture, the frame pictures are combined in groups respectively, and the size difference between the combined pictures is smaller than a preset value.
In one example, the composite graph is stored in a byte array when each composite graph is loaded to memory in a corresponding thread.
Application example
To facilitate understanding of the solution of the embodiments of the present invention and the effects thereof, a specific application example is given below. It will be understood by those skilled in the art that this example is merely for the purpose of facilitating an understanding of the present invention and that any specific details thereof are not intended to limit the invention in any way.
Fig. 2 a-2 l show 12 frame pictures, in order pic1, pic2, pic3, pic4, pic5, pic6, pic7, pic8, pic9, pic10, pic11, pic 12.
The frame animation composed of these 12 frame pictures is subjected to load acceleration processing by the following steps.
Step 1: the pictures are preprocessed, that is, 12 frame pictures pic1-pic12 shown in fig. 2 a-2 l are combined into three combined pictures, each combined picture comprises 4 frame pictures. As shown in FIGS. 3 a-3 c, FIG. 1 includes pic1-pic4, FIG. 2 includes pic5-pic8, and FIG. 3 includes pic9-pic 12. And exporting the picture file information of the three combined pictures; and after the pretreatment is finished, uploading the data to a server side for downloading by a terminal.
The picture information of fig. 1, 2, and 3 is synthesized as follows:
FIG. 1 is synthesized:
FIG. 2 is synthesized:
FIG. 3 is a synthesis diagram:
step 2: downloading the composite drawings 1, 2 and 3 at a mobile phone end, creating 3 threads at a Native end, and loading the composite drawings 1, 2 and 3 into a memory in the corresponding threads respectively;
and step 3: reading a picture information file, and associating each frame of picture loaded into the memory with the position in the memory one by one according to the sequence of all the frame pictures in the original frame animation based on the read information, wherein the correspondence comprises the correspondence of coordinates and sizes;
and 4, step 4: newly building a frame animation instance animationDrawable, and adding data of each frame of picture into the frame animation instance according to the position in a memory associated with each frame of picture;
and 5: and transferring the instance to a View class View currently displayed on a screen, and calling start () of the frame animation instance to play the animation so as to display the frame animation on the screen of the mobile phone.
It will be appreciated by persons skilled in the art that the above description of embodiments of the invention is intended only to illustrate the benefits of embodiments of the invention and is not intended to limit embodiments of the invention to any examples given.
The present invention may be an apparatus, method and/or computer program product. The computer program product may include a computer-readable storage medium having computer-readable program instructions embodied therewith for causing a processor to implement various aspects of the present invention.
The computer readable storage medium may be a tangible device that can hold and store the instructions for use by the instruction execution device. The computer readable storage medium may be, for example, but not limited to, an electronic memory device, a magnetic memory device, an optical memory device, an electromagnetic memory device, a semiconductor memory device, or any suitable combination of the foregoing. More specific examples (a non-exhaustive list) of the computer readable storage medium would include the following: a portable computer diskette, a hard disk, a Random Access Memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), a Static Random Access Memory (SRAM), a portable compact disc read-only memory (CD-ROM), a Digital Versatile Disc (DVD), a memory stick, a floppy disk, a mechanical coding device, such as punch cards or in-groove projection structures having instructions stored thereon, and any suitable combination of the foregoing. Computer-readable storage media as used herein is not to be construed as transitory signals per se, such as radio waves or other freely propagating electromagnetic waves, electromagnetic waves propagating through a waveguide or other transmission medium (e.g., optical pulses through a fiber optic cable), or electrical signals transmitted through electrical wires.
The computer-readable program instructions described herein may be downloaded from a computer-readable storage medium to a respective computing/processing device, or to an external computer or external storage device via a network, such as the internet, a local area network, a wide area network, and/or a wireless network. The network may include copper transmission cables, fiber optic transmission, wireless transmission, routers, firewalls, switches, gateway computers and/or edge servers. The network adapter card or network interface in each computing/processing device receives computer-readable program instructions from the network and forwards the computer-readable program instructions for storage in a computer-readable storage medium in the respective computing/processing device.
The computer program instructions for carrying out operations of the present invention may be assembler instructions, Instruction Set Architecture (ISA) instructions, machine-related instructions, microcode, firmware instructions, state setting data, or source or object code written in any combination of one or more programming languages, including an object oriented programming language such as Smalltalk, C + + or the like and conventional procedural programming languages, such as the "C" programming language or similar programming languages. The computer-readable program instructions may execute entirely on the user's computer, partly on the user's computer, as a stand-alone software package, partly on the user's computer and partly on a remote computer or entirely on the remote computer or server. In the case of a remote computer, the remote computer may be connected to the user's computer through any type of network, including a Local Area Network (LAN) or a Wide Area Network (WAN), or the connection may be made to an external computer (for example, through the Internet using an Internet service provider). In some embodiments, aspects of the present invention are implemented by personalizing an electronic circuit, such as a programmable logic circuit, a Field Programmable Gate Array (FPGA), or a Programmable Logic Array (PLA), with state information of computer-readable program instructions, which can execute the computer-readable program instructions.
Aspects of the present invention are described herein with reference to flowchart illustrations and/or block diagrams of methods, apparatus (systems) and computer program products according to embodiments of the invention. It will be understood that each block of the flowchart illustrations and/or block diagrams, and combinations of blocks in the flowchart illustrations and/or block diagrams, can be implemented by computer-readable program instructions.
These computer-readable program instructions may be provided to a processor of a general purpose computer, special purpose computer, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, create means for implementing the functions/acts specified in the flowchart and/or block diagram block or blocks. These computer-readable program instructions may also be stored in a computer-readable storage medium that can direct a computer, programmable data processing apparatus, and/or other devices to function in a particular manner, such that the computer-readable medium storing the instructions comprises an article of manufacture including instructions which implement the function/act specified in the flowchart and/or block diagram block or blocks.
The computer readable program instructions may also be loaded onto a computer, other programmable data processing apparatus, or other devices to cause a series of operational steps to be performed on the computer, other programmable apparatus or other devices to produce a computer implemented process such that the instructions which execute on the computer, other programmable apparatus or other devices implement the functions/acts specified in the flowchart and/or block diagram block or blocks.
The flowchart and block diagrams in the figures illustrate the architecture, functionality, and operation of possible implementations of systems, methods and computer program products according to various embodiments of the present invention. In this regard, each block in the flowchart or block diagrams may represent a module, segment, or portion of instructions, which comprises one or more executable instructions for implementing the specified logical function(s). In some alternative implementations, the functions noted in the block may occur out of the order noted in the figures. For example, two blocks shown in succession may, in fact, be executed substantially concurrently, or the blocks may sometimes be executed in the reverse order, depending upon the functionality involved. It will also be noted that each block of the block diagrams and/or flowchart illustration, and combinations of blocks in the block diagrams and/or flowchart illustration, can be implemented by special purpose hardware-based systems which perform the specified functions or acts, or combinations of special purpose hardware and computer instructions.
Having described embodiments of the present invention, the foregoing description is intended to be exemplary, not exhaustive, and not limited to the embodiments disclosed. Many modifications and variations will be apparent to those of ordinary skill in the art without departing from the scope and spirit of the described embodiments.