Class: AdbSdkLib::RawImage

Inherits:
Object
  • Object
show all
Defined in:
lib/adb_sdklib/raw_image.rb

Overview

Data representing an image taken from a device frame buffer.

This is a wrapper of com.android.ddmlib.RawImage

Instance Method Summary collapse

Constructor Details

#initialize(image) ⇒ RawImage

Returns a new instance of RawImage.

Parameters:

  • RawImage (Rjb::Rjb_JavaProxy)

    Rjb proxy of com.android.ddmlib.RawImage



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/adb_sdklib/raw_image.rb', line 26

def initialize(image)
  unless image.instance_of?(Rjb::Rjb_JavaProxy) &&
      image._classname == 'com.android.ddmlib.RawImage'
    raise TypeError, "Parameter is not com.android.ddmlib.RawImage class"
  end
  class << image
    def call_java_method(method_name, *args)
      rjb_method_missing(method_name, *args)
    rescue => e
      raise SdkLibError.new(e.message, e.class.to_s, self._classname, method_name)
    end
    alias_method :rjb_method_missing, :method_missing
    alias_method :method_missing, :call_java_method
  end
  @image = image
end

Instance Method Details

#argb(index) ⇒ Integer

Returns ARGB value of a pixel

Parameters:

  • index (Integer)

    of the pixel in data

Returns:

  • (Integer)

    ARGB value of the given pixel



53
54
55
# File 'lib/adb_sdklib/raw_image.rb', line 53

def argb(index)
  @image.getARGB(index)
end

#argb_at(x, y) ⇒ Integer

Returns ARGB value of a pixel

Parameters:

  • pixel (Integer)

    index

Returns:

  • (Integer)

    ARGB value of the given pixel



60
61
62
# File 'lib/adb_sdklib/raw_image.rb', line 60

def argb_at(x,y)
  @image.getARGB(point_to_index(x,y))
end

#bppInteger

Returns image’s bpp

Returns:

  • (Integer)

    image’s bpp



101
102
103
# File 'lib/adb_sdklib/raw_image.rb', line 101

def bpp()
  @image.bpp
end

#each_pixel {|pixel| ... } ⇒ Enumerator, self

Calls block once for each pixel in data, passing that device as a parameter. If no block is given, an enumerator is returned instead.

Yields:

  • (pixel)

    called with each pixel

Yield Parameters:

  • pixel (Pixel)

    a pixel instance

Returns:

  • (Enumerator)

    if not block given

  • (self)

    if block given



77
78
79
80
81
82
83
84
85
# File 'lib/adb_sdklib/raw_image.rb', line 77

def each_pixel()
  return to_enum :each_pixel unless block_given?
  @image.height.times do |y|
    @image.width.times do |x|
      yield pixel(x,y)
    end
  end
  self
end

#heightInteger

Returns image’s height

Returns:

  • (Integer)

    image’s height



95
96
97
# File 'lib/adb_sdklib/raw_image.rb', line 95

def height()
  @image.height
end

#pixel(x, y) ⇒ AdbSdkLib::Pixel

Returns pixel content

Parameters:

  • pixel (Integer, Integer)

    position x,y

Returns:



67
68
69
# File 'lib/adb_sdklib/raw_image.rb', line 67

def pixel(x,y)
  Pixel.new(x,y,@image.getARGB(point_to_index(x,y)))
end

#point_to_index(x, y) ⇒ Integer

Returns pixel index for a given position

Parameters:

  • pixel (Integer, Integer)

    position x,y

Returns:

  • (Integer)

    pixel index



108
109
110
# File 'lib/adb_sdklib/raw_image.rb', line 108

def point_to_index(x,y)
  return (x*(bpp >> 3))+(y*((bpp >> 3)*(width)))
end

#rotatedRawImage

Returns a rotated version of the image The image is rotated counter-clockwise.

Returns:



46
47
48
# File 'lib/adb_sdklib/raw_image.rb', line 46

def rotated
  RawImage.new(@image.getRotated())
end

#widthInteger

Returns image’s width

Returns:

  • (Integer)

    image’s width



89
90
91
# File 'lib/adb_sdklib/raw_image.rb', line 89

def width()
  @image.width
end