Skip to content

Commit e751450

Browse files
committed
styling
1 parent 98d9706 commit e751450

File tree

1 file changed

+13
-11
lines changed

1 file changed

+13
-11
lines changed

R/plotImage.R

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -98,15 +98,15 @@ plotSpatialData <- \() ggplot() + scale_y_reverse() + .theme
9898
#' @importFrom SpatialData getZarrArrayPath
9999
#' @importFrom Rarr zarr_overview
100100
#' @noRd
101-
.get_image_dtype <- \(a) {
101+
.get_img_dt <- \(a) {
102102
pa <- getZarrArrayPath(a)
103103
df <- zarr_overview(pa, as_data_frame=TRUE)
104104
if (!is.null(dt <- df$data_type)) return(dt)
105105
}
106106

107107
# normalize the image data given its data type
108108
#' @noRd
109-
.normalize_image_array <- \(a, dt) {
109+
.norm_ia <- \(a, dt) {
110110
d <- dim(a)[1]
111111
if (dt %in% names(.DTYPE_MAX_VALUES)) {
112112
a <- a / .DTYPE_MAX_VALUES[dt]
@@ -159,7 +159,7 @@ plotSpatialData <- \() ggplot() + scale_y_reverse() + .theme
159159
which.min(d)
160160
}
161161

162-
.get_plot_data <- \(x, k=NULL, w=800, h=800) {
162+
.get_img_data <- \(x, k=NULL, w=800, h=800) {
163163
if (!is.null(k)) return(data(x, k))
164164
data(x, .guess_scale(x, w, h))
165165
}
@@ -168,15 +168,17 @@ plotSpatialData <- \() ggplot() + scale_y_reverse() + .theme
168168
#' @importFrom grDevices rgb
169169
#' @importFrom DelayedArray realize
170170
.df_i <- \(x, k=NULL, ch=NULL, c=NULL, cl=NULL) {
171-
a <- .get_plot_data(x, k)
172-
ch_i <- .ch_idx(x, ch)
171+
a <- .get_img_data(x, k)
172+
ch <- .ch_idx(x, ch)
173173
if (!.is_rgb(x))
174-
a <- a[ch_i, , , drop=FALSE]
175-
dt <- .get_image_dtype(a)
176-
a <- realize(as(a, "DelayedArray"))
177-
a <- .normalize_image_array(a, dt)
178-
if (!.is_rgb(x))
179-
a <- .chs2rgb(a, ch_i, c, cl)
174+
a <- a[ch, , , drop=FALSE]
175+
dt <- .get_img_dt(a)
176+
a <- as(a, "DelayedArray")
177+
a <- .norm_ia(realize(a), dt)
178+
# enter when image isn't RGB already, either
179+
# custom colors or contrasts are specified
180+
if (!.is_rgb(x) || !is.null(c) || !is.null(cl))
181+
a <- .chs2rgb(a, ch, c, cl)
180182
apply(a, c(2, 3), \(.) do.call(rgb, as.list(.)))
181183
}
182184

0 commit comments

Comments
 (0)