CN109271540B - Implementation method for combining picture lossy compression and recording transparency information - Google Patents

Implementation method for combining picture lossy compression and recording transparency information Download PDF

Info

Publication number
CN109271540B
CN109271540B CN201811123480.5A CN201811123480A CN109271540B CN 109271540 B CN109271540 B CN 109271540B CN 201811123480 A CN201811123480 A CN 201811123480A CN 109271540 B CN109271540 B CN 109271540B
Authority
CN
China
Prior art keywords
format
file
byte stream
png
transparency information
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
CN201811123480.5A
Other languages
Chinese (zh)
Other versions
CN109271540A (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.)
Zhejiang Wanpeng Digital Intelligence Technology Co ltd
Original Assignee
Zhejiang Wanpeng Education Science And Technology Stock 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 Zhejiang Wanpeng Education Science And Technology Stock Co ltd filed Critical Zhejiang Wanpeng Education Science And Technology Stock Co ltd
Priority to CN201811123480.5A priority Critical patent/CN109271540B/en
Publication of CN109271540A publication Critical patent/CN109271540A/en
Application granted granted Critical
Publication of CN109271540B publication Critical patent/CN109271540B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Classifications

    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04NPICTORIAL COMMUNICATION, e.g. TELEVISION
    • H04N19/00Methods or arrangements for coding, decoding, compressing or decompressing digital video signals
    • H04N19/85Methods or arrangements for coding, decoding, compressing or decompressing digital video signals using pre-processing or post-processing specially adapted for video compression

Landscapes

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

Abstract

The invention discloses a method for realizing lossy compression and transparency information recording in combination with a picture. The present invention comprises two parts, conversion from png format to specified format and conversion from specified format to png format. The method has the idea that the jpg format and the png format are combined, so that the advantage of high compression rate of the jpg format and the advantage of transparency information supported by the png format are obtained, and the file length is greatly shortened on the whole.

Description

Implementation method for combining picture lossy compression and recording transparency information
Technical Field
The invention belongs to the field of data compression and computer graphic image processing, and particularly relates to a method which can be used when high compression ratio of lossy compression is required to be combined with the requirement of recording transparency information.
Background
With the rapid development of computers and networks, pictures are one of very important media, and the compression modes of pictures are divided into two categories, namely lossy compression and lossless compression, wherein lossy compression refers to selectively discarding some insensitive data according to the sensitivity of human eyes to color, brightness, details and the like, so as to achieve the effect of reducing space occupation. Transparency information is also very important in practical application of pictures, and an image containing the transparency information can enable edges of a color image to be smoothly fused with any background, so that the phenomenon that the edges are jagged is thoroughly eliminated. The method integrates the advantages of the jpg format and the png format, can improve the compression rate by using lossy compression, can store transparency information, and is suitable for wider use scenes.
Disclosure of Invention
The invention aims to provide a method for storing transparency information by using lossy compression aiming at the blank of the prior art. The present invention comprises two parts, conversion from png format to the present method format and conversion from the present method format to png format.
The method comprises the following specific steps of converting the png format into the format of the method:
step one, reading a png image file to be processed by using an open source image processing class library CXImage, recording the png image file as SRC, calling an Encode method of the SRC, setting a type parameter as CXIMAGE _ FORMAT _ JPG, converting the SRC into a memory byte stream in a JPG FORMAT, recording the memory byte stream as M1, calling an Encode2RGBA method of the SRC, and acquiring a memory byte stream of SRC transparency information, recording the memory byte stream as M2.
And secondly, writing a file header in the new file, wherein the file header comprises a default value I for identifying the file type, the length of the byte stream M1 and the length of the byte stream M2 are used as the content of the file header, and the content of the byte stream M1 and the content of the byte stream M2 are used as the content of the new file, so that the writing of the new file is completed.
The method comprises the following specific steps of converting the format of the method into the png format:
step three, reading a file header from the file in the format of the method, wherein the file header comprises a default value II for identifying the file type, a length L1 of lossy compression data of the picture and a transparency information length L2 of the picture, and if the read default value II for identifying the file type is the same as the default value I, entering step four; if the default value II of the read identification file type is different from the default value I, the file is not in the format of the method, and the conversion fails.
Reading a byte stream with the length of L1, namely picture data in a jpg FORMAT, behind a file header, decoding the picture data by using CXImage to obtain RGB data of an image, recording the RGB data as DST, continuously reading the byte stream with the length of L2, namely the memory byte stream of transparency information, calling an AlphaSet function of the DST, setting the transparency information into the image content of the DST, calling an Encode function of the DST, and setting the type parameter as CXIMAGE _ FORMAT _ PNG to obtain a final PNG FORMAT result.
The invention has the following beneficial effects:
the method has the idea that the jpg format and the png format are combined, so that the advantage of high compression rate of the jpg format and the advantage of transparency information supported by the png format are obtained, and the file length is greatly shortened on the whole.
Detailed Description
The present invention will be further described with reference to the following examples.
Taking img _ answer _ tc.png as an example, the original file size is 15232 bytes, the open source image processing class library CXImage is used to read in the img _ answer _ tc.png to be processed, which is recorded as SRC, then the Encode method of SRC is invoked, the type parameter is set as CXImage _ FORMAT _ JPG, the memory byte stream is converted into a memory byte stream in JPG FORMAT, which is recorded as M1, the length of M1 is 7431 bytes, then the Encode2RGBA method of SRC is invoked, the memory byte stream for obtaining transparency information is recorded as M2, the length of M2 is 1425 bytes, the file header is added, the total length of the finally generated file is 8888 bytes, and the occupied space is 58% of the original file.
Reading a file header from the beginning of a file to be decompressed, obtaining a default value II for identifying the file type, a memory byte stream length L1 of a jpg format being 7431, a memory byte stream length L2 of transparency information being 1425, comparing the default value II with the default value I, and confirming that the file is in the format of the method; then 7431 bytes are read again, and CXImage is used for decoding to obtain RGB data of the image, and the RGB data is recorded as DST; then, 1425 bytes are read again to be a memory byte stream of transparency information, an AlphaSet function of the DST is called, the memory byte stream of transparency information is set in the image content of the DST, an Encode function of the DST is called, a type parameter is set as CXIMAGE _ FORMAT _ PNG, a final PNG FORMAT result can be obtained, the size of a finally recovered file is 15048 bytes, the reason that the size of the finally recovered file is different from that of the original file is that the method contains a lossy compression process, and data after compression and decompression is not completely consistent with the original data.

Claims (1)

1. A method for realizing lossy compression and transparency information recording in combination with pictures is characterized by comprising two parts, namely converting from a png format to a specified format and converting from the specified format to the png format, and specifically comprises the following steps:
the specific steps for converting the png format into the specified format are as follows:
reading a png image file to be processed by using an open source image processing class library CXImage, recording the png image file as SRC, calling an Encode method of the SRC, setting a type parameter as CXIMAGE _ FORMAT _ JPG, converting the SRC into a memory byte stream in a JPG FORMAT, recording the memory byte stream as M1, calling an Encode2RGBA method of the SRC, and acquiring a memory byte stream of SRC transparency information, recording the memory byte stream as M2;
writing a file header in the new file, wherein the file header comprises a default value I for identifying the file type, the length of the byte stream M1 and the length of the byte stream M2 are used as the content of the file header, and the content of the byte stream M1 and the content of the byte stream M2 are used as the content of the new file, so that the writing of the new file is completed;
the specific steps for converting the specified format into the png format are as follows:
step three, reading a file header from a file with a specified format, wherein the file header comprises a specified value II for identifying the file type, a length L1 of lossy compressed data of the picture and a transparency information length L2 of the picture, and if the read specified value II for identifying the file type is the same as the specified value I, entering step four; if the default value II of the read identification file type is different from the default value I, the identification file type is not in the format of the method, and the conversion fails;
reading a byte stream with the length of L1, namely picture data in a jpg FORMAT, behind a file header, decoding the picture data by using CXImage to obtain RGB data of an image, recording the RGB data as DST, continuously reading the byte stream with the length of L2, namely the memory byte stream of transparency information, calling an AlphaSet function of the DST, setting the transparency information into the image content of the DST, calling an Encode function of the DST, and setting the type parameter as CXIMAGE _ FORMAT _ PNG to obtain a final PNG FORMAT result.
CN201811123480.5A 2018-09-26 2018-09-26 Implementation method for combining picture lossy compression and recording transparency information Active CN109271540B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201811123480.5A CN109271540B (en) 2018-09-26 2018-09-26 Implementation method for combining picture lossy compression and recording transparency information

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201811123480.5A CN109271540B (en) 2018-09-26 2018-09-26 Implementation method for combining picture lossy compression and recording transparency information

Publications (2)

Publication Number Publication Date
CN109271540A CN109271540A (en) 2019-01-25
CN109271540B true CN109271540B (en) 2021-05-25

Family

ID=65197556

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201811123480.5A Active CN109271540B (en) 2018-09-26 2018-09-26 Implementation method for combining picture lossy compression and recording transparency information

Country Status (1)

Country Link
CN (1) CN109271540B (en)

Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN102036059A (en) * 2009-09-25 2011-04-27 腾讯科技(深圳)有限公司 Method, device and system for compressing and decompressing transparent images
CN105430393A (en) * 2014-09-19 2016-03-23 腾讯科技(深圳)有限公司 Picture processing method, picture processing device and picture processing platform
CN105491398A (en) * 2014-09-19 2016-04-13 腾讯科技(深圳)有限公司 Picture processing method, picture processing device and picture processing platform
CN106937132A (en) * 2017-04-08 2017-07-07 腾讯科技(深圳)有限公司 A kind of photograph document handling method
CN108154542A (en) * 2017-12-22 2018-06-12 北京小鱼在家科技有限公司 A kind of method for increasing translucent attribute to JPG files

