Movatterモバイル変換


[0]ホーム

URL:


CN104142924A - Compression method and device for animation picture format - Google Patents

Compression method and device for animation picture format
Download PDF

Info

Publication number
CN104142924A
CN104142924ACN201310162376.8ACN201310162376ACN104142924ACN 104142924 ACN104142924 ACN 104142924ACN 201310162376 ACN201310162376 ACN 201310162376ACN 104142924 ACN104142924 ACN 104142924A
Authority
CN
China
Prior art keywords
picture
data
file
png
compression
Prior art date
Legal status (The legal status 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 status listed.)
Pending
Application number
CN201310162376.8A
Other languages
Chinese (zh)
Inventor
裴峥
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
China Mobile Group Fujian Co Ltd
Original Assignee
China Mobile Group Fujian Co Ltd
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 China Mobile Group Fujian Co LtdfiledCriticalChina Mobile Group Fujian Co Ltd
Priority to CN201310162376.8ApriorityCriticalpatent/CN104142924A/en
Publication of CN104142924ApublicationCriticalpatent/CN104142924A/en
Pendinglegal-statusCriticalCurrent

Links

Classifications

Landscapes

Abstract

Translated fromChinese

本发明公开了一种动画图片格式的压缩方法和装置,其中,该方法包括:获取待压缩的动画图片,将每帧动画图片的图片头进行分析挑选处理;创建新压缩文件,自动画图片提取相近色信息,进行重新组合填入到新压缩文件的相应数据位置;将自图片头分析挑选出的文件数据写入新压缩文件中,存储所述动画图片的实体数据。本发明的动画图片格式的压缩方法和装置,采用相近色图片压缩技术,支持手机中都是16位以上的效果图,在高压缩率的压缩过程中,同系列(相近色)图片越多,压缩率越高,可以达到70%左右,且在压缩过程中不会丢失图像色彩深度。

The invention discloses a method and device for compressing an animation picture format, wherein the method includes: obtaining an animation picture to be compressed, analyzing and selecting the picture header of each frame of animation picture; creating a new compressed file, and extracting the animation picture automatically The similar color information is recombined and filled into the corresponding data position of the new compressed file; the file data selected from the analysis of the picture header is written into the new compressed file, and the entity data of the animation picture is stored. The animation image format compression method and device of the present invention adopt similar-color image compression technology to support effect images of more than 16 bits in mobile phones. The higher the compression rate, it can reach about 70%, and the image color depth will not be lost during the compression process.

Description

Translated fromChinese
一种动画图片格式的压缩方法和装置Compression method and device for animation picture format

技术领域technical field

本发明涉及通信领域中数据业务技术领域,具体地,涉及一种动画图片格式的压缩方法和装置。The present invention relates to the technical field of data services in the communication field, in particular to a method and device for compressing animation picture formats.

背景技术Background technique

现有常见的动画图片格式是图像互换格式(Graphics Interchange Format,以下简称GIF),GIF是CompuServe公司在1987年开发的图像文件格式。GIF文件的数据,是一种基于LZW(Lempel Ziv Compression)压缩算法的连续色调的无损压缩格式。The existing common animation picture format is Graphics Interchange Format (hereinafter referred to as GIF). GIF is an image file format developed by CompuServe in 1987. The data of the GIF file is a continuous tone lossless compression format based on the LZW (Lempel Ziv Compression) compression algorithm.

如图1所示,现有的图片动画包压缩的流程包括:As shown in Figure 1, the existing picture animation package compression process includes:

步骤102:创建新的压缩包文件;Step 102: Create a new compressed package file;

步骤104:利用LZW压缩算法写新的压缩包文件头;Step 104: Utilize the LZW compression algorithm to write a new compressed package file header;

步骤106:利用LZW压缩算法填写新的压缩包文件内容。Step 106: Use the LZW compression algorithm to fill in the content of the new compressed package file.

LZW压缩算法的详细编码过程包括:The detailed encoding process of the LZW compression algorithm includes:

GIF文件的图像数据使用了可变长度编码的LZW压缩算法(Variable-Length_Code LZW Compression),其是从LZW压缩算法演变过来,通过压缩原始数据的重复部分来达到减少文件大小的目的。The image data of the GIF file uses the variable-length coded LZW compression algorithm (Variable-Length_Code LZW Compression), which evolved from the LZW compression algorithm, and reduces the file size by compressing the repeated part of the original data.

在介绍LZW的压缩原理之前,先解释几个基本概念:Before introducing the compression principle of LZW, explain a few basic concepts:

LZW压缩有三个重要的对象:数据流(Char Stream)、编码流(CodeStream)和编译表(String Table)。LZW compression has three important objects: data stream (Char Stream), encoding stream (CodeStream) and compilation table (String Table).

在编码时,数据流是输入对象(图像的光栅数据序列),编码流是输出对象(存储在GIF文件的图像数据);在解码时,编码流是输入对象,数据流是输出对象;而编译表是在编码和解码时都需要借助的对象。When encoding, the data stream is the input object (the raster data sequence of the image), and the encoded stream is the output object (the image data stored in the GIF file); when decoding, the encoded stream is the input object, and the data stream is the output object; while compiling Tables are objects that are needed both for encoding and decoding.

字符(Character):最基础的数据元素,在文本文件中是一个字节,在光栅数据中是一个像素的颜色在指定的颜色列表中的索引值;Character (Character): the most basic data element, which is a byte in a text file and an index value of a pixel's color in the specified color list in raster data;

字符串(String):由几个连续的字符组成;String (String): consists of several consecutive characters;

前缀(Prefix):也是一个字符串,不过通常用在另一个字符的前面,而且它的长度可以为0;Prefix: It is also a string, but it is usually used in front of another character, and its length can be 0;

根(Root):单个长度的字符串;Root: a single-length string;

编码(Code):一个数字,按照固定长度(编码长度)从编码流中取出,也是编码表的映射值;Code (Code): a number, which is taken out from the code stream according to a fixed length (code length), and is also the mapping value of the code table;

图案:一个字符串,按不定长度从数据流中读出。Pattern: A character string, of variable length, read from the data stream.

LZW压缩的原理:先提取原始图像数据中的不同图案,基于这些图案创建一个编译表,然后用编译表中的图案索引来替代原始光栅数据中的相应图案,减少原始数据大小。其与调色板图像的实现原理相似。但是,上述的编译表不是事先创建好的,而是根据原始图像数据动态创建的,解码时还要从已编码的数据中还原出原来的编译表(GIF文件中不携带编译表信息),为了更好理解编解码原理,先交代其具体处理过程:The principle of LZW compression: first extract different patterns in the original image data, create a compilation table based on these patterns, and then use the pattern index in the compilation table to replace the corresponding pattern in the original raster data, reducing the size of the original data. It is similar to the implementation principle of the palette image. However, the above compilation table is not created in advance, but is dynamically created according to the original image data. When decoding, the original compilation table must be restored from the encoded data (the GIF file does not carry the compilation table information). To better understand the principle of encoding and decoding, first explain its specific processing process:

编码器(Compressor),即编码数据:第一步,初始化一个编译表,假设该编译表的大小是12位,即最多有4096个单位,另外假设有32个不同的字符(图像的每个像素最多有32种颜色),表示为a,b,c,d,e……,初始化编译表:第0项为a,第1项为b,第2项为c……,一直到第31项,将这32项称为根。Encoder (Compressor), that is, encoded data: the first step is to initialize a compilation table, assuming that the size of the compilation table is 12 bits, that is, there are up to 4096 units, and it is assumed that there are 32 different characters (each pixel of the image There are up to 32 colors), expressed as a, b, c, d, e..., initialize the compilation table: the 0th item is a, the 1st item is b, the 2nd item is c..., until the 31st item , and call these 32 items the root.

解码器(Decompressor),数据编码的逆向过程:要从已编译的数据(编码流)中找出编译表,然后对照编译表还原图像的光栅数据。Decompressor (Decompressor), the reverse process of data encoding: to find the compilation table from the compiled data (coded stream), and then restore the raster data of the image against the compilation table.

首先,初始化编译表。GIF文件的图像数据的第一个字节存储的就是LZW编码的编码大小(一般等于图像的位数),根据编码大小,初始化编译表的根条目(从0到2的编码大小次方),然后定义一个当前编码Current Code,记作[code],定义一个Old Code,记作[old]。First, initialize the compilation table. The first byte of the image data of the GIF file stores the encoding size of the LZW encoding (generally equal to the number of bits of the image). According to the encoding size, initialize the root entry of the compilation table (from 0 to 2 to the power of the encoding size), Then define a Current Code, denoted as [code], define an Old Code, denoted as [old].

读取第一个编码到[code],为一个根编码,在编译表中可以找到,将该编码所对应的字符输出到数据流,即[old]=[code];读取下一个编码到[code],包括两种情况:在编译表中存在或未存在该编码。Read the first code to [code], which is a root code, which can be found in the compilation table, and output the character corresponding to the code to the data stream, that is, [old]=[code]; read the next code to [code], including two cases: the code exists or does not exist in the compilation table.

先来看编译表中存在该编码的情况:先输出当前编码[code]所对应的字符(串)到数据流,然后将[old]所对应的字符(串)当成prefix[...],当前编码[code]所对应的字符(串)的第一个字符当成k,组合起来当前字符串CurrentString就为[...]k,将[...]k添加到编译表,读下一个编码。Let’s first look at the existence of this encoding in the compilation table: first output the character (string) corresponding to the current encoding [code] to the data stream, and then use the character (string) corresponding to [old] as prefix[...], The first character of the character (string) corresponding to the current code [code] is regarded as k, and the current string CurrentString is […]k when combined, add […]k to the compilation table, and read the next coding.

再来看编译表中未存在该编码的情况:如果数据流中有一个p[...]p[...]pq这样的字符串,p[...]在编译表中而p[...]p不在,编译器将输出p[...]的索引而添加p[...]p到编译表,下一个字符串p[...]p可以在编译表中找到,而p[...]pq在编译表中找不到,同样将输出p[...]p的索引值而添加p[...]pq到编译表。因此,解码器总比编码器“慢一步”,当遇到p[...]p所对应的索引时,我们不知道该索引对应的字符串(在解码器的编译表中还未存在该索引,事实上,该索引将在下一步添加)。此时需用猜测法:现在假设上述p[...]所对应的索引值是#58,那么上述字符串经过编译之后是#58#59。我们在解码器中读到#59时,编译表的最大索引只有#58,#59所对应的字符串就等于#58所对应的字符串(也就是p[...])加上它的第一个字符(即p),即p[...]p。事实上,GIF数据压缩,表1是GIF文件的图像数据结构。Let's look at the case where the code does not exist in the compilation table: if there is a string such as p[...]p[...]pq in the data stream, p[...] is in the compilation table and p[. ..]p is absent, the compiler will output the index of p[…]p and add p[…]p to the compilation table, the next string p[…]p can be found in the compilation table, and p[...]pq cannot be found in the compilation table, and the index value of p[...]p will also be output and p[...]pq will be added to the compilation table. Therefore, the decoder is always "one step slower" than the encoder. When encountering the index corresponding to p[...]p, we don't know the string corresponding to the index (this index does not exist in the decoder's compilation table yet. index, in fact, the index will be added in the next step). At this time, guessing is required: Now suppose that the index value corresponding to the above p[...] is #58, then the above string after compilation is #58#59. When we read #59 in the decoder, the maximum index of the compilation table is only #58, and the string corresponding to #59 is equal to the string corresponding to #58 (that is, p[...]) plus its The first character (i.e. p), i.e. p[...]p. In fact, GIF data compression, Table 1 is the image data structure of GIF files.

表1Table 1

将光栅数据序列(数据流)压缩成GIF文件的图像数据(字符流)可以按以下步骤进行:Compressing raster data sequence (data stream) into image data (character stream) of GIF file can be carried out as follows:

1、定义编码长度:GIF图像数据的第一个字节就是编码长度(Code Size),该值是指要表现一个像素所需要的最小位数,通常等于图像的色深;1. Define the code length: the first byte of GIF image data is the code size (Code Size), which refers to the minimum number of bits required to represent a pixel, usually equal to the color depth of the image;

2、压缩数据:通过LZW压缩算法将图像的光栅数据流压缩成GIF的编码数据流。本步骤使用的LZW压缩算法是从标准的LZW压缩算法演变过来的,它们之间有如下的差别:2. Compressed data: Compress the raster data stream of the image into the encoded data stream of GIF through the LZW compression algorithm. The LZW compression algorithm used in this step is evolved from the standard LZW compression algorithm, and the differences between them are as follows:

(1)GIF文件定义了一个编码大小(Clear Code),该值等于2的“编码长度”次方,在重新开始一个编译表(编译表溢出)时均需输出该值,解码器遇到该值时要重新初始化一个编译表;(1) The GIF file defines a code size (Clear Code), which is equal to 2 to the power of "code length". This value must be output when restarting a compilation table (compilation table overflow), and the decoder encounters this value. value to reinitialize a compilation table;

(2)在一个图像的编码数据结束之前(即在块终结器的前面),需要输出一个Clear Code+1的值,解码器在遇到该值时意味着GIF文件的一个图像数据流的结束;(2) Before the end of the encoded data of an image (that is, in front of the block terminator), a value of Clear Code+1 needs to be output. When the decoder encounters this value, it means the end of an image data stream of the GIF file. ;

(3)第一个可用到的编译表索引值是Clear Code+2(从0到Clear Code-1是根索引,再上去两个索引不可使用,新的索引值从Clare Code+2开始添加);(3) The first available compilation table index value is Clear Code+2 (from 0 to Clear Code-1 is the root index, and the next two indexes cannot be used, and the new index value is added from Clare Code+2) ;

(4)GIF输出的编码流是不定长的,每个编码的大小从Code Size+1位到12位,编码的最大值是4095(编译表需要定义的索引数就是4096),当编码所需位数超过当前位数时就把当前位数加1,这就需要在编码或解码时注意编码长度的改变。(4) The coded stream output by GIF is of variable length. The size of each code is from Code Size+1 bit to 12 bits. When the number of digits exceeds the current number of digits, add 1 to the current number of digits, which requires attention to the change of the code length during encoding or decoding.

3、编译成字节序列3. Compile into byte sequence

由于GIF输出的编码流是不定长的,故需要将GIF输出的编码流编译成固定的8-bit长度的字符流,编译顺序是自右向左生成。Since the encoded stream output by GIF is of variable length, it is necessary to compile the encoded stream output by GIF into a fixed 8-bit length character stream, and the compilation sequence is generated from right to left.

现有一个GIF的数据块大小为0到255个字节,第一个字节是该数据块的大小(字节数),需要将编译后的码数据打包成一个或几个大小不大于255个字节的数据包,然后写入图像数据块中。The data block size of an existing GIF is 0 to 255 bytes, and the first byte is the size (number of bytes) of the data block. It is necessary to pack the compiled code data into one or several blocks whose size is not greater than 255 bytes of data packets, and then written to the image data block.

GIF是一种基于LZW算法的连续色调的无损压缩格式,其压缩率一般在50%左右。GIF文件在压缩过程中,图像的像素资料不会丢失,丢失的是图像色彩。GIF is a continuous tone lossless compression format based on the LZW algorithm, and its compression ratio is generally around 50%. During the compression process of GIF files, the pixel data of the image will not be lost, but the color of the image will be lost.

GIF格式最多只能储存256色,通常用来显示简单图形及字体。因此,现有的动画很难有超过256色的效果,无法满足现在的用户需求。目前上述动画在处理压缩算法上都存在2D的效果,而且在多状态动画间播放存在无法分割的问题,难于控制。特别是现有的动画进入了2.5D、3D时代,使用GIF动画格式作为动画包会存在如下几个重大缺陷:The GIF format can only store up to 256 colors and is usually used to display simple graphics and fonts. Therefore, it is difficult for the existing animation to have an effect of more than 256 colors, which cannot meet the needs of current users. At present, the above-mentioned animations all have 2D effects in the processing of compression algorithms, and there is an inseparable problem in the playback of multi-state animations, which is difficult to control. Especially when the existing animation has entered the 2.5D and 3D era, using the GIF animation format as the animation package will have the following major defects:

1、不支持256色以上,效果很难让用户满意;1. It does not support more than 256 colors, and the effect is difficult to satisfy users;

2、现有手机的显示都是16位以上,8位256色基本不使用;2. The display of existing mobile phones is more than 16 bits, and 8 bits and 256 colors are basically not used;

3、压缩率只有50%左右,较难进一步提高容量;3. The compression rate is only about 50%, and it is difficult to further increase the capacity;

4、在压缩过程中丢失图像色彩严重。4. The color of the image is seriously lost during the compression process.

发明内容Contents of the invention

本发明是为了克服现有技术中对GIF动画图片压缩不充分的缺陷,根据本发明的一个方面,提出一种动画图片格式的压缩方法。The purpose of the present invention is to overcome the defect of insufficient compression of GIF animation pictures in the prior art. According to one aspect of the invention, a compression method of the animation picture format is proposed.

根据本发明实施例的动画图片格式的压缩方法,包括:The compression method of the animated picture format according to the embodiment of the present invention comprises:

获取待压缩的动画图片,将每帧动画图片的图片头进行分析挑选处理;Obtain the animation picture to be compressed, analyze and select the picture header of each frame of animation picture;

创建新压缩文件,自动画图片提取相近色信息,进行重新组合填入到新压缩文件的相应数据位置;Create a new compressed file, automatically draw pictures to extract similar color information, recombine and fill in the corresponding data position of the new compressed file;

将自图片头分析挑选出的文件数据写入新压缩文件中,存储动画图片的实体数据。Write the file data selected from the picture header analysis into the new compressed file to store the entity data of the animation picture.

本发明是为了克服现有技术中对GIF动画图片压缩不充分的缺陷,根据本发明的另一个方面,提出一种动画图片格式的压缩装置。The purpose of the present invention is to overcome the defect of insufficient compression of GIF animation pictures in the prior art. According to another aspect of the invention, a compression device for animation picture format is proposed.

根据本发明实施例的动画图片格式的压缩装置,包括:The compression device of the animated picture format according to the embodiment of the present invention comprises:

分析处理模块,用于获取待压缩的动画图片,将每帧动画图片的图片头进行分析挑选处理;The analysis processing module is used to obtain the animated picture to be compressed, and analyze and select the picture header of each frame of the animated picture;

创建提取模块,用于创建新压缩文件,自动画图片提取相近色信息,进行重新组合填入到新压缩文件的相应数据位置;Create an extraction module, which is used to create a new compressed file, extract similar color information from the animated picture, reassemble and fill it into the corresponding data position of the new compressed file;

写入存储模块,用于将自图片头分析挑选出的文件数据写入新压缩文件中,存储动画图片的实体数据。The writing storage module is used for writing the file data selected from the picture header analysis into the new compressed file, and storing the entity data of the animation picture.

本发明的动画图片格式的压缩方法和装置,支持256位色以上的颜色图片,采用相近色图片压缩技术,支持手机中都是16位以上的效果图,PNG序列动画图片压缩率高,在高压缩率的压缩过程中,同系列(相近色)图片越多,压缩率越高,可以达到70%左右,且在压缩过程中不会丢失图像色彩深度。The animation picture format compression method and device of the present invention support color pictures with more than 256-bit color, adopt similar color picture compression technology, and support effect pictures with more than 16-bit in mobile phones. Compression rate During the compression process, the more images in the same series (similar colors), the higher the compression rate, which can reach about 70%, and the image color depth will not be lost during the compression process.

本发明的其它特征和优点将在随后的说明书中阐述,并且,部分地从说明书中变得显而易见,或者通过实施本发明而了解。本发明的目的和其他优点可通过在所写的说明书、权利要求书、以及附图中所特别指出的结构来实现和获得。Additional features and advantages of the invention will be set forth in the description which follows, and in part will be apparent from the description, or may be learned by practice of the invention. The objectives and other advantages of the invention may be realized and attained by the structure particularly pointed out in the written description and claims hereof as well as the appended drawings.

下面通过附图和实施例,对本发明的技术方案做进一步的详细描述。The technical solutions of the present invention will be described in further detail below with reference to the accompanying drawings and embodiments.

附图说明Description of drawings

附图用来提供对本发明的进一步理解,并且构成说明书的一部分,与本发明的实施例一起用于解释本发明,并不构成对本发明的限制。在附图中:The accompanying drawings are used to provide a further understanding of the present invention, and constitute a part of the description, and are used together with the embodiments of the present invention to explain the present invention, and do not constitute a limitation to the present invention. In the attached picture:

图1为现有技术中图片动画包压缩的流程图;Fig. 1 is the flowchart of picture animation package compression in the prior art;

图2为本发明动画图片格式的压缩方法的参考示意图;Fig. 2 is the reference schematic diagram of the compression method of animation picture format of the present invention;

图3为本发明动画图片格式的压缩方法的流程示意图;Fig. 3 is the schematic flow chart of the compression method of animation picture format of the present invention;

图4为本发明PNG文件的结构示意图;Fig. 4 is the structural representation of PNG file of the present invention;

图5为本发明IHDR数据块的结构示意图;Fig. 5 is the structural representation of IHDR data block of the present invention;

图6为本发明动画图片格式的压缩装置的结构示意图。FIG. 6 is a schematic structural diagram of a compression device for an animation picture format according to the present invention.

具体实施方式Detailed ways

下面结合附图,对本发明的具体实施方式进行详细描述,但应当理解本发明的保护范围并不受具体实施方式的限制。The specific embodiments of the present invention will be described in detail below in conjunction with the accompanying drawings, but it should be understood that the protection scope of the present invention is not limited by the specific embodiments.

本发明涉及一种动画图片包的压缩方法,通过改进关键帧格式和图片补偿技术来改进压缩算法。本发明的动画图片格式的压缩方法,参考GIF中的关键帧技术,采用PNG图作为动画的关键帧(相近色)内容,在下一个关键帧(相近色)到来时,使用动画补偿方法进行图片压缩,如图2所示。The invention relates to a compression method of an animation picture package, which improves the compression algorithm by improving the key frame format and picture compensation technology. The animation picture format compression method of the present invention, referring to the key frame technology in GIF, adopts the PNG picture as the key frame (similar color) content of animation, when the next key frame (similar color) arrives, uses the animation compensation method to carry out picture compression ,as shown in picture 2.

本发明的动画图片格式的压缩方法,解决现有GIF图片只支持256色,压缩过程中丢失颜色深度,压缩率不高的缺陷。The animation picture format compression method of the present invention solves the defects that the existing GIF picture only supports 256 colors, the color depth is lost during the compression process, and the compression rate is not high.

本发明的动画图片格式的压缩方法,如图3所示,包括:The compression method of animation picture format of the present invention, as shown in Figure 3, comprises:

步骤202,获取待压缩的PNG动画图片,将每帧PNG动画图片的图片头进行分析挑选处理;Step 202, obtaining the PNG animation picture to be compressed, and analyzing and selecting the picture header of each frame of the PNG animation picture;

具体地,步骤1包括:读取需要压缩的PNG图片文件,删除PNG图片中的可选数据块sBIT、调色板信息pHys/tExt、IDAT数据块和IEND数据块等辅助数据块。Specifically, step 1 includes: reading the PNG image file that needs to be compressed, and deleting auxiliary data blocks such as optional data block sBIT, palette information pHys/tExt, IDAT data block, and IEND data block in the PNG image.

步骤204,创建新压缩文件,自动画图片提取相近色信息,进行重新组合填入到新压缩文件的相应数据位置;Step 204, creating a new compressed file, extracting similar color information from the animated picture, recombining and filling it into the corresponding data position of the new compressed file;

上述创建新压缩文件的步骤包括:利用可变长度编码LZW压缩算法,压缩PNG图片中原始数据的重复部分。The above-mentioned steps of creating a new compressed file include: using the variable length coding LZW compression algorithm to compress the repeated part of the original data in the PNG image.

上述利用可变长度编码LZW压缩算法,压缩PNG图片中原始数据的重复部分的步骤包括:提取原始数据中的不同字符,基于不同字符创建编译表,利用编译表中的字符索引替换原始数据中的相应字符,减少原始数据大小,看起来与调色板图像的实现原理差不多。但是应该注意的是,我们这里的编译表不是事先创建好的,而是根据原始文件数据动态创建的,解码时还要从已编码的数据中还原出原来的编译表。The steps of compressing the repeated part of the original data in the PNG image by using the variable length encoding LZW compression algorithm include: extracting different characters in the original data, creating a compilation table based on different characters, and replacing the characters in the original data with the character index in the compilation table. The corresponding characters, reducing the size of the original data, seem to be similar to the implementation principle of the palette image. But it should be noted that the compilation table here is not created in advance, but is dynamically created according to the original file data, and the original compilation table must be restored from the encoded data when decoding.

1.初始化:将所有的单字符串放入串表1. Initialization: Put all single strings into the string table

2.读第一个输入字符给前缀串ω2. Read the first input character to the prefix string ω

3.Step:读下一个输入字符K3. Step: Read the next input character K

if没有这样的K(输入已穷尽)if no such K (input exhausted)

码字(ω)输出,结束Codeword (ω) output, end

If ωK已存在于串表中If ωK already exists in the string table

ω:=ωK;repeat  Stepω:=ωK; repeat Step

else ωK不在串表中else ωK is not in the list

码字(ω)输出Codeword (ω) output

ωK加进串表ωK is added to the string table

其中ω:=K;repeat  Step.Where ω:=K; repeat Step.

再将数据写入刚创建的文件中。Then write the data to the file you just created.

上述自动画图片提取相近色信息的步骤包括自PNG图片的调色板和图像数据块提取相近色信息:The step of extracting similar color information from the above-mentioned automatic animation picture includes extracting similar color information from the palette and image data blocks of the PNG picture:

遍历PNG图片的色素点,对每个相同色素点进行相似处理,生成数组长度个数为相同色素点个数加1的二维数组;Traverse the pigment points of the PNG image, perform similar processing on each of the same pigment points, and generate a two-dimensional array whose array length is the number of the same pigment points plus 1;

二维数组的第一数组位存放色素RGB值,第二数组位存放色素点的相对位置,也就是色素点相对于本图片的位置信息;同时对每个相同色素点做相似处理,也就是相同颜色的色素点,在生成的二维数组中的RGB是同样的数值。依次生成一个二维数组,组成新的数据块。The first array bit of the two-dimensional array stores the RGB value of the pigment, and the second array bit stores the relative position of the pigment point, that is, the position information of the pigment point relative to the picture; at the same time, similar processing is performed on each of the same pigment points, that is, the same The color of the pigment point, RGB in the generated two-dimensional array is the same value. Generate a two-dimensional array in turn to form a new data block.

步骤206,将自图片头分析挑选出的文件数据写入新压缩文件中,存储动画图片的实体数据。Step 206, write the file data selected from the analysis of the picture header into the new compressed file to store the entity data of the animation picture.

具体地,读取上述步骤204生成的二维数组,将读取颜色和位置信息,填充到刚创建的新压缩文件的相应数据位置。Specifically, read the two-dimensional array generated in step 204 above, and fill the read color and position information into the corresponding data position of the newly created compressed file.

256位色图像需要8位,即一个字节来表示一个像素包含的信息,所包含的数据量即是16色的两倍。A 256-bit color image needs 8 bits, that is, a byte to represent the information contained in a pixel, and the amount of data contained is twice that of 16 colors.

PNG增加一些GIF文件格式所不具备的特性。流式网络图形格式(PortableNetwork Graphic Format,PNG)名称来源于非官方的“PNG's Not GIF”,是一种位图文件(bitmap file)存储格式,读成“ping”。PNG用来存储灰度图像时,灰度图像的深度可多达16位,存储彩色图像时,彩色图像的深度可多达48位,并且还可存储多达16位的α通道数据。使用彩色查找表或者叫做调色板可支持256种颜色的彩色图像。图像文件格式允许连续读出和写入图像数据,这个特性很适合于在通信过程中生成和显示图像。这种特性可使在通信链路上传输图像文件的同时在终端上显示图像,将整个轮廓显示出来之后逐步显示图像的细节,也就是先用低分辨率显示图像,然后逐步提高它的分辨率。该性能可使图像中某些部分不显示出来,用来创建一些有特色的图像。该特性可用来在图像文件中存储一些文本注释信息。PNG adds some features that the GIF file format does not have. The PortableNetwork Graphic Format (PNG) name comes from the unofficial "PNG's Not GIF", which is a bitmap file (bitmap file) storage format, read as "ping". When PNG is used to store grayscale images, the depth of grayscale images can be up to 16 bits. When storing color images, the depth of color images can be up to 48 bits, and it can also store alpha channel data up to 16 bits. Color images with 256 colors are supported using a color lookup table or palette. The image file format allows continuous reading and writing of image data, a feature well suited for generating and displaying images during communication. This feature allows the image to be displayed on the terminal while the image file is being transmitted on the communication link, and the details of the image are gradually displayed after the entire outline is displayed, that is, the image is displayed at a low resolution first, and then its resolution is gradually increased. . This feature can hide certain parts of the image to create some distinctive images. This feature can be used to store some text annotation information in the image file.

使用无损压缩,每个像素为48位的真彩色图像,每个像素为16位的灰度图像,可为灰度图和真彩色图添加α通道。添加图像的γ信息。使用循环冗余码(cyclic redundancy code,CRC)检测损坏的文件。加快图像显示的逐次逼近显示方式。Using lossless compression, each pixel is a 48-bit true color image, each pixel is a 16-bit grayscale image, and an alpha channel can be added to grayscale and true color images. Add gamma information to the image. Use cyclic redundancy code (CRC) to detect corrupted files. A successive approximation display method that speeds up image display.

我们采用PNG格式图片,支持256位色以上的图片。We use PNG format images and support images with more than 256-bit colors.

色彩深度计算机图形学领域表示在位图或者视频帧缓冲区中储存1像素的颜色所用的位数,它也称为位/像素(bpp)。色彩深度越高,可用的颜色就越多。Color depth in the field of computer graphics represents the number of bits used to store 1 pixel of color in a bitmap or video frame buffer, also known as bits per pixel (bpp). The higher the color depth, the more colors are available.

色彩深度是用“n位颜色”(n-bit colour)来说明的。若色彩深度是n位,即有2n种颜色选择,而储存每像素所用的位数就是n。常见的有:Color depth is described by "n-bit color". If the color depth is n bits, there are 2n colors to choose from, and the number of bits used to store each pixel is n. The common ones are:

1位:2种颜色,单色光,黑白二色,用于compact Macintoshes。1 bit: 2 colors, monochromatic light, black and white, for compact Macintoshes.

2位:4种颜色,CGA,用于gray-scale早期的NeXTstation及colorMacintoshes。2 bits: 4 colors, CGA, for gray-scale early NeXTstation and colorMacintoshes.

3位:8种颜色,用于大部分早期的电脑显示器。3 bits: 8 colors, used in most early computer monitors.

4位:16种颜色,用于EGA及不常见及在更高的分辨率的VGA标准。4-bit: 16 colors for EGA and the less common VGA standard at higher resolutions.

5位:32种颜色,用于Original Amiga chipset。5 bits: 32 colors for Original Amiga chipset.

6位:64种颜色,用于Original Amiga chipset。6 bits: 64 colors for Original Amiga chipset.

8位:256种颜色,用于最早期的彩色Unix工作站,低分辨率的VGA,Super VGA,AGA,color Macintoshes。灰阶,有256种灰色(包括黑白)。若以24位模式来表示,则RGB的数值均一样,例如(200,200,200)。8-bit: 256 colors, used in the earliest color Unix workstations, low-resolution VGA, Super VGA, AGA, color Macintoshes. Gray scale, there are 256 kinds of gray (including black and white). If expressed in 24-bit mode, the values of RGB are the same, for example (200,200,200).

12位:4,096种颜色,用于部分硅谷图形系统,Neo Geo,彩色NeXTstation及Amiga系统于HAM mode。12-bit: 4,096 colors, used in some Silicon Valley graphics systems, Neo Geo, color NeXTstation and Amiga systems in HAM mode.

16位:65,536种颜色,用于部分color Macintoshes。16-bit: 65,536 colors, used on some color Macintoshes.

24位:16,777,216种颜色,真彩色,能提供比肉眼能识别更多的颜色,用于拍摄照片。24-bit: 16,777,216 colors, true color, can provide more colors than the naked eye can recognize, for taking photos.

另外有高动态范围影像(High Dynamic Range Image),这种影像使用超过一般的256色阶来储存影像,通常来说每个像素会分配到32+32+32个bit来储存颜色信息,也就是说对于每一个原色都使用一个32bit的浮点数来储存。In addition, there is a high dynamic range image (High Dynamic Range Image), which uses more than the general 256 color levels to store the image. Generally speaking, each pixel will be allocated 32+32+32 bits to store color information, that is, It is said that a 32bit floating point number is used to store each primary color.

图像色彩深度在图片存储的关键数据块中(文件头数据块),我们予以保留,不会丢失图像色彩深度。The image color depth is stored in the key data block (file header data block) of the image storage, we will keep it, and the image color depth will not be lost.

我们将每张图片的文件头进行读取后,对文件体的内容进行重新排序读取文件实体写入新创建的压缩文件中,压缩后的三张文件存储块如表2显示:After reading the file header of each picture, we reorder the content of the file body, read the file entity and write it into the newly created compressed file. The compressed three file storage blocks are shown in Table 2:

表2Table 2

现对上述步骤202和204进行重点说明和分析:Now the above-mentioned steps 202 and 204 are mainly explained and analyzed:

通过对PNG的文件头的索引,来压缩合并动画中的数据源,对于一个PNG文件来说,其文件头总是由位固定的字节来描述的,如表3所示。The data source in the animation is compressed and merged by indexing the PNG file header. For a PNG file, its file header is always described by fixed-bit bytes, as shown in Table 3.

表3table 3

十进制数Decimal1378078711310261013780787113102610十六进制数hexadecimal number89504E470D0A1A0A89504E470D0A1A0A

表3中,第一个字节0x89超出了ASCII字符的范围,这是为了避免某些软件将PNG文件当作文本文件来处理。文件中剩余的部分由3个以上的PNG的数据块(Chunk)按照特定的顺序组成。因此,一个标准的PNG文件结构如表4所示。In Table 3, the first byte 0x89 is beyond the range of ASCII characters, which is to prevent some software from treating PNG files as text files. The remaining part of the file consists of more than 3 PNG data blocks (Chunk) in a specific order. Therefore, a standard PNG file structure is shown in Table 4.

表4Table 4

PNG文件标志PNG file logoPNG数据块PNG chunk……...PNG数据块PNG chunk

PNG数据块(Chunk)PNG data block (Chunk)

PNG定义了两种类型的数据块,一种称为关键数据块(critical chunk),其为标准的数据块。另一种称为辅助数据块(ancillary chunks),其为可选的数据块。关键数据块定义了4个标准数据块,每个PNG文件都必须包含它们,PNG读写软件也都要支持这些数据块。虽然PNG文件规范没有要求PNG编译码器对可选数据块进行编码和译码,但PNG文件规范提倡支持可选数据块。PNG defines two types of data blocks, one is called critical chunk, which is a standard data block. The other is called ancillary chunks, which are optional data chunks. Key data blocks define 4 standard data blocks, each PNG file must contain them, PNG reading and writing software must also support these data blocks. Although the PNG file specification does not require PNG codecs to encode and decode optional data chunks, the PNG file specification advocates support for optional data chunks.

表5为PNG中数据块的类别,其中,符号为IHDR、PLTE、IDAT、IEND的数据块为关键数据块。Table 5 shows the categories of data blocks in PNG, where the data blocks whose symbols are IHDR, PLTE, IDAT, and IEND are key data blocks.

表5table 5

为了简单起见,我们假设在我们使用的PNG文件中,上述4个关键数据块按上述先后顺序进行存储,并且都只出现一次。For the sake of simplicity, we assume that in the PNG file we use, the above four key data blocks are stored in the above sequence, and all appear only once.

数据块结构data block structure

如表6所示,PNG文件中,每个数据块由4个部分组成。As shown in Table 6, in the PNG file, each data block consists of 4 parts.

表6Table 6

CRC(cyclic redundancy check)域中的值是对Chunk Type Code域和ChunkData域中的数据计算得到。CRC具体算法定义在ISO3309和ITU-T V.42中,其值按下面的CRC码生成多项式进行计算:The value in the CRC (cyclic redundancy check) field is calculated from the data in the Chunk Type Code field and the ChunkData field. The specific algorithm of CRC is defined in ISO3309 and ITU-T V.42, and its value is calculated according to the following CRC code generator polynomial:

x32+x26+x23+x22+x16+x12+x11+x10+x8+x7+x5+x4+x2+x+1x32+x26+x23+x22+x16+x12+x11+x10+x8+x7+x5+x4+x2+x+1

下面,我们依次来介绍一下各关键数据块的结构。Next, let's introduce the structure of each key data block in turn.

IHDRIHDR

文件头数据块IHDR(header chunk):它包含PNG文件中存储的图像数据的基本信息,并要作为第一个数据块出现在PNG数据流中,而且一个PNG数据流中只能有一个文件头数据块。File header data block IHDR (header chunk): It contains the basic information of the image data stored in the PNG file, and should appear in the PNG data stream as the first data block, and there can only be one file header in a PNG data stream data block.

文件头数据块由13字节组成,它的格式如表7所示。The file header data block consists of 13 bytes, and its format is shown in Table 7.

表7Table 7

由于我们研究的是手机上的PNG,因此,首先我们看看Android对所使用PNG图片的要求:Since we are studying PNG on mobile phones, first let's look at Android's requirements for the PNG images used:

在Android中,我们仅可以使用1.0版本的PNG图片。并且,PNG的关键数据块都有特别要求:In Android, we can only use version 1.0 PNG images. Moreover, the key data blocks of PNG have special requirements:

IHDR文件大小:Android支持任意大小的PNG图片,然而,如果一个图片过大,会由于内存耗尽而无法读取。IHDR file size: Android supports PNG images of any size, however, if an image is too large, it will fail to read due to memory exhaustion.

颜色类型:所有颜色类型都被支持,虽然这些颜色的显示依赖于实际设备的显示能力。同时,Android也能支持alpha通道,但是,所有的alpha通道信息都会被忽略并且当作不透明的颜色对待。Color Type: All color types are supported, although the display of these colors depends on the display capabilities of the actual device. At the same time, Android can also support alpha channels, however, all alpha channel information will be ignored and treated as opaque colors.

色深:所有的色深都能被支持。Color depth: All color depths are supported.

压缩方法:仅支持压缩方式0(deflate压缩方式),这与apk文件的压缩方式完全相同。所以,PNG图片数据的解压和apk文件的解压可以使用相同的代码。这也是Android能很好的支持PNG图像的原因。Compression method: Only compression method 0 (deflate compression method) is supported, which is exactly the same as the compression method of apk files. Therefore, the decompression of the PNG image data and the decompression of the apk file can use the same code. This is why Android can support PNG images very well.

滤波器方法:虽然在PNG的白皮书中仅定义了方法0,但所有的5种方法都被支持。Filter method: Although only method 0 is defined in the PNG white paper, all 5 methods are supported.

隔行扫描:虽然Android支持0、1两种方式,然而,当使用隔行扫描时,Android却不会真正的使用隔行扫描方式来显示。Interlaced scanning: Although Android supports two methods of 0 and 1, however, when using interlaced scanning, Android will not really use the interlaced scanning method to display.

PLTE chunk:支持PLTE chunk: support

