Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@deadprogram
Copy link
Contributor

This PR modifies image to allows for a QOI format to be loaded from a []byte. It is a lot more flexible for working with various formats in embedded files.

Copy link
Owner

@aykevl aykevl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you give a bit more context why this is needed?
Typically I'll include an image using //go:embed as a string, so that it doesn't take up any RAM (while a []byte would):
https://github.com/aykevl/things/blob/cb1f745f268d6e51daacc670b6282d28a095c4c1/badge/images.go#L13-L21

return nil, errQOIUnsupportedColorSpace
}
img := &QOI[T]{
data: []byte(data),
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will result in a heap allocation the size of the image, which is probably not what you want.
We could unsafely cast the string to a byte slice using unsafe.Slice (and then make sure to never modify it) to avoid this. It's a bit dangerous though.

@deadprogram
Copy link
Contributor Author

What I really want to do is to load it directly via io.Reader to avoid any allocations. I might be getting this data from an embedded file system for example. This was just a step in that direction.

@aykevl
Copy link
Owner

aykevl commented Mar 10, 2024

What do you mean exactly? That you'd load the entire image file into RAM, or only chunks of it on-demand?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants