Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

java.lang.NegativeArraySizeException #2

Open
jacksoftapp opened this issue Apr 8, 2024 · 4 comments
Open

java.lang.NegativeArraySizeException #2

jacksoftapp opened this issue Apr 8, 2024 · 4 comments
Assignees
Labels
enhancement New feature or request
Milestone

Comments

@jacksoftapp
Copy link

image

Hello, a java.lang.NegativeArraySizeException exception was reported. Can this be fixed? Thanks

@stanio
Copy link
Owner

stanio commented Apr 9, 2024

Please don't post screenshots of error traces but the output text like:

% sh ./xbrz.sh 1_4.jpeg 4
Exception in thread "main" java.lang.NegativeArraySizeException: -1624375296
	at io.github.stanio.xbrz.awt.ImageData.<init>(ImageData.java:55)
	at io.github.stanio.xbrz.awt.AwtXbrz.scaleImage(AwtXbrz.java:55)
	at io.github.stanio.xbrz.awt.AwtXbrz.scaleImage(AwtXbrz.java:33)
	at io.github.stanio.xbrz.tool.ScalerTool$ScaledImageIterator.next(ScalerTool.java:129)
	at io.github.stanio.xbrz.tool.ScalerTool$ScaledImageIterator.next(ScalerTool.java:79)
	at io.github.stanio.xbrz.tool.ScalerTool.main(ScalerTool.java:61)

Could you specify the xbrz tool and java versions (java -version) you're using? Thank you.

Looking at the trace, it seems the input image is larger than what the tool could handle – what are the exact image dimensions (width and height)? More precisely, the result dimensions @4x the given input image are larger than what the tool could produce. I will improve the error reporting for the related cases in a future version of the tool, but it wouldn't make it process such images successfully.

Note, this tool is meant for processing relatively small pixel-art graphics and is not a general image scaling tool. Could you share your use case for scaling very large images with xBRZ?

@jacksoftapp
Copy link
Author

The Test image size of 2608 x 4000 is 1.8M, and the file size after being enlarged by 4 times is 72M. Can you optimize the enlarged image in the later stage and make it smaller? thank you .

@stanio
Copy link
Owner

stanio commented Apr 12, 2024

2608×4000 scaled by a factor of 4 would be 16 times the original size = 166,912,000 pixels – well within the limits. However, it doesn't match the observed exception: NegativeArraySizeException: -1624375296. The last number as unsigned long would be 2,670,592,000 – a "bit" over the maximum int value: 2,147,483,647.

It could be the source image is not decoded properly by the Java Image I/O library. If the test image is not private, could you share it here? You may also try saving it as PNG to use as a source for the xbrz tool.

@stanio
Copy link
Owner

stanio commented Apr 16, 2024

... it doesn't match the observed exception: NegativeArraySizeException: -1624375296. The last number as unsigned long would be 2,670,592,000...

It does match:

 (2,608 × 4) × (4,000 × 4) = 10,432 × 16,000 = 166,912,000 pixels
(10,432 × 4) × (16,000 × 4) = 41,728 × 64,000 = 2,670,592,000 pixels

It looks like you're trying to scale a 10432×16000 (and not a 2608×4000) image by a factor of 4 which exceeds the implementation limits: target dimension of 41728×64000. For comparison – the maximum target image dimension is about 46000×46000:

sqrt(2,147,483,647) ≈ 46,340.95

Can you optimize the enlarged image in the later stage and make it smaller?

Not sure what you're up to, but xBRZ is not a compression algorithm. It is an upscaling algorithm originally meant for scaling up pixel-art graphics.

stanio added a commit that referenced this issue Apr 16, 2024
Instead of NegativeArraySizeException throw OutOfMemoryException with message
info about the cause: source dimensions and scale factor resulting in target
size integer overflow.
@stanio stanio self-assigned this Apr 17, 2024
@stanio stanio added this to the 1.8.3 milestone Apr 26, 2024
@stanio stanio added the enhancement New feature or request label Apr 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants