class AdbSdkLib::RawImage

Data representing an image taken from a device frame buffer.

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

Public Class Methods

new(image) click to toggle source

@param [Rjb::Rjb_JavaProxy] RawImage Rjb proxy of com.android.ddmlib.RawImage

# 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

Public Instance Methods

argb(index) click to toggle source

Returns ARGB value of a pixel @param [Integer] index of the pixel in data @return [Integer] ARGB value of the given pixel

# File lib/adb_sdklib/raw_image.rb, line 53
def argb(index)
  @image.getARGB(index)
end
argb_at(x,y) click to toggle source

Returns ARGB value of a pixel @param [Integer] pixel index @return [Integer] ARGB value of the given pixel

# File lib/adb_sdklib/raw_image.rb, line 60
def argb_at(x,y)
  @image.getARGB(point_to_index(x,y))
end
bpp() click to toggle source

Returns image’s bpp @return [Integer] image’s bpp

# File lib/adb_sdklib/raw_image.rb, line 101
def bpp()
  @image.bpp
end
each_pixel() { |pixel(x,y)| ... } click to toggle source

Calls block once for each pixel in data, passing that device as a parameter. If no block is given, an enumerator is returned instead. @return [Enumerator] if not block given @return [self] if block given @yield [pixel] called with each pixel @yieldparam [Pixel] pixel a pixel instance

# 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
height() click to toggle source

Returns image’s height @return [Integer] image’s height

# File lib/adb_sdklib/raw_image.rb, line 95
def height()
  @image.height
end
pixel(x,y) click to toggle source

Returns pixel content @param [Integer, Integer] pixel position x,y @return [AdbSdkLib::Pixel] pixel content

# 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) click to toggle source

Returns pixel index for a given position @param [Integer, Integer] pixel position x,y @return [Integer] pixel index

# File lib/adb_sdklib/raw_image.rb, line 108
def point_to_index(x,y)
  return (x*(bpp >> 3))+(y*((bpp >> 3)*(width)))
end
rotated() click to toggle source

Returns a rotated version of the image The image is rotated counter-clockwise. @return [RawImage] rotated image

# File lib/adb_sdklib/raw_image.rb, line 46
def rotated
  RawImage.new(@image.getRotated())
end
width() click to toggle source

Returns image’s width @return [Integer] image’s width

# File lib/adb_sdklib/raw_image.rb, line 89
def width()
  @image.width
end