class Pixel
  @mp = nil

  @r = 0
  @g = 0
  @b = 0

  def initialize(mp)
    @mp = mp

    @r = @mp.red
    @g = @mp.green
    @b = @mp.blue
  end

  def randomize
    @r = ((@r >> 2) << 2) | rand(4)
    @g = ((@g >> 2) << 2) | rand(4)
    @b = ((@b >> 2) << 2) | rand(4)
  end

  def getMagickPixel
    @mp.red   = @r
    @mp.green = @g
    @mp.blue  = @b
    return @mp
  end

  def getPixelBits()
    bits = 0

    bits = (bits << 8) | @r
    bits = (bits << 8) | @g
    bits = (bits << 8) | @b

    return bits
  end

  def encodeBits(bits)
    @r = ((@r >> 2) << 2) | (bits & 3)
    bits = bits >> 2

    @g = ((@g >> 2) << 2) | (bits & 3)
    bits = bits >> 2

    @b = ((@b >> 2) << 2) | (bits & 3)
    bits = bits >> 2

    return bits
  end

  def decodeBits
    bits = 0

    bits = (bits << 2) | (@b & 3)
    bits = (bits << 2) | (@g & 3)
    bits = (bits << 2) | (@r & 3)

    return bits
  end
end