Skip to content

Commit

Permalink
Fix #179
Browse files Browse the repository at this point in the history
Fix Gray buffer settings

Fix fillgrayalpha!

Adjust tests for new color layout
  • Loading branch information
rsrock committed Sep 8, 2014
1 parent f556bdd commit 724f345
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 32 deletions.
8 changes: 4 additions & 4 deletions src/ioformats/OSXnative.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module LibOSXNative

#import Base: error, size
using Images, Color, Images.ColorTypes
using Images, Color, Images.ColorTypes, FixedPointNumbers

export imread

Expand Down Expand Up @@ -56,8 +56,8 @@ function imread(filename)
sz = imframes > 1 ? (int(imwidth), int(imheight), int(imframes)) : (int(imwidth), int(imheight))
T = Images.ufixedtype[pixeldepth]
if colormodel == "Gray" && alphacode == 0 && storagedepth == 1
buf = Array(T, sz)
fillgray!(buf, imgsrc)
buf = Array(Gray{T}, sz)
fillgray!(reinterpret(T, buf, tuple(sz...)), imgsrc)
elseif colormodel == "Gray" && in(alphacode, [1, 2, 3, 4])
buf = Array(GrayAlpha{T}, sz)
fillgrayalpha!(reinterpret(T, buf, tuple(2, sz...)), imgsrc)
Expand Down Expand Up @@ -129,7 +129,7 @@ function fillgray!{T}(buffer::AbstractArray{T, 3}, imgsrc)
end
end

function fillgrayalpha!{T<:Uint8}(buffer::AbstractArray{T, 3}, imgsrc)
function fillgrayalpha!{T<:Union(Uint8, Ufixed8)}(buffer::AbstractArray{T, 3}, imgsrc)
imwidth, imheight = size(buffer, 2), size(buffer, 3)
CGimg = CGImageSourceCreateImageAtIndex(imgsrc, 0)
imagepixels = CopyImagePixels(CGimg)
Expand Down
56 changes: 28 additions & 28 deletions test/readOSX.jl
Original file line number Diff line number Diff line change
@@ -1,62 +1,62 @@
using Images, TestImages
using Images, TestImages, Color, FixedPointNumbers
using Base.Test

img = testimage("autumn_leaves")
@assert colorspace(img) == "RGBA"
@assert ndims(img) == 3
@assert colordim(img) == 1
@assert eltype(img) == Uint16
@assert ndims(img) == 2
@assert colordim(img) == 0
@assert eltype(img) == AlphaColorValue{RGB{Ufixed16}, Ufixed16}

img = testimage("cameraman")
@assert colorspace(img) == "Gray"
@assert ndims(img) == 2
@assert colordim(img) == 0
@assert eltype(img) == Uint8
@assert eltype(img) == Gray{Ufixed8}

img = testimage("earth_apollo17")
@assert colorspace(img) == "RGB"
@assert ndims(img) == 3
@assert colordim(img) == 1
@assert eltype(img) == Uint8
@assert colorspace(img) == "RGB4"
@assert ndims(img) == 2
@assert colordim(img) == 0
@assert eltype(img) == RGB4{Ufixed8}

img = testimage("fabio")
@assert colorspace(img) == "Gray"
@assert ndims(img) == 2
@assert colordim(img) == 0
@assert eltype(img) == Uint8
@assert eltype(img) == Gray{Ufixed8}

img = testimage("house")
@assert colorspace(img) == "GrayAlpha"
@assert ndims(img) == 3
@assert colordim(img) == 1
@assert eltype(img) == Uint8
@assert ndims(img) == 2
@assert colordim(img) == 0
@assert eltype(img) == AlphaColorValue{Gray{Ufixed8}, Ufixed8}

img = testimage("jetplane")
@assert colorspace(img) == "GrayAlpha"
@assert ndims(img) == 3
@assert colordim(img) == 1
@assert eltype(img) == Uint8
@assert ndims(img) == 2
@assert colordim(img) == 0
@assert eltype(img) == AlphaColorValue{Gray{Ufixed8}, Ufixed8}

img = testimage("lighthouse")
@assert colorspace(img) == "RGB"
@assert ndims(img) == 3
@assert colordim(img) == 1
@assert eltype(img) == Uint8
@assert colorspace(img) == "RGB4"
@assert ndims(img) == 2
@assert colordim(img) == 0
@assert eltype(img) == RGB4{Ufixed8}

img = testimage("mandrill")
@assert colorspace(img) == "RGB"
@assert ndims(img) == 3
@assert colordim(img) == 1
@assert eltype(img) == Uint8
@assert ndims(img) == 2
@assert colordim(img) == 0
@assert eltype(img) == RGB{Ufixed8}

img = testimage("moonsurface")
@assert colorspace(img) == "Gray"
@assert ndims(img) == 2
@assert colordim(img) == 0
@assert eltype(img) == Uint8
@assert eltype(img) == Gray{Ufixed8}

img = testimage("mountainstream")
@assert colorspace(img) == "RGB"
@assert ndims(img) == 3
@assert colordim(img) == 1
@assert eltype(img) == Uint8
@assert colorspace(img) == "RGB4"
@assert ndims(img) == 2
@assert colordim(img) == 0
@assert eltype(img) == RGB4{Ufixed8}

0 comments on commit 724f345

Please sign in to comment.