CN103903285B - Thumbnail extraction method of PNG image and BMP image - Google Patents

Thumbnail extraction method of PNG image and BMP image Download PDF

Info

Publication number
CN103903285B
CN103903285B CN201210572320.5A CN201210572320A CN103903285B CN 103903285 B CN103903285 B CN 103903285B CN 201210572320 A CN201210572320 A CN 201210572320A CN 103903285 B CN103903285 B CN 103903285B
Authority
CN
China
Prior art keywords
row
pixel values
image
decoding
color mixing
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.)
Active
Application number
CN201210572320.5A
Other languages
Chinese (zh)
Other versions
CN103903285A (en
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.)
Samsung Electronics China R&D Center
Samsung Electronics Co Ltd
Original Assignee
Samsung Electronics China R&D Center
Samsung Electronics 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 Samsung Electronics China R&D Center, Samsung Electronics Co Ltd filed Critical Samsung Electronics China R&D Center
Priority to CN201210572320.5A priority Critical patent/CN103903285B/en
Publication of CN103903285A publication Critical patent/CN103903285A/en
Application granted granted Critical
Publication of CN103903285B publication Critical patent/CN103903285B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Landscapes

  • Color Image Communication Systems (AREA)
  • Editing Of Facsimile Originals (AREA)

Abstract

一种PNG图像和BMP图像的缩略图提取方法。本申请公开了一种PNG图像的缩略图提取方法,包括:对于非交织的PNG图像,开辟2行像素所占用空间大小的缓冲,用于存储当前行及其上一行的解码前像素值;对所述PNG图像从第一行开始逐行进行解码处理,并对每行的解码后重建像素值进行下采样得到目标缩略图的对应行像素值;其中,在所述逐行进行解码处理时,对除第一行之外的当前行解码完成后,将所述上一行的解码前像素值移出所述缓冲,再将下一行的解码前像素值写入所述缓冲,并将下一行作为当前行进行解码。应用本申请,能够节省系统的内存开销。

A method for extracting thumbnails of PNG images and BMP images. The present application discloses a method for extracting a thumbnail image of a PNG image, comprising: for a non-interlaced PNG image, opening up a buffer of the size of the space occupied by two rows of pixels for storing the pixel values of the current row and the previous row before decoding; The PNG image is decoded row by row starting from the first row, and downsamples the decoded reconstructed pixel values of each row to obtain the corresponding row pixel values of the target thumbnail; wherein, when the row-by-row decoding is performed, After the decoding of the current line except the first line is completed, the pixel values of the previous line before decoding are moved out of the buffer, and then the pixel values of the next line before decoding are written into the buffer, and the next line is used as the current line line to decode. By applying this application, the memory overhead of the system can be saved.

Description

一种PNG图像和BMP图像的缩略图提取方法A Method for Extracting Thumbnails of PNG Images and BMP Images

技术领域technical field

本申请涉及图像处理技术,特别涉及一种BMP图像的缩略图提取方法。The present application relates to image processing technology, in particular to a method for extracting thumbnails of BMP images.

背景技术Background technique

个人计算机可以访问存储在自身硬盘、其他外接设备、网络上的多媒体文件(视频,音乐,图片等),并为用户提供了浏览这些文件概貌的缩略图预览功能。在数字电视、手机等基于嵌入式系统的显示设备上,也拥有同样的预览功能。其中,预览图片能够向用户提供直观的图片内容概貌,具有很高的实用价值。A personal computer can access multimedia files (video, music, pictures, etc.) stored on its own hard disk, other external devices, and the network, and provide users with a thumbnail preview function for browsing the overview of these files. Display devices based on embedded systems such as digital TVs and mobile phones also have the same preview function. Wherein, the preview picture can provide the user with an intuitive overview of the content of the picture, and has high practical value.

由于图像文件较小,存储介质可以存储大量的图像文件。这就要求显示设备可以快速的处理原图像以生成缩略图信息,并快速的显示缩略图。Since the image files are small, the storage medium can store a large number of image files. This requires that the display device can quickly process the original image to generate thumbnail information, and quickly display the thumbnail.

当前对于图像文件的缩略图获取,现有方法有硬件实现方式,也有软件实现方式。其中,采用硬件实现时,其速度虽快,但其扩展性、容错性和多种格式兼容性差。采用软件方式提取缩略图时,会根据不同的图像源格式采取不同的缩略图提取方式。At present, for obtaining thumbnails of image files, existing methods include hardware implementations and software implementations. Among them, when implemented by hardware, although its speed is fast, its scalability, fault tolerance and compatibility with multiple formats are poor. When using software to extract thumbnails, different thumbnail extraction methods will be adopted according to different image source formats.

具体地,对于PNG(便携式网络图形格式)格式的缩略图,现有的方法主要是对原图像直接进行解码,然后再对原图像进行缩放以获得缩略图信息。对于BMP(Bitmap位图)格式的缩略图,现有的方法主要是对原图像直接进行解码,然后再对原图像进行缩放以获得缩略图信息。Specifically, for thumbnails in PNG (Portable Network Graphics Format) format, existing methods mainly decode the original image directly, and then scale the original image to obtain thumbnail information. For thumbnails in BMP (Bitmap) format, the existing method is mainly to directly decode the original image, and then scale the original image to obtain the thumbnail information.

对于上述软件方式进行的PNG格式的缩略图提取,多直接对原图像解码然后缩放。对于尺寸较大的图像,全图像解码会占用较多系统内存。例如对于1张1920x1080色彩空间为RGBA的PNG图像,其全图解码,存储解码图像就要消耗8M的系统内存,不利于多幅图像提取缩略图。For the thumbnail extraction in PNG format performed by the above-mentioned software method, the original image is usually directly decoded and then scaled. For larger images, full image decoding will take up more system memory. For example, for a 1920x1080 PNG image whose color space is RGBA, decoding the whole image and storing the decoded image will consume 8M of system memory, which is not conducive to extracting thumbnails of multiple images.

对于上述软件方式进行的BMP格式的缩略图提取,多直接对原图像解码然后缩放。由于BMP格式的图像往往比较大(如24bit的BMP图像最为常见),解码会占用较多内存且耗费较长时间,难以满足实时显示要求。例如:一张分辨率为1920x1080的24bitBMP图像,全图像解码再缩放,就要消耗6M的系统内存,而且每个像素都读取并存储一遍非常耗时,不能满足实时显示的要求,也不利于对多幅图像提取缩略图。For the thumbnail extraction in BMP format performed by the above-mentioned software method, the original image is usually directly decoded and then scaled. Since images in BMP format are often relatively large (such as 24bit BMP images are the most common), decoding will take up a lot of memory and take a long time, which is difficult to meet the real-time display requirements. For example: for a 24bit BMP image with a resolution of 1920x1080, decoding and scaling the entire image will consume 6M of system memory, and it is very time-consuming to read and store each pixel, which cannot meet the requirements of real-time display and is not conducive to Extract thumbnails for multiple images.

发明内容Contents of the invention

本申请提供了一种PNG图像的缩略图提取方法和一种BMP图像的缩略图提取方法,能够大大节约系统内存消耗,提高缩略图的提取速度。The application provides a method for extracting a thumbnail of a PNG image and a method for extracting a thumbnail of a BMP image, which can greatly save system memory consumption and increase the speed of extracting thumbnails.

一种PNG图像的缩略图提取方法,包括:A method for extracting thumbnails of PNG images, comprising:

对于非交织的PNG图像,开辟2行像素所占用空间大小的缓冲,用于存储当前行及其上一行的解码前像素值;For non-interlaced PNG images, a buffer of the space occupied by 2 rows of pixels is opened to store the pixel values before decoding of the current row and the previous row;

对所述PNG图像从第一行开始逐行进行解码处理,并对每行的解码后重建像素值进行下采样得到目标缩略图的对应行像素值;其中,在所述逐行进行解码处理时,对除第一行之外的当前行解码完成后,将所述上一行的解码前像素值移出所述缓冲,再将下一行的解码前像素值写入所述缓冲,并将下一行作为当前行进行解码。Decoding the PNG image row by row starting from the first row, and downsampling the decoded reconstructed pixel values of each row to obtain the corresponding row pixel values of the target thumbnail; wherein, when the row-by-row decoding is performed , after the decoding of the current line except the first line is completed, the pixel value of the previous line before decoding is moved out of the buffer, and then the pixel value of the next line before decoding is written into the buffer, and the next line is used as The current line to decode.

较佳地,该方法进一步包括:在对当前行的重建像素值进行下采样后,该方法进一步包括:根据图像显示设备的输入参数,确定解码后的重建像素值是否需要进行混色处理,如果需要,则对当前行下采样后的像素值进行混色处理后输入显示设备;否则,直接将当前行下采样后的像素值输入显示设备。Preferably, the method further includes: after down-sampling the reconstructed pixel values of the current row, the method further includes: determining whether the decoded reconstructed pixel values need color mixing processing according to the input parameters of the image display device, and if necessary , the downsampled pixel values of the current line are mixed and then input to the display device; otherwise, the downsampled pixel values of the current line are directly input to the display device.

较佳地,当显示设备要求输入的数据格式为R、G、B、A四通道像素值时,确定不需要进行混色处理。Preferably, when the input data format required by the display device is R, G, B, A four-channel pixel values, it is determined that color mixing processing is not required.

较佳地,当显示设备要求输入的数据格式为R、G、B三通道像素值时,确定需要进行混色处理;Preferably, when the display device requires the input data format to be R, G, and B three-channel pixel values, it is determined that color mixing processing is required;

所述混色处理为:根据重建的每个像素点的R、G、B、A像素值计算其中,BG为背景颜色,黑色背景BG=0,白色背景BG=1,R′、G′、B′为混色后的像素值,用于进行所述下采样处理。The color mixing process is: calculate according to the R, G, B, A pixel values of each reconstructed pixel Wherein, BG is the background color, black background BG=0, white background BG=1, R′, G′, B′ are pixel values after color mixing, and are used for the down-sampling process.

较佳地,当显示设备要求输入的数据格式为Y、Cb、Cr三通道像素值时,确定需要进行混色处理;Preferably, when the display device requires the input data format to be Y, Cb, and Cr three-channel pixel values, it is determined that color mixing processing is required;

所述混色处理为:根据重建的每个像素点的R、G、B、A像素值计算并根据R′、G′、B′计算其中,BG为背景颜色,黑色背景BG=0,白色背景BG=1,Y、Cb、Cr为混色后的像素值,用于进行所述下采样处理。The color mixing process is: calculate according to the R, G, B, A pixel values of each reconstructed pixel And calculate according to R', G', B' Wherein, BG is the background color, black background BG=0, white background BG=1, Y, Cb, Cr are pixel values after color mixing, and are used for the down-sampling process.

较佳地,所述计算为:计算 Preferably, the calculation For: calculate

