CN114387355A - PNG (portable network group) coding and decoding method supporting random access to image - Google Patents

PNG (portable network group) coding and decoding method supporting random access to image Download PDF

Info

Publication number
CN114387355A
CN114387355A CN202011111251.9A CN202011111251A CN114387355A CN 114387355 A CN114387355 A CN 114387355A CN 202011111251 A CN202011111251 A CN 202011111251A CN 114387355 A CN114387355 A CN 114387355A
Authority
CN
China
Prior art keywords
block
image
png
algorithm
random access
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
CN202011111251.9A
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.)
Siche Technology Chongqing Co ltd
Original Assignee
Siche Technology Chongqing 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 Siche Technology Chongqing Co ltd filed Critical Siche Technology Chongqing Co ltd
Priority to CN202011111251.9A priority Critical patent/CN114387355A/en
Publication of CN114387355A publication Critical patent/CN114387355A/en
Pending legal-status Critical Current

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06TIMAGE DATA PROCESSING OR GENERATION, IN GENERAL
    • G06T9/00Image coding

Landscapes

  • Engineering & Computer Science (AREA)
  • Multimedia (AREA)
  • Physics & Mathematics (AREA)
  • General Physics & Mathematics (AREA)
  • Theoretical Computer Science (AREA)
  • Compression Or Coding Systems Of Tv Signals (AREA)

Abstract

The invention belongs to the technical field of image processing, and particularly relates to a PNG (portable network group) coding and decoding method supporting random access to an image; the coding method comprises the steps of carrying out block division on the PNG image according to the number of the blocking lines of the image block; adding a block index mechanism for specifying the number of block lines into an image head block of the PNG image; calling a specified filtering algorithm, a specified coding algorithm and a specified compression algorithm from the image header block to independently process each image block; after all the image blocks are processed, an image ending block is added at the tail of the last image block to finish data coding of the PNG image; corresponding to the encoding method, after a designated area of random access is selected in the decoding process, the invention uses a block indexing mechanism to find the block corresponding to the designated area, and accesses according to the block, thereby reducing a large number of irrelevant scanning line traversal processes and improving the image access efficiency; the invention can be widely applied to products such as MCU chips supporting PNG formats.

Description

PNG (portable network group) coding and decoding method supporting random access to image
Technical Field
The invention belongs to the technical field of image processing, and particularly relates to a PNG (portable network group) coding and decoding method supporting random access to an image.
Background
PNG is a bitmap format employing lossless compression algorithms designed to attempt to replace GIF and TIFF file formats while adding features not available with some GIF file formats. The PNG coding process comprises three processes of filter, deflate and chunk coding; the PNG decoding process comprises three processes of chunk decoding, unfolding and un-filter.
Taking the encoding process as an example, before filtering, the pixels of the PNG image need to be arranged into smaller images, forming a series of image blocks, which are scanned from left to right, from top to bottom; each row of pixels, called a scan line, is represented as a sequence of one byte; causing the pixels of the image blocks to be stored sequentially in a byte sequence; correspondingly, in the decoding process, the PNG image data is restored according to the byte sequence of the scanning lines after filtering restoration.
In an actual application scenario, if a certain data block of a PNG image needs to be accessed, the corresponding data block needs to be found according to the decoding sequence of the scan lines, and obviously, this way will read unnecessary data blocks, bring about a large amount of redundant operations, and waste resources.
Disclosure of Invention
Based on the problems in the prior art, the invention provides a PNG coding and decoding method supporting random access to images, which can realize independent coding of any number of line blocks and adds a block index mechanism in a PNG header; the method is based on the partitioning independent coding and partitioning index mechanism, so that part of the PNG image can be randomly accessed by decoding; the invention is suitable for MCU chips and products supporting PNG format, and can realize random access to PNG images, thereby enabling PNG images to have wider application scenes when GUI displays, and solving the problem of application limitation caused by that PNG images can only be decoded in sequence; the method is also suitable for other scenes applying PNG and the field of CPU chips.
The invention is used for solving the problems by the following scheme:
in a first aspect thereof, the present invention provides a PNG encoding method supporting random access, the encoding method comprising the steps of:
s101, block division is carried out on the PNG image according to the number of the block lines of the image block;
s102, adding a block index mechanism for specifying the number of block lines into an image head block of the PNG image;
s103, calling a specified filtering algorithm, a specified coding algorithm and a specified compression algorithm from the image header block to independently process each image block;
and S104, after all the image blocks are processed, adding an image ending block at the tail part of the last image block to finish the data coding of the PNG image.
In a second aspect of the present invention, the present invention further provides a decoding method corresponding to the above encoding method, a PNG decoding method supporting random access, the decoding method including the following steps:
s201, reading data codes of the PNG image, and completing identification of an image head block, an image data block and an image end block;
s202, selecting a designated area for random access of the image; wherein the designated area comprises starting line information and ending line information;
s203, calling a block index mechanism in a head block of the image to determine a certain block or continuous blocks corresponding to the specified area;
and S204, calling a specified decompression algorithm, a decoding algorithm and a filtering reduction algorithm from the image header block to decode a certain block or continuous blocks in a specified area.
The invention has the beneficial effects that:
in the encoding process, the PNG image is blocked according to the mode of specifying the number of the blocking lines, a blocking index mechanism is added in the head block of the image, and the blocks correspond to the PNG image, so that the process that the scanning lines and the image need to be in one-to-one correspondence in the traditional technology is simplified; due to the establishment of a block index mechanism, independent coding processing can be executed on each block, and each block can adopt an incompletely consistent coding algorithm, so that the PNG image has more diversity; in the decoding process, a designated area for random access is selected firstly, the block position where the designated area is located can be determined from a block indexing mechanism of an image head block, and when access is carried out, the content can be directly read from the corresponding block and a designated decoding algorithm is called to decode the block; the coding method can independently code each block, and when the decoding method is used, the random access to the PNG image can be realized, so that the problem of application limitation caused by that the PNG image can only be decoded in sequence is solved; therefore, the invention can be widely applied to MCU chips, CPU chips and other products supporting PNG formats.
Drawings
FIG. 1 is a flow chart of a PNG encoding method supporting random access according to the present invention;
FIG. 2 is a flow chart of a PNG decoding method supporting random access according to the present invention;
fig. 3 is a schematic diagram of a designated area of a PNG image according to an embodiment of the present invention.
Detailed Description
The technical solutions in the embodiments of the present invention will be clearly and completely described below with reference to the drawings in the embodiments of the present invention, and it is obvious that the described embodiments are only a part of the embodiments of the present invention, and not all of the embodiments. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present invention.
The PNG image is a data structure including an image header block, an image data block, and an image end block; wherein for blocks of image data, the image blocks are scanned from left to right, top to bottom; each row of pixels, called a scan line, is represented as a byte sequence and is stored in byte sequence; in this way, if a random block in the PNG image needs to be accessed, a large amount of redundant operations will be performed from the first scanning line to the last scanning line corresponding to the block, for example, if the PNG image includes 100 scanning lines, if the block is located on the 80 th line, the conventional technology needs to read the 80 th scanning line from the 1 st scanning line all the time to access the block; the large number of redundant operations from the 1 st to the 79 th scan line would be disadvantageous to be performed on the MCU device.
Based on the above, the invention provides a method for solving the problem of random access in a block index mode, and a large amount of unnecessary operations can be reduced.
Fig. 1 is a flowchart of a PNG encoding method supporting random access, as shown in fig. 1, the method comprising the steps of:
s101, block division is carried out on the PNG image according to the number of the block lines of the image block;
in the embodiment of the present invention, the number of rows of a specific block needs to be preset, and the number of rows of the specific block may be a number different from 10, 20, and 30, that is, it indicates that a block includes 10, 20, and 30 scan lines; if an image is divided into 20 lines (i.e., "the number of divided lines") by one block, it should be divided into 26 blocks, for example, 502 lines. That is, where the first 500 rows are divided into 25 partitions, each partition has 20 rows, and the last two rows are divided into one partition, there are 26 partitions in total. For the same PNG image, the number of lines of the designated blocks is fixed, the number of lines of the designated blocks can be set according to actual needs, if finer granularity is needed, one block contains fewer scanning lines, and if coarser granularity is needed, one block contains more scanning lines.
According to the preset line number of the designated blocks, a PNG image is subjected to block division according to the following formula, which is expressed as follows:
Figure BDA0002728672950000041
wherein N represents the number of blocks into which the PNG image is divided; q represents the total number of lines in the PNG image; p represents the number of rows of the specified block;
Figure BDA0002728672950000042
indicating a rounding down.
S102, adding a block index mechanism for specifying the number of block lines into an image head block of the PNG image;
in the present embodiment, a designated number of lines of blocks, an address index of each block in the PNG image, and an index when each block is independently processed are added to the image header block of the PNG image.
The index for each block to be processed independently comprises indexes of a filtering algorithm, a coding algorithm and a compression algorithm called by each block.
For example, if a PNG image is divided into 10 blocks, in a specific encoding process, we need to perform encoding processing on the 10 blocks respectively, and in some realizable manners, the first block of the 10 blocks adopts a filtering algorithm a, an encoding algorithm B and a compression algorithm C; the tenth block adopts a filtering algorithm A1, an encoding algorithm B1 and a compression algorithm C1; then we will store the index of the first block-a-B-C, the index of the tenth block-a 1-B1-C1 in the index mechanism in the picture header block, so that the decoding mode corresponding to each block can be determined directly according to the index of the algorithm in the subsequent decoding process.
S103, calling a specified filtering algorithm, a specified coding algorithm and a specified compression algorithm from the image header block to independently process each image block;
in the last process, after the algorithm index of each block is determined, a filtering algorithm A1, an encoding algorithm B1 and a compression algorithm C1 are directly called from the image header block to encode the first block, a filtering algorithm A1, an encoding algorithm B1 and a compression algorithm C1 are called to encode the tenth block, and the rest blocks are similar.
As the compression algorithm, an LZ77 algorithm, an LZ77 compression algorithm, or the like can be used as it is. For the coding algorithm, the huffman coding algorithm may be directly employed. For the filtering algorithm, a filtering method in the PNG file format white paper can be adopted, but the filtering algorithm therein has a plurality of filtering types. The filtering method does not affect the size of data and does not affect the loss of any information, only one filtering purpose is provided, and better compressed data is provided for the compression method, and the embodiment can process different blocks according to different filtering types, for example, the first block adopts a Sub filtering type, that is, the difference value between the current pixel and the left pixel is recorded, and the first pixel from the left is used as a standard value without any filtering; the second partition is of the Average filtering type and records the difference between the current pixel and the Average values of the left pixel and the upper pixel. If the current row is taken as the first row of the current block: and (4) performing special Sub filtering, wherein the first pixel from the left is a standard value, and no filtering is performed. The other pixels record the difference in value of the pixel and one-half of the left pixel. If the current row is not the first row of the tile: the first pixel from the left records the difference value of the pixel and one half of the value of the pixel at the upper side, and the other pixels carry out normal Average filtering. Of course, other types of filtering may be used for processing in specific implementations, and the present invention is not limited thereto.
And S104, after all the image blocks are processed, adding an image ending block at the tail part of the last image block to finish the data coding of the PNG image.
And after the image blocks are processed, the last data block is used as an end mark, and finally the block coding of the PNG image is realized.
Fig. 2 is a flowchart of a PNG decoding method supporting random access, as shown in fig. 2, the method comprising the steps of:
s201, reading data codes of the PNG image, and completing identification of an image head block, an image data block and an image end block;
the method comprises the steps that a GPU at a host side acquires a PNG image to be decoded, the file format of the PNG image is analyzed by adopting C language and the like, the file mark information, key data block information, auxiliary data blocks and other contents are read from the PNG image, and whether the PNG image is a standard PNG image file or not is judged by analyzing a file mark.
In a preferred mode, when the file mark indicates that the current image is not a standard PNG image file, it may be converted into a standard PNC image.
The key data block information includes an analysis image header block, an image data block, and an image end block, wherein the image data block may include a palette data block, an IDAT image data block, and the like, and when the PNG image is determined to be a standard PNG image according to the file flag information, the image data block may be obtained from the key data block information as original data of the PNG image.
S202, selecting a designated area for random access of the image; wherein the designated area comprises starting line information and ending line information;
when an independent blocked PNG graph exists, the initial row and column information and the ending row and column information of an area need to be specified; the designated area is composed of a quadruple including a start row, a start column, an end row and an end column, and is represented as (start _ row, start _ col; end _ row, end _ col); as shown in fig. 3, taking a PNG image of 86 rows and 96 columns as an example, the selected designated area has 23 rows of start columns and 18 columns of start columns, 65 rows of end columns and 88 columns of end columns.
S203, calling a block index mechanism in a head block of the image to determine a certain block or continuous blocks corresponding to the specified area;
after the initial row and column information and the ending row and column information of the designated area are determined, a first block number corresponding to the initial row information and a second block number corresponding to the ending row are determined according to an index mechanism, and therefore the designated area is determined to be a plurality of continuous blocks from the first block number to the second block number.
The calculation formula corresponding to the block number is expressed as:
Figure BDA0002728672950000071
Figure BDA0002728672950000072
wherein M is1Represents a first partition number; r1Start line information indicating a designated area; p' represents the number of rows of the specified block obtained from the block indexing mechanism; m2Represents a second partition number; r2Start line information indicating a designated area;
Figure BDA0002728672950000073
indicating a rounding down.
In FIG. 3, R1=23,R 265; p' is 20, the value is obtained from the chunk index mechanism, so M1=2,M2=4。
The designated area is corresponding to the block number 2 and the block number 4, and only the data in the second block to the fourth block need to be decoded during subsequent decoding, and the data in the first block does not need to be traversed.
And S204, calling a specified decompression algorithm, a decoding algorithm and a filtering reduction algorithm from the image header block to decode a certain block or continuous blocks in a specified area.
And according to the design of the coding process, determining the algorithm index adopted by each block from the block index mechanism of the image head block, determining the algorithm actually adopted by the block according to the index, and decoding the second to fourth blocks in the designated area by adopting a decompression algorithm, a decoding algorithm and a filtering reduction algorithm corresponding to the inverse algorithm of the algorithm.
In the description of the present invention, it is to be understood that the terms "coaxial", "bottom", "one end", "top", "middle", "other end", "upper", "one side", "top", "inner", "outer", "front", "center", "both ends", and the like, indicate orientations or positional relationships based on those shown in the drawings, and are only for convenience of description and simplicity of description, and do not indicate or imply that the devices or elements referred to must have a particular orientation, be constructed and operated in a particular orientation, and thus, are not to be construed as limiting the present invention.
In the present invention, unless otherwise expressly stated or limited, the terms "mounted," "disposed," "connected," "fixed," "rotated," and the like are to be construed broadly, e.g., as meaning fixedly connected, detachably connected, or integrally formed; can be mechanically or electrically connected; the terms may be directly connected or indirectly connected through an intermediate, and may be communication between two elements or interaction relationship between two elements, unless otherwise specifically limited, and the specific meaning of the terms in the present invention will be understood by those skilled in the art according to specific situations.
Although embodiments of the present invention have been shown and described, it will be appreciated by those skilled in the art that changes, modifications, substitutions and alterations can be made in these embodiments without departing from the principles and spirit of the invention, the scope of which is defined in the appended claims and their equivalents.

Claims (8)

1. A PNG encoding method supporting random access, the encoding method comprising the steps of:
s101, block division is carried out on the PNG image according to the number of the block lines of the image block;
s102, adding a block index mechanism for specifying the number of block lines into an image head block of the PNG image;
s103, calling a specified filtering algorithm, a specified coding algorithm and a specified compression algorithm from the image header block to independently process each image block;
and S104, after all the image blocks are processed, adding an image ending block at the tail part of the last image block to finish the data coding of the PNG image.
2. The PNG encoding method supporting random access according to claim 1, wherein in step S101, the calculation formula of the number of divided blocks is represented as:
Figure FDA0002728672940000011
wherein N represents the number of blocks into which the PNG image is divided; q represents the total number of lines in the PNG image; p represents the number of rows of the specified block;
Figure FDA0002728672940000012
indicating a rounding down.
3. The PNG encoding method capable of supporting random access according to claim 1, wherein the block indexing mechanism comprises adding a specified block line number, an address index of each block in the PNG image, and an index of each block when it is processed independently, to a picture header block of the PNG image.
4. A PNG coding method supporting random access according to claim 3, wherein the index for each partition to be processed independently comprises an index of a filtering algorithm, a coding algorithm and a compression algorithm called by each partition.
5. A PNG decoding method supporting random access, the decoding method comprising the steps of:
s201, reading data codes of the PNG image, and completing identification of an image head block, an image data block and an image end block;
s202, selecting a designated area for random access of the image; wherein the designated area comprises starting line information and ending line information;
s203, calling a block index mechanism in a head block of the image to determine a certain block or continuous blocks corresponding to the specified area;
and S204, calling a specified decompression algorithm, a decoding algorithm and a filtering reduction algorithm from the image header block to decode a certain block or continuous blocks in a specified area.
6. The PNG decoding method supporting random access according to claim 5, wherein the step S203 of determining a block or consecutive blocks corresponding to the designated area includes analyzing the obtained start row and column information and the obtained end row and column information of the designated area, and determining a first block number corresponding to the start row information and a second block number corresponding to the end row according to an indexing mechanism, so as to determine that the designated area is consecutive blocks from the first block number to the second block number.
7. The PNG decoding method supporting random access according to claim 6, wherein a calculation formula corresponding to a block number is expressed as:
Figure FDA0002728672940000021
Figure FDA0002728672940000022
wherein M is1Represents a first partition number; r1Start line information indicating a designated area; p' represents the number of rows of the specified block obtained from the block indexing mechanism; m2Represents a second partition number; r2Start line information indicating a designated area;
Figure FDA0002728672940000023
indicating a rounding down.
8. The PNG decoding method supporting random access according to claim 5, wherein the step S204 includes reading the partitions of the first partition number and the second partition number when decoding the partitions in the designated area, determining the algorithm index of the partitions for independent processing according to the partition index mechanism, and retrieving the corresponding decompression algorithm, decoding algorithm and filter-restoring algorithm from the image header block according to the algorithm index to decode the partitions in the designated area.
CN202011111251.9A 2020-10-16 2020-10-16 PNG (portable network group) coding and decoding method supporting random access to image Pending CN114387355A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202011111251.9A CN114387355A (en) 2020-10-16 2020-10-16 PNG (portable network group) coding and decoding method supporting random access to image

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202011111251.9A CN114387355A (en) 2020-10-16 2020-10-16 PNG (portable network group) coding and decoding method supporting random access to image

