Skip to content

Commit

Permalink
Comments tweaks.
Browse files Browse the repository at this point in the history
  • Loading branch information
joa-quim committed Apr 25, 2024
1 parent 34ac25a commit 7c07ef4
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
4 changes: 2 additions & 2 deletions src/gdal_utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -366,8 +366,8 @@ function gmt2gd(GI)
# Julia show methods. A further problem is that if we use 'GI = gmtread("file", layout="TRB")', GI's
# array still has a visible mem layout equal to a column major array. AS an example of this, see:
# gmtwrite("z.grd", mat2grid(reshape(1:20, 4,5))); Gr = gmtread("z.grd", layout="TRB"); Gc = gmtread("z.grd");
# Now both Gr.z and Gc.r are 4x5 matrices, but Gr can't be passed as is to 'gmt2gd(...)' because its
# memory layout is wrong when seen from the GDAL wrapper functions. To disambiguate this, we are not
# Now both Gr.z and Gc.z are 4x5 matrices, but Gr can't be passed as is to 'gmt2gd(...)' because its
# memory layout is wrong when seen from the GDAL wrapper functions. To disambiguate this, we are not
# relying in 'size(GI)' but on the length of the x,y coordinates vectors, that are assumed to always be correct.

width, height = (GI.layout != "" && GI.layout[2] == 'C') ? (size(GI,2), size(GI,1)) : (length(GI.x), length(GI.y)) .- GI.registration
Expand Down
12 changes: 7 additions & 5 deletions src/gmt_main.jl
Original file line number Diff line number Diff line change
Expand Up @@ -483,10 +483,10 @@ function get_image(API::Ptr{Nothing}, object)::GMTimage
o = (nz == 1) ? (ny, nx) : (ny, nx, nz)
isBRP = startswith(layout, "BRP")
(nz == 1 && isBRP) && (layout = "BRPa") # For 1 layer "BRBa" and "BRPa" is actualy the same.
(!isBRP) && @warn("Only 'I' for Images.jl and 'BRP' MEM layouts are allowed.")
(!isBRP && nz > 1) && @warn("Only 'I' for Images.jl and 'BRP' MEM layouts are allowed.")

# OK, the above is not always true. Image cubes are not pixel interleaved. But how to detect them?
(I.type > 1 || (nz == 2 || nz > 4)) && (layout = layout[1:2] * "B") # Stil leaves out cases of uint8 cubes.
(I.type > 1 || (nz == 2 || nz > 4)) && (layout = layout[1:2] * "B" * layout[4]) # Stil leaves out cases of uint8 cubes.
end
t = reshape(unsafe_wrap(Array, data, ny * nx * nz), o) # Apparently the reshape() creates a copy
end
Expand Down Expand Up @@ -923,7 +923,8 @@ function image_init(API::Ptr{Nothing}, Img::GMTimage)::Ptr{GMT_IMAGE}
toRP_pad(Img, img_padded, n_rows, n_cols, pad)
already_converted = true
else
Ib.data = pointer(Img.image)
isa(Img.image, BitMatrix) && (copy_data = collect(Img.image)) # BitMatrx cannot be sent to C and we may need a copy bellow
Ib.data = (!isa(Img.image, BitMatrix)) ? pointer(Img.image) : pointer(copy_data)
mem_owned_by_gmt = (pad == 0) ? false : true
end

Expand All @@ -946,9 +947,9 @@ function image_init(API::Ptr{Nothing}, Img::GMTimage)::Ptr{GMT_IMAGE}
unsafe_store!(I, Ib)

if (!already_converted && !startswith(Img.layout, "BRP"))
img = (mem_owned_by_gmt) ? img_padded : copy(Img.image)
img = (mem_owned_by_gmt) ? img_padded : copy(Img.image) # This copy is a waste when not Change_layout. Needs revisit.
(size(img,3) > 2) && GMT_Change_Layout(API, GMT_IS_IMAGE, "BRP", 0, I, img); # Convert to BRP. Not 100% on the > 2 though.
Ib.data = pointer(img)
Ib.data = !isa(Img.image, BitMatrix) ? pointer(img) : pointer(copy_data)
unsafe_store!(I, Ib)
end

Expand Down Expand Up @@ -1414,6 +1415,7 @@ Shows information about the `D` GMTdataset (or vector of them).
Runs ``show(stdout, "text/plain", any)`` which prints all elements of `any`. Good for printing the entire vector or matrix.
"""
function info(GI::GItype, showdata::Bool=true; data=true, full=false, crs::Bool=false)
isempty(GI) && return println("Empty object")
crs && return print_crs(GI)
(data != 1) && (showdata = false)
isa(GI, GMTimage) ? println("A GMTimage object with $(size(GI,3)) bands of type $(eltype(GI))") :
Expand Down

0 comments on commit 7c07ef4

Please sign in to comment.