Skip to content

Commit

Permalink
Merge pull request #609 from GenericMappingTools/fixes
Browse files Browse the repository at this point in the history
Fix error in ind2rgb and gd2gmt when mem-layout == "R"
  • Loading branch information
joa-quim authored May 15, 2021
2 parents a1f0203 + 36fcf43 commit e53a5db
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 12 deletions.
3 changes: 0 additions & 3 deletions src/gdal_utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
22 changes: 13 additions & 9 deletions src/utils_types.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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

# ---------------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit e53a5db

Please sign in to comment.