较佳地,所述根据R′、G′、B′计算为:预先对应R′、G′、B′的所有取值,计算相应的Y、Cb、Cr,并将计算结果与相应的R′、G′、B′取值对应保存,在计算时,选择与当前R′、G′、B′取值对应保存的Y、Cb、Cr作为计算结果。Preferably, the calculation based on R', G', B' To: Correspond to all the values of R', G', B' in advance, calculate the corresponding Y, Cb, Cr, and save the calculation results corresponding to the corresponding values of R', G', B', in the calculation , select Y, Cb, and Cr corresponding to the current R', G', and B' values as the calculation results.

较佳地,该方法进一步包括:对于交织的PNG图像,解码与目标缩略图尺寸最接近的一幅图像,并将解码后的像素值进行下采样,获取目标缩略图。Preferably, the method further includes: for the interleaved PNG image, decoding an image whose size is closest to the target thumbnail, and downsampling the decoded pixel values to obtain the target thumbnail.

一种BMP图像的缩略图提取方法,包括:对于非RLE压缩格式的BMP图像,对应目标缩略图的任一像素,计算对应的所述BMP图像数据的字节位置;A method for extracting a thumbnail of a BMP image, comprising: for a BMP image in a non-RLE compressed format, any pixel of the corresponding target thumbnail, calculating the byte position of the corresponding BMP image data;

在计算出的所述字节位置上读取颜色表索引并根据所述颜色表索引确定对应的像素值,或者直接读取所述字节位置上的RGB数据,写入目标缩略图中所述任一像素对应的位置上。Read the color table index at the calculated byte position and determine the corresponding pixel value according to the color table index, or directly read the RGB data at the byte position and write it into the target thumbnail The position corresponding to any pixel.

较佳地,所述计算对应的所述BMP图像数据的字节位置包括:Preferably, the byte position of the BMP image data corresponding to the calculation includes:

byte=Tstart+linesize×((i-1)×HBMP)/HTHU+((j-1)×WBMP)×pixelsize/(WTHU×8)byte=T start +linesize×((i-1)×H BMP )/H THU +((j-1)×W BMP )×pixelsize/(W THU ×8)

其中,Tstart为所述BMP图像基本信息中的数据起始位置,linesize为所述BMP图像基本数据中的每行像素的字节数,pixelsize为所述BMP图像基本数据中每个像素的比特数。Wherein, T start is the data start position in the basic information of the BMP image, linesize is the number of bytes of each row of pixels in the basic data of the BMP image, and pixelsize is the bit of each pixel in the basic data of the BMP image number.

由上述技术方案可见,本申请中,对于非交织的PNG图像,开辟2行像素所占用空间大小的缓冲,用于存储当前行及其上一行的解码前像素值;对PNG图像从第一行开始逐行进行解码处理,并对每行的解码后重建像素值进行下采样得到目标缩略图的对应行像素值。在逐行进行解码处理时,对除第一行之外的当前行解码完成后,将上一行的解码前像素值移出缓冲,再将下一行的解码前像素值写入缓冲,并将下一行作为当前行进行解码。这样,在整个解码过程中,只需要存储2行图像的解码前像素值,大大节省了解码时的系统内存消耗。It can be seen from the above-mentioned technical scheme that in the present application, for non-interlaced PNG images, a buffer of the size of the space occupied by 2 rows of pixels is opened up to store the pixel values before decoding of the current row and its previous row; Start the decoding process row by row, and down-sample the decoded reconstructed pixel values of each row to obtain the corresponding row pixel values of the target thumbnail image. When decoding row by row, after the decoding of the current row except the first row is completed, the pixel value before decoding of the previous row is moved out of the buffer, and then the pixel value of the next row before decoding is written into the buffer, and the next row Decode as the current line. In this way, during the whole decoding process, only the pre-decoding pixel values of 2 lines of images need to be stored, which greatly saves the system memory consumption during decoding.

附图说明Description of drawings

图1为本申请实施例中PNG图像的缩略图提取方法流程示意图;Fig. 1 is the schematic flow chart of the thumbnail extraction method of PNG image in the embodiment of the present application;

图2为本申请中BMP图像的缩略图提取方法示意图。FIG. 2 is a schematic diagram of a method for extracting a thumbnail of a BMP image in the present application.

具体实施方式detailed description

为了使本申请的目的、技术手段和优点更加清楚明白,以下结合附图对本申请做进一步详细说明。In order to make the purpose, technical means and advantages of the present application clearer, the present application will be further described in detail below in conjunction with the accompanying drawings.

图1为本申请实施例中PNG图像的缩略图提取方法流程示意图。如图1所示,该方法包括:FIG. 1 is a schematic flowchart of a method for extracting a thumbnail of a PNG image in an embodiment of the present application. As shown in Figure 1, the method includes:

步骤101,判断当前图像是否是PNG格式的图像,如果是,则继续执行步骤102,如果不是则退出;Step 101, judge whether current image is the image of PNG format, if yes, then continue to execute step 102, if not then exit;

步骤102,解析PNG图像的头信息,获取该图像的基本信息。Step 102, parse the header information of the PNG image to obtain the basic information of the image.

其中,获取的基本信息包括:原图像的宽WORG和高HORG、位深、色彩类型和交织类型等。Among them, the acquired basic information includes: width W ORG and height H ORG of the original image, bit depth, color type and interleaving type, etc.

