Skip to content

Commit

Permalink
revert change to image_as_matrix
Browse files Browse the repository at this point in the history
  • Loading branch information
cormullion committed Sep 8, 2020
1 parent 0a823be commit ba19650
Show file tree
Hide file tree
Showing 6 changed files with 401 additions and 906 deletions.
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
# Changelog

## [v2.5.1] - September 8 2020

### Added

### Changed

- image_as_matrix(): reverted accidental flip of xy coordinates introduced at 2.5.0 (sorry everyone!)

### Removed

### Deprecated

## [v2.5.0] - September 6 2020

### Added
Expand Down
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "Luxor"
uuid = "ae8d54c2-7ccd-5906-9d76-62fc9837b5bc"
authors = ["cormullion <[email protected]>"]
version = "2.5.0"
version = "2.5.1"

[deps]
Cairo = "159f3aea-2a34-519c-b102-8c37f9878175"
Expand Down
1,253 changes: 363 additions & 890 deletions docs/src/assets/figures/image-drawings.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
27 changes: 14 additions & 13 deletions docs/src/basics.md
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ matrix, using the `image_as_matrix()` function.

`image_as_matrix()` returns a array of ARGB32 values that encode the Red, Green, Blue, and Alpha values of each pixel.

The following example draws a red box, then copies the drawing into a matrix called `mat1`. Then it draws a blue circle, and copies the updated drawing into `mat2`. Then, the second drawing reads the values in from the two matrices and draws some square tiles depending on the corresponding values in the two matrices ... a very primitive Boolean operation.
The following example draws a red box, then copies the drawing into a matrix called `mat1`. Then it draws a blue triangle, and copies the updated drawing into `mat2`. Then, the second drawing reads the values in from the two matrices and draws some square tiles depending on the corresponding values in the two matrices ... a very primitive Boolean operation.

```@example
using Luxor, Colors
Expand All @@ -271,29 +271,30 @@ Drawing(40, 40, :png)
origin()
background("black")
sethue("red")
box(O, 40, 20, :fill)
mat1 = image_as_matrix()'
box(O, 40, 15, :fill)
mat1 = image_as_matrix()
sethue("blue")
setline(5)
circle(O, 15, :stroke)
mat2 = image_as_matrix()'
setline(10)
setopacity(0.6)
ngon(O, 10, 3, 0, :stroke)
mat2 = image_as_matrix()
finish()
# second drawing
Drawing(400, 400, "assets/figures/image-drawings.svg")
background("grey20")
origin()
t = Tiler(400, 400, size(mat1)..., margin=0)
t = Table(mr, mc, 4, 4)
sethue("white")
for (pos, n) in t
pixel1 = convert(Colors.RGBA, mat1[n])
pixel2 = convert(Colors.RGBA, mat2[n])
rc = CartesianIndices(mat1)
for i in rc
r, c = Tuple(i)
pixel1 = convert(Colors.RGBA, mat1[r, c])
pixel2 = convert(Colors.RGBA, mat2[r, c])
if red(pixel1) > .5 && blue(pixel2) > .5
randomhue()
box(pos, t.tilewidth - 1, t.tileheight - 1, :fillstroke)
box(t, r, c, :fillstroke)
end
end
finish() # hide
Expand Down
5 changes: 3 additions & 2 deletions src/drawings.jl
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ function Base.show(io::IO, ::MIME"text/plain", d::Drawing)
# perhaps drawing hasn't started yet, eg in the REPL
if !ispath(d.filename)
location = !isempty(d.filename) ? d.filename : "in memory"
println(" Luxor drawing: (type = :$(d.surfacetype), width = $(d.width), height = $(d.width), location = $(location))")
println(" Luxor drawing: (type = :$(d.surfacetype), width = $(d.width), height = $(d.height), location = $(location))")
else
# open the image file
if Sys.isapple()
Expand Down Expand Up @@ -693,7 +693,8 @@ function image_as_matrix()
h = Int(current_surface().height)
z = zeros(UInt32, w, h)
# create a new image surface to receive the data from the current drawing
imagesurface = CairoImageSurface(z, Cairo.FORMAT_ARGB32)
# flipxy: see issue https://github.com/Wikunia/Javis.jl/pull/149
imagesurface = CairoImageSurface(z, Cairo.FORMAT_ARGB32, flipxy=false)
cr = Cairo.CairoContext(imagesurface)
Cairo.set_source_surface(cr, current_surface(), 0, 0)
Cairo.paint(cr)
Expand Down
8 changes: 8 additions & 0 deletions test/imagematrix.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,14 @@ function convertmatrixtocolors(m)
end

function imagematrix()

Drawing(10, 2, :png)
origin()
img = image_as_matrix()
finish()

@test size(img) == (2, 10)

Drawing(2, 2, :png)

# get image as matrix
Expand Down

0 comments on commit ba19650

Please sign in to comment.