IDAT chunk:图像信息必须使用5种过滤方式中的方式0(None、Sub、Up、Average、Paeth)IDAT chunk: Image information must use method 0 (None, Sub, Up, Average, Paeth) among the five filtering methods

IEND chunk:当IEND数据块被找到时,该PNG图像才认为是合法的PNG图像。IEND chunk: When the IEND data chunk is found, the PNG image is considered to be a legal PNG image.

可选数据块:Android可以支持下列辅助数据块,但不是必须的:Optional Data Blocks: Android MAY support the following auxiliary data blocks, but is not required:

bKGD cHRM gAMA hIST iCCP iTXt pHYsbKGD cHRM gAMA hIST iCCP iTXt pHYs

sBIT sPLT sRGB tEXt tIME tRNS zTXtsBIT sPLT sRGB tEXt tIME tRNS zTXt

PLTEPLTE

调色板数据块PLTE(palette chunk)包含有与索引彩色图像(indexed-colorimage)相关的彩色变换数据,它仅与索引彩色图像有关,而且要放在图像数据块(image data chunk)之前。The palette data block PLTE (palette chunk) contains the color transformation data related to the indexed color image (indexed-color image), it is only related to the indexed color image, and it should be placed before the image data chunk (image data chunk).

PLTE数据块是定义图像的调色板信息,PLTE可以包含1-256个调色板信息,每一个调色板信息由表8的3个字节组成:The PLTE data block is the palette information that defines the image. PLTE can contain 1-256 palette information, and each palette information consists of 3 bytes in Table 8:

表8Table 8

颜色color字节byte意义significanceRedRed1byte1byte0=黑色,255=红0=black, 255=redGreenGreen1byte1byte0=黑色,255=绿色0=black, 255=greenBlueBlue1byte1byte0=黑色,255=蓝色0=black, 255=blue

因此,调色板的长度应该是3的倍数,否则,这将是一个非法的调色板。Therefore, the length of the palette should be a multiple of 3, otherwise, it will be an illegal palette.

对于索引图像,调色板信息是必需的,调色板的颜色索引从0开始编号,然后是1、2……,调色板的颜色数不能超过色深中规定的颜色数。如图像色深为4的时候,调色板中的颜色数不可以超过2^4=16。否则,这将导致PNG图像不合法。For indexed images, palette information is required. The color index of the palette starts from 0, then 1, 2..., and the number of colors in the palette cannot exceed the number of colors specified in the color depth. For example, when the color depth of the image is 4, the number of colors in the palette cannot exceed 2^4=16. Otherwise, this would make the PNG image illegal.

真彩色图像和带α通道数据的真彩色图像也可以有调色板数据块,目的是便于非真彩色显示程序用调色板来量化图像数据,从而显示该图像。True color images and true color images with α channel data can also have a palette data block, the purpose is to facilitate the non-true color display program to use the palette to quantize the image data, so as to display the image.

IDATIDAT

图像数据块IDAT(image data chunk):它存储实际的数据,在数据流中可包含多个连续顺序的图像数据块。Image data block IDAT (image data chunk): It stores actual data, and can contain multiple sequential image data blocks in the data stream.

由于IDAT存储图像的真正数据信息,因此,如果能够了解IDAT的结构,我们就可以很方便的生成PNG图像。Since IDAT stores the real data information of the image, if we can understand the structure of IDAT, we can easily generate PNG images.

IENDIEND

图像结束数据IEND(image trailer chunk):它用来标记PNG文件或者数据流已经结束,并且要放在文件的尾部。Image end data IEND (image trailer chunk): It is used to mark the end of the PNG file or data stream, and it should be placed at the end of the file.

如果我们仔细观察PNG文件,我们会发现,文件的结尾12个字符看起来应该如下:If we look closely at the PNG file, we can see that the last 12 characters of the file should look like this:

00 00 00 00 49 45 4E 44 AE 42 60 8200 00 00 00 49 45 4E 44 AE 42 60 82

由于数据块结构的定义,IEND数据块的长度总是0(00 00 00 00,除非人为加入信息),数据标识总是IEND(49 45 4E 44)。因此,CRC码也总是AE 42 60 82。Due to the definition of the data block structure, the length of the IEND data block is always 0 (00 00 00 00, unless information is artificially added), and the data identifier is always IEND (49 45 4E 44). Therefore, the CRC code is also always AE 42 60 82.

研究PNGResearch PNG

以下是由Fireworks生成的一幅图像,图像大小为8*8,使用UltraEdit32打开该文件,如下:00000000-00000007。The following is an image generated by Fireworks, the image size is 8*8, use UltraEdit32 to open the file, as follows: 00000000-00000007.

如图4所示,可以看到,图4中选中的头8个字节即为PNG文件的标识。As shown in Figure 4, it can be seen that the first 8 bytes selected in Figure 4 are the identifier of the PNG file.

接下来的字节就是IHDR数据块:00000008-00000020;The next byte is the IHDR data block: 00000008-00000020;

如图5所示,00 00 00 0D说明IHDR头块长为13;As shown in Figure 5, 00 00 00 0D indicates that the IHDR header block length is 13;

49 48 44 52为IHDR标识;49 48 44 52 is the IHDR logo;

00 00 00 08表示图像的宽,为8像素;00 00 00 08 indicates the width of the image, which is 8 pixels;

00 00 00 08表示图像的高,为8像素;00 00 00 08 indicates the height of the image, which is 8 pixels;

04表示色深,2^4=16,即这是一个16色的图像,也有可能颜色数不超过16。如果颜色数不超过8,用03表示更合适。04 means color depth, 2^4=16, that is, this is a 16-color image, and it is possible that the number of colors does not exceed 16. If the number of colors does not exceed 8, it is more appropriate to use 03.

03表示颜色类型,为索引图像;03 indicates the color type, which is an index image;

00PNG Spec规定此处总为0,非0值为将来使用更好的压缩方法预留,表示使用压缩方法(例如LZ77派生算法)。00PNG Spec stipulates that this is always 0, and the non-zero value is reserved for better compression methods in the future, indicating that the compression method (such as the LZ77 derivative algorithm) is used.

00同上00 ditto

00表示非隔行扫描00 means non-interlaced scanning

36 21 A3 B8表示CRC校验36 21 A3 B8 means CRC check

00000021-0000002F:00000021-0000002F:

可选数据块sBIT,颜色采样率,RGB都是256(2^8=256):Optional data block sBIT, color sampling rate, RGB is 256 (2^8=256):

00000030-00000062:00000030-00000062:

调色板信息:Palette information:

00 00 00 27说明调色板数据长为39字节,即13个颜色数00 00 00 27 indicates that the palette data is 39 bytes long, that is, 13 colors

50 4C 54 45 PLTE标识50 4C 54 45 PLTE logo

FF FF 00表示颜色为0FF FF 00 means the color is 0

FF ED 00表示颜色为1FF ED 00 means the color is 1

……………………

09 00 B2最后一个颜色为1209 00 B2 last color is 12

5F F5 BB DD CRC校验5F F5 BB DD CRC check

00000063-000000C5:00000063-000000C5:

本部分包含了pHYs、tExt两种类型的数据块共3块,由于并不太重要,因此也不再详细描述。This part contains two types of data blocks, pHYs and tExt, and there are 3 blocks in total. Since they are not too important, they will not be described in detail.

000000C0-000000F8:000000C0-000000F8:

以上选中部分是IDAT数据块。The selected part above is the IDAT data block.

其中,00 00 00 27数据长为39字节Among them, 00 00 00 27 data length is 39 bytes

49 44 41 54 为IDAT标识49 44 41 54 is the IDAT logo

78 9C……为采用LZ77派生压缩方法压缩的数据78 9C...for data compressed using LZ77-derived compression methods

DA 12 06 A5为CRC校验DA 12 06 A5 is CRC check

IDAT中压缩数据部分将在后面详细介绍。The compressed data part of IDAT will be introduced in detail later.

000000F9-00000104:000000F9-00000104:

IEND数据块,这部分如上述所示,通常都应该是:IEND data block, this part is shown above, usually it should be:

