mirror of
				https://github.com/python-pillow/Pillow.git
				synced 2025-11-04 01:47:47 +03:00 
			
		
		
		
	Consider I;16 pixel size when drawing
This commit is contained in:
		
							parent
							
								
									32d10505a3
								
							
						
					
					
						commit
						e0cbfb2708
					
				
							
								
								
									
										
											BIN
										
									
								
								Tests/images/imagedraw_rectangle_I.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								Tests/images/imagedraw_rectangle_I.png
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							| 
		 After Width: | Height: | Size: 181 B  | 
| 
						 | 
				
			
			@ -479,6 +479,19 @@ class TestImageDraw(PillowTestCase):
 | 
			
		|||
        # Assert
 | 
			
		||||
        self.assert_image_equal(im, Image.open(expected))
 | 
			
		||||
 | 
			
		||||
    def test_rectangle_I16(self):
 | 
			
		||||
        # Arrange
 | 
			
		||||
        im = Image.new("I;16", (W, H))
 | 
			
		||||
        draw = ImageDraw.Draw(im)
 | 
			
		||||
 | 
			
		||||
        # Act
 | 
			
		||||
        draw.rectangle(BBOX1, fill="black", outline="green")
 | 
			
		||||
 | 
			
		||||
        # Assert
 | 
			
		||||
        self.assert_image_equal(
 | 
			
		||||
            im.convert("I"), Image.open("Tests/images/imagedraw_rectangle_I.png")
 | 
			
		||||
        )
 | 
			
		||||
 | 
			
		||||
    def test_floodfill(self):
 | 
			
		||||
        red = ImageColor.getrgb("red")
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -68,7 +68,12 @@ static inline void
 | 
			
		|||
point8(Imaging im, int x, int y, int ink)
 | 
			
		||||
{
 | 
			
		||||
    if (x >= 0 && x < im->xsize && y >= 0 && y < im->ysize)
 | 
			
		||||
        if (strncmp(im->mode, "I;16", 4) == 0) {
 | 
			
		||||
            im->image8[y][x*2] = (UINT8) ink;
 | 
			
		||||
            im->image8[y][x*2+1] = (UINT8) ink;
 | 
			
		||||
        } else {
 | 
			
		||||
            im->image8[y][x] = (UINT8) ink;
 | 
			
		||||
        }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static inline void
 | 
			
		||||
| 
						 | 
				
			
			@ -95,7 +100,7 @@ point32rgba(Imaging im, int x, int y, int ink)
 | 
			
		|||
static inline void
 | 
			
		||||
hline8(Imaging im, int x0, int y0, int x1, int ink)
 | 
			
		||||
{
 | 
			
		||||
    int tmp;
 | 
			
		||||
    int tmp, pixelwidth;
 | 
			
		||||
 | 
			
		||||
    if (y0 >= 0 && y0 < im->ysize) {
 | 
			
		||||
        if (x0 > x1)
 | 
			
		||||
| 
						 | 
				
			
			@ -108,8 +113,11 @@ hline8(Imaging im, int x0, int y0, int x1, int ink)
 | 
			
		|||
            return;
 | 
			
		||||
        else if (x1 >= im->xsize)
 | 
			
		||||
            x1 = im->xsize-1;
 | 
			
		||||
        if (x0 <= x1)
 | 
			
		||||
            memset(im->image8[y0] + x0, (UINT8) ink, x1 - x0 + 1);
 | 
			
		||||
        if (x0 <= x1) {
 | 
			
		||||
            pixelwidth = strncmp(im->mode, "I;16", 4) == 0 ? 2 : 1;
 | 
			
		||||
            memset(im->image8[y0] + x0 * pixelwidth, (UINT8) ink,
 | 
			
		||||
                   (x1 - x0 + 1) * pixelwidth);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue
	
	Block a user