From 1015917acbefee69580612a86b798e52f3f4f16c Mon Sep 17 00:00:00 2001 From: Joaquim Luis Date: Sat, 15 May 2021 13:49:12 +0100 Subject: [PATCH 1/2] Don't swap x & y coord vectors when mem-layout is R --- src/gdal_utils.jl | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/gdal_utils.jl b/src/gdal_utils.jl index 417f49f09d..f29110407c 100644 --- a/src/gdal_utils.jl +++ b/src/gdal_utils.jl @@ -104,9 +104,6 @@ function gd2gmt(_dataset; band::Int=0, bands=Vector{Int}(), sds::Int=0, pad::Int ((nodata = Gdal.getnodatavalue(Gdal.getband(dataset))) !== nothing) && (O.nodata = nodata) end end - if (O.layout[2] == 'R') - O.x, O.y = O.y, O.x # Because mat2* thought mat were column-major but it's rwo-major - end O.inc = [x_inc, y_inc] # Reset because if pad != 0 they were recomputed inside the mat2? funs O.pad = pad return O From 36fcf43f1ad9b677f266aab855b7983f780f0616 Mon Sep 17 00:00:00 2001 From: Joaquim Luis Date: Sat, 15 May 2021 13:49:41 +0100 Subject: [PATCH 2/2] In ind2rgb keep the original memory layout --- src/utils_types.jl | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/src/utils_types.jl b/src/utils_types.jl index f2bb0d4ff8..fc36e5ab68 100644 --- a/src/utils_types.jl +++ b/src/utils_types.jl @@ -407,15 +407,19 @@ Convert an indexed image I to RGB. It uses the internal colormap to do the conve function ind2rgb(img::GMTimage) # ... (size(img.image, 3) >= 3) && return img # Image is already RGB(A) - imgRGB = zeros(UInt8,size(img.image,1), size(img.image,2), 3) - n = 1 - for k = 1:length(img.image) - start_c = img.image[k] * 4 - for c = 1:3 - imgRGB[n] = img.colormap[start_c+c]; n += 1 + if (img.n_colors == 0) # If no cmap just replicate the first layer. + imgRGB = repeat(img.image, 1, 1, 3) + else + imgRGB = zeros(UInt8,size(img.image,1), size(img.image,2), 3) + n = 1 + for k = 1:length(img.image) + start_c = img.image[k] * 4 + for c = 1:3 + imgRGB[n] = img.colormap[start_c+c]; n += 1 + end end end - mat2img(imgRGB, x=img.x, y=img.y, proj4=img.proj4, wkt=img.wkt, mem_layout="BRPa") + mat2img(imgRGB, x=img.x, y=img.y, proj4=img.proj4, wkt=img.wkt, mem_layout=img.layout) end # --------------------------------------------------------------------------------------------------- @@ -584,8 +588,8 @@ function grdimg_hdr_xy(mat, reg, hdr, x=Vector{Float64}(), y=Vector{Float64}()) nx = Int(round((hdr[2] - hdr[1]) / hdr[8] + one_or_zero)) ny = Int(round((hdr[4] - hdr[3]) / hdr[9] + one_or_zero)) end - x = collect(range(hdr[1], stop=hdr[2], length=nx)) - y = collect(range(hdr[3], stop=hdr[4], length=ny)) + x = collect(range(hdr[1], stop=hdr[2], length=(nx+Int(hdr[7])) )) + y = collect(range(hdr[3], stop=hdr[4], length=(ny+Int(hdr[7])) )) # Recompute the x|y_inc to make sure they are right. x_inc = (hdr[2] - hdr[1]) / (nx - one_or_zero) y_inc = (hdr[4] - hdr[3]) / (ny - one_or_zero)