步骤103,确定的文件交织类型,若为交织的PNG图像,执行步骤104,若为非交织的PNG图像,执行步骤105-106。Step 103, if the determined file interleaving type is an interlaced PNG image, execute step 104; if it is a non-interleaved PNG image, execute steps 105-106.

步骤104,对于交织PNG图像,解码PNG图像文件中与目标缩略图尺寸最接近的一幅图像,并对该图像进行下采样得到目标缩略图。Step 104, for the interlaced PNG image, decode an image in the PNG image file whose size is closest to the target thumbnail, and down-sample the image to obtain the target thumbnail.

本步骤的处理与现有方式相同。假定IBASE表示PNG图像文件中与目标缩略图尺寸最接近的一幅图像的像素值,下采样得到的目标缩略图宽高尺寸分别为WREL和HREL,则目标缩略图每个像素的像素值IREL(i,j)=IBASE(HIndex[i],WIndex[j]),其中,HIndex[]和WIndex[]分别为行索引数组和列索引数组,HIndex[]表明IREL的行索引到IBASE的行索引的映射关系,WIndex[]表明IREL的列索引到IBASE的列索引的映射关系,这些映射关系是在预先根据目标缩略图的尺寸和PNG图像尺寸计算得到的,具体可以按照现有方式实现,这里就不再赘述。The processing of this step is the same as the existing method. Assuming that I BASE represents the pixel value of an image closest to the size of the target thumbnail in the PNG image file, and the width and height dimensions of the target thumbnail obtained by downsampling are W REL and H REL respectively, then the pixel value of each pixel of the target thumbnail Value I REL (i, j) = I BASE (HIndex[i], WIndex[j]), where HIndex[] and WIndex[] are row index array and column index array respectively, and HIndex[] indicates the row of I REL The mapping relationship between the index and the row index of I BASE , WIndex[] indicates the mapping relationship between the column index of I REL and the column index of I BASE , these mapping relationships are calculated in advance according to the size of the target thumbnail and the size of the PNG image, Specifically, it can be implemented according to an existing method, which will not be repeated here.

步骤105对于非交织的PNG图像,开辟2行像素所需空间大小的缓冲,记为预测缓冲,其中储存的上下相邻两行像素值分别记为line0、line1。Step 105: For the non-interlaced PNG image, open up a buffer with the space required for two lines of pixels, which is denoted as a prediction buffer, and the stored pixel values of the upper and lower adjacent lines are respectively denoted as line0 and line1.

步骤106,对PNG图像从第一行开始逐行进行解码处理,并对每行的解码后重建像素值进行下采样得到目标缩略图的对应行像素值。Step 106: Decode the PNG image line by line starting from the first line, and down-sample the decoded reconstructed pixel values of each line to obtain the corresponding line pixel values of the target thumbnail image.

在逐行进行解码处理时,可以按照下述方式进行:When performing decoding processing line by line, it can be performed in the following manner:

A、将前2行的解码前像素写入预测缓冲,对第1行进行解码处理,并将第2行作为当前行;A. Write the pre-decoded pixels of the first two lines into the prediction buffer, decode the first line, and use the second line as the current line;

B、对当前行进行解码,得到解码后的重建像素;B. Decoding the current row to obtain decoded reconstructed pixels;

C、将当前行的上一行的解码前像素值移出预测缓冲;C. Move the pixel value before decoding of the previous line of the current line out of the prediction buffer;

D、将当前行的下一行的解码前像素值写入预测缓冲,并将下一行作为当前行返回步骤B,直到完成整幅图像的解码。D. Write the pre-decoding pixel values of the next line of the current line into the prediction buffer, and return the next line as the current line to step B until the decoding of the entire image is completed.

在上述处理中,将当前行的上一行移出预测缓冲,并将下一行写入预测缓冲时,优选地,可以在上一行移出预测缓冲后,将当前行的解码前像素值移动到上一行移出预测缓冲前的位置上,再将下一行的解码前像素写入当前行移动前的位置上。这样,每次移出预测缓冲的数据都是相同位置上的数据。这里,在预测缓冲中保存两行像素的原因是考虑到解码当前行时有可能需要上一行的解码前像素值作为预测基准。In the above processing, when the previous line of the current line is moved out of the prediction buffer and the next line is written into the prediction buffer, preferably, after the previous line is moved out of the prediction buffer, the pixel values of the current line before decoding can be moved to the previous line and moved out At the position before the prediction buffer, write the undecoded pixels of the next line into the position before the current line moves. In this way, the data that is moved out of the prediction buffer each time is the data at the same location. Here, the reason why two lines of pixels are stored in the prediction buffer is to consider that when decoding the current line, the pre-decoding pixel value of the previous line may be used as a prediction reference.

在步骤B每完成当前一行的解码处理后,可以对该当前行解码后重建像素值进行下采样得到目标缩略图的对应行像素值。也就是说,下采样处理可以与步骤C、D甚至下一次步骤B的执行同步进行,从而提高缩略图获取速度。After each decoding process of the current row is completed in step B, the decoded and reconstructed pixel values of the current row may be down-sampled to obtain the corresponding row pixel values of the target thumbnail image. That is to say, the down-sampling process can be performed synchronously with the execution of steps C, D and even the next step B, so as to increase the thumbnail acquisition speed.

其中,进行下采样的操作与前述步骤104中的下采样相同。假定IBASE表示当前行解码重建后的像素值,下采样得到的目标缩略图宽高尺寸分别为WREL和HREL,则目标缩略图每个像素的像素值IREL(i,j)=IBASE(HIndex[i],WIndex[j]),其中,HIndex[]和WIndex[]分别为行索引数组和列索引数组,HIndex[]表明IREL的行索引到IBASE的行索引的映射关系,WIndex[]表明IREL的列索引到IBASE的列索引的映射关系,这些映射关系是在预先根据目标缩略图的尺寸和PNG图像尺寸计算得到的,具体可以按照现有方式实现,这里就不再赘述。Wherein, the operation of performing down-sampling is the same as the down-sampling in the aforementioned step 104 . Assuming that I BASE represents the decoded and reconstructed pixel value of the current row, and the width and height dimensions of the target thumbnail obtained by downsampling are W REL and H REL respectively, then the pixel value I REL (i, j)=I of each pixel of the target thumbnail BASE (HIndex[i], WIndex[j]), where HIndex[] and WIndex[] are the row index array and column index array respectively, and HIndex[] indicates the mapping relationship between the row index of I REL and the row index of I BASE , WIndex[] indicates the mapping relationship between the column index of I REL and the column index of I BASE . These mapping relationships are calculated in advance according to the size of the target thumbnail and the size of the PNG image. Specifically, it can be implemented according to the existing method, here is No longer.

在对当前行的重建像素进行下采样处理时,仅将与目标缩略图对应的像素值拷贝到目标缩略图中,其余像素值不做处理。当所有行的像素值解码完成并实现下采样处理后,停止循环步骤B-D。When downsampling the reconstructed pixels of the current row, only the pixel values corresponding to the target thumbnail are copied to the target thumbnail, and the rest of the pixel values are not processed. When the decoding of the pixel values of all rows is completed and the downsampling process is implemented, the loop steps B-D are stopped.

至此,本申请中的JPEG图像的缩略图提取方法结束。So far, the method for extracting a thumbnail of a JPEG image in this application ends.

另外,考虑到不同显示设备的输入参数的不同要求,可能还需要对重建并下采样后的像素值进行混色处理(即将透明色通道混入RGB三通道中),否则图像可能会出现混叠效果。In addition, considering the different requirements of the input parameters of different display devices, it may be necessary to perform color mixing on the reconstructed and downsampled pixel values (that is, to mix the transparent color channel into the RGB three channels), otherwise the image may appear aliasing effect.

基于此,优选地,可以在每次执行完步骤B后,进一步执行步骤E:根据图像显示设备的输入参数,确定解码后的RGBA数据是否需要混色处理,如果需要混色处理,对下采样后的像素值执行相应的混色处理,并将混色处理后的像素值输入显示设备;否则,直接将下采样后的像素值输入显示设备。Based on this, preferably, step E can be further performed after step B is executed each time: according to the input parameters of the image display device, it is determined whether the decoded RGBA data needs color mixing processing, and if color mixing processing is required, the down-sampled Perform corresponding color mixing processing on the pixel value, and input the pixel value after color mixing processing to the display device; otherwise, directly input the downsampled pixel value to the display device.

具体地,本申请中给出判断是否进行混色处理以及相应的混色处理的如下两种具体方式:Specifically, this application provides the following two specific methods for judging whether to perform color mixing processing and the corresponding color mixing processing:

1)如果显示设备要求输入的是R、G、B、A四通道的像素值,则确定不需要进行混色处理,直接将解码后的R、G、B、A输入显示设备;1) If the display device requires the input of four-channel pixel values of R, G, B, and A, it is determined that color mixing processing is not required, and the decoded R, G, B, and A are directly input to the display device;

2)如果显示设备要求输入的是R、G、B三通道像素值,则确定需要进行混色处理,具体混色处理为:对每一个像素值的R、G、B值进行混色处理,混色后的像素值分别为R′、G′、B′:2) If the display device requires the input of R, G, and B three-channel pixel values, it is determined that color mixing processing is required. The specific color mixing processing is: perform color mixing processing on the R, G, and B values of each pixel value, and the mixed color The pixel values are R', G', B' respectively:

混色公式: Color mixing formula:

因上式有除法,优选地,可进一步用移位进行优化:Because the above formula has division, preferably, it can be further optimized by shifting:

R′=[(R×A)>>8]+(255-A)×BGR'=[(R×A)>>8]+(255-A)×BG

G′=[(G×A)>>8]+(255-A)×BGG'=[(G×A)>>8]+(255-A)×BG

B′=[(B×A)>>8]+(255-A)×BGB'=[(B×A)>>8]+(255-A)×BG

(其中BG为背景颜色,黑色背景BG=0,白色背景BG=1)(where BG is the background color, black background BG=0, white background BG=1)

经测试发现:用移位代替除法,优化过后的缩略图提取时间比缩略图提取时间缩短10%~20%,而每个像素精度损失不超过1,这对于快速提取PNG图像缩略图具有显著的效果;After testing, it is found that: using shift instead of division, the optimized thumbnail extraction time is 10% to 20% shorter than the thumbnail extraction time, and the loss of precision per pixel does not exceed 1, which has a significant effect on quickly extracting PNG image thumbnails Effect;

3)如果显示设备要求输入的为Y、Cb、Cr三通道像素值,则先按照上述(1)中的混色公式对每一个像素点进行混色处理得到R′、G′、B′,并将得到的R′、G′、B′按照下式转换为Y、Cb、Cr值,将该Y、Cb、Cr作为混色后的像素值输入显示设备。3) If the display device requires the input of three-channel pixel values of Y, Cb, and Cr, first perform color mixing processing on each pixel according to the color mixing formula in (1) above to obtain R', G', and B', and then The obtained R', G', and B' are converted into Y, Cb, and Cr values according to the following formula, and the Y, Cb, and Cr values are input into the display device as pixel values after color mixing.

同时,上式由于有浮点数乘法,且R′、G′、B′的取值范围为0到255,所以为进一步提高计算效率,优选地,可以预先对应R′、G′、B′的所有取值,计算相应的Y、Cb、Cr,并将计算结果与相应的R′、G′、B′取值对应保存,例如利用表格存储,在实际进行混色处理时,可以直接根据当前的R′、G′、B′取值,查表确定相应的Y、Cb、Cr值,经测试优化后缩略图提取速度能够提高50%。At the same time, since the above formula has floating-point number multiplication, and the value range of R', G', B' is 0 to 255, so in order to further improve the calculation efficiency, it is preferable to pre-correspond to R', G', B' For all the values, calculate the corresponding Y, Cb, Cr, and save the calculation results corresponding to the corresponding R', G', B' values. R', G', and B' are selected, and the corresponding Y, Cb, and Cr values are determined by looking up the table. After testing and optimization, the thumbnail extraction speed can be increased by 50%.

由上述本申请的具体实现可见,本申请中,使用逐行解码大大减少了解码PNG图像过程中的内存开销,能够大大降低内存使用量;经测试,对于1张1080p的非交织PNG图像,本申请方法的内存使用量为全图解码的2‰;对于1张1080i的交织PNG图像,本申请方法内存使用量为现有方法的50%,解码所用时间缩短为全图解码的60%以下。本发明将解码重建过程与缩略图像素提取过程结合,进一步减少运算复杂度和时间消耗。It can be seen from the specific implementation of the above-mentioned application that in this application, the use of progressive decoding greatly reduces the memory overhead in the process of decoding PNG images, and can greatly reduce the amount of memory used; after testing, for a 1080p non-interlaced PNG image, this The memory usage of the application method is 2‰ of full-image decoding; for a 1080i interlaced PNG image, the memory usage of the application method is 50% of the existing method, and the decoding time is shortened to less than 60% of full-image decoding. The present invention combines the decoding and reconstruction process with the thumbnail image pixel extraction process to further reduce the computational complexity and time consumption.

图2为本申请中BMP图像的缩略图提取方法示意图。如图2所示,该方法包括:FIG. 2 is a schematic diagram of a method for extracting a thumbnail of a BMP image in the present application. As shown in Figure 2, the method includes:

步骤201,判断当前图像是否是BMP格式的图像,如果是,则继续执行步骤202,如果不是则退出;Step 201, judge whether current image is the image of BMP format, if yes, then continue to execute step 202, if not then exit;

步骤202,解析BMP图像的头信息,获取该图像的基本信息。Step 202, analyzing the header information of the BMP image to obtain the basic information of the image.

BMP图像的基本信息包括:图像宽WBMP、高HBMP,压缩类型,每个像素bit数pixelsize,每行像素byte数linesize,颜色表,数据起始位置TstartThe basic information of the BMP image includes: image width W BMP , height H BMP , compression type, number of bits per pixel pixelsize, number of bytes of pixels per row linesize, color table, and data start position T start .

步骤203,如果该BMP图像为RLE压缩格式,则执行步骤206对图像进行解码;否则执行步骤204;Step 203, if the BMP image is an RLE compressed format, then execute step 206 to decode the image; otherwise execute step 204;

步骤204,计算缩略图索引到BMP数据的映射关系。Step 204, calculating the mapping relationship between thumbnail index and BMP data.

假定目标缩略图宽为WTHU,高为HTHU,这里对于行索引为i(i=1,...,HTHU),列索引为j(j=1,..,WTHU)的缩略图索引,其对应的BMP数据byte位置如此计算:Assume that the width of the target thumbnail is W THU and the height is H THU . Here, for the thumbnail whose row index is i (i=1,...,H THU ) and column index is j (j=1,...,W THU ) Thumbnail index, its corresponding BMP data byte position is calculated as follows:

byte=Tstart+linesize×((i-1)×HBMP)/HTHU+((j-1)×WBMP)×pixelsize/(WTHU×8)byte=T start +linesize×((i-1)×H BMP )/H THU +((j-1)×W BMP )×pixelsize/(W THU ×8)

这样只需要计算好如下两项:In this way, only the following two items need to be calculated:

Hi=linesize×((i-1)×HBMP)/HTHU H i =linesize×((i-1)×H BMP )/H THU

Wj=((j-1)×WBMP)×pixelsize/(WTHU×8)W j =((j-1)×W BMP )×pixelsize/(W THU ×8)

该映射关系即可表示为:The mapping relationship can be expressed as:

byte=Tsart+Hi+Wj byte=T sart +H i +W j

步骤205,对于缩略图I,对于其某一个像素Ii,j,先由byte=Tstart+Hi+Wj得到其对应的数据起始位置byte,在该位置读取相应的颜色表索引,再在颜色表中寻找对应的像素值,或者直接读取RGB数据(24bit,32bit BMP图像)写入目标缩略图的相应像素位置上。Step 205, for the thumbnail image I, for a certain pixel I i,j , first obtain its corresponding data starting position byte by byte=T start +H i +W j , and read the corresponding color table index at this position , and then look for the corresponding pixel value in the color table, or directly read the RGB data (24bit, 32bit BMP image) and write it to the corresponding pixel position of the target thumbnail.

步骤206,对于RLE压缩格式的BMP图像,先对整个图像进行解码,然后根据缩放比例进行下采样,并获得最终的缩略图。Step 206, for the BMP image in the RLE compression format, first decode the entire image, and then perform down-sampling according to the scaling ratio, and obtain the final thumbnail image.

其中,下采样的处理与前述PNG图像处理中的下采样相同,这里就不再赘述。Wherein, the down-sampling process is the same as the down-sampling in the aforementioned PNG image processing, and will not be repeated here.

上述本申请的BMP图像缩略图提取方法中,对于常见的BMP格式图像能够大大降低内存使用量,并具有较快的处理速度;经测试:对于一张1080p的BMP图像,提取分辨率为160x120的缩略图,本申请的方法内存使用量仅为全图解码的1%;解码所用时间缩短为全图解码的10%以下。In the BMP image thumbnail extraction method of the above-mentioned application, the memory usage can be greatly reduced for common BMP format images, and the processing speed is faster; after testing: for a 1080p BMP image, the extraction resolution is 160x120 For the thumbnail image, the memory usage of the method of this application is only 1% of that of the full image decoding; the decoding time is shortened to less than 10% of that of the full image decoding.

以上所述仅为本发明的较佳实施例而已,并不用以限制本发明,凡在本发明的精神和原则之内,所做的任何修改、等同替换、改进等,均应包含在本发明保护的范围之内。The above descriptions are only preferred embodiments of the present invention, and are not intended to limit the present invention. Any modifications, equivalent replacements, improvements, etc. made within the spirit and principles of the present invention shall be included in the present invention. within the scope of protection.

Claims (7)

1.一种PNG图像的缩略图提取方法,其特征在于,包括:1. a method for extracting thumbnail images of PNG images, characterized in that, comprising: 对于非交织的PNG图像,开辟2行像素所占用空间大小的缓冲,用于存储当前行及其上一行的解码前像素值;For non-interlaced PNG images, a buffer of the space occupied by 2 rows of pixels is opened to store the pixel values before decoding of the current row and the previous row; 对所述PNG图像从第一行开始逐行进行解码处理,并对每行的解码后重建像素值进行下采样得到目标缩略图的对应行像素值;其中,在所述逐行进行解码处理时,对除第一行之外的当前行解码完成后,将所述上一行的解码前像素值移出所述缓冲,再将下一行的解码前像素值写入所述缓冲,并将下一行作为当前行进行解码;Decoding the PNG image row by row starting from the first row, and downsampling the decoded reconstructed pixel values of each row to obtain the corresponding row pixel values of the target thumbnail; wherein, when the row-by-row decoding is performed , after the decoding of the current line except the first line is completed, the pixel value of the previous line before decoding is moved out of the buffer, and then the pixel value of the next line before decoding is written into the buffer, and the next line is used as The current line is decoded; 其中,在对当前行的重建像素值进行下采样后,该方法进一步包括:根据图像显示设备的输入参数,确定解码后的重建像素值是否需要进行混色处理,如果需要,则对当前行下采样后的像素值进行混色处理后输入显示设备;否则,直接将当前行下采样后的像素值输入显示设备。Wherein, after downsampling the reconstructed pixel values of the current row, the method further includes: according to the input parameters of the image display device, determining whether the decoded reconstructed pixel values need color mixing processing, and if so, downsampling the current row After the pixel value is processed by color mixing, it is input to the display device; otherwise, the pixel value after the downsampling of the current line is directly input to the display device. 2.根据权利要求1所述的方法,其特征在于,当显示设备要求输入的数据格式为R、G、B、A四通道像素值时,确定不需要进行混色处理。2 . The method according to claim 1 , wherein, when the input data format required by the display device is R, G, B, and A four-channel pixel values, it is determined that color mixing processing is not required. 3.根据权利要求1所述的方法,其特征在于,当显示设备要求输入的数据格式为R、G、B三通道像素值时,确定需要进行混色处理;3. The method according to claim 1, wherein, when the data format required by the display device to be input is R, G, and B three-channel pixel values, it is determined that color mixing processing is required; 所述混色处理为:根据重建的每个像素点的R、G、B、A像素值计算其中,BG为背景颜色,黑色背景BG=0,白色背景BG=1,R'、G'、B'为混色后的像素值,用于进行所述下采样处理。The color mixing process is: calculate according to the R, G, B, A pixel values of each reconstructed pixel Wherein, BG is the background color, black background BG=0, white background BG=1, R', G', B' are the pixel values after color mixing, which are used for the down-sampling process. 4.根据权利要求1所述的方法,其特征在于,当显示设备要求输入的数据格式为Y、Cb、Cr三通道像素值时,确定需要进行混色处理;4. The method according to claim 1, characterized in that, when the data format required by the display device to be input is Y, Cb, and Cr three-channel pixel values, it is determined that color mixing processing is required; 所述混色处理为:根据重建的每个像素点的R、G、B、A像素值计算并根据R'、G'、B'计算其中,BG为背景颜色,黑色背景BG=0,白色背景BG=1,Y、Cb、Cr为混色后的像素值,用于进行所述下采样处理。The color mixing process is: calculate according to the R, G, B, A pixel values of each reconstructed pixel And calculated according to R', G', B' Wherein, BG is the background color, black background BG=0, white background BG=1, Y, Cb, Cr are pixel values after color mixing, and are used for the down-sampling process. 5.根据权利要求3或4所述的方法,其特征在于,所述计算的方式为:计算 5. The method according to claim 3 or 4, wherein said calculating The method is: calculate 6.根据权利要求4所述的方法,其特征在于,所述根据R'、G'、B'计算为:预先对应R'、G'、B'的所有取值,计算相应的Y、Cb、Cr,并将计算结果与相应的R'、G'、B'取值对应保存,在计算时,选择与当前R'、G'、B'取值对应保存的Y、Cb、Cr作为计算结果。6. The method according to claim 4, characterized in that, the calculation according to R', G', B' To: Correspond to all the values of R', G', B' in advance, calculate the corresponding Y, Cb, Cr, and save the calculation results corresponding to the corresponding values of R', G', B', in the calculation , select Y, Cb, and Cr corresponding to the current R', G', and B' values as the calculation results. 7.根据权利要求1所述的方法,其特征在于,该方法进一步包括:对于交织的PNG图像,解码与目标缩略图尺寸最接近的一幅图像,并将解码后的像素值进行下采样,获取目标缩略图。7. The method according to claim 1, further comprising: for the interleaved PNG image, decoding an image closest to the size of the target thumbnail, and downsampling the decoded pixel value, Get the target thumbnail.
CN201210572320.5A 2012-12-25 2012-12-25 Thumbnail extraction method of PNG image and BMP image Active CN103903285B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201210572320.5A CN103903285B (en) 2012-12-25 2012-12-25 Thumbnail extraction method of PNG image and BMP image

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201210572320.5A CN103903285B (en) 2012-12-25 2012-12-25 Thumbnail extraction method of PNG image and BMP image

Publications (2)

Publication Number Publication Date
CN103903285A CN103903285A (en) 2014-07-02
CN103903285B true CN103903285B (en) 2017-05-10

Family

ID=50994592

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201210572320.5A Active CN103903285B (en) 2012-12-25 2012-12-25 Thumbnail extraction method of PNG image and BMP image

Country Status (1)

Country Link
CN (1) CN103903285B (en)

Families Citing this family (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN107172425B (en) * 2016-03-07 2020-01-31 百度在线网络技术(北京)有限公司 Thumbnail generation method and device and terminal equipment
CN114387356B (en) * 2020-10-16 2025-04-18 思澈科技(重庆)有限公司 A PNG format encoding and decoding method and device

Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN1652155A (en) * 2005-03-28 2005-08-10 北京中星微电子有限公司 Method and apparatus for changing digital image size
CN101287057A (en) * 2008-05-16 2008-10-15 无敌科技(西安)有限公司 Buffer saving image decompressing storing method and module thereof
CN101520887A (en) * 2009-03-30 2009-09-02 北京中星微电子有限公司 Image zooming method, device and chip
CN100589123C (en) * 2007-04-23 2010-02-10 北京中星微电子有限公司 A still image scaling device and method thereof

Patent Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN1652155A (en) * 2005-03-28 2005-08-10 北京中星微电子有限公司 Method and apparatus for changing digital image size
CN100589123C (en) * 2007-04-23 2010-02-10 北京中星微电子有限公司 A still image scaling device and method thereof
CN101287057A (en) * 2008-05-16 2008-10-15 无敌科技(西安)有限公司 Buffer saving image decompressing storing method and module thereof
CN101520887A (en) * 2009-03-30 2009-09-02 北京中星微电子有限公司 Image zooming method, device and chip

Also Published As

Publication number Publication date
CN103903285A (en) 2014-07-02

Similar Documents

Publication Publication Date Title
WO2020010997A1 (en) Video frame extraction method and apparatus, computer readable medium, and electronic device
WO2020248951A1 (en) Method and device for rendering animation, computer readable storage medium, and computer apparatus
US10891032B2 (en) Image reproduction apparatus and method for simultaneously displaying multiple moving-image thumbnails
JP4919743B2 (en) Method and apparatus for generating thumbnails with digital images
US20140086309A1 (en) Method and device for encoding and decoding an image
US8218616B2 (en) Method and system for addition of video thumbnail
EP2787738B1 (en) Tile-based compression for graphic applications
JP4609568B2 (en) Data processing apparatus, data processing method, and data processing system
CN103903285B (en) Thumbnail extraction method of PNG image and BMP image
CN103886624B (en) JPEG image thumbnail extracting method
CN103975583A (en) Capturing multiple video channels for video analytics and encoding
CN110232657A (en) A kind of image-scaling method, device, equipment and medium
US20130286285A1 (en) Method, apparatus and system for exchanging video data in parallel
US9888250B2 (en) Techniques for image bitstream processing
KR101484101B1 (en) Moving Picture Tranformation Device
JP4270169B2 (en) Method and apparatus for transforming an image without using a line buffer
CN104980751B (en) Image data processing apparatus and image data processing method
US20250005799A1 (en) Cross subtile prediction for bandwidth compression
KR20230142474A (en) Method and apparatus for lossless compression of GPU data
US20110286663A1 (en) Method And Apparatus Of Color Image Rotation For Display And Recording Using JPEG
CN103176788B (en) The method and apparatus that a kind of mobile phone desktop animated content seamlessly transits
KR101695007B1 (en) Apparatus for parallel processing of large-scale video data and method thereof
US20140300628A1 (en) Tile-based compression and decompression for graphic applications
CN103918002A (en) Memory controller for video analytics and encoding
CN103176788A (en) Method and device used for smooth transition of animation content of mobile phone desktop

Legal Events

Date Code Title Description
C06 Publication
PB01 Publication
C10 Entry into substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant