mirror of
https://github.com/kovidgoyal/kitty
synced 2026-07-27 10:41:58 +02:00
Store mode data per frame
This commit is contained in:
@@ -41,6 +41,7 @@ class Frame:
|
|||||||
ydpi: float
|
ydpi: float
|
||||||
canvas_x: int
|
canvas_x: int
|
||||||
canvas_y: int
|
canvas_y: int
|
||||||
|
mode: str
|
||||||
path: str = ''
|
path: str = ''
|
||||||
|
|
||||||
def __init__(self, identify_data: Union['Frame', Dict[str, str]]):
|
def __init__(self, identify_data: Union['Frame', Dict[str, str]]):
|
||||||
@@ -55,6 +56,7 @@ class Frame:
|
|||||||
self.width, self.height = map(positive_int, identify_data['size'].split('x', 1))
|
self.width, self.height = map(positive_int, identify_data['size'].split('x', 1))
|
||||||
self.xdpi, self.ydpi = map(positive_float, identify_data['dpi'].split('x', 1))
|
self.xdpi, self.ydpi = map(positive_float, identify_data['dpi'].split('x', 1))
|
||||||
self.index = positive_int(identify_data['index'])
|
self.index = positive_int(identify_data['index'])
|
||||||
|
self.mode = 'rgba' if identify_data['transparency'].lower() in ('blend', 'true') else 'rgb'
|
||||||
|
|
||||||
def __repr__(self) -> str:
|
def __repr__(self) -> str:
|
||||||
canvas = f'{self.canvas_width}x{self.canvas_height}:{self.canvas_x}+{self.canvas_y}'
|
canvas = f'{self.canvas_width}x{self.canvas_height}:{self.canvas_x}+{self.canvas_y}'
|
||||||
@@ -118,14 +120,9 @@ def identify(path: str) -> ImageData:
|
|||||||
q = '{"fmt":"%m","canvas":"%g","transparency":"%A","gap":"%T","index":"%p","size":"%wx%h","dpi":"%xx%y"},'
|
q = '{"fmt":"%m","canvas":"%g","transparency":"%A","gap":"%T","index":"%p","size":"%wx%h","dpi":"%xx%y"},'
|
||||||
p = run_imagemagick(path, ['identify', '-format', q, '--', path])
|
p = run_imagemagick(path, ['identify', '-format', q, '--', path])
|
||||||
data = json.loads(b'[' + p.stdout.rstrip(b',') + b']')
|
data = json.loads(b'[' + p.stdout.rstrip(b',') + b']')
|
||||||
frame = data[0]
|
first = data[0]
|
||||||
all_transparencies = {f['transparency'].lower() for f in data}
|
|
||||||
mode = 'rgba' if all_transparencies & {'blend', 'true'} else 'rgb'
|
|
||||||
fmt = frame['fmt'].lower()
|
|
||||||
if fmt == 'jpeg':
|
|
||||||
mode = 'rgb'
|
|
||||||
frames = list(map(Frame, data))
|
frames = list(map(Frame, data))
|
||||||
return ImageData(fmt, frames[0].width, frames[0].height, mode, frames)
|
return ImageData(first['fmt'].lower(), frames[0].width, frames[0].height, frames[0].mode, frames)
|
||||||
|
|
||||||
|
|
||||||
class RenderedImage(ImageData):
|
class RenderedImage(ImageData):
|
||||||
|
|||||||
Reference in New Issue
Block a user