WO2022142039A1 - 图像数据的压缩方法、装置、计算机设备以及存储介质 - Google Patents

图像数据的压缩方法、装置、计算机设备以及存储介质 Download PDF

Info

Publication number
WO2022142039A1
WO2022142039A1 PCT/CN2021/091689 CN2021091689W WO2022142039A1 WO 2022142039 A1 WO2022142039 A1 WO 2022142039A1 CN 2021091689 W CN2021091689 W CN 2021091689W WO 2022142039 A1 WO2022142039 A1 WO 2022142039A1
Authority
WO
WIPO (PCT)
Prior art keywords
image data
compression
compression algorithm
target
luban
Prior art date
Application number
PCT/CN2021/091689
Other languages
English (en)
French (fr)
Inventor
卢中华
Original Assignee
平安普惠企业管理有限公司
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by 平安普惠企业管理有限公司 filed Critical 平安普惠企业管理有限公司
Publication of WO2022142039A1 publication Critical patent/WO2022142039A1/zh

Links

Classifications

    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04NPICTORIAL COMMUNICATION, e.g. TELEVISION
    • H04N19/00Methods or arrangements for coding, decoding, compressing or decompressing digital video signals
    • H04N19/10Methods or arrangements for coding, decoding, compressing or decompressing digital video signals using adaptive coding
    • H04N19/102Methods or arrangements for coding, decoding, compressing or decompressing digital video signals using adaptive coding characterised by the element, parameter or selection affected or controlled by the adaptive coding
    • H04N19/103Selection of coding mode or of prediction mode
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L69/00Network arrangements, protocols or services independent of the application payload and not provided for in the other groups of this subclass
    • H04L69/04Protocols for data compression, e.g. ROHC
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04NPICTORIAL COMMUNICATION, e.g. TELEVISION
    • H04N19/00Methods or arrangements for coding, decoding, compressing or decompressing digital video signals
    • H04N19/42Methods or arrangements for coding, decoding, compressing or decompressing digital video signals characterised by implementation details or hardware specially adapted for video compression or decompression, e.g. dedicated software implementation
    • YGENERAL TAGGING OF NEW TECHNOLOGICAL DEVELOPMENTS; GENERAL TAGGING OF CROSS-SECTIONAL TECHNOLOGIES SPANNING OVER SEVERAL SECTIONS OF THE IPC; TECHNICAL SUBJECTS COVERED BY FORMER USPC CROSS-REFERENCE ART COLLECTIONS [XRACs] AND DIGESTS
    • Y02TECHNOLOGIES OR APPLICATIONS FOR MITIGATION OR ADAPTATION AGAINST CLIMATE CHANGE
    • Y02DCLIMATE CHANGE MITIGATION TECHNOLOGIES IN INFORMATION AND COMMUNICATION TECHNOLOGIES [ICT], I.E. INFORMATION AND COMMUNICATION TECHNOLOGIES AIMING AT THE REDUCTION OF THEIR OWN ENERGY USE
    • Y02D10/00Energy efficient computing, e.g. low power processors, power management or thermal management

