1414# > Local Imports
1515from .functions import arange , aiter , wrapper_run_in_executor , run_in_executor
1616
17-
1817# ! Just Pixels
1918class Pixels :
2019 def __init__ (self ) -> None :
@@ -66,13 +65,12 @@ def _segments_from_image(
6665 for x in range (width ):
6766 r , g , b , a = get_pixel ((x , y ))
6867 style = parse_style (f"on rgb({ r } ,{ g } ,{ b } )" ) if a > 0 else null_style
69- row_append (Segment (" " , style ))
68+ row_append (Segment (" " , style ))
7069
7170 row_append (Segment ("\n " , null_style ))
7271
7372 # TODO: Double-check if this is required - I've forgotten...
74- if not all (t [1 ] == "" for t in this_row [:- 1 ]):
75- segments += this_row
73+ segments += this_row
7674
7775 return segments
7876
@@ -128,17 +126,20 @@ def __init__(self) -> None:
128126 async def from_image (
129127 image : Image ,
130128 resize : Optional [Tuple [int , int ]] = None ,
129+ resample : Optional [Resampling ] = None ,
131130 loop : Optional [AbstractEventLoop ] = None
132131 ) -> AsyncPixels :
133132 if loop is None : loop = get_running_loop ()
133+ resample = resample or Resampling .NEAREST
134134
135- segments = await AsyncPixels ._segments_from_image (image , resize , loop )
135+ segments = await AsyncPixels ._segments_from_image (image , resize , resample , loop )
136136 return AsyncPixels .from_segments (segments )
137137
138138 @staticmethod
139139 async def from_image_path (
140140 path : Union [PurePath , str ],
141141 resize : Optional [Tuple [int , int ]] = None ,
142+ resample : Optional [Resampling ] = None ,
142143 loop : Optional [AbstractEventLoop ] = None
143144 ) -> AsyncPixels :
144145 """Create a Pixels object from an image. Requires 'image' extra dependencies.
@@ -147,22 +148,26 @@ async def from_image_path(
147148 path: The path to the image file.
148149 resize: A tuple of (width, height) to resize the image to.
149150 """
151+ resample = resample or Resampling .NEAREST
152+
150153 if loop is None : loop = get_running_loop ()
151154 pilopen = wrapper_run_in_executor (loop , None , PILImageModule .open )
152155
153156 with await pilopen (Path (path )) as image :
154- segments = await AsyncPixels ._segments_from_image (image , resize , loop )
157+ segments = await AsyncPixels ._segments_from_image (image , resize , resample , loop )
155158
156159 return await AsyncPixels .from_segments (segments )
157160
158161 @staticmethod
159162 async def _segments_from_image (
160163 image : Image ,
161164 resize : Optional [Tuple [int , int ]] = None ,
165+ resize_resample : Optional [Resampling ] = None ,
162166 loop : Optional [AbstractEventLoop ] = None
163167 ) -> List [Segment ]:
168+ resample = resize_resample or Resampling .NEAREST
164169 if loop is None : loop = get_running_loop ()
165- if resize is not None : image = await run_in_executor (loop , None , image .resize , resize , resample = Resampling . NEAREST )
170+ if resize is not None : image = await run_in_executor (loop , None , image .resize , resize , resample = resample )
166171
167172 width , height = image .width , image .height
168173 rgba_image = await run_in_executor (loop , None , image .convert , "RGBA" ) if image .mode != "RGBA" else image
@@ -178,13 +183,10 @@ async def _segments_from_image(
178183 async for x in arange (width ):
179184 r , g , b , a = await get_pixel ((x , y ))
180185 style = await parse_style (f"on rgb({ r } ,{ g } ,{ b } )" ) if (a > 0 ) else null_style
181- row_append (Segment (" " , style ))
182-
186+ row_append (Segment (" " , style ))
183187 row_append (Segment ("\n " , null_style ))
184-
185- # TODO: Double-check if this is required - I've forgotten...
186- if not all (t [1 ] == "" async for t in aiter (this_row [:- 1 ])):
187- segments += this_row
188+
189+ segments += this_row
188190
189191 return segments
190192
0 commit comments