mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
AZW3 Input: Do not fail to identify JPEG images with BIM headers created with Adobe Photoshop. Fixes #1167985 (Private bug)
This commit is contained in:
parent
de663280c2
commit
891b73c785
@ -51,9 +51,11 @@ def reverse_tag_iter(block):
|
|||||||
end = len(block)
|
end = len(block)
|
||||||
while True:
|
while True:
|
||||||
pgt = block.rfind(b'>', 0, end)
|
pgt = block.rfind(b'>', 0, end)
|
||||||
if pgt == -1: break
|
if pgt == -1:
|
||||||
|
break
|
||||||
plt = block.rfind(b'<', 0, pgt)
|
plt = block.rfind(b'<', 0, pgt)
|
||||||
if plt == -1: break
|
if plt == -1:
|
||||||
|
break
|
||||||
yield block[plt:pgt+1]
|
yield block[plt:pgt+1]
|
||||||
end = plt
|
end = plt
|
||||||
|
|
||||||
@ -231,12 +233,12 @@ class Mobi8Reader(object):
|
|||||||
flowpart = self.flows[j]
|
flowpart = self.flows[j]
|
||||||
nstr = '%04d' % j
|
nstr = '%04d' % j
|
||||||
m = svg_tag_pattern.search(flowpart)
|
m = svg_tag_pattern.search(flowpart)
|
||||||
if m != None:
|
if m is not None:
|
||||||
# svg
|
# svg
|
||||||
typ = 'svg'
|
typ = 'svg'
|
||||||
start = m.start()
|
start = m.start()
|
||||||
m2 = image_tag_pattern.search(flowpart)
|
m2 = image_tag_pattern.search(flowpart)
|
||||||
if m2 != None:
|
if m2 is not None:
|
||||||
format = 'inline'
|
format = 'inline'
|
||||||
dir = None
|
dir = None
|
||||||
fname = None
|
fname = None
|
||||||
@ -320,7 +322,7 @@ class Mobi8Reader(object):
|
|||||||
if len(pos_fid) != 2:
|
if len(pos_fid) != 2:
|
||||||
continue
|
continue
|
||||||
except TypeError:
|
except TypeError:
|
||||||
continue # thumbnailstandard record, ignore it
|
continue # thumbnailstandard record, ignore it
|
||||||
linktgt, idtext = self.get_id_tag_by_pos_fid(*pos_fid)
|
linktgt, idtext = self.get_id_tag_by_pos_fid(*pos_fid)
|
||||||
if idtext:
|
if idtext:
|
||||||
linktgt += b'#' + idtext
|
linktgt += b'#' + idtext
|
||||||
@ -389,7 +391,7 @@ class Mobi8Reader(object):
|
|||||||
href = None
|
href = None
|
||||||
if typ in {b'FLIS', b'FCIS', b'SRCS', b'\xe9\x8e\r\n',
|
if typ in {b'FLIS', b'FCIS', b'SRCS', b'\xe9\x8e\r\n',
|
||||||
b'RESC', b'BOUN', b'FDST', b'DATP', b'AUDI', b'VIDE'}:
|
b'RESC', b'BOUN', b'FDST', b'DATP', b'AUDI', b'VIDE'}:
|
||||||
pass # Ignore these records
|
pass # Ignore these records
|
||||||
elif typ == b'FONT':
|
elif typ == b'FONT':
|
||||||
font = read_font_record(data)
|
font = read_font_record(data)
|
||||||
href = "fonts/%05d.%s" % (fname_idx, font['ext'])
|
href = "fonts/%05d.%s" % (fname_idx, font['ext'])
|
||||||
@ -406,7 +408,11 @@ class Mobi8Reader(object):
|
|||||||
else:
|
else:
|
||||||
imgtype = what(None, data)
|
imgtype = what(None, data)
|
||||||
if imgtype is None:
|
if imgtype is None:
|
||||||
imgtype = 'unknown'
|
from calibre.utils.magick.draw import identify_data
|
||||||
|
try:
|
||||||
|
imgtype = identify_data(data)[2]
|
||||||
|
except Exception:
|
||||||
|
imgtype = 'unknown'
|
||||||
href = 'images/%05d.%s'%(fname_idx, imgtype)
|
href = 'images/%05d.%s'%(fname_idx, imgtype)
|
||||||
with open(href.replace('/', os.sep), 'wb') as f:
|
with open(href.replace('/', os.sep), 'wb') as f:
|
||||||
f.write(data)
|
f.write(data)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user