Image format crc check

png format pictures, the file header is 89 50 4e 47 0d 0a 1a 0a 00 00 00 0d 

IHD is

File header data block

no

no

The first piece

The name of the domain

Bytes

Explanation

Width

4 bytes

Image width, in pixels

Height

4 bytes

Image height, in pixels

Bit depth

1 byte

Image Depth:  
Indexed color image: 1 , 2 , 4, or 8  
Grayscale image: 1 , 2 , 4 , 8 or 16  
True color image: 8 or 16

ColorType

1 byte

Color type:
0 : grayscale image , 1 , 2 , 4 , 8 or 16  
2 : true color image, 8 or 16  
3 : indexed color image, 1 , 2 , 4, or 8  
4 : grayscale image with alpha channel data , 8 or 16  
6 : true color image with alpha channel data, 8 or 16

Compression method

1 byte

Compression method (LZ77 derived algorithm )

Filter method

1 byte

Filter method

Interlace method

1 byte

Interlaced scanning method:
0 : Non-interlaced scanning  
1 :  Adam7 ( 7- pass interlaced scanning method developed by Adam M. Costello )

 

The first four digits of the second line are wide, the next four digits are high, and 0806 is the one below. The C1 D0 B3 D4 at the back is the check code. The range of verification is from 494844 to 000000

Bit depth

1 byte

Image Depth:  
Indexed color image: 1 , 2 , 4, or 8  
Grayscale image: 1 , 2 , 4 , 8 or 16  
True color image: 8 or 16

ColorType

1 byte

Color type:
0 : grayscale image , 1 , 2 , 4 , 8 or 16  
2 : true color image, 8 or 16  
3 : indexed color image, 1 , 2 , 4, or 8  
4 : grayscale image with alpha channel data , 8 or 16  
6 : true color image with alpha channel data, 8 or 16

py2 code for crc verification:

# -*- coding: utf-8 -*-
import binascii
import struct
crc32key = 0xC1D0B3E4
for i in range(0, 65535):
  height = struct.pack('>i', i)
  data = b'\x49\x48\x44\x52\x00\x00\x0C\xC0'+height+ b'\x08\x06\x00\x00\x00'

  crc32result = binascii.crc32(data) & 0xffffffff
  if crc32result == crc32key:
    print ''.join(map(lambda c: "%02X" % ord(c), height))

 

Published 125 original articles · Like 31 · Visits 60,000+

Guess you like

Origin blog.csdn.net/Fiverya/article/details/104126369