Family Cites Families (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
JP2007089136A (en) * 2005-08-23 2007-04-05 Ricoh Co Ltd Image processing method, image processing program, recording medium, and composite device

Patent Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN102036059A (en) * 2009-09-25 2011-04-27 腾讯科技(深圳)有限公司 Method, device and system for compressing and decompressing transparent images
CN105430393A (en) * 2014-09-19 2016-03-23 腾讯科技(深圳)有限公司 Picture processing method, picture processing device and picture processing platform
CN105491398A (en) * 2014-09-19 2016-04-13 腾讯科技(深圳)有限公司 Picture processing method, picture processing device and picture processing platform
CN106937132A (en) * 2017-04-08 2017-07-07 腾讯科技(深圳)有限公司 A kind of photograph document handling method
CN108154542A (en) * 2017-12-22 2018-06-12 北京小鱼在家科技有限公司 A kind of method for increasing translucent attribute to JPG files

Non-Patent Citations (1)

* Cited by examiner, † Cited by third party
Title
基于Android手机应用开发的png图片压缩打包技术研究;吴昊;《中国新通信》;20180105;第115-116页 *

Also Published As

Publication number Publication date
CN109271540A (en) 2019-01-25

Similar Documents

Publication Publication Date Title
CN103843032B (en) For the image procossing of high dynamic range images
WO2017206761A1 (en) Method and apparatus for displaying picture content in application, and storage medium
DK2375383T3 (en) Decoding High Dynamic Range (HDR) images
WO2018184458A1 (en) Picture file processing method and device, and storage medium
KR101906779B1 (en) Backwards compatible extended image format
TWI707309B (en) Method, system and storage medium for processing image file
CN102821279A (en) Picture compression method keeping with alpha channel
CN102036059A (en) Method, device and system for compressing and decompressing transparent images
JPH04504920A (en) Method and apparatus for manipulating digital video data
JP2006345315A5 (en)
CN105933708B (en) A kind of method and apparatus of data compression and decompression
JP6617719B2 (en) Information processing apparatus, information recording medium, information processing method, and program
WO2018184464A1 (en) Picture file processing method and device, and storage medium
US10304212B2 (en) Graphic data compression device and graphic data compression method
CN104243886A (en) High-speed image analyzing and video generating technology based on plug-in technology
CN109271540B (en) Implementation method for combining picture lossy compression and recording transparency information
US20140301641A1 (en) Tile-Based Compression and Decompression for Graphic Applications
WO2023138491A1 (en) Image capturing method, image display method, and device
JP6990179B2 (en) Methods and equipment for selecting processes to be applied to video data from a candidate process set driven by a common information dataset.
CN111246249A (en) Image encoding method, encoding device, decoding method, decoding device and storage medium
CN115866254A (en) Method and equipment for transmitting video frame and camera shooting parameter information
KR101937718B1 (en) Image Processing Method and Apparatus Using Bus Protocol Based Valid Pixel
US8428355B2 (en) Image file processing method
CN112417920A (en) Scan input method, device, equipment and medium based on high-speed scanner
EP4387236A1 (en) Method and image-processing device for adding an overlay to a video sequence

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
GR01 Patent grant
GR01 Patent grant
CP02 Change in the address of a patent holder
CP02 Change in the address of a patent holder

Address after: 12 / F, building 8, No. 19, Jugong Road, Xixing street, Binjiang District, Hangzhou City, Zhejiang Province, 310051

Patentee after: ZHEJIANG WANPENG EDUCATION SCIENCE AND TECHNOLOGY STOCK CO.,LTD.

Address before: Room 1406, Hangzhou e-commerce building, 118 Wensan West Road, Xihu District, Hangzhou City, Zhejiang Province, 310013

Patentee before: ZHEJIANG WANPENG EDUCATION SCIENCE AND TECHNOLOGY STOCK CO.,LTD.

CP01 Change in the name or title of a patent holder
CP01 Change in the name or title of a patent holder

Address after: 12 / F, building 8, No. 19, Jugong Road, Xixing street, Binjiang District, Hangzhou City, Zhejiang Province, 310051

Patentee after: Zhejiang Wanpeng Digital Intelligence Technology Co.,Ltd.

Address before: 12 / F, building 8, No. 19, Jugong Road, Xixing street, Binjiang District, Hangzhou City, Zhejiang Province, 310051

Patentee before: ZHEJIANG WANPENG EDUCATION SCIENCE AND TECHNOLOGY STOCK CO.,LTD.