On Wed, 10 Jun 2026 05:15:16 GMT, Jayathirth D V <[email protected]> wrote:

> We use `Math.ceil()` at 2 places in BMPImageWriter and both of them are under 
> encodeRLE4() function. Also they are used only under absolute mode of 
> encoding.
> 
> First usage `(int)Math.ceil((absVal-1)/2)` is while encoding data in each 
> scanline. Here absVal always starts with 3 and increments by 2, so 
> `Math.ceil()` is basically a no-op here and its usage can be removed.
> 
> Second usage `(int)Math.ceil((absVal+1)/2)` is while encoding end of scanline 
> data. Here absVal can be even and we need to use `Math.ceil()` properly 
> otherwise padding will not be added properly. I have added regression test 
> which actually identifies this issue and it creates a corrupt encoded BMP 
> image. In this regression test we have odd number of distinct pixels at the 
> end of scanline and encoding without proper padding corrupts next scanline of 
> data.
> 
> ---------
> - [x] I confirm that I make this contribution in accordance with the [OpenJDK 
> Interim AI Policy](https://openjdk.org/legal/ai).

test/jdk/javax/imageio/plugins/bmp/RLE4PaddingTest.java line 32:

> 30:  */
> 31: 
> 32: import javax.imageio.IIOImage;

Maybe `import javax.*` looks better after `import java.*`

test/jdk/javax/imageio/plugins/bmp/RLE4PaddingTest.java line 44:

> 42: 
> 43: public class RLE4PaddingTest {
> 44:     static int width = 5;

The `width` and `height` can be modified as `private static final`

-------------

PR Review Comment: https://git.openjdk.org/jdk/pull/31447#discussion_r3388299821
PR Review Comment: https://git.openjdk.org/jdk/pull/31447#discussion_r3388291271

Reply via email to