Ext.: http://my.oschina.net/1pei/blog/479162
PNG format: Each PNG file is made up of a PNG identifier (signature) followed by some data blocks (chunk), each chunk by
A chunk type to identify its functionality.
Abstract this article addresses the libpng Warning:iCCP:Not recognizing known SRGB profiles that have been edited warning issues that occur during the compilation of Android Studio 1.2.2.
Catalogue [-]
- 1. Description of the problem
- 2. png file format
- 2.2 Data block (chunk)
- 2.2.1 Class 4 key chunk
- 2.2.2 Class 14 Auxiliary chunk
- 2.2.3 Chunk Format
- 3. libpng
- 4. Problem analysis and resolution
- 4.1 ICCP Chunk Analysis
- 4.2 Problem PNG picture ICCP Chunk Analysis
- 4.3 libpng Code Analysis
- 4.4 Warning Information Analysis
- 4.5 Answer the questions raised in the first chapter
- 4.6 Problem Solving
- 4.6.1 Solution 1: Remove the PNG image embedded in ICCP profile SRGB
- 4.6.2 Solution 2: Convert ARGB to sRGB
- 5. References
1. Description of the problem
During compilation under Android Studio 1.2.2, the following warning message appears:
... \res\drawable-hdpi\add_green.png:libpng warning:iCCP:Not Recognizing known SRGB profile it has been edited
Baidu and Google, some users are non-PNG images (such as JPG format) and the wrong use of PNG as a suffix, the above alarm information can also appear, see [7], this article does not consider these circumstances.
Other netizens ' answers are basically: The reason is that the new version of Libpng has adopted more stringent constraints on ICCP. But from which libpng version of the strict inspection, mainly to check which content caused by the alarm information? Basically don't see the answer.
This article first learn the PNG file format, then understand the next libpng, and then to analyze and resolve this warning message.
2. png file format
[2] is the specification of the WWW png, [3] is an example to introduce the PNG file format written in Chinese, the following materials are mainly from the two documents.
Each PNG file is made up of a PNG identifier (signature) followed by a number of data blocks (chunk), each chunk identified by a chunk type.
2.1 PNG identification (signature)
The first 8 bytes of each PNG file always contain the following values:
Decimal 137 80 78 71 13 10 26 106 binary 4E 0D 0A 1 a 0A
The first byte 0x89 is outside the range of ASCII characters, in order to prevent some software from treating PNG files as text files.
2.2 Data block (chunk)
In the PNG specification [2] A total of 18 kinds of chunk are defined, of which 4 classes of chunk are critical data blocks (critical chunk), each PNG file must contain them, and the remaining 14 classes are auxiliary blocks (ancillary chunks), which is an optional block of data.
2.2.1 Class 4 key chunk
Ihdr:image header, the position in the PNG file is the first block of chunk.
Plte: Palette (palette table) before the Idat block.
IDAT: An image data block that can have multiple contiguous IDAT blocks.
Iend:image trailer, the position in the PNG file is the last chunk.
2.2.2 Class 14 Auxiliary chunk
Class 14 auxiliary chunk can be categorized into the following categories:
A. Transparency information (transparent information)
Trns (transparency-Transparent)
B. Colour space information (color space information)
CHRM (Primary chromaticities and white point: base colors and whites)
GAMA (Image gamma: gamma)
ICCP (Embedded profile: Embedded profile)
Sbit (Significant bits: sample valid bit)
SRGB (standard RGB colour space: normal RGB color spaces)
C. Textual information (text message)
iTXt (International Textual Data: Internationalized text)
Text (Textual data: textual)
Ztxt (compressed textual data: Compressed text)
D. Miscellaneous information (other information)
BKGD (Background colour: background color)
HIST (Image histogram: graph histogram)
PHYs (Physical pixel dimensions: physical pixel size)
SPLT (Suggested palette: Recommended color grading)
E. Time information (timing information)
Time (Image last-modification: Image last modified)
2.2.3 Chunk Format
Each piece of chunk consists of 3 or 4 fields.
Length 4 bytes Specifies the length of the chunk data field, which can be 0, not more than (2^31-1) bytes
Chunk Type (data block type) 4 byte block type consists of ASCII letters (A-Z and A-Z),
Bit 5 per byte represents the Chunk property, see [2] 5.4 Chunk naming conventions
Chunk Data (data block data) variable-length storage is specified according to Chunk type
CRC (cyclic redundancy detection) 4 bytes Storage for cyclic redundancy codes to detect errors
[2] 5.6 Chunk ordering describes the order of each class of Chunk in a PNG file.
There is no data field in Iend chunk, so the length field is 0 and iend Chunk is the following 12 bytes (hex):
4E (42 60 82) for the XX
The first 4 bytes are 00,type always iend (4E 44), so the CRC is always AE 42 60 82, and the last 12 bytes of each PNG file are the same.
3. libpng
[4] is the official home page of libpng, from the introduction can be known that it is written in ANSI C (C89), need to zlib 1.0.4/1.2.5 and later. Currently the latest version is 1.6.17 (2015-07-16), from 1.6 source Http://sourceforge.net/p/libpng/code/ci/libpng16/tree/CHANGES It can be seen that the official version of 1.6.18 is about to be released.
On the homepage of the official website has the following vulnerability warning message:
Libpng versions 1.6.9 through 1.6.15 (and some subset of versions up through 1.5.20) has an integer-overflow vulnerabilit Y in Png_combine_row () when decoding very wide interlaced images, which can allow a attacker to overwrite an arbitrary AM Ount of memory with arbitrary (attacker-controlled) data. This vulnerability have been assigned ID cve-2014-9495 and is a fixed in versions 1.6.16 and 1.5.21, released on December 2014.
It is therefore recommended to use the latest version of Linpng whenever possible.
4. Problem analysis and resolution
Following a brief analysis of the chunk in the PNG file format, as well as libpng, you will begin to analyze and resolve the warning issues that you encountered earlier:
... \res\drawable-hdpi\add_green.png:libpng warning:iCCP:Not Recognizing known SRGB profile it has been edited
4.1 ICCP Chunk Analysis
It is also necessary to analyze the next ICCP chunk, whose chunk type is 16-in-a-year (ICCP). Referring to [2] 11.3.3.3 ICCP Embedded profile, you can see that the ICCP chunk contains the data field:
Profile Name 1-79 bytes (character string)
Null separator 1 byte (null character)
Compression Method 1 byte
Compressed profile N bytes
Where profile name is case-sensitive and can only contain printable Latin characters with spaces (that is, the range is decimal characters 32-126 and 161-255), does not allow spaces before and after, and does not allow multiple contiguous spaces in the middle. The compression method can only take a value of 0,0 to represent the deflate compression of the zlib data stream, followed by the compressed profile.
Each PNG file can contain a maximum of one embedded profile, which can be specified explicitly in ICCP chunk or implicitly in sRGB Chunk.
4.2 Problem PNG picture ICCP Chunk Analysis
The following is the ICCP chunk included in the problem add_green.png file:
ICCP The meaning of each field of the data block:
hexadecimal value |
stroke |
xx 0A 4F |
ICCP length of the data block, 0A 4F = decimal 2639 |
metric + |
block type flag, 69 43 43 50 ASCII value equals ICCP |
, &N Bsp  50- 6F 6F (6F)-------------------- 1~79 byte, string with 0 as Terminator, ASCII value equals Photoshop profile |
xx |
compression method, 0 table Use deflate compression |
9D DA 53~03 98 F3 FC |
Compressed profile, decoding using |
63 2D DB |
CRC |
Therefore, the data field of the ICCP chunk here starts with 0x3d, since the length is 0 a 4F, so the data field range is 0x00 3d~ 0A 8 c.
4.3 libpng Code Analysis
To download the code from http://sourceforge.net/p/libpng/code/ci/libpng16/tree/, you can see that the alarm information is in int Png_compare_icc_profile_with_srgb () Functions that appear in:
By examining the HTTP://SOURCEFORGE.NET/P/LIBPNG/CODE/CI/D630301D996B152DE09028BB6803C4C136A0E85F/LOG/?PATH=%2FPNG.C, You can see that this function in Png.c was added by John bowler in 2012.03.29, modifying the comment information as:
[LIBPNG16] Recognize known SRGB profiles while reading; Prefer writing the ICCP profile over writing the SRGB chunk, controlled by the png_srgb_profile_checks option.
The code uses the Png_icc_checksum macro to define an entry in the array png_srgb_checks[], and each item's structure field includes Adler CRC, Length, Md5[4], HAVE_MD5, Is_broken, intent, see:
PNG_CHECKSUM macro After three parameters date, length, File-name is only used for marking.
The following 4 SRGB profiles are from www.color.org, each with MD5 parity codes
The following 3 profiles do not have a clear MD5 checksum, and if the match is empty MD5 the other fields are used to try to match and give a warning. The top two of these profiles have a ' cprt ' tag, which indicates that they were created by HP (Hewlett Packard).
Traverse the png_srgb_checks[] array according to the logic in the Png_compare_icc_profile_with_srgb () function, when. Md5[4] is the same as the MD5 value in the profile, length, intent, The Adler is the same, but when the recalculation of the CRC is unequal, it will prompt "not recognizing known the SRGB profile, which has been edited" warning message.
The intent of this modification and the reason for the default check level of 2 are explained in the Scripts/pnglibconf.dfa file:
Setting srgb_profile_checks Default 2
See also [5] for details.
4.4 Warning Information Analysis
In conjunction with the Png.c file Png_compare_icc_profile_with_srgb () function in libpng, it can be seen that when many fields of profile are all the same, if the CRC does not equal the hint "not recognizing known SRGB Profile this has been edited "warning message.
Front-facing Problems add_green.png file analysis concludes that the last four bytes of a compressed profile in ICCP Chunk are 98 F3 FC, corresponding to the png_srgb_checks[field of the last profiles in the Adler] array:
Png_icc_checksum (0X0398F3FC, 0xf29e526d,
PNG_MD5 (0x00000000, 0x00000000, 0x00000000, 0x00000000), 1, 1/*broken*/,
"1998/02/09 06:49:00", 3144, "Hp-microsoft SRGB v2 media-relative")
Therefore, the ICCP profile file name of this graph is "Hp-microsoft SRGB v2 media-relative".
From the https://github.com/madler/zlib/blob/master/zlib.h in the struct Z_stream can be seen:
ULong Adler; /* Adler32 value of the uncompressed data */
The field Adler is the Adler value of the uncompressed data. So what does this Adler field do? According to [6], the ADLER-32 checksum is almost reliable as a CRC32 in zlib, but it is faster to calculate and is appended to data after the ICCP profile data is compressed. Adler is actually the name of the founder Mark Adler.
4.5 Answer the questions raised in the first chapter
In summary, through the analysis of the profile in the PNG file format ICCP Chunk, libpng png.c file analysis, www.color.org in the SRGB profiles, As well as the analysis of Adler32 in Zlib.h, the following conclusions can be drawn:
When the compressed profile in the PNG image ICCP Chunk is processed, the MD5, length, intent, adler32 fields are the same, but the recalculation of the CRC does not indicate "not recognizing known SRGB profile That has been edited "warning message.
The warning message was given in 2012.03.29 by John Bowler's new Png_compare_icc_profile_with_srgb () function, which is introduced in the Libpng 1.6.0 formal version of this check function.
4.6 Problem Solving
After you have identified the Linpng and checked the content, then how to solve the problem.
4.6.1 Solution 1: Remove the PNG image embedded in ICCP profile SRGB
[13, 16, 17] Some of the answers suggest "convert" or "mogrify" images by using tools such as Image Magick/mogrify/gimp/exiftool to remove ICCP profile SRGB embedded in the PNG image:
Image Magick uses an example:
Delete the profile within a single PNG file:% convert-strip <input filename> <output filename>
Bulk Delete the profile SRGB in all PNG files:
Set Fn=e:\program Files\imagemagick-6.9.0-q16\convert.exe
for/f "tokens=*"%%i in (' dir/s/b *.png ') do "%fn%" "%%i"-strip "%%i"
Examples of mogrify use:
Delete profile srgb:mogrify +profile SRGB <png file> in a single PNG file
Bulk Delete the profile SRGB in all PNG files:
Find <path to res folder>-name *.png-exec mogrify +profile SRGB {} \;
Examples of GIMP use:
To delete an embedded profile, first enter image > Mode > Assign Color Profile and set to RGB workspace (SRGB built-in), then file > Overwrite add_gree N.png overwrite the original PNG file.
To modify the embedded profile, you can enter image > Mode > Convert to Color profiles to select a profile.
Also mentioned in [17]: libpng 1.6+ More stringent inspection will be on the original Hp/ms SRGB profile alarm. The old profile uses D50 Whitepoint, and D65 is the standard. This profile is used by Adobe Photoshop, although the profile is not embedded in the PNG image by default. The simplest way to do this is to remove the embedded profile from the image, but this can cause a slight deviation in color (when there is a color correction system). However, if you do not want the color to be biased (for example, for printouts), you can embed another different color profile.
[13] There are also netizens pointed out: so delete the PNG image in ICCP Profile SRGB, will lose how to render pictures and other information, PNG color may be changed.
4.6.2 Solution 2: Convert ARGB to sRGB
[14] In a netizen mentioned: This image is sRGB changed to ARGB (Adobe RGB) can be, in the upper right corner of Android Studio will display 24-bit and ARGB picture display is 32-bit, However, my local report of this kind of warning PNG image in addition to 32 bits and 24 bits, so this scheme is not feasible.
Combining the above comments, [17] gives a convincing conclusion, using the GIMP tool to remove the embedded profile after the problem is resolved.
5. References
[1] Libpng 1.6.17-march, Http://www.libpng.org/pub/png/src/libpng-1.6.17-README.txt
[2] Portable Network Graphics (PNG) specification (Second Edition), http://www.w3.org/TR/2003/PR-PNG-20030520/
[3] PNG file structure analysis, Http://wenku.baidu.com/view/b87e978583d049649b66586a.html?re=view
[4] libpng official, http://libmng.com/pub/png/libpng.html
[5] [libpng16] recognize known SRGB profiles while reading, http://sourceforge.net/p/libpng/code/ci/ 921648a997e733eb63e18e835a9b98a5507da197/
[6] Zlib Library Anatomy (1): implementation overview, http://blog.csdn.net/zhoudaxia/article/details/8034606
[7] Picture resource Add problem: No resource found that matches the given name Android Maven compilation, http://1985wanggang.blog.163.com/blog/static/776 38332015011114647601/
[8] zlib Technical Details, http://www.zlib.net/zlib_tech.html
[9] Talk about display color management (i.), http://zhuanlan.zhihu.com/hardware/19648994
[10] ramble on display Color Management (ii), http://zhuanlan.zhihu.com/hardware/19649559
[11] Talk about display color Management (iii), http://zhuanlan.zhihu.com/hardware/19649897
[12] ramble on display color Management (iv), http://zhuanlan.zhihu.com/hardware/19651812
[Issue] 77704:built tools 21.0.1:multiple libpng warnings, https://code.google.com/p/android/issues/detail?id=77704
[Androidstudio] How to resolve \com.android.support errors, http://ask.csdn.net/questions/161424
[] sRGB and ARGB color settings conversion, http://blog.sina.com.cn/s/blog_6cf45fc10102v81s.html
[[+] libpng warning:iCCP:Not Recognizing known SRGB profile it has been edited, https://groups.google.com/forum/#!msg /adt-dev/rjtq_str3oe/-ucnqristksj
[Libpng] errors, https://wiki.archlinux.org/index.php/Libpng_errors
[+] GIMP, http://www.gimp.org/
Android Studio Issue-iccp:not recognizing known SRGB profile