Skip to content

Commit

Permalink
made it work with Ruby 1.9
Browse files Browse the repository at this point in the history
Ruby 1.9 has a different treatment of "character" data type.

In 1.8.7, it's an integer. 1.9.2 treats it as one-char string.
Thus, for 1.9.2 to work, it is necessary to insert the conversion
functions ord and chr at appropriate places. 1.8.7 will treat ord
on integers as no-op. chr is always invoked on integers, as is
correct. This will make a slight performance hit, as an additional
function call is performed for each pixel access.
  • Loading branch information
Goran Topic committed May 18, 2011
1 parent fbdaf01 commit 2266494
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions lib/imageruby/bitmap/rbbitmap.rb
Expand Up @@ -41,10 +41,10 @@ def get_pixel(x,y)
index = (y*@width + x)
pointindex = index*3
Color.from_rgba(
@array[pointindex+2],
@array[pointindex+1],
@array[pointindex],
@alpha ? @alpha[index] : 255
@array[pointindex+2].ord,
@array[pointindex+1].ord,
@array[pointindex].ord,
@alpha ? @alpha[index].ord : 255
)

end
Expand All @@ -66,13 +66,13 @@ def set_pixel(x,y,color)

index = (y*@width + x)
pointindex = index*3
@array[pointindex+2] = color.r
@array[pointindex+1] = color.g
@array[pointindex] = color.b
@array[pointindex+2] = color.r.chr
@array[pointindex+1] = color.g.chr
@array[pointindex] = color.b.chr

if color.a != 255 then
@alpha = "\xff"*(@height * @width) unless @alpha
@alpha[index] = color.a
@alpha[index] = color.a.chr
end

self
Expand Down

0 comments on commit 2266494

Please sign in to comment.