Class: Skia::ImageInfo

Inherits:
Object
  • Object
show all
Defined in:
lib/skia/image_info.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(width:, height:, color_type: :rgba_8888, alpha_type: :premul, color_space: nil) ⇒ ImageInfo

Returns a new instance of ImageInfo.

Raises:

  • (ArgumentError)


7
8
9
10
11
12
13
14
15
16
17
# File 'lib/skia/image_info.rb', line 7

def initialize(width:, height:, color_type: :rgba_8888, alpha_type: :premul, color_space: nil)
  @width = width.to_i
  @height = height.to_i
  @color_type = color_type
  @alpha_type = alpha_type
  @color_space = color_space

  raise ArgumentError, 'width must be positive' if @width <= 0
  raise ArgumentError, 'height must be positive' if @height <= 0
  raise ArgumentError, 'color_space must be a Skia::ColorSpace or nil' unless @color_space.nil? || @color_space.is_a?(ColorSpace)
end

Instance Attribute Details

#alpha_typeObject (readonly)

Returns the value of attribute alpha_type.



5
6
7
# File 'lib/skia/image_info.rb', line 5

def alpha_type
  @alpha_type
end

#color_spaceObject (readonly)

Returns the value of attribute color_space.



5
6
7
# File 'lib/skia/image_info.rb', line 5

def color_space
  @color_space
end

#color_typeObject (readonly)

Returns the value of attribute color_type.



5
6
7
# File 'lib/skia/image_info.rb', line 5

def color_type
  @color_type
end

#heightObject (readonly)

Returns the value of attribute height.



5
6
7
# File 'lib/skia/image_info.rb', line 5

def height
  @height
end

#widthObject (readonly)

Returns the value of attribute width.



5
6
7
# File 'lib/skia/image_info.rb', line 5

def width
  @width
end

Class Method Details

.from_struct(struct, retain_color_space: true) ⇒ Object



19
20
21
22
23
24
25
26
27
28
# File 'lib/skia/image_info.rb', line 19

def self.from_struct(struct, retain_color_space: true)
  color_space = ColorSpace.wrap(struct[:colorspace], retain: retain_color_space)
  new(
    width: struct[:width],
    height: struct[:height],
    color_type: struct[:colorType],
    alpha_type: struct[:alphaType],
    color_space: color_space
  )
end

Instance Method Details

#bytes_per_pixelObject



40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/skia/image_info.rb', line 40

def bytes_per_pixel
  case @color_type
  when :alpha_8, :gray_8
    1
  when :rgb_565, :argb_4444
    2
  when :rgba_f16
    8
  when :rgba_f32
    16
  else
    4
  end
end

#min_row_bytesObject



55
56
57
# File 'lib/skia/image_info.rb', line 55

def min_row_bytes
  @width * bytes_per_pixel
end

#to_structObject



30
31
32
33
34
35
36
37
38
# File 'lib/skia/image_info.rb', line 30

def to_struct
  struct = Native::SKImageInfo.new
  struct[:width] = @width
  struct[:height] = @height
  struct[:colorType] = @color_type
  struct[:alphaType] = @alpha_type
  struct[:colorspace] = @color_space&.ptr
  struct
end