Definitions

  • the present application relates to the technical field of image processing, and in particular, to an image data compression method, apparatus, computer device, and storage medium.
  • the image compression method in the luban open source library cannot precisely control the size of the compressed image obtained after compression, and internally encapsulates asyncTaks for asynchronous image compression, which fails to support rxJava well, while the compressor open source library
  • the image compression method can accurately control the size of the compressed image, the compression efficiency of the image is low, and the data type of the supported image is relatively simple. Therefore, in the process of developing an android application, it is usually necessary to select an appropriate image compression method for image compression according to actual development requirements, which increases the workload and difficulty of android application development. It can be seen that the performance of the current image compression method is limited and cannot meet the diversified development needs.
  • the technical problem to be solved by this application is that the performance of the current image compression method is limited and cannot meet the diversified development demands.
  • a first aspect of the present application discloses a method for compressing image data, the method comprising:
  • the preset multiple compression algorithms include a luban class compression algorithm and a compressor class compression algorithm
  • the luban class compression algorithm refers to a compression algorithm based on the luban framework
  • the compressor class compression algorithm refers to a compression algorithm based on the compressor framework
  • the target compression algorithm corresponding to the image data From the luban-type compression algorithm according to the compression parameter;
  • a target compression algorithm corresponding to the image data is determined from the compressor type compression algorithm according to the compression parameter.
  • a second aspect of the present application discloses a device for compressing image data, the device comprising:
  • a determining module configured to determine a target compression algorithm corresponding to the image data according to the compression parameter, where the target compression algorithm is one of multiple preset compression algorithms;
  • the preset multiple compression algorithms include a luban class compression algorithm and a compressor class compression algorithm
  • the luban class compression algorithm refers to a compression algorithm based on the luban framework
  • the compressor class compression algorithm refers to a compression algorithm based on the compressor framework
  • the specific manner in which the determining module determines the target compression algorithm corresponding to the image data according to the compression parameter is:
  • the target compression algorithm corresponding to the image data From the luban-type compression algorithm according to the compression parameter;
  • the preset multiple compression algorithms include a luban class compression algorithm and a compressor class compression algorithm
  • the luban class compression algorithm refers to a compression algorithm based on the luban framework
  • the compressor class compression algorithm refers to a compression algorithm based on the compressor framework
  • a target compression algorithm corresponding to the image data is determined from the compressor type compression algorithm according to the compression parameter.
  • FIG. 3 is a schematic structural diagram of a computer device disclosed in an embodiment of the present application.
  • FIG. 1 is a schematic flowchart of an image data compression method disclosed in an embodiment of the present application.
  • the compression method of the image data may include the following operations:
  • the open source library After inputting the image data and compression parameters into the open source library, the open source library selects a suitable compression algorithm from a variety of compression algorithms according to the input compression parameters to compress the image data (described later), so as to obtain a solution that satisfies the Develop desired image compression effects.
  • the preset multiple compression algorithms include a luban-type compression algorithm and a compressor-type compression algorithm
  • the luban-type compression algorithm refers to a compression algorithm based on the luban framework
  • the compressor-type compression algorithm refers to a compression algorithm based on the luban framework. Compression algorithm based on compressor framework;
  • the target compression algorithm corresponding to the image data From the luban-type compression algorithm according to the compression parameter;
  • the target compression algorithm When compressing an image, if the corresponding size parameter is set in the compression parameter (indicating that the size of the compressed image needs to be controlled), the target compression algorithm is selected from the compressor class compression algorithm to compress the image, so as to realize the compression of the image.
  • the size of the image after the image is controlled if the corresponding size parameter is not set in the compression parameters (indicating that the size of the compressed image does not need to be controlled), then select the target compression algorithm from the luban compression algorithm to compress the image to achieve better compression. Good compression efficiency and compression effect. In this way, the luban type compression algorithm or the compressor type compression algorithm can be selected according to the actual image compression requirements to meet different image compression requirements.
  • the compression parameters may also include the target compression algorithm identification corresponding to the target compression algorithm, and by setting the corresponding target compression algorithm identification in the compression parameters, that is, the target compression algorithm identification can be specified from the preset multiple compression algorithms.
  • Compression algorithm for image compression Developers can set the custom compression algorithm in the open source library, and then use the custom compression algorithm to compress the image by setting the target compression algorithm identifier in the compression parameters, so as to realize the use of the custom compression algorithm for image compression. It can further improve the performance of the image compression method and meet the diversified development needs.
  • determining the target compression algorithm corresponding to the image data from the luban compression algorithm according to the compression parameter including:
  • the Luban framework supports the RxJava mode, and a related program of RxJava is added on the basis of the existing program of the luban compression algorithm, that is, the RxJava mode capable of realizing the luban compression algorithm.
  • the RxJava mode of the luban compression algorithm by setting the relevant parameters of RxJava, the thread for processing the image compression task and the thread for processing the image compression result callback task can be specified.
  • the thread for processing the image compression task and the thread for processing the image compression result callback task By setting the thread for processing the image compression task and the thread for processing the image compression result callback task, the asynchronous compression or synchronous compression of the image can be realized.
  • the thread processing the image compression task is set as the background thread
  • the thread processing the image compression result callback task is the main thread, which is the luban asynchronous compression algorithm
  • the main thread is the luban class synchronous compression algorithm
  • the main thread is mainly used to process key tasks in the android system. It is not appropriate to process tasks that take a long time in the main thread. If the main thread is blocked for a long time, it is not conducive to the process operation of the android system. It is also easy to cause errors in the android system.
  • the image compression task usually takes a long time and requires more resources. Therefore, in the development process of an android application, in order to ensure the normal operation of the android system, it is sometimes necessary to place the image compression task in a background thread for execution. , reducing the interference of image compression tasks on the main thread.
  • the asynchronous compression flag can be set in the compression parameters, so that when compressing the image, the luban asynchronous compression algorithm will be selected to compress the image, so as to realize the asynchronous compression of the image.
  • the method further includes:
  • the operation of selecting the luban-type asynchronous compression algorithm from the luban-type compression algorithm as the target compression algorithm corresponding to the image data is triggered.
  • the asynchronous compression of the image may not be performed, but the synchronous compression of the image can be performed, so that the image compression method can be applied to more Multiple development scenarios to better meet development needs.
  • the synchronous compression or asynchronous compression of the image can be automatically adjusted according to whether the currently used thread is a background thread, so that the image compression method can be applied to more Multiple development scenarios to better meet development needs.
  • the compressor framework also supports the RxJava mode, so the compressor class compression algorithm can also include the compressor class synchronous compression algorithm and the compressor class asynchronous compression algorithm.
  • the use process of the compressor class synchronous compression algorithm and the compressor class asynchronous compression algorithm can be Referring to the use process of the above-mentioned luban-type synchronous compression algorithm and luban-type asynchronous compression algorithm, in order to avoid repetition, details are not repeated.
  • the android system restricts that the interface UI cannot be refreshed in the background thread, so when the image data is used to refresh the interface UI (that is, the compressed image data obtained after compressing the image data will be used for When the interface UI is refreshed), the thread that processes the image compression result callback task is set as the main thread, so that the compressed image data corresponding to the image data can be returned to the main thread to refresh the interface UI.
  • the compressed image data can be returned to the main thread, so that the limitations of the android system can be accommodated, and the compressed image data can be used for The interface UI is refreshed, so that the image compression method can be applied to more development scenarios and better meet the development needs.
  • the method further includes:
  • the data type of the image data is converted to the target data type, and the execution of the compression algorithm based on the target compression algorithm is triggered.
  • the android system there are three data types commonly used for image data in the android system: File type, byte type, and Bitmap type.
  • General open source compression algorithms can only compress image data of specific data types.
  • both the luban framework and the compressor framework can only compress image data of File type.
  • the native data type conversion API of the android system can be used to convert the data type of the image data.
  • the BitmapFactory class in the android system supports byte to Bitmap and File to Bitmap
  • the BufferedOutputStream class supports Bitmap to File
  • the ByteArrayOutputStream class supports Bitmap to byte.
  • the data type of the compressed image data is converted to the data type corresponding to the output data type identifier.
  • a general open source compression algorithm can usually only output the compressed image data in a specific data type.
  • both the luban framework and the compressor framework can only output compressed image data as File type data.
  • the data types of the compressed image data that need to be obtained are also various, so making the image compression method support the output of compressed image data of various data types can increase the adaptability of the image compression method. Better meet development needs.
  • the native data type conversion API of the Android system can be used to perform the data type conversion of the output compressed image data. convert.
  • the image compression method can support the output of compressed image data of various data types, increase the adaptation scenarios of the image compression method, and better meet the development requirements.
  • the compression information is obtained by running the compression method of the image data, and is used to record the compression situation of the image data, for example, the image data to be compressed, the compressed image data obtained after compression, and the selected compression algorithm , the duration of the compression process, and so on.
  • Uploading compressed information to the blockchain ensures its security and fairness and transparency to users.
  • the user can download the compression information from the blockchain, so as to verify whether the compression information of the compression method of the image data has been tampered with.
  • the blockchain referred to in this example is a new application mode of computer technology such as distributed data storage, point-to-point transmission, consensus mechanism, and encryption algorithm.
  • Blockchain essentially a decentralized database, is a series of data blocks associated with cryptographic methods. Each data block contains a batch of network transaction information to verify its Validity of information (anti-counterfeiting) and generation of the next block.
  • the blockchain can include the underlying platform of the blockchain, the platform product service layer, and the application service layer.
  • a suitable image compression algorithm can be determined from multiple image compression algorithms according to the compression parameters, so as to compress the image data.
  • Appropriate compression processing so that a variety of image compression algorithms can be integrated to achieve a variety of image compression effects, improve the performance of image compression methods, and meet diverse development needs. It is also possible to select a suitable compression algorithm from the luban compression algorithm and the compressor compression algorithm according to whether it is necessary to control the size of the compressed image when the preset multiple compression algorithms include the luban compression algorithm and the compressor compression algorithm. Perform image compression to better meet the control requirements for the size of the compressed image.
  • the image compression method can also realize synchronous compression or asynchronous compression of images according to actual development requirements, so as to further improve the performance of the image compression method and meet diversified development requirements. It can also automatically adjust the synchronous compression or asynchronous compression of the image according to whether the currently used thread is a background thread when the compression parameter contains the asynchronous compression flag, so that the image compression method can be applied to more development scenarios and better meet the needs of development needs. It can also return the compressed image data to the main thread when the image data to be compressed is used to refresh the interface UI, so as to adapt to the limitations of the android system, so that the compressed image data can be used to refresh the interface UI, so that the image compression The method can be applied to more development scenarios and better meet the development needs.
  • the image compression method can also support the input of image data of various data types and the output of compressed image data of various data types, increase the adaptable scene of the image compression method, and better meet the development requirements.
  • FIG. 2 is a schematic structural diagram of an image data compression apparatus disclosed in an embodiment of the present application.
  • the image data compression device may include:
  • an acquisition module 201 configured to acquire image data to be compressed and compression parameters corresponding to the image data
  • a determination module 202 configured to determine a target compression algorithm corresponding to the image data according to the compression parameter, where the target compression algorithm is one of multiple preset compression algorithms;
  • the compression module 203 is configured to perform compression processing on the image data based on the target compression algorithm to obtain compressed image data corresponding to the image data.
  • the preset multiple compression algorithms include a luban-type compression algorithm and a compressor-type compression algorithm
  • the luban-type compression algorithm refers to a compression algorithm based on the luban framework
  • the compressor-type compression algorithm refers to a compression algorithm based on the luban framework. Compression algorithm based on compressor framework;
  • the determining module 202 determines the target compression algorithm corresponding to the image data according to the compression parameter is:
  • a target compression algorithm corresponding to the image data is determined from the compressor type compression algorithm according to the compression parameter.
  • the luban type compression algorithm includes a luban type synchronous compression algorithm and a luban type asynchronous compression algorithm;
  • the luban asynchronous compression algorithm When judging that the compression parameter includes the asynchronous compression identifier, selecting the luban asynchronous compression algorithm from the luban compression algorithm as the target compression algorithm corresponding to the image data;
  • the luban-type synchronous compression algorithm is selected from the luban-type compression algorithm as the target compression algorithm corresponding to the image data.
  • a judgment module configured to select the luban type asynchronous compression algorithm from the luban type compression algorithm as the image after the determination module 202 judges that the compression parameter contains the asynchronous compression identifier Before the target compression algorithm corresponding to the data, judge whether the currently used thread is a background thread; when judging that the currently used thread is a background thread, trigger the determination module 202 to execute the described selection from the luban class compression algorithm
  • the luban class synchronous compression algorithm is used as the operation of the target compression algorithm corresponding to the image data; when it is judged that the currently used thread is not a background thread, the determining module 202 is triggered to execute the described selection from the luban class compression algorithm.
  • the luban-like asynchronous compression algorithm operates as the target compression algorithm corresponding to the image data.
  • the judging module is further configured to, after judging that the compression parameter contains the asynchronous compression identifier, the determining module 202 selects the luban class from the luban class compression algorithm Before the asynchronous compression algorithm is used as the target compression algorithm corresponding to the image data, it is judged whether the currently used thread is a background thread; when it is judged that the currently used thread is a background thread, the determining module 202 is triggered to execute the In the class compression algorithm, the operation of selecting the luban class synchronous compression algorithm as the target compression algorithm corresponding to the image data; when judging that the thread currently used is not a background thread, triggering the determination module 202 to execute the description from the luban In the class compression algorithm, the luban class asynchronous compression algorithm is selected as the operation of the target compression algorithm corresponding to the image data.
  • the judgment module is further configured to, after the compression module 203 compresses the image data based on the target compression algorithm, and obtains compressed image data corresponding to the image data, It is judged whether the image data is used to refresh the interface UI; when it is judged that the image data is used to refresh the interface UI, the compressed image data corresponding to the image data is returned to the main thread.
  • the determining module 202 is further configured to, after determining the target compression algorithm corresponding to the image data according to the compression parameter, the compression module 203 , based on the target compression algorithm
  • the image data is compressed, and before the compressed image data corresponding to the image data is obtained, the target data type corresponding to the target compression algorithm is determined, and the target data type refers to the data type that can be processed by the target compression algorithm;
  • the compression parameter includes an output data type identifier
  • the judgment module is further configured for the compression module 203 to compress the image data based on the target compression algorithm, and after obtaining compressed image data corresponding to the image data, judge the data of the compressed image data Whether the type is the same as the data type corresponding to the output data type identifier; when it is judged that the data type of the compressed image data and the data type corresponding to the output data type identifier are not the same, convert the data type of the compressed image data A corresponding data type is identified for the output data type.
  • FIG. 3 is a schematic structural diagram of a computer device disclosed in an embodiment of the present application.
  • the computer equipment may include:
  • a memory 301 storing executable program code
  • processor 302 connected to the memory 301;
  • the processor 302 invokes the executable program code stored in the memory 301 to execute the steps in the image data compression method disclosed in the first embodiment of the present application.
  • the embodiment of the present application discloses a computer storage medium 401, and the computer storage medium 401 stores a computer instruction, when the computer instruction is invoked, is used to execute the steps in the image data compression method disclosed in the first embodiment of the present application.
  • the computer storage medium 401 may be non-volatile or volatile.

Landscapes

  • Engineering & Computer Science (AREA)
  • Signal Processing (AREA)
  • Multimedia (AREA)
  • Computer Security & Cryptography (AREA)
  • Computer Networks & Wireless Communication (AREA)
  • Compression Of Band Width Or Redundancy In Fax (AREA)
  • Compression Or Coding Systems Of Tv Signals (AREA)

Abstract

本申请公开了一种图像数据的压缩方法,包括:获取待压缩的图像数据和所述图像数据对应的压缩参数;根据所述压缩参数确定所述图像数据对应的目标压缩算法,所述目标压缩算法是预先设置的多种压缩算法中的其中一种;基于所述目标压缩算法对所述图像数据进行压缩处理,得到所述图像数据对应的压缩图像数据。可见,本申请能够将多种图像压缩算法结合在一起,然后根据压缩参数从多种图像压缩算法中确定出合适的图像压缩算法,以对图像数据进行合适的压缩处理,从而能够综合多种图像压缩算法实现多样化的图像压缩效果,提高图像压缩方法的性能,满足多样化的开发需求。本申请还涉及区块链技术领域。

Description

图像数据的压缩方法、装置、计算机设备以及存储介质
本申请要求于2020年12月29日提交中国专利局、申请号为202011590409.5,发明名称为“图像数据的压缩方法、装置、计算机设备以及存储介质”的中国专利申请的优先权,其全部内容通过引用结合在本申请中。
技术领域
本申请涉及图像处理技术领域,尤其涉及一种图像数据的压缩方法、装置、计算机设备以及存储介质。
背景技术
在android应用中经常需要对图像进行加载,但是加载图像是一个需要消耗内存的动作,而android系统分配给单个android应用的内存空间通常是非常有限的(大致为16M、64M、128M等),如果一个android应用加载大量高质量的图像,则容易导致内存溢出。为了避免内存溢出的情况出现,android应用在加载图像之前,通常需要对将要加载的图像进行压缩。目前,在android应用中通常使用第三方开源库(如,luban、compressor)中预设好的图像压缩方法进行图像的压缩。然而,发明人发现,目前已存在的第三方开源库中的图像压缩方法均存在一些不足,未能很好地满足多样化的开发需求。例如,luban开源库中的图像压缩方法无法对压缩后得到的压缩图像的尺寸进行精准的控制,且内部封装asyncTaks来进行异步的图片压缩,未能很好地支持rxJava,而compressor开源库中的图像压缩方法虽然能够对压缩图像的尺寸进行精准的控制,但是图像的压缩效率较低,支持的图像的数据类型也较为单一。因此,在开发android应用的过程中,通常需要根据实际开发需求选择使用合适的图像压缩方法进行图像的压缩,这增加了android应用开发的工作量与开发难度。可见,目前的图像压缩方法的性能有限,未能满足多样化的开发需求。
技术问题
本申请所要解决的技术问题在于,目前的图像压缩方法的性能有限,未能满足多样化的开发需求。
技术解决方案
为了解决上述技术问题,本申请第一方面公开了一种图像数据的压缩方法,所述方法包括:
获取待压缩的图像数据和所述图像数据对应的压缩参数;
根据所述压缩参数确定所述图像数据对应的目标压缩算法,所述目标压缩算法是预先设置的多种压缩算法中的其中一种;
基于所述目标压缩算法对所述图像数据进行压缩处理,得到所述图像数据对应的压缩图像数据;
其中,预先设置的多种压缩算法包括luban类压缩算法和compressor类压缩算法,所述luban类压缩算法是指基于luban框架的压缩算法,所述compressor类压缩算法是指基于compressor框架的压缩算法;
以及,所述根据所述压缩参数确定所述图像数据对应的目标压缩算法,包括:
判断所述压缩参数是否包含所述压缩图像数据对应的尺寸参数;
当判断出所述压缩参数包含所述压缩图像数据对应的尺寸参数时,根据所述压缩参数从所述luban类压缩算法中确定出所述图像数据对应的目标压缩算法;
当判断出所述压缩参数不包含所述压缩图像数据对应的尺寸参数时,根据所述压缩参数从所述compressor类压缩算法中确定出所述图像数据对应的目标压缩算法。
本申请第二方面公开了一种图像数据的压缩装置,所述装置包括:
获取模块,用于获取待压缩的图像数据和所述图像数据对应的压缩参数;
确定模块,用于根据所述压缩参数确定所述图像数据对应的目标压缩算法,所述目标压缩算法是预先设置的多种压缩算法中的其中一种;
压缩模块,用于基于所述目标压缩算法对所述图像数据进行压缩处理,得到所述图像数据对应的压缩图像数据;
其中,预先设置的多种压缩算法包括luban类压缩算法和compressor类压缩算法,所述luban类压缩算法是指基于luban框架的压缩算法,所述compressor类压缩算法是指基于compressor框架的压缩算法;
以及,所述确定模块根据所述压缩参数确定所述图像数据对应的目标压缩算法的具体方式为:
判断所述压缩参数是否包含所述压缩图像数据对应的尺寸参数;
当判断出所述压缩参数包含所述压缩图像数据对应的尺寸参数时,根据所述压缩参数从所述luban类压缩算法中确定出所述图像数据对应的目标压缩算法;
当判断出所述压缩参数不包含所述压缩图像数据对应的尺寸参数时,根据所述压缩参数从所述compressor类压缩算法中确定出所述图像数据对应的目标压缩算法。
本申请第三方面公开了一种计算机设备,所述计算机设备包括:
存储有可执行程序代码的存储器;
与所述存储器连接的处理器;
所述处理器调用所述存储器中存储的所述可执行程序代码,执行如下方法:
获取待压缩的图像数据和所述图像数据对应的压缩参数;
根据所述压缩参数确定所述图像数据对应的目标压缩算法,所述目标压缩算法是预先设置的多种压缩算法中的其中一种;
基于所述目标压缩算法对所述图像数据进行压缩处理,得到所述图像数据对应的压缩图像数据;
其中,预先设置的多种压缩算法包括luban类压缩算法和compressor类压缩算法,所述luban类压缩算法是指基于luban框架的压缩算法,所述compressor类压缩算法是指基于compressor框架的压缩算法;
以及,所述根据所述压缩参数确定所述图像数据对应的目标压缩算法,包括:
判断所述压缩参数是否包含所述压缩图像数据对应的尺寸参数;
当判断出所述压缩参数包含所述压缩图像数据对应的尺寸参数时,根据所述压缩参数从所述luban类压缩算法中确定出所述图像数据对应的目标压缩算法;
当判断出所述压缩参数不包含所述压缩图像数据对应的尺寸参数时,根据所述压缩参数从所述compressor类压缩算法中确定出所述图像数据对应的目标压缩算法。
本申请第四方面公开了一种计算机存储介质,所述计算机存储介质存储有计算机指令,所述计算机指令被调用时,执行如下方法:
获取待压缩的图像数据和所述图像数据对应的压缩参数;
根据所述压缩参数确定所述图像数据对应的目标压缩算法,所述目标压缩算法是预先设置的多种压缩算法中的其中一种;
基于所述目标压缩算法对所述图像数据进行压缩处理,得到所述图像数据对应的压缩图像数据;
其中,预先设置的多种压缩算法包括luban类压缩算法和compressor类压缩算法,所述luban类压缩算法是指基于luban框架的压缩算法,所述compressor类压缩算法是指基于compressor框架的压缩算法;
以及,所述根据所述压缩参数确定所述图像数据对应的目标压缩算法,包括:
判断所述压缩参数是否包含所述压缩图像数据对应的尺寸参数;
当判断出所述压缩参数包含所述压缩图像数据对应的尺寸参数时,根据所述压缩参数从所述luban类压缩算法中确定出所述图像数据对应的目标压缩算法;
当判断出所述压缩参数不包含所述压缩图像数据对应的尺寸参数时,根据所述压缩参数从所述compressor类压缩算法中确定出所述图像数据对应的目标压缩算法。
有益效果
本申请实施例中,能够将多种图像压缩算法结合在一起,然后根据压缩参数从多种图像压缩算法中确定出合适的图像压缩算法,以对图像数据进行合适的压缩处理,从而能够综合多种图像压缩算法实现多样化的图像压缩效果,提高图像压缩方法的性能,满足多样化的开发需求。
附图说明
为了更清楚地说明本申请实施例中的技术方案,下面将对实施例描述中所需要使用的附图作简单地介绍,显而易见地,下面描述中的附图仅仅是本申请的一些实施例,对于本领域普通技术人员来讲,在不付出创造性劳动的前提下,还可以根据这些附图获得其他的附图。
图1是本申请实施例公开的一种图像数据的压缩方法的流程示意图;
图2是本申请实施例公开的一种图像数据的压缩装置的结构示意图;
图3是本申请实施例公开的一种计算机设备的结构示意图;
图4是本申请实施例公开的一种计算机存储介质的结构示意图。
本发明的实施方式
本申请公开了一种图像数据的压缩方法、装置、计算机设备以及存储介质,能够将多种图像压缩算法结合在一起,然后根据压缩参数从多种图像压缩算法中确定出合适的图像压缩算法,以对图像数据进行合适的压缩处理,从而能够综合多种图像压缩算法实现多样化的图像压缩效果,提高图像压缩方法的性能,满足多样化的开发需求。以下分别进行详细说明。
实施例一
请参阅图1,图1是本申请实施例公开的一种图像数据的压缩方法的流程示意图。如图1所示,该图像数据的压缩方法可以包括以下操作:
101、获取待压缩的图像数据和所述图像数据对应的压缩参数。
102、根据所述压缩参数确定所述图像数据对应的目标压缩算法,所述目标压缩算法是预先设置的多种压缩算法中的其中一种。
103、基于所述目标压缩算法对所述图像数据进行压缩处理,得到所述图像数据对应的压缩图像数据。
本申请实施例中,可以将用于实现该图像数据的压缩方法的程序封装成一个新的开源库,在开发android应用的过程中,若需要进行图像的压缩,则可以直接调用该开源库,然后将需要进行压缩的图像的数据和用于控制图像数据的压缩过程的压缩参数输入至该开源库,该开源库根据压缩参数对图像数据进行压缩处理,从而得到对应的压缩图像数据。这样,即能够通过简单的调用与设置,实现对图像数据进行合适的压缩处理,大大降低android应用开发的工作量与开发难度。其中,压缩参数可以包括用于表示压缩图像的尺寸大小的尺寸参数、用于表示是否需要执行异步压缩处理的异步压缩标识、用于表示所输出的压缩图像数据的数据类型的输出数据类型标识等(稍后描述)。开发人员根据实际开发需求设置压缩参数,例如,需要将图像压缩至200乘200像素大小,则将尺寸参数设置为200乘200。该开源库中可以预先设置有多种压缩算法,如,luban类同步压缩算法、luban类异步压缩算法、compressor类同步压缩算法、compressor类异步压缩算法等(稍后描述)。在将图像数据和压缩参数输入至该开源库之后,该开源库根据输入的压缩参数从多种压缩算法中选取出合适的压缩算法对图像数据进行压缩处理(稍后描述),从而得到能够满足开发需求的图像压缩效果。
可见,实施图1所描述的图像数据的压缩方法,能够将多种图像压缩算法结合在一起,然后根据压缩参数从多种图像压缩算法中确定出合适的图像压缩算法,以对图像数据进行合适的压缩处理,从而能够综合多种图像压缩算法实现多样化的图像压缩效果,提高图像压缩方法的性能,满足多样化的开发需求。
在一个可选的实施例中,预先设置的多种压缩算法包括luban类压缩算法和compressor类压缩算法,所述luban类压缩算法是指基于luban框架的压缩算法,所述compressor类压缩算法是指基于compressor框架的压缩算法;
以及所述根据所述压缩参数确定所述图像数据对应的目标压缩算法,包括:
判断所述压缩参数是否包含所述压缩图像数据对应的尺寸参数;
当判断出所述压缩参数包含所述压缩图像数据对应的尺寸参数时,根据所述压缩参数从所述luban类压缩算法中确定出所述图像数据对应的目标压缩算法;
当判断出所述压缩参数不包含所述压缩图像数据对应的尺寸参数时,根据所述压缩参数从所述compressor类压缩算法中确定出所述图像数据对应的目标压缩算法。
在该可选的实施例中,Luban框架和compressor框架是目前android应用开发中较为常用的图像压缩框架。其中,luban框架是根据“微信”APP中的图像压缩过程逆向推算出的一种开源图像压缩框架,其压缩效率和压缩效果较好,在压缩图像数据大小和保持图像数据的信息之间做到了较好的平衡,但是不能够精准地控制压缩后的图像的尺寸。compressor框架结合了三种android原生的压缩方式(质量压缩、邻近采样、双线性采样),能够实现精准地控制压缩后的图像的尺寸,但是其压缩效率和压缩效果比luban框架差。所以,可以在压缩参数中设置用于表示压缩图像的尺寸大小的尺寸参数作为控制压缩图像大小的接口,若需要对压缩后的图像的尺寸进行控制,则在压缩参数中设置对应的尺寸参数。在对图像进行压缩时,若在压缩参数中设置了对应的尺寸参数(表示需要控制压缩后的图像的尺寸),则从compressor类压缩算法中选取目标压缩算法进行图像的压缩,从而实现对压缩后的图像的尺寸的控制,若在压缩参数中未设置对应的尺寸参数(表示不需要控制压缩后的图像的尺寸),则从luban类压缩算法中选取目标压缩算法进行图像的压缩,实现更好的压缩效率和压缩效果。这样,即能够根据实际的图像压缩需求选择luban类压缩算法或者compressor类压缩算法,以满足不同的图像压缩需求。
可选地,压缩参数中也可以包括目标压缩算法对应的目标压缩算法标识,通过在压缩参数中设置对应的目标压缩算法标识,即能够从预先设置的多种压缩算法中指定目标压缩算法标识对应的压缩算法进行图像的压缩。开发人员可以将自定义的压缩算法设置在开源库中,然后通过在压缩参数中设置目标压缩算法标识即能够实现使用自定义的压缩算法进行图像的压缩,从而实现使用自定义的压缩算法进行图像的压缩,进一步提高图像压缩方法的性能,满足多样化的开发需求。
可见,实施该可选的实施例,能够在预先设置的多种压缩算法包括luban类压缩算法和compressor类压缩算法时,根据是否需要控制压缩后的图像的尺寸大小,从luban类压缩算法和compressor类压缩算法中选取合适的压缩算法进行图像的压缩,以更好地满足对压缩后的图像的尺寸大小的控制需求。
在一个可选的实施例中,所述luban类压缩算法包括luban类同步压缩算法和luban类异步压缩算法;
以及,所述根据所述压缩参数从所述luban类压缩算法中确定出所述图像数据对应的目标压缩算法,包括:
判断所述压缩参数是否包含异步压缩标识;
当判断出所述压缩参数包含所述异步压缩标识时,从所述luban类压缩算法中选取所述luban类异步压缩算法作为所述图像数据对应的目标压缩算法;
当判断出所述压缩参数不包含所述异步压缩标识时,从所述luban类压缩算法中选取所述luban类同步压缩算法作为所述图像数据对应的目标压缩算法。
在该可选的实施例中,Luban框架支持RxJava模式,在已有的luban压缩算法的程序的基础之上添加RxJava的相关程序,即能够实现luban压缩算法的RxJava模式。在使用luban压缩算法的RxJava模式时,通过设置RxJava的相关参数,能够指定处理图像压缩任务的线程和处理图像压缩结果回调任务的线程。通过设置处理图像压缩任务的线程和处理图像压缩结果回调任务所在的线程,即能够实现图像的异步压缩或同步压缩。例如,在luban压缩算法的RxJava模式中设置了处理图像压缩任务的线程为后台线程,处理图像压缩结果回调任务的线程为主线程,则为luban类异步压缩算法,在luban压缩算法的RxJava模式中设置了处理图像压缩任务的线程和处理图像压缩结果回调任务的线程均为主线程,则为luban类同步压缩算法。在android系统中,主线程主要用于进行android系统中的关键任务的处理,在主线程中不宜长时间处理耗时较长的任务,若主线程长时间堵塞,不利于android系统的流程运行,也容易引起android系统的报错。而对处理图像的压缩任务通常是需要较长时间以及较多资源的,所以在android应用的开发过程中,为保证android系统的正常运转,有时会需要将图像的压缩任务放置在后台线程中执行,减少图像压缩任务对主线程的干扰。当需要对图像进行异步压缩时,即可以在压缩参数中设置异步压缩标识,这样在对图像进行压缩时,将选择luban类异步压缩算法进行图像的压缩,从而实现对图像的异步压缩。当需要对图像进行同步压缩时,即可以不在压缩参数中设置异步压缩标识,这样在对图像进行压缩时,将选择luban类同步压缩算法进行图像的压缩,从而实现对图像的同步压缩。
可见,实施该可选的实施例,能够根据实际的开发需求实现对图像的同步压缩或者异步压缩,从而进一步提高图像压缩方法的性能,满足多样化的开发需求。
在一个可选的实施例中,在判断出所述压缩参数包含所述异步压缩标识之后,所述从所述luban类压缩算法中选取所述luban类异步压缩算法作为所述图像数据对应的目标压缩算法之前,所述方法还包括:
判断当前使用的线程是否是后台线程;
当判断出当前使用的线程是后台线程时,触发执行所述从所述luban类压缩算法中选取所述luban类同步压缩算法作为所述图像数据对应的目标压缩算法的操作;
当判断出当前使用的线程不是后台线程时,触发执行所述从所述luban类压缩算法中选取所述luban类异步压缩算法作为所述图像数据对应的目标压缩算法的操作。
在该可选的实施例中,对图像进行异步压缩的目的主要是将图像的压缩任务放置在后台线程中执行,避免压缩任务占用主线程,对android系统造成影响。在android应用中大多数时候使用的线程是主线程,所以大多数时候对图像执行异步压缩,即能够将图像的压缩任务放置在后台线程中执行。但是,有一些特殊的时间内,android应用使用的是后台线程,此时若再对图像进行异步压缩,则会将图像的压缩任务放置在主线程中,这显然是不合适的。所以,在判断出压缩参数包含异步压缩标识之后,若当前所使用的线程是后台线程,则可以不进行图像的异步压缩,而是进行图像的同步压缩,这样能够使图像压缩方法能够适用于更多的开发场景,更好地满足开发需求。
可见,实施该可选的实施例,能够在压缩参数包含异步压缩标识时,根据当前使用的线程是否是后台线程,自动调整图像的同步压缩或者异步压缩,从而能够使图像压缩方法能够适用于更多的开发场景,更好地满足开发需求。
同理,compressor框架也支持RxJava模式,所以compressor类压缩算法也可以包括compressor类同步压缩算法和compressor类异步压缩算法,在图像压缩方法对compressor类同步压缩算法和compressor类异步压缩算法的使用过程可以参照上述luban类同步压缩算法和luban类异步压缩算法的使用过程,为避免重复,不再赘述。
在一个可选的实施例中,所述基于所述目标压缩算法对所述图像数据进行压缩处理,得到所述图像数据对应的压缩图像数据之后,所述方法还包括:
判断所述图像数据是否用于刷新界面UI;
当判断出所述图像数据是用于刷新界面UI,将所述图像数据对应的压缩图像数据返回至主线程。
在该可选的实施例中,android系统限制了在后台线程中不可以刷新界面UI,所以当图像数据是用于刷新界面UI(即对图像数据进行压缩后得到的压缩图像数据将用于进行界面UI的刷新)时,将处理图像压缩结果回调任务的线程设置为主线程,这样能够将图像数据对应的压缩图像数据返回至主线程以进行界面UI的刷新。
可见,实施该可选的实施例,能够在待压缩的图像数据是用于刷新界面UI时,将压缩图像数据返回至主线程,从而能够适应android系统的限制,使压缩图像数据能够被用于进行界面UI的刷新,使得图像压缩方法能够适用于更多的开发场景,更好地满足开发需求。
在一个可选的实施例中,所述根据所述压缩参数确定所述图像数据对应的目标压缩算法之后,所述基于所述目标压缩算法对所述图像数据进行压缩处理,得到所述图像数据对应的压缩图像数据之前,所述方法还包括:
确定所述目标压缩算法对应的目标数据类型,所述目标数据类型是指所述目标压缩算法能够处理的数据类型;
判断所述图像数据的数据类型是否和所述目标数据类型相同;
当判断出所述图像数据的数据类型和所述目标数据类型不相同时,将所述图像数据的数据类型转换为所述目标数据类型,并触发执行所述基于所述目标压缩算法对所述图像数据进行压缩处理,得到所述图像数据对应的压缩图像数据的操作;
当判断出所述图像数据的数据类型和所述目标数据类型相同时,触发执行所述基于所述目标压缩算法对所述图像数据进行压缩处理,得到所述图像数据对应的压缩图像数据的操作。
在该可选的实施例中,android系统中图像数据常用的数据类型有三种:File类型、byte类型、Bitmap类型。一般的开源压缩算法通常只能对特定的数据类型的图像数据进行压缩,例如,luban框架和compressor框架都只能对File类型的图像数据进行压缩。但是,在实际android应用的开发中,需要进行压缩的图像数据的数据类型多种多样,所以使图像压缩方法能够支持各种数据类型的图像数据的压缩能够增加图像压缩方法的适应场景,能够更好地满足开发需求。具体地,当确定出的目标压缩算法所能够处理的数据类型与待压缩的图像数据的数据类型不一致时,可以使用android系统原生的数据类型转换API,对图像数据的数据类型进行转换。例如,android系统中的BitmapFactory类支持byte转Bitmap、File转Bitmap,BufferedOutputStream类支持Bitmap转File,ByteArrayOutputStream类支持Bitmap转byte。
可见,实施该可选的实施例,能够使图像压缩方法支持各种数据类型的图像数据的输入,增加图像压缩方法的适应场景,更好地满足开发需求。
在一个可选的实施例中,所述压缩参数包括输出数据类型标识;
以及,所述基于所述目标压缩算法对所述图像数据进行压缩处理,得到所述图像数据对应的压缩图像数据之后,所述方法还包括:
判断所述压缩图像数据的数据类型是否和所述输出数据类型标识对应的数据类型相同;
当判断出所述压缩图像数据的数据类型和所述输出数据类型标识对应的数据类型不相同,将所述压缩图像数据的数据类型转换为所述输出数据类型标识对应的数据类型。
在该可选的实施例中,类似地,一般的开源压缩算法在对图像数据进行压缩后通常只能将压缩图像数据以特定的数据类型输出。例如,luban框架和compressor框架都只能将压缩图像数据以File类型的数据输出。但是,在实际android应用的开发中,需要得到的压缩图像数据的数据类型也多种多样,所以使图像压缩方法支持各种数据类型的压缩图像数据的输出,能够增加图像压缩方法的适应场景,更好地满足开发需求。具体地,当需要输出的压缩图像数据的数据类型与确定出的目标压缩算法所能够输出的数据类型不一致时,可以使用android系统原生的数据类型转换API,对输出的压缩图像数据的数据类型进行转换。
可见,实施该可选的实施例,能够使图像压缩方法支持各种数据类型的压缩图像数据的输出,增加图像压缩方法的适应场景,更好地满足开发需求。
可选地,还可以:将所述图像数据的压缩方法的压缩信息上传至区块链中。
具体来说,压缩信息是通过运行所述图像数据的压缩方法后得到的,用于记录图像数据的压缩情况,例如,待压缩的图像数据、压缩后得到的压缩图像数据、选取出的压缩算法、压缩处理所使用的时长等等。将压缩信息上传至区块链可保证其安全性和对用户的公正透明性。用户可以从区块链中下载得到该压缩信息,以便查证所述图像数据的压缩方法的压缩信息是否被篡改。本示例所指区块链是分布式数据存储、点对点传输、共识机制、加密算法等计算机技术的新型应用模式。区块链(Blockchain),本质上是一个去中心化的数据库,是一串使用密码学方法相关联产生的数据块,每一个数据块中包含了一批次网络交易的信息,用于验证其信息的有效性(防伪)和生成下一个区块。区块链可以包括区块链底层平台、平台产品服务层以及应用服务层等。
可见,实施实施例一所描述的图像数据的压缩方法,能够将多种图像压缩算法结合在一起,然后根据压缩参数从多种图像压缩算法中确定出合适的图像压缩算法,以对图像数据进行合适的压缩处理,从而能够综合多种图像压缩算法实现多样化的图像压缩效果,提高图像压缩方法的性能,满足多样化的开发需求。还能够在预先设置的多种压缩算法包括luban类压缩算法和compressor类压缩算法时,根据是否需要控制压缩后的图像的尺寸大小,从luban类压缩算法和compressor类压缩算法中选取合适的压缩算法进行图像的压缩,以更好地满足对压缩后的图像的尺寸大小的控制需求。还能够根据实际的开发需求实现对图像的同步压缩或者异步压缩,从而进一步提高图像压缩方法的性能,满足多样化的开发需求。还能够在压缩参数包含异步压缩标识时,根据当前使用的线程是否是后台线程,自动调整图像的同步压缩或者异步压缩,从而能够使图像压缩方法能够适用于更多的开发场景,更好地满足开发需求。还能够在待压缩的图像数据是用于刷新界面UI时,将压缩图像数据返回至主线程,从而能够适应android系统的限制,使压缩图像数据能够被用于进行界面UI的刷新,使得图像压缩方法能够适用于更多的开发场景,更好地满足开发需求。还能够使图像压缩方法支持各种数据类型的图像数据的输入和各种数据类型的压缩图像数据的输出,增加图像压缩方法的适应场景,更好地满足开发需求。
实施例二
请参阅图2,图2是本申请实施例公开的一种图像数据的压缩装置的结构示意图。如图2所示,该图像数据的压缩装置可以包括:
获取模块201,用于获取待压缩的图像数据和所述图像数据对应的压缩参数;
确定模块202,用于根据所述压缩参数确定所述图像数据对应的目标压缩算法,所述目标压缩算法是预先设置的多种压缩算法中的其中一种;
压缩模块203,用于基于所述目标压缩算法对所述图像数据进行压缩处理,得到所述图像数据对应的压缩图像数据。
在一个可选的实施例中,预先设置的多种压缩算法包括luban类压缩算法和compressor类压缩算法,所述luban类压缩算法是指基于luban框架的压缩算法,所述compressor类压缩算法是指基于compressor框架的压缩算法;
以及所述确定模块202根据所述压缩参数确定所述图像数据对应的目标压缩算法的具体方式为:
判断所述压缩参数是否包含所述压缩图像数据对应的尺寸参数;
当判断出所述压缩参数包含所述压缩图像数据对应的尺寸参数时,根据所述压缩参数从所述luban类压缩算法中确定出所述图像数据对应的目标压缩算法;
当判断出所述压缩参数不包含所述压缩图像数据对应的尺寸参数时,根据所述压缩参数从所述compressor类压缩算法中确定出所述图像数据对应的目标压缩算法。
在一个可选的实施例中,所述luban类压缩算法包括luban类同步压缩算法和luban类异步压缩算法;
以及,所述确定模块202根据所述压缩参数从所述luban类压缩算法中确定出所述图像数据对应的目标压缩算法的具体方式为:
判断所述压缩参数是否包含异步压缩标识;
当判断出所述压缩参数包含所述异步压缩标识时,从所述luban类压缩算法中选取所述luban类异步压缩算法作为所述图像数据对应的目标压缩算法;
当判断出所述压缩参数不包含所述异步压缩标识时,从所述luban类压缩算法中选取所述luban类同步压缩算法作为所述图像数据对应的目标压缩算法。
在一个可选的实施例中,所述装置还包括:
判断模块,用于在所述确定模块202判断出所述压缩参数包含所述异步压缩标识之后,所述确定模块202从所述luban类压缩算法中选取所述luban类异步压缩算法作为所述图像数据对应的目标压缩算法之前,判断当前使用的线程是否是后台线程;当判断出当前使用的线程是后台线程时,触发所述确定模块202执行所述从所述luban类压缩算法中选取所述luban类同步压缩算法作为所述图像数据对应的目标压缩算法的操作;当判断出当前使用的线程不是后台线程时,触发所述确定模块202执行所述从所述luban类压缩算法中选取所述luban类异步压缩算法作为所述图像数据对应的目标压缩算法的操作。
在一个可选的实施例中,所述判断模块,还用于在判断出所述压缩参数包含所述异步压缩标识之后,所述确定模块202从所述luban类压缩算法中选取所述luban类异步压缩算法作为所述图像数据对应的目标压缩算法之前,判断当前使用的线程是否是后台线程;当判断出当前使用的线程是后台线程时,触发所述确定模块202执行所述从所述luban类压缩算法中选取所述luban类同步压缩算法作为所述图像数据对应的目标压缩算法的操作;当判断出当前使用的线程不是后台线程时,触发所述确定模块202执行所述从所述luban类压缩算法中选取所述luban类异步压缩算法作为所述图像数据对应的目标压缩算法的操作。
在一个可选的实施例中,所述判断模块,还用于在所述压缩模块203基于所述目标压缩算法对所述图像数据进行压缩处理,得到所述图像数据对应的压缩图像数据之后,判断所述图像数据是否用于刷新界面UI;当判断出所述图像数据是用于刷新界面UI,将所述图像数据对应的压缩图像数据返回至主线程。
在一个可选的实施例中,所述确定模块202,还用于在根据所述压缩参数确定所述图像数据对应的目标压缩算法之后,所述压缩模块203基于所述目标压缩算法对所述图像数据进行压缩处理,得到所述图像数据对应的压缩图像数据之前,确定所述目标压缩算法对应的目标数据类型,所述目标数据类型是指所述目标压缩算法能够处理的数据类型;
以及,所述判断模块,还用于判断所述图像数据的数据类型是否和所述目标数据类型相同;当判断出所述图像数据的数据类型和所述目标数据类型不相同时,将所述图像数据的数据类型转换为所述目标数据类型,并触发所述压缩模块203执行所述基于所述目标压缩算法对所述图像数据进行压缩处理,得到所述图像数据对应的压缩图像数据的操作;当判断出所述图像数据的数据类型和所述目标数据类型相同时,触发所述压缩模块203执行所述基于所述目标压缩算法对所述图像数据进行压缩处理,得到所述图像数据对应的压缩图像数据的操作。
在一个可选的实施例中,所述压缩参数包括输出数据类型标识;
以及,所述判断模块,还用于所述压缩模块203基于所述目标压缩算法对所述图像数据进行压缩处理,得到所述图像数据对应的压缩图像数据之后,判断所述压缩图像数据的数据类型是否和所述输出数据类型标识对应的数据类型相同;当判断出所述压缩图像数据的数据类型和所述输出数据类型标识对应的数据类型不相同,将所述压缩图像数据的数据类型转换为所述输出数据类型标识对应的数据类型。
对于上述图像数据的压缩装置的具体描述可以参照上述图像数据的压缩方法的具体描述,在此不再一一赘述。
实施例三
请参阅图3,图3是本申请实施例公开的一种计算机设备的结构示意图。如图3所示,该计算机设备可以包括:
存储有可执行程序代码的存储器301;
与存储器301连接的处理器302;
处理器302调用存储器301中存储的可执行程序代码,执行本申请实施例一公开的图像数据的压缩方法中的步骤。
实施例四
本申请实施例公开了一种计算机存储介质401,计算机存储介质401存储有计算机指令,该计算机指令被调用时,用于执行本申请实施例一公开的图像数据的压缩方法中的步骤。其中,计算机存储介质401可以是非易失性,也可以是易失性。

Claims (20)

1、一种图像数据的压缩方法,其中,所述方法包括:
获取待压缩的图像数据和所述图像数据对应的压缩参数;
根据所述压缩参数确定所述图像数据对应的目标压缩算法,所述目标压缩算法是预先设置的多种压缩算法中的其中一种;
基于所述目标压缩算法对所述图像数据进行压缩处理,得到所述图像数据对应的压缩图像数据;
其中,预先设置的多种压缩算法包括luban类压缩算法和compressor类压缩算法,所述luban类压缩算法是指基于luban框架的压缩算法,所述compressor类压缩算法是指基于compressor框架的压缩算法;
以及,所述根据所述压缩参数确定所述图像数据对应的目标压缩算法,包括:
判断所述压缩参数是否包含所述压缩图像数据对应的尺寸参数;
当判断出所述压缩参数包含所述压缩图像数据对应的尺寸参数时,根据所述压缩参数从所述luban类压缩算法中确定出所述图像数据对应的目标压缩算法;
当判断出所述压缩参数不包含所述压缩图像数据对应的尺寸参数时,根据所述压缩参数从所述compressor类压缩算法中确定出所述图像数据对应的目标压缩算法。
2、根据权利要求1所述的图像数据的压缩方法,其中,所述luban类压缩算法包括luban类同步压缩算法和luban类异步压缩算法;
以及,所述根据所述压缩参数从所述luban类压缩算法中确定出所述图像数据对应的目标压缩算法,包括:
判断所述压缩参数是否包含异步压缩标识;
当判断出所述压缩参数包含所述异步压缩标识时,从所述luban类压缩算法中选取所述luban类异步压缩算法作为所述图像数据对应的目标压缩算法;
当判断出所述压缩参数不包含所述异步压缩标识时,从所述luban类压缩算法中选取所述luban类同步压缩算法作为所述图像数据对应的目标压缩算法。
3、根据权利要求2所述的图像数据的压缩方法,其中,在判断出所述压缩参数包含所述异步压缩标识之后,所述从所述luban类压缩算法中选取所述luban类异步压缩算法作为所述图像数据对应的目标压缩算法之前,所述方法还包括:
判断当前使用的线程是否是后台线程;
当判断出当前使用的线程是后台线程时,触发执行所述从所述luban类压缩算法中选取所述luban类同步压缩算法作为所述图像数据对应的目标压缩算法的操作;
当判断出当前使用的线程不是后台线程时,触发执行所述从所述luban类压缩算法中选取所述luban类异步压缩算法作为所述图像数据对应的目标压缩算法的操作。
4、根据权利要求1-3任一项所述的图像数据的压缩方法,其中,所述基于所述目标压缩算法对所述图像数据进行压缩处理,得到所述图像数据对应的压缩图像数据之后,所述方法还包括:
判断所述图像数据是否用于刷新界面UI;
当判断出所述图像数据是用于刷新界面UI,将所述图像数据对应的压缩图像数据返回至主线程。
5、根据权利要求1-3任一项所述的图像数据的压缩方法,其中,所述根据所述压缩参数确定所述图像数据对应的目标压缩算法之后,所述基于所述目标压缩算法对所述图像数据进行压缩处理,得到所述图像数据对应的压缩图像数据之前,所述方法还包括:
确定所述目标压缩算法对应的目标数据类型,所述目标数据类型是指所述目标压缩算法能够处理的数据类型;
判断所述图像数据的数据类型是否和所述目标数据类型相同;
当判断出所述图像数据的数据类型和所述目标数据类型不相同时,将所述图像数据的数据类型转换为所述目标数据类型,并触发执行所述基于所述目标压缩算法对所述图像数据进行压缩处理,得到所述图像数据对应的压缩图像数据的操作;
当判断出所述图像数据的数据类型和所述目标数据类型相同时,触发执行所述基于所述目标压缩算法对所述图像数据进行压缩处理,得到所述图像数据对应的压缩图像数据的操作。
6、根据权利要求5所述的图像数据的压缩方法,其中,所述压缩参数包括输出数据类型标识;
以及,所述基于所述目标压缩算法对所述图像数据进行压缩处理,得到所述图像数据对应的压缩图像数据之后,所述方法还包括:
判断所述压缩图像数据的数据类型是否和所述输出数据类型标识对应的数据类型相同;
当判断出所述压缩图像数据的数据类型和所述输出数据类型标识对应的数据类型不相同,将所述压缩图像数据的数据类型转换为所述输出数据类型标识对应的数据类型。
7、一种图像数据的压缩装置,其中,所述装置包括:
获取模块,用于获取待压缩的图像数据和所述图像数据对应的压缩参数;
确定模块,用于根据所述压缩参数确定所述图像数据对应的目标压缩算法,所述目标压缩算法是预先设置的多种压缩算法中的其中一种;
压缩模块,用于基于所述目标压缩算法对所述图像数据进行压缩处理,得到所述图像数据对应的压缩图像数据;
其中,预先设置的多种压缩算法包括luban类压缩算法和compressor类压缩算法,所述luban类压缩算法是指基于luban框架的压缩算法,所述compressor类压缩算法是指基于compressor框架的压缩算法;
以及,所述确定模块根据所述压缩参数确定所述图像数据对应的目标压缩算法的具体方式为:
判断所述压缩参数是否包含所述压缩图像数据对应的尺寸参数;
当判断出所述压缩参数包含所述压缩图像数据对应的尺寸参数时,根据所述压缩参数从所述luban类压缩算法中确定出所述图像数据对应的目标压缩算法;
当判断出所述压缩参数不包含所述压缩图像数据对应的尺寸参数时,根据所述压缩参数从所述compressor类压缩算法中确定出所述图像数据对应的目标压缩算法。
8、根据权利要求7所述的图像数据的压缩装置,其中,所述luban类压缩算法包括luban类同步压缩算法和luban类异步压缩算法;
以及,所述确定模块根据所述压缩参数从所述luban类压缩算法中确定出所述图像数据对应的目标压缩算法的具体方式为:
判断所述压缩参数是否包含异步压缩标识;
当判断出所述压缩参数包含所述异步压缩标识时,从所述luban类压缩算法中选取所述luban类异步压缩算法作为所述图像数据对应的目标压缩算法;
当判断出所述压缩参数不包含所述异步压缩标识时,从所述luban类压缩算法中选取所述luban类同步压缩算法作为所述图像数据对应的目标压缩算法。
9、一种计算机设备,其中,所述计算机设备包括:
存储有可执行程序代码的存储器;
与所述存储器连接的处理器;
所述处理器调用所述存储器中存储的所述可执行程序代码时,执行如下方法:
获取待压缩的图像数据和所述图像数据对应的压缩参数;
根据所述压缩参数确定所述图像数据对应的目标压缩算法,所述目标压缩算法是预先设置的多种压缩算法中的其中一种;
基于所述目标压缩算法对所述图像数据进行压缩处理,得到所述图像数据对应的压缩图像数据;
其中,预先设置的多种压缩算法包括luban类压缩算法和compressor类压缩算法,所述luban类压缩算法是指基于luban框架的压缩算法,所述compressor类压缩算法是指基于compressor框架的压缩算法;
以及,所述根据所述压缩参数确定所述图像数据对应的目标压缩算法,包括:
判断所述压缩参数是否包含所述压缩图像数据对应的尺寸参数;
当判断出所述压缩参数包含所述压缩图像数据对应的尺寸参数时,根据所述压缩参数从所述luban类压缩算法中确定出所述图像数据对应的目标压缩算法;
当判断出所述压缩参数不包含所述压缩图像数据对应的尺寸参数时,根据所述压缩参数从所述compressor类压缩算法中确定出所述图像数据对应的目标压缩算法。
10、根据权利要求9所述的计算机设备,其中,所述luban类压缩算法包括luban类同步压缩算法和luban类异步压缩算法;
以及,所述根据所述压缩参数从所述luban类压缩算法中确定出所述图像数据对应的目标压缩算法,包括:
判断所述压缩参数是否包含异步压缩标识;
当判断出所述压缩参数包含所述异步压缩标识时,从所述luban类压缩算法中选取所述luban类异步压缩算法作为所述图像数据对应的目标压缩算法;
当判断出所述压缩参数不包含所述异步压缩标识时,从所述luban类压缩算法中选取所述luban类同步压缩算法作为所述图像数据对应的目标压缩算法。
11、根据权利要求10所述的计算机设备,其中,在判断出所述压缩参数包含所述异步压缩标识之后,所述从所述luban类压缩算法中选取所述luban类异步压缩算法作为所述图像数据对应的目标压缩算法之前,所述方法还包括:
判断当前使用的线程是否是后台线程;
当判断出当前使用的线程是后台线程时,触发执行所述从所述luban类压缩算法中选取所述luban类同步压缩算法作为所述图像数据对应的目标压缩算法的操作;
当判断出当前使用的线程不是后台线程时,触发执行所述从所述luban类压缩算法中选取所述luban类异步压缩算法作为所述图像数据对应的目标压缩算法的操作。
12、根据权利要求9-11任一项所述的计算机设备,其中,所述基于所述目标压缩算法对所述图像数据进行压缩处理,得到所述图像数据对应的压缩图像数据之后,所述方法还包括:
判断所述图像数据是否用于刷新界面UI;
当判断出所述图像数据是用于刷新界面UI,将所述图像数据对应的压缩图像数据返回至主线程。
13、根据权利要求9-11任一项所述的计算机设备,其中,所述根据所述压缩参数确定所述图像数据对应的目标压缩算法之后,所述基于所述目标压缩算法对所述图像数据进行压缩处理,得到所述图像数据对应的压缩图像数据之前,所述方法还包括:
确定所述目标压缩算法对应的目标数据类型,所述目标数据类型是指所述目标压缩算法能够处理的数据类型;
判断所述图像数据的数据类型是否和所述目标数据类型相同;
当判断出所述图像数据的数据类型和所述目标数据类型不相同时,将所述图像数据的数据类型转换为所述目标数据类型,并触发执行所述基于所述目标压缩算法对所述图像数据进行压缩处理,得到所述图像数据对应的压缩图像数据的操作;
当判断出所述图像数据的数据类型和所述目标数据类型相同时,触发执行所述基于所述目标压缩算法对所述图像数据进行压缩处理,得到所述图像数据对应的压缩图像数据的操作。
14、根据权利要求13所述的计算机设备,其中,所述压缩参数包括输出数据类型标识;
以及,所述基于所述目标压缩算法对所述图像数据进行压缩处理,得到所述图像数据对应的压缩图像数据之后,所述方法还包括:
判断所述压缩图像数据的数据类型是否和所述输出数据类型标识对应的数据类型相同;
当判断出所述压缩图像数据的数据类型和所述输出数据类型标识对应的数据类型不相同,将所述压缩图像数据的数据类型转换为所述输出数据类型标识对应的数据类型。
15、一种计算机存储介质,所述计算机存储介质存储有计算机程序,其中,所述计算机程序被处理器执行时,实现如下方法:
获取待压缩的图像数据和所述图像数据对应的压缩参数;
根据所述压缩参数确定所述图像数据对应的目标压缩算法,所述目标压缩算法是预先设置的多种压缩算法中的其中一种;
基于所述目标压缩算法对所述图像数据进行压缩处理,得到所述图像数据对应的压缩图像数据;
其中,预先设置的多种压缩算法包括luban类压缩算法和compressor类压缩算法,所述luban类压缩算法是指基于luban框架的压缩算法,所述compressor类压缩算法是指基于compressor框架的压缩算法;
以及,所述根据所述压缩参数确定所述图像数据对应的目标压缩算法,包括:
判断所述压缩参数是否包含所述压缩图像数据对应的尺寸参数;
当判断出所述压缩参数包含所述压缩图像数据对应的尺寸参数时,根据所述压缩参数从所述luban类压缩算法中确定出所述图像数据对应的目标压缩算法;
当判断出所述压缩参数不包含所述压缩图像数据对应的尺寸参数时,根据所述压缩参数从所述compressor类压缩算法中确定出所述图像数据对应的目标压缩算法。
16、根据权利要求15所述的计算机存储介质,其中,所述luban类压缩算法包括luban类同步压缩算法和luban类异步压缩算法;
以及,所述根据所述压缩参数从所述luban类压缩算法中确定出所述图像数据对应的目标压缩算法,包括:
判断所述压缩参数是否包含异步压缩标识;
当判断出所述压缩参数包含所述异步压缩标识时,从所述luban类压缩算法中选取所述luban类异步压缩算法作为所述图像数据对应的目标压缩算法;
当判断出所述压缩参数不包含所述异步压缩标识时,从所述luban类压缩算法中选取所述luban类同步压缩算法作为所述图像数据对应的目标压缩算法。
17、根据权利要求16所述的计算机存储介质,其中,在判断出所述压缩参数包含所述异步压缩标识之后,所述从所述luban类压缩算法中选取所述luban类异步压缩算法作为所述图像数据对应的目标压缩算法之前,所述方法还包括:
判断当前使用的线程是否是后台线程;
当判断出当前使用的线程是后台线程时,触发执行所述从所述luban类压缩算法中选取所述luban类同步压缩算法作为所述图像数据对应的目标压缩算法的操作;
当判断出当前使用的线程不是后台线程时,触发执行所述从所述luban类压缩算法中选取所述luban类异步压缩算法作为所述图像数据对应的目标压缩算法的操作。
18、根据权利要求15-17任一项所述的计算机存储介质,其中,所述基于所述目标压缩算法对所述图像数据进行压缩处理,得到所述图像数据对应的压缩图像数据之后,所述方法还包括:
判断所述图像数据是否用于刷新界面UI;
当判断出所述图像数据是用于刷新界面UI,将所述图像数据对应的压缩图像数据返回至主线程。
19、根据权利要求15-17任一项所述的计算机存储介质,其中,所述根据所述压缩参数确定所述图像数据对应的目标压缩算法之后,所述基于所述目标压缩算法对所述图像数据进行压缩处理,得到所述图像数据对应的压缩图像数据之前,所述方法还包括:
确定所述目标压缩算法对应的目标数据类型,所述目标数据类型是指所述目标压缩算法能够处理的数据类型;
判断所述图像数据的数据类型是否和所述目标数据类型相同;
当判断出所述图像数据的数据类型和所述目标数据类型不相同时,将所述图像数据的数据类型转换为所述目标数据类型,并触发执行所述基于所述目标压缩算法对所述图像数据进行压缩处理,得到所述图像数据对应的压缩图像数据的操作;
当判断出所述图像数据的数据类型和所述目标数据类型相同时,触发执行所述基于所述目标压缩算法对所述图像数据进行压缩处理,得到所述图像数据对应的压缩图像数据的操作。
20、根据权利要求19所述的计算机存储介质,其中,所述压缩参数包括输出数据类型标识;
以及,所述基于所述目标压缩算法对所述图像数据进行压缩处理,得到所述图像数据对应的压缩图像数据之后,所述方法还包括:
判断所述压缩图像数据的数据类型是否和所述输出数据类型标识对应的数据类型相同;
当判断出所述压缩图像数据的数据类型和所述输出数据类型标识对应的数据类型不相同,将所述压缩图像数据的数据类型转换为所述输出数据类型标识对应的数据类型。
PCT/CN2021/091689 2020-12-29 2021-04-30 图像数据的压缩方法、装置、计算机设备以及存储介质 WO2022142039A1 (zh)

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CN202011590409.5 2020-12-29
CN202011590409.5A CN112770114B (zh) 2020-12-29 2020-12-29 图像数据的压缩方法、装置、计算机设备以及存储介质

Publications (1)

Publication Number Publication Date
WO2022142039A1 true WO2022142039A1 (zh) 2022-07-07

Family

ID=75696669

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2021/091689 WO2022142039A1 (zh) 2020-12-29 2021-04-30 图像数据的压缩方法、装置、计算机设备以及存储介质

Country Status (2)

Country Link
CN (1) CN112770114B (zh)
WO (1) WO2022142039A1 (zh)

Families Citing this family (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN115643310B (zh) * 2022-09-26 2024-08-13 建信金融科技有限责任公司 一种压缩数据的方法、装置和系统
CN116823492B (zh) * 2023-05-05 2024-04-02 上海原力枫林信息技术有限公司 一种数据的存储方法及系统
CN117478888A (zh) * 2023-12-28 2024-01-30 中移(苏州)软件技术有限公司 一种图像压缩方法、装置、终端设备及可读存储介质

Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US7930436B1 (en) * 2009-03-09 2011-04-19 Znosko Dmitry Y System and method for dynamically adjusting data compression parameters
CN102761339A (zh) * 2012-05-30 2012-10-31 北京奇虎科技有限公司 数据压缩方法及装置
CN106919617A (zh) * 2015-12-25 2017-07-04 北京奇虎科技有限公司 一种压缩存储方法和装置
US20190028116A1 (en) * 2015-03-06 2019-01-24 Oracle International Corporation Dynamic data compression selection
CN111683189A (zh) * 2020-05-14 2020-09-18 苏州达家迎信息技术有限公司 图片压缩方法、系统、终端、及存储介质

Family Cites Families (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US10474896B2 (en) * 2017-07-18 2019-11-12 Facebook, Inc. Image compression using content categories
CN111836052B (zh) * 2020-07-06 2022-11-15 Oppo广东移动通信有限公司 图像压缩方法、装置、电子设备及存储介质

Patent Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US7930436B1 (en) * 2009-03-09 2011-04-19 Znosko Dmitry Y System and method for dynamically adjusting data compression parameters
CN102761339A (zh) * 2012-05-30 2012-10-31 北京奇虎科技有限公司 数据压缩方法及装置
US20190028116A1 (en) * 2015-03-06 2019-01-24 Oracle International Corporation Dynamic data compression selection
CN106919617A (zh) * 2015-12-25 2017-07-04 北京奇虎科技有限公司 一种压缩存储方法和装置
CN111683189A (zh) * 2020-05-14 2020-09-18 苏州达家迎信息技术有限公司 图片压缩方法、系统、终端、及存储介质

Also Published As

Publication number Publication date
CN112770114A (zh) 2021-05-07
CN112770114B (zh) 2023-03-28

Similar Documents

Publication Publication Date Title
WO2022142039A1 (zh) 图像数据的压缩方法、装置、计算机设备以及存储介质
EP3754490B1 (en) User interface rendering method and apparatus, and terminal
CN111163345B (zh) 一种图像渲染方法及装置
CN105378689B (zh) 用于统一可扩展固件接口(uefi)驱动器和协议的方法和装置
WO2022257699A1 (zh) 图像画面显示方法、装置、设备、存储介质及程序产品
JP2001051860A (ja) マルチスレッド処理装置及び処理方法並びにマルチスレッドプログラムを格納したコンピュータ可読の記録媒体
CN113473214B (zh) 一种屏幕录制方法、装置、计算设备及可读存储介质
CN110968395B (zh) 一种在模拟器中处理渲染指令的方法及移动终端
CN112055072A (zh) 云端音频输入方法、装置、云系统、电子设备与存储介质
WO2022199283A1 (zh) 用于确定调用栈栈帧的对象的方法、装置、设备和介质
CN111858200B (zh) 系统测试中的吞吐量控制方法、装置及电子设备
WO2019136837A1 (zh) 一种智能加载系统、方法、存储介质及设备
CN108563719A (zh) 一种用于异常日志转储的lzo压缩方法及系统
CN113393367A (zh) 图像处理方法、装置、设备和介质
US20240212255A1 (en) Scene Rendering Method, Apparatus, Device, and System
CN111294377B (zh) 一种依赖关系的网络请求发送方法、终端装置及存储介质
CN114205680A (zh) 视频封面展示方法及其装置、设备、介质、产品
WO2015058594A1 (zh) 一种进程加载方法、装置及系统
WO2023185765A1 (zh) 基于云应用的文件处理方法、电子设备和存储介质
CN108536429A (zh) 一种开发软件的方法、装置、存储介质及电子设备
CN110012003B (zh) 一种云应用抓屏方法和装置
CN116546228A (zh) 用于虚拟场景的推流方法、装置、设备及存储介质
CN115309315A (zh) Wayland环境下X应用的截图方法、系统及介质
CN106126253B (zh) 一种应用程序视图生成图像的方法及装置
CN113641674A (zh) 一种自适应全局序号发生方法和装置

Legal Events

Date Code Title Description
121 Ep: the epo has been informed by wipo that ep was designated in this application

Ref document number: 21912801

Country of ref document: EP

Kind code of ref document: A1

NENP Non-entry into the national phase

Ref country code: DE

32PN Ep: public notification in the ep bulletin as address of the adressee cannot be established

Free format text: NOTING OF LOSS OF RIGHTS PURSUANT TO RULE 112(1) EPC (EPO FORM 1205A DATED 23.10.2023)

122 Ep: pct application non-entry in european phase

Ref document number: 21912801

Country of ref document: EP

Kind code of ref document: A1