Skip to content

Commit

Permalink
fixes #1280
Browse files Browse the repository at this point in the history
  • Loading branch information
rhijmans committed Sep 15, 2023
1 parent 742808e commit f7eb847
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions R/colors.R
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ setMethod ("coltab<-" , "SpatRaster",
x@cpp <- x@cpp$deepcopy()
if (inherits(value, "list")) {
for (i in seq_along(value)) {
layer <- i
layer <- i-1
if (is.null(value[[i]])) {
x@cpp$removeColors(layer)
}
Expand All @@ -51,9 +51,9 @@ setMethod ("coltab<-" , "SpatRaster",

d <- .makeSpatDF(value[[i]])
if (!x@cpp$setColors(layer, d)) {
error("coltab<-", "cannot set these values")
messages(x, "cols<-")
}
}
}
} else {
layer <- layer[1]-1
if (is.null(value)) {
Expand All @@ -71,7 +71,7 @@ setMethod ("coltab<-" , "SpatRaster",
}
if (ncol(value) == 2) {
value <- data.frame(values=value[,1], t(grDevices::col2rgb(value[,2], alpha=TRUE)), stringsAsFactors=FALSE)
} else {
} #else {
# nms <- tolower(names(value))
# if (!(grepl("value", nms))) {
# value <- cbind(values=(1:nrow(value))-1, value)
Expand All @@ -80,18 +80,18 @@ setMethod ("coltab<-" , "SpatRaster",
# if (ncol(value) == 4) {
# value <- cbind(value, alpha=255)
# }
}
#}
value[, 1] <- as.integer(value[, 1])
for (i in 2:ncol(value)) {
value[, i] <- as.integer(clamp(value[, i], 0, 255))
}
value[is.na(value)] <- 255
d <- .makeSpatDF(value)
if (!x@cpp$setColors(layer, d)) {
messages("cols<-", x)
messages(x, "cols<-")
}
x
}
x
}
)

0 comments on commit f7eb847

Please sign in to comment.