1# encoding: utf-8 2 3""" 4Constants specific the the image sub-package 5""" 6 7 8class JPEG_MARKER_CODE(object): 9 """ 10 JPEG marker codes 11 """ 12 TEM = b'\x01' 13 DHT = b'\xC4' 14 DAC = b'\xCC' 15 JPG = b'\xC8' 16 17 SOF0 = b'\xC0' 18 SOF1 = b'\xC1' 19 SOF2 = b'\xC2' 20 SOF3 = b'\xC3' 21 SOF5 = b'\xC5' 22 SOF6 = b'\xC6' 23 SOF7 = b'\xC7' 24 SOF9 = b'\xC9' 25 SOFA = b'\xCA' 26 SOFB = b'\xCB' 27 SOFD = b'\xCD' 28 SOFE = b'\xCE' 29 SOFF = b'\xCF' 30 31 RST0 = b'\xD0' 32 RST1 = b'\xD1' 33 RST2 = b'\xD2' 34 RST3 = b'\xD3' 35 RST4 = b'\xD4' 36 RST5 = b'\xD5' 37 RST6 = b'\xD6' 38 RST7 = b'\xD7' 39 40 SOI = b'\xD8' 41 EOI = b'\xD9' 42 SOS = b'\xDA' 43 DQT = b'\xDB' # Define Quantization Table(s) 44 DNL = b'\xDC' 45 DRI = b'\xDD' 46 DHP = b'\xDE' 47 EXP = b'\xDF' 48 49 APP0 = b'\xE0' 50 APP1 = b'\xE1' 51 APP2 = b'\xE2' 52 APP3 = b'\xE3' 53 APP4 = b'\xE4' 54 APP5 = b'\xE5' 55 APP6 = b'\xE6' 56 APP7 = b'\xE7' 57 APP8 = b'\xE8' 58 APP9 = b'\xE9' 59 APPA = b'\xEA' 60 APPB = b'\xEB' 61 APPC = b'\xEC' 62 APPD = b'\xED' 63 APPE = b'\xEE' 64 APPF = b'\xEF' 65 66 STANDALONE_MARKERS = ( 67 TEM, SOI, EOI, RST0, RST1, RST2, RST3, RST4, RST5, RST6, RST7 68 ) 69 70 SOF_MARKER_CODES = ( 71 SOF0, SOF1, SOF2, SOF3, SOF5, SOF6, SOF7, SOF9, SOFA, SOFB, SOFD, 72 SOFE, SOFF 73 ) 74 75 marker_names = { 76 b'\x00': 'UNKNOWN', 77 b'\xC0': 'SOF0', 78 b'\xC2': 'SOF2', 79 b'\xC4': 'DHT', 80 b'\xDA': 'SOS', # start of scan 81 b'\xD8': 'SOI', # start of image 82 b'\xD9': 'EOI', # end of image 83 b'\xDB': 'DQT', 84 b'\xE0': 'APP0', 85 b'\xE1': 'APP1', 86 b'\xE2': 'APP2', 87 b'\xED': 'APP13', 88 b'\xEE': 'APP14', 89 } 90 91 @classmethod 92 def is_standalone(cls, marker_code): 93 return marker_code in cls.STANDALONE_MARKERS 94 95 96class MIME_TYPE(object): 97 """ 98 Image content types 99 """ 100 BMP = 'image/bmp' 101 GIF = 'image/gif' 102 JPEG = 'image/jpeg' 103 PNG = 'image/png' 104 TIFF = 'image/tiff' 105 106 107class PNG_CHUNK_TYPE(object): 108 """ 109 PNG chunk type names 110 """ 111 IHDR = 'IHDR' 112 pHYs = 'pHYs' 113 IEND = 'IEND' 114 115 116class TIFF_FLD_TYPE(object): 117 """ 118 Tag codes for TIFF Image File Directory (IFD) entries. 119 """ 120 BYTE = 1 121 ASCII = 2 122 SHORT = 3 123 LONG = 4 124 RATIONAL = 5 125 126 field_type_names = { 127 1: 'BYTE', 2: 'ASCII char', 3: 'SHORT', 4: 'LONG', 128 5: 'RATIONAL' 129 } 130 131 132TIFF_FLD = TIFF_FLD_TYPE 133 134 135class TIFF_TAG(object): 136 """ 137 Tag codes for TIFF Image File Directory (IFD) entries. 138 """ 139 IMAGE_WIDTH = 0x0100 140 IMAGE_LENGTH = 0x0101 141 X_RESOLUTION = 0x011A 142 Y_RESOLUTION = 0x011B 143 RESOLUTION_UNIT = 0x0128 144 145 tag_names = { 146 0x00FE: 'NewSubfileType', 147 0x0100: 'ImageWidth', 148 0x0101: 'ImageLength', 149 0x0102: 'BitsPerSample', 150 0x0103: 'Compression', 151 0x0106: 'PhotometricInterpretation', 152 0x010E: 'ImageDescription', 153 0x010F: 'Make', 154 0x0110: 'Model', 155 0x0111: 'StripOffsets', 156 0x0112: 'Orientation', 157 0x0115: 'SamplesPerPixel', 158 0x0117: 'StripByteCounts', 159 0x011A: 'XResolution', 160 0x011B: 'YResolution', 161 0x011C: 'PlanarConfiguration', 162 0x0128: 'ResolutionUnit', 163 0x0131: 'Software', 164 0x0132: 'DateTime', 165 0x0213: 'YCbCrPositioning', 166 0x8769: 'ExifTag', 167 0x8825: 'GPS IFD', 168 0xC4A5: 'PrintImageMatching', 169 } 170