make apng support more robust by using delay denominator
This commit is contained in:
parent
b7f5bbd895
commit
e37e07c565
28
apng_test.py
Normal file
28
apng_test.py
Normal file
@ -0,0 +1,28 @@
|
||||
from apng import APNG
|
||||
|
||||
print "image1"
|
||||
|
||||
img = APNG.open("image.apng")
|
||||
|
||||
for png, control in img.frames:
|
||||
print "---------"
|
||||
print control.delay
|
||||
print control.delay_den
|
||||
|
||||
print "image2"
|
||||
|
||||
img = APNG.open("shocked.apng")
|
||||
|
||||
for png, control in img.frames:
|
||||
print "---------"
|
||||
print control.delay
|
||||
print control.delay_den
|
||||
|
||||
print "image3"
|
||||
|
||||
img = APNG.open("(a)mad.apng")
|
||||
|
||||
for png, control in img.frames:
|
||||
print "---------"
|
||||
print control.delay
|
||||
print control.delay_den
|
10
images.py
10
images.py
@ -34,8 +34,6 @@ def load_apng(file): # this one was hell to implement compared to the three func
|
||||
i = img.frames.index((frame, frame_info))
|
||||
pilframe = Image.open(io.BytesIO(frame.to_bytes())).convert("RGBA")
|
||||
|
||||
#print str(i)+"\t"+disposes[dispose_op]+"\t\t"+blends[frame_info.blend_op]
|
||||
|
||||
if dispose_op == APNG_DISPOSE_OP_BACKGROUND or (i == 0 and dispose_op == APNG_DISPOSE_OP_PREVIOUS):
|
||||
prev_frame = outputbuf.copy()
|
||||
emptyrect = Image.new("RGBA", (img.frames[i-1][0].width, img.frames[i-1][0].height), (255,255,255,0))
|
||||
@ -55,14 +53,18 @@ def load_apng(file): # this one was hell to implement compared to the three func
|
||||
final_frame = outputbuf.copy()
|
||||
pilframes.append(final_frame)
|
||||
if frame_info:
|
||||
frames.append([final_frame.toqimage(), frame_info.delay*10]) # convert delay from centiseconds to milliseconds
|
||||
# convert delay from centiseconds to milliseconds
|
||||
if frame_info.delay_den == 100:
|
||||
delay = frame_info.delay * 10
|
||||
else:
|
||||
delay = frame_info.delay * (1000.0 / frame_info.delay_den)
|
||||
frames.append([final_frame.toqimage(), delay])
|
||||
dispose_op = frame_info.depose_op
|
||||
else:
|
||||
frames.append([final_frame.toqimage(), 0])
|
||||
|
||||
for frame in pilframes: frame.close()
|
||||
return frames
|
||||
#return pilframes
|
||||
|
||||
def load_webp(file):
|
||||
img = Image.open(file)
|
||||
|
Loading…
Reference in New Issue
Block a user