Publications (1)

Publication Number Publication Date
CN114387355A true CN114387355A (en) 2022-04-22

Family

ID=81193957

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202011111251.9A Pending CN114387355A (en) 2020-10-16 2020-10-16 PNG (portable network group) coding and decoding method supporting random access to image

Country Status (1)

Country Link
CN (1) CN114387355A (en)

Similar Documents

Publication Publication Date Title
CN104378644B (en) Image compression method and device for fixed-width variable-length pixel sample string matching enhancement
US8977048B2 (en) Method medium system encoding and/or decoding an image using image slices
EP3107289A1 (en) Picture coding and decoding methods and devices
US20140064382A1 (en) Method and system for video encoding and decoding
US7567716B2 (en) Method and device for randomly accessing a region of an encoded image for the purpose of decoding it and a method and device for encoding an image
US8213727B2 (en) Image encoding apparatus and image decoding apparatus, and control method thereof
JP4895400B2 (en) Improved compression in the representation of non-frame edge blocks of image frames
US20080253461A1 (en) Method and system for video encoding and decoding
US11202083B2 (en) Encoder, decoder and method employing palette utilization and compression
KR20120065394A (en) Image processing apparatus and processing method therefor
JPH07327134A (en) Image processor and its method
CN104754362B (en) Image compression method using fine-divided block matching
US9326011B2 (en) Method and apparatus for generating bitstream based on syntax element
JP2005525006A (en) Transform factor compression using multiple scans
CN101742330B (en) Image coding method and device
CN113099221A (en) Cross-component sample point self-adaptive compensation method, coding method and related device
US8406517B2 (en) Image processing apparatus and image processing method
JP2018509069A (en) Image encoding method and apparatus, and image decoding method and apparatus
CN112565793A (en) Image lossless compression method based on prediction difference value classification entropy coding
CN114387355A (en) PNG (portable network group) coding and decoding method supporting random access to image
CN114827612A (en) Video image encoding and decoding method, apparatus and medium
JPH11308465A (en) Encoding method for color image, encoder therefor, decoding method for color image and decoder therefor
US10003808B2 (en) Apparatus and method for encoding
CN113115041A (en) Lossless picture compression method, device and medium supporting alpha channel
CN110392259A (en) Image compression system and utilization image compression system are in the method for compressing image picture

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination