mirror of
				https://github.com/python-pillow/Pillow.git
				synced 2025-11-04 09:57:43 +03:00 
			
		
		
		
	return fresh image is no mode specified and cached version otherwise
This commit is contained in:
		
							parent
							
								
									fb788b85a9
								
							
						
					
					
						commit
						a86e032a18
					
				| 
						 | 
					@ -182,22 +182,24 @@ def tostring(im, format, **options):
 | 
				
			||||||
    return out.getvalue()
 | 
					    return out.getvalue()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def hopper(mode="RGB", cache={}):
 | 
					def hopper(mode=None, cache={}):
 | 
				
			||||||
    from PIL import Image
 | 
					    from PIL import Image
 | 
				
			||||||
    im = None
 | 
					    if mode is None:
 | 
				
			||||||
 | 
					        # Always return fresh not-yet-loaded version of image.
 | 
				
			||||||
 | 
					        # Operations on not-yet-loaded images is separate class of errors
 | 
				
			||||||
 | 
					        # what we should catch.
 | 
				
			||||||
 | 
					        return Image.open("Tests/images/hopper.ppm")
 | 
				
			||||||
    # Use caching to reduce reading from disk but so an original copy is
 | 
					    # Use caching to reduce reading from disk but so an original copy is
 | 
				
			||||||
    # returned each time and the cached image isn't modified by tests
 | 
					    # returned each time and the cached image isn't modified by tests
 | 
				
			||||||
    # (for fast, isolated, repeatable tests).
 | 
					    # (for fast, isolated, repeatable tests).
 | 
				
			||||||
    im = cache.get(mode)
 | 
					    im = cache.get(mode)
 | 
				
			||||||
    if im is None:
 | 
					    if im is None:
 | 
				
			||||||
        if mode == "RGB":
 | 
					        if mode == "F":
 | 
				
			||||||
            im = Image.open("Tests/images/hopper.ppm")
 | 
					 | 
				
			||||||
        elif mode == "F":
 | 
					 | 
				
			||||||
            im = hopper("L").convert(mode)
 | 
					            im = hopper("L").convert(mode)
 | 
				
			||||||
        elif mode[:4] == "I;16":
 | 
					        elif mode[:4] == "I;16":
 | 
				
			||||||
            im = hopper("I").convert(mode)
 | 
					            im = hopper("I").convert(mode)
 | 
				
			||||||
        else:
 | 
					        else:
 | 
				
			||||||
            im = hopper("RGB").convert(mode)
 | 
					            im = hopper().convert(mode)
 | 
				
			||||||
        cache[mode] = im
 | 
					        cache[mode] = im
 | 
				
			||||||
    return im.copy()
 | 
					    return im.copy()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue
	
	Block a user