00 00 00 00 49 45 4E 44 AE 42 60 8200 00 00 00 49 45 4E 44 AE 42 60 82

至此,我们已经能够从一个PNG文件中识别出各个数据块。由于PNG中规定除关键数据块外,其它的辅助数据块都为可选部分。因此,有了这个标准后,我们可以通过删除所有的辅助数据块来减少PNG文件的大小。当然,需要注意的是,PNG格式可以保存图像中的层、文字等信息,一旦删除了这些辅助数据块后,图像将失去原来的可编辑性。So far, we have been able to identify individual data blocks from a PNG file. Since it is stipulated in PNG that except for the key data block, other auxiliary data blocks are all optional parts. So, with this standard in place, we can reduce PNG file size by removing all ancillary chunks. Of course, it should be noted that the PNG format can save information such as layers and text in the image. Once these auxiliary data blocks are deleted, the image will lose its original editability.

删除了辅助数据块后的PNG文件,现在文件大小为147字节,原文件大小为261字节,文件大小减少后,并不影响图像的内容。The PNG file after the auxiliary data block is deleted, the file size is now 147 bytes, and the original file size is 261 bytes. After the file size is reduced, the content of the image will not be affected.

本发明的动画图片格式的压缩方法,支持256位色以上的颜色图片,采用相近色图片压缩技术,支持手机中都是16位以上的效果图,PNG序列动画图片压缩率高,在高压缩率的压缩过程中,同系列(相近色)图片越多,压缩率越高,可以达到70%左右,且在压缩过程中不会丢失图像色彩深度。The compression method of the animation picture format of the present invention supports color pictures with more than 256-bit color, adopts similar color picture compression technology, supports effect pictures with more than 16 bits in mobile phones, and has a high compression rate of PNG sequence animation pictures. During the compression process, the more images in the same series (similar colors), the higher the compression rate, which can reach about 70%, and the image color depth will not be lost during the compression process.

如图6所示,本发明公开了一种动画图片格式的压缩装置,包括:As shown in Fig. 6, the present invention discloses a compression device of animation picture format, comprising:

分析处理模块10,用于获取待压缩的动画图片,将每帧动画图片的图片头进行分析挑选处理;The analysis processing module 10 is used to obtain the animated picture to be compressed, and the picture header of each frame of animated picture is analyzed and selected;

创建提取模块20,用于创建新压缩文件,自动画图片提取相近色信息,进行重新组合填入到新压缩文件的相应数据位置;Create and extract module 20, be used for creating new compressed file, automatically draw pictures and extract similar color information, carry out recombination and fill in the corresponding data position of new compressed file;

写入存储模块30,用于将自图片头分析挑选出的文件数据写入新压缩文件中,存储动画图片的实体数据。The writing storage module 30 is used to write the file data selected from the analysis of the picture header into the new compressed file, and store the entity data of the animation picture.

其中:动画图片为PNG图片格式。Among them: the animation picture is in PNG picture format.

其中:分析处理模块10包括:Wherein: analysis processing module 10 comprises:

读取子模块11,用于读取需要压缩的PNG图片文件;Read submodule 11, for reading the PNG image file that needs to be compressed;

删除子模块12,用于删除PNG图片中的可选数据块sBIT、调色板信息pHys/tExt、IDAT数据块和IEND数据块。The deletion sub-module 12 is used to delete the optional data block sBIT, palette information pHys/tExt, IDAT data block and IEND data block in the PNG picture.

其中:创建提取模块20包括:Wherein: create extraction module 20 and include:

压缩子模块21,用于利用可变长度编码LZW压缩算法,压缩PNG图片中原始数据的重复部分。The compression sub-module 21 is used to compress the repeated part of the original data in the PNG picture by using the variable length coding LZW compression algorithm.

其中:压缩子模块21,具体用于提取原始数据中的不同字符,基于不同字符创建编译表,利用编译表中的字符索引替换原始数据中的相应字符。Wherein: the compression sub-module 21 is specifically used to extract different characters in the original data, create a compilation table based on the different characters, and use the character index in the compilation table to replace the corresponding characters in the original data.

其中:创建提取模块20包括:Wherein: create extraction module 20 and include:

自PNG图片的调色板和图像数据块提取相近色信息的提取子模块22,用于遍历PNG图片的色度点,对每个相同色素点进行相似处理,生成数组长度个数为相同色素点个数加1的二维数组;The extraction sub-module 22 for extracting similar color information from the palette of the PNG image and the image data block is used to traverse the chromaticity points of the PNG image, perform similar processing on each identical pigment point, and generate an array length of the same pigment point A two-dimensional array with the number plus 1;

二维数组的第一数组位存放色素RGB值,后续数组位存放相对位置的色素点。The first array bit of the two-dimensional array stores the RGB value of the pigment, and the subsequent array bits store the relative position of the pigment point.

本发明的动画图片格式的压缩装置,支持256位色以上的颜色图片,采用相近色图片压缩技术,支持手机中都是16位以上的效果图,PNG序列动画图片压缩率高,在高压缩率的压缩过程中,同系列(相近色)图片越多,压缩率越高,可以达到70%左右,且在压缩过程中不会丢失图像色彩深度。The compression device of the animation picture format of the present invention supports color pictures with more than 256-bit color, adopts similar color picture compression technology, supports effect pictures with more than 16-bit in mobile phones, and has a high compression rate of PNG sequence animation pictures. During the compression process, the more images in the same series (similar colors), the higher the compression rate, which can reach about 70%, and the image color depth will not be lost during the compression process.

本发明能有多种不同形式的具体实施方式,上面以图2-图6为例结合附图对本发明的技术方案作举例说明,这并不意味着本发明所应用的具体实例只能局限在特定的流程或实施例结构中,本领域的普通技术人员应当了解,上文所提供的具体实施方案只是多种优选用法中的一些示例,任何体现本发明权利要求的实施方式均应在本发明技术方案所要求保护的范围之内。The present invention can have multiple specific implementations in different forms. Above, the technical solutions of the present invention are illustrated by taking Fig. 2-Fig. 6 as an example in conjunction with the accompanying drawings. In the specific process or embodiment structure, those of ordinary skill in the art should understand that the specific implementations provided above are only some examples of various preferred usages, and any implementation that embodies the claims of the present invention shall be included in the present invention. Within the scope of protection required by the technical solution.

最后应说明的是:以上所述仅为本发明的优选实施例而已,并不用于限制本发明,尽管参照前述实施例对本发明进行了详细的说明,对于本领域的技术人员来说,其依然可以对前述各实施例所记载的技术方案进行修改,或者对其中部分技术特征进行等同替换。凡在本发明的精神和原则之内,所作的任何修改、等同替换、改进等,均应包含在本发明的保护范围之内。Finally, it should be noted that: the above is only a preferred embodiment of the present invention, and is not intended to limit the present invention. Although the present invention has been described in detail with reference to the foregoing embodiments, for those skilled in the art, it still The technical solutions recorded in the foregoing embodiments may be modified, or some technical features thereof may be equivalently replaced. Any modifications, equivalent replacements, improvements, etc. made within the spirit and principles of the present invention shall be included within the protection scope of the present invention.

Claims (12)

CN201310162376.8A2013-05-062013-05-06 Compression method and device for animation picture formatPendingCN104142924A (en)

Priority Applications (1)

Application NumberPriority DateFiling DateTitle
CN201310162376.8ACN104142924A (en)2013-05-062013-05-06 Compression method and device for animation picture format

Applications Claiming Priority (1)

Application NumberPriority DateFiling DateTitle
CN201310162376.8ACN104142924A (en)2013-05-062013-05-06 Compression method and device for animation picture format

Publications (1)

Publication NumberPublication Date
CN104142924Atrue CN104142924A (en)2014-11-12

Family

ID=51852099

Family Applications (1)

Application NumberTitlePriority DateFiling Date
CN201310162376.8APendingCN104142924A (en)2013-05-062013-05-06 Compression method and device for animation picture format

Country Status (1)

CountryLink
CN (1)CN104142924A (en)

Cited By (14)

* Cited by examiner, † Cited by third party
Publication numberPriority datePublication dateAssigneeTitle
CN105721810A (en)*2014-12-052016-06-29北大方正集团有限公司Image compression storage method and apparatus
CN105719223A (en)*2014-12-052016-06-29北大方正集团有限公司Batch image encryption method, decryption method and system
CN105808567A (en)*2014-12-302016-07-27航天信息股份有限公司Method and device for reducing sizes of PNG pictures
CN107682016A (en)*2017-09-262018-02-09深信服科技股份有限公司A kind of data compression method, data decompression method and related system
CN108111858A (en)*2016-11-242018-06-01腾讯科技(深圳)有限公司A kind of picture compression method and device
CN108259041A (en)*2017-12-292018-07-06中国电子科技集团公司第二十研究所A kind of Big Dipper data expansion method based on modified LZW Coding Compression Technologies
CN109993817A (en)*2017-12-282019-07-09腾讯科技(深圳)有限公司A kind of implementation method and terminal of animation
CN110060310A (en)*2019-01-302019-07-26阿里巴巴集团控股有限公司File compression method, device and equipment
CN110309654A (en)*2019-06-282019-10-08四川长虹电器股份有限公司The safety detection method and device that picture uploads
CN113223100A (en)*2021-05-072021-08-06深圳市中科世为科技有限公司Picture compression and decompression processing method
CN113473150A (en)*2021-07-082021-10-01浙江大华技术股份有限公司Image processing method and device and computer readable storage device
CN113538208A (en)*2020-04-202021-10-22华为技术有限公司Picture loading method and related device
CN113971702A (en)*2021-10-292022-01-25深圳市道通科技股份有限公司 A kind of picture compression method, decompression method and electronic device
CN114445264A (en)*2022-01-252022-05-06上海秉匠信息科技有限公司Texture compression method and device, electronic equipment and computer readable storage medium

Citations (3)

* Cited by examiner, † Cited by third party
Publication numberPriority datePublication dateAssigneeTitle
CN1447283A (en)*2002-03-272003-10-08天瀚科技股份有限公司Method for compressing image by using color classification
CN1696977A (en)*2005-05-262005-11-16无敌科技(西安)有限公司Method for compressing image
CN101031085A (en)*2007-03-302007-09-05中国联合通信有限公司Method for processing mobile-terminal frame carboon

Patent Citations (3)

* Cited by examiner, † Cited by third party
Publication numberPriority datePublication dateAssigneeTitle
CN1447283A (en)*2002-03-272003-10-08天瀚科技股份有限公司Method for compressing image by using color classification
CN1696977A (en)*2005-05-262005-11-16无敌科技(西安)有限公司Method for compressing image
CN101031085A (en)*2007-03-302007-09-05中国联合通信有限公司Method for processing mobile-terminal frame carboon

Non-Patent Citations (1)

* Cited by examiner, † Cited by third party
Title
冯长宝: "《一种基于J2ME平台的PNG图像压缩方法》", 《2010国际数字科技博物馆学术论坛暨第二届数字科技馆技术与应用研讨会论文集》*

Cited By (23)

* Cited by examiner, † Cited by third party
Publication numberPriority datePublication dateAssigneeTitle
CN105719223A (en)*2014-12-052016-06-29北大方正集团有限公司Batch image encryption method, decryption method and system
CN105721810A (en)*2014-12-052016-06-29北大方正集团有限公司Image compression storage method and apparatus
CN105721810B (en)*2014-12-052019-06-04北大方正集团有限公司 A kind of image compression storage method and device
CN105719223B (en)*2014-12-052020-01-17北大方正集团有限公司 A batch image encryption method, decryption method and system
CN105808567A (en)*2014-12-302016-07-27航天信息股份有限公司Method and device for reducing sizes of PNG pictures
CN105808567B (en)*2014-12-302021-02-05航天信息股份有限公司Method and device for reducing size of PNG (portable network graphics) picture
CN108111858B (en)*2016-11-242020-06-05腾讯科技(深圳)有限公司Picture compression method and device
CN108111858A (en)*2016-11-242018-06-01腾讯科技(深圳)有限公司A kind of picture compression method and device
CN107682016A (en)*2017-09-262018-02-09深信服科技股份有限公司A kind of data compression method, data decompression method and related system
CN109993817A (en)*2017-12-282019-07-09腾讯科技(深圳)有限公司A kind of implementation method and terminal of animation
CN109993817B (en)*2017-12-282022-09-20腾讯科技(深圳)有限公司Animation realization method and terminal
CN108259041A (en)*2017-12-292018-07-06中国电子科技集团公司第二十研究所A kind of Big Dipper data expansion method based on modified LZW Coding Compression Technologies
CN110060310A (en)*2019-01-302019-07-26阿里巴巴集团控股有限公司File compression method, device and equipment
CN110060310B (en)*2019-01-302023-10-20创新先进技术有限公司File compression method, device and equipment
CN110309654A (en)*2019-06-282019-10-08四川长虹电器股份有限公司The safety detection method and device that picture uploads
CN113538208A (en)*2020-04-202021-10-22华为技术有限公司Picture loading method and related device
WO2021213351A1 (en)*2020-04-202021-10-28华为技术有限公司Picture loading method and related apparatus
US12282980B2 (en)2020-04-202025-04-22Huawei Technologies Co., Ltd.Picture loading method and related apparatus
CN113223100A (en)*2021-05-072021-08-06深圳市中科世为科技有限公司Picture compression and decompression processing method
CN113223100B (en)*2021-05-072024-09-13深圳市中科世为科技有限公司Picture compression and decompression processing method
CN113473150A (en)*2021-07-082021-10-01浙江大华技术股份有限公司Image processing method and device and computer readable storage device
CN113971702A (en)*2021-10-292022-01-25深圳市道通科技股份有限公司 A kind of picture compression method, decompression method and electronic device
CN114445264A (en)*2022-01-252022-05-06上海秉匠信息科技有限公司Texture compression method and device, electronic equipment and computer readable storage medium

Similar Documents

PublicationPublication DateTitle
CN104142924A (en) Compression method and device for animation picture format
CN107071514B (en) Image file processing method and intelligent terminal
US7415154B2 (en)Compression of palettized color images with variable length color codes
JP6703032B2 (en) Backward compatibility extended image format
US20090010533A1 (en)Method and apparatus for displaying an encoded image
CN105933708B (en)A kind of method and apparatus of data compression and decompression
CN102244784B (en)Method for compressing and displaying picture including transparent information
CN102088604A (en)Method and device for compressing film thumbnails
US9807402B2 (en)Method of color palette coding applicable to electronic device and electronic device using the same
US10440360B2 (en)Video processing system
KR20200038171A (en)Methods of variable rate compression and decompression of image data in image pipeline of graphics processing system
KR102194615B1 (en)Tile-based compression and decompression for graphic applications
CN110971904B (en)Control method for image compression
US11263786B2 (en)Decoding data arrays
CN112118449B (en)Method and device for compressing and decompressing image
JP3462867B2 (en) Image compression method and apparatus, image compression program, and image processing apparatus
KR20050113500A (en)Compression and decompression device of graphic data and therefor method
CN104093027B (en)Joint scalar embedded graphics coding for coloured image
CN114189687B (en) Display screen overdrive controller
TW202240398A (en)Accessing encoded blocks of data
CN101459854A (en)Encoding/decoding apparatus for picture compression and encoding/decoding method therefor
CN110572664A (en) A New BMP Image Compression Method and System
KR100852958B1 (en) Display driver device using subpixel rendering and data compression and its control method
KR101844971B1 (en)Image encoding method based on pixels and image decoding method based on pixels
CN114387356B (en) A PNG format encoding and decoding method and device

Legal Events

DateCodeTitleDescription
C06Publication
PB01Publication
C10Entry into substantive examination
SE01Entry into force of request for substantive examination
RJ01Rejection of invention patent application after publication
RJ01Rejection of invention patent application after publication

Application publication date:20141112


[8]ページ先頭

©2009-2025 Movatter.jp