Class: String

Inherits:
Object show all
Defined in:
lib/glimr/renderer/texture.rb

Instance Method Summary collapse

Instance Method Details

#unpremultiply!Object



246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
# File 'lib/glimr/renderer/texture.rb', line 246

def unpremultiply!
  if MAC_OS_X
    i = 0
    while i < size
      a = self[i+3]
      a2 = a / 2
      if a > 0
        r = self[i]
        self[i] = (self[i+2] * 255 + a2) / a
        self[i+1] = (self[i+1] * 255 + a2) / a
        self[i+2] = (r * 255 + a2) / a
      end
      i += 4
    end
  else
    i = 0
    while i < size
      r = self[i+1]
      g = self[i+2]
      b = self[i+3]
      a = self[i]
      if a > 0
        self[i] = (r * 255 + a / 2) / a
        self[i+1] = (g * 255 + a / 2) / a
        self[i+2] = (b * 255 + a / 2) / a
      end
      self[i+3] = a
      i += 4
    end
  end
  self
end