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

support raw vector input? #32

Open
mdsumner opened this issue Jun 30, 2022 · 2 comments
Open

support raw vector input? #32

mdsumner opened this issue Jun 30, 2022 · 2 comments

Comments

@mdsumner
Copy link
Contributor

mdsumner commented Jun 30, 2022

It seems feasible to support raw vector input, say as a 3 or 4 column matrix for RGB,RGBA. I'm reading raw direct from GDAL imagery, but it seems I need to expand to integer type to then convert to character hex or nativeRaster.

f <- system.file("img", "Rlogo.png", package="png")
info <- vapour::vapour_raster_info(f)
rawv <- lapply(1:4, function(.x) vapour::vapour_read_raster_raw(f, native = TRUE, band = .x))
plot(0:1, 0:1)
rasterImage(structure(matrix(farver::encode_native(do.call(cbind, lapply(rawv, as.integer))), 
                             info$dimXY[2]), 
                      class = "nativeRaster"), 
            0, 0, 1, 1, interpolate = FALSE)

pryr::object_size(rawv)
#> 30,672 B

pryr::object_size(lapply(rawv, as.integer))
#> 121,872 B

Created on 2022-06-30 by the reprex package (v2.0.1)

It would save some memory to avoid expansion to integer, but is there another pathway perhaps? Ultimately it's probably best if the conversion is done all in Cpp in my own read code, and I have UI to provide nativeRaster output or hex output from there - but maybe this is of interest generally.

@mdsumner
Copy link
Contributor Author

(I don't know why my alpha isn't working in the example above, but it's unrelated to the request - I'll update once I find what's wrong) 🙏

@mdsumner
Copy link
Contributor Author

ah, it's a separate input - apologies, I'lll leave the original example above just please refer to this one:

f <- system.file("img", "Rlogo.png", package="png")
info <- vapour::vapour_raster_info(f)
rawv <- lapply(1:4, function(.x) vapour::vapour_read_raster_raw(f, native = TRUE, band = .x))
plot(0:1, 0:1, type = "n")
alpha <- as.integer(rawv[[4]])
nr_object <- structure(matrix(farver::encode_native(do.call(cbind, lapply(rawv[1:3], as.integer)), alpha = alpha), 
                             info$dimXY[2]), 
                      class = "nativeRaster")
rasterImage(nr_object, 
            0, 0, 1, 1, interpolate = FALSE)

pryr::object_size(rawv)
#> 30,672 B
pryr::object_size(lapply(rawv, as.integer))
#> 121,872 B

Created on 2022-07-01 by the reprex package (v2.0.1)

I guess it's a different reqeuest now too, allow raw input for 'colour' and 'alpha' - which might have UI-implications, I'll have more of a think.

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

No branches or pull requests

1 participant