Skip to content

Issue with thumbnail generation failure for extremely large images #1880

Open
@guiyanakuang

Description

@guiyanakuang

Reported by @sunxiang0918

In addition, I also found a BUG related to generating thumbnails.
When using skia to generate pictures (thumbnails), if the size of the picture is too large, the generation will fail and become an empty file with a small size.
On the CrossPaste interface, it is just a blank block.

image

I roughly looked for the reason, and what was said on the Internet may be related to CPU and memory:
https://groups.google.com/g/skia-discuss/c/A47-OtBOnKU
https://groups.google.com/g/skia-discuss/c/886WuVcQUGo
https://stackoverflow.com/questions/52206463/large-image-resizing-shows-blank

I tried it a little bit myself.
In the environment of my macmini (intel-i5 + 32g), the maximum size is 2317023170 (sqrt(uint32/8)), and the program reports an error if it exceeds the size.
In my mbp (apple m2 + 16g) environment, I tested 128k
128k and it still works...
Therefore, I have not specifically tested what the boundaries and influencing factors are.

@Test
fun testCreateImage() {
    val width = 23170
    val height = 23170
    
    val surface = Surface.makeRasterN32Premul(width, height)
    val canvas = surface.canvas

    // fill gray background
    val paint = Paint().apply { color = Color.makeRGB(128, 128, 128) }
    canvas.drawRect(Rect.makeXYWH(0f, 0f, width.toFloat(), height.toFloat()), paint)

    val img = surface.makeImageSnapshot()

    val result = File("/Users/sun/Downloads/create1111.png").toOkioPath(true)
    
    img.encodeToData()?.bytes?.let {
        result.toNioPath().writeBytes(it)
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions