MCPcopy Create free account
hub / github.com/ipython/ipython / _jpegxy

Function _jpegxy

IPython/core/display.py:1071–1088  ·  view source on GitHub ↗

read the (width, height) from a JPEG header

(data)

Source from the content-addressed store, hash-verified

1069 return struct.unpack('>ii', data[ihdr+4:ihdr+12])
1070
1071def _jpegxy(data):
1072 """read the (width, height) from a JPEG header"""
1073 # adapted from http://www.64lines.com/jpeg-width-height
1074
1075 idx = 4
1076 while True:
1077 block_size = struct.unpack('>H', data[idx:idx+2])[0]
1078 idx = idx + block_size
1079 if data[idx:idx+2] == b'\xFF\xC0':
1080 # found Start of Frame
1081 iSOF = idx
1082 break
1083 else:
1084 # read another block
1085 idx += 2
1086
1087 h, w = struct.unpack('>HH', data[iSOF+5:iSOF+9])
1088 return w, h
1089
1090def _gifxy(data):
1091 """read the (width, height) from a GIF header"""

Callers 1

_retina